From mboxrd@z Thu Jan 1 00:00:00 1970 X-GM-THRID: 6517147827419742208 X-Received: by 10.80.202.11 with SMTP id d11mr11913891edi.9.1517391723248; Wed, 31 Jan 2018 01:42:03 -0800 (PST) X-BeenThere: isar-users@googlegroups.com Received: by 10.80.158.236 with SMTP id a99ls2775657edf.7.gmail; Wed, 31 Jan 2018 01:42:02 -0800 (PST) X-Google-Smtp-Source: AH8x224k4awKJN53WPhllnMdosHSQOTY30qCj/hgAE7RhA/AAauE4eKN8awSfz575GrpZCLCpRd+ X-Received: by 10.80.184.23 with SMTP id j23mr11896127ede.3.1517391722810; Wed, 31 Jan 2018 01:42:02 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1517391722; cv=none; d=google.com; s=arc-20160816; b=GeDacfl/cQ+Kh8whTGO5gLi6eWg6HICWu6yHKS8j8cnOElCN+Oy1pjExHitfS6Qzxo d2G5xXXeLkNP+x1hA9LMQwEh91mQZeS2RHcXjjL8r87TMtQs3BYPG8vIW4WJxQkLeOc/ W+iNg/nxpLiYARCUbsUigNErq2uilyv0o2bBtvtRNlyksgnRDs1OW/FuRhcsC2Je/O+f hfqZXUweeqwCOiW3eMWjVmQzuA5r+U5/yBQhVp+KQsiCEvcDBUgMOfeiwuxWrfeBB7NW lldgyBsWvjB4UYUNTZOm7OmoBtsYOh6zmP/wO5joItXnVhX0DgPRdCBKZ5JYZZne8avA zumQ== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=references:in-reply-to:references:in-reply-to:message-id:date :subject:cc:to:from:arc-authentication-results; bh=24Lrwp2wqvEKZQyrHQI/lGwv+RlwQqBbm7/LAlMUsX8=; b=bPLU3ZeI3zmkL/4f5WjyB1A04ZkhvhczHVl9xiDyeMhFLZMSzqT0iq6+9V1+YRVwbq dvFWnC6Lu1Cwuh3FGpgQXciuo/2I8cDnSr6S7QrPXEy/nF7KOTCufvPJ2ssxnL6gEgGT KLd74fMEREVhpCJd/eOokwPYOJ55n8lDwrCq5fi+UMkfxvxyDssGGU34GwWpmA7vIdF6 a1/Y3m4didtrvXrsLEO7aZ2Swv5UdjZptS7ola0RMn6L/nPNc1qDefySKRyWzVVV+zwv D4+4FDMXddgDIIXtS3t7rYnwt/mZ/Y6iAEdg6nm+MzI15F1L9mtu3ufCqzID94Umm1TO XedA== ARC-Authentication-Results: i=1; gmr-mx.google.com; spf=pass (google.com: domain of henning.schild@siemens.com designates 192.35.17.14 as permitted sender) smtp.mailfrom=henning.schild@siemens.com Return-Path: Received: from david.siemens.de (david.siemens.de. [192.35.17.14]) by gmr-mx.google.com with ESMTPS id m19si1701475edd.4.2018.01.31.01.42.02 for (version=TLS1_2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Wed, 31 Jan 2018 01:42:02 -0800 (PST) Received-SPF: pass (google.com: domain of henning.schild@siemens.com designates 192.35.17.14 as permitted sender) client-ip=192.35.17.14; Authentication-Results: gmr-mx.google.com; spf=pass (google.com: domain of henning.schild@siemens.com designates 192.35.17.14 as permitted sender) smtp.mailfrom=henning.schild@siemens.com Received: from mail3.siemens.de (mail3.siemens.de [139.25.208.14]) by david.siemens.de (8.15.2/8.15.2) with ESMTPS id w0V9g2ef029641 (version=TLSv1.2 cipher=DHE-RSA-AES256-GCM-SHA384 bits=256 verify=OK) for ; Wed, 31 Jan 2018 10:42:02 +0100 Received: from md1pvb1c.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 w0V9g1aX008484; Wed, 31 Jan 2018 10:42:02 +0100 From: Henning Schild To: isar-users@googlegroups.com Cc: Henning Schild Subject: [PATCH 3/9] wic: add a bootimg-efi-isar plugin outside the wic tree Date: Wed, 31 Jan 2018 10:41:54 +0100 Message-Id: <5813b0e31a65669b6e27294b70050e3e70626b57.1517390790.git.henning.schild@siemens.com> X-Mailer: git-send-email 2.13.6 In-Reply-To: References: In-Reply-To: References: X-TUID: nefqSjd3Bt6u The added plugin is a copy of the modified version in our wic. Move it out and rename it so we can get back to a clean wic. Issues: - wic in Isar has been messed with Impact: This patch prepares for the Issue beeing solved, because now the plugin is outside the wic-tree. Nothing changes for users. Signed-off-by: Henning Schild --- .../scripts/lib/wic/canned-wks/sdimage-efi.wks | 2 +- .../lib/wic/plugins/source/bootimg-efi-isar.py | 307 +++++++++++++++++++++ 2 files changed, 308 insertions(+), 1 deletion(-) create mode 100644 meta-isar/scripts/lib/wic/plugins/source/bootimg-efi-isar.py diff --git a/meta-isar/scripts/lib/wic/canned-wks/sdimage-efi.wks b/meta-isar/scripts/lib/wic/canned-wks/sdimage-efi.wks index 1171a26..580ad21 100644 --- a/meta-isar/scripts/lib/wic/canned-wks/sdimage-efi.wks +++ b/meta-isar/scripts/lib/wic/canned-wks/sdimage-efi.wks @@ -2,7 +2,7 @@ # long-description: Creates a partitioned EFI disk image without any swap that # the user can directly dd to boot media. -part /boot --source bootimg-efi --sourceparams="loader=grub-efi" --ondisk sda --label msdos --active --align 1024 +part /boot --source bootimg-efi-isar --sourceparams="loader=grub-efi" --ondisk sda --label msdos --active --align 1024 part / --source rootfs --ondisk sda --fstype=ext4 --label platform --align 1024 --use-uuid diff --git a/meta-isar/scripts/lib/wic/plugins/source/bootimg-efi-isar.py b/meta-isar/scripts/lib/wic/plugins/source/bootimg-efi-isar.py new file mode 100644 index 0000000..68ff67b --- /dev/null +++ b/meta-isar/scripts/lib/wic/plugins/source/bootimg-efi-isar.py @@ -0,0 +1,307 @@ +# 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-efi-isar' source plugin class for 'wic' +# +# AUTHORS +# Tom Zanussi +# + +import logging +import os +import shutil + +from wic import WicError +from wic.engine import get_custom_config +from wic.pluginbase import SourcePlugin +from wic.utils.misc import (exec_cmd, get_bitbake_var, BOOTDD_EXTRA_SPACE) + +logger = logging.getLogger('wic') + +class BootimgEFIPlugin(SourcePlugin): + """ + Create EFI boot partition. + This plugin supports GRUB 2 and systemd-boot bootloaders. + """ + + name = 'bootimg-efi-isar' + + @classmethod + def do_configure_grubefi(cls, creator, cr_workdir): + """ + Create loader-specific (grub-efi) config + """ + configfile = creator.ks.bootloader.configfile + custom_cfg = None + if configfile: + custom_cfg = get_custom_config(configfile) + if custom_cfg: + # Use a custom configuration for grub + grubefi_conf = custom_cfg + logger.debug("Using custom configuration file " + "%s for grub.cfg", configfile) + else: + raise WicError("configfile is specified but failed to " + "get it from %s." % configfile) + + if not custom_cfg: + # Create grub configuration using parameters from wks file + bootloader = creator.ks.bootloader + + grubefi_conf = "" + grubefi_conf += "serial --unit=0 --speed=115200 --word=8 --parity=no --stop=1\n" + grubefi_conf += "default=boot\n" + grubefi_conf += "timeout=%s\n" % bootloader.timeout + grubefi_conf += "set root='hd0,gpt2'\n" + grubefi_conf += "menuentry 'boot'{\n" + + kernel_image = get_bitbake_var("KERNEL_IMAGE") + kernel = "/boot/%s" % kernel_image + + grubefi_conf += "linux %s root=/dev/sda2 rootwait %s\n" \ + % (kernel, bootloader.append) + + initrd_image = get_bitbake_var("INITRD_IMAGE") + initrd = "/boot/%s" % initrd_image + + grubefi_conf += "initrd %s\n" % initrd + + grubefi_conf += "}\n" + + logger.debug("Writing grubefi config %s/hdd/boot/EFI/BOOT/grub.cfg", + cr_workdir) + cfg = open("%s/hdd/boot/EFI/BOOT/grub.cfg" % cr_workdir, "w") + cfg.write(grubefi_conf) + cfg.close() + + cfg = open("%s/hdd/boot/EFI/BOOT/grub-mkimage.cfg" % cr_workdir, "w") + mkimage_conf = "set root='hd0,gpt1'\n" + mkimage_conf += "set prefix=($root)/EFI/BOOT\n" + cfg.write(mkimage_conf) + cfg.close() + + @classmethod + def do_configure_systemdboot(cls, hdddir, creator, cr_workdir, source_params): + """ + Create loader-specific systemd-boot/gummiboot config + """ + install_cmd = "install -d %s/loader" % hdddir + exec_cmd(install_cmd) + + install_cmd = "install -d %s/loader/entries" % hdddir + exec_cmd(install_cmd) + + bootloader = creator.ks.bootloader + + loader_conf = "" + loader_conf += "default boot\n" + loader_conf += "timeout %d\n" % bootloader.timeout + + initrd = source_params.get('initrd') + + if initrd: + # obviously we need to have a common common deploy var + bootimg_dir = get_bitbake_var("DEPLOY_DIR_IMAGE") + if not bootimg_dir: + raise WicError("Couldn't find DEPLOY_DIR_IMAGE, exiting") + + cp_cmd = "cp %s/%s %s" % (bootimg_dir, initrd, hdddir) + exec_cmd(cp_cmd, True) + else: + logger.debug("Ignoring missing initrd") + + logger.debug("Writing systemd-boot config " + "%s/hdd/boot/loader/loader.conf", cr_workdir) + cfg = open("%s/hdd/boot/loader/loader.conf" % cr_workdir, "w") + cfg.write(loader_conf) + cfg.close() + + configfile = creator.ks.bootloader.configfile + custom_cfg = None + if configfile: + custom_cfg = get_custom_config(configfile) + if custom_cfg: + # Use a custom configuration for systemd-boot + boot_conf = custom_cfg + logger.debug("Using custom configuration file " + "%s for systemd-boots's boot.conf", configfile) + else: + raise WicError("configfile is specified but failed to " + "get it from %s.", configfile) + + if not custom_cfg: + # Create systemd-boot configuration using parameters from wks file + kernel_name = get_bitbake_var("KERNEL_IMAGE") + kernel = "/%s" % kernel_name + + boot_conf = "" + boot_conf += "title boot\n" + boot_conf += "linux %s\n" % kernel + boot_conf += "options LABEL=Boot root=%s %s\n" % \ + (creator.rootdev, bootloader.append) + + if initrd: + boot_conf += "initrd /%s\n" % initrd + + logger.debug("Writing systemd-boot config " + "%s/hdd/boot/loader/entries/boot.conf", cr_workdir) + cfg = open("%s/hdd/boot/loader/entries/boot.conf" % cr_workdir, "w") + cfg.write(boot_conf) + cfg.close() + + + @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 loader-specific config + """ + hdddir = "%s/hdd/boot" % cr_workdir + + install_cmd = "install -d %s/EFI/BOOT" % hdddir + exec_cmd(install_cmd) + + try: + if source_params['loader'] == 'grub-efi': + cls.do_configure_grubefi(creator, cr_workdir) + elif source_params['loader'] == 'systemd-boot': + cls.do_configure_systemdboot(hdddir, creator, cr_workdir, source_params) + else: + raise WicError("unrecognized bootimg-efi-isar loader: %s" % source_params['loader']) + except KeyError: + raise WicError("bootimg-efi-isar requires a loader, none specified") + + + @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 an EFI (grub) boot partition. + """ + if not kernel_dir: + kernel_dir = get_bitbake_var("DEPLOY_DIR_IMAGE") + if not kernel_dir: + raise WicError("Couldn't find DEPLOY_DIR_IMAGE, exiting") + + staging_kernel_dir = kernel_dir + + hdddir = "%s/hdd/boot" % cr_workdir + + kernel_name = get_bitbake_var("KERNEL_IMAGE") + install_cmd = "install -m 0644 %s/%s %s/%s" % \ + (staging_kernel_dir, kernel_name, hdddir, kernel_name) + exec_cmd(install_cmd) + + + try: + if source_params['loader'] == 'grub-efi': + shutil.copyfile("%s/hdd/boot/EFI/BOOT/grub.cfg" % cr_workdir, + "%s/grub.cfg" % cr_workdir) + shutil.copyfile("%s/hdd/boot/EFI/BOOT/grub-mkimage.cfg" % cr_workdir, + "%s/grub-mkimage.cfg" % cr_workdir) + for mod in [x for x in os.listdir(kernel_dir) if x.startswith("grub-efi-")]: + cp_cmd = "cp %s/%s %s/EFI/BOOT/%s" % (kernel_dir, mod, hdddir, mod[9:]) + exec_cmd(cp_cmd, True) + shutil.move("%s/grub.cfg" % cr_workdir, + "%s/hdd/boot/EFI/BOOT/grub.cfg" % cr_workdir) + + distro_arch = get_bitbake_var("DISTRO_ARCH") + if not distro_arch: + raise WicError("Couldn't find target architecture") + + if distro_arch == "amd64": + grub_target = 'x86_64-efi' + grub_image = "bootx64.efi" + elif distro_arch == "i386": + grub_target = 'i386-efi' + grub_image = "bootia32.efi" + else: + raise WicError("grub-efi is incompatible with target %s" % + distro_arch) + + bootimg_dir = "%s/hdd/boot" % cr_workdir + if not os.path.isfile("%s/EFI/BOOT/%s" \ + % (bootimg_dir, grub_image)): + + # TODO: check that grub-mkimage is available + grub_cmd = "grub-mkimage -p /EFI/BOOT " + grub_cmd += "-c %s/grub-mkimage.cfg " % cr_workdir + grub_cmd += "-O %s -o %s/EFI/BOOT/%s " \ + % (grub_target, bootimg_dir, grub_image) + grub_cmd += "part_gpt part_msdos ntfs ntfscomp fat ext2 " + grub_cmd += "normal chain boot configfile linux multiboot " + grub_cmd += "search efi_gop efi_uga font gfxterm gfxmenu " + grub_cmd += "terminal minicmd test iorw loadenv echo help " + grub_cmd += "reboot serial terminfo iso9660 loopback tar " + grub_cmd += "memdisk ls search_fs_uuid udf btrfs xfs lvm " + grub_cmd += "reiserfs ata " + exec_cmd(grub_cmd) + elif source_params['loader'] == 'systemd-boot': + for mod in [x for x in os.listdir(kernel_dir) if x.startswith("systemd-")]: + cp_cmd = "cp %s/%s %s/EFI/BOOT/%s" % (kernel_dir, mod, hdddir, mod[8:]) + exec_cmd(cp_cmd, True) + else: + raise WicError("unrecognized bootimg-efi-isar loader: %s" % + source_params['loader']) + except KeyError: + raise WicError("bootimg-efi-isar requires a loader, none specified") + + startup = os.path.join(kernel_dir, "startup.nsh") + if os.path.exists(startup): + cp_cmd = "cp %s %s/" % (startup, hdddir) + exec_cmd(cp_cmd, True) + + 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 efi -C %s %d" % (bootimg, blocks) + exec_cmd(dosfs_cmd) + + mcopy_cmd = "env MTOOLS_SKIP_CHECK=1 mcopy -i %s -s %s/* ::/" % \ + (bootimg, hdddir) + exec_cmd(mcopy_cmd, True) + + 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.13.6