* [PATCH] scripts: imx-usb-loader: simplify code flow for file size calculations
@ 2022-06-15 12:38 Uwe Kleine-König
2022-06-17 8:13 ` Sascha Hauer
0 siblings, 1 reply; 4+ messages in thread
From: Uwe Kleine-König @ 2022-06-15 12:38 UTC (permalink / raw)
To: barebox
This change contains several changes that make the code flow easier to
understand (in my eyes at least):
- Rename max_length to fststage_length
In some cases the image is loaded in two stages: First the PBL which
is started after the PBL is loaded completely and then the whole
image. So the size of the first stage isn't about some maximum.
- Drop unintuitive total_size variable
This variable used to be 0 in the one stage case and the filesize
otherwise. Just use fststage_length for the first stage and use the
filesize for the second stage (if needed).
- Don't call the first stage size "fsize" in the debug output.
- Add offset for second stage to debug output.
Signed-off-by: Uwe Kleine-König <u.kleine-koenig@pengutronix.de>
---
scripts/imx/imx-usb-loader.c | 37 ++++++++++++++++--------------------
1 file changed, 16 insertions(+), 21 deletions(-)
diff --git a/scripts/imx/imx-usb-loader.c b/scripts/imx/imx-usb-loader.c
index 96d36fa0a85e..3676f87abb3a 100644
--- a/scripts/imx/imx-usb-loader.c
+++ b/scripts/imx/imx-usb-loader.c
@@ -1213,7 +1213,7 @@ static int perform_dcd(unsigned char *p, const unsigned char *file_start,
}
static int get_dl_start(const unsigned char *p, const unsigned char *file_start,
- unsigned cnt, unsigned *max_length, unsigned *plugin,
+ unsigned cnt, size_t *fststage_length, unsigned *plugin,
unsigned *header_addr)
{
const unsigned char *file_end = file_start + cnt;
@@ -1228,7 +1228,7 @@ static int get_dl_start(const unsigned char *p, const unsigned char *file_start,
*header_addr = ohdr->dcd_ptr_ptr - offsetof(struct imx_flash_header, dcd);
*plugin = 0;
if (err >= 0)
- *max_length = dcd_end[0] | (dcd_end[1] << 8) | (dcd_end[2] << 16) | (dcd_end[3] << 24);
+ *fststage_length = dcd_end[0] | (dcd_end[1] << 8) | (dcd_end[2] << 16) | (dcd_end[3] << 24);
break;
}
@@ -1244,7 +1244,7 @@ static int get_dl_start(const unsigned char *p, const unsigned char *file_start,
return -1;
}
- *max_length = ((struct imx_boot_data *)bd)->size;
+ *fststage_length = ((struct imx_boot_data *)bd)->size;
*plugin = ((struct imx_boot_data *)bd)->plugin;
((struct imx_boot_data *)bd)->plugin = 0;
@@ -1271,7 +1271,7 @@ static int get_payload_start(const unsigned char *p, uint32_t *ofs)
}
static int process_header(struct usb_work *curr, unsigned char *buf, int cnt,
- unsigned *p_max_length, unsigned *p_plugin,
+ size_t *p_fststage_length, unsigned *p_plugin,
unsigned *p_header_addr)
{
int ret;
@@ -1286,7 +1286,7 @@ static int process_header(struct usb_work *curr, unsigned char *buf, int cnt,
if (!is_header(p))
continue;
- ret = get_dl_start(p, buf, cnt, p_max_length, p_plugin, p_header_addr);
+ ret = get_dl_start(p, buf, cnt, p_fststage_length, p_plugin, p_header_addr);
if (ret < 0) {
printf("!!get_dl_start returned %i\n", ret);
return ret;
@@ -1303,7 +1303,7 @@ static int process_header(struct usb_work *curr, unsigned char *buf, int cnt,
if (*p_plugin && (!curr->plug) && (!header_cnt)) {
header_cnt++;
- header_max = header_offset + *p_max_length + 0x400;
+ header_max = header_offset + *p_fststage_length + 0x400;
if (header_max > cnt - 32)
header_max = cnt - 32;
printf("header_max=%x\n", header_max);
@@ -1329,18 +1329,17 @@ static int do_irom_download(struct usb_work *curr, int verify)
unsigned char *buf = NULL;
unsigned char *image;
unsigned char *verify_buffer = NULL;
- unsigned max_length;
+ size_t fststage_length;
unsigned plugin = 0;
unsigned header_addr = 0;
- unsigned total_size = 0;
buf = read_file(curr->filename, &fsize);
if (!buf)
return -errno;
- max_length = fsize;
+ fststage_length = fsize;
- ret = process_header(curr, buf, fsize, &max_length, &plugin, &header_addr);
+ ret = process_header(curr, buf, fsize, &fststage_length, &plugin, &header_addr);
if (ret < 0)
goto cleanup;
@@ -1352,14 +1351,10 @@ static int do_irom_download(struct usb_work *curr, int verify)
goto cleanup;
}
+ /* skip over the imx-image-part */
image = buf + header_offset;
fsize -= header_offset;
- if (fsize > max_length) {
- total_size = fsize;
- fsize = max_length;
- }
-
type = FT_APP;
if (verify) {
@@ -1379,10 +1374,10 @@ static int do_irom_download(struct usb_work *curr, int verify)
}
}
- printf("loading binary file(%s) to 0x%08x, fsize=%zu type=%d...\n",
- curr->filename, header_addr, fsize, type);
+ printf("loading binary file(%s) to 0x%08x, fststage_length=%zu type=%d, hdroffset=%u...\n",
+ curr->filename, header_addr, fststage_length, type, header_offset);
- ret = load_file(image, fsize, header_addr, type, false);
+ ret = load_file(image, fststage_length, header_addr, type, false);
if (ret < 0)
goto cleanup;
@@ -1420,7 +1415,7 @@ static int do_irom_download(struct usb_work *curr, int verify)
return ret;
}
- if (total_size) {
+ if (fststage_length < fsize) {
uint32_t ofs;
ret = get_payload_start(image, &ofs);
@@ -1428,9 +1423,9 @@ static int do_irom_download(struct usb_work *curr, int verify)
printf("Cannot get offset of payload\n");
goto cleanup;
}
- printf("Loading full image\n");
+ printf("Loading full image from offset %u\n", ofs);
printf("Note: This needs board support on the other end\n");
- load_file(image + ofs, total_size - ofs, 0, 0, true);
+ load_file(image + ofs, fsize - ofs, 0, 0, true);
}
ret = 0;
base-commit: a91d44f25b0a279260d2c5710d7c8a7d7d0d1d78
--
2.30.2
^ permalink raw reply [flat|nested] 4+ messages in thread
* Re: [PATCH] scripts: imx-usb-loader: simplify code flow for file size calculations
2022-06-15 12:38 [PATCH] scripts: imx-usb-loader: simplify code flow for file size calculations Uwe Kleine-König
@ 2022-06-17 8:13 ` Sascha Hauer
2022-06-17 8:24 ` Uwe Kleine-König
0 siblings, 1 reply; 4+ messages in thread
From: Sascha Hauer @ 2022-06-17 8:13 UTC (permalink / raw)
To: Uwe Kleine-König; +Cc: barebox
On Wed, Jun 15, 2022 at 02:38:37PM +0200, Uwe Kleine-König wrote:
> This change contains several changes that make the code flow easier to
> understand (in my eyes at least):
>
> - Rename max_length to fststage_length
> In some cases the image is loaded in two stages: First the PBL which
> is started after the PBL is loaded completely and then the whole
> image. So the size of the first stage isn't about some maximum.
When not reading this note I think it's not clear that "fst" is an
abbreviation for "first". Can you rename to "firststage_length"?
If you care about variable name length then you could maybe rather
drop the last three letters ;)
Sascha
>
> - Drop unintuitive total_size variable
> This variable used to be 0 in the one stage case and the filesize
> otherwise. Just use fststage_length for the first stage and use the
> filesize for the second stage (if needed).
>
> - Don't call the first stage size "fsize" in the debug output.
>
> - Add offset for second stage to debug output.
>
> Signed-off-by: Uwe Kleine-König <u.kleine-koenig@pengutronix.de>
> ---
> scripts/imx/imx-usb-loader.c | 37 ++++++++++++++++--------------------
> 1 file changed, 16 insertions(+), 21 deletions(-)
>
> diff --git a/scripts/imx/imx-usb-loader.c b/scripts/imx/imx-usb-loader.c
> index 96d36fa0a85e..3676f87abb3a 100644
> --- a/scripts/imx/imx-usb-loader.c
> +++ b/scripts/imx/imx-usb-loader.c
> @@ -1213,7 +1213,7 @@ static int perform_dcd(unsigned char *p, const unsigned char *file_start,
> }
>
> static int get_dl_start(const unsigned char *p, const unsigned char *file_start,
> - unsigned cnt, unsigned *max_length, unsigned *plugin,
> + unsigned cnt, size_t *fststage_length, unsigned *plugin,
> unsigned *header_addr)
> {
> const unsigned char *file_end = file_start + cnt;
> @@ -1228,7 +1228,7 @@ static int get_dl_start(const unsigned char *p, const unsigned char *file_start,
> *header_addr = ohdr->dcd_ptr_ptr - offsetof(struct imx_flash_header, dcd);
> *plugin = 0;
> if (err >= 0)
> - *max_length = dcd_end[0] | (dcd_end[1] << 8) | (dcd_end[2] << 16) | (dcd_end[3] << 24);
> + *fststage_length = dcd_end[0] | (dcd_end[1] << 8) | (dcd_end[2] << 16) | (dcd_end[3] << 24);
>
> break;
> }
> @@ -1244,7 +1244,7 @@ static int get_dl_start(const unsigned char *p, const unsigned char *file_start,
> return -1;
> }
>
> - *max_length = ((struct imx_boot_data *)bd)->size;
> + *fststage_length = ((struct imx_boot_data *)bd)->size;
> *plugin = ((struct imx_boot_data *)bd)->plugin;
> ((struct imx_boot_data *)bd)->plugin = 0;
>
> @@ -1271,7 +1271,7 @@ static int get_payload_start(const unsigned char *p, uint32_t *ofs)
> }
>
> static int process_header(struct usb_work *curr, unsigned char *buf, int cnt,
> - unsigned *p_max_length, unsigned *p_plugin,
> + size_t *p_fststage_length, unsigned *p_plugin,
> unsigned *p_header_addr)
> {
> int ret;
> @@ -1286,7 +1286,7 @@ static int process_header(struct usb_work *curr, unsigned char *buf, int cnt,
> if (!is_header(p))
> continue;
>
> - ret = get_dl_start(p, buf, cnt, p_max_length, p_plugin, p_header_addr);
> + ret = get_dl_start(p, buf, cnt, p_fststage_length, p_plugin, p_header_addr);
> if (ret < 0) {
> printf("!!get_dl_start returned %i\n", ret);
> return ret;
> @@ -1303,7 +1303,7 @@ static int process_header(struct usb_work *curr, unsigned char *buf, int cnt,
>
> if (*p_plugin && (!curr->plug) && (!header_cnt)) {
> header_cnt++;
> - header_max = header_offset + *p_max_length + 0x400;
> + header_max = header_offset + *p_fststage_length + 0x400;
> if (header_max > cnt - 32)
> header_max = cnt - 32;
> printf("header_max=%x\n", header_max);
> @@ -1329,18 +1329,17 @@ static int do_irom_download(struct usb_work *curr, int verify)
> unsigned char *buf = NULL;
> unsigned char *image;
> unsigned char *verify_buffer = NULL;
> - unsigned max_length;
> + size_t fststage_length;
> unsigned plugin = 0;
> unsigned header_addr = 0;
> - unsigned total_size = 0;
>
> buf = read_file(curr->filename, &fsize);
> if (!buf)
> return -errno;
>
> - max_length = fsize;
> + fststage_length = fsize;
>
> - ret = process_header(curr, buf, fsize, &max_length, &plugin, &header_addr);
> + ret = process_header(curr, buf, fsize, &fststage_length, &plugin, &header_addr);
> if (ret < 0)
> goto cleanup;
>
> @@ -1352,14 +1351,10 @@ static int do_irom_download(struct usb_work *curr, int verify)
> goto cleanup;
> }
>
> + /* skip over the imx-image-part */
> image = buf + header_offset;
> fsize -= header_offset;
>
> - if (fsize > max_length) {
> - total_size = fsize;
> - fsize = max_length;
> - }
> -
> type = FT_APP;
>
> if (verify) {
> @@ -1379,10 +1374,10 @@ static int do_irom_download(struct usb_work *curr, int verify)
> }
> }
>
> - printf("loading binary file(%s) to 0x%08x, fsize=%zu type=%d...\n",
> - curr->filename, header_addr, fsize, type);
> + printf("loading binary file(%s) to 0x%08x, fststage_length=%zu type=%d, hdroffset=%u...\n",
> + curr->filename, header_addr, fststage_length, type, header_offset);
>
> - ret = load_file(image, fsize, header_addr, type, false);
> + ret = load_file(image, fststage_length, header_addr, type, false);
> if (ret < 0)
> goto cleanup;
>
> @@ -1420,7 +1415,7 @@ static int do_irom_download(struct usb_work *curr, int verify)
> return ret;
> }
>
> - if (total_size) {
> + if (fststage_length < fsize) {
> uint32_t ofs;
>
> ret = get_payload_start(image, &ofs);
> @@ -1428,9 +1423,9 @@ static int do_irom_download(struct usb_work *curr, int verify)
> printf("Cannot get offset of payload\n");
> goto cleanup;
> }
> - printf("Loading full image\n");
> + printf("Loading full image from offset %u\n", ofs);
> printf("Note: This needs board support on the other end\n");
> - load_file(image + ofs, total_size - ofs, 0, 0, true);
> + load_file(image + ofs, fsize - ofs, 0, 0, true);
> }
>
> ret = 0;
>
> base-commit: a91d44f25b0a279260d2c5710d7c8a7d7d0d1d78
> --
> 2.30.2
>
>
>
--
Pengutronix e.K. | |
Steuerwalder Str. 21 | http://www.pengutronix.de/ |
31137 Hildesheim, Germany | Phone: +49-5121-206917-0 |
Amtsgericht Hildesheim, HRA 2686 | Fax: +49-5121-206917-5555 |
^ permalink raw reply [flat|nested] 4+ messages in thread
* [PATCH] scripts: imx-usb-loader: simplify code flow for file size calculations
2022-06-17 8:13 ` Sascha Hauer
@ 2022-06-17 8:24 ` Uwe Kleine-König
2022-06-17 8:35 ` Sascha Hauer
0 siblings, 1 reply; 4+ messages in thread
From: Uwe Kleine-König @ 2022-06-17 8:24 UTC (permalink / raw)
To: barebox
This change contains several changes that make the code flow easier to
understand (in my eyes at least):
- Rename max_length to firststage_len
In some cases the image is loaded in two stages: First the PBL which
is started after the PBL is loaded completely and then the whole
image. So the size of the first stage isn't about some maximum.
- Drop unintuitive total_size variable
This variable used to be 0 in the one stage case and the filesize
otherwise. Just use firststage_len for the first stage and use the
filesize for the second stage (if needed).
- Don't call the first stage size "fsize" in the debug output.
- Add offset for second stage to debug output.
Signed-off-by: Uwe Kleine-König <u.kleine-koenig@pengutronix.de>
---
scripts/imx/imx-usb-loader.c | 37 ++++++++++++++++--------------------
1 file changed, 16 insertions(+), 21 deletions(-)
diff --git a/scripts/imx/imx-usb-loader.c b/scripts/imx/imx-usb-loader.c
index d8b284298920..4448b19b54bb 100644
--- a/scripts/imx/imx-usb-loader.c
+++ b/scripts/imx/imx-usb-loader.c
@@ -1218,7 +1218,7 @@ static int perform_dcd(unsigned char *p, const unsigned char *file_start,
}
static int get_dl_start(const unsigned char *p, const unsigned char *file_start,
- unsigned cnt, unsigned *max_length, unsigned *plugin,
+ unsigned cnt, size_t *firststage_len, unsigned *plugin,
unsigned *header_addr)
{
const unsigned char *file_end = file_start + cnt;
@@ -1233,7 +1233,7 @@ static int get_dl_start(const unsigned char *p, const unsigned char *file_start,
*header_addr = ohdr->dcd_ptr_ptr - offsetof(struct imx_flash_header, dcd);
*plugin = 0;
if (err >= 0)
- *max_length = dcd_end[0] | (dcd_end[1] << 8) | (dcd_end[2] << 16) | (dcd_end[3] << 24);
+ *firststage_len = dcd_end[0] | (dcd_end[1] << 8) | (dcd_end[2] << 16) | (dcd_end[3] << 24);
break;
}
@@ -1249,7 +1249,7 @@ static int get_dl_start(const unsigned char *p, const unsigned char *file_start,
return -1;
}
- *max_length = ((struct imx_boot_data *)bd)->size;
+ *firststage_len = ((struct imx_boot_data *)bd)->size;
*plugin = ((struct imx_boot_data *)bd)->plugin;
((struct imx_boot_data *)bd)->plugin = 0;
@@ -1276,7 +1276,7 @@ static int get_payload_start(const unsigned char *p, uint32_t *ofs)
}
static int process_header(struct usb_work *curr, unsigned char *buf, int cnt,
- unsigned *p_max_length, unsigned *p_plugin,
+ size_t *p_firststage_len, unsigned *p_plugin,
unsigned *p_header_addr)
{
int ret;
@@ -1291,7 +1291,7 @@ static int process_header(struct usb_work *curr, unsigned char *buf, int cnt,
if (!is_header(p))
continue;
- ret = get_dl_start(p, buf, cnt, p_max_length, p_plugin, p_header_addr);
+ ret = get_dl_start(p, buf, cnt, p_firststage_len, p_plugin, p_header_addr);
if (ret < 0) {
printf("!!get_dl_start returned %i\n", ret);
return ret;
@@ -1308,7 +1308,7 @@ static int process_header(struct usb_work *curr, unsigned char *buf, int cnt,
if (*p_plugin && (!curr->plug) && (!header_cnt)) {
header_cnt++;
- header_max = header_offset + *p_max_length + 0x400;
+ header_max = header_offset + *p_firststage_len + 0x400;
if (header_max > cnt - 32)
header_max = cnt - 32;
printf("header_max=%x\n", header_max);
@@ -1334,18 +1334,17 @@ static int do_irom_download(struct usb_work *curr, int verify)
unsigned char *buf = NULL;
unsigned char *image;
unsigned char *verify_buffer = NULL;
- unsigned max_length;
+ size_t firststage_len;
unsigned plugin = 0;
unsigned header_addr = 0;
- unsigned total_size = 0;
buf = read_file(curr->filename, &fsize);
if (!buf)
return -errno;
- max_length = fsize;
+ firststage_len = fsize;
- ret = process_header(curr, buf, fsize, &max_length, &plugin, &header_addr);
+ ret = process_header(curr, buf, fsize, &firststage_len, &plugin, &header_addr);
if (ret < 0)
goto cleanup;
@@ -1357,14 +1356,10 @@ static int do_irom_download(struct usb_work *curr, int verify)
goto cleanup;
}
+ /* skip over the imx-image-part */
image = buf + header_offset;
fsize -= header_offset;
- if (fsize > max_length) {
- total_size = fsize;
- fsize = max_length;
- }
-
type = FT_APP;
if (verify) {
@@ -1384,10 +1379,10 @@ static int do_irom_download(struct usb_work *curr, int verify)
}
}
- printf("loading binary file(%s) to 0x%08x, fsize=%zu type=%d...\n",
- curr->filename, header_addr, fsize, type);
+ printf("loading binary file(%s) to 0x%08x, firststage_len=%zu type=%d, hdroffset=%u...\n",
+ curr->filename, header_addr, firststage_len, type, header_offset);
- ret = load_file(image, fsize, header_addr, type, false);
+ ret = load_file(image, firststage_len, header_addr, type, false);
if (ret < 0)
goto cleanup;
@@ -1425,7 +1420,7 @@ static int do_irom_download(struct usb_work *curr, int verify)
return ret;
}
- if (total_size) {
+ if (firststage_len < fsize) {
uint32_t ofs;
ret = get_payload_start(image, &ofs);
@@ -1433,9 +1428,9 @@ static int do_irom_download(struct usb_work *curr, int verify)
printf("Cannot get offset of payload\n");
goto cleanup;
}
- printf("Loading full image\n");
+ printf("Loading full image from offset %u\n", ofs);
printf("Note: This needs board support on the other end\n");
- load_file(image + ofs, total_size - ofs, 0, 0, true);
+ load_file(image + ofs, fsize - ofs, 0, 0, true);
}
ret = 0;
base-commit: 339737fcf0a7c4be1d1984283619cb14aaee6aff
--
2.36.1
^ permalink raw reply [flat|nested] 4+ messages in thread
* Re: [PATCH] scripts: imx-usb-loader: simplify code flow for file size calculations
2022-06-17 8:24 ` Uwe Kleine-König
@ 2022-06-17 8:35 ` Sascha Hauer
0 siblings, 0 replies; 4+ messages in thread
From: Sascha Hauer @ 2022-06-17 8:35 UTC (permalink / raw)
To: Uwe Kleine-König; +Cc: barebox
On Fri, Jun 17, 2022 at 10:24:14AM +0200, Uwe Kleine-König wrote:
> This change contains several changes that make the code flow easier to
> understand (in my eyes at least):
>
> - Rename max_length to firststage_len
> In some cases the image is loaded in two stages: First the PBL which
> is started after the PBL is loaded completely and then the whole
> image. So the size of the first stage isn't about some maximum.
>
> - Drop unintuitive total_size variable
> This variable used to be 0 in the one stage case and the filesize
> otherwise. Just use firststage_len for the first stage and use the
> filesize for the second stage (if needed).
>
> - Don't call the first stage size "fsize" in the debug output.
>
> - Add offset for second stage to debug output.
>
> Signed-off-by: Uwe Kleine-König <u.kleine-koenig@pengutronix.de>
> ---
> scripts/imx/imx-usb-loader.c | 37 ++++++++++++++++--------------------
> 1 file changed, 16 insertions(+), 21 deletions(-)
Applied, thanks
Sascha
>
> diff --git a/scripts/imx/imx-usb-loader.c b/scripts/imx/imx-usb-loader.c
> index d8b284298920..4448b19b54bb 100644
> --- a/scripts/imx/imx-usb-loader.c
> +++ b/scripts/imx/imx-usb-loader.c
> @@ -1218,7 +1218,7 @@ static int perform_dcd(unsigned char *p, const unsigned char *file_start,
> }
>
> static int get_dl_start(const unsigned char *p, const unsigned char *file_start,
> - unsigned cnt, unsigned *max_length, unsigned *plugin,
> + unsigned cnt, size_t *firststage_len, unsigned *plugin,
> unsigned *header_addr)
> {
> const unsigned char *file_end = file_start + cnt;
> @@ -1233,7 +1233,7 @@ static int get_dl_start(const unsigned char *p, const unsigned char *file_start,
> *header_addr = ohdr->dcd_ptr_ptr - offsetof(struct imx_flash_header, dcd);
> *plugin = 0;
> if (err >= 0)
> - *max_length = dcd_end[0] | (dcd_end[1] << 8) | (dcd_end[2] << 16) | (dcd_end[3] << 24);
> + *firststage_len = dcd_end[0] | (dcd_end[1] << 8) | (dcd_end[2] << 16) | (dcd_end[3] << 24);
>
> break;
> }
> @@ -1249,7 +1249,7 @@ static int get_dl_start(const unsigned char *p, const unsigned char *file_start,
> return -1;
> }
>
> - *max_length = ((struct imx_boot_data *)bd)->size;
> + *firststage_len = ((struct imx_boot_data *)bd)->size;
> *plugin = ((struct imx_boot_data *)bd)->plugin;
> ((struct imx_boot_data *)bd)->plugin = 0;
>
> @@ -1276,7 +1276,7 @@ static int get_payload_start(const unsigned char *p, uint32_t *ofs)
> }
>
> static int process_header(struct usb_work *curr, unsigned char *buf, int cnt,
> - unsigned *p_max_length, unsigned *p_plugin,
> + size_t *p_firststage_len, unsigned *p_plugin,
> unsigned *p_header_addr)
> {
> int ret;
> @@ -1291,7 +1291,7 @@ static int process_header(struct usb_work *curr, unsigned char *buf, int cnt,
> if (!is_header(p))
> continue;
>
> - ret = get_dl_start(p, buf, cnt, p_max_length, p_plugin, p_header_addr);
> + ret = get_dl_start(p, buf, cnt, p_firststage_len, p_plugin, p_header_addr);
> if (ret < 0) {
> printf("!!get_dl_start returned %i\n", ret);
> return ret;
> @@ -1308,7 +1308,7 @@ static int process_header(struct usb_work *curr, unsigned char *buf, int cnt,
>
> if (*p_plugin && (!curr->plug) && (!header_cnt)) {
> header_cnt++;
> - header_max = header_offset + *p_max_length + 0x400;
> + header_max = header_offset + *p_firststage_len + 0x400;
> if (header_max > cnt - 32)
> header_max = cnt - 32;
> printf("header_max=%x\n", header_max);
> @@ -1334,18 +1334,17 @@ static int do_irom_download(struct usb_work *curr, int verify)
> unsigned char *buf = NULL;
> unsigned char *image;
> unsigned char *verify_buffer = NULL;
> - unsigned max_length;
> + size_t firststage_len;
> unsigned plugin = 0;
> unsigned header_addr = 0;
> - unsigned total_size = 0;
>
> buf = read_file(curr->filename, &fsize);
> if (!buf)
> return -errno;
>
> - max_length = fsize;
> + firststage_len = fsize;
>
> - ret = process_header(curr, buf, fsize, &max_length, &plugin, &header_addr);
> + ret = process_header(curr, buf, fsize, &firststage_len, &plugin, &header_addr);
> if (ret < 0)
> goto cleanup;
>
> @@ -1357,14 +1356,10 @@ static int do_irom_download(struct usb_work *curr, int verify)
> goto cleanup;
> }
>
> + /* skip over the imx-image-part */
> image = buf + header_offset;
> fsize -= header_offset;
>
> - if (fsize > max_length) {
> - total_size = fsize;
> - fsize = max_length;
> - }
> -
> type = FT_APP;
>
> if (verify) {
> @@ -1384,10 +1379,10 @@ static int do_irom_download(struct usb_work *curr, int verify)
> }
> }
>
> - printf("loading binary file(%s) to 0x%08x, fsize=%zu type=%d...\n",
> - curr->filename, header_addr, fsize, type);
> + printf("loading binary file(%s) to 0x%08x, firststage_len=%zu type=%d, hdroffset=%u...\n",
> + curr->filename, header_addr, firststage_len, type, header_offset);
>
> - ret = load_file(image, fsize, header_addr, type, false);
> + ret = load_file(image, firststage_len, header_addr, type, false);
> if (ret < 0)
> goto cleanup;
>
> @@ -1425,7 +1420,7 @@ static int do_irom_download(struct usb_work *curr, int verify)
> return ret;
> }
>
> - if (total_size) {
> + if (firststage_len < fsize) {
> uint32_t ofs;
>
> ret = get_payload_start(image, &ofs);
> @@ -1433,9 +1428,9 @@ static int do_irom_download(struct usb_work *curr, int verify)
> printf("Cannot get offset of payload\n");
> goto cleanup;
> }
> - printf("Loading full image\n");
> + printf("Loading full image from offset %u\n", ofs);
> printf("Note: This needs board support on the other end\n");
> - load_file(image + ofs, total_size - ofs, 0, 0, true);
> + load_file(image + ofs, fsize - ofs, 0, 0, true);
> }
>
> ret = 0;
>
> base-commit: 339737fcf0a7c4be1d1984283619cb14aaee6aff
> --
> 2.36.1
>
>
>
--
Pengutronix e.K. | |
Steuerwalder Str. 21 | http://www.pengutronix.de/ |
31137 Hildesheim, Germany | Phone: +49-5121-206917-0 |
Amtsgericht Hildesheim, HRA 2686 | Fax: +49-5121-206917-5555 |
^ permalink raw reply [flat|nested] 4+ messages in thread
end of thread, other threads:[~2022-06-17 8:36 UTC | newest]
Thread overview: 4+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2022-06-15 12:38 [PATCH] scripts: imx-usb-loader: simplify code flow for file size calculations Uwe Kleine-König
2022-06-17 8:13 ` Sascha Hauer
2022-06-17 8:24 ` Uwe Kleine-König
2022-06-17 8:35 ` Sascha Hauer
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox