一 嵌入式linux启动流程
上电 -----> 启动u-boot(引导程序) ----> 加载内核 ----> 挂载Rootfs -----> 启动应用(QT等应用程序)
二 启动u-boot
1 什么是u-boot
u-boot它就是一种通用的引导程序(bootloader),类似于windows的bios ,不是一种linux操作系统,不支持linux命令
2 u-boot的作用
1)在于初始化硬件平台,保证硬件可以正常工作
stage1:初始化核心(板级)硬件平台的初始化:CPU,内存-DDR3,电子硬盘-eMMC等核心硬件
CPU:GEC6818 ----A53
stage2:初始化一些外围的硬件:UART,USB,LCD,等
2)给u-boot终端界面,提供一个操作命令
可通过输入help或者?进行查看
3)加载内核
3 通用的意义:
1) 支持多种CPU体系:ARM,PowerPC,MIPS
2) 支持多种的操作系统:linux,WINCE
4 u-boot源码下载
打开:http:
------> FTP server - Alternative Cloud Access
源码下载网址:ftp:
5 u-boot的输出
--------------------------------------------------------------------------------
Second Boot by Nexell Co. : Ver0.3.6 - Built on Jun 12 2015 20:06:08
--------------------------------------------------------------------------------
NSIH : Ver0.0.xx
DDR3 POR Init Start 0
phy init
Lock value = 194
GATE CYC = 0x00000492
GATE CODE = 0x00000000
Read DQ = 0x08080808
Write DQ = 0x08080808
DDR3 Init Done!----- 初始化内存
CCI Init!
Wakeup CPU Wakeup CPU 1234567
CPU Wakeup done! WFI is expected.
CPU0 is Master!
Loading from sdmmc...
Image Loading Done!
Launch to 0x0000000043C00000
U-Boot 2014.07 (Jul 19 2016 - 18:02:07) ---- 开发板所用到的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 ----- 内存的大小
Heap = 0x44000000~0x46000000
Code = 0x43c00000~0x43c86188
GLD = 0x43bffeb8
GLBD = 0x43bffe68
SP = 0x43bffe68,0x43bffe48(CURR) --- stack pointer
PC = 0x43c06640 ---- programer counter(程序计数寄存器)
TAGS = 0x40000100
PAGE = 0x43c90000~0x43c9c000 ---- 页的大小: c000 1010 0000 0000 0000 ----> 4k
MACH = [4330] ---- 机器ID ,跟内核中机器ID要保持一致,才能成功加载内核
VER = 0
BOARD= [x6818] ------ 开发板的板级名字
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) : 0x40 0x40 0x00 0x00 0x00
## CHG_TYPE : ADP
## BAT_VOL : 0mV
## BAT_CAP : 100%
DONE: Logo bmp 300 by 300 (3bpp), len=270056 ----- u-boot启动过程中,加载图片
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: x6818 eth init... ----- 初始化网卡
x6818 mac init...
6 u-boot命令与信息
1)bdinfo - print Board Info structure --- 打印板级的结构信息
X6818# bdinfo ---- 打印硬件平台的信息
arch_number = 0x000010EA ---- > 4330 硬件平台的架构ID ----> 是由开发人员在代码中来制定
boot_params = 0x40000100 -----> 启动参数所在的地址
DRAM bank = 0x00000000
-> start = 0x40000000 ----> 内存的起始地址
-> size = 0x40000000 ----> 内存的大小
eth0name = dwmac.c0060000
ethaddr = 00:e2:1c:ba:e8:60 ----> mac地址
current eth = dwmac.c0060000
ip_addr = 192.168.27.3 ------> ip地址
baudrate = 115200 bps -----> 波特率
TLB addr = 0x7FFF0000
relocaddr = 0x46000000
reloc off = 0x00000000
irq_sp = 0x7DF68F00
sp start = 0x43BFFE68
2) printenv- print environment variables ---- 打印环境变量
X6818# printenv
androidcrc=-411152780
baudrate=115200
bootargs=lcd=at070tn92 tp=gslx680-linux root=/dev/mmcblk0p2 rw rootfstype=ext4 ----> 启动参数
bootcmd=ext4load mmc 2:1 0x48000000 uImage;bootm 0x48000000 ---- > 启动命令
bootdelay=1 -----> 启动延时
bootfile=uImage ----> 启动文件
ethact=dwmac.c0060000
ethaddr=00:e2:1c:ba:e8:60
ethprime=RTL8211
fastboot=flash=mmc,2:ubootpak:2nd:0x200,0x78000;flash=mmc,2:2ndboot:2nd:0x200,0x4000;flash=mmc,2:bootloader:boot:0x8000,0x70000;flash=mmc,2:boot:ext4:0x00100000,0x04000000;flash=mmc,2:system:ext4:0x04100000,0x2F200000;flash=mmc,2:cache:ext4:0x33300000,0x1AC00000;flash=mmc,2:misc:emmc:0x4E000000,0x00800000;flash=mmc,2:recovery:emmc:0x4E900000,0x01600000;flash=mmc,2:userdata:ext4:0x50000000,0x0;
filesize=41ee8
gatewayip=192.168.27.1
ipaddr=192.168.27.3
netmask=255.255.255.0
qtcrc=1446511370
serverip=192.168.27.2
stderr=serial
stdin=serial
stdout=serial
Environment size: 866/32764 bytes
关键内容:
1) bootargs(启动参数)
bootargs=lcd=at070tn92 tp=gslx680-linux root=/dev/mmcblk0p2 rw rootfstype=ext4
lcd=at070tn92 --- lcd显示屏
tp=gslx680-linux --- 触摸屏
root=/dev/mmcblk0p2 rw rootfstype=ext4 ---->rootfs在哪里,告诉内核(kernel)去哪里挂载rootfs
root=/dev/mmcblk0p2 mmcblk0---->电子硬盘 ,p2----> 电子硬盘的第二个分区
rw rootfstype=ext4 ---> rootfs 可读可写 文件的类型:ext4
2) bootcmd(启动命令)
bootcmd=ext4load mmc 2:1 0x48000000 uImage;bootm 0x48000000
以ext4文件系统类型去emmc的第二个分区(mmc 2:1)加载内核,加载到0x48000000上,然后在0x48000000这个地址上启动内核
总结:bootcmd告诉u-boot去哪里加载内核
bootargs告诉内核去哪里挂载rootfs
3) bootdelay
X6818# setenv bootdelay 3
X6818# saveenv(或者 save)
==================================================================================================
三 linux内核----- linux 核心
1 linux内核作用
1)进程管理和进程调度:进程的创建和删除,进程的优先级和抢占,进程的时间片轮询 进程间通信机制
2)内存管理:内存的分配(内存的分配算法)
内存申请与释放
3)设备管理: linux驱动:字符设备,块设备,网络设备,内核时钟,中断
4)网络协议: tcp/ip, 无线通信协议
5)内核虚拟文件系统
[root@6818 /proc]#cat filesystems
2 linux内核源码的下载
内核源码:https:
从内核官网下载的源码,不能直接编译,要针对具体的硬件平台进行配置编译
3 linux内核的启动
由u-boot启动命令(bootcmd)去指定的地址(0x48000000)上加载内核,并且u-boot源码中的arch_number要与内核源码的
arch_number保持一致,表示u-boot下的硬件平台与内核中的硬件平台一致
u-boot源码中的路径:
xxx\arch\arm\include\asm\arch-s5p6818\mach-types.h
#define MACH_TYPE_S5P6818 4330
内核源码中的路径:xxx\kernel\arch\arm\tools\mach-types.h
nxp5430 MACH_S5P6818 S5P6818 4330
1)开发板内核启动输出
1) 内核的信息
Hit any key to stop autoboot: 0
## Booting kernel from Legacy Image at 48000000 ...
Image Name: Linux-3.4.39-gec ----> 镜像的名字
Image Type: ARM Linux Kernel Image (uncompressed)
Data Size: 5525536 Bytes = 5.3 MiB
Load Address: 40008000
Entry Point: 40008000
Verifying Checksum ... OK
Loading Kernel Image ... OK
Starting kernel ...
[ 0.000000] Booting Linux on physical CPU 0
[ 0.000000] Initializing cgroup subsys cpu
[ 0.000000] Linux version 3.4.39-gec (bobey@ubuntu) (gcc version 4.8 (GCC) ) #1 SMP PREEMPT Sat Oct 28 16:30:19 CST 2017 -----> linux内核的版本 GCC编译器的版本
[ 0.000000] CPU: ARMv7 Processor [410fd033] revision 3 (ARMv7), cr=10c5387d
[ 0.000000] CPU: PIPT / VIPT nonaliasing data cache, VIPT aliasing instruction cache
[ 0.000000] Machine: s5p6818
2) 内存分配
[ 0.000000] Memory: 1024MB = 1024MB total ----> 1G
[ 0.000000] Memory: 810820k/810820k available, 237756k reserved, 272384K highmem
[ 0.000000] Virtual kernel memory layout: ----> 虚拟内存布局
[ 0.000000] vector : 0xffff0000 - 0xffff1000 ( 4 kB) ---> 向量表
[ 0.000000] fixmap : 0xfff00000 - 0xfffe0000 ( 896 kB)
[ 0.000000] vmalloc : 0xef800000 - 0xfee00000 ( 246 MB)
[ 0.000000] lowmem : 0xc0000000 - 0xef600000 ( 758 MB)
[ 0.000000] pkmap : 0xbfe00000 - 0xc0000000 ( 2 MB)
[ 0.000000] modules : 0xbf000000 - 0xbfe00000 ( 14 MB)
[ 0.000000] .text : 0xc0008000 - 0xc0a51018 (10533 kB)
[ 0.000000] .init : 0xc0a52000 - 0xc0a8f100 ( 245 kB)
[ 0.000000] .data : 0xc0a90000 - 0xc0b297d8 ( 614 kB)
[ 0.000000] .bss : 0xc0b297fc - 0xc0d09488 (1920 kB)
[ 0.000000] SLUB: Genslabs=11, HWalign=64, Order=0-3, MinObjects=0, CPUs=8, Nodes=1
3) linux设备管理
GPIO口
串口
USB
网卡等
4) linux内核启动完成
[ 4.180000] nxp-rtc nxp-rtc.0: setting system clock to 2015-01-01 01:18:21 UTC (1420075101)
[ 4.189000] tmu[0] = trim 46:0, ret 1
[ 4.192000] TMU: register tmu.0 to hwmon (max 1400000khz)
[ 4.198000] ALSA device list:
[ 4.200000] #0: I2S-alc5623
5) 挂载Rootfs
[ 4.219000] EXT4-fs (mmcblk0p2): mounted filesystem with ordered data mode. Opts: (null)
[ 4.220000] VFS: Mounted root (ext4 filesystem) on device 179:2.
[ 4.225000] devtmpfs: mounted
6)释放清理的工作和数据保护处理
[ 4.227000] Freeing init memory: 244K ---->清理.init内存区
[ 4.231000] Write protecting the kernel text section c0008000 - c0a1b000 --->代码段保护
[ 4.238000] rodata_test: attempting to write to read-only section: ----> 只读数据段
[ 4.244000] write to read-only section trapped, success ---- 数据保护
[ 4.392000] EXT4-fs (mmcblk0p2): re-mounted. Opts: data=ordered
[ 4.682000] HDMI HPD State 0x0
[ 4.740000] eth0: device MAC address 7e:82:61:68:02:56
[ 4.747000] stmmac_open: failed PTP initialisation
[ 4.759000] irq = 147
[ 4.759000] irq = 134
[ 4.759000] irq = 168
[ 4.760000] irq = 169
[ 4.763000] gecBt initialized
[ 4.772000] dc_motor initialized
[ 4.781000] gec_gas_drv initialized
[ 4.794000] Led initialized
[ 4.801000] relay initialized
[ 4.822000] humidity initialized
==================================================================================================
三 根文件系统---Rootfs
1、什么是Rootfs
linux内核挂载的第一个文件系统,根文件系统是挂载到根目录下的文件系统.
根文件系统就是一个包,该包中包含了:
etc lost+found root sys usr
bin lib mnt run test var
dev linuxrc proc sbin tmp
1)linux shell命令
/bin ----> 一般shell命令
/sbin ----> 超级用户管理员命令
/usr/bin ---> 项目在编译生成的可执行的文件,可以用来当做shell命令
/usr/sbin
2)设备节点:用来存放设备节点或者文件 ---> 应用程序可通过系统调用来访问底层的设备
/dev
3) linux系统配置文件
/etc ---->用户、密码、网络配置、系统配置,修改该目录下的内容,为了确保生效,要进行开发板重启
4)实时反映linux系统的工作状态(进程的运行情况)
/proc
[root@6818 /proc]#ls
1 24 5 asound loadavg
10 25 50 buddyinfo locks
100 26 51 bus meminfo
101 27 52 cgroups misc
102 28 53 cmdline modules
103 29 539 config.gz mounts
104 3 6 consoles net
105 30 609 cpu pagetypeinfo
106 31 65 cpuinfo partitions
107 32 66 crypto sched_debug
108 33 67 devices schedstat
109 34 68 diskstats scsi
11 35 69 dma-mappings self
110 36 7 driver slabinfo
12 37 70 execdomains softirqs
(1) 数字 ---> PID进程的状态信息
(2) cpuinfo ---> 查看CPU信息
(3) meminfo ---> 查看内存的状态
(4) version ---> 查看linux系统版本
[root@6818 /proc]#cat version
Linux version 3.4.39-gec (bobey@ubuntu) (gcc version 4.8 (GCC) ) #1 SMP PREEMPT Sat Oct 28 16:30:19 CST 2017
(5) uptime --->系统的工作时间
5)linux应用程序运行时,所要用到的库(*.so)
/lib
/usr/lib
6) 指向linux的shell命令的环境
/linuxrc
[root@6818 /]#ls -l linuxrc
lrwxrwxrwx 1 root root 11 Dec 27 2016 linuxrc -> bin/busybox
busybox的作用:
1)它是一个用来生成linux常用命令和工具的软件
2)通过编译busybox的源码得到常用命令,比如:ls,cd
7) 系统的挂载点
/mnt
8) linux设备驱动的详细信息
/sys
9) 系统的工作日志目录
/var
10) 系统的临时文件
/tmp
注意:该目录下的文件,默认情况下,重启开发板,该文件会被清除,普遍用于项目来保存临时的数据