From 59956cf5b49025a523ebfd94921f695a81265ab8 Mon Sep 17 00:00:00 2001 From: Philipp Tomsich Date: Fri, 16 Sep 2016 15:09:16 +0200 Subject: spl: inject '/boot-device' into FDT --- common/spl/spl.c | 45 +++++++++++++++++++++++++++++++++++++-------- common/spl/spl_fit.c | 1 + include/spl.h | 1 + 3 files changed, 39 insertions(+), 8 deletions(-) diff --git a/common/spl/spl.c b/common/spl/spl.c index 82e7f58e80..da10c3b1c5 100644 --- a/common/spl/spl.c +++ b/common/spl/spl.c @@ -249,17 +249,13 @@ struct boot_device_name boot_name_table[] = { { BOOT_DEVICE_NONE, "unknown boot device" }, }; -static void announce_boot_device(u32 boot_device) +static const char* boot_device_name(u32 boot_device) { - int i; - - puts("Trying to boot from "); + int i; #ifdef CONFIG_SPL_BOARD_LOAD_IMAGE if (boot_device == BOOT_DEVICE_BOARD) { - spl_board_announce_boot_device(); - puts("\n"); - return; + return ""; } #endif for (i = 0; i < ARRAY_SIZE(boot_name_table) - 1; i++) { @@ -267,7 +263,12 @@ static void announce_boot_device(u32 boot_device) break; } - printf("%s\n", boot_name_table[i].name); + return boot_name_table[i].name; +} + +static void announce_boot_device(u32 boot_device) +{ + printf("Trying to boot from %s\n", boot_device_name(boot_device)); } #else static inline void announce_boot_device(u32 boot_device) { } @@ -381,6 +382,34 @@ void board_init_r(gd_t *dummy1, ulong dummy2) hang(); } +#ifdef CONFIG_SPL_LIBCOMMON_SUPPORT + if (spl_image.fdt) + { + int err; + int nodeoffset; + + /* I don't feel happy with having a u32 for spl_image.fdt (considering ARMv8)... */ + void* fdt = (void*)spl_image.fdt; + + fdt_set_totalsize(fdt, fdt_totalsize(fdt) + 4096); + nodeoffset = fdt_path_offset(fdt, "/"); + if (nodeoffset < 0) { + debug("FDT postprocess: did not find '/'\n"); + } else { + const char* device_name = boot_device_name(spl_boot_list[i]); + if (device_name) { + err = fdt_setprop(fdt, nodeoffset, "boot-device", + device_name, strlen(device_name) + 1); + + if (err < 0) + debug("ERROR on setprop: %s\n", fdt_strerror(err)); + } + + debug("FDT @ 0x%p\n", fdt); + } + } +#endif + switch (spl_image.os) { case IH_OS_U_BOOT: debug("Jumping to U-Boot\n"); diff --git a/common/spl/spl_fit.c b/common/spl/spl_fit.c index be86072c24..4eecafbea4 100644 --- a/common/spl/spl_fit.c +++ b/common/spl/spl_fit.c @@ -251,6 +251,7 @@ int spl_load_simple_fit(struct spl_load_info *info, ulong sector, void *fit) #endif memcpy(dst, src, fdt_len); + spl_image.fdt = (u32)dst; return 0; } diff --git a/include/spl.h b/include/spl.h index af02a6de9a..701f139d5b 100644 --- a/include/spl.h +++ b/include/spl.h @@ -27,6 +27,7 @@ struct spl_image_info { u32 entry_point; u32 size; u32 flags; + u32 fdt; }; /* -- cgit v1.2.3