PetaLinux啓動過程解析

1、BootROM部分

在器件上電運行後,處理器自動開始Stage-0 Boot,也就是執行片內BootROM中的代碼

BootROM會初始化CPU和一些外設,以便讀取下一個啓動階段所需的程序代碼,FSBL(First

2、BOOT.bin部分

BootROM會去讀取MIO[2..8],從而確定啓動設備方式(Zynq支持多種啓動設備方式,可以使用跳線帽設置),將選定設備的頭192Kbyte內容,也就是FSBL,複製到OCM(On Chip Memory)中,並將控制器交給FSBL。

FSBL部分

FSBL啓動時可以使用整塊256Kb的OCM,當FSBL開始運行後,器件就正式由開發者或用戶控制了。Xilinx提供了一份FSBL代碼,如果沒什麼特殊要求,可以直接使用。

嵌入式系統系統啓動一般都是在 nor flash (NOR flash 可以直接運行程序,NAND flash需要將程序加載到內存運行,和 BIOS 很類似,nor flash 成本很高)。

BIOS是(Basic Input Output System)"基本輸入輸出系統"

它是一組固化到計算機內主板上一個ROM芯片上的程序,它保存着計算機最重要的基本輸入輸出的程序、開機後自檢程序和系統自啓動程序,它可從CMOS中讀寫系統設置的具體信息。 其主要功能是爲計算機提供最底層的、最直接的硬件設置和控制。

RAM(random access memory)即隨機存儲內存,這種存儲器在斷電時將丟失其存儲內容,故主要用於存儲短時間使用的程序。ROM(Read-Only Memory)即只讀內存,是一種只能讀出事先所存數據的固態半導體存儲器。

uboot 就是針對嵌入式環境特別編譯準備的一級引導程序。用來初始化環境,並且讀取啓動 Linux 內核的東西。

因爲在u-boot中配置從eMMC啓動,所以在u-boot之前會先初始化一些外設,配置PL端資源,如eMMC,下面爲初始化eMMC的打印信息。

Device: sdhci@e0100000

Manufacturer ID: fe

OEM: 14e

Name: MMC02

Tran Speed: 52000000

Rd Block Len: 512

MMC version 4.4.1

High Capacity: No

Capacity: 1.8 GiB

Bus Width: 4-bit

Erase Group Size: 512 KiB

HC WP Group Size: 0 Bytes

User Capacity: 1.8 GiB

Boot Capacity: 1 MiB ENH

RPMB Capacity: 128 KiB ENH

u-boot.elf從發eMMC加載image.ub到片上內存DDR3(2G)中

readingimage.ub

11274340 bytes read in 611 ms (17.6 MiB/s)

首先是加載Linux kernel,狀態爲尚未解壓,大小3.8MiB,使用了SHA1安全哈希算法(Secure Hash Algorithm)

## Loading kernel from FIT Image at10000000 ...

  Using 'conf@1' configuration

  Verifying Hash Integrity ... OK

  Trying 'kernel@0' kernel subimage

    Description:  Linux Kernel

    Type:         Kernel Image

    Compression:  uncompressed

    Data Start:   0x100000d4

    Data Size:    4005144 Bytes = 3.8MiB

    Architecture: ARM

    OS:           Linux

    Load Address: 0x00008000

    Entry Point:  0x00008000

    Hash algo:    sha1

    Hash value:  3b953474750d8fb67e6a25dece81e156c4ecdcb2

  Verifying Hash Integrity ... sha1+ OK

接着是加載ramdisk,狀態爲尚未解壓,大小6.9MiB,使用了SHA1安全哈希算法(Secure Hash Algorithm)

## Loading ramdisk from FIT Image at10000000 ...

  Using 'conf@1' configuration

  Trying 'ramdisk@0' ramdisk subimage

    Description:  ramdisk

    Type:         RAMDisk Image

    Compression:  uncompressed

    Data Start:   0x103d686c

    Data Size:    7248902 Bytes = 6.9MiB

    Architecture: ARM

    OS:           Linux

    Load Address: unavailable

    Entry Point:  unavailable

    Hash algo:    sha1

    Hash value:  e934ce35c9f408811fcb859dff09b0aed896871b

  Verifying Hash Integrity ... sha1+ OK

最後是加載fdt(設備樹文件),狀態爲尚未解壓,大小18.2KiB,使用了SHA1安全哈希算法(Secure Hash Algorithm)

## Loading fdt from FIT Image at 10000000...

  Using 'conf@1' configuration

  Trying 'fdt@0' fdt subimage

    Description:  Flattened DeviceTree blob

    Type:         Flat Device Tree

    Compression:  uncompressed

    Data Start:   0x103d1ee0

    Data Size:    18649 Bytes = 18.2KiB

    Architecture: ARM

    Hash algo:    sha1

    Hash value:  97ab0c048f0da9de6329b48e1345c2aedc552995

  Verifying Hash Integrity ... sha1+ OK

   Booting using the fdt blob at 0x103d1ee0

   Loading Kernel Image ... OK

   Loading Ramdisk to 07916000, end 07fffc06... OK

   Loading Device Tree to 0790e000, end079158d8 ... OK

引導加載完成,準備運行

解壓Linux內核鏡像並啓動Linux內核,運行在CPU0上

Starting kernel ...

Uncompressing Linux...done, booting the kernel.

Booting Linux on physical CPU0x0

Linux version 4.6.0-xilinx(bjut@virtua-ubuntu1604) (gcc version 5.2.1 20151005 (Linaro GCC 5.2-2015.11-2)) #1 SMP PREEMPT Mon Apr 24 15:03:20 CST 2017

CPU: ARMv7 Processor[413fc090] revision 0 (ARMv7), cr=18c5387d

CPU: PIPT / VIPTnonaliasing data cache, VIPT aliasing instruction cache

Machine model:huanbao_qspi_emmc

bootconsole [earlycon0]enabled

cma: Reserved 16 MiB at0x3f000000

Memory policy: Data cachewritealloc

percpu: Embedded 12pages/cpu @ef7d0000 s19776 r8192 d21184 u49152

Built 1 zonelists in Zoneorder, mobility grouping on.  Totalpages: 260608

Kernel command line:console=ttyPS0,115200 earlyprintk

 

開始解壓文件系統鏡像

Trying to unpack rootfsimage as initramfs...

Freeing initrd memory:7080K (c7916000 - c8000000)

hw perfevents: enabledwith armv7_cortex_a9 PMU driver, 7 counters available

futex hash table entries:512 (order: 3, 32768 bytes)

workingset:timestamp_bits=28 max_order=18 bucket_order=0

jffs2: version 2.2. (NAND)(SUMMARY)  漏2001-2006 Red Hat, Inc.

bounce: pool size: 64pages

io scheduler noopregistered

io scheduler deadlineregistered

io scheduler cfqregistered (default)

dma-pl330 f8003000.dmac:Loaded driver for PL330 DMAC-241330

dma-pl330 f8003000.dmac:    DBUFF-128x8bytes Num_Chans-8 Num_Peri-4Num_Events-16

42c00000.serial: ttyUL1 atMMIO 0x42c00000 (irq = 167, base_baud = 0) is a uartlite

42c10000.serial: ttyUL2 atMMIO 0x42c10000 (irq = 168, base_baud = 0) is a uartlite

42ca0000.serial: ttyUL3 atMMIO 0x42ca0000 (irq = 169, base_baud = 0) is a uartlite

42cb0000.serial: ttyUL4 atMMIO 0x42cb0000 (irq = 170, base_baud = 0) is a uartlite

42c20000.serial: ttyUL5 atMMIO 0x42c20000 (irq = 171, base_baud = 0) is a uartlite

42c30000.serial: ttyUL6 atMMIO 0x42c30000 (irq = 172, base_baud = 0) is a uartlite

42c40000.serial: ttyUL7 atMMIO 0x42c40000 (irq = 173, base_baud = 0) is a uartlite

42c50000.serial: ttyUL8 atMMIO 0x42c50000 (irq = 174, base_baud = 0) is a uartlite

42c60000.serial: ttyUL9 atMMIO 0x42c60000 (irq = 175, base_baud = 0) is a uartlite

42c70000.serial: ttyUL10at MMIO 0x42c70000 (irq = 176, base_baud = 0) is a uartlite

42c80000.serial: ttyUL11at MMIO 0x42c80000 (irq = 177, base_baud = 0) is a uartlite

42c90000.serial: ttyUL12at MMIO 0x42c90000 (irq = 178, base_baud = 0) is a uartlite

e0000000.serial: ttyPS1 atMMIO 0xe0000000 (irq = 145, base_baud = 3125000) is a xuartps

e0001000.serial: ttyPS0 atMMIO 0xe0001000 (irq = 146, base_baud = 3125000) is a xuartps

郼onsole [ttyPS0] enabled

console [ttyPS0] enabled

bootconsole [earlycon0]disabled

bootconsole [earlycon0]disabled

xdevcfg f8007000.devcfg:ioremap 0xf8007000 to f090c000

[drm] Initialized drm1.1.0 20060810

brd: module loaded

loop: module loaded

m25p80 spi0.0: n25q128a11(16384 Kbytes)

4 ofpart partitions foundon MTD device spi0.0

Creating 4 MTD partitionson "spi0.0":

0x000000000000-0x000000500000: "boot"

0x000000500000-0x000000520000: "bootenv"

0x000000520000-0x000000fa0000: "kernel"

0x000000fa0000-0x000001000000: "spare"

CAN device driverinterface

gpiod_set_value: invalidGPIO

libphy: MACB_mii_bus:probed

[Firmware Warn]:/amba/ethernet@e000b000/mdio/phy@7: Whitelisted compatible string. Pleaseremove

macb e000b000.etherneteth0: Cadence GEM rev 0x00020118 at 0xe000b000 irq 148 (00:0a:35:00:1e:53)

Marvell 88E1111e000b000.etherne:07: attached PHY driver [Marvell 88E1111](mii_bus:phy_addr=e000b000.etherne:07, irq=-1)

e1000e: Intel(R) PRO/1000Network Driver - 3.2.6-k

e1000e: Copyright(c) 1999- 2015 Intel Corporation.

//開始註冊驅動

PPP generic driver version2.4.2

PPP BSD Compression moduleregistered

PPP Deflate Compressionmodule registered

PPP MPPE Compressionmodule registered

NET: Registered protocolfamily 24

usbcore: registered newinterface driver asix

usbcore: registered newinterface driver ax88179_178a

usbcore: registered newinterface driver cdc_ether

usbcore: registered newinterface driver net1080

usbcore: registered newinterface driver cdc_subset

usbcore: registered newinterface driver zaurus

usbcore: registered newinterface driver cdc_ncm

usbcore: registered newinterface driver huawei_cdc_ncm

usbcore: registered newinterface driver cdc_mbim

ehci_hcd: USB 2.0'Enhanced' Host Controller (EHCI) Driver

ehci-pci: EHCI PCIplatform driver

ohci_hcd: USB 1.1 'Open'Host Controller (OHCI) Driver

ohci-pci: OHCI PCIplatform driver

ohci-platform: OHCIgeneric platform driver

uhci_hcd: USB UniversalHost Controller Interface driver

usbcore: registered newinterface driver cdc_acm

cdc_acm: USB AbstractControl Model driver for USB modems and ISDN adapters

usbcore: registered newinterface driver cdc_wdm

usbcore: registered newinterface driver usb-storage

usbcore: registered newinterface driver usbserial

usbcore: registered newinterface driver option

usbserial: USB Serialsupport registered for GSM modem (1-port)

e0002000.usb supply vbusnot found, using dummy regulator

ULPI transceivervendor/product ID 0x0424/0x0007

Found SMSC USB3320 ULPItransceiver.

ULPI integrity check:passed.

ci_hdrc ci_hdrc.0: EHCIHost Controller

ci_hdrc ci_hdrc.0: new USBbus registered, assigned bus number 1

ci_hdrc ci_hdrc.0: USB 2.0started, EHCI 1.00

hub 1-0:1.0: USB hub found

hub 1-0:1.0: 1 portdetected

mousedev: PS/2 mousedevice common for all mice

i2c /dev entries driver

rtc-pcf8563 0-0051: chipfound, driver version 0.4.4

rtc-pcf8563 0-0051: rtccore: registered rtc-pcf8563 as rtc0

cdns-i2c e0004000.i2c: 400kHz mmio e0004000 irq 142

Driver for 1-wire Dallasnetwork protocol.

EDAC MC: ECC not enabled

Xilinx Zynq CpuIdle Driverstarted

sdhci: Secure Digital HostController Interface driver

sdhci: Copyright(c) PierreOssman

sdhci-pltfm: SDHCIplatform and OF driver helper

mmc0: SDHCI controller one0100000.sdhci [e0100000.sdhci] using DMA

ledtrig-cpu: registered toindicate activity on CPUs

usbcore: registered newinterface driver usbhid

usbhid: USB HID coredriver

NET: Registered protocolfamily 10

sit: IPv6 over IPv4tunneling driver

NET: Registered protocolfamily 17

can: controller areanetwork core (rev 20120528 abi 9)

NET: Registered protocolfamily 29

can: raw protocol (rev20120528)

can: broadcast managerprotocol (rev 20120528 t)

can: netlink gateway (rev20130117) max_hops=1

Registering SWP/SWPBemulation handler

rtc-pcf8563 0-0051:setting system clock to 2000-04-09 21:55:13 UTC (955317313)

ALSA device list:

  No soundcards found.

mmc0: new high speed MMCcard at address 0001

Freeing unused kernelmemory: 1024K (c0a00000 - c0b00000)

mmcblk0: mmc0:0001 MMC02G1.79 GiB

INIT: mmcblk0boot0:mmc0:0001 MMC02G partition 1 1.00 MiB

version 2.88bootingmmcblk0boot1: mmc0:0001 MMC02G partition 2 1.00 MiB

mmcblk0rpmb: mmc0:0001MMC02G partition 3 128 KiB

mmcblk0: p1

usb 1-1: new high-speedUSB device number 2 using ci_hdrc

hub 1-1:1.0: USB hub found

hub 1-1:1.0: 4 portsdetected

EXT4-fs (mmcblk0rpmb):unable to read superblock

EXT4-fs (mmcblk0rpmb):unable to read superblock

EXT2-fs (mmcblk0rpmb):error: unable to read superblock

FAT-fs (mmcblk0rpmb):unable to read boot sector

EXT4-fs (mmcblk0rpmb):unable to read superblock

EXT4-fs (mmcblk0rpmb):unable to read superblock

EXT2-fs (mmcblk0rpmb):error: unable to read superblock

FAT-fs (mmcblk0rpmb):unable to read boot sector

FAT-fs (mmcblk0rpmb):unable to read boot sector

usb 1-1.1: new high-speedUSB device number 3 using ci_hdrc

mount: mounting/dev/mmcblk0rpmb on /run/media/mmcblk0rpmb failed: Input/output error

mount: mounting/dev/mmcblk0boot0 on /run/media/mmcblk0boot0 failed: Invalid argument

cdc_ether 1-1.1:2.0 usb0:register 'cdc_ether' at usb-ci_hdrc.0-1.1, CDC Ethernet Device,02:1e:10:1f:00:00

//檢測到4G模塊,啓動4G模塊

option 1-1.1:2.2: GSMmodem (1-port) converter detected

usb 1-1.1: GSM modem(1-port) converter now attached to ttyUSB0

option 1-1.1:2.3: GSMmodem (1-port) converter detected

mount: mounting/dev/mmcblk0boot1 on /run/media/mmcblk0boot1 failed: Invalid argument

usb 1-1.1: GSM modem(1-port) converter now attached to ttyUSB1

option 1-1.1:2.4: GSMmodem (1-port) converter detected

usb 1-1.1: GSM modem (1-port)converter now attached to ttyUSB2

option 1-1.1:2.5: GSMmodem (1-port) converter detected

usb 1-1.1: GSM modem(1-port) converter now attached to ttyUSB3

option 1-1.1:2.6: GSMmodem (1-port) converter detected

usb 1-1.1: GSM modem(1-port) converter now attached to ttyUSB4

/etc/mdev/mdev-mount.sh:line 28: [: /sys/block/mmcblk0/mmcblk0boot1: binary operator expected

mount: mounting/dev/mmcblk0 on /run/media/mmcblk0 failed: Device or resource busy

random: dd urandom readwith 5 bits of entropy available

Mon Apr 24 07:06:36 UTC2017

Starting internetsuperserver: inetd.

INIT: Entering runlevel: 5

//配置以太網接口,等待網口芯片啓動

Configuring networkinterfaces... IPv6: ADDRCONF(NETDEV_UP): eth0: link is not ready

done.

// 啓動Dropbear並生成密鑰,Dropbear是一個相對較小的SSH服務器和客戶端(開源軟件)。

Starting Dropbear SSHserver: Generating key, this may take a while...

//公鑰,用公鑰加密數據就必須用私鑰解密,如果用私鑰加密也必須用公鑰解密。

Public key portion is:

ssh-rsaAAAAB3NzaC1yc2EAAAADAQABAAABAQCQWM1vqfFHlIPbduTWsKeX1iQI4HMwuDZ46GV4FgJbtAFG/+9inB9K42p4YR06RrdnPdkvv2cPAQ/srfbm/qgF5BoKGdE32JsLU4EP9ovBecA6xSe2C2yzJ3e1HQOIaHcSWf59QpxTPFUrw+GYHNR4N8WZj6V9XJ+w6/5NWWSTwICjgo2yizVEodjsPc0VChAqmC8EBUz2evgBBJGbzm3mxgHXzsoKD/kKSlw2dtGcPCvO7GSdxYE1hBtk6xb8a6zToVOAPIqZFCnWtfEKUSexUx60I72nZngOtwqZR+ILR6BBLZqpomwc0AONZtjAYRrdIqnVPR2y0irVNIz1JAPx

root@plnx_arm

Fingerprint: md5b4:d4:cf:bc:ad:c0:79:93:89:66:ce:4a:b0:93:a5:2c

dropbear.

//啓動PetaLinux成功

Start Hello PetaLinux.

//運行初始化腳本

run init.sh

//配置網絡、路由

config network

//啓動系統日誌

Starting syslogd/klogd:set board time

//啓動4G撥號程序,後臺運行

run LTEConnection &

done

open /dev/ttyUSB0 SUCCESS

ttyclear:

Starting tcf-agent: OK

PetaLinux 2016.4 plnx_arm/dev/ttyPS0

//網卡芯片啓動成功

macb e000b000.etherneteth0: link up (1000/Full)

IPv6:ADDRCONF(NETDEV_CHANGE): eth0: link becomes ready

//用戶登錄系統

plnx_arm login:

//查看系統網卡信息

 

ifconfig

eth0      Link encap:Ethernet  HWaddr 00:0A:35:00:1E:53 

          inet addr:192.168.0.100  Bcast:192.168.0.255  Mask:255.255.255.0

          inet6 addr:fe80::20a:35ff:fe00:1e53%768720/64 Scope:Link

          UP BROADCAST RUNNING MULTICAST  MTU:1500 Metric:1

          RX packets:60 errors:0 dropped:0overruns:0 frame:0

          TX packets:10 errors:0 dropped:0overruns:0 carrier:0

          collisions:0 txqueuelen:1000

          RX bytes:6671 (6.5 KiB)  TX bytes:1206 (1.1 KiB)

          Interrupt:148 Base address:0xb000

 

lo        Link encap:Local Loopback 

          inet addr:127.0.0.1  Mask:255.0.0.0

          inet6 addr: ::1%768720/128 Scope:Host

          UP LOOPBACK RUNNING  MTU:65536 Metric:1

          RX packets:8 errors:0 dropped:0overruns:0 frame:0

          TX packets:8 errors:0 dropped:0overruns:0 carrier:0

          collisions:0 txqueuelen:1

          RX bytes:488 (488.0 B)  TX bytes:488 (488.0 B)

 

usb0      Link encap:Ethernet  HWaddr 02:1E:10:1F:00:00 

          inet addr:10.81.49.191  Bcast:10.81.49.255  Mask:255.255.255.128

          inet6 addr:fe80::1e:10ff:fe1f:0%768720/64 Scope:Link

          UP BROADCAST RUNNING MULTICAST  MTU:1500 Metric:1

          RX packets:9 errors:0 dropped:0overruns:0 frame:0

          TX packets:15 errors:0 dropped:0overruns:0 carrier:0

          collisions:0 txqueuelen:1000

          RX bytes:1040 (1.0 KiB)  TX bytes:1802 (1.7 KiB)

//查看系統設備信息

root@plnx_arm:~# ls /dev

bus                 null                tty21               tty59

console             port                tty22               tty6

cpu_dma_latency     ppp                 tty23               tty60

full                psaux               tty24               tty61

i2c-0               ptmx                tty25               tty62

initctl             pts                 tty26               tty63

input               ram0                tty27               tty7

kmsg                ram1                tty28               tty8

log                 ram10               tty29               tty9

loop-control        ram11               tty3                ttyPS0

loop0               ram12               tty30               ttyPS1

loop1               ram13               tty31               ttyUL1

loop2               ram14               tty32               ttyUL10

loop3               ram15               tty33               ttyUL11

loop4               ram2                tty34               ttyUL12

loop5               ram3                tty35               ttyUL2

loop6               ram4                tty36               ttyUL3

loop7               ram5                tty37               ttyUL4

mdev.seq            ram6                tty38               ttyUL5

mem                 ram7                tty39               ttyUL6

memory_bandwidth    ram8                tty4                ttyUL7

mmcblk0             ram9                tty40               ttyUL8

mmcblk0boot0        random              tty41               ttyUL9

mmcblk0boot1        rtc0                tty42               ttyUSB0

mmcblk0p1           shm                 tty43               ttyUSB1

mmcblk0rpmb         snd                 tty44               ttyUSB2

mtab                tty                 tty45               ttyUSB3

mtd0                tty0                tty46               ttyUSB4

mtd0ro              tty1                tty47               urandom

mtd1                tty10               tty48               usbmon0

mtd1ro              tty11               tty49               usbmon1

mtd2                tty12               tty5                vcs

mtd2ro              tty13               tty50               vcs1

mtd3                tty14               tty51               vcsa

mtd3ro              tty15               tty52               vcsa1

mtdblock0           tty16               tty53               vga_arbiter

mtdblock1           tty17               tty54               watchdog

mtdblock2           tty18               tty55               watchdog0

mtdblock3           tty19               tty56               xdevcfg

network_latency     tty2                tty57               zero

network_throughput  tty20               tty58

//系統關機過程:

oot@plnx_arm:~# shutdown-h now

Broadcast message fromroot@plnx_arm (ttyPS0) (Fri Oct 20 11:28:20 2017):

The syste@J蛠going down for system halt NOW!

INIT: Switching to runlev

//改變系統runlevel,0表示關機

//向系統進程發送中斷信號

INIT: Sending processesthe TERM signal

//停止Dropbear SSH server

root@plnx_arm:~# StoppingDropbear SSH server: stopped /usr/sbin/dropbear (pid 1160)

dropbear.

 //停止Linux系統

Stop Hello PetaLinux.

//停止系統日誌進程

Stopping syslogd/klogd:stopped syslogd (pid 1173)

stopped klogd (pid 1175)

done

Stopping tcf-agent:random: nonblocking pool is initialized

FAIL

//清空網絡接口的配置

Deconfiguring networkinterfaces... done.

Sending all processes theTERM signal...

//退出用戶登錄

logout

macb e000b000.etherneteth0: link down

Sending all processes theKILL signal...

//卸載遠程文件系統和本地文件系統

Unmounting remotefilesystems...

Deactivating swap...

Unmounting localfilesystems...

//系統關機完成

reboot: System halted

附加信息:

Linux系統有7個運行級別(runlevel)

 

Linux系統有7個運行級別(runlevel)

運行級別0:系統停機狀態,系統默認運行級別不能設爲0,否則不能正常啓動

運行級別1:單用戶工作狀態,root權限,用於系統維護,禁止遠程登陸

運行級別2:多用戶狀態(沒有NFS)

運行級別3:完全的多用戶狀態(有NFS),登陸後進入控制檯命令行模式

運行級別4:系統未使用,保留

運行級別5:X11控制檯,登陸後進入圖形GUI模式

運行級別6:系統正常關閉並重啓,默認運行級別不能設爲6,否則不能正常啓動

 

多數的桌面的linux系統缺省的runlevel是5,用戶登陸時是圖形界面,而多數的服務器版本的linux系統缺省的runlevel是3,用戶登陸時是字符界面,runlevel 1和2除了調試之外很少使用,runlevel s和S並不是直接給用戶使用,而是用來爲Single user mode作準備。

在基於Busybox的系統上執行busybox --list即可看到一個系統可用命令列表

發表評論
所有評論
還沒有人評論,想成為第一個評論的人麼? 請在上方評論欄輸入並且點擊發布.
相關文章