diff options
author | Mikko Rapeli <mikko.rapeli@linaro.org> | 2024-10-23 15:08:33 +0300 |
---|---|---|
committer | Richard Purdie <richard.purdie@linuxfoundation.org> | 2024-10-25 15:12:22 +0100 |
commit | 2f0ef8cd0e61c34e67ad9c7508094da3c23f5fce (patch) | |
tree | 5371cc7454a54925bca571c6ef07dff9e74e133c /scripts/lib | |
parent | c50552a2a5bf62b113975bdeb171860068ba9994 (diff) | |
download | poky-2f0ef8cd0e61c34e67ad9c7508094da3c23f5fce.tar.gz |
wic bootimg-efi.py: change UKI support from wic plugin to uki.bbclass
Remove custom wic plugin implementation and use systemd ukify reference
implementation when generating UKI images. Fail if users still have
create-unified-kernel-image in wic image config. uki.bbclass use is
detected from IMAGE_CLASSES variable ("inherit uki" in image
recipe) so export that to wic plugins.
If UKI is used, then only generate a minimal loader config for
systemd-boot which basically just sets a timeout. Also set 5 second
timeout by default instead of failing if wic bootloader config is
missing. Boot menu is generated at runtime based on UKI binaries
found from ESP partition.
(From OE-Core rev: 725fed6ea40c7443b5e0e69dc1dd9c38ac814c56)
Signed-off-by: Mikko Rapeli <mikko.rapeli@linaro.org>
Signed-off-by: Richard Purdie <richard.purdie@linuxfoundation.org>
Diffstat (limited to 'scripts/lib')
-rw-r--r-- | scripts/lib/wic/plugins/source/bootimg-efi.py | 140 |
1 files changed, 25 insertions, 115 deletions
diff --git a/scripts/lib/wic/plugins/source/bootimg-efi.py b/scripts/lib/wic/plugins/source/bootimg-efi.py index d00f5428da..c05f38f229 100644 --- a/scripts/lib/wic/plugins/source/bootimg-efi.py +++ b/scripts/lib/wic/plugins/source/bootimg-efi.py | |||
@@ -125,8 +125,16 @@ class BootimgEFIPlugin(SourcePlugin): | |||
125 | @classmethod | 125 | @classmethod |
126 | def do_configure_systemdboot(cls, hdddir, creator, cr_workdir, source_params): | 126 | def do_configure_systemdboot(cls, hdddir, creator, cr_workdir, source_params): |
127 | """ | 127 | """ |
128 | Create loader-specific systemd-boot/gummiboot config | 128 | Create loader-specific systemd-boot/gummiboot config. Unified Kernel Image (uki) |
129 | support is done in image recipe with uki.bbclass and only systemd-boot loader config | ||
130 | and ESP partition structure is created here. | ||
129 | """ | 131 | """ |
132 | # detect uki.bbclass usage | ||
133 | image_classes = get_bitbake_var("IMAGE_CLASSES").split() | ||
134 | unified_image = False | ||
135 | if "uki" in image_classes: | ||
136 | unified_image = True | ||
137 | |||
130 | install_cmd = "install -d %s/loader" % hdddir | 138 | install_cmd = "install -d %s/loader" % hdddir |
131 | exec_cmd(install_cmd) | 139 | exec_cmd(install_cmd) |
132 | 140 | ||
@@ -134,19 +142,10 @@ class BootimgEFIPlugin(SourcePlugin): | |||
134 | exec_cmd(install_cmd) | 142 | exec_cmd(install_cmd) |
135 | 143 | ||
136 | bootloader = creator.ks.bootloader | 144 | bootloader = creator.ks.bootloader |
137 | |||
138 | unified_image = source_params.get('create-unified-kernel-image') == "true" | ||
139 | |||
140 | loader_conf = "" | 145 | loader_conf = "" |
141 | if not unified_image: | ||
142 | loader_conf += "default boot\n" | ||
143 | loader_conf += "timeout %d\n" % bootloader.timeout | ||
144 | 146 | ||
145 | initrd = source_params.get('initrd') | 147 | # 5 seconds is a sensible default timeout |
146 | dtb = source_params.get('dtb') | 148 | loader_conf += "timeout %d\n" % (bootloader.timeout or 5) |
147 | |||
148 | if not unified_image: | ||
149 | cls._copy_additional_files(hdddir, initrd, dtb) | ||
150 | 149 | ||
151 | logger.debug("Writing systemd-boot config " | 150 | logger.debug("Writing systemd-boot config " |
152 | "%s/hdd/boot/loader/loader.conf", cr_workdir) | 151 | "%s/hdd/boot/loader/loader.conf", cr_workdir) |
@@ -155,8 +154,14 @@ class BootimgEFIPlugin(SourcePlugin): | |||
155 | logger.debug("loader.conf:\n%s" % (loader_conf)) | 154 | logger.debug("loader.conf:\n%s" % (loader_conf)) |
156 | cfg.close() | 155 | cfg.close() |
157 | 156 | ||
157 | initrd = source_params.get('initrd') | ||
158 | dtb = source_params.get('dtb') | ||
159 | if not unified_image: | ||
160 | cls._copy_additional_files(hdddir, initrd, dtb) | ||
161 | |||
158 | configfile = creator.ks.bootloader.configfile | 162 | configfile = creator.ks.bootloader.configfile |
159 | custom_cfg = None | 163 | custom_cfg = None |
164 | boot_conf = "" | ||
160 | if configfile: | 165 | if configfile: |
161 | custom_cfg = get_custom_config(configfile) | 166 | custom_cfg = get_custom_config(configfile) |
162 | if custom_cfg: | 167 | if custom_cfg: |
@@ -167,8 +172,7 @@ class BootimgEFIPlugin(SourcePlugin): | |||
167 | else: | 172 | else: |
168 | raise WicError("configfile is specified but failed to " | 173 | raise WicError("configfile is specified but failed to " |
169 | "get it from %s.", configfile) | 174 | "get it from %s.", configfile) |
170 | 175 | else: | |
171 | if not custom_cfg: | ||
172 | # Create systemd-boot configuration using parameters from wks file | 176 | # Create systemd-boot configuration using parameters from wks file |
173 | kernel = get_bitbake_var("KERNEL_IMAGETYPE") | 177 | kernel = get_bitbake_var("KERNEL_IMAGETYPE") |
174 | if get_bitbake_var("INITRAMFS_IMAGE_BUNDLE") == "1": | 178 | if get_bitbake_var("INITRAMFS_IMAGE_BUNDLE") == "1": |
@@ -178,7 +182,6 @@ class BootimgEFIPlugin(SourcePlugin): | |||
178 | 182 | ||
179 | title = source_params.get('title') | 183 | title = source_params.get('title') |
180 | 184 | ||
181 | boot_conf = "" | ||
182 | boot_conf += "title %s\n" % (title if title else "boot") | 185 | boot_conf += "title %s\n" % (title if title else "boot") |
183 | boot_conf += "linux /%s\n" % kernel | 186 | boot_conf += "linux /%s\n" % kernel |
184 | 187 | ||
@@ -203,6 +206,7 @@ class BootimgEFIPlugin(SourcePlugin): | |||
203 | "%s/hdd/boot/loader/entries/boot.conf", cr_workdir) | 206 | "%s/hdd/boot/loader/entries/boot.conf", cr_workdir) |
204 | cfg = open("%s/hdd/boot/loader/entries/boot.conf" % cr_workdir, "w") | 207 | cfg = open("%s/hdd/boot/loader/entries/boot.conf" % cr_workdir, "w") |
205 | cfg.write(boot_conf) | 208 | cfg.write(boot_conf) |
209 | logger.debug("boot.conf:\n%s" % (boot_conf)) | ||
206 | cfg.close() | 210 | cfg.close() |
207 | 211 | ||
208 | 212 | ||
@@ -307,107 +311,13 @@ class BootimgEFIPlugin(SourcePlugin): | |||
307 | (get_bitbake_var("KERNEL_IMAGETYPE"), get_bitbake_var("INITRAMFS_LINK_NAME")) | 311 | (get_bitbake_var("KERNEL_IMAGETYPE"), get_bitbake_var("INITRAMFS_LINK_NAME")) |
308 | 312 | ||
309 | if source_params.get('create-unified-kernel-image') == "true": | 313 | if source_params.get('create-unified-kernel-image') == "true": |
310 | initrd = source_params.get('initrd') | 314 | raise WicError("create-unified-kernel-image is no longer supported. Please use uki.bbclass.") |
311 | if not initrd: | ||
312 | raise WicError("initrd= must be specified when create-unified-kernel-image=true, exiting") | ||
313 | |||
314 | deploy_dir = get_bitbake_var("DEPLOY_DIR_IMAGE") | ||
315 | efi_stub = glob("%s/%s" % (deploy_dir, "linux*.efi.stub")) | ||
316 | if len(efi_stub) == 0: | ||
317 | raise WicError("Unified Kernel Image EFI stub not found, exiting") | ||
318 | efi_stub = efi_stub[0] | ||
319 | |||
320 | with tempfile.TemporaryDirectory() as tmp_dir: | ||
321 | label = source_params.get('label') | ||
322 | label_conf = "root=%s" % creator.rootdev | ||
323 | if label: | ||
324 | label_conf = "LABEL=%s" % label | ||
325 | |||
326 | bootloader = creator.ks.bootloader | ||
327 | cmdline = open("%s/cmdline" % tmp_dir, "w") | ||
328 | cmdline.write("%s %s" % (label_conf, bootloader.append)) | ||
329 | cmdline.close() | ||
330 | 315 | ||
331 | initrds = initrd.split(';') | 316 | if source_params.get('install-kernel-into-boot-dir') != 'false': |
332 | initrd = open("%s/initrd" % tmp_dir, "wb") | 317 | install_cmd = "install -v -p -m 0644 %s/%s %s/%s" % \ |
333 | for f in initrds: | 318 | (staging_kernel_dir, kernel, hdddir, kernel) |
334 | with open("%s/%s" % (deploy_dir, f), 'rb') as in_file: | 319 | out = exec_cmd(install_cmd) |
335 | shutil.copyfileobj(in_file, initrd) | 320 | logger.debug("Installed kernel files:\n%s" % out) |
336 | initrd.close() | ||
337 | |||
338 | # Searched by systemd-boot: | ||
339 | # https://systemd.io/BOOT_LOADER_SPECIFICATION/#type-2-efi-unified-kernel-images | ||
340 | install_cmd = "install -d %s/EFI/Linux" % hdddir | ||
341 | exec_cmd(install_cmd) | ||
342 | |||
343 | staging_dir_host = get_bitbake_var("STAGING_DIR_HOST") | ||
344 | target_sys = get_bitbake_var("TARGET_SYS") | ||
345 | |||
346 | objdump_cmd = "%s-objdump" % target_sys | ||
347 | objdump_cmd += " -p %s" % efi_stub | ||
348 | objdump_cmd += " | awk '{ if ($1 == \"SectionAlignment\"){print $2} }'" | ||
349 | |||
350 | ret, align_str = exec_native_cmd(objdump_cmd, native_sysroot) | ||
351 | align = int(align_str, 16) | ||
352 | |||
353 | objdump_cmd = "%s-objdump" % target_sys | ||
354 | objdump_cmd += " -h %s | tail -2" % efi_stub | ||
355 | ret, output = exec_native_cmd(objdump_cmd, native_sysroot) | ||
356 | |||
357 | offset = int(output.split()[2], 16) + int(output.split()[3], 16) | ||
358 | |||
359 | osrel_off = offset + align - offset % align | ||
360 | osrel_path = "%s/usr/lib/os-release" % staging_dir_host | ||
361 | osrel_sz = os.stat(osrel_path).st_size | ||
362 | |||
363 | cmdline_off = osrel_off + osrel_sz | ||
364 | cmdline_off = cmdline_off + align - cmdline_off % align | ||
365 | cmdline_sz = os.stat(cmdline.name).st_size | ||
366 | |||
367 | dtb_off = cmdline_off + cmdline_sz | ||
368 | dtb_off = dtb_off + align - dtb_off % align | ||
369 | |||
370 | dtb = source_params.get('dtb') | ||
371 | if dtb: | ||
372 | if ';' in dtb: | ||
373 | raise WicError("Only one DTB supported, exiting") | ||
374 | dtb_path = "%s/%s" % (deploy_dir, dtb) | ||
375 | dtb_params = '--add-section .dtb=%s --change-section-vma .dtb=0x%x' % \ | ||
376 | (dtb_path, dtb_off) | ||
377 | linux_off = dtb_off + os.stat(dtb_path).st_size | ||
378 | linux_off = linux_off + align - linux_off % align | ||
379 | else: | ||
380 | dtb_params = '' | ||
381 | linux_off = dtb_off | ||
382 | |||
383 | linux_path = "%s/%s" % (staging_kernel_dir, kernel) | ||
384 | linux_sz = os.stat(linux_path).st_size | ||
385 | |||
386 | initrd_off = linux_off + linux_sz | ||
387 | initrd_off = initrd_off + align - initrd_off % align | ||
388 | |||
389 | # https://www.freedesktop.org/software/systemd/man/systemd-stub.html | ||
390 | objcopy_cmd = "%s-objcopy" % target_sys | ||
391 | objcopy_cmd += " --enable-deterministic-archives" | ||
392 | objcopy_cmd += " --preserve-dates" | ||
393 | objcopy_cmd += " --add-section .osrel=%s" % osrel_path | ||
394 | objcopy_cmd += " --change-section-vma .osrel=0x%x" % osrel_off | ||
395 | objcopy_cmd += " --add-section .cmdline=%s" % cmdline.name | ||
396 | objcopy_cmd += " --change-section-vma .cmdline=0x%x" % cmdline_off | ||
397 | objcopy_cmd += dtb_params | ||
398 | objcopy_cmd += " --add-section .linux=%s" % linux_path | ||
399 | objcopy_cmd += " --change-section-vma .linux=0x%x" % linux_off | ||
400 | objcopy_cmd += " --add-section .initrd=%s" % initrd.name | ||
401 | objcopy_cmd += " --change-section-vma .initrd=0x%x" % initrd_off | ||
402 | objcopy_cmd += " %s %s/EFI/Linux/linux.efi" % (efi_stub, hdddir) | ||
403 | |||
404 | exec_native_cmd(objcopy_cmd, native_sysroot) | ||
405 | else: | ||
406 | if source_params.get('install-kernel-into-boot-dir') != 'false': | ||
407 | install_cmd = "install -v -p -m 0644 %s/%s %s/%s" % \ | ||
408 | (staging_kernel_dir, kernel, hdddir, kernel) | ||
409 | out = exec_cmd(install_cmd) | ||
410 | logger.debug("Installed kernel files:\n%s" % out) | ||
411 | 321 | ||
412 | if get_bitbake_var("IMAGE_EFI_BOOT_FILES"): | 322 | if get_bitbake_var("IMAGE_EFI_BOOT_FILES"): |
413 | for src_path, dst_path in cls.install_task: | 323 | for src_path, dst_path in cls.install_task: |