Skip to contentSkip to conversation

Add rkmtd command

PATCH Superseded Johan Jonker 2 participants 7 messages Sep 28, 2023 – Oct 12, 2023

Subsystems (4)

v2 of 5 Superseded Latest is v5 →

lore
Share & tools
lore
#0 lore raw

v2 cover Add rkmtd command

The command rkmtd creates a virtual block device to transfer Rockchip boot block data to and from NAND with block orientated tools like "ums" and "rockusb".

It uses the Rockchip MTD driver to scan for boot blocks and copies data from the first block in a GPT formatted virtual disk. Data must be written in U-boot "idbloader.img" format and start at partition "loader1" offset 64. The data header is parsed for length and offset. When the last sector is received it erases up to 5 erase blocks on NAND and writes boot blocks in a pattern depending on the NAND ID. Data is then verified. When a block turns out bad the block header is discarded.

Limitations:
Support for Rockchip boot block header type 1 only.
Pattern for listed NAND IDs only. (Logic still not disclosed by Rockchip) The MTD framework driver data and NAND ID must be extracted at a lower level.

Available rkmtd commands:

rkmtd bind <label>      - bind RKMTD device
rkmtd unbind <label>    - unbind RKMTD device
rkmtd info [<label>]    - show all available RKMTD devices
rkmtd dev [<label>]     - show or set current RKMTD device

U-boot settings:
Config to enable Rockchip MTD support:
CONFIG_MTD=y
CONFIG_MTD_RAW_NAND=y
CONFIG_SYS_NAND_DRIVER_ECC_LAYOUT=y
CONFIG_SYS_NAND_USE_FLASH_BBT=y
CONFIG_ROCKCHIP_NAND=y

Option to keep existing NAND data unchanged:
CONFIG_ROCKCHIP_NAND_SKIP_BBTSCAN=y

Commands to enable:
CONFIG_CMD_USB=y
CONFIG_CMD_RKMTD=y
CONFIG_CMD_ROCKUSB=y
CONFIG_CMD_USB_MASS_STORAGE=y

Linux Host (PC) tool commands combinations that work:

U-boot Linux
rkmtd bind 0

# rockusb
rockusb 0 rkmtd 0
					upgrade_tool pl
					upgrade_tool wl 64 idbloader.img
					upgrade_tool rl 64 512 upgrade_tool_rl_64_512.img
					upgrade_tool rd

rkdeveloptool ppt
rkdeveloptool wlx loader1 idbloader.img rkdeveloptool wl 64 idbloader.img rkdeveloptool rl 64 512 rkdeveloptool_rl_64_512.img rkdeveloptool rd

rkflashtool w 64 512 < idbloader.img rkflashtool r 64 512 > rkflashtool_r_64_512.img

# ums
ums 0 rkmtd 0
					dd if=idbloader.img of=/dev/sda1
					dd if=/dev/sda1 of=ums_0_idb_0_rd.img

Johan Jonker (3):
mtd: nand: raw: rockchip_nfc: add NAND_SKIP_BBTSCAN option
dm: prepare rkmtd UCLASS
rockchip: cmd: add rkmtd command

 cmd/Kconfig                         |    7 +
 cmd/Makefile                        |    1 +
 cmd/rkmtd.c                         | 1432 +++++++++++++++++++++++++++
 disk/part.c                         |    4 +
 drivers/block/blk-uclass.c          |    1 +
 drivers/mtd/nand/raw/Kconfig        |    9 +
 drivers/mtd/nand/raw/rockchip_nfc.c |    3 +
 include/dm/uclass-id.h              |    1 +
 8 files changed, 1458 insertions(+)
 create mode 100644 cmd/rkmtd.c

--
2.39.2

#1 lore raw

PATCH v2 1/3 mtd: nand: raw: rockchip_nfc: add NAND_SKIP_BBTSCAN option

On Rockchip SoCs the first boot stages are written on NAND with help of manufacturer software that uses a different format then the MTD framework. Skip the automatic BBT scan with the NAND_SKIP_BBTSCAN option to be able to pass the driver probe function and to let the original data unchanged.

---
 drivers/mtd/nand/raw/Kconfig        | 9 +++++++++
 drivers/mtd/nand/raw/rockchip_nfc.c | 3 +++
 2 files changed, 12 insertions(+)
drivers/mtd/nand/raw/Kconfig +9 -0
index d624589a892b..72547f00fbec 100644
@@ -611,6 +611,15 @@ config ROCKCHIP_NAND
 	    NFC v800: RK3308, RV1108
 	    NFC v900: PX30, RK3326
 
+config ROCKCHIP_NAND_SKIP_BBTSCAN
+	bool "Skip the automatic BBT scan with Rockchip NAND controllers"
+	depends on ROCKCHIP_NAND
+	default n
+	help
+	  Skip the automatic BBT scan with the NAND_SKIP_BBTSCAN
+	  option when data content is not in MTD format or
+	  must remain unchanged.
+
 config TEGRA_NAND
 	bool "Support for NAND controller on Tegra SoCs"
 	depends on ARCH_TEGRA
drivers/mtd/nand/raw/rockchip_nfc.c +3 -0
index 6ad51df4acff..df6742c2f9bb 100644
@@ -981,6 +981,9 @@ static int rk_nfc_nand_chip_init(ofnode node, struct rk_nfc *nfc, int devnum)
 	chip->bbt_options = NAND_BBT_USE_FLASH | NAND_BBT_NO_OOB;
 	chip->options |= NAND_NO_SUBPAGE_WRITE | NAND_USE_BOUNCE_BUFFER;
 
+	if (IS_ENABLED(CONFIG_ROCKCHIP_NAND_SKIP_BBTSCAN))
+		chip->options |= NAND_SKIP_BBTSCAN;
+
 	rk_nfc_hw_init(nfc);
 	ret = nand_scan_ident(mtd, nsels, NULL);
 	if (ret)

--
2.39.2

#2 lore raw

PATCH v2 2/3 dm: prepare rkmtd UCLASS

In reply to Johan Jonker

Prepare a rkmtd UCLASS in use for writing Rockchip boot blocks in combination with existing userspace tools and rockusb command.

---
 disk/part.c                | 4 ++++
 drivers/block/blk-uclass.c | 1 +
 include/dm/uclass-id.h     | 1 +
 3 files changed, 6 insertions(+)
disk/part.c +4 -0
index 186ee965006e..a65f9df5dd29 100644
@@ -170,6 +170,7 @@ void dev_print(struct blk_desc *dev_desc)
 	case UCLASS_PVBLOCK:
 	case UCLASS_HOST:
 	case UCLASS_BLKMAP:
