mail archive of the barebox mailing list
 help / color / mirror / Atom feed
From: Sascha Hauer <s.hauer@pengutronix.de>
To: BAREBOX <barebox@lists.infradead.org>
Cc: Matthias Zoechmann <matthias.zoechmann@ife-doors.com>
Subject: [PATCH 2/3] scripts: imx-image: support DCD_WRITE on closed dev
Date: Mon, 01 Sep 2025 09:35:30 +0200	[thread overview]
Message-ID: <20250901-imx6-usb-uuu-v1-2-1194bb6135ae@pengutronix.de> (raw)
In-Reply-To: <20250901-imx6-usb-uuu-v1-0-1194bb6135ae@pengutronix.de>

From: Matthias Zoechmann <matthias.zoechmann@ife-doors.com>

If an image is loaded by serial download protocol with DCD_WRITE ROM
command on closed i.mx6 devices, the DCD table block loaded into the
OCRAM must be signed.
This patch adds the option '-a' to apply the additional authentication
block for the OCRAM section into the CSF.
The load address for the block is fixed to '0x00910000' which is the
default address configured in mfg-tools of NXP.

Signed-off-by: Matthias Zoechmann <matthias.zoechmann@ife-doors.com>
---
 include/mach/imx/imx-header.h |  2 ++
 scripts/imx/imx-image.c       | 19 ++++++++++++++++++-
 scripts/imx/imx.c             | 22 ++++++++++++++++++++++
 3 files changed, 42 insertions(+), 1 deletion(-)

diff --git a/include/mach/imx/imx-header.h b/include/mach/imx/imx-header.h
index 08329e3d056171ff1b4b5d9399f68fb8e0387f77..e8ead33a9ead4024da63574a71afc96923d54671 100644
--- a/include/mach/imx/imx-header.h
+++ b/include/mach/imx/imx-header.h
@@ -115,6 +115,7 @@ struct config_data {
 	int (*write_mem)(const struct config_data *data, uint32_t addr,
 			 uint32_t val, int width, int set_bits, int clear_bits);
 	int (*nop)(const struct config_data *data);
+	int (*get_dcd_length)(void);
 	char *csf;
 	char *flexspi_csf;
 	int sign_image;
@@ -122,6 +123,7 @@ struct config_data {
 	int encrypt_image;
 	size_t dek_size;
 	bool hab_qspi_support;
+	bool dcd_usb_image;
 };
 
 #define MAX_RECORDS_DCD_V2 1024
diff --git a/scripts/imx/imx-image.c b/scripts/imx/imx-image.c
index a8ac34091fc0811ad76064b178416056a02ea2c9..c08857a6157e92ae7cb4a395a618b3eaeaedae9f 100644
--- a/scripts/imx/imx-image.c
+++ b/scripts/imx/imx-image.c
@@ -495,6 +495,9 @@ static void usage(const char *prgname)
 		"             variable 'CST'\n"
 		"-u           create USB image suitable for imx-usb-loader\n"
 		"             necessary for signed images (-s) only\n"
+		"-a           authenticate additionaly the DCD block loaded via\n"
+		"             'SDP: DCD_WRITE' to the internal RAM on i.mx6 devices\n"
+		"             necessary for usb images (-u) only\n"
 		"-h           this help\n", prgname);
 	exit(1);
 }
@@ -662,6 +665,11 @@ static int nop(const struct config_data *data)
 	}
 }
 
+static int get_dcd_length(void)
+{
+	return sizeof(uint32_t) + (curdcd * sizeof(uint32_t));
+}
+
 /*
  * This uses the Freescale Code Signing Tool (CST) to sign the image.
  * The cst is expected to be executable as 'cst' or if exists, the content
@@ -875,6 +883,7 @@ int main(int argc, char *argv[])
 		.write_mem = write_mem,
 		.check = check,
 		.nop = nop,
+		.get_dcd_length = get_dcd_length
 	};
 	uint32_t *bb_header;
 	size_t sizeof_bb_header;
@@ -883,7 +892,7 @@ int main(int argc, char *argv[])
 
 	prgname = argv[0];
 
-	while ((opt = getopt(argc, argv, "c:hf:o:p:bduse")) != -1) {
+	while ((opt = getopt(argc, argv, "c:hf:o:p:bduase")) != -1) {
 		switch (opt) {
 		case 'c':
 			configfile = optarg;
@@ -909,6 +918,9 @@ int main(int argc, char *argv[])
 		case 'u':
 			create_usb_image = true;
 			break;
+		case 'a':
+			data.dcd_usb_image = true;
+			break;
 		case 'e':
 			data.encrypt_image = 1;
 			break;
@@ -969,6 +981,11 @@ int main(int argc, char *argv[])
 		create_usb_image = 0;
 	}
 
+	if (data.dcd_usb_image && !create_usb_image) {
+		fprintf(stderr, "Warning: the -a option only has effect with usb images\n");
+		data.dcd_usb_image = false;
+	}
+
 	if (data.image_ivt_offset == 0xffffffff) {
 		if (create_usb_image)
 			data.image_ivt_offset = 0x0;
diff --git a/scripts/imx/imx.c b/scripts/imx/imx.c
index 6dabaf59c159b582dfe84eff81cec039c4863b77..26efe6d813dca5ecc7b2a06459df2b2f26673e0f 100644
--- a/scripts/imx/imx.c
+++ b/scripts/imx/imx.c
@@ -430,6 +430,28 @@ static int do_hab_blocks(struct config_data *data, int argc, char *argv[])
 		ret = asprintf(&str, "Blocks = 0x%08x 0x%08x 0x%08x \"%s\"",
 			data->image_load_addr + data->image_ivt_offset, offset,
 			signed_size - data->image_ivt_offset, data->outfile);
+
+		if (data->dcd_usb_image && (data->cpu_type == IMX_CPU_IMX6)) {
+			char *str_dcd_blk;
+			uint32_t dcd_offset = offset + offsetof(struct imx_flash_header_v2, dcd_header);
+			uint32_t dcd_length = data->get_dcd_length();
+
+			if(!dcd_length) {
+				fprintf(stderr, "failed to get dcd length\n");
+				return -EINVAL;
+			}
+
+			ret |= asprintf(&str_dcd_blk, ", \\\n 0x00910000 0x%08x 0x%08x \"%s\"",
+				dcd_offset, dcd_length, data->outfile);
+
+			str = strcata(str, str_dcd_blk);
+			free(str_dcd_blk);
+
+			if(!str) {
+				return -ENOMEM;
+			}
+		}
+
 		if (data->flexspi_csf)
 			ret |= asprintf(&flexspi_str,
 					"Blocks = 0x%08x 0x%08x 0x%08x \"%s\"",

-- 
2.47.2




  parent reply	other threads:[~2025-09-01  8:02 UTC|newest]

Thread overview: 6+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2025-09-01  7:35 [PATCH 0/3] i.MX6 uuu support for signed images Sascha Hauer
2025-09-01  7:35 ` [PATCH 1/3] scripts: imx: fix string in further auth block Sascha Hauer
2025-09-01  7:35 ` Sascha Hauer [this message]
2025-09-01  7:35 ` [PATCH 3/3] mach-imx: Kconfig: add option for image with dcd " Sascha Hauer
2025-09-01  8:23   ` Ahmad Fatoum
2025-09-01  8:28     ` Sascha Hauer

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=20250901-imx6-usb-uuu-v1-2-1194bb6135ae@pengutronix.de \
    --to=s.hauer@pengutronix.de \
    --cc=barebox@lists.infradead.org \
    --cc=matthias.zoechmann@ife-doors.com \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox