We need to know from what device we are booting in order to save the enviroment in right place
Signed-off-by: Michael Trimarchi <mich...@amarulasolutions.com> --- arch/arm/dts/rk3288-tinker-s-u-boot.dtsi | 1 + arch/arm/mach-rockchip/rk3288/rk3288.c | 46 ++++++++++++++++++++ board/rockchip/tinker_rk3288/tinker-rk3288.c | 41 +++++++++++++++++ configs/tinker-rk3288_defconfig | 2 + configs/tinker-s-rk3288_defconfig | 2 + 5 files changed, 92 insertions(+) diff --git a/arch/arm/dts/rk3288-tinker-s-u-boot.dtsi b/arch/arm/dts/rk3288-tinker-s-u-boot.dtsi index 538593359a..2193127514 100644 --- a/arch/arm/dts/rk3288-tinker-s-u-boot.dtsi +++ b/arch/arm/dts/rk3288-tinker-s-u-boot.dtsi @@ -10,6 +10,7 @@ chosen { u-boot,spl-boot-order = \ "same-as-spl", &sdmmc, &emmc; + u-boot,spl-boot-device = "/dwmmc@ff0f0000"; }; }; diff --git a/arch/arm/mach-rockchip/rk3288/rk3288.c b/arch/arm/mach-rockchip/rk3288/rk3288.c index 987b4e0d58..002d1508e5 100644 --- a/arch/arm/mach-rockchip/rk3288/rk3288.c +++ b/arch/arm/mach-rockchip/rk3288/rk3288.c @@ -3,6 +3,8 @@ * Copyright (c) 2016 Rockchip Electronics Co., Ltd */ #include <common.h> +#include <spl.h> +#include <fdt_support.h> #include <dm.h> #include <env.h> #include <clk.h> @@ -26,6 +28,50 @@ const char * const boot_devices[BROM_LAST_BOOTSOURCE + 1] = { [BROM_BOOTSOURCE_SD] = "/dwmmc@ff0c0000", }; +#if defined(CONFIG_SPL_BUILD) && !defined(CONFIG_TPL_BUILD) +const char *spl_decode_boot_device(u32 boot_device) +{ + int i; + static const struct { + u32 boot_device; + const char *ofpath; + } spl_boot_devices_tbl[] = { + { BOOT_DEVICE_MMC2, "/dwmmc@ff0f0000" }, + { BOOT_DEVICE_MMC1, "/dwmmc@ff0c0000" }, + }; + + for (i = 0; i < ARRAY_SIZE(spl_boot_devices_tbl); ++i) + if (spl_boot_devices_tbl[i].boot_device == boot_device) + return spl_boot_devices_tbl[i].ofpath; + + return NULL; +} + +void spl_perform_fixups(struct spl_image_info *spl_image) +{ + void *blob = (void *)gd->fdt_blob; + const char *boot_ofpath; + int chosen; + + if (!blob) + return; + + boot_ofpath = spl_decode_boot_device(spl_image->boot_device); + if (!boot_ofpath) { + pr_err("%s: could not map boot_device to ofpath\n", __func__); + return; + } + + chosen = fdt_find_or_add_subnode(blob, 0, "chosen"); + if (chosen < 0) { + pr_err("%s: could not find/create '/chosen'\n", __func__); + return; + } + fdt_setprop_string(blob, chosen, + "u-boot,spl-boot-device", boot_ofpath); +} +#endif + #ifdef CONFIG_SPL_BUILD static void configure_l2ctlr(void) { diff --git a/board/rockchip/tinker_rk3288/tinker-rk3288.c b/board/rockchip/tinker_rk3288/tinker-rk3288.c index 6c76c3c25c..66a7394d95 100644 --- a/board/rockchip/tinker_rk3288/tinker-rk3288.c +++ b/board/rockchip/tinker_rk3288/tinker-rk3288.c @@ -9,6 +9,34 @@ #include <i2c_eeprom.h> #include <netdev.h> +static int tinker_boot_device = CONFIG_SYS_MMC_ENV_DEV; + +/* + * Select the boot device according to what was set in spl step + */ +static int setup_boottargets(void) +{ + const char *boot_device = + ofnode_get_chosen_prop("u-boot,spl-boot-device"); + + if (!boot_device) { + debug("%s: /chosen/u-boot,spl-boot-device not set\n", + __func__); + return -1; + } + debug("%s: booted from %s\n", __func__, boot_device); + + if (!strcmp(boot_device, "/dwmmc@ff0f0000")) { + /* eMMC boot device */ + tinker_boot_device = 1; + } else { + /* sdcard boot device */ + tinker_boot_device = 0; + } + + return 0; +} + static int get_ethaddr_from_eeprom(u8 *addr) { int ret; @@ -33,3 +61,16 @@ int rk3288_board_late_init(void) return 0; } + +int misc_init_r(void) +{ + setup_boottargets(); + + return 0; +} + +int mmc_get_env_dev(void) +{ + debug("boot device %d\n", tinker_boot_device); + return tinker_boot_device; +} diff --git a/configs/tinker-rk3288_defconfig b/configs/tinker-rk3288_defconfig index c851a93f31..106e24e8ca 100644 --- a/configs/tinker-rk3288_defconfig +++ b/configs/tinker-rk3288_defconfig @@ -13,7 +13,9 @@ CONFIG_DEBUG_UART=y CONFIG_TPL_SYS_MALLOC_F_LEN=0x4000 CONFIG_SPL_SYS_MALLOC_F_LEN=0x4000 CONFIG_SYS_MALLOC_F_LEN=0x4000 +CONFIG_SPL_OF_LIBFDT=y # CONFIG_ANDROID_BOOT_IMAGE is not set +CONFIG_MISC_INIT_R=y CONFIG_USE_PREBOOT=y CONFIG_SILENT_CONSOLE=y CONFIG_CONSOLE_MUX=y diff --git a/configs/tinker-s-rk3288_defconfig b/configs/tinker-s-rk3288_defconfig index c851a93f31..106e24e8ca 100644 --- a/configs/tinker-s-rk3288_defconfig +++ b/configs/tinker-s-rk3288_defconfig @@ -13,7 +13,9 @@ CONFIG_DEBUG_UART=y CONFIG_TPL_SYS_MALLOC_F_LEN=0x4000 CONFIG_SPL_SYS_MALLOC_F_LEN=0x4000 CONFIG_SYS_MALLOC_F_LEN=0x4000 +CONFIG_SPL_OF_LIBFDT=y # CONFIG_ANDROID_BOOT_IMAGE is not set +CONFIG_MISC_INIT_R=y CONFIG_USE_PREBOOT=y CONFIG_SILENT_CONSOLE=y CONFIG_CONSOLE_MUX=y -- 2.17.1 _______________________________________________ U-Boot mailing list U-Boot@lists.denx.de https://lists.denx.de/listinfo/u-boot