+	case UCLASS_RKMTD:
 		printf ("Vendor: %s Rev: %s Prod: %s\n",
 			dev_desc->vendor,
 			dev_desc->revision,
@@ -303,6 +304,9 @@ static void print_part_header(const char *type, struct blk_desc *dev_desc)
 	case UCLASS_PVBLOCK:
 		puts("PV BLOCK");
 		break;
+	case UCLASS_RKMTD:
+		puts("RKMTD");
+		break;
 	case UCLASS_VIRTIO:
 		puts("VirtIO");
 		break;
drivers/block/blk-uclass.c +1 -0
index 614b975e25c2..6bad2719e729 100644
@@ -34,6 +34,7 @@ static struct {
 	{ UCLASS_VIRTIO, "virtio" },
 	{ UCLASS_PVBLOCK, "pvblock" },
 	{ UCLASS_BLKMAP, "blkmap" },
+	{ UCLASS_RKMTD, "rkmtd" },
 };
 
 static enum uclass_id uclass_name_to_iftype(const char *uclass_idname)
include/dm/uclass-id.h +1 -0
index 307ad6931ca7..99a411429a2f 100644
@@ -113,6 +113,7 @@ enum uclass_id {
 	UCLASS_REGULATOR,	/* Regulator device */
 	UCLASS_REMOTEPROC,	/* Remote Processor device */
 	UCLASS_RESET,		/* Reset controller device */
+	UCLASS_RKMTD,		/* Rockchip MTD device */
 	UCLASS_RNG,		/* Random Number Generator */
 	UCLASS_RTC,		/* Real time clock device */
 	UCLASS_SCMI_AGENT,	/* Interface with an SCMI server */

--
2.39.2

#3 lore raw

Re: [PATCH v2 2/3] dm: prepare rkmtd UCLASS

Hi Johan,

Quoted 4 lines · Johan Jonker

Prepare a rkmtd UCLASS in use for writing Rockchip boot blocks in combination with existing userspace tools and rockusb command.

Quoted 8 lines
---
 disk/part.c                | 4 ++++
 drivers/block/blk-uclass.c | 1 +
 include/dm/uclass-id.h     | 1 +
 3 files changed, 6 insertions(+)

A new uclass should have a sandbox test and a header file or some other docs describing it.

REgards,
Simon

#4 lore raw

Re: [PATCH v2 2/3] dm: prepare rkmtd UCLASS

Quoted 16 lines · Simon Glass

Hi Johan,

Quoted 4 lines · Johan Jonker

Prepare a rkmtd UCLASS in use for writing Rockchip boot blocks in combination with existing userspace tools and rockusb command.

Quoted 8 lines
---
 disk/part.c                | 4 ++++
 drivers/block/blk-uclass.c | 1 +
 include/dm/uclass-id.h     | 1 +
 3 files changed, 6 insertions(+)
Quoted 2 lines

A new uclass should have a sandbox test and a header file or some other docs describing it.

Hi Simon, Mark,

Found by git bisect. This serie worked fine till this patch was applied:

blk: Add bounce buffer support to read/write operations
https://source.denx.de/u-boot/u-boot/-/commit/75191f75bce45f3b9aff607c88f17778d3805c61

On Rockchip boards CONFIG_BOUNCE_BUFFER is selected by CONFIG_MMC_DW. These DW controllers have there own DMA interface.
However Rockchip boards CONFIG_DM_DMA is not enabled.
A virtual disk driver doesn't work with that extra buffer.

This patch is there. What route should we take to get rid of it.

Please advise,

Johan

Quoted 3 lines

REgards,
Simon

#5 lore raw

Re: [PATCH v2 2/3] dm: prepare rkmtd UCLASS

Hi Johan,

Quoted 30 lines · Johan Jonker
Quoted 16 lines · Simon Glass

Hi Johan,

Quoted 4 lines · Johan Jonker

Prepare a rkmtd UCLASS in use for writing Rockchip boot blocks in combination with existing userspace tools and rockusb command.

Quoted 8 lines
---
 disk/part.c                | 4 ++++
 drivers/block/blk-uclass.c | 1 +
 include/dm/uclass-id.h     | 1 +
 3 files changed, 6 insertions(+)
Quoted 2 lines

A new uclass should have a sandbox test and a header file or some other docs describing it.

Hi Simon, Mark,

Found by git bisect. This serie worked fine till this patch was applied:

blk: Add bounce buffer support to read/write operations
https://source.denx.de/u-boot/u-boot/-/commit/75191f75bce45f3b9aff607c88f17778d3805c61

Quoted 6 lines

On Rockchip boards CONFIG_BOUNCE_BUFFER is selected by CONFIG_MMC_DW. These DW controllers have there own DMA interface.
However Rockchip boards CONFIG_DM_DMA is not enabled.
A virtual disk driver doesn't work with that extra buffer.

This patch is there. What route should we take to get rid of it.

This rkmtd driver should depend on !BOUNCE_BUFFER perhaps? Or if the bounce buffer is needed by rockchip, then perhaps we need to be able to enable/disable it at runtime for different uclasses / devices?

Regards,
Simon

#6 lore raw

PATCH v2 3/3 rockchip: cmd: add rkmtd command

In reply to Johan Jonker

The command rkmtd creates a virtual block device to transfer Rockchip boot block data to and from NAND with block orientated tools like "ums" and "rockusb".

It uses the Rockchip MTD driver to scan for boot blocks and copies data from the first block in a GPT formated virtual disk. Data must be written in U-boot "idbloader.img" format and start at partition "loader1" offset 64. The data header is parsed for length and offset. When the last sector is received it erases up to 5 erase blocks on NAND and writes bootblocks in a pattern depending on the NAND ID. Data is then verified. When a block turns out bad the block header is discarded.

---

Changed V2:
rename to rkmtd
change function call
restyle

---
 cmd/Kconfig  |    7 +
 cmd/Makefile |    1 +
 cmd/rkmtd.c  | 1432 ++++++++++++++++++++++++++++++++++++++++++++++++++
 3 files changed, 1440 insertions(+)
 create mode 100644 cmd/rkmtd.c
cmd/Kconfig +7 -0
index 2d6e5f993f04..4ce6123b5017 100644
@@ -1553,6 +1553,13 @@ config CMD_USB_SDP
 	  Enables the command "sdp" which is used to have U-Boot emulating the
 	  Serial Download Protocol (SDP) via USB.
 
+config CMD_RKMTD
+	bool "rkmtd"
+	help
+	  Enable the command "rkmtd" to create a virtual block device to transfer
+	  Rockchip boot block data to and from NAND with block orientated tools
+	  like "ums" and "rockusb".
+
 config CMD_ROCKUSB
 	bool "rockusb"
 	depends on USB_FUNCTION_ROCKUSB
cmd/Makefile +1 -0
index 9f8c0b058bea..dfada2306026 100644
@@ -150,6 +150,7 @@ obj-$(CONFIG_CMD_REISER) += reiser.o
 obj-$(CONFIG_CMD_REMOTEPROC) += remoteproc.o
 obj-$(CONFIG_CMD_RNG) += rng.o
 obj-$(CONFIG_CMD_KASLRSEED) += kaslrseed.o
+obj-$(CONFIG_CMD_RKMTD) += rkmtd.o
 obj-$(CONFIG_CMD_ROCKUSB) += rockusb.o
 obj-$(CONFIG_CMD_RTC) += rtc.o
 obj-$(CONFIG_SANDBOX) += host.o
cmd/rkmtd.c new file +1432 -0

1,432 lines not on this page · raw message

--
2.39.2