From 3e252cae2b5b95c483104318120338d5a51a6b4d Mon Sep 17 00:00:00 2001
From: Jonas Karlman <jonas@kwiboo.se>
Date: Wed, 29 Jan 2025 22:36:32 +0000
Subject: [PATCH] rockchip: mkimage: Add option for image load address and flag

The v2 image format supports defining a load address and flag for each
embedded image.

Add initial support for writing the image load address and flag to the
v2 image format header.

This may later be used for RK3576 to embed a minimal initial image that
if required to fix booting from SD-card due to a BootROM issue.

Signed-off-by: Jonas Karlman <jonas@kwiboo.se>
---
 tools/rkcommon.c | 7 ++++++-
 1 file changed, 6 insertions(+), 1 deletion(-)

--- a/tools/rkcommon.c
+++ b/tools/rkcommon.c
@@ -152,12 +152,16 @@ static struct spl_info spl_infos[] = {
  *
  * @file:	image file path
  * @size:	aligned size of image in bytes
+ * @address:	image load address
+ * @flag:	no use
  */
 
 struct spl_params {
 	struct {
 		char *file;
 		uint32_t size;
+		uint32_t address;
+		uint32_t flag;
 	} images[4];
 };
 
@@ -368,7 +372,8 @@ static void rkcommon_set_header0_v2(void
 		image_sector_count = spl_params.images[i].size / RK_BLK_SIZE;
 		hdr->images[i].offset = cpu_to_le16(sector_offset);
 		hdr->images[i].size = cpu_to_le16(image_sector_count);
-		hdr->images[i].address = 0xFFFFFFFF;
+		hdr->images[i].address = spl_params.images[i].address ?: 0xFFFFFFFF;
+		hdr->images[i].flag = spl_params.images[i].flag;
 		hdr->images[i].counter = cpu_to_le32(i + 1);
 		image_ptr = buf + sector_offset * RK_BLK_SIZE;
 		do_sha256_hash(image_ptr, spl_params.images[i].size,
