Skip to contentSkip to conversation

Enable full UFS boot on Rockchip RK3576

PATCH Superseded Alexey Charkov 4 participants 9 messages Jan 5 – Jan 6

Subsystems (6)

v2 of 6 Superseded Latest is v6 →

lore
Share & tools
lore
#0 lore raw

v2 cover Enable full UFS boot on Rockchip RK3576

Rockchip RK3576 can load its bootloader from UFS among other options, so this series adds the necessary bits and pieces to enable an end-to-end boot from UFS (boot ROM -> SPL -> U-boot proper -> kernel).

To achieve the above, this series goes through the following:
- Patch 1 introduces arch-independent code to enable SPL images to use UFS devices, including build system tweaks and a function to locate a U-boot image at a fixed UFS offset and LUN (SCSI device number)
- Patch 2 adds device-reset functionality to the Rockchip UFS glue code, which is required for (at least some) UFS modules to respond to controller commands upon initial enumeration
- Patch 3 ties it all together for Rockchip RK3576

This has been tested on a FriendlyElec NanoPi M5 board with a Biwin BWU3AKC46C256G UFS module. Note that booting directly from UFS masks the issue which patch 2 aims to address, because the boot ROM initializes the UFS module before handing over to U-boot. If, however, one boots SPL from FSPI1 with the same driver code, the module fails to respond unless patch 2 is applied.

Changes to spl_fit.c which used to be part of v1 submission are no longer required with the introduction of an optional bounce buffer for UFS block reads, which is now folded into current Patch 1. This bounce buffer is currently enabled by default for ARCH_ROCKCHIP, and it is similar to how Rockchip's downstream SPL operates. It might be possible to allow the UFSHC to write directly to PMU_SRAM, in which case the bounce buffer can be disabled going forward, but there is no documented way to do so yet.

Note that in my experience none of the RK3576 boards actually boot current mainline U-boot versions without a single-word SRAM write before jumping to DDR initialization, as done in Kwiboo's commit at [1]. Therefore, to test this series I additionally applied commits ea2ebb491e2c..390668db9d13 from Kwiboo's rk3576 branch [2] (including ea2ebb491e2c), so any testers might want to:

git cherry-pick a256b4182bd2..390668db9d13

from there before or after applying this series

[1] https://source.denx.de/u-boot/contributors/kwiboo/u-boot/-/commit/390668db9d13b2cd0ac0077c15edb4b575ee28f9
[2] https://source.denx.de/u-boot/contributors/kwiboo/u-boot/-/commits/rk3576?ref_type=heads

---
Changes in v2:
- Rename the SPL UFS read helper function more self-descriptively (thanks Neil)
- Add an option to configure the UFS LUN used to look for the U-boot image in raw offset mode - or rather the SCSI device number, which most of the time coincides with the UFS LUN as long as the UFS device is the only SCSI block device the SPL sees (thanks Neil)
- Add an option to use a bounce buffer in RAM while loading U-boot from UFS, which helps avoid changes to common spl_fit.c code which in v1 achieved a similar result at a performance cost to unrelated platforms (thanks Jonas)
- Link to v1: https://lore.kernel.org/r/[email protected]

---
Alexey Charkov (3):
spl: Make UFS available for SPL builds
ufs: rockchip: Add device reset support
rockchip: spl: Add support for booting from UFS

 MAINTAINERS                                  |  1 +
 arch/arm/dts/rk3576-u-boot.dtsi              | 13 +++++-
 arch/arm/include/asm/arch-rockchip/bootrom.h |  1 +
 arch/arm/include/asm/spl.h                   |  1 +
 arch/arm/mach-rockchip/Kconfig               |  3 ++
 arch/arm/mach-rockchip/rk3576/rk3576.c       |  1 +
 arch/arm/mach-rockchip/spl-boot-order.c      | 14 ++++++
 common/spl/Kconfig                           | 48 ++++++++++++++++++++
 common/spl/Makefile                          |  1 +
 common/spl/spl_ufs.c                         | 65 ++++++++++++++++++++++++++++
 drivers/Makefile                             |  1 +
 drivers/reset/Kconfig                        |  9 ++++
 drivers/reset/Makefile                       |  2 +-
 drivers/scsi/Makefile                        |  3 ++
 drivers/ufs/Kconfig                          |  1 +
 drivers/ufs/ufs-rockchip.c                   | 25 +++++++++++
 drivers/ufs/ufs-rockchip.h                   |  1 +
 lib/Makefile                                 |  1 +
 18 files changed, 189 insertions(+), 2 deletions(-)

---
base-commit: 5e7624979083e2bc163e18165452d8ead462b58c
change-id: 20251210-rk3576-ufs-ac3bf4e87156

Best regards,

Signature · 1 line
Alexey Charkov <[email protected]>
#1 lore raw

PATCH v2 1/3 spl: Make UFS available for SPL builds

Add minimal infrastructure to build SPL images with support for UFS storage devices. This also pulls in SCSI support and charset functions, which are dependencies of the UFS code.

With this, only a fixed offset is supported for loading the next image, which should be specified in CONFIG_SPL_UFS_RAW_U_BOOT_SECTOR as the number of 4096-byte sectors into the UFS block device.

