From mboxrd@z Thu Jan 1 00:00:00 1970 X-GM-THRID: 6543937367387930624 X-Received: by 10.28.150.144 with SMTP id y138mr877238wmd.2.1523879281849; Mon, 16 Apr 2018 04:48:01 -0700 (PDT) X-BeenThere: isar-users@googlegroups.com Received: by 10.28.11.10 with SMTP id 10ls1745374wml.12.canary-gmail; Mon, 16 Apr 2018 04:48:01 -0700 (PDT) X-Google-Smtp-Source: AIpwx4/XMxuE3fvkGhsDn0R+EH5lOntcN1Utu8Y8oP6rY/InKDiIIJMNFfsltbsHsvIZLrPJlwi+ X-Received: by 10.28.192.4 with SMTP id q4mr774424wmf.27.1523879281211; Mon, 16 Apr 2018 04:48:01 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1523879281; cv=none; d=google.com; s=arc-20160816; b=jMKlneBDN2Dwgms3fH7ZPYr5FQJ504/8PSC5VN5J582f7nJpq8VVNx2OvD0x5VSv44 /gH2uPjV08HFcx+AxMj76eBGlPpvqfzLOs7srkOQdZp2582Fkjoo4k1IbB2mP6PbP8C8 qhBUSTakpTYfnby5CtTlHdtnlbgz0+CJNi7NfMpZ4th57NXSWSEid2rC7zTKl8hCOShs f0ARSAhqxKYG82FwPefVM3id/tQc06ZnUUdht5wckSSgwzXLt/1VhdXgHsKQwzZJxons boSN6IT0uVw59ufj4/2dCJODKJKZ7CJ4ucir4QOX5Ym1xea7I65Nw0PXpNts97fVaSH2 jbHw== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:subject:cc:to:from:date:arc-authentication-results; bh=GIB8KjCZN7lOr/gawYrAt8qWsfHWyz/R3zosBuH0UrQ=; b=QdSlwrNJycocnrTPUURgXMw3w44PLb2NmF84tWzTLoUpWCwNxMWcRZizWTTxeUcKNE /5g35+eJEaf9bCGBDdkKphkmgI7/afOLKCeTdbjLK2R/+ksUH8ucHrLl2MDxFdZB2vO5 gQMhm9Bl8UDUcWHAg46ykuBJVxzi5oravibnJ0+P7BZnClNh5wM01a9rvdZ6m/Q7w8sS 1QasZQsTYXFlW3VU5HFL82InTUfsG0cEHZezlOrjU0IHHczButZdJ3bfPQkOUIPzyKtK r08GtwWE9yf/tr4wuY074WmbNPRALDY5cb8b2ugknSR544Jwntkd2gp8RWtZ3ThQp4nl qJmw== ARC-Authentication-Results: i=1; gmr-mx.google.com; spf=pass (google.com: domain of henning.schild@siemens.com designates 192.35.17.2 as permitted sender) smtp.mailfrom=henning.schild@siemens.com Return-Path: Received: from thoth.sbs.de (thoth.sbs.de. [192.35.17.2]) by gmr-mx.google.com with ESMTPS id k9si429031wri.5.2018.04.16.04.48.01 for (version=TLS1_2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Mon, 16 Apr 2018 04:48:01 -0700 (PDT) Received-SPF: pass (google.com: domain of henning.schild@siemens.com designates 192.35.17.2 as permitted sender) client-ip=192.35.17.2; Authentication-Results: gmr-mx.google.com; spf=pass (google.com: domain of henning.schild@siemens.com designates 192.35.17.2 as permitted sender) smtp.mailfrom=henning.schild@siemens.com Received: from mail3.siemens.de (mail3.siemens.de [139.25.208.14]) by thoth.sbs.de (8.15.2/8.15.2) with ESMTPS id w3GBm0vF010571 (version=TLSv1.2 cipher=DHE-RSA-AES256-GCM-SHA384 bits=256 verify=OK); Mon, 16 Apr 2018 13:48:00 +0200 Received: from mmd1pvb1c.ad001.siemens.net (md1pvb1c.ad001.siemens.net [139.25.68.40] (may be forged)) by mail3.siemens.de (8.15.2/8.15.2) with ESMTP id w3GBm02c010156; Mon, 16 Apr 2018 13:48:00 +0200 Date: Mon, 16 Apr 2018 13:48:00 +0200 From: Henning Schild To: Andreas Reichel Cc: , Cedric Hombourger Subject: Re: [PATCH v2 12/17] wic: Add pcibios boot plugins and wks files Message-ID: <20180416134800.13072d29@mmd1pvb1c.ad001.siemens.net> In-Reply-To: <20180416105229.GG8866@iiotirae> References: <26083c546f8e46359f4a4edb29e169e9935fe6ee.1523628814.git.henning.schild@siemens.com> <20180416105229.GG8866@iiotirae> X-Mailer: Claws Mail 3.15.0-dirty (GTK+ 2.24.31; x86_64-pc-linux-gnu) MIME-Version: 1.0 Content-Type: text/plain; charset=US-ASCII Content-Transfer-Encoding: 7bit X-TUID: M4iTO8zaKJ6E Am Mon, 16 Apr 2018 12:52:29 +0200 schrieb Andreas Reichel : > On Fri, Apr 13, 2018 at 04:19:01PM +0200, Henning Schild wrote: > > Create a modified version of directdisk.wks that enabled legacy boot > > images in Isar. "bootimg-pcbios-isar" expects the buildchroot to > > contain the packages "syslinux syslinux-common" and will create a > > disk using this bootloader. > > > > Signed-off-by: Henning Schild > > --- > > .../scripts/lib/wic/canned-wks/common-isar.wks.inc | 3 + > > .../scripts/lib/wic/canned-wks/directdisk-isar.wks | 7 + > > .../lib/wic/plugins/source/bootimg-pcbios-isar.py | 217 > > +++++++++++++++++++++ 3 files changed, 227 insertions(+) > > create mode 100644 > > meta-isar/scripts/lib/wic/canned-wks/common-isar.wks.inc create > > mode 100644 > > meta-isar/scripts/lib/wic/canned-wks/directdisk-isar.wks create > > mode 100644 > > meta-isar/scripts/lib/wic/plugins/source/bootimg-pcbios-isar.py > > > > diff --git > > a/meta-isar/scripts/lib/wic/canned-wks/common-isar.wks.inc > > b/meta-isar/scripts/lib/wic/canned-wks/common-isar.wks.inc new file > > mode 100644 index 0000000..c8ea4c2 --- /dev/null > > +++ b/meta-isar/scripts/lib/wic/canned-wks/common-isar.wks.inc > > @@ -0,0 +1,3 @@ > > +# This file is included into 3 canned wks files from this directory > > +part /boot --source bootimg-pcbios-isar --ondisk sda --label boot > > --active --align 1024 +part / --source rootfs --ondisk sda > > --fstype=ext4 --label platform --align 1024 diff --git > > a/meta-isar/scripts/lib/wic/canned-wks/directdisk-isar.wks > > b/meta-isar/scripts/lib/wic/canned-wks/directdisk-isar.wks new file > > mode 100644 index 0000000..2b9576d --- /dev/null > > +++ b/meta-isar/scripts/lib/wic/canned-wks/directdisk-isar.wks > > @@ -0,0 +1,7 @@ > > +# short-description: Create a 'pcbios' direct disk image > > +# long-description: Creates a partitioned legacy BIOS disk image > > that the user +# can directly dd to boot media. > > + > > +include common-isar.wks.inc > > + > > +bootloader --timeout=0 --append="rootwait rootfstype=ext4 > > video=vesafb vga=0x318 console=tty0 console=ttyS0,115200n8" diff > > --git > > a/meta-isar/scripts/lib/wic/plugins/source/bootimg-pcbios-isar.py > > b/meta-isar/scripts/lib/wic/plugins/source/bootimg-pcbios-isar.py > > new file mode 100644 index 0000000..0423862 --- /dev/null +++ > > b/meta-isar/scripts/lib/wic/plugins/source/bootimg-pcbios-isar.py > > @@ -0,0 +1,217 @@ +# ex:ts=4:sw=4:sts=4:et > > +# -*- tab-width: 4; c-basic-offset: 4; indent-tabs-mode: nil -*- > > +# > > +# Copyright (c) 2014, Intel Corporation. > > +# All rights reserved. > > +# > > +# This program is free software; you can redistribute it and/or > > modify +# it under the terms of the GNU General Public License > > version 2 as +# published by the Free Software Foundation. > > +# > > +# This program is distributed in the hope that it will be useful, > > +# but WITHOUT ANY WARRANTY; without even the implied warranty of > > +# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the > > +# GNU General Public License for more details. > > +# > > +# You should have received a copy of the GNU General Public > > License along +# with this program; if not, write to the Free > > Software Foundation, Inc., +# 51 Franklin Street, Fifth Floor, > > Boston, MA 02110-1301 USA. +# > > +# DESCRIPTION > > +# This implements the 'bootimg-pcbios-isar' source plugin class > > for 'wic' +# > > +# AUTHORS > > +# Tom Zanussi > > +# > > + > > +import logging > > +import os > > + > > +from wic import WicError > > +from wic.engine import get_custom_config > > +from wic.utils import runner > > +from wic.pluginbase import SourcePlugin > > +from wic.utils.misc import (exec_cmd, exec_native_cmd, > > + get_bitbake_var, BOOTDD_EXTRA_SPACE) > > + > > +logger = logging.getLogger('wic') > > + > > +class BootimgPcbiosIsarPlugin(SourcePlugin): > > + """ > > + Create MBR boot partition and install syslinux on it. > > + """ > > + > > + name = 'bootimg-pcbios-isar' > > + > > + @classmethod > > + def _get_syslinux_dir(cls, bootimg_dir): > > + """ > > + Get path to syslinux from either default bootimg_dir > > + or wic-tools STAGING_DIR. > > + """ > > + for path in (bootimg_dir, > > get_bitbake_var("STAGING_DATADIR", "wic-tools")): > > + if not path: > > + continue > > + syslinux_dir = os.path.join(path, 'syslinux') > > + if os.path.exists(syslinux_dir): > > + return syslinux_dir > > + > > + raise WicError("Couldn't find syslinux directory, exiting") > > + > > + @classmethod > > + def do_install_disk(cls, disk, disk_name, creator, workdir, > > oe_builddir, > > + bootimg_dir, kernel_dir, native_sysroot): > > + """ > > + Called after all partitions have been prepared and > > assembled into a > > + disk image. In this case, we install the MBR. > > + """ > > + syslinux_dir = cls._get_syslinux_dir(bootimg_dir) > > + if creator.ptable_format == 'msdos': > > + mbrfile = os.path.join(syslinux_dir, "mbr/mbr.bin") > > + elif creator.ptable_format == 'gpt': > > + mbrfile = os.path.join(syslinux_dir, > > "mbr/gptmbr.bin") > I know that a GPT contains an MBR for compatibility reasons. But this > is usually just to stop the system from booting of the harddisk > partitioned by GPT if it is used in an older PC accidentally. Why > would one want to install syslinux with MBR support into the > protected MBR of a GPT that should not be used for booting? Or do I > get that wrong? This is exactly how wic does it. Maybe when i send that as fork and later modify we can just review the isar-changes. Henning > > + else: > > + raise WicError("Unsupported partition table: %s" % > > + creator.ptable_format) > > + > > + if not os.path.exists(mbrfile): > > + raise WicError("Couldn't find %s. If using the -e > > option, do you " > > + "have the right MACHINE set in > > local.conf? If not, " > > + "is the bootimg_dir path correct?" % > > mbrfile) + > > + full_path = creator._full_path(workdir, disk_name, > > "direct") > > + logger.debug("Installing MBR on disk %s as %s with size %s > > bytes", > > + disk_name, full_path, disk.min_size) > > + > > + rcode = runner.show(['dd', 'if=%s' % mbrfile, > > + 'of=%s' % full_path, 'conv=notrunc']) > > + if rcode != 0: > > + raise WicError("Unable to set MBR to %s" % full_path) > > + > > + @classmethod > > + def do_configure_partition(cls, part, source_params, creator, > > cr_workdir, > > + oe_builddir, bootimg_dir, > > kernel_dir, > > + native_sysroot): > > + """ > > + Called before do_prepare_partition(), creates syslinux > > config > > + """ > > + hdddir = "%s/hdd/boot" % cr_workdir > > + > > + install_cmd = "install -d %s" % hdddir > > + exec_cmd(install_cmd) > > + > > + bootloader = creator.ks.bootloader > > + > > + custom_cfg = None > > + if bootloader.configfile: > > + custom_cfg = get_custom_config(bootloader.configfile) > > + if custom_cfg: > > + # Use a custom configuration for grub > > + syslinux_conf = custom_cfg > > + logger.debug("Using custom configuration file %s " > > + "for syslinux.cfg", > > bootloader.configfile) > > + else: > > + raise WicError("configfile is specified but failed > > to " > > + "get it from %s." % > > bootloader.configfile) + > > + if not custom_cfg: > > + # Create syslinux configuration using parameters from > > wks file > > + splash = os.path.join(cr_workdir, > > "/hdd/boot/splash.jpg") > > + if os.path.exists(splash): > > + splashline = "menu background splash.jpg" > > + else: > > + splashline = "" > > + > > + syslinux_conf = "" > > + syslinux_conf += "PROMPT 0\n" > > + syslinux_conf += "TIMEOUT " + str(bootloader.timeout) > > + "\n" > > + syslinux_conf += "\n" > > + syslinux_conf += "ALLOWOPTIONS 1\n" > > + syslinux_conf += "SERIAL 0 115200\n" > > + syslinux_conf += "\n" > > + if splashline: > > + syslinux_conf += "%s\n" % splashline > > + syslinux_conf += "DEFAULT boot\n" > > + syslinux_conf += "LABEL boot\n" > > + > > + kernel = get_bitbake_var("KERNEL_IMAGE") > > + initrd = get_bitbake_var("INITRD_IMAGE") > > + syslinux_conf += "KERNEL " + kernel + "\n" > > + > > + syslinux_conf += "APPEND label=boot root=%s initrd=%s > > %s\n" % \ > > + (creator.rootdev, initrd, > > bootloader.append) + > > + logger.debug("Writing syslinux config > > %s/hdd/boot/syslinux.cfg", > > + cr_workdir) > > + cfg = open("%s/hdd/boot/syslinux.cfg" % cr_workdir, "w") > > + cfg.write(syslinux_conf) > > + cfg.close() > > + > > + @classmethod > > + def do_prepare_partition(cls, part, source_params, creator, > > cr_workdir, > > + oe_builddir, bootimg_dir, kernel_dir, > > + rootfs_dir, native_sysroot): > > + """ > > + Called to do the actual content population for a partition > > i.e. it > > + 'prepares' the partition to be incorporated into the image. > > + In this case, prepare content for legacy bios boot > > partition. > > + """ > > + syslinux_dir = cls._get_syslinux_dir(bootimg_dir) > > + > > + staging_kernel_dir = kernel_dir > > + kernel = get_bitbake_var("KERNEL_IMAGE") > > + initrd = get_bitbake_var("INITRD_IMAGE") > > + > > + hdddir = "%s/hdd/boot" % cr_workdir > > + > > + cmds = ("install -m 0644 %s/%s %s/%s" % > > + (staging_kernel_dir, kernel, hdddir, kernel), > > + "install -m 0644 %s/%s %s/%s" % > > + (staging_kernel_dir, initrd, hdddir, initrd), > > + "install -m 444 %s/modules/bios/ldlinux.c32 > > %s/ldlinux.c32" % > > + (syslinux_dir, hdddir), > > + "install -m 0644 %s/modules/bios/vesamenu.c32 > > %s/vesamenu.c32" % > > + (syslinux_dir, hdddir), > > + "install -m 444 %s/modules/bios/libcom32.c32 > > %s/libcom32.c32" % > > + (syslinux_dir, hdddir), > > + "install -m 444 %s/modules/bios/libutil.c32 > > %s/libutil.c32" % > > + (syslinux_dir, hdddir)) > > + > > + for install_cmd in cmds: > > + exec_cmd(install_cmd) > > + > > + du_cmd = "du -bks %s" % hdddir > > + out = exec_cmd(du_cmd) > > + blocks = int(out.split()[0]) > > + > > + extra_blocks = part.get_extra_block_count(blocks) > > + > > + if extra_blocks < BOOTDD_EXTRA_SPACE: > > + extra_blocks = BOOTDD_EXTRA_SPACE > > + > > + blocks += extra_blocks > > + > > + logger.debug("Added %d extra blocks to %s to get to %d > > total blocks", > > + extra_blocks, part.mountpoint, blocks) > > + > > + # dosfs image, created by mkdosfs > > + bootimg = "%s/boot.img" % cr_workdir > > + > > + dosfs_cmd = "mkdosfs -n boot -S 512 -C %s %d" % (bootimg, > > blocks) > > + exec_native_cmd(dosfs_cmd, native_sysroot) > > + > > + mcopy_cmd = "mcopy -i %s -s %s/* ::/" % (bootimg, hdddir) > > + exec_cmd(mcopy_cmd, native_sysroot) > > + > > + syslinux_cmd = "syslinux %s" % bootimg > > + exec_native_cmd(syslinux_cmd, native_sysroot) > > + > > + chmod_cmd = "chmod 644 %s" % bootimg > > + exec_cmd(chmod_cmd) > > + > > + du_cmd = "du -Lbks %s" % bootimg > > + out = exec_cmd(du_cmd) > > + bootimg_size = out.split()[0] > > + > > + part.size = int(bootimg_size) > > + part.source_file = bootimg > > -- > > 2.16.1 > > >