mail archive of the barebox mailing list
 help / color / mirror / Atom feed
From: Sascha Hauer <s.hauer@pengutronix.de>
To: Barebox List <barebox@lists.infradead.org>
Subject: [PATCH 05/25] scripts: imx9image: Add PBL size option
Date: Fri, 10 Nov 2023 13:57:40 +0100	[thread overview]
Message-ID: <20231110125800.1901232-6-s.hauer@pengutronix.de> (raw)
In-Reply-To: <20231110125800.1901232-1-s.hauer@pengutronix.de>

The i.MX9 ROM can only load images that fit into OCRAM. The barebox
image is usually bigger. This adds a -pblsize option that has the
effect that it sets the image size in the header to the provided pbl
size, so that the ROM only partially loads the image. barebox will
then use the ROMAPI to load the rest of the image.

We also add an additional alignment of 1KiB to the pblsize. This
helps us with USB booting, as the USB protocol uploads in chunks of
1KiB.

Signed-off-by: Sascha Hauer <s.hauer@pengutronix.de>
---
 scripts/imx9image.c | 26 +++++++++++++++++---------
 1 file changed, 17 insertions(+), 9 deletions(-)

diff --git a/scripts/imx9image.c b/scripts/imx9image.c
index a991ba5f35..53fb879882 100644
--- a/scripts/imx9image.c
+++ b/scripts/imx9image.c
@@ -346,7 +346,7 @@ static void set_imx_hdr_v3(struct imx_header_v3 *imxhdr, uint32_t dcd_len,
 	fhdr_v3->version = IVT_VERSION_B0;
 }
 
