[U-Boot-Users] [PATCH] Fix initrd length miscalculation in bootm command
Timur Tabi
timur at freescale.com
Mon Feb 5 20:39:39 CET 2007
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 at 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
More information about the U-Boot
mailing list