summaryrefslogtreecommitdiffstats
path: root/scripts/lib/wic/plugins/source/bootimg-efi.py
diff options
context:
space:
mode:
authorAlexandre Belloni <alexandre.belloni@bootlin.com>2023-08-09 00:17:43 +0200
committerRichard Purdie <richard.purdie@linuxfoundation.org>2023-08-09 21:43:33 +0100
commit6c0350934952b7b06104d7dacbe152386ba72aec (patch)
tree9afe30384bd0d4e9f60b1680272771b09dc989c1 /scripts/lib/wic/plugins/source/bootimg-efi.py
parent8e6dc32e5e0f63c1265bba3f676a7c795a6c63b6 (diff)
downloadpoky-6c0350934952b7b06104d7dacbe152386ba72aec.tar.gz
wic: bootimg-efi: Stop hardcoding VMA offsets
Section VMA's are currently hardcoded. This doesn't work anymore starting with systemd-boot v254. Follow the actually solution to this which is documented here: https://wiki.archlinux.org/title/Unified_kernel_image#Manually This is also used by dracut. Later on, we may want to switch to ukify instead but this is not ready yet. (From OE-Core rev: 3abf99a6c6bde2fb8770f54dba609b35f6c6ee5a) Signed-off-by: Alexandre Belloni <alexandre.belloni@bootlin.com> Signed-off-by: Richard Purdie <richard.purdie@linuxfoundation.org>
Diffstat (limited to 'scripts/lib/wic/plugins/source/bootimg-efi.py')
-rw-r--r--scripts/lib/wic/plugins/source/bootimg-efi.py63
1 files changed, 49 insertions, 14 deletions
diff --git a/scripts/lib/wic/plugins/source/bootimg-efi.py b/scripts/lib/wic/plugins/source/bootimg-efi.py
index 2bf7375887..4f30926f1a 100644
--- a/scripts/lib/wic/plugins/source/bootimg-efi.py
+++ b/scripts/lib/wic/plugins/source/bootimg-efi.py
@@ -332,37 +332,72 @@ class BootimgEFIPlugin(SourcePlugin):
332 shutil.copyfileobj(in_file, initrd) 332 shutil.copyfileobj(in_file, initrd)
333 initrd.close() 333 initrd.close()
334 334
335 # Searched by systemd-boot:
336 # https://systemd.io/BOOT_LOADER_SPECIFICATION/#type-2-efi-unified-kernel-images
337 install_cmd = "install -d %s/EFI/Linux" % hdddir
338 exec_cmd(install_cmd)
339
340 staging_dir_host = get_bitbake_var("STAGING_DIR_HOST")
341 target_sys = get_bitbake_var("TARGET_SYS")
342
343 objdump_cmd = "%s-objdump" % target_sys
344 objdump_cmd += " -p %s" % efi_stub
345 objdump_cmd += " | awk '{ if ($1 == \"SectionAlignment\"){print $2} }'"
346
347 ret, align_str = exec_native_cmd(objdump_cmd, native_sysroot)
348 align = int(align_str, 16)
349
350 objdump_cmd = "%s-objdump" % target_sys
351 objdump_cmd += " -h %s | tail -2" % efi_stub
352 ret, output = exec_native_cmd(objdump_cmd, native_sysroot)
353
354 offset = int(output.split()[2], 16) + int(output.split()[3], 16)
355
356 osrel_off = offset + align - offset % align
357 osrel_path = "%s/usr/lib/os-release" % staging_dir_host
358 osrel_sz = os.stat(osrel_path).st_size
359
360 cmdline_off = osrel_off + osrel_sz
361 cmdline_off = cmdline_off + align - cmdline_off % align
362 cmdline_sz = os.stat(cmdline.name).st_size
363
364 dtb_off = cmdline_off + cmdline_sz
365 dtb_off = dtb_off + align - dtb_off % align
366
335 dtb = source_params.get('dtb') 367 dtb = source_params.get('dtb')
336 if dtb: 368 if dtb:
337 if ';' in dtb: 369 if ';' in dtb:
338 raise WicError("Only one DTB supported, exiting") 370 raise WicError("Only one DTB supported, exiting")
339 dtb_params = '--add-section .dtb=%s/%s --change-section-vma .dtb=0x40000' % \ 371 dtb_path = "%s/%s" % (deploy_dir, dtb)
340 (deploy_dir, dtb) 372 dtb_params = '--add-section .dtb=%s --change-section-vma .dtb=0x%x' % \
373 (dtb_path, dtb_off)
374 linux_off = dtb_off + os.stat(dtb_path).st_size
375 linux_off = linux_off + align - linux_off % align
341 else: 376 else:
342 dtb_params = '' 377 dtb_params = ''
378 linux_off = dtb_off
343 379
344 # Searched by systemd-boot: 380 linux_path = "%s/%s" % (staging_kernel_dir, kernel)
345 # https://systemd.io/BOOT_LOADER_SPECIFICATION/#type-2-efi-unified-kernel-images 381 linux_sz = os.stat(linux_path).st_size
346 install_cmd = "install -d %s/EFI/Linux" % hdddir
347 exec_cmd(install_cmd)
348 382
349 staging_dir_host = get_bitbake_var("STAGING_DIR_HOST") 383 initrd_off = linux_off + linux_sz
350 target_sys = get_bitbake_var("TARGET_SYS") 384 initrd_off = initrd_off + align - initrd_off % align
351 385
352 # https://www.freedesktop.org/software/systemd/man/systemd-stub.html 386 # https://www.freedesktop.org/software/systemd/man/systemd-stub.html
353 objcopy_cmd = "%s-objcopy" % target_sys 387 objcopy_cmd = "%s-objcopy" % target_sys
354 objcopy_cmd += " --enable-deterministic-archives" 388 objcopy_cmd += " --enable-deterministic-archives"
355 objcopy_cmd += " --preserve-dates" 389 objcopy_cmd += " --preserve-dates"
356 objcopy_cmd += " --add-section .osrel=%s/usr/lib/os-release" % staging_dir_host 390 objcopy_cmd += " --add-section .osrel=%s" % osrel_path
357 objcopy_cmd += " --change-section-vma .osrel=0x20000" 391 objcopy_cmd += " --change-section-vma .osrel=0x%x" % osrel_off
358 objcopy_cmd += " --add-section .cmdline=%s" % cmdline.name 392 objcopy_cmd += " --add-section .cmdline=%s" % cmdline.name
359 objcopy_cmd += " --change-section-vma .cmdline=0x30000" 393 objcopy_cmd += " --change-section-vma .cmdline=0x%x" % cmdline_off
360 objcopy_cmd += dtb_params 394 objcopy_cmd += dtb_params
361 objcopy_cmd += " --add-section .linux=%s/%s" % (staging_kernel_dir, kernel) 395 objcopy_cmd += " --add-section .linux=%s" % linux_path
362 objcopy_cmd += " --change-section-vma .linux=0x2000000" 396 objcopy_cmd += " --change-section-vma .linux=0x%x" % linux_off
363 objcopy_cmd += " --add-section .initrd=%s" % initrd.name 397 objcopy_cmd += " --add-section .initrd=%s" % initrd.name
364 objcopy_cmd += " --change-section-vma .initrd=0x3000000" 398 objcopy_cmd += " --change-section-vma .initrd=0x%x" % initrd_off
365 objcopy_cmd += " %s %s/EFI/Linux/linux.efi" % (efi_stub, hdddir) 399 objcopy_cmd += " %s %s/EFI/Linux/linux.efi" % (efi_stub, hdddir)
400
366 exec_native_cmd(objcopy_cmd, native_sysroot) 401 exec_native_cmd(objcopy_cmd, native_sysroot)
367 else: 402 else:
368 install_cmd = "install -m 0644 %s/%s %s/%s" % \ 403 install_cmd = "install -m 0644 %s/%s %s/%s" % \