[PATCH v2 20/29] scripts: imx-image: hab_sign: refactor function

Marco Felsch m.felsch at pengutronix.de
Tue Oct 17 07:51:22 PDT 2023


Refactor the code to make it possible to write multiple CSF blocks. This
is required for the upcoming FlexSPI CSF data fix.

Signed-off-by: Marco Felsch <m.felsch at pengutronix.de>
---
Changelog:
v2:
- unchanged
- v1-link: https://lore.barebox.org/barebox/20231010143314.2031253-1-m.felsch@pengutronix.de/T/#t

 scripts/imx/imx-image.c | 11 +++++++----
 1 file changed, 7 insertions(+), 4 deletions(-)

diff --git a/scripts/imx/imx-image.c b/scripts/imx/imx-image.c
index e9eded7f0828..4372ff85067b 100644
--- a/scripts/imx/imx-image.c
+++ b/scripts/imx/imx-image.c
@@ -660,7 +660,8 @@ static int nop(const struct config_data *data)
  * The cst is expected to be executable as 'cst' or if exists, the content
  * of the environment variable 'CST' is used.
  */
-static int hab_sign(struct config_data *data)
+static int hab_sign(struct config_data *data, const char *csfcmds,
+		    unsigned int csf_slot)
 {
 	int fd, outfd, ret, lockfd;
 	char *csffile, *command;
@@ -674,7 +675,7 @@ static int hab_sign(struct config_data *data)
 	if (!cst)
 		cst = "cst";
 
-	ret = asprintf(&csffile, "%s.csfbin", data->outfile);
+	ret = asprintf(&csffile, "%s.slot%u.csfbin", data->outfile, csf_slot);
 	if (ret < 0)
 		exit(1);
 
@@ -743,7 +744,7 @@ static int hab_sign(struct config_data *data)
 		return -errno;
 	}
 
-	fwrite(data->csf, 1, strlen(data->csf) + 1, f);
+	fwrite(csfcmds, 1, strlen(csfcmds) + 1, f);
 
 	pclose(f);
 
@@ -814,6 +815,8 @@ static int hab_sign(struct config_data *data)
 		if (flexspi_image(data))
 			offset += FLEXSPI_HEADER_LEN;
 
+		offset += csf_slot * CSF_LEN;
+
 		offset = roundup(offset, 0x1000);
 		if (data->signed_hdmi_firmware_file)
 			offset += PLUGIN_HDMI_SIZE;
@@ -1104,7 +1107,7 @@ int main(int argc, char *argv[])
 	}
 
 	if (data.csf && data.sign_image) {
-		ret = hab_sign(&data);
+		ret = hab_sign(&data, data.csf, 0);
 		if (ret)
 			exit(1);
 	}
-- 
2.39.2




More information about the barebox mailing list