Linux 开机启动详解

一、开发环境

1、ubuntu-16.04 64bits,不能使用32bits的系统。
2、vmware12.01 —->mnt/hgfs
3、windows 64bits

二、嵌入式概述

这里写图片描述

1、用户空间—应用程序,内核空间—驱动程序
2、应用程序如何访问驱动程序?(系统调用)
3、驱动程序给应用程序提供的接口
4、驱动程序访问硬件

三、嵌入式平台的启动过程概述(GEC6818为例)

说明:GEC6818是以cortex A53 为核心架构,以三星公司生产的 S5P6818为核心主板的一块开发板
如图:

这里写图片描述

硬件上电–>运行CPU自带的boot–>启动u-boot—>加载linux内核
–>挂载rootfs–>调用rootfs中的脚本/etc/profile—>调用用户的应用程序

四、u-boot

1、什么是u-boot?

u-boot是嵌入式平台硬件的启动引导程序,完成硬件的初始化和操作系统的启动。
u-boot—>通用的boot loader, u–universal

1)通用
(1)u-boot支持多种架构的CPU:ARM、x86、MIPS、PowerPC、…..
(2)u-boot支持多种操作系统的启动引导:linux、WinCE、Vxworks、….。uC/OS-III–>简单的操作系统,不需要使用u-boot,直接引导。

2)boot
硬件的初始化代码,使用uboot可以完成硬件的初始化。uboot做硬件初始化的时候,分成2个阶段:
stage1:CPU级的初始化(核心初始化)—>CPU的cache、时钟频率、MMU、DDR3内存、串口、电源管理、……
stage2:board级的初始化(外设的初始化)—>网卡、LCD、IIC、USB、…..
注意:
stage1一般使用ARM汇编语言编程;stage2使用C语言编程。

3)loader
加载linux系统的内核,并启动内核。将linux内核从电子硬盘(flash存储器,掉电不丢失)拷贝到DDR3内存(RAM,掉电数据丢失),并向linux内核传递启动参数(bootargs—boot arguments),然后linux内核根据启动参数完成启动。

2、u-boot是免费的,源码开放的。

uboot本身不是操作系统,是一个裸机程序。
1)u-boot的官网
http://www.denx.de/wiki/U-Boot/WebHome
ftp://ftp.denx.de/pub/u-boot/

3、GEC6818平台的u-boot的版本

U-Boot 2014.07

五、u-boot的使用

u-boot除了有boot和loader的功能以外,它也提供了一些工具—命令。使用这些命令可以查看硬件信息,也可以下载程序、…..
uboot命令和linux的shell是不同的。

1、进入uboot命令行

Hit any key to stop autoboot: 0
X6818#
X6818#
X6818#

2、查看uboot支持的命令

X6818# help

3、bdinfo - 查看嵌入式硬件平台的信息

X6818# bdinfo
arch_number = 0x000010EA —->u-boot针对每一个具体的硬件平台(GEC6818)有一个ID。这个ID会传给linux内核,linux内核收到该ID会与自身的ID做对比,如果二者一致,linux内核才可以启动。

boot_params = 0x40000100 —>uboot传给linux内核的启动参数存放的地址,uboot将该地址传给内核,内核启动过程中,去该地址获取启动参数。

DRAM bank = 0x00000000 —>DDR3内存
-> start = 0x40000000 —>内存的开始地址
-> size = 0x40000000 —>内存的大小 4*2**28=1*2**2 * 2**28=1*2**30=1GB

提示1:eMMC电子硬盘,8GB

提示2:linux内核在内存中运行的地址:

Booting kernel from Legacy Image at 48000000 …
Image Name: Linux-3.4.39-gec
Image Type: ARM Linux Kernel Image (uncompressed)
Data Size: 5533816 Bytes = 5.3 MiB
Load Address: 40008000 —->linux内核的运行地址。
Entry Point: 40008000
Verifying Checksum … OK
Loading Kernel Image … OK

提示3:DDR3地址范围:
0x40000000~0x80000000-1

eth0name = dwmac.c0060000
ethaddr = 00:e2:1c:ba:e8:60 —>网卡的MAC地址
current eth = dwmac.c0060000
ip_addr = 192.168.14.3 —>IP地址
baudrate = 115200 bps
TLB addr = 0x7FFF0000
relocaddr = 0x46000000
reloc off = 0x00000000
irq_sp = 0x7DF6BF00
sp start = 0x43BFFE68

4、fastboot

系统刷新命令,可以看到eMMC的分区

X6818# fastboot

