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 2/4] pblimage: simplify a bit
Date: Tue, 19 Dec 2023 14:00:38 +0100	[thread overview]
Message-ID: <20231219130040.4115-3-s.hauer@pengutronix.de> (raw)
In-Reply-To: <20231219130040.4115-1-s.hauer@pengutronix.de>

next_pbl_cmd is a global static variable that is initialized multiple
times, but used in a single function only. Instead of obfuscating its
usage, just pass its value as a parameter to generate_pbl_cmd().

Signed-off-by: Sascha Hauer <s.hauer@pengutronix.de>
---
 scripts/pblimage.c | 23 ++++++++---------------
 1 file changed, 8 insertions(+), 15 deletions(-)

diff --git a/scripts/pblimage.c b/scripts/pblimage.c
index 9489c52b18..d0a589f2fe 100644
--- a/scripts/pblimage.c
+++ b/scripts/pblimage.c
@@ -39,10 +39,6 @@
  */
 #define BAREBOX_START	(128 * 1024)
 
-/*
- * Initialize to an invalid value.
- */
-static uint32_t next_pbl_cmd = 0x82000000;
 /*
  * need to store all bytes in memory for calculating crc32, then write the
  * bytes to image file for PBL boot.
@@ -56,7 +52,6 @@ static int out_fd;
 static int in_fd;
 static int spiimage;
 
-static uint32_t pbl_cmd_initaddr;
 static uint32_t pbi_crc_cmd1;
 static uint32_t pbi_crc_cmd2;
 
@@ -77,10 +72,8 @@ static uint32_t pbl_crc32(uint32_t in_crc, const char *buf, uint32_t len)
  * "xxxxxx" is the offset. Calculate the start offset by subtracting the size of
  * the image from the top of the allowable 24-bit range.
  */
-static void generate_pbl_cmd(void)
+static void generate_pbl_cmd(uint32_t val)
 {
-	uint32_t val = next_pbl_cmd;
-	next_pbl_cmd += 0x40;
 	int i;
 
 	for (i = 3; i >= 0; i--) {
@@ -186,6 +179,7 @@ static void add_end_cmd(void)
 static void pbl_load_image(void)
 {
 	int size;
+	unsigned int n;
 	uint64_t *buf64 = (void *)mem_buf;
 
 	/* parse the rcw.cfg file. */
@@ -195,9 +189,12 @@ static void pbl_load_image(void)
 	if (pbifile)
 		pbl_parser(pbifile);
 
-	next_pbl_cmd = pbl_cmd_initaddr - image_size;
-	while (next_pbl_cmd < pbl_cmd_initaddr) {
-		generate_pbl_cmd();
+	for (n = 0; n < image_size; n += 0x40) {
+		uint32_t pbl_cmd;
+
+		pbl_cmd = (loadaddr & PBL_ADDR_24BIT_MASK) | PBL_ACS_CONT_CMD;
+		pbl_cmd += n;
+		generate_pbl_cmd(pbl_cmd);
 		pbl_fget(64, in_fd);
 	}
 
@@ -249,11 +246,7 @@ static int pblimage_check_params(void)
 
 	pbi_crc_cmd1 = 0x61;
 	pbi_crc_cmd2 = 0;
-	pbl_cmd_initaddr = loadaddr & PBL_ADDR_24BIT_MASK;
-	pbl_cmd_initaddr |= PBL_ACS_CONT_CMD;
-	pbl_cmd_initaddr += image_size;
 
-	next_pbl_cmd = pbl_cmd_initaddr;
 	return 0;
 };
 
-- 
2.39.2




  parent reply	other threads:[~2023-12-19 13:02 UTC|newest]

Thread overview: 5+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2023-12-19 13:00 [PATCH 0/4] Layerscape LS1028a pblimage support Sascha Hauer
2023-12-19 13:00 ` [PATCH 1/4] pblimage: drop PowerPC support Sascha Hauer
2023-12-19 13:00 ` Sascha Hauer [this message]
2023-12-19 13:00 ` [PATCH 3/4] pblimage: use roundup() from kernel.h Sascha Hauer
2023-12-19 13:00 ` [PATCH 4/4] pblimage: Add LS1028a support 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=20231219130040.4115-3-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