Skip to contentSkip to conversation

rockchip: mkimage: add rockchip nand support

PATCH New Johan Jonker 1 participant 1 message Jun 3, 2022

lore
Share & tools
lore
#0 lore raw

PATCH 1/1 rockchip: mkimage: add rockchip nand support

The Rockchip boot ROM requires a particular file format for booting from NAND:

* It starts with 512-byte, rc4 encoded header and is aligned to NAND page size.

* Then 2KB pieces of spl and tpl data aligned to the NAND page size in a
* fixed pattern with empty pages.

Size of spl and tpl must be aligned to 2KB.
Empty NAND pages not in use need 0xFF padding to increase NAND durability.

Main output here is aimed at for example MTD that only writes whole pages. The pattern and the padding needed depends on the chip and the application that loads. (This format is not fit for BOOTROM mode)

As input file a 4 byte pre-padded tpl/spl file is expected. These bytes are replaced by ASCII characters for example "RK30".

For NAND two extra mkimage input argument types are available:

Direct:
-X [pagesize, lsb_mode]

Obtain arguments by chip ID and a lookup table:

    -X [id0:id1:id2:id3:id4:id5]

As extra SD card images can be made by setting the page size to 2048 and mode 0. Compared to rksd.c the output pads extra 0xFF to the unused sections 1,2,3 of the header which replaces 0x00 by rkcommon_vrec_header() memset.

Example usage for NAND with page size 16384 and pattern mode 2:

    # "SDTNQGAMA 64G 3.3V 8-bit"
    ./mkimage -n rk3066 -T rknand -d u-boot-tpl.bin:u-boot-spl.bin -X 16384,2 out

Example usage for NAND with chip id "ad:de:94:da:74:c4":

    # "H27UCG8T2ATR-BC 64G 3.3V 8-bit"
    ./mkimage -n rk3066 -T rknand -d u-boot-tpl.bin:u-boot-spl.bin -X ad:de:94:da:74:c4 out

Example usage for SD card image with page size 2048 and pattern mode 0:

    # "SD CARD"
    ./mkimage -n rk3188 -T rknand -d u-boot-tpl.bin:u-boot-spl.bin -X 2048,0 out
---
 boot/image.c      |   1 +
 include/image.h   |   1 +
 tools/Makefile    |   2 +-
 tools/imagetool.h |   1 +
 tools/mkimage.c   |   8 +-
 tools/rknand.c    | 432 ++++++++++++++++++++++++++++++++++++++++++++++
 6 files changed, 442 insertions(+), 3 deletions(-)
 create mode 100644 tools/rknand.c
boot/image.c +1 -0
index 5dcb55ba..5a4e98a5 100644
@@ -164,6 +164,7 @@ static const table_entry_t uimage_type[] = {
 	{	IH_TYPE_X86_SETUP,  "x86_setup",  "x86 setup.bin",    },
 	{	IH_TYPE_LPC32XXIMAGE, "lpc32xximage",  "LPC32XX Boot Image", },
 	{	IH_TYPE_RKIMAGE,    "rkimage",    "Rockchip Boot Image" },
+	{	IH_TYPE_RKNAND,     "rknand",     "Rockchip NAND Boot Image" },
 	{	IH_TYPE_RKSD,       "rksd",       "Rockchip SD Boot Image" },
 	{	IH_TYPE_RKSPI,      "rkspi",      "Rockchip SPI Boot Image" },
 	{	IH_TYPE_VYBRIDIMAGE, "vybridimage",  "Vybrid Boot Image", },
include/image.h +1 -0
index e4c6a50b..01963ba7 100644
@@ -211,6 +211,7 @@ enum {
 	IH_TYPE_LPC32XXIMAGE,		/* x86 setup.bin Image		*/
 	IH_TYPE_LOADABLE,		/* A list of typeless images	*/
 	IH_TYPE_RKIMAGE,		/* Rockchip Boot Image		*/
+	IH_TYPE_RKNAND,			/* Rockchip NAND Boot Image	*/
 	IH_TYPE_RKSD,			/* Rockchip SD card		*/
 	IH_TYPE_RKSPI,			/* Rockchip SPI image		*/
 	IH_TYPE_ZYNQIMAGE,		/* Xilinx Zynq Boot Image */
tools/Makefile +1 -1
index 9f233966..b79a0745 100644
@@ -99,7 +99,7 @@ LIBCRYPTO_OBJS-$(CONFIG_TOOLS_LIBCRYPTO) := \
 			lib/fdt-libcrypto.o \
 			sunxi_toc0.o
 
-ROCKCHIP_OBS = lib/rc4.o rkcommon.o rkimage.o rksd.o rkspi.o
+ROCKCHIP_OBS = lib/rc4.o rkcommon.o rkimage.o rknand.o rksd.o rkspi.o
 
 # common objs for dumpimage and mkimage
 dumpimage-mkimage-objs := aisimage.o \
tools/imagetool.h +1 -0
index 05dd94d1..805ddf5b 100644
@@ -90,6 +90,7 @@ struct image_tool_params {
 	const char *engine_id;	/* Engine to use for signing */
 	bool reset_timestamp;	/* Reset the timestamp on an existing image */
 	struct image_summary summary;	/* results of signing process */
+	char *extraparams;	/* Extra parameters for img creation (-X) */
 };
 
 /*
tools/mkimage.c +6 -2
index be58e565..d54f727b 100644
@@ -156,7 +156,7 @@ static void process_args(int argc, char **argv)
 	int opt;
 
 	while ((opt = getopt(argc, argv,
-		   "a:A:b:B:c:C:d:D:e:Ef:FG:k:i:K:ln:N:p:o:O:rR:qstT:vVx")) != -1) {
+		   "a:A:b:B:c:C:d:D:e:Ef:FG:k:i:K:ln:N:p:o:O:rR:qstT:vVxX:")) != -1) {
 		switch (opt) {
 		case 'a':
 			params.addr = strtoull(optarg, &ptr, 16);
@@ -310,6 +310,9 @@ static void process_args(int argc, char **argv)
 		case 'x':
 			params.xflag++;
 			break;
+		case 'X':
+			params.extraparams = optarg;
+			break;
 		default:
 			usage("Invalid option");
 		}
@@ -636,7 +639,8 @@ int main(int argc, char **argv)
 			if (ret)
 				return ret;
 		} else if ((params.type == IH_TYPE_RKSD) ||
-				(params.type == IH_TYPE_RKSPI)) {
+			   (params.type == IH_TYPE_RKSPI) ||
+			   (params.type == IH_TYPE_RKNAND)) {
 			/* Rockchip has special Image format */
 			int ret;
 
tools/rknand.c new file +432 -0

432 lines not on this page · raw message

Signature · 1 line
2.20.1