diff options
author | nl6720 <nl6720@gmail.com> | 2023-09-10 13:54:41 +0300 |
---|---|---|
committer | nl6720 <nl6720@gmail.com> | 2023-10-11 18:58:10 +0300 |
commit | b8f91b24e32d0dbf4de9a3d3e12ca38040a79908 (patch) | |
tree | cc0f1e2cf5209f1d40a69e0b3a6d10873c1f9b79 | |
parent | a708ff89a5020ad2aac295cf0d4f2659c5bd2b4e (diff) |
mkinitcpio: try to determine the UEFI architecture
Use systemd-stub of the appropriate architecture. The system may have
multiple `linux*.efi.stub` files available, but only one of them will
actually boot on the system.
Also detect when a 64-bit x86_64 system has a 32-bit IA32 UEFI and use
the IA32 stub accordingly.
-rwxr-xr-x | mkinitcpio | 34 |
1 files changed, 32 insertions, 2 deletions
@@ -334,18 +334,48 @@ uki_assemble() { } build_uki() { - local out="$1" initramfs="$2" cmdline="$3" osrelease="$4" splash="$5" kernelimg="$6" uefistub="$7" microcode=("${@:8}") errmsg='' + local out="$1" initramfs="$2" cmdline="$3" osrelease="$4" splash="$5" kernelimg="$6" uefistub="$7" microcode=("${@:8}") errmsg='' stub cpuarch uefiarch msg "Creating unified kernel image: '%s'" "$out" if [[ -z "$uefistub" ]]; then - for stub in {/usr,}/lib/{systemd/boot/efi,gummiboot}/linux{x64,ia32,aa64}.efi.stub; do + cpuarch="$(uname -m)" + case "$cpuarch" in + x86_64) + uefiarch='x64' + # Detect 64-bit x86_64 systems with 32-bit IA32 UEFI + if [[ -e /sys/firmware/efi/fw_platform_size ]]; then + if (( $(< /sys/firmware/efi/fw_platform_size) == 32 )); then + uefiarch='ia32' + fi + else + warning 'Cannot determine UEFI bitness. Assuming x64 UEFI.' + fi + ;; + i386|i686) + uefiarch='ia32' + ;; + aarch64*|arm64|armv8*) + uefiarch='aa64' + ;; + arm*) + uefiarch='arm' + ;; + *) + uefiarch="$cpuarch" + ;; + esac + for stub in /usr/lib/{systemd/boot/efi,gummiboot}/"linux${uefiarch}.efi.stub"; do if [[ -f "$stub" ]]; then uefistub="$stub" msg2 "Using UEFI stub: '%s'" "$uefistub" break fi done + if [[ -z "$uefistub" ]]; then + error "UEFI stub for architecture '%s' not found" "$uefiarch" + return 1 + fi fi if [[ ! -f "$uefistub" ]]; then error "UEFI stub '%s' not found" "$uefistub" |