objcopy: Calculate addresses to use

Fix systemd254 issue:
https://links.gardouille.fr/shaare/paOraQ
This commit is contained in:
Jeremy Gardais 2023-07-20 14:19:42 +02:00
parent bd3c2de8a4
commit 8d89b5cd8d
Signed by: jegardai
GPG Key ID: E759BAA22501AF32
1 changed files with 15 additions and 8 deletions

View File

@ -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