Skip to content

Commit

Permalink
configs: apple: Add custom bootcmd to boot from preferred ESP
Browse files Browse the repository at this point in the history
AsahiLinux uses a distinct EFI system partition per OS installation 1).
To boot the intended system u-boot has to prefer the intended partition
for booting. The previous stage bootloader specifies in UUID of the
partition in the device tree as "/chosen/asahi,efi-system-partition".
'apple_bootcmd' reads the UUID from the device tree and uses modified
distro boot scripts to only boot from a partition with a matching UUID.
If it fails it tries to boot from the first USB device.

1: https://github.com/AsahiLinux/docs/wiki/Open-OS-Ecosystem-on-Apple-Silicon-Macs

Signed-off-by: Janne Grunau <j@jannau.net>
  • Loading branch information
jannau authored and marcan committed Aug 2, 2022
1 parent 95eae22 commit 20be5ea
Showing 1 changed file with 44 additions and 1 deletion.
45 changes: 44 additions & 1 deletion include/configs/apple.h
Expand Up @@ -27,8 +27,51 @@

#include <config_distro_bootcmd.h>

#if CONFIG_IS_ENABLED(CMD_NVME) && CONFIG_IS_ENABLED(CMD_USB)
#define BOOTENV_APPLE \
"scan_dev_for_boot_partuuid=" \
"part list ${devtype} ${devnum} -bootable devplist; " \
"env exists devplist || setenv devplist 1; " \
"for distro_bootpart in ${devplist}; do " \
"part uuid ${devtype} ${devnum}:${distro_bootpart} " \
"partuuid; " \
"if test U${partuuid} = U${esp_partuuid} ; then " \
"if fstype ${devtype} " \
"${devnum}:${distro_bootpart} "\
"bootfstype; then " \
"run scan_dev_for_boot; " \
"fi; " \
"fi; " \
"done; " \
"setenv partuuid; " \
"setenv devplist\0" \
"nvme_boot_partuuid=" \
"run nvme_init; " \
"if nvme dev ${devnum}; then " \
"devtype=nvme; run scan_dev_for_boot_partuuid;" \
" fi\0" \
"bootcmd_apple_nvme0=devnum=0; run nvme_boot_partuuid\0" \
"apple_bootcfg=" \
"if fdt addr ${fdtcontroladdr}; then " \
"fdt get value esp_partuuid /chosen asahi,efi-system-partition; "\
"fi\0" \
"apple_bootcmd=" \
"setenv nvme_need_init; run apple_bootcfg; " \
"if test -n ${esp_partuuid}; then " \
"run bootcmd_apple_nvme0; " \
"echo Failed to boot from ESP with UUID ${esp_partuuid}; " \
"echo Trying to boot from USB ...; " \
"fi; " \
"run bootcmd_usb0; " \
"echo Failed to find boot partition `run distro_bootcmd` to boot from any partition\0" \
"bootcmd=run apple_bootcmd\0"
#else
#define BOOTENV_APPLE
#endif

#define CONFIG_EXTRA_ENV_SETTINGS \
ENV_DEVICE_SETTINGS \
BOOTENV
BOOTENV \
BOOTENV_APPLE

#endif

0 comments on commit 20be5ea

Please sign in to comment.