From b97a2a0a21f279d66de8a9bdbfe21920968bcb1c Mon Sep 17 00:00:00 2001 From: Marian Balakowicz Date: Tue, 8 Jan 2008 18:14:09 +0100 Subject: [new uImage] Define a API for image handling operations - Add inline helper macros for basic header processing - Move common non inline code common/image.c - Replace direct header access with the API routines - Rename IH_CPU_* to IH_ARCH_* Signed-off-by: Marian Balakowicz --- lib_m68k/m68k_linux.c | 64 +++++++++++++++------------------------------------ 1 file changed, 18 insertions(+), 46 deletions(-) (limited to 'lib_m68k/m68k_linux.c') diff --git a/lib_m68k/m68k_linux.c b/lib_m68k/m68k_linux.c index cc974c2d60..3759fd2d35 100644 --- a/lib_m68k/m68k_linux.c +++ b/lib_m68k/m68k_linux.c @@ -48,12 +48,14 @@ DECLARE_GLOBAL_DATA_PTR; extern image_header_t header; +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[], ulong addr, ulong * len_ptr, int verify) { ulong sp; - ulong len, checksum; + ulong len; ulong initrd_start, initrd_end; ulong cmd_start, cmd_end; ulong initrd_high; @@ -131,7 +133,7 @@ void do_bootm_linux(cmd_tbl_t * cmdtp, int flag, } kernel = - (void (*)(bd_t *, ulong, ulong, ulong, ulong))ntohl(hdr->ih_ep); + (void (*)(bd_t *, ulong, ulong, ulong, ulong))image_get_ep (hdr); /* * Check if there is an initrd image @@ -142,25 +144,17 @@ void do_bootm_linux(cmd_tbl_t * cmdtp, int flag, SHOW_BOOT_PROGRESS(9); addr = simple_strtoul(argv[2], NULL, 16); + hdr = (image_header_t *)addr; printf("## Loading RAMDisk Image at %08lx ...\n", addr); - /* Copy header so we can blank CRC field for re-calculation */ - memmove(&header, (char *)addr, sizeof(image_header_t)); - - if (ntohl(hdr->ih_magic) != IH_MAGIC) { + if (!image_check_magic (hdr)) { puts("Bad Magic Number\n"); SHOW_BOOT_PROGRESS(-10); do_reset(cmdtp, flag, argc, argv); } - data = (ulong) & header; - len = sizeof(image_header_t); - - checksum = ntohl(hdr->ih_hcrc); - hdr->ih_hcrc = 0; - - if (crc32(0, (uchar *) data, len) != checksum) { + if (!image_check_hcrc (hdr)) { puts("Bad Header Checksum\n"); SHOW_BOOT_PROGRESS(-11); do_reset(cmdtp, flag, argc, argv); @@ -168,36 +162,14 @@ void do_bootm_linux(cmd_tbl_t * cmdtp, int flag, SHOW_BOOT_PROGRESS(10); - print_image_hdr(hdr); + print_image_hdr (hdr); - data = addr + sizeof(image_header_t); - len = ntohl(hdr->ih_size); + data = image_get_data (hdr); + len = image_get_data_size (hdr); if (verify) { - ulong csum = 0; -#if defined(CONFIG_HW_WATCHDOG) || defined(CONFIG_WATCHDOG) - ulong cdata = data, edata = cdata + len; -#endif /* CONFIG_HW_WATCHDOG || CONFIG_WATCHDOG */ - puts(" Verifying Checksum ... "); - -#if defined(CONFIG_HW_WATCHDOG) || defined(CONFIG_WATCHDOG) - - while (cdata < edata) { - ulong chunk = edata - cdata; - - if (chunk > CHUNKSZ) - chunk = CHUNKSZ; - csum = crc32(csum, (uchar *) cdata, chunk); - cdata += chunk; - - WATCHDOG_RESET(); - } -#else /* !(CONFIG_HW_WATCHDOG || CONFIG_WATCHDOG) */ - csum = crc32(0, (uchar *) data, len); -#endif /* CONFIG_HW_WATCHDOG || CONFIG_WATCHDOG */ - - if (csum != ntohl(hdr->ih_dcrc)) { + if (!image_check_dcrc_wd (hdr, CHUNKSZ)) { puts("Bad Data CRC\n"); SHOW_BOOT_PROGRESS(-12); do_reset(cmdtp, flag, argc, argv); @@ -207,9 +179,9 @@ void do_bootm_linux(cmd_tbl_t * cmdtp, int flag, SHOW_BOOT_PROGRESS(11); - if ((hdr->ih_os != IH_OS_LINUX) || - (hdr->ih_arch != IH_CPU_M68K) || - (hdr->ih_type != IH_TYPE_RAMDISK)) { + if (!image_check_os (hdr, IH_OS_LINUX) || + !image_check_arch (hdr, IH_ARCH_M68K) || + !image_check_type (hdr, IH_TYPE_RAMDISK)) { puts("No Linux ColdFire Ramdisk Image\n"); SHOW_BOOT_PROGRESS(-13); do_reset(cmdtp, flag, argc, argv); @@ -218,8 +190,8 @@ void do_bootm_linux(cmd_tbl_t * cmdtp, int flag, /* * Now check if we have a multifile image */ - } else if ((hdr->ih_type == IH_TYPE_MULTI) && (len_ptr[1])) { - u_long tail = ntohl(len_ptr[0]) % 4; + } else if (image_check_type (hdr, IH_TYPE_MULTI) && (len_ptr[1])) { + u_long tail = image_to_cpu (len_ptr[0]) % 4; int i; SHOW_BOOT_PROGRESS(13); @@ -230,12 +202,12 @@ void do_bootm_linux(cmd_tbl_t * cmdtp, int flag, for (i = 1; len_ptr[i]; ++i) data += 4; /* add kernel length, and align */ - data += ntohl(len_ptr[0]); + data += image_to_cpu (len_ptr[0]); if (tail) { data += 4 - tail; } - len = ntohl(len_ptr[1]); + len = image_to_cpu (len_ptr[1]); } else { /* -- cgit v1.2.3 From 559316faf7eae0614c91d77f509b57d6c4c091ba Mon Sep 17 00:00:00 2001 From: Marian Balakowicz Date: Tue, 8 Jan 2008 18:11:44 +0100 Subject: [new uImage] Move CHUNKSZ definition to image.h CHUNKSZ defined for PPC and M68K is set to the same value of 64K, move this definition to a common header. Signed-off-by: Marian Balakowicz --- common/cmd_bootm.c | 7 ------- include/image.h | 7 +++++++ lib_m68k/m68k_linux.c | 2 -- lib_ppc/ppc_linux.c | 2 -- 4 files changed, 7 insertions(+), 11 deletions(-) (limited to 'lib_m68k/m68k_linux.c') diff --git a/common/cmd_bootm.c b/common/cmd_bootm.c index 67f555e1de..fbe81d3039 100644 --- a/common/cmd_bootm.c +++ b/common/cmd_bootm.c @@ -61,13 +61,6 @@ extern int do_reset (cmd_tbl_t *cmdtp, int flag, int argc, char *argv[]); #include #endif -/* - * Some systems (for example LWMON) have very short watchdog periods; - * we must make sure to split long operations like memmove() or - * crc32() into reasonable chunks. - */ -#define CHUNKSZ (64 * 1024) - int gunzip (void *, int, unsigned char *, unsigned long *); #ifdef CONFIG_BZIP2 diff --git a/include/image.h b/include/image.h index c9f42980e8..aab3f44ccb 100644 --- a/include/image.h +++ b/include/image.h @@ -164,6 +164,13 @@ typedef struct image_header { uint8_t ih_name[IH_NMLEN]; /* Image Name */ } image_header_t; +/* + * Some systems (for example LWMON) have very short watchdog periods; + * we must make sure to split long operations like memmove() or + * crc32() into reasonable chunks. + */ +#define CHUNKSZ (64 * 1024) + #define image_to_cpu(x) ntohl(x) #define cpu_to_image(x) htonl(x) diff --git a/lib_m68k/m68k_linux.c b/lib_m68k/m68k_linux.c index 3759fd2d35..f865c0c6a5 100644 --- a/lib_m68k/m68k_linux.c +++ b/lib_m68k/m68k_linux.c @@ -37,8 +37,6 @@ DECLARE_GLOBAL_DATA_PTR; #define LINUX_MAX_ENVS 256 #define LINUX_MAX_ARGS 256 -#define CHUNKSZ (64 * 1024) - #ifdef CONFIG_SHOW_BOOT_PROGRESS # include # define SHOW_BOOT_PROGRESS(arg) show_boot_progress(arg) diff --git a/lib_ppc/ppc_linux.c b/lib_ppc/ppc_linux.c index 94872a61dc..4e7734ccd3 100644 --- a/lib_ppc/ppc_linux.c +++ b/lib_ppc/ppc_linux.c @@ -49,8 +49,6 @@ #include #endif -#define CHUNKSZ (64 * 1024) - DECLARE_GLOBAL_DATA_PTR; extern image_header_t header; -- cgit v1.2.3 From af13cdbc01eaf88880978bfb4f603e012818ba24 Mon Sep 17 00:00:00 2001 From: Marian Balakowicz Date: Tue, 8 Jan 2008 18:11:45 +0100 Subject: [new uImage] Add memmove_wd() common routine Move common, watchdog sensible memmove code to a helper memmmove_wd() routine. Signed-off-by: Marian Balakowicz --- common/cmd_bootm.c | 20 ++++---------------- common/image.c | 18 ++++++++++++++++++ include/image.h | 3 +++ lib_m68k/m68k_linux.c | 23 ++++------------------- lib_ppc/ppc_linux.c | 22 ++++------------------ 5 files changed, 33 insertions(+), 53 deletions(-) (limited to 'lib_m68k/m68k_linux.c') diff --git a/common/cmd_bootm.c b/common/cmd_bootm.c index aa7c0f5b77..b059336ca5 100644 --- a/common/cmd_bootm.c +++ b/common/cmd_bootm.c @@ -250,24 +250,12 @@ int do_bootm (cmd_tbl_t *cmdtp, int flag, int argc, char *argv[]) if (image_get_load (hdr) == addr) { printf (" XIP %s ... ", name); } else { -#if defined(CONFIG_HW_WATCHDOG) || defined(CONFIG_WATCHDOG) - size_t l = len; - void *to = (void *)image_get_load (hdr); - void *from = (void *)data; - printf (" Loading %s ... ", name); - while (l > 0) { - size_t tail = (l > CHUNKSZ) ? CHUNKSZ : l; - WATCHDOG_RESET(); - memmove (to, from, tail); - to += tail; - from += tail; - l -= tail; - } -#else /* !(CONFIG_HW_WATCHDOG || CONFIG_WATCHDOG) */ - memmove ((void *)image_get_load (hdr), (uchar *)data, len); -#endif /* CONFIG_HW_WATCHDOG || CONFIG_WATCHDOG */ + memmove_wd ((void *)image_get_load (hdr), + (void *)data, len, CHUNKSZ); + + puts("OK\n"); } break; case IH_COMP_GZIP: diff --git a/common/image.c b/common/image.c index 7a0a3d2a90..048b866ce6 100644 --- a/common/image.c +++ b/common/image.c @@ -57,6 +57,7 @@ int image_check_dcrc (image_header_t *hdr) return (dcrc == image_get_dcrc (hdr)); } +#ifndef USE_HOSTCC int image_check_dcrc_wd (image_header_t *hdr, ulong chunksz) { ulong dcrc = 0; @@ -89,3 +90,20 @@ int getenv_verify (void) char *s = getenv ("verify"); return (s && (*s == 'n')) ? 0 : 1; } + +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 */ diff --git a/include/image.h b/include/image.h index aab3f44ccb..9dc0343586 100644 --- a/include/image.h +++ b/include/image.h @@ -250,8 +250,11 @@ static inline void image_set_name (image_header_t *hdr, const char *name) int image_check_hcrc (image_header_t *hdr); int image_check_dcrc (image_header_t *hdr); +#ifndef USE_HOSTCC int image_check_dcrc_wd (image_header_t *hdr, ulong chunksize); int getenv_verify (void); +void memmove_wd (void *to, void *from, size_t len, ulong chunksz); +#endif static inline int image_check_magic (image_header_t *hdr) { diff --git a/lib_m68k/m68k_linux.c b/lib_m68k/m68k_linux.c index f865c0c6a5..0af2eae568 100644 --- a/lib_m68k/m68k_linux.c +++ b/lib_m68k/m68k_linux.c @@ -266,25 +266,10 @@ void do_bootm_linux(cmd_tbl_t * cmdtp, int flag, initrd_end = initrd_start + len; printf(" Loading Ramdisk to %08lx, end %08lx ... ", initrd_start, initrd_end); -#if defined(CONFIG_HW_WATCHDOG) || defined(CONFIG_WATCHDOG) - { - size_t l = len; - void *to = (void *)initrd_start; - void *from = (void *)data; - - while (l > 0) { - size_t tail = - (l > CHUNKSZ) ? CHUNKSZ : l; - WATCHDOG_RESET(); - memmove(to, from, tail); - to += tail; - from += tail; - l -= tail; - } - } -#else /* !(CONFIG_HW_WATCHDOG || CONFIG_WATCHDOG) */ - memmove((void *)initrd_start, (void *)data, len); -#endif /* CONFIG_HW_WATCHDOG || CONFIG_WATCHDOG */ + + memmove_wd((void *)initrd_start, + (void *)data, len, CHUNKSZ); + puts("OK\n"); } } else { diff --git a/lib_ppc/ppc_linux.c b/lib_ppc/ppc_linux.c index 671673fcb8..6e2afed9b0 100644 --- a/lib_ppc/ppc_linux.c +++ b/lib_ppc/ppc_linux.c @@ -426,24 +426,10 @@ do_bootm_linux (cmd_tbl_t *cmdtp, int flag, initrd_end = initrd_start + len; printf (" Loading Ramdisk to %08lx, end %08lx ... ", initrd_start, initrd_end); -#if defined(CONFIG_HW_WATCHDOG) || defined(CONFIG_WATCHDOG) - { - size_t l = len; - void *to = (void *)initrd_start; - void *from = (void *)data; - - while (l > 0) { - size_t tail = (l > CHUNKSZ) ? CHUNKSZ : l; - WATCHDOG_RESET(); - memmove (to, from, tail); - to += tail; - from += tail; - l -= tail; - } - } -#else /* !(CONFIG_HW_WATCHDOG || CONFIG_WATCHDOG) */ - memmove ((void *)initrd_start, (void *)data, len); -#endif /* CONFIG_HW_WATCHDOG || CONFIG_WATCHDOG */ + + memmove_wd((void *)initrd_start, + (void *)data, len, CHUNKSZ); + puts ("OK\n"); } } else { -- cgit v1.2.3 From f13e7b2e993c61fed1f607962501e051940d6e80 Mon Sep 17 00:00:00 2001 From: Marian Balakowicz Date: Tue, 8 Jan 2008 18:12:17 +0100 Subject: [new uImage] Cleanup image header pointer use in bootm code - use single image header pointer instead of a set of auxilliary variables. - add multi component image helper routines: get component size/data address Signed-off-by: Marian Balakowicz --- common/cmd_autoscript.c | 10 +-- common/cmd_bootm.c | 153 ++++++++++++++------------------ common/image.c | 86 ++++++++++++++++++ include/image.h | 27 +++++- lib_arm/armlinux.c | 88 ++++++++----------- lib_avr32/avr32_linux.c | 68 ++++++--------- lib_blackfin/bf533_linux.c | 4 +- lib_i386/i386_linux.c | 81 +++++++---------- lib_m68k/m68k_linux.c | 84 ++++++++---------- lib_microblaze/microblaze_linux.c | 71 ++++++--------- lib_mips/mips_linux.c | 68 ++++++--------- lib_nios/nios_linux.c | 2 +- lib_nios2/nios_linux.c | 5 +- lib_ppc/ppc_linux.c | 177 ++++++++++++++++---------------------- 14 files changed, 435 insertions(+), 489 deletions(-) (limited to 'lib_m68k/m68k_linux.c') diff --git a/common/cmd_autoscript.c b/common/cmd_autoscript.c index 3e68ced1fe..53f8e8311a 100644 --- a/common/cmd_autoscript.c +++ b/common/cmd_autoscript.c @@ -54,7 +54,7 @@ autoscript (ulong addr) { ulong len; image_header_t *hdr = (image_header_t *)addr; - ulong *len_ptr; + ulong *data; char *cmd; int rcode = 0; int verify; @@ -84,9 +84,9 @@ autoscript (ulong addr) } /* get length of script */ - len_ptr = (ulong *)image_get_data (hdr); + data = (ulong *)image_get_data (hdr); - if ((len = image_to_cpu (*len_ptr)) == 0) { + if ((len = image_to_cpu (*data)) == 0) { puts ("Empty Script\n"); return 1; } @@ -97,10 +97,10 @@ autoscript (ulong addr) return 1; } - while (*len_ptr++); + while (*data++); /* make sure cmd is null terminated */ - memmove (cmd, (char *)len_ptr, len); + memmove (cmd, (char *)data, len); *(cmd + len) = 0; #ifdef CFG_HUSH_PARSER /*?? */ diff --git a/common/cmd_bootm.c b/common/cmd_bootm.c index 2de132961a..2d17bdd4f9 100644 --- a/common/cmd_bootm.c +++ b/common/cmd_bootm.c @@ -93,14 +93,13 @@ extern int do_reset (cmd_tbl_t *cmdtp, int flag, int argc, char *argv[]); * - disabled interrupts. */ typedef void boot_os_fn (cmd_tbl_t *cmdtp, int flag, - int argc, char *argv[], - ulong addr, /* of image to boot */ - ulong *len_ptr, /* multi-file image length table */ - int verify); /* getenv("verify")[0] != 'n' */ + int argc, char *argv[], + image_header_t *hdr, /* of image to boot */ + int verify); /* getenv("verify")[0] != 'n' */ extern boot_os_fn do_bootm_linux; static boot_os_fn do_bootm_netbsd; -#ifdef CONFIG_LYNXKDI +#if defined(CONFIG_LYNXKDI) static boot_os_fn do_bootm_lynxkdi; extern void lynxkdi_boot (image_header_t *); #endif @@ -116,8 +115,6 @@ extern uchar (*env_get_char)(int); /* Returns a character from the environment * static boot_os_fn do_bootm_artos; #endif -image_header_t header; - ulong load_addr = CFG_LOAD_ADDR; /* Default Load Address */ @@ -126,34 +123,32 @@ ulong load_addr = CFG_LOAD_ADDR; /* Default Load Address */ /*******************************************************************/ int do_bootm (cmd_tbl_t *cmdtp, int flag, int argc, char *argv[]) { - ulong iflag; - ulong addr; - ulong data, len; - ulong *len_ptr; - uint unc_len = CFG_BOOTM_LEN; - int i, verify; - char *name, *s; - int (*appl)(int, char *[]); - image_header_t *hdr = &header; + ulong iflag; + char *name, *s; + int (*appl)(int, char *[]); + uint unc_len = CFG_BOOTM_LEN; + int verify = getenv_verify(); - verify = getenv_verify (); + image_header_t *hdr; + ulong img_addr; + ulong os_data, os_len; if (argc < 2) { - addr = load_addr; + img_addr = load_addr; } else { - addr = simple_strtoul(argv[1], NULL, 16); + img_addr = simple_strtoul(argv[1], NULL, 16); } show_boot_progress (1); - printf ("## Booting image at %08lx ...\n", addr); + printf ("## Booting image at %08lx ...\n", img_addr); - /* Copy header so we can blank CRC field for re-calculation */ #ifdef CONFIG_HAS_DATAFLASH - if (addr_dataflash(addr)){ - read_dataflash (addr, image_get_header_size (), (char *)&header); + if (addr_dataflash (img_addr)){ + hdr = (image_header_t *)CFG_LOAD_ADDR; + read_dataflash (img_addr, image_get_header_size (), (char *)hdr); } else #endif - memmove (&header, (char *)addr, image_get_header_size ()); + hdr = (image_header_t *)img_addr; if (!image_check_magic(hdr)) { puts ("Bad Magic Number\n"); @@ -170,23 +165,18 @@ int do_bootm (cmd_tbl_t *cmdtp, int flag, int argc, char *argv[]) show_boot_progress (3); #ifdef CONFIG_HAS_DATAFLASH - if (addr_dataflash(addr)){ - len = image_get_image_size (hdr); - read_dataflash(addr, len, (char *)CFG_LOAD_ADDR); - addr = CFG_LOAD_ADDR; - } + if (addr_dataflash (img_addr)) + read_dataflash (img_addr + image_get_header_size (), + image_get_data_size (hdr), + (char *)image_get_data (hdr)); #endif - /* for multi-file images we need the data part, too */ - print_image_hdr ((image_header_t *)addr); - - len = image_get_data_size (hdr); - data = addr + image_get_header_size (); - len_ptr = (ulong *)data; + /* uImage is in a system RAM, pointed to by hdr */ + print_image_hdr (hdr); if (verify) { puts (" Verifying Checksum ... "); - if (!image_check_dcrc ((image_header_t *)addr)) { + if (!image_check_dcrc (hdr)) { printf ("Bad Data CRC\n"); show_boot_progress (-3); return 1; @@ -212,14 +202,12 @@ int do_bootm (cmd_tbl_t *cmdtp, int flag, int argc, char *argv[]) break; case IH_TYPE_KERNEL: name = "Kernel Image"; + os_data = image_get_data (hdr); + os_len = image_get_data_size (hdr); break; case IH_TYPE_MULTI: name = "Multi-File Image"; - len = image_to_cpu (len_ptr[0]); - /* OS kernel is always the first image */ - data += 8; /* kernel_len + terminator */ - for (i=1; len_ptr[i]; ++i) - data += 4; + image_multi_getimg (hdr, 0, &os_data, &os_len); break; default: printf ("Wrong Image Type for %s command\n", cmdtp->name); @@ -248,13 +236,13 @@ 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) == addr) { + if (image_get_load (hdr) == img_addr) { printf (" XIP %s ... ", name); } else { printf (" Loading %s ... ", name); memmove_wd ((void *)image_get_load (hdr), - (void *)data, len, CHUNKSZ); + (void *)os_data, os_len, CHUNKSZ); puts("OK\n"); } @@ -262,7 +250,7 @@ int do_bootm (cmd_tbl_t *cmdtp, int flag, int argc, char *argv[]) case IH_COMP_GZIP: printf (" Uncompressing %s ... ", name); if (gunzip ((void *)image_get_load (hdr), unc_len, - (uchar *)data, &len) != 0) { + (uchar *)os_data, &os_len) != 0) { puts ("GUNZIP ERROR - must RESET board to recover\n"); show_boot_progress (-6); do_reset (cmdtp, flag, argc, argv); @@ -276,9 +264,9 @@ int do_bootm (cmd_tbl_t *cmdtp, int flag, int argc, char *argv[]) * use slower decompression algorithm which requires * at most 2300 KB of memory. */ - i = BZ2_bzBuffToBuffDecompress ((char*)image_get_load (hdr), - &unc_len, (char *)data, len, - CFG_MALLOC_LEN < (4096 * 1024), 0); + int i = BZ2_bzBuffToBuffDecompress ((char*)image_get_load (hdr), + &unc_len, (char *)os_data, os_len, + CFG_MALLOC_LEN < (4096 * 1024), 0); if (i != BZ_OK) { printf ("BUNZIP2 ERROR %d - must RESET board to recover\n", i); show_boot_progress (-6); @@ -306,7 +294,7 @@ int do_bootm (cmd_tbl_t *cmdtp, int flag, int argc, char *argv[]) */ if (((s = getenv("autostart")) != NULL) && (strcmp(s,"no") == 0)) { char buf[32]; - sprintf(buf, "%lX", len); + sprintf(buf, "%lX", image_get_data_size(hdr)); setenv("filesize", buf); return 0; } @@ -332,42 +320,36 @@ int do_bootm (cmd_tbl_t *cmdtp, int flag, int argc, char *argv[]) #ifdef CONFIG_SILENT_CONSOLE fixup_silent_linux(); #endif - do_bootm_linux (cmdtp, flag, argc, argv, - addr, len_ptr, verify); + do_bootm_linux (cmdtp, flag, argc, argv, hdr, verify); break; case IH_OS_NETBSD: - do_bootm_netbsd (cmdtp, flag, argc, argv, - addr, len_ptr, verify); + do_bootm_netbsd (cmdtp, flag, argc, argv, hdr, verify); break; #ifdef CONFIG_LYNXKDI case IH_OS_LYNXOS: - do_bootm_lynxkdi (cmdtp, flag, argc, argv, - addr, len_ptr, verify); + do_bootm_lynxkdi (cmdtp, flag, argc, argv, hdr, verify); break; #endif case IH_OS_RTEMS: - do_bootm_rtems (cmdtp, flag, argc, argv, - addr, len_ptr, verify); + do_bootm_rtems (cmdtp, flag, argc, argv, hdr, verify); break; #if defined(CONFIG_CMD_ELF) case IH_OS_VXWORKS: - do_bootm_vxworks (cmdtp, flag, argc, argv, - addr, len_ptr, verify); + do_bootm_vxworks (cmdtp, flag, argc, argv, hdr, verify); break; + case IH_OS_QNX: - do_bootm_qnxelf (cmdtp, flag, argc, argv, - addr, len_ptr, verify); + do_bootm_qnxelf (cmdtp, flag, argc, argv, hdr, verify); break; #endif #ifdef CONFIG_ARTOS case IH_OS_ARTOS: - do_bootm_artos (cmdtp, flag, argc, argv, - addr, len_ptr, verify); + do_bootm_artos (cmdtp, flag, argc, argv, hdr, verify); break; #endif } @@ -570,11 +552,12 @@ void print_image_hdr (image_header_t *hdr) if (image_check_type (hdr, IH_TYPE_MULTI)) { int i; - ulong len; - ulong *len_ptr = (ulong *)((ulong)hdr + image_get_header_size ()); + ulong data, len; + ulong count = image_multi_count (hdr); puts (" Contents:\n"); - for (i = 0; (len = image_to_cpu (*len_ptr)); ++i, ++len_ptr) { + for (i = 0; i < count; i++) { + image_multi_getimg (hdr, i, &data, &len); printf (" Image %d: %8ld Bytes = ", i, len); print_size (len, "\n"); } @@ -684,14 +667,12 @@ static void fixup_silent_linux () /*******************************************************************/ static void do_bootm_netbsd (cmd_tbl_t *cmdtp, int flag, - int argc, char *argv[], - ulong addr, ulong *len_ptr, - int verify) + int argc, char *argv[], + image_header_t *hdr, int verify) { - image_header_t *hdr = &header; - void (*loader)(bd_t *, image_header_t *, char *, char *); image_header_t *img_addr; + ulong kernel_data, kernel_len; char *consdev; char *cmdline; @@ -708,8 +689,11 @@ static void do_bootm_netbsd (cmd_tbl_t *cmdtp, int flag, */ img_addr = 0; - if ((image_check_type (hdr, IH_TYPE_MULTI)) && (len_ptr[1])) - img_addr = (image_header_t *)addr; + if (image_check_type (hdr, IH_TYPE_MULTI)) { + image_multi_getimg (hdr, 1, &kernel_data, &kernel_len); + if (kernel_len) + img_addr = hdr; + } consdev = ""; #if defined (CONFIG_8xx_CONS_SMC1) @@ -760,19 +744,16 @@ static void do_bootm_netbsd (cmd_tbl_t *cmdtp, int flag, #ifdef CONFIG_LYNXKDI static void do_bootm_lynxkdi (cmd_tbl_t *cmdtp, int flag, int argc, char *argv[], - ulong addr, ulong *len_ptr, - int verify) + image_header_t *hdr, int verify) { - lynxkdi_boot (&header); + lynxkdi_boot (hdr); } #endif /* CONFIG_LYNXKDI */ static void do_bootm_rtems (cmd_tbl_t *cmdtp, int flag, int argc, char *argv[], - ulong addr, ulong *len_ptr, - int verify) + image_header_t *hdr, int verify) { - image_header_t *hdr = &header; void (*entry_point)(bd_t *); entry_point = (void (*)(bd_t *))image_get_ep (hdr); @@ -792,10 +773,8 @@ static void do_bootm_rtems (cmd_tbl_t *cmdtp, int flag, #if defined(CONFIG_CMD_ELF) static void do_bootm_vxworks (cmd_tbl_t *cmdtp, int flag, int argc, char *argv[], - ulong addr, ulong *len_ptr, - int verify) + image_header_t *hdr, int verify) { - image_header_t *hdr = &header; char str[80]; sprintf(str, "%x", image_get_ep (hdr)); /* write entry-point into string */ @@ -803,12 +782,10 @@ static void do_bootm_vxworks (cmd_tbl_t *cmdtp, int flag, do_bootvx(cmdtp, 0, 0, NULL); } -static void do_bootm_qnxelf (cmd_tbl_t *cmdtp, int flag, - int argc, char *argv[], - ulong addr, ulong *len_ptr, - int verify) +static void do_bootm_qnxelf(cmd_tbl_t *cmdtp, int flag, + int argc, char *argv[], + image_header_t *hdr, int verify) { - image_header_t *hdr = &header; char *local_args[2]; char str[16]; @@ -822,8 +799,7 @@ static void do_bootm_qnxelf (cmd_tbl_t *cmdtp, int flag, #if defined(CONFIG_ARTOS) && defined(CONFIG_PPC) static void do_bootm_artos (cmd_tbl_t *cmdtp, int flag, int argc, char *argv[], - ulong addr, ulong *len_ptr, - int verify) + image_header_t *hdr, int verify) { ulong top; char *s, *cmdline; @@ -831,7 +807,6 @@ static void do_bootm_artos (cmd_tbl_t *cmdtp, int flag, int i, j, nxt, len, envno, envsz; bd_t *kbd; void (*entry)(bd_t *bd, char *cmdline, char **fwenv, ulong top); - image_header_t *hdr = &header; /* * Booting an ARTOS kernel image + application diff --git a/common/image.c b/common/image.c index 048b866ce6..6eee83da84 100644 --- a/common/image.c +++ b/common/image.c @@ -107,3 +107,89 @@ void memmove_wd (void *to, void *from, size_t len, ulong chunksz) #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 + * + * image_multi_count() returns number of components in a multi + * component image. + * + * Note: no checking of the image type is done, caller must pass + * a valid multi component image. + * + * returns: + * number of components + */ +ulong image_multi_count (image_header_t *hdr) +{ + ulong i, count = 0; + ulong *size; + + /* get start of the image payload, which in case of multi + * component images that points to a table of component sizes */ + size = (ulong *)image_get_data (hdr); + + /* count non empty slots */ + for (i = 0; size[i]; ++i) + count++; + + return count; +} + +/** + * image_multi_getimg - get component data address and size + * @hdr: pointer to the header of the multi component image + * @idx: index of the requested component + * @data: pointer to a ulong variable, will hold component data address + * @len: pointer to a ulong variable, will hold component size + * + * image_multi_getimg() returns size and data address for the requested + * component in a multi component image. + * + * Note: no checking of the image type is done, caller must pass + * a valid multi component image. + * + * returns: + * data address and size of the component, if idx is valid + * 0 in data and len, if idx is out of range + */ +void image_multi_getimg (image_header_t *hdr, ulong idx, + ulong *data, ulong *len) +{ + int i; + ulong *size; + ulong offset, tail, count, img_data; + + /* get number of component */ + count = image_multi_count (hdr); + + /* get start of the image payload, which in case of multi + * component images that points to a table of component sizes */ + size = (ulong *)image_get_data (hdr); + + /* get address of the proper component data start, which means + * skipping sizes table (add 1 for last, null entry) */ + img_data = image_get_data (hdr) + (count + 1) * sizeof (ulong); + + if (idx < count) { + *len = size[idx]; + offset = 0; + tail = 0; + + /* go over all indices preceding requested component idx */ + for (i = 0; i < idx; i++) { + /* add up i-th component size */ + offset += size[i]; + + /* add up alignment for i-th component */ + tail += (4 - size[i] % 4); + } + + /* calculate idx-th component data address */ + *data = img_data + offset + tail; + } else { + *len = 0; + *data = 0; + } +} diff --git a/include/image.h b/include/image.h index 9dc0343586..c605d66269 100644 --- a/include/image.h +++ b/include/image.h @@ -211,13 +211,30 @@ static inline uint32_t image_get_data_size (image_header_t *hdr) { return image_get_size (hdr); } + +/** + * image_get_data - get image payload start address + * @hdr: image header + * + * image_get_data() returns address of the image payload. For single + * component images it is image data start. For multi component + * images it points to the null terminated table of sub-images sizes. + * + * returns: + * image payload data start address + */ +static inline ulong image_get_data (image_header_t *hdr) +{ + return ((ulong)hdr + image_get_header_size ()); +} + static inline uint32_t image_get_image_size (image_header_t *hdr) { return (image_get_size (hdr) + image_get_header_size ()); } -static inline ulong image_get_data (image_header_t *hdr) +static inline ulong image_get_image_end (image_header_t *hdr) { - return ((ulong)hdr + image_get_header_size ()); + return ((ulong)hdr + image_get_image_size (hdr)); } #define image_set_hdr_l(f) \ @@ -307,4 +324,8 @@ static inline int image_check_target_arch (image_header_t *hdr) } #endif -#endif /* __IMAGE_H__ */ +ulong image_multi_count (image_header_t *hdr); +void image_multi_getimg (image_header_t *hdr, ulong idx, + ulong *data, ulong *len); + +#endif /* __IMAGE_H__ */ diff --git a/lib_arm/armlinux.c b/lib_arm/armlinux.c index 09038cc93f..4f9aae613e 100644 --- a/lib_arm/armlinux.c +++ b/lib_arm/armlinux.c @@ -66,17 +66,14 @@ static void setup_videolfb_tag (gd_t *gd); static struct tag *params; #endif /* CONFIG_SETUP_MEMORY_TAGS || CONFIG_CMDLINE_TAG || CONFIG_INITRD_TAG */ -extern image_header_t header; /* from cmd_bootm.c */ - - void do_bootm_linux (cmd_tbl_t *cmdtp, int flag, int argc, char *argv[], - ulong addr, ulong *len_ptr, int verify) + image_header_t *hdr, int verify) { - ulong len = 0; + ulong rd_addr; + ulong rd_data, rd_len = 0; ulong initrd_start, initrd_end; - ulong data; + image_header_t *rd_hdr; void (*theKernel)(int zero, int arch, uint params); - image_header_t *hdr = &header; bd_t *bd = gd->bd; #ifdef CONFIG_CMDLINE_TAG @@ -91,27 +88,26 @@ void do_bootm_linux (cmd_tbl_t *cmdtp, int flag, int argc, char *argv[], if (argc >= 3) { show_boot_progress (9); - addr = simple_strtoul (argv[2], NULL, 16); - - printf ("## Loading Ramdisk Image at %08lx ...\n", addr); + 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 (addr)) { - read_dataflash (addr, image_get_header_size (), - (char *) &header); + 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 - memcpy (&header, (char *) addr, - image_get_header_size ()); + rd_hdr = (image_header_t *)rd_addr; - if (!image_check_magic (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 (hdr)) { + if (!image_check_hcrc (rd_hdr)) { printf ("Bad Header Checksum\n"); show_boot_progress (-11); do_reset (cmdtp, flag, argc, argv); @@ -119,21 +115,20 @@ void do_bootm_linux (cmd_tbl_t *cmdtp, int flag, int argc, char *argv[], show_boot_progress (10); - print_image_hdr (hdr); + print_image_hdr (rd_hdr); - data = image_get_data (hdr); - len = image_get_data_size (hdr); + rd_data = image_get_data (rd_hdr); + rd_len = image_get_data_size (rd_hdr); #ifdef CONFIG_HAS_DATAFLASH - if (addr_dataflash (addr)) { - read_dataflash (data, len, (char *) CFG_LOAD_ADDR); - data = CFG_LOAD_ADDR; - } + 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 (hdr)) { + if (!image_get_dcrc (rd_hdr)) { printf ("Bad Data CRC\n"); show_boot_progress (-12); do_reset (cmdtp, flag, argc, argv); @@ -143,9 +138,9 @@ void do_bootm_linux (cmd_tbl_t *cmdtp, int flag, int argc, char *argv[], show_boot_progress (11); - if (!image_check_os (hdr, IH_OS_LINUX) || - !image_check_arch (hdr, IH_ARCH_ARM) || - !image_check_type (hdr, IH_TYPE_RAMDISK)) { + 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); @@ -155,50 +150,37 @@ void do_bootm_linux (cmd_tbl_t *cmdtp, int flag, int argc, char *argv[], /* *we need to copy the ramdisk to SRAM to let Linux boot */ - memmove ((void *)image_get_load (hdr), (uchar *)data, len); - data = image_get_load (hdr); + 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) && (len_ptr[1])) { - ulong tail = image_to_cpu (len_ptr[0]) % 4; - int i; - + } else if (image_check_type (hdr, IH_TYPE_MULTI)) { + /* + * Get second entry data start address and len + */ show_boot_progress (13); - - /* skip kernel length and terminator */ - data = (ulong) (&len_ptr[2]); - /* skip any additional image length fields */ - for (i = 1; len_ptr[i]; ++i) - data += 4; - /* add kernel length, and align */ - data += image_to_cpu (len_ptr[0]); - if (tail) { - data += 4 - tail; - } - - len = image_to_cpu (len_ptr[1]); - + image_multi_getimg (hdr, 1, &rd_data, &rd_len); } else { /* * no initrd image */ show_boot_progress (14); - len = data = 0; + rd_len = rd_data = 0; } #ifdef DEBUG - if (!data) { + if (!rd_data) { printf ("No initrd\n"); } #endif - if (data) { - initrd_start = data; - initrd_end = initrd_start + len; + if (rd_data) { + initrd_start = rd_data; + initrd_end = initrd_start + rd_len; } else { initrd_start = 0; initrd_end = 0; diff --git a/lib_avr32/avr32_linux.c b/lib_avr32/avr32_linux.c index 44827ec885..455590e37d 100644 --- a/lib_avr32/avr32_linux.c +++ b/lib_avr32/avr32_linux.c @@ -174,20 +174,16 @@ static void setup_end_tag(struct tag *params) } void do_bootm_linux(cmd_tbl_t *cmdtp, int flag, int argc, char *argv[], - unsigned long addr, unsigned long *len_ptr, int verify) + image_header_t *hdr, int verify) { - unsigned long data, len = 0; - unsigned long initrd_start, initrd_end; - unsigned long image_start, image_end; + ulong rd_data, rd_len = 0; + ulong initrd_start, initrd_end; + image_header_t *rd_hdr; + void (*theKernel)(int magic, void *tagtable); - image_header_t *hdr; struct tag *params, *params_start; char *commandline = getenv("bootargs"); - hdr = (image_header_t *)addr; - image_start = addr; - image_end = addr + image_get_data_size (hdr); - theKernel = (void *)image_get_ep (hdr); /* @@ -196,29 +192,27 @@ void do_bootm_linux(cmd_tbl_t *cmdtp, int flag, int argc, char *argv[], if (argc >= 3) { show_boot_progress (9); - addr = simple_strtoul(argv[2], NULL, 16); - hdr = (image_header_t *)addr; + rd_hdr = (image_header_t *)simple_strtoul (argv[2], NULL, 16); + printf ("## Loading RAMDISK image at %08lx ...\n", rd_hdr); - printf("## Loading RAMDISK image at %08lx ...\n", addr); - - if (!image_check_magic (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 (hdr)) { + 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 (hdr); + print_image_hdr (rd_hdr); if (verify) { puts(" Verifying Checksum ... "); - if (!image_check_dcrc (hdr)) { + if (!image_check_dcrc (rd_hdr)) { puts("Bad Data CRC\n"); show_boot_progress (-12); do_reset(cmdtp, flag, argc, argv); @@ -228,44 +222,32 @@ void do_bootm_linux(cmd_tbl_t *cmdtp, int flag, int argc, char *argv[], show_boot_progress (11); - if (!image_check_os (hdr, IH_OS_LINUX) || - !image_check_arch (hdr, IH_ARCH_AVR32) || - !image_check_type (hdr, IH_TYPE_RAMDISK)) { + 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); } - data = image_get_data (hdr); - len = image_get_data_size (hdr); - - } else if (image_check_type (hdr, IH_TYPE_MULTI) && (len_ptr[1])) { - ulong tail = image_to_cpu (len_ptr[0]) % 4; - int i; + 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); - - /* skip kernel length and terminator */ - data = (ulong) (&len_ptr[2]); - /* skip any additional image length fields */ - for (i = 1; len_ptr[i]; ++i) - data += 4; - /* add kernel length, and align */ - data += image_to_cpu (len_ptr[0]); - if (tail) { - data += 4 - tail; - } - - len = image_to_cpu (len_ptr[1]); + image_multi_getimg (hdr, 1, &rd_data, &rd_len); } else { /* no initrd image */ show_boot_progress (14); - len = data = 0; + rd_len = rd_data = 0; } - if (data) { - initrd_start = data; - initrd_end = initrd_start + len; + if (rd_data) { + initrd_start = rd_data; + initrd_end = initrd_start + rd_len; } else { initrd_start = 0; initrd_end = 0; diff --git a/lib_blackfin/bf533_linux.c b/lib_blackfin/bf533_linux.c index 26c65340f2..6299415b11 100644 --- a/lib_blackfin/bf533_linux.c +++ b/lib_blackfin/bf533_linux.c @@ -42,17 +42,15 @@ extern void swap_to(int device_id); #endif -extern image_header_t header; extern void flush_instruction_cache(void); extern void flush_data_cache(void); static char *make_command_line(void); void do_bootm_linux(cmd_tbl_t * cmdtp, int flag, int argc, char *argv[], - ulong addr, ulong * len_ptr, int verify) + image_header_t *hdr, int verify) { int (*appl) (char *cmdline); char *cmdline; - image_header_t *hdr = &header; #ifdef SHARED_RESOURCES swap_to(FLASH); diff --git a/lib_i386/i386_linux.c b/lib_i386/i386_linux.c index b0cf2630ca..27a2b0d9ab 100644 --- a/lib_i386/i386_linux.c +++ b/lib_i386/i386_linux.c @@ -31,54 +31,50 @@ /*cmd_boot.c*/ extern int do_reset (cmd_tbl_t *cmdtp, int flag, int argc, char *argv[]); -extern image_header_t header; /* from cmd_bootm.c */ - void do_bootm_linux(cmd_tbl_t *cmdtp, int flag, int argc, char *argv[], - ulong addr, ulong *len_ptr, int verify) + image_header_t *hdr, int verify) { void *base_ptr; - ulong len = 0; + ulong os_data, os_len; + ulong rd_data, rd_len; ulong initrd_start, initrd_end; - ulong data; - image_header_t *hdr = &header; + image_header_t *rd_hdr; /* * Check if there is an initrd image */ if (argc >= 3) { - addr = simple_strtoul(argv[2], NULL, 16); - hdr = (image_header_t *)addr; - - printf ("## Loading Ramdisk Image at %08lx ...\n", addr); + rd_hdr = (image_header_t *)simple_strtoul (argv[2], NULL, 16); + printf ("## Loading Ramdisk Image at %08lx ...\n", rd_hdr); - if (!image_check_magic (hdr)) { + if (!image_check_magic (rd_hdr)) { printf ("Bad Magic Number\n"); do_reset (cmdtp, flag, argc, argv); } - if (!image_check_hcrc (hdr)) { + if (!image_check_hcrc (rd_hdr)) { printf ("Bad Header Checksum\n"); do_reset (cmdtp, flag, argc, argv); } - print_image_hdr (hdr); + print_image_hdr (rd_hdr); - data = image_get_data (hdr); - len = image_get_data_size (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 (hdr)) { + if (!image_check_dcrc (rd_hdr)) { printf ("Bad Data CRC\n"); do_reset (cmdtp, flag, argc, argv); } printf ("OK\n"); } - if (!image_check_os (hdr, IH_OS_LINUX) || - !image_check_arch (hdr, IH_ARCH_I386) || - !image_check_type (hdr, IH_TYPE_RAMDISK)) { + 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); } @@ -86,42 +82,30 @@ void do_bootm_linux(cmd_tbl_t *cmdtp, int flag, int argc, char *argv[], /* * Now check if we have a multifile image */ - } else if (image_check_type (hdr, IH_TYPE_MULTI) && (len_ptr[1])) { - ulong tail = image_to_cpu (len_ptr[0]) % 4; - int i; - - /* skip kernel length and terminator */ - data = (ulong)(&len_ptr[2]); - /* skip any additional image length fields */ - for (i=1; len_ptr[i]; ++i) - data += 4; - /* add kernel length, and align */ - data += image_to_cpu (len_ptr[0]); - if (tail) { - data += 4 - tail; - } - - len = image_to_cpu (len_ptr[1]); - + } 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 */ - data = 0; + rd_data = rd_len = 0; } #ifdef DEBUG - if (!data) { + if (!rd_data) { printf ("No initrd\n"); } #endif - if (data) { - initrd_start = data; - initrd_end = initrd_start + len; + 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 *)data, len); + memmove ((void *)initrd_start, (void *)rd_data, rd_len); printf ("OK\n"); } else { initrd_start = 0; @@ -129,14 +113,15 @@ void do_bootm_linux(cmd_tbl_t *cmdtp, int flag, int argc, char *argv[], } /* if multi-part image, we need to advance base ptr */ - if (image_check_type (&header, IH_TYPE_MULTI) && (len_ptr[1])) { - int i; - for (i=0, addr+=sizeof(int); len_ptr[i++]; addr+=sizeof(int)); + if (image_check_type (hdr, IH_TYPE_MULTI)) { + image_multi_getimg (hdr, 0, &os_data, &os_len); + } else { + os_data = image_get_data (hdr); + os_len = image_get_data_size (hdr); } - base_ptr = load_zimage ((void*)addr + image_get_header_size (), - image_get_data_size (&header), - initrd_start, initrd_end-initrd_start, 0); + base_ptr = load_zimage ((void*)os_data, os_len, + initrd_start, rd_len, 0); if (NULL == base_ptr) { printf ("## Kernel loading failed ...\n"); diff --git a/lib_m68k/m68k_linux.c b/lib_m68k/m68k_linux.c index 0af2eae568..b135556a99 100644 --- a/lib_m68k/m68k_linux.c +++ b/lib_m68k/m68k_linux.c @@ -44,26 +44,25 @@ DECLARE_GLOBAL_DATA_PTR; # define SHOW_BOOT_PROGRESS(arg) #endif -extern image_header_t header; - 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[], - ulong addr, ulong * len_ptr, int verify) + image_header_t *hdr, int verify) { ulong sp; - ulong len; - ulong initrd_start, initrd_end; - ulong cmd_start, cmd_end; + + ulong rd_data, rd_len; ulong initrd_high; - ulong data; + ulong initrd_start, initrd_end; + image_header_t *rd_hdr; int initrd_copy_to_ram = 1; + + ulong cmd_start, cmd_end; char *cmdline; char *s; bd_t *kbd; void (*kernel) (bd_t *, ulong, ulong, ulong, ulong); - image_header_t *hdr = &header; if ((s = getenv("initrd_high")) != NULL) { /* a value of "no" or a similar string will act like 0, @@ -141,18 +140,16 @@ void do_bootm_linux(cmd_tbl_t * cmdtp, int flag, debug("Not skipping initrd\n"); SHOW_BOOT_PROGRESS(9); - addr = simple_strtoul(argv[2], NULL, 16); - hdr = (image_header_t *)addr; + rd_hdr = (image_header_t *)simple_strtoul (argv[2], NULL, 16); + printf ("## Loading RAMDisk Image at %08lx ...\n", rd_hdr); - printf("## Loading RAMDisk Image at %08lx ...\n", addr); - - if (!image_check_magic (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 (hdr)) { + if (!image_check_hcrc (rd_hdr)) { puts("Bad Header Checksum\n"); SHOW_BOOT_PROGRESS(-11); do_reset(cmdtp, flag, argc, argv); @@ -160,14 +157,14 @@ void do_bootm_linux(cmd_tbl_t * cmdtp, int flag, SHOW_BOOT_PROGRESS(10); - print_image_hdr (hdr); + print_image_hdr (rd_hdr); - data = image_get_data (hdr); - len = image_get_data_size (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 (hdr, CHUNKSZ)) { + if (!image_check_dcrc_wd (rd_hdr, CHUNKSZ)) { puts("Bad Data CRC\n"); SHOW_BOOT_PROGRESS(-12); do_reset(cmdtp, flag, argc, argv); @@ -177,9 +174,9 @@ void do_bootm_linux(cmd_tbl_t * cmdtp, int flag, SHOW_BOOT_PROGRESS(11); - if (!image_check_os (hdr, IH_OS_LINUX) || - !image_check_arch (hdr, IH_ARCH_M68K) || - !image_check_type (hdr, IH_TYPE_RAMDISK)) { + 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); @@ -188,44 +185,31 @@ void do_bootm_linux(cmd_tbl_t * cmdtp, int flag, /* * Now check if we have a multifile image */ - } else if (image_check_type (hdr, IH_TYPE_MULTI) && (len_ptr[1])) { - u_long tail = image_to_cpu (len_ptr[0]) % 4; - int i; - - SHOW_BOOT_PROGRESS(13); - - /* skip kernel length and terminator */ - data = (ulong) (&len_ptr[2]); - /* skip any additional image length fields */ - for (i = 1; len_ptr[i]; ++i) - data += 4; - /* add kernel length, and align */ - data += image_to_cpu (len_ptr[0]); - if (tail) { - data += 4 - tail; - } - - len = image_to_cpu (len_ptr[1]); - + } 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); - len = data = 0; + rd_len = rd_data = 0; } - if (!data) { + if (!rd_data) { debug("No initrd\n"); } - if (data) { + if (rd_data) { if (!initrd_copy_to_ram) { /* zero-copy ramdisk support */ - initrd_start = data; - initrd_end = initrd_start + len; + initrd_start = rd_data; + initrd_end = initrd_start + rd_len; } else { - initrd_start = (ulong) kbd - len; + initrd_start = (ulong) kbd - rd_len; initrd_start &= ~(4096 - 1); /* align on page */ if (initrd_high) { @@ -250,7 +234,7 @@ void do_bootm_linux(cmd_tbl_t * cmdtp, int flag, if (nsp > initrd_high) /* limit as specified */ nsp = initrd_high; - nsp -= len; + nsp -= rd_len; nsp &= ~(4096 - 1); /* align on page */ if (nsp >= sp) @@ -261,14 +245,14 @@ void do_bootm_linux(cmd_tbl_t * cmdtp, int flag, debug ("## initrd at 0x%08lX ... 0x%08lX (len=%ld=0x%lX)\n", - data, data + len - 1, len, len); + rd_data, rd_data + rd_len - 1, rd_len, rd_len); - initrd_end = initrd_start + len; + initrd_end = initrd_start + rd_len; printf(" Loading Ramdisk to %08lx, end %08lx ... ", initrd_start, initrd_end); memmove_wd((void *)initrd_start, - (void *)data, len, CHUNKSZ); + (void *)rd_data, rd_len, CHUNKSZ); puts("OK\n"); } diff --git a/lib_microblaze/microblaze_linux.c b/lib_microblaze/microblaze_linux.c index 7cd97995e8..a4fce5a73c 100644 --- a/lib_microblaze/microblaze_linux.c +++ b/lib_microblaze/microblaze_linux.c @@ -32,21 +32,21 @@ DECLARE_GLOBAL_DATA_PTR; -extern image_header_t header; /* from cmd_bootm.c */ -/*cmd_boot.c*/ 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[], - ulong addr, ulong * len_ptr, int verify) + image_header_t *hdr, int verify) { - ulong len = 0, checksum; + int i; + ulong checksum; + + ulong rd_data, rd_len; ulong initrd_start, initrd_end; - ulong data; + image_header_t *rd_hdr; + /* First parameter is mapped to $r5 for kernel boot args */ void (*theKernel) (char *); - image_header_t *hdr = &header; char *commandline = getenv ("bootargs"); - int i; theKernel = (void (*)(char *))image_get_ep (hdr); @@ -54,33 +54,30 @@ void do_bootm_linux (cmd_tbl_t * cmdtp, int flag, int argc, char *argv[], if (argc >= 3) { show_boot_progress (9); - addr = simple_strtoul (argv[2], NULL, 16); - hdr = (image_header_t *)addr; + rd_hdr = (image_header_t *)simple_strtoul (argv[2], NULL, 16); + printf ("## Loading Ramdisk Image at %08lx ...\n", rd_hdr); - printf ("## Loading Ramdisk Image at %08lx ...\n", addr); - - if (!image_check_magic (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 (hdr)) { + 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); - print_image_hdr (hdr); - - data = image_get_data (hdr); - len = image_get_data_size (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 (hdr)) { + if (!image_check_dcrc (rd_hdr)) { printf ("Bad Data CRC\n"); show_boot_progress (-12); do_reset (cmdtp, flag, argc, argv); @@ -90,9 +87,9 @@ void do_bootm_linux (cmd_tbl_t * cmdtp, int flag, int argc, char *argv[], show_boot_progress (11); - if (!image_check_os (hdr, IH_OS_LINUX) || - !image_check_arch (hdr, IH_ARCH_MICROBLAZE) || - !image_check_type (hdr, IH_TYPE_RAMDISK)) { + 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); @@ -101,42 +98,30 @@ void do_bootm_linux (cmd_tbl_t * cmdtp, int flag, int argc, char *argv[], /* * Now check if we have a multifile image */ - } else if (image_check_type (hdr, IH_TYPE_MULTI) && (len_ptr[1])) { - ulong tail = image_to_cpu (len_ptr[0]) % 4; - + } else if (image_check_type (hdr, IH_TYPE_MULTI)) { + /* + * Get second entry data start address and len + */ show_boot_progress (13); - - /* skip kernel length and terminator */ - data = (ulong) (&len_ptr[2]); - /* skip any additional image length fields */ - for (i = 1; len_ptr[i]; ++i) - data += 4; - /* add kernel length, and align */ - data += image_to_cpu (len_ptr[0]); - if (tail) { - data += 4 - tail; - } - - len = image_to_cpu (len_ptr[1]); - + image_multi_getimg (hdr, 1, &rd_data, &rd_len); } else { /* * no initrd image */ show_boot_progress (14); - data = 0; + rd_data = rd_len = 0; } #ifdef DEBUG - if (!data) { + if (!rd_data) { printf ("No initrd\n"); } #endif - if (data) { - initrd_start = data; - initrd_end = initrd_start + len; + if (rd_data) { + initrd_start = rd_data; + initrd_end = initrd_start + rd_len; } else { initrd_start = 0; initrd_end = 0; diff --git a/lib_mips/mips_linux.c b/lib_mips/mips_linux.c index 0881b6db99..7ea7571a81 100644 --- a/lib_mips/mips_linux.c +++ b/lib_mips/mips_linux.c @@ -33,8 +33,6 @@ DECLARE_GLOBAL_DATA_PTR; #define LINUX_MAX_ENVS 256 #define LINUX_MAX_ARGS 256 -extern image_header_t header; /* from cmd_bootm.c */ - extern int do_reset (cmd_tbl_t *cmdtp, int flag, int argc, char *argv[]); static int linux_argc; @@ -49,13 +47,13 @@ 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[], - ulong addr, ulong * len_ptr, int verify) + image_header_t *hdr, int verify) { - ulong len = 0; + ulong rd_data, rd_len; ulong initrd_start, initrd_end; - ulong data; + image_header_t *rd_hdr; + void (*theKernel) (int, char **, char **, int *); - image_header_t *hdr = &header; char *commandline = getenv ("bootargs"); char env_buf[12]; @@ -68,33 +66,30 @@ void do_bootm_linux (cmd_tbl_t * cmdtp, int flag, int argc, char *argv[], if (argc >= 3) { show_boot_progress (9); - addr = simple_strtoul (argv[2], NULL, 16); - hdr = (image_header_t *)addr; - - printf ("## Loading Ramdisk Image at %08lx ...\n", addr); + rd_hdr = (image_header_t *)simple_strtoul (argv[2], NULL, 16); + printf ("## Loading Ramdisk Image at %08lx ...\n", rd_hdr); - if (!image_check_magic (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 (hdr)) { + 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); - print_image_hdr (hdr); - - data = image_get_data (hdr); - len = image_get_data_size (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 (hdr)) { + if (!image_check_dcrc (rd_hdr)) { printf ("Bad Data CRC\n"); show_boot_progress (-12); do_reset (cmdtp, flag, argc, argv); @@ -104,9 +99,9 @@ void do_bootm_linux (cmd_tbl_t * cmdtp, int flag, int argc, char *argv[], show_boot_progress (11); - if (!image_check_os (hdr, IH_OS_LINUX) || - !image_check_arch (hdr, IH_ARCH_MIPS) || - !image_check_type (hdr, IH_TYPE_RAMDISK)) { + 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); @@ -115,43 +110,30 @@ void do_bootm_linux (cmd_tbl_t * cmdtp, int flag, int argc, char *argv[], /* * Now check if we have a multifile image */ - } else if (image_check_type (hdr, IH_TYPE_MULTI) && (len_ptr[1])) { - ulong tail = image_to_cpu (len_ptr[0]) % 4; - int i; - + } else if (image_check_type (hdr, IH_TYPE_MULTI)) { + /* + * Get second entry data start address and len + */ show_boot_progress (13); - - /* skip kernel length and terminator */ - data = (ulong) (&len_ptr[2]); - /* skip any additional image length fields */ - for (i = 1; len_ptr[i]; ++i) - data += 4; - /* add kernel length, and align */ - data += image_to_cpu (len_ptr[0]); - if (tail) { - data += 4 - tail; - } - - len = image_to_cpu (len_ptr[1]); - + image_multi_getimg (hdr, 1, &rd_data, &rd_len); } else { /* * no initrd image */ show_boot_progress (14); - data = 0; + rd_data = rd_len = 0; } #ifdef DEBUG - if (!data) { + if (!rd_data) { printf ("No initrd\n"); } #endif - if (data) { - initrd_start = data; - initrd_end = initrd_start + len; + if (rd_data) { + initrd_start = rd_data; + initrd_end = initrd_start + rd_len; } else { initrd_start = 0; initrd_end = 0; diff --git a/lib_nios/nios_linux.c b/lib_nios/nios_linux.c index eef17573f9..55f7e3adc1 100644 --- a/lib_nios/nios_linux.c +++ b/lib_nios/nios_linux.c @@ -29,6 +29,6 @@ * */ void do_bootm_linux(cmd_tbl_t *cmdtp, int flag, int argc, char *argv[], - ulong addr, ulong *len_ptr, int verify) + image__header_t *hdr, int verify) { } diff --git a/lib_nios2/nios_linux.c b/lib_nios2/nios_linux.c index dea1ec174a..cb843246b8 100644 --- a/lib_nios2/nios_linux.c +++ b/lib_nios2/nios_linux.c @@ -25,12 +25,9 @@ #include #include -extern image_header_t header; /* common/cmd_bootm.c */ - void do_bootm_linux(cmd_tbl_t *cmdtp, int flag, int argc, char *argv[], - ulong addr, ulong *len_ptr, int verify) + image_header_t *hdr, int verify) { - image_header_t *hdr = &header; void (*kernel)(void) = (void (*)(void))image_get_ep (hdr); /* For now we assume the Microtronix linux ... which only diff --git a/lib_ppc/ppc_linux.c b/lib_ppc/ppc_linux.c index 6e2afed9b0..0a625fc071 100644 --- a/lib_ppc/ppc_linux.c +++ b/lib_ppc/ppc_linux.c @@ -50,9 +50,7 @@ #endif DECLARE_GLOBAL_DATA_PTR; -extern image_header_t header; -/*cmd_boot.c*/ extern int do_reset (cmd_tbl_t *cmdtp, int flag, int argc, char *argv[]); #if defined(CONFIG_CMD_BDI) @@ -60,25 +58,27 @@ extern int do_bdinfo(cmd_tbl_t *cmdtp, int flag, int argc, char *argv[]); #endif void __attribute__((noinline)) -do_bootm_linux (cmd_tbl_t *cmdtp, int flag, +do_bootm_linux(cmd_tbl_t *cmdtp, int flag, int argc, char *argv[], - ulong addr, - ulong *len_ptr, + image_header_t *hdr, int verify) { - ulong sp; - ulong len; - ulong initrd_start, initrd_end; - ulong cmd_start, cmd_end; ulong initrd_high; - ulong data; int initrd_copy_to_ram = 1; + ulong initrd_start, initrd_end; + ulong rd_data, rd_len; + image_header_t *rd_hdr; + + ulong cmd_start, cmd_end; char *cmdline; + + ulong sp; char *s; bd_t *kbd; void (*kernel)(bd_t *, ulong, ulong, ulong, ulong); - image_header_t *hdr = &header; + #if defined(CONFIG_OF_FLAT_TREE) || defined(CONFIG_OF_LIBFDT) + image_header_t *fdt_hdr; char *of_flat_tree = NULL; ulong of_data = 0; #endif @@ -177,7 +177,7 @@ do_bootm_linux (cmd_tbl_t *cmdtp, int flag, /* Look for a '-' which indicates to ignore the ramdisk argument */ if (argc >= 3 && strcmp(argv[2], "-") == 0) { debug ("Skipping initrd\n"); - len = data = 0; + rd_len = rd_data = 0; } else #endif @@ -185,30 +185,28 @@ do_bootm_linux (cmd_tbl_t *cmdtp, int flag, debug ("Not skipping initrd\n"); show_boot_progress (9); - addr = simple_strtoul(argv[2], NULL, 16); + rd_hdr = (image_header_t *)simple_strtoul (argv[2], NULL, 16); + printf ("## Loading RAMDisk Image at %08lx ...\n", (ulong)rd_hdr); - printf ("## Loading RAMDisk Image at %08lx ...\n", addr); - hdr = (image_header_t *)addr; - - if (!image_check_magic (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 (hdr)) { + 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 (hdr); + print_image_hdr (rd_hdr); if (verify) { puts (" Verifying Checksum ... "); - if (!image_check_dcrc_wd (hdr, CHUNKSZ)) { + if (!image_check_dcrc_wd (rd_hdr, CHUNKSZ)) { puts ("Bad Data CRC\n"); show_boot_progress (-12); do_reset (cmdtp, flag, argc, argv); @@ -218,52 +216,39 @@ do_bootm_linux (cmd_tbl_t *cmdtp, int flag, show_boot_progress (11); - if (!image_check_os (hdr, IH_OS_LINUX) || - !image_check_arch (hdr, IH_ARCH_PPC) || - !image_check_type (hdr, IH_TYPE_RAMDISK)) { + 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); } - data = image_get_data (hdr); - len = image_get_data_size (hdr); + 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) && (len_ptr[1])) { - u_long tail = image_to_cpu (len_ptr[0]) % 4; - int i; - + } 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); - - /* skip kernel length and terminator */ - data = (ulong)(&len_ptr[2]); - /* skip any additional image length fields */ - for (i=1; len_ptr[i]; ++i) - data += 4; - /* add kernel length, and align */ - data += image_to_cpu (len_ptr[0]); - if (tail) { - data += 4 - tail; - } - - len = image_to_cpu (len_ptr[1]); - } else { /* - * no initrd image + * No initrd image */ show_boot_progress (14); - len = data = 0; + rd_len = rd_data = 0; } #if defined(CONFIG_OF_FLAT_TREE) || defined(CONFIG_OF_LIBFDT) if(argc > 3) { of_flat_tree = (char *) simple_strtoul(argv[3], NULL, 16); - hdr = (image_header_t *)of_flat_tree; + fdt_hdr = (image_header_t *)of_flat_tree; #if defined(CONFIG_OF_FLAT_TREE) if (*((ulong *)(of_flat_tree)) == OF_DT_HEADER) { #elif defined(CONFIG_OF_LIBFDT) @@ -273,37 +258,37 @@ do_bootm_linux (cmd_tbl_t *cmdtp, int flag, if (addr2info((ulong)of_flat_tree) != NULL) of_data = (ulong)of_flat_tree; #endif - } else if (image_check_magic (hdr)) { - printf("## Flat Device Tree at %08lX\n", hdr); - print_image_hdr (hdr); + } else if (image_check_magic (fdt_hdr)) { + printf ("## Flat Device Tree at %08lX\n", fdt_hdr); + print_image_hdr (fdt_hdr); - if ((image_get_load (hdr) < ((unsigned long)hdr + image_get_image_size (hdr))) && - ((image_get_load (hdr) + image_get_data_size (hdr)) > (unsigned long)hdr)) { + if ((image_get_load (fdt_hdr) < image_get_image_end (fdt_hdr)) && + ((image_get_load (fdt_hdr) + image_get_data_size (fdt_hdr)) > (unsigned long)fdt_hdr)) { puts ("ERROR: fdt overwritten - " "must RESET the board to recover.\n"); do_reset (cmdtp, flag, argc, argv); } puts (" Verifying Checksum ... "); - if (!image_check_hcrc (hdr)) { + if (!image_check_hcrc (fdt_hdr)) { puts ("ERROR: fdt header checksum invalid - " "must RESET the board to recover.\n"); do_reset (cmdtp, flag, argc, argv); } - if (!image_check_dcrc (hdr)) { + if (!image_check_dcrc (fdt_hdr)) { puts ("ERROR: fdt checksum invalid - " "must RESET the board to recover.\n"); do_reset (cmdtp, flag, argc, argv); } puts ("OK\n"); - if (!image_check_type (hdr, IH_TYPE_FLATDT)) { + if (!image_check_type (fdt_hdr, IH_TYPE_FLATDT)) { puts ("ERROR: uImage is not a fdt - " "must RESET the board to recover.\n"); do_reset (cmdtp, flag, argc, argv); } - if (image_get_comp (hdr) != IH_COMP_NONE) { + if (image_get_comp (fdt_hdr) != IH_COMP_NONE) { puts ("ERROR: uImage is compressed - " "must RESET the board to recover.\n"); do_reset (cmdtp, flag, argc, argv); @@ -318,11 +303,11 @@ do_bootm_linux (cmd_tbl_t *cmdtp, int flag, do_reset (cmdtp, flag, argc, argv); } - memmove ((void *)image_get_load (hdr), + memmove ((void *)image_get_load (fdt_hdr), (void *)(of_flat_tree + image_get_header_size ()), - image_get_data_size (hdr)); + image_get_data_size (fdt_hdr)); - of_flat_tree = (char *)image_get_load (hdr); + of_flat_tree = (char *)image_get_load (fdt_hdr); } else { puts ("Did not find a flat Flat Device Tree.\n" "Must RESET the board to recover.\n"); @@ -330,68 +315,52 @@ do_bootm_linux (cmd_tbl_t *cmdtp, int flag, } printf (" Booting using the fdt at 0x%x\n", of_flat_tree); - } else if (image_check_type (hdr, IH_TYPE_MULTI) && (len_ptr[1]) && (len_ptr[2])) { - u_long tail = image_to_cpu (len_ptr[0]) % 4; - int i; - - /* skip kernel length, initrd length, and terminator */ - of_flat_tree = (char *)(&len_ptr[3]); - /* skip any additional image length fields */ - for (i=2; len_ptr[i]; ++i) - of_flat_tree += 4; - /* add kernel length, and align */ - of_flat_tree += image_to_cpu (len_ptr[0]); - if (tail) { - of_flat_tree += 4 - tail; - } + } else if (image_check_type (hdr, IH_TYPE_MULTI)) { + ulong fdt_data, fdt_len; - /* add initrd length, and align */ - tail = image_to_cpu (len_ptr[1]) % 4; - of_flat_tree += image_to_cpu (len_ptr[1]); - if (tail) { - of_flat_tree += 4 - tail; - } + 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; + /* 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 defined(CONFIG_OF_FLAT_TREE) - if (*((ulong *)(of_flat_tree)) != OF_DT_HEADER) { + if (*((ulong *)(of_flat_tree)) != OF_DT_HEADER) { #elif defined(CONFIG_OF_LIBFDT) - if (fdt_check_header (of_flat_tree) != 0) { + if (fdt_check_header (of_flat_tree) != 0) { #endif - puts ("ERROR: image is not a fdt - " - "must RESET the board to recover.\n"); - do_reset (cmdtp, flag, argc, argv); - } + puts ("ERROR: image is not a fdt - " + "must RESET the board to recover.\n"); + do_reset (cmdtp, flag, argc, argv); + } #if defined(CONFIG_OF_FLAT_TREE) - if (((struct boot_param_header *)of_flat_tree)->totalsize != - image_to_cpu (len_ptr[2])) { + if (((struct boot_param_header *)of_flat_tree)->totalsize != fdt_len) { #elif defined(CONFIG_OF_LIBFDT) - if (be32_to_cpu (fdt_totalsize (of_flat_tree)) != - image_to_cpu (len_ptr[2])) { + if (be32_to_cpu (fdt_totalsize (of_flat_tree)) != fdt_len) { #endif - puts ("ERROR: fdt size != image size - " - "must RESET the board to recover.\n"); - do_reset (cmdtp, flag, argc, argv); + puts ("ERROR: fdt size != image size - " + "must RESET the board to recover.\n"); + do_reset (cmdtp, flag, argc, argv); + } } } #endif - if (!data) { + if (!rd_data) { debug ("No initrd\n"); } - if (data) { + if (rd_data) { if (!initrd_copy_to_ram) { /* zero-copy ramdisk support */ - initrd_start = data; - initrd_end = initrd_start + len; + initrd_start = rd_data; + initrd_end = initrd_start + rd_len; } else { - initrd_start = (ulong)kbd - len; + initrd_start = (ulong)kbd - rd_len; initrd_start &= ~(4096 - 1); /* align on page */ if (initrd_high) { @@ -412,7 +381,7 @@ do_bootm_linux (cmd_tbl_t *cmdtp, int flag, nsp &= ~0xF; if (nsp > initrd_high) /* limit as specified */ nsp = initrd_high; - nsp -= len; + nsp -= rd_len; nsp &= ~(4096 - 1); /* align on page */ if (nsp >= sp) initrd_start = nsp; @@ -421,14 +390,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", - data, data + len - 1, len, len); + rd_data, rd_data + rd_len - 1, rd_len, rd_len); - initrd_end = initrd_start + len; + initrd_end = initrd_start + rd_len; printf (" Loading Ramdisk to %08lx, end %08lx ... ", initrd_start, initrd_end); memmove_wd((void *)initrd_start, - (void *)data, len, CHUNKSZ); + (void *)rd_data, rd_len, CHUNKSZ); puts ("OK\n"); } -- cgit v1.2.3 From 4a995edec1ac163d9326d143ffe2b47e7543407f Mon Sep 17 00:00:00 2001 From: Marian Balakowicz Date: Thu, 31 Jan 2008 13:20:06 +0100 Subject: [new uImage] Rename architecture specific bootm code files Implementation of the do_bootm_linux() and other bootm helper routines is architecture specific code. As such it resides in lib_ directories in files named _linux.c This patch renames those files to a more clear and accurate lib_/bootm.c form. List of the renamed files: lib_arm/armlinux.c -> lib_arm/bootm.c lib_avr32/avr32_linux.c -> lib_avr32/bootm.c lib_blackfin/bf533_linux.c -> lib_blackfin/bootm.c lib_i386/i386_linux.c -> lib_i386/bootm.c lib_m68k/m68k_linux.c -> lib_m68k/bootm.c lib_microblaze/microblaze_linux.c -> lib_microblaze/bootm.c lib_mips/mips_linux.c -> lib_mips/bootm.c lib_nios/nios_linux.c -> lib_nios/bootm.c lib_nios2/nios_linux.c -> lib_nios2/bootm.c lib_ppc/ppc_linux.c -> lib_ppc/bootm.c lib_sh/sh_linux.c -> lib_sh/bootm.c Signed-off-by: Marian Balakowicz --- lib_arm/Makefile | 2 +- lib_arm/armlinux.c | 384 -------------------------- lib_arm/bootm.c | 384 ++++++++++++++++++++++++++ lib_avr32/Makefile | 2 +- lib_avr32/avr32_linux.c | 277 ------------------- lib_avr32/bootm.c | 277 +++++++++++++++++++ lib_blackfin/Makefile | 2 +- lib_blackfin/bf533_linux.c | 84 ------ lib_blackfin/bootm.c | 84 ++++++ lib_i386/Makefile | 2 +- lib_i386/bootm.c | 142 ++++++++++ lib_i386/i386_linux.c | 142 ---------- lib_m68k/Makefile | 2 +- lib_m68k/bootm.c | 279 +++++++++++++++++++ lib_m68k/m68k_linux.c | 279 ------------------- lib_microblaze/Makefile | 2 +- lib_microblaze/bootm.c | 138 ++++++++++ lib_microblaze/microblaze_linux.c | 138 ---------- lib_mips/Makefile | 2 +- lib_mips/bootm.c | 249 +++++++++++++++++ lib_mips/mips_linux.c | 249 ----------------- lib_nios/Makefile | 2 +- lib_nios/bootm.c | 34 +++ lib_nios/nios_linux.c | 34 --- lib_nios2/Makefile | 2 +- lib_nios2/bootm.c | 37 +++ lib_nios2/nios_linux.c | 37 --- lib_ppc/Makefile | 2 +- lib_ppc/bootm.c | 554 ++++++++++++++++++++++++++++++++++++++ lib_ppc/ppc_linux.c | 554 -------------------------------------- lib_sh/Makefile | 2 +- lib_sh/bootm.c | 74 +++++ lib_sh/sh_linux.c | 74 ----- 33 files changed, 2263 insertions(+), 2263 deletions(-) delete mode 100644 lib_arm/armlinux.c create mode 100644 lib_arm/bootm.c delete mode 100644 lib_avr32/avr32_linux.c create mode 100644 lib_avr32/bootm.c delete mode 100644 lib_blackfin/bf533_linux.c create mode 100644 lib_blackfin/bootm.c create mode 100644 lib_i386/bootm.c delete mode 100644 lib_i386/i386_linux.c create mode 100644 lib_m68k/bootm.c delete mode 100644 lib_m68k/m68k_linux.c create mode 100644 lib_microblaze/bootm.c delete mode 100644 lib_microblaze/microblaze_linux.c create mode 100644 lib_mips/bootm.c delete mode 100644 lib_mips/mips_linux.c create mode 100644 lib_nios/bootm.c delete mode 100644 lib_nios/nios_linux.c create mode 100644 lib_nios2/bootm.c delete mode 100644 lib_nios2/nios_linux.c create mode 100644 lib_ppc/bootm.c delete mode 100644 lib_ppc/ppc_linux.c create mode 100644 lib_sh/bootm.c delete mode 100644 lib_sh/sh_linux.c (limited to 'lib_m68k/m68k_linux.c') diff --git a/lib_arm/Makefile b/lib_arm/Makefile index 037c475f8b..aa9bee75cc 100644 --- a/lib_arm/Makefile +++ b/lib_arm/Makefile @@ -27,7 +27,7 @@ LIB = $(obj)lib$(ARCH).a SOBJS = _ashldi3.o _ashrdi3.o _divsi3.o _modsi3.o _udivsi3.o _umodsi3.o -COBJS = armlinux.o board.o \ +COBJS = bootm.o board.o \ cache.o div0.o SRCS := $(SOBJS:.o=.S) $(COBJS:.o=.c) diff --git a/lib_arm/armlinux.c b/lib_arm/armlinux.c deleted file mode 100644 index 4f9aae613e..0000000000 --- a/lib_arm/armlinux.c +++ /dev/null @@ -1,384 +0,0 @@ -/* - * (C) Copyright 2002 - * Sysgo Real-Time Solutions, GmbH - * Marius Groeger - * - * Copyright (C) 2001 Erik Mouw (J.A.K.Mouw@its.tudelft.nl) - * - * This program is free software; you can redistribute it and/or modify - * it under the terms of the GNU General Public License as published by - * the Free Software Foundation; either version 2 of the License, or - * (at your option) any later version. - * - * This program is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - * GNU General Public License for more details. - * - * You should have received a copy of the GNU General Public License - * along with this program; if not, write to the Free Software - * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA - * - */ - -#include -#include -#include -#include -#include -#ifdef CONFIG_HAS_DATAFLASH -#include -#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) || \ - defined (CONFIG_SERIAL_TAG) || \ - defined (CONFIG_REVISION_TAG) || \ - defined (CONFIG_VFD) || \ - defined (CONFIG_LCD) -static void setup_start_tag (bd_t *bd); - -# ifdef CONFIG_SETUP_MEMORY_TAGS -static void setup_memory_tags (bd_t *bd); -# endif -static void setup_commandline_tag (bd_t *bd, char *commandline); - -#if 0 -static void setup_ramdisk_tag (bd_t *bd); -#endif -# ifdef CONFIG_INITRD_TAG -static void setup_initrd_tag (bd_t *bd, ulong initrd_start, - ulong initrd_end); -# endif -static void setup_end_tag (bd_t *bd); - -# if defined (CONFIG_VFD) || defined (CONFIG_LCD) -static void setup_videolfb_tag (gd_t *gd); -# endif - - -static struct tag *params; -#endif /* CONFIG_SETUP_MEMORY_TAGS || CONFIG_CMDLINE_TAG || CONFIG_INITRD_TAG */ - -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; - -#ifdef CONFIG_CMDLINE_TAG - char *commandline = getenv ("bootargs"); -#endif - - 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; - } - - show_boot_progress (15); - - debug ("## Transferring control to Linux (at address %08lx) ...\n", - (ulong) theKernel); - -#if defined (CONFIG_SETUP_MEMORY_TAGS) || \ - defined (CONFIG_CMDLINE_TAG) || \ - defined (CONFIG_INITRD_TAG) || \ - defined (CONFIG_SERIAL_TAG) || \ - defined (CONFIG_REVISION_TAG) || \ - defined (CONFIG_LCD) || \ - defined (CONFIG_VFD) - setup_start_tag (bd); -#ifdef CONFIG_SERIAL_TAG - setup_serial_tag (¶ms); -#endif -#ifdef CONFIG_REVISION_TAG - setup_revision_tag (¶ms); -#endif -#ifdef CONFIG_SETUP_MEMORY_TAGS - setup_memory_tags (bd); -#endif -#ifdef CONFIG_CMDLINE_TAG - setup_commandline_tag (bd, commandline); -#endif -#ifdef CONFIG_INITRD_TAG - if (initrd_start && initrd_end) - setup_initrd_tag (bd, initrd_start, initrd_end); -#endif -#if defined (CONFIG_VFD) || defined (CONFIG_LCD) - setup_videolfb_tag ((gd_t *) gd); -#endif - setup_end_tag (bd); -#endif - - /* we assume that the kernel is in place */ - printf ("\nStarting kernel ...\n\n"); - -#ifdef CONFIG_USB_DEVICE - { - extern void udc_disconnect (void); - udc_disconnect (); - } -#endif - - cleanup_before_linux (); - - theKernel (0, bd->bi_arch_number, bd->bi_boot_params); -} - - -#if defined (CONFIG_SETUP_MEMORY_TAGS) || \ - defined (CONFIG_CMDLINE_TAG) || \ - defined (CONFIG_INITRD_TAG) || \ - defined (CONFIG_SERIAL_TAG) || \ - defined (CONFIG_REVISION_TAG) || \ - defined (CONFIG_LCD) || \ - defined (CONFIG_VFD) -static void setup_start_tag (bd_t *bd) -{ - params = (struct tag *) bd->bi_boot_params; - - params->hdr.tag = ATAG_CORE; - params->hdr.size = tag_size (tag_core); - - params->u.core.flags = 0; - params->u.core.pagesize = 0; - params->u.core.rootdev = 0; - - params = tag_next (params); -} - - -#ifdef CONFIG_SETUP_MEMORY_TAGS -static void setup_memory_tags (bd_t *bd) -{ - int i; - - for (i = 0; i < CONFIG_NR_DRAM_BANKS; i++) { - params->hdr.tag = ATAG_MEM; - params->hdr.size = tag_size (tag_mem32); - - params->u.mem.start = bd->bi_dram[i].start; - params->u.mem.size = bd->bi_dram[i].size; - - params = tag_next (params); - } -} -#endif /* CONFIG_SETUP_MEMORY_TAGS */ - - -static void setup_commandline_tag (bd_t *bd, char *commandline) -{ - char *p; - - if (!commandline) - return; - - /* eat leading white space */ - for (p = commandline; *p == ' '; p++); - - /* skip non-existent command lines so the kernel will still - * use its default command line. - */ - if (*p == '\0') - return; - - params->hdr.tag = ATAG_CMDLINE; - params->hdr.size = - (sizeof (struct tag_header) + strlen (p) + 1 + 4) >> 2; - - strcpy (params->u.cmdline.cmdline, p); - - params = tag_next (params); -} - - -#ifdef CONFIG_INITRD_TAG -static void setup_initrd_tag (bd_t *bd, ulong initrd_start, ulong initrd_end) -{ - /* an ATAG_INITRD node tells the kernel where the compressed - * ramdisk can be found. ATAG_RDIMG is a better name, actually. - */ - params->hdr.tag = ATAG_INITRD2; - params->hdr.size = tag_size (tag_initrd); - - params->u.initrd.start = initrd_start; - params->u.initrd.size = initrd_end - initrd_start; - - params = tag_next (params); -} -#endif /* CONFIG_INITRD_TAG */ - - -#if defined (CONFIG_VFD) || defined (CONFIG_LCD) -extern ulong calc_fbsize (void); -static void setup_videolfb_tag (gd_t *gd) -{ - /* An ATAG_VIDEOLFB node tells the kernel where and how large - * the framebuffer for video was allocated (among other things). - * Note that a _physical_ address is passed ! - * - * We only use it to pass the address and size, the other entries - * in the tag_videolfb are not of interest. - */ - params->hdr.tag = ATAG_VIDEOLFB; - params->hdr.size = tag_size (tag_videolfb); - - params->u.videolfb.lfb_base = (u32) gd->fb_base; - /* Fb size is calculated according to parameters for our panel - */ - params->u.videolfb.lfb_size = calc_fbsize(); - - params = tag_next (params); -} -#endif /* CONFIG_VFD || CONFIG_LCD */ - -#ifdef CONFIG_SERIAL_TAG -void setup_serial_tag (struct tag **tmp) -{ - struct tag *params = *tmp; - struct tag_serialnr serialnr; - void get_board_serial(struct tag_serialnr *serialnr); - - get_board_serial(&serialnr); - params->hdr.tag = ATAG_SERIAL; - params->hdr.size = tag_size (tag_serialnr); - params->u.serialnr.low = serialnr.low; - params->u.serialnr.high= serialnr.high; - params = tag_next (params); - *tmp = params; -} -#endif - -#ifdef CONFIG_REVISION_TAG -void setup_revision_tag(struct tag **in_params) -{ - u32 rev = 0; - u32 get_board_rev(void); - - rev = get_board_rev(); - params->hdr.tag = ATAG_REVISION; - params->hdr.size = tag_size (tag_revision); - params->u.revision.rev = rev; - params = tag_next (params); -} -#endif /* CONFIG_REVISION_TAG */ - - -static void setup_end_tag (bd_t *bd) -{ - params->hdr.tag = ATAG_NONE; - params->hdr.size = 0; -} - -#endif /* CONFIG_SETUP_MEMORY_TAGS || CONFIG_CMDLINE_TAG || CONFIG_INITRD_TAG */ diff --git a/lib_arm/bootm.c b/lib_arm/bootm.c new file mode 100644 index 0000000000..4f9aae613e --- /dev/null +++ b/lib_arm/bootm.c @@ -0,0 +1,384 @@ +/* + * (C) Copyright 2002 + * Sysgo Real-Time Solutions, GmbH + * Marius Groeger + * + * Copyright (C) 2001 Erik Mouw (J.A.K.Mouw@its.tudelft.nl) + * + * This program is free software; you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation; either version 2 of the License, or + * (at your option) any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with this program; if not, write to the Free Software + * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA + * + */ + +#include +#include +#include +#include +#include +#ifdef CONFIG_HAS_DATAFLASH +#include +#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) || \ + defined (CONFIG_SERIAL_TAG) || \ + defined (CONFIG_REVISION_TAG) || \ + defined (CONFIG_VFD) || \ + defined (CONFIG_LCD) +static void setup_start_tag (bd_t *bd); + +# ifdef CONFIG_SETUP_MEMORY_TAGS +static void setup_memory_tags (bd_t *bd); +# endif +static void setup_commandline_tag (bd_t *bd, char *commandline); + +#if 0 +static void setup_ramdisk_tag (bd_t *bd); +#endif +# ifdef CONFIG_INITRD_TAG +static void setup_initrd_tag (bd_t *bd, ulong initrd_start, + ulong initrd_end); +# endif +static void setup_end_tag (bd_t *bd); + +# if defined (CONFIG_VFD) || defined (CONFIG_LCD) +static void setup_videolfb_tag (gd_t *gd); +# endif + + +static struct tag *params; +#endif /* CONFIG_SETUP_MEMORY_TAGS || CONFIG_CMDLINE_TAG || CONFIG_INITRD_TAG */ + +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; + +#ifdef CONFIG_CMDLINE_TAG + char *commandline = getenv ("bootargs"); +#endif + + 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; + } + + show_boot_progress (15); + + debug ("## Transferring control to Linux (at address %08lx) ...\n", + (ulong) theKernel); + +#if defined (CONFIG_SETUP_MEMORY_TAGS) || \ + defined (CONFIG_CMDLINE_TAG) || \ + defined (CONFIG_INITRD_TAG) || \ + defined (CONFIG_SERIAL_TAG) || \ + defined (CONFIG_REVISION_TAG) || \ + defined (CONFIG_LCD) || \ + defined (CONFIG_VFD) + setup_start_tag (bd); +#ifdef CONFIG_SERIAL_TAG + setup_serial_tag (¶ms); +#endif +#ifdef CONFIG_REVISION_TAG + setup_revision_tag (¶ms); +#endif +#ifdef CONFIG_SETUP_MEMORY_TAGS + setup_memory_tags (bd); +#endif +#ifdef CONFIG_CMDLINE_TAG + setup_commandline_tag (bd, commandline); +#endif +#ifdef CONFIG_INITRD_TAG + if (initrd_start && initrd_end) + setup_initrd_tag (bd, initrd_start, initrd_end); +#endif +#if defined (CONFIG_VFD) || defined (CONFIG_LCD) + setup_videolfb_tag ((gd_t *) gd); +#endif + setup_end_tag (bd); +#endif + + /* we assume that the kernel is in place */ + printf ("\nStarting kernel ...\n\n"); + +#ifdef CONFIG_USB_DEVICE + { + extern void udc_disconnect (void); + udc_disconnect (); + } +#endif + + cleanup_before_linux (); + + theKernel (0, bd->bi_arch_number, bd->bi_boot_params); +} + + +#if defined (CONFIG_SETUP_MEMORY_TAGS) || \ + defined (CONFIG_CMDLINE_TAG) || \ + defined (CONFIG_INITRD_TAG) || \ + defined (CONFIG_SERIAL_TAG) || \ + defined (CONFIG_REVISION_TAG) || \ + defined (CONFIG_LCD) || \ + defined (CONFIG_VFD) +static void setup_start_tag (bd_t *bd) +{ + params = (struct tag *) bd->bi_boot_params; + + params->hdr.tag = ATAG_CORE; + params->hdr.size = tag_size (tag_core); + + params->u.core.flags = 0; + params->u.core.pagesize = 0; + params->u.core.rootdev = 0; + + params = tag_next (params); +} + + +#ifdef CONFIG_SETUP_MEMORY_TAGS +static void setup_memory_tags (bd_t *bd) +{ + int i; + + for (i = 0; i < CONFIG_NR_DRAM_BANKS; i++) { + params->hdr.tag = ATAG_MEM; + params->hdr.size = tag_size (tag_mem32); + + params->u.mem.start = bd->bi_dram[i].start; + params->u.mem.size = bd->bi_dram[i].size; + + params = tag_next (params); + } +} +#endif /* CONFIG_SETUP_MEMORY_TAGS */ + + +static void setup_commandline_tag (bd_t *bd, char *commandline) +{ + char *p; + + if (!commandline) + return; + + /* eat leading white space */ + for (p = commandline; *p == ' '; p++); + + /* skip non-existent command lines so the kernel will still + * use its default command line. + */ + if (*p == '\0') + return; + + params->hdr.tag = ATAG_CMDLINE; + params->hdr.size = + (sizeof (struct tag_header) + strlen (p) + 1 + 4) >> 2; + + strcpy (params->u.cmdline.cmdline, p); + + params = tag_next (params); +} + + +#ifdef CONFIG_INITRD_TAG +static void setup_initrd_tag (bd_t *bd, ulong initrd_start, ulong initrd_end) +{ + /* an ATAG_INITRD node tells the kernel where the compressed + * ramdisk can be found. ATAG_RDIMG is a better name, actually. + */ + params->hdr.tag = ATAG_INITRD2; + params->hdr.size = tag_size (tag_initrd); + + params->u.initrd.start = initrd_start; + params->u.initrd.size = initrd_end - initrd_start; + + params = tag_next (params); +} +#endif /* CONFIG_INITRD_TAG */ + + +#if defined (CONFIG_VFD) || defined (CONFIG_LCD) +extern ulong calc_fbsize (void); +static void setup_videolfb_tag (gd_t *gd) +{ + /* An ATAG_VIDEOLFB node tells the kernel where and how large + * the framebuffer for video was allocated (among other things). + * Note that a _physical_ address is passed ! + * + * We only use it to pass the address and size, the other entries + * in the tag_videolfb are not of interest. + */ + params->hdr.tag = ATAG_VIDEOLFB; + params->hdr.size = tag_size (tag_videolfb); + + params->u.videolfb.lfb_base = (u32) gd->fb_base; + /* Fb size is calculated according to parameters for our panel + */ + params->u.videolfb.lfb_size = calc_fbsize(); + + params = tag_next (params); +} +#endif /* CONFIG_VFD || CONFIG_LCD */ + +#ifdef CONFIG_SERIAL_TAG +void setup_serial_tag (struct tag **tmp) +{ + struct tag *params = *tmp; + struct tag_serialnr serialnr; + void get_board_serial(struct tag_serialnr *serialnr); + + get_board_serial(&serialnr); + params->hdr.tag = ATAG_SERIAL; + params->hdr.size = tag_size (tag_serialnr); + params->u.serialnr.low = serialnr.low; + params->u.serialnr.high= serialnr.high; + params = tag_next (params); + *tmp = params; +} +#endif + +#ifdef CONFIG_REVISION_TAG +void setup_revision_tag(struct tag **in_params) +{ + u32 rev = 0; + u32 get_board_rev(void); + + rev = get_board_rev(); + params->hdr.tag = ATAG_REVISION; + params->hdr.size = tag_size (tag_revision); + params->u.revision.rev = rev; + params = tag_next (params); +} +#endif /* CONFIG_REVISION_TAG */ + + +static void setup_end_tag (bd_t *bd) +{ + params->hdr.tag = ATAG_NONE; + params->hdr.size = 0; +} + +#endif /* CONFIG_SETUP_MEMORY_TAGS || CONFIG_CMDLINE_TAG || CONFIG_INITRD_TAG */ diff --git a/lib_avr32/Makefile b/lib_avr32/Makefile index bb2938fe5c..ebe237b157 100644 --- a/lib_avr32/Makefile +++ b/lib_avr32/Makefile @@ -29,7 +29,7 @@ LIB = $(obj)lib$(ARCH).a SOBJS = memset.o -COBJS = board.o interrupts.o avr32_linux.o +COBJS = board.o interrupts.o bootm.o SRCS := $(SOBJS:.o=.S) $(COBJS:.o=.c) OBJS := $(addprefix $(obj),$(SOBJS) $(COBJS)) diff --git a/lib_avr32/avr32_linux.c b/lib_avr32/avr32_linux.c deleted file mode 100644 index 455590e37d..0000000000 --- a/lib_avr32/avr32_linux.c +++ /dev/null @@ -1,277 +0,0 @@ -/* - * Copyright (C) 2004-2006 Atmel Corporation - * - * See file CREDITS for list of people who contributed to this - * project. - * - * This program is free software; you can redistribute it and/or - * modify it under the terms of the GNU General Public License as - * published by the Free Software Foundation; either version 2 of - * the License, or (at your option) any later version. - * - * This program is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - * GNU General Public License for more details. - * - * You should have received a copy of the GNU General Public License - * along with this program; if not, write to the Free Software - * Foundation, Inc., 59 Temple Place, Suite 330, Boston, - * MA 02111-1307 USA - */ -#include -#include -#include -#include -#include -#include -#include -#include -#include - -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); - -static struct tag *setup_start_tag(struct tag *params) -{ - params->hdr.tag = ATAG_CORE; - params->hdr.size = tag_size(tag_core); - - params->u.core.flags = 0; - params->u.core.pagesize = 4096; - params->u.core.rootdev = 0; - - return tag_next(params); -} - -static struct tag *setup_memory_tags(struct tag *params) -{ - bd_t *bd = gd->bd; - int i; - - for (i = 0; i < CONFIG_NR_DRAM_BANKS; i++) { - params->hdr.tag = ATAG_MEM; - params->hdr.size = tag_size(tag_mem_range); - - params->u.mem_range.addr = bd->bi_dram[i].start; - params->u.mem_range.size = bd->bi_dram[i].size; - - params = tag_next(params); - } - - return params; -} - -static struct tag *setup_commandline_tag(struct tag *params, char *cmdline) -{ - if (!cmdline) - return params; - - /* eat leading white space */ - while (*cmdline == ' ') cmdline++; - - /* - * Don't include tags for empty command lines; let the kernel - * use its default command line. - */ - if (*cmdline == '\0') - return params; - - params->hdr.tag = ATAG_CMDLINE; - params->hdr.size = - (sizeof (struct tag_header) + strlen(cmdline) + 1 + 3) >> 2; - strcpy(params->u.cmdline.cmdline, cmdline); - - return tag_next(params); -} - -static struct tag *setup_ramdisk_tag(struct tag *params, - unsigned long rd_start, - unsigned long rd_end) -{ - if (rd_start == rd_end) - return params; - - params->hdr.tag = ATAG_RDIMG; - params->hdr.size = tag_size(tag_mem_range); - - params->u.mem_range.addr = rd_start; - params->u.mem_range.size = rd_end - rd_start; - - return tag_next(params); -} - -static struct tag *setup_clock_tags(struct tag *params) -{ - params->hdr.tag = ATAG_CLOCK; - params->hdr.size = tag_size(tag_clock); - params->u.clock.clock_id = ACLOCK_BOOTCPU; - params->u.clock.clock_flags = 0; - params->u.clock.clock_hz = gd->cpu_hz; - -#ifdef CONFIG_AT32AP7000 - /* - * New kernels don't need this, but we should be backwards - * compatible for a while... - */ - params = tag_next(params); - - params->hdr.tag = ATAG_CLOCK; - params->hdr.size = tag_size(tag_clock); - params->u.clock.clock_id = ACLOCK_HSB; - params->u.clock.clock_flags = 0; - params->u.clock.clock_hz = get_hsb_clk_rate(); -#endif - - return tag_next(params); -} - -static struct tag *setup_ethernet_tag(struct tag *params, - char *addr, int index) -{ - char *s, *e; - int i; - - params->hdr.tag = ATAG_ETHERNET; - params->hdr.size = tag_size(tag_ethernet); - - params->u.ethernet.mac_index = index; - params->u.ethernet.mii_phy_addr = gd->bd->bi_phy_id[index]; - - s = addr; - for (i = 0; i < 6; i++) { - params->u.ethernet.hw_address[i] = simple_strtoul(s, &e, 16); - s = e + 1; - } - - return tag_next(params); -} - -static struct tag *setup_ethernet_tags(struct tag *params) -{ - char name[16] = "ethaddr"; - char *addr; - int i = 0; - - do { - addr = getenv(name); - if (addr) - params = setup_ethernet_tag(params, addr, i); - sprintf(name, "eth%daddr", ++i); - } while (i < 4); - - return params; -} - -static void setup_end_tag(struct tag *params) -{ - params->hdr.tag = ATAG_NONE; - params->hdr.size = 0; -} - -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; - char *commandline = getenv("bootargs"); - - 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; - } - - show_boot_progress (15); - - params = params_start = (struct tag *)gd->bd->bi_boot_params; - params = setup_start_tag(params); - params = setup_memory_tags(params); - if (initrd_start) { - params = setup_ramdisk_tag(params, - PHYSADDR(initrd_start), - PHYSADDR(initrd_end)); - } - params = setup_commandline_tag(params, commandline); - params = setup_clock_tags(params); - params = setup_ethernet_tags(params); - setup_end_tag(params); - - printf("\nStarting kernel at %p (params at %p)...\n\n", - theKernel, params_start); - - prepare_to_boot(); - - theKernel(ATAG_MAGIC, params_start); -} diff --git a/lib_avr32/bootm.c b/lib_avr32/bootm.c new file mode 100644 index 0000000000..455590e37d --- /dev/null +++ b/lib_avr32/bootm.c @@ -0,0 +1,277 @@ +/* + * Copyright (C) 2004-2006 Atmel Corporation + * + * See file CREDITS for list of people who contributed to this + * project. + * + * This program is free software; you can redistribute it and/or + * modify it under the terms of the GNU General Public License as + * published by the Free Software Foundation; either version 2 of + * the License, or (at your option) any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with this program; if not, write to the Free Software + * Foundation, Inc., 59 Temple Place, Suite 330, Boston, + * MA 02111-1307 USA + */ +#include +#include +#include +#include +#include +#include +#include +#include +#include + +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); + +static struct tag *setup_start_tag(struct tag *params) +{ + params->hdr.tag = ATAG_CORE; + params->hdr.size = tag_size(tag_core); + + params->u.core.flags = 0; + params->u.core.pagesize = 4096; + params->u.core.rootdev = 0; + + return tag_next(params); +} + +static struct tag *setup_memory_tags(struct tag *params) +{ + bd_t *bd = gd->bd; + int i; + + for (i = 0; i < CONFIG_NR_DRAM_BANKS; i++) { + params->hdr.tag = ATAG_MEM; + params->hdr.size = tag_size(tag_mem_range); + + params->u.mem_range.addr = bd->bi_dram[i].start; + params->u.mem_range.size = bd->bi_dram[i].size; + + params = tag_next(params); + } + + return params; +} + +static struct tag *setup_commandline_tag(struct tag *params, char *cmdline) +{ + if (!cmdline) + return params; + + /* eat leading white space */ + while (*cmdline == ' ') cmdline++; + + /* + * Don't include tags for empty command lines; let the kernel + * use its default command line. + */ + if (*cmdline == '\0') + return params; + + params->hdr.tag = ATAG_CMDLINE; + params->hdr.size = + (sizeof (struct tag_header) + strlen(cmdline) + 1 + 3) >> 2; + strcpy(params->u.cmdline.cmdline, cmdline); + + return tag_next(params); +} + +static struct tag *setup_ramdisk_tag(struct tag *params, + unsigned long rd_start, + unsigned long rd_end) +{ + if (rd_start == rd_end) + return params; + + params->hdr.tag = ATAG_RDIMG; + params->hdr.size = tag_size(tag_mem_range); + + params->u.mem_range.addr = rd_start; + params->u.mem_range.size = rd_end - rd_start; + + return tag_next(params); +} + +static struct tag *setup_clock_tags(struct tag *params) +{ + params->hdr.tag = ATAG_CLOCK; + params->hdr.size = tag_size(tag_clock); + params->u.clock.clock_id = ACLOCK_BOOTCPU; + params->u.clock.clock_flags = 0; + params->u.clock.clock_hz = gd->cpu_hz; + +#ifdef CONFIG_AT32AP7000 + /* + * New kernels don't need this, but we should be backwards + * compatible for a while... + */ + params = tag_next(params); + + params->hdr.tag = ATAG_CLOCK; + params->hdr.size = tag_size(tag_clock); + params->u.clock.clock_id = ACLOCK_HSB; + params->u.clock.clock_flags = 0; + params->u.clock.clock_hz = get_hsb_clk_rate(); +#endif + + return tag_next(params); +} + +static struct tag *setup_ethernet_tag(struct tag *params, + char *addr, int index) +{ + char *s, *e; + int i; + + params->hdr.tag = ATAG_ETHERNET; + params->hdr.size = tag_size(tag_ethernet); + + params->u.ethernet.mac_index = index; + params->u.ethernet.mii_phy_addr = gd->bd->bi_phy_id[index]; + + s = addr; + for (i = 0; i < 6; i++) { + params->u.ethernet.hw_address[i] = simple_strtoul(s, &e, 16); + s = e + 1; + } + + return tag_next(params); +} + +static struct tag *setup_ethernet_tags(struct tag *params) +{ + char name[16] = "ethaddr"; + char *addr; + int i = 0; + + do { + addr = getenv(name); + if (addr) + params = setup_ethernet_tag(params, addr, i); + sprintf(name, "eth%daddr", ++i); + } while (i < 4); + + return params; +} + +static void setup_end_tag(struct tag *params) +{ + params->hdr.tag = ATAG_NONE; + params->hdr.size = 0; +} + +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; + char *commandline = getenv("bootargs"); + + 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; + } + + show_boot_progress (15); + + params = params_start = (struct tag *)gd->bd->bi_boot_params; + params = setup_start_tag(params); + params = setup_memory_tags(params); + if (initrd_start) { + params = setup_ramdisk_tag(params, + PHYSADDR(initrd_start), + PHYSADDR(initrd_end)); + } + params = setup_commandline_tag(params, commandline); + params = setup_clock_tags(params); + params = setup_ethernet_tags(params); + setup_end_tag(params); + + printf("\nStarting kernel at %p (params at %p)...\n\n", + theKernel, params_start); + + prepare_to_boot(); + + theKernel(ATAG_MAGIC, params_start); +} diff --git a/lib_blackfin/Makefile b/lib_blackfin/Makefile index a7aaef7a3c..ac3fb28553 100644 --- a/lib_blackfin/Makefile +++ b/lib_blackfin/Makefile @@ -31,7 +31,7 @@ LIB = $(obj)lib$(ARCH).a SOBJS = memcpy.o memcmp.o memset.o memmove.o -COBJS = post.o tests.o board.o bf533_linux.o bf533_string.o cache.o muldi3.o +COBJS = post.o tests.o board.o bootm.o bf533_string.o cache.o muldi3.o SRCS := $(SOBJS:.o=.S) $(COBJS:.o=.c) OBJS := $(addprefix $(obj),$(SOBJS) $(COBJS)) diff --git a/lib_blackfin/bf533_linux.c b/lib_blackfin/bf533_linux.c deleted file mode 100644 index 6299415b11..0000000000 --- a/lib_blackfin/bf533_linux.c +++ /dev/null @@ -1,84 +0,0 @@ -/* - * U-boot - bf533_linux.c - * - * Copyright (c) 2005-2007 Analog Devices Inc. - * - * (C) Copyright 2000-2004 - * Wolfgang Denk, DENX Software Engineering, wd@denx.de. - * - * See file CREDITS for list of people who contributed to this - * project. - * - * This program is free software; you can redistribute it and/or - * modify it under the terms of the GNU General Public License as - * published by the Free Software Foundation; either version 2 of - * the License, or (at your option) any later version. - * - * This program is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - * GNU General Public License for more details. - * - * You should have received a copy of the GNU General Public License - * along with this program; if not, write to the Free Software - * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, - * MA 02110-1301 USA - */ - -/* Dummy functions, currently not in Use */ - -#include -#include -#include -#include -#include - -#define LINUX_MAX_ENVS 256 -#define LINUX_MAX_ARGS 256 - -#define CMD_LINE_ADDR 0xFF900000 /* L1 scratchpad */ - -#ifdef SHARED_RESOURCES -extern void swap_to(int device_id); -#endif - -extern void flush_instruction_cache(void); -extern void flush_data_cache(void); -static char *make_command_line(void); - -void do_bootm_linux(cmd_tbl_t * cmdtp, int flag, int argc, char *argv[], - image_header_t *hdr, int verify) -{ - int (*appl) (char *cmdline); - char *cmdline; - -#ifdef SHARED_RESOURCES - swap_to(FLASH); -#endif - - appl = (int (*)(char *))image_get_ep (hdr); - printf("Starting Kernel at = %x\n", appl); - cmdline = make_command_line(); - if (icache_status()) { - flush_instruction_cache(); - icache_disable(); - } - if (dcache_status()) { - flush_data_cache(); - dcache_disable(); - } - (*appl) (cmdline); -} - -char *make_command_line(void) -{ - char *dest = (char *)CMD_LINE_ADDR; - char *bootargs; - - if ((bootargs = getenv("bootargs")) == NULL) - return NULL; - - strncpy(dest, bootargs, 0x1000); - dest[0xfff] = 0; - return dest; -} diff --git a/lib_blackfin/bootm.c b/lib_blackfin/bootm.c new file mode 100644 index 0000000000..6299415b11 --- /dev/null +++ b/lib_blackfin/bootm.c @@ -0,0 +1,84 @@ +/* + * U-boot - bf533_linux.c + * + * Copyright (c) 2005-2007 Analog Devices Inc. + * + * (C) Copyright 2000-2004 + * Wolfgang Denk, DENX Software Engineering, wd@denx.de. + * + * See file CREDITS for list of people who contributed to this + * project. + * + * This program is free software; you can redistribute it and/or + * modify it under the terms of the GNU General Public License as + * published by the Free Software Foundation; either version 2 of + * the License, or (at your option) any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with this program; if not, write to the Free Software + * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, + * MA 02110-1301 USA + */ + +/* Dummy functions, currently not in Use */ + +#include +#include +#include +#include +#include + +#define LINUX_MAX_ENVS 256 +#define LINUX_MAX_ARGS 256 + +#define CMD_LINE_ADDR 0xFF900000 /* L1 scratchpad */ + +#ifdef SHARED_RESOURCES +extern void swap_to(int device_id); +#endif + +extern void flush_instruction_cache(void); +extern void flush_data_cache(void); +static char *make_command_line(void); + +void do_bootm_linux(cmd_tbl_t * cmdtp, int flag, int argc, char *argv[], + image_header_t *hdr, int verify) +{ + int (*appl) (char *cmdline); + char *cmdline; + +#ifdef SHARED_RESOURCES + swap_to(FLASH); +#endif + + appl = (int (*)(char *))image_get_ep (hdr); + printf("Starting Kernel at = %x\n", appl); + cmdline = make_command_line(); + if (icache_status()) { + flush_instruction_cache(); + icache_disable(); + } + if (dcache_status()) { + flush_data_cache(); + dcache_disable(); + } + (*appl) (cmdline); +} + +char *make_command_line(void) +{ + char *dest = (char *)CMD_LINE_ADDR; + char *bootargs; + + if ((bootargs = getenv("bootargs")) == NULL) + return NULL; + + strncpy(dest, bootargs, 0x1000); + dest[0xfff] = 0; + return dest; +} diff --git a/lib_i386/Makefile b/lib_i386/Makefile index e344da5157..ef0ba54673 100644 --- a/lib_i386/Makefile +++ b/lib_i386/Makefile @@ -27,7 +27,7 @@ LIB = $(obj)lib$(ARCH).a SOBJS = bios.o bios_pci.o realmode_switch.o -COBJS = board.o bios_setup.o i386_linux.o zimage.o realmode.o \ +COBJS = board.o bios_setup.o bootm.o zimage.o realmode.o \ pci_type1.o pci.o video_bios.o video.o SRCS := $(SOBJS:.o=.S) $(COBJS:.o=.c) diff --git a/lib_i386/bootm.c b/lib_i386/bootm.c new file mode 100644 index 0000000000..27a2b0d9ab --- /dev/null +++ b/lib_i386/bootm.c @@ -0,0 +1,142 @@ +/* + * (C) Copyright 2002 + * Sysgo Real-Time Solutions, GmbH + * Marius Groeger + * + * Copyright (C) 2001 Erik Mouw (J.A.K.Mouw@its.tudelft.nl) + * + * This program is free software; you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation; either version 2 of the License, or + * (at your option) any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with this program; if not, write to the Free Software + * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA + * + */ + +#include +#include +#include +#include +#include +#include + +/*cmd_boot.c*/ +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) +{ + 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; + } + + /* if multi-part image, we need to advance base ptr */ + if (image_check_type (hdr, IH_TYPE_MULTI)) { + image_multi_getimg (hdr, 0, &os_data, &os_len); + } else { + os_data = image_get_data (hdr); + os_len = image_get_data_size (hdr); + } + + base_ptr = load_zimage ((void*)os_data, os_len, + initrd_start, rd_len, 0); + + if (NULL == base_ptr) { + printf ("## Kernel loading failed ...\n"); + do_reset(cmdtp, flag, argc, argv); + + } + +#ifdef DEBUG + printf ("## Transferring control to Linux (at address %08x) ...\n", + (u32)base_ptr); +#endif + + /* we assume that the kernel is in place */ + printf("\nStarting kernel ...\n\n"); + + boot_zimage(base_ptr); + +} diff --git a/lib_i386/i386_linux.c b/lib_i386/i386_linux.c deleted file mode 100644 index 27a2b0d9ab..0000000000 --- a/lib_i386/i386_linux.c +++ /dev/null @@ -1,142 +0,0 @@ -/* - * (C) Copyright 2002 - * Sysgo Real-Time Solutions, GmbH - * Marius Groeger - * - * Copyright (C) 2001 Erik Mouw (J.A.K.Mouw@its.tudelft.nl) - * - * This program is free software; you can redistribute it and/or modify - * it under the terms of the GNU General Public License as published by - * the Free Software Foundation; either version 2 of the License, or - * (at your option) any later version. - * - * This program is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - * GNU General Public License for more details. - * - * You should have received a copy of the GNU General Public License - * along with this program; if not, write to the Free Software - * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA - * - */ - -#include -#include -#include -#include -#include -#include - -/*cmd_boot.c*/ -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) -{ - 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; - } - - /* if multi-part image, we need to advance base ptr */ - if (image_check_type (hdr, IH_TYPE_MULTI)) { - image_multi_getimg (hdr, 0, &os_data, &os_len); - } else { - os_data = image_get_data (hdr); - os_len = image_get_data_size (hdr); - } - - base_ptr = load_zimage ((void*)os_data, os_len, - initrd_start, rd_len, 0); - - if (NULL == base_ptr) { - printf ("## Kernel loading failed ...\n"); - do_reset(cmdtp, flag, argc, argv); - - } - -#ifdef DEBUG - printf ("## Transferring control to Linux (at address %08x) ...\n", - (u32)base_ptr); -#endif - - /* we assume that the kernel is in place */ - printf("\nStarting kernel ...\n\n"); - - boot_zimage(base_ptr); - -} diff --git a/lib_m68k/Makefile b/lib_m68k/Makefile index 03784fd84e..d515223259 100644 --- a/lib_m68k/Makefile +++ b/lib_m68k/Makefile @@ -27,7 +27,7 @@ LIB = $(obj)lib$(ARCH).a SOBJS = -COBJS = cache.o traps.o time.o interrupts.o board.o m68k_linux.o +COBJS = cache.o traps.o time.o interrupts.o board.o bootm.o SRCS := $(SOBJS:.o=.S) $(COBJS:.o=.c) OBJS := $(addprefix $(obj),$(SOBJS) $(COBJS)) diff --git a/lib_m68k/bootm.c b/lib_m68k/bootm.c new file mode 100644 index 0000000000..b135556a99 --- /dev/null +++ b/lib_m68k/bootm.c @@ -0,0 +1,279 @@ +/* + * (C) Copyright 2003 + * Wolfgang Denk, DENX Software Engineering, wd@denx.de. + * + * See file CREDITS for list of people who contributed to this + * project. + * + * This program is free software; you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation; either version 2 of the License, or + * (at your option) any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with this program; if not, write to the Free Software + * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA + * + */ + +#include +#include +#include +#include +#include +#include +#include +#include + +DECLARE_GLOBAL_DATA_PTR; + +#define PHYSADDR(x) x + +#define LINUX_MAX_ENVS 256 +#define LINUX_MAX_ARGS 256 + +#ifdef CONFIG_SHOW_BOOT_PROGRESS +# include +# define SHOW_BOOT_PROGRESS(arg) show_boot_progress(arg) +#else +# 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 initrd_high; + ulong initrd_start, initrd_end; + image_header_t *rd_hdr; + int initrd_copy_to_ram = 1; + + ulong cmd_start, cmd_end; + char *cmdline; + char *s; + 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 + * + * Allocate space for command line and board info - the + * address should be as high as possible within the reach of + * the kernel (see CFG_BOOTMAPSZ settings), but in unused + * memory, which means far enough below the current stack + * pointer. + */ + asm("movel %%a7, %%d0\n" + "movel %%d0, %0\n": "=d"(sp): :"%d0"); + + debug("## Current stack ends at 0x%08lX ", sp); + + sp -= 2048; /* just to be sure */ + if (sp > CFG_BOOTMAPSZ) + sp = CFG_BOOTMAPSZ; + sp &= ~0xF; + + debug("=> set upper limit to 0x%08lX\n", sp); + + cmdline = (char *)((sp - 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); + +#ifdef DEBUG + printf("## cmdline at 0x%08lX ... 0x%08lX\n", cmd_start, cmd_end); + + do_bdinfo(NULL, 0, 0, NULL); +#endif + + if ((s = getenv("clocks_in_mhz")) != NULL) { + /* convert all clock information to MHz */ + kbd->bi_intfreq /= 1000000L; + kbd->bi_busfreq /= 1000000L; + } + + 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); + + 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 (!initrd_copy_to_ram) { /* zero-copy ramdisk support */ + initrd_start = rd_data; + initrd_end = initrd_start + 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 + * 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, rd_data + rd_len - 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); + + puts("OK\n"); + } + } else { + initrd_start = 0; + initrd_end = 0; + } + + debug("## Transferring control to Linux (at address %08lx) ...\n", + (ulong) kernel); + + SHOW_BOOT_PROGRESS(15); + + /* + * Linux Kernel Parameters (passing board info data): + * r3: ptr to board info data + * r4: initrd_start or 0 if no initrd + * r5: initrd_end - unused if r4 is 0 + * r6: Start of command line string + * r7: End of command line string + */ + (*kernel) (kbd, initrd_start, initrd_end, cmd_start, cmd_end); + /* does not return */ +} diff --git a/lib_m68k/m68k_linux.c b/lib_m68k/m68k_linux.c deleted file mode 100644 index b135556a99..0000000000 --- a/lib_m68k/m68k_linux.c +++ /dev/null @@ -1,279 +0,0 @@ -/* - * (C) Copyright 2003 - * Wolfgang Denk, DENX Software Engineering, wd@denx.de. - * - * See file CREDITS for list of people who contributed to this - * project. - * - * This program is free software; you can redistribute it and/or modify - * it under the terms of the GNU General Public License as published by - * the Free Software Foundation; either version 2 of the License, or - * (at your option) any later version. - * - * This program is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - * GNU General Public License for more details. - * - * You should have received a copy of the GNU General Public License - * along with this program; if not, write to the Free Software - * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA - * - */ - -#include -#include -#include -#include -#include -#include -#include -#include - -DECLARE_GLOBAL_DATA_PTR; - -#define PHYSADDR(x) x - -#define LINUX_MAX_ENVS 256 -#define LINUX_MAX_ARGS 256 - -#ifdef CONFIG_SHOW_BOOT_PROGRESS -# include -# define SHOW_BOOT_PROGRESS(arg) show_boot_progress(arg) -#else -# 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 initrd_high; - ulong initrd_start, initrd_end; - image_header_t *rd_hdr; - int initrd_copy_to_ram = 1; - - ulong cmd_start, cmd_end; - char *cmdline; - char *s; - 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 - * - * Allocate space for command line and board info - the - * address should be as high as possible within the reach of - * the kernel (see CFG_BOOTMAPSZ settings), but in unused - * memory, which means far enough below the current stack - * pointer. - */ - asm("movel %%a7, %%d0\n" - "movel %%d0, %0\n": "=d"(sp): :"%d0"); - - debug("## Current stack ends at 0x%08lX ", sp); - - sp -= 2048; /* just to be sure */ - if (sp > CFG_BOOTMAPSZ) - sp = CFG_BOOTMAPSZ; - sp &= ~0xF; - - debug("=> set upper limit to 0x%08lX\n", sp); - - cmdline = (char *)((sp - 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); - -#ifdef DEBUG - printf("## cmdline at 0x%08lX ... 0x%08lX\n", cmd_start, cmd_end); - - do_bdinfo(NULL, 0, 0, NULL); -#endif - - if ((s = getenv("clocks_in_mhz")) != NULL) { - /* convert all clock information to MHz */ - kbd->bi_intfreq /= 1000000L; - kbd->bi_busfreq /= 1000000L; - } - - 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); - - 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 (!initrd_copy_to_ram) { /* zero-copy ramdisk support */ - initrd_start = rd_data; - initrd_end = initrd_start + 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 - * 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, rd_data + rd_len - 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); - - puts("OK\n"); - } - } else { - initrd_start = 0; - initrd_end = 0; - } - - debug("## Transferring control to Linux (at address %08lx) ...\n", - (ulong) kernel); - - SHOW_BOOT_PROGRESS(15); - - /* - * Linux Kernel Parameters (passing board info data): - * r3: ptr to board info data - * r4: initrd_start or 0 if no initrd - * r5: initrd_end - unused if r4 is 0 - * r6: Start of command line string - * r7: End of command line string - */ - (*kernel) (kbd, initrd_start, initrd_end, cmd_start, cmd_end); - /* does not return */ -} diff --git a/lib_microblaze/Makefile b/lib_microblaze/Makefile index 82b7beadb0..9b317a2da8 100644 --- a/lib_microblaze/Makefile +++ b/lib_microblaze/Makefile @@ -27,7 +27,7 @@ LIB = $(obj)lib$(ARCH).a SOBJS = -COBJS = board.o microblaze_linux.o time.o cache.o +COBJS = board.o bootm.o time.o cache.o SRCS := $(SOBJS:.o=.S) $(COBJS:.o=.c) OBJS := $(addprefix $(obj),$(SOBJS) $(COBJS)) diff --git a/lib_microblaze/bootm.c b/lib_microblaze/bootm.c new file mode 100644 index 0000000000..a4fce5a73c --- /dev/null +++ b/lib_microblaze/bootm.c @@ -0,0 +1,138 @@ +/* + * (C) Copyright 2007 Michal Simek + * (C) Copyright 2004 Atmark Techno, Inc. + * + * Michal SIMEK + * Yasushi SHOJI + * + * See file CREDITS for list of people who contributed to this + * project. + * + * This program is free software; you can redistribute it and/or + * modify it under the terms of the GNU General Public License as + * published by the Free Software Foundation; either version 2 of + * the License, or (at your option) any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with this program; if not, write to the Free Software + * Foundation, Inc., 59 Temple Place, Suite 330, Boston, + * MA 02111-1307 USA + */ + +#include +#include +#include +#include +#include + +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 *); + char *commandline = getenv ("bootargs"); + + 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; + } + + show_boot_progress (15); + +#ifdef DEBUG + printf ("## Transferring control to Linux (at address %08lx) ...\n", + (ulong) theKernel); +#endif + + theKernel (commandline); +} diff --git a/lib_microblaze/microblaze_linux.c b/lib_microblaze/microblaze_linux.c deleted file mode 100644 index a4fce5a73c..0000000000 --- a/lib_microblaze/microblaze_linux.c +++ /dev/null @@ -1,138 +0,0 @@ -/* - * (C) Copyright 2007 Michal Simek - * (C) Copyright 2004 Atmark Techno, Inc. - * - * Michal SIMEK - * Yasushi SHOJI - * - * See file CREDITS for list of people who contributed to this - * project. - * - * This program is free software; you can redistribute it and/or - * modify it under the terms of the GNU General Public License as - * published by the Free Software Foundation; either version 2 of - * the License, or (at your option) any later version. - * - * This program is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - * GNU General Public License for more details. - * - * You should have received a copy of the GNU General Public License - * along with this program; if not, write to the Free Software - * Foundation, Inc., 59 Temple Place, Suite 330, Boston, - * MA 02111-1307 USA - */ - -#include -#include -#include -#include -#include - -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 *); - char *commandline = getenv ("bootargs"); - - 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; - } - - show_boot_progress (15); - -#ifdef DEBUG - printf ("## Transferring control to Linux (at address %08lx) ...\n", - (ulong) theKernel); -#endif - - theKernel (commandline); -} diff --git a/lib_mips/Makefile b/lib_mips/Makefile index 3163f00e01..93cca7a239 100644 --- a/lib_mips/Makefile +++ b/lib_mips/Makefile @@ -27,7 +27,7 @@ LIB = $(obj)lib$(ARCH).a SOBJS = -COBJS = board.o time.o mips_linux.o +COBJS = board.o time.o bootm.o SRCS := $(SOBJS:.o=.S) $(COBJS:.o=.c) OBJS := $(addprefix $(obj),$(SOBJS) $(COBJS)) diff --git a/lib_mips/bootm.c b/lib_mips/bootm.c new file mode 100644 index 0000000000..7ea7571a81 --- /dev/null +++ b/lib_mips/bootm.c @@ -0,0 +1,249 @@ +/* + * (C) Copyright 2003 + * Wolfgang Denk, DENX Software Engineering, wd@denx.de. + * + * See file CREDITS for list of people who contributed to this + * project. + * + * This program is free software; you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation; either version 2 of the License, or + * (at your option) any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with this program; if not, write to the Free Software + * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA + * + */ + +#include +#include +#include +#include +#include +#include + +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; + +static char ** linux_env; +static char * linux_env_p; +static int linux_env_idx; + +static void linux_params_init (ulong start, char * commandline); +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"); + char env_buf[12]; + + 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; + } + + show_boot_progress (15); + +#ifdef DEBUG + printf ("## Transferring control to Linux (at address %08lx) ...\n", + (ulong) theKernel); +#endif + + linux_params_init (UNCACHED_SDRAM (gd->bd->bi_boot_params), commandline); + +#ifdef CONFIG_MEMSIZE_IN_BYTES + sprintf (env_buf, "%lu", gd->ram_size); +#ifdef DEBUG + printf ("## Giving linux memsize in bytes, %lu\n", gd->ram_size); +#endif +#else + sprintf (env_buf, "%lu", gd->ram_size >> 20); +#ifdef DEBUG + printf ("## Giving linux memsize in MB, %lu\n", gd->ram_size >> 20); +#endif +#endif /* CONFIG_MEMSIZE_IN_BYTES */ + + linux_env_set ("memsize", env_buf); + + sprintf (env_buf, "0x%08X", (uint) UNCACHED_SDRAM (initrd_start)); + linux_env_set ("initrd_start", env_buf); + + sprintf (env_buf, "0x%X", (uint) (initrd_end - initrd_start)); + linux_env_set ("initrd_size", env_buf); + + sprintf (env_buf, "0x%08X", (uint) (gd->bd->bi_flashstart)); + linux_env_set ("flash_start", env_buf); + + sprintf (env_buf, "0x%X", (uint) (gd->bd->bi_flashsize)); + linux_env_set ("flash_size", env_buf); + + /* we assume that the kernel is in place */ + printf ("\nStarting kernel ...\n\n"); + + theKernel (linux_argc, linux_argv, linux_env, 0); +} + +static void linux_params_init (ulong start, char *line) +{ + char *next, *quote, *argp; + + linux_argc = 1; + linux_argv = (char **) start; + linux_argv[0] = 0; + argp = (char *) (linux_argv + LINUX_MAX_ARGS); + + next = line; + + while (line && *line && linux_argc < LINUX_MAX_ARGS) { + quote = strchr (line, '"'); + next = strchr (line, ' '); + + while (next != NULL && quote != NULL && quote < next) { + /* we found a left quote before the next blank + * now we have to find the matching right quote + */ + next = strchr (quote + 1, '"'); + if (next != NULL) { + quote = strchr (next + 1, '"'); + next = strchr (next + 1, ' '); + } + } + + if (next == NULL) { + next = line + strlen (line); + } + + linux_argv[linux_argc] = argp; + memcpy (argp, line, next - line); + argp[next - line] = 0; + + argp += next - line + 1; + linux_argc++; + + if (*next) + next++; + + line = next; + } + + linux_env = (char **) (((ulong) argp + 15) & ~15); + linux_env[0] = 0; + linux_env_p = (char *) (linux_env + LINUX_MAX_ENVS); + linux_env_idx = 0; +} + +static void linux_env_set (char *env_name, char *env_val) +{ + if (linux_env_idx < LINUX_MAX_ENVS - 1) { + linux_env[linux_env_idx] = linux_env_p; + + strcpy (linux_env_p, env_name); + linux_env_p += strlen (env_name); + + strcpy (linux_env_p, "="); + linux_env_p += 1; + + strcpy (linux_env_p, env_val); + linux_env_p += strlen (env_val); + + linux_env_p++; + linux_env[++linux_env_idx] = 0; + } +} diff --git a/lib_mips/mips_linux.c b/lib_mips/mips_linux.c deleted file mode 100644 index 7ea7571a81..0000000000 --- a/lib_mips/mips_linux.c +++ /dev/null @@ -1,249 +0,0 @@ -/* - * (C) Copyright 2003 - * Wolfgang Denk, DENX Software Engineering, wd@denx.de. - * - * See file CREDITS for list of people who contributed to this - * project. - * - * This program is free software; you can redistribute it and/or modify - * it under the terms of the GNU General Public License as published by - * the Free Software Foundation; either version 2 of the License, or - * (at your option) any later version. - * - * This program is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - * GNU General Public License for more details. - * - * You should have received a copy of the GNU General Public License - * along with this program; if not, write to the Free Software - * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA - * - */ - -#include -#include -#include -#include -#include -#include - -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; - -static char ** linux_env; -static char * linux_env_p; -static int linux_env_idx; - -static void linux_params_init (ulong start, char * commandline); -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"); - char env_buf[12]; - - 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; - } - - show_boot_progress (15); - -#ifdef DEBUG - printf ("## Transferring control to Linux (at address %08lx) ...\n", - (ulong) theKernel); -#endif - - linux_params_init (UNCACHED_SDRAM (gd->bd->bi_boot_params), commandline); - -#ifdef CONFIG_MEMSIZE_IN_BYTES - sprintf (env_buf, "%lu", gd->ram_size); -#ifdef DEBUG - printf ("## Giving linux memsize in bytes, %lu\n", gd->ram_size); -#endif -#else - sprintf (env_buf, "%lu", gd->ram_size >> 20); -#ifdef DEBUG - printf ("## Giving linux memsize in MB, %lu\n", gd->ram_size >> 20); -#endif -#endif /* CONFIG_MEMSIZE_IN_BYTES */ - - linux_env_set ("memsize", env_buf); - - sprintf (env_buf, "0x%08X", (uint) UNCACHED_SDRAM (initrd_start)); - linux_env_set ("initrd_start", env_buf); - - sprintf (env_buf, "0x%X", (uint) (initrd_end - initrd_start)); - linux_env_set ("initrd_size", env_buf); - - sprintf (env_buf, "0x%08X", (uint) (gd->bd->bi_flashstart)); - linux_env_set ("flash_start", env_buf); - - sprintf (env_buf, "0x%X", (uint) (gd->bd->bi_flashsize)); - linux_env_set ("flash_size", env_buf); - - /* we assume that the kernel is in place */ - printf ("\nStarting kernel ...\n\n"); - - theKernel (linux_argc, linux_argv, linux_env, 0); -} - -static void linux_params_init (ulong start, char *line) -{ - char *next, *quote, *argp; - - linux_argc = 1; - linux_argv = (char **) start; - linux_argv[0] = 0; - argp = (char *) (linux_argv + LINUX_MAX_ARGS); - - next = line; - - while (line && *line && linux_argc < LINUX_MAX_ARGS) { - quote = strchr (line, '"'); - next = strchr (line, ' '); - - while (next != NULL && quote != NULL && quote < next) { - /* we found a left quote before the next blank - * now we have to find the matching right quote - */ - next = strchr (quote + 1, '"'); - if (next != NULL) { - quote = strchr (next + 1, '"'); - next = strchr (next + 1, ' '); - } - } - - if (next == NULL) { - next = line + strlen (line); - } - - linux_argv[linux_argc] = argp; - memcpy (argp, line, next - line); - argp[next - line] = 0; - - argp += next - line + 1; - linux_argc++; - - if (*next) - next++; - - line = next; - } - - linux_env = (char **) (((ulong) argp + 15) & ~15); - linux_env[0] = 0; - linux_env_p = (char *) (linux_env + LINUX_MAX_ENVS); - linux_env_idx = 0; -} - -static void linux_env_set (char *env_name, char *env_val) -{ - if (linux_env_idx < LINUX_MAX_ENVS - 1) { - linux_env[linux_env_idx] = linux_env_p; - - strcpy (linux_env_p, env_name); - linux_env_p += strlen (env_name); - - strcpy (linux_env_p, "="); - linux_env_p += 1; - - strcpy (linux_env_p, env_val); - linux_env_p += strlen (env_val); - - linux_env_p++; - linux_env[++linux_env_idx] = 0; - } -} diff --git a/lib_nios/Makefile b/lib_nios/Makefile index 7c9d62cf7c..d8ae7bd265 100644 --- a/lib_nios/Makefile +++ b/lib_nios/Makefile @@ -27,7 +27,7 @@ LIB = $(obj)lib$(ARCH).a SOBJS = -COBJS = board.o cache.o divmod.o nios_linux.o mult.o time.o +COBJS = board.o cache.o divmod.o bootm.o mult.o time.o SRCS := $(SOBJS:.o=.S) $(COBJS:.o=.c) OBJS := $(addprefix $(obj),$(SOBJS) $(COBJS)) diff --git a/lib_nios/bootm.c b/lib_nios/bootm.c new file mode 100644 index 0000000000..55f7e3adc1 --- /dev/null +++ b/lib_nios/bootm.c @@ -0,0 +1,34 @@ +/* + * (C) Copyright 2003, Psyent Corporation + * Scott McNutt + * + * See file CREDITS for list of people who contributed to this + * project. + * + * This program is free software; you can redistribute it and/or + * modify it under the terms of the GNU General Public License as + * published by the Free Software Foundation; either version 2 of + * the License, or (at your option) any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with this program; if not, write to the Free Software + * Foundation, Inc., 59 Temple Place, Suite 330, Boston, + * MA 02111-1307 USA + */ + +#include +#include + +/* FIXME: Once we find a stable version of uC-linux for nios + * we can get this working. ;-) + * + */ +void do_bootm_linux(cmd_tbl_t *cmdtp, int flag, int argc, char *argv[], + image__header_t *hdr, int verify) +{ +} diff --git a/lib_nios/nios_linux.c b/lib_nios/nios_linux.c deleted file mode 100644 index 55f7e3adc1..0000000000 --- a/lib_nios/nios_linux.c +++ /dev/null @@ -1,34 +0,0 @@ -/* - * (C) Copyright 2003, Psyent Corporation - * Scott McNutt - * - * See file CREDITS for list of people who contributed to this - * project. - * - * This program is free software; you can redistribute it and/or - * modify it under the terms of the GNU General Public License as - * published by the Free Software Foundation; either version 2 of - * the License, or (at your option) any later version. - * - * This program is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - * GNU General Public License for more details. - * - * You should have received a copy of the GNU General Public License - * along with this program; if not, write to the Free Software - * Foundation, Inc., 59 Temple Place, Suite 330, Boston, - * MA 02111-1307 USA - */ - -#include -#include - -/* FIXME: Once we find a stable version of uC-linux for nios - * we can get this working. ;-) - * - */ -void do_bootm_linux(cmd_tbl_t *cmdtp, int flag, int argc, char *argv[], - image__header_t *hdr, int verify) -{ -} diff --git a/lib_nios2/Makefile b/lib_nios2/Makefile index 1ff2f29bcb..5f996d3bf5 100644 --- a/lib_nios2/Makefile +++ b/lib_nios2/Makefile @@ -27,7 +27,7 @@ LIB = $(obj)lib$(ARCH).a SOBJS = cache.o -COBJS = board.o divmod.o nios_linux.o mult.o time.o +COBJS = board.o divmod.o bootm.o mult.o time.o SRCS := $(SOBJS:.o=.S) $(COBJS:.o=.c) OBJS := $(addprefix $(obj),$(SOBJS) $(COBJS)) diff --git a/lib_nios2/bootm.c b/lib_nios2/bootm.c new file mode 100644 index 0000000000..cb843246b8 --- /dev/null +++ b/lib_nios2/bootm.c @@ -0,0 +1,37 @@ +/* + * (C) Copyright 2003, Psyent Corporation + * Scott McNutt + * + * See file CREDITS for list of people who contributed to this + * project. + * + * This program is free software; you can redistribute it and/or + * modify it under the terms of the GNU General Public License as + * published by the Free Software Foundation; either version 2 of + * the License, or (at your option) any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with this program; if not, write to the Free Software + * Foundation, Inc., 59 Temple Place, Suite 330, Boston, + * MA 02111-1307 USA + */ + +#include +#include +#include + +void do_bootm_linux(cmd_tbl_t *cmdtp, int flag, int argc, char *argv[], + image_header_t *hdr, int verify) +{ + void (*kernel)(void) = (void (*)(void))image_get_ep (hdr); + + /* For now we assume the Microtronix linux ... which only + * needs to be called ;-) + */ + kernel (); +} diff --git a/lib_nios2/nios_linux.c b/lib_nios2/nios_linux.c deleted file mode 100644 index cb843246b8..0000000000 --- a/lib_nios2/nios_linux.c +++ /dev/null @@ -1,37 +0,0 @@ -/* - * (C) Copyright 2003, Psyent Corporation - * Scott McNutt - * - * See file CREDITS for list of people who contributed to this - * project. - * - * This program is free software; you can redistribute it and/or - * modify it under the terms of the GNU General Public License as - * published by the Free Software Foundation; either version 2 of - * the License, or (at your option) any later version. - * - * This program is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - * GNU General Public License for more details. - * - * You should have received a copy of the GNU General Public License - * along with this program; if not, write to the Free Software - * Foundation, Inc., 59 Temple Place, Suite 330, Boston, - * MA 02111-1307 USA - */ - -#include -#include -#include - -void do_bootm_linux(cmd_tbl_t *cmdtp, int flag, int argc, char *argv[], - image_header_t *hdr, int verify) -{ - void (*kernel)(void) = (void (*)(void))image_get_ep (hdr); - - /* For now we assume the Microtronix linux ... which only - * needs to be called ;-) - */ - kernel (); -} diff --git a/lib_ppc/Makefile b/lib_ppc/Makefile index 2aa0154856..6845ed0121 100644 --- a/lib_ppc/Makefile +++ b/lib_ppc/Makefile @@ -29,7 +29,7 @@ SOBJS = ppcstring.o ticks.o COBJS = board.o \ bat_rw.o cache.o extable.o kgdb.o time.o interrupts.o \ - ppc_linux.o + bootm.o SRCS := $(SOBJS:.o=.S) $(COBJS:.o=.c) OBJS := $(addprefix $(obj),$(SOBJS) $(COBJS)) diff --git a/lib_ppc/bootm.c b/lib_ppc/bootm.c new file mode 100644 index 0000000000..391168787a --- /dev/null +++ b/lib_ppc/bootm.c @@ -0,0 +1,554 @@ +/* + * (C) Copyright 2008 Semihalf + * + * (C) Copyright 2000-2006 + * Wolfgang Denk, DENX Software Engineering, wd@denx.de. + * + * See file CREDITS for list of people who contributed to this + * project. + * + * This program is free software; you can redistribute it and/or + * modify it under the terms of the GNU General Public License as + * published by the Free Software Foundation; either version 2 of + * the License, or (at your option) any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with this program; if not, write to the Free Software + * Foundation, Inc., 59 Temple Place, Suite 330, Boston, + * MA 02111-1307 USA + */ + +#define DEBUG + +#include +#include +#include +#include +#include +#include +#include +#include +#include + +#if defined(CONFIG_OF_LIBFDT) +#include +#include +#include +#elif defined(CONFIG_OF_FLAT_TREE) +#include +#endif + +#ifdef CONFIG_LOGBUFFER +#include +#endif + +#ifdef CFG_INIT_RAM_LOCK +#include +#endif + +DECLARE_GLOBAL_DATA_PTR; + +extern int do_reset (cmd_tbl_t *cmdtp, int flag, int argc, char *argv[]); + +#if defined(CONFIG_CMD_BDI) +extern int do_bdinfo(cmd_tbl_t *cmdtp, int flag, int argc, char *argv[]); +#endif + +void __attribute__((noinline)) +do_bootm_linux(cmd_tbl_t *cmdtp, int flag, + int argc, char *argv[], + image_header_t *hdr, + int verify) +{ + 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 cmd_start, cmd_end; + char *cmdline; + + ulong sp; + char *s; + bd_t *kbd; + void (*kernel)(bd_t *, ulong, ulong, ulong, ulong); + +#if defined(CONFIG_OF_FLAT_TREE) || defined(CONFIG_OF_LIBFDT) + image_header_t *fdt_hdr; + char *of_flat_tree = NULL; + 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 + * + * Allocate space for command line and board info - the + * address should be as high as possible within the reach of + * the kernel (see CFG_BOOTMAPSZ settings), but in unused + * memory, which means far enough below the current stack + * pointer. + */ + + asm( "mr %0,1": "=r"(sp) : ); + + debug ("## Current stack ends at 0x%08lX ", sp); + + sp -= 2048; /* just to be sure */ + if (sp > CFG_BOOTMAPSZ) + sp = CFG_BOOTMAPSZ; + sp &= ~0xF; + + debug ("=> set upper limit to 0x%08lX\n", sp); + + cmdline = (char *)((sp - 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); + +#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 */ + } + + kernel = (void (*)(bd_t *, ulong, ulong, ulong, ulong))image_get_ep (hdr); + + /* + * Check if there is an initrd image + */ + +#if defined(CONFIG_OF_FLAT_TREE) || 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; + } + +#if defined(CONFIG_OF_FLAT_TREE) || defined(CONFIG_OF_LIBFDT) + if(argc > 3) { + of_flat_tree = (char *) simple_strtoul(argv[3], NULL, 16); + fdt_hdr = (image_header_t *)of_flat_tree; +#if defined(CONFIG_OF_FLAT_TREE) + if (*((ulong *)(of_flat_tree)) == OF_DT_HEADER) { +#elif defined(CONFIG_OF_LIBFDT) + if (fdt_check_header (of_flat_tree) == 0) { +#endif +#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)) { + puts ("ERROR: fdt overwritten - " + "must RESET the board to recover.\n"); + do_reset (cmdtp, flag, argc, argv); + } + + puts (" Verifying Checksum ... "); + if (!image_check_hcrc (fdt_hdr)) { + puts ("ERROR: fdt header checksum invalid - " + "must RESET the board to recover.\n"); + do_reset (cmdtp, flag, argc, argv); + } + + if (!image_check_dcrc (fdt_hdr)) { + puts ("ERROR: fdt checksum invalid - " + "must RESET the board to recover.\n"); + do_reset (cmdtp, flag, argc, argv); + } + puts ("OK\n"); + + if (!image_check_type (fdt_hdr, IH_TYPE_FLATDT)) { + puts ("ERROR: uImage is not a fdt - " + "must RESET the board to recover.\n"); + do_reset (cmdtp, flag, argc, argv); + } + if (image_get_comp (fdt_hdr) != IH_COMP_NONE) { + puts ("ERROR: uImage is compressed - " + "must RESET the board to recover.\n"); + do_reset (cmdtp, flag, argc, argv); + } +#if defined(CONFIG_OF_FLAT_TREE) + if (*((ulong *)(of_flat_tree + image_get_header_size ())) != OF_DT_HEADER) { +#elif defined(CONFIG_OF_LIBFDT) + if (fdt_check_header (of_flat_tree + image_get_header_size ()) != 0) { +#endif + puts ("ERROR: uImage data is not a fdt - " + "must RESET the board to recover.\n"); + 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 { + puts ("Did not find a flat Flat Device Tree.\n" + "Must RESET the board to recover.\n"); + 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 defined(CONFIG_OF_FLAT_TREE) + if (*((ulong *)(of_flat_tree)) != OF_DT_HEADER) { +#elif defined(CONFIG_OF_LIBFDT) + if (fdt_check_header (of_flat_tree) != 0) { +#endif + puts ("ERROR: image is not a fdt - " + "must RESET the board to recover.\n"); + do_reset (cmdtp, flag, argc, argv); + } + +#if defined(CONFIG_OF_FLAT_TREE) + if (((struct boot_param_header *)of_flat_tree)->totalsize != fdt_len) { +#elif defined(CONFIG_OF_LIBFDT) + if (be32_to_cpu (fdt_totalsize (of_flat_tree)) != fdt_len) { +#endif + puts ("ERROR: fdt size != image size - " + "must RESET the board to recover.\n"); + do_reset (cmdtp, flag, argc, argv); + } + } + } +#endif + if (!rd_data) { + debug ("No initrd\n"); + } + + if (rd_data) { + if (!initrd_copy_to_ram) { /* zero-copy ramdisk support */ + initrd_start = rd_data; + initrd_end = initrd_start + 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 + * 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, rd_data + rd_len - 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); + + puts ("OK\n"); + } + } else { + initrd_start = 0; + initrd_end = 0; + } + +#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 kbd */ + of_start = (ulong)kbd - 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); + + 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) { + puts ("ERROR: fdt move failed - " + "must RESET the board to recover.\n"); + 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). + */ + if (of_flat_tree) { + if (fdt_chosen(of_flat_tree, initrd_start, initrd_end, 0) < 0) { + puts ("ERROR: /chosen node create failed - " + "must RESET the board to recover.\n"); + do_reset (cmdtp, flag, argc, argv); + } +#ifdef CONFIG_OF_HAS_UBOOT_ENV + if (fdt_env(of_flat_tree) < 0) { + puts ("ERROR: /u-boot-env node create failed - " + "must RESET the board to recover.\n"); + do_reset (cmdtp, flag, argc, argv); + } +#endif +#ifdef CONFIG_OF_HAS_BD_T + if (fdt_bd_t(of_flat_tree) < 0) { + puts ("ERROR: /bd_t node create failed - " + "must RESET the board to recover.\n"); + do_reset (cmdtp, flag, argc, argv); + } +#endif +#ifdef CONFIG_OF_BOARD_SETUP + /* Call the board-specific fixup routine */ + ft_board_setup(of_flat_tree, gd->bd); +#endif + } + +#elif defined(CONFIG_OF_FLAT_TREE) + +#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) { + ulong of_start, of_len; + of_len = ((struct boot_param_header *)of_data)->totalsize; + + /* provide extra 8k pad */ + of_start = (ulong)kbd - of_len - 8192; + 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); + + of_flat_tree = (char *)of_start; + printf (" Loading Device Tree to %08lx, end %08lx ... ", + of_start, of_start + of_len - 1); + memmove ((void *)of_start, (void *)of_data, of_len); + puts ("OK\n"); + } + /* + * Create the /chosen node and modify the blob with board specific + * values as needed. + */ + ft_setup(of_flat_tree, kbd, initrd_start, initrd_end); + /* ft_dump_blob(of_flat_tree); */ + +#endif /* #if defined(CONFIG_OF_LIBFDT) #elif defined(CONFIG_OF_FLAT_TREE) */ + + debug ("## Transferring control to Linux (at address %08lx) ...\n", + (ulong)kernel); + + show_boot_progress (15); + +#if defined(CFG_INIT_RAM_LOCK) && !defined(CONFIG_E500) + unlock_ram_in_cache(); +#endif + +#if defined(CONFIG_OF_FLAT_TREE) || defined(CONFIG_OF_LIBFDT) + if (of_flat_tree) { /* device tree; boot new style */ + /* + * Linux Kernel Parameters (passing device tree): + * r3: pointer to the fdt, followed by the board info data + * r4: physical pointer to the kernel itself + * r5: NULL + * r6: NULL + * r7: NULL + */ + (*kernel) ((bd_t *)of_flat_tree, (ulong)kernel, 0, 0, 0); + /* does not return */ + } +#endif + /* + * Linux Kernel Parameters (passing board info data): + * r3: ptr to board info data + * r4: initrd_start or 0 if no initrd + * r5: initrd_end - unused if r4 is 0 + * r6: Start of command line string + * r7: End of command line string + */ + (*kernel) (kbd, initrd_start, initrd_end, cmd_start, cmd_end); + /* does not return */ +} diff --git a/lib_ppc/ppc_linux.c b/lib_ppc/ppc_linux.c deleted file mode 100644 index 391168787a..0000000000 --- a/lib_ppc/ppc_linux.c +++ /dev/null @@ -1,554 +0,0 @@ -/* - * (C) Copyright 2008 Semihalf - * - * (C) Copyright 2000-2006 - * Wolfgang Denk, DENX Software Engineering, wd@denx.de. - * - * See file CREDITS for list of people who contributed to this - * project. - * - * This program is free software; you can redistribute it and/or - * modify it under the terms of the GNU General Public License as - * published by the Free Software Foundation; either version 2 of - * the License, or (at your option) any later version. - * - * This program is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - * GNU General Public License for more details. - * - * You should have received a copy of the GNU General Public License - * along with this program; if not, write to the Free Software - * Foundation, Inc., 59 Temple Place, Suite 330, Boston, - * MA 02111-1307 USA - */ - -#define DEBUG - -#include -#include -#include -#include -#include -#include -#include -#include -#include - -#if defined(CONFIG_OF_LIBFDT) -#include -#include -#include -#elif defined(CONFIG_OF_FLAT_TREE) -#include -#endif - -#ifdef CONFIG_LOGBUFFER -#include -#endif - -#ifdef CFG_INIT_RAM_LOCK -#include -#endif - -DECLARE_GLOBAL_DATA_PTR; - -extern int do_reset (cmd_tbl_t *cmdtp, int flag, int argc, char *argv[]); - -#if defined(CONFIG_CMD_BDI) -extern int do_bdinfo(cmd_tbl_t *cmdtp, int flag, int argc, char *argv[]); -#endif - -void __attribute__((noinline)) -do_bootm_linux(cmd_tbl_t *cmdtp, int flag, - int argc, char *argv[], - image_header_t *hdr, - int verify) -{ - 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 cmd_start, cmd_end; - char *cmdline; - - ulong sp; - char *s; - bd_t *kbd; - void (*kernel)(bd_t *, ulong, ulong, ulong, ulong); - -#if defined(CONFIG_OF_FLAT_TREE) || defined(CONFIG_OF_LIBFDT) - image_header_t *fdt_hdr; - char *of_flat_tree = NULL; - 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 - * - * Allocate space for command line and board info - the - * address should be as high as possible within the reach of - * the kernel (see CFG_BOOTMAPSZ settings), but in unused - * memory, which means far enough below the current stack - * pointer. - */ - - asm( "mr %0,1": "=r"(sp) : ); - - debug ("## Current stack ends at 0x%08lX ", sp); - - sp -= 2048; /* just to be sure */ - if (sp > CFG_BOOTMAPSZ) - sp = CFG_BOOTMAPSZ; - sp &= ~0xF; - - debug ("=> set upper limit to 0x%08lX\n", sp); - - cmdline = (char *)((sp - 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); - -#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 */ - } - - kernel = (void (*)(bd_t *, ulong, ulong, ulong, ulong))image_get_ep (hdr); - - /* - * Check if there is an initrd image - */ - -#if defined(CONFIG_OF_FLAT_TREE) || 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; - } - -#if defined(CONFIG_OF_FLAT_TREE) || defined(CONFIG_OF_LIBFDT) - if(argc > 3) { - of_flat_tree = (char *) simple_strtoul(argv[3], NULL, 16); - fdt_hdr = (image_header_t *)of_flat_tree; -#if defined(CONFIG_OF_FLAT_TREE) - if (*((ulong *)(of_flat_tree)) == OF_DT_HEADER) { -#elif defined(CONFIG_OF_LIBFDT) - if (fdt_check_header (of_flat_tree) == 0) { -#endif -#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)) { - puts ("ERROR: fdt overwritten - " - "must RESET the board to recover.\n"); - do_reset (cmdtp, flag, argc, argv); - } - - puts (" Verifying Checksum ... "); - if (!image_check_hcrc (fdt_hdr)) { - puts ("ERROR: fdt header checksum invalid - " - "must RESET the board to recover.\n"); - do_reset (cmdtp, flag, argc, argv); - } - - if (!image_check_dcrc (fdt_hdr)) { - puts ("ERROR: fdt checksum invalid - " - "must RESET the board to recover.\n"); - do_reset (cmdtp, flag, argc, argv); - } - puts ("OK\n"); - - if (!image_check_type (fdt_hdr, IH_TYPE_FLATDT)) { - puts ("ERROR: uImage is not a fdt - " - "must RESET the board to recover.\n"); - do_reset (cmdtp, flag, argc, argv); - } - if (image_get_comp (fdt_hdr) != IH_COMP_NONE) { - puts ("ERROR: uImage is compressed - " - "must RESET the board to recover.\n"); - do_reset (cmdtp, flag, argc, argv); - } -#if defined(CONFIG_OF_FLAT_TREE) - if (*((ulong *)(of_flat_tree + image_get_header_size ())) != OF_DT_HEADER) { -#elif defined(CONFIG_OF_LIBFDT) - if (fdt_check_header (of_flat_tree + image_get_header_size ()) != 0) { -#endif - puts ("ERROR: uImage data is not a fdt - " - "must RESET the board to recover.\n"); - 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 { - puts ("Did not find a flat Flat Device Tree.\n" - "Must RESET the board to recover.\n"); - 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 defined(CONFIG_OF_FLAT_TREE) - if (*((ulong *)(of_flat_tree)) != OF_DT_HEADER) { -#elif defined(CONFIG_OF_LIBFDT) - if (fdt_check_header (of_flat_tree) != 0) { -#endif - puts ("ERROR: image is not a fdt - " - "must RESET the board to recover.\n"); - do_reset (cmdtp, flag, argc, argv); - } - -#if defined(CONFIG_OF_FLAT_TREE) - if (((struct boot_param_header *)of_flat_tree)->totalsize != fdt_len) { -#elif defined(CONFIG_OF_LIBFDT) - if (be32_to_cpu (fdt_totalsize (of_flat_tree)) != fdt_len) { -#endif - puts ("ERROR: fdt size != image size - " - "must RESET the board to recover.\n"); - do_reset (cmdtp, flag, argc, argv); - } - } - } -#endif - if (!rd_data) { - debug ("No initrd\n"); - } - - if (rd_data) { - if (!initrd_copy_to_ram) { /* zero-copy ramdisk support */ - initrd_start = rd_data; - initrd_end = initrd_start + 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 - * 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, rd_data + rd_len - 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); - - puts ("OK\n"); - } - } else { - initrd_start = 0; - initrd_end = 0; - } - -#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 kbd */ - of_start = (ulong)kbd - 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); - - 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) { - puts ("ERROR: fdt move failed - " - "must RESET the board to recover.\n"); - 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). - */ - if (of_flat_tree) { - if (fdt_chosen(of_flat_tree, initrd_start, initrd_end, 0) < 0) { - puts ("ERROR: /chosen node create failed - " - "must RESET the board to recover.\n"); - do_reset (cmdtp, flag, argc, argv); - } -#ifdef CONFIG_OF_HAS_UBOOT_ENV - if (fdt_env(of_flat_tree) < 0) { - puts ("ERROR: /u-boot-env node create failed - " - "must RESET the board to recover.\n"); - do_reset (cmdtp, flag, argc, argv); - } -#endif -#ifdef CONFIG_OF_HAS_BD_T - if (fdt_bd_t(of_flat_tree) < 0) { - puts ("ERROR: /bd_t node create failed - " - "must RESET the board to recover.\n"); - do_reset (cmdtp, flag, argc, argv); - } -#endif -#ifdef CONFIG_OF_BOARD_SETUP - /* Call the board-specific fixup routine */ - ft_board_setup(of_flat_tree, gd->bd); -#endif - } - -#elif defined(CONFIG_OF_FLAT_TREE) - -#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) { - ulong of_start, of_len; - of_len = ((struct boot_param_header *)of_data)->totalsize; - - /* provide extra 8k pad */ - of_start = (ulong)kbd - of_len - 8192; - 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); - - of_flat_tree = (char *)of_start; - printf (" Loading Device Tree to %08lx, end %08lx ... ", - of_start, of_start + of_len - 1); - memmove ((void *)of_start, (void *)of_data, of_len); - puts ("OK\n"); - } - /* - * Create the /chosen node and modify the blob with board specific - * values as needed. - */ - ft_setup(of_flat_tree, kbd, initrd_start, initrd_end); - /* ft_dump_blob(of_flat_tree); */ - -#endif /* #if defined(CONFIG_OF_LIBFDT) #elif defined(CONFIG_OF_FLAT_TREE) */ - - debug ("## Transferring control to Linux (at address %08lx) ...\n", - (ulong)kernel); - - show_boot_progress (15); - -#if defined(CFG_INIT_RAM_LOCK) && !defined(CONFIG_E500) - unlock_ram_in_cache(); -#endif - -#if defined(CONFIG_OF_FLAT_TREE) || defined(CONFIG_OF_LIBFDT) - if (of_flat_tree) { /* device tree; boot new style */ - /* - * Linux Kernel Parameters (passing device tree): - * r3: pointer to the fdt, followed by the board info data - * r4: physical pointer to the kernel itself - * r5: NULL - * r6: NULL - * r7: NULL - */ - (*kernel) ((bd_t *)of_flat_tree, (ulong)kernel, 0, 0, 0); - /* does not return */ - } -#endif - /* - * Linux Kernel Parameters (passing board info data): - * r3: ptr to board info data - * r4: initrd_start or 0 if no initrd - * r5: initrd_end - unused if r4 is 0 - * r6: Start of command line string - * r7: End of command line string - */ - (*kernel) (kbd, initrd_start, initrd_end, cmd_start, cmd_end); - /* does not return */ -} diff --git a/lib_sh/Makefile b/lib_sh/Makefile index cf127a826c..edb03d0082 100644 --- a/lib_sh/Makefile +++ b/lib_sh/Makefile @@ -24,7 +24,7 @@ LIB = $(obj)lib$(ARCH).a SOBJS = -COBJS = board.o sh_linux.o # time.o +COBJS = board.o bootm.o # time.o SRCS := $(SOBJS:.o=.S) $(COBJS:.o=.c) OBJS := $(addprefix $(obj),$(SOBJS) $(COBJS)) diff --git a/lib_sh/bootm.c b/lib_sh/bootm.c new file mode 100644 index 0000000000..14b6815cd4 --- /dev/null +++ b/lib_sh/bootm.c @@ -0,0 +1,74 @@ +/* + * (C) Copyright 2003 + * Wolfgang Denk, DENX Software Engineering, wd@denx.de. + * + * See file CREDITS for list of people who contributed to this + * project. + * + * This program is free software; you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation; either version 2 of the License, or + * (at your option) any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with this program; if not, write to the Free Software + * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA + * + */ + +#include +#include +#include + +extern image_header_t header; /* common/cmd_bootm.c */ + +/* The SH kernel reads arguments from the empty zero page at location + * 0 at the start of SDRAM. The following are copied from + * arch/sh/kernel/setup.c and may require tweaking if the kernel sources + * change. + */ +#define PARAM ((unsigned char *)CFG_SDRAM_BASE + 0x1000) + +#define MOUNT_ROOT_RDONLY (*(unsigned long *) (PARAM+0x000)) +#define RAMDISK_FLAGS (*(unsigned long *) (PARAM+0x004)) +#define ORIG_ROOT_DEV (*(unsigned long *) (PARAM+0x008)) +#define LOADER_TYPE (*(unsigned long *) (PARAM+0x00c)) +#define INITRD_START (*(unsigned long *) (PARAM+0x010)) +#define INITRD_SIZE (*(unsigned long *) (PARAM+0x014)) +/* ... */ +#define COMMAND_LINE ((char *) (PARAM+0x100)) + +#define RAMDISK_IMAGE_START_MASK 0x07FF + +#ifdef CFG_DEBUG +static void hexdump (unsigned char *buf, int len) +{ + int i; + + for (i = 0; i < len; i++) { + if ((i % 16) == 0) + printf ("%s%08x: ", i ? "\n" : "", (unsigned int) &buf[i]); + printf ("%02x ", buf[i]); + } + printf ("\n"); +} +#endif + +void do_bootm_linux (cmd_tbl_t *cmdtp, int flag, int argc, char *argv[], + ulong addr, ulong *len_ptr, int verify) +{ + image_header_t *hdr = &header; + char *bootargs = getenv("bootargs"); + void (*kernel) (void) = (void (*)(void)) ntohl (hdr->ih_ep); + + /* Setup parameters */ + memset(PARAM, 0, 0x1000); /* Clear zero page */ + strcpy(COMMAND_LINE, bootargs); + + kernel(); +} diff --git a/lib_sh/sh_linux.c b/lib_sh/sh_linux.c deleted file mode 100644 index 14b6815cd4..0000000000 --- a/lib_sh/sh_linux.c +++ /dev/null @@ -1,74 +0,0 @@ -/* - * (C) Copyright 2003 - * Wolfgang Denk, DENX Software Engineering, wd@denx.de. - * - * See file CREDITS for list of people who contributed to this - * project. - * - * This program is free software; you can redistribute it and/or modify - * it under the terms of the GNU General Public License as published by - * the Free Software Foundation; either version 2 of the License, or - * (at your option) any later version. - * - * This program is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - * GNU General Public License for more details. - * - * You should have received a copy of the GNU General Public License - * along with this program; if not, write to the Free Software - * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA - * - */ - -#include -#include -#include - -extern image_header_t header; /* common/cmd_bootm.c */ - -/* The SH kernel reads arguments from the empty zero page at location - * 0 at the start of SDRAM. The following are copied from - * arch/sh/kernel/setup.c and may require tweaking if the kernel sources - * change. - */ -#define PARAM ((unsigned char *)CFG_SDRAM_BASE + 0x1000) - -#define MOUNT_ROOT_RDONLY (*(unsigned long *) (PARAM+0x000)) -#define RAMDISK_FLAGS (*(unsigned long *) (PARAM+0x004)) -#define ORIG_ROOT_DEV (*(unsigned long *) (PARAM+0x008)) -#define LOADER_TYPE (*(unsigned long *) (PARAM+0x00c)) -#define INITRD_START (*(unsigned long *) (PARAM+0x010)) -#define INITRD_SIZE (*(unsigned long *) (PARAM+0x014)) -/* ... */ -#define COMMAND_LINE ((char *) (PARAM+0x100)) - -#define RAMDISK_IMAGE_START_MASK 0x07FF - -#ifdef CFG_DEBUG -static void hexdump (unsigned char *buf, int len) -{ - int i; - - for (i = 0; i < len; i++) { - if ((i % 16) == 0) - printf ("%s%08x: ", i ? "\n" : "", (unsigned int) &buf[i]); - printf ("%02x ", buf[i]); - } - printf ("\n"); -} -#endif - -void do_bootm_linux (cmd_tbl_t *cmdtp, int flag, int argc, char *argv[], - ulong addr, ulong *len_ptr, int verify) -{ - image_header_t *hdr = &header; - char *bootargs = getenv("bootargs"); - void (*kernel) (void) = (void (*)(void)) ntohl (hdr->ih_ep); - - /* Setup parameters */ - memset(PARAM, 0, 0x1000); /* Clear zero page */ - strcpy(COMMAND_LINE, bootargs); - - kernel(); -} -- cgit v1.2.3