arm: Align section alignment with manual relocation offset code
PATCH 1/1 arm: Align section alignment with manual relocation offset code
The arm relocation code has a manual special case for EFI binaries to add the natural alignment to its own relocation awareness.
Since commit a51f953f4ee87 ("mkimage: Align efi sections on 4k boundary") we changed that alignment from 0x400 to 0x1000 bytes. Reflect the change in that branch that we forgot as well.
This fixes running 32bit arm grub efi binaries for me again.
--- util/grub-mkimagexx.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-)
util/grub-mkimagexx.c +1 -1
@@ -1137,7 +1137,7 @@ SUFFIX (relocate_addrs) (Elf_Ehdr *e, struct section_metadata *smd, (int) sym_addr, (int) sym_addr);/* Data will be naturally aligned */ if (image_target->id ==IMAGE_EFI ) - sym_addr +=0x400 ; + sym_addr +=GRUB_PE32_SECTION_ALIGNMENT ; *target =grub_host_to_target32 (grub_target_to_host32 (*target) + sym_addr); }break ;
Signature · 1 line
2.16.4
Quoted 7 lines · Alexander Graf
The arm relocation code has a manual special case for EFI binaries to add the natural alignment to its own relocation awareness.
Since commit
a51f953f4ee87("mkimage: Align efi sections on 4k boundary") we changed that alignment from0x400to0x1000bytes. Reflect the change in that branch that we forgot as well.
Quoted 6 lines
This fixes running 32bit arm grub efi binaries for me again.
Fixes a51f953f4ee87 ("mkimage: Align efi sections on 4k boundary")Reported-by Heinrich Schuchardt <[email protected]>Reported-by Steve McIntyre <[email protected]>Signed-off-by Alexander Graf <[email protected]>
However, I will apply this patch if I get some Tested-by and I am sure that other EFI targets are not affected.
Daniel
PS FYI, I am on vacation this week. So, I will take care about
urgent stuff only. Sorry about that.
Seems that this patch is a step forward for arm-efi (32 bits), and doesn't affect others EFI targets (arm64-efi, i386-efi and x86_64-efi are still working fine, including the aarch64-laptop). So it's definitely better than nothing. However, for arm-efi (32 bits), as opposed to the previously suggested revert, this patch fails with some QEMU firmwares :
* --target=arm-linux-gnueabihf --with-platform=efi
o fine with u-boot
o fine with https://efi.akeo.ie/QEMU_EFI/
o *not running fine* with "AAVMF32_code.fd" available into Debian "qemu-efi-arm" package (buster and sid) : continuous rain of Exception messages
o *not running fine* with recent versions of :
http://snapshots.linaro.org/components/kernel/leg-virt-tianocore-edk2-upstream/latest/QEMU-ARM/
Welcome to Grub! Followed by 2 exception messages
* --target=aarch64-linux-gnu --with-platform=efi
o fine with QEMU
o fine with Asus NovaGo TP370QL (Qualcomm Snapdragon 835)
* --target=i386 --with-platform=efi
o fine with QEMU
* --target=x86_64 --with-platform=efi
o fine with QEMU
o fine with an Asus R510JK-DM086H (Intel Core-i5 4200H)
Screencap of the arm-efi error is attached, with a "Debug" firmware, in case it's possible to learn something from the displayed error. Instructions I followed to create the efi files, and to run QEMU against an USB stick image containing those files, are attached too. I can confirm that the previously suggested revert works fine with arm-efi and the same firmware, _so the failure is linked to the new alignment_.
May be something more in the code should be changed somewhere else to follow the new alignment ? Or some differences between firmwares involved in the test ?
Best regards,
Julien
Quoted 16 lines · Daniel Kiper
Quoted 7 lines · Alexander Graf
The arm relocation code has a manual special case for EFI binaries to add the natural alignment to its own relocation awareness.
Since commit
a51f953f4ee87("mkimage: Align efi sections on 4k boundary") we changed that alignment from0x400to0x1000bytes. Reflect the change in that branch that we forgot as well.Quoted 6 lines
This fixes running 32bit arm grub efi binaries for me again.
Fixes a51f953f4ee87 ("mkimage: Align efi sections on 4k boundary")Reported-by Heinrich Schuchardt<[email protected]>Reported-by Steve McIntyre<[email protected]>Signed-off-by Alexander Graf<[email protected]>Reviewed-by Daniel Kiper<[email protected]>
Quoted 7 lines
However, I will apply this patch if I get some Tested-by and I am sure that other EFI targets are not affected.
Daniel
PS FYI, I am on vacation this week. So, I will take care about
urgent stuff only. Sorry about that.
#arm-efi build
cd grub && ./bootstrap && ./configure --target=arm-linux-gnueabihf --with-platform=efi --prefix=/home/user/Desktop/grub-arm-32/ && make -j 8 && make install && /home/user/Desktop/grub-arm-32/bin/grub-mkstandalone -o bootarm.efi -O arm-efi --directory /home/user/Desktop/grub-arm-32/lib/grub/arm-efi/
#arm64-efi build
cd grub && ./bootstrap && ./configure --target=aarch64-linux-gnu --with-platform=efi --prefix=/home/user/Desktop/grub-arm-64/ && make -j 8 && make install && /home/user/Desktop/grub-arm-64/bin/grub-mkstandalone -o bootaa64.efi -O arm64-efi --directory /home/user/Desktop/grub-arm-64/lib/grub/arm64-efi/
#i386-efi build
cd grub && ./bootstrap && ./configure --target=i386 --with-platform=efi --prefix=/home/user/Desktop/grub-x86_32/ && make -j 8 && make install && /home/user/Desktop/grub-x86_32/bin/grub-mkstandalone -o bootia32.efi -O i386-efi --directory /home/user/Desktop/grub-x86_32/lib/grub/i386-efi/
#x86_64-efi build
cd grub && ./bootstrap && ./configure --target=x86_64 --with-platform=efi --prefix=/home/user/Desktop/grub-x86_64/ && make -j 8 && make install && /home/user/Desktop/grub-x86_64/bin/grub-mkstandalone -o bootx64.efi -O x86_64-efi --directory /home/user/Desktop/grub-x86_64/lib/grub/x86_64-efi/
#arm-efi test :
wget http://snapshots.linaro.org/components/kernel/leg-virt-tianocore-edk2-upstream/latest/QEMU-ARM/RELEASE_GCC5/QEMU_EFI.fd
#renamed QEMU_EFI_ARM.fd
qemu-system-arm -M virt -m 512 -net none -monitor none -parallel none -L ./ -bios QEMU_EFI_ARM.fd -drive format=raw,file=../grub-efi-esp-arm-intel-32-64.img #Work with u-boot and akeo - problem with others
#arm64-efi test :
wget http://snapshots.linaro.org/components/kernel/leg-virt-tianocore-edk2-upstream/latest/QEMU-AARCH64/RELEASE_GCC5/QEMU_EFI.fd
#renamed QEMU_EFI_AA64.fd
qemu-system-aarch64 -M virt -cpu cortex-a57 -m 2048 -monitor none -parallel none -L ./ -bios QEMU_EFI_AA64.fd -drive format=raw,file=../grub-efi-esp-arm-intel-32-64.img
#i386-efi test :
#https://www.kraxel.org/repos/jenkins/edk2/edk2.git-ovmf-ia32-0-20190308.1033.ge2d3a25f1a.noarch.rpm #Extracted OVMF-pure-efi.fd
qemu-system-i386 -m 2048 -smp 4 -L ./ -bios OVMF-pure-efi.fd -vga virtio -drive format=raw,file=../grub-efi-esp-arm-intel-32-64.img
#x86_64-efi test :
apt install ovmf
qemu-system-x86_64 -m 2048 -smp 4 -L /usr/share/ovmf -bios OVMF.fd -vga virtio -drive format=raw,file=../grub-efi-esp-arm-intel-32-64.img
Hi Julien,
Thanks a lot for the very detailed report!
Quoted 8 lines · Julien ROBIN
Seems that this patch is a step forward for arm-efi (32 bits), and doesn't affect others EFI targets (arm64-efi, i386-efi and x86_64-efi are still working fine, including the aarch64-laptop). So it's definitely better than nothing. However, for arm-efi (32 bits), as opposed to the previously suggested revert, this patch fails with some QEMU firmwares :
Quoted 10 lines
* --target=arm-linux-gnueabihf --with-platform=efi
o fine with u-boot
o fine with https://efi.akeo.ie/QEMU_EFI/
o *not running fine* with "AAVMF32_code.fd" available into Debian "qemu-efi-arm" package (buster and sid) : continuous rain of Exception messages
o *not running fine* with recent versions of :
http://snapshots.linaro.org/components/kernel/leg-virt-tianocore-edk2-upstream/latest/QEMU-ARM/
Welcome to Grub! Followed by 2 exception messages
This is because of some breakage with Thumb trampolines which seem to get written into NX space now. Trying to isolate it down further with Leif ...
The reason I didn't see the breakage was that both my local as well as the Travis builds were using ARM mode, rather than Thumb. The reason it works with U-Boot and the old OVMF version is that it they don't implement NX.
Thanks a lot again,
Alex