---
 MAINTAINERS                |  1 +
 arch/arm/include/asm/spl.h |  1 +
 common/spl/Kconfig         | 48 ++++++++++++++++++++++++++++++++++
 common/spl/Makefile        |  1 +
 common/spl/spl_ufs.c       | 65 ++++++++++++++++++++++++++++++++++++++++++++++
 drivers/Makefile           |  1 +
 drivers/scsi/Makefile      |  3 +++
 lib/Makefile               |  1 +
 8 files changed, 121 insertions(+)
MAINTAINERS +1 -0
index 27ce73d83f48..ca31e57f018a 100644
@@ -1861,6 +1861,7 @@ M:	Neil Armstrong <[email protected]>
 M:	Bhupesh Sharma <[email protected]>
 M:	Neha Malcom Francis <[email protected]>
 S:	Maintained
+F:	common/spl/spl_ufs.c
 F:	drivers/ufs/
 
 UPL
arch/arm/include/asm/spl.h +1 -0
index ee79a19c05c9..dd462ea6ad82 100644
@@ -30,6 +30,7 @@ enum {
 	BOOT_DEVICE_XIP,
 	BOOT_DEVICE_BOOTROM,
 	BOOT_DEVICE_SMH,
+	BOOT_DEVICE_UFS,
 	BOOT_DEVICE_NONE
 };
 #endif
common/spl/Kconfig +48 -0

54 lines not on this page · raw message

common/spl/Makefile +1 -0
index 4c9482bd3096..e18f3cf09484 100644
@@ -37,6 +37,7 @@ obj-$(CONFIG_$(PHASE_)DFU) += spl_dfu.o
 obj-$(CONFIG_$(PHASE_)SPI_LOAD) += spl_spi.o
 obj-$(CONFIG_$(PHASE_)RAM_SUPPORT) += spl_ram.o
 obj-$(CONFIG_$(PHASE_)USB_SDP_SUPPORT) += spl_sdp.o
+obj-$(CONFIG_$(PHASE_)UFS_SUPPORT) += spl_ufs.o
 endif
 
 obj-$(CONFIG_$(PHASE_)UPL) += spl_upl.o
common/spl/spl_ufs.c new file +65 -0

65 lines not on this page · raw message

drivers/Makefile +1 -0
index de993ae42ac7..43d0ba332818 100644
@@ -73,6 +73,7 @@ obj-$(CONFIG_SPL_USB_HOST) += usb/host/
 obj-$(CONFIG_SPL_SATA) += ata/ scsi/
 obj-$(CONFIG_SPL_LEGACY_BLOCK) += block/
 obj-$(CONFIG_SPL_THERMAL) += thermal/
+obj-$(CONFIG_SPL_UFS_SUPPORT) += scsi/ ufs/
 
 endif
 endif
drivers/scsi/Makefile +3 -0
index b76de1b22a8b..c9af60d5d03c 100644
@@ -16,4 +16,7 @@ ifdef CONFIG_XPL_BUILD
 ifdef CONFIG_SPL_SATA
 obj-$(CONFIG_SCSI) += scsi.o scsi-uclass.o
 endif
+ifdef CONFIG_SPL_UFS_SUPPORT
+obj-$(CONFIG_SCSI) += scsi.o scsi-uclass.o
+endif
 endif
lib/Makefile +1 -0
index 70667f3728c2..d0ffabc2b476 100644
@@ -147,6 +147,7 @@ else
 obj-$(CONFIG_$(PHASE_)SPRINTF) += vsprintf.o
 endif
 obj-$(CONFIG_$(PHASE_)STRTO) += strto.o
+obj-$(CONFIG_$(PHASE_)UFS_SUPPORT) += charset.o
 else
 # Main U-Boot always uses the full printf support
 obj-y += vsprintf.o strto.o
Signature · 1 line
2.51.2
#2 lore raw

Re: [PATCH v2 1/3] spl: Make UFS available for SPL builds

Quoted 9 lines · Alexey Charkov

Add minimal infrastructure to build SPL images with support for UFS storage devices. This also pulls in SCSI support and charset functions, which are dependencies of the UFS code.

With this, only a fixed offset is supported for loading the next image, which should be specified in CONFIG_SPL_UFS_RAW_U_BOOT_SECTOR as the number of 4096-byte sectors into the UFS block device.

[snip]

Quoted 8 lines
common/spl/Kconfig +8 -0
+config SPL_UFS_SUPPORT
+	bool "Support loading from UFS"
+	select SPL_LOAD_BLOCK
+	help
+	  Enable support for UFS in SPL. This allows
+	  use of UFS devices such as hard drives and flash drivers for
+	  loading U-Boot.
+

common/spl/Kconfig config SPL_THERMAL · line 1632

Quoted 10 lines
common/spl/Kconfig +10 -0
+config SPL_UFS_BOUNCE_BUF
+	bool "Use a bounce buffer for UFS loading"
+	depends on SPL_UFS_SUPPORT
+	default y if ARCH_ROCKCHIP
+	help
+	  On some platforms the UFS host controller may be unable to load all
+	  image segments directly to their required memory locations (e.g. due
+	  to DMA constraints). This option enables an interim bounce buffer in
+	  system RAM to let such platforms boot directly from UFS, at a cost of
+	  an additional memory move while loading the image.

