From ae7af6f87782fc0f57fb9f74153465e8a7ea02ea Mon Sep 17 00:00:00 2001 From: Otavio Salvador Date: Wed, 14 Dec 2022 15:15:26 -0300 Subject: classes/image_populate_mfgtool: init The class provides the infrastructure for MFGTOOL generation and is tied to images. To generate the bundle, the task populate_mfgtool must be called. For example: ,----[ Running populate_mfgtool for core-image-minimal image ] | $: bitbake core-image-minimal -c populate_mfgtool `---- The class behavior is controlled through the MFGTOOLCONFIG (analogous to PACKAGECONFIG) variable. The MFGTOOLCONFIG variable itself specifies a space-separated list of the script to enable. Following the script, you can determine the behavior of each script by providing up to two order-dependent arguments, which are separated by commas. You can omit any argument you like but must retain the separating commas. The order is important and specifies the following: 1. Extra dependencies that should be added to the do_populate_mfgtool task, if the script is enabled. 2. Extra binaries that should be added to the bundle, if the script is enabled. For example: ,----[ Defining foo.uuu.in and bar.uuu script ] | MFGTOOLCONFIG = "foo.uuu.in bar.uuu" | MFGTOOLCONFIG[foo.uuu.in] = "dep-foo1:do_deploy dep-foo2:do_deploy,file-foo1" | MFGTOOLCONFIG[bar.uuu] = "dep-bar1:do_deploy,file-bar1 file-bar2" `---- The dep-foo1:do_deploy, dep-foo2:do_deploy, and dep-bar1:do_deploy are added to do_populate_mfgtool dependencies. In addition, file-foo1, file-bar1, and file-bar2 are copied to the bundle, only if the script is enabled. During the mfgtool bundle generation, the uuu.in files are processed and some variables replaced. The variables are: - MACHINE - UBOOT_BINARY - SPL_BINARY - IMAGE_BASENAME Signed-off-by: Otavio Salvador --- classes/image_populate_mfgtool.bbclass | 139 +++++++++++++++++++++++++++++++++ conf/machine/include/imx-base.inc | 3 + 2 files changed, 142 insertions(+) create mode 100644 classes/image_populate_mfgtool.bbclass diff --git a/classes/image_populate_mfgtool.bbclass b/classes/image_populate_mfgtool.bbclass new file mode 100644 index 00000000..90226e35 --- /dev/null +++ b/classes/image_populate_mfgtool.bbclass @@ -0,0 +1,139 @@ +# Allow generation of mfgtool bundle +# +# The class provides the infrastructure for MFGTOOL generation and is tied to images. To generate +# the bundle, the task populate_mfgtool must be called. For example: +# +# ,----[ Running populate_mfgtool for core-image-minimal image ] +# | $: bitbake core-image-minimal -c populate_mfgtool +# `---- +# +# The class behavior is controlled through the MFGTOOLCONFIG (analogous to PACKAGECONFIG) +# variable. The MFGTOOLCONFIG variable itself specifies a space-separated list of the script to +# enable. Following the script, you can determine the behavior of each script by providing up to two +# order-dependent arguments, which are separated by commas. You can omit any argument you like but +# must retain the separating commas. The order is important and specifies the following: +# +# 1. Extra dependencies that should be added to the do_populate_mfgtool task, if the script is +# enabled. +# 2. Extra binaries that should be added to the bundle, if the script is enabled. +# +# For example: +# +# ,----[ Defining foo.uuu.in and bar.uuu script ] +# | MFGTOOLCONFIG = "foo.uuu.in bar.uuu" +# | MFGTOOLCONFIG[foo.uuu.in] = "dep-foo1:do_deploy dep-foo2:do_deploy,file-foo1" +# | MFGTOOLCONFIG[bar.uuu] = "dep-bar1:do_deploy,file-bar1 file-bar2" +# `---- +# +# The dep-foo1:do_deploy, dep-foo2:do_deploy, and dep-bar1:do_deploy are added to +# do_populate_mfgtool dependencies. In addition, file-foo1, file-bar1, and file-bar2 are copied to +# the bundle, only if the script is enabled. +# +# During the mfgtool bundle generation, the uuu.in files are processed and some variables +# replaced. The variables are: +# +# - MACHINE +# - UBOOT_BINARY +# - SPL_BINARY +# - IMAGE_BASENAME +# +# Copyright 2022-2023 (C) O.S. Systems Software LTDA. +# +# SPDX-License-Identifier: MIT + +MFGTOOL_FILESPATH ??= " \ + ${@base_set_filespath(["%s/mfgtool" % p for p in "${BBPATH}".split(":")] \ + + ["${FILE_DIRNAME}/${BP}/mfgtool", \ + "${FILE_DIRNAME}/${BPN}/mfgtool", \ + "${FILE_DIRNAME}/files/mfgtool"] \ + , d)} \ +" + +MFGTOOLDIR = "${WORKDIR}/mfgtool-${PN}" +do_populate_mfgtool[dirs] = "${MFGTOOLDIR}" +do_populate_mfgtool[cleandirs] = "${MFGTOOLDIR}" + +addtask populate_mfgtool after do_image_complete do_unpack before do_deploy +do_populate_mfgtool[dirs] ?= "${DEPLOY_DIR_IMAGE} ${WORKDIR}" +do_populate_mfgtool[nostamp] = "1" +do_populate_mfgtool[recrdeptask] += "do_deploy" +do_populate_mfgtool[depends] += "uuu-bin:do_populate_sysroot" + +python () { + depends = [] + deploy_files = [] + scripts = (d.getVar('MFGTOOLCONFIG') or "").split() + scripts_and_flags = d.getVarFlags('MFGTOOLCONFIG') or {} + for flag, flagval in sorted(scripts_and_flags.items()): + items = flagval.split(",") + num = len(items) + if num > 2: + bb.error("%s: MFGTOOLCONFIG[%s] Only \"depends,deploy files\" can be specified!" % (d.getVar("PN"), flag)) + + if flag in scripts: + if num >= 2 and items[1]: + deploy_files.append(items[1]) + if num >= 1 and items[0]: + depends.append(items[0]) + + d.appendVarFlag('do_populate_mfgtool', 'depends', ' ' + ' '.join(depends)) + d.setVar('_SCRIPT_DEPLOY_FILES', ' '.join(deploy_files)) +} + +python do_populate_mfgtool() { + # For MFGTOOLCONFIG items we use BitBake's fetcher module allowing a consistent behavior. + scripts = (d.getVar('MFGTOOLCONFIG') or "").split() + src_uri = ["file://%s" % f for f in scripts] + if not src_uri: + bb.fatal("MFGTOOLCONFIG is empty so populate_mfgtool cannot be run.") + return + bb.debug(1, "following scripts are used: %s" % ', '.join(scripts)) + + localdata = bb.data.createCopy(d) + filespath = (d.getVar('MFGTOOL_FILESPATH') or "") + localdata.setVar('FILESPATH', filespath) + + try: + fetcher = bb.fetch2.Fetch(src_uri, localdata) + fetcher.unpack(localdata.getVar('WORKDIR')) + except bb.fetch2.BBFetchException as e: + bb.fatal("BitBake Fetcher Error: " + repr(e)) + + # Generate MFGTOOL bundle. + bb.build.exec_func('generate_mfgtool_bundle', d) +} + +generate_mfgtool_bundle() { + bbnote "Processing uuu files ..." + for src in $(ls -1 ${WORKDIR}/*.uuu.in); do + dest=$(echo $src | sed 's,.in$,,g') + bbnote " - $src -> $dest" + sed -e 's/@@MACHINE@@/${MACHINE}/g' \ + -e "s,@@UBOOT_BINARY@@,${UBOOT_BINARY},g" \ + -e "s,@@SPL_BINARY@@,${SPL_BINARY},g" \ + -e "s,@@IMAGE_BASENAME@@,${IMAGE_BASENAME},g" \ + $src > $dest + done + + bbnote "Deploying uuu files ..." + for src in $(ls -1 ${WORKDIR}/*.uuu); do + dest=$(basename $src) + bbnote " - $src -> ${MFGTOOLDIR}/${PN}-${MACHINE}/$dest" + install -D -m 0644 $src ${MFGTOOLDIR}/${PN}-${MACHINE}/$dest + done + + bbnote "Copying uuu binaries..." + cp -v -s ${STAGING_LIBDIR}/uuu/* ${MFGTOOLDIR}/${PN}-${MACHINE}/ + + bbnote "Copying MFGTOOL extra deploy files..." + for f in ${_SCRIPT_DEPLOY_FILES}; do + mkdir -p ${MFGTOOLDIR}/${PN}-${MACHINE}/binaries + cp -v -s ${DEPLOY_DIR_IMAGE}/$f ${MFGTOOLDIR}/${PN}-${MACHINE}/binaries/ + done + + tar -czf ${DEPLOY_DIR_IMAGE}/mfgtool-bundle-${PN}-${MACHINE}.tar.gz \ + --dereference -C ${MFGTOOLDIR} ${PN}-${MACHINE} + + ln -fs mfgtool-bundle-${PN}-${MACHINE}.tar.gz \ + ${DEPLOY_DIR_IMAGE}/mfgtool-bundle-${PN}.tar.gz +} diff --git a/conf/machine/include/imx-base.inc b/conf/machine/include/imx-base.inc index 37e67dea..7ff2741d 100644 --- a/conf/machine/include/imx-base.inc +++ b/conf/machine/include/imx-base.inc @@ -614,5 +614,8 @@ MACHINE_FEATURES = "usbgadget usbhost vfat alsa touchscreen" HOSTTOOLS_NONFATAL:append:mx8-nxp-bsp = " sha384sum" +# Add task to generate the mfgtool bundle for the image. +IMAGE_CLASSES:append:imx-generic-bsp = " image_populate_mfgtool" + # Allow meta-imx to add NIP devices information until upstreamed. include conf/machine/include/imx-base-extend.inc -- cgit v1.2.3-54-g00ecf