Skip to contentSkip to conversation

Most rockchip platform based boards use a key to instruct

PATCH Superseded Andy Yan 2 participants 19 messages Oct 11, 2017 – Nov 21, 2017

Subsystems (3)
lore
Share & tools
lore

Andy Yan

author
#0 lore raw

v3 cover Most rockchip platform based boards use a key to instruct

the board enter download firmware mode, some boards use a adc to detect the key status, and some use a gpio.

This series try to implement all the download mode related functions on the base of Dr. Philipp's patch[0].

[0]https://lists.denx.de/pipermail/u-boot/2017-October/309060.html

Changes in v3:
- add support for rk3188
- rebase on Dr. Philipp's series

Changes in v2:
- correct the rk322x boot mode register address
- make the help text more clear
- implement the back to bootrom download mode check in c, thanks for Dr. Philipp Tomsich's suggestion.
- more document
- move adc key detect as the default

Andy Yan (3):
rockchip: make boot_mode related codes reused across all platforms
rockchip: add support for enter to bootrom download mode
rockchip: check download key before bootup

 arch/arm/include/asm/arch-rockchip/boot_mode.h |  6 ++
 arch/arm/mach-rockchip/Kconfig                 | 16 ++++++
 arch/arm/mach-rockchip/Makefile                |  6 ++
 arch/arm/mach-rockchip/boot_mode.c             | 76 ++++++++++++++++++++++++++
 arch/arm/mach-rockchip/bootrom.c               | 47 +++++++++++++++-
 arch/arm/mach-rockchip/rk3036-board.c          | 24 --------
 arch/arm/mach-rockchip/rk3188-board.c          |  1 +
 arch/arm/mach-rockchip/rk322x-board.c          | 24 --------
 arch/arm/mach-rockchip/rk3288-board.c          | 25 ---------
 arch/arm/mach-rockchip/rk3399-board.c          | 14 +++++
 10 files changed, 164 insertions(+), 75 deletions(-)
 create mode 100644 arch/arm/mach-rockchip/boot_mode.c
 create mode 100644 arch/arm/mach-rockchip/rk3399-board.c
Signature · 1 line
2.7.4
author
#1 lore raw

PATCH v3 1/3 rockchip: make boot_mode related codes reused across all platforms

setup_boot_mode function use the same logic but different mode register address across all the rockchip platforms, so it's better to make this function reused across all the platforms, and let the mode register address setting from the config file.

---

Changes in v3:
- add support for rk3188

Changes in v2:
- correct the rk322x boot mode register address
- make the help text more clear

 arch/arm/include/asm/arch-rockchip/boot_mode.h |  2 ++
 arch/arm/mach-rockchip/Kconfig                 | 15 ++++++++++++
 arch/arm/mach-rockchip/Makefile                |  6 +++++
 arch/arm/mach-rockchip/boot_mode.c             | 33 ++++++++++++++++++++++++++
 arch/arm/mach-rockchip/rk3036-board.c          | 24 -------------------
 arch/arm/mach-rockchip/rk3188-board.c          |  1 +
 arch/arm/mach-rockchip/rk322x-board.c          | 24 -------------------
 arch/arm/mach-rockchip/rk3288-board.c          | 25 -------------------
 arch/arm/mach-rockchip/rk3399-board.c          | 14 +++++++++++
 9 files changed, 71 insertions(+), 73 deletions(-)
 create mode 100644 arch/arm/mach-rockchip/boot_mode.c
 create mode 100644 arch/arm/mach-rockchip/rk3399-board.c
arch/arm/include/asm/arch-rockchip/boot_mode.h +2 -0
index bd65f60..163b2e7 100644
@@ -16,4 +16,6 @@
 /* enter usb mass storage mode */
 #define BOOT_UMS		(REBOOT_FLAG + 12)
 
+int setup_boot_mode(void);
+
 #endif
arch/arm/mach-rockchip/Kconfig +15 -0
index 36df484..6144057 100644
@@ -117,6 +117,7 @@ config ROCKCHIP_RK3399
 	select SPL_SERIAL_SUPPORT
 	select SPL_DRIVERS_MISC_SUPPORT
 	select DEBUG_UART_BOARD_INIT
+	select BOARD_LATE_INIT
 	help
 	  The Rockchip RK3399 is a ARM-based SoC with a dual-core Cortex-A72
 	  and quad-core Cortex-A53.
@@ -152,6 +153,20 @@ config TPL_ROCKCHIP_BACK_TO_BROM
           SPL will return to the boot rom, which will then load the U-Boot
           binary to keep going on.
 
+config ROCKCHIP_BOOT_MODE_REG
+	hex "Rockchip boot mode flag register address"
+	default 0x200081c8 if ROCKCHIP_RK3036
+	default 0x20004040 if ROCKCHIP_RK3188
+	default 0x110005c8 if ROCKCHIP_RK322X
+	default 0xff730094 if ROCKCHIP_RK3288
+	default 0xff738200 if ROCKCHIP_RK3368
+	default 0xff320300 if ROCKCHIP_RK3399
+	default 0x10300580 if ROCKCHIP_RV1108
+	default 0
+	help
+	  The Soc will enter to different boot mode(defined in asm/arch/boot_mode.h)
+	  according to the value from this register.
+
 config ROCKCHIP_SPL_RESERVE_IRAM
 	hex "Size of IRAM reserved in SPL"
 	default 0x4000
arch/arm/mach-rockchip/Makefile +6 -0
index c15e9bf..2127f2b 100644
@@ -22,10 +22,16 @@ obj-spl-$(CONFIG_ROCKCHIP_RK3368) += rk3368-board-spl.o spl-boot-order.o
 obj-spl-$(CONFIG_ROCKCHIP_RK3399) += rk3399-board-spl.o spl-boot-order.o
 
 ifeq ($(CONFIG_SPL_BUILD)$(CONFIG_TPL_BUILD),)
+
+ifneq ($(CONFIG_ROCKCHIP_BOOT_MODE_REG),0)
+obj-y += boot_mode.o
+endif
+
 obj-$(CONFIG_ROCKCHIP_RK3188) += rk3188-board.o
 obj-$(CONFIG_ROCKCHIP_RK322X) += rk322x-board.o
 obj-$(CONFIG_ROCKCHIP_RK3288) += rk3288-board.o
 obj-$(CONFIG_ROCKCHIP_RK3036) += rk3036-board.o
+obj-$(CONFIG_ROCKCHIP_RK3399) += rk3399-board.o
 endif
 
 obj-$(CONFIG_$(SPL_TPL_)RAM) += sdram_common.o
arch/arm/mach-rockchip/boot_mode.c new file +33 -0
new file mode 100644
index 0000000..4652490
@@ -0,0 +1,33 @@
+/*
+ * (C) Copyright 2016 Rockchip Electronics Co., Ltd
+ *
+ * SPDX-License-Identifier:     GPL-2.0+
+ */
+
+#include <common.h>
+#include <asm/io.h>
+#include <asm/arch/boot_mode.h>
+
+int setup_boot_mode(void)
+{
+	void *reg = (void *)CONFIG_ROCKCHIP_BOOT_MODE_REG;
+	int boot_mode = readl(reg);
+
+	debug("boot mode %x.\n", boot_mode);
+
+	/* Clear boot mode */
+	writel(BOOT_NORMAL, reg);
+
+	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; ums mmc 0");
+		break;
+	}
+
+	return 0;
+}
arch/arm/mach-rockchip/rk3036-board.c +0 -24
index a3457f3..a5d2571 100644
@@ -19,30 +19,6 @@
 
 DECLARE_GLOBAL_DATA_PTR;
 