So, the full U-Boot rockchip UFS driver does not use the generic BOUNCE_BUFFER mechanism. Is this because of memory constraints in SPL? Second, can we not just re-use the generic bounce buffer code (common/bouncebuf.c) ? Thanks.

Signature · 1 line
Tom
#3 lore raw

Re: [PATCH v2 1/3] spl: Make UFS available for SPL builds

Hi Tom, Neil,

Your replies came pretty much simultaneously :)

Quoted 36 lines · Tom Rini
Quoted 9 lines · Alexey Charkov

Add minimal infrastructure to build SPL images with support for UFS storage devices. This also pulls in SCSI support and charset functions, which are dependencies of the UFS code.

With this, only a fixed offset is supported for loading the next image, which should be specified in CONFIG_SPL_UFS_RAW_U_BOOT_SECTOR as the number of 4096-byte sectors into the UFS block device.

[snip]

Quoted 8 lines
common/spl/Kconfig +8 -0
+config SPL_UFS_SUPPORT
+     bool "Support loading from UFS"
+     select SPL_LOAD_BLOCK
+     help
+       Enable support for UFS in SPL. This allows
+       use of UFS devices such as hard drives and flash drivers for
+       loading U-Boot.
+

common/spl/Kconfig config SPL_THERMAL · line 1632

Quoted 10 lines
common/spl/Kconfig +10 -0
+config SPL_UFS_BOUNCE_BUF
+     bool "Use a bounce buffer for UFS loading"
+     depends on SPL_UFS_SUPPORT
+     default y if ARCH_ROCKCHIP
+     help
+       On some platforms the UFS host controller may be unable to load all
+       image segments directly to their required memory locations (e.g. due
+       to DMA constraints). This option enables an interim bounce buffer in
+       system RAM to let such platforms boot directly from UFS, at a cost of
+       an additional memory move while loading the image.

So, the full U-Boot rockchip UFS driver does not use the generic BOUNCE_BUFFER mechanism. Is this because of memory constraints in SPL? Second, can we not just re-use the generic bounce buffer code (common/bouncebuf.c) ? Thanks.

Quoted 1 line · Neil Armstrong

Can't this be replaced by the SCSI bounce buffer ?

Thanks for the pointers. Frankly, I've overlooked the existing generic functionality, being somewhat new to the codebase.

It seems that the current UFSHC driver only deals with broken 64-bit addressing when deciding to use a generic bounce buffer, while the constraint in this case is that part of the FIT image containing the ATF wants to load itself not to system RAM, but to a PMU SRAM region, which is inaccessible to the UFSHC's DMA engine either due to security firewall settings (as Jonas Karlman proposed in his comments to v1 of this series) or some other reason.

I guess I could add a per-variant override of the scsi_ops ->buffer_aligned() callback (which in turn gets propagated to blk_ops), checking if the requested buffer is above/below the start of RAM on Rockchip RK3576 specifically? Just wondering whether that would be considered an abuse of the interface, given that it's not really anything to do with alignment as the callback name implies.

Best regards,
Alexey

#4 lore raw

Re: [PATCH v2 1/3] spl: Make UFS available for SPL builds

Quoted 57 lines · Alexey Charkov

Hi Tom, Neil,

Your replies came pretty much simultaneously :)

Quoted 36 lines · Tom Rini
Quoted 9 lines · Alexey Charkov

Add minimal infrastructure to build SPL images with support for UFS storage devices. This also pulls in SCSI support and charset functions, which are dependencies of the UFS code.

With this, only a fixed offset is supported for loading the next image, which should be specified in CONFIG_SPL_UFS_RAW_U_BOOT_SECTOR as the number of 4096-byte sectors into the UFS block device.

[snip]

Quoted 8 lines
(quoted diff) +8 -0
+config SPL_UFS_SUPPORT
+     bool "Support loading from UFS"
+     select SPL_LOAD_BLOCK
+     help
+       Enable support for UFS in SPL. This allows
+       use of UFS devices such as hard drives and flash drivers for
+       loading U-Boot.
+

Review

Quoted 10 lines
(quoted diff) +10 -0
+config SPL_UFS_BOUNCE_BUF
+     bool "Use a bounce buffer for UFS loading"
+     depends on SPL_UFS_SUPPORT
+     default y if ARCH_ROCKCHIP
+     help
+       On some platforms the UFS host controller may be unable to load all
+       image segments directly to their required memory locations (e.g. due
+       to DMA constraints). This option enables an interim bounce buffer in
+       system RAM to let such platforms boot directly from UFS, at a cost of
+       an additional memory move while loading the image.

So, the full U-Boot rockchip UFS driver does not use the generic BOUNCE_BUFFER mechanism. Is this because of memory constraints in SPL? Second, can we not just re-use the generic bounce buffer code (common/bouncebuf.c) ? Thanks.

Quoted 1 line · Neil Armstrong

Can't this be replaced by the SCSI bounce buffer ?

Thanks for the pointers. Frankly, I've overlooked the existing generic functionality, being somewhat new to the codebase.

