[U-Boot] [PATCH v2 2/3] rockchip: add support for enter to bootrom download mode
Andy Yan
andy.yan at rock-chips.com
Thu Sep 14 08:52:01 UTC 2017
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/tps code override the interrupt configurations.
Signed-off-by: Andy Yan <andy.yan at rock-chips.com>
Reviewed-by: Kever Yang <kever.yang at rock-chips.com>
---
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 | 5 +++++
arch/arm/include/asm/arch-rockchip/bootrom.h | 15 ++++++++++++-
arch/arm/mach-rockchip/Kconfig | 1 +
arch/arm/mach-rockchip/bootrom.c | 31 +++++++++++++++++++++++++-
arch/arm/mach-rockchip/save_boot_param.S | 25 ++++++++++++++-------
5 files changed, 67 insertions(+), 10 deletions(-)
diff --git a/arch/arm/include/asm/arch-rockchip/boot_mode.h b/arch/arm/include/asm/arch-rockchip/boot_mode.h
index 163b2e7..c2cf6fd 100644
--- a/arch/arm/include/asm/arch-rockchip/boot_mode.h
+++ b/arch/arm/include/asm/arch-rockchip/boot_mode.h
@@ -15,7 +15,12 @@
#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);
+void check_back_to_brom_dnl_flag(void);
+#endif
#endif
diff --git a/arch/arm/include/asm/arch-rockchip/bootrom.h b/arch/arm/include/asm/arch-rockchip/bootrom.h
index 92eb878..0bdea14 100644
--- a/arch/arm/include/asm/arch-rockchip/bootrom.h
+++ b/arch/arm/include/asm/arch-rockchip/bootrom.h
@@ -8,6 +8,16 @@
#define _ASM_ARCH_BOOTROM_H
/*
+ *@BOOT_CONTINUE: bootrom continue load next stage image and boot.
+ *@BOOT_BROM_DNL, bootrom enter download mode if no valid image
+ * found in backup partition.
+ */
+enum {
+ BOOT_BROM_CONTINUE = 0,
+ BOOT_BROM_DNL = 1
+};
+
+/*
* Saved Stack pointer address.
* Access might be needed in some special cases.
*/
@@ -21,7 +31,10 @@ void back_to_bootrom(void);
/**
* Assembler component for the above (do not call this directly)
+ * @mode: BOOT_BROM_CONTINUE, bootrom continue load next stage image and boot;
+ * BOOT_BROM_DNL, bootrom enter download mode if no valid image
+ * found in packup partition.
*/
-void _back_to_bootrom_s(void);
+void _back_to_bootrom_s(int mode);
#endif
diff --git a/arch/arm/mach-rockchip/Kconfig b/arch/arm/mach-rockchip/Kconfig
index bf01395..2fd9eb2 100644
--- a/arch/arm/mach-rockchip/Kconfig
+++ b/arch/arm/mach-rockchip/Kconfig
@@ -113,6 +113,7 @@ config ROCKCHIP_RK3399
select SPL_SERIAL_SUPPORT
select SPL_DRIVERS_MISC_SUPPORT
select ENABLE_ARM_SOC_BOOT0_HOOK
+ select ROCKCHIP_BROM_HELPER
select DEBUG_UART_BOARD_INIT
select BOARD_LATE_INIT
help
diff --git a/arch/arm/mach-rockchip/bootrom.c b/arch/arm/mach-rockchip/bootrom.c
index 8380e4e..463462c 100644
--- a/arch/arm/mach-rockchip/bootrom.c
+++ b/arch/arm/mach-rockchip/bootrom.c
@@ -5,12 +5,41 @@
*/
#include <common.h>
+#include <asm/io.h>
#include <asm/arch/bootrom.h>
+#include <asm/arch/boot_mode.h>
void back_to_bootrom(void)
{
#if CONFIG_IS_ENABLED(LIBCOMMON_SUPPORT)
puts("Returning to boot ROM...\n");
#endif
- _back_to_bootrom_s();
+ _back_to_bootrom_s(BOOT_BROM_CONTINUE);
+}
+
+/*
+ * we back to bootrom download mode if get a
+ * BOOT_BROM_DOWNLOAD flag in boot mode register
+ *
+ * note: (a)the boot mode register is configured by
+ * application(next stage bootloader, kernel, etc),
+ * the bootrom never check this register, so we need
+ * to check it and back at very early bootstage(before
+ * some basic configurations such as interrupts been
+ * changed by TPL/TPL), as the bootrom download operation
+ * relys on many default settings(such as interrupts) by
+ * it's self.
+ * (b)this function share the sampe SP with bootrom code.
+ */
+void check_back_to_brom_dnl_flag(void)
+{
+ u32 boot_mode;
+
+ if (CONFIG_ROCKCHIP_BOOT_MODE_REG) {
+ boot_mode = readl(CONFIG_ROCKCHIP_BOOT_MODE_REG);
+ if (boot_mode == BOOT_BROM_DOWNLOAD) {
+ writel(0, CONFIG_ROCKCHIP_BOOT_MODE_REG);
+ _back_to_bootrom_s(BOOT_BROM_DNL);
+ }
+ }
}
diff --git a/arch/arm/mach-rockchip/save_boot_param.S b/arch/arm/mach-rockchip/save_boot_param.S
index 50fce20..e8fa10b 100644
--- a/arch/arm/mach-rockchip/save_boot_param.S
+++ b/arch/arm/mach-rockchip/save_boot_param.S
@@ -23,14 +23,19 @@ ENTRY(save_boot_params)
ldr x8, =SAVE_SP_ADDR
mov x9, sp
str x9, [x8]
+ bl check_back_to_brom_dnl_flag
b save_boot_params_ret /* back to my caller */
ENDPROC(save_boot_params)
+/*
+ * x0: return value for bootrom, non-zero for bootrom download
+ * mode and zero for normal boot mode
+ */
.globl _back_to_bootrom_s
ENTRY(_back_to_bootrom_s)
- ldr x0, =SAVE_SP_ADDR
- ldr x0, [x0]
- mov sp, x0
+ ldr x1, =SAVE_SP_ADDR
+ ldr x1, [x1]
+ mov sp, x1
ldp x29, x30, [sp, #0x50]
ldp x27, x28, [sp, #0x40]
ldp x25, x26, [sp, #0x30]
@@ -38,7 +43,6 @@ ENTRY(_back_to_bootrom_s)
ldp x21, x22, [sp, #0x10]
ldp x19, x20, [sp]
add sp, sp, #0x60
- mov x0, xzr
ret
ENDPROC(_back_to_bootrom_s)
#else
@@ -55,15 +59,20 @@ ENTRY(save_boot_params)
push {r1-r12, lr}
ldr r0, =SAVE_SP_ADDR
str sp, [r0]
- b save_boot_params_ret @ back to my caller
+ bl check_back_to_brom_dnl_flag
+ b save_boot_params_ret @ back to my caller
ENDPROC(save_boot_params)
+/*
+ * r0: return value for bootrom, non-zero for
+ * bootrom download mode and zero for normal
+ * boot mode
+ */
.globl _back_to_bootrom_s
ENTRY(_back_to_bootrom_s)
- ldr r0, =SAVE_SP_ADDR
- ldr sp, [r0]
- mov r0, #0
+ ldr r1, =SAVE_SP_ADDR
+ ldr sp, [r1]
pop {r1-r12, pc}
ENDPROC(_back_to_bootrom_s)
#endif
--
2.7.4
More information about the U-Boot
mailing list