Skip to contentSkip to conversation

Enable full UFS boot on Rockchip RK3576

PATCH Superseded Alexey Charkov 3 participants 10 messages Jan 6 – Jan 8

Subsystems (6)

v3 of 6 Superseded Latest is v6 →

lore
Share & tools
lore
#0 lore raw

v3 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)
- Patches 2-3 introduce a quirk for the UFSHC to force the use of a SCSI bounce buffer for addresses outside system SDRAM, and enable it on Rockchip RK3576
- Patch 4 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 5 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 4 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 4 is applied.

The bounce buffer and the corresponding quirk is required to enable the loading of ATF image segments into PMU SRAM, which is inaccessible to the UFSHC for direct write on Rockchip RK3576.

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 v3:
- Added a UFSHC quirk to use the SCSI bounce buffer for addresses outside SDRAM, and enabled it on Rockchip (thanks Neil and Tom)
- Dropped the open-coded bounce buffer from spl_ufs.c, now unneeded
- Link to v2: https://lore.kernel.org/r/[email protected]

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 (5):
spl: Make UFS available for SPL builds
ufs: Add a quirk for SDRAM-only DMA
ufs: rockchip: Enable SDRAM-only DMA quirk
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                           | 29 ++++++++++++++++
 common/spl/Makefile                          |  1 +
 common/spl/spl_ufs.c                         | 49 ++++++++++++++++++++++++++++
 drivers/Makefile                             |  1 +
 drivers/reset/Kconfig                        |  9 +++++
 drivers/reset/Makefile                       |  2 +-
 drivers/scsi/Makefile                        |  3 ++
 drivers/ufs/Kconfig                          |  2 ++
 drivers/ufs/ufs-rockchip.c                   | 26 +++++++++++++++
 drivers/ufs/ufs-rockchip.h                   |  1 +
 drivers/ufs/ufs-uclass.c                     | 13 ++++++--
 drivers/ufs/ufs.h                            |  7 ++++
 lib/Makefile                                 |  1 +
 20 files changed, 173 insertions(+), 5 deletions(-)

---
base-commit: 6cdd7597a2fbfc1572c1b0af23d3daf1cefa2de7
change-id: 20251210-rk3576-ufs-ac3bf4e87156

Best regards,

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

PATCH v3 1/5 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         | 29 +++++++++++++++++++++++++++
 common/spl/Makefile        |  1 +
 common/spl/spl_ufs.c       | 49 ++++++++++++++++++++++++++++++++++++++++++++++
 drivers/Makefile           |  1 +
 drivers/scsi/Makefile      |  3 +++
 lib/Makefile               |  1 +
 8 files changed, 86 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 +29 -0
index 4f4119f5806c..6a82260dd010 100644
@@ -1612,6 +1612,35 @@ 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.
+
+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 +49 -0

49 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

PATCH v3 2/5 ufs: Add a quirk for SDRAM-only DMA

In reply to Alexey Charkov

Some UFS controllers can only directly access buffers in system SDRAM and not in other memory (such as various SRAM regions used for low power states).

To enable block reads and writes from UFS to such non-SDRAM addresses, add a quirk forcing the UFS core to use a bounce buffer whenever the requested user buffer falls outside the system RAM range.

---
 drivers/ufs/ufs-uclass.c | 13 ++++++++++---
 drivers/ufs/ufs.h        |  7 +++++++
 2 files changed, 17 insertions(+), 3 deletions(-)