Fastboot Partitions:
mmc.2: ubootpak, img : 0x200, 0x78000
mmc.2: 2ndboot, img : 0x200, 0x4000
mmc.2: bootloader, img : 0x8000, 0x70000
mmc.2: boot, fs : 0x100000, 0x4000000
mmc.2: system, fs : 0x4100000, 0x2f200000
mmc.2: cache, fs : 0x33300000, 0x1ac00000
mmc.2: misc, fs : 0x4e000000, 0x800000
mmc.2: recovery, fs : 0x4e900000, 0x1600000
mmc.2: userdata, fs : 0x50000000, 0x0
Support fstype : 2nd boot factory raw fat ext4 emmc nand ubi ubifs
Reserved part : partmap mem env cmd
DONE: Logo bmp 311 by 300 (3bpp), len=280854
DRAW: 0x47000000 -> 0x46000000
Load USB Driver: android
Core usb device tie configuration done
OTG cable Connected!

5、printenv

查看uboot的环境变量
X6818# printenv
baudrate=115200 —->串口控制台的波特率。console=/dev/ttySAC0

bootargs=lcd=at070tn92 tp=gslx680-linux root=/dev/mmcblk0p2 rw rootfstype=ext4

bootcmd=ext4load mmc 2:1 0x48000000 uImage;bootm 0x48000000

bootdelay=2 —>uboot自动系统的倒计时
bootfile=uImage —>linux内核映像文件的格式
ethaddr=00:e2:1c:ba:e8:60 —>网卡的MAC地址
ethprime=RTL8211
—->网络信息
gatewayip=192.168.14.1
ipaddr=192.168.14.3
netmask=255.255.254.0
serverip=192.168.15.216
Environment size: 865/32764 bytes

1)启动命令
—->告诉uboot,自动启动后,去哪里加载linux内核,并运行内核。
bootcmd=ext4load mmc 2:1 0x48000000 uImage;bootm 0x48000000
ext4load mmc 2:1 —->去电子硬盘eMMC的第一个分区去加载linux内核
0x48000000 —->内核要加载到DDR3内存的0x48000000地址上
uImage —>linux内核映像文件的格式是uImage

bootm 0x48000000 —>运行拷贝到0x48000000地址上的linux内核映像。
如果uboot可以启动,但是不能启动linux内核,可以查看uboot的bootcmd是否正确。

2)启动参数
bootargs=lcd=at070tn92 tp=gslx680-linux root=/dev/mmcblk0p2 rw rootfstype=ext4
—–>uboot将启动参数存放到DDR3内存的0x40000100地址上,linux内核从该地址或这些启动参数,并根据启动参数进行内核的启动和rootfs的挂载。
lcd=at070tn92 —>GEC6818平台使用LCD的型号,内核根据这个型号,来调用对应LCD的驱动。
tp=gslx680-linux —>GEC6818平台使用触摸屏的型号,内核根据这个型号,来调用对应触摸屏的驱动。
root=/dev/mmcblk0p2 —->根文件系统是存放在eMMC的第2个分区
rw rootfstype=ext4 —>rw–rootfs是可读写的,rootfstype=ext4—rootfs的类型是ext4.

—->如果linux内核可以启动,但是不能挂载rootfs,我们可以查看启动参数是否指定了rootfs的路径。

6、setenv

—–>设置环境变量
X6818# setenv bootdelay 5
X6818# setenv ipaddr 192.168.7.5
X6818# setenv serverip 192.168.7.3
X6818# setenv gatewayip 192.168.7.1
X6818# saveenv
Saving Environment to MMC…
Writing to MMC(2)… done

六、linux内核

1、linux内核的作用

1)进程的管理和进程通信
2)内存管理—虚拟内存
3)文件系统
[root@GEC6818 /]#cat /proc/filesystems
nodev sysfs
nodev rootfs
nodev bdev
nodev proc
nodev cgroup
nodev tmpfs
nodev devtmpfs
nodev binfmt_misc
nodev debugfs
nodev sockfs
nodev pipefs
nodev anon_inodefs
nodev rpc_pipefs
nodev devpts
ext2
ext3
ext4 —–> rootfs的文件系统类型
nodev ramfs
vfat —->U盘、SD卡的文件系统类型
msdos
iso9660
nodev nfs ——>网络文件系统
nodev nfs4
ntfs
nodev autofs
fuseblk
nodev fuse
nodev fusectl

注意:
想要linux内核支持一种新的文件系统—->通过配置linux内核,来选择新的文件系统。

