[U-Boot] [PATCH v2 1/3] rockchip: rk3399: detect boot mode

U-Boot fastboot, kernel may reboot with parameter which require bootloader to get into different boot mode, detect it and enter proper mode.
Signed-off-by: Kever Yang kever.yang@rock-chips.com ---
Changes in v2: - use env_set() instead of setenv()
arch/arm/mach-rockchip/rk3399/Kconfig | 1 + arch/arm/mach-rockchip/rk3399/rk3399.c | 42 +++++++++++++++++++++++++++++++++- 2 files changed, 42 insertions(+), 1 deletion(-)
diff --git a/arch/arm/mach-rockchip/rk3399/Kconfig b/arch/arm/mach-rockchip/rk3399/Kconfig index 415466a..c4a6d46 100644 --- a/arch/arm/mach-rockchip/rk3399/Kconfig +++ b/arch/arm/mach-rockchip/rk3399/Kconfig @@ -5,6 +5,7 @@ choice
config TARGET_EVB_RK3399 bool "RK3399 evaluation board" + select BOARD_LATE_INIT help RK3399evb is a evaluation board for Rockchp rk3399, with full function and phisical connectors support like type-C ports, diff --git a/arch/arm/mach-rockchip/rk3399/rk3399.c b/arch/arm/mach-rockchip/rk3399/rk3399.c index dbc248f..3a5e4f9 100644 --- a/arch/arm/mach-rockchip/rk3399/rk3399.c +++ b/arch/arm/mach-rockchip/rk3399/rk3399.c @@ -5,9 +5,13 @@ */
#include <common.h> +#include <syscon.h> #include <asm/armv8/mmu.h> -#include <asm/io.h> +#include <asm/arch/boot_mode.h> +#include <asm/arch/clock.h> +#include <asm/arch/grf_rk3399.h> #include <asm/arch/hardware.h> +#include <asm/io.h>
DECLARE_GLOBAL_DATA_PTR;
@@ -55,3 +59,39 @@ int arch_cpu_init(void)
return 0; } + +static void setup_boot_mode(void) +{ + struct rk3399_pmugrf_regs *pmugrf; + int boot_mode; + + pmugrf = syscon_get_first_range(ROCKCHIP_SYSCON_PMUGRF); + boot_mode = readl(&pmugrf->os_reg0); + debug("boot mode %x\n", boot_mode); + + /* Clear boot mode */ + writel(BOOT_NORMAL, &pmugrf->os_reg0); + + switch (boot_mode) { + case BOOT_FASTBOOT: + printf("enter fastboot!\n"); + env_set("preboot", "setenv preboot; fastboot usb0"); + break; + case BOOT_UMS: + printf("enter UMS!\n"); + env_set("preboot", "setenv preboot; if mmc dev 0;" + "then ums mmc 0; else ums mmc 1;fi"); + break; + case BOOT_LOADER: + printf("enter Rockusb!\n"); + env_set("preboot", "setenv preboot; rockusb 0 mmc 0"); + break; + } +} + +int board_late_init(void) +{ + setup_boot_mode(); + + return 0; +}

fastboot have a command "reboot-bootloader" which require the boot loader to reboot and get into fastboot mode again.
Signed-off-by: Kever Yang kever.yang@rock-chips.com Reviewed-by: Simon Glass sjg@chromium.org Acked-by: Philipp Tomsich philipp.tomsich@theobroma-systems.com ---
Changes in v2: None
arch/arm/mach-rockchip/rk3399/rk3399.c | 14 ++++++++++++++ 1 file changed, 14 insertions(+)
diff --git a/arch/arm/mach-rockchip/rk3399/rk3399.c b/arch/arm/mach-rockchip/rk3399/rk3399.c index 3a5e4f9..3135b65 100644 --- a/arch/arm/mach-rockchip/rk3399/rk3399.c +++ b/arch/arm/mach-rockchip/rk3399/rk3399.c @@ -95,3 +95,17 @@ int board_late_init(void)
return 0; } + +#if defined(CONFIG_USB_FUNCTION_FASTBOOT) +int fb_set_reboot_flag(void) +{ + struct rk3399_pmugrf_regs *pmugrf; + + printf("Setting reboot to fastboot flag ...\n"); + pmugrf = syscon_get_first_range(ROCKCHIP_SYSCON_PMUGRF); + /* Clear boot mode */ + writel(BOOT_FASTBOOT, &pmugrf->os_reg0); + + return 0; +} +#endif

