summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorAdrian Freihofer <adrian.freihofer@siemens.com>2025-06-03 10:23:31 +0200
committerRichard Purdie <richard.purdie@linuxfoundation.org>2025-06-05 11:02:22 +0100
commit1d8c78c8cd68f77ff509c053f0608eb4391c0121 (patch)
tree8f5d99aca0c6e74ffff83b3f2a1160630b1f9f26
parent18861ef0eb23d4f8823955a6bff5d3fe89e191b6 (diff)
downloadpoky-1d8c78c8cd68f77ff509c053f0608eb4391c0121.tar.gz
kernel-fitimage.bbclass: remove it
The integration of the FIT image-related build steps into the kernel recipe has proven to be not very good. The new implementation with kernel-fit-image.bbclass fixes some design issues: * sstate does not work well when a fitImage contains an initramfs. The kernel is rebuilt from scratch if the build runs from an empty TMPDIR. * A fitImage kernel is not available as a package, but all other kernel image types are. * The task dependencies in the kernel are very complex and difficult to debug if something goes wrong. As a separate, downstream recipe, this is now much easier. The long storry about this issue is here: [YOCTO #12912] (From OE-Core rev: deb6bc3bea30dadabdb580a7a58a3b2e277af400) Signed-off-by: Adrian Freihofer <adrian.freihofer@siemens.com> Signed-off-by: Richard Purdie <richard.purdie@linuxfoundation.org>
-rw-r--r--meta/classes-recipe/kernel-fitimage.bbclass289
-rw-r--r--meta/classes-recipe/kernel-uboot.bbclass45
2 files changed, 0 insertions, 334 deletions
diff --git a/meta/classes-recipe/kernel-fitimage.bbclass b/meta/classes-recipe/kernel-fitimage.bbclass
deleted file mode 100644
index a253b210ef..0000000000
--- a/meta/classes-recipe/kernel-fitimage.bbclass
+++ /dev/null
@@ -1,289 +0,0 @@
1#
2# Copyright OpenEmbedded Contributors
3#
4# SPDX-License-Identifier: MIT
5#
6
7inherit kernel-uboot kernel-artifact-names uboot-config
8require conf/image-fitimage.conf
9
10def get_fit_replacement_type(d):
11 kerneltypes = d.getVar('KERNEL_IMAGETYPES') or ""
12 replacementtype = ""
13 if 'fitImage' in kerneltypes.split():
14 uarch = d.getVar("UBOOT_ARCH")
15 if uarch == "arm64":
16 replacementtype = "Image"
17 elif uarch == "riscv":
18 replacementtype = "Image"
19 elif uarch == "mips":
20 replacementtype = "vmlinuz.bin"
21 elif uarch == "x86":
22 replacementtype = "bzImage"
23 elif uarch == "microblaze":
24 replacementtype = "linux.bin"
25 else:
26 replacementtype = "zImage"
27 return replacementtype
28
29KERNEL_IMAGETYPE_REPLACEMENT ?= "${@get_fit_replacement_type(d)}"
30DEPENDS:append = " \
31 ${@'u-boot-tools-native dtc-native' if 'fitImage' in (d.getVar('KERNEL_IMAGETYPES') or '').split() else ''} \
32 ${@'kernel-signing-keys-native' if d.getVar('FIT_GENERATE_KEYS') == '1' else ''} \
33"
34
35python __anonymous () {
36 # Override KERNEL_IMAGETYPE_FOR_MAKE variable, which is internal
37 # to kernel.bbclass . We have to override it, since we pack zImage
38 # (at least for now) into the fitImage .
39 typeformake = d.getVar("KERNEL_IMAGETYPE_FOR_MAKE") or ""
40 if 'fitImage' in typeformake.split():
41 d.setVar('KERNEL_IMAGETYPE_FOR_MAKE', typeformake.replace('fitImage', d.getVar('KERNEL_IMAGETYPE_REPLACEMENT')))
42
43 image = d.getVar('INITRAMFS_IMAGE')
44 if image and not bb.utils.to_boolean(d.getVar('INITRAMFS_IMAGE_BUNDLE')):
45 if d.getVar('INITRAMFS_MULTICONFIG'):
46 mc = d.getVar('BB_CURRENT_MC')
47 d.appendVarFlag('do_assemble_fitimage_initramfs', 'mcdepends', ' mc:' + mc + ':${INITRAMFS_MULTICONFIG}:${INITRAMFS_IMAGE}:do_image_complete')
48 else:
49 d.appendVarFlag('do_assemble_fitimage_initramfs', 'depends', ' ${INITRAMFS_IMAGE}:do_image_complete')
50
51 #check if there are any dtb providers
52 providerdtb = d.getVar("PREFERRED_PROVIDER_virtual/dtb")
53 if providerdtb:
54 d.appendVarFlag('do_assemble_fitimage', 'depends', ' virtual/dtb:do_populate_sysroot')
55 d.appendVarFlag('do_assemble_fitimage_initramfs', 'depends', ' virtual/dtb:do_populate_sysroot')
56 d.setVar('EXTERNAL_KERNEL_DEVICETREE', "${RECIPE_SYSROOT}/boot/devicetree")
57}
58
59def fitimage_assemble(d, itsfile, fitname, ramdiskcount):
60 import shutil
61 import glob
62 import oe.fitimage
63
64 DTBS=""
65 default_dtb_image=""
66
67 for f in [itsfile, os.path.join("arch", d.getVar("ARCH"), "boot", fitname)]:
68 if os.path.exists(f):
69 os.remove(f)
70
71 root_node = oe.fitimage.ItsNodeRootKernel(
72 d.getVar("FIT_DESC"), d.getVar("FIT_ADDRESS_CELLS"),
73 d.getVar('HOST_PREFIX'), d.getVar('UBOOT_ARCH'), d.getVar("FIT_CONF_PREFIX"),
74 d.getVar('UBOOT_SIGN_ENABLE') == "1", d.getVar("UBOOT_SIGN_KEYDIR"),
75 d.getVar("UBOOT_MKIMAGE"), d.getVar("UBOOT_MKIMAGE_DTCOPTS"),
76 d.getVar("UBOOT_MKIMAGE_SIGN"), d.getVar("UBOOT_MKIMAGE_SIGN_ARGS"),
77 d.getVar('FIT_HASH_ALG'), d.getVar('FIT_SIGN_ALG'), d.getVar('FIT_PAD_ALG'),
78 d.getVar('UBOOT_SIGN_KEYNAME'),
79 d.getVar('FIT_SIGN_INDIVIDUAL') == "1", d.getVar('UBOOT_SIGN_IMG_KEYNAME')
80 )
81
82 #
83 # Step 1: Prepare a kernel image section.
84 #
85 linux_comp = uboot_prep_kimage_py(d)
86 root_node.fitimage_emit_section_kernel("kernel-1", "linux.bin", linux_comp,
87 d.getVar('UBOOT_LOADADDRESS'), d.getVar('UBOOT_ENTRYPOINT'),
88 d.getVar('UBOOT_MKIMAGE_KERNEL_TYPE'), d.getVar("UBOOT_ENTRYSYMBOL"))
89
90 #
91 # Step 2: Prepare a DTB image section
92 #
93 kernel_devicetree = d.getVar('KERNEL_DEVICETREE')
94 external_kernel_devicetree = d.getVar("EXTERNAL_KERNEL_DEVICETREE")
95 if kernel_devicetree:
96 for DTB in kernel_devicetree.split():
97 if "/dts/" in DTB:
98 bb.warn(f"{DTB} contains the full path to the dts file, but only the dtb name should be used.")
99 DTB = os.path.basename(DTB).replace(".dts", ".dtb")
100
101 # Skip DTB if it's also provided in EXTERNAL_KERNEL_DEVICETREE
102 if external_kernel_devicetree:
103 ext_dtb_path = os.path.join(external_kernel_devicetree, DTB)
104 if os.path.exists(ext_dtb_path) and os.path.getsize(ext_dtb_path) > 0:
105 continue
106
107 DTB_PATH = os.path.join(d.getVar("KERNEL_OUTPUT_DIR"), "dts", DTB)
108 if not os.path.exists(DTB_PATH):
109 DTB_PATH = os.path.join(d.getVar("KERNEL_OUTPUT_DIR"), DTB)
110
111 # Strip off the path component from the filename
112 if not oe.types.boolean(d.getVar("KERNEL_DTBVENDORED")):
113 DTB = os.path.basename(DTB)
114
115 # Set the default dtb image if it exists in the devicetree.
116 if d.getVar("FIT_CONF_DEFAULT_DTB") == DTB:
117 default_dtb_image = DTB.replace("/", "_")
118
119 DTB = DTB.replace("/", "_")
120
121 # Skip DTB if we've picked it up previously
122 if DTB in DTBS.split():
123 continue
124
125 DTBS += " " + DTB
126
127 root_node.fitimage_emit_section_dtb(DTB, DTB_PATH,
128 d.getVar("UBOOT_DTB_LOADADDRESS"), d.getVar("UBOOT_DTBO_LOADADDRESS"))
129
130 if external_kernel_devicetree:
131 dtb_files = []
132 for ext in ['*.dtb', '*.dtbo']:
133 dtb_files.extend(sorted(glob.glob(os.path.join(external_kernel_devicetree, ext))))
134
135 for dtb_path in dtb_files:
136 dtb_name = os.path.relpath(dtb_path, external_kernel_devicetree)
137 dtb_name_underscore = dtb_name.replace('/', '_')
138
139 # Set the default dtb image if it exists in the devicetree.
140 if d.getVar("FIT_CONF_DEFAULT_DTB") == dtb_name:
141 default_dtb_image = dtb_name_underscore
142
143 # Skip DTB/DTBO if we've picked it up previously
144 if dtb_name_underscore in DTBS.split():
145 continue
146
147 DTBS += " " + dtb_name_underscore
148
149 # For symlinks, add a configuration node that refers to the DTB image node to which the symlink points
150 symlink_target = oe.fitimage.symlink_points_below(dtb_name, external_kernel_devicetree)
151 if symlink_target:
152 root_node.fitimage_emit_section_dtb_alias(dtb_name, symlink_target, True)
153 # For real DTB files add an image node and a configuration node
154 else:
155 root_node.fitimage_emit_section_dtb(dtb_name_underscore, dtb_path,
156 d.getVar("UBOOT_DTB_LOADADDRESS"), d.getVar("UBOOT_DTBO_LOADADDRESS"), True)
157
158 if d.getVar("FIT_CONF_DEFAULT_DTB") and not default_dtb_image:
159 bb.warn("%s is not available in the list of device trees." % d.getVar('FIT_CONF_DEFAULT_DTB'))
160
161 #
162 # Step 3: Prepare a u-boot script section
163 #
164 fit_uboot_env = d.getVar("FIT_UBOOT_ENV")
165 if fit_uboot_env:
166 unpack_dir = d.getVar("UNPACKDIR")
167 shutil.copy(os.path.join(unpack_dir, fit_uboot_env), fit_uboot_env)
168 root_node.fitimage_emit_section_boot_script("bootscr-"+fit_uboot_env , fit_uboot_env)
169
170 #
171 # Step 4: Prepare a setup section. (For x86)
172 #
173 setup_bin_path = os.path.join(d.getVar("KERNEL_OUTPUT_DIR"), "setup.bin")
174 if os.path.exists(setup_bin_path):
175 root_node.fitimage_emit_section_setup("setup-1", setup_bin_path)
176
177 #
178 # Step 5: Prepare a ramdisk section.
179 #
180 if ramdiskcount == 1 and d.getVar("INITRAMFS_IMAGE_BUNDLE") != "1":
181 # Find and use the first initramfs image archive type we find
182 found = False
183 for img in d.getVar("FIT_SUPPORTED_INITRAMFS_FSTYPES").split():
184 initramfs_path = os.path.join(d.getVar("DEPLOY_DIR_IMAGE"), "%s.%s" % (d.getVar('INITRAMFS_IMAGE_NAME'), img))
185 if os.path.exists(initramfs_path):
186 bb.note("Found initramfs image: " + initramfs_path)
187 found = True
188 root_node.fitimage_emit_section_ramdisk("ramdisk-%d" % ramdiskcount, initramfs_path,
189 d.getVar('INITRAMFS_IMAGE'),
190 d.getVar("UBOOT_RD_LOADADDRESS"),
191 d.getVar("UBOOT_RD_ENTRYPOINT"))
192 break
193 else:
194 bb.note("Did not find initramfs image: " + initramfs_path)
195
196 if not found:
197 bb.fatal("Could not find a valid initramfs type for %s, the supported types are: %s" % (d.getVar('INITRAMFS_IMAGE_NAME'), d.getVar('FIT_SUPPORTED_INITRAMFS_FSTYPES')))
198
199 # Generate the configuration section
200 root_node.fitimage_emit_section_config(default_dtb_image)
201
202 #
203 # Write the ITS file
204 root_node.write_its_file(itsfile)
205
206 #
207 # Step 7: Assemble the image
208 #
209 fitfile = os.path.join(d.getVar("KERNEL_OUTPUT_DIR"), fitname)
210 root_node.run_mkimage_assemble(itsfile, fitfile)
211
212 #
213 # Step 8: Sign the image if required
214 #
215 root_node.run_mkimage_sign(fitfile)
216
217
218python do_assemble_fitimage() {
219 if "fitImage" in d.getVar("KERNEL_IMAGETYPES").split():
220 os.chdir(d.getVar("B"))
221 fitimage_assemble(d, "fit-image.its", "fitImage-none", "")
222 if d.getVar("INITRAMFS_IMAGE_BUNDLE") != "1":
223 link_name = os.path.join(d.getVar("B"), d.getVar("KERNEL_OUTPUT_DIR"), "fitImage")
224 if os.path.islink(link_name):
225 os.unlink(link_name)
226 os.symlink("fitImage-none", link_name)
227}
228
229addtask assemble_fitimage before do_install after do_compile
230
231SYSROOT_DIRS:append = " /sysroot-only"
232do_install:append() {
233 if echo ${KERNEL_IMAGETYPES} | grep -wq "fitImage" && \
234 [ "${UBOOT_SIGN_ENABLE}" = "1" ]; then
235 install -D ${B}/${KERNEL_OUTPUT_DIR}/fitImage-none ${D}/sysroot-only/fitImage
236 fi
237}
238
239python do_assemble_fitimage_initramfs() {
240 if "fitImage" in d.getVar("KERNEL_IMAGETYPES").split() and d.getVar("INITRAMFS_IMAGE"):
241 os.chdir(d.getVar("B"))
242 if d.getVar("INITRAMFS_IMAGE_BUNDLE") == "1":
243 fitimage_assemble(d, "fit-image-%s.its" % d.getVar("INITRAMFS_IMAGE"), "fitImage-bundle", "")
244 link_name = os.path.join(d.getVar("B"), d.getVar("KERNEL_OUTPUT_DIR"), "fitImage")
245 if os.path.islink(link_name):
246 os.unlink(link_name)
247 os.symlink("fitImage-bundle", link_name)
248 else:
249 fitimage_assemble(d, "fit-image-%s.its" % d.getVar("INITRAMFS_IMAGE"), "fitImage-%s" % d.getVar("INITRAMFS_IMAGE"), 1)
250}
251
252addtask assemble_fitimage_initramfs before do_deploy after do_bundle_initramfs
253
254kernel_do_deploy[vardepsexclude] = "DATETIME"
255kernel_do_deploy:append() {
256 # Update deploy directory
257 if echo ${KERNEL_IMAGETYPES} | grep -wq "fitImage"; then
258
259 if [ "${INITRAMFS_IMAGE_BUNDLE}" != "1" ]; then
260 bbnote "Copying fit-image.its source file..."
261 install -m 0644 ${B}/fit-image.its "$deployDir/fitImage-its-${KERNEL_FIT_NAME}.its"
262 if [ -n "${KERNEL_FIT_LINK_NAME}" ] ; then
263 ln -snf fitImage-its-${KERNEL_FIT_NAME}.its "$deployDir/fitImage-its-${KERNEL_FIT_LINK_NAME}"
264 fi
265
266 bbnote "Copying linux.bin file..."
267 install -m 0644 ${B}/linux.bin $deployDir/fitImage-linux.bin-${KERNEL_FIT_NAME}${KERNEL_FIT_BIN_EXT}
268 if [ -n "${KERNEL_FIT_LINK_NAME}" ] ; then
269 ln -snf fitImage-linux.bin-${KERNEL_FIT_NAME}${KERNEL_FIT_BIN_EXT} "$deployDir/fitImage-linux.bin-${KERNEL_FIT_LINK_NAME}"
270 fi
271 fi
272
273 if [ -n "${INITRAMFS_IMAGE}" ]; then
274 bbnote "Copying fit-image-${INITRAMFS_IMAGE}.its source file..."
275 install -m 0644 ${B}/fit-image-${INITRAMFS_IMAGE}.its "$deployDir/fitImage-its-${INITRAMFS_IMAGE_NAME}-${KERNEL_FIT_NAME}.its"
276 if [ -n "${KERNEL_FIT_LINK_NAME}" ] ; then
277 ln -snf fitImage-its-${INITRAMFS_IMAGE_NAME}-${KERNEL_FIT_NAME}.its "$deployDir/fitImage-its-${INITRAMFS_IMAGE_NAME}-${KERNEL_FIT_LINK_NAME}"
278 fi
279
280 if [ "${INITRAMFS_IMAGE_BUNDLE}" != "1" ]; then
281 bbnote "Copying fitImage-${INITRAMFS_IMAGE} file..."
282 install -m 0644 ${B}/${KERNEL_OUTPUT_DIR}/fitImage-${INITRAMFS_IMAGE} "$deployDir/fitImage-${INITRAMFS_IMAGE_NAME}-${KERNEL_FIT_NAME}${KERNEL_FIT_BIN_EXT}"
283 if [ -n "${KERNEL_FIT_LINK_NAME}" ] ; then
284 ln -snf fitImage-${INITRAMFS_IMAGE_NAME}-${KERNEL_FIT_NAME}${KERNEL_FIT_BIN_EXT} "$deployDir/fitImage-${INITRAMFS_IMAGE_NAME}-${KERNEL_FIT_LINK_NAME}"
285 fi
286 fi
287 fi
288 fi
289}
diff --git a/meta/classes-recipe/kernel-uboot.bbclass b/meta/classes-recipe/kernel-uboot.bbclass
index 6d365355e3..62974baaf0 100644
--- a/meta/classes-recipe/kernel-uboot.bbclass
+++ b/meta/classes-recipe/kernel-uboot.bbclass
@@ -57,48 +57,3 @@ uboot_prep_kimage() {
57 57
58 printf "$linux_comp" > "$output_dir/linux_comp" 58 printf "$linux_comp" > "$output_dir/linux_comp"
59} 59}
60
61def uboot_prep_kimage_py(d):
62 import subprocess
63
64 arch = d.getVar('ARCH')
65 initramfs_image_bundle = d.getVar('INITRAMFS_IMAGE_BUNDLE')
66 fit_kernel_comp_alg = d.getVar('FIT_KERNEL_COMP_ALG') or 'gzip'
67 fit_kernel_comp_alg_extension = d.getVar('FIT_KERNEL_COMP_ALG_EXTENSION') or '.gz'
68 kernel_objcopy = d.getVar('KERNEL_OBJCOPY')
69
70 vmlinux_path = ""
71 linux_suffix = ""
72 linux_comp = "none"
73
74 if os.path.exists(f'arch/{arch}/boot/compressed/vmlinux'):
75 vmlinux_path = f'arch/{arch}/boot/compressed/vmlinux'
76 elif os.path.exists(f'arch/{arch}/boot/vmlinuz.bin'):
77 if os.path.exists('linux.bin'):
78 os.remove('linux.bin')
79 os.link(f'arch/{arch}/boot/vmlinuz.bin', 'linux.bin')
80 else:
81 vmlinux_path = 'vmlinux'
82 # Use vmlinux.initramfs for linux.bin when INITRAMFS_IMAGE_BUNDLE set
83 # As per the implementation in kernel.bbclass.
84 # See do_bundle_initramfs function
85 if initramfs_image_bundle == '1' and os.path.exists('vmlinux.initramfs'):
86 vmlinux_path = 'vmlinux.initramfs'
87 linux_suffix = fit_kernel_comp_alg_extension
88 linux_comp = fit_kernel_comp_alg
89
90 if vmlinux_path:
91 subprocess.run([kernel_objcopy.strip(), '-O', 'binary', '-R', '.note', '-R', '.comment', '-S', os.path.abspath(vmlinux_path), 'linux.bin'], check=True)
92 # if ret.returncode != 0:
93 # bb.fatal(f"Error: stderr: {ret.stderr.decode('utf-8')} stdout: {ret.stdout.decode('utf-8')}, vmlinux_path: {os.path.abspath(vmlinux_path)}, pwd: {os.getcwd()}, args: {ret.args}")
94
95 if linux_comp != "none":
96 if linux_comp == "gzip":
97 subprocess.run(['gzip', '-9', 'linux.bin'], check=True)
98 elif linux_comp == "lzo":
99 subprocess.run(['lzop', '-9', 'linux.bin'], check=True)
100 elif linux_comp == "lzma":
101 subprocess.run(['xz', '--format=lzma', '-f', '-6', 'linux.bin'], check=True)
102 os.rename(f'linux.bin{linux_suffix}', 'linux.bin')
103
104 return linux_comp