It seems that the current UFSHC driver only deals with broken 64-bit addressing when deciding to use a generic bounce buffer, while the constraint in this case is that part of the FIT image containing the ATF wants to load itself not to system RAM, but to a PMU SRAM region, which is inaccessible to the UFSHC's DMA engine either due to security firewall settings (as Jonas Karlman proposed in his comments to v1 of this series) or some other reason.

Quoted 6 lines

I guess I could add a per-variant override of the scsi_ops ->buffer_aligned() callback (which in turn gets propagated to blk_ops), checking if the requested buffer is above/below the start of RAM on Rockchip RK3576 specifically? Just wondering whether that would be considered an abuse of the interface, given that it's not really anything to do with alignment as the callback name implies.

Quick update. I can confirm that the following one-liner works just fine instead of my open-coded version:

drivers/ufs/ufs-uclass.c +0 -0
index 3c8e4299259c..eb2882d35e03 100644
@@ -2257,7 +2257,7 @@ static int ufs_scsi_buffer_aligned(struct

udevice *scsi_dev, struct bounce_buffe

                return 0;
        }

#endif
- return 1;
+ return (ulong)state->user_buffer >= CFG_SYS_SDRAM_BASE;
}
#endif /* CONFIG_BOUNCE_BUFFER */

Would anything of this sort be acceptable? Happy to adjust in v3.

I'm guessing that DMA reads to an address not in SDRAM is a niche situation, so no one should be too upset about them going through a bounce buffer. Furthermore, this block of code would currently only apply to Rockchip RK3576 and Renesas gen4/gen5 by the virtue of Kconfig dependencies.

Best regards,
Alexey

#5 lore raw

Re: [PATCH v2 1/3] spl: Make UFS available for SPL builds

In reply to Alexey Charkov
Quoted 60 lines · Alexey Charkov

Add minimal infrastructure to build SPL images with support for UFS storage devices. This also pulls in SCSI support and charset functions, which are dependencies of the UFS code.

With this, only a fixed offset is supported for loading the next image, which should be specified in CONFIG_SPL_UFS_RAW_U_BOOT_SECTOR as the number of 4096-byte sectors into the UFS block device.

---
  MAINTAINERS                |  1 +
  arch/arm/include/asm/spl.h |  1 +
  common/spl/Kconfig         | 48 ++++++++++++++++++++++++++++++++++
  common/spl/Makefile        |  1 +
  common/spl/spl_ufs.c       | 65 ++++++++++++++++++++++++++++++++++++++++++++++
  drivers/Makefile           |  1 +
  drivers/scsi/Makefile      |  3 +++
  lib/Makefile               |  1 +
  8 files changed, 121 insertions(+)
MAINTAINERS +1 -0
index 27ce73d83f48..ca31e57f018a 100644
@@ -1861,6 +1861,7 @@ M:	Neil Armstrong <[email protected]>
  M:	Bhupesh Sharma <[email protected]>
  M:	Neha Malcom Francis <[email protected]>
  S:	Maintained
+F:	common/spl/spl_ufs.c
  F:	drivers/ufs/
 
  UPL
arch/arm/include/asm/spl.h +1 -0
index ee79a19c05c9..dd462ea6ad82 100644
@@ -30,6 +30,7 @@ enum {
  	BOOT_DEVICE_XIP,
  	BOOT_DEVICE_BOOTROM,
  	BOOT_DEVICE_SMH,
+	BOOT_DEVICE_UFS,
  	BOOT_DEVICE_NONE
  };
  #endif
common/spl/Kconfig +8 -0
index 4f4119f5806c..1ed7f56598f6 100644
@@ -1612,6 +1612,54 @@ config SPL_THERMAL
  	  automatic power-off when the temperature gets too high or low. Other
  	  devices may be discrete but connected on a suitable bus.
 
+config SPL_UFS_SUPPORT
+	bool "Support loading from UFS"
+	select SPL_LOAD_BLOCK
+	help
+	  Enable support for UFS in SPL. This allows
+	  use of UFS devices such as hard drives and flash drivers for
+	  loading U-Boot.
+

common/spl/Kconfig config SPL_THERMAL · line 1632

Quoted 10 lines
common/spl/Kconfig +10 -0
+config SPL_UFS_BOUNCE_BUF
+	bool "Use a bounce buffer for UFS loading"
+	depends on SPL_UFS_SUPPORT
+	default y if ARCH_ROCKCHIP
+	help
+	  On some platforms the UFS host controller may be unable to load all
+	  image segments directly to their required memory locations (e.g. due
+	  to DMA constraints). This option enables an interim bounce buffer in
+	  system RAM to let such platforms boot directly from UFS, at a cost of
+	  an additional memory move while loading the image.

Can't this be replaced by the SCSI bounce buffer ?

