From mboxrd@z Thu Jan 1 00:00:00 1970 X-GM-THRID: 6628101524314652672 X-Received: by 2002:a05:6000:100d:: with SMTP id a13mr2687257wrx.2.1543225144567; Mon, 26 Nov 2018 01:39:04 -0800 (PST) X-BeenThere: isar-users@googlegroups.com Received: by 2002:a1c:c85:: with SMTP id 127ls4522892wmm.14.canary-gmail; Mon, 26 Nov 2018 01:39:04 -0800 (PST) X-Google-Smtp-Source: AJdET5c7cuHr+jps/zwUhev4Xkt5lRmFw0vcBNH4WG12zrSAIR+bOed1yX11nsIMicrIuX64zJ89 X-Received: by 2002:a1c:344f:: with SMTP id b76-v6mr3288470wma.2.1543225144008; Mon, 26 Nov 2018 01:39:04 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1543225143; cv=none; d=google.com; s=arc-20160816; b=feemsZopTph6NSqs9fJL+oCiYOXRqOISbDPak+w7tuhqKKMKid5JN3pNbGiTh652Tq G4aHAhgSs4AoglMdDWY7yAANJhSFjMGcgslGnM/TfJfE0C56GDyw8xgjHTdG0pbyjJtf gr//cU4UhdCKRAk0yKb+m5uQPjH1xUTDRIcLAcBvY96DDspL5kcybXpYzcOBxpUVm71F 0mXCbBvZIRTkDebPEVviHmwZgtZvIRyV8X6IHn24D06HFGnU0W4nKL4LjxBq/jKE0G2l fkmgt/nsk3EKRo4aStZ1CgakqjFRlIn1djFzmUg5eW2wXjD68oPRc6k5cCMFVVobE0uW No3A== 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; bh=Z9GkWU2EKSaeH2XouqsCuc0uwIV6aYBm8de2oyWiejs=; b=wx2LLoAUjNEZV4esYIOfKdc/rU1HBtuPLMPIBve3J7QK4mPR7lrxLX29fi33qiR/HZ wknqKSVaupFLsGuh41DxKRoSzIei7jqHOSrOGEP2oe6NAPR3QSfRx6kqYBpINUOsE7QR hRbJ0hujpqUxcMy9zsxZlSsdS3e9mjq0eCi5g+B7l845hMJq5pei/qlB3OW/eT3rHYR6 PqNaFOtQkfm8j1FEhBKYbnsMJb6FxxMWBNYLhqXfyDctlc9OKEhHQ5o0adPGugXrKEUX TmVCTc360MbjhxsnKmVwAPh3kpncLthxQzwHgj8CK0odR9mNDBq+/hqD2ysMzqBfAz8a Uoyw== ARC-Authentication-Results: i=1; gmr-mx.google.com; spf=pass (google.com: domain of jan.kiszka@siemens.com designates 192.35.17.28 as permitted sender) smtp.mailfrom=jan.kiszka@siemens.com Return-Path: Received: from goliath.siemens.de (goliath.siemens.de. [192.35.17.28]) by gmr-mx.google.com with ESMTPS id x13si846316wrn.3.2018.11.26.01.39.03 for (version=TLS1_2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Mon, 26 Nov 2018 01:39:03 -0800 (PST) Received-SPF: pass (google.com: domain of jan.kiszka@siemens.com designates 192.35.17.28 as permitted sender) client-ip=192.35.17.28; Authentication-Results: gmr-mx.google.com; spf=pass (google.com: domain of jan.kiszka@siemens.com designates 192.35.17.28 as permitted sender) smtp.mailfrom=jan.kiszka@siemens.com Received: from mail2.sbs.de (mail2.sbs.de [192.129.41.66]) by goliath.siemens.de (8.15.2/8.15.2) with ESMTPS id wAQ9d3WM010682 (version=TLSv1.2 cipher=DHE-RSA-AES256-GCM-SHA384 bits=256 verify=OK) for ; Mon, 26 Nov 2018 10:39:03 +0100 Received: from md1f2u6c.ad001.siemens.net ([139.23.79.230]) by mail2.sbs.de (8.15.2/8.15.2) with ESMTP id wAQ9d2uw012310; Mon, 26 Nov 2018 10:39:03 +0100 From: Jan Kiszka To: isar-users Cc: Henning Schild Subject: [PATCH 4/7] wic: Add rootfs-u-boot Date: Mon, 26 Nov 2018 10:38:59 +0100 Message-Id: <3b1245ea1ffcd8e742014c7ff3c6c946059832e4.1543225142.git.jan.kiszka@siemens.com> X-Mailer: git-send-email 2.16.4 In-Reply-To: References: In-Reply-To: References: X-TUID: y/AbXMuiDF7V From: Jan Kiszka This implements the translation of the target wks into an U-Boot script file as wic plugin. It allows to remove any image or kernel specifics from the u-boot-script package. And then, in turn, permits to make wks files image-specific again, just like in OE. As u-boot-script is already installed on the target, we chroot into that rootfs in order to run update-u-boot-script in-place. In cross-arch scenarios, we just need to restore qemu-*-static temporarily for this because do_rootfs already cleaned it up. The plugin allows to inject the SCRIPT_PREPEND and NO_INITRD parameters via --sourceparams, which also obsoletes the need to carry /etc/default/ u-boot-script in customization packages. Signed-off-by: Jan Kiszka --- .../lib/wic/plugins/source/rootfs-u-boot.py | 91 ++++++++++++++++++++++ 1 file changed, 91 insertions(+) create mode 100644 meta/scripts/lib/wic/plugins/source/rootfs-u-boot.py diff --git a/meta/scripts/lib/wic/plugins/source/rootfs-u-boot.py b/meta/scripts/lib/wic/plugins/source/rootfs-u-boot.py new file mode 100644 index 0000000..0c7710e --- /dev/null +++ b/meta/scripts/lib/wic/plugins/source/rootfs-u-boot.py @@ -0,0 +1,91 @@ +# +# Copyright (c) Siemens AG, 2018 +# +# SPDX-License-Identifier: MIT +# +# DESCRIPTION +# This implements the 'rootfs-u-boot' source plugin class for 'wic'. +# It performs the same tasks as the 'rootfs' plugin and additionally configures +# u-boot-script to boot this rootfs. +# Recognized sourceparams: +# - no_initrd=yes (disables initrd loading) +# - script_prepend=cmd;... (prepends U-Boot command) + +import glob +import logging +import os + +from wic import WicError +from wic.plugins.source.rootfs import RootfsPlugin +from wic.utils.misc import exec_cmd + +logger = logging.getLogger('wic') + +class RootfsUBootPlugin(RootfsPlugin): + """ + Populate partition content from a rootfs directory and set up + /etc/default/u-boot-script. + """ + + name = 'rootfs-u-boot' + + @classmethod + def do_prepare_partition(cls, part, source_params, cr, cr_workdir, + oe_builddir, bootimg_dir, kernel_dir, + krootfs_dir, native_sysroot): + # Prologue from RootfsPlugin.do_prepare_partition, retrieves the + # rootfs directory + if part.rootfs_dir is None: + if not 'ROOTFS_DIR' in krootfs_dir: + raise WicError("Couldn't find --rootfs-dir, exiting") + + rootfs_dir = krootfs_dir['ROOTFS_DIR'] + else: + if part.rootfs_dir in krootfs_dir: + rootfs_dir = krootfs_dir[part.rootfs_dir] + elif part.rootfs_dir: + rootfs_dir = part.rootfs_dir + else: + raise WicError("Couldn't find --rootfs-dir=%s connection or " + "it is not a valid path, exiting" % part.rootfs_dir) + if os.path.isdir(rootfs_dir): + real_rootfs_dir = rootfs_dir + else: + image_rootfs_dir = get_bitbake_var("IMAGE_ROOTFS", rootfs_dir) + if not os.path.isdir(image_rootfs_dir): + raise WicError("No valid artifact IMAGE_ROOTFS from image " + "named %s has been found at %s, exiting." % + (rootfs_dir, image_rootfs_dir)) + real_rootfs_dir = image_rootfs_dir + + u_boot_script = os.path.join(real_rootfs_dir, + "etc/default/u-boot-script") + if not os.path.exists(u_boot_script): + raise WicError("u-boot-scripts package not installed") + + # Write new /etc/default/u-boot-script + with open(u_boot_script, 'w') as cfg: + cfg.write('# Generated by wic, rootfs-u-boot plugin\n') + cfg.write('ROOT_PARTITION="%d"\n' % part.realnum) + cfg.write('KERNEL_ARGS="root=%s %s"\n' % \ + (cr.rootdev, cr.ks.bootloader.append)) + no_initrd = source_params.get('no_initrd') or '' + cfg.write('NO_INITRD="%s"\n' % no_initrd) + script_prepend = source_params.get('script_prepend') or '' + cfg.write('SCRIPT_PREPEND="%s"\n' % script_prepend) + + # Run update-u-boot-script in the target rootfs + results = glob.glob(os.path.join("/usr/bin/qemu-*-static")) + qemu_static = results[0] if len(results) > 0 else None + if qemu_static: + cp_cmd = "cp -L %s %s/usr/bin" % (qemu_static, real_rootfs_dir) + exec_cmd(cp_cmd) + update_cmd = "chroot %s sh -c update-u-boot-script" % real_rootfs_dir + exec_cmd(update_cmd) + if qemu_static: + rm_cmd = "rm -f %s/usr/bin/%s" % (real_rootfs_dir, qemu_static) + exec_cmd(rm_cmd) + + RootfsPlugin.do_prepare_partition(part, source_params, cr, cr_workdir, + oe_builddir, bootimg_dir, kernel_dir, + krootfs_dir, native_sysroot) -- 2.16.4