【linux啟動】嵌入式Linux系統啟動過程分析
阿新 • • 發佈:2021-11-21
一、概述
嵌入式linux系統啟動過程一般包含以下幾個過程:
- 上電
- 執行IROM(晶片內部只讀儲存器)中固化的程式碼。
- 執行uboot
- 載入核心到記憶體,啟動核心。
- 掛載根檔案系統rootfs
- 執行其中的指令碼和應用程式。
二、核心的幾個組成部分介紹
1、uboot介紹
(1)概述
- 是一個通用的bootloader
- Boot:完成硬體的初始化
-
Loader:載入作業系統核心,並啟動核心.
- uboot支援多種處理器架構:ARM、PowerPC 、X86 、 Mips等等。
- 支援載入啟動多種作業系統:linux、wince、VXworks等
- uboot的原始碼下載地址:
(2)作用
- CPU的初始化(晶片級)主要採用ARM組合語言,包含初始化快取、MMC、Watchdog、終端、clock等。
- 板級初始化(採用C語言編寫):主要初始化串列埠、網絡卡、USB、LCD等裝置.
-
為作業系統的啟動準備引數,載入作業系統映象到記憶體,並啟動.
(3)u-boot的開機列印資訊分析
U-Boot 2014.07 (Apr 10 2021 - 02:16:01)---U-boot版本號 //時鐘系統中各個總線上的時鐘頻率 PLL : [0] = 800000000, [1] = 800000000, [2] = 780000000, [3] = 800000000 (0) PLL1: CPU FCLK = 800000000, HCLK = 200000000 (G0) (7) PLL1: CPU FCLK = 800000000, HCLK = 200000000 (G1) (2) PLL3: MEM FCLK = 800000000, DCLK = 800000000, BCLK = 400000000, PCLK = 200000000 (1) PLL0: BUS BCLK = 400000000, PCLK = 200000000 (8) PLL0: CCI4 BCLK = 400000000, PCLK = 200000000 (3) PLL0: G3D BCLK = 400000000 (4) PLL0: CODA BCLK = 400000000, PCLK = 200000000 (5) PLL0: DISP BCLK = 400000000, PCLK = 200000000 (6) PLL0: HDMI PCLK = 133333333 I2C: ready DRAM: 1 GiB------------記憶體1GBHeap = 0x44000000~0x46000000 Code = 0x43c00000~0x43c83e48 GLD = 0x43bffeb8 GLBD = 0x43bffe68 SP = 0x43bffe68,0x43bffe48(CURR) PC = 0x43c06640 TAGS = 0x40000100 PAGE = 0x43c90000~0x43c9c000 MACH = [4330] VER = 0 BOARD= [GEC6818] MMC: NXP DWMMC: 0, NXP DWMMC: 1, NXP DWMMC: 2 In: serial Out: serial Err: serial ## DCDC_MODE(0x80): DCDC1[PFM], DCDC2[PFM], DCDC3[PFM], DCDC4[PWM], DCDC5[PWM] ## STATUS(0x00) : 0xe4 0x10 ## IRQ(0x48) : 0x00 0x00 0x00 0x00 0x00 ## CHG_TYPE : ADP ## BAT_VOL : 0mV ## BAT_CAP : 100% DONE: Logo bmp 300 by 300 (3bpp), len=270056 DRAW: 0x47000000 -> 0x46000000 DONE: Logo bmp 300 by 300 (3bpp), len=270056 DRAW: 0x47000000 -> 0x46000000 RGB: display.0 MIPI: display.0 DSIM_ESCMODE 1 : 0xc0 DSIM_STATUS : 0x10010f MIPI clk: 420MHz DSIM_ESCMODE 2 : 0x0 DSIM_STATUS : 0x10010f ## Skip BAT Animation. ## IRQ(0x48) : 0x00 0x00 0x00 0x00 0x00 ## chg_type : ADP ## battery_vol : 0mV ## battery_cap : 100% ## Booting Card did not respond to voltage select! Net: GEC6818 mac init... dwmac.c0060000 Hit any key to stop autoboot: 0---倒計時結束載入啟動核心,倒計時結束前按下鍵盤上的任意按鍵,進入U-BOOT命令列
(4)uboot的命令
=> help //在uboot下執行help看uboot下的幫助文件 ? - alias for 'help' base - print or set address offset bdinfo - print Board Info structure blkcache - block cache diagnostics and control boot - boot default, i.e., run 'bootcmd' bootd - boot default, i.e., run 'bootcmd' bootefi - Boots an EFI payload from memory bootelf - Boot from an ELF image in memory bootm - boot application image from memory bootp - boot image via network using BOOTP/TFTP protocol bootvx - Boot vxWorks from an ELF image bootz - boot Linux zImage image from memory cmp - memory compare coninfo - print console devices and information cp - memory copy crc32 - checksum calculation dhcp - boot image via network using DHCP/TFTP protocol dm - Driver model low level access echo - echo args to console editenv - edit environment variable env - environment handling commands erase - erase FLASH memory exit - exit script ext2load - load binary file from a Ext2 filesystem ext2ls - list files in a directory (default /) ext4load - load binary file from a Ext4 filesystem ext4ls - list files in a directory (default /) ext4size - determine a file's size false - do nothing, unsuccessfully fatinfo - print information about filesystem fatload - load binary file from a dos filesystem fatls - list files in a directory (default /) fatmkdir - create a directory fatrm - delete a file fatsize - determine a file's size fatwrite - write file into a dos filesystem fdt - flattened device tree utility commands flinfo - print FLASH memory information fstype - Look up a filesystem type go - start application at address 'addr' gpio - query and control gpio pins gpt - GUID Partition Table help - print command description/usage iminfo - print header information for application image imxtract - extract a part of a multi-image itest - return true/false on integer compare ln - Create a symbolic link load - load binary file from a filesystem loadb - load binary file over serial line (kermit mode) loads - load S-Record file over serial line loadx - load binary file over serial line (xmodem mode) loady - load binary file over serial line (ymodem mode) loop - infinite loop on address range ls - list files in a directory (default /) md - memory display mdio - MDIO utility commands mii - MII utility commands mm - memory modify (auto-incrementing address) mmc - MMC sub system mmcinfo - display MMC info mtd - MTD utils mw - memory write (fill) nfs - boot image via network using NFS protocol nm - memory modify (constant address) part - disk partition related commands ping - send ICMP ECHO_REQUEST to network host printenv - print environment variables protect - enable or disable FLASH write protection pxe - commands to get and boot from pxe files random - fill memory with random pattern reset - Perform RESET of the CPU run - run commands in an environment variable save - save file to a filesystem saveenv - save environment variables to persistent storage setenv - set environment variables setexpr - set environment variable as the result of eval expression sf - SPI flash sub-system showvar - print local hushshell variables size - determine a file's size sleep - delay execution for some time source - run script from memory sysboot - command to get and boot from syslinux files test - minimal test like /bin/sh tftpboot - boot image via network using TFTP protocol true - do nothing, successfully usb - USB sub-system usbboot - boot from USB device version - print monitor, compiler and linker version
- bdinfo:打印出開發板的資訊
GEC6818# bdinfo arch_number = 0x000010EA-------開發板的編號,要與核心原始碼中開發板編號一致 boot_params = 0x40000100-------啟動核心所需引數在記憶體的0x40000100處 DRAM bank = 0x00000000 -> start = 0x40000000-----------記憶體的起始地址,結束地址0x7fffffff -> size = 0x40000000-----------記憶體的大小 1GB eth0name = dwmac.c0060000---網絡卡的名字 ethaddr = 00:e2:1c:ba:e8:60 --網絡卡的MAC地址 current eth = dwmac.c0060000 ip_addr = 192.168.51.5----------U-BOOT設定的網絡卡IP baudrate = 115200 bps-----------串列埠的波特率 TLB addr = 0x7FFF0000 relocaddr = 0x46000000 reloc off = 0x00000000 irq_sp = 0x7DF6BF00 sp start = 0x43BFFE6
- 啟動核心的命令
boot - boot default, i.e., run 'bootcmd' bootd - boot default, i.e., run 'bootcmd' bootm - boot application image from memory bootp - boot image via network using BOOTP/TFTP protocol
- printenv:列印環境變數
GEC6818# printenv baudrate=115200 bootargs=lcd=at070tn92 tp=gslx680-linux root=/dev/mmcblk0p2 rw rootfstype=ext4 bootcmd=ext4load mmc 2:1 0x48000000 uImage;bootm 0x48000000
兩個重要的環境變數:
bootargs啟動引數:告訴核心一些重要啟動資訊 lcd=at070tn92-------------LCD屏驅動晶片的型號 tp=gslx680-linux-----------觸控式螢幕的型號 root=/dev/mmcblk0p2----根檔案系統在emmc的第2個分割槽 rw rootfstype=ext4--------根檔案系統可讀可寫,型別是ext4 bootcmd--------------------啟動命令環境變數,告訴U-boot一些資訊 bootcmd=ext4load mmc 2:1 0x48000000 uImage;bootm 0x48000000 以ext4格式把核心映象uImage從emmc的第1分割槽載入到記憶體的0x48000000處,然後去到記憶體0x48000000處,啟動核心 bootdelay=3---------------倒計時3S bootfile=uImage ethact=dwmac.c0060000 ethaddr=00:e2:1c:ba:e8:60 ethprime=RTL8211------網絡卡晶片的型號 gatewayip=192.168.51.1-----------------預設閘道器 ipaddr=192.168.51.5---------------------開發板IP netmask=255.255.255.0----------------子網掩碼 qtcrc=-1489582083 serverip=192.168.51.2-------------------伺服器IP stderr=serial stdin=serial stdout=serial