]> git.ipfire.org Git - thirdparty/u-boot.git/commitdiff
rockchip: Add support for RAM boot from maskrom mode
authorJonas Karlman <jonas@kwiboo.se>
Sat, 2 Aug 2025 22:07:23 +0000 (22:07 +0000)
committerKever Yang <kever.yang@rock-chips.com>
Sat, 13 Dec 2025 16:02:10 +0000 (00:02 +0800)
The BootROM in Rockchip SoCs will enter maskrom mode when boot firmware
cannot be found in nand/spi/mmc storage.

In maskrom mode the USB OTG port can accept one of two custom commands.

Initially a 0x471 command to load TPL into SRAM. After TPL has been
executed and it has returned back-to-BROM, a 0x472 command to load SPL
into start of DRAM.

Add two binman images that can be used to RAM boot from maskrom mode:
- u-boot-rockchip-usb471.bin that contains TPL to init DRAM.
- u-boot-rockchip-usb472.bin that contains SPL and the normal FIT
  payload with i.e. U-Boot proper, TF-A and FDT.

A config fragment rockchip-ramboot.config can be used to enable building
of these two binman images, e.g.:

  make generic-rk3588_defconfig rockchip-ramboot.config

These binman images can be used with the proprietary rkbin boot_merger
tool to create a special loader image that can be used with tools such
as rkdeveloptool or rockusb tools to RAM boot from maskrom, e.g.:

  Create loader image:
    $ ../rkbin/tools/boot_merger ./RK3588MINIALL.ini

  Boot from maskrom:
    $ rkdeveloptool db u-boot-rockchip-rk3588-loader.bin
   or
    $ rockusb download-boot u-boot-rockchip-rk3588-loader.bin

Another option that does not require use of proprietary tools is using
open source tools such as rkflashtool or rkusbboot that can load the
binman images directly without any need to first create a special loader
image to RAM boot from maskrom, e.g.:

  $ rkflashtool l < u-boot-rockchip-usb471.bin
  $ rkflashtool L < u-boot-rockchip-usb472.bin
 or
  $ rkusbboot u-boot-rockchip-usb471.bin u-boot-rockchip-usb472.bin

Signed-off-by: Jonas Karlman <jonas@kwiboo.se>
Tested-by: Arnaud Patard <arnaud.patard@collabora.com>
Reviewed-by: Kever Yang <kever.yang@rock-chips.com>
arch/arm/dts/rockchip-u-boot.dtsi
arch/arm/mach-rockchip/Kconfig
arch/arm/mach-rockchip/spl-boot-order.c
board/rockchip/rockchip-ramboot.config [new file with mode: 0644]
boot/Kconfig

index cc2feed6464fb3d3f19f7fc188e8a48cac436698..71d7623fe2ca69eb0d90e88f74db6753f7e9bb17 100644 (file)
                };
        };
 #endif /* CONFIG_ROCKCHIP_SPI_IMAGE */
+
+#ifdef CONFIG_ROCKCHIP_MASKROM_IMAGE
+       simple-bin-usb471 {
+               filename = "u-boot-rockchip-usb471.bin";
+
+#ifdef CONFIG_ROCKCHIP_EXTERNAL_TPL
+               rockchip-tpl {
+               };
+#elif defined(CONFIG_TPL)
+               u-boot-tpl {
+                       no-write-symbols;
+               };
+#endif
+       };
+
+       simple-bin-usb472 {
+               filename = "u-boot-rockchip-usb472.bin";
+               pad-byte = <0x00>;
+
+               u-boot-spl {
+                       no-write-symbols;
+               };
+
+#ifdef HAS_FIT
+               fit {
+                       insert-template = <&fit_template>;
+#else
+               u-boot-img {
+#endif
+                       offset = <(CONFIG_SPL_LOAD_FIT_ADDRESS - CFG_SYS_SDRAM_BASE)>;
+               };
+       };
+#endif /* CONFIG_ROCKCHIP_MASKROM_IMAGE */
 };
 #endif /* CONFIG_SPL */
