public inbox for isar-users@googlegroups.com
 help / color / mirror / Atom feed
From: Ulrich Teichert <ulrich.teichert@kumkeo.de>
To: Jan Kiszka <jan.kiszka@siemens.com>,
	"isar-users@googlegroups.com" <isar-users@googlegroups.com>
Subject: AW: Re: wic plugins, any documentation?
Date: Wed, 8 Jan 2025 07:46:17 +0000	[thread overview]
Message-ID: <fbec2c09dd134f8484820974e4de2db9@kumkeo.de> (raw)
In-Reply-To: <601d6d45-c47f-47e3-acad-28547eb7413e@siemens.com>

Hi Jan,

>> I'm trying to write a wic plugin to generate a bootable partition for a Xilinix zynqmp
>> board. I've managed building the necessary infrastructure (bootgen) and have the
>> contents available for the python script. As far as I can tell all gets assembled correctly,
>> but it doesn't show up in the FAT partition (mounted as /boot on the target).

>Hmm, I created images for zynqmp before but didn't need that back then:
>
>https://github.com/siemens/jailhouse-images/blob/master/wic/ultra96.wks
>
>What does your plugin have to do differently?

Perhaps it got too complicated - it's my first dip into wic:

part /boot --source bootgen-partition --sourceparams "fsbl=/usr/lib/boot-firmware/fsbl_a53.elf,pmu=/usr/lib/boot-firmware/pmufw.elf,armtfw=/usr/lib/arm-trusted-firmware/zynqmp/bl31.elf,uboot_dir=/usr/lib/boot-firmware/u-boot" --ondisk mmcblk0 --fstype=vfat --label boot --active --align 4096 --size 100M

part / --source rootfs --ondisk mmcblk0 --fstype=ext4 --mkfs-extraopts "-T default" --label root --align 4096 --exclude-path=boot --size 1G

bootloader

In the python script the extra source params are used to generate a BOOT.bin:

import logging
import os
import types

from importlib.machinery import SourceFileLoader
from wic import WicError
from wic.plugins.source.rootfs import RootfsPlugin
from wic.misc import get_bitbake_var, exec_cmd

logger = logging.getLogger('wic')

class BootgenPlugin(RootfsPlugin):
    """
    Create a boot.bin with bootgen, contents are at least the FSBL,
    the PMU and an U-BOOT FIT image on a FAT partition.
    """

    name = 'bootgen-partition'

    @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.
        """
        logger.debug("bootgen-partition: do_prepare_partition: part: %s", part)

        # check for options which have to be set
        if source_params.get('fsbl', None) is None:
            raise WicError("bootgen-partition: fsbl source_param must be set.")
        if source_params.get('pmu', None) is None:
            raise WicError("bootgen-partition: pmu source_param must be set.")
        if source_params.get('armtfw', None) is None:
            raise WicError("bootgen-partition: armtfw source_param must be set.")
        if source_params.get('uboot_dir', None) is None:
            raise WicError("bootgen-partition: uboot_dir source_param must be set.")

        # Prologue from RootfsPlugin.do_prepare_partition, retrieves the
        # rootfs directory
        if part.rootfs_dir is None:
            if not 'ROOTFS_DIR' in rootfs_dir:
                raise WicError("Couldn't find --rootfs-dir, exiting")

            rootfs_dir = rootfs_dir['ROOTFS_DIR']
        else:
            if part.rootfs_dir in rootfs_dir:
                rootfs_dir = rootfs_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

        root_dev = creator.rootdev
        if not root_dev:
            root_dev = source_params.get("root", None)
            if not root_dev:
                raise WicError("root not defined, exiting.")
            root_dev = root_dev.replace(":", "=")

        logger.warn("bootgen: root dev: %s, root fs: %s, build in %s, bootimg_dir: %s", root_dev, real_rootfs_dir, cr_workdir, bootimg_dir)
        # copy all parts
        cp_cmd = "cp -a %s%s %s" % (real_rootfs_dir, source_params.get('fsbl'), cr_workdir)
        exec_cmd(cp_cmd)
        cp_cmd = "cp -a %s%s %s" % (real_rootfs_dir, source_params.get('pmu'), cr_workdir)
        exec_cmd(cp_cmd)
        cp_cmd = "cp -a %s%s %s" % (real_rootfs_dir, source_params.get('armtfw'), cr_workdir)
        exec_cmd(cp_cmd)
        cp_cmd = "cp -a %s%s/u-boot.elf %s" % (real_rootfs_dir, source_params.get('uboot_dir'), cr_workdir)
        exec_cmd(cp_cmd)
        cp_cmd = "cp -a %s%s/uboot-env.txt %s" % (real_rootfs_dir, source_params.get('uboot_dir'), cr_workdir)
        exec_cmd(cp_cmd)
        cp_cmd = "cp -a %s%s/boot.bif %s" % (real_rootfs_dir, source_params.get('uboot_dir'), cr_workdir)
        exec_cmd(cp_cmd)
        bootgen_cmd = "cd %s && bootgen -arch zynqmp -image boot.bif -o BOOT.bin" % (cr_workdir)
        exec_cmd(bootgen_cmd, True)
        # we need to create the VFAT image
        bootimg = "%s/boot.img" % cr_workdir
        label = part.label if part.label else "boot"
        dosfs_cmd = "mkfs.fat -n %s -i %s -C %s %d" % \
                    (label, part.fsuuid, bootimg, part.size)
        exec_cmd(dosfs_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


>> Is there a documentation available for wic plugins which I've missed? If not, would it
>> be a mistake for my plugin to derive from the RootfsPlugin? In which way the plugin
>> controls where the content ends up in the target partition?

>We are taking wic from upstream OE, and I'm not aware of any generated
>doc from what wic has inline. But you could browse it, e.g. here:
>
>https://github.com/ilbers/isar/blob/master/scripts/lib/wic/pluginbase.py

Yes, I have seen that, but this only talks about the plugin entry points which are called
but not about where the output of the plugin is expected. Perhaps I am missing
something essential here....

TIA,
Uli

Schöne Grüße / Kind regards


Dipl.-Inform. Ulrich Teichert
Senior Software Developer



Phone +49 431 375938-0
_____________________________________

e.bs kumkeo GmbH


-- 
You received this message because you are subscribed to the Google Groups "isar-users" group.
To unsubscribe from this group and stop receiving emails from it, send an email to isar-users+unsubscribe@googlegroups.com.
To view this discussion visit https://groups.google.com/d/msgid/isar-users/fbec2c09dd134f8484820974e4de2db9%40kumkeo.de.

      reply	other threads:[~2025-01-08  7:46 UTC|newest]

Thread overview: 3+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2025-01-07 15:57 Ulrich Teichert
2025-01-07 17:03 ` 'Jan Kiszka' via isar-users
2025-01-08  7:46   ` Ulrich Teichert [this message]

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=fbec2c09dd134f8484820974e4de2db9@kumkeo.de \
    --to=ulrich.teichert@kumkeo.de \
    --cc=isar-users@googlegroups.com \
    --cc=jan.kiszka@siemens.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