summaryrefslogtreecommitdiffstats
path: root/classes
diff options
context:
space:
mode:
authorOtavio Salvador <otavio@ossystems.com.br>2022-12-14 15:15:26 -0300
committerOtavio Salvador <otavio@ossystems.com.br>2023-04-12 17:12:18 -0300
commitae7af6f87782fc0f57fb9f74153465e8a7ea02ea (patch)
treefef362ae819d92cffb2b2b6ce6ffcbc3a466bcef /classes
parent039b28e30420671fdd932e0a8b6ec355b07cec7c (diff)
downloadmeta-freescale-ae7af6f87782fc0f57fb9f74153465e8a7ea02ea.tar.gz
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 <otavio@ossystems.com.br>
Diffstat (limited to 'classes')
-rw-r--r--classes/image_populate_mfgtool.bbclass139
1 files changed, 139 insertions, 0 deletions
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 @@
1# Allow generation of mfgtool bundle
2#
3# The class provides the infrastructure for MFGTOOL generation and is tied to images. To generate
4# the bundle, the task populate_mfgtool must be called. For example:
5#
6# ,----[ Running populate_mfgtool for core-image-minimal image ]
7# | $: bitbake core-image-minimal -c populate_mfgtool
8# `----
9#
10# The class behavior is controlled through the MFGTOOLCONFIG (analogous to PACKAGECONFIG)
11# variable. The MFGTOOLCONFIG variable itself specifies a space-separated list of the script to
12# enable. Following the script, you can determine the behavior of each script by providing up to two
13# order-dependent arguments, which are separated by commas. You can omit any argument you like but
14# must retain the separating commas. The order is important and specifies the following:
15#
16# 1. Extra dependencies that should be added to the do_populate_mfgtool task, if the script is
17# enabled.
18# 2. Extra binaries that should be added to the bundle, if the script is enabled.
19#
20# For example:
21#
22# ,----[ Defining foo.uuu.in and bar.uuu script ]
23# | MFGTOOLCONFIG = "foo.uuu.in bar.uuu"
24# | MFGTOOLCONFIG[foo.uuu.in] = "dep-foo1:do_deploy dep-foo2:do_deploy,file-foo1"
25# | MFGTOOLCONFIG[bar.uuu] = "dep-bar1:do_deploy,file-bar1 file-bar2"
26# `----
27#
28# The dep-foo1:do_deploy, dep-foo2:do_deploy, and dep-bar1:do_deploy are added to
29# do_populate_mfgtool dependencies. In addition, file-foo1, file-bar1, and file-bar2 are copied to
30# the bundle, only if the script is enabled.
31#
32# During the mfgtool bundle generation, the uuu.in files are processed and some variables
33# replaced. The variables are:
34#
35# - MACHINE
36# - UBOOT_BINARY
37# - SPL_BINARY
38# - IMAGE_BASENAME
39#
40# Copyright 2022-2023 (C) O.S. Systems Software LTDA.
41#
42# SPDX-License-Identifier: MIT
43
44MFGTOOL_FILESPATH ??= " \
45 ${@base_set_filespath(["%s/mfgtool" % p for p in "${BBPATH}".split(":")] \
46 + ["${FILE_DIRNAME}/${BP}/mfgtool", \
47 "${FILE_DIRNAME}/${BPN}/mfgtool", \
48 "${FILE_DIRNAME}/files/mfgtool"] \
49 , d)} \
50"
51
52MFGTOOLDIR = "${WORKDIR}/mfgtool-${PN}"
53do_populate_mfgtool[dirs] = "${MFGTOOLDIR}"
54do_populate_mfgtool[cleandirs] = "${MFGTOOLDIR}"
55
56addtask populate_mfgtool after do_image_complete do_unpack before do_deploy
57do_populate_mfgtool[dirs] ?= "${DEPLOY_DIR_IMAGE} ${WORKDIR}"
58do_populate_mfgtool[nostamp] = "1"
59do_populate_mfgtool[recrdeptask] += "do_deploy"
60do_populate_mfgtool[depends] += "uuu-bin:do_populate_sysroot"
61
62python () {
63 depends = []
64 deploy_files = []
65 scripts = (d.getVar('MFGTOOLCONFIG') or "").split()
66 scripts_and_flags = d.getVarFlags('MFGTOOLCONFIG') or {}
67 for flag, flagval in sorted(scripts_and_flags.items()):
68 items = flagval.split(",")
69 num = len(items)
70 if num > 2:
71 bb.error("%s: MFGTOOLCONFIG[%s] Only \"depends,deploy files\" can be specified!" % (d.getVar("PN"), flag))
72
73 if flag in scripts:
74 if num >= 2 and items[1]:
75 deploy_files.append(items[1])
76 if num >= 1 and items[0]:
77 depends.append(items[0])
78
79 d.appendVarFlag('do_populate_mfgtool', 'depends', ' ' + ' '.join(depends))
80 d.setVar('_SCRIPT_DEPLOY_FILES', ' '.join(deploy_files))
81}
82
83python do_populate_mfgtool() {
84 # For MFGTOOLCONFIG items we use BitBake's fetcher module allowing a consistent behavior.
85 scripts = (d.getVar('MFGTOOLCONFIG') or "").split()
86 src_uri = ["file://%s" % f for f in scripts]
87 if not src_uri:
88 bb.fatal("MFGTOOLCONFIG is empty so populate_mfgtool cannot be run.")
89 return
90 bb.debug(1, "following scripts are used: %s" % ', '.join(scripts))
91
92 localdata = bb.data.createCopy(d)
93 filespath = (d.getVar('MFGTOOL_FILESPATH') or "")
94 localdata.setVar('FILESPATH', filespath)
95
96 try:
97 fetcher = bb.fetch2.Fetch(src_uri, localdata)
98 fetcher.unpack(localdata.getVar('WORKDIR'))
99 except bb.fetch2.BBFetchException as e:
100 bb.fatal("BitBake Fetcher Error: " + repr(e))
101
102 # Generate MFGTOOL bundle.
103 bb.build.exec_func('generate_mfgtool_bundle', d)
104}
105
106generate_mfgtool_bundle() {
107 bbnote "Processing uuu files ..."
108 for src in $(ls -1 ${WORKDIR}/*.uuu.in); do
109 dest=$(echo $src | sed 's,.in$,,g')
110 bbnote " - $src -> $dest"
111 sed -e 's/@@MACHINE@@/${MACHINE}/g' \
112 -e "s,@@UBOOT_BINARY@@,${UBOOT_BINARY},g" \
113 -e "s,@@SPL_BINARY@@,${SPL_BINARY},g" \
114 -e "s,@@IMAGE_BASENAME@@,${IMAGE_BASENAME},g" \
115 $src > $dest
116 done
117
118 bbnote "Deploying uuu files ..."
119 for src in $(ls -1 ${WORKDIR}/*.uuu); do
120 dest=$(basename $src)
121 bbnote " - $src -> ${MFGTOOLDIR}/${PN}-${MACHINE}/$dest"
122 install -D -m 0644 $src ${MFGTOOLDIR}/${PN}-${MACHINE}/$dest
123 done
124
125 bbnote "Copying uuu binaries..."
126 cp -v -s ${STAGING_LIBDIR}/uuu/* ${MFGTOOLDIR}/${PN}-${MACHINE}/
127
128 bbnote "Copying MFGTOOL extra deploy files..."
129 for f in ${_SCRIPT_DEPLOY_FILES}; do
130 mkdir -p ${MFGTOOLDIR}/${PN}-${MACHINE}/binaries
131 cp -v -s ${DEPLOY_DIR_IMAGE}/$f ${MFGTOOLDIR}/${PN}-${MACHINE}/binaries/
132 done
133
134 tar -czf ${DEPLOY_DIR_IMAGE}/mfgtool-bundle-${PN}-${MACHINE}.tar.gz \
135 --dereference -C ${MFGTOOLDIR} ${PN}-${MACHINE}
136
137 ln -fs mfgtool-bundle-${PN}-${MACHINE}.tar.gz \
138 ${DEPLOY_DIR_IMAGE}/mfgtool-bundle-${PN}.tar.gz
139}