Skip to contentSkip to conversation

mkimage/rockchip: support packing optional second level boot-loader

PATCH Superseded Jeffy Chen 1 participant 4 messages Dec 27, 2019 Arm Rockchip

v3 of 4 Superseded Latest is v4 →

lore
Share & tools
lore

Jeffy Chen

author
#0 lore raw

v3 cover mkimage/rockchip: support packing optional second level boot-loader

When enabling back-to-bootrom, the bootrom would continue to load the second level boot-loader. And currently we are packing it by appending the generated image manually (with a predefined max size):

./firefly-rk3288/tools/mkimage -n rk3288 -T rksd -d \
firefly-rk3288/spl/u-boot-spl-dtb.bin out && \
cat firefly-rk3288/u-boot-dtb.bin >> out

This series add support of packing optional second level loader with mkimage tool:

./tools/mkimage -n rk3399 -T rksd -d \
    rk3399_ddr_800MHz_v1.24.bin:rk3399_miniloader_v1.19.bin out

Changes in v3:
Rule out hdr when checking spl size. (The bootrom would put hdr on stack.)

Changes in v2:
Do rc4 encode for boot data when needed as well.

Jeffy Chen (3):
rockchip: mkimage: support packing optional second level boot-loader
doc: rockchip: document packing second level loader with mkimage
rockchip: mkimage: fix wrong range of rc4 encoding for boot image

 doc/README.rockchip |  11 +++
 tools/imagetool.h   |   1 +
 tools/mkimage.c     |   8 ++
 tools/rkcommon.c    | 244 +++++++++++++++++++++++++++++++++++++++++++---------
 tools/rkcommon.h    |  18 ++--
 tools/rkimage.c     |   2 +-
 tools/rksd.c        |  35 +-------
 tools/rkspi.c       |  42 +++------
 8 files changed, 244 insertions(+), 117 deletions(-)
Signature · 1 line
2.11.0
author
#1 lore raw

PATCH v3 1/3 rockchip: mkimage: support packing optional second level boot-loader

Support packing optional second level boot-loader:

$ ./tools/mkimage -n rk3399 -T rksd -d \
  rk3399_ddr_800MHz_v1.24.bin:rk3399_miniloader_v1.19.bin out -v
Adding Image rk3399_ddr_800MHz_v1.24.bin
Size 116492(pad to 116736)
Adding Image rk3399_miniloader_v1.19.bin
Size 88060(pad to 88064)
Image Type:   Rockchip RK33 (SD/MMC) boot image
Init Data Size: 116736 bytes
Boot Data Size: 88064 bytes

Mainly parse init file and boot file from datafile option, copy them to the image with 2KB alignment.

---

Changes in v3:
Rule out hdr when checking spl size. (The bootrom would put hdr on stack.)

Changes in v2:
Do rc4 encode for boot data when needed as well.

 tools/imagetool.h |   1 +
 tools/mkimage.c   |   8 ++
 tools/rkcommon.c  | 244 ++++++++++++++++++++++++++++++++++++++++++++----------
 tools/rkcommon.h  |  18 ++--
 tools/rksd.c      |  35 +-------
 tools/rkspi.c     |  42 ++++------
 6 files changed, 232 insertions(+), 116 deletions(-)
tools/imagetool.h +1 -0
index 2689a4004a..e1c778b0df 100644
@@ -253,6 +253,7 @@ void pbl_load_uboot(int fd, struct image_tool_params *mparams);
 int zynqmpbif_copy_image(int fd, struct image_tool_params *mparams);
 int imx8image_copy_image(int fd, struct image_tool_params *mparams);
 int imx8mimage_copy_image(int fd, struct image_tool_params *mparams);
+int rockchip_copy_image(int fd, struct image_tool_params *mparams);
 
 #define ___cat(a, b) a ## b
 #define __cat(a, b) ___cat(a, b)