drivers/ufs/ufs-uclass.c +10 -3
index 3c8e4299259c..8b0e2f5305d6 100644
@@ -2244,19 +2244,26 @@ int ufshcd_probe(struct udevice *ufs_dev, struct ufs_hba_ops *hba_ops)
 #if IS_ENABLED(CONFIG_BOUNCE_BUFFER)
 static int ufs_scsi_buffer_aligned(struct udevice *scsi_dev, struct bounce_buffer *state)
 {
-#ifdef CONFIG_PHYS_64BIT
 	struct ufs_hba *hba = dev_get_uclass_priv(scsi_dev->parent);
 	uintptr_t ubuf = (uintptr_t)state->user_buffer;
 	size_t len = state->len_aligned;
 
 	/* Check if below 32bit boundary */
-	if ((hba->quirks & UFSHCD_QUIRK_BROKEN_64BIT_ADDRESS) &&
+	if (IS_ENABLED(CONFIG_PHYS_64BIT) &&
+	    (hba->quirks & UFSHCD_QUIRK_BROKEN_64BIT_ADDRESS) &&
 	    ((ubuf >> 32) || (ubuf + len) >> 32)) {
 		dev_dbg(scsi_dev, "Buffer above 32bit boundary %lx-%lx\n",
 			ubuf, ubuf + len);
 		return 0;
 	}
-#endif
+
+	if ((hba->quirks && UFSHCD_QUIRK_DMA_SDRAM_ONLY) &&
+	    (ubuf < gd->ram_base || (ubuf + len) > gd->ram_top)) {
+		dev_dbg(scsi_dev, "Buffer outside SDRAM %lx-%lx\n",
+			ubuf, ubuf + len);
+		return 0;
+	    };
+
 	return 1;
 }
 #endif	/* CONFIG_BOUNCE_BUFFER */
drivers/ufs/ufs.h +7 -0
index bc839a437045..f860c7143bf7 100644
@@ -691,6 +691,13 @@ enum ufshcd_quirks {
 	 * single doorbell mode.
 	 */
 	UFSHCD_QUIRK_BROKEN_LSDBS_CAP			= 1 << 25,
+
+	/*
+	 * This quirk needs to be enabled if the host controller can only
+	 * access SDRAM addresses but not some other memory type needed for
+	 * U-boot loading or operation
+	 */
+	UFSHCD_QUIRK_DMA_SDRAM_ONLY			= 1 << 26,
 };
 
 struct ufs_hba {
Signature · 1 line
2.51.2
#3 lore raw

PATCH v3 3/5 ufs: rockchip: Enable SDRAM-only DMA quirk

In reply to Alexey Charkov

Rockchip RK3576 can boot fully from UFS, but as part of the boot process the SPL needs to place part of the ATF code into PMU SRAM, which is outside the SDRAM range that the UFSHC can access.

Enable a quirk to force bounce operation for this case.

---
 drivers/ufs/Kconfig        | 1 +
 drivers/ufs/ufs-rockchip.c | 1 +
 2 files changed, 2 insertions(+)
drivers/ufs/Kconfig +1 -0
index 6c75bb2a0790..2543b5d47c04 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 BOUNCE_BUFFER
 	help
 	  This selects the Rockchip specific additions to UFSHCD platform driver.
 
drivers/ufs/ufs-rockchip.c +1 -0
index 0384244387da..699460fc4d15 100644
@@ -153,6 +153,7 @@ static int ufs_rockchip_common_init(struct ufs_hba *hba)
 		return err;
 	}
 
+	hba->quirks |= UFSHCD_QUIRK_DMA_SDRAM_ONLY;
 	host->hba = hba;
 
 	return 0;
Signature · 1 line
2.51.2
#4 lore raw

Re: [PATCH v3 3/5] ufs: rockchip: Enable SDRAM-only DMA quirk

Quoted 29 lines · Alexey Charkov

Rockchip RK3576 can boot fully from UFS, but as part of the boot process the SPL needs to place part of the ATF code into PMU SRAM, which is outside the SDRAM range that the UFSHC can access.

Enable a quirk to force bounce operation for this case.

---
  drivers/ufs/Kconfig        | 1 +
  drivers/ufs/ufs-rockchip.c | 1 +
  2 files changed, 2 insertions(+)
drivers/ufs/Kconfig +1 -0
index 6c75bb2a0790..2543b5d47c04 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 BOUNCE_BUFFER
  	help
  	  This selects the Rockchip specific additions to UFSHCD platform driver.
 
drivers/ufs/ufs-rockchip.c +0 -0
index 0384244387da..699460fc4d15 100644

drivers/ufs/ufs-rockchip.c static int ufs_rockchip_common_init(struct ufs_hba *hba) · line 156

Quoted 4 lines
drivers/ufs/ufs-rockchip.c +1 -0
@@ -153,6 +153,7 @@ static int ufs_rockchip_common_init(struct ufs_hba *hba)
  		return err;
  	}
 
+	hba->quirks |= UFSHCD_QUIRK_DMA_SDRAM_ONLY;

So you really want to enable this quirk for non-SPL builds aswell ?

Neil

Quoted 4 lines
drivers/ufs/ufs-rockchip.c +0 -0
  	host->hba = hba;
 
  	return 0;
#5 lore raw

Re: [PATCH v3 3/5] ufs: rockchip: Enable SDRAM-only DMA quirk

Quoted 34 lines · Neil Armstrong
Quoted 32 lines · Alexey Charkov

