]> git.dujemihanovic.xyz Git - u-boot.git/commitdiff
rockchip: add support for enter to bootrom download mode
authorAndy Yan <andy.yan@rock-chips.com>
Wed, 11 Oct 2017 07:00:49 +0000 (15:00 +0800)
committerPhilipp Tomsich <philipp.tomsich@theobroma-systems.com>
Tue, 21 Nov 2017 22:57:23 +0000 (23:57 +0100)
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.

Signed-off-by: Andy Yan <andy.yan@rock-chips.com>
Reviewed-by: Kever Yang <kever.yang@rock-chips.com>
Acked-by: Philipp Tomsich <philipp.tomsich@theobroma-systems.com>
Reviewed-by: Philipp Tomsich <philipp.tomsich@theobroma-systems.com>
arch/arm/include/asm/arch-rockchip/boot_mode.h
arch/arm/mach-rockchip/Kconfig
arch/arm/mach-rockchip/bootrom.c

index 163b2e7b04d2e5df57c9ab81d648da1d82637c7c..6b2a610cf4c5e29d84516791605e00c7a684357e 100644 (file)
 #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
index 6144057ad45f7f753d265aaf2b84cc8d503a0056..a26736a5aca7cb07abd08e347bc0b971d23343fd 100644 (file)
@@ -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.
index e369fdc25a88e90131d80fb2cba2644e34f8d430..bef2a90d1fcd9be9758404fe4f28f37f7bf95fa4 100644 (file)
@@ -6,6 +6,8 @@
 
 #include <common.h>
 #include <asm/arch/bootrom.h>
+#include <asm/arch/boot_mode.h>
+#include <asm/io.h>
 #include <asm/setjmp.h>
 #include <asm/system.h>
 
  */
 static jmp_buf brom_ctx __section(".data");
 
+static void _back_to_bootrom(enum rockchip_bootrom_cmd brom_cmd)
+{
+       longjmp(brom_ctx, brom_cmd);
+}
+
 void back_to_bootrom(enum rockchip_bootrom_cmd brom_cmd)
 {
 #if CONFIG_IS_ENABLED(LIBCOMMON_SUPPORT)
        puts("Returning to boot ROM...\n");
 #endif
-       longjmp(brom_ctx, brom_cmd);
+       _back_to_bootrom(brom_cmd);
+}
+
+/*
+ * we back to bootrom download mode if get a
+ * BOOT_BROM_DOWNLOAD flag in boot mode register
+ *
+ * note: the boot mode register is configured by
+ * application(next stage bootloader, kernel, etc),
+ * and the bootrom never check this register, so we need
+ * to check it and back to bootrom at very early bootstage(before
+ * some basic configurations(such as interrupts) been
+ * changed by TPL/SPL, as the bootrom download operation
+ * relys on many default settings(such as interrupts) by
+ * it's self.
+ */
+static bool 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);
+                       return true;
+               }
+       }
+
+       return false;
 }
 
 /*
@@ -34,6 +69,8 @@ int save_boot_params(void)
 
        switch (ret) {
        case 0:
+               if (check_back_to_brom_dnl_flag())
+                       _back_to_bootrom(BROM_BOOT_ENTER_DNL);
                /*
                 * This is the initial pass through this function
                 * (i.e. saving the context), setjmp just setup up the
@@ -54,7 +91,13 @@ int save_boot_params(void)
                 */
                ret = 0;
                break;
-
+       case BROM_BOOT_ENTER_DNL:
+               /*
+                * A non-zero return value will instruct the BROM enter
+                * download mode.
+                */
+               ret = 1;
+               break;
        default:
 #if CONFIG_IS_ENABLED(LIBCOMMON_SUPPORT)
                puts("FATAL: unexpected command to back_to_bootrom()\n");