日韩性视频-久久久蜜桃-www中文字幕-在线中文字幕av-亚洲欧美一区二区三区四区-撸久久-香蕉视频一区-久久无码精品丰满人妻-国产高潮av-激情福利社-日韩av网址大全-国产精品久久999-日本五十路在线-性欧美在线-久久99精品波多结衣一区-男女午夜免费视频-黑人极品ⅴideos精品欧美棵-人人妻人人澡人人爽精品欧美一区-日韩一区在线看-欧美a级在线免费观看

歡迎訪問 生活随笔!

生活随笔

當前位置: 首頁 > 编程资源 > 编程问答 >内容正文

编程问答

u-boot简单学习笔记(三)——AR9331 uboot启动分析

發(fā)布時間:2023/12/20 编程问答 33 豆豆
生活随笔 收集整理的這篇文章主要介紹了 u-boot简单学习笔记(三)——AR9331 uboot启动分析 小編覺得挺不錯的,現在分享給大家,幫大家做個參考.

1.最開始系統上電后 ENTRY(_start)程序入口點是 _start? 由board/ap121/u-boot.lds引導

2._start: cpu/mips/start.S 是第一個源程序文件,主要完成初始化看門狗、定時器、重定位(拷貝代碼段到內存中)、初始化堆? 棧、? 跳轉到第二階段等工作。

3. la t9, board_init_f 將函數board_init_f地址賦予t9
j t9 跳轉到t9寄存器中保存的地址指向的指令
即跳轉到RAM 中執(zhí)行 C 代碼
這里會打印一些信息。

3.1 board_init_f() lib_mips/board.c
初始化外部內存
relocate_code() 回到cpu/mips/start.S中繼續(xù)執(zhí)行

4.la t9,board_init_r cpu/mips/start.S
j t9 將函數board_init_r地址賦予t9
跳轉到t9寄存器中保存的地址指向的指令
即跳轉到RAM 中執(zhí)行 C 代碼
這里會打印一些信息
4.1 board_init_r() 函數 lib_mips/board.c

4.2 main_loop() common/main.c
s=getenv ("bootcmd") 取得環(huán)境變量中的啟動命令行,如bootcmd=bootm 0xbf020000
run_command (s, 0); //執(zhí)行這個命令行 ,即bootm
4.3 do_bootm() common/cmd_bootm.c
// printf ("## Booting image at %08lx .../n", addr); //比如

5. bootm 啟動內核
5.1 do_bootm_linux() lib_mips/mips_linux.c

函數解析

1.board_init_f()

