📄 board.c
字号:
* Reserve memory at end of RAM for (top down in that order): * - area that won't get touched by U-Boot and Linux (optional) * - kernel log buffer * - protected RAM * - LCD framebuffer * - monitor code * - board info struct */ len = (ulong)&_end - CFG_MONITOR_BASE; /* * Subtract specified amount of memory to hide so that it won't * get "touched" at all by U-Boot. By fixing up gd->ram_size * the Linux kernel should now get passed the now "corrected" * memory size and won't touch it either. This should work * for arch/ppc and arch/powerpc. Only Linux board ports in * arch/powerpc with bootwrapper support, that recalculate the * memory size from the SDRAM controller setup will have to * get fixed. */ gd->ram_size -= CFG_MEM_TOP_HIDE; addr = CFG_SDRAM_BASE + get_effective_memsize();#ifdef CONFIG_LOGBUFFER#ifndef CONFIG_ALT_LB_ADDR /* reserve kernel log buffer */ addr -= (LOGBUFF_RESERVE); debug ("Reserving %dk for kernel logbuffer at %08lx\n", LOGBUFF_LEN, addr);#endif#endif#ifdef CONFIG_PRAM /* * reserve protected RAM */ i = getenv_r ("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);#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);#ifdef CONFIG_LCD /* reserve memory for LCD display (always full pages) */ addr = lcd_setmem (addr); gd->fb_base = addr;#endif /* CONFIG_LCD */#if defined(CONFIG_VIDEO) && defined(CONFIG_8xx) /* reserve memory for video display (always full pages) */ addr = video_setmem (addr); gd->fb_base = addr;#endif /* CONFIG_VIDEO */ /* * reserve memory for U-Boot code, data & bss * round down to next 4 kB limit */ addr -= len; addr &= ~(4096 - 1);#ifdef CONFIG_E500 /* round down to next 64 kB limit so that IVPR stays aligned */ addr &= ~(65536 - 1);#endif debug ("Reserving %ldk for U-Boot at: %08lx\n", len >> 10, addr);#ifdef CONFIG_AMIGAONEG3SE gd->relocaddr = addr;#endif /* * 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); /* * (permanently) allocate a Board Info struct * and a permanent copy of the "global" data */ addr_sp -= sizeof (bd_t); bd = (bd_t *) addr_sp; gd->bd = bd; 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); /* * Finally, we set up a new (bigger) stack. * * Leave some safety gap for SP, force alignment on 16 byte boundary * Clear initial stack frame */ 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); /* * Save local variables to board info struct */ bd->bi_memstart = CFG_SDRAM_BASE; /* start of DRAM memory */ bd->bi_memsize = gd->ram_size; /* size of DRAM memory in bytes */#ifdef CONFIG_IP860 bd->bi_sramstart = SRAM_BASE; /* start of SRAM memory */ bd->bi_sramsize = SRAM_SIZE; /* size of SRAM memory */#elif defined CONFIG_MPC8220 bd->bi_sramstart = CFG_SRAM_BASE; /* start of SRAM memory */ bd->bi_sramsize = CFG_SRAM_SIZE; /* size of SRAM memory */#else bd->bi_sramstart = 0; /* FIXME */ /* start of SRAM memory */ bd->bi_sramsize = 0; /* FIXME */ /* size of SRAM memory */#endif#if defined(CONFIG_8xx) || defined(CONFIG_8260) || defined(CONFIG_5xx) || \ defined(CONFIG_E500) || defined(CONFIG_MPC86xx) bd->bi_immr_base = CFG_IMMR; /* base of IMMR register */#endif#if defined(CONFIG_MPC5xxx) bd->bi_mbar_base = CFG_MBAR; /* base of internal registers */#endif#if defined(CONFIG_MPC83XX) bd->bi_immrbar = CFG_IMMR;#endif#if defined(CONFIG_MPC8220) bd->bi_mbar_base = CFG_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; /* store bootparam to sram (backward compatible), here? */ { u32 *sram = (u32 *)CFG_SRAM_BASE; *sram++ = gd->ram_size; *sram++ = gd->bus_clk; *sram++ = gd->inp_clk; *sram++ = gd->cpu_clk; *sram++ = gd->vco_clk; *sram++ = gd->flb_clk; *sram++ = 0xb8c3ba11; /* boot signature */ }#endif bd->bi_bootflags = bootflag; /* boot / reboot flag (for LynxOS) */ 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;#endif /* CONFIG_CPM2 */#if defined(CONFIG_MPC512X) bd->bi_ipsfreq = gd->ips_clk;#endif /* CONFIG_MPC512X */#if defined(CONFIG_MPC5xxx) bd->bi_ipbfreq = gd->ipb_clk; bd->bi_pcifreq = gd->pci_clk;#endif /* CONFIG_MPC5xxx */ bd->bi_baudrate = gd->baudrate; /* Console Baudrate */#ifdef CFG_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)); 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 ();#elif defined(CONFIG_XILINX_405) 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 WATCHDOG_RESET(); memcpy (id, (void *)gd, sizeof (gd_t)); 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){ cmd_tbl_t *cmdtp; char *s, *e; bd_t *bd; int i; extern void malloc_bin_reloc (void);#ifndef CFG_ENV_IS_NOWHERE extern char * env_name_spec;#endif#ifndef CFG_NO_FLASH ulong flash_size;#endif gd = id; /* initialize RAM version of global data */ bd = gd->bd; gd->flags |= GD_FLG_RELOC; /* tell others: relocation done */#if defined(CONFIG_RELOC_FIXUP_WORKS) gd->reloc_off = 0; mem_malloc_end = dest_addr;#else gd->reloc_off = dest_addr - CFG_MONITOR_BASE;#endif#ifdef CONFIG_SERIAL_MULTI serial_initialize();#endif debug ("Now running in RAM - U-Boot at: %08lx\n", dest_addr); WATCHDOG_RESET ();#if defined(CONFIG_BOARD_EARLY_INIT_R) board_early_init_r ();#endif monitor_flash_len = (ulong)&__init_end - dest_addr; /* * We have to relocate the command table manually */ for (cmdtp = &__u_boot_cmd_start; cmdtp != &__u_boot_cmd_end; cmdtp++) { ulong addr; addr = (ulong) (cmdtp->cmd) + gd->reloc_off;#if 0 printf ("Command \"%s\": 0x%08lx => 0x%08lx\n", cmdtp->name, (ulong) (cmdtp->cmd), addr);#endif cmdtp->cmd = (int (*)(struct cmd_tbl_s *, int, int, char *[]))addr; addr = (ulong)(cmdtp->name) + gd->reloc_off; cmdtp->name = (char *)addr; if (cmdtp->usage) { addr = (ulong)(cmdtp->usage) + gd->reloc_off; cmdtp->usage = (char *)addr; }#ifdef CFG_LONGHELP if (cmdtp->help) { addr = (ulong)(cmdtp->help) + gd->reloc_off; cmdtp->help = (char *)addr; }#endif } /* there are some other pointer constants we must deal with */#ifndef CFG_ENV_IS_NOWHERE env_name_spec += gd->reloc_off;#endif WATCHDOG_RESET ();#ifdef CONFIG_LOGBUFFER logbuff_init_ptrs ();#endif#ifdef CONFIG_POST post_output_backlog (); post_reloc ();#endif WATCHDOG_RESET();#if defined(CONFIG_IP860) || defined(CONFIG_PCU_E) || \ defined (CONFIG_FLAGADM) || defined(CONFIG_MPC83XX) icache_enable (); /* it's time to enable the instruction cache */#endif#if defined(CFG_INIT_RAM_LOCK) && defined(CONFIG_E500) unlock_ram_in_cache(); /* it's time to unlock D-cache in e500 */#endif#if defined(CONFIG_BAB7xx) || defined(CONFIG_CPC45) /* * Do PCI configuration on BAB7xx and CPC45 _before_ the flash * gets initialised, because we need the ISA resp. PCI_to_LOCAL bus * bridge there. */ pci_init ();#endif#if defined(CONFIG_BAB7xx) /* * Initialise the ISA bridge */ initialise_w83c553f ();#endif asm ("sync ; isync"); /* * Setup trap handlers */ trap_init (dest_addr);#if !defined(CFG_NO_FLASH) puts ("FLASH: "); if ((flash_size = flash_init ()) > 0) {# ifdef CFG_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 *) CFG_FLASH_BASE, flash_size) ); } putc ('\n');# else /* !CFG_FLASH_CHECKSUM */ print_size (flash_size, "\n");# endif /* CFG_FLASH_CHECKSUM */ } else { puts (failed); hang (); } bd->bi_flashstart = CFG_FLASH_BASE; /* update start of FLASH memory */ bd->bi_flashsize = flash_size; /* size of FLASH memory (final value) */#if defined(CFG_UPDATE_FLASH_SIZE) /* Make a update of the Memctrl. */ update_flash_size (flash_size);#endif# if defined(CONFIG_PCU_E) || defined(CONFIG_OXC) || defined(CONFIG_RMU) /* flash mapped at end of memory map */ bd->bi_flashoffset = TEXT_BASE + flash_size;# elif CFG_MONITOR_BASE == CFG_FLASH_BASE bd->bi_flashoffset = monitor_flash_len; /* reserved area for startup monitor */# else bd->bi_flashoffset = 0;# endif#else /* CFG_NO_FLASH */ bd->bi_flashsize = 0; bd->bi_flashstart = 0; bd->bi_flashoffset = 0;#endif /* !CFG_NO_FLASH */ WATCHDOG_RESET (); /* initialize higher level parts of CPU like time base and timers */ cpu_init_r (); WATCHDOG_RESET (); /* initialize malloc() area */ mem_malloc_init (); malloc_bin_reloc ();#ifdef CONFIG_SPI# if !defined(CFG_ENV_IS_IN_EEPROM) spi_init_f ();# endif spi_init_r ();#endif#if defined(CONFIG_CMD_NAND) WATCHDOG_RESET (); puts ("NAND: "); nand_init(); /* go init the NAND */#endif /* relocate environment function pointers etc. */ env_relocate (); /* * Fill in missing fields of bd_info. * We do this here, where we have "normal" access to the * environment; we used to do this still running from ROM, * where had to use getenv_r(), which can be pretty slow when * the environment is in EEPROM. */#if defined(CFG_EXTBDINFO)#if defined(CONFIG_405GP) || defined(CONFIG_405EP)#if defined(CONFIG_I2CFAST) /* * set bi_iic_fast for linux taking environment variable * "i2cfast" into account */ { char *s = getenv ("i2cfast"); if (s && ((*s == 'y') || (*s == 'Y'))) { bd->bi_iic_fast[0] = 1; bd->bi_iic_fast[1] = 1; } else { bd->bi_iic_fast[0] = 0;
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -