From 102777230b057efa00fe39c7e545e13ddead1177 Mon Sep 17 00:00:00 2001 From: Janne Grunau Date: Sun, 20 Feb 2022 20:48:04 +0100 Subject: [PATCH] configs: apple: Add custom bootcmd to boot from preferred ESP 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 --- include/configs/apple.h | 45 ++++++++++++++++++++++++++++++++++++++++- 1 file changed, 44 insertions(+), 1 deletion(-) diff --git a/include/configs/apple.h b/include/configs/apple.h index b06660add4..8d39e7d076 100644 --- a/include/configs/apple.h +++ b/include/configs/apple.h @@ -27,8 +27,51 @@ #include +#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