tools/mkimage.c +8 -0
index 4217188310..5f51d2cc89 100644
@@ -544,6 +544,14 @@ int main(int argc, char **argv)
 			ret = imx8mimage_copy_image(ifd, &params);
 			if (ret)
 				return ret;
+		} else if ((params.type == IH_TYPE_RKSD) ||
+				(params.type == IH_TYPE_RKSPI)) {
+			/* Rockchip has special Image format */
+			int ret;
+
+			ret = rockchip_copy_image(ifd, &params);
+			if (ret)
+				return ret;
 		} else {
 			copy_file(ifd, params.datafile, pad_len);
 		}
tools/rkcommon.c +202 -42

332 lines not on this page · raw message

tools/rkcommon.h +5 -13
index 47f47a52aa..93518824a5 100644
@@ -9,13 +9,11 @@
 
 enum {
 	RK_BLK_SIZE		= 512,
-	RK_INIT_SIZE_ALIGN      = 2048,
+	RK_SIZE_ALIGN		= 2048,
 	RK_INIT_OFFSET		= 4,
 	RK_MAX_BOOT_SIZE	= 512 << 10,
 	RK_SPL_HDR_START	= RK_INIT_OFFSET * RK_BLK_SIZE,
 	RK_SPL_HDR_SIZE		= 4,
-	RK_SPL_START		= RK_SPL_HDR_START + RK_SPL_HDR_SIZE,
-	RK_IMAGE_HEADER_LEN	= RK_SPL_START,
 };
 
 /**
@@ -49,11 +47,9 @@ int rkcommon_get_spl_size(struct image_tool_params *params);
  * This sets up a 2KB header which can be interpreted by the Rockchip boot ROM.
  *
  * @buf:	Pointer to header place (must be@least 2KB in size)
- * @file_size:	Size of the file we want the boot ROM to load, in bytes
- * @return 0 if OK, -ENOSPC if too large
  */
-int rkcommon_set_header(void *buf, uint file_size,
-			struct image_tool_params *params);
+void rkcommon_set_header(void *buf,  struct stat *sbuf,  int ifd,
+			 struct image_tool_params *params);
 
 /**
  * rkcommon_verify_header() - verify the header for a Rockchip boot image
@@ -102,14 +98,10 @@ void rkcommon_rc4_encode_spl(void *buf, unsigned int offset, unsigned int size);
  * @params:     Pointer to the tool params structure
  * @tparams:    Pointer tot the image type structure (for setting
  *              the header and header_size)
- * @alignment:  Alignment (a power of two) that the image should be
- *              padded to (e.g. 512 if we want to align with SD/MMC
- *              blocksizes or 2048 for the SPI format)
  *
- * @return bytes of padding required/added (does not include the header_size)
+ * @return 0 (always)
  */
 int rkcommon_vrec_header(struct image_tool_params *params,
-			 struct image_type_params *tparams,
-			 unsigned int alignment);
+			 struct image_type_params *tparams);
 
 #endif
tools/rksd.c +2 -33
index 24411d863a..7d46a1b07b 100644
@@ -12,27 +12,6 @@
 #include "mkimage.h"
 #include "rkcommon.h"
 
-static void rksd_set_header(void *buf,  struct stat *sbuf,  int ifd,
-			    struct image_tool_params *params)
-{
-	unsigned int size;
-	int ret;
-
-	/*
-	 * We need to calculate this using 'RK_SPL_HDR_START' and not using
-	 * 'tparams->header_size', as the additional byte inserted when
-	 * 'is_boot0' is true counts towards the payload (and not towards the
-	 * header).
-	 */
-	size = params->file_size - RK_SPL_HDR_START;
-	ret = rkcommon_set_header(buf, size, params);
-	if (ret) {
-		/* TODO(sjg at chromium.org): This method should return an error */
-		printf("Warning: SPL image is too large (size %#x) and will "
-		       "not boot\n", size);
-	}
-}
-
 static int rksd_check_image_type(uint8_t type)
 {
 	if (type == IH_TYPE_RKSD)
@@ -41,16 +20,6 @@ static int rksd_check_image_type(uint8_t type)
 		return EXIT_FAILURE;
 }
 
