pmaports/main/systemd-boot/0002-fix-wchar-for-compiling-on-musl.patch

98 lines
3.5 KiB
Diff
Raw Normal View History

From 3153e2edb2b97117284e046b9cb9b846569b77df Mon Sep 17 00:00:00 2001
main/systemd-boot: new aport (MR 4484) EFI bootloader from systemd, with hacks to build it on Alpine/pmOS. Cross compilation (using a meson cross file) is used for building 32-bit version on x86_64, for systems that have a 32-bit EFI. Everything else assumes that the EFI arch matches the CPU arch. Besides supporting all the archs we need, another major goal was to minimize the number of changes to systemd's build system required to build only the bootloader, so that maintaining/rebasing isn't *too* painful... I am adding this to the "main" category, because I don't think there's a way to add it to Alpine. It requires cross compiling to x86 on x86_64 (to support 32-bit EFI on this arch), and Alpine doesn't support this. It requires stuff in pmaports/cross. --- Research notes --- I started looking at all of this because I wanted to come up with a single way to boot Linux via EFI, that supports all (or as many as possible) devices in pmaports. I looked at quite a few different options, and have some notes below about my observations and conclusions for each. Of everything I looked at, systemd-boot was the clear winner that met the most requirements ("pro" below) with the fewest downsides ("con" below). Using a Unified Kernel Image (UKI) was a close second place, however systemd-boot can also support booting UKI images quite easily (while also giving us more flexibility to boot other things easily too), so I think it wins over UKI. The capitalization (or lack thereof) of the "pro" and "con" markers below is significant: "PRO" / "CON" are major pros or cons for each point (e.g. a major downside that blocks using the option), and "pro"/"con" are minor (e.g. a downside that I'm willing to overlook.) ---- Requirements ---- - Arch support: - x86_64 - x86 (nice to have, but not sure if necessary...) - armv7 - aarch64 - riscv64 - EFI support: - support 32-bit EFI on x86_64 CPU (includes being able to build 32-bit .efi app on x86_64) - Easy to configure - Easy to maintain - Any changes to the bootloader required to get it working in pmOS - Config for it ---- Evaluated options ---- ------ grub ------ - (PRO) can target all required archs - (CON) grub can't be installed in pmb chroot, it calls grub-install and that fails due to something missing in /dev. Maybe this could be worked around in pmb? - (CON) grub-mkimage exe is integrated in grub package, grub-efi depends on grub - don't want to install all of grub just for 1 exe and/or the EFI modules - downsides of installing all of grub is that I think it can mislead users into thinking we use grub the "normal way". this might cause them to have the wrong expectations and break pmOS boot on their system - have POC "fixing" this - I'm not sure upstream Alpine will like this, it's ugly - (CON) grub x86 EFI support for x86_64 is currently in pmaports, that's pretty ugly. - IMHO forking grub (or grub components) for this purpose signals to me that grub is the wrong tool for this job ------- kernel's efistub ------- - (PRO) already included in the kernel, nothing else required - (pro) initrd and dtb can be passed in the kernel cmdline... however.... - (CON) kernel cmdline can only be set at compile time - (con) not all kernels may have EFISTUB set? - (con) can't do measured/secure boot - (con) requires a fairly recent kernel on aarch w/ efi_zboot support enabled since we compress the kernel ------- UKI ------- - (PRO) very simple, 1 file thing - (PRO) supports adding dtb, setting kernel cmdline and so on - (pro) can do measured/secure boot - (CON) requires an EFI stub loader - can't find a stub loader that meets all requirements (other than the one from systemd-boot...) - (con) requires efi-mkuki or dealing with objcopy directly (eww) - (con) requires a fairly recent kernel on aarch w/ efi_zboot support ------- limine ------- - (PRO) easy to install/configure, already have boot-deploy and pmaports patches - (PRO) can be cross compiled easily - evidence is in aports - ...but I couldn't reproduce building aarch64 and riscv64 on x86_64 - (pro) can do measured/secure boot (I think?) - (CON) doesn't target all required archs - can't do "linux boot" on aarch64, only "chainload" - what about using chainload everywhere? - requires using efistub in kernel - what about dtb= and upstream recommendation to not use it except for debug? - no kernel compression support on aarch64 - see efi-stub.txt kernel doc - (CON) vendors libgcc to support cross compilation - probably not a good idea to trust binaries produced in microsoft github's CI for some random project ------- stubbyboot ------- - (PRO) a straight forward stub loader - (pro) can do measured/secure boot - (CON) doesn't target all required archs - (CON) cross compiling doesn't work. - gcc can't do 32-bit on x86_64 Alpine... - gnu-efi-dev needs to be fixed to package both 32-bit and 64-bit on x86_64... - have patch in ~/src/aports that kinda does it.. but needs to be fixed/finished - maybe limine-efi works with it? - tried, but fails due to missing efilib.h in limine-efi ------- systemd-stub ------- - (PRO) another straight forward stub loader - (PRO) many (many) people using it, as part of systemd-boot - (pro) can do measured/secure boot - (con) requires a fairly recent kernel on aarch w/ efi_zboot support enabled since we compress the kernel - (con) doesn't target all required archs - but does claim to support most... missing armv7.. maybe it works? - (con) will end up maintaining some downstream patch to build it - hopefully the patch (if I can even make a working one!) is not too complex! - (CON) can't be built outside of systemd's silly large build system. - UPDATE: largely resolved this in pmaports - was able to build for native arch! - can't build 32-bit on x86_64, no gcc multilib support in Alpine... Couldn't get clang to work properly, but maybe it can somehow... - https://github.com/mintsuki/libgcc-binaries ? NO! (don't want bootloader binaries that depend on code compiled by microsoft / github...) ------- DIY stub / bootloader ----- - (PRO) **might** target all required archs and other meet requirements - (CON) lots of time required to learn, design, do, debug, test - (CON) lots of time required to learn, design, do, debug, test - (CON) lots of time required to learn, design, do, debug, test - (CON) (get the hint yet???) - (CON) written in C, probably (there's a rust EFI lib, lol...) [ci:skip-build]: Already built successfully in CI
2023-10-06 19:52:53 +00:00
From: Clayton Craft <clayton@craftyguy.net>
Date: Fri, 6 Oct 2023 08:30:52 -0700
Subject: [PATCH 2/2] fix wchar for compiling on musl
---
src/boot/efi/efi-string.c | 10 +++++-----
src/boot/efi/efi.h | 5 +----
2 files changed, 6 insertions(+), 9 deletions(-)
main/systemd-boot: new aport (MR 4484) EFI bootloader from systemd, with hacks to build it on Alpine/pmOS. Cross compilation (using a meson cross file) is used for building 32-bit version on x86_64, for systems that have a 32-bit EFI. Everything else assumes that the EFI arch matches the CPU arch. Besides supporting all the archs we need, another major goal was to minimize the number of changes to systemd's build system required to build only the bootloader, so that maintaining/rebasing isn't *too* painful... I am adding this to the "main" category, because I don't think there's a way to add it to Alpine. It requires cross compiling to x86 on x86_64 (to support 32-bit EFI on this arch), and Alpine doesn't support this. It requires stuff in pmaports/cross. --- Research notes --- I started looking at all of this because I wanted to come up with a single way to boot Linux via EFI, that supports all (or as many as possible) devices in pmaports. I looked at quite a few different options, and have some notes below about my observations and conclusions for each. Of everything I looked at, systemd-boot was the clear winner that met the most requirements ("pro" below) with the fewest downsides ("con" below). Using a Unified Kernel Image (UKI) was a close second place, however systemd-boot can also support booting UKI images quite easily (while also giving us more flexibility to boot other things easily too), so I think it wins over UKI. The capitalization (or lack thereof) of the "pro" and "con" markers below is significant: "PRO" / "CON" are major pros or cons for each point (e.g. a major downside that blocks using the option), and "pro"/"con" are minor (e.g. a downside that I'm willing to overlook.) ---- Requirements ---- - Arch support: - x86_64 - x86 (nice to have, but not sure if necessary...) - armv7 - aarch64 - riscv64 - EFI support: - support 32-bit EFI on x86_64 CPU (includes being able to build 32-bit .efi app on x86_64) - Easy to configure - Easy to maintain - Any changes to the bootloader required to get it working in pmOS - Config for it ---- Evaluated options ---- ------ grub ------ - (PRO) can target all required archs - (CON) grub can't be installed in pmb chroot, it calls grub-install and that fails due to something missing in /dev. Maybe this could be worked around in pmb? - (CON) grub-mkimage exe is integrated in grub package, grub-efi depends on grub - don't want to install all of grub just for 1 exe and/or the EFI modules - downsides of installing all of grub is that I think it can mislead users into thinking we use grub the "normal way". this might cause them to have the wrong expectations and break pmOS boot on their system - have POC "fixing" this - I'm not sure upstream Alpine will like this, it's ugly - (CON) grub x86 EFI support for x86_64 is currently in pmaports, that's pretty ugly. - IMHO forking grub (or grub components) for this purpose signals to me that grub is the wrong tool for this job ------- kernel's efistub ------- - (PRO) already included in the kernel, nothing else required - (pro) initrd and dtb can be passed in the kernel cmdline... however.... - (CON) kernel cmdline can only be set at compile time - (con) not all kernels may have EFISTUB set? - (con) can't do measured/secure boot - (con) requires a fairly recent kernel on aarch w/ efi_zboot support enabled since we compress the kernel ------- UKI ------- - (PRO) very simple, 1 file thing - (PRO) supports adding dtb, setting kernel cmdline and so on - (pro) can do measured/secure boot - (CON) requires an EFI stub loader - can't find a stub loader that meets all requirements (other than the one from systemd-boot...) - (con) requires efi-mkuki or dealing with objcopy directly (eww) - (con) requires a fairly recent kernel on aarch w/ efi_zboot support ------- limine ------- - (PRO) easy to install/configure, already have boot-deploy and pmaports patches - (PRO) can be cross compiled easily - evidence is in aports - ...but I couldn't reproduce building aarch64 and riscv64 on x86_64 - (pro) can do measured/secure boot (I think?) - (CON) doesn't target all required archs - can't do "linux boot" on aarch64, only "chainload" - what about using chainload everywhere? - requires using efistub in kernel - what about dtb= and upstream recommendation to not use it except for debug? - no kernel compression support on aarch64 - see efi-stub.txt kernel doc - (CON) vendors libgcc to support cross compilation - probably not a good idea to trust binaries produced in microsoft github's CI for some random project ------- stubbyboot ------- - (PRO) a straight forward stub loader - (pro) can do measured/secure boot - (CON) doesn't target all required archs - (CON) cross compiling doesn't work. - gcc can't do 32-bit on x86_64 Alpine... - gnu-efi-dev needs to be fixed to package both 32-bit and 64-bit on x86_64... - have patch in ~/src/aports that kinda does it.. but needs to be fixed/finished - maybe limine-efi works with it? - tried, but fails due to missing efilib.h in limine-efi ------- systemd-stub ------- - (PRO) another straight forward stub loader - (PRO) many (many) people using it, as part of systemd-boot - (pro) can do measured/secure boot - (con) requires a fairly recent kernel on aarch w/ efi_zboot support enabled since we compress the kernel - (con) doesn't target all required archs - but does claim to support most... missing armv7.. maybe it works? - (con) will end up maintaining some downstream patch to build it - hopefully the patch (if I can even make a working one!) is not too complex! - (CON) can't be built outside of systemd's silly large build system. - UPDATE: largely resolved this in pmaports - was able to build for native arch! - can't build 32-bit on x86_64, no gcc multilib support in Alpine... Couldn't get clang to work properly, but maybe it can somehow... - https://github.com/mintsuki/libgcc-binaries ? NO! (don't want bootloader binaries that depend on code compiled by microsoft / github...) ------- DIY stub / bootloader ----- - (PRO) **might** target all required archs and other meet requirements - (CON) lots of time required to learn, design, do, debug, test - (CON) lots of time required to learn, design, do, debug, test - (CON) lots of time required to learn, design, do, debug, test - (CON) (get the hint yet???) - (CON) written in C, probably (there's a rust EFI lib, lol...) [ci:skip-build]: Already built successfully in CI
2023-10-06 19:52:53 +00:00
diff --git a/src/boot/efi/efi-string.c b/src/boot/efi/efi-string.c
index 4144c0d497..40e8d1f3b0 100644
main/systemd-boot: new aport (MR 4484) EFI bootloader from systemd, with hacks to build it on Alpine/pmOS. Cross compilation (using a meson cross file) is used for building 32-bit version on x86_64, for systems that have a 32-bit EFI. Everything else assumes that the EFI arch matches the CPU arch. Besides supporting all the archs we need, another major goal was to minimize the number of changes to systemd's build system required to build only the bootloader, so that maintaining/rebasing isn't *too* painful... I am adding this to the "main" category, because I don't think there's a way to add it to Alpine. It requires cross compiling to x86 on x86_64 (to support 32-bit EFI on this arch), and Alpine doesn't support this. It requires stuff in pmaports/cross. --- Research notes --- I started looking at all of this because I wanted to come up with a single way to boot Linux via EFI, that supports all (or as many as possible) devices in pmaports. I looked at quite a few different options, and have some notes below about my observations and conclusions for each. Of everything I looked at, systemd-boot was the clear winner that met the most requirements ("pro" below) with the fewest downsides ("con" below). Using a Unified Kernel Image (UKI) was a close second place, however systemd-boot can also support booting UKI images quite easily (while also giving us more flexibility to boot other things easily too), so I think it wins over UKI. The capitalization (or lack thereof) of the "pro" and "con" markers below is significant: "PRO" / "CON" are major pros or cons for each point (e.g. a major downside that blocks using the option), and "pro"/"con" are minor (e.g. a downside that I'm willing to overlook.) ---- Requirements ---- - Arch support: - x86_64 - x86 (nice to have, but not sure if necessary...) - armv7 - aarch64 - riscv64 - EFI support: - support 32-bit EFI on x86_64 CPU (includes being able to build 32-bit .efi app on x86_64) - Easy to configure - Easy to maintain - Any changes to the bootloader required to get it working in pmOS - Config for it ---- Evaluated options ---- ------ grub ------ - (PRO) can target all required archs - (CON) grub can't be installed in pmb chroot, it calls grub-install and that fails due to something missing in /dev. Maybe this could be worked around in pmb? - (CON) grub-mkimage exe is integrated in grub package, grub-efi depends on grub - don't want to install all of grub just for 1 exe and/or the EFI modules - downsides of installing all of grub is that I think it can mislead users into thinking we use grub the "normal way". this might cause them to have the wrong expectations and break pmOS boot on their system - have POC "fixing" this - I'm not sure upstream Alpine will like this, it's ugly - (CON) grub x86 EFI support for x86_64 is currently in pmaports, that's pretty ugly. - IMHO forking grub (or grub components) for this purpose signals to me that grub is the wrong tool for this job ------- kernel's efistub ------- - (PRO) already included in the kernel, nothing else required - (pro) initrd and dtb can be passed in the kernel cmdline... however.... - (CON) kernel cmdline can only be set at compile time - (con) not all kernels may have EFISTUB set? - (con) can't do measured/secure boot - (con) requires a fairly recent kernel on aarch w/ efi_zboot support enabled since we compress the kernel ------- UKI ------- - (PRO) very simple, 1 file thing - (PRO) supports adding dtb, setting kernel cmdline and so on - (pro) can do measured/secure boot - (CON) requires an EFI stub loader - can't find a stub loader that meets all requirements (other than the one from systemd-boot...) - (con) requires efi-mkuki or dealing with objcopy directly (eww) - (con) requires a fairly recent kernel on aarch w/ efi_zboot support ------- limine ------- - (PRO) easy to install/configure, already have boot-deploy and pmaports patches - (PRO) can be cross compiled easily - evidence is in aports - ...but I couldn't reproduce building aarch64 and riscv64 on x86_64 - (pro) can do measured/secure boot (I think?) - (CON) doesn't target all required archs - can't do "linux boot" on aarch64, only "chainload" - what about using chainload everywhere? - requires using efistub in kernel - what about dtb= and upstream recommendation to not use it except for debug? - no kernel compression support on aarch64 - see efi-stub.txt kernel doc - (CON) vendors libgcc to support cross compilation - probably not a good idea to trust binaries produced in microsoft github's CI for some random project ------- stubbyboot ------- - (PRO) a straight forward stub loader - (pro) can do measured/secure boot - (CON) doesn't target all required archs - (CON) cross compiling doesn't work. - gcc can't do 32-bit on x86_64 Alpine... - gnu-efi-dev needs to be fixed to package both 32-bit and 64-bit on x86_64... - have patch in ~/src/aports that kinda does it.. but needs to be fixed/finished - maybe limine-efi works with it? - tried, but fails due to missing efilib.h in limine-efi ------- systemd-stub ------- - (PRO) another straight forward stub loader - (PRO) many (many) people using it, as part of systemd-boot - (pro) can do measured/secure boot - (con) requires a fairly recent kernel on aarch w/ efi_zboot support enabled since we compress the kernel - (con) doesn't target all required archs - but does claim to support most... missing armv7.. maybe it works? - (con) will end up maintaining some downstream patch to build it - hopefully the patch (if I can even make a working one!) is not too complex! - (CON) can't be built outside of systemd's silly large build system. - UPDATE: largely resolved this in pmaports - was able to build for native arch! - can't build 32-bit on x86_64, no gcc multilib support in Alpine... Couldn't get clang to work properly, but maybe it can somehow... - https://github.com/mintsuki/libgcc-binaries ? NO! (don't want bootloader binaries that depend on code compiled by microsoft / github...) ------- DIY stub / bootloader ----- - (PRO) **might** target all required archs and other meet requirements - (CON) lots of time required to learn, design, do, debug, test - (CON) lots of time required to learn, design, do, debug, test - (CON) lots of time required to learn, design, do, debug, test - (CON) (get the hint yet???) - (CON) written in C, probably (there's a rust EFI lib, lol...) [ci:skip-build]: Already built successfully in CI
2023-10-06 19:52:53 +00:00
--- a/src/boot/efi/efi-string.c
+++ b/src/boot/efi/efi-string.c
@@ -569,7 +569,7 @@ typedef struct {
main/systemd-boot: new aport (MR 4484) EFI bootloader from systemd, with hacks to build it on Alpine/pmOS. Cross compilation (using a meson cross file) is used for building 32-bit version on x86_64, for systems that have a 32-bit EFI. Everything else assumes that the EFI arch matches the CPU arch. Besides supporting all the archs we need, another major goal was to minimize the number of changes to systemd's build system required to build only the bootloader, so that maintaining/rebasing isn't *too* painful... I am adding this to the "main" category, because I don't think there's a way to add it to Alpine. It requires cross compiling to x86 on x86_64 (to support 32-bit EFI on this arch), and Alpine doesn't support this. It requires stuff in pmaports/cross. --- Research notes --- I started looking at all of this because I wanted to come up with a single way to boot Linux via EFI, that supports all (or as many as possible) devices in pmaports. I looked at quite a few different options, and have some notes below about my observations and conclusions for each. Of everything I looked at, systemd-boot was the clear winner that met the most requirements ("pro" below) with the fewest downsides ("con" below). Using a Unified Kernel Image (UKI) was a close second place, however systemd-boot can also support booting UKI images quite easily (while also giving us more flexibility to boot other things easily too), so I think it wins over UKI. The capitalization (or lack thereof) of the "pro" and "con" markers below is significant: "PRO" / "CON" are major pros or cons for each point (e.g. a major downside that blocks using the option), and "pro"/"con" are minor (e.g. a downside that I'm willing to overlook.) ---- Requirements ---- - Arch support: - x86_64 - x86 (nice to have, but not sure if necessary...) - armv7 - aarch64 - riscv64 - EFI support: - support 32-bit EFI on x86_64 CPU (includes being able to build 32-bit .efi app on x86_64) - Easy to configure - Easy to maintain - Any changes to the bootloader required to get it working in pmOS - Config for it ---- Evaluated options ---- ------ grub ------ - (PRO) can target all required archs - (CON) grub can't be installed in pmb chroot, it calls grub-install and that fails due to something missing in /dev. Maybe this could be worked around in pmb? - (CON) grub-mkimage exe is integrated in grub package, grub-efi depends on grub - don't want to install all of grub just for 1 exe and/or the EFI modules - downsides of installing all of grub is that I think it can mislead users into thinking we use grub the "normal way". this might cause them to have the wrong expectations and break pmOS boot on their system - have POC "fixing" this - I'm not sure upstream Alpine will like this, it's ugly - (CON) grub x86 EFI support for x86_64 is currently in pmaports, that's pretty ugly. - IMHO forking grub (or grub components) for this purpose signals to me that grub is the wrong tool for this job ------- kernel's efistub ------- - (PRO) already included in the kernel, nothing else required - (pro) initrd and dtb can be passed in the kernel cmdline... however.... - (CON) kernel cmdline can only be set at compile time - (con) not all kernels may have EFISTUB set? - (con) can't do measured/secure boot - (con) requires a fairly recent kernel on aarch w/ efi_zboot support enabled since we compress the kernel ------- UKI ------- - (PRO) very simple, 1 file thing - (PRO) supports adding dtb, setting kernel cmdline and so on - (pro) can do measured/secure boot - (CON) requires an EFI stub loader - can't find a stub loader that meets all requirements (other than the one from systemd-boot...) - (con) requires efi-mkuki or dealing with objcopy directly (eww) - (con) requires a fairly recent kernel on aarch w/ efi_zboot support ------- limine ------- - (PRO) easy to install/configure, already have boot-deploy and pmaports patches - (PRO) can be cross compiled easily - evidence is in aports - ...but I couldn't reproduce building aarch64 and riscv64 on x86_64 - (pro) can do measured/secure boot (I think?) - (CON) doesn't target all required archs - can't do "linux boot" on aarch64, only "chainload" - what about using chainload everywhere? - requires using efistub in kernel - what about dtb= and upstream recommendation to not use it except for debug? - no kernel compression support on aarch64 - see efi-stub.txt kernel doc - (CON) vendors libgcc to support cross compilation - probably not a good idea to trust binaries produced in microsoft github's CI for some random project ------- stubbyboot ------- - (PRO) a straight forward stub loader - (pro) can do measured/secure boot - (CON) doesn't target all required archs - (CON) cross compiling doesn't work. - gcc can't do 32-bit on x86_64 Alpine... - gnu-efi-dev needs to be fixed to package both 32-bit and 64-bit on x86_64... - have patch in ~/src/aports that kinda does it.. but needs to be fixed/finished - maybe limine-efi works with it? - tried, but fails due to missing efilib.h in limine-efi ------- systemd-stub ------- - (PRO) another straight forward stub loader - (PRO) many (many) people using it, as part of systemd-boot - (pro) can do measured/secure boot - (con) requires a fairly recent kernel on aarch w/ efi_zboot support enabled since we compress the kernel - (con) doesn't target all required archs - but does claim to support most... missing armv7.. maybe it works? - (con) will end up maintaining some downstream patch to build it - hopefully the patch (if I can even make a working one!) is not too complex! - (CON) can't be built outside of systemd's silly large build system. - UPDATE: largely resolved this in pmaports - was able to build for native arch! - can't build 32-bit on x86_64, no gcc multilib support in Alpine... Couldn't get clang to work properly, but maybe it can somehow... - https://github.com/mintsuki/libgcc-binaries ? NO! (don't want bootloader binaries that depend on code compiled by microsoft / github...) ------- DIY stub / bootloader ----- - (PRO) **might** target all required archs and other meet requirements - (CON) lots of time required to learn, design, do, debug, test - (CON) lots of time required to learn, design, do, debug, test - (CON) lots of time required to learn, design, do, debug, test - (CON) (get the hint yet???) - (CON) written in C, probably (there's a rust EFI lib, lol...) [ci:skip-build]: Already built successfully in CI
2023-10-06 19:52:53 +00:00
bool have_field_width;
const char *str;
- const wchar_t *wstr;
+ const uint16_t *wstr;
/* For numbers. */
bool is_signed;
@@ -630,7 +630,7 @@ static bool push_str(FormatContext *ctx, SpecifierContext *sp) {
main/systemd-boot: new aport (MR 4484) EFI bootloader from systemd, with hacks to build it on Alpine/pmOS. Cross compilation (using a meson cross file) is used for building 32-bit version on x86_64, for systems that have a 32-bit EFI. Everything else assumes that the EFI arch matches the CPU arch. Besides supporting all the archs we need, another major goal was to minimize the number of changes to systemd's build system required to build only the bootloader, so that maintaining/rebasing isn't *too* painful... I am adding this to the "main" category, because I don't think there's a way to add it to Alpine. It requires cross compiling to x86 on x86_64 (to support 32-bit EFI on this arch), and Alpine doesn't support this. It requires stuff in pmaports/cross. --- Research notes --- I started looking at all of this because I wanted to come up with a single way to boot Linux via EFI, that supports all (or as many as possible) devices in pmaports. I looked at quite a few different options, and have some notes below about my observations and conclusions for each. Of everything I looked at, systemd-boot was the clear winner that met the most requirements ("pro" below) with the fewest downsides ("con" below). Using a Unified Kernel Image (UKI) was a close second place, however systemd-boot can also support booting UKI images quite easily (while also giving us more flexibility to boot other things easily too), so I think it wins over UKI. The capitalization (or lack thereof) of the "pro" and "con" markers below is significant: "PRO" / "CON" are major pros or cons for each point (e.g. a major downside that blocks using the option), and "pro"/"con" are minor (e.g. a downside that I'm willing to overlook.) ---- Requirements ---- - Arch support: - x86_64 - x86 (nice to have, but not sure if necessary...) - armv7 - aarch64 - riscv64 - EFI support: - support 32-bit EFI on x86_64 CPU (includes being able to build 32-bit .efi app on x86_64) - Easy to configure - Easy to maintain - Any changes to the bootloader required to get it working in pmOS - Config for it ---- Evaluated options ---- ------ grub ------ - (PRO) can target all required archs - (CON) grub can't be installed in pmb chroot, it calls grub-install and that fails due to something missing in /dev. Maybe this could be worked around in pmb? - (CON) grub-mkimage exe is integrated in grub package, grub-efi depends on grub - don't want to install all of grub just for 1 exe and/or the EFI modules - downsides of installing all of grub is that I think it can mislead users into thinking we use grub the "normal way". this might cause them to have the wrong expectations and break pmOS boot on their system - have POC "fixing" this - I'm not sure upstream Alpine will like this, it's ugly - (CON) grub x86 EFI support for x86_64 is currently in pmaports, that's pretty ugly. - IMHO forking grub (or grub components) for this purpose signals to me that grub is the wrong tool for this job ------- kernel's efistub ------- - (PRO) already included in the kernel, nothing else required - (pro) initrd and dtb can be passed in the kernel cmdline... however.... - (CON) kernel cmdline can only be set at compile time - (con) not all kernels may have EFISTUB set? - (con) can't do measured/secure boot - (con) requires a fairly recent kernel on aarch w/ efi_zboot support enabled since we compress the kernel ------- UKI ------- - (PRO) very simple, 1 file thing - (PRO) supports adding dtb, setting kernel cmdline and so on - (pro) can do measured/secure boot - (CON) requires an EFI stub loader - can't find a stub loader that meets all requirements (other than the one from systemd-boot...) - (con) requires efi-mkuki or dealing with objcopy directly (eww) - (con) requires a fairly recent kernel on aarch w/ efi_zboot support ------- limine ------- - (PRO) easy to install/configure, already have boot-deploy and pmaports patches - (PRO) can be cross compiled easily - evidence is in aports - ...but I couldn't reproduce building aarch64 and riscv64 on x86_64 - (pro) can do measured/secure boot (I think?) - (CON) doesn't target all required archs - can't do "linux boot" on aarch64, only "chainload" - what about using chainload everywhere? - requires using efistub in kernel - what about dtb= and upstream recommendation to not use it except for debug? - no kernel compression support on aarch64 - see efi-stub.txt kernel doc - (CON) vendors libgcc to support cross compilation - probably not a good idea to trust binaries produced in microsoft github's CI for some random project ------- stubbyboot ------- - (PRO) a straight forward stub loader - (pro) can do measured/secure boot - (CON) doesn't target all required archs - (CON) cross compiling doesn't work. - gcc can't do 32-bit on x86_64 Alpine... - gnu-efi-dev needs to be fixed to package both 32-bit and 64-bit on x86_64... - have patch in ~/src/aports that kinda does it.. but needs to be fixed/finished - maybe limine-efi works with it? - tried, but fails due to missing efilib.h in limine-efi ------- systemd-stub ------- - (PRO) another straight forward stub loader - (PRO) many (many) people using it, as part of systemd-boot - (pro) can do measured/secure boot - (con) requires a fairly recent kernel on aarch w/ efi_zboot support enabled since we compress the kernel - (con) doesn't target all required archs - but does claim to support most... missing armv7.. maybe it works? - (con) will end up maintaining some downstream patch to build it - hopefully the patch (if I can even make a working one!) is not too complex! - (CON) can't be built outside of systemd's silly large build system. - UPDATE: largely resolved this in pmaports - was able to build for native arch! - can't build 32-bit on x86_64, no gcc multilib support in Alpine... Couldn't get clang to work properly, but maybe it can somehow... - https://github.com/mintsuki/libgcc-binaries ? NO! (don't want bootloader binaries that depend on code compiled by microsoft / github...) ------- DIY stub / bootloader ----- - (PRO) **might** target all required archs and other meet requirements - (CON) lots of time required to learn, design, do, debug, test - (CON) lots of time required to learn, design, do, debug, test - (CON) lots of time required to learn, design, do, debug, test - (CON) (get the hint yet???) - (CON) written in C, probably (there's a rust EFI lib, lol...) [ci:skip-build]: Already built successfully in CI
2023-10-06 19:52:53 +00:00
push_padding(ctx, ' ', sp->padded_len);
/* In userspace unit tests we cannot just memcpy() the wide string. */
- if (sp->wstr && sizeof(wchar_t) == sizeof(char16_t)) {
+ if (sp->wstr && sizeof(uint16_t) == sizeof(char16_t)) {
memcpy(ctx->buf + ctx->n, sp->wstr, sp->len * sizeof(*sp->wstr));
ctx->n += sp->len;
} else {
@@ -724,7 +724,7 @@ static bool handle_format_specifier(FormatContext *ctx, SpecifierContext *sp) {
main/systemd-boot: new aport (MR 4484) EFI bootloader from systemd, with hacks to build it on Alpine/pmOS. Cross compilation (using a meson cross file) is used for building 32-bit version on x86_64, for systems that have a 32-bit EFI. Everything else assumes that the EFI arch matches the CPU arch. Besides supporting all the archs we need, another major goal was to minimize the number of changes to systemd's build system required to build only the bootloader, so that maintaining/rebasing isn't *too* painful... I am adding this to the "main" category, because I don't think there's a way to add it to Alpine. It requires cross compiling to x86 on x86_64 (to support 32-bit EFI on this arch), and Alpine doesn't support this. It requires stuff in pmaports/cross. --- Research notes --- I started looking at all of this because I wanted to come up with a single way to boot Linux via EFI, that supports all (or as many as possible) devices in pmaports. I looked at quite a few different options, and have some notes below about my observations and conclusions for each. Of everything I looked at, systemd-boot was the clear winner that met the most requirements ("pro" below) with the fewest downsides ("con" below). Using a Unified Kernel Image (UKI) was a close second place, however systemd-boot can also support booting UKI images quite easily (while also giving us more flexibility to boot other things easily too), so I think it wins over UKI. The capitalization (or lack thereof) of the "pro" and "con" markers below is significant: "PRO" / "CON" are major pros or cons for each point (e.g. a major downside that blocks using the option), and "pro"/"con" are minor (e.g. a downside that I'm willing to overlook.) ---- Requirements ---- - Arch support: - x86_64 - x86 (nice to have, but not sure if necessary...) - armv7 - aarch64 - riscv64 - EFI support: - support 32-bit EFI on x86_64 CPU (includes being able to build 32-bit .efi app on x86_64) - Easy to configure - Easy to maintain - Any changes to the bootloader required to get it working in pmOS - Config for it ---- Evaluated options ---- ------ grub ------ - (PRO) can target all required archs - (CON) grub can't be installed in pmb chroot, it calls grub-install and that fails due to something missing in /dev. Maybe this could be worked around in pmb? - (CON) grub-mkimage exe is integrated in grub package, grub-efi depends on grub - don't want to install all of grub just for 1 exe and/or the EFI modules - downsides of installing all of grub is that I think it can mislead users into thinking we use grub the "normal way". this might cause them to have the wrong expectations and break pmOS boot on their system - have POC "fixing" this - I'm not sure upstream Alpine will like this, it's ugly - (CON) grub x86 EFI support for x86_64 is currently in pmaports, that's pretty ugly. - IMHO forking grub (or grub components) for this purpose signals to me that grub is the wrong tool for this job ------- kernel's efistub ------- - (PRO) already included in the kernel, nothing else required - (pro) initrd and dtb can be passed in the kernel cmdline... however.... - (CON) kernel cmdline can only be set at compile time - (con) not all kernels may have EFISTUB set? - (con) can't do measured/secure boot - (con) requires a fairly recent kernel on aarch w/ efi_zboot support enabled since we compress the kernel ------- UKI ------- - (PRO) very simple, 1 file thing - (PRO) supports adding dtb, setting kernel cmdline and so on - (pro) can do measured/secure boot - (CON) requires an EFI stub loader - can't find a stub loader that meets all requirements (other than the one from systemd-boot...) - (con) requires efi-mkuki or dealing with objcopy directly (eww) - (con) requires a fairly recent kernel on aarch w/ efi_zboot support ------- limine ------- - (PRO) easy to install/configure, already have boot-deploy and pmaports patches - (PRO) can be cross compiled easily - evidence is in aports - ...but I couldn't reproduce building aarch64 and riscv64 on x86_64 - (pro) can do measured/secure boot (I think?) - (CON) doesn't target all required archs - can't do "linux boot" on aarch64, only "chainload" - what about using chainload everywhere? - requires using efistub in kernel - what about dtb= and upstream recommendation to not use it except for debug? - no kernel compression support on aarch64 - see efi-stub.txt kernel doc - (CON) vendors libgcc to support cross compilation - probably not a good idea to trust binaries produced in microsoft github's CI for some random project ------- stubbyboot ------- - (PRO) a straight forward stub loader - (pro) can do measured/secure boot - (CON) doesn't target all required archs - (CON) cross compiling doesn't work. - gcc can't do 32-bit on x86_64 Alpine... - gnu-efi-dev needs to be fixed to package both 32-bit and 64-bit on x86_64... - have patch in ~/src/aports that kinda does it.. but needs to be fixed/finished - maybe limine-efi works with it? - tried, but fails due to missing efilib.h in limine-efi ------- systemd-stub ------- - (PRO) another straight forward stub loader - (PRO) many (many) people using it, as part of systemd-boot - (pro) can do measured/secure boot - (con) requires a fairly recent kernel on aarch w/ efi_zboot support enabled since we compress the kernel - (con) doesn't target all required archs - but does claim to support most... missing armv7.. maybe it works? - (con) will end up maintaining some downstream patch to build it - hopefully the patch (if I can even make a working one!) is not too complex! - (CON) can't be built outside of systemd's silly large build system. - UPDATE: largely resolved this in pmaports - was able to build for native arch! - can't build 32-bit on x86_64, no gcc multilib support in Alpine... Couldn't get clang to work properly, but maybe it can somehow... - https://github.com/mintsuki/libgcc-binaries ? NO! (don't want bootloader binaries that depend on code compiled by microsoft / github...) ------- DIY stub / bootloader ----- - (PRO) **might** target all required archs and other meet requirements - (CON) lots of time required to learn, design, do, debug, test - (CON) lots of time required to learn, design, do, debug, test - (CON) lots of time required to learn, design, do, debug, test - (CON) (get the hint yet???) - (CON) written in C, probably (there's a rust EFI lib, lol...) [ci:skip-build]: Already built successfully in CI
2023-10-06 19:52:53 +00:00
* int in vararg functions, which is why we fetch only ints for any such types. The compiler would
* otherwise warn about fetching smaller types. */
assert_cc(sizeof(int) == 4);
- assert_cc(sizeof(wchar_t) <= sizeof(int));
+ assert_cc(sizeof(uint16_t) <= sizeof(int));
assert_cc(sizeof(intmax_t) <= sizeof(long long));
assert(ctx);
@@ -819,13 +819,13 @@ static bool handle_format_specifier(FormatContext *ctx, SpecifierContext *sp) {
main/systemd-boot: new aport (MR 4484) EFI bootloader from systemd, with hacks to build it on Alpine/pmOS. Cross compilation (using a meson cross file) is used for building 32-bit version on x86_64, for systems that have a 32-bit EFI. Everything else assumes that the EFI arch matches the CPU arch. Besides supporting all the archs we need, another major goal was to minimize the number of changes to systemd's build system required to build only the bootloader, so that maintaining/rebasing isn't *too* painful... I am adding this to the "main" category, because I don't think there's a way to add it to Alpine. It requires cross compiling to x86 on x86_64 (to support 32-bit EFI on this arch), and Alpine doesn't support this. It requires stuff in pmaports/cross. --- Research notes --- I started looking at all of this because I wanted to come up with a single way to boot Linux via EFI, that supports all (or as many as possible) devices in pmaports. I looked at quite a few different options, and have some notes below about my observations and conclusions for each. Of everything I looked at, systemd-boot was the clear winner that met the most requirements ("pro" below) with the fewest downsides ("con" below). Using a Unified Kernel Image (UKI) was a close second place, however systemd-boot can also support booting UKI images quite easily (while also giving us more flexibility to boot other things easily too), so I think it wins over UKI. The capitalization (or lack thereof) of the "pro" and "con" markers below is significant: "PRO" / "CON" are major pros or cons for each point (e.g. a major downside that blocks using the option), and "pro"/"con" are minor (e.g. a downside that I'm willing to overlook.) ---- Requirements ---- - Arch support: - x86_64 - x86 (nice to have, but not sure if necessary...) - armv7 - aarch64 - riscv64 - EFI support: - support 32-bit EFI on x86_64 CPU (includes being able to build 32-bit .efi app on x86_64) - Easy to configure - Easy to maintain - Any changes to the bootloader required to get it working in pmOS - Config for it ---- Evaluated options ---- ------ grub ------ - (PRO) can target all required archs - (CON) grub can't be installed in pmb chroot, it calls grub-install and that fails due to something missing in /dev. Maybe this could be worked around in pmb? - (CON) grub-mkimage exe is integrated in grub package, grub-efi depends on grub - don't want to install all of grub just for 1 exe and/or the EFI modules - downsides of installing all of grub is that I think it can mislead users into thinking we use grub the "normal way". this might cause them to have the wrong expectations and break pmOS boot on their system - have POC "fixing" this - I'm not sure upstream Alpine will like this, it's ugly - (CON) grub x86 EFI support for x86_64 is currently in pmaports, that's pretty ugly. - IMHO forking grub (or grub components) for this purpose signals to me that grub is the wrong tool for this job ------- kernel's efistub ------- - (PRO) already included in the kernel, nothing else required - (pro) initrd and dtb can be passed in the kernel cmdline... however.... - (CON) kernel cmdline can only be set at compile time - (con) not all kernels may have EFISTUB set? - (con) can't do measured/secure boot - (con) requires a fairly recent kernel on aarch w/ efi_zboot support enabled since we compress the kernel ------- UKI ------- - (PRO) very simple, 1 file thing - (PRO) supports adding dtb, setting kernel cmdline and so on - (pro) can do measured/secure boot - (CON) requires an EFI stub loader - can't find a stub loader that meets all requirements (other than the one from systemd-boot...) - (con) requires efi-mkuki or dealing with objcopy directly (eww) - (con) requires a fairly recent kernel on aarch w/ efi_zboot support ------- limine ------- - (PRO) easy to install/configure, already have boot-deploy and pmaports patches - (PRO) can be cross compiled easily - evidence is in aports - ...but I couldn't reproduce building aarch64 and riscv64 on x86_64 - (pro) can do measured/secure boot (I think?) - (CON) doesn't target all required archs - can't do "linux boot" on aarch64, only "chainload" - what about using chainload everywhere? - requires using efistub in kernel - what about dtb= and upstream recommendation to not use it except for debug? - no kernel compression support on aarch64 - see efi-stub.txt kernel doc - (CON) vendors libgcc to support cross compilation - probably not a good idea to trust binaries produced in microsoft github's CI for some random project ------- stubbyboot ------- - (PRO) a straight forward stub loader - (pro) can do measured/secure boot - (CON) doesn't target all required archs - (CON) cross compiling doesn't work. - gcc can't do 32-bit on x86_64 Alpine... - gnu-efi-dev needs to be fixed to package both 32-bit and 64-bit on x86_64... - have patch in ~/src/aports that kinda does it.. but needs to be fixed/finished - maybe limine-efi works with it? - tried, but fails due to missing efilib.h in limine-efi ------- systemd-stub ------- - (PRO) another straight forward stub loader - (PRO) many (many) people using it, as part of systemd-boot - (pro) can do measured/secure boot - (con) requires a fairly recent kernel on aarch w/ efi_zboot support enabled since we compress the kernel - (con) doesn't target all required archs - but does claim to support most... missing armv7.. maybe it works? - (con) will end up maintaining some downstream patch to build it - hopefully the patch (if I can even make a working one!) is not too complex! - (CON) can't be built outside of systemd's silly large build system. - UPDATE: largely resolved this in pmaports - was able to build for native arch! - can't build 32-bit on x86_64, no gcc multilib support in Alpine... Couldn't get clang to work properly, but maybe it can somehow... - https://github.com/mintsuki/libgcc-binaries ? NO! (don't want bootloader binaries that depend on code compiled by microsoft / github...) ------- DIY stub / bootloader ----- - (PRO) **might** target all required archs and other meet requirements - (CON) lots of time required to learn, design, do, debug, test - (CON) lots of time required to learn, design, do, debug, test - (CON) lots of time required to learn, design, do, debug, test - (CON) (get the hint yet???) - (CON) written in C, probably (there's a rust EFI lib, lol...) [ci:skip-build]: Already built successfully in CI
2023-10-06 19:52:53 +00:00
return push_str(ctx, sp);
case 'c':
- sp->wstr = &(wchar_t){ va_arg(ctx->ap, int) };
+ sp->wstr = &(uint16_t){ va_arg(ctx->ap, int) };
sp->len = 1;
return push_str(ctx, sp);
case 's':
if (sp->long_arg) {
- sp->wstr = va_arg(ctx->ap, const wchar_t *) ?: L"(null)";
+ sp->wstr = va_arg(ctx->ap, const uint16_t *) ?: L"(null)";
sp->len = wcsnlen(sp->wstr, sp->len);
} else {
sp->str = va_arg(ctx->ap, const char *) ?: "(null)";
diff --git a/src/boot/efi/efi.h b/src/boot/efi/efi.h
index fbc5d10565..23ccdc5dd5 100644
main/systemd-boot: new aport (MR 4484) EFI bootloader from systemd, with hacks to build it on Alpine/pmOS. Cross compilation (using a meson cross file) is used for building 32-bit version on x86_64, for systems that have a 32-bit EFI. Everything else assumes that the EFI arch matches the CPU arch. Besides supporting all the archs we need, another major goal was to minimize the number of changes to systemd's build system required to build only the bootloader, so that maintaining/rebasing isn't *too* painful... I am adding this to the "main" category, because I don't think there's a way to add it to Alpine. It requires cross compiling to x86 on x86_64 (to support 32-bit EFI on this arch), and Alpine doesn't support this. It requires stuff in pmaports/cross. --- Research notes --- I started looking at all of this because I wanted to come up with a single way to boot Linux via EFI, that supports all (or as many as possible) devices in pmaports. I looked at quite a few different options, and have some notes below about my observations and conclusions for each. Of everything I looked at, systemd-boot was the clear winner that met the most requirements ("pro" below) with the fewest downsides ("con" below). Using a Unified Kernel Image (UKI) was a close second place, however systemd-boot can also support booting UKI images quite easily (while also giving us more flexibility to boot other things easily too), so I think it wins over UKI. The capitalization (or lack thereof) of the "pro" and "con" markers below is significant: "PRO" / "CON" are major pros or cons for each point (e.g. a major downside that blocks using the option), and "pro"/"con" are minor (e.g. a downside that I'm willing to overlook.) ---- Requirements ---- - Arch support: - x86_64 - x86 (nice to have, but not sure if necessary...) - armv7 - aarch64 - riscv64 - EFI support: - support 32-bit EFI on x86_64 CPU (includes being able to build 32-bit .efi app on x86_64) - Easy to configure - Easy to maintain - Any changes to the bootloader required to get it working in pmOS - Config for it ---- Evaluated options ---- ------ grub ------ - (PRO) can target all required archs - (CON) grub can't be installed in pmb chroot, it calls grub-install and that fails due to something missing in /dev. Maybe this could be worked around in pmb? - (CON) grub-mkimage exe is integrated in grub package, grub-efi depends on grub - don't want to install all of grub just for 1 exe and/or the EFI modules - downsides of installing all of grub is that I think it can mislead users into thinking we use grub the "normal way". this might cause them to have the wrong expectations and break pmOS boot on their system - have POC "fixing" this - I'm not sure upstream Alpine will like this, it's ugly - (CON) grub x86 EFI support for x86_64 is currently in pmaports, that's pretty ugly. - IMHO forking grub (or grub components) for this purpose signals to me that grub is the wrong tool for this job ------- kernel's efistub ------- - (PRO) already included in the kernel, nothing else required - (pro) initrd and dtb can be passed in the kernel cmdline... however.... - (CON) kernel cmdline can only be set at compile time - (con) not all kernels may have EFISTUB set? - (con) can't do measured/secure boot - (con) requires a fairly recent kernel on aarch w/ efi_zboot support enabled since we compress the kernel ------- UKI ------- - (PRO) very simple, 1 file thing - (PRO) supports adding dtb, setting kernel cmdline and so on - (pro) can do measured/secure boot - (CON) requires an EFI stub loader - can't find a stub loader that meets all requirements (other than the one from systemd-boot...) - (con) requires efi-mkuki or dealing with objcopy directly (eww) - (con) requires a fairly recent kernel on aarch w/ efi_zboot support ------- limine ------- - (PRO) easy to install/configure, already have boot-deploy and pmaports patches - (PRO) can be cross compiled easily - evidence is in aports - ...but I couldn't reproduce building aarch64 and riscv64 on x86_64 - (pro) can do measured/secure boot (I think?) - (CON) doesn't target all required archs - can't do "linux boot" on aarch64, only "chainload" - what about using chainload everywhere? - requires using efistub in kernel - what about dtb= and upstream recommendation to not use it except for debug? - no kernel compression support on aarch64 - see efi-stub.txt kernel doc - (CON) vendors libgcc to support cross compilation - probably not a good idea to trust binaries produced in microsoft github's CI for some random project ------- stubbyboot ------- - (PRO) a straight forward stub loader - (pro) can do measured/secure boot - (CON) doesn't target all required archs - (CON) cross compiling doesn't work. - gcc can't do 32-bit on x86_64 Alpine... - gnu-efi-dev needs to be fixed to package both 32-bit and 64-bit on x86_64... - have patch in ~/src/aports that kinda does it.. but needs to be fixed/finished - maybe limine-efi works with it? - tried, but fails due to missing efilib.h in limine-efi ------- systemd-stub ------- - (PRO) another straight forward stub loader - (PRO) many (many) people using it, as part of systemd-boot - (pro) can do measured/secure boot - (con) requires a fairly recent kernel on aarch w/ efi_zboot support enabled since we compress the kernel - (con) doesn't target all required archs - but does claim to support most... missing armv7.. maybe it works? - (con) will end up maintaining some downstream patch to build it - hopefully the patch (if I can even make a working one!) is not too complex! - (CON) can't be built outside of systemd's silly large build system. - UPDATE: largely resolved this in pmaports - was able to build for native arch! - can't build 32-bit on x86_64, no gcc multilib support in Alpine... Couldn't get clang to work properly, but maybe it can somehow... - https://github.com/mintsuki/libgcc-binaries ? NO! (don't want bootloader binaries that depend on code compiled by microsoft / github...) ------- DIY stub / bootloader ----- - (PRO) **might** target all required archs and other meet requirements - (CON) lots of time required to learn, design, do, debug, test - (CON) lots of time required to learn, design, do, debug, test - (CON) lots of time required to learn, design, do, debug, test - (CON) (get the hint yet???) - (CON) written in C, probably (there's a rust EFI lib, lol...) [ci:skip-build]: Already built successfully in CI
2023-10-06 19:52:53 +00:00
--- a/src/boot/efi/efi.h
+++ b/src/boot/efi/efi.h
@@ -10,7 +10,7 @@
#if SD_BOOT
/* uchar.h/wchar.h are not suitable for freestanding environments. */
-typedef __WCHAR_TYPE__ wchar_t;
+typedef __WCHAR_TYPE__ uint16_t;
typedef __CHAR16_TYPE__ char16_t;
typedef __CHAR32_TYPE__ char32_t;
@@ -22,7 +22,6 @@ assert_cc(sizeof(uint8_t) == 1);
main/systemd-boot: new aport (MR 4484) EFI bootloader from systemd, with hacks to build it on Alpine/pmOS. Cross compilation (using a meson cross file) is used for building 32-bit version on x86_64, for systems that have a 32-bit EFI. Everything else assumes that the EFI arch matches the CPU arch. Besides supporting all the archs we need, another major goal was to minimize the number of changes to systemd's build system required to build only the bootloader, so that maintaining/rebasing isn't *too* painful... I am adding this to the "main" category, because I don't think there's a way to add it to Alpine. It requires cross compiling to x86 on x86_64 (to support 32-bit EFI on this arch), and Alpine doesn't support this. It requires stuff in pmaports/cross. --- Research notes --- I started looking at all of this because I wanted to come up with a single way to boot Linux via EFI, that supports all (or as many as possible) devices in pmaports. I looked at quite a few different options, and have some notes below about my observations and conclusions for each. Of everything I looked at, systemd-boot was the clear winner that met the most requirements ("pro" below) with the fewest downsides ("con" below). Using a Unified Kernel Image (UKI) was a close second place, however systemd-boot can also support booting UKI images quite easily (while also giving us more flexibility to boot other things easily too), so I think it wins over UKI. The capitalization (or lack thereof) of the "pro" and "con" markers below is significant: "PRO" / "CON" are major pros or cons for each point (e.g. a major downside that blocks using the option), and "pro"/"con" are minor (e.g. a downside that I'm willing to overlook.) ---- Requirements ---- - Arch support: - x86_64 - x86 (nice to have, but not sure if necessary...) - armv7 - aarch64 - riscv64 - EFI support: - support 32-bit EFI on x86_64 CPU (includes being able to build 32-bit .efi app on x86_64) - Easy to configure - Easy to maintain - Any changes to the bootloader required to get it working in pmOS - Config for it ---- Evaluated options ---- ------ grub ------ - (PRO) can target all required archs - (CON) grub can't be installed in pmb chroot, it calls grub-install and that fails due to something missing in /dev. Maybe this could be worked around in pmb? - (CON) grub-mkimage exe is integrated in grub package, grub-efi depends on grub - don't want to install all of grub just for 1 exe and/or the EFI modules - downsides of installing all of grub is that I think it can mislead users into thinking we use grub the "normal way". this might cause them to have the wrong expectations and break pmOS boot on their system - have POC "fixing" this - I'm not sure upstream Alpine will like this, it's ugly - (CON) grub x86 EFI support for x86_64 is currently in pmaports, that's pretty ugly. - IMHO forking grub (or grub components) for this purpose signals to me that grub is the wrong tool for this job ------- kernel's efistub ------- - (PRO) already included in the kernel, nothing else required - (pro) initrd and dtb can be passed in the kernel cmdline... however.... - (CON) kernel cmdline can only be set at compile time - (con) not all kernels may have EFISTUB set? - (con) can't do measured/secure boot - (con) requires a fairly recent kernel on aarch w/ efi_zboot support enabled since we compress the kernel ------- UKI ------- - (PRO) very simple, 1 file thing - (PRO) supports adding dtb, setting kernel cmdline and so on - (pro) can do measured/secure boot - (CON) requires an EFI stub loader - can't find a stub loader that meets all requirements (other than the one from systemd-boot...) - (con) requires efi-mkuki or dealing with objcopy directly (eww) - (con) requires a fairly recent kernel on aarch w/ efi_zboot support ------- limine ------- - (PRO) easy to install/configure, already have boot-deploy and pmaports patches - (PRO) can be cross compiled easily - evidence is in aports - ...but I couldn't reproduce building aarch64 and riscv64 on x86_64 - (pro) can do measured/secure boot (I think?) - (CON) doesn't target all required archs - can't do "linux boot" on aarch64, only "chainload" - what about using chainload everywhere? - requires using efistub in kernel - what about dtb= and upstream recommendation to not use it except for debug? - no kernel compression support on aarch64 - see efi-stub.txt kernel doc - (CON) vendors libgcc to support cross compilation - probably not a good idea to trust binaries produced in microsoft github's CI for some random project ------- stubbyboot ------- - (PRO) a straight forward stub loader - (pro) can do measured/secure boot - (CON) doesn't target all required archs - (CON) cross compiling doesn't work. - gcc can't do 32-bit on x86_64 Alpine... - gnu-efi-dev needs to be fixed to package both 32-bit and 64-bit on x86_64... - have patch in ~/src/aports that kinda does it.. but needs to be fixed/finished - maybe limine-efi works with it? - tried, but fails due to missing efilib.h in limine-efi ------- systemd-stub ------- - (PRO) another straight forward stub loader - (PRO) many (many) people using it, as part of systemd-boot - (pro) can do measured/secure boot - (con) requires a fairly recent kernel on aarch w/ efi_zboot support enabled since we compress the kernel - (con) doesn't target all required archs - but does claim to support most... missing armv7.. maybe it works? - (con) will end up maintaining some downstream patch to build it - hopefully the patch (if I can even make a working one!) is not too complex! - (CON) can't be built outside of systemd's silly large build system. - UPDATE: largely resolved this in pmaports - was able to build for native arch! - can't build 32-bit on x86_64, no gcc multilib support in Alpine... Couldn't get clang to work properly, but maybe it can somehow... - https://github.com/mintsuki/libgcc-binaries ? NO! (don't want bootloader binaries that depend on code compiled by microsoft / github...) ------- DIY stub / bootloader ----- - (PRO) **might** target all required archs and other meet requirements - (CON) lots of time required to learn, design, do, debug, test - (CON) lots of time required to learn, design, do, debug, test - (CON) lots of time required to learn, design, do, debug, test - (CON) (get the hint yet???) - (CON) written in C, probably (there's a rust EFI lib, lol...) [ci:skip-build]: Already built successfully in CI
2023-10-06 19:52:53 +00:00
assert_cc(sizeof(uint16_t) == 2);
assert_cc(sizeof(uint32_t) == 4);
assert_cc(sizeof(uint64_t) == 8);
-assert_cc(sizeof(wchar_t) == 2);
assert_cc(sizeof(char16_t) == 2);
assert_cc(sizeof(char32_t) == 4);
assert_cc(sizeof(size_t) == sizeof(void *));
@@ -32,7 +31,6 @@ assert_cc(alignof(uint8_t) == 1);
assert_cc(alignof(uint16_t) == 2);
assert_cc(alignof(uint32_t) == 4);
assert_cc(alignof(uint64_t) == 8);
-assert_cc(alignof(wchar_t) == 2);
assert_cc(alignof(char16_t) == 2);
assert_cc(alignof(char32_t) == 4);
@@ -41,7 +39,6 @@ assert_cc(alignof(char32_t) == 4);
main/systemd-boot: new aport (MR 4484) EFI bootloader from systemd, with hacks to build it on Alpine/pmOS. Cross compilation (using a meson cross file) is used for building 32-bit version on x86_64, for systems that have a 32-bit EFI. Everything else assumes that the EFI arch matches the CPU arch. Besides supporting all the archs we need, another major goal was to minimize the number of changes to systemd's build system required to build only the bootloader, so that maintaining/rebasing isn't *too* painful... I am adding this to the "main" category, because I don't think there's a way to add it to Alpine. It requires cross compiling to x86 on x86_64 (to support 32-bit EFI on this arch), and Alpine doesn't support this. It requires stuff in pmaports/cross. --- Research notes --- I started looking at all of this because I wanted to come up with a single way to boot Linux via EFI, that supports all (or as many as possible) devices in pmaports. I looked at quite a few different options, and have some notes below about my observations and conclusions for each. Of everything I looked at, systemd-boot was the clear winner that met the most requirements ("pro" below) with the fewest downsides ("con" below). Using a Unified Kernel Image (UKI) was a close second place, however systemd-boot can also support booting UKI images quite easily (while also giving us more flexibility to boot other things easily too), so I think it wins over UKI. The capitalization (or lack thereof) of the "pro" and "con" markers below is significant: "PRO" / "CON" are major pros or cons for each point (e.g. a major downside that blocks using the option), and "pro"/"con" are minor (e.g. a downside that I'm willing to overlook.) ---- Requirements ---- - Arch support: - x86_64 - x86 (nice to have, but not sure if necessary...) - armv7 - aarch64 - riscv64 - EFI support: - support 32-bit EFI on x86_64 CPU (includes being able to build 32-bit .efi app on x86_64) - Easy to configure - Easy to maintain - Any changes to the bootloader required to get it working in pmOS - Config for it ---- Evaluated options ---- ------ grub ------ - (PRO) can target all required archs - (CON) grub can't be installed in pmb chroot, it calls grub-install and that fails due to something missing in /dev. Maybe this could be worked around in pmb? - (CON) grub-mkimage exe is integrated in grub package, grub-efi depends on grub - don't want to install all of grub just for 1 exe and/or the EFI modules - downsides of installing all of grub is that I think it can mislead users into thinking we use grub the "normal way". this might cause them to have the wrong expectations and break pmOS boot on their system - have POC "fixing" this - I'm not sure upstream Alpine will like this, it's ugly - (CON) grub x86 EFI support for x86_64 is currently in pmaports, that's pretty ugly. - IMHO forking grub (or grub components) for this purpose signals to me that grub is the wrong tool for this job ------- kernel's efistub ------- - (PRO) already included in the kernel, nothing else required - (pro) initrd and dtb can be passed in the kernel cmdline... however.... - (CON) kernel cmdline can only be set at compile time - (con) not all kernels may have EFISTUB set? - (con) can't do measured/secure boot - (con) requires a fairly recent kernel on aarch w/ efi_zboot support enabled since we compress the kernel ------- UKI ------- - (PRO) very simple, 1 file thing - (PRO) supports adding dtb, setting kernel cmdline and so on - (pro) can do measured/secure boot - (CON) requires an EFI stub loader - can't find a stub loader that meets all requirements (other than the one from systemd-boot...) - (con) requires efi-mkuki or dealing with objcopy directly (eww) - (con) requires a fairly recent kernel on aarch w/ efi_zboot support ------- limine ------- - (PRO) easy to install/configure, already have boot-deploy and pmaports patches - (PRO) can be cross compiled easily - evidence is in aports - ...but I couldn't reproduce building aarch64 and riscv64 on x86_64 - (pro) can do measured/secure boot (I think?) - (CON) doesn't target all required archs - can't do "linux boot" on aarch64, only "chainload" - what about using chainload everywhere? - requires using efistub in kernel - what about dtb= and upstream recommendation to not use it except for debug? - no kernel compression support on aarch64 - see efi-stub.txt kernel doc - (CON) vendors libgcc to support cross compilation - probably not a good idea to trust binaries produced in microsoft github's CI for some random project ------- stubbyboot ------- - (PRO) a straight forward stub loader - (pro) can do measured/secure boot - (CON) doesn't target all required archs - (CON) cross compiling doesn't work. - gcc can't do 32-bit on x86_64 Alpine... - gnu-efi-dev needs to be fixed to package both 32-bit and 64-bit on x86_64... - have patch in ~/src/aports that kinda does it.. but needs to be fixed/finished - maybe limine-efi works with it? - tried, but fails due to missing efilib.h in limine-efi ------- systemd-stub ------- - (PRO) another straight forward stub loader - (PRO) many (many) people using it, as part of systemd-boot - (pro) can do measured/secure boot - (con) requires a fairly recent kernel on aarch w/ efi_zboot support enabled since we compress the kernel - (con) doesn't target all required archs - but does claim to support most... missing armv7.. maybe it works? - (con) will end up maintaining some downstream patch to build it - hopefully the patch (if I can even make a working one!) is not too complex! - (CON) can't be built outside of systemd's silly large build system. - UPDATE: largely resolved this in pmaports - was able to build for native arch! - can't build 32-bit on x86_64, no gcc multilib support in Alpine... Couldn't get clang to work properly, but maybe it can somehow... - https://github.com/mintsuki/libgcc-binaries ? NO! (don't want bootloader binaries that depend on code compiled by microsoft / github...) ------- DIY stub / bootloader ----- - (PRO) **might** target all required archs and other meet requirements - (CON) lots of time required to learn, design, do, debug, test - (CON) lots of time required to learn, design, do, debug, test - (CON) lots of time required to learn, design, do, debug, test - (CON) (get the hint yet???) - (CON) written in C, probably (there's a rust EFI lib, lol...) [ci:skip-build]: Already built successfully in CI
2023-10-06 19:52:53 +00:00
# endif
#else
# include <uchar.h>
-# include <wchar.h>
#endif
/* We use size_t/ssize_t to represent UEFI UINTN/INTN. */
--
2.43.0
main/systemd-boot: new aport (MR 4484) EFI bootloader from systemd, with hacks to build it on Alpine/pmOS. Cross compilation (using a meson cross file) is used for building 32-bit version on x86_64, for systems that have a 32-bit EFI. Everything else assumes that the EFI arch matches the CPU arch. Besides supporting all the archs we need, another major goal was to minimize the number of changes to systemd's build system required to build only the bootloader, so that maintaining/rebasing isn't *too* painful... I am adding this to the "main" category, because I don't think there's a way to add it to Alpine. It requires cross compiling to x86 on x86_64 (to support 32-bit EFI on this arch), and Alpine doesn't support this. It requires stuff in pmaports/cross. --- Research notes --- I started looking at all of this because I wanted to come up with a single way to boot Linux via EFI, that supports all (or as many as possible) devices in pmaports. I looked at quite a few different options, and have some notes below about my observations and conclusions for each. Of everything I looked at, systemd-boot was the clear winner that met the most requirements ("pro" below) with the fewest downsides ("con" below). Using a Unified Kernel Image (UKI) was a close second place, however systemd-boot can also support booting UKI images quite easily (while also giving us more flexibility to boot other things easily too), so I think it wins over UKI. The capitalization (or lack thereof) of the "pro" and "con" markers below is significant: "PRO" / "CON" are major pros or cons for each point (e.g. a major downside that blocks using the option), and "pro"/"con" are minor (e.g. a downside that I'm willing to overlook.) ---- Requirements ---- - Arch support: - x86_64 - x86 (nice to have, but not sure if necessary...) - armv7 - aarch64 - riscv64 - EFI support: - support 32-bit EFI on x86_64 CPU (includes being able to build 32-bit .efi app on x86_64) - Easy to configure - Easy to maintain - Any changes to the bootloader required to get it working in pmOS - Config for it ---- Evaluated options ---- ------ grub ------ - (PRO) can target all required archs - (CON) grub can't be installed in pmb chroot, it calls grub-install and that fails due to something missing in /dev. Maybe this could be worked around in pmb? - (CON) grub-mkimage exe is integrated in grub package, grub-efi depends on grub - don't want to install all of grub just for 1 exe and/or the EFI modules - downsides of installing all of grub is that I think it can mislead users into thinking we use grub the "normal way". this might cause them to have the wrong expectations and break pmOS boot on their system - have POC "fixing" this - I'm not sure upstream Alpine will like this, it's ugly - (CON) grub x86 EFI support for x86_64 is currently in pmaports, that's pretty ugly. - IMHO forking grub (or grub components) for this purpose signals to me that grub is the wrong tool for this job ------- kernel's efistub ------- - (PRO) already included in the kernel, nothing else required - (pro) initrd and dtb can be passed in the kernel cmdline... however.... - (CON) kernel cmdline can only be set at compile time - (con) not all kernels may have EFISTUB set? - (con) can't do measured/secure boot - (con) requires a fairly recent kernel on aarch w/ efi_zboot support enabled since we compress the kernel ------- UKI ------- - (PRO) very simple, 1 file thing - (PRO) supports adding dtb, setting kernel cmdline and so on - (pro) can do measured/secure boot - (CON) requires an EFI stub loader - can't find a stub loader that meets all requirements (other than the one from systemd-boot...) - (con) requires efi-mkuki or dealing with objcopy directly (eww) - (con) requires a fairly recent kernel on aarch w/ efi_zboot support ------- limine ------- - (PRO) easy to install/configure, already have boot-deploy and pmaports patches - (PRO) can be cross compiled easily - evidence is in aports - ...but I couldn't reproduce building aarch64 and riscv64 on x86_64 - (pro) can do measured/secure boot (I think?) - (CON) doesn't target all required archs - can't do "linux boot" on aarch64, only "chainload" - what about using chainload everywhere? - requires using efistub in kernel - what about dtb= and upstream recommendation to not use it except for debug? - no kernel compression support on aarch64 - see efi-stub.txt kernel doc - (CON) vendors libgcc to support cross compilation - probably not a good idea to trust binaries produced in microsoft github's CI for some random project ------- stubbyboot ------- - (PRO) a straight forward stub loader - (pro) can do measured/secure boot - (CON) doesn't target all required archs - (CON) cross compiling doesn't work. - gcc can't do 32-bit on x86_64 Alpine... - gnu-efi-dev needs to be fixed to package both 32-bit and 64-bit on x86_64... - have patch in ~/src/aports that kinda does it.. but needs to be fixed/finished - maybe limine-efi works with it? - tried, but fails due to missing efilib.h in limine-efi ------- systemd-stub ------- - (PRO) another straight forward stub loader - (PRO) many (many) people using it, as part of systemd-boot - (pro) can do measured/secure boot - (con) requires a fairly recent kernel on aarch w/ efi_zboot support enabled since we compress the kernel - (con) doesn't target all required archs - but does claim to support most... missing armv7.. maybe it works? - (con) will end up maintaining some downstream patch to build it - hopefully the patch (if I can even make a working one!) is not too complex! - (CON) can't be built outside of systemd's silly large build system. - UPDATE: largely resolved this in pmaports - was able to build for native arch! - can't build 32-bit on x86_64, no gcc multilib support in Alpine... Couldn't get clang to work properly, but maybe it can somehow... - https://github.com/mintsuki/libgcc-binaries ? NO! (don't want bootloader binaries that depend on code compiled by microsoft / github...) ------- DIY stub / bootloader ----- - (PRO) **might** target all required archs and other meet requirements - (CON) lots of time required to learn, design, do, debug, test - (CON) lots of time required to learn, design, do, debug, test - (CON) lots of time required to learn, design, do, debug, test - (CON) (get the hint yet???) - (CON) written in C, probably (there's a rust EFI lib, lol...) [ci:skip-build]: Already built successfully in CI
2023-10-06 19:52:53 +00:00