From: Timur Tabi <timur@freescale.com>
To: u-boot@lists.denx.de
Subject: [U-Boot-Users] [PATCH] Fix initrd length miscalculation in bootm command
Date: Mon, 5 Feb 2007 13:39:39 -0600 [thread overview]
Message-ID: <11707043793601-git-send-email-timur@freescale.com> (raw)
The do_bootm_linux() function was using the same variable ('len') to calculate
the the dtu length and the initrd length, which meant that the initrd length
was incorrect. This patch creates renames 'len' and 'data' to 'initrd_len'
and 'initrd_data', thereby preventing any future confusion. It also deletes
'len' and 'data' because the dtu calculations don't actually need them.
Signed-off-by: Timur Tabi <timur@freescale.com>
---
common/cmd_bootm.c | 57 +++++++++++++++++++++++----------------------------
1 files changed, 26 insertions(+), 31 deletions(-)
diff --git a/common/cmd_bootm.c b/common/cmd_bootm.c
index 7aae8a6..0c092c7 100644
--- a/common/cmd_bootm.c
+++ b/common/cmd_bootm.c
@@ -518,11 +518,10 @@ do_bootm_linux (cmd_tbl_t *cmdtp, int fl
int verify)
{
ulong sp;
- ulong len, checksum;
- ulong initrd_start, initrd_end;
+ ulong checksum;
+ ulong initrd_start, initrd_end, initrd_data, initrd_len;
ulong cmd_start, cmd_end;
ulong initrd_high;
- ulong data;
int initrd_copy_to_ram = 1;
char *cmdline;
char *s;
@@ -626,7 +625,7 @@ do_bootm_linux (cmd_tbl_t *cmdtp, int fl
/* Look for a '-' which indicates to ignore the ramdisk argument */
if (argc >= 3 && strcmp(argv[2], "-") == 0) {
debug ("Skipping initrd\n");
- len = data = 0;
+ initrd_len = initrd_data = 0;
}
else
#endif
@@ -647,13 +646,10 @@ do_bootm_linux (cmd_tbl_t *cmdtp, int fl
do_reset (cmdtp, flag, argc, argv);
}
- data = (ulong)&header;
- len = sizeof(image_header_t);
-
checksum = ntohl(hdr->ih_hcrc);
hdr->ih_hcrc = 0;
- if (crc32 (0, (uchar *)data, len) != checksum) {
+ if (crc32 (0, (uchar *) &header, sizeof(image_header_t)) != checksum) {
puts ("Bad Header Checksum\n");
SHOW_BOOT_PROGRESS (-11);
do_reset (cmdtp, flag, argc, argv);
@@ -663,13 +659,13 @@ do_bootm_linux (cmd_tbl_t *cmdtp, int fl
print_image_hdr (hdr);
- data = addr + sizeof(image_header_t);
- len = ntohl(hdr->ih_size);
+ initrd_data = addr + sizeof(image_header_t);
+ initrd_len = ntohl(hdr->ih_size);
if (verify) {
ulong csum = 0;
#if defined(CONFIG_HW_WATCHDOG) || defined(CONFIG_WATCHDOG)
- ulong cdata = data, edata = cdata + len;
+ ulong cdata = initrd_data, edata = cdata + initrd_len;
#endif /* CONFIG_HW_WATCHDOG || CONFIG_WATCHDOG */
puts (" Verifying Checksum ... ");
@@ -687,7 +683,7 @@ do_bootm_linux (cmd_tbl_t *cmdtp, int fl
WATCHDOG_RESET();
}
#else /* !(CONFIG_HW_WATCHDOG || CONFIG_WATCHDOG) */
- csum = crc32 (0, (uchar *)data, len);
+ csum = crc32 (0, (uchar *) initrd_data, initrd_len);
#endif /* CONFIG_HW_WATCHDOG || CONFIG_WATCHDOG */
if (csum != ntohl(hdr->ih_dcrc)) {
@@ -718,17 +714,17 @@ do_bootm_linux (cmd_tbl_t *cmdtp, int fl
SHOW_BOOT_PROGRESS (13);
/* skip kernel length and terminator */
- data = (ulong)(&len_ptr[2]);
+ initrd_data = (ulong)(&len_ptr[2]);
/* skip any additional image length fields */
for (i=1; len_ptr[i]; ++i)
- data += 4;
+ initrd_data += 4;
/* add kernel length, and align */
- data += ntohl(len_ptr[0]);
+ initrd_data += ntohl(len_ptr[0]);
if (tail) {
- data += 4 - tail;
+ initrd_data += 4 - tail;
}
- len = ntohl(len_ptr[1]);
+ initrd_len = ntohl(len_ptr[1]);
} else {
/*
@@ -736,7 +732,7 @@ do_bootm_linux (cmd_tbl_t *cmdtp, int fl
*/
SHOW_BOOT_PROGRESS (14);
- len = data = 0;
+ initrd_len = initrd_data = 0;
}
#ifdef CONFIG_OF_FLAT_TREE
@@ -771,9 +767,8 @@ do_bootm_linux (cmd_tbl_t *cmdtp, int fl
checksum = ntohl(hdr->ih_dcrc);
addr = (ulong)((uchar *)(hdr) + sizeof(image_header_t));
- len = ntohl(hdr->ih_size);
- if(checksum != crc32(0, (uchar *)addr, len)) {
+ if(checksum != crc32(0, (uchar *)addr, ntohl(hdr->ih_size))) {
printf("ERROR: Flat Device Tree checksum is invalid\n");
return;
}
@@ -835,16 +830,16 @@ do_bootm_linux (cmd_tbl_t *cmdtp, int fl
}
}
#endif
- if (!data) {
+ if (!initrd_data) {
debug ("No initrd\n");
}
- if (data) {
+ if (initrd_data) {
if (!initrd_copy_to_ram) { /* zero-copy ramdisk support */
- initrd_start = data;
- initrd_end = initrd_start + len;
+ initrd_start = initrd_data;
+ initrd_end = initrd_start + initrd_len;
} else {
- initrd_start = (ulong)kbd - len;
+ initrd_start = (ulong)kbd - initrd_len;
initrd_start &= ~(4096 - 1); /* align on page */
if (initrd_high) {
@@ -865,7 +860,7 @@ do_bootm_linux (cmd_tbl_t *cmdtp, int fl
nsp &= ~0xF;
if (nsp > initrd_high) /* limit as specified */
nsp = initrd_high;
- nsp -= len;
+ nsp -= initrd_len;
nsp &= ~(4096 - 1); /* align on page */
if (nsp >= sp)
initrd_start = nsp;
@@ -874,16 +869,16 @@ do_bootm_linux (cmd_tbl_t *cmdtp, int fl
SHOW_BOOT_PROGRESS (12);
debug ("## initrd at 0x%08lX ... 0x%08lX (len=%ld=0x%lX)\n",
- data, data + len - 1, len, len);
+ initrd_data, initrd_data + initrd_len - 1, initrd_len, initrd_len);
- initrd_end = initrd_start + len;
+ initrd_end = initrd_start + initrd_len;
printf (" Loading Ramdisk to %08lx, end %08lx ... ",
initrd_start, initrd_end);
#if defined(CONFIG_HW_WATCHDOG) || defined(CONFIG_WATCHDOG)
{
- size_t l = len;
+ size_t l = initrd_len;
void *to = (void *)initrd_start;
- void *from = (void *)data;
+ void *from = (void *)initrd_data;
while (l > 0) {
size_t tail = (l > CHUNKSZ) ? CHUNKSZ : l;
@@ -895,7 +890,7 @@ do_bootm_linux (cmd_tbl_t *cmdtp, int fl
}
}
#else /* !(CONFIG_HW_WATCHDOG || CONFIG_WATCHDOG) */
- memmove ((void *)initrd_start, (void *)data, len);
+ memmove ((void *)initrd_start, (void *)initrd_data, initrd_len);
#endif /* CONFIG_HW_WATCHDOG || CONFIG_WATCHDOG */
puts ("OK\n");
}
--
1.4.4
next reply other threads:[~2007-02-05 19:39 UTC|newest]
Thread overview: 22+ messages / expand[flat|nested] mbox.gz Atom feed top
2007-02-05 19:39 Timur Tabi [this message]
2007-02-06 0:43 ` [U-Boot-Users] [PATCH] Fix initrd length miscalculation in bootm command Wolfgang Denk
2007-02-06 15:11 ` Timur Tabi
2007-02-06 17:07 ` Kumar Gala
2007-02-06 17:11 ` Timur Tabi
2007-02-06 17:14 ` Kumar Gala
2007-02-06 17:17 ` Timur Tabi
2007-02-19 23:51 ` Timur Tabi
2007-02-20 16:14 ` Kumar Gala
2007-02-20 16:36 ` Timur Tabi
2007-02-20 19:06 ` Wolfgang Denk
2007-02-20 19:19 ` Timur Tabi
2007-02-20 23:05 ` Timur Tabi
2007-02-26 13:10 ` Wolfgang Denk
2007-02-26 16:15 ` Timur Tabi
2007-02-27 16:48 ` Timur Tabi
2007-02-27 20:55 ` Wolfgang Denk
2007-02-27 22:13 ` Timur Tabi
2007-03-16 21:49 ` Timur Tabi
2007-03-23 22:44 ` Johns Daniel
2007-03-27 16:25 ` Johns Daniel
2007-03-27 16:30 ` Timur Tabi
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=11707043793601-git-send-email-timur@freescale.com \
--to=timur@freescale.com \
--cc=u-boot@lists.denx.de \
/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