X-Git-Url: https://git.kernelconcepts.de/?p=karo-tx-uboot.git;a=blobdiff_plain;f=arch%2Fpowerpc%2Flib%2Fboard.c;h=422b4a39bb8a5c08d2f0f195cbc41902e4fe6ae3;hp=c0c7fd4f6ee0caf89ae2d859e606ce39edc7e35a;hb=8dc16cf9dd6196d99969d12741df186a61a2f9a3;hpb=d98b0523cfaaedeecb263b15c121c0727b0d80b9 diff --git a/arch/powerpc/lib/board.c b/arch/powerpc/lib/board.c index c0c7fd4f6e..422b4a39bb 100644 --- a/arch/powerpc/lib/board.c +++ b/arch/powerpc/lib/board.c @@ -1,5 +1,5 @@ /* - * (C) Copyright 2000-2010 + * (C) Copyright 2000-2011 * Wolfgang Denk, DENX Software Engineering, wd@denx.de. * * See file CREDITS for list of people who contributed to this @@ -88,7 +88,7 @@ #endif #ifdef CONFIG_SYS_UPDATE_FLASH_SIZE -extern int update_flash_size (int flash_size); +extern int update_flash_size(int flash_size); #endif #if defined(CONFIG_SC3) @@ -96,7 +96,7 @@ extern void sc3_read_eeprom(void); #endif #if defined(CONFIG_CMD_DOC) -void doc_init (void); +void doc_init(void); #endif #if defined(CONFIG_HARD_I2C) || \ defined(CONFIG_SOFT_I2C) @@ -123,16 +123,15 @@ DECLARE_GLOBAL_DATA_PTR; #endif extern ulong __init_end; -extern ulong _end; +extern ulong __bss_end; ulong monitor_flash_len; #if defined(CONFIG_CMD_BEDBUG) #include #endif -/************************************************************************ - * Utilities * - ************************************************************************ +/* + * Utilities */ /* @@ -147,104 +146,116 @@ ulong monitor_flash_len; * argument, and returns an integer return code, where 0 means * "continue" and != 0 means "fatal error, hang the system". */ -typedef int (init_fnc_t) (void); +typedef int (init_fnc_t)(void); -/************************************************************************ - * Init Utilities * - ************************************************************************ +/* + * Init Utilities + * * Some of this code should be moved into the core functions, * but let's get it working (again) first... */ -static int init_baudrate (void) +static int init_baudrate(void) { - char tmp[64]; /* long enough for environment variables */ - int i = getenv_f("baudrate", tmp, sizeof (tmp)); - - gd->baudrate = (i > 0) - ? (int) simple_strtoul (tmp, NULL, 10) - : CONFIG_BAUDRATE; - return (0); + gd->baudrate = getenv_ulong("baudrate", 10, CONFIG_BAUDRATE); + return 0; } /***********************************************************************/ -void __board_add_ram_info(int use_default) +static void __board_add_ram_info(int use_default) { /* please define platform specific board_add_ram_info() */ } -void board_add_ram_info(int) __attribute__((weak, alias("__board_add_ram_info"))); +void board_add_ram_info(int) + __attribute__ ((weak, alias("__board_add_ram_info"))); -static int init_func_ram (void) +static int __board_flash_wp_on(void) +{ + /* + * Most flashes can't be detected when write protection is enabled, + * so provide a way to let U-Boot gracefully ignore write protected + * devices. + */ + return 0; +} + +int board_flash_wp_on(void) + __attribute__ ((weak, alias("__board_flash_wp_on"))); + +static void __cpu_secondary_init_r(void) +{ +} + +void cpu_secondary_init_r(void) + __attribute__ ((weak, alias("__cpu_secondary_init_r"))); + +static int init_func_ram(void) { #ifdef CONFIG_BOARD_TYPES int board_type = gd->board_type; #else int board_type = 0; /* use dummy arg */ #endif - puts ("DRAM: "); + puts("DRAM: "); + + gd->ram_size = initdram(board_type); - if ((gd->ram_size = initdram (board_type)) > 0) { - print_size (gd->ram_size, ""); + if (gd->ram_size > 0) { + print_size(gd->ram_size, ""); board_add_ram_info(0); putc('\n'); - return (0); + return 0; } - puts (failed); - return (1); + puts(failed); + return 1; } /***********************************************************************/ #if defined(CONFIG_HARD_I2C) || defined(CONFIG_SOFT_I2C) -static int init_func_i2c (void) +static int init_func_i2c(void) { - puts ("I2C: "); - i2c_init (CONFIG_SYS_I2C_SPEED, CONFIG_SYS_I2C_SLAVE); - puts ("ready\n"); - return (0); + puts("I2C: "); + i2c_init(CONFIG_SYS_I2C_SPEED, CONFIG_SYS_I2C_SLAVE); + puts("ready\n"); + return 0; } #endif #if defined(CONFIG_HARD_SPI) -static int init_func_spi (void) +static int init_func_spi(void) { - puts ("SPI: "); - spi_init (); - puts ("ready\n"); - return (0); + puts("SPI: "); + spi_init(); + puts("ready\n"); + return 0; } #endif /***********************************************************************/ #if defined(CONFIG_WATCHDOG) -static int init_func_watchdog_init (void) +int init_func_watchdog_init(void) { - puts (" Watchdog enabled\n"); - WATCHDOG_RESET (); - return (0); + puts(" Watchdog enabled\n"); + WATCHDOG_RESET(); + return 0; } -# define INIT_FUNC_WATCHDOG_INIT init_func_watchdog_init, -static int init_func_watchdog_reset (void) +int init_func_watchdog_reset(void) { - WATCHDOG_RESET (); - return (0); + WATCHDOG_RESET(); + return 0; } -# define INIT_FUNC_WATCHDOG_RESET init_func_watchdog_reset, -#else -# define INIT_FUNC_WATCHDOG_INIT /* undef */ -# define INIT_FUNC_WATCHDOG_RESET /* undef */ #endif /* CONFIG_WATCHDOG */ -/************************************************************************ - * Initialization sequence * - ************************************************************************ +/* + * Initialization sequence */ -init_fnc_t *init_sequence[] = { +static init_fnc_t *init_sequence[] = { #if defined(CONFIG_MPC85xx) || defined(CONFIG_MPC86xx) probecpu, #endif @@ -269,8 +280,10 @@ init_fnc_t *init_sequence[] = { #endif env_init, #if defined(CONFIG_8xx_CPUCLK_DEFAULT) - get_clocks_866, /* get CPU and bus clocks according to the environment variable */ - sdram_adjust_866, /* adjust sdram refresh rate according to the new clock */ + /* get CPU and bus clocks according to the environment variable */ + get_clocks_866, + /* adjust sdram refresh rate according to the new clock */ + sdram_adjust_866, init_timebase, #endif init_baudrate, @@ -312,8 +325,7 @@ init_fnc_t *init_sequence[] = { testdram, #endif /* CONFIG_SYS_DRAM_TEST */ INIT_FUNC_WATCHDOG_RESET - - NULL, /* Terminate this list */ + NULL, /* Terminate this list */ }; ulong get_effective_memsize(void) @@ -323,12 +335,18 @@ ulong get_effective_memsize(void) #else /* limit stack to what we can reasonable map */ return ((gd->ram_size > CONFIG_MAX_MEM_MAPPED) ? - CONFIG_MAX_MEM_MAPPED : gd->ram_size); + CONFIG_MAX_MEM_MAPPED : gd->ram_size); #endif } -/************************************************************************ - * +static int __fixup_cpu(void) +{ + return 0; +} + +int fixup_cpu(void) __attribute__((weak, alias("__fixup_cpu"))); + +/* * This is the first part of the initialization sequence that is * implemented in C, but still running from ROM. * @@ -339,8 +357,6 @@ ulong get_effective_memsize(void) * * Be aware of the restrictions: global data is read-only, BSS is not * initialized, and stack space is limited to a few kB. - * - ************************************************************************ */ #ifdef CONFIG_LOGBUFFER @@ -350,36 +366,40 @@ unsigned long logbuffer_base(void) } #endif -void board_init_f (ulong bootflag) +void board_init_f(ulong bootflag) { bd_t *bd; ulong len, addr, addr_sp; ulong *s; gd_t *id; init_fnc_t **init_fnc_ptr; + #ifdef CONFIG_PRAM - int i; ulong reg; - uchar tmp[64]; /* long enough for environment variables */ #endif /* Pointer is writable since we allocated a register for it */ gd = (gd_t *) (CONFIG_SYS_INIT_RAM_ADDR + CONFIG_SYS_GBL_DATA_OFFSET); /* compiler optimization barrier needed for GCC >= 3.4 */ - __asm__ __volatile__("": : :"memory"); + __asm__ __volatile__("":::"memory"); #if !defined(CONFIG_CPM2) && !defined(CONFIG_MPC512X) && \ !defined(CONFIG_MPC83xx) && !defined(CONFIG_MPC85xx) && \ !defined(CONFIG_MPC86xx) /* Clear initial global data */ - memset ((void *) gd, 0, sizeof (gd_t)); + memset((void *) gd, 0, sizeof(gd_t)); #endif - for (init_fnc_ptr = init_sequence; *init_fnc_ptr; ++init_fnc_ptr) { - if ((*init_fnc_ptr) () != 0) { - hang (); - } - } + for (init_fnc_ptr = init_sequence; *init_fnc_ptr; ++init_fnc_ptr) + if ((*init_fnc_ptr) () != 0) + hang(); + +#ifdef CONFIG_POST + post_bootmode_init(); + post_run(NULL, POST_ROM | post_bootmode_get(NULL)); +#endif + + WATCHDOG_RESET(); /* * Now that we have DRAM mapped and working, we can @@ -393,7 +413,7 @@ void board_init_f (ulong bootflag) * - monitor code * - board info struct */ - len = (ulong)&_end - CONFIG_SYS_MONITOR_BASE; + len = (ulong)&__bss_end - CONFIG_SYS_MONITOR_BASE; /* * Subtract specified amount of memory to hide so that it won't @@ -414,9 +434,9 @@ void board_init_f (ulong bootflag) * We need to make sure the location we intend to put secondary core * boot code is reserved and not used by any part of u-boot */ - if (addr > determine_mp_bootpg()) { - addr = determine_mp_bootpg(); - debug ("Reserving MP boot page to %08lx\n", addr); + if (addr > determine_mp_bootpg(NULL)) { + addr = determine_mp_bootpg(NULL); + debug("Reserving MP boot page to %08lx\n", addr); } #endif @@ -424,7 +444,8 @@ void board_init_f (ulong bootflag) #ifndef CONFIG_ALT_LB_ADDR /* reserve kernel log buffer */ addr -= (LOGBUFF_RESERVE); - debug ("Reserving %dk for kernel logbuffer at %08lx\n", LOGBUFF_LEN, addr); + debug("Reserving %dk for kernel logbuffer at %08lx\n", LOGBUFF_LEN, + addr); #endif #endif @@ -432,25 +453,28 @@ void board_init_f (ulong bootflag) /* * reserve protected RAM */ - i = getenv_f("pram", (char *)tmp, sizeof (tmp)); - reg = (i > 0) ? simple_strtoul ((const char *)tmp, NULL, 10) : CONFIG_PRAM; - addr -= (reg << 10); /* size is in kB */ - debug ("Reserving %ldk for protected RAM at %08lx\n", reg, addr); + reg = getenv_ulong("pram", 10, CONFIG_PRAM); + addr -= (reg << 10); /* size is in kB */ + debug("Reserving %ldk for protected RAM at %08lx\n", reg, addr); #endif /* CONFIG_PRAM */ /* round down to next 4 kB limit */ addr &= ~(4096 - 1); - debug ("Top of RAM usable for U-Boot at: %08lx\n", addr); + debug("Top of RAM usable for U-Boot at: %08lx\n", addr); #ifdef CONFIG_LCD +#ifdef CONFIG_FB_ADDR + gd->fb_base = CONFIG_FB_ADDR; +#else /* reserve memory for LCD display (always full pages) */ - addr = lcd_setmem (addr); + addr = lcd_setmem(addr); gd->fb_base = addr; +#endif /* CONFIG_FB_ADDR */ #endif /* CONFIG_LCD */ #if defined(CONFIG_VIDEO) && defined(CONFIG_8xx) /* reserve memory for video display (always full pages) */ - addr = video_setmem (addr); + addr = video_setmem(addr); gd->fb_base = addr; #endif /* CONFIG_VIDEO */ @@ -465,29 +489,29 @@ void board_init_f (ulong bootflag) addr &= ~(65536 - 1); #endif - debug ("Reserving %ldk for U-Boot at: %08lx\n", len >> 10, addr); + debug("Reserving %ldk for U-Boot at: %08lx\n", len >> 10, addr); /* * reserve memory for malloc() arena */ addr_sp = addr - TOTAL_MALLOC_LEN; - debug ("Reserving %dk for malloc() at: %08lx\n", - TOTAL_MALLOC_LEN >> 10, addr_sp); + debug("Reserving %dk for malloc() at: %08lx\n", + TOTAL_MALLOC_LEN >> 10, addr_sp); /* * (permanently) allocate a Board Info struct * and a permanent copy of the "global" data */ - addr_sp -= sizeof (bd_t); + addr_sp -= sizeof(bd_t); bd = (bd_t *) addr_sp; memset(bd, 0, sizeof(bd_t)); gd->bd = bd; - debug ("Reserving %zu Bytes for Board Info at: %08lx\n", - sizeof (bd_t), addr_sp); - addr_sp -= sizeof (gd_t); + debug("Reserving %zu Bytes for Board Info at: %08lx\n", + sizeof(bd_t), addr_sp); + addr_sp -= sizeof(gd_t); id = (gd_t *) addr_sp; - debug ("Reserving %zu Bytes for Global Data at: %08lx\n", - sizeof (gd_t), addr_sp); + debug("Reserving %zu Bytes for Global Data at: %08lx\n", + sizeof(gd_t), addr_sp); /* * Finally, we set up a new (bigger) stack. @@ -497,22 +521,21 @@ void board_init_f (ulong bootflag) */ addr_sp -= 16; addr_sp &= ~0xF; - s = (ulong *)addr_sp; - *s-- = 0; - *s-- = 0; - addr_sp = (ulong)s; - debug ("Stack Pointer at: %08lx\n", addr_sp); + s = (ulong *) addr_sp; + *s = 0; /* Terminate back chain */ + *++s = 0; /* NULL return address */ + debug("Stack Pointer at: %08lx\n", addr_sp); /* * Save local variables to board info struct */ - bd->bi_memstart = CONFIG_SYS_SDRAM_BASE; /* start of DRAM memory */ - bd->bi_memsize = gd->ram_size; /* size of DRAM memory in bytes */ + bd->bi_memstart = CONFIG_SYS_SDRAM_BASE; /* start of memory */ + bd->bi_memsize = gd->ram_size; /* size in bytes */ #ifdef CONFIG_SYS_SRAM_BASE - bd->bi_sramstart = CONFIG_SYS_SRAM_BASE; /* start of SRAM memory */ - bd->bi_sramsize = CONFIG_SYS_SRAM_SIZE; /* size of SRAM memory */ + bd->bi_sramstart = CONFIG_SYS_SRAM_BASE; /* start of SRAM */ + bd->bi_sramsize = CONFIG_SYS_SRAM_SIZE; /* size of SRAM */ #endif #if defined(CONFIG_8xx) || defined(CONFIG_8260) || defined(CONFIG_5xx) || \ @@ -527,91 +550,82 @@ void board_init_f (ulong bootflag) #endif #if defined(CONFIG_MPC8220) bd->bi_mbar_base = CONFIG_SYS_MBAR; /* base of internal registers */ - bd->bi_inpfreq = gd->inp_clk; - bd->bi_pcifreq = gd->pci_clk; - bd->bi_vcofreq = gd->vco_clk; - bd->bi_pevfreq = gd->pev_clk; - bd->bi_flbfreq = gd->flb_clk; + bd->bi_inpfreq = gd->arch.inp_clk; + bd->bi_pcifreq = gd->pci_clk; + bd->bi_vcofreq = gd->arch.vco_clk; + bd->bi_pevfreq = gd->arch.pev_clk; + bd->bi_flbfreq = gd->arch.flb_clk; /* store bootparam to sram (backward compatible), here? */ { - u32 *sram = (u32 *)CONFIG_SYS_SRAM_BASE; + u32 *sram = (u32 *) CONFIG_SYS_SRAM_BASE; + *sram++ = gd->ram_size; *sram++ = gd->bus_clk; - *sram++ = gd->inp_clk; + *sram++ = gd->arch.inp_clk; *sram++ = gd->cpu_clk; - *sram++ = gd->vco_clk; - *sram++ = gd->flb_clk; - *sram++ = 0xb8c3ba11; /* boot signature */ + *sram++ = gd->arch.vco_clk; + *sram++ = gd->arch.flb_clk; + *sram++ = 0xb8c3ba11; /* boot signature */ } #endif - WATCHDOG_RESET (); + WATCHDOG_RESET(); bd->bi_intfreq = gd->cpu_clk; /* Internal Freq, in Hz */ bd->bi_busfreq = gd->bus_clk; /* Bus Freq, in Hz */ #if defined(CONFIG_CPM2) - bd->bi_cpmfreq = gd->cpm_clk; - bd->bi_brgfreq = gd->brg_clk; - bd->bi_sccfreq = gd->scc_clk; - bd->bi_vco = gd->vco_out; + bd->bi_cpmfreq = gd->arch.cpm_clk; + bd->bi_brgfreq = gd->arch.brg_clk; + bd->bi_sccfreq = gd->arch.scc_clk; + bd->bi_vco = gd->arch.vco_out; #endif /* CONFIG_CPM2 */ #if defined(CONFIG_MPC512X) - bd->bi_ipsfreq = gd->ips_clk; + bd->bi_ipsfreq = gd->arch.ips_clk; #endif /* CONFIG_MPC512X */ #if defined(CONFIG_MPC5xxx) - bd->bi_ipbfreq = gd->ipb_clk; + bd->bi_ipbfreq = gd->arch.ipb_clk; bd->bi_pcifreq = gd->pci_clk; #endif /* CONFIG_MPC5xxx */ bd->bi_baudrate = gd->baudrate; /* Console Baudrate */ #ifdef CONFIG_SYS_EXTBDINFO - strncpy ((char *)bd->bi_s_version, "1.2", sizeof (bd->bi_s_version)); - strncpy ((char *)bd->bi_r_version, U_BOOT_VERSION, sizeof (bd->bi_r_version)); + strncpy((char *) bd->bi_s_version, "1.2", sizeof(bd->bi_s_version)); + strncpy((char *) bd->bi_r_version, U_BOOT_VERSION, + sizeof(bd->bi_r_version)); bd->bi_procfreq = gd->cpu_clk; /* Processor Speed, In Hz */ bd->bi_plb_busfreq = gd->bus_clk; #if defined(CONFIG_405GP) || defined(CONFIG_405EP) || \ defined(CONFIG_440EP) || defined(CONFIG_440GR) || \ defined(CONFIG_440EPX) || defined(CONFIG_440GRX) - bd->bi_pci_busfreq = get_PCI_freq (); - bd->bi_opbfreq = get_OPB_freq (); + bd->bi_pci_busfreq = get_PCI_freq(); + bd->bi_opbfreq = get_OPB_freq(); #elif defined(CONFIG_XILINX_405) - bd->bi_pci_busfreq = get_PCI_freq (); + bd->bi_pci_busfreq = get_PCI_freq(); #endif #endif - debug ("New Stack Pointer is: %08lx\n", addr_sp); - - WATCHDOG_RESET (); - -#ifdef CONFIG_POST - post_bootmode_init(); - post_run (NULL, POST_ROM | post_bootmode_get(0)); -#endif + debug("New Stack Pointer is: %08lx\n", addr_sp); WATCHDOG_RESET(); - gd->relocaddr = addr; /* Record relocation address, useful for debug */ + gd->relocaddr = addr; /* Store relocation addr, useful for debug */ - memcpy (id, (void *)gd, sizeof (gd_t)); + memcpy(id, (void *) gd, sizeof(gd_t)); - relocate_code (addr_sp, id, addr); + relocate_code(addr_sp, id, addr); /* NOTREACHED - relocate_code() does not return */ } -/************************************************************************ - * +/* * This is the next part if the initialization sequence: we are now * running from RAM and have a "normal" C environment, i. e. global * data can be written, BSS has been cleared, the stack size in not * that critical any more, etc. - * - ************************************************************************ */ -void board_init_r (gd_t *id, ulong dest_addr) +void board_init_r(gd_t *id, ulong dest_addr) { - char *s; bd_t *bd; ulong malloc_start; @@ -629,48 +643,64 @@ void board_init_r (gd_t *id, ulong dest_addr) #if defined(CONFIG_MPC85xx) || defined(CONFIG_MPC86xx) /* - * The gd->cpu pointer is set to an address in flash before relocation. - * We need to update it to point to the same CPU entry in RAM. + * The gd->arch.cpu pointer is set to an address in flash before + * relocation. We need to update it to point to the same CPU entry + * in RAM. + */ + gd->arch.cpu += dest_addr - CONFIG_SYS_MONITOR_BASE; + + /* + * If we didn't know the cpu mask & # cores, we can save them of + * now rather than 'computing' them constantly */ - gd->cpu += dest_addr - CONFIG_SYS_MONITOR_BASE; + fixup_cpu(); #endif -#ifdef CONFIG_SERIAL_MULTI - serial_initialize(); +#ifdef CONFIG_SYS_EXTRA_ENV_RELOC + /* + * Some systems need to relocate the env_addr pointer early because the + * location it points to will get invalidated before env_relocate is + * called. One example is on systems that might use a L2 or L3 cache + * in SRAM mode and initialize that cache from SRAM mode back to being + * a cache in cpu_init_r. + */ + gd->env_addr += dest_addr - CONFIG_SYS_MONITOR_BASE; #endif - debug ("Now running in RAM - U-Boot at: %08lx\n", dest_addr); + serial_initialize(); - WATCHDOG_RESET (); + debug("Now running in RAM - U-Boot at: %08lx\n", dest_addr); + + WATCHDOG_RESET(); /* * Setup trap handlers */ - trap_init (dest_addr); + trap_init(dest_addr); #ifdef CONFIG_ADDR_MAP init_addr_map(); #endif #if defined(CONFIG_BOARD_EARLY_INIT_R) - board_early_init_r (); + board_early_init_r(); #endif monitor_flash_len = (ulong)&__init_end - dest_addr; - WATCHDOG_RESET (); + WATCHDOG_RESET(); #ifdef CONFIG_LOGBUFFER - logbuff_init_ptrs (); + logbuff_init_ptrs(); #endif #ifdef CONFIG_POST - post_output_backlog (); + post_output_backlog(); #endif WATCHDOG_RESET(); #if defined(CONFIG_SYS_DELAYED_ICACHE) - icache_enable (); /* it's time to enable the instruction cache */ + icache_enable(); /* it's time to enable the instruction cache */ #endif #if defined(CONFIG_SYS_INIT_RAM_LOCK) && defined(CONFIG_E500) @@ -682,79 +712,86 @@ void board_init_r (gd_t *id, ulong dest_addr) * Do early PCI configuration _before_ the flash gets initialised, * because PCU ressources are crucial for flash access on some boards. */ - pci_init (); + pci_init(); #endif -#if defined(CONFIG_BAB7xx) +#if defined(CONFIG_WINBOND_83C553) /* * Initialise the ISA bridge */ - initialise_w83c553f (); + initialise_w83c553f(); #endif - asm ("sync ; isync"); + asm("sync ; isync"); - mem_malloc_init (malloc_start, TOTAL_MALLOC_LEN); + mem_malloc_init(malloc_start, TOTAL_MALLOC_LEN); #if !defined(CONFIG_SYS_NO_FLASH) - puts ("FLASH: "); - - if ((flash_size = flash_init ()) > 0) { -# ifdef CONFIG_SYS_FLASH_CHECKSUM - print_size (flash_size, ""); + puts("Flash: "); + + if (board_flash_wp_on()) { + printf("Uninitialized - Write Protect On\n"); + /* Since WP is on, we can't find real size. Set to 0 */ + flash_size = 0; + } else if ((flash_size = flash_init()) > 0) { +#ifdef CONFIG_SYS_FLASH_CHECKSUM + print_size(flash_size, ""); /* * Compute and print flash CRC if flashchecksum is set to 'y' * * NOTE: Maybe we should add some WATCHDOG_RESET()? XXX */ - s = getenv ("flashchecksum"); - if (s && (*s == 'y')) { - printf (" CRC: %08X", - crc32 (0, (const unsigned char *) CONFIG_SYS_FLASH_BASE, flash_size) - ); + if (getenv_yesno("flashchecksum") == 1) { + printf(" CRC: %08X", + crc32(0, + (const unsigned char *) + CONFIG_SYS_FLASH_BASE, flash_size) + ); } - putc ('\n'); -# else /* !CONFIG_SYS_FLASH_CHECKSUM */ - print_size (flash_size, "\n"); -# endif /* CONFIG_SYS_FLASH_CHECKSUM */ + putc('\n'); +#else /* !CONFIG_SYS_FLASH_CHECKSUM */ + print_size(flash_size, "\n"); +#endif /* CONFIG_SYS_FLASH_CHECKSUM */ } else { - puts (failed); - hang (); + puts(failed); + hang(); } - bd->bi_flashstart = CONFIG_SYS_FLASH_BASE; /* update start of FLASH memory */ - bd->bi_flashsize = flash_size; /* size of FLASH memory (final value) */ + /* update start of FLASH memory */ + bd->bi_flashstart = CONFIG_SYS_FLASH_BASE; + /* size of FLASH memory (final value) */ + bd->bi_flashsize = flash_size; #if defined(CONFIG_SYS_UPDATE_FLASH_SIZE) /* Make a update of the Memctrl. */ - update_flash_size (flash_size); + update_flash_size(flash_size); #endif -# if defined(CONFIG_OXC) || defined(CONFIG_RMU) +#if defined(CONFIG_OXC) || defined(CONFIG_RMU) /* flash mapped at end of memory map */ bd->bi_flashoffset = CONFIG_SYS_TEXT_BASE + flash_size; -# elif CONFIG_SYS_MONITOR_BASE == CONFIG_SYS_FLASH_BASE - bd->bi_flashoffset = monitor_flash_len; /* reserved area for startup monitor */ -# endif +#elif CONFIG_SYS_MONITOR_BASE == CONFIG_SYS_FLASH_BASE + bd->bi_flashoffset = monitor_flash_len; /* reserved area for monitor */ +#endif #endif /* !CONFIG_SYS_NO_FLASH */ - WATCHDOG_RESET (); + WATCHDOG_RESET(); /* initialize higher level parts of CPU like time base and timers */ - cpu_init_r (); + cpu_init_r(); - WATCHDOG_RESET (); + WATCHDOG_RESET(); #ifdef CONFIG_SPI -# if !defined(CONFIG_ENV_IS_IN_EEPROM) - spi_init_f (); -# endif - spi_init_r (); +#if !defined(CONFIG_ENV_IS_IN_EEPROM) + spi_init_f(); +#endif + spi_init_r(); #endif #if defined(CONFIG_CMD_NAND) - WATCHDOG_RESET (); - puts ("NAND: "); + WATCHDOG_RESET(); + puts("NAND: "); nand_init(); /* go init the NAND */ #endif @@ -764,13 +801,21 @@ void board_init_r (gd_t *id, ulong dest_addr) * Thus It is required that operations like pin multiplexer * be put in board_init. */ - WATCHDOG_RESET (); - puts ("MMC: "); - mmc_initialize (bd); + WATCHDOG_RESET(); + puts("MMC: "); + mmc_initialize(bd); #endif /* relocate environment function pointers etc. */ - env_relocate (); + env_relocate(); + + /* + * after non-volatile devices & environment is setup and cpu code have + * another round to deal with any initialization that might require + * full access to the environment or loading of some image (firmware) + * from a non-volatile device + */ + cpu_secondary_init_r(); /* * Fill in missing fields of bd_info. @@ -788,21 +833,20 @@ void board_init_r (gd_t *id, ulong dest_addr) * "i2cfast" into account */ { - char *s = getenv ("i2cfast"); - if (s && ((*s == 'y') || (*s == 'Y'))) { + if (getenv_yesno("i2cfast") == 1) { bd->bi_iic_fast[0] = 1; bd->bi_iic_fast[1] = 1; } } -#endif /* CONFIG_I2CFAST */ -#endif /* CONFIG_405GP, CONFIG_405EP */ -#endif /* CONFIG_SYS_EXTBDINFO */ +#endif /* CONFIG_I2CFAST */ +#endif /* CONFIG_405GP, CONFIG_405EP */ +#endif /* CONFIG_SYS_EXTBDINFO */ #if defined(CONFIG_SC3) sc3_read_eeprom(); #endif -#if defined (CONFIG_ID_EEPROM) || defined (CONFIG_SYS_I2C_MAC_OFFSET) +#if defined(CONFIG_ID_EEPROM) || defined(CONFIG_SYS_I2C_MAC_OFFSET) mac_read_from_eeprom(); #endif @@ -833,147 +877,130 @@ void board_init_r (gd_t *id, ulong dest_addr) #endif #endif /* CONFIG_CMD_NET */ - /* IP Address */ - bd->bi_ip_addr = getenv_IPaddr ("ipaddr"); - - WATCHDOG_RESET (); + WATCHDOG_RESET(); #if defined(CONFIG_PCI) && !defined(CONFIG_SYS_EARLY_PCI_INIT) /* * Do pci configuration */ - pci_init (); + pci_init(); #endif /** leave this here (after malloc(), environment and PCI are working) **/ /* Initialize stdio devices */ - stdio_init (); + stdio_init(); /* Initialize the jump table for applications */ - jumptable_init (); + jumptable_init(); #if defined(CONFIG_API) /* Initialize API */ - api_init (); + api_init(); #endif /* Initialize the console (after the relocation and devices init) */ - console_init_r (); + console_init_r(); #if defined(CONFIG_MISC_INIT_R) /* miscellaneous platform dependent initialisations */ - misc_init_r (); + misc_init_r(); #endif #ifdef CONFIG_HERMES if (bd->bi_ethspeed != 0xFFFF) - hermes_start_lxt980 ((int) bd->bi_ethspeed); + hermes_start_lxt980((int) bd->bi_ethspeed); #endif #if defined(CONFIG_CMD_KGDB) - WATCHDOG_RESET (); - puts ("KGDB: "); - kgdb_init (); + WATCHDOG_RESET(); + puts("KGDB: "); + kgdb_init(); #endif - debug ("U-Boot relocated to %08lx\n", dest_addr); + debug("U-Boot relocated to %08lx\n", dest_addr); /* * Enable Interrupts */ - interrupt_init (); + interrupt_init(); #if defined(CONFIG_STATUS_LED) && defined(STATUS_LED_BOOT) - status_led_set (STATUS_LED_BOOT, STATUS_LED_BLINKING); + status_led_set(STATUS_LED_BOOT, STATUS_LED_BLINKING); #endif - udelay (20); - - set_timer (0); + udelay(20); /* Initialize from environment */ - if ((s = getenv ("loadaddr")) != NULL) { - load_addr = simple_strtoul (s, NULL, 16); - } -#if defined(CONFIG_CMD_NET) - if ((s = getenv ("bootfile")) != NULL) { - copy_filename (BootFile, s, sizeof (BootFile)); - } -#endif + load_addr = getenv_ulong("loadaddr", 16, load_addr); - WATCHDOG_RESET (); + WATCHDOG_RESET(); -#if defined(CONFIG_DTT) /* Digital Thermometers and Thermostats */ - dtt_init (); -#endif #if defined(CONFIG_CMD_SCSI) - WATCHDOG_RESET (); - puts ("SCSI: "); - scsi_init (); + WATCHDOG_RESET(); + puts("SCSI: "); + scsi_init(); #endif #if defined(CONFIG_CMD_DOC) - WATCHDOG_RESET (); - puts ("DOC: "); - doc_init (); + WATCHDOG_RESET(); + puts("DOC: "); + doc_init(); #endif #ifdef CONFIG_BITBANGMII bb_miiphy_init(); #endif #if defined(CONFIG_CMD_NET) -#if defined(CONFIG_NET_MULTI) - WATCHDOG_RESET (); - puts ("Net: "); -#endif - eth_initialize (bd); + WATCHDOG_RESET(); + puts("Net: "); + eth_initialize(bd); #endif #if defined(CONFIG_CMD_NET) && defined(CONFIG_RESET_PHY_R) - WATCHDOG_RESET (); - debug ("Reset Ethernet PHY\n"); - reset_phy (); + WATCHDOG_RESET(); + debug("Reset Ethernet PHY\n"); + reset_phy(); #endif #ifdef CONFIG_POST - post_run (NULL, POST_RAM | post_bootmode_get(0)); + post_run(NULL, POST_RAM | post_bootmode_get(0)); #endif #if defined(CONFIG_CMD_PCMCIA) \ && !defined(CONFIG_CMD_IDE) - WATCHDOG_RESET (); - puts ("PCMCIA:"); - pcmcia_init (); + WATCHDOG_RESET(); + puts("PCMCIA:"); + pcmcia_init(); #endif #if defined(CONFIG_CMD_IDE) - WATCHDOG_RESET (); -# ifdef CONFIG_IDE_8xx_PCCARD - puts ("PCMCIA:"); -# else - puts ("IDE: "); + WATCHDOG_RESET(); +#ifdef CONFIG_IDE_8xx_PCCARD + puts("PCMCIA:"); +#else + puts("IDE: "); #endif #if defined(CONFIG_START_IDE) if (board_start_ide()) - ide_init (); + ide_init(); #else - ide_init (); + ide_init(); #endif #endif #ifdef CONFIG_LAST_STAGE_INIT - WATCHDOG_RESET (); + WATCHDOG_RESET(); /* * Some parts can be only initialized if all others (like * Interrupts) are up and running (i.e. the PC-style ISA * keyboard). */ - last_stage_init (); + last_stage_init(); #endif #if defined(CONFIG_CMD_BEDBUG) - WATCHDOG_RESET (); - bedbug_init (); + WATCHDOG_RESET(); + bedbug_init(); #endif #if defined(CONFIG_PRAM) || defined(CONFIG_LOGBUFFER) @@ -982,62 +1009,57 @@ void board_init_r (gd_t *id, ulong dest_addr) * taking into account the protected RAM at top of memory */ { - ulong pram; - uchar memsz[32]; -#ifdef CONFIG_PRAM - char *s; + ulong pram = 0; + char memsz[32]; - if ((s = getenv ("pram")) != NULL) { - pram = simple_strtoul (s, NULL, 10); - } else { - pram = CONFIG_PRAM; - } -#else - pram=0; +#ifdef CONFIG_PRAM + pram = getenv_ulong("pram", 10, CONFIG_PRAM); #endif #ifdef CONFIG_LOGBUFFER #ifndef CONFIG_ALT_LB_ADDR /* Also take the logbuffer into account (pram is in kB) */ - pram += (LOGBUFF_LEN+LOGBUFF_OVERHEAD)/1024; + pram += (LOGBUFF_LEN + LOGBUFF_OVERHEAD) / 1024; #endif #endif - sprintf ((char *)memsz, "%ldk", (bd->bi_memsize / 1024) - pram); - setenv ("mem", (char *)memsz); + sprintf(memsz, "%ldk", (bd->bi_memsize / 1024) - pram); + setenv("mem", memsz); } #endif #ifdef CONFIG_PS2KBD - puts ("PS/2: "); + puts("PS/2: "); kbd_init(); #endif #ifdef CONFIG_MODEM_SUPPORT - { - extern int do_mdm_init; - do_mdm_init = gd->do_mdm_init; - } + { + extern int do_mdm_init; + + do_mdm_init = gd->do_mdm_init; + } #endif /* Initialization complete - start the monitor */ /* main_loop() can return to retry autoboot, if so just run it again. */ for (;;) { - WATCHDOG_RESET (); - main_loop (); + WATCHDOG_RESET(); + main_loop(); } /* NOTREACHED - no way out of command loop except booting */ } -void hang (void) +void hang(void) { - puts ("### ERROR ### Please RESET the board ###\n"); - show_boot_progress(-30); - for (;;); + puts("### ERROR ### Please RESET the board ###\n"); + bootstage_error(BOOTSTAGE_ID_NEED_RESET); + for (;;) + ; } -#if 0 /* We could use plain global data, but the resulting code is bigger */ +#if 0 /* We could use plain global data, but the resulting code is bigger */ /* * Pointer to initial global data area * @@ -1045,7 +1067,8 @@ void hang (void) */ #undef XTRN_DECLARE_GLOBAL_DATA_PTR #define XTRN_DECLARE_GLOBAL_DATA_PTR /* empty = allocate here */ -DECLARE_GLOBAL_DATA_PTR = (gd_t *) (CONFIG_SYS_INIT_RAM_ADDR + CONFIG_SYS_GBL_DATA_OFFSET); -#endif /* 0 */ +DECLARE_GLOBAL_DATA_PTR = + (gd_t *) (CONFIG_SYS_INIT_RAM_ADDR + CONFIG_SYS_GBL_DATA_OFFSET); +#endif /* 0 */ /************************************************************************/