index c9ce30760292340766f15d82b938524223903a80..e32e49ff59acc633feba96f8870754b60fc366c6 100644 (file)
@@ -706,6 +706,14 @@ config ROCKCHIP_SPI_IMAGE
          option to produce a SPI-flash image containing U-Boot. The image
          is built by binman. U-Boot sits near the start of the image.
 
+config ROCKCHIP_MASKROM_IMAGE
+       bool "Build a maskrom mode image for Rockchip"
+       depends on TPL || ROCKCHIP_EXTERNAL_TPL
+       select SPL_RAM_DEVICE
+       help
+         Rockchip SoCs support maskrom mode boot over USB. Enable this
+         option to produce maskrom mode boot images containing U-Boot.
+
 config LNX_KRNL_IMG_TEXT_OFFSET_BASE
        default TEXT_BASE
 
index 1ea1033b5eace561d1838656e6e2381579ff1ce0..6572dde29f65a586754026d9c531ce859b8f0ca4 100644 (file)
@@ -8,6 +8,7 @@
 #include <log.h>
 #include <mmc.h>
 #include <spl.h>
+#include <asm/arch-rockchip/bootrom.h>
 #include <asm/global_data.h>
 #include <dm/uclass-internal.h>
 
@@ -98,15 +99,22 @@ __weak const char *board_spl_was_booted_from(void)
 
 void board_boot_order(u32 *spl_boot_list)
 {
+       int idx = 0;
+
+       /* Add RAM boot for maskrom mode boot over USB */
+       if (BROM_BOOTSOURCE_ID_ADDR && CONFIG_IS_ENABLED(RAM_DEVICE) &&
+           read_brom_bootsource_id() == BROM_BOOTSOURCE_USB) {
+               spl_boot_list[idx++] = BOOT_DEVICE_RAM;
+       }
+
        /* In case of no fdt (or only plat), use spl_boot_device() */
        if (!CONFIG_IS_ENABLED(OF_CONTROL) || CONFIG_IS_ENABLED(OF_PLATDATA)) {
-               spl_boot_list[0] = spl_boot_device();
+               spl_boot_list[idx++] = spl_boot_device();
                return;
        }
 
        const void *blob = gd->fdt_blob;
        int chosen_node = fdt_path_offset(blob, "/chosen");
-       int idx = 0;
        int elem;
        int boot_device;
        int node;
@@ -115,7 +123,7 @@ void board_boot_order(u32 *spl_boot_list)
        if (chosen_node < 0) {
                debug("%s: /chosen not found, using spl_boot_device()\n",
                      __func__);
-               spl_boot_list[0] = spl_boot_device();
+               spl_boot_list[idx++] = spl_boot_device();
                return;
        }
 
diff --git a/board/rockchip/rockchip-ramboot.config b/board/rockchip/rockchip-ramboot.config
new file mode 100644 (file)
index 0000000..312363e
--- /dev/null
@@ -0,0 +1 @@
+CONFIG_ROCKCHIP_MASKROM_IMAGE=y
index 85f4d4680699a8af5ba6f9bbec13697785d55f21..245e120c70bf4b5e6f797cbdd5331f0dff584db4 100644 (file)
@@ -275,6 +275,9 @@ config SPL_LOAD_FIT_ADDRESS
        hex "load address of fit image"
        depends on SPL_LOAD_FIT
        default 0x44000000 if ARCH_IMX8M
+       default 0x60080000 if ARCH_ROCKCHIP && SPL_TEXT_BASE = 0x60000000
+       default 0x40200000 if ARCH_ROCKCHIP && SPL_TEXT_BASE = 0x40000000
+       default 0x00200000 if ARCH_ROCKCHIP && SPL_TEXT_BASE = 0x00000000
        default 0x0
        help
          Specify the load address of the fit image that will be loaded