4)设备管理—-linux设备驱动
5)网络协议—TCP/IP
网络七层:
应用层、表示层、会话层—–>linux用户空间,属于linux应用程序:ftp、telnet、http、….
传输层、网络层 —–>linux内核中标准网络协议(TCP/IP)
数据链路层—–网卡驱动
物理层—网卡

2、GEC6818内核启动的过程中,主要做了哪些工作?

1)uboot加载linux内核,得到内核的信息,并启动内核。

Booting kernel from Legacy Image at 48000000 …

Image Name: Linux-3.4.39-gec —->3.4.39, -gec—->编译内核时,加入的本地版本(local version)
Image Type: ARM Linux Kernel Image (uncompressed)
Data Size: 5533816 Bytes = 5.3 MiB
Load Address: 40008000
Entry Point: 40008000
Verifying Checksum … OK
Loading Kernel Image … OK

Starting kernel …

2)linux内核的基本信息
[ 0.000000] Booting Linux on physical CPU 0
[ 0.000000] Linux version 3.4.39-gec (gec@ubuntu) (gcc version 4.8 (GCC) ) #3 SMP PREEMPT Thu Jan 25 14:47:54 CST 2018
[ 0.000000] GEC6818 : done board initialize …
[ 0.000000] PERCPU: Embedded 9 pages/cpu @c1519000 s12544 r8192 d16128 u36864
[ 0.000000] Kernel command line: console=ttySAC0,115200n8 androidboot.hardware=GEC6818 androidboot.console=ttySAC0 androidboot.serialno=0123456789abcdef initrd=0x49000000,0x1000000 lcd=at070tn92 tp=gslx680-linux root=/dev/mmcblk0p2 rw rootfstype=ext4

3)linux内核内存的划分:
[ 0.000000] Memory: 1024MB = 1024MB total
[ 0.000000] Memory: 810812k/810812k available, 237764k 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 - 0xc0a53154 (10541 kB)
[ 0.000000] .init : 0xc0a54000 - 0xc0a91100 ( 245 kB)
[ 0.000000] .data : 0xc0a92000 - 0xc0b2c148 ( 617 kB)
[ 0.000000] .bss : 0xc0b2c16c - 0xc0d0be88 (1920 kB)
[ 0.000000] SLUB: Genslabs=11, HWalign=64, Order=0-3, MinObjects=0, CPUs=8, Nodes=1

4)8核处理器的测试
[ 0.008000] CPU: Testing write buffer coherency: ok
[ 0.008000] CPU0: thread -1, cpu 0, socket 0, mpidr 80000000
[ 0.008000] hw perfevents: no hardware support available
[ 0.008000] Setting up static identity map for 0x407343c8 - 0x40734420
[ 0.024000] CPU1: thread -1, cpu 1, socket 0, mpidr 80000001
[ 0.037000] CPU2: thread -1, cpu 2, socket 0, mpidr 80000002
[ 0.050000] CPU3: thread -1, cpu 3, socket 0, mpidr 80000003
[ 0.063000] CPU4: thread -1, cpu 0, socket 4, mpidr 80040400
[ 0.076000] CPU5: thread -1, cpu 1, socket 4, mpidr 80040401
[ 0.088000] CPU6: thread -1, cpu 2, socket 4, mpidr 80040402
[ 0.101000] CPU7: thread -1, cpu 3, socket 4, mpidr 80040403
[ 0.101000] Brought up 8 CPUs
[ 0.101000] SMP: Total of 8 processors activated (12750.84 BogoMIPS).

5)设备驱动的初始化
[ 0.223000] axp22_ldo1: 3000 mV
[ 0.309000] Advanced Linux Sound Architecture Driver Version 1.0.25.
[ 0.309000] Bluetooth: Core ver 2.16
[ 0.353000] Display LCD register operation
[ 0.354000] Display LVDS register operation
[ 0.354000] Display MiPi register operation

[ 0.381000] nxp-uart.0: ttySAC0 at MMIO 0xc00a1000 (irq = 39) is a S3C6400/10
[ 1.431000] console [ttySAC0] enabled
[ 1.435000] nxp-uart.1: ttySAC1 at MMIO 0xc00a0000 (irq = 38) is a S3C6400/10
[ 1.442000] nxp-uart.2: ttySAC2 at MMIO 0xc00a2000 (irq = 40) is a S3C6400/10
[ 1.449000] nxp-uart.3: ttySAC3 at MMIO 0xc00a3000 (irq = 41) is a S3C6400/10
[ 1.456000] nxp-uart nxp-uart.0: DMA channel TX dma1chan2
[ 1.462000] nxp-uart nxp-uart.0: DMA channel RX dma1chan3
[ 1.467000] nxp-uart nxp-uart.1: DMA channel TX dma1chan0
[ 1.472000] nxp-uart nxp-uart.1: DMA channel RX dma1chan1
[ 1.478000] nxp-uart nxp-uart.2: DMA channel TX dma1chan4
[ 1.483000] nxp-uart nxp-uart.2: DMA channel RX dma1chan5

