public inbox for isar-users@googlegroups.com
 help / color / mirror / Atom feed
From: Jan Kiszka <jan.kiszka@siemens.com>
To: isar-users <isar-users@googlegroups.com>
Cc: Henning Schild <henning.schild@siemens.com>
Subject: [PATCH 4/7] wic: Add rootfs-u-boot
Date: Mon, 26 Nov 2018 10:38:59 +0100	[thread overview]
Message-ID: <3b1245ea1ffcd8e742014c7ff3c6c946059832e4.1543225142.git.jan.kiszka@siemens.com> (raw)
In-Reply-To: <cover.1543225142.git.jan.kiszka@siemens.com>
In-Reply-To: <cover.1543225142.git.jan.kiszka@siemens.com>

From: Jan Kiszka <jan.kiszka@siemens.com>

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 <jan.kiszka@siemens.com>
---
 .../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


  parent reply	other threads:[~2018-11-26  9:39 UTC|newest]

Thread overview: 13+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2018-11-26  9:38 [PATCH 0/7] u-boot-script rework, the Final One (tm) Jan Kiszka
2018-11-26  9:38 ` [PATCH 1/7] wic: Move isar plugins out of example layer to core Jan Kiszka
2018-11-26  9:38 ` [PATCH 2/7] wic: Remove obsolete reference to msger logger Jan Kiszka
2018-11-26  9:45   ` Henning Schild
2018-11-26  9:50     ` Jan Kiszka
2018-11-26 10:07       ` Henning Schild
2018-11-26 11:02         ` Jan Kiszka
2018-11-26  9:38 ` [PATCH 3/7] meta-isar: Factor out bananapi machine config Jan Kiszka
2018-11-26  9:38 ` Jan Kiszka [this message]
2018-11-26  9:39 ` [PATCH 5/7] meta-isar: Switch bananapi and de0-nano-soc to rootfs-u-boot Jan Kiszka
2018-11-26  9:39 ` [PATCH 6/7] u-boot-script: Make truly generic Jan Kiszka
2018-11-26  9:39 ` [PATCH 7/7] meta: Fold wks-file class into wic-img Jan Kiszka
2018-11-29 12:15 ` [PATCH 0/7] u-boot-script rework, the Final One (tm) Maxim Yu. Osipov

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=3b1245ea1ffcd8e742014c7ff3c6c946059832e4.1543225142.git.jan.kiszka@siemens.com \
    --to=jan.kiszka@siemens.com \
    --cc=henning.schild@siemens.com \
    --cc=isar-users@googlegroups.com \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox