[U-Boot-Users] [PATCH 0/6] [new uImage] patchset3 - legacy code refactoring

This is the third patch-set of the new uImage format work. It concludes the phase of clean-up and reorganization of the old format code, preparing the ground for adding the code implementing the new format.
All the new uImage patches sent to the list so far, as well as updates resulting from the feedback received, will be soon available from the new-image branch of the u-boot-testing repository (there will be a separate announcement).
The completion of the clean-up phase is a good moment to review the patches posted to date, and help with testing. This work affects all architectures and operating systems, so it would be much appreciated if people could give u-boot-testing#new-image a try and report back. So far, the changes were tested on a lite5200b board and successfully built for ppc, arm, mips and coldfire targets.
Work is now ongoing on adding support for the new format, results will be posted to the list, and also available from u-boot-testing#new-image. Once the implementation is complete, and the code is reviewed and tested, it will be merged to the master.
Marian Balakowicz (6): [new uImage] Move kernel data find code to get_kernel() routine [new uImage] Cleanup FDT handling in PPC do_boot_linux() [new uImage] Cleanup PPC and M68K do_bootm_linux() boot allocations [new uImage] Move PPC and M68K ramdisk loading to a common routine [new uImage] Removed dead ramdisk code on microblaze architecture [new uImage] Factor out common image_get_ramdisk() routine
Cheers, m.

