All of lore.kernel.org
 help / color / mirror / Atom feed
* [PATCH] arm: imx: Add command to get offset of first image in AHAB OS container
@ 2025-11-10 12:41 Lukasz Majewski
  2025-11-10 14:53 ` Tom Rini
  0 siblings, 1 reply; 3+ messages in thread
From: Lukasz Majewski @ 2025-11-10 12:41 UTC (permalink / raw)
  To: Stefano Babic, Fabio Estevam
  Cc: uboot-imx, Tom Rini, u-boot, John Ripple, Peng Fan, Ji Luo,
	Lukasz Majewski

With current mainline it is possible to check with AHAB if system OS image
can be trusted (with 'auth_cntr' command).
However, after the validation one needs to use the image (fitImage in this
case) itself. Such operation requires getting the offset in the image
eligible for AHAB validation to start execution of the fitImage.

Command in this patch allows it, so with:
auth_cntr_offset ${addr} auth_cntr_os_offset;
setexpr addr ${kernel_addr_r} + ${auth_cntr_os_offset};

it is possible to boot the fitImage after AHAB IP block vaidation.

Signed-off-by: Lukasz Majewski <lukma@nabladev.com>
---
 arch/arm/mach-imx/imx8/ahab.c | 50 +++++++++++++++++++++++++++++++++++
 1 file changed, 50 insertions(+)

diff --git a/arch/arm/mach-imx/imx8/ahab.c b/arch/arm/mach-imx/imx8/ahab.c
index f13baa871cc..da0e1f3382b 100644
--- a/arch/arm/mach-imx/imx8/ahab.c
+++ b/arch/arm/mach-imx/imx8/ahab.c
@@ -7,6 +7,7 @@
 #include <errno.h>
 #include <imx_container.h>
 #include <log.h>
+#include <env.h>
 #include <asm/global_data.h>
 #include <asm/io.h>
 #include <firmware/imx/sci/sci.h>
@@ -424,6 +425,55 @@ static int do_ahab_commit(struct cmd_tbl *cmdtp, int flag, int argc,
 	return CMD_RET_SUCCESS;
 }
 
+static int do_ahab_get_offset(struct cmd_tbl *cmdtp, int flag, int argc,
+			      char *const argv[])
+{
+	struct container_hdr *phdr;
+	const char *name = argv[2];
+	struct boot_img_t *img;
+	u16 length;
+	ulong cntr;
+	int err;
+
+	if (argc != 3)
+		return CMD_RET_USAGE;
+
+	if (!name)
+		return CMD_RET_USAGE;
+
+	cntr = hextoul(argv[1], NULL);
+
+	phdr = (struct container_hdr *)cntr;
+	length = phdr->length_lsb + (phdr->length_msb << 8);
+
+	err = ahab_auth_cntr_hdr(phdr, length);
+	if (err) {
+		printf("Authenticate OS container header has failed!\n");
+		return 1;
+	}
+
+	ahab_auth_release();
+
+	/*
+	 * Get the offset for first image (Image0Offset at Fitgure 1.
+	 * of AN12312)
+	 */
+	img = (struct boot_img_t *)
+		((ulong)phdr + sizeof(struct container_hdr));
+
+	debug("%s=0x%x\n", name, img->offset);
+
+	return env_set_hex(name, img->offset);
+}
+
+U_BOOT_CMD(auth_cntr_offset, CONFIG_SYS_MAXARGS, 1, do_ahab_get_offset,
+	   "provide first image offset from AHAB OS container",
+	   "addr name\n"
+	   "addr - OS container hex address\n"
+	   "name - name of the env variable to store offset of the first\n"
+	   "       image from AHAB OS container\n"
+);
+
 U_BOOT_CMD(auth_cntr, CONFIG_SYS_MAXARGS, 1, do_authenticate,
 	   "autenticate OS container via AHAB",
 	   "addr\n"
-- 
2.39.5


^ permalink raw reply related	[flat|nested] 3+ messages in thread

end of thread, other threads:[~2025-11-10 19:14 UTC | newest]

Thread overview: 3+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2025-11-10 12:41 [PATCH] arm: imx: Add command to get offset of first image in AHAB OS container Lukasz Majewski
2025-11-10 14:53 ` Tom Rini
2025-11-10 19:14   ` Łukasz Majewski

This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.