-static int rksd_vrec_header(struct image_tool_params *params,
-			    struct image_type_params *tparams)
-{
-	/*
-	 * Pad to a 2KB alignment, as required for init_size by the ROM
-	 * (see https://lists.denx.de/pipermail/u-boot/2017-May/293268.html)
-	 */
-	return rkcommon_vrec_header(params, tparams, RK_INIT_SIZE_ALIGN);
-}
-
 /*
  * rk_sd parameters
  */
@@ -62,9 +31,9 @@ U_BOOT_IMAGE_TYPE(
 	rkcommon_check_params,
 	rkcommon_verify_header,
 	rkcommon_print_header,
-	rksd_set_header,
+	rkcommon_set_header,
 	NULL,
 	rksd_check_image_type,
 	NULL,
-	rksd_vrec_header
+	rkcommon_vrec_header
 );
tools/rkspi.c +14 -28

71 lines not on this page · raw message

Signature · 1 line
2.11.0
author
#2 lore raw

PATCH v3 2/3 doc: rockchip: document packing second level loader with mkimage

In reply to Jeffy Chen

Add documentation about packing optional second level boot-loader with mkimage tool.

---

Changes in v3: None
Changes in v2: None

 doc/README.rockchip | 11 +++++++++++
 1 file changed, 11 insertions(+)
doc/README.rockchip +11 -0
index dae4ebc8e4..e54b7b8df5 100644
@@ -340,6 +340,12 @@ You can create the image via the following operations:
    cat firefly-rk3288/u-boot-dtb.bin >> out && \
    sudo dd if=out of=/dev/sdc seek=64
 
+Or:
+   ./firefly-rk3288/tools/mkimage -n rk3288 -T rksd -d \
+	firefly-rk3288/spl/u-boot-spl-dtb.bin:firefly-rk3288/u-boot-dtb.bin \
+	out && \
+   sudo dd if=out of=/dev/sdc seek=64
+
 If you have an HDMI cable attached you should see a video console.
 
 For evb_rk3036 board:
@@ -347,6 +353,11 @@ For evb_rk3036 board:
 	cat evb-rk3036/u-boot-dtb.bin >> out && \
 	sudo dd if=out of=/dev/sdc seek=64
 
+Or:
+	./evb-rk3036/tools/mkimage -n rk3036 -T rksd -d \
+		evb-rk3036/spl/u-boot-spl.bin:evb-rk3036/u-boot-dtb.bin out && \
+	sudo dd if=out of=/dev/sdc seek=64
+
 Note: rk3036 SDMMC and debug uart use the same iomux, so if you boot from SD, the
       debug uart must be disabled
 
Signature · 1 line
2.11.0
author
#3 lore raw

PATCH v3 3/3 rockchip: mkimage: fix wrong range of rc4 encoding for boot image

In reply to Jeffy Chen

The rc4 encoding should cover spl header as well, and the file_size contains spl header too.

---

Changes in v3: None
Changes in v2: None

 tools/rkimage.c | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)
tools/rkimage.c +1 -1
index ae50de55c9..1c5540b1c3 100644
@@ -18,7 +18,7 @@ static void rkimage_set_header(void *buf, struct stat *sbuf, int ifd,
 	memcpy(buf, rkcommon_get_spl_hdr(params), RK_SPL_HDR_SIZE);
 
 	if (rkcommon_need_rc4_spl(params))
-		rkcommon_rc4_encode_spl(buf, 4, params->file_size);
+		rkcommon_rc4_encode_spl(buf, 0, params->file_size);
 }
 
 static int rkimage_check_image_type(uint8_t type)
Signature · 1 line
2.11.0