We need to get into preboot once we detect that we are not get into normal boot.
Signed-off-by: Kever Yang kever.yang@rock-chips.com Reviewed-by: Simon Glass sjg@chromium.org Acked-by: Philipp Tomsich philipp.tomsich@theobroma-systems.com ---
Changes in v2: None
include/configs/rk3399_common.h | 2 ++ 1 file changed, 2 insertions(+)
diff --git a/include/configs/rk3399_common.h b/include/configs/rk3399_common.h index 3317887..21bf2cd 100644 --- a/include/configs/rk3399_common.h +++ b/include/configs/rk3399_common.h @@ -71,6 +71,8 @@
#endif
+#define CONFIG_PREBOOT + /* enable usb config for usb ether */ #define CONFIG_USB_HOST_ETHER

On Tue, 22 Aug 2017, Kever Yang wrote:
U-Boot fastboot, kernel may reboot with parameter which require bootloader to get into different boot mode, detect it and enter proper mode.
Signed-off-by: Kever Yang kever.yang@rock-chips.com
Reviewed-by: Philipp Tomsich philipp.tomsich@theobroma-systems.com
Requested changes below.
Changes in v2:
- use env_set() instead of setenv()
arch/arm/mach-rockchip/rk3399/Kconfig | 1 + arch/arm/mach-rockchip/rk3399/rk3399.c | 42 +++++++++++++++++++++++++++++++++- 2 files changed, 42 insertions(+), 1 deletion(-)
diff --git a/arch/arm/mach-rockchip/rk3399/Kconfig b/arch/arm/mach-rockchip/rk3399/Kconfig index 415466a..c4a6d46 100644 --- a/arch/arm/mach-rockchip/rk3399/Kconfig +++ b/arch/arm/mach-rockchip/rk3399/Kconfig @@ -5,6 +5,7 @@ choice
config TARGET_EVB_RK3399 bool "RK3399 evaluation board"
- select BOARD_LATE_INIT
With the changes below, we can make this a default for all RK3399 boards. So let's imply BOARD_LATE_INIT from the RK3399 selection.
help RK3399evb is a evaluation board for Rockchp rk3399, with full function and phisical connectors support like type-C ports, diff --git a/arch/arm/mach-rockchip/rk3399/rk3399.c b/arch/arm/mach-rockchip/rk3399/rk3399.c index dbc248f..3a5e4f9 100644 --- a/arch/arm/mach-rockchip/rk3399/rk3399.c +++ b/arch/arm/mach-rockchip/rk3399/rk3399.c @@ -5,9 +5,13 @@ */
#include <common.h> +#include <syscon.h> #include <asm/armv8/mmu.h> -#include <asm/io.h> +#include <asm/arch/boot_mode.h> +#include <asm/arch/clock.h> +#include <asm/arch/grf_rk3399.h> #include <asm/arch/hardware.h> +#include <asm/io.h>
DECLARE_GLOBAL_DATA_PTR;
@@ -55,3 +59,39 @@ int arch_cpu_init(void)
return 0; }
+static void setup_boot_mode(void) +{
- struct rk3399_pmugrf_regs *pmugrf;
- int boot_mode;
- pmugrf = syscon_get_first_range(ROCKCHIP_SYSCON_PMUGRF);
- boot_mode = readl(&pmugrf->os_reg0);
- debug("boot mode %x\n", boot_mode);
- /* Clear boot mode */
- writel(BOOT_NORMAL, &pmugrf->os_reg0);
- switch (boot_mode) {
- case BOOT_FASTBOOT:
printf("enter fastboot!\n");
I would use a debug() here...
env_set("preboot", "setenv preboot; fastboot usb0");
Could we just set a more neutral (than 'preboot') environment variable that can then be run by bootscripts? This would allow custom boot scripts to either run this or not (while 'preboot' is unconditional).
Alternatively, you could just set an environment variable indicating that the 'fastboot'-flag was set and then a bootscript could test this and forward into fastboot mode.
break;
- case BOOT_UMS:
printf("enter UMS!\n");
env_set("preboot", "setenv preboot; if mmc dev 0;"
"then ums mmc 0; else ums mmc 1;fi");
Same.
break;
- case BOOT_LOADER:
printf("enter Rockusb!\n");
env_set("preboot", "setenv preboot; rockusb 0 mmc 0");
Same.
break;
- }
+}
+int board_late_init(void) +{
- setup_boot_mode();
- return 0;
+}
participants (2)
-
Kever Yang
-
Philipp Tomsich