Inject boot-device into DTS and use in distro-boot on the RK3399-Q7
Subsystems (3)
cover Inject boot-device into DTS and use in distro-boot on the RK3399-Q7
The RK3399-Q7 has the ability to bypass the on-module eMMC and SPI (which always come first in our boot-order) and force a boot from an external SD card. If this is the case, we want all later boot-stages notified and will modify our environment for distro-boot to also try to boot from the SD card before trying to boot from eMMC.
Klaus Goger (1):
rockchip: rk3399: change boot_target based on u-boot,spl-boot-device
Philipp Tomsich (3):
spl: record boot_device into spl_image and call spl_perform_fixups
spl: document 'chosen/u-boot,spl-boot-device'
rockchip: rk3399: inject 'u-boot,spl-boot-device' for next-stage
arch/arm/mach-rockchip/rk3399-board-spl.c | 48 +++++++++++++++ board/theobroma-systems/puma_rk3399/puma-rk3399.c | 74 +++++++++++++++++++++++ common/spl/spl.c | 12 +++- doc/device-tree-bindings/chosen.txt | 10 +++ include/spl.h | 7 +++ 5 files changed, 150 insertions(+), 1 deletion(-)
Signature · 1 line
2.1.4
PATCH 1/4 spl: record boot_device into spl_image and call spl_perform_fixups
On some boards, we want to give the board/architecture-specific code a chance to look at where the next image has been loaded from and perform fixups before starting the next image. This is of particular importance, when we probe multiple devices for bootable payloads and boot the first one found.
This change adds the following:
- we record the boot_device used into the spl_image structure
- we provide an extension-point for boards/architectures that can perform late fixups depending on a fully populated spl_image structure (i.e. we'll know the final boot_device and have info on the image type and operating system to be booted).
---
common/spl/spl.c | 12 +++++++++++- include/spl.h | 7 +++++++ 2 files changed, 18 insertions(+), 1 deletion(-)
common/spl/spl.c +11 -1
@@ -80,6 +80,11 @@ int __weak bootz_setup(ulong image, ulong *start, ulong *end) }#endif +/* Weak default function for arch/board-specific fixups to the spl_image_info */ +void __weak spl_perform_fixups (struct spl_image_info *spl_image) +{ +} +void spl_fixup_fdt (void ) {#if defined(CONFIG_SPL_OF_LIBFDT ) && defined(CONFIG_SYS_SPL_ARGS_ADDR )
@@ -445,8 +450,10 @@ static int boot_from_devices(struct spl_image_info *spl_image, else puts("SPL: Unsupported Boot Device!\n");#endif -if (loader && !spl_load_image (spl_image, loader)) +if (loader && !spl_load_image (spl_image, loader)) { + spl_image->boot_device = spl_boot_list[i];return 0 ; + } }return -ENODEV ;
@@ -498,6 +505,7 @@ void board_init_r(gd_t *dummy1, ulong dummy2)#ifdef CONFIG_SYS_SPL_ARGS_ADDR spl_image.arg = (void *)CONFIG_SYS_SPL_ARGS_ADDR ;#endif + spl_image.boot_device =BOOT_DEVICE_NONE ;board_boot_order (spl_boot_list); if (boot_from_devices(&spl_image, spl_boot_list,
@@ -506,6 +514,8 @@ void board_init_r(gd_t *dummy1, ulong dummy2)hang (); } +spl_perform_fixups (&spl_image); +#ifdef CONFIG_CPU_V7M spl_image.entry_point |=0x1 ;#endif
include/spl.h +7 -0
@@ -29,6 +29,7 @@ struct spl_image_info {#if CONFIG_IS_ENABLED (LOAD_FIT )void *fdt_addr;#endif +u32 boot_device;u32 size;u32 flags;void *arg;
@@ -296,4 +297,10 @@ void spl_invoke_atf(struct spl_image_info *spl_image);* can implement 'board_return_to_bootrom'. */ void board_return_to_bootrom (void ); + +/** +* spl_perform_fixups() - arch/board-specific callback before processing +* the boot-payload +*/ +void spl_perform_fixups (struct spl_image_info *spl_image);#endif
Signature · 1 line
2.1.4
PATCH 1/4 spl: record boot_device into spl_image and call spl_perform_fixups
Hi Philipp,
Quoted 86 lines
On some boards, we want to give the board/architecture-specific code a chance to look at where the next image has been loaded from and perform fixups before starting the next image. This is of particular importance, when we probe multiple devices for bootable payloads and boot the first one found.
This change adds the following:
- we record theboot_deviceused into thespl_imagestructure
- we provide an extension-point for boards/architectures that can perform late fixups depending on a fully populatedspl_imagestructure (i.e. we'll know the finalboot_deviceand have info on the image type and operating system to be booted).Signed-off-by Philipp Tomsich <[email protected]>Tested-by Klaus Goger <[email protected]>---
common/spl/spl.c | 12 +++++++++++- include/spl.h | 7 +++++++ 2 files changed, 18 insertions(+), 1 deletion(-)common/spl/spl.c +1
-0@@ -80,6 +80,11 @@ int __weak bootz_setup(ulong image, ulong *start, ulong *end) }#endif +/* Weak default function for arch/board-specific fixups to the
spl_image_info*/ +void__weakspl_perform_fixups(struct spl_image_info *spl_image)+{common/spl/spl.c +2
-0+} +void spl_fixup_fdt (void ) { #if defined(CONFIG_SPL_OF_LIBFDT) &&
defined(CONFIG_SYS_SPL_ARGS_ADDR)@@ -445,8 +450,10 @@ static int boot_from_devices(structspl_image_info*spl_image, elsecommon/spl/spl.c +6
-1puts ("SPL: Unsupported Boot Device!\n" );#endif -if (loader && !spl_load_image (spl_image, loader)) +if (loader && !spl_load_image (spl_image, loader)) { + spl_image->boot_device = spl_boot_list[i];return 0 ; + } }return -ENODEV ;@@ -498,6 +505,7 @@ void board_init_r(gd_t *dummy1, ulong dummy2)#ifdef CONFIG_SYS_SPL_ARGS_ADDR spl_image.arg = (void *)CONFIG_SYS_SPL_ARGS_ADDR ;#endif + spl_image.boot_device =BOOT_DEVICE_NONE ;board_boot_order (spl_boot_list); if (boot_from_devices(&spl_image, spl_boot_list,@@ -506,6 +514,8 @@ void board_init_r(gd_t *dummy1, ulong dummy2)hang (); } +spl_perform_fixups (&spl_image); +#ifdef CONFIG_CPU_V7M spl_image.entry_point |=0x1 ;#endif include/spl.h +4
-0@@ -29,6 +29,7 @@ struct spl_image_info {#if CONFIG_IS_ENABLED (LOAD_FIT )void *fdt_addr;#endif +u32 boot_device;u32 size;u32 flags;void *arg;@@ -296,4 +297,10 @@ void spl_invoke_atf(struct spl_image_info*spl_image); * can implement 'board_return_to_bootrom'. */ void board_return_to_bootrom (void ); + +/** +* spl_perform_fixups() - arch/board-specific callback before
Quoted 5 lines
processing
+ * the boot-payload
+ */
+voidspl_perform_fixups(struct spl_image_info *spl_image);
#endif
Have I understood correctly that after applying this patch I can define my own spl_perform_fixup() function in my board's spl.c and then decide if I want to boot kernel/u-boot proper from eMMC, even if I started the boot process from SPI-NOR (where SPL is placed) ?
Best regards,
Lukasz Majewski
--
DENX Software Engineering GmbH, Managing Director: Wolfgang Denk
HRB 165235 Munich, Office: Kirchenstr.5, D-82194 Groebenzell, Germany
Phone: (+49)-8142-66989-10 Fax: (+49)-8142-66989-80 Email: wd at denx.de -------------- next part --------------
A non-text attachment was scrubbed...
Name: not available
Type: application/pgp-signature
Size: 488 bytes
Desc: OpenPGP digital signature
URL: <http://lists.denx.de/pipermail/u-boot/attachments/20180525/cd2eab21/attachment.sig>
PATCH 1/4 spl: record boot_device into spl_image and call spl_perform_fixups
Lukasz,
Quoted 92 lines · Lukasz Majewski
Hi Philipp,
Quoted 88 lines
On some boards, we want to give the board/architecture-specific code a chance to look at where the next image has been loaded from and perform fixups before starting the next image. This is of particular importance, when we probe multiple devices for bootable payloads and boot the first one found.
This change adds the following:
- we record theboot_deviceused into thespl_imagestructure
- we provide an extension-point for boards/architectures that can perform late fixups depending on a fully populatedspl_imagestructure (i.e. we'll know the finalboot_deviceand have info on the image type and operating system to be booted).Signed-off-by Philipp Tomsich <[email protected]>Tested-by Klaus Goger <[email protected]>---
common/spl/spl.c| 12 +++++++++++-include/spl.h| 7 +++++++2 files changed, 18 insertions(+), 1 deletion(-)common/spl/spl.c +1
-0@@ -80,6 +80,11 @@ int __weak bootz_setup(ulong image, ulong *start, ulong *end) }#endif +/* Weak default function for arch/board-specific fixups to the
spl_image_info*/ +void__weakspl_perform_fixups(struct spl_image_info *spl_image)+{common/spl/spl.c +2
-0+} +void
spl_fixup_fdt(void)
{
#ifdefined(CONFIG_SPL_OF_LIBFDT)&&defined(CONFIG_SYS_SPL_ARGS_ADDR)@@ -445,8 +450,10 @@ static int boot_from_devices(structspl_image_info*spl_image, elseputs("SPL: Unsupported Boot Device!\n");#endif
common/spl/spl.c +2
-1-if (loader && !spl_load_image (spl_image, loader)) +if (loader && !spl_load_image (spl_image, loader)) { + spl_image->boot_device = spl_boot_list[i];return 0;common/spl/spl.c +1
-0+ }} return -ENODEV;common/spl/spl.c +3
-0@@ -498,6 +505,7 @@ void board_init_r(gd_t *dummy1, ulong dummy2)#ifdef CONFIG_SYS_SPL_ARGS_ADDR spl_image.arg = (void *)CONFIG_SYS_SPL_ARGS_ADDR ;#endif + spl_image.boot_device =BOOT_DEVICE_NONE ;board_boot_order (spl_boot_list); if (boot_from_devices(&spl_image, spl_boot_list,@@ -506,6 +514,8 @@ void board_init_r(gd_t *dummy1, ulong dummy2)hang (); } +spl_perform_fixups (&spl_image); +#ifdef CONFIG_CPU_V7M spl_image.entry_point |=0x1 ;#endif include/spl.h +4
-0@@ -29,6 +29,7 @@ struct spl_image_info {#if CONFIG_IS_ENABLED (LOAD_FIT )void *fdt_addr;#endif +u32 boot_device;u32 size;u32 flags;void *arg;@@ -296,4 +297,10 @@ void spl_invoke_atf(struct spl_image_info*spl_image); * can implement 'board_return_to_bootrom'. */ void board_return_to_bootrom (void ); + +/** +* spl_perform_fixups() - arch/board-specific callback before processing
+ * the boot-payload
Quoted 8 lines
Quoted 3 lines
+ */
+voidspl_perform_fixups(struct spl_image_info *spl_image); #endifHave I understood correctly that after applying this patch I can define my own
spl_perform_fixup()function in my board'sspl.cand then decide if I want to bootkernel/u-bootproper from eMMC, even if I started the boot process from SPI-NOR (where SPL is placed) ?
Starting from SPI-NOR and then continuing from eMMC is already possible using other mechanisms (e.g. we use FIT images and the boot device list infrastructure)… so no, this is something different.
This was implemented for the full U-Boot to decide where to boot the OS from. Our use-case is that if SPL boots the full U-Boot from external storage, we’d like to continue booting from external storage.
Patches 3 + 4 from the series show an example implementation for our RK3399-Q7:
- patch 3 injects a property into the DTS seen by the full U-Boot stage
- patch 4 uses this to change the order of mmc0 and mmc1 in the env for distroboot
Quoted 11 lines
Best regards,
Lukasz Majewski
--
DENX Software Engineering GmbH, Managing Director: Wolfgang Denk
HRB 165235 Munich, Office: Kirchenstr.5, D-82194 Groebenzell, Germany
Phone: (+49)-8142-66989-10 Fax: (+49)-8142-66989-80 Email: wd at denx.de <mailto:[email protected]>
PATCH 1/4 spl: record boot_device into spl_image and call spl_perform_fixups
In reply to Philipp TomsichQuoted 13 lines
On some boards, we want to give the board/architecture-specific code a chance to look at where the next image has been loaded from and perform fixups before starting the next image. This is of particular importance, when we probe multiple devices for bootable payloads and boot the first one found.
This change adds the following:
- we record theboot_deviceused into thespl_imagestructure
- we provide an extension-point for boards/architectures that can perform late fixups depending on a fully populatedspl_imagestructure (i.e. we'll know the finalboot_deviceand have info on the image type and operating system to be booted).
Quoted 8 lines
Signed-off-by Philipp Tomsich <[email protected]>Tested-by Klaus Goger <[email protected]>---
common/spl/spl.c | 12 +++++++++++- include/spl.h | 7 +++++++ 2 files changed, 18 insertions(+), 1 deletion(-)
Applied to u-boot-rockchip, thanks!
PATCH 2/4 spl: document 'chosen/u-boot, spl-boot-device'
In reply to Philipp TomsichTo let the full U-Boot know where it was booted from (i.e. which of the entries in /chosen/u-boot,spl-boot-order' contained a valid image), we define (and document) /chosen/u-boot,spl-boot-device as the property that could/should automatically be injected by SPL.
This commit only contains a documentation change, which documents the new property and the intended usage.
---
doc/device-tree-bindings/chosen.txt | 10 ++++++++++ 1 file changed, 10 insertions(+)
doc/device-tree-bindings/chosen.txt +10 -0
@@ -73,3 +73,13 @@ Example u-boot,spl-boot-order = "same-as-spl", &sdmmc, "/sdhci at fe330000"; }; }; + +u-boot,spl-boot-device property +------------------------------- + +This property is a companion-property to the u-boot,spl-boot-order and +will be injected automatically by the SPL stage to notify a later stage +of where said later stage was booted from. + +You should not define this property yourself in the device-tree, as it +may be overwritten without warning.
Signature · 1 line
2.1.4
PATCH 2/4 spl: document 'chosen/u-boot, spl-boot-device'
Quoted 8 lines
To let the full U-Boot know where it was booted from (i.e. which of the entries in /chosen/u-boot,spl-boot-order' contained a valid image), we define (and document) /chosen/u-boot,spl-boot-device as the property that could/should automatically be injected by SPL.
This commit only contains a documentation change, which documents the new property and the intended usage.
Quoted 7 lines
Signed-off-by Philipp Tomsich <[email protected]>Tested-by Klaus Goger <[email protected]>---
doc/device-tree-bindings/chosen.txt | 10 ++++++++++ 1 file changed, 10 insertions(+)
Applied to u-boot-rockchip, thanks!
PATCH 3/4 rockchip: rk3399: inject 'u-boot, spl-boot-device' for next-stage
In reply to Philipp TomsichThis implements the new 'spl_perform_fixups' hook for RK3399-based boards and injects the /chosen/u-boot,spl-boot-device with an ofpath corresponding to the boot device used.
The intended usage is for the full U-Boot stage to evaluate this in scripts and then adapt its boot-order when using distro-boot.
---
arch/arm/mach-rockchip/rk3399-board-spl.c | 48 +++++++++++++++++++++++++++++++ 1 file changed, 48 insertions(+)
arch/arm/mach-rockchip/rk3399-board-spl.c +48 -0
@@ -57,6 +57,54 @@ u32 spl_boot_device(void)return boot_device; } +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_MMC1 ,"/dwmmc at fe320000" }, + {BOOT_DEVICE_MMC2 ,"/sdhci at fe330000" }, + {BOOT_DEVICE_SPI ,"/spi at ff1d0000" }, + }; + +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 = spl_image->fdt_addr; +const char *boot_ofpath; +int chosen; + +/* +* Inject the ofpath of the device the full U-Boot (or Linux in +* Falcon-mode) was booted from into the FDT, if a FDT has been +* loaded at the same time. +*/ +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); +} +#define TIMER_CHN10_BASE 0xff8680a0#define TIMER_END_COUNT_L 0x00#define TIMER_END_COUNT_H 0x04
Signature · 1 line
2.1.4
PATCH 3/4 rockchip: rk3399: inject 'u-boot, spl-boot-device' for next-stage
Quoted 7 lines
This implements the new '
spl_perform_fixups' hook for RK3399-based boards and injects the /chosen/u-boot,spl-boot-device with an ofpath corresponding to the boot device used.The intended usage is for the full U-Boot stage to evaluate this in scripts and then adapt its boot-order when using distro-boot.
Quoted 7 lines
Signed-off-by Philipp Tomsich <[email protected]>Tested-by Klaus Goger <[email protected]>---
arch/arm/mach-rockchip/rk3399-board-spl.c | 48 +++++++++++++++++++++++++++++++ 1 file changed, 48 insertions(+)
Applied to u-boot-rockchip, thanks!
PATCH 4/4 rockchip: rk3399: change boot_target based on u-boot, spl-boot-device
In reply to Philipp TomsichFrom: Klaus Goger <[email protected]>
The order distroboot searches for a boot.scr is fixed at compile time. To make BIOS_DISABLE work as expected and boot from mmc1 instead of mmc0 if enabled, we need to change the environment at runtime. Especially as commit: 482cf22333 ("rockchip: rk3399-puma: add boot-on regulator to override BIOS_DISABLE") enables the eMMC in U-Boot even if BIOS_DISABLE is active.
---
board/theobroma-systems/puma_rk3399/puma-rk3399.c | 74 +++++++++++++++++++++++ 1 file changed, 74 insertions(+)
board/theobroma-systems/puma_rk3399/puma-rk3399.c +74 -0
@@ -196,11 +196,85 @@ static void setup_iodomain(void)rk_setreg (&grf->io_vsel,1 <<GRF_IO_VSEL_GPIO4CD_SHIFT ); } +/* +* Swap mmc0 and mmc1 in boot_targets if booted from SD-Card. +* +* If bootsource is uSD-card we can assume that we want to use the +* SD-Card instead of the eMMC as first boot_target for distroboot. +* We only want to swap the defaults and not any custom environment a +* user has set. We exit early if a changed boot_targets environment +* is detected. +*/ +static int setup_boottargets (void ) +{ +const char *boot_device = +ofnode_get_chosen_prop ("u-boot,spl-boot-device" ); +char *env_default, *env; + +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); + + env_default =env_get_default ("boot_targets" ); + env =env_get ("boot_targets" ); +if (!env) { +debug ("%s: boot_targets does not exist\n" , __func__); +return -1 ; + } +debug ("%s: boot_targets current: %s - default: %s\n" , + __func__, env, env_default); + +if (strcmp (env_default, env) !=0 ) { +debug ("%s: boot_targets not default, don't change it\n" , + __func__); +return 0 ; + } + +/* +* Only run, if booting from mmc1 (i.e. /dwmmc at fe320000) and +* only consider cases where the default boot-order first +* tries to boot from mmc0 (eMMC) and then from mmc1 +* (i.e. external SD). +* +* In other words: the SD card will be moved to earlier in the +* order, if U-Boot was also loaded from the SD-card. +*/ +if (!strcmp (boot_device,"/dwmmc@fe320000" )) { +char *mmc0, *mmc1; + +debug ("%s: booted from SD-Card\n" , __func__); + mmc0 =strstr (env,"mmc0" ); + mmc1 =strstr (env,"mmc1" ); + +if (!mmc0 || !mmc1) { +debug ("%s: only one mmc boot_target found\n" , __func__); +return -1 ; + } + +/* +* If mmc0 comes first in the boot order, we need to change +* the strings to make mmc1 first. +*/ +if (mmc0 < mmc1) { + mmc0[3 ] ='1' ; + mmc1[3 ] ='0' ; +debug ("%s: set boot_targets to: %s\n" , __func__, env); +env_set ("boot_targets" , env); + } + } + +return 0 ; +} +int misc_init_r (void ) {setup_serial ();setup_macaddr ();setup_iodomain (); +setup_boottargets ();return 0 ; }
Signature · 1 line
2.1.4
PATCH 4/4 rockchip: rk3399: change boot_target based on u-boot, spl-boot-device
Quoted 9 lines
From: Klaus Goger <[email protected]>
The order distroboot searches for a boot.scr is fixed at compile time. To make
BIOS_DISABLEwork as expected and boot from mmc1 instead of mmc0 if enabled, we need to change the environment at runtime. Especially as commit:482cf22333("rockchip: rk3399-puma: add boot-on regulator to overrideBIOS_DISABLE") enables the eMMC in U-Boot even ifBIOS_DISABLEis active.
Quoted 7 lines
Signed-off-by Klaus Goger <[email protected]>Signed-off-by Philipp Tomsich <[email protected]>---
board/theobroma-systems/puma_rk3399/puma-rk3399.c | 74 +++++++++++++++++++++++ 1 file changed, 74 insertions(+)
Applied to u-boot-rockchip, thanks!