Enable full UFS boot on Rockchip RK3576
Subsystems (6)
v4 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.
This depends on Jonas' recent series [3] enabling DMA writes to PMU SRAM, without which the UFS controller will fail to load ATF and end up in an unrecoverable error state requiring a hard reset.
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
[3] https://lore.kernel.org/all/[email protected]/
---
Changes in v4:
- Added a dependency in b4 metadata on Jonas' new series enabling DMA writes to PMU SRAM (thanks Jonas)
- Dropped the bounce buffer quirk altogether, as it now works as-is
- Link to v3: https://lore.kernel.org/r/[email protected]
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 (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 | 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 | 1 + drivers/ufs/ufs-rockchip.c | 25 ++++++++++++++ drivers/ufs/ufs-rockchip.h | 1 + lib/Makefile | 1 + 18 files changed, 154 insertions(+), 2 deletions(-)
---
base-commit: 6cdd7597a2fbfc1572c1b0af23d3daf1cefa2de7
change-id: 20251210-rk3576-ufs-ac3bf4e87156
prerequisite-message-id: [email protected]
prerequisite-patch-id: 3748e3880ac841dc25628911608140ebb4d4382f
prerequisite-patch-id: 671586e63ec9021b624d6cdc3b75aef53ed84972
Best regards,
Signature · 1 line
Alexey Charkov <[email protected]>
PATCH v4 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 | 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
@@ -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
@@ -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
@@ -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
@@ -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
@@ -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
@@ -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
@@ -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
Re: [PATCH v4 1/3] spl: Make UFS available for SPL builds
Quoted 181 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_SECTORas the number of 4096-byte sectors into the UFS block device.Signed-off-by Alexey Charkov <[email protected]>--- 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@@ -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/ UPLarch/arm/include/asm/spl.h +1
-0@@ -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@@ -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_WATCHDOGcommon/spl/Makefile +1
-0@@ -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.ocommon/spl/spl_ufs.c new file +49
-0@@ -0,0 +1,49 @@ +// 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) +{ +struct blk_desc *bd = load->priv; +lbaint_t sector = off >> bd->log2blksz; +lbaint_t count = size >> bd->log2blksz; + +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@@ -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 endifdrivers/scsi/Makefile +3
-0@@ -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 endiflib/Makefile +0
-0
lib/Makefile else · line 153
Quoted 7 lines
lib/Makefile +1
-0@@ -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
Thanks,
Neil
Re: [PATCH v4 1/3] spl: Make UFS available for SPL builds
In reply to Alexey CharkovHi Alexey,
Quoted 49 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_SECTORas the number of 4096-byte sectors into the UFS block device.Signed-off-by Alexey Charkov <[email protected]>--- 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@@ -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/ UPLarch/arm/include/asm/spl.h +1
-0@@ -30,6 +30,7 @@ enum {BOOT_DEVICE_XIP ,BOOT_DEVICE_BOOTROM ,BOOT_DEVICE_SMH , +BOOT_DEVICE_UFS ,BOOT_DEVICE_NONE };#endif common/spl/Kconfig +0
-0
common/spl/Kconfig config SPL_THERMAL · line 1617
Quoted 6 lines
common/spl/Kconfig +3
-0@@ -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
Doesn;t this depend on CONFIG_SCSI as well? Like it does nothing without it (does it even compile?), see changes you made to drivers/scsi/Makefile.
Quoted 8 lines
common/spl/Kconfig +8
-0+ 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
common/spl/Kconfig config SPL_THERMAL · line 1635
Quoted 10 lines
common/spl/Kconfig +10
-0+ 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. +
I'm not verse in SCSI... Is the device number guaranteed to be stable across reboots? Is it probe order dependent? If that's the case, this is not a useful symbol and we should be trying to figure out a way to make it stable (via aliases for example, or using another mechanism).
common/spl/Kconfig config SPL_THERMAL · line 1641
Quoted 6 lines
common/spl/Kconfig +6
-0+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,
s/,/./
Quoted 43 lines
common/spl/Kconfig +2
-0+ Units: UFS sectors (1 sector = 4096 bytes). + config SPL_WATCHDOG bool "Support watchdog drivers" imply SPL_WDT if !HW_WATCHDOGcommon/spl/Makefile +1
-0@@ -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.ocommon/spl/spl_ufs.c new file +20
-0@@ -0,0 +1,49 @@ +// 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) +{ +struct blk_desc *bd = load->priv; +lbaint_t sector = off >> bd->log2blksz; +lbaint_t count = size >> bd->log2blksz; + +return blk_dread (bd, sector, count, buf) << bd->log2blksz;
common/spl/spl_ufs.c line 30
Quoted 10 lines
common/spl/spl_ufs.c new file +10
-0+} + +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 ;
Reverse christmas tree here usually (so longest line at the top).
common/spl/spl_ufs.c line 42
Quoted 12 lines
common/spl/spl_ufs.c new file +12
-0+ +/* 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);
Why both a print and a log_debug?
Cheers,
Quentin
Re: [PATCH v4 1/3] spl: Make UFS available for SPL builds
Quoted 56 lines · Quentin Schulz
Hi Alexey,
Quoted 52 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_SECTORas the number of 4096-byte sectors into the UFS block device.Signed-off-by Alexey Charkov <[email protected]>--- 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@@ -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/ UPLarch/arm/include/asm/spl.h +1
-0@@ -30,6 +30,7 @@ enum {BOOT_DEVICE_XIP ,BOOT_DEVICE_BOOTROM ,BOOT_DEVICE_SMH , +BOOT_DEVICE_UFS ,BOOT_DEVICE_NONE };#endif common/spl/Kconfig +0
-0@@ -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.
Quoted 6 lines
common/spl/Kconfig config SPL_THERMAL · line 1617
Quoted 3 lines
common/spl/Kconfig +3
-0+config SPL_UFS_SUPPORT + bool "Support loading from UFS" + select SPL_LOAD_BLOCKDoesn;t this depend on
CONFIG_SCSIas well? Like it does nothing without it (does it even compile?), see changes you made todrivers/scsi/Makefile.
You're right. It's currently possible to disable CONFIG_UFS and CONFIG_SCSI while keeping this enabled, and then this fails to compile. I wonder how e.g. CONFIG_SPL_SATA solves this, as it doesn't pull in SCSI either... Might be something to look into later.
Quoted 15 lines
Quoted 15 lines
common/spl/Kconfig +15
-0+ 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
Quoted 8 lines
common/spl/Kconfig config SPL_THERMAL · line 1635
Quoted 3 lines
common/spl/Kconfig +3
-0+ SCSI device number, which might differ from the UFS LUN if you have + multiple SCSI devices attached and recognized by the SPL. +I'm not verse in SCSI... Is the device number guaranteed to be stable across reboots? Is it probe order dependent? If that's the case, this is not a useful symbol and we should be trying to figure out a way to make it stable (via aliases for example, or using another mechanism).
It is stable across reboots and it follows the same sequence as LUNs, but I suspect that if multiple SCSI drives are present (e.g. a UFS module and some SATA drive) then their numbering might change if e.g. one plugs/unplugs the SATA drive. Can't check it unfortunately, as I don't have a device which would support more than one.
There is a dedicated attribute for the LUN within SCSI structures (and also blk_desc for that matter), but to get to it one still needs to provide a device number first. So the alternative seems to be to iterate through all available device numbers, looking for a particular SCSI target and LUN (and belonging to UCLASS_UFS). That felt a bit over engineered for the use case at hand, and even then one can still think of a case where the logic breaks - e.g. if more than one UFS device is present in the system, and their SCSI target numbers change based on probe order.
spl_sata.c for instance hardcodes devnum = 0, meaning that a system with two drives would likely boot unpredictably
Quoted 8 lines
common/spl/Kconfig config SPL_THERMAL · line 1641
Quoted 6 lines
common/spl/Kconfig +6
-0+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,s/,/./
Ack
Quoted 47 lines
Quoted 47 lines
common/spl/Kconfig +2
-0+ Units: UFS sectors (1 sector = 4096 bytes). + config SPL_WATCHDOG bool "Support watchdog drivers" imply SPL_WDT if !HW_WATCHDOGcommon/spl/Makefile +1
-0@@ -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.ocommon/spl/spl_ufs.c new file +24
-0@@ -0,0 +1,49 @@ +// 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) +{ +struct blk_desc *bd = load->priv; +lbaint_t sector = off >> bd->log2blksz; +lbaint_t count = size >> bd->log2blksz; + +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)
Quoted 8 lines
common/spl/spl_ufs.c line 30
Quoted 6 lines
common/spl/spl_ufs.c new file +6
-0+{ +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 ;Reverse christmas tree here usually (so longest line at the top).
Ack
Quoted 6 lines
Quoted 6 lines
common/spl/spl_ufs.c new file +6
-0+ +/* try to recognize storage devices immediately */ +scsi_scan (false); + bd =blk_get_devnum_by_uclass_id (UCLASS_SCSI , devnum); +if (!bd) +return -ENODEV ;
Quoted 8 lines
common/spl/spl_ufs.c line 42
Quoted 6 lines
common/spl/spl_ufs.c new file +6
-0+ +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);Why both a print and a
log_debug?
If debug is compiled out along with all the string formatting stuff, the puts still provides a useful error message with reduced functionality. I see much of the code under common/spl uses puts for error strings, and log_* for everything else.
Thanks a lot,
Alexey
PATCH v4 2/3 ufs: rockchip: Add device reset support
In reply to Alexey CharkovWire 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
--- 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
@@ -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
@@ -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
@@ -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
Re: [PATCH v4 2/3] ufs: rockchip: Add device reset support
Hi Alexey,
Quoted 3 lines · Alexey Charkov
Wire up the GPIO line which Rockchip RK3576 UFS controller uses to reset the connected UFS device.
It'd be nice to say that reset-gpios is required as per the Device Tree binding, c.f. https://elixir.bootlin.com/linux/v6.18.5/source/Documentation/devicetree/bindings/ufs/rockchip,rk3576-ufshc.yaml#L70
Quoted 42 lines
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 -6Fixes 76465ce21ee4 ("ufs: rockchip: Add initial support")Reviewed-by Neil Armstrong <[email protected]>Reviewed-by Shawn Lin <[email protected]>Signed-off-by Alexey Charkov <[email protected]>--- 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@@ -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 +1
-0@@ -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>
drivers/ufs/ufs-rockchip.c static int ufs_rockchip_common_init(struct ufs_hba *hba) · line 160
Quoted 7 lines
drivers/ufs/ufs-rockchip.c +4
-0@@ -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" );
No need for "Warning: " as it is an actual error.
drivers/ufs/ufs-rockchip.c static int ufs_rockchip_common_init(struct ufs_hba *hba) · line 173
Quoted 1 line
drivers/ufs/ufs-rockchip.c +1
-0+if (!dm_gpio_is_valid (&host->device_reset))
How could it be invalid if we managed to request it in probe?
Cheers,
Quentin
Re: [PATCH v4 2/3] ufs: rockchip: Add device reset support
Quoted 11 lines · Quentin Schulz
Hi Alexey,
Quoted 3 lines · Alexey Charkov
Wire up the GPIO line which Rockchip RK3576 UFS controller uses to reset the connected UFS device.
It'd be nice to say that reset-gpios is required as per the Device Tree binding, c.f.
https://elixir.bootlin.com/linux/v6.18.5/source/Documentation/devicetree/bindings/ufs/rockchip,rk3576-ufshc.yaml#L70
Will do, thanks!
Quoted 45 lines
Quoted 45 lines
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 -6Fixes 76465ce21ee4 ("ufs: rockchip: Add initial support")Reviewed-by Neil Armstrong <[email protected]>Reviewed-by Shawn Lin <[email protected]>Signed-off-by Alexey Charkov <[email protected]>--- 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@@ -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 +1
-0@@ -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; }
Quoted 6 lines
drivers/ufs/ufs-rockchip.c static int ufs_rockchip_common_init(struct ufs_hba *hba) · line 160
Quoted 4 lines
drivers/ufs/ufs-rockchip.c +4
-0+ 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" );No need for "Warning: " as it is an actual error.
Agree, will change.
Quoted 3 lines
drivers/ufs/ufs-rockchip.c static int ufs_rockchip_common_init(struct ufs_hba *hba) · line 173
Quoted 1 line
drivers/ufs/ufs-rockchip.c +1
-0+if (!dm_gpio_is_valid (&host->device_reset))How could it be invalid if we managed to request it in probe?
Probably can't, indeed. Will drop.
Thanks a lot,
Alexey
PATCH v4 3/3 rockchip: spl: Add support for booting from UFS
In reply to Alexey CharkovAdd 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
@@ -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
@@ -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
@@ -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
@@ -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
@@ -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
@@ -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
@@ -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
Re: [PATCH v4 3/3] rockchip: spl: Add support for booting from UFS
Hi Alexey,
Quoted 6 lines · 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_RESETframework to be available in SPL, as the UFS driver uses it.
If it is a hard dependency, why is it not specified as such in the symbol directly instead of relying on imply's at the ARCH level? This will also be "painful" once a new Rockchip SoC has UFS support as we'll need to forget not to add those imply.
Quoted 26 lines
Signed-off-by Alexey Charkov <[email protected]>--- 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 +1
-1@@ -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 {
arch/arm/dts/rk3576-u-boot.dtsi line 89
Quoted 9 lines
arch/arm/dts/rk3576-u-boot.dtsi +6
-0@@ -81,6 +81,12 @@ bootph-some-ram; }; +&gpio4 { + /* Used for resetting the UFS device during initialization */ + bootph-pre-ram; + bootph-some-ram; +}; +
Is it always GPIO4 for the reset GPIO for UFS? Seems like something that should probably be put in a board -u-boot.dtsi instead?
Quoted 20 lines
arch/arm/dts/rk3576-u-boot.dtsi +5
-0&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 +0
-0
arch/arm/include/asm/arch-rockchip/bootrom.h enum { · line 54
Quoted 4 lines
arch/arm/include/asm/arch-rockchip/bootrom.h +1
-0@@ -51,6 +51,7 @@ enum {BROM_BOOTSOURCE_SPINOR =3 ,BROM_BOOTSOURCE_SPINAND =4 ,BROM_BOOTSOURCE_SD =5 , + BROM_BOOTSOURCE_UFS = 7,
Hopefully this will be the same value for all upcoming SoCs with UFS (and not used for something else :) ).
Quoted 68 lines
arch/arm/include/asm/arch-rockchip/bootrom.h +0
-0BROM_BOOTSOURCE_I2C =8 ,BROM_BOOTSOURCE_SPI =9 , BROM_BOOTSOURCE_USB = 10,arch/arm/mach-rockchip/Kconfig +3
-0@@ -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_SUPPORTarch/arm/mach-rockchip/rk3576/rk3576.c +1
-0@@ -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@@ -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 +0
-0@@ -99,6 +99,15 @@ config RESET_ROCKCHIP though is that some reset signals, like I2C or MISC reset multiple devices.
drivers/reset/Kconfig config RESET_ROCKCHIP · line 110
Quoted 10 lines
drivers/reset/Kconfig +9
-0+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 +
Separate patch for this please.
drivers/reset/Makefile obj-$(CONFIG_RESET_BCM6345) += reset-bcm6345.o · line 19
Quoted 13 lines
drivers/reset/Kconfig +0
-0config RESET_HSDK bool "Synopsys HSDK Reset Driver" depends on DM_RESET && TARGET_HSDKdrivers/reset/Makefile +1
-1@@ -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
Separate patch for this please.
Cheers,
Quentin
Re: [PATCH v4 3/3] rockchip: spl: Add support for booting from UFS
Hi Quentin,
Quoted 8 lines · Quentin Schulz
Hi Alexey,
Quoted 4 lines · 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.
Quoted 7 lines
Quoted 2 lines
This also requires the
DM_RESETframework to be available in SPL, as the UFS driver uses it.If it is a hard dependency, why is it not specified as such in the symbol directly instead of relying on imply's at the ARCH level? This will also be "painful" once a new Rockchip SoC has UFS support as we'll need to forget not to add those imply.
Fair enough, will convert it into a "select" under Rockchip UFS, thanks for pointing it out!
Quoted 28 lines
Quoted 28 lines
Signed-off-by Alexey Charkov <[email protected]>--- 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 +1
-1@@ -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; };
Quoted 9 lines
arch/arm/dts/rk3576-u-boot.dtsi line 89
Quoted 6 lines
arch/arm/dts/rk3576-u-boot.dtsi +6
-0+&gpio4 { + /* Used for resetting the UFS device during initialization */ + bootph-pre-ram; + bootph-some-ram; +}; +Is it always GPIO4 for the reset GPIO for UFS? Seems like something that should probably be put in a board
-u-boot.dtsiinstead?
It is in fact always GPIO4 pin D0. It's multiplexed to a somehow-hardware-controlled pin inconspicuously called UFS_RSTn within VCCIO7_IOC_GPIOD_IOMUX_SEL_L, but I couldn't find how it's supposed to operate in a hardware-controlled mode (it's not described in the TRM). Mainline Linux does the same thing as I do here (GPIO mode [1]), while Rockchip's own U-boot code switches the pin to the hardware-controlled mode [2] and never touches anything about device resets from then on - which feels like a potentially fragile black box to me. Hardware controlled mode would also deviate from the upstream DT binding, as it stipulates a GPIO for device resets [3].
[1] https://github.com/torvalds/linux/blob/master/drivers/ufs/host/ufs-rockchip.c#L220-L231
[2] https://github.com/rockchip-linux/u-boot/blob/next-dev/drivers/ufs/ufs-rockchip.c#L222
[3] https://github.com/torvalds/linux/blob/master/Documentation/devicetree/bindings/ufs/rockchip%2Crk3576-ufshc.yaml#L53-L58
Quoted 19 lines
Quoted 19 lines
arch/arm/dts/rk3576-u-boot.dtsi +5
-0&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 +0
-0
Quoted 8 lines
arch/arm/include/asm/arch-rockchip/bootrom.h enum { · line 54
Quoted 5 lines
arch/arm/include/asm/arch-rockchip/bootrom.h +1
-0@@ -51,6 +51,7 @@ enum {BROM_BOOTSOURCE_SPINOR =3 ,BROM_BOOTSOURCE_SPINAND =4 ,BROM_BOOTSOURCE_SD =5 , + BROM_BOOTSOURCE_UFS = 7,Hopefully this will be the same value for all upcoming SoCs with UFS (and not used for something else :) ).
Well it's hard to guarantee (otherwise Jonas wouldn't have had to add a translation function [4] for the IDs that changed in RK3576). Maybe at some point we'll have to switch to a lookup table per each SoC variant if these keep changing, but thankfully that point is not today :)
[4] https://source.denx.de/u-boot/u-boot/-/commit/99a9b6ba6cf1c2f376e6f0ac3e6a2ced6c6addd4
Quoted 69 lines
Quoted 69 lines
arch/arm/include/asm/arch-rockchip/bootrom.h +0
-0BROM_BOOTSOURCE_I2C =8 ,BROM_BOOTSOURCE_SPI =9 , BROM_BOOTSOURCE_USB = 10,arch/arm/mach-rockchip/Kconfig +3
-0@@ -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_SUPPORTarch/arm/mach-rockchip/rk3576/rk3576.c +1
-0@@ -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@@ -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 +0
-0@@ -99,6 +99,15 @@ config RESET_ROCKCHIP though is that some reset signals, like I2C or MISC reset multiple devices.
Quoted 11 lines
drivers/reset/Kconfig config RESET_ROCKCHIP · line 110
Quoted 9 lines
drivers/reset/Kconfig +9
-0+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 +Separate patch for this please.
Ack
Quoted 7 lines
Quoted 7 lines
drivers/reset/Kconfig +0
-0config RESET_HSDK bool "Synopsys HSDK Reset Driver" depends on DM_RESET && TARGET_HSDKdrivers/reset/Makefile +0
-0
Quoted 8 lines
drivers/reset/Makefile obj-$(CONFIG_RESET_BCM6345) += reset-bcm6345.o · line 19
Quoted 6 lines
drivers/reset/Makefile +1
-1@@ -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.oSeparate patch for this please.
Ack
Thanks a lot,
Alexey
Re: [PATCH v4 3/3] rockchip: spl: Add support for booting from UFS
Hi Alexey,
Quoted 15 lines · Alexey Charkov
Hi Quentin,
Quoted 11 lines · Quentin Schulz
Hi Alexey,
Quoted 6 lines · 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_RESETframework to be available in SPL, as the UFS driver uses it.
Quoted 8 lines
Quoted 4 lines
If it is a hard dependency, why is it not specified as such in the symbol directly instead of relying on imply's at the ARCH level? This will also be "painful" once a new Rockchip SoC has UFS support as we'll need to forget not to add those imply.
Fair enough, will convert it into a "select" under Rockchip UFS, thanks for pointing it out!
Watch out for select, it may not be doing what you want, see https://www.kernel.org/doc/html/latest/kbuild/kconfig-language.html#menu-attributes at the notes in the select bullet item.
Quoted 38 lines
Quoted 28 lines
Quoted 28 lines
Signed-off-by Alexey Charkov <[email protected]>--- 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 +1
-1@@ -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; };Quoted 9 lines
arch/arm/dts/rk3576-u-boot.dtsi line 89
Quoted 6 lines
arch/arm/dts/rk3576-u-boot.dtsi +6
-0+&gpio4 { + /* Used for resetting the UFS device during initialization */ + bootph-pre-ram; + bootph-some-ram; +}; +Is it always GPIO4 for the reset GPIO for UFS? Seems like something that should probably be put in a board
-u-boot.dtsiinstead?
Quoted 1 line
It is in fact always GPIO4 pin D0. It's multiplexed to a
This is probably the typical Rockchip BS :) It is the "same" for SD CD or WP pins. They have a hardware-controlled mode for pin A which is usually a black box for SW (nothing to do, it "works"). But nothing prevents you from using another GPIO for that (just have to be careful about the voltage level I guess, here it seems to be 1.2V for the domain, which isn't that usual I guess.
Quoted 3 lines
somehow-hardware-controlled pin inconspicuously called
UFS_RSTnwithinVCCIO7_IOC_GPIOD_IOMUX_SEL_L, but I couldn't find how it's supposed to operate in a hardware-controlled mode (it's not described in the TRM).
I guess it automagically does stuff in the silicon when initializing (or doing a controller reset for example, don't know). Your guess is as good as mine :)
Quoted 4 lines
Mainline Linux does the same thing as I do here (GPIO mode [1]), while Rockchip's own U-boot code switches the pin to the hardware-controlled mode [2] and never touches anything about device resets from then on - which feels like a potentially fragile black box to me. Hardware
Yes, we've had our share of SD CD signal issues with the hardware-controlled one. I actually switched one of our devices to use GPIO instead (see https://elixir.bootlin.com/linux/v6.18.5/source/arch/arm64/boot/dts/rockchip/rk3588-tiger-haikou.dts#L272), so I understand not wanting to rely on that ;)
Quoted 3 lines
controlled mode would also deviate from the upstream DT binding, as it stipulates a GPIO for device resets [3].
Not asking for this, rather wondering if we should really have this at the SoC level rather than the board level. If it can be any GPIO why forcing all boards to have GPIO4 bank "enabled" in SPL + U-Boot proper before reloc. It isn't the first SoC to have that (also see all SoC u-boot.dtsi having the UART controller from the reference design "enabled"), and I don't think it's planned for us to have a product on it, so... not a blocker from my side :)
Quoted 32 lines
[1] https://github.com/torvalds/linux/blob/master/drivers/ufs/host/ufs-rockchip.c#L220-L231
[2] https://github.com/rockchip-linux/u-boot/blob/next-dev/drivers/ufs/ufs-rockchip.c#L222
[3] https://github.com/torvalds/linux/blob/master/Documentation/devicetree/bindings/ufs/rockchip%2Crk3576-ufshc.yaml#L53-L58Quoted 19 lines
Quoted 19 lines
arch/arm/dts/rk3576-u-boot.dtsi +5
-0&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 +0
-0Quoted 8 lines
arch/arm/include/asm/arch-rockchip/bootrom.h enum { · line 54
Quoted 5 lines
arch/arm/include/asm/arch-rockchip/bootrom.h +1
-0@@ -51,6 +51,7 @@ enum {BROM_BOOTSOURCE_SPINOR =3 ,BROM_BOOTSOURCE_SPINAND =4 ,BROM_BOOTSOURCE_SD =5 , + BROM_BOOTSOURCE_UFS = 7,Hopefully this will be the same value for all upcoming SoCs with UFS (and not used for something else :) ).
Quoted 6 lines
Well it's hard to guarantee (otherwise Jonas wouldn't have had to add a translation function [4] for the IDs that changed in RK3576). Maybe at some point we'll have to switch to a lookup table per each SoC variant if these keep changing, but thankfully that point is not today :)
See https://lore.kernel.org/devicetree-spec/[email protected]/
Cheers,Quentin
Re: [PATCH v4 3/3] rockchip: spl: Add support for booting from UFS
Quoted 24 lines · Quentin Schulz
Hi Alexey,
Quoted 20 lines · Alexey Charkov
Hi Quentin,
Quoted 15 lines · Quentin Schulz
Hi Alexey,
Quoted 6 lines · 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_RESETframework to be available in SPL, as the UFS driver uses it.If it is a hard dependency, why is it not specified as such in the symbol directly instead of relying on imply's at the ARCH level? This will also be "painful" once a new Rockchip SoC has UFS support as we'll need to forget not to add those imply.
Quoted 7 lines
Quoted 3 lines
Fair enough, will convert it into a "select" under Rockchip UFS, thanks for pointing it out!
Watch out for select, it may not be doing what you want, see
https://www.kernel.org/doc/html/latest/kbuild/kconfig-language.html#menu-attributes
at the notes in the select bullet item.
Ouch. Alright, thank you for pointing it out.
Quoted 38 lines
Quoted 38 lines
Quoted 37 lines
Quoted 25 lines
Signed-off-by Alexey Charkov <[email protected]>--- 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 +1
-1@@ -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 {arch/arm/dts/rk3576-u-boot.dtsi line 89
Quoted 9 lines
arch/arm/dts/rk3576-u-boot.dtsi +6
-0@@ -81,6 +81,12 @@ bootph-some-ram; }; +&gpio4 { + /* Used for resetting the UFS device during initialization */ + bootph-pre-ram; + bootph-some-ram; +}; +Is it always GPIO4 for the reset GPIO for UFS? Seems like something that should probably be put in a board
-u-boot.dtsiinstead?
Quoted 8 lines
Quoted 1 line
It is in fact always GPIO4 pin D0. It's multiplexed to a
This is probably the typical Rockchip BS :) It is the "same" for SD CD or WP pins. They have a hardware-controlled mode for pin A which is usually a black box for SW (nothing to do, it "works"). But nothing prevents you from using another GPIO for that (just have to be careful about the voltage level I guess, here it seems to be 1.2V for the domain, which isn't that usual I guess.
I bet that the boot ROM might get picky there, and only work with GPIO4_D0. But if the UFS chip is not meant to be used as the primary boot device - sure, can't see why not. On the other hand, there's not much direct gain for board designers from using a different pin, and people tend to just stick with Rockchip reference schematics unless something different is explicitly required for their design, so my money is on "it will be GPIO4 for all RK3576 boards".
Extra consideration in the same stream: the pin itself is defined in rk3576.dtsi upstream, not in board-specific .dts files.
Quoted 13 lines
Quoted 3 lines
somehow-hardware-controlled pin inconspicuously called
UFS_RSTnwithinVCCIO7_IOC_GPIOD_IOMUX_SEL_L, but I couldn't find how it's supposed to operate in a hardware-controlled mode (it's not described in the TRM).I guess it automagically does stuff in the silicon when initializing (or doing a controller reset for example, don't know). Your guess is as good as mine :)
Quoted 4 lines
Mainline Linux does the same thing as I do here (GPIO mode [1]), while Rockchip's own U-boot code switches the pin to the hardware-controlled mode [2] and never touches anything about device resets from then on - which feels like a potentially fragile black box to me. Hardware
Quoted 5 lines
Yes, we've had our share of SD CD signal issues with the hardware-controlled one. I actually switched one of our devices to use GPIO instead (see
https://elixir.bootlin.com/linux/v6.18.5/source/arch/arm64/boot/dts/rockchip/rk3588-tiger-haikou.dts#L272),
so I understand not wanting to rely on that ;)
Indeed. Also Shawn's recent series for RK3576 to a similar effect [1]
[1] https://lore.kernel.org/linux-rockchip/[email protected]/
Quoted 11 lines
Quoted 3 lines
controlled mode would also deviate from the upstream DT binding, as it stipulates a GPIO for device resets [3].
Not asking for this, rather wondering if we should really have this at the SoC level rather than the board level. If it can be any GPIO why forcing all boards to have GPIO4 bank "enabled" in SPL + U-Boot proper before reloc. It isn't the first SoC to have that (also see all SoC
u-boot.dtsihaving the UART controller from the reference design "enabled"), and I don't think it's planned for us to have a product on it, so... not a blocker from my side :)
I believe that the boards which don't use UFS for early boot will just compile it out, together with the respective GPIO code. Then the only downside for them is a marginally larger SPL DTB - but not on a scale that matters for RK3576. And those that use UFS for early boot will likely want it to be on the pin expected by the boot ROM, then having the prerequisites already defined makes life easier for them (and it's not much different from having e.g. FSPI0/1 and eMMC enabled by default even for boards that don't use them).
Quoted 39 lines
Quoted 32 lines
[1] https://github.com/torvalds/linux/blob/master/drivers/ufs/host/ufs-rockchip.c#L220-L231
[2] https://github.com/rockchip-linux/u-boot/blob/next-dev/drivers/ufs/ufs-rockchip.c#L222
[3] https://github.com/torvalds/linux/blob/master/Documentation/devicetree/bindings/ufs/rockchip%2Crk3576-ufshc.yaml#L53-L58Quoted 19 lines
Quoted 19 lines
arch/arm/dts/rk3576-u-boot.dtsi +5
-0&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 +0
-0Quoted 8 lines
arch/arm/include/asm/arch-rockchip/bootrom.h enum { · line 54
Quoted 5 lines
arch/arm/include/asm/arch-rockchip/bootrom.h +1
-0@@ -51,6 +51,7 @@ enum {BROM_BOOTSOURCE_SPINOR =3 ,BROM_BOOTSOURCE_SPINAND =4 ,BROM_BOOTSOURCE_SD =5 , + BROM_BOOTSOURCE_UFS = 7,Hopefully this will be the same value for all upcoming SoCs with UFS (and not used for something else :) ).
Quoted 6 lines
Well it's hard to guarantee (otherwise Jonas wouldn't have had to add a translation function [4] for the IDs that changed in RK3576). Maybe at some point we'll have to switch to a lookup table per each SoC variant if these keep changing, but thankfully that point is not today :)
Quoted 2 lines
See
https://lore.kernel.org/devicetree-spec/[email protected]/
Ooooh that sounds like a discussion that can potentially stretch out for a long time. I'd much rather use a value that works for the only chip where it matters now (RK3576), then solve the problem whenever it arises (if it does). After all, bootrom.h is not ABI, and DT is, so it is much easier to fix up bootrom.h without stepping on too many toes.
Furthermore, I'm not even sure that /chosen/bootsource can address the issue here, because boot ROM's won't magically start passing DT phandles to the bootloader, so there will still be an ID->node lookup table somewhere in early code (with potentially per-SoC overrides). Which is exactly what we have here.
Thanks a lot,
Alexey
Re: [PATCH v4 3/3] rockchip: spl: Add support for booting from UFS
Hi Alexey,
Quoted 13 lines · Alexey Charkov
Quoted 12 lines · Quentin Schulz
Hi Alexey,
Quoted 8 lines · Alexey Charkov
Hi Quentin,
Quoted 4 lines · Quentin Schulz
Hi Alexey,
On 1/8/26 6:50 PM, Alexey Charkov wrote:
[...]
Quoted 27 lines
Quoted 10 lines
Quoted 10 lines
Quoted 9 lines
arch/arm/dts/rk3576-u-boot.dtsi line 89
Quoted 6 lines
+&gpio4 {
arch/arm/dts/rk3576-u-boot.dtsi +5
-0+ /* Used for resetting the UFS device during initialization */ + bootph-pre-ram; + bootph-some-ram; +}; +Is it always GPIO4 for the reset GPIO for UFS? Seems like something that should probably be put in a board
-u-boot.dtsiinstead?Quoted 8 lines
Quoted 1 line
It is in fact always GPIO4 pin D0. It's multiplexed to a
This is probably the typical Rockchip BS :) It is the "same" for SD CD or WP pins. They have a hardware-controlled mode for pin A which is usually a black box for SW (nothing to do, it "works"). But nothing prevents you from using another GPIO for that (just have to be careful about the voltage level I guess, here it seems to be 1.2V for the domain, which isn't that usual I guess.
I bet that the boot ROM might get picky there, and only work with
GPIO4_D0. But if the UFS chip is not meant to be used as the primary boot device - sure, can't see why not. On the other hand, there's not much direct gain for board designers from using a different pin, and people tend to just stick with Rockchip reference schematics unless something different is explicitly required for their design, so my money is on "it will be GPIO4 for all RK3576 boards".
Quoted 3 lines
Extra consideration in the same stream: the pin itself is defined in
rk3576.dtsiupstream, not in board-specific .dts files.
OK, I see that rk3576.dtsi specifies the reset-gpios here. I guess it should be seen as a default value, like we have for pinmuxes. Also, this is lacking a pinmux for the GPIO, so there's no guarantee the pin will be muxed into the GPIO function before you control it.
[...]
Quoted 12 lines
Quoted 11 lines
Quoted 3 lines
controlled mode would also deviate from the upstream DT binding, as it stipulates a GPIO for device resets [3].
Not asking for this, rather wondering if we should really have this at the SoC level rather than the board level. If it can be any GPIO why forcing all boards to have GPIO4 bank "enabled" in SPL + U-Boot proper before reloc. It isn't the first SoC to have that (also see all SoC
u-boot.dtsihaving the UART controller from the reference design "enabled"), and I don't think it's planned for us to have a product on it, so... not a blocker from my side :)
Quoted 9 lines
I believe that the boards which don't use UFS for early boot will just compile it out, together with the respective GPIO code. Then the only downside for them is a marginally larger SPL DTB - but not on a scale that matters for RK3576. And those that use UFS for early boot will likely want it to be on the pin expected by the boot ROM, then having the prerequisites already defined makes life easier for them (and it's not much different from having e.g. FSPI0/1 and eMMC enabled by default even for boards that don't use them).
My hunch is the BootROM may not even attempt to reset the UFS chip and rely on it having lost power (see different ways for the PMIC to reset its regulators when it's itself reset in SW). But I have nothing to prove this :)
Quoted 39 lines
Quoted 39 lines
Quoted 38 lines
[1] https://github.com/torvalds/linux/blob/master/drivers/ufs/host/ufs-rockchip.c#L220-L231
[2] https://github.com/rockchip-linux/u-boot/blob/next-dev/drivers/ufs/ufs-rockchip.c#L222
[3] https://github.com/torvalds/linux/blob/master/Documentation/devicetree/bindings/ufs/rockchip%2Crk3576-ufshc.yaml#L53-L58Quoted 19 lines
Quoted 19 lines
&ioc_grf { bootph-all; };arch/arm/dts/rk3576-u-boot.dtsi +5
-0@@ -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 +0
-0Quoted 8 lines
arch/arm/include/asm/arch-rockchip/bootrom.h enum { · line 54
Quoted 5 lines
arch/arm/include/asm/arch-rockchip/bootrom.h +1
-0@@ -51,6 +51,7 @@ enum {BROM_BOOTSOURCE_SPINOR =3 ,BROM_BOOTSOURCE_SPINAND =4 ,BROM_BOOTSOURCE_SD =5 , + BROM_BOOTSOURCE_UFS = 7,Hopefully this will be the same value for all upcoming SoCs with UFS (and not used for something else :) ).
Well it's hard to guarantee (otherwise Jonas wouldn't have had to add a translation function [4] for the IDs that changed in RK3576). Maybe at some point we'll have to switch to a lookup table per each SoC variant if these keep changing, but thankfully that point is not today :)
Quoted 5 lines
Quoted 2 lines
See
https://lore.kernel.org/devicetree-spec/[email protected]/Ooooh that sounds like a discussion that can potentially stretch out for a long time. I'd much rather use a value that works for the only
Anything to be added to the dt spec is taking months if not year, even when agreed upon.
Quoted 4 lines
chip where it matters now (RK3576), then solve the problem whenever it arises (if it does). After all,
bootrom.his not ABI, and DT is, so it is much easier to fix upbootrom.hwithout stepping on too many toes.
I'm saying this will solve the problem, not that we have to rely on it now :)
Quoted 1 line
Furthermore, I'm not even sure that /chosen/bootsource can address the
It's not /chosen/bootsource, this has merged already in the spec and won't be usable for this mapping (lots to read but it's explained somewhere in the thread).
Quoted 3 lines
issue here, because boot ROM's won't magically start passing DT phandles to the bootloader, so there will still be an
ID->nodelookup table somewhere in early code (with potentially per-SoC overrides).
No, that's the point of the thread I linked. The idea is to provide in DTS the mapping between the value in the register set by the BootROM to a controller/flash node somehow (via phandle or something else) so that we don't have to have this table in code at all. After all, this is hardware description (albeit based on BootROM "API" but that cannot change anyway, it's silicon (if it does, good luck all may the odds be in your favor)) so there's no reason for all bootloaders to have to reinvent their own sauce (see barebox doing something different than U-Boot there).
I read the BootROM register value, I read the DT property with the mapping, then I know which device it is. Bonus point, you don't need to keep the DT node path in sync in your table, because the mapping is in the same DT as what it refers to.
This is not for now (and I should probably revive the topic), just wanted to tell you there's another way to do that and we should probably aim at doing that in the mid/long term (and then all this in-code mapping won't need to maintained anymore, and there won't be conflicts between SoCs having the same value for different meanings, or differnet values for the same meaning).
Cheers,
Quentin
Re: [PATCH v4 3/3] rockchip: spl: Add support for booting from UFS
Quoted 45 lines · Quentin Schulz
Hi Alexey,
Quoted 13 lines · Alexey Charkov
Quoted 12 lines · Quentin Schulz
Hi Alexey,
Quoted 8 lines · Alexey Charkov
Hi Quentin,
Quoted 4 lines · Quentin Schulz
Hi Alexey,
On 1/8/26 6:50 PM, Alexey Charkov wrote:
[...]
Quoted 27 lines
Quoted 10 lines
Quoted 10 lines
Quoted 9 lines
arch/arm/dts/rk3576-u-boot.dtsi line 89
Quoted 6 lines
+&gpio4 {
arch/arm/dts/rk3576-u-boot.dtsi +5
-0+ /* Used for resetting the UFS device during initialization */ + bootph-pre-ram; + bootph-some-ram; +}; +Is it always GPIO4 for the reset GPIO for UFS? Seems like something that should probably be put in a board
-u-boot.dtsiinstead?Quoted 8 lines
Quoted 1 line
It is in fact always GPIO4 pin D0. It's multiplexed to a
This is probably the typical Rockchip BS :) It is the "same" for SD CD or WP pins. They have a hardware-controlled mode for pin A which is usually a black box for SW (nothing to do, it "works"). But nothing prevents you from using another GPIO for that (just have to be careful about the voltage level I guess, here it seems to be 1.2V for the domain, which isn't that usual I guess.
I bet that the boot ROM might get picky there, and only work with
GPIO4_D0. But if the UFS chip is not meant to be used as the primary boot device - sure, can't see why not. On the other hand, there's not much direct gain for board designers from using a different pin, and people tend to just stick with Rockchip reference schematics unless something different is explicitly required for their design, so my money is on "it will be GPIO4 for all RK3576 boards".
Quoted 8 lines
Quoted 3 lines
Extra consideration in the same stream: the pin itself is defined in
rk3576.dtsiupstream, not in board-specific .dts files.OK, I see that
rk3576.dtsispecifies the reset-gpios here. I guess it should be seen as a default value, like we have for pinmuxes. Also, this is lacking a pinmux for the GPIO, so there's no guarantee the pin will be muxed into the GPIO function before you control it.
Indeed. This must have been overlooked upon addition, given that GPIO function is supposed to be the power-on default for this pin. So in the end it's either reconfigured by the boot ROM to the hardware-controlled reset mode (then it leaves the UFS controller in a magically working state), or it's left at the power-on default GPIO state - end result is a working UFS controller in both cases, but possibly with traces of dark magic.
Sounds like a patch to the upstream .dtsi is warranted - will do that.
Quoted 22 lines
Quoted 12 lines
Quoted 11 lines
Quoted 3 lines
controlled mode would also deviate from the upstream DT binding, as it stipulates a GPIO for device resets [3].
Not asking for this, rather wondering if we should really have this at the SoC level rather than the board level. If it can be any GPIO why forcing all boards to have GPIO4 bank "enabled" in SPL + U-Boot proper before reloc. It isn't the first SoC to have that (also see all SoC
u-boot.dtsihaving the UART controller from the reference design "enabled"), and I don't think it's planned for us to have a product on it, so... not a blocker from my side :)Quoted 9 lines
I believe that the boards which don't use UFS for early boot will just compile it out, together with the respective GPIO code. Then the only downside for them is a marginally larger SPL DTB - but not on a scale that matters for RK3576. And those that use UFS for early boot will likely want it to be on the pin expected by the boot ROM, then having the prerequisites already defined makes life easier for them (and it's not much different from having e.g. FSPI0/1 and eMMC enabled by default even for boards that don't use them).
Quoted 4 lines
My hunch is the BootROM may not even attempt to reset the UFS chip and rely on it having lost power (see different ways for the PMIC to reset its regulators when it's itself reset in SW). But I have nothing to prove this :)
I took my JTAG out. Boot ROM at its code address 0x6448 writes 0xff0011 to 0x2604b398, where:
- 0x2604b398 is VCCIO7_IOC_GPIOD4_IOMUX_SEL_L
- 0xff << 16 is the write mask
- 0x10 is GPIO4_D1 mux (=UFS_REFCLK, not GPIO mode)
- 0x01 is GPIO4_D0 mux (=UFS_RSTn, not GPIO mode)
Further down the line at its code address 0x6480 it writes 0x100010 to 0x2604b400, where:
- 0x2604b400 is VCCIO7_IOC_XIN_UFS_CON
- 0x10 << 16 is the write mask
- 0x10 is ufs_rstn_out a.k.a. UFS reset IO configuration (presumably
enabling the hardware-controlled device reset mode)
This only applies to when UFS is identified as the boot storage - otherwise the registers stay at their power-on reset defaults (i.e. zeros for these fields)
Quoted 81 lines
Quoted 39 lines
Quoted 39 lines
Quoted 38 lines
[1] https://github.com/torvalds/linux/blob/master/drivers/ufs/host/ufs-rockchip.c#L220-L231
[2] https://github.com/rockchip-linux/u-boot/blob/next-dev/drivers/ufs/ufs-rockchip.c#L222
[3] https://github.com/torvalds/linux/blob/master/Documentation/devicetree/bindings/ufs/rockchip%2Crk3576-ufshc.yaml#L53-L58Quoted 19 lines
Quoted 19 lines
&ioc_grf { bootph-all; };arch/arm/dts/rk3576-u-boot.dtsi +5
-0@@ -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 +0
-0Quoted 8 lines
arch/arm/include/asm/arch-rockchip/bootrom.h enum { · line 54
Quoted 5 lines
arch/arm/include/asm/arch-rockchip/bootrom.h +1
-0@@ -51,6 +51,7 @@ enum {BROM_BOOTSOURCE_SPINOR =3 ,BROM_BOOTSOURCE_SPINAND =4 ,BROM_BOOTSOURCE_SD =5 , + BROM_BOOTSOURCE_UFS = 7,Hopefully this will be the same value for all upcoming SoCs with UFS (and not used for something else :) ).
Well it's hard to guarantee (otherwise Jonas wouldn't have had to add a translation function [4] for the IDs that changed in RK3576). Maybe at some point we'll have to switch to a lookup table per each SoC variant if these keep changing, but thankfully that point is not today :)
Quoted 5 lines
Quoted 2 lines
See
https://lore.kernel.org/devicetree-spec/[email protected]/Ooooh that sounds like a discussion that can potentially stretch out for a long time. I'd much rather use a value that works for the only
Anything to be added to the dt spec is taking months if not year, even when agreed upon.
Quoted 4 lines
chip where it matters now (RK3576), then solve the problem whenever it arises (if it does). After all,
bootrom.his not ABI, and DT is, so it is much easier to fix upbootrom.hwithout stepping on too many toes.I'm saying this will solve the problem, not that we have to rely on it now :)
Quoted 1 line
Furthermore, I'm not even sure that /chosen/bootsource can address the
It's not /chosen/bootsource, this has merged already in the spec and won't be usable for this mapping (lots to read but it's explained somewhere in the thread).
Quoted 3 lines
issue here, because boot ROM's won't magically start passing DT phandles to the bootloader, so there will still be an
ID->nodelookup table somewhere in early code (with potentially per-SoC overrides).No, that's the point of the thread I linked. The idea is to provide in DTS the mapping between the value in the register set by the BootROM to a controller/flash node somehow (via phandle or something else) so that we don't have to have this table in code at all. After all, this is hardware description (albeit based on BootROM "API" but that cannot change anyway, it's silicon (if it does, good luck all may the odds be in your favor)) so there's no reason for all bootloaders to have to reinvent their own sauce (see barebox doing something different than U-Boot there).
I read the BootROM register value, I read the DT property with the mapping, then I know which device it is. Bonus point, you don't need to keep the DT node path in sync in your table, because the mapping is in the same DT as what it refers to.
Quoted 6 lines
This is not for now (and I should probably revive the topic), just wanted to tell you there's another way to do that and we should probably aim at doing that in the mid/long term (and then all this in-code mapping won't need to maintained anymore, and there won't be conflicts between SoCs having the same value for different meanings, or differnet values for the same meaning).
Oh, I got it now. Yes, that sounds like a beautiful longer-term solution, separating data from code cleanly and avoiding if-then-else trees.
Best regards,
Alexey