Quoted 153 lines
common/spl/Kconfig +30 -0
+
+config SPL_UFS_BOUNCE_BUF_ADDR
+	hex "Memory address of the bounce buffer for UFS loading"
+	depends on SPL_UFS_BOUNCE_BUF
+	default SYS_LOAD_ADDR
+	help
+	  Address of a memory region to use as the interim bounce buffer when
+	  loading images from UFS.
+
+config SPL_UFS_RAW_U_BOOT_DEVNUM
+	int "SCSI device number of the UFS device to load U-Boot from"
+	depends on SPL_UFS_SUPPORT
+	default 0
+	help
+	  UFS devices are usually configured with multiple LUNs, which present
+	  themselves as sequentially numbered SCSI devices. Usually one would
+	  get a default LUN 0 taking up most of the space on the device, with
+	  a number of smaller LUNs following it. This option controls which of
+	  them the SPL will attempt to load U-Boot from. Note that this is the
+	  SCSI device number, which might differ from the UFS LUN if you have
+	  multiple SCSI devices attached and recognized by the SPL.
+
+config SPL_UFS_RAW_U_BOOT_SECTOR
+	hex "Address on the UFS to load U-Boot from"
+	depends on SPL_UFS_SUPPORT
+	default 0x800 if ARCH_ROCKCHIP
+	help
+	  Address on the block device to load U-Boot from,
+	  Units: UFS sectors (1 sector = 4096 bytes).
+
  config SPL_WATCHDOG
  	bool "Support watchdog drivers"
  	imply SPL_WDT if !HW_WATCHDOG
common/spl/Makefile +1 -0
index 4c9482bd3096..e18f3cf09484 100644
@@ -37,6 +37,7 @@ obj-$(CONFIG_$(PHASE_)DFU) += spl_dfu.o
  obj-$(CONFIG_$(PHASE_)SPI_LOAD) += spl_spi.o
  obj-$(CONFIG_$(PHASE_)RAM_SUPPORT) += spl_ram.o
  obj-$(CONFIG_$(PHASE_)USB_SDP_SUPPORT) += spl_sdp.o
+obj-$(CONFIG_$(PHASE_)UFS_SUPPORT) += spl_ufs.o
  endif
 
  obj-$(CONFIG_$(PHASE_)UPL) += spl_upl.o
common/spl/spl_ufs.c new file +65 -0
new file mode 100644
index 000000000000..3952bc4be0a2
@@ -0,0 +1,65 @@
+// SPDX-License-Identifier: GPL-2.0+
+/*
+ * (C) Copyright 2025 Alexey Charkov <[email protected]>
+ */
+
+#include <spl.h>
+#include <spl_load.h>
+#include <scsi.h>
+#include <errno.h>
+#include <image.h>
+#include <linux/compiler.h>
+#include <log.h>
+
+static ulong spl_ufs_load_read(struct spl_load_info *load, ulong off, ulong size, void *buf)
+{
+	ulong bounce_buf_addr = config_opt_enabled(CONFIG_SPL_UFS_BOUNCE_BUF,
+						   CONFIG_SPL_UFS_BOUNCE_BUF_ADDR, 0);
+	struct blk_desc *bd = load->priv;
+	lbaint_t sector = off >> bd->log2blksz;
+	lbaint_t count = size >> bd->log2blksz;
+	void *bounce_buf;
+	ulong ret;
+
+	if (IS_ENABLED(CONFIG_SPL_UFS_BOUNCE_BUF)) {
+		bounce_buf = map_sysmem(ALIGN(bounce_buf_addr, ARCH_DMA_MINALIGN), size);
+		ret = blk_dread(bd, sector, count, bounce_buf);
+		if (ret <= 0)
+			return ret;
+
+		ret <<= bd->log2blksz;
+		memmove(buf, bounce_buf, ret);
+
+		return ret;
+	} else {
+		return blk_dread(bd, sector, count, buf) << bd->log2blksz;
+	}
+}
+
+static int spl_ufs_load_image(struct spl_image_info *spl_image,
+			      struct spl_boot_device *bootdev)
+{
+	int err = -ENOSYS;
+	struct blk_desc *bd;
+	struct spl_load_info load;
+	int devnum = CONFIG_SPL_UFS_RAW_U_BOOT_DEVNUM;
+	unsigned long sector = CONFIG_SPL_UFS_RAW_U_BOOT_SECTOR;
+
+	/* try to recognize storage devices immediately */
+	scsi_scan(false);
+	bd = blk_get_devnum_by_uclass_id(UCLASS_SCSI, devnum);
+	if (!bd)
+		return -ENODEV;
+
+	spl_load_init(&load, spl_ufs_load_read, bd, bd->blksz);
+	err = spl_load(spl_image, bootdev, &load, 0, sector << bd->log2blksz);
+	if (err) {
+		puts("spl_ufs_load_image: ufs block read error\n");
+		log_debug("(error=%d)\n", err);
+		return err;
+	}
+
+	return 0;
+}
+
+SPL_LOAD_IMAGE_METHOD("UFS", 0, BOOT_DEVICE_UFS, spl_ufs_load_image);
drivers/Makefile +1 -0
index de993ae42ac7..43d0ba332818 100644
@@ -73,6 +73,7 @@ obj-$(CONFIG_SPL_USB_HOST) += usb/host/
  obj-$(CONFIG_SPL_SATA) += ata/ scsi/
  obj-$(CONFIG_SPL_LEGACY_BLOCK) += block/
  obj-$(CONFIG_SPL_THERMAL) += thermal/
+obj-$(CONFIG_SPL_UFS_SUPPORT) += scsi/ ufs/
 
  endif
  endif
drivers/scsi/Makefile +3 -0
index b76de1b22a8b..c9af60d5d03c 100644
@@ -16,4 +16,7 @@ ifdef CONFIG_XPL_BUILD
  ifdef CONFIG_SPL_SATA
  obj-$(CONFIG_SCSI) += scsi.o scsi-uclass.o
  endif