-static void set_image_hash(struct boot_img *img, char *filename, uint32_t hash_type)
+static void set_image_hash(struct boot_img *img, char *filename, uint32_t hash_type, int size)
 {
 	FILE *fp = NULL;
 	char sha_command[512];
@@ -383,13 +383,11 @@ static void set_image_hash(struct boot_img *img, char *filename, uint32_t hash_t
 		break;
 	}
 
-	if (img->size == 0 || !filename)
+	if (!size || !filename)
 		sprintf(sha_command, "%s /dev/null", digest_type);
 	else
-		sprintf(sha_command, "dd status=none if=/dev/zero of=tmp_pad bs=%d count=1;\
-				dd status=none if=\'%s\' of=tmp_pad conv=notrunc;\
-				%s tmp_pad; rm -f tmp_pad",
-			img->size, filename, digest_type);
+		sprintf(sha_command, "cat \'%s\' /dev/zero | dd status=none bs=1 count=%d | %s",
+			filename, size, digest_type);
 
 	memset(img->hash, 0, HASH_MAX_LEN);
 
@@ -562,7 +560,7 @@ static void set_image_array_entry(struct flash_header_v3 *container, soc_type_t
 	img->offset = offset;  /* Is re-adjusted later */
 	img->size = size;
 
-	set_image_hash(img, tmp_filename, get_hash_algo(images_hash));
+	set_image_hash(img, tmp_filename, get_hash_algo(images_hash), size);
 
 	switch (type) {
 	case SECO:
@@ -678,7 +676,7 @@ static void set_image_array_entry(struct flash_header_v3 *container, soc_type_t
 			img = &container->img[container->num_images];
 			img->hab_flags |= IMG_TYPE_DCD_DDR;
 			img->hab_flags |= CORE_SC << BOOT_IMG_FLAGS_CORE_SHIFT;
-			set_image_hash(img, "/dev/null", IMAGE_HASH_ALGO_DEFAULT);
+			set_image_hash(img, "/dev/null", IMAGE_HASH_ALGO_DEFAULT, 0);
 			img->offset = offset + img->size;
 			img->entry = read_dcd_offset(tmp_filename);
 			img->dst = img->entry - 1;
@@ -871,6 +869,8 @@ static void copy_file(int ifd, const char *datafile, int pad, int offset)
 	(void) close (dfd);
 }
 
+static int pblsize;
+
 static int build_container_qx_qm_b0(soc_type_t soc, uint32_t sector_size, uint32_t ivt_offset,
 				    char *out_file, bool emmc_fastboot, image_t *image_stack,
 				    bool dcd_skip, uint8_t fuse_version, uint16_t sw_version,
@@ -920,6 +920,7 @@ static int build_container_qx_qm_b0(soc_type_t soc, uint32_t sector_size, uint32
 	img_sp = image_stack;
 
 	while (img_sp->option != NO_IMG) { /* stop once we reach null terminator */
+		int isize;
 		switch (img_sp->option) {
 		case FCB:
 		case AP:
@@ -934,11 +935,14 @@ static int build_container_qx_qm_b0(soc_type_t soc, uint32_t sector_size, uint32
 				exit(EXIT_FAILURE);
 			}
 			check_file(&sbuf, img_sp->filename);
+			isize = ALIGN(sbuf.st_size, sector_size);
+			if (pblsize && isize > ALIGN(pblsize, 1024))
+				isize = ALIGN(pblsize, 1024);
 			set_image_array_entry(&imx_header.fhdr[container],
 						soc,
 						img_sp,
 						file_off,
-						ALIGN(sbuf.st_size, sector_size),
+						isize,
 						img_sp->filename,
 						dcd_skip,
 						images_hash);
@@ -1788,6 +1792,7 @@ int main(int argc, char **argv)
 		{"upower", required_argument, NULL, 'w'},
 		{"fcb", required_argument, NULL, 'b'},
 		{"padding", required_argument, NULL, 'G'},
+		{"pblsize", required_argument, NULL, 0x1000},
 		{NULL, 0, NULL, 0}
 	};
 
@@ -2122,6 +2127,9 @@ int main(int argc, char **argv)
 			printf("Padding length:\t%s bytes\n", optarg);
 			file_off = atoi(optarg);
 			break;
+		case 0x1000:
+			pblsize = atoi(optarg);
+			break;
 		case '?':
 		default:
 			/* invalid option */
-- 
2.39.2




  parent reply	other threads:[~2023-11-10 12:59 UTC|newest]

Thread overview: 29+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2023-11-10 12:57 [PATCH 00/25] Add i.MX93 support Sascha Hauer
2023-11-10 12:57 ` [PATCH 01/25] ARM: initial i.MX9 support Sascha Hauer
2023-11-10 12:57 ` [PATCH 02/25] ARM: i.MX: Add i.MX93 s4mu support Sascha Hauer
2023-11-13  7:25   ` Ahmad Fatoum
2023-11-10 12:57 ` [PATCH 03/25] ARM: i.MX: Add i.MX93 trdc support Sascha Hauer
2023-11-13  7:24   ` Ahmad Fatoum
2023-11-13  8:11     ` Sascha Hauer
2023-11-10 12:57 ` [PATCH 04/25] scripts: Add imx9image tool Sascha Hauer
2023-11-10 12:57 ` Sascha Hauer [this message]
2023-11-10 12:57 ` [PATCH 06/25] clk: Add i.MX93 clock support Sascha Hauer
2023-11-10 12:57 ` [PATCH 07/25] clk: imx: clk-fracn-gppll: make usable from PBL Sascha Hauer
2023-11-10 12:57 ` [PATCH 08/25] gpio-vf610: Add i.MX93 support Sascha Hauer
2023-11-10 12:57 ` [PATCH 09/25] iomux: " Sascha Hauer
2023-11-10 12:57 ` [PATCH 10/25] watchdog: Add ULP wdog support Sascha Hauer
2023-11-10 12:57 ` [PATCH 11/25] I2c: Add i2c_8bit_addr_from_msg() Sascha Hauer
2023-11-10 12:57 ` [PATCH 12/25] i2c: Add lpi2c support Sascha Hauer
2023-11-10 12:57 ` [PATCH 13/25] ARM: Add imx93.dtsi for USB Sascha Hauer
2023-11-10 12:57 ` [PATCH 14/25] serial: Add lpuart32 driver Sascha Hauer
2023-11-10 12:57 ` [PATCH 15/25] ARM: i.MX: add i.MX9 debug_ll support Sascha Hauer
2023-11-10 12:57 ` [PATCH 16/25] ARM: Add TQ MBA9XXXCA board support Sascha Hauer
2023-11-10 12:57 ` [PATCH 17/25] ARM: i.MX93: Add DDR size read support Sascha Hauer
2023-11-10 12:57 ` [PATCH 18/25] ARM: i.MX: romapi: rename functions to *romapi* Sascha Hauer
2023-11-10 12:57 ` [PATCH 19/25] ARM: i.MX: romapi: Implement i.MX93 support Sascha Hauer
2023-11-10 12:57 ` [PATCH 20/25] ARM: i.MX: atf: add imx93_load_and_start_image_via_tfa() Sascha Hauer
2023-11-10 12:57 ` [PATCH 21/25] imx-usb-loader: Add i.MX9 support Sascha Hauer
2023-11-10 12:57 ` [PATCH 22/25] spi: spi-nxp-fspi: Enable for i.MX9 Sascha Hauer
2023-11-10 12:57 ` [PATCH 23/25] usb: i.MX chipidea: Enable usbmisc driver " Sascha Hauer
2023-11-10 12:57 ` [PATCH 24/25] ARM: Update imx_v8_defconfig Sascha Hauer
2023-11-10 12:58 ` [PATCH 25/25] ARM: multi_v8_defconfig: enable i.MX9 boards 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=20231110125800.1901232-6-s.hauer@pengutronix.de \
    --to=s.hauer@pengutronix.de \
    --cc=barebox@lists.infradead.org \
    /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