1.1

  • void board_init_f(ulong bootflag)??
  • {??
  • for (init_fnc_ptr = init_sequence; *init_fnc_ptr; ++init_fnc_ptr)??
  • { if ((*init_fnc_ptr)() != 0)??
  • { hang (); }??
  • }??
  • //調用init_sequence 函數隊列,對板子進行一些初始化,詳細見后面
  • 初始化external memory,初始化堆棧用cache作堆棧,為??
  • relocate_code (addr_sp, id, addr); //回到cpu/mips/start.S 中
  • /* NOTREACHED - relocate_code() does not return */
  • }?
  • 1.2

  • typedef int (init_fnc_t) (void);??
  • init_fnc_t *init_sequence[] =??
  • { clx_board_init, //初始化GPIO,CPU速度,PLL,SDRAM 等
  • timer_init, //時鐘初始化
  • env_init, //環(huán)境變臉初始化
  • incaip_set_cpuclk, //根據環(huán)境變量設置CPU 時鐘
  • init_baudrate, //初始化串口波特率
  • serial_init, /* serial communications setup */
  • console_init_f, //串口初始化,后面才能顯示
  • display_banner, //在屏幕上輸出一些顯示信息
  • checkboard,??
  • init_func_ram,??
  • NULL,??
  • };?
  • 2.board_init_r()
    (1)調用一系列的初始化函數。
    (2)初始化Flash設備。
    (3)初始化系統內存分配函數。
    (4)如果目標系統擁有NAND設備,則初始化NAND設備。
    (5)如果目標系統有顯示設備,則初始化該類設備。
    (6)初始化相關網絡設備,填寫IP、MAC地址等。
    (7)進去命令循環(huán)(即整個boot的工作循環(huán)),接受用戶從串口輸入的命令,然后進行相應的工作

  • void board_init_r (gd_t *id, ulong dest_addr)??
  • {??
  • /* configure available FLASH banks */ //配置可用的flash單元
  • size = flash_init(); //初始化flash
  • display_flash_config (size); //顯示flash 的大小
  • /* initialize malloc() area */
  • mem_malloc_init();??
  • malloc_bin_reloc();??
  • puts ("NAND:");??
  • nand_init(); /* go init the NAND */ //NAND初始化
  • /* relocate environment function pointers etc. */
  • env_relocate(); //初始化環(huán)境變量
  • /* board MAC address */
  • s = getenv ("ethaddr"); //以太網MAC地址
  • for (i = 0; i < 6; ++i) {??
  • bd->bi_enetaddr[i] = s ? simple_strtoul (s, &e, 16) : 0;??
  • if (s)??
  • s = (*e) ? e + 1 : e;??
  • }??
  • /* IP Address */
  • bd->bi_ip_addr = getenv_IPaddr("ipaddr");??
  • pci_init(); //pci初始化配置
  • /** leave this here (after malloc(), environment and PCI are working) **/
  • /* Initialize devices */
  • devices_init ();??
  • jumptable_init ();??
  • /* Initialize the console (after the relocation and devices init) */
  • console_init_r (); //串口初始化
  • /* miscellaneous platform dependent initialisations */
  • misc_init_r ();??
  • puts ("Net: ");??
  • eth_initialize(gd->bd);??
  • /* main_loop() can return to retry autoboot, if so just run it again. */
  • for (;;) {??
  • main_loop (); //循環(huán)執(zhí)行,試圖自動啟動,接受用戶從串口輸入的命令,然后進行相應的工作,設置延時時間,確定目標板是進入下載模式還是啟動加載模式
  • }??
  • /* NOTREACHED - no way out of command loop except booting */
  • }??
  • 3.main_loop()??
  • void main_loop (void)??
  • {??
  • s = getenv ("bootdelay"); //從環(huán)境變量中取得bootdelay 內核等待延時
  • bootdelay = s ? (int)simple_strtol(s, NULL, 10) : CONFIG_BOOTDELAY;??
  • debug ("### main_loop entered: bootdelay=%d/n/n", bootdelay);??
  • s = getenv ("bootcmd"); //從環(huán)境變量中取得bootcmd 啟動命令行
  • 如bootcmd=tftp;bootm 或者 bootcmd=bootm 0xbf020000??
  • char *s1 = getenv ("bootargs"); //從環(huán)境變量中取得bootargs 啟動參數
  • debug ("### main_loop: bootcmd=/"%s/"/n", s ? s : "<UNDEFINED>");??
  • run_command (s, 0); //執(zhí)行啟動命令
  • //手動輸入命令
  • for (;;) {??
  • len = readline (CFG_PROMPT); //讀取鍵入的命令到CFG_PROMPT 中
  • rc = run_command (lastcommand, flag); //執(zhí)行這個命令
  • }??
  • #endif /*CFG_HUSH_PARSER*/
  • }?
  • 4.do_bootm()
    int do_bootm (cmd_tbl_t *cmdtp, int flag, int argc, char *argv[])
    這個函數看著挺長的,其實無非就是將內核解壓縮,然后調用do_bootm_linux引導內核

    5.do_bootm_linux() lib_mips/mips_linux.c
    打印信息Starting kernel ...

  • void do_bootm_linux (cmd_tbl_t * cmdtp, int flag, int argc, char *argv[],??
  • ulong addr, ulong * len_ptr, int verify)??
  • {??
  • char *commandline = getenv ("bootargs");??
  • theKernel =??
  • (void (*)(int, char **, char **, int *)) ntohl (hdr->ih_ep);??
  • //hdr為指向image header的指針,hdr->ih_ep就是我們用mkimage創(chuàng)建image時-e選項的參數:內核的入口地址
  • linux_params_init (UNCACHED_SDRAM (gd->bd->bi_boot_params), commandline);??
  • /* we assume that the kernel is in place */
  • printf ("/nStarting kernel .../n/n");??
  • theKernel (linux_argc, linux_argv, linux_env, 0); //啟動內核
  • }?
  • u-boot向內核傳遞啟動參數由一系列在include/configs/.h中的宏控制,啟動參數傳遞的地址在board_init中初始化

    轉載于:https://www.cnblogs.com/xuyh/p/5092252.html

    總結

    以上是生活随笔為你收集整理的u-boot简单学习笔记(三)——AR9331 uboot启动分析的全部內容,希望文章能夠幫你解決所遇到的問題。

    如果覺得生活随笔網站內容還不錯,歡迎將生活随笔推薦給好友。