u boot的啟動流程分析(一)

2021-08-25 02:49:29 字數 4821 閱讀 4060

這週翻了翻u-boot-xilinx的原始碼,結合著網上看的對cortexa8、a9的u-boot的原始碼分析,再結合自己在xilinx上下的u-boot原始碼,試著對u-boot的啟動流程進行一下分析,也給自己理一下思路。

u-boot原始碼的目錄結構:

第一階段:

(1)start.s(arch/arm/cpu/armv7/start.s)

在flash中執行的引導**,也就是bootloader中的stage1,負責初始化硬體環境,把u-boot從flash載入到ram中去,對cpu的乙個初始化,然後跳到board/xilinx/zynq/board.c中去執行。

第二階段:

(2)board.c(board/xilinx/zynq/board.c)

選擇板卡晶元的型號,啟動fpga,選擇啟動方式(qspi、sd、jtag、nand、nor)、讀取rom、ram。

(3)cmd/bootm.c和bootmenu.c

(4)然後在include/config/zynq_common.h中定義了z7系列的一些硬體引數配置,比較重要的乙個預設啟動環境配置:

/* default environment */

#ifndef config_extra_env_settings

#define config_extra_env_settings \

"ethaddr=00:0a:35:00:01:22\0" \

"kernel_image=uimage\0" \

"kernel_load_address=0x2080000\0" \

"ramdisk_image=uramdisk.image.gz\0" \

"ramdisk_load_address=0x4000000\0" \

"devicetree_image=devicetree.dtb\0" \

"devicetree_load_address=0x2000000\0" \

"bitstream_image=system.bit.bin\0" \

"boot_image=boot.bin\0" \

"loadbit_addr=0x100000\0" \

"loadbootenv_addr=0x2000000\0" \

"kernel_size=0x500000\0" \

"devicetree_size=0x20000\0" \

"ramdisk_size=0x5e0000\0" \

"boot_size=0xf00000\0" \

"fdt_high=0x20000000\0" \

"initrd_high=0x20000000\0" \

"bootenv=uenv.txt\0" \

"loadbootenv=load mmc 0 $ $\0" \

"importbootenv=echo importing environment from sd ...; " \

"env import -t $ $filesize\0" \

"sd_uenvtxt_existence_test=test -e mmc 0 /uenv.txt\0" \

"preboot=if test $modeboot = sdboot && env run sd_uenvtxt_existence_test; " \

"then if env run loadbootenv; " \

"then env run importbootenv; " \

"fi; " \

"fi; \0" \

"mmc_loadbit=echo loading bitstream from sd/mmc/emmc to ram.. && " \

"mmcinfo && " \

"load mmc 0 $ $ && " \

"fpga load 0 $ $\0" \

"norboot=echo copying linux from nor flash to ram... && " \

"cp.b 0xe2100000 $ $ && " \

"cp.b 0xe2600000 $ $ && " \

"echo copying ramdisk... && " \

"cp.b 0xe2620000 $ $ && " \

"bootm $ $ $\0" \

"qspiboot=echo copying linux from qspi flash to ram... && " \

"sf probe 0 0 0 && " \

"sf read $ 0x100000 $ && " \

"sf read $ 0x600000 $ && " \

"echo copying ramdisk... && " \

"sf read $ 0x620000 $ && " \

"bootm $ $ $\0" \

"uenvboot=" \

"if run loadbootenv; then " \

"echo loaded environment from $; " \

"run importbootenv; " \

"fi; " \

"if test -n $uenvcmd; then " \

"echo running uenvcmd ...; " \

"run uenvcmd; " \

"fi\0" \

"sdboot=if mmcinfo; then " \

"run uenvboot; " \

"echo copying linux from sd to ram... && " \

"load mmc 0 $ $ && " \

"load mmc 0 $ $ && " \

"load mmc 0 $ $ && " \

"bootm $ $ $; " \

"fi\0" \

"usbboot=if usb start; then " \

"run uenvboot; " \

"echo copying linux from usb to ram... && " \

"load usb 0 $ $ && " \

"load usb 0 $ $ && " \

"load usb 0 $ $ && " \

"bootm $ $ $; " \

"fi\0" \

"nandboot=echo copying linux from nand flash to ram... && " \

"nand read $ 0x100000 $ && " \

"nand read $ 0x600000 $ && " \

"echo copying ramdisk... && " \

"nand read $ 0x620000 $ && " \

"bootm $ $ $\0" \

"jtagboot=echo tftping linux to ram... && " \

"tftpboot $ $ && " \

"tftpboot $ $ && " \

"tftpboot $ $ && " \

"bootm $ $ $\0" \

"rsa_norboot=echo copying image from nor flash to ram... && " \

"cp.b 0xe2100000 0x100000 $ && " \

"zynqrsa 0x100000 && " \

"bootm $ $ $\0" \

"rsa_nandboot=echo copying image from nand flash to ram... && " \

"nand read 0x100000 0x0 $ && " \

"zynqrsa 0x100000 && " \

"bootm $ $ $\0" \

"rsa_qspiboot=echo copying image from qspi flash to ram... && " \

"sf probe 0 0 0 && " \

"sf read 0x100000 0x0 $ && " \

"zynqrsa 0x100000 && " \

"bootm $ $ $\0" \

"rsa_sdboot=echo copying image from sd to ram... && " \

"load mmc 0 0x100000 $ && " \

"zynqrsa 0x100000 && " \

"bootm $ $ $\0" \

"rsa_jtagboot=echo tftping image to ram... && " \

"tftpboot 0x100000 $ && " \

"zynqrsa 0x100000 && " \

"bootm $ $ $\0" \

dfu_alt_info \

bootenv

#endif

(5)u-boot引導kernel關鍵地方:

u-boot 給kernel 傳引數和kernel 讀取引數,.u-boot 給kernel 傳ram 引數bootm.c 檔案中, bootm 命令對應的 do_bootm 函式,當分析 uimage 中資訊發現 os 是 linux 時 , 呼叫 ./arch/arc/include/lib/bootm.c 檔案中的 do_bootm_linux 函式來啟動 linux kernel 。

(一)u boot啟動流程分析

u boot是標準的開放原始碼,主要的作用是系統引導。uboot支援多種嵌入式作業系統核心,如linux netbsd,vxworks,qnx,rtems,artos,lynxos,android 支援多個處理器系列,如powerpc arm x86 mips 根據具體的專案情況,我們需要修改 ub...

Uboot啟動流程分析

uboot是嵌入式系統中最常用的bootloader,這裡我們以s3c2410為例分析一下uboot的啟動流程。首先通過uboot的鏈結檔案,我們可以看到uboot執行是執行的第一段 在start.s中。entry start sections align 4 rodata align 4 data...

u boot啟動流程(一)

arch arm cpu armv7 start.s 這裡要看你用的是什麼樣的cpu,我用的contex a5,所以在armv7目錄下 set stackpointer in internal ram to call board init f call board init f ldr sp,con...