* [U-Boot-Users] [PATCH v2] Fix initrd length miscalculation in bootm command
@ 2007-05-03 15:09 Timur Tabi
0 siblings, 0 replies; only message in thread
From: Timur Tabi @ 2007-05-03 15:09 UTC (permalink / raw)
To: u-boot
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>
---
This an updated version of patch that was originally submitted on Feb 5, 2007,
because the libfdt code breaks the previous patch. Wolfgang, will you *please*
apply this fix?!?!!?! I don't want to have to refactor and retest this patch
in 6 weeks because you haven't applied it.
common/cmd_bootm.c | 60 ++++++++++++++++++++++++---------------------------
1 files changed, 28 insertions(+), 32 deletions(-)
diff --git a/common/cmd_bootm.c b/common/cmd_bootm.c
index 32c29e5..a21df7d 100644
--- a/common/cmd_bootm.c
+++ b/common/cmd_bootm.c
@@ -523,11 +523,10 @@ do_bootm_linux (cmd_tbl_t *cmdtp, int flag,
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;
@@ -631,7 +630,7 @@ do_bootm_linux (cmd_tbl_t *cmdtp, int flag,
/* 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
@@ -652,13 +651,10 @@ do_bootm_linux (cmd_tbl_t *cmdtp, int flag,
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);
@@ -668,13 +664,13 @@ do_bootm_linux (cmd_tbl_t *cmdtp, int flag,
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 ... ");
@@ -692,7 +688,7 @@ do_bootm_linux (cmd_tbl_t *cmdtp, int flag,
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)) {
@@ -723,17 +719,17 @@ do_bootm_linux (cmd_tbl_t *cmdtp, int flag,
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 {
/*
@@ -741,7 +737,7 @@ do_bootm_linux (cmd_tbl_t *cmdtp, int flag,
*/
SHOW_BOOT_PROGRESS (14);
- len = data = 0;
+ initrd_len = initrd_data = 0;
}
#if defined(CONFIG_OF_FLAT_TREE) || defined(CONFIG_OF_LIBFDT)
@@ -779,9 +775,8 @@ do_bootm_linux (cmd_tbl_t *cmdtp, int flag,
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;
}
@@ -855,16 +850,17 @@ do_bootm_linux (cmd_tbl_t *cmdtp, int flag,
}
}
#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) {
@@ -885,7 +881,7 @@ do_bootm_linux (cmd_tbl_t *cmdtp, int flag,
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;
@@ -894,16 +890,16 @@ do_bootm_linux (cmd_tbl_t *cmdtp, int flag,
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;
@@ -915,7 +911,7 @@ do_bootm_linux (cmd_tbl_t *cmdtp, int flag,
}
}
#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");
}
@@ -952,7 +948,7 @@ do_bootm_linux (cmd_tbl_t *cmdtp, int flag,
of_flat_tree = (char *)of_start;
printf (" Loading Device Tree to %08lx, end %08lx ... ",
of_start, of_start + of_len - 1);
- err = fdt_open_into((void *)of_start, (void *)of_data, of_len);
+ err = fdt_open_into((void *)of_data, (void *)of_start, of_len);
if (err != 0) {
printf ("libfdt: %s " __FILE__ " %d\n", fdt_strerror(err), __LINE__);
}
--
1.5.0.2.260.g2eb065
^ permalink raw reply related [flat|nested] only message in thread
only message in thread, other threads:[~2007-05-03 15:09 UTC | newest]
Thread overview: (only message) (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2007-05-03 15:09 [U-Boot-Users] [PATCH v2] Fix initrd length miscalculation in bootm command Timur Tabi
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox