diff mbox series

[v4,2/2] spl: fdt: Record load/entry fit-images entries in 64bit format

Message ID efbbb81a4483e770b43076050063dfffefac4695.1603118139.git.michal.simek@xilinx.com
State Accepted
Commit 13d1ca8742ab714d4238f7b1598931bb6aaa1ea4
Delegated to: Tom Rini
Headers show
Series Add support for loading images above 4GB | expand

Commit Message

Michal Simek Oct. 19, 2020, 2:35 p.m. UTC
The commit 9f45aeb93727 ("spl: fit: implement fdt_record_loadable") which
introduced fdt_record_loadable() state there spl_fit.c is not 64bit safe.
Based on my tests on Xilinx ZynqMP zcu102 platform there shouldn't be a
problem to record these addresses in 64bit format.
The patch adds support for systems which need to load images above 4GB.

Signed-off-by: Michal Simek <michal.simek@xilinx.com>
Reviewed-by: Simon Glass <sjg@chromium.org>
---

Changes in v4:
- RISCV32_SPL reports issue that two cells format (64bit value) is
  unsupported address size. But that's not accurate because two cell format
  is valid on any 32bit platform. What it is not supported is address above
  4GB. That's why code is fixed by reading value to 64bit type first and then
  check if upper 32bits are zero or not. On all 32bit platforms upper bits
  should be 0 and if not, message is shown.

 common/fdt_support.c |  9 ++-------
 common/image-fit.c   | 11 ++++++-----
 2 files changed, 8 insertions(+), 12 deletions(-)
diff mbox series

Patch

diff --git a/common/fdt_support.c b/common/fdt_support.c
index b8a8768a2147..5ae75df3c658 100644
--- a/common/fdt_support.c
+++ b/common/fdt_support.c
@@ -611,14 +611,9 @@  int fdt_record_loadable(void *blob, u32 index, const char *name,
 	if (node < 0)
 		return node;
 
-	/*
-	 * We record these as 32bit entities, possibly truncating addresses.
-	 * However, spl_fit.c is not 64bit safe either: i.e. we should not
-	 * have an issue here.
-	 */
-	fdt_setprop_u32(blob, node, "load", load_addr);
+	fdt_setprop_u64(blob, node, "load", load_addr);
 	if (entry_point != -1)
-		fdt_setprop_u32(blob, node, "entry", entry_point);
+		fdt_setprop_u64(blob, node, "entry", entry_point);
 	fdt_setprop_u32(blob, node, "size", size);
 	if (type)
 		fdt_setprop_string(blob, node, "type", type);
diff --git a/common/image-fit.c b/common/image-fit.c
index d54eff9033cc..c82d4d8015f0 100644
--- a/common/image-fit.c
+++ b/common/image-fit.c
@@ -791,17 +791,18 @@  static int fit_image_get_address(const void *fit, int noffset, char *name,
 		return -1;
 	}
 
-	if (len > sizeof(ulong)) {
-		printf("Unsupported %s address size\n", name);
-		return -1;
-	}
-
 	cell_len = len >> 2;
 	/* Use load64 to avoid compiling warning for 32-bit target */
 	while (cell_len--) {
 		load64 = (load64 << 32) | uimage_to_cpu(*cell);
 		cell++;
 	}
+
+	if (len > sizeof(ulong) && (uint32_t)(load64 >> 32)) {
+		printf("Unsupported %s address size\n", name);
+		return -1;
+	}
+
 	*load = (ulong)load64;
 
 	return 0;