[ 3.037000] input: ft5x0x as /devices/virtual/input/input0
[ 3.046000] i2c-nxp.1: ack was not received
[ 3.046000] i2c->nxp.1: incomplete xfer (-6)
[ 3.050000] ft5x0x 1-0038: chip not found
[ 3.074000] ft5x0x 1-0038: probe ft5x0x TouchScreen failed, -6
[ 3.075000] nxp-rtc nxp-rtc.0: rtc core: registered nxp-rtc as rtc0
[ 3.078000] i2c /dev entries driver

[ 3.283000] nxp_wdt: NXP Watchdog Timer, (c) 2014 SLsiAP

6)网络初始化
[ 0.331000] NET: Registered protocol family 2
[ 0.331000] IP route cache hash table entries: 32768 (order: 5, 131072 bytes)
[ 0.332000] TCP established hash table entries: 131072 (order: 8, 1048576 bytes)
[ 0.334000] TCP bind hash table entries: 65536 (order: 8, 1572864 bytes)
[ 0.336000] TCP: Hash tables configured (established 131072 bind 65536)
[ 0.336000] TCP: reno registered
[ 0.336000] UDP hash table entries: 512 (order: 3, 32768 bytes)
[ 0.337000] UDP-Lite hash table entries: 512 (order: 3, 32768 bytes)
[ 0.337000] NET: Registered protocol family 1
[ 0.338000] RPC: Registered named UNIX socket transport module.
[ 0.338000] RPC: Registered udp transport module.
[ 0.338000] RPC: Registered tcp transport module.
[ 0.338000] RPC: Registered tcp NFSv4.1 backchannel transport module.

7)文件系统
[ 0.365000] NFS: Registering the id_resolver key type
[ 0.366000] NTFS driver 2.1.30 [Flags: R/W].
[ 0.366000] fuse init (API version 7.18)
[ 0.367000] msgmni has been set to 1083

8)挂载rootfs
[ 3.911000] EXT4-fs (mmcblk0p2): mounted filesystem with ordered data mode. Opts: (null)
[ 3.913000] VFS: Mounted root (ext4 filesystem) on device 179:2. —->挂载rootfs
[ 3.920000] devtmpfs: mounted —->成功挂载
[ 3.922000] Freeing init memory: 244K
[ 3.926000] Write protecting the kernel text section c0008000 - c0a1d000
[ 3.933000] rodata_test: attempting to write to read-only section:
[ 3.939000] write to read-only section trapped, success
[ 4.079000] EXT4-fs (mmcblk0p2): re-mounted. Opts: data=ordered
-/bin/sh: fconfig: not found
[ 4.436000] eth0: device MAC address 7e:82:f1:98:01:8f
[ 4.443000] stmmac_open: failed PTP initialisation

9)初始化环境变量(执行/etc/profile),进入linux的命令行,可以执行应用程序
[root@GEC6818 /]#
[root@GEC6818 /]#
[root@GEC6818 /]#

讲解:VFS: Mounted root (ext4 filesystem) on device 179:2.—通过虚拟文件系统挂载rootfs。rootfs在179:2设备上
[root@GEC6818 /]#ls /dev/mmc* -l
brw-rw—- 1 root root 179, 0 Jan 1 1970 /dev/mmcblk0
brw-rw—- 1 root root 179, 8 Jan 1 1970 /dev/mmcblk0boot0
brw-rw—- 1 root root 179, 16 Jan 1 1970 /dev/mmcblk0boot1
brw-rw—- 1 root root 179, 1 Jan 1 1970 /dev/mmcblk0p1
brw-rw—- 1 root root 179, 2 Jan 1 1970 /dev/mmcblk0p2 —->179主设备号,2—次设备号,硬盘的第二个分区。

3、linux源码

源码开发,免费使用。
https://www.kernel.org/
https://www.kernel.org/pub/linux/kernel/v3.x/

  • 2
    点赞
  • 18
    收藏
    觉得还不错? 一键收藏
  • 1
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论 1
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值