-#define GRF_BASE	0x20008000
-
-static void setup_boot_mode(void)
-{
-	struct rk3036_grf *const grf = (void *)GRF_BASE;
-	int boot_mode = readl(&grf->os_reg[4]);
-
-	debug("boot mode %x.\n", boot_mode);
-
-	/* Clear boot mode */
-	writel(BOOT_NORMAL, &grf->os_reg[4]);
-
-	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; ums mmc 0");
-		break;
-	}
-}
-
 __weak int rk_board_late_init(void)
 {
 	return 0;
arch/arm/mach-rockchip/rk3188-board.c +1 -0
index 96859a5..916d18f 100644
@@ -24,6 +24,7 @@ int board_late_init(void)
 {
 	struct rk3188_grf *grf;
 
+	setup_boot_mode();
 	grf = syscon_get_first_range(ROCKCHIP_SYSCON_GRF);
 	if (IS_ERR(grf)) {
 		pr_err("grf syscon returned %ld\n", PTR_ERR(grf));
arch/arm/mach-rockchip/rk322x-board.c +0 -24
index d443114..e71847d 100644
@@ -16,30 +16,6 @@
 
 DECLARE_GLOBAL_DATA_PTR;
 
-#define GRF_BASE	0x11000000
-
-static void setup_boot_mode(void)
-{
-	struct rk322x_grf *const grf = (void *)GRF_BASE;
-	int boot_mode = readl(&grf->os_reg[0]);
-
-	debug("boot mode %x.\n", boot_mode);
-
-	/* Clear boot mode */
-	writel(BOOT_NORMAL, &grf->os_reg[0]);
-
-	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; ums mmc 0");
-		break;
-	}
-}
-
 __weak int rk_board_late_init(void)
 {
 	return 0;
arch/arm/mach-rockchip/rk3288-board.c +0 -25
index 278bb40..1c53cca 100644
@@ -23,31 +23,6 @@
 
 DECLARE_GLOBAL_DATA_PTR;
 
-#define PMU_BASE	0xff730000
-
-static void setup_boot_mode(void)
-{
-	struct rk3288_pmu *const pmu = (void *)PMU_BASE;
-	int boot_mode = readl(&pmu->sys_reg[0]);
-
-	debug("boot mode %x.\n", boot_mode);
-
-	/* Clear boot mode */
-	writel(BOOT_NORMAL, &pmu->sys_reg[0]);
-
-	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;
-	}
-}
-
 __weak int rk_board_late_init(void)
 {
 	return 0;
arch/arm/mach-rockchip/rk3399-board.c new file +14 -0
new file mode 100644
index 0000000..9293843
@@ -0,0 +1,14 @@
+/*
+ * Copyright (c) 2017 Rockchip Electronics Co., Ltd
+ *
+ * SPDX-License-Identifier:     GPL-2.0+
+ */
+
+#include <common.h>
+#include <asm/arch/boot_mode.h>
+
+int board_late_init(void)
+{
+	setup_boot_mode();
+	return 0;
+}
Signature · 1 line
2.7.4
#2 lore raw

PATCH v3 1/3 rockchip: make boot_mode related codes reused across all platforms

Quoted 17 lines

setup_boot_mode function use the same logic but different mode register address across all the rockchip platforms, so it's better to make this function reused across all the platforms, and let the mode register address setting from the config file.

---

Changes in v3:
- add support for rk3188

Changes in v2:
- correct the rk322x boot mode register address
- make the help text more clear

Quoted 13 lines
 arch/arm/include/asm/arch-rockchip/boot_mode.h |  2 ++
 arch/arm/mach-rockchip/Kconfig                 | 15 ++++++++++++
 arch/arm/mach-rockchip/Makefile                |  6 +++++
 arch/arm/mach-rockchip/boot_mode.c             | 33 ++++++++++++++++++++++++++
 arch/arm/mach-rockchip/rk3036-board.c          | 24 -------------------
 arch/arm/mach-rockchip/rk3188-board.c          |  1 +
 arch/arm/mach-rockchip/rk322x-board.c          | 24 -------------------
 arch/arm/mach-rockchip/rk3288-board.c          | 25 -------------------
 arch/arm/mach-rockchip/rk3399-board.c          | 14 +++++++++++
 9 files changed, 71 insertions(+), 73 deletions(-)
 create mode 100644 arch/arm/mach-rockchip/boot_mode.c
 create mode 100644 arch/arm/mach-rockchip/rk3399-board.c
#3 lore raw

PATCH v3 1/3 rockchip: make boot_mode related codes reused across all platforms

In reply to Andy Yan
Quoted 9 lines · Andy Yan

setup_boot_mode function use the same logic but different mode register address across all the rockchip platforms, so it's better to make this function reused across all the platforms, and let the mode register address setting from the config file.

See below for a suggestion...

Quoted 96 lines

---

Changes in v3:
- add support for rk3188

Changes in v2:
- correct the rk322x boot mode register address
- make the help text more clear

arch/arm/include/asm/arch-rockchip/boot_mode.h |  2 ++
arch/arm/mach-rockchip/Kconfig                 | 15 ++++++++++++
arch/arm/mach-rockchip/Makefile                |  6 +++++
arch/arm/mach-rockchip/boot_mode.c             | 33 ++++++++++++++++++++++++++
arch/arm/mach-rockchip/rk3036-board.c          | 24 -------------------
arch/arm/mach-rockchip/rk3188-board.c          |  1 +
arch/arm/mach-rockchip/rk322x-board.c          | 24 -------------------
arch/arm/mach-rockchip/rk3288-board.c          | 25 -------------------
arch/arm/mach-rockchip/rk3399-board.c          | 14 +++++++++++
9 files changed, 71 insertions(+), 73 deletions(-)

create mode 100644 arch/arm/mach-rockchip/boot_mode.c create mode 100644 arch/arm/mach-rockchip/rk3399-board.c

arch/arm/include/asm/arch-rockchip/boot_mode.h +2 -0
index bd65f60..163b2e7 100644
@@ -16,4 +16,6 @@
 /* enter usb mass storage mode */
 #define BOOT_UMS		(REBOOT_FLAG + 12)
 
+int setup_boot_mode(void);
+
 #endif
arch/arm/mach-rockchip/Kconfig +15 -0
index 36df484..6144057 100644
@@ -117,6 +117,7 @@ config ROCKCHIP_RK3399
 	select SPL_SERIAL_SUPPORT
 	select SPL_DRIVERS_MISC_SUPPORT
 	select DEBUG_UART_BOARD_INIT
+	select BOARD_LATE_INIT
 	help
 	  The Rockchip RK3399 is a ARM-based SoC with a dual-core Cortex-A72
 	  and quad-core Cortex-A53.
@@ -152,6 +153,20 @@ config TPL_ROCKCHIP_BACK_TO_BROM
          SPL will return to the boot rom, which will then load the U-Boot
          binary to keep going on.
 
+config ROCKCHIP_BOOT_MODE_REG
+	hex "Rockchip boot mode flag register address"
+	default 0x200081c8 if ROCKCHIP_RK3036
+	default 0x20004040 if ROCKCHIP_RK3188
+	default 0x110005c8 if ROCKCHIP_RK322X
+	default 0xff730094 if ROCKCHIP_RK3288
+	default 0xff738200 if ROCKCHIP_RK3368
+	default 0xff320300 if ROCKCHIP_RK3399
+	default 0x10300580 if ROCKCHIP_RV1108
+	default 0
+	help
+	  The Soc will enter to different boot mode(defined in asm/arch/boot_mode.h)
+	  according to the value from this register.
+

config ROCKCHIP_SPL_RESERVE_IRAM

	hex "Size of IRAM reserved in SPL"
	default 0x4000
arch/arm/mach-rockchip/Makefile +0 -0
index c15e9bf..2127f2b 100644
@@ -22,10 +22,16 @@ obj-spl-$(CONFIG_ROCKCHIP_RK3368) += rk3368-board-spl.o spl-boot-order.o

obj-spl-$(CONFIG_ROCKCHIP_RK3399) += rk3399-board-spl.o spl-boot-order.o

ifeq ($(CONFIG_SPL_BUILD)$(CONFIG_TPL_BUILD),)

arch/arm/mach-rockchip/Makefile +5 -0
+
+ifneq ($(CONFIG_ROCKCHIP_BOOT_MODE_REG),0)
+obj-y += boot_mode.o
+endif
+

obj-$(CONFIG_ROCKCHIP_RK3188) += rk3188-board.o
obj-$(CONFIG_ROCKCHIP_RK322X) += rk322x-board.o
obj-$(CONFIG_ROCKCHIP_RK3288) += rk3288-board.o
obj-$(CONFIG_ROCKCHIP_RK3036) += rk3036-board.o
+obj-$(CONFIG_ROCKCHIP_RK3399) += rk3399-board.o
endif

obj-$(CONFIG_$(SPL_TPL_)RAM) += sdram_common.o

arch/arm/mach-rockchip/boot_mode.c new file +3 -0
new file mode 100644
index 0000000..4652490
@@ -0,0 +1,33 @@
+/*
+ * (C) Copyright 2016 Rockchip Electronics Co., Ltd
+ *

arch/arm/mach-rockchip/boot_mode.c line 13

Quoted 10 lines
arch/arm/mach-rockchip/boot_mode.c new file +10 -0
+ * SPDX-License-Identifier:     GPL-2.0+
+ */
+
+#include <common.h>
+#include <asm/io.h>
+#include <asm/arch/boot_mode.h>
+
+int setup_boot_mode(void)
+{
+	void *reg = (void *)CONFIG_ROCKCHIP_BOOT_MODE_REG;

I am somewhat uneasy about this... could we use a syscon/regmap instead that will map to something different on each device? I am thinking of something along the lines of "syscon_get_first_range(ROCKCHIP_BOOTMODE)".

Quoted 159 lines
arch/arm/mach-rockchip/boot_mode.c new file +20 -0
+	int boot_mode = readl(reg);
+
+	debug("boot mode %x.\n", boot_mode);
+
+	/* Clear boot mode */
+	writel(BOOT_NORMAL, reg);
+
+	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; ums mmc 0");
+		break;
+	}
+
+	return 0;
+}
arch/arm/mach-rockchip/rk3036-board.c +0 -24
index a3457f3..a5d2571 100644
@@ -19,30 +19,6 @@
 
 DECLARE_GLOBAL_DATA_PTR;
 
-#define GRF_BASE	0x20008000
-
-static void setup_boot_mode(void)
-{
-	struct rk3036_grf *const grf = (void *)GRF_BASE;
-	int boot_mode = readl(&grf->os_reg[4]);
-
-	debug("boot mode %x.\n", boot_mode);
-
-	/* Clear boot mode */
-	writel(BOOT_NORMAL, &grf->os_reg[4]);
-
-	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; ums mmc 0");
-		break;
-	}
-}
-
 __weak int rk_board_late_init(void)
 {
 	return 0;
arch/arm/mach-rockchip/rk3188-board.c +1 -0
index 96859a5..916d18f 100644
@@ -24,6 +24,7 @@ int board_late_init(void)
 {
 	struct rk3188_grf *grf;
 
+	setup_boot_mode();
 	grf = syscon_get_first_range(ROCKCHIP_SYSCON_GRF);
 	if (IS_ERR(grf)) {
 		pr_err("grf syscon returned %ld\n", PTR_ERR(grf));
arch/arm/mach-rockchip/rk322x-board.c +0 -24
index d443114..e71847d 100644
@@ -16,30 +16,6 @@
 
 DECLARE_GLOBAL_DATA_PTR;
 
-#define GRF_BASE	0x11000000
-
-static void setup_boot_mode(void)
-{
-	struct rk322x_grf *const grf = (void *)GRF_BASE;
-	int boot_mode = readl(&grf->os_reg[0]);
-
-	debug("boot mode %x.\n", boot_mode);
-
-	/* Clear boot mode */
-	writel(BOOT_NORMAL, &grf->os_reg[0]);
-
-	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; ums mmc 0");
-		break;
-	}
-}
-
 __weak int rk_board_late_init(void)
 {
 	return 0;
arch/arm/mach-rockchip/rk3288-board.c +0 -25
index 278bb40..1c53cca 100644
@@ -23,31 +23,6 @@
 
 DECLARE_GLOBAL_DATA_PTR;
 
-#define PMU_BASE	0xff730000
-
-static void setup_boot_mode(void)
-{
-	struct rk3288_pmu *const pmu = (void *)PMU_BASE;
-	int boot_mode = readl(&pmu->sys_reg[0]);
-
-	debug("boot mode %x.\n", boot_mode);
-
-	/* Clear boot mode */
-	writel(BOOT_NORMAL, &pmu->sys_reg[0]);
-
-	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;
-	}
-}
-
 __weak int rk_board_late_init(void)
 {
 	return 0;
arch/arm/mach-rockchip/rk3399-board.c new file +14 -0
new file mode 100644
index 0000000..9293843
@@ -0,0 +1,14 @@
+/*
+ * Copyright (c) 2017 Rockchip Electronics Co., Ltd
+ *
+ * SPDX-License-Identifier:     GPL-2.0+
+ */
+
+#include <common.h>
+#include <asm/arch/boot_mode.h>
+
+int board_late_init(void)
+{
+	setup_boot_mode();
+	return 0;
+}
author
#4 lore raw

PATCH v3 1/3 rockchip: make boot_mode related codes reused across all platforms

Hi Philipp:

Quoted 128 lines · Philipp Tomsich
Quoted 9 lines · Andy Yan

setup_boot_mode function use the same logic but different mode register address across all the rockchip platforms, so it's better to make this function reused across all the platforms, and let the mode register address setting from the config file.

See below for a suggestion...

Quoted 110 lines

---

Changes in v3:
- add support for rk3188

Changes in v2:
- correct the rk322x boot mode register address
- make the help text more clear

arch/arm/include/asm/arch-rockchip/boot_mode.h |  2 ++ arch/arm/mach-rockchip/Kconfig                 | 15 ++++++++++++ arch/arm/mach-rockchip/Makefile                |  6 +++++ arch/arm/mach-rockchip/boot_mode.c             | 33
++++++++++++++++++++++++++

arch/arm/mach-rockchip/rk3036-board.c          | 24 -------------------
arch/arm/mach-rockchip/rk3188-board.c          |  1 +
arch/arm/mach-rockchip/rk322x-board.c          | 24 -------------------
arch/arm/mach-rockchip/rk3288-board.c          | 25 -------------------
arch/arm/mach-rockchip/rk3399-board.c          | 14 +++++++++++
9 files changed, 71 insertions(+), 73 deletions(-)

create mode 100644 arch/arm/mach-rockchip/boot_mode.c create mode 100644 arch/arm/mach-rockchip/rk3399-board.c

arch/arm/include/asm/arch-rockchip/boot_mode.h +2 -0
index bd65f60..163b2e7 100644
@@ -16,4 +16,6 @@
 /* enter usb mass storage mode */
 #define BOOT_UMS        (REBOOT_FLAG + 12)
 
+int setup_boot_mode(void);
+
 #endif
arch/arm/mach-rockchip/Kconfig +0 -0
index 36df484..6144057 100644
@@ -117,6 +117,7 @@ config ROCKCHIP_RK3399

    select SPL_SERIAL_SUPPORT
    select SPL_DRIVERS_MISC_SUPPORT
    select DEBUG_UART_BOARD_INIT
+    select BOARD_LATE_INIT
    help
      The Rockchip RK3399 is a ARM-based SoC with a dual-core Cortex-A72 and quad-core Cortex-A53.

arch/arm/mach-rockchip/Kconfig +0 -0
@@ -152,6 +153,20 @@ config TPL_ROCKCHIP_BACK_TO_BROM

          SPL will return to the boot rom, which will then load the U-Boot
          binary to keep going on.

+config ROCKCHIP_BOOT_MODE_REG
+    hex "Rockchip boot mode flag register address" +    default 0x200081c8 if ROCKCHIP_RK3036
+    default 0x20004040 if ROCKCHIP_RK3188
+    default 0x110005c8 if ROCKCHIP_RK322X
+    default 0xff730094 if ROCKCHIP_RK3288
+    default 0xff738200 if ROCKCHIP_RK3368
+    default 0xff320300 if ROCKCHIP_RK3399
+    default 0x10300580 if ROCKCHIP_RV1108
+    default 0
+    help
+      The Soc will enter to different boot mode(defined in asm/arch/boot_mode.h)
+      according to the value from this register. +
config ROCKCHIP_SPL_RESERVE_IRAM
    hex "Size of IRAM reserved in SPL"
    default 0x4000

arch/arm/mach-rockchip/Makefile +0 -0
index c15e9bf..2127f2b 100644
@@ -22,10 +22,16 @@ obj-spl-$(CONFIG_ROCKCHIP_RK3368) += 

rk3368-board-spl.o spl-boot-order.o obj-spl-$(CONFIG_ROCKCHIP_RK3399) += rk3399-board-spl.o spl-boot-order.o

ifeq ($(CONFIG_SPL_BUILD)$(CONFIG_TPL_BUILD),)

arch/arm/mach-rockchip/Makefile +5 -0
+
+ifneq ($(CONFIG_ROCKCHIP_BOOT_MODE_REG),0)
+obj-y += boot_mode.o
+endif
+

obj-$(CONFIG_ROCKCHIP_RK3188) += rk3188-board.o
obj-$(CONFIG_ROCKCHIP_RK322X) += rk322x-board.o
obj-$(CONFIG_ROCKCHIP_RK3288) += rk3288-board.o
obj-$(CONFIG_ROCKCHIP_RK3036) += rk3036-board.o
+obj-$(CONFIG_ROCKCHIP_RK3399) += rk3399-board.o
endif

obj-$(CONFIG_$(SPL_TPL_)RAM) += sdram_common.o

arch/arm/mach-rockchip/boot_mode.c new file +9 -0
new file mode 100644
index 0000000..4652490
@@ -0,0 +1,33 @@
+/*
+ * (C) Copyright 2016 Rockchip Electronics Co., Ltd
+ *
+ * SPDX-License-Identifier:     GPL-2.0+
+ */
+
+#include <common.h>
+#include <asm/io.h>
+#include <asm/arch/boot_mode.h>
Quoted 8 lines

arch/arm/mach-rockchip/boot_mode.c line 13

Quoted 4 lines
arch/arm/mach-rockchip/boot_mode.c new file +4 -0
+
+int setup_boot_mode(void)
+{
+    void *reg = (void *)CONFIG_ROCKCHIP_BOOT_MODE_REG;

I am somewhat uneasy about this... could we use a syscon/regmap instead that will map to something different on each device?  I am thinking of something along the lines of "syscon_get_first_range(ROCKCHIP_BOOTMODE)".

 The reason why we put the BOOTMODE register in Kconfig is because that
we also need to access the resister in function save_boot_params(see patch 2/3) to check
the BROM_DNL flag, we have no way to access the dtb or syscon driver at that point(it's the first step we enter the tpl/spl world from bootrom).

Quoted 168 lines
Quoted 165 lines
arch/arm/mach-rockchip/boot_mode.c new file +20 -0
+    int boot_mode = readl(reg);
+
+    debug("boot mode %x.\n", boot_mode);
+
+    /* Clear boot mode */
+    writel(BOOT_NORMAL, reg);
+
+    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; ums mmc 0");
+        break;
+    }
+
+    return 0;
+}
arch/arm/mach-rockchip/rk3036-board.c +0 -24
index a3457f3..a5d2571 100644
@@ -19,30 +19,6 @@
 
 DECLARE_GLOBAL_DATA_PTR;
 
-#define GRF_BASE    0x20008000
-
-static void setup_boot_mode(void)
-{
-    struct rk3036_grf *const grf = (void *)GRF_BASE;
-    int boot_mode = readl(&grf->os_reg[4]);
-
-    debug("boot mode %x.\n", boot_mode);
-
-    /* Clear boot mode */
-    writel(BOOT_NORMAL, &grf->os_reg[4]);
-
-    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; ums mmc 0");
-        break;
-    }
-}
-
 __weak int rk_board_late_init(void)
 {
     return 0;
arch/arm/mach-rockchip/rk3188-board.c +1 -0
index 96859a5..916d18f 100644
@@ -24,6 +24,7 @@ int board_late_init(void)
 {
     struct rk3188_grf *grf;
 
+    setup_boot_mode();
     grf = syscon_get_first_range(ROCKCHIP_SYSCON_GRF);
     if (IS_ERR(grf)) {
         pr_err("grf syscon returned %ld\n", PTR_ERR(grf));
arch/arm/mach-rockchip/rk322x-board.c +0 -24
index d443114..e71847d 100644
@@ -16,30 +16,6 @@
 
 DECLARE_GLOBAL_DATA_PTR;
 
-#define GRF_BASE    0x11000000
-
-static void setup_boot_mode(void)
-{
-    struct rk322x_grf *const grf = (void *)GRF_BASE;
-    int boot_mode = readl(&grf->os_reg[0]);
-
-    debug("boot mode %x.\n", boot_mode);
-
-    /* Clear boot mode */
-    writel(BOOT_NORMAL, &grf->os_reg[0]);
-
-    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; ums mmc 0");
-        break;
-    }
-}
-
 __weak int rk_board_late_init(void)
 {
     return 0;
arch/arm/mach-rockchip/rk3288-board.c +0 -25
index 278bb40..1c53cca 100644
@@ -23,31 +23,6 @@
 
 DECLARE_GLOBAL_DATA_PTR;
 
-#define PMU_BASE    0xff730000
-
-static void setup_boot_mode(void)
-{
-    struct rk3288_pmu *const pmu = (void *)PMU_BASE;
-    int boot_mode = readl(&pmu->sys_reg[0]);
-
-    debug("boot mode %x.\n", boot_mode);
-
-    /* Clear boot mode */
-    writel(BOOT_NORMAL, &pmu->sys_reg[0]);
-
-    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;
-    }
-}
-
 __weak int rk_board_late_init(void)
 {
     return 0;
arch/arm/mach-rockchip/rk3399-board.c new file +14 -0
new file mode 100644
index 0000000..9293843
@@ -0,0 +1,14 @@
+/*
+ * Copyright (c) 2017 Rockchip Electronics Co., Ltd
+ *
+ * SPDX-License-Identifier:     GPL-2.0+
+ */
+
+#include <common.h>
+#include <asm/arch/boot_mode.h>
+
+int board_late_init(void)
+{
+    setup_boot_mode();
+    return 0;
+}
#5 lore raw

PATCH v3 1/3 rockchip: make boot_mode related codes reused across all platforms

Andy,

Quoted 135 lines · Andy Yan

Hi Philipp:

Quoted 119 lines · Philipp Tomsich
Quoted 9 lines · Andy Yan

setup_boot_mode function use the same logic but different mode register address across all the rockchip platforms, so it's better to make this function reused across all the platforms, and let the mode register address setting from the config file.

See below for a suggestion...

Quoted 101 lines

---

Changes in v3:
- add support for rk3188

Changes in v2:
- correct the rk322x boot mode register address
- make the help text more clear

arch/arm/include/asm/arch-rockchip/boot_mode.h |  2 ++
arch/arm/mach-rockchip/Kconfig                 | 15 ++++++++++++
arch/arm/mach-rockchip/Makefile                |  6 +++++
arch/arm/mach-rockchip/boot_mode.c             | 33 ++++++++++++++++++++++++++
arch/arm/mach-rockchip/rk3036-board.c          | 24 -------------------
arch/arm/mach-rockchip/rk3188-board.c          |  1 +
arch/arm/mach-rockchip/rk322x-board.c          | 24 -------------------
arch/arm/mach-rockchip/rk3288-board.c          | 25 -------------------
arch/arm/mach-rockchip/rk3399-board.c          | 14 +++++++++++
9 files changed, 71 insertions(+), 73 deletions(-)

create mode 100644 arch/arm/mach-rockchip/boot_mode.c create mode 100644 arch/arm/mach-rockchip/rk3399-board.c

arch/arm/include/asm/arch-rockchip/boot_mode.h +2 -0
index bd65f60..163b2e7 100644
@@ -16,4 +16,6 @@
 /* enter usb mass storage mode */
 #define BOOT_UMS        (REBOOT_FLAG + 12)
 
+int setup_boot_mode(void);
+
 #endif
arch/arm/mach-rockchip/Kconfig +15 -0
index 36df484..6144057 100644
@@ -117,6 +117,7 @@ config ROCKCHIP_RK3399
    select SPL_SERIAL_SUPPORT
    select SPL_DRIVERS_MISC_SUPPORT
    select DEBUG_UART_BOARD_INIT
+    select BOARD_LATE_INIT
    help
      The Rockchip RK3399 is a ARM-based SoC with a dual-core Cortex-A72
      and quad-core Cortex-A53.
@@ -152,6 +153,20 @@ config TPL_ROCKCHIP_BACK_TO_BROM
          SPL will return to the boot rom, which will then load the U-Boot
          binary to keep going on.
 
+config ROCKCHIP_BOOT_MODE_REG
+    hex "Rockchip boot mode flag register address"
+    default 0x200081c8 if ROCKCHIP_RK3036
+    default 0x20004040 if ROCKCHIP_RK3188
+    default 0x110005c8 if ROCKCHIP_RK322X
+    default 0xff730094 if ROCKCHIP_RK3288
+    default 0xff738200 if ROCKCHIP_RK3368
+    default 0xff320300 if ROCKCHIP_RK3399
+    default 0x10300580 if ROCKCHIP_RV1108
+    default 0
+    help
+      The Soc will enter to different boot mode(defined in asm/arch/boot_mode.h)
+      according to the value from this register.
+

config ROCKCHIP_SPL_RESERVE_IRAM
hex "Size of IRAM reserved in SPL"
default 0x4000

arch/arm/mach-rockchip/Makefile +0 -0
index c15e9bf..2127f2b 100644
@@ -22,10 +22,16 @@ obj-spl-$(CONFIG_ROCKCHIP_RK3368) += rk3368-board-spl.o spl-boot-order.o

obj-spl-$(CONFIG_ROCKCHIP_RK3399) += rk3399-board-spl.o spl-boot-order.o

ifeq ($(CONFIG_SPL_BUILD)$(CONFIG_TPL_BUILD),)

arch/arm/mach-rockchip/Makefile +5 -0
+
+ifneq ($(CONFIG_ROCKCHIP_BOOT_MODE_REG),0)
+obj-y += boot_mode.o
+endif
+

obj-$(CONFIG_ROCKCHIP_RK3188) += rk3188-board.o
obj-$(CONFIG_ROCKCHIP_RK322X) += rk322x-board.o
obj-$(CONFIG_ROCKCHIP_RK3288) += rk3288-board.o
obj-$(CONFIG_ROCKCHIP_RK3036) += rk3036-board.o
+obj-$(CONFIG_ROCKCHIP_RK3399) += rk3399-board.o
endif

obj-$(CONFIG_$(SPL_TPL_)RAM) += sdram_common.o

arch/arm/mach-rockchip/boot_mode.c new file +8 -0
new file mode 100644
index 0000000..4652490
@@ -0,0 +1,33 @@
+/*
+ * (C) Copyright 2016 Rockchip Electronics Co., Ltd
+ *
+ * SPDX-License-Identifier:     GPL-2.0+
+ */
+
+#include <common.h>
+#include <asm/io.h>
Quoted 8 lines

arch/arm/mach-rockchip/boot_mode.c line 13

Quoted 5 lines
arch/arm/mach-rockchip/boot_mode.c new file +5 -0
+#include <asm/arch/boot_mode.h>
+
+int setup_boot_mode(void)
+{
+    void *reg = (void *)CONFIG_ROCKCHIP_BOOT_MODE_REG;

I am somewhat uneasy about this... could we use a syscon/regmap instead
that will map to something different on each device? I am thinking of something along the lines of "syscon_get_first_range(ROCKCHIP_BOOTMODE)".

Quoted 2 lines

The reason why we put the BOOTMODE register in Kconfig is because that we also need to access the resister in function save_boot_params(see patch 2/3) to check
the BROM_DNL flag, we have no way to access the dtb or syscon driver at that point(it's the first step we enter the tpl/spl world from bootrom).

Thanks for explaining.
I suspected something like that, but it wasn’t obvious on the first glance.

Quoted 165 lines
Quoted 163 lines
Quoted 160 lines
arch/arm/mach-rockchip/boot_mode.c new file +20 -0
+    int boot_mode = readl(reg);
+
+    debug("boot mode %x.\n", boot_mode);
+
+    /* Clear boot mode */
+    writel(BOOT_NORMAL, reg);
+
+    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; ums mmc 0");
+        break;
+    }
+
+    return 0;
+}
arch/arm/mach-rockchip/rk3036-board.c +0 -24
index a3457f3..a5d2571 100644
@@ -19,30 +19,6 @@
 
 DECLARE_GLOBAL_DATA_PTR;
 
-#define GRF_BASE    0x20008000
-
-static void setup_boot_mode(void)
-{
-    struct rk3036_grf *const grf = (void *)GRF_BASE;
-    int boot_mode = readl(&grf->os_reg[4]);
-
-    debug("boot mode %x.\n", boot_mode);
-
-    /* Clear boot mode */
-    writel(BOOT_NORMAL, &grf->os_reg[4]);
-
-    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; ums mmc 0");
-        break;
-    }
-}
-
 __weak int rk_board_late_init(void)
 {
    return 0;
arch/arm/mach-rockchip/rk3188-board.c +1 -0
index 96859a5..916d18f 100644
@@ -24,6 +24,7 @@ int board_late_init(void)
 {
    struct rk3188_grf *grf;
 
+    setup_boot_mode();
    grf = syscon_get_first_range(ROCKCHIP_SYSCON_GRF);
    if (IS_ERR(grf)) {
        pr_err("grf syscon returned %ld\n", PTR_ERR(grf));
arch/arm/mach-rockchip/rk322x-board.c +0 -24
index d443114..e71847d 100644
@@ -16,30 +16,6 @@
 
 DECLARE_GLOBAL_DATA_PTR;
 
-#define GRF_BASE    0x11000000
-
-static void setup_boot_mode(void)
-{
-    struct rk322x_grf *const grf = (void *)GRF_BASE;
-    int boot_mode = readl(&grf->os_reg[0]);
-
-    debug("boot mode %x.\n", boot_mode);
-
-    /* Clear boot mode */
-    writel(BOOT_NORMAL, &grf->os_reg[0]);
-
-    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; ums mmc 0");
-        break;
-    }
-}
-
 __weak int rk_board_late_init(void)
 {
    return 0;
arch/arm/mach-rockchip/rk3288-board.c +0 -25
index 278bb40..1c53cca 100644
@@ -23,31 +23,6 @@
 
 DECLARE_GLOBAL_DATA_PTR;
 
-#define PMU_BASE    0xff730000
-
-static void setup_boot_mode(void)
-{
-    struct rk3288_pmu *const pmu = (void *)PMU_BASE;
-    int boot_mode = readl(&pmu->sys_reg[0]);
-
-    debug("boot mode %x.\n", boot_mode);
-
-    /* Clear boot mode */
-    writel(BOOT_NORMAL, &pmu->sys_reg[0]);
-
-    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;
-    }
-}
-
 __weak int rk_board_late_init(void)
 {
    return 0;
arch/arm/mach-rockchip/rk3399-board.c new file +14 -0
new file mode 100644
index 0000000..9293843
@@ -0,0 +1,14 @@
+/*
+ * Copyright (c) 2017 Rockchip Electronics Co., Ltd
+ *
+ * SPDX-License-Identifier:     GPL-2.0+
+ */
+
+#include <common.h>
+#include <asm/arch/boot_mode.h>
+
+int board_late_init(void)
+{
+    setup_boot_mode();
+    return 0;
+}
#6 lore raw

PATCH v3 1/3 rockchip: make boot_mode related codes reused across all platforms

In reply to Andy Yan
Quoted 19 lines

setup_boot_mode function use the same logic but different mode register address across all the rockchip platforms, so it's better to make this function reused across all the platforms, and let the mode register address setting from the config file.

---

Changes in v3:
- add support for rk3188

Changes in v2:
- correct the rk322x boot mode register address
- make the help text more clear

Quoted 13 lines
 arch/arm/include/asm/arch-rockchip/boot_mode.h |  2 ++
 arch/arm/mach-rockchip/Kconfig                 | 15 ++++++++++++
 arch/arm/mach-rockchip/Makefile                |  6 +++++
 arch/arm/mach-rockchip/boot_mode.c             | 33 ++++++++++++++++++++++++++
 arch/arm/mach-rockchip/rk3036-board.c          | 24 -------------------
 arch/arm/mach-rockchip/rk3188-board.c          |  1 +
 arch/arm/mach-rockchip/rk322x-board.c          | 24 -------------------
 arch/arm/mach-rockchip/rk3288-board.c          | 25 -------------------
 arch/arm/mach-rockchip/rk3399-board.c          | 14 +++++++++++
 9 files changed, 71 insertions(+), 73 deletions(-)
 create mode 100644 arch/arm/mach-rockchip/boot_mode.c
 create mode 100644 arch/arm/mach-rockchip/rk3399-board.c

Applied to u-boot-rockchip, thanks!

author
#7 lore raw

PATCH v3 2/3 rockchip: add support for enter to bootrom download mode

In reply to Andy Yan

Rockchip bootrom will enter download mode if it returns from spl/tpl with a non-zero value and couldn't find a valid image in the backup partition.
This patch provide a method to instruct the system to back to bootrom download mode by checking the BROM_DOWNLOAD_FLAG register. As the bootrom download function relys on some modules such as interrupts, so we need to back to bootrom as early as possbile before the tpl/spl code override the interrupt configurations.

---

Changes in v3:
- rebase on Dr. Philipp's series

Changes in v2:
- implement the back to bootrom download mode check in c, thanks for Dr. Philipp Tomsich's suggestion.

 arch/arm/include/asm/arch-rockchip/boot_mode.h |  4 +++
 arch/arm/mach-rockchip/Kconfig                 |  1 +
 arch/arm/mach-rockchip/bootrom.c               | 47 ++++++++++++++++++++++++--
 3 files changed, 50 insertions(+), 2 deletions(-)
arch/arm/include/asm/arch-rockchip/boot_mode.h +4 -0
index 163b2e7..6b2a610 100644
@@ -15,7 +15,11 @@
 #define BOOT_CHARGING		(REBOOT_FLAG + 11)
 /* enter usb mass storage mode */
 #define BOOT_UMS		(REBOOT_FLAG + 12)
+/* enter bootrom download mode */
+#define BOOT_BROM_DOWNLOAD	0xEF08A53C
 
+#ifndef __ASSEMBLY__
 int setup_boot_mode(void);
+#endif
 
 #endif
arch/arm/mach-rockchip/Kconfig +1 -0
index 6144057..a26736a 100644
@@ -118,6 +118,7 @@ config ROCKCHIP_RK3399
 	select SPL_DRIVERS_MISC_SUPPORT
 	select DEBUG_UART_BOARD_INIT
 	select BOARD_LATE_INIT
+	select ROCKCHIP_BROM_HELPER
 	help
 	  The Rockchip RK3399 is a ARM-based SoC with a dual-core Cortex-A72
 	  and quad-core Cortex-A53.
arch/arm/mach-rockchip/bootrom.c +45 -2

76 lines not on this page · raw message

Signature · 1 line
2.7.4
#8 lore raw

PATCH v3 2/3 rockchip: add support for enter to bootrom download mode

Quoted 16 lines

Rockchip bootrom will enter download mode if it returns from spl/tpl with a non-zero value and couldn't find a valid image in the backup partition.
This patch provide a method to instruct the system to back to bootrom download mode by checking the BROM_DOWNLOAD_FLAG register. As the bootrom download function relys on some modules such as interrupts, so we need to back to bootrom as early as possbile before the tpl/spl code override the interrupt configurations.

---

Changes in v3:
- rebase on Dr. Philipp's series

Quoted 9 lines

Changes in v2:
- implement the back to bootrom download mode check in c, thanks for Dr. Philipp Tomsich's suggestion.

 arch/arm/include/asm/arch-rockchip/boot_mode.h |  4 +++
 arch/arm/mach-rockchip/Kconfig                 |  1 +
 arch/arm/mach-rockchip/bootrom.c               | 47 ++++++++++++++++++++++++--
 3 files changed, 50 insertions(+), 2 deletions(-)
#9 lore raw

PATCH v3 2/3 rockchip: add support for enter to bootrom download mode

In reply to Andy Yan
Quoted 16 lines

Rockchip bootrom will enter download mode if it returns from spl/tpl with a non-zero value and couldn't find a valid image in the backup partition.
This patch provide a method to instruct the system to back to bootrom download mode by checking the BROM_DOWNLOAD_FLAG register. As the bootrom download function relys on some modules such as interrupts, so we need to back to bootrom as early as possbile before the tpl/spl code override the interrupt configurations.

---

Changes in v3:
- rebase on Dr. Philipp's series

Quoted 9 lines

Changes in v2:
- implement the back to bootrom download mode check in c, thanks for Dr. Philipp Tomsich's suggestion.

 arch/arm/include/asm/arch-rockchip/boot_mode.h |  4 +++
 arch/arm/mach-rockchip/Kconfig                 |  1 +
 arch/arm/mach-rockchip/bootrom.c               | 47 ++++++++++++++++++++++++--
 3 files changed, 50 insertions(+), 2 deletions(-)
#10 lore raw

PATCH v3 2/3 rockchip: add support for enter to bootrom download mode

In reply to Andy Yan
Quoted 18 lines

Rockchip bootrom will enter download mode if it returns from spl/tpl with a non-zero value and couldn't find a valid image in the backup partition.
This patch provide a method to instruct the system to back to bootrom download mode by checking the BROM_DOWNLOAD_FLAG register. As the bootrom download function relys on some modules such as interrupts, so we need to back to bootrom as early as possbile before the tpl/spl code override the interrupt configurations.

---

Changes in v3:
- rebase on Dr. Philipp's series

Quoted 9 lines

Changes in v2:
- implement the back to bootrom download mode check in c, thanks for Dr. Philipp Tomsich's suggestion.

 arch/arm/include/asm/arch-rockchip/boot_mode.h |  4 +++
 arch/arm/mach-rockchip/Kconfig                 |  1 +
 arch/arm/mach-rockchip/bootrom.c               | 47 ++++++++++++++++++++++++--
 3 files changed, 50 insertions(+), 2 deletions(-)

Applied to u-boot-rockchip, thanks!

author
#11 lore raw

PATCH v3 3/3 rockchip: check download key before bootup

In reply to Andy Yan

Enter download mode if the download key pressed.

---

Changes in v3: None
Changes in v2:
- more document
- move adc key detect as the default

 arch/arm/mach-rockchip/boot_mode.c | 43 ++++++++++++++++++++++++++++++++++++++
 1 file changed, 43 insertions(+)
arch/arm/mach-rockchip/boot_mode.c +43 -0
index 4652490..bf0a410 100644
@@ -5,14 +5,57 @@
  */
 
 #include <common.h>
+#include <adc.h>
 #include <asm/io.h>
 #include <asm/arch/boot_mode.h>
 
+void set_back_to_bootrom_dnl_flag(void)
+{
+	writel(BOOT_BROM_DOWNLOAD, CONFIG_ROCKCHIP_BOOT_MODE_REG);
+}
+
+/*
+ * detect download key status by adc, most rockchip
+ * based boards use adc sample the download key status,
+ * but there are also some use gpio. So it's better to
+ * make this a weak function that can be override by
+ * some special boards.
+ */
+#define KEY_DOWN_MIN_VAL	0
+#define KEY_DOWN_MAX_VAL	30
+
+__weak int rockchip_dnl_key_pressed(void)
+{
+	unsigned int val;
+
+	if (adc_channel_single_shot("saradc", 1, &val)) {
+		printf("%s adc_channel_single_shot fail!\n", __func__);
+		return false;
+	}
+
+	if ((val >= KEY_DOWN_MIN_VAL) && (val <= KEY_DOWN_MAX_VAL))
+		return true;
+	else
+		return false;
+}
+
+void rockchip_dnl_mode_check(void)
+{
+	if (rockchip_dnl_key_pressed()) {
+		printf("download key pressed, entering download mode...");
+		set_back_to_bootrom_dnl_flag();
+		do_reset(NULL, 0, 0, NULL);
+	}
+}
+
 int setup_boot_mode(void)
 {
 	void *reg = (void *)CONFIG_ROCKCHIP_BOOT_MODE_REG;
 	int boot_mode = readl(reg);
 
+	rockchip_dnl_mode_check();
+
+	boot_mode = readl(reg);
 	debug("boot mode %x.\n", boot_mode);
 
 	/* Clear boot mode */
Signature · 1 line
2.7.4
#12 lore raw

PATCH v3 3/3 rockchip: check download key before bootup

Quoted 5 lines

Enter download mode if the download key pressed.

---

Quoted 8 lines

Changes in v3: None
Changes in v2:
- more document
- move adc key detect as the default

 arch/arm/mach-rockchip/boot_mode.c | 43 ++++++++++++++++++++++++++++++++++++++
 1 file changed, 43 insertions(+)
#13 lore raw

PATCH v3 3/3 rockchip: check download key before bootup

In reply to Andy Yan
Quoted 4 lines · Andy Yan

Enter download mode if the download key pressed.

See below for requested changes.

Quoted 33 lines

---

Changes in v3: None
Changes in v2:
- more document
- move adc key detect as the default

arch/arm/mach-rockchip/boot_mode.c | 43 ++++++++++++++++++++++++++++++++++++++

1 file changed, 43 insertions(+)
arch/arm/mach-rockchip/boot_mode.c +12 -0
index 4652490..bf0a410 100644
@@ -5,14 +5,57 @@
 */
 
 #include <common.h>
+#include <adc.h>
 #include <asm/io.h>
 #include <asm/arch/boot_mode.h>
 
+void set_back_to_bootrom_dnl_flag(void)
+{
+	writel(BOOT_BROM_DOWNLOAD, CONFIG_ROCKCHIP_BOOT_MODE_REG);
+}
+
+/*
+ * detect download key status by adc, most rockchip
+ * based boards use adc sample the download key status,
+ * but there are also some use gpio. So it's better to
+ * make this a weak function that can be override by
+ * some special boards.

arch/arm/mach-rockchip/boot_mode.c line 32

Quoted 10 lines
arch/arm/mach-rockchip/boot_mode.c +10 -0
+ */
+#define KEY_DOWN_MIN_VAL	0
+#define KEY_DOWN_MAX_VAL	30
+
+__weak int rockchip_dnl_key_pressed(void)
+{
+	unsigned int val;
+
+	if (adc_channel_single_shot("saradc", 1, &val)) {
+		printf("%s adc_channel_single_shot fail!\n", __func__);

This should be a pr_debug() or pr_err().
Thanks.

Quoted 30 lines
arch/arm/mach-rockchip/boot_mode.c +21 -0
+		return false;
+	}
+
+	if ((val >= KEY_DOWN_MIN_VAL) && (val <= KEY_DOWN_MAX_VAL))
+		return true;
+	else
+		return false;
+}
+
+void rockchip_dnl_mode_check(void)
+{
+	if (rockchip_dnl_key_pressed()) {
+		printf("download key pressed, entering download mode...");
+		set_back_to_bootrom_dnl_flag();
+		do_reset(NULL, 0, 0, NULL);
+	}
+}
+
 int setup_boot_mode(void)
 {
 	void *reg = (void *)CONFIG_ROCKCHIP_BOOT_MODE_REG;
 	int boot_mode = readl(reg);
 
+	rockchip_dnl_mode_check();
+
+	boot_mode = readl(reg);
 	debug("boot mode %x.\n", boot_mode);
 
 	/* Clear boot mode */
author
#14 lore raw

PATCH v3 3/3 rockchip: check download key before bootup

Hi Philipp:

Quoted 52 lines · Philipp Tomsich
Quoted 4 lines · Andy Yan

Enter download mode if the download key pressed.

See below for requested changes.

Quoted 39 lines

---

Changes in v3: None
Changes in v2:
- more document
- move adc key detect as the default

arch/arm/mach-rockchip/boot_mode.c | 43
++++++++++++++++++++++++++++++++++++++

1 file changed, 43 insertions(+)
arch/arm/mach-rockchip/boot_mode.c +16 -0
index 4652490..bf0a410 100644
@@ -5,14 +5,57 @@
  */
 
 #include <common.h>
+#include <adc.h>
 #include <asm/io.h>
 #include <asm/arch/boot_mode.h>
 
+void set_back_to_bootrom_dnl_flag(void)
+{
+    writel(BOOT_BROM_DOWNLOAD, CONFIG_ROCKCHIP_BOOT_MODE_REG);
+}
+
+/*
+ * detect download key status by adc, most rockchip
+ * based boards use adc sample the download key status,
+ * but there are also some use gpio. So it's better to
+ * make this a weak function that can be override by
+ * some special boards.
+ */
+#define KEY_DOWN_MIN_VAL    0
+#define KEY_DOWN_MAX_VAL    30
+
Quoted 8 lines

arch/arm/mach-rockchip/boot_mode.c line 32

Quoted 6 lines
arch/arm/mach-rockchip/boot_mode.c +6 -0
+__weak int rockchip_dnl_key_pressed(void)
+{
+    unsigned int val;
+
+    if (adc_channel_single_shot("saradc", 1, &val)) {
+        printf("%s adc_channel_single_shot fail!\n", __func__);

This should be a pr_debug() or pr_err().

    Okay, I will update it.

Quoted 35 lines

Thanks.

Quoted 30 lines
arch/arm/mach-rockchip/boot_mode.c +21 -0
+        return false;
+    }
+
+    if ((val >= KEY_DOWN_MIN_VAL) && (val <= KEY_DOWN_MAX_VAL))
+        return true;
+    else
+        return false;
+}
+
+void rockchip_dnl_mode_check(void)
+{
+    if (rockchip_dnl_key_pressed()) {
+        printf("download key pressed, entering download mode...");
+        set_back_to_bootrom_dnl_flag();
+        do_reset(NULL, 0, 0, NULL);
+    }
+}
+
 int setup_boot_mode(void)
 {
     void *reg = (void *)CONFIG_ROCKCHIP_BOOT_MODE_REG;
     int boot_mode = readl(reg);
 
+    rockchip_dnl_mode_check();
+
+    boot_mode = readl(reg);
     debug("boot mode %x.\n", boot_mode);
 
     /* Clear boot mode */
#15 lore raw

PATCH v3 3/3 rockchip: check download key before bootup

Andy,

Quoted 65 lines · Andy Yan

Hi Philipp:

Quoted 50 lines · Philipp Tomsich
Quoted 4 lines · Andy Yan

Enter download mode if the download key pressed.

See below for requested changes.

Quoted 37 lines

---

Changes in v3: None
Changes in v2:
- more document
- move adc key detect as the default

arch/arm/mach-rockchip/boot_mode.c | 43 ++++++++++++++++++++++++++++++++++++++

1 file changed, 43 insertions(+)
arch/arm/mach-rockchip/boot_mode.c +16 -0
index 4652490..bf0a410 100644
@@ -5,14 +5,57 @@
 */
 
 #include <common.h>
+#include <adc.h>
 #include <asm/io.h>
 #include <asm/arch/boot_mode.h>
 
+void set_back_to_bootrom_dnl_flag(void)
+{
+    writel(BOOT_BROM_DOWNLOAD, CONFIG_ROCKCHIP_BOOT_MODE_REG);
+}
+
+/*
+ * detect download key status by adc, most rockchip
+ * based boards use adc sample the download key status,
+ * but there are also some use gpio. So it's better to
+ * make this a weak function that can be override by
+ * some special boards.
+ */
+#define KEY_DOWN_MIN_VAL    0
+#define KEY_DOWN_MAX_VAL    30
+
Quoted 8 lines

arch/arm/mach-rockchip/boot_mode.c line 32

Quoted 6 lines
arch/arm/mach-rockchip/boot_mode.c +6 -0
+__weak int rockchip_dnl_key_pressed(void)
+{
+    unsigned int val;
+
+    if (adc_channel_single_shot("saradc", 1, &val)) {
+        printf("%s adc_channel_single_shot fail!\n", __func__);

This should be a pr_debug() or pr_err().

Quoted 1 line

Okay, I will update it.

Never mind. I’ll change this to a pr_err() when I commit.

Quoted 31 lines
Quoted 31 lines

Thanks.

Quoted 29 lines
arch/arm/mach-rockchip/boot_mode.c +21 -0
+        return false;
+    }
+
+    if ((val >= KEY_DOWN_MIN_VAL) && (val <= KEY_DOWN_MAX_VAL))
+        return true;
+    else
+        return false;
+}
+
+void rockchip_dnl_mode_check(void)
+{
+    if (rockchip_dnl_key_pressed()) {
+        printf("download key pressed, entering download mode...");
+        set_back_to_bootrom_dnl_flag();
+        do_reset(NULL, 0, 0, NULL);
+    }
+}
+
 int setup_boot_mode(void)
 {
    void *reg = (void *)CONFIG_ROCKCHIP_BOOT_MODE_REG;
    int boot_mode = readl(reg);
 
+    rockchip_dnl_mode_check();
+
+    boot_mode = readl(reg);
    debug("boot mode %x.\n", boot_mode);
 
    /* Clear boot mode */
#16 lore raw

PATCH v3 3/3 rockchip: check download key before bootup

In reply to Andy Yan
Quoted 7 lines

Enter download mode if the download key pressed.

---

Quoted 8 lines

Changes in v3: None
Changes in v2:
- more document
- move adc key detect as the default

 arch/arm/mach-rockchip/boot_mode.c | 43 ++++++++++++++++++++++++++++++++++++++
 1 file changed, 43 insertions(+)

Applied to u-boot-rockchip, thanks!

author
#17 lore raw

v3 cover Most rockchip platform based boards use a key to instruct

In reply to Andy Yan

Hi Philipp:

    Please remember to take this series if they are looks ok for you.
And if you have questions about them, please let me know.

Quoted 39 lines · Andy Yan

the board enter download firmware mode, some boards use a adc to detect the key status, and some use a gpio.

This series try to implement all the download mode related functions on the base of Dr. Philipp's patch[0].

[0]https://lists.denx.de/pipermail/u-boot/2017-October/309060.html

Changes in v3:
- add support for rk3188
- rebase on Dr. Philipp's series

Changes in v2:
- correct the rk322x boot mode register address
- make the help text more clear
- implement the back to bootrom download mode check in c, thanks for Dr. Philipp Tomsich's suggestion.
- more document
- move adc key detect as the default

Andy Yan (3):
rockchip: make boot_mode related codes reused across all platforms
rockchip: add support for enter to bootrom download mode
rockchip: check download key before bootup

  arch/arm/include/asm/arch-rockchip/boot_mode.h |  6 ++
  arch/arm/mach-rockchip/Kconfig                 | 16 ++++++
  arch/arm/mach-rockchip/Makefile                |  6 ++
  arch/arm/mach-rockchip/boot_mode.c             | 76 ++++++++++++++++++++++++++
  arch/arm/mach-rockchip/bootrom.c               | 47 +++++++++++++++-
  arch/arm/mach-rockchip/rk3036-board.c          | 24 --------
  arch/arm/mach-rockchip/rk3188-board.c          |  1 +
  arch/arm/mach-rockchip/rk322x-board.c          | 24 --------
  arch/arm/mach-rockchip/rk3288-board.c          | 25 ---------
  arch/arm/mach-rockchip/rk3399-board.c          | 14 +++++
  10 files changed, 164 insertions(+), 75 deletions(-)

create mode 100644 arch/arm/mach-rockchip/boot_mode.c create mode 100644 arch/arm/mach-rockchip/rk3399-board.c

#18 lore raw

v3 cover Most rockchip platform based boards use a key to instruct

Andy,

Thanks for the reminder.
I had this on my list as one of the next ones to be merged.

Cheers,
Philipp.

Quoted 49 lines · Andy Yan

Hi Philipp:

Please remember to take this series if they are looks ok for you. And if you have questions about them, please let me know.

Quoted 39 lines · Andy Yan

the board enter download firmware mode, some boards use a adc to detect the key status, and some use a gpio.

This series try to implement all the download mode related functions on the base of Dr. Philipp's patch[0].

[0]https://lists.denx.de/pipermail/u-boot/2017-October/309060.html

Changes in v3:
- add support for rk3188
- rebase on Dr. Philipp's series

Changes in v2:
- correct the rk322x boot mode register address
- make the help text more clear
- implement the back to bootrom download mode check in c, thanks for Dr. Philipp Tomsich's suggestion.
- more document
- move adc key detect as the default

Andy Yan (3):
rockchip: make boot_mode related codes reused across all platforms
rockchip: add support for enter to bootrom download mode
rockchip: check download key before bootup

 arch/arm/include/asm/arch-rockchip/boot_mode.h |  6 ++
 arch/arm/mach-rockchip/Kconfig                 | 16 ++++++
 arch/arm/mach-rockchip/Makefile                |  6 ++
 arch/arm/mach-rockchip/boot_mode.c             | 76 ++++++++++++++++++++++++++
 arch/arm/mach-rockchip/bootrom.c               | 47 +++++++++++++++-
 arch/arm/mach-rockchip/rk3036-board.c          | 24 --------
 arch/arm/mach-rockchip/rk3188-board.c          |  1 +
 arch/arm/mach-rockchip/rk322x-board.c          | 24 --------
 arch/arm/mach-rockchip/rk3288-board.c          | 25 ---------
 arch/arm/mach-rockchip/rk3399-board.c          | 14 +++++
 10 files changed, 164 insertions(+), 75 deletions(-)
 create mode 100644 arch/arm/mach-rockchip/boot_mode.c
 create mode 100644 arch/arm/mach-rockchip/rk3399-board.c