Rockchip RK3576 can boot fully from UFS, but as part of the boot process the SPL needs to place part of the ATF code into PMU SRAM, which is outside the SDRAM range that the UFSHC can access.

Enable a quirk to force bounce operation for this case.

---
  drivers/ufs/Kconfig        | 1 +
  drivers/ufs/ufs-rockchip.c | 1 +
  2 files changed, 2 insertions(+)
drivers/ufs/Kconfig +1 -0
index 6c75bb2a0790..2543b5d47c04 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 BOUNCE_BUFFER
      help
        This selects the Rockchip specific additions to UFSHCD platform driver.
 
drivers/ufs/ufs-rockchip.c +0 -0
index 0384244387da..699460fc4d15 100644
@@ -153,6 +153,7 @@ static int ufs_rockchip_common_init(struct ufs_hba *hba)
              return err;
      }
 
Quoted 3 lines

drivers/ufs/ufs-rockchip.c static int ufs_rockchip_common_init(struct ufs_hba *hba) · line 156

Quoted 1 line
drivers/ufs/ufs-rockchip.c +1 -0
+     hba->quirks |= UFSHCD_QUIRK_DMA_SDRAM_ONLY;

So you really want to enable this quirk for non-SPL builds aswell ?

Well I haven't run into any similar issues with the main U-boot, so I don't have a strong opinion about keeping it in place there.

However:
1. Having the quirk enabled doesn't cause all transfers to go via the bounce buffer. Only those for which the provided destination buffer happens to be outside SDRAM (which must be extremely rare if at all possible under U-boot, given that it hasn't caused issues for anyone)
2. If it turns out that there are indeed cases when the UFSHC needs to read or write something outside SDRAM while operating under U-boot (I can't think of a reason now, but then I couldn't think about that ATF to PMU SRAM thing either, until I ran into it and spent more than half a day debugging) then I'd rather spend a couple of CPU cycles on a memmove than end up with a hard lock up, a cryptic error message and a dump of UFSHC status registers
3. It's one line less code this way :)

Happy to add something like "if (xpl_phase() == PHASE_SPL)" though, if that sounds better to everyone.

Best regards,
Alexey

#6 lore raw

Re: [PATCH v3 3/5] ufs: rockchip: Enable SDRAM-only DMA quirk

Hi Alexey,

Quoted 56 lines · Alexey Charkov
Quoted 34 lines · Neil Armstrong
Quoted 32 lines · Alexey Charkov

Rockchip RK3576 can boot fully from UFS, but as part of the boot process the SPL needs to place part of the ATF code into PMU SRAM, which is outside the SDRAM range that the UFSHC can access.

Enable a quirk to force bounce operation for this case.

---
  drivers/ufs/Kconfig        | 1 +
  drivers/ufs/ufs-rockchip.c | 1 +
  2 files changed, 2 insertions(+)
drivers/ufs/Kconfig +1 -0
index 6c75bb2a0790..2543b5d47c04 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 BOUNCE_BUFFER
      help
        This selects the Rockchip specific additions to UFSHCD platform driver.
 
drivers/ufs/ufs-rockchip.c +0 -0
index 0384244387da..699460fc4d15 100644
@@ -153,6 +153,7 @@ static int ufs_rockchip_common_init(struct ufs_hba *hba)
              return err;
      }
 
Quoted 3 lines

drivers/ufs/ufs-rockchip.c static int ufs_rockchip_common_init(struct ufs_hba *hba) · line 156

Quoted 1 line
drivers/ufs/ufs-rockchip.c +1 -0
+     hba->quirks |= UFSHCD_QUIRK_DMA_SDRAM_ONLY;

So you really want to enable this quirk for non-SPL builds aswell ?

Well I haven't run into any similar issues with the main U-boot, so I don't have a strong opinion about keeping it in place there.

However:
1. Having the quirk enabled doesn't cause all transfers to go via the bounce buffer. Only those for which the provided destination buffer happens to be outside SDRAM (which must be extremely rare if at all possible under U-boot, given that it hasn't caused issues for anyone)
2. If it turns out that there are indeed cases when the UFSHC needs to read or write something outside SDRAM while operating under U-boot (I can't think of a reason now, but then I couldn't think about that ATF to PMU SRAM thing either, until I ran into it and spent more than half a day debugging) then I'd rather spend a couple of CPU cycles on a memmove than end up with a hard lock up, a cryptic error message and a dump of UFSHC status registers
3. It's one line less code this way :)

Quoted 2 lines

Happy to add something like "if (xpl_phase() == PHASE_SPL)" though, if that sounds better to everyone.

You should most likely be able to drop this quirk workaround with the "rockchip: rk3576: Fix DMA transfer of TF-A to PMU_SRAM" series [1][2] that I just sent out.

Please try if that also solves the DMA transfer from UFS to PMU SRAM issue, it did for eMMC, SD-card and SPI flash.

[1] https://patchwork.ozlabs.org/cover/2181298/
[2] https://lore.kernel.org/r/[email protected]/

Regards,
Jonas

Quoted 2 lines

Best regards,
Alexey

#7 lore raw

Re: [PATCH v3 3/5] ufs: rockchip: Enable SDRAM-only DMA quirk

Hi Jonas,

Quoted 67 lines · Jonas Karlman

Hi Alexey,

Quoted 56 lines · Alexey Charkov
Quoted 34 lines · Neil Armstrong
Quoted 32 lines · Alexey Charkov

Rockchip RK3576 can boot fully from UFS, but as part of the boot process the SPL needs to place part of the ATF code into PMU SRAM, which is outside the SDRAM range that the UFSHC can access.

Enable a quirk to force bounce operation for this case.

---
  drivers/ufs/Kconfig        | 1 +
  drivers/ufs/ufs-rockchip.c | 1 +
  2 files changed, 2 insertions(+)
drivers/ufs/Kconfig +1 -0
index 6c75bb2a0790..2543b5d47c04 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 BOUNCE_BUFFER
      help
        This selects the Rockchip specific additions to UFSHCD platform driver.
 
drivers/ufs/ufs-rockchip.c +0 -0
index 0384244387da..699460fc4d15 100644
@@ -153,6 +153,7 @@ static int ufs_rockchip_common_init(struct ufs_hba *hba)
              return err;
      }
 
Quoted 3 lines

drivers/ufs/ufs-rockchip.c static int ufs_rockchip_common_init(struct ufs_hba *hba) · line 156

Quoted 1 line
drivers/ufs/ufs-rockchip.c +1 -0
+     hba->quirks |= UFSHCD_QUIRK_DMA_SDRAM_ONLY;

So you really want to enable this quirk for non-SPL builds aswell ?

Well I haven't run into any similar issues with the main U-boot, so I don't have a strong opinion about keeping it in place there.

However:
1. Having the quirk enabled doesn't cause all transfers to go via the bounce buffer. Only those for which the provided destination buffer happens to be outside SDRAM (which must be extremely rare if at all possible under U-boot, given that it hasn't caused issues for anyone)
2. If it turns out that there are indeed cases when the UFSHC needs to read or write something outside SDRAM while operating under U-boot (I can't think of a reason now, but then I couldn't think about that ATF to PMU SRAM thing either, until I ran into it and spent more than half a day debugging) then I'd rather spend a couple of CPU cycles on a memmove than end up with a hard lock up, a cryptic error message and a dump of UFSHC status registers
3. It's one line less code this way :)

Quoted 2 lines

Happy to add something like "if (xpl_phase() == PHASE_SPL)" though, if that sounds better to everyone.

You should most likely be able to drop this quirk workaround with the "rockchip: rk3576: Fix DMA transfer of TF-A to PMU_SRAM" series [1][2] that I just sent out.

Quoted 5 lines

Please try if that also solves the DMA transfer from UFS to PMU SRAM issue, it did for eMMC, SD-card and SPI flash.

[1] https://patchwork.ozlabs.org/cover/2181298/
[2] https://lore.kernel.org/r/[email protected]/

This is brilliant - works like a charm on UFS without any quirks! Thanks a lot, I'll re-roll my patch series without the quirks portion and mark a dependency on your series in b4 metadata.

Best regards,
Alexey

#8 lore raw

PATCH v3 4/5 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 2543b5d47c04..e9b22acb262f 100644
@@ -77,6 +77,7 @@ config UFS_ROCKCHIP
 	bool "Rockchip specific hooks to UFS controller platform driver"
 	depends on UFS
 	select BOUNCE_BUFFER
+	select DM_GPIO
 	help
 	  This selects the Rockchip specific additions to UFSHCD platform driver.
 
drivers/ufs/ufs-rockchip.c +25 -0
index 699460fc4d15..20ad78d5f558 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,12 +154,35 @@ 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;
+	}
+
 	hba->quirks |= UFSHCD_QUIRK_DMA_SDRAM_ONLY;
 	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;
@@ -176,6 +200,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
#9 lore raw

PATCH v3 5/5 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