/lib_arm/ board.c 主要完成了一些初始化的操作,最重要的是有start_armboot函數 _armboot_start地址為多少?? /* * * U-Boot code: 00F00000 -> 00F3C774 BSS: -> 00FC3274 * IRQ Stack: 00ebff7c * FIQ Stack: 00ebef7c */ #include <common.h> #include <command.h> #include <malloc.h> #include <devices.h> #include <version.h> #include <net.h> #ifdef CONFIG_DRIVER_SMC91111 #include " ../drivers/smc91111.h " #endif #ifdef CONFIG_DRIVER_LAN91C96 應該是關于網卡的定義 #include " ../drivers/lan91c96.h " #endif DECLARE_GLOBAL_DATA_PTR // 聲明全局數據指針 #if (CONFIG_COMMANDS & CFG_CMD_NAND) void nand_init ( void ); 聲明這個方法 #endif ulong monitor_flash_len; #ifdef CONFIG_HAS_DATAFLASH extern int AT91F_DataflashInit( void ); extern void dataflash_print_info( void ); #endif #ifndef CONFIG_IDENT_STRING 如果沒有定義,CONFIG_IDENT_STRING就定義為空 #define CONFIG_IDENT_STRING "" #endif const char version_string[] = 版本字符串 U_BOOT_VERSION " ( " __DATE__ " - " __TIME__ " ) " CONFIG_IDENT_STRING; #ifdef CONFIG_DRIVER_CS8900 如果是CS8900網卡,則聲明下面的函數。好像是獲取網址的意思 extern void cs8900_get_enetaddr (uchar * addr); #endif #ifdef CONFIG_DRIVER_RTL8019 extern void rtl8019_get_enetaddr (uchar * addr); #endif /* * Begin and End of memory area for malloc(), and current "brk" malloc用于用戶程序進行分配內存 */ static ulong mem_malloc_start = 0 ; static ulong mem_malloc_end = 0 ; static ulong mem_malloc_brk = 0 ; static void mem_malloc_init ( ulong dest_addr) 內存分配初始函數。 { mem_malloc_start = dest_addr; mem_malloc_end = dest_addr + CFG_MALLOC_LEN; mem_malloc_brk = mem_malloc_start; memset (( void *) mem_malloc_start, 0 , mem_malloc_end - mem_malloc_start); 真正實現內存分配的函數。分配了一個CFG_MALLOC_LEN大小的內存空間 } void * sbrk (ptrdiff_t increment) 所分配內存區的brk指針調整。 { ulong old = mem_malloc_brk; ulong new = old + increment; if (( new < mem_malloc_start) || ( new > mem_malloc_end)) { return (NULL); } mem_malloc_brk = new ; return (( void * ) old); } /* *********************************************************************** * Init Utilities * ************************************************************************ * Some of this code should be moved into the core functions, * or dropped completely, * but let's get it working (again) first... */ 下面就是一系列的初始化操作。 static int init_baudrate ( void ) 初始化波特率 { char tmp[ 64 ]; /* long enough for environment variables */ int i = getenv_r ( " baudrate " , tmp, sizeof (tmp)); gd ->bd->bi_baudrate = gd->baudrate = (i > 0 ) ? ( int ) simple_strtoul (tmp, NULL, 10 ) : CONFIG_BAUDRATE; return ( 0 ); } static int display_banner ( void ) 一些顯示函數。顯示IRQ_STACK_START等的地址 _armboot_start, _bss_start, _bss_end 這些值 { printf ( " \n\n%s\n\n " , version_string); debug ( " U-Boot code: %08lX -> %08lX BSS: -> %08lX\n " , _armboot_start, _bss_start, _bss_end); #ifdef CONFIG_MODEM_SUPPORT debug ( " Modem Support enabled\n " ); #endif #ifdef CONFIG_USE_IRQ debug ( " IRQ Stack: %08lx\n " , IRQ_STACK_START); debug ( " FIQ Stack: %08lx\n " , FIQ_STACK_START); #endif return ( 0 ); } /* * WARNING: this code looks "cleaner" than the PowerPC version, but * has the disadvantage that you either get nothing, or everything. * On PowerPC, you might see "DRAM: " before the system hangs - which * gives a simple yet clear indication which part of the * initialization if failing. */ static int display_dram_config ( void ) 顯示內存的配置,打印出DRAM的大小 { int i; #ifdef DEBUG puts ( " RAM Configuration:\n " ); for (i= 0 ; i<CONFIG_NR_DRAM_BANKS; i++ ) { printf ( " Bank #%d: %08lx " , i, gd->bd-> bi_dram[i].start); print_size (gd ->bd->bi_dram[i].size, " \n " ); } #else ulong size = 0 ; for (i= 0 ; i<CONFIG_NR_DRAM_BANKS; i++ ) { size += gd->bd-> bi_dram[i].size; } puts( " DRAM: " ); print_size(size, " \n " ); #endif return ( 0 ); } #ifndef CFG_NO_FLASH static void display_flash_config ( ulong size) { puts ( " Flash: " ); print_size (size, " \n " ); } #endif /* CFG_NO_FLASH */ /* 初始化一個串行口作為控制臺,同時進行一些硬件測試 * Breathe some life into the board... * * Initialize a serial port as console, and carry out some hardware * tests. * * The first part of initialization is running from Flash memory; * its main purpose is to initialize the RAM so that we * can relocate the monitor code to RAM. */ 不存在一個common 即通用的初始化序列來為所有的開發板及結構進行初始化。因為不同的體系結構差別還是比較大的。 /* * All attempts to come up with a "common" initialization sequence * that works for all boards and architectures failed: some of the * requirements are just _too_ different. To get rid of the resulting * mess of board dependent #ifdef'ed code we now make the whole * initialization sequence configurable to the user. * * The requirements for any new initalization function is simple: it * receives a pointer to the "global data" structure as it's only * 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 ); int print_cpuinfo ( void ); /* test-only */ init_fnc_t *init_sequence[] = {定義一個初始化的整型指針數組 cpu_init, /* basic cpu dependent setup */ /cpu/arm920t/ cpu.c 這個函數在cpu.c函數中定義了 board_init, /* basic board dependent setup */ /board/smdk2410/ smdk2410.c interrupt_init, /* set up exceptions */ env_init, /* initialize environment */ tools/env/ FW_env.c init_baudrate, /* initialze baudrate settings */ serial_init, /* serial communications setup */ console_init_f, /* stage 1 init of console */ display_banner, /* say that we are here */ #if defined(CONFIG_DISPLAY_CPUINFO) 顯示cpu的信息 print_cpuinfo, /* display cpu info (and speed) */ #endif #if defined(CONFIG_DISPLAY_BOARDINFO) 顯示板的信息 checkboard, /* display board info */ #endif dram_init, /* configure available RAM banks */ display_dram_config, NULL, }; void start_armboot ( void ) { init_fnc_t ** init_fnc_ptr;定義一個雙重整型指針。 char * s; #ifndef CFG_NO_FLASH ulong size; #endif #if defined(CONFIG_VFD) || defined(CONFIG_LCD) unsigned long addr; #endif /* Pointer is writable since we allocated a register for it */ gd = (gd_t*)(_armboot_start - CFG_MALLOC_LEN - sizeof (gd_t)); _armboot_start為0x33f80000,CFG_MALLOC_LEN是堆大小加環境數據區大小,在smdk2410.h中有定義 #define CFG_MALLOC_LEN (CFG_ENV_SIZE + 128*1024) CFG_ENV_SIZE為64K,所以共192K /* compiler optimization barrier needed for GCC >= 3.4 */ __asm__ __volatile__( "" : : : " memory " ); memset (( void *)gd, 0 , sizeof (gd_t));獲得一個gd指針,給全局數據變量gd分配內存 gd ->bd = (bd_t*)(( char *)gd - sizeof (bd_t)); memset (gd ->bd, 0 , sizeof (bd_t));給板子數據變量分配內存空間 monitor_flash_len = _bss_start - _armboot_start;取整個代碼區Uboot的長度 順序執行init_sequence數組中的初始化函數 for (init_fnc_ptr = init_sequence; *init_fnc_ptr; ++ init_fnc_ptr) { if ((*init_fnc_ptr)() != 0 ) { hang (); } } #ifndef CFG_NO_FLASH /* configure available FLASH banks */ 從其實現上來看,好像只是配置nor flash size = flash_init (); display_flash_config (size);顯示flash的信息 #endif /* CFG_NO_FLASH */ #ifdef CONFIG_VFD 定義顯示類型 # ifndef PAGE_SIZE # define PAGE_SIZE 4096 # endif /* * reserve memory for VFD display (always full pages) */ /* bss_end is defined in the board-specific linker script */ addr = (_bss_end + (PAGE_SIZE - 1 )) & ~(PAGE_SIZE - 1 );按頁對齊的方式保留顯存 size = vfd_setmem (addr); gd ->fb_base = addr; #endif /* CONFIG_VFD */ #ifdef CONFIG_LCD # ifndef PAGE_SIZE # define PAGE_SIZE 4096 # endif /* * reserve memory for LCD display (always full pages) */ /* bss_end is defined in the board-specific linker script */ addr = (_bss_end + (PAGE_SIZE - 1 )) & ~(PAGE_SIZE - 1 );同上 size = lcd_setmem (addr); gd ->fb_base = addr; #endif /* CONFIG_LCD */ /* armboot_start is defined in the board-specific linker script */ 初始化CFG_MALLOC_LEN大小空間 mem_malloc_init (_armboot_start - CFG_MALLOC_LEN); #if (CONFIG_COMMANDS & CFG_CMD_NAND) 初始化nandflash,這是在nandflash啟動的s3c2410移植Uboot的關鍵,根據flash時序編寫函數即可。首先要在include /configs/ smdk2410.h中打開CFG_CMD_NAND命令 puts ( " NAND: " ); nand_init(); /* go init the NAND */ ,這個函數在前面被聲明過,現在就可以直接使用了/board/smdk2410/ smdk2410.c中沒有定義這個函數,需要添加 #endif #ifdef CONFIG_HAS_DATAFLASH AT91F_DataflashInit(); dataflash_print_info(); #endif /* initialize environment */ env_relocate ();初始化環境參數 #ifdef CONFIG_VFD /* must do this after the framebuffer is allocated */ drv_vfd_init();framebuffer初始化 #endif /* CONFIG_VFD */ /* IP Address */ gd ->bd->bi_ip_addr = getenv_IPaddr ( " ipaddr " ); /* MAC Address */ { int i; ulong reg; char *s, * e; char tmp[ 64 ]; i = getenv_r ( " ethaddr " , tmp, sizeof (tmp)); s = (i > 0 ) ? tmp : NULL; for (reg = 0 ; reg < 6 ; ++ reg) { gd ->bd->bi_enetaddr[reg] = s ? simple_strtoul (s, &e, 16 ) : 0 ; if (s) s = (*e) ? e + 1 : e; }獲取網卡地址 #ifdef CONFIG_HAS_ETH1 i = getenv_r ( " eth1addr " , tmp, sizeof (tmp)); s = (i > 0 ) ? tmp : NULL; for (reg = 0 ; reg < 6 ; ++ reg) { gd ->bd->bi_enet1addr[reg] = s ? simple_strtoul (s, &e, 16 ) : 0 ; if (s) s = (*e) ? e + 1 : e; } #endif } devices_init (); /* get the devices list going. */ 調用相應驅動函數對硬件設備進行初始化 #ifdef CONFIG_CMC_PU2 load_sernum_ethaddr (); #endif /* CONFIG_CMC_PU2 */ jumptable_init (); console_init_r (); /* fully init console as a device */ #if defined(CONFIG_MISC_INIT_R) /* miscellaneous platform dependent initialisations */ misc_init_r (); #endif /* enable exceptions */ enable_interrupts ();開中斷 /* Perform network card initialisation if necessary */ #ifdef CONFIG_DRIVER_CS8900 cs8900_get_enetaddr (gd ->bd-> bi_enetaddr); #endif #if defined(CONFIG_DRIVER_SMC91111) || defined (CONFIG_DRIVER_LAN91C96) if (getenv ( " ethaddr " )) { smc_set_mac_addr(gd ->bd-> bi_enetaddr); } #endif /* CONFIG_DRIVER_SMC91111 || CONFIG_DRIVER_LAN91C96 */ /* Initialize from environment */ if ((s = getenv ( " loadaddr " )) != NULL) { load_addr = simple_strtoul (s, NULL, 16 ); } #if (CONFIG_COMMANDS & CFG_CMD_NET) if ((s = getenv ( " bootfile " )) != NULL) { copy_filename (BootFile, s, sizeof (BootFile)); } #endif /* CFG_CMD_NET */ #ifdef BOARD_LATE_INIT board_late_init (); #endif #if (CONFIG_COMMANDS & CFG_CMD_NET) #if defined(CONFIG_NET_MULTI) puts ( " Net: " ); #endif eth_initialize(gd -> bd); #endif /* main_loop() can return to retry autoboot, if so just run it again. */ for (;;) { main_loop (); } /* NOTREACHED - no way out of command loop except booting */ } void hang ( void ) { puts ( " ### ERROR ### Please RESET the board ###\n " ); for (;;); } ....... 后面是modem的配置 不用管
?
更多文章、技術交流、商務合作、聯系博主
微信掃碼或搜索:z360901061

微信掃一掃加我為好友
QQ號聯系: 360901061
您的支持是博主寫作最大的動力,如果您喜歡我的文章,感覺我的文章對您有幫助,請用微信掃描下面二維碼支持博主2元、5元、10元、20元等您想捐的金額吧,狠狠點擊下面給點支持吧,站長非常感激您!手機微信長按不能支付解決辦法:請將微信支付二維碼保存到相冊,切換到微信,然后點擊微信右上角掃一掃功能,選擇支付二維碼完成支付。
【本文對您有幫助就好】元
