diff options
author | Marian Balakowicz <m8@semihalf.com> | 2008-02-29 14:58:34 +0100 |
---|---|---|
committer | Marian Balakowicz <m8@semihalf.com> | 2008-02-29 14:58:34 +0100 |
commit | 9a4daad0a35eb5143037eea9f786a3e9d672bdd6 (patch) | |
tree | 69650696145431c6b48d0792b4d6bdf8b714d37a /common/image.c | |
parent | e18489e8c27e843e337258fb00f2652ff0f43b92 (diff) |
[new uImage] Update naming convention for bootm/uImage related code
This patch introduces the following prefix convention for the
image format handling and bootm related code:
genimg_ - dual format shared code
image_ - legacy uImage format specific code
fit_ - new uImage format specific code
boot_ - booting process related code
Related routines are renamed and a few pieces of code are moved around and
re-grouped.
Signed-off-by: Marian Balakowicz <m8@semihalf.com>
Diffstat (limited to 'common/image.c')
-rw-r--r-- | common/image.c | 429 |
1 files changed, 218 insertions, 211 deletions
diff --git a/common/image.c b/common/image.c index 9e446faa730..99ed3b8aa86 100644 --- a/common/image.c +++ b/common/image.c @@ -68,6 +68,9 @@ static image_header_t* image_get_ramdisk (cmd_tbl_t *cmdtp, int flag, unsigned long crc32 (unsigned long, const unsigned char *, unsigned int); +/*****************************************************************************/ +/* Legacy format routines */ +/*****************************************************************************/ int image_check_hcrc (image_header_t *hdr) { ulong hcrc; @@ -120,61 +123,6 @@ int image_check_dcrc_wd (image_header_t *hdr, ulong chunksz) return (dcrc == image_get_dcrc (hdr)); } -int getenv_verify (void) -{ - char *s = getenv ("verify"); - return (s && (*s == 'n')) ? 0 : 1; -} - -int getenv_autostart (void) -{ - char *s = getenv ("autostart"); - return (s && (*s == 'n')) ? 0 : 1; -} - -ulong getenv_bootm_low(void) -{ - char *s = getenv ("bootm_low"); - if (s) { - ulong tmp = simple_strtoul (s, NULL, 16); - return tmp; - } - -#ifdef CFG_SDRAM_BASE - return CFG_SDRAM_BASE; -#else - return 0; -#endif -} - -ulong getenv_bootm_size(void) -{ - char *s = getenv ("bootm_size"); - if (s) { - ulong tmp = simple_strtoul (s, NULL, 16); - return tmp; - } - - return gd->bd->bi_memsize; -} - -void memmove_wd (void *to, void *from, size_t len, ulong chunksz) -{ -#if defined(CONFIG_HW_WATCHDOG) || defined(CONFIG_WATCHDOG) - while (len > 0) { - size_t tail = (len > chunksz) ? chunksz : len; - WATCHDOG_RESET (); - memmove (to, from, tail); - to += tail; - from += tail; - len -= tail; - } -#else /* !(CONFIG_HW_WATCHDOG || CONFIG_WATCHDOG) */ - memmove (to, from, len); -#endif /* CONFIG_HW_WATCHDOG || CONFIG_WATCHDOG */ -} -#endif /* USE_HOSTCC */ - /** * image_multi_count - get component (sub-image) count * @hdr: pointer to the header of the multi component image @@ -262,7 +210,185 @@ void image_multi_getimg (image_header_t *hdr, ulong idx, } #ifndef USE_HOSTCC -const char* image_get_os_name (uint8_t os) +static void image_print_type (image_header_t *hdr) +{ + const char *os, *arch, *type, *comp; + + os = genimg_get_os_name (image_get_os (hdr)); + arch = genimg_get_arch_name (image_get_arch (hdr)); + type = genimg_get_type_name (image_get_type (hdr)); + comp = genimg_get_comp_name (image_get_comp (hdr)); + + printf ("%s %s %s (%s)", arch, os, type, comp); +} + +void image_print_contents (image_header_t *hdr) +{ +#if defined(CONFIG_TIMESTAMP) || defined(CONFIG_CMD_DATE) + time_t timestamp = (time_t)image_get_time (hdr); + struct rtc_time tm; +#endif + + printf (" Image Name: %.*s\n", IH_NMLEN, image_get_name (hdr)); + +#if defined(CONFIG_TIMESTAMP) || defined(CONFIG_CMD_DATE) + to_tm (timestamp, &tm); + printf (" Created: %4d-%02d-%02d %2d:%02d:%02d UTC\n", + tm.tm_year, tm.tm_mon, tm.tm_mday, + tm.tm_hour, tm.tm_min, tm.tm_sec); +#endif + puts (" Image Type: "); + image_print_type (hdr); + + printf ("\n Data Size: %d Bytes = ", image_get_data_size (hdr)); + print_size (image_get_data_size (hdr), "\n"); + printf (" Load Address: %08x\n" + " Entry Point: %08x\n", + image_get_load (hdr), image_get_ep (hdr)); + + if (image_check_type (hdr, IH_TYPE_MULTI)) { + int i; + ulong data, len; + ulong count = image_multi_count (hdr); + + puts (" Contents:\n"); + for (i = 0; i < count; i++) { + image_multi_getimg (hdr, i, &data, &len); + printf (" Image %d: %8ld Bytes = ", i, len); + print_size (len, "\n"); + } + } +} + +/** + * 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, return NULL + */ +static 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); + rd_hdr = (image_header_t *)rd_addr; + + if (!image_check_magic (rd_hdr)) { + puts ("Bad Magic Number\n"); + show_boot_progress (-10); + return NULL; + } + + if (!image_check_hcrc (rd_hdr)) { + puts ("Bad Header Checksum\n"); + show_boot_progress (-11); + return NULL; + } + + show_boot_progress (10); + image_print_contents (rd_hdr); + + if (verify) { + puts(" Verifying Checksum ... "); + if (!image_check_dcrc_wd (rd_hdr, CHUNKSZ)) { + puts ("Bad Data CRC\n"); + show_boot_progress (-12); + return NULL; + } + 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", + genimg_get_arch_name(arch)); + show_boot_progress (-13); + return NULL; + } + + return rd_hdr; +} + +/*****************************************************************************/ +/* Shared dual-format routines */ +/*****************************************************************************/ +int getenv_verify (void) +{ + char *s = getenv ("verify"); + return (s && (*s == 'n')) ? 0 : 1; +} + +int getenv_autostart (void) +{ + char *s = getenv ("autostart"); + return (s && (*s == 'n')) ? 0 : 1; +} + +ulong getenv_bootm_low(void) +{ + char *s = getenv ("bootm_low"); + if (s) { + ulong tmp = simple_strtoul (s, NULL, 16); + return tmp; + } + +#ifdef CFG_SDRAM_BASE + return CFG_SDRAM_BASE; +#else + return 0; +#endif +} + +ulong getenv_bootm_size(void) +{ + char *s = getenv ("bootm_size"); + if (s) { + ulong tmp = simple_strtoul (s, NULL, 16); + return tmp; + } + + return gd->bd->bi_memsize; +} + +void memmove_wd (void *to, void *from, size_t len, ulong chunksz) +{ +#if defined(CONFIG_HW_WATCHDOG) || defined(CONFIG_WATCHDOG) + while (len > 0) { + size_t tail = (len > chunksz) ? chunksz : len; + WATCHDOG_RESET (); + memmove (to, from, tail); + to += tail; + from += tail; + len -= tail; + } +#else /* !(CONFIG_HW_WATCHDOG || CONFIG_WATCHDOG) */ + memmove (to, from, len); +#endif /* CONFIG_HW_WATCHDOG || CONFIG_WATCHDOG */ +} +#endif /* USE_HOSTCC */ + +const char* genimg_get_os_name (uint8_t os) { const char *name; @@ -286,7 +412,7 @@ const char* image_get_os_name (uint8_t os) return name; } -const char* image_get_arch_name (uint8_t arch) +const char* genimg_get_arch_name (uint8_t arch) { const char *name; @@ -315,7 +441,7 @@ const char* image_get_arch_name (uint8_t arch) return name; } -const char* image_get_type_name (uint8_t type) +const char* genimg_get_type_name (uint8_t type) { const char *name; @@ -334,7 +460,7 @@ const char* image_get_type_name (uint8_t type) return name; } -const char* image_get_comp_name (uint8_t comp) +const char* genimg_get_comp_name (uint8_t comp) { const char *name; @@ -348,71 +474,21 @@ const char* image_get_comp_name (uint8_t comp) return name; } -static void image_print_type (image_header_t *hdr) -{ - const char *os, *arch, *type, *comp; - - os = image_get_os_name (image_get_os (hdr)); - arch = image_get_arch_name (image_get_arch (hdr)); - type = image_get_type_name (image_get_type (hdr)); - comp = image_get_comp_name (image_get_comp (hdr)); - - printf ("%s %s %s (%s)", arch, os, type, comp); -} - -void image_print_contents (image_header_t *hdr) -{ -#if defined(CONFIG_TIMESTAMP) || defined(CONFIG_CMD_DATE) - time_t timestamp = (time_t)image_get_time (hdr); - struct rtc_time tm; -#endif - - printf (" Image Name: %.*s\n", IH_NMLEN, image_get_name (hdr)); - -#if defined(CONFIG_TIMESTAMP) || defined(CONFIG_CMD_DATE) - to_tm (timestamp, &tm); - printf (" Created: %4d-%02d-%02d %2d:%02d:%02d UTC\n", - tm.tm_year, tm.tm_mon, tm.tm_mday, - tm.tm_hour, tm.tm_min, tm.tm_sec); -#endif - puts (" Image Type: "); - image_print_type (hdr); - - printf ("\n Data Size: %d Bytes = ", image_get_data_size (hdr)); - print_size (image_get_data_size (hdr), "\n"); - printf (" Load Address: %08x\n" - " Entry Point: %08x\n", - image_get_load (hdr), image_get_ep (hdr)); - - if (image_check_type (hdr, IH_TYPE_MULTI)) { - int i; - ulong data, len; - ulong count = image_multi_count (hdr); - - puts (" Contents:\n"); - for (i = 0; i < count; i++) { - image_multi_getimg (hdr, i, &data, &len); - printf (" Image %d: %8ld Bytes = ", i, len); - print_size (len, "\n"); - } - } -} - /** - * gen_image_get_format - get image format type + * genimg_get_format - get image format type * @img_addr: image start address * - * gen_image_get_format() checks whether provided address points to a valid + * genimg_get_format() checks whether provided address points to a valid * legacy or FIT image. * * New uImage format and FDT blob are based on a libfdt. FDT blob * may be passed directly or embedded in a FIT image. In both situations - * gen_image_get_format() must be able to dectect libfdt header. + * genimg_get_format() must be able to dectect libfdt header. * * returns: * image format type or IMAGE_FORMAT_INVALID if no image is present */ -int gen_image_get_format (void *img_addr) +int genimg_get_format (void *img_addr) { ulong format = IMAGE_FORMAT_INVALID; image_header_t *hdr; @@ -435,16 +511,16 @@ int gen_image_get_format (void *img_addr) } /** - * gen_get_image - get image from special storage (if necessary) + * genimg_get_image - get image from special storage (if necessary) * @img_addr: image start address * - * gen_get_image() checks if provided image start adddress is located + * genimg_get_image() checks if provided image start adddress is located * in a dataflash storage. If so, image is moved to a system RAM memory. * * returns: * image start address after possible relocation from special storage */ -ulong gen_get_image (ulong img_addr) +ulong genimg_get_image (ulong img_addr) { ulong ram_addr = img_addr; @@ -469,7 +545,7 @@ ulong gen_get_image (ulong img_addr) read_dataflash (img_addr, h_size, (char *)ram_addr); /* get data size */ - switch (gen_image_get_format ((void *)ram_addr)) { + switch (genimg_get_format ((void *)ram_addr)) { case IMAGE_FORMAT_LEGACY: d_size = image_get_data_size ((image_header_t *)ram_addr); debug (" Legacy format image found at 0x%08lx, size 0x%08lx\n", @@ -502,77 +578,7 @@ ulong gen_get_image (ulong img_addr) } /** - * 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, return NULL - */ -static 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); - rd_hdr = (image_header_t *)rd_addr; - - if (!image_check_magic (rd_hdr)) { - puts ("Bad Magic Number\n"); - show_boot_progress (-10); - return NULL; - } - - if (!image_check_hcrc (rd_hdr)) { - puts ("Bad Header Checksum\n"); - show_boot_progress (-11); - return NULL; - } - - show_boot_progress (10); - image_print_contents (rd_hdr); - - if (verify) { - puts(" Verifying Checksum ... "); - if (!image_check_dcrc_wd (rd_hdr, CHUNKSZ)) { - puts ("Bad Data CRC\n"); - show_boot_progress (-12); - return NULL; - } - 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); - return NULL; - } - - return rd_hdr; -} - -/** - * get_ramdisk - main ramdisk handling routine + * boot_get_ramdisk - main ramdisk handling routine * @cmdtp: command table pointer * @flag: command flag * @argc: command argument count @@ -582,7 +588,7 @@ static image_header_t* image_get_ramdisk (cmd_tbl_t *cmdtp, int flag, * @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. + * boot_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. @@ -593,7 +599,7 @@ static image_header_t* image_get_ramdisk (cmd_tbl_t *cmdtp, int flag, * rd_start and rd_end are set to 0 if no ramdisk exists * return 1 if ramdisk image is found but corrupted */ -int get_ramdisk (cmd_tbl_t *cmdtp, int flag, int argc, char *argv[], +int boot_get_ramdisk (cmd_tbl_t *cmdtp, int flag, int argc, char *argv[], bootm_headers_t *images, uint8_t arch, ulong *rd_start, ulong *rd_end) { @@ -645,14 +651,14 @@ int get_ramdisk (cmd_tbl_t *cmdtp, int flag, int argc, char *argv[], /* copy from dataflash if needed */ printf ("## Loading init Ramdisk Image at %08lx ...\n", rd_addr); - rd_addr = gen_get_image (rd_addr); + rd_addr = genimg_get_image (rd_addr); /* * Check if there is an initrd image at the * address provided in the second bootm argument * check image type, for FIT images get FIT node. */ - switch (gen_image_get_format ((void *)rd_addr)) { + switch (genimg_get_format ((void *)rd_addr)) { case IMAGE_FORMAT_LEGACY: debug ("* ramdisk: legacy format image\n"); @@ -729,7 +735,7 @@ int get_ramdisk (cmd_tbl_t *cmdtp, int flag, int argc, char *argv[], #if defined(CONFIG_PPC) || defined(CONFIG_M68K) /** - * ramdisk_high - relocate init ramdisk + * boot_ramdisk_high - relocate init ramdisk * @lmb: pointer to lmb handle, will be used for memory mgmt * @rd_data: ramdisk data start address * @rd_len: ramdisk data length @@ -738,18 +744,18 @@ int get_ramdisk (cmd_tbl_t *cmdtp, int flag, int argc, char *argv[], * @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 + * boot_ramdisk_high() takes a relocation hint from "initrd_high" environement * variable and if requested ramdisk data is moved to a specified location. * + * 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 set to zeros. + * * 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 set to zeros - * - returns: - * 0 - success - * -1 - failure + * 0 - success + * -1 - failure */ -int ramdisk_high (struct lmb *lmb, ulong rd_data, ulong rd_len, +int boot_ramdisk_high (struct lmb *lmb, ulong rd_data, ulong rd_len, ulong *initrd_start, ulong *initrd_end) { char *s; @@ -779,12 +785,12 @@ int ramdisk_high (struct lmb *lmb, ulong rd_data, ulong rd_len, lmb_reserve(lmb, rd_data, rd_len); } else { if (initrd_high) - *initrd_start = lmb_alloc_base(lmb, rd_len, 0x1000, initrd_high); + *initrd_start = lmb_alloc_base (lmb, rd_len, 0x1000, initrd_high); else - *initrd_start = lmb_alloc(lmb, rd_len, 0x1000); + *initrd_start = lmb_alloc (lmb, rd_len, 0x1000); if (*initrd_start == 0) { - puts("ramdisk - allocation error\n"); + puts ("ramdisk - allocation error\n"); goto error; } show_boot_progress (12); @@ -793,7 +799,7 @@ int ramdisk_high (struct lmb *lmb, ulong rd_data, ulong rd_len, printf (" Loading Ramdisk to %08lx, end %08lx ... ", *initrd_start, *initrd_end); - memmove_wd((void *)*initrd_start, + memmove_wd ((void *)*initrd_start, (void *)rd_data, rd_len, CHUNKSZ); puts ("OK\n"); @@ -804,6 +810,7 @@ int ramdisk_high (struct lmb *lmb, ulong rd_data, ulong rd_len, } debug (" ramdisk load start = 0x%08lx, ramdisk load end = 0x%08lx\n", *initrd_start, *initrd_end); + return 0; error: @@ -811,14 +818,14 @@ error: } /** - * get_boot_cmdline - allocate and initialize kernel cmdline + * boot_get_cmdline - allocate and initialize kernel cmdline * @lmb: pointer to lmb handle, will be used for memory mgmt * @cmd_start: pointer to a ulong variable, will hold cmdline start * @cmd_end: pointer to a ulong variable, will hold cmdline end * @bootmap_base: ulong variable, holds offset in physical memory to * base of bootmap * - * get_boot_cmdline() allocates space for kernel command line below + * boot_get_cmdline() allocates space for kernel command line below * BOOTMAPSZ + bootmap_base address. If "bootargs" U-boot environemnt * variable is present its contents is copied to allocated kernel * command line. @@ -827,7 +834,7 @@ error: * 0 - success * -1 - failure */ -int get_boot_cmdline (struct lmb *lmb, ulong *cmd_start, ulong *cmd_end, +int boot_get_cmdline (struct lmb *lmb, ulong *cmd_start, ulong *cmd_end, ulong bootmap_base) { char *cmdline; @@ -853,13 +860,13 @@ int get_boot_cmdline (struct lmb *lmb, ulong *cmd_start, ulong *cmd_end, } /** - * get_boot_kbd - allocate and initialize kernel copy of board info + * boot_get_kbd - allocate and initialize kernel copy of board info * @lmb: pointer to lmb handle, will be used for memory mgmt * @kbd: double pointer to board info data * @bootmap_base: ulong variable, holds offset in physical memory to * base of bootmap * - * get_boot_kbd() allocates space for kernel copy of board info data below + * boot_get_kbd() allocates space for kernel copy of board info data below * BOOTMAPSZ + bootmap_base address and kernel board info is initialized with * the current u-boot board info data. * @@ -867,7 +874,7 @@ int get_boot_cmdline (struct lmb *lmb, ulong *cmd_start, ulong *cmd_end, * 0 - success * -1 - failure */ -int get_boot_kbd (struct lmb *lmb, bd_t **kbd, ulong bootmap_base) +int boot_get_kbd (struct lmb *lmb, bd_t **kbd, ulong bootmap_base) { *kbd = (bd_t *)lmb_alloc_base(lmb, sizeof(bd_t), 0xf, CFG_BOOTMAPSZ + bootmap_base); |