+ifdef CONFIG_SPL_UFS_SUPPORT
+obj-$(CONFIG_SCSI) += scsi.o scsi-uclass.o
+endif
  endif
lib/Makefile +1 -0
index 70667f3728c2..d0ffabc2b476 100644
@@ -147,6 +147,7 @@ else
  obj-$(CONFIG_$(PHASE_)SPRINTF) += vsprintf.o
  endif
  obj-$(CONFIG_$(PHASE_)STRTO) += strto.o
+obj-$(CONFIG_$(PHASE_)UFS_SUPPORT) += charset.o
  else
  # Main U-Boot always uses the full printf support
  obj-y += vsprintf.o strto.o
#6 lore raw

PATCH v2 2/3 ufs: rockchip: Add device reset support

In reply to Alexey Charkov

Wire up the GPIO line which Rockchip RK3576 UFS controller uses to reset the connected UFS device.

This seems necessary at least for some UFS modules and fixes the following error while enumerating UFS storage:

ufshcd-rockchip ufshc@2a2d0000: ufshcd_link_startup: Device not present ufshcd-rockchip ufshc@2a2d0000: link startup failed -6 ufshcd-rockchip ufshc@2a2d0000: ufshcd_pltfrm_init() failed -6

Fixes 76465ce21ee4 ("ufs: rockchip: Add initial support")
---
 drivers/ufs/Kconfig        |  1 +
 drivers/ufs/ufs-rockchip.c | 25 +++++++++++++++++++++++++
 drivers/ufs/ufs-rockchip.h |  1 +
 3 files changed, 27 insertions(+)
drivers/ufs/Kconfig +1 -0
index 6c75bb2a0790..30b0c87798e1 100644
@@ -76,6 +76,7 @@ config UFS_RENESAS_GEN5
 config UFS_ROCKCHIP
 	bool "Rockchip specific hooks to UFS controller platform driver"
 	depends on UFS
+	select DM_GPIO
 	help
 	  This selects the Rockchip specific additions to UFSHCD platform driver.
 
drivers/ufs/ufs-rockchip.c +25 -0
index 0384244387da..48444705fb29 100644
@@ -5,6 +5,7 @@
  * Copyright (C) 2025 Rockchip Electronics Co.Ltd.
  */
 
+#include <asm/gpio.h>
 #include <asm/io.h>
 #include <clk.h>
 #include <dm.h>
@@ -153,11 +154,34 @@ static int ufs_rockchip_common_init(struct ufs_hba *hba)
 		return err;
 	}
 
+	err = gpio_request_by_name(dev, "reset-gpios", 0, &host->device_reset,
+				   GPIOD_IS_OUT | GPIOD_ACTIVE_LOW);
+	if (err) {
+		dev_err(dev, "Warning: cannot get reset GPIO\n");
+		return err;
+	}
+
 	host->hba = hba;
 
 	return 0;
 }
 
+static int ufs_rockchip_device_reset(struct ufs_hba *hba)
+{
+	struct ufs_rockchip_host *host = dev_get_priv(hba->dev);
+
+	if (!dm_gpio_is_valid(&host->device_reset))
+		return 0;
+
+	dm_gpio_set_value(&host->device_reset, true);
+	udelay(20);
+
+	dm_gpio_set_value(&host->device_reset, false);
+	udelay(20);
+
+	return 0;
+}
+
 static int ufs_rockchip_rk3576_init(struct ufs_hba *hba)
 {
 	int ret = 0;
@@ -175,6 +199,7 @@ static struct ufs_hba_ops ufs_hba_rk3576_vops = {
 	.init = ufs_rockchip_rk3576_init,
 	.phy_initialization = ufs_rockchip_rk3576_phy_init,
 	.hce_enable_notify = ufs_rockchip_hce_enable_notify,
+	.device_reset = ufs_rockchip_device_reset,
 };
 
 static const struct udevice_id ufs_rockchip_of_match[] = {
drivers/ufs/ufs-rockchip.h +1 -0
index 3dcb80f57020..50c2539da78a 100644
@@ -72,6 +72,7 @@ struct ufs_rockchip_host {
 	void __iomem *ufs_sys_ctrl;
 	void __iomem *mphy_base;
 	struct reset_ctl_bulk rsts;
+	struct gpio_desc device_reset;
 	struct clk ref_out_clk;
 	uint64_t caps;
 	uint32_t phy_config_mode;
Signature · 1 line
2.51.2
Reviewed-by on v2 2/3
#7 lore raw

Re: [PATCH v2 2/3] ufs: rockchip: Add device reset support

Quoted 10 lines · Alexey Charkov

Wire up the GPIO line which Rockchip RK3576 UFS controller uses to reset the connected UFS device.

This seems necessary at least for some UFS modules and fixes the following error while enumerating UFS storage:

ufshcd-rockchip ufshc@2a2d0000: ufshcd_link_startup: Device not present ufshcd-rockchip ufshc@2a2d0000: link startup failed -6 ufshcd-rockchip ufshc@2a2d0000: ufshcd_pltfrm_init() failed -6

LGTM, thanks.

Quoted 89 lines
Fixes 76465ce21ee4 ("ufs: rockchip: Add initial support")
---
  drivers/ufs/Kconfig        |  1 +
  drivers/ufs/ufs-rockchip.c | 25 +++++++++++++++++++++++++
  drivers/ufs/ufs-rockchip.h |  1 +
  3 files changed, 27 insertions(+)
drivers/ufs/Kconfig +1 -0
index 6c75bb2a0790..30b0c87798e1 100644
@@ -76,6 +76,7 @@ config UFS_RENESAS_GEN5
  config UFS_ROCKCHIP
  	bool "Rockchip specific hooks to UFS controller platform driver"
  	depends on UFS
+	select DM_GPIO
  	help
  	  This selects the Rockchip specific additions to UFSHCD platform driver.
 
drivers/ufs/ufs-rockchip.c +25 -0
index 0384244387da..48444705fb29 100644
@@ -5,6 +5,7 @@
   * Copyright (C) 2025 Rockchip Electronics Co.Ltd.
   */
 
+#include <asm/gpio.h>
  #include <asm/io.h>
  #include <clk.h>
  #include <dm.h>
@@ -153,11 +154,34 @@ static int ufs_rockchip_common_init(struct ufs_hba *hba)
  		return err;
  	}
 
+	err = gpio_request_by_name(dev, "reset-gpios", 0, &host->device_reset,
+				   GPIOD_IS_OUT | GPIOD_ACTIVE_LOW);
+	if (err) {
+		dev_err(dev, "Warning: cannot get reset GPIO\n");
+		return err;
+	}
+
  	host->hba = hba;
 
  	return 0;
  }
 
+static int ufs_rockchip_device_reset(struct ufs_hba *hba)
+{
+	struct ufs_rockchip_host *host = dev_get_priv(hba->dev);
+
+	if (!dm_gpio_is_valid(&host->device_reset))
+		return 0;
+
+	dm_gpio_set_value(&host->device_reset, true);
+	udelay(20);
+
+	dm_gpio_set_value(&host->device_reset, false);
+	udelay(20);
+
+	return 0;
+}
+
  static int ufs_rockchip_rk3576_init(struct ufs_hba *hba)
  {
  	int ret = 0;
@@ -175,6 +199,7 @@ static struct ufs_hba_ops ufs_hba_rk3576_vops = {
  	.init = ufs_rockchip_rk3576_init,
  	.phy_initialization = ufs_rockchip_rk3576_phy_init,
  	.hce_enable_notify = ufs_rockchip_hce_enable_notify,
+	.device_reset = ufs_rockchip_device_reset,
  };
 
  static const struct udevice_id ufs_rockchip_of_match[] = {
drivers/ufs/ufs-rockchip.h +1 -0
index 3dcb80f57020..50c2539da78a 100644
@@ -72,6 +72,7 @@ struct ufs_rockchip_host {
  	void __iomem *ufs_sys_ctrl;
  	void __iomem *mphy_base;
  	struct reset_ctl_bulk rsts;
+	struct gpio_desc device_reset;
  	struct clk ref_out_clk;
  	uint64_t caps;
  	uint32_t phy_config_mode;
#8 lore raw

PATCH v2 3/3 rockchip: spl: Add support for booting from UFS

In reply to Alexey Charkov

Add the required architecture-specific lookups to enable U-boot SPL to load images from UFS storage devices on Rockchip RK3576, which has a boot ROM capable of loading the SPL image from UFS.

This also requires the DM_RESET framework to be available in SPL, as the UFS driver uses it.

---
 arch/arm/dts/rk3576-u-boot.dtsi              | 13 ++++++++++++-
 arch/arm/include/asm/arch-rockchip/bootrom.h |  1 +
 arch/arm/mach-rockchip/Kconfig               |  3 +++
 arch/arm/mach-rockchip/rk3576/rk3576.c       |  1 +
 arch/arm/mach-rockchip/spl-boot-order.c      | 14 ++++++++++++++
 drivers/reset/Kconfig                        |  9 +++++++++
 drivers/reset/Makefile                       |  2 +-
 7 files changed, 41 insertions(+), 2 deletions(-)
arch/arm/dts/rk3576-u-boot.dtsi +12 -1
index dc3771b556a3..84d9f39fd407 100644
@@ -12,7 +12,7 @@
 	};
 
 	chosen {
-		u-boot,spl-boot-order = "same-as-spl", &sdmmc, &sdhci;
+		u-boot,spl-boot-order = "same-as-spl", &sdmmc, &sdhci, &ufshc;
 	};
 
 	dmc {
@@ -81,6 +81,12 @@
 	bootph-some-ram;
 };
 
+&gpio4 {
+	/* Used for resetting the UFS device during initialization */
+	bootph-pre-ram;
+	bootph-some-ram;
+};
+
 &ioc_grf {
 	bootph-all;
 };
@@ -176,6 +182,11 @@
 	bootph-pre-ram;
 };
 
+&ufshc {
+	bootph-pre-ram;
+	bootph-some-ram;
+};
+
 &xin24m {
 	bootph-all;
 };
arch/arm/include/asm/arch-rockchip/bootrom.h +1 -0
index b15938c021d6..f9ecb6858f04 100644
@@ -51,6 +51,7 @@ enum {
 	BROM_BOOTSOURCE_SPINOR = 3,
 	BROM_BOOTSOURCE_SPINAND = 4,
 	BROM_BOOTSOURCE_SD = 5,
+	BROM_BOOTSOURCE_UFS = 7,
 	BROM_BOOTSOURCE_I2C = 8,
 	BROM_BOOTSOURCE_SPI = 9,
 	BROM_BOOTSOURCE_USB = 10,
arch/arm/mach-rockchip/Kconfig +3 -0
index 92bb4aa62f11..483a2f7c4ab2 100644
@@ -436,6 +436,9 @@ config ROCKCHIP_RK3576
 	imply SPL_ATF_NO_PLATFORM_PARAM if SPL_ATF
 	imply SPL_CLK
 	imply SPL_DM_SEQ_ALIAS
+	imply SPL_DM_GPIO if UFS_ROCKCHIP && SPL_UFS_SUPPORT
+	imply SPL_DM_RESET if UFS_ROCKCHIP && SPL_UFS_SUPPORT
+	imply SPL_GPIO if UFS_ROCKCHIP && SPL_UFS_SUPPORT
 	imply SPL_FIT_SIGNATURE
 	imply SPL_LOAD_FIT
 	imply SPL_MMC_HS200_SUPPORT if SPL_MMC && MMC_HS200_SUPPORT
arch/arm/mach-rockchip/rk3576/rk3576.c +1 -0
index a1e8a7572fa4..46cf60dc77c7 100644
@@ -46,6 +46,7 @@ const char * const boot_devices[BROM_LAST_BOOTSOURCE + 1] = {
 	[BROM_BOOTSOURCE_FSPI0] = "/soc/spi@2a340000/flash@0",
 	[BROM_BOOTSOURCE_FSPI1_M1] = "/soc/spi@2a300000/flash@0",
 	[BROM_BOOTSOURCE_SD] = "/soc/mmc@2a310000",
+	[BROM_BOOTSOURCE_UFS] = "/soc/ufshc@2a2d0000",
 };
 
 static struct mm_region rk3576_mem_map[] = {
arch/arm/mach-rockchip/spl-boot-order.c +14 -0
index 6572dde29f65..d2dd5e10935f 100644
@@ -76,6 +76,9 @@ static int spl_node_to_boot_device(int node)
 	if (!uclass_find_device_by_of_offset(UCLASS_SPI_FLASH, node, &parent))
 		return BOOT_DEVICE_SPI;
 
+	if (!uclass_find_device_by_of_offset(UCLASS_UFS, node, &parent))
+		return BOOT_DEVICE_UFS;
+
 	return -1;
 }
 
@@ -231,6 +234,17 @@ int spl_decode_boot_device(u32 boot_device, char *buf, size_t buflen)
 		return -ENODEV;
 	}
 
+	if (boot_device == BOOT_DEVICE_UFS) {
+		ret = uclass_find_device(UCLASS_UFS, 0, &dev);
+		if (ret) {
+			debug("%s: could not find device for UFS: %d\n",
+			      __func__, ret);
+			return ret;
+		}
+
+		return ofnode_get_path(dev_ofnode(dev), buf, buflen);
+	}
+
 #if CONFIG_IS_ENABLED(BLK)
 	dev_num = (boot_device == BOOT_DEVICE_MMC1) ? 0 : 1;
 
drivers/reset/Kconfig +9 -0
index 74c267dfc4e5..d35f3904e404 100644
@@ -99,6 +99,15 @@ config RESET_ROCKCHIP
 	  though is that some reset signals, like I2C or MISC reset multiple
 	  devices.
 
+config SPL_RESET_ROCKCHIP
+	bool "SPL reset controller driver for Rockchip SoCs"
+	depends on SPL_DM_RESET && ARCH_ROCKCHIP && CLK
+	default y
+	help
+	  Support for the reset controller on Rockchip SoCs in SPL. Select this
+	  if you observe any reset-related warnings or errors when booting SPL,
+	  such as when using UFS storage
+
 config RESET_HSDK
 	bool "Synopsys HSDK Reset Driver"
 	depends on DM_RESET && TARGET_HSDK
drivers/reset/Makefile +1 -1
index ee5b009d1341..dc7d3b610e6e 100644
@@ -16,7 +16,7 @@ obj-$(CONFIG_RESET_BCM6345) += reset-bcm6345.o
 obj-$(CONFIG_RESET_UNIPHIER) += reset-uniphier.o
 obj-$(CONFIG_RESET_AST2500) += reset-ast2500.o
 obj-$(CONFIG_RESET_AST2600) += reset-ast2600.o
-obj-$(CONFIG_RESET_ROCKCHIP) += reset-rockchip.o rst-rk3528.o rst-rk3576.o rst-rk3588.o
+obj-$(CONFIG_$(PHASE_)RESET_ROCKCHIP) += reset-rockchip.o rst-rk3528.o rst-rk3576.o rst-rk3588.o
 obj-$(CONFIG_RESET_MESON) += reset-meson.o
 obj-$(CONFIG_RESET_SOCFPGA) += reset-socfpga.o
 obj-$(CONFIG_RESET_MEDIATEK) += reset-mediatek.o
Signature · 1 line
2.51.2