Open WhyNotHugo opened 1 year ago
FWIW, I also tried using objcopy
directly like this:
objcopy \
--preserve-dates \
--enable-deterministic-archives \
--add-section ".kernel=$KERNEL" --set-section-flags .kernel=code,readonly \
--add-section ".cmdline=$CMDLINE" --set-section-flags .cmdline=data,readonly \
--add-section ".initrd=$INITRD" --set-section-flags .initrd=data,readonly \
target/x86_64-unknown-uefi/debug/hello-uefi.efi \
ESP/efi/boot/bootx64.efi
But the result in the same.
Looks like --change-section-vma
is required (and mkuki
is specifying it), but the addresses need to be relative to the ImageBase, which is simply different for my binary:
> objdump -p ESP/efi/boot/bootx64.efi | grep ImageBase
ImageBase 0000000140000000
I'm not sure if I know how to address this in mkuki
though, I'll have to do a bit more experimentation first (since I'm manually calculating offsets for now) and adding, for example:
--add-section ".kernel=$KERNEL" --set-section-flags .kernel=code,readonly --change-section-vma .kernel+0x140020314\
@WhyNotHugo -- did you ever figure out how to resolve or work around this problem?
I was successfully using efi-mkuki until changing the kernel that I'm using from 5.15 to 6.8, and my base OS image from Ubuntu 22.04LTS to Ubuntu 24.04LTS.
I now have the object loaded below base error too.
I couldn't figure out how to make this work with efi-mkuki
; I still don't fully understand all the parts in play here.
At the time, I wrote my own custom code using a library that handled PE for this. It was a horrible pile of hacks. I can't seem to find any of it now, sorry.
I found the problem to be /usr/lib/systemd/boot/efi/linuxx64.efi.stub that is included in Ubuntu 24.04LTS's systemd-efi-bin package. Using this stub to produce the unified kernel image results in the following warning from objcopy:
objcopy:/tmp/NEW_ROOT1224/boot/efi/EFI/ubuntu/vmlinuz.efi:.osrel:sectionbelowimagebase objcopy:/tmp/NEW_ROOT1224/boot/efi/EFI/ubuntu/vmlinuz.efi:.cmdline:sectionbelowimagebase objcopy: /tmp/NEW_ROOT1224/boot/efi/EFI/ubuntu/vmlinuz.efi:.linux: section below image base objcopy:/*mp/NEW_ROOT1224/boot/efi/EFI/ubuntu/vmlinuz.efi:.initrd:section below image base And the resulting EFI binary will not boot.
If I copied the same file from an Ubuntu 22.04LTS system (in systemd package) and used that instead, I got an EFI binary that boots.
So, at least for now, that is my work-around.
Given that gummiboot and other stubs rely on the now-deprecated handover protocol, I'm writing my own little stub loader.
The loader by itself "runs" and can inspect its own PE table to find PE sections (e.g.: the kernel, cmdline, initrd). However, I'm having a hard time assembling a binary which actually contains the stub plus these three.
I'm basically using the following:
Which warns:
Indeed, it seems that the new sections are added to the begging of the file, not to the end of it:
For reference, this is by stub before running
mkuki
:The resulting binary doesn't run. I'm pretty sure that it is not valid due to the order of the sections (e.g.: the image base should be at the beginning). However, I can't figure out how to force a different order.
For reference, using
mkuki
with gummiboot's stub results in a different ordering:I tried using
objcopy
manually, but ended up having the same issue. Any ideas how to address this?