Architecture specific do_bootm_linux() routines share common ramdisk image processing code. Move this code to a common helper routine.
Signed-off-by: Marian Balakowicz m8@semihalf.com ---
common/image.c | 203 +++++++++++++++++++++++++++++++++++++++++++++++- include/image.h | 10 ++ lib_arm/bootm.c | 114 --------------------------- lib_avr32/bootm.c | 72 ----------------- lib_i386/bootm.c | 76 +----------------- lib_m68k/bootm.c | 89 ++------------------- lib_microblaze/bootm.c | 85 -------------------- lib_mips/bootm.c | 84 -------------------- lib_ppc/bootm.c | 94 ++-------------------- 9 files changed, 239 insertions(+), 588 deletions(-)
diff --git a/common/image.c b/common/image.c index 6726f03..e4be4ca 100644 --- a/common/image.c +++ b/common/image.c @@ -23,10 +23,20 @@ * MA 02111-1307 USA */ #ifndef USE_HOSTCC -# include <common.h> -# include <watchdog.h> +#include <common.h> +#include <watchdog.h> + +#ifdef CONFIG_SHOW_BOOT_PROGRESS +#include <status_led.h> +#endif + +#ifdef CONFIG_HAS_DATAFLASH +#include <dataflash.h> +#endif + +extern int do_reset (cmd_tbl_t *cmdtp, int flag, int argc, char *argv[]); #else -# include "mkimage.h" +#include "mkimage.h" #endif
#include <image.h> @@ -280,4 +290,191 @@ const char* image_get_comp_name (uint8_t comp)
return name; } + +/** + * image_get_ramdisk - get and verify ramdisk image + * @cmdtp: command table pointer + * @flag: command flag + * @argc: command argument count + * @argv: command argument list + * @rd_addr: ramdisk image start address + * @arch: expected ramdisk architecture + * @verify: checksum verification flag + * + * image_get_ramdisk() returns a pointer to the verified ramdisk image + * header. Routine receives image start address and expected architecture + * flag. Verification done covers data and header integrity and os/type/arch + * fields checking. + * + * If dataflash support is enabled routine checks for dataflash addresses + * and handles required dataflash reads. + * + * returns: + * pointer to a ramdisk image header, if image was found and valid + * otherwise, board is reset + */ +image_header_t* image_get_ramdisk (cmd_tbl_t *cmdtp, int flag, + int argc, char *argv[], + ulong rd_addr, uint8_t arch, int verify) +{ + image_header_t *rd_hdr; + + show_boot_progress (9); + +#ifdef CONFIG_HAS_DATAFLASH + if (addr_dataflash (rd_addr)) { + rd_hdr = (image_header_t *)CFG_LOAD_ADDR; + debug (" Reading Ramdisk image header from dataflash address " + "%08lx to %08lx\n", rd_addr, (ulong)rd_hdr); + read_dataflash (rd_addr, image_get_header_size (), + (char *)rd_hdr); + } else +#endif + rd_hdr = (image_header_t *)rd_addr; + + if (!image_check_magic (rd_hdr)) { + puts ("Bad Magic Number\n"); + show_boot_progress (-10); + do_reset (cmdtp, flag, argc, argv); + } + + if (!image_check_hcrc (rd_hdr)) { + puts ("Bad Header Checksum\n"); + show_boot_progress (-11); + do_reset (cmdtp, flag, argc, argv); + } + + show_boot_progress (10); + print_image_hdr (rd_hdr); + +#ifdef CONFIG_HAS_DATAFLASH + if (addr_dataflash (rd_addr)) { + debug (" Reading Ramdisk image data from dataflash address " + "%08lx to %08lx\n", rd_addr + image_get_header_size, + (ulong)image_get_data (rd_hdr)); + + read_dataflash (rd_addr + image_get_header_size (), + image_get_data_size (rd_hdr), + (char *)image_get_data (rd_hdr)); + } #endif + + if (verify) { + puts(" Verifying Checksum ... "); + if (!image_check_dcrc_wd (rd_hdr, CHUNKSZ)) { + puts ("Bad Data CRC\n"); + show_boot_progress (-12); + do_reset (cmdtp, flag, argc, argv); + } + puts("OK\n"); + } + + show_boot_progress (11); + + if (!image_check_os (rd_hdr, IH_OS_LINUX) || + !image_check_arch (rd_hdr, arch) || + !image_check_type (rd_hdr, IH_TYPE_RAMDISK)) { + printf ("No Linux %s Ramdisk Image\n", + image_get_arch_name(arch)); + show_boot_progress (-13); + do_reset (cmdtp, flag, argc, argv); + } + + return rd_hdr; +} + +/** + * get_ramdisk - main ramdisk handling routine + * @cmdtp: command table pointer + * @flag: command flag + * @argc: command argument count + * @argv: command argument list + * @hdr: pointer to the posiibly multi componet kernel image + * @verify: checksum verification flag + * @arch: expected ramdisk architecture + * @rd_start: pointer to a ulong variable, will hold ramdisk start address + * @rd_end: pointer to a ulong variable, will hold ramdisk end + * + * get_ramdisk() is responsible for finding a valid ramdisk image. + * Curently supported are the following ramdisk sources: + * - multicomponent kernel/ramdisk image, + * - commandline provided address of decicated ramdisk image. + * + * returns: + * rd_start and rd_end are set to ramdisk start/end addresses if + * ramdisk image is found and valid + * rd_start and rd_end are set to 0 if no ramdisk exists + * board is reset if ramdisk image is found but corrupted + */ +void get_ramdisk (cmd_tbl_t *cmdtp, int flag, int argc, char *argv[], + image_header_t *hdr, int verify, uint8_t arch, + ulong *rd_start, ulong *rd_end) +{ + ulong rd_addr; + ulong rd_data, rd_len; + image_header_t *rd_hdr; + + if (argc >= 3) { + /* + * Look for a '-' which indicates to ignore the + * ramdisk argument + */ + if (strcmp(argv[2], "-") == 0) { + debug ("## Skipping init Ramdisk\n"); + rd_len = rd_data = 0; + } else { + /* + * Check if there is an initrd image at the + * address provided in the second bootm argument + */ + rd_addr = simple_strtoul (argv[2], NULL, 16); + printf ("## Loading init Ramdisk Image at %08lx ...\n", + rd_addr); + + rd_hdr = image_get_ramdisk (cmdtp, flag, argc, argv, + rd_addr, arch, verify); + + rd_data = image_get_data (rd_hdr); + rd_len = image_get_data_size (rd_hdr); + +#if defined(CONFIG_B2) || defined(CONFIG_EVB4510) || defined(CONFIG_ARMADILLO) + /* + *we need to copy the ramdisk to SRAM to let Linux boot + */ + memmove ((void *)image_get_load (rd_hdr), + (uchar *)rd_data, rd_len); + + rd_data = image_get_load (rd_hdr); +#endif /* CONFIG_B2 || CONFIG_EVB4510 || CONFIG_ARMADILLO */ + } + + } else if (image_check_type (hdr, IH_TYPE_MULTI)) { + /* + * Now check if we have a multifile image + * Get second entry data start address and len + */ + show_boot_progress (13); + printf ("## Loading init Ramdisk from multi component " + "Image at %08lx ...\n", (ulong)hdr); + image_multi_getimg (hdr, 1, &rd_data, &rd_len); + } else { + /* + * no initrd image + */ + show_boot_progress (14); + rd_len = rd_data = 0; + } + + if (!rd_data) { + debug ("## No init Ramdisk\n"); + *rd_start = 0; + *rd_end = 0; + } else { + *rd_start = rd_data; + *rd_end = rd_data + rd_len; + } + debug (" ramdisk start = 0x%08lx, ramdisk end = 0x%08lx\n", + *rd_start, *rd_end); +} +#endif /* USE_HOSTCC */ + diff --git a/include/image.h b/include/image.h index 9ac25c9..b438564 100644 --- a/include/image.h +++ b/include/image.h @@ -34,6 +34,7 @@ #define __IMAGE_H__
#include <asm/byteorder.h> +#include <command.h> #ifndef USE_HOSTCC #include <linux/string.h> #endif @@ -331,6 +332,15 @@ const char* image_get_os_name (uint8_t os); const char* image_get_arch_name (uint8_t arch); const char* image_get_type_name (uint8_t type); const char* image_get_comp_name (uint8_t comp); + +image_header_t* image_get_ramdisk (cmd_tbl_t *cmdtp, int flag, + int argc, char *argv[], + ulong rd_addr, uint8_t arch, int verify); + +void get_ramdisk (cmd_tbl_t *cmdtp, int flag, int argc, char *argv[], + image_header_t *hdr, int verify, uint8_t arch, + ulong *rd_start, ulong *rd_end); #endif /* USE_HOSTCCa */
+ #endif /* __IMAGE_H__ */ diff --git a/lib_arm/bootm.c b/lib_arm/bootm.c index 4f9aae6..529b097 100644 --- a/lib_arm/bootm.c +++ b/lib_arm/bootm.c @@ -26,15 +26,9 @@ #include <image.h> #include <zlib.h> #include <asm/byteorder.h> -#ifdef CONFIG_HAS_DATAFLASH -#include <dataflash.h> -#endif
DECLARE_GLOBAL_DATA_PTR;
-/*cmd_boot.c*/ -extern int do_reset (cmd_tbl_t *cmdtp, int flag, int argc, char *argv[]); - #if defined (CONFIG_SETUP_MEMORY_TAGS) || \ defined (CONFIG_CMDLINE_TAG) || \ defined (CONFIG_INITRD_TAG) || \ @@ -69,10 +63,7 @@ static struct tag *params; void do_bootm_linux (cmd_tbl_t *cmdtp, int flag, int argc, char *argv[], image_header_t *hdr, int verify) { - ulong rd_addr; - ulong rd_data, rd_len = 0; ulong initrd_start, initrd_end; - image_header_t *rd_hdr; void (*theKernel)(int zero, int arch, uint params); bd_t *bd = gd->bd;
@@ -82,109 +73,8 @@ void do_bootm_linux (cmd_tbl_t *cmdtp, int flag, int argc, char *argv[],
theKernel = (void (*)(int, int, uint))image_get_ep (hdr);
- /* - * Check if there is an initrd image - */ - if (argc >= 3) { - show_boot_progress (9); - - rd_addr = simple_strtoul (argv[2], NULL, 16); - printf ("## Loading Ramdisk Image at %08lx ...\n", rd_addr); - - /* Copy header so we can blank CRC field for re-calculation */ -#ifdef CONFIG_HAS_DATAFLASH - if (addr_dataflash (rd_addr)) { - rd_hdr = (image_header_t *)CFG_LOAD_ADDR; - read_dataflash (rd_addr, image_get_header_size (), - (char *)rd_hdr); - } else -#endif - rd_hdr = (image_header_t *)rd_addr; - - if (!image_check_magic (rd_hdr)) { - printf ("Bad Magic Number\n"); - show_boot_progress (-10); - do_reset (cmdtp, flag, argc, argv); - } - - if (!image_check_hcrc (rd_hdr)) { - printf ("Bad Header Checksum\n"); - show_boot_progress (-11); - do_reset (cmdtp, flag, argc, argv); - } - - show_boot_progress (10); - - print_image_hdr (rd_hdr); - - rd_data = image_get_data (rd_hdr); - rd_len = image_get_data_size (rd_hdr); - -#ifdef CONFIG_HAS_DATAFLASH - if (addr_dataflash (rd_addr)) - read_dataflash (rd_addr + image_get_header_size (), - rd_len, (char *)rd_data); -#endif - - if (verify) { - printf (" Verifying Checksum ... "); - if (!image_get_dcrc (rd_hdr)) { - printf ("Bad Data CRC\n"); - show_boot_progress (-12); - do_reset (cmdtp, flag, argc, argv); - } - printf ("OK\n"); - } - - show_boot_progress (11); - - if (!image_check_os (rd_hdr, IH_OS_LINUX) || - !image_check_arch (rd_hdr, IH_ARCH_ARM) || - !image_check_type (rd_hdr, IH_TYPE_RAMDISK)) { - printf ("No Linux ARM Ramdisk Image\n"); - show_boot_progress (-13); - do_reset (cmdtp, flag, argc, argv); - } - -#if defined(CONFIG_B2) || defined(CONFIG_EVB4510) || defined(CONFIG_ARMADILLO) - /* - *we need to copy the ramdisk to SRAM to let Linux boot - */ - memmove ((void *)image_get_load (rd_hdr), (uchar *)rd_data, rd_len); - rd_data = image_get_load (rd_hdr); -#endif /* CONFIG_B2 || CONFIG_EVB4510 */ - - /* - * Now check if we have a multifile image - */ - } else if (image_check_type (hdr, IH_TYPE_MULTI)) { - /* - * Get second entry data start address and len - */ - show_boot_progress (13); - image_multi_getimg (hdr, 1, &rd_data, &rd_len); - } else { - /* - * no initrd image - */ - show_boot_progress (14); - - rd_len = rd_data = 0; - } - -#ifdef DEBUG - if (!rd_data) { - printf ("No initrd\n"); - } -#endif - - if (rd_data) { - initrd_start = rd_data; - initrd_end = initrd_start + rd_len; - } else { - initrd_start = 0; - initrd_end = 0; - } + get_ramdisk (cmdtp, flag, argc, argv, hdr, verify, + IH_ARCH_ARM, &initrd_start, &initrd_end);
show_boot_progress (15);
diff --git a/lib_avr32/bootm.c b/lib_avr32/bootm.c index 455590e..a934cae 100644 --- a/lib_avr32/bootm.c +++ b/lib_avr32/bootm.c @@ -31,8 +31,6 @@
DECLARE_GLOBAL_DATA_PTR;
-extern int do_reset(cmd_tbl_t *cmdtp, int flag, int argc, char *argv[]); - /* CPU-specific hook to allow flushing of caches, etc. */ extern void prepare_to_boot(void);
@@ -176,9 +174,7 @@ static void setup_end_tag(struct tag *params) void do_bootm_linux(cmd_tbl_t *cmdtp, int flag, int argc, char *argv[], image_header_t *hdr, int verify) { - ulong rd_data, rd_len = 0; ulong initrd_start, initrd_end; - image_header_t *rd_hdr;
void (*theKernel)(int magic, void *tagtable); struct tag *params, *params_start; @@ -186,72 +182,8 @@ void do_bootm_linux(cmd_tbl_t *cmdtp, int flag, int argc, char *argv[],
theKernel = (void *)image_get_ep (hdr);
- /* - * Check if there is an initrd image - */ - if (argc >= 3) { - show_boot_progress (9); - - rd_hdr = (image_header_t *)simple_strtoul (argv[2], NULL, 16); - printf ("## Loading RAMDISK image at %08lx ...\n", rd_hdr); - - if (!image_check_magic (rd_hdr)) { - puts("Bad Magic Number\n"); - show_boot_progress (-10); - do_reset(cmdtp, flag, argc, argv); - } - - if (!image_check_hcrc (rd_hdr)) { - puts("Bad Header Checksum\n"); - show_boot_progress (-11); - do_reset(cmdtp, flag, argc, argv); - } - - show_boot_progress (10); - print_image_hdr (rd_hdr); - - if (verify) { - puts(" Verifying Checksum ... "); - if (!image_check_dcrc (rd_hdr)) { - puts("Bad Data CRC\n"); - show_boot_progress (-12); - do_reset(cmdtp, flag, argc, argv); - } - puts("OK\n"); - } - - show_boot_progress (11); - - if (!image_check_os (rd_hdr, IH_OS_LINUX) || - !image_check_arch (rd_hdr, IH_ARCH_AVR32) || - !image_check_type (rd_hdr, IH_TYPE_RAMDISK)) { - puts("Not a Linux/AVR32 RAMDISK image\n"); - show_boot_progress (-13); - do_reset(cmdtp, flag, argc, argv); - } - - rd_data = image_get_data (rd_hdr); - rd_len = image_get_data_size (rd_hdr); - - } else if (image_check_type (hdr, IH_TYPE_MULTI)) { - /* - * Get second entry data start address and len - */ - show_boot_progress (13); - image_multi_getimg (hdr, 1, &rd_data, &rd_len); - } else { - /* no initrd image */ - show_boot_progress (14); - rd_len = rd_data = 0; - } - - if (rd_data) { - initrd_start = rd_data; - initrd_end = initrd_start + rd_len; - } else { - initrd_start = 0; - initrd_end = 0; - } + get_ramdisk (cmdtp, flag, argc, argv, hdr, verify, + IH_ARCH_AVR32, &initrd_start, &initrd_end);
show_boot_progress (15);
diff --git a/lib_i386/bootm.c b/lib_i386/bootm.c index 27a2b0d..ab6c2a9 100644 --- a/lib_i386/bootm.c +++ b/lib_i386/bootm.c @@ -37,80 +37,10 @@ void do_bootm_linux(cmd_tbl_t *cmdtp, int flag, int argc, char *argv[], void *base_ptr;
ulong os_data, os_len; - ulong rd_data, rd_len; ulong initrd_start, initrd_end; - image_header_t *rd_hdr;
- /* - * Check if there is an initrd image - */ - if (argc >= 3) { - rd_hdr = (image_header_t *)simple_strtoul (argv[2], NULL, 16); - printf ("## Loading Ramdisk Image at %08lx ...\n", rd_hdr); - - if (!image_check_magic (rd_hdr)) { - printf ("Bad Magic Number\n"); - do_reset (cmdtp, flag, argc, argv); - } - - if (!image_check_hcrc (rd_hdr)) { - printf ("Bad Header Checksum\n"); - do_reset (cmdtp, flag, argc, argv); - } - - print_image_hdr (rd_hdr); - - rd_data = image_get_data (rd_hdr); - rd_len = image_get_data_size (rd_hdr); - - if (verify) { - printf (" Verifying Checksum ... "); - if (!image_check_dcrc (rd_hdr)) { - printf ("Bad Data CRC\n"); - do_reset (cmdtp, flag, argc, argv); - } - printf ("OK\n"); - } - - if (!image_check_os (rd_hdr, IH_OS_LINUX) || - !image_check_arch (rd_hdr, IH_ARCH_I386) || - !image_check_type (rd_hdr, IH_TYPE_RAMDISK)) { - printf ("No Linux i386 Ramdisk Image\n"); - do_reset (cmdtp, flag, argc, argv); - } - - /* - * Now check if we have a multifile image - */ - } else if (image_check_type (hdr, IH_TYPE_MULTI)) { - /* - * Get second entry data start address and len - */ - image_multi_getimg (hdr, 1, &rd_data, &rd_len); - } else { - /* - * no initrd image - */ - rd_data = rd_len = 0; - } - -#ifdef DEBUG - if (!rd_data) { - printf ("No initrd\n"); - } -#endif - - if (rd_data) { - initrd_start = rd_data; - initrd_end = initrd_start + rd_len; - printf (" Loading Ramdisk to %08lx, end %08lx ... ", - initrd_start, initrd_end); - memmove ((void *)initrd_start, (void *)rd_data, rd_len); - printf ("OK\n"); - } else { - initrd_start = 0; - initrd_end = 0; - } + get_ramdisk (cmdtp, flag, argc, argv, hdr, verify, + IH_ARCH_I386, &initrd_start, &initrd_end);
/* if multi-part image, we need to advance base ptr */ if (image_check_type (hdr, IH_TYPE_MULTI)) { @@ -121,7 +51,7 @@ void do_bootm_linux(cmd_tbl_t *cmdtp, int flag, int argc, char *argv[], }
base_ptr = load_zimage ((void*)os_data, os_len, - initrd_start, rd_len, 0); + initrd_start, initrd_end - initrd_start, 0);
if (NULL == base_ptr) { printf ("## Kernel loading failed ...\n"); diff --git a/lib_m68k/bootm.c b/lib_m68k/bootm.c index b135556..dac5276 100644 --- a/lib_m68k/bootm.c +++ b/lib_m68k/bootm.c @@ -44,18 +44,15 @@ DECLARE_GLOBAL_DATA_PTR; # define SHOW_BOOT_PROGRESS(arg) #endif
-int do_reset (cmd_tbl_t *cmdtp, int flag, int argc, char *argv[]); - void do_bootm_linux(cmd_tbl_t * cmdtp, int flag, int argc, char *argv[], image_header_t *hdr, int verify) { ulong sp;
- ulong rd_data, rd_len; + ulong rd_data_start, rd_data_end, rd_len; ulong initrd_high; ulong initrd_start, initrd_end; - image_header_t *rd_hdr; int initrd_copy_to_ram = 1;
ulong cmd_start, cmd_end; @@ -132,82 +129,14 @@ void do_bootm_linux(cmd_tbl_t * cmdtp, int flag, kernel = (void (*)(bd_t *, ulong, ulong, ulong, ulong))image_get_ep (hdr);
- /* - * Check if there is an initrd image - */ - - if (argc >= 3) { - debug("Not skipping initrd\n"); - SHOW_BOOT_PROGRESS(9); + get_ramdisk (cmdtp, flag, argc, argv, hdr, verify, + IH_ARCH_M68K, &rd_data_start, &rd_data_end); + rd_len = rd_data_end - rd_data_start;
- rd_hdr = (image_header_t *)simple_strtoul (argv[2], NULL, 16); - printf ("## Loading RAMDisk Image at %08lx ...\n", rd_hdr); - - if (!image_check_magic (rd_hdr)) { - puts("Bad Magic Number\n"); - SHOW_BOOT_PROGRESS(-10); - do_reset(cmdtp, flag, argc, argv); - } - - if (!image_check_hcrc (rd_hdr)) { - puts("Bad Header Checksum\n"); - SHOW_BOOT_PROGRESS(-11); - do_reset(cmdtp, flag, argc, argv); - } - - SHOW_BOOT_PROGRESS(10); - - print_image_hdr (rd_hdr); - - rd_data = image_get_data (rd_hdr); - rd_len = image_get_data_size (rd_hdr); - - if (verify) { - puts(" Verifying Checksum ... "); - if (!image_check_dcrc_wd (rd_hdr, CHUNKSZ)) { - puts("Bad Data CRC\n"); - SHOW_BOOT_PROGRESS(-12); - do_reset(cmdtp, flag, argc, argv); - } - puts("OK\n"); - } - - SHOW_BOOT_PROGRESS(11); - - if (!image_check_os (rd_hdr, IH_OS_LINUX) || - !image_check_arch (rd_hdr, IH_ARCH_M68K) || - !image_check_type (rd_hdr, IH_TYPE_RAMDISK)) { - puts("No Linux ColdFire Ramdisk Image\n"); - SHOW_BOOT_PROGRESS(-13); - do_reset(cmdtp, flag, argc, argv); - } - - /* - * Now check if we have a multifile image - */ - } else if (image_check_type (hdr, IH_TYPE_MULTI)) { - /* - * Get second entry data start address and len - */ - SHOW_BOOT_PROGRESS (13); - image_multi_getimg (hdr, 1, &rd_data, &rd_len); - } else { - /* - * no initrd image - */ - SHOW_BOOT_PROGRESS(14); - - rd_len = rd_data = 0; - } - - if (!rd_data) { - debug("No initrd\n"); - } - - if (rd_data) { + if (rd_data_start) { if (!initrd_copy_to_ram) { /* zero-copy ramdisk support */ - initrd_start = rd_data; - initrd_end = initrd_start + rd_len; + initrd_start = rd_data_start; + initrd_end = rd_data_end; } else { initrd_start = (ulong) kbd - rd_len; initrd_start &= ~(4096 - 1); /* align on page */ @@ -245,14 +174,14 @@ void do_bootm_linux(cmd_tbl_t * cmdtp, int flag,
debug ("## initrd at 0x%08lX ... 0x%08lX (len=%ld=0x%lX)\n", - rd_data, rd_data + rd_len - 1, rd_len, rd_len); + rd_data_start, rd_data_end - 1, rd_len, rd_len);
initrd_end = initrd_start + rd_len; printf(" Loading Ramdisk to %08lx, end %08lx ... ", initrd_start, initrd_end);
memmove_wd((void *)initrd_start, - (void *)rd_data, rd_len, CHUNKSZ); + (void *)rd_data_start, rd_len, CHUNKSZ);
puts("OK\n"); } diff --git a/lib_microblaze/bootm.c b/lib_microblaze/bootm.c index a4fce5a..1f3e777 100644 --- a/lib_microblaze/bootm.c +++ b/lib_microblaze/bootm.c @@ -32,17 +32,10 @@
DECLARE_GLOBAL_DATA_PTR;
-extern int do_reset (cmd_tbl_t * cmdtp, int flag, int argc, char *argv[]); - void do_bootm_linux (cmd_tbl_t * cmdtp, int flag, int argc, char *argv[], image_header_t *hdr, int verify) { - int i; - ulong checksum; - - ulong rd_data, rd_len; ulong initrd_start, initrd_end; - image_header_t *rd_hdr;
/* First parameter is mapped to $r5 for kernel boot args */ void (*theKernel) (char *); @@ -50,82 +43,8 @@ void do_bootm_linux (cmd_tbl_t * cmdtp, int flag, int argc, char *argv[],
theKernel = (void (*)(char *))image_get_ep (hdr);
- /* Check if there is an initrd image */ - if (argc >= 3) { - show_boot_progress (9); - - rd_hdr = (image_header_t *)simple_strtoul (argv[2], NULL, 16); - printf ("## Loading Ramdisk Image at %08lx ...\n", rd_hdr); - - if (!image_check_magic (rd_hdr)) { - printf ("Bad Magic Number\n"); - show_boot_progress (-10); - do_reset (cmdtp, flag, argc, argv); - } - - if (!image_check_magic (rd_hdr)) { - printf ("Bad Header Checksum\n"); - show_boot_progress (-11); - do_reset (cmdtp, flag, argc, argv); - } - - show_boot_progress (10); - print_image_hdr (rd_hdr); - - rd_data = image_get_data (rd_hdr); - rd_en = image_get_data_size (rd_hdr); - - if (verify) { - printf (" Verifying Checksum ... "); - if (!image_check_dcrc (rd_hdr)) { - printf ("Bad Data CRC\n"); - show_boot_progress (-12); - do_reset (cmdtp, flag, argc, argv); - } - printf ("OK\n"); - } - - show_boot_progress (11); - - if (!image_check_os (rd_hdr, IH_OS_LINUX) || - !image_check_arch (rd_hdr, IH_ARCH_MICROBLAZE) || - !image_check_type (rd_hdr, IH_TYPE_RAMDISK)) { - printf ("No Linux Microblaze Ramdisk Image\n"); - show_boot_progress (-13); - do_reset (cmdtp, flag, argc, argv); - } - - /* - * Now check if we have a multifile image - */ - } else if (image_check_type (hdr, IH_TYPE_MULTI)) { - /* - * Get second entry data start address and len - */ - show_boot_progress (13); - image_multi_getimg (hdr, 1, &rd_data, &rd_len); - } else { - /* - * no initrd image - */ - show_boot_progress (14); - - rd_data = rd_len = 0; - } - -#ifdef DEBUG - if (!rd_data) { - printf ("No initrd\n"); - } -#endif - - if (rd_data) { - initrd_start = rd_data; - initrd_end = initrd_start + rd_len; - } else { - initrd_start = 0; - initrd_end = 0; - } + get_ramdisk (cmdtp, flag, argc, argv, hdr, verify, + IH_ARCH_MICROBLAZE, &initrd_start, &initrd_end);
show_boot_progress (15);
diff --git a/lib_mips/bootm.c b/lib_mips/bootm.c index 7ea7571..fb91c76 100644 --- a/lib_mips/bootm.c +++ b/lib_mips/bootm.c @@ -33,8 +33,6 @@ DECLARE_GLOBAL_DATA_PTR; #define LINUX_MAX_ENVS 256 #define LINUX_MAX_ARGS 256
-extern int do_reset (cmd_tbl_t *cmdtp, int flag, int argc, char *argv[]); - static int linux_argc; static char ** linux_argv;
@@ -49,9 +47,7 @@ static void linux_env_set (char * env_name, char * env_val); void do_bootm_linux (cmd_tbl_t * cmdtp, int flag, int argc, char *argv[], image_header_t *hdr, int verify) { - ulong rd_data, rd_len; ulong initrd_start, initrd_end; - image_header_t *rd_hdr;
void (*theKernel) (int, char **, char **, int *); char *commandline = getenv ("bootargs"); @@ -60,84 +56,8 @@ void do_bootm_linux (cmd_tbl_t * cmdtp, int flag, int argc, char *argv[], theKernel = (void (*)(int, char **, char **, int *))image_get_ep (hdr);
- /* - * Check if there is an initrd image - */ - if (argc >= 3) { - show_boot_progress (9); - - rd_hdr = (image_header_t *)simple_strtoul (argv[2], NULL, 16); - printf ("## Loading Ramdisk Image at %08lx ...\n", rd_hdr); - - if (!image_check_magic (rd_hdr)) { - printf ("Bad Magic Number\n"); - show_boot_progress (-10); - do_reset (cmdtp, flag, argc, argv); - } - - if (!image_check_hcrc (rd_hdr)) { - printf ("Bad Header Checksum\n"); - show_boot_progress (-11); - do_reset (cmdtp, flag, argc, argv); - } - - show_boot_progress (10); - print_image_hdr (rd_hdr); - - rd_data = image_get_data (rd_hdr); - rd_len = image_get_data_size (rd_hdr); - - if (verify) { - printf (" Verifying Checksum ... "); - if (!image_check_dcrc (rd_hdr)) { - printf ("Bad Data CRC\n"); - show_boot_progress (-12); - do_reset (cmdtp, flag, argc, argv); - } - printf ("OK\n"); - } - - show_boot_progress (11); - - if (!image_check_os (rd_hdr, IH_OS_LINUX) || - !image_check_arch (rd_hdr, IH_ARCH_MIPS) || - !image_check_type (rd_hdr, IH_TYPE_RAMDISK)) { - printf ("No Linux MIPS Ramdisk Image\n"); - show_boot_progress (-13); - do_reset (cmdtp, flag, argc, argv); - } - - /* - * Now check if we have a multifile image - */ - } else if (image_check_type (hdr, IH_TYPE_MULTI)) { - /* - * Get second entry data start address and len - */ - show_boot_progress (13); - image_multi_getimg (hdr, 1, &rd_data, &rd_len); - } else { - /* - * no initrd image - */ - show_boot_progress (14); - - rd_data = rd_len = 0; - } - -#ifdef DEBUG - if (!rd_data) { - printf ("No initrd\n"); - } -#endif - - if (rd_data) { - initrd_start = rd_data; - initrd_end = initrd_start + rd_len; - } else { - initrd_start = 0; - initrd_end = 0; - } + get_ramdisk (cmdtp, flag, argc, argv, hdr, verify, + IH_ARCH_MIPS, &initrd_start, &initrd_end);
show_boot_progress (15);
diff --git a/lib_ppc/bootm.c b/lib_ppc/bootm.c index 36e6776..65edcdb 100644 --- a/lib_ppc/bootm.c +++ b/lib_ppc/bootm.c @@ -68,8 +68,7 @@ do_bootm_linux(cmd_tbl_t *cmdtp, int flag, ulong initrd_high; int initrd_copy_to_ram = 1; ulong initrd_start, initrd_end; - ulong rd_data, rd_len; - image_header_t *rd_hdr; + ulong rd_data_start, rd_data_end, rd_len;
ulong cmd_start, cmd_end; char *cmdline; @@ -171,81 +170,9 @@ do_bootm_linux(cmd_tbl_t *cmdtp, int flag,
kernel = (void (*)(bd_t *, ulong, ulong, ulong, ulong))image_get_ep (hdr);
- /* - * Check if there is an initrd image - */ - -#if defined(CONFIG_OF_LIBFDT) - /* Look for a '-' which indicates to ignore the ramdisk argument */ - if (argc >= 3 && strcmp(argv[2], "-") == 0) { - debug ("Skipping initrd\n"); - rd_len = rd_data = 0; - } - else -#endif - if (argc >= 3) { - debug ("Not skipping initrd\n"); - show_boot_progress (9); - - rd_hdr = (image_header_t *)simple_strtoul (argv[2], NULL, 16); - printf ("## Loading RAMDisk Image at %08lx ...\n", (ulong)rd_hdr); - - if (!image_check_magic (rd_hdr)) { - puts ("Bad Magic Number\n"); - show_boot_progress (-10); - do_reset (cmdtp, flag, argc, argv); - } - - if (!image_check_hcrc (rd_hdr)) { - puts ("Bad Header Checksum\n"); - show_boot_progress (-11); - do_reset (cmdtp, flag, argc, argv); - } - show_boot_progress (10); - - print_image_hdr (rd_hdr); - - if (verify) { - puts (" Verifying Checksum ... "); - - if (!image_check_dcrc_wd (rd_hdr, CHUNKSZ)) { - puts ("Bad Data CRC\n"); - show_boot_progress (-12); - do_reset (cmdtp, flag, argc, argv); - } - puts ("OK\n"); - } - - show_boot_progress (11); - - if (!image_check_os (rd_hdr, IH_OS_LINUX) || - !image_check_arch (rd_hdr, IH_ARCH_PPC) || - !image_check_type (rd_hdr, IH_TYPE_RAMDISK)) { - puts ("No Linux PPC Ramdisk Image\n"); - show_boot_progress (-13); - do_reset (cmdtp, flag, argc, argv); - } - - rd_data = image_get_data (rd_hdr); - rd_len = image_get_data_size (rd_hdr); - - /* - * Now check if we have a multifile image - */ - } else if (image_check_type (hdr, IH_TYPE_MULTI)) { - /* - * Get second entry data start address and len - */ - image_multi_getimg (hdr, 1, &rd_data, &rd_len); - show_boot_progress (13); - } else { - /* - * No initrd image - */ - show_boot_progress (14); - - rd_len = rd_data = 0; - } + get_ramdisk (cmdtp, flag, argc, argv, hdr, verify, + IH_ARCH_PPC, &rd_data_start, &rd_data_end); + rd_len = rd_data_end - rd_data_start;
#if defined(CONFIG_OF_LIBFDT) if(argc > 3) { @@ -337,14 +264,11 @@ do_bootm_linux(cmd_tbl_t *cmdtp, int flag, } } #endif - if (!rd_data) { - debug ("No initrd\n"); - }
- if (rd_data) { + if (rd_data_start) { if (!initrd_copy_to_ram) { /* zero-copy ramdisk support */ - initrd_start = rd_data; - initrd_end = initrd_start + rd_len; + initrd_start = rd_data_start; + initrd_end = rd_data_end; } else { initrd_start = (ulong)kbd - rd_len; initrd_start &= ~(4096 - 1); /* align on page */ @@ -376,14 +300,14 @@ 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", - rd_data, rd_data + rd_len - 1, rd_len, rd_len); + rd_data_start, rd_data_end - 1, rd_len, rd_len);
initrd_end = initrd_start + rd_len; printf (" Loading Ramdisk to %08lx, end %08lx ... ", initrd_start, initrd_end);
memmove_wd((void *)initrd_start, - (void *)rd_data, rd_len, CHUNKSZ); + (void *)rd_data_start, rd_len, CHUNKSZ);
puts ("OK\n"); }

Microblaze do_bootm_linux() includes ramdisk processing code but the ramdisk does not get used anywhere later on.
Signed-off-by: Marian Balakowicz m8@semihalf.com ---
lib_microblaze/bootm.c | 5 ----- 1 files changed, 0 insertions(+), 5 deletions(-)
diff --git a/lib_microblaze/bootm.c b/lib_microblaze/bootm.c index 1f3e777..bccfbe1 100644 --- a/lib_microblaze/bootm.c +++ b/lib_microblaze/bootm.c @@ -35,17 +35,12 @@ DECLARE_GLOBAL_DATA_PTR; void do_bootm_linux (cmd_tbl_t * cmdtp, int flag, int argc, char *argv[], image_header_t *hdr, int verify) { - ulong initrd_start, initrd_end; - /* First parameter is mapped to $r5 for kernel boot args */ void (*theKernel) (char *); char *commandline = getenv ("bootargs");
theKernel = (void (*)(char *))image_get_ep (hdr);
- get_ramdisk (cmdtp, flag, argc, argv, hdr, verify, - IH_ARCH_MICROBLAZE, &initrd_start, &initrd_end); - show_boot_progress (15);
#ifdef DEBUG

Hi Marian,
do you have git repository with your changes? I would like to see what is changed from previous state. I have some changes in my internal repository which modified linux booting with using ramdisk too.
Regards, Michal Simek
Microblaze do_bootm_linux() includes ramdisk processing code but the ramdisk does not get used anywhere later on.
Signed-off-by: Marian Balakowicz m8@semihalf.com
lib_microblaze/bootm.c | 5 ----- 1 files changed, 0 insertions(+), 5 deletions(-)
diff --git a/lib_microblaze/bootm.c b/lib_microblaze/bootm.c index 1f3e777..bccfbe1 100644 --- a/lib_microblaze/bootm.c +++ b/lib_microblaze/bootm.c @@ -35,17 +35,12 @@ DECLARE_GLOBAL_DATA_PTR; void do_bootm_linux (cmd_tbl_t * cmdtp, int flag, int argc, char *argv[], image_header_t *hdr, int verify) {
ulong initrd_start, initrd_end;
/* First parameter is mapped to $r5 for kernel boot args */ void (*theKernel) (char *); char *commandline = getenv ("bootargs");
theKernel = (void (*)(char *))image_get_ep (hdr);
get_ramdisk (cmdtp, flag, argc, argv, hdr, verify,
IH_ARCH_MICROBLAZE, &initrd_start, &initrd_end);
show_boot_progress (15);
#ifdef DEBUG

Michal Simek wrote:
Hi Marian,
do you have git repository with your changes?
Hi Michal,
Let me answer this, as Marian is out of office. Yes, the changes are available form the new-image branch of the u-boot-testing repo. For more details, please see my email to the list announcing it, sent a while ago ([U-Boot-Users] [new uImage] Code available on new-image branch of u-boot-testing repo).
I would like to see what is changed from previous state. I have some changes in my internal repository which modified linux booting with using ramdisk too.
It would be very good to have a look at your changes -- could you post them (preferably using the new-image branch as a baseline :).
Thanks, Bartlomiej

Hi Bartolomiej,
Hi Marian,
do you have git repository with your changes?
Hi Michal,
Let me answer this, as Marian is out of office. Yes, the changes are available form the new-image branch of the u-boot-testing repo. For more details, please see my email to the list announcing it, sent a while ago ([U-Boot-Users] [new uImage] Code available on new-image branch of u-boot-testing repo).
Thanks.
I would like to see what is changed from previous state. I have some changes in my internal repository which modified linux booting with using ramdisk too.
It would be very good to have a look at your changes -- could you post them (preferably using the new-image branch as a baseline :).
Microblaze linux bootm function will be simpler powerpc bootm function. Microblaze supports FDT and Ramdisk now.
I'll check it soon and I'll send my changes.
Regards, Michal Simek

Ramdisk loading code, including initrd_high variable handling, was duplicated for PPC and M68K platforms. This patch creates common helper routine that is being called from both platforms' do_bootm_linux() routines.
Signed-off-by: Marian Balakowicz m8@semihalf.com ---
common/image.c | 113 ++++++++++++++++++++++++++++++++++++++++++++++++++++++ include/image.h | 7 +++ lib_m68k/bootm.c | 114 ++++++++++++------------------------------------------ lib_ppc/bootm.c | 112 ++++++++++++----------------------------------------- 4 files changed, 171 insertions(+), 175 deletions(-)
diff --git a/common/image.c b/common/image.c index e4be4ca..56d6b52 100644 --- a/common/image.c +++ b/common/image.c @@ -22,6 +22,9 @@ * Foundation, Inc., 59 Temple Place, Suite 330, Boston, * MA 02111-1307 USA */ + +#define DEBUG + #ifndef USE_HOSTCC #include <common.h> #include <watchdog.h> @@ -34,6 +37,10 @@ #include <dataflash.h> #endif
+#ifdef CONFIG_LOGBUFFER +#include <logbuff.h> +#endif + extern int do_reset (cmd_tbl_t *cmdtp, int flag, int argc, char *argv[]); #else #include "mkimage.h" @@ -476,5 +483,111 @@ void get_ramdisk (cmd_tbl_t *cmdtp, int flag, int argc, char *argv[], debug (" ramdisk start = 0x%08lx, ramdisk end = 0x%08lx\n", *rd_start, *rd_end); } + +#if defined(CONFIG_PPC) || defined(CONFIG_M68K) +/** + * ramdisk_high - relocate init ramdisk + * @rd_data: ramdisk data start address + * @rd_len: ramdisk data length + * @kbd: kernel board info copy (within BOOTMAPSZ boundary) + * @sp_limit: stack pointer limit (including BOOTMAPSZ) + * @sp: current stack pointer + * @initrd_start: pointer to a ulong variable, will hold final init ramdisk + * start address (after possible relocation) + * @initrd_end: pointer to a ulong variable, will hold final init ramdisk + * end address (after possible relocation) + * + * ramdisk_high() takes a relocation hint from "initrd_high" environement + * variable and if requested ramdisk data is moved to a specified location. + * + * returns: + * initrd_start and initrd_end are set to final (after relocation) ramdisk + * start/end addresses if ramdisk image start and len were provided + * otherwise set initrd_start and initrd_end to zeros + * + */ +void ramdisk_high (ulong rd_data, ulong rd_len, bd_t *kbd, ulong sp_limit, + ulong sp, ulong *initrd_start, ulong *initrd_end) +{ + char *s; + ulong initrd_high; + int initrd_copy_to_ram = 1; + + if ((s = getenv ("initrd_high")) != NULL) { + /* a value of "no" or a similar string will act like 0, + * turning the "load high" feature off. This is intentional. + */ + initrd_high = simple_strtoul (s, NULL, 16); + if (initrd_high == ~0) + initrd_copy_to_ram = 0; + } else { + /* not set, no restrictions to load high */ + initrd_high = ~0; + } + +#ifdef CONFIG_LOGBUFFER + /* Prevent initrd from overwriting logbuffer */ + if (initrd_high < (kbd->bi_memsize - LOGBUFF_LEN - LOGBUFF_OVERHEAD)) + initrd_high = kbd->bi_memsize - LOGBUFF_LEN - LOGBUFF_OVERHEAD; + debug ("## Logbuffer at 0x%08lx ", kbd->bi_memsize - LOGBUFF_LEN); +#endif + debug ("## initrd_high = 0x%08lx, copy_to_ram = %d\n", + initrd_high, initrd_copy_to_ram); + + if (rd_data) { + if (!initrd_copy_to_ram) { /* zero-copy ramdisk support */ + debug (" in-place initrd\n"); + *initrd_start = rd_data; + *initrd_end = rd_data + rd_len; + } else { + *initrd_start = (ulong)kbd - rd_len; + *initrd_start &= ~(4096 - 1); /* align on page */ + + if (initrd_high) { + ulong nsp; + + /* + * the inital ramdisk does not need to be within + * CFG_BOOTMAPSZ as it is not accessed until after + * the mm system is initialised. + * + * do the stack bottom calculation again and see if + * the initrd will fit just below the monitor stack + * bottom without overwriting the area allocated + * for command line args and board info. + */ + nsp = sp; + nsp -= 2048; /* just to be sure */ + nsp &= ~0xF; + + if (nsp > initrd_high) /* limit as specified */ + nsp = initrd_high; + + nsp -= rd_len; + nsp &= ~(4096 - 1); /* align on page */ + + if (nsp >= sp_limit) + *initrd_start = nsp; + } + + show_boot_progress (12); + + *initrd_end = *initrd_start + rd_len; + printf (" Loading Ramdisk to %08lx, end %08lx ... ", + *initrd_start, *initrd_end); + + memmove_wd((void *)*initrd_start, + (void *)rd_data, rd_len, CHUNKSZ); + + puts ("OK\n"); + } + } else { + *initrd_start = 0; + *initrd_end = 0; + } + debug (" ramdisk load start = 0x%08lx, ramdisk load end = 0x%08lx\n", + *initrd_start, *initrd_end); +} +#endif /* CONFIG_PPC || CONFIG_M68K */ #endif /* USE_HOSTCC */
diff --git a/include/image.h b/include/image.h index b438564..a8cb1da 100644 --- a/include/image.h +++ b/include/image.h @@ -37,6 +37,7 @@ #include <command.h> #ifndef USE_HOSTCC #include <linux/string.h> +#include <asm/u-boot.h> #endif
/* @@ -340,7 +341,11 @@ image_header_t* image_get_ramdisk (cmd_tbl_t *cmdtp, int flag, void get_ramdisk (cmd_tbl_t *cmdtp, int flag, int argc, char *argv[], image_header_t *hdr, int verify, uint8_t arch, ulong *rd_start, ulong *rd_end); -#endif /* USE_HOSTCCa */
+#if defined(CONFIG_PPC) || defined(CONFIG_M68K) +void ramdisk_high (ulong rd_data_start, ulong rd_len, bd_t *kbd, ulong sp_limit, + ulong sp, ulong *initrd_start, ulong *initrd_end); +#endif /* CONFIG_PPC || CONFIG_M68K */ +#endif /* USE_HOSTCC */
#endif /* __IMAGE_H__ */ diff --git a/lib_m68k/bootm.c b/lib_m68k/bootm.c index dac5276..3fd38e9 100644 --- a/lib_m68k/bootm.c +++ b/lib_m68k/bootm.c @@ -44,16 +44,16 @@ DECLARE_GLOBAL_DATA_PTR; # define SHOW_BOOT_PROGRESS(arg) #endif
+static ulong get_sp (void); + void do_bootm_linux(cmd_tbl_t * cmdtp, int flag, int argc, char *argv[], image_header_t *hdr, int verify) { - ulong sp; + ulong sp_limit;
ulong rd_data_start, rd_data_end, rd_len; - ulong initrd_high; ulong initrd_start, initrd_end; - int initrd_copy_to_ram = 1;
ulong cmd_start, cmd_end; char *cmdline; @@ -61,25 +61,6 @@ void do_bootm_linux(cmd_tbl_t * cmdtp, int flag, bd_t *kbd; void (*kernel) (bd_t *, ulong, ulong, ulong, ulong);
- if ((s = getenv("initrd_high")) != NULL) { - /* a value of "no" or a similar string will act like 0, - * turning the "load high" feature off. This is intentional. - */ - initrd_high = simple_strtoul(s, NULL, 16); - if (initrd_high == ~0) - initrd_copy_to_ram = 0; - } else { /* not set, no restrictions to load high */ - initrd_high = ~0; - } - -#ifdef CONFIG_LOGBUFFER - kbd = gd->bd; - /* Prevent initrd from overwriting logbuffer */ - if (initrd_high < (kbd->bi_memsize - LOGBUFF_LEN - LOGBUFF_OVERHEAD)) - initrd_high = kbd->bi_memsize - LOGBUFF_LEN - LOGBUFF_OVERHEAD; - debug("## Logbuffer at 0x%08lX ", kbd->bi_memsize - LOGBUFF_LEN); -#endif - /* * Booting a (Linux) kernel image * @@ -89,19 +70,18 @@ void do_bootm_linux(cmd_tbl_t * cmdtp, int flag, * memory, which means far enough below the current stack * pointer. */ - asm("movel %%a7, %%d0\n" - "movel %%d0, %0\n": "=d"(sp): :"%d0"); + sp_limit = get_sp();
- debug("## Current stack ends at 0x%08lX ", sp); + debug("## Current stack ends at 0x%08lX ", sp_limit);
- sp -= 2048; /* just to be sure */ - if (sp > CFG_BOOTMAPSZ) - sp = CFG_BOOTMAPSZ; - sp &= ~0xF; + sp_limit -= 2048; /* just to be sure */ + if (sp_limit > CFG_BOOTMAPSZ) + sp_limit = CFG_BOOTMAPSZ; + sp_limit &= ~0xF;
- debug("=> set upper limit to 0x%08lX\n", sp); + debug("=> set upper limit to 0x%08lX\n", sp_limit);
- cmdline = (char *)((sp - CFG_BARGSIZE) & ~0xF); + cmdline = (char *)((sp_limit - CFG_BARGSIZE) & ~0xF); kbd = (bd_t *) (((ulong) cmdline - sizeof(bd_t)) & ~0xF);
if ((s = getenv("bootargs")) == NULL) @@ -126,69 +106,17 @@ void do_bootm_linux(cmd_tbl_t * cmdtp, int flag, kbd->bi_busfreq /= 1000000L; }
+ /* find kernel */ kernel = (void (*)(bd_t *, ulong, ulong, ulong, ulong))image_get_ep (hdr);
+ /* find ramdisk */ get_ramdisk (cmdtp, flag, argc, argv, hdr, verify, IH_ARCH_M68K, &rd_data_start, &rd_data_end); - rd_len = rd_data_end - rd_data_start;
- if (rd_data_start) { - if (!initrd_copy_to_ram) { /* zero-copy ramdisk support */ - initrd_start = rd_data_start; - initrd_end = rd_data_end; - } else { - initrd_start = (ulong) kbd - rd_len; - initrd_start &= ~(4096 - 1); /* align on page */ - - if (initrd_high) { - ulong nsp; - - /* - * the inital ramdisk does not need to be within - * CFG_BOOTMAPSZ as it is not accessed until after - * the mm system is initialised. - * - * do the stack bottom calculation again and see if - * the initrd will fit just below the monitor stack - * bottom without overwriting the area allocated - * above for command line args and board info. - */ - asm("movel %%a7, %%d0\n" - "movel %%d0, %0\n": "=d"(nsp): :"%d0"); - - nsp -= 2048; /* just to be sure */ - nsp &= ~0xF; - - if (nsp > initrd_high) /* limit as specified */ - nsp = initrd_high; - - nsp -= rd_len; - nsp &= ~(4096 - 1); /* align on page */ - - if (nsp >= sp) - initrd_start = nsp; - } - - SHOW_BOOT_PROGRESS(12); - - debug - ("## initrd at 0x%08lX ... 0x%08lX (len=%ld=0x%lX)\n", - rd_data_start, rd_data_end - 1, rd_len, rd_len); - - initrd_end = initrd_start + rd_len; - printf(" Loading Ramdisk to %08lx, end %08lx ... ", - initrd_start, initrd_end); - - memmove_wd((void *)initrd_start, - (void *)rd_data_start, rd_len, CHUNKSZ); - - puts("OK\n"); - } - } else { - initrd_start = 0; - initrd_end = 0; - } + rd_len = rd_data_end - rd_data_start; + ramdisk_high (rd_data_start, rd_len, kdb, sp_limit, get_sp (), + &initrd_start, &initrd_end);
debug("## Transferring control to Linux (at address %08lx) ...\n", (ulong) kernel); @@ -206,3 +134,13 @@ void do_bootm_linux(cmd_tbl_t * cmdtp, int flag, (*kernel) (kbd, initrd_start, initrd_end, cmd_start, cmd_end); /* does not return */ } + +static ulong get_sp (void) +{ + ulong sp; + + asm("movel %%a7, %%d0\n" + "movel %%d0, %0\n": "=d"(sp): :"%d0"); + + return sp; +} diff --git a/lib_ppc/bootm.c b/lib_ppc/bootm.c index 65edcdb..d73d2fd 100644 --- a/lib_ppc/bootm.c +++ b/lib_ppc/bootm.c @@ -43,10 +43,6 @@ static void fdt_error (const char *msg); #endif
-#ifdef CONFIG_LOGBUFFER -#include <logbuff.h> -#endif - #ifdef CFG_INIT_RAM_LOCK #include <asm/cache.h> #endif @@ -54,9 +50,10 @@ static void fdt_error (const char *msg); DECLARE_GLOBAL_DATA_PTR;
extern int do_reset (cmd_tbl_t *cmdtp, int flag, int argc, char *argv[]); +static ulong get_sp (void);
#if defined(CONFIG_CMD_BDI) -extern int do_bdinfo(cmd_tbl_t *cmdtp, int flag, int argc, char *argv[]); +extern int do_bdinfo (cmd_tbl_t *cmdtp, int flag, int argc, char *argv[]); #endif
void __attribute__((noinline)) @@ -65,15 +62,13 @@ do_bootm_linux(cmd_tbl_t *cmdtp, int flag, image_header_t *hdr, int verify) { - ulong initrd_high; - int initrd_copy_to_ram = 1; ulong initrd_start, initrd_end; ulong rd_data_start, rd_data_end, rd_len;
ulong cmd_start, cmd_end; char *cmdline;
- ulong sp; + ulong sp_limit; char *s; bd_t *kbd; void (*kernel)(bd_t *, ulong, ulong, ulong, ulong); @@ -84,25 +79,6 @@ do_bootm_linux(cmd_tbl_t *cmdtp, int flag, ulong of_data = 0; #endif
- if ((s = getenv ("initrd_high")) != NULL) { - /* a value of "no" or a similar string will act like 0, - * turning the "load high" feature off. This is intentional. - */ - initrd_high = simple_strtoul(s, NULL, 16); - if (initrd_high == ~0) - initrd_copy_to_ram = 0; - } else { /* not set, no restrictions to load high */ - initrd_high = ~0; - } - -#ifdef CONFIG_LOGBUFFER - kbd=gd->bd; - /* Prevent initrd from overwriting logbuffer */ - if (initrd_high < (kbd->bi_memsize-LOGBUFF_LEN-LOGBUFF_OVERHEAD)) - initrd_high = kbd->bi_memsize-LOGBUFF_LEN-LOGBUFF_OVERHEAD; - debug ("## Logbuffer at 0x%08lX ", kbd->bi_memsize-LOGBUFF_LEN); -#endif - /* * Booting a (Linux) kernel image * @@ -113,18 +89,17 @@ do_bootm_linux(cmd_tbl_t *cmdtp, int flag, * pointer. */
- asm( "mr %0,1": "=r"(sp) : ); - - debug ("## Current stack ends at 0x%08lX ", sp); + sp_limit = get_sp(); + debug ("## Current stack ends at 0x%08lX ", sp_limit);
- sp -= 2048; /* just to be sure */ - if (sp > CFG_BOOTMAPSZ) - sp = CFG_BOOTMAPSZ; - sp &= ~0xF; + sp_limit -= 2048; /* just to be sure */ + if (sp_limit > CFG_BOOTMAPSZ) + sp_limit = CFG_BOOTMAPSZ; + sp_limit &= ~0xF;
- debug ("=> set upper limit to 0x%08lX\n", sp); + debug ("=> set upper limit to 0x%08lX\n", sp_limit);
- cmdline = (char *)((sp - CFG_BARGSIZE) & ~0xF); + cmdline = (char *)((sp_limit - CFG_BARGSIZE) & ~0xF); kbd = (bd_t *)(((ulong)cmdline - sizeof(bd_t)) & ~0xF);
if ((s = getenv("bootargs")) == NULL) @@ -168,13 +143,20 @@ do_bootm_linux(cmd_tbl_t *cmdtp, int flag, #endif /* CONFIG_MPC5xxx */ }
+ /* find kernel */ kernel = (void (*)(bd_t *, ulong, ulong, ulong, ulong))image_get_ep (hdr);
+ /* find ramdisk */ get_ramdisk (cmdtp, flag, argc, argv, hdr, verify, IH_ARCH_PPC, &rd_data_start, &rd_data_end); + rd_len = rd_data_end - rd_data_start;
+ ramdisk_high (rd_data_start, rd_len, kbd, sp_limit, get_sp (), + &initrd_start, &initrd_end); + #if defined(CONFIG_OF_LIBFDT) + /* find flattened device tree */ if(argc > 3) { of_flat_tree = (char *) simple_strtoul(argv[3], NULL, 16); fdt_hdr = (image_header_t *)of_flat_tree; @@ -265,56 +247,6 @@ do_bootm_linux(cmd_tbl_t *cmdtp, int flag, } #endif
- if (rd_data_start) { - if (!initrd_copy_to_ram) { /* zero-copy ramdisk support */ - initrd_start = rd_data_start; - initrd_end = rd_data_end; - } else { - initrd_start = (ulong)kbd - rd_len; - initrd_start &= ~(4096 - 1); /* align on page */ - - if (initrd_high) { - ulong nsp; - - /* - * the inital ramdisk does not need to be within - * CFG_BOOTMAPSZ as it is not accessed until after - * the mm system is initialised. - * - * do the stack bottom calculation again and see if - * the initrd will fit just below the monitor stack - * bottom without overwriting the area allocated - * above for command line args and board info. - */ - asm( "mr %0,1": "=r"(nsp) : ); - nsp -= 2048; /* just to be sure */ - nsp &= ~0xF; - if (nsp > initrd_high) /* limit as specified */ - nsp = initrd_high; - nsp -= rd_len; - nsp &= ~(4096 - 1); /* align on page */ - if (nsp >= sp) - initrd_start = nsp; - } - - show_boot_progress (12); - - debug ("## initrd at 0x%08lX ... 0x%08lX (len=%ld=0x%lX)\n", - rd_data_start, rd_data_end - 1, rd_len, rd_len); - - initrd_end = initrd_start + rd_len; - printf (" Loading Ramdisk to %08lx, end %08lx ... ", - initrd_start, initrd_end); - - memmove_wd((void *)initrd_start, - (void *)rd_data_start, rd_len, CHUNKSZ); - - puts ("OK\n"); - } - } else { - initrd_start = 0; - initrd_end = 0; - }
#if defined(CONFIG_OF_LIBFDT)
@@ -413,6 +345,14 @@ do_bootm_linux(cmd_tbl_t *cmdtp, int flag, /* does not return */ }
+static ulong get_sp (void) +{ + ulong sp; + + asm( "mr %0,1": "=r"(sp) : ); + return sp; +} + #if defined(CONFIG_OF_LIBFDT) static void fdt_error (const char *msg) {

This patch moves common pre-boot allocation steps shared between PPC and M68K to a helper routines:
common: - get_boot_sp_limit() - get_boot_cmline() - get_boot_kbd()
platform: - set_clocks_in_mhz()
Signed-off-by: Marian Balakowicz m8@semihalf.com ---
common/image.c | 118 ++++++++++++++++++++++++++++++++++++++++++++++++++---- include/image.h | 10 ++++- lib_m68k/bootm.c | 72 +++++++++++++-------------------- lib_ppc/bootm.c | 106 ++++++++++++++++++++----------------------------- 4 files changed, 189 insertions(+), 117 deletions(-)
diff --git a/common/image.c b/common/image.c index 56d6b52..39e5f23 100644 --- a/common/image.c +++ b/common/image.c @@ -42,9 +42,15 @@ #endif
extern int do_reset (cmd_tbl_t *cmdtp, int flag, int argc, char *argv[]); + +#ifdef CONFIG_CMD_BDI +extern int do_bdinfo(cmd_tbl_t *cmdtp, int flag, int argc, char *argv[]); +#endif + +DECLARE_GLOBAL_DATA_PTR; #else #include "mkimage.h" -#endif +#endif /* USE_HOSTCC*/
#include <image.h>
@@ -501,17 +507,19 @@ void get_ramdisk (cmd_tbl_t *cmdtp, int flag, int argc, char *argv[], * variable and if requested ramdisk data is moved to a specified location. * * returns: - * initrd_start and initrd_end are set to final (after relocation) ramdisk + * - initrd_start and initrd_end are set to final (after relocation) ramdisk * start/end addresses if ramdisk image start and len were provided - * otherwise set initrd_start and initrd_end to zeros - * + * otherwise set initrd_start and initrd_end set to zeros + * - returns new allc_current, next free address below BOOTMAPSZ */ -void ramdisk_high (ulong rd_data, ulong rd_len, bd_t *kbd, ulong sp_limit, - ulong sp, ulong *initrd_start, ulong *initrd_end) +ulong ramdisk_high (ulong alloc_current, ulong rd_data, ulong rd_len, + bd_t *kbd, ulong sp_limit, ulong sp, + ulong *initrd_start, ulong *initrd_end) { char *s; ulong initrd_high; int initrd_copy_to_ram = 1; + ulong new_alloc_current = alloc_current;
if ((s = getenv ("initrd_high")) != NULL) { /* a value of "no" or a similar string will act like 0, @@ -540,7 +548,8 @@ void ramdisk_high (ulong rd_data, ulong rd_len, bd_t *kbd, ulong sp_limit, *initrd_start = rd_data; *initrd_end = rd_data + rd_len; } else { - *initrd_start = (ulong)kbd - rd_len; + new_alloc_current = alloc_current - rd_len; + *initrd_start = new_alloc_current; *initrd_start &= ~(4096 - 1); /* align on page */
if (initrd_high) { @@ -566,8 +575,10 @@ void ramdisk_high (ulong rd_data, ulong rd_len, bd_t *kbd, ulong sp_limit, nsp -= rd_len; nsp &= ~(4096 - 1); /* align on page */
- if (nsp >= sp_limit) + if (nsp >= sp_limit) { *initrd_start = nsp; + new_alloc_current = alloc_current; + } }
show_boot_progress (12); @@ -587,7 +598,96 @@ void ramdisk_high (ulong rd_data, ulong rd_len, bd_t *kbd, ulong sp_limit, } debug (" ramdisk load start = 0x%08lx, ramdisk load end = 0x%08lx\n", *initrd_start, *initrd_end); + + return new_alloc_current; +} + +/** + * get_boot_sp_limit - calculate stack pointer limit + * @sp: current stack pointer + * + * get_boot_sp_limit() takes current stack pointer adrress and calculates + * stack pointer limit, below which kernel boot data (cmdline, board info, + * etc.) will be allocated. + * + * returns: + * stack pointer limit + */ +ulong get_boot_sp_limit(ulong sp) +{ + ulong sp_limit = sp; + + sp_limit -= 2048; /* just to be sure */ + + /* make sure sp_limit is within kernel mapped space */ + if (sp_limit > CFG_BOOTMAPSZ) + sp_limit = CFG_BOOTMAPSZ; + sp_limit &= ~0xF; + + return sp_limit; +} + +/** + * get_boot_cmdline - allocate and initialize kernel cmdline + * @alloc_current: current boot allocation address (counting down + * from sp_limit) + * @cmd_start: pointer to a ulong variable, will hold cmdline start + * @cmd_end: pointer to a ulong variable, will hold cmdline end + * + * get_boot_cmdline() allocates space for kernel command line below + * provided alloc_current address. If "bootargs" U-boot environemnt + * variable is present its contents is copied to allocated kernel + * command line. + * + * returns: + * alloc_current after cmdline allocation + */ +ulong get_boot_cmdline (ulong alloc_current, ulong *cmd_start, ulong *cmd_end) +{ + char *cmdline; + char *s; + + cmdline = (char *)((alloc_current - CFG_BARGSIZE) & ~0xF); + + if ((s = getenv("bootargs")) == NULL) + s = ""; + + strcpy(cmdline, s); + + *cmd_start = (ulong) & cmdline[0]; + *cmd_end = *cmd_start + strlen(cmdline); + + debug ("## cmdline at 0x%08lx ... 0x%08lx\n", *cmd_start, *cmd_end); + + return (ulong)cmdline; +} + +/** + * get_boot_kbd - allocate and initialize kernel copy of board info + * @alloc_current: current boot allocation address (counting down + * from sp_limit) + * @kbd: double pointer to board info data + * + * get_boot_kbd() - allocates space for kernel copy of board info data. + * Space is allocated below provided alloc_current address and kernel + * board info is initialized with the current u-boot board info data. + * + * returns: + * alloc_current after kbd allocation + */ +ulong get_boot_kbd (ulong alloc_current, bd_t **kbd) +{ + *kbd = (bd_t *) (((ulong)alloc_current - sizeof(bd_t)) & ~0xF); + **kbd = *(gd->bd); + + debug ("## kernel board info at 0x%08lx\n", (ulong)*kbd); + +#if defined(DEBUG) && defined(CONFIG_CMD_BDI) + do_bdinfo(NULL, 0, 0, NULL); +#endif + + return (ulong)*kbd; } #endif /* CONFIG_PPC || CONFIG_M68K */ -#endif /* USE_HOSTCC */
+#endif /* USE_HOSTCC */ diff --git a/include/image.h b/include/image.h index a8cb1da..dbbbee9 100644 --- a/include/image.h +++ b/include/image.h @@ -343,9 +343,15 @@ void get_ramdisk (cmd_tbl_t *cmdtp, int flag, int argc, char *argv[], ulong *rd_start, ulong *rd_end);
#if defined(CONFIG_PPC) || defined(CONFIG_M68K) -void ramdisk_high (ulong rd_data_start, ulong rd_len, bd_t *kbd, ulong sp_limit, - ulong sp, ulong *initrd_start, ulong *initrd_end); +ulong ramdisk_high (ulong alloc_current, ulong rd_data, ulong rd_len, + bd_t *kbd, ulong sp_limit, ulong sp, + ulong *initrd_start, ulong *initrd_end); + +ulong get_boot_sp_limit (ulong sp); +ulong get_boot_cmdline (ulong alloc_current, ulong *cmd_start, ulong *cmd_end); +ulong get_boot_kbd (ulong alloc_current, bd_t **kbd); #endif /* CONFIG_PPC || CONFIG_M68K */ + #endif /* USE_HOSTCC */
#endif /* __IMAGE_H__ */ diff --git a/lib_m68k/bootm.c b/lib_m68k/bootm.c index 3fd38e9..ac04da0 100644 --- a/lib_m68k/bootm.c +++ b/lib_m68k/bootm.c @@ -29,6 +29,9 @@ #include <watchdog.h> #include <environment.h> #include <asm/byteorder.h> +#ifdef CONFIG_SHOW_BOOT_PROGRESS +# include <status_led.h> +#endif
DECLARE_GLOBAL_DATA_PTR;
@@ -37,27 +40,19 @@ DECLARE_GLOBAL_DATA_PTR; #define LINUX_MAX_ENVS 256 #define LINUX_MAX_ARGS 256
-#ifdef CONFIG_SHOW_BOOT_PROGRESS -# include <status_led.h> -# define SHOW_BOOT_PROGRESS(arg) show_boot_progress(arg) -#else -# define SHOW_BOOT_PROGRESS(arg) -#endif - static ulong get_sp (void); +static void set_clocks_in_mhz (bd_t *kbd);
void do_bootm_linux(cmd_tbl_t * cmdtp, int flag, int argc, char *argv[], image_header_t *hdr, int verify) { - ulong sp_limit; + ulong sp, sp_limit, alloc_current;
ulong rd_data_start, rd_data_end, rd_len; ulong initrd_start, initrd_end;
ulong cmd_start, cmd_end; - char *cmdline; - char *s; bd_t *kbd; void (*kernel) (bd_t *, ulong, ulong, ulong, ulong);
@@ -70,41 +65,18 @@ void do_bootm_linux(cmd_tbl_t * cmdtp, int flag, * memory, which means far enough below the current stack * pointer. */ - sp_limit = get_sp(); - - debug("## Current stack ends at 0x%08lX ", sp_limit); - - sp_limit -= 2048; /* just to be sure */ - if (sp_limit > CFG_BOOTMAPSZ) - sp_limit = CFG_BOOTMAPSZ; - sp_limit &= ~0xF; - - debug("=> set upper limit to 0x%08lX\n", sp_limit); - - cmdline = (char *)((sp_limit - CFG_BARGSIZE) & ~0xF); - kbd = (bd_t *) (((ulong) cmdline - sizeof(bd_t)) & ~0xF); - - if ((s = getenv("bootargs")) == NULL) - s = ""; - - strcpy(cmdline, s); - - cmd_start = (ulong) & cmdline[0]; - cmd_end = cmd_start + strlen(cmdline); - - *kbd = *(gd->bd); + sp = get_sp(); + debug ("## Current stack ends at 0x%08lx ", sp);
-#ifdef DEBUG - printf("## cmdline at 0x%08lX ... 0x%08lX\n", cmd_start, cmd_end); + alloc_current = sp_limit = get_boot_sp_limit(sp); + debug ("=> set upper limit to 0x%08lx\n", sp_limit);
- do_bdinfo(NULL, 0, 0, NULL); -#endif + /* allocate space and init command line */ + alloc_current = get_boot_cmdline (alloc_current, &cmd_start, &cmd_end);
- if ((s = getenv("clocks_in_mhz")) != NULL) { - /* convert all clock information to MHz */ - kbd->bi_intfreq /= 1000000L; - kbd->bi_busfreq /= 1000000L; - } + /* allocate space for kernel copy of board info */ + alloc_current = get_boot_kbd (alloc_current, &kbd); + set_clocks_in_mhz(kbd);
/* find kernel */ kernel = @@ -115,13 +87,14 @@ void do_bootm_linux(cmd_tbl_t * cmdtp, int flag, IH_ARCH_M68K, &rd_data_start, &rd_data_end);
rd_len = rd_data_end - rd_data_start; - ramdisk_high (rd_data_start, rd_len, kdb, sp_limit, get_sp (), + alloc_current = ramdisk_high (alloc_current, rd_data_start, rd_len, + kbd, sp_limit, get_sp (), &initrd_start, &initrd_end);
debug("## Transferring control to Linux (at address %08lx) ...\n", (ulong) kernel);
- SHOW_BOOT_PROGRESS(15); + show_boot_progress (15);
/* * Linux Kernel Parameters (passing board info data): @@ -144,3 +117,14 @@ static ulong get_sp (void)
return sp; } + +static void set_clocks_in_mhz (bd_t *kbd) +{ + char *s; + + if ((s = getenv("clocks_in_mhz")) != NULL) { + /* convert all clock information to MHz */ + kbd->bi_intfreq /= 1000000L; + kbd->bi_busfreq /= 1000000L; + } +} diff --git a/lib_ppc/bootm.c b/lib_ppc/bootm.c index d73d2fd..7eb8712 100644 --- a/lib_ppc/bootm.c +++ b/lib_ppc/bootm.c @@ -51,10 +51,7 @@ DECLARE_GLOBAL_DATA_PTR;
extern int do_reset (cmd_tbl_t *cmdtp, int flag, int argc, char *argv[]); static ulong get_sp (void); - -#if defined(CONFIG_CMD_BDI) -extern int do_bdinfo (cmd_tbl_t *cmdtp, int flag, int argc, char *argv[]); -#endif +static void set_clocks_in_mhz (bd_t *kbd);
void __attribute__((noinline)) do_bootm_linux(cmd_tbl_t *cmdtp, int flag, @@ -62,14 +59,12 @@ do_bootm_linux(cmd_tbl_t *cmdtp, int flag, image_header_t *hdr, int verify) { + ulong sp, sp_limit, alloc_current; + ulong initrd_start, initrd_end; ulong rd_data_start, rd_data_end, rd_len;
ulong cmd_start, cmd_end; - char *cmdline; - - ulong sp_limit; - char *s; bd_t *kbd; void (*kernel)(bd_t *, ulong, ulong, ulong, ulong);
@@ -88,60 +83,18 @@ do_bootm_linux(cmd_tbl_t *cmdtp, int flag, * memory, which means far enough below the current stack * pointer. */ + sp = get_sp(); + debug ("## Current stack ends at 0x%08lx ", sp);
- sp_limit = get_sp(); - debug ("## Current stack ends at 0x%08lX ", sp_limit); - - sp_limit -= 2048; /* just to be sure */ - if (sp_limit > CFG_BOOTMAPSZ) - sp_limit = CFG_BOOTMAPSZ; - sp_limit &= ~0xF; - - debug ("=> set upper limit to 0x%08lX\n", sp_limit); + alloc_current = sp_limit = get_boot_sp_limit(sp); + debug ("=> set upper limit to 0x%08lx\n", sp_limit);
- cmdline = (char *)((sp_limit - CFG_BARGSIZE) & ~0xF); - kbd = (bd_t *)(((ulong)cmdline - sizeof(bd_t)) & ~0xF); + /* allocate space and init command line */ + alloc_current = get_boot_cmdline (alloc_current, &cmd_start, &cmd_end);
- if ((s = getenv("bootargs")) == NULL) - s = ""; - - strcpy (cmdline, s); - - cmd_start = (ulong)&cmdline[0]; - cmd_end = cmd_start + strlen(cmdline); - - *kbd = *(gd->bd); - -#ifdef DEBUG - printf ("## cmdline at 0x%08lX ... 0x%08lX\n", cmd_start, cmd_end); - -#if defined(CONFIG_CMD_BDI) - do_bdinfo (NULL, 0, 0, NULL); -#endif -#endif - - if ((s = getenv ("clocks_in_mhz")) != NULL) { - /* convert all clock information to MHz */ - kbd->bi_intfreq /= 1000000L; - kbd->bi_busfreq /= 1000000L; -#if defined(CONFIG_MPC8220) - kbd->bi_inpfreq /= 1000000L; - kbd->bi_pcifreq /= 1000000L; - kbd->bi_pevfreq /= 1000000L; - kbd->bi_flbfreq /= 1000000L; - kbd->bi_vcofreq /= 1000000L; -#endif -#if defined(CONFIG_CPM2) - kbd->bi_cpmfreq /= 1000000L; - kbd->bi_brgfreq /= 1000000L; - kbd->bi_sccfreq /= 1000000L; - kbd->bi_vco /= 1000000L; -#endif -#if defined(CONFIG_MPC5xxx) - kbd->bi_ipbfreq /= 1000000L; - kbd->bi_pcifreq /= 1000000L; -#endif /* CONFIG_MPC5xxx */ - } + /* allocate space for kernel copy of board info */ + alloc_current = get_boot_kbd (alloc_current, &kbd); + set_clocks_in_mhz(kbd);
/* find kernel */ kernel = (void (*)(bd_t *, ulong, ulong, ulong, ulong))image_get_ep (hdr); @@ -152,7 +105,8 @@ do_bootm_linux(cmd_tbl_t *cmdtp, int flag,
rd_len = rd_data_end - rd_data_start;
- ramdisk_high (rd_data_start, rd_len, kbd, sp_limit, get_sp (), + alloc_current = ramdisk_high (alloc_current, rd_data_start, rd_len, + kbd, sp_limit, get_sp (), &initrd_start, &initrd_end);
#if defined(CONFIG_OF_LIBFDT) @@ -266,8 +220,8 @@ do_bootm_linux(cmd_tbl_t *cmdtp, int flag,
of_len = be32_to_cpu(fdt_totalsize(of_data));
- /* position on a 4K boundary before the kbd */ - of_start = (ulong)kbd - of_len; + /* position on a 4K boundary before the alloc_current */ + of_start = alloc_current - of_len; of_start &= ~(4096 - 1); /* align on page */ debug ("## device tree at 0x%08lX ... 0x%08lX (len=%ld=0x%lX)\n", of_data, of_data + of_len - 1, of_len, of_len); @@ -353,6 +307,34 @@ static ulong get_sp (void) return sp; }
+static void set_clocks_in_mhz (bd_t *kbd) +{ + char *s; + + if ((s = getenv ("clocks_in_mhz")) != NULL) { + /* convert all clock information to MHz */ + kbd->bi_intfreq /= 1000000L; + kbd->bi_busfreq /= 1000000L; +#if defined(CONFIG_MPC8220) + kbd->bi_inpfreq /= 1000000L; + kbd->bi_pcifreq /= 1000000L; + kbd->bi_pevfreq /= 1000000L; + kbd->bi_flbfreq /= 1000000L; + kbd->bi_vcofreq /= 1000000L; +#endif +#if defined(CONFIG_CPM2) + kbd->bi_cpmfreq /= 1000000L; + kbd->bi_brgfreq /= 1000000L; + kbd->bi_sccfreq /= 1000000L; + kbd->bi_vco /= 1000000L; +#endif +#if defined(CONFIG_MPC5xxx) + kbd->bi_ipbfreq /= 1000000L; + kbd->bi_pcifreq /= 1000000L; +#endif /* CONFIG_MPC5xxx */ + } +} + #if defined(CONFIG_OF_LIBFDT) static void fdt_error (const char *msg) {

Move FDT blob finding and relocation to a dedicated get_fdt() routine. It increases code readability and will make adding support for new uImage format easier.
Signed-off-by: Marian Balakowicz m8@semihalf.com ---
lib_ppc/bootm.c | 285 ++++++++++++++++++++++++++++++------------------------- 1 files changed, 158 insertions(+), 127 deletions(-)
diff --git a/lib_ppc/bootm.c b/lib_ppc/bootm.c index 7eb8712..69ec459 100644 --- a/lib_ppc/bootm.c +++ b/lib_ppc/bootm.c @@ -41,6 +41,9 @@ #include <fdt_support.h>
static void fdt_error (const char *msg); +static ulong get_fdt (ulong alloc_current, cmd_tbl_t *cmdtp, int flag, + int argc, char *argv[], + image_header_t *hdr, char **of_flat_tree); #endif
#ifdef CFG_INIT_RAM_LOCK @@ -69,9 +72,7 @@ do_bootm_linux(cmd_tbl_t *cmdtp, int flag, void (*kernel)(bd_t *, ulong, ulong, ulong, ulong);
#if defined(CONFIG_OF_LIBFDT) - image_header_t *fdt_hdr; - char *of_flat_tree = NULL; - ulong of_data = 0; + char *of_flat_tree; #endif
/* @@ -111,131 +112,9 @@ do_bootm_linux(cmd_tbl_t *cmdtp, int flag,
#if defined(CONFIG_OF_LIBFDT) /* find flattened device tree */ - if(argc > 3) { - of_flat_tree = (char *) simple_strtoul(argv[3], NULL, 16); - fdt_hdr = (image_header_t *)of_flat_tree; - - if (fdt_check_header (of_flat_tree) == 0) { -#ifndef CFG_NO_FLASH - if (addr2info((ulong)of_flat_tree) != NULL) - of_data = (ulong)of_flat_tree; -#endif - } else if (image_check_magic (fdt_hdr)) { - ulong image_start, image_end; - ulong load_start, load_end; - - printf ("## Flat Device Tree at %08lX\n", fdt_hdr); - print_image_hdr (fdt_hdr); - - image_start = (ulong)fdt_hdr; - image_end = image_get_image_end (fdt_hdr); - - load_start = image_get_load (fdt_hdr); - load_end = load_start + image_get_data_size (fdt_hdr); - - if ((load_start < image_end) && (load_end > image_start)) { - fdt_error ("fdt overwritten"); - do_reset (cmdtp, flag, argc, argv); - } - - puts (" Verifying Checksum ... "); - if (!image_check_hcrc (fdt_hdr)) { - fdt_error ("fdt header checksum invalid"); - do_reset (cmdtp, flag, argc, argv); - } - - if (!image_check_dcrc (fdt_hdr)) { - fdt_error ("fdt checksum invalid"); - do_reset (cmdtp, flag, argc, argv); - } - puts ("OK\n"); - - if (!image_check_type (fdt_hdr, IH_TYPE_FLATDT)) { - fdt_error ("uImage is not a fdt"); - do_reset (cmdtp, flag, argc, argv); - } - if (image_get_comp (fdt_hdr) != IH_COMP_NONE) { - fdt_error ("uImage is compressed"); - do_reset (cmdtp, flag, argc, argv); - } - if (fdt_check_header (of_flat_tree + image_get_header_size ()) != 0) { - fdt_error ("uImage data is not a fdt"); - do_reset (cmdtp, flag, argc, argv); - } - - memmove ((void *)image_get_load (fdt_hdr), - (void *)(of_flat_tree + image_get_header_size ()), - image_get_data_size (fdt_hdr)); - - of_flat_tree = (char *)image_get_load (fdt_hdr); - } else { - fdt_error ("Did not find a Flattened Device Tree"); - do_reset (cmdtp, flag, argc, argv); - } - printf (" Booting using the fdt at 0x%x\n", - of_flat_tree); - } else if (image_check_type (hdr, IH_TYPE_MULTI)) { - ulong fdt_data, fdt_len; - - image_multi_getimg (hdr, 2, &fdt_data, &fdt_len); - if (fdt_len) { - - of_flat_tree = (char *)fdt_data; - -#ifndef CFG_NO_FLASH - /* move the blob if it is in flash (set of_data to !null) */ - if (addr2info ((ulong)of_flat_tree) != NULL) - of_data = (ulong)of_flat_tree; -#endif - - if (fdt_check_header (of_flat_tree) != 0) { - fdt_error ("image is not a fdt"); - do_reset (cmdtp, flag, argc, argv); - } - - if (be32_to_cpu (fdt_totalsize (of_flat_tree)) != fdt_len) { - fdt_error ("fdt size != image size"); - do_reset (cmdtp, flag, argc, argv); - } - } - } -#endif - - -#if defined(CONFIG_OF_LIBFDT) - -#ifdef CFG_BOOTMAPSZ - /* - * The blob must be within CFG_BOOTMAPSZ, - * so we flag it to be copied if it is not. - */ - if (of_flat_tree >= (char *)CFG_BOOTMAPSZ) - of_data = (ulong)of_flat_tree; -#endif - - /* move of_flat_tree if needed */ - if (of_data) { - int err; - ulong of_start, of_len; - - of_len = be32_to_cpu(fdt_totalsize(of_data)); - - /* position on a 4K boundary before the alloc_current */ - of_start = alloc_current - of_len; - of_start &= ~(4096 - 1); /* align on page */ - debug ("## device tree at 0x%08lX ... 0x%08lX (len=%ld=0x%lX)\n", - of_data, of_data + of_len - 1, of_len, of_len); + alloc_current = get_fdt (alloc_current, + cmdtp, flag, argc, argv, hdr, &of_flat_tree);
- 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_data, (void *)of_start, of_len); - if (err != 0) { - fdt_error ("fdt move failed"); - do_reset (cmdtp, flag, argc, argv); - } - puts ("OK\n"); - } /* * Add the chosen node if it doesn't exist, add the env and bd_t * if the user wants it (the logic is in the subroutines). @@ -342,4 +221,156 @@ static void fdt_error (const char *msg) puts (msg); puts (" - must RESET the board to recover.\n"); } + +static ulong get_fdt (ulong alloc_current, + cmd_tbl_t *cmdtp, int flag, + int argc, char *argv[], + image_header_t *hdr, char **of_flat_tree) +{ + image_header_t *fdt_hdr; + ulong fdt_relocate = 0; + char *fdt = NULL; + ulong new_alloc_current; + + if(argc > 3) { + fdt = (char *)simple_strtoul (argv[3], NULL, 16); + fdt_hdr = (image_header_t *)fdt; + + if (fdt_check_header (fdt) == 0) { + printf ("## Flattened Device Tree blob at %08lx\n", fdt); +#ifndef CFG_NO_FLASH + if (addr2info ((ulong)fdt) != NULL) + fdt_relocate = 1; +#endif + } else if (image_check_magic (fdt_hdr)) { + ulong image_start, image_end; + ulong load_start, load_end; + + printf ("## Flattened Device Tree Image at %08lx\n", + fdt_hdr); + + print_image_hdr (fdt_hdr); + + image_start = (ulong)fdt_hdr; + image_end = image_get_image_end (fdt_hdr); + + load_start = image_get_load (fdt_hdr); + load_end = load_start + image_get_data_size (fdt_hdr); + + if ((load_start < image_end) && (load_end > image_start)) { + fdt_error ("fdt overwritten"); + do_reset (cmdtp, flag, argc, argv); + } + + puts (" Verifying Checksum ... "); + if (!image_check_hcrc (fdt_hdr)) { + fdt_error ("fdt header checksum invalid"); + do_reset (cmdtp, flag, argc, argv); + } + + if (!image_check_dcrc (fdt_hdr)) { + fdt_error ("fdt checksum invalid"); + do_reset (cmdtp, flag, argc, argv); + } + puts ("OK\n"); + + if (!image_check_type (fdt_hdr, IH_TYPE_FLATDT)) { + fdt_error ("uImage is not a fdt"); + do_reset (cmdtp, flag, argc, argv); + } + if (image_get_comp (fdt_hdr) != IH_COMP_NONE) { + fdt_error ("uImage is compressed"); + do_reset (cmdtp, flag, argc, argv); + } + if (fdt_check_header ((char *)image_get_data (fdt_hdr)) != 0) { + fdt_error ("uImage data is not a fdt"); + do_reset (cmdtp, flag, argc, argv); + } + + memmove ((void *)image_get_load (fdt_hdr), + (void *)image_get_data (fdt_hdr), + image_get_data_size (fdt_hdr)); + + fdt = (char *)image_get_load (fdt_hdr); + } else { + fdt_error ("Did not find a Flattened Device Tree"); + do_reset (cmdtp, flag, argc, argv); + } + printf (" Booting using the fdt at 0x%x\n", + fdt); + } else if (image_check_type (hdr, IH_TYPE_MULTI)) { + ulong fdt_data, fdt_len; + + printf ("## Flattened Device Tree from multi " + "component Image at %08lX\n", (ulong)hdr); + + image_multi_getimg (hdr, 2, &fdt_data, &fdt_len); + if (fdt_len) { + + fdt = (char *)fdt_data; + printf (" Booting using the fdt at 0x%x\n", fdt); + +#ifndef CFG_NO_FLASH + /* move the blob if it is in flash (set of_relocte) */ + if (addr2info ((ulong)fdt) != NULL) + fdt_relocate = 1; +#endif + + if (fdt_check_header (fdt) != 0) { + fdt_error ("image is not a fdt"); + do_reset (cmdtp, flag, argc, argv); + } + + if (be32_to_cpu (fdt_totalsize (fdt)) != fdt_len) { + fdt_error ("fdt size != image size"); + do_reset (cmdtp, flag, argc, argv); + } + } else { + debug (" Did not find a Flattened Device Tree"); + } + } + +#ifdef CFG_BOOTMAPSZ + /* + * The blob must be within CFG_BOOTMAPSZ, + * so we flag it to be copied if it is not. + */ + if (fdt >= (char *)CFG_BOOTMAPSZ) + fdt_relocate = 1; +#endif + + /* move flattend device tree if needed */ + if (fdt_relocate) { + int err; + ulong of_start, of_len; + + of_len = be32_to_cpu (fdt_totalsize (fdt)); + + /* position on a 4K boundary before the alloc_current */ + of_start = alloc_current - of_len; + of_start &= ~(4096 - 1); /* align on page */ + + debug ("## device tree at 0x%08lX ... 0x%08lX (len=%ld=0x%lX)\n", + (ulong)fdt, (ulong)fdt + of_len - 1, + of_len, of_len); + + printf (" Loading Device Tree to %08lx, end %08lx ... ", + of_start, of_start + of_len - 1); + + err = fdt_open_into (fdt, (void *)of_start, of_len); + if (err != 0) { + fdt_error ("fdt move failed"); + do_reset (cmdtp, flag, argc, argv); + } + puts ("OK\n"); + + *of_flat_tree = (char *)of_start; + new_alloc_current = of_start; + } else { + *of_flat_tree = fdt; + new_alloc_current = alloc_current; + } + + return new_alloc_current; +} #endif

Verification of the kernel image (in old format) and finding kernel data is moved to a dedicated routine. The routine will also hold support for, to be added, new image format.
Signed-off-by: Marian Balakowicz m8@semihalf.com ---
common/cmd_bootm.c | 181 +++++++++++++++++++++++++++++++--------------------- 1 files changed, 107 insertions(+), 74 deletions(-)
diff --git a/common/cmd_bootm.c b/common/cmd_bootm.c index 8b6616b..2ddb191 100644 --- a/common/cmd_bootm.c +++ b/common/cmd_bootm.c @@ -74,6 +74,9 @@ static void fixup_silent_linux (void); #endif
static void print_type (image_header_t *hdr); +static image_header_t *get_kernel (cmd_tbl_t *cmdtp, int flag, + int argc, char *argv[], int verify, + ulong *os_data, ulong *os_len); extern int do_reset (cmd_tbl_t *cmdtp, int flag, int argc, char *argv[]);
/* @@ -121,85 +124,17 @@ int do_bootm (cmd_tbl_t *cmdtp, int flag, int argc, char *argv[]) int verify = getenv_verify();
image_header_t *hdr; - ulong img_addr; ulong os_data, os_len;
ulong image_start, image_end; ulong load_start, load_end;
- - if (argc < 2) { - img_addr = load_addr; - } else { - img_addr = simple_strtoul(argv[1], NULL, 16); - } - - show_boot_progress (1); - printf ("## Booting image at %08lx ...\n", img_addr); - -#ifdef CONFIG_HAS_DATAFLASH - if (addr_dataflash (img_addr)){ - hdr = (image_header_t *)CFG_LOAD_ADDR; - read_dataflash (img_addr, image_get_header_size (), (char *)hdr); - } else -#endif - hdr = (image_header_t *)img_addr; - - if (!image_check_magic(hdr)) { - puts ("Bad Magic Number\n"); - show_boot_progress (-1); - return 1; - } - show_boot_progress (2); - - if (!image_check_hcrc (hdr)) { - puts ("Bad Header Checksum\n"); - show_boot_progress (-2); + /* get kernel image header, start address and length */ + hdr = get_kernel (cmdtp, flag, argc, argv, verify, + &os_data, &os_len); + if (hdr == NULL) return 1; - } - show_boot_progress (3);
-#ifdef CONFIG_HAS_DATAFLASH - if (addr_dataflash (img_addr)) - read_dataflash (img_addr + image_get_header_size (), - image_get_data_size (hdr), - (char *)image_get_data (hdr)); -#endif - - /* uImage is in a system RAM, pointed to by hdr */ - print_image_hdr (hdr); - - if (verify) { - puts (" Verifying Checksum ... "); - if (!image_check_dcrc (hdr)) { - printf ("Bad Data CRC\n"); - show_boot_progress (-3); - return 1; - } - puts ("OK\n"); - } - show_boot_progress (4); - - if (!image_check_target_arch (hdr)) { - printf ("Unsupported Architecture 0x%x\n", image_get_arch (hdr)); - show_boot_progress (-4); - return 1; - } - show_boot_progress (5); - - switch (image_get_type (hdr)) { - case IH_TYPE_KERNEL: - os_data = image_get_data (hdr); - os_len = image_get_data_size (hdr); - break; - case IH_TYPE_MULTI: - image_multi_getimg (hdr, 0, &os_data, &os_len); - break; - default: - printf ("Wrong Image Type for %s command\n", cmdtp->name); - show_boot_progress (-5); - return 1; - } show_boot_progress (6);
/* @@ -229,7 +164,7 @@ int do_bootm (cmd_tbl_t *cmdtp, int flag, int argc, char *argv[])
switch (image_get_comp (hdr)) { case IH_COMP_NONE: - if (image_get_load (hdr) == img_addr) { + if (image_get_load (hdr) == (ulong)hdr) { printf (" XIP %s ... ", type_name); } else { printf (" Loading %s ... ", type_name); @@ -280,6 +215,7 @@ int do_bootm (cmd_tbl_t *cmdtp, int flag, int argc, char *argv[]) return 1; } puts ("OK\n"); + debug (" kernel loaded at 0x%08lx, end = 0x%08lx\n", load_start, load_end); show_boot_progress (7);
if ((load_start < image_end) && (load_end > image_start)) { @@ -340,6 +276,103 @@ int do_bootm (cmd_tbl_t *cmdtp, int flag, int argc, char *argv[]) return 1; }
+/** + * get_kernel - find kernel image + * @os_data: pointer to a ulong variable, will hold os data start address + * @os_len: pointer to a ulong variable, will hold os data length + * + * get_kernel() tries to find a kernel image, verifies its integrity + * and locates kernel data. + * + * returns: + * pointer to image header if valid image was found, plus kernel start + * address and length, otherwise NULL + */ +static image_header_t *get_kernel (cmd_tbl_t *cmdtp, int flag, + int argc, char *argv[], int verify, + ulong *os_data, ulong *os_len) +{ + image_header_t *hdr; + ulong img_addr; + + if (argc < 2) { + img_addr = load_addr; + } else { + img_addr = simple_strtoul(argv[1], NULL, 16); + } + + show_boot_progress (1); + printf ("## Booting image at %08lx ...\n", img_addr); + +#ifdef CONFIG_HAS_DATAFLASH + if (addr_dataflash (img_addr)){ + hdr = (image_header_t *)CFG_LOAD_ADDR; + read_dataflash (img_addr, image_get_header_size (), (char *)hdr); + } else +#endif + hdr = (image_header_t *)img_addr; + + if (!image_check_magic(hdr)) { + puts ("Bad Magic Number\n"); + show_boot_progress (-1); + return NULL; + } + show_boot_progress (2); + + if (!image_check_hcrc (hdr)) { + puts ("Bad Header Checksum\n"); + show_boot_progress (-2); + return NULL; + } + show_boot_progress (3); + +#ifdef CONFIG_HAS_DATAFLASH + if (addr_dataflash (img_addr)) + read_dataflash (img_addr + image_get_header_size (), + image_get_data_size (hdr), + (char *)image_get_data (hdr)); +#endif + + /* uImage is in a system RAM, pointed to by hdr */ + print_image_hdr (hdr); + + if (verify) { + puts (" Verifying Checksum ... "); + if (!image_check_dcrc (hdr)) { + printf ("Bad Data CRC\n"); + show_boot_progress (-3); + return NULL; + } + puts ("OK\n"); + } + show_boot_progress (4); + + if (!image_check_target_arch (hdr)) { + printf ("Unsupported Architecture 0x%x\n", image_get_arch (hdr)); + show_boot_progress (-4); + return NULL; + } + show_boot_progress (5); + + switch (image_get_type (hdr)) { + case IH_TYPE_KERNEL: + *os_data = image_get_data (hdr); + *os_len = image_get_data_size (hdr); + break; + case IH_TYPE_MULTI: + image_multi_getimg (hdr, 0, os_data, os_len); + break; + default: + printf ("Wrong Image Type for %s command\n", cmdtp->name); + show_boot_progress (-5); + return NULL; + } + debug (" kernel data at 0x%08lx, end = 0x%08lx\n", + *os_data, *os_data + *os_len); + + return hdr; +} + U_BOOT_CMD( bootm, CFG_MAXARGS, 1, do_bootm, "bootm - boot application image from memory\n", @@ -502,7 +535,7 @@ U_BOOT_CMD( #endif
/*******************************************************************/ -/* */ +/* helper routines */ /*******************************************************************/ void print_image_hdr (image_header_t *hdr) {

On Feb 1, 2008, at 6:00 AM, Marian Balakowicz wrote:
This is the third patch-set of the new uImage format work. It concludes the phase of clean-up and reorganization of the old format code, preparing the ground for adding the code implementing the new format.
All the new uImage patches sent to the list so far, as well as updates resulting from the feedback received, will be soon available from the new-image branch of the u-boot-testing repository (there will be a separate announcement).
The completion of the clean-up phase is a good moment to review the patches posted to date, and help with testing. This work affects all architectures and operating systems, so it would be much appreciated if people could give u-boot-testing#new-image a try and report back. So far, the changes were tested on a lite5200b board and successfully built for ppc, arm, mips and coldfire targets.
Work is now ongoing on adding support for the new format, results will be posted to the list, and also available from u-boot-testing#new- image. Once the implementation is complete, and the code is reviewed and tested, it will be merged to the master.
Marian Balakowicz (6): [new uImage] Move kernel data find code to get_kernel() routine [new uImage] Cleanup FDT handling in PPC do_boot_linux() [new uImage] Cleanup PPC and M68K do_bootm_linux() boot allocations [new uImage] Move PPC and M68K ramdisk loading to a common routine [new uImage] Removed dead ramdisk code on microblaze architecture [new uImage] Factor out common image_get_ramdisk() routine
Have you thought about passing load_end into the do_bootm_* commands. I think this will help us do better allocation/memory management in bootm.
- k
participants (4)
-
Bartlomiej Sieka
-
Kumar Gala
-
Marian Balakowicz
-
Michal Simek