Skip to content

Commit 5f0bda0

Browse files
kettenisjannau
authored andcommitted
apple: Set up file system firmware loader
Find the appropriate EFI system partition on the internal NVMe storage and set the U-Boot environment variables such that the file system firmware loader can load firmware from it. Signed-off-by: Mark Kettenis <[email protected]>
1 parent 030d434 commit 5f0bda0

1 file changed

Lines changed: 59 additions & 0 deletions

File tree

arch/arm/mach-apple/board.c

Lines changed: 59 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,8 @@
88
#include <efi_loader.h>
99
#include <env.h>
1010
#include <lmb.h>
11+
#include <nvme.h>
12+
#include <part.h>
1113

1214
#include <asm/armv8/mmu.h>
1315
#include <asm/global_data.h>
@@ -771,6 +773,60 @@ u64 get_page_table_size(void)
771773
return SZ_256K;
772774
}
773775

776+
static char *asahi_esp_devpart(void)
777+
{
778+
struct disk_partition info;
779+
struct blk_desc *nvme_blk;
780+
const char *uuid = NULL;
781+
int devnum, len, p, part, ret;
782+
static char devpart[64];
783+
struct udevice *dev;
784+
ofnode node;
785+
786+
if (devpart[0])
787+
return devpart;
788+
789+
node = ofnode_path("/chosen");
790+
if (ofnode_valid(node)) {
791+
uuid = ofnode_get_property(node, "asahi,efi-system-partition",
792+
&len);
793+
}
794+
795+
nvme_scan_namespace();
796+
for (devnum = 0, part = 0; ; devnum++) {
797+
nvme_blk = blk_get_devnum_by_uclass_id(UCLASS_NVME, devnum);
798+
if (!nvme_blk)
799+
break;
800+
801+
dev = dev_get_parent(nvme_blk->bdev);
802+
if (!device_is_compatible(dev, "apple,nvme-ans2"))
803+
continue;
804+
805+
for (p = 1; p <= MAX_SEARCH_PARTITIONS; p++) {
806+
ret = part_get_info(nvme_blk, p, &info);
807+
if (ret < 0)
808+
break;
809+
810+
if (info.bootable & PART_EFI_SYSTEM_PARTITION) {
811+
if (uuid && strcasecmp(uuid, info.uuid) == 0) {
812+
part = p;
813+
break;
814+
}
815+
if (part == 0)
816+
part = p;
817+
}
818+
}
819+
820+
if (part > 0)
821+
break;
822+
}
823+
824+
if (part > 0)
825+
snprintf(devpart, sizeof(devpart), "%x:%x", devnum, part);
826+
827+
return devpart;
828+
}
829+
774830
#define KERNEL_COMP_SIZE SZ_128M
775831

776832
#define lmb_alloc(size, addr) lmb_alloc_mem(LMB_MEM_ALLOC_ANY, SZ_2M, addr, size, LMB_NONE)
@@ -780,6 +836,9 @@ int board_late_init(void)
780836
u32 status = 0;
781837
phys_addr_t addr;
782838

839+
env_set("storage_interface", blk_get_uclass_name(UCLASS_NVME));
840+
env_set("fw_dev_part", asahi_esp_devpart());
841+
783842
/* somewhat based on the Linux Kernel boot requirements:
784843
* align by 2M and maximal FDT size 2M
785844
*/

0 commit comments

Comments
 (0)