From 8d89b5cd8d0556159a754b2ba31462b88a1a8a58 Mon Sep 17 00:00:00 2001 From: Gardouille Date: Thu, 20 Jul 2023 14:19:42 +0200 Subject: [PATCH] objcopy: Calculate addresses to use Fix systemd254 issue: https://links.gardouille.fr/shaare/paOraQ --- debian/create-efi-kernel | 23 +++++++++++++++-------- 1 file changed, 15 insertions(+), 8 deletions(-) diff --git a/debian/create-efi-kernel b/debian/create-efi-kernel index 4cb02d0..007ae7b 100755 --- a/debian/create-efi-kernel +++ b/debian/create-efi-kernel @@ -64,13 +64,20 @@ while IFS= read -r KERNEL; do ESP_DISK=$(lsblk /dev/"${ESP}" -no pkname) ESP_PART=$(cat /sys/class/block/"${ESP}"/partition) + ### Calculate address values to use for each section + osrel_offs=$(objdump -h "/usr/lib/systemd/boot/efi/linuxx64.efi.stub" | awk 'NF==7 {size=strtonum("0x"$3); offset=strtonum("0x"$4)} END {print size + offset}') + cmdline_offs=$((osrel_offs + $(stat -Lc%s "/usr/lib/os-release"))) + linux_offs=$((cmdline_offs + $(stat -Lc%s "${temp_kernel_command_file}"))) + initrd_offs=$((linux_offs + $(stat -Lc%s "/boot/vmlinuz-6.3.0-1-amd64"))) + ### Create a unified kernel + printf "%s\n" "Creating unified kernel for version ${KERNEL_VERSION}..." objcopy \ - --add-section .osrel="/usr/lib/os-release" --change-section-vma .osrel=0x20000 \ - --add-section .cmdline="${temp_kernel_command_file}" --change-section-vma .cmdline=0x30000 \ - --add-section .linux="/boot/vmlinuz-${KERNEL_VERSION}" --change-section-vma .linux=0x2000000 \ - --add-section .initrd="/boot/initrd.img-${KERNEL_VERSION}" --change-section-vma .initrd=0x3000000 \ + --add-section .osrel="/usr/lib/os-release" --change-section-vma .osrel=$(printf 0x%x $osrel_offs) \ + --add-section .cmdline="${temp_kernel_command_file}" --change-section-vma .cmdline=$(printf 0x%x $cmdline_offs) \ + --add-section .linux="/boot/vmlinuz-${KERNEL_VERSION}" --change-section-vma .linux=$(printf 0x%x $linux_offs) \ + --add-section .initrd="/boot/initrd.img-${KERNEL_VERSION}" --change-section-vma .initrd=$(printf 0x%x $initrd_offs) \ /usr/lib/systemd/boot/efi/linuxx64.efi.stub "${EFI_MOUNT_PATH}/EFI/debian/linux.debian.${KERNEL_VERSION}.efi" ### Create a efiboot entry @@ -84,10 +91,10 @@ done < "${temp_kernel_list_file}" ### Create a unified kernel printf "%s\n" "Creating unified generic kernel for the last version (${KERNEL_VERSION})..." objcopy \ - --add-section .osrel="/usr/lib/os-release" --change-section-vma .osrel=0x20000 \ - --add-section .cmdline="${temp_kernel_command_file}" --change-section-vma .cmdline=0x30000 \ - --add-section .linux="/boot/vmlinuz-${KERNEL_VERSION}" --change-section-vma .linux=0x2000000 \ - --add-section .initrd="/boot/initrd.img-${KERNEL_VERSION}" --change-section-vma .initrd=0x3000000 \ + --add-section .osrel="/usr/lib/os-release" --change-section-vma .osrel=$(printf 0x%x $osrel_offs) \ + --add-section .cmdline="${temp_kernel_command_file}" --change-section-vma .cmdline=$(printf 0x%x $cmdline_offs) \ + --add-section .linux="/boot/vmlinuz-${KERNEL_VERSION}" --change-section-vma .linux=$(printf 0x%x $linux_offs) \ + --add-section .initrd="/boot/initrd.img-${KERNEL_VERSION}" --change-section-vma .initrd=$(printf 0x%x $initrd_offs) \ /usr/lib/systemd/boot/efi/linuxx64.efi.stub "${EFI_MOUNT_PATH}/EFI/debian/linux.debian.efi" ### Create a efiboot entry