前面介绍过了从SD卡启动uboot和kernel,并且在sd卡创建了两个分区,一个分区用来存放kernel,格式为FAT32。另一个分区用来存放文件系统,格式为EXT4,接下来介绍如何从sd卡启动文件系统。
首先使用一个已经做好的可以挂载的根文件,这里可以使用友善官方提供的rootfs_rtm_210.tgz文件系统。
1、解压文件系统
tar xzvf rootfs_rtm_210.tgz
2、官方提供的文件系统里面缺少了console和null设备文件,所以需要创建这个两个文件才能成功挂载
cd rootfs_rtm_210/dev/
sudo mknod -m 666 console c 5 1
sudo mknod -m 666 null c 1 3
3、挂载sd ext4分区,拷贝文件到sd卡
mount /dev/sdb2 /mnt
cd rootfs_rtm_210/
sudo cp ./* /mnt -rf
进入到/mnt目录可以看到文件都拷贝到了sd卡第二分区
cd /mnt
ls
bin dev etc home lib linuxrc lost+found mnt opt proc root sbin sdcard sys tmp usr var
其中有lost+found录说明改分区格式为ext4,说明我们的分区创建是成功的。
4、修改kernel支持ext4格式
进入到linux内核
make menuconfig ARCH=arm
File systems —><*> The Extended 4 (ext4) filesystem
5、设置bootargs参数,支持从sd卡启动
setenv bootargs "console=ttySAC0,115200n8 noinitrd root=/dev/mmcblk0p2 rw rootfstype=ext4 init=/linuxrc lcd=H43 ctp=2"
参数解析:root=/dev/mmcblk0p2,mmcblk0是SD卡,mmcblk1是eMMC;mmcblk0p1是SD卡的root分区,mmcblk0p2是SD卡的rootfs分区。由于上文提到,将根文件系统放到rootfs分区,也就是/dev/mmcblk0p2分区
6、设置bootcmd参数,从sd卡读取kernel并启动
setenv bootcmd "mmc part; fatload mmc 0:1 0x21000000 uImage; bootm 0x21000000"
7、kernel启动并成功挂载根文件系统log
OKOKraise: Signal # 8 caught
########################################################
# Modified by GJGJ http://blog.csdn.net/liukun321 #
########################################################
U-Boot 2011.06 (Jun 09 2017 - 01:00:18) for FriendlyLEG-TINY210
CPU: S5PC110@1000MHz
Board: FriendlyLEG-TINY210
DRAM: 512 MiB
WARNING: Caches not enabled
PWM Moudle Initialized.
NAND: 512 MiB
MMC: SAMSUNG SD/MMC: 0, SAMSUNG SD/MMC: 1
In: serial
Out: serial
Err: serial
Net: dm9000
Hit any key to stop autoboot: 0
Partition Map for MMC device 0 -- Partition Type: DOS
Partition Start Sector Num Sectors Type
1 268288 204800 b
2 473088 4194304 83
reading uImage
4809352 bytes read
## Booting kernel from Legacy Image at 21000000 ...
Image Name: Linux-3.0.8-FriendlyARM
Image Type: ARM Linux Kernel Image (uncompressed)
Data Size: 4809288 Bytes = 4.6 MiB
Load Address: 20008000
Entry Point: 20008000
Verifying Checksum ... OK
Loading Kernel Image ... OK
OK
Starting kernel ...
Uncompressing Linux... done, booting the kernel.
[ 0.000000] Initializing cgroup subsys cpu
[ 0.000000] Linux version 3.0.8-FriendlyARM (root@kangear) (gcc version 4.5.1 (ctng-1.8.1-FA) ) #2 PREEMPT Sat Aug 17 17:03:05 CST 2013
[ 0.000000] CPU: ARMv7 Processor [412fc082] revision 2 (ARMv7), cr=10c53c7f
[ 0.000000] CPU: VIPT nonaliasing data cache, VIPT aliasing instruction cache
[ 0.000000] Machine: MINI210
[ 0.000000] MINI210: H43 selected
[ 0.000000] Memory policy: ECC disabled, Data cache writeback
[ 0.000000] CPU S5PV210/S5PC110 (id 0x43110220)
[ 0.000000] S3C24XX Clocks, Copyright 2004 Simtec Electronics
[ 0.000000] S5PV210: PLL settings, A=1000000000, M=667000000, E=80000000 V=54000000
[ 0.000000] S5PV210: ARMCLK=1000000000, HCLKM=200000000, HCLKD=166750000
[ 0.000000] HCLKP=133400000, PCLKM=100000000, PCLKD=83375000, PCLKP=66700000
[ 0.000000] sclk_dmc: source is sclk_a2m (0), rate is 200000000
[ 0.000000] sclk_onenand: source is hclk_dsys (1), rate is 166750000
[ 0.000000] uclk1: source is mout_mpll (6), rate is 66700000
[ 0.000000] uclk1: source is mout_mpll (6), rate is 66700000
[ 0.000000] uclk1: source is mout_mpll (6), rate is 66700000
[ 0.000000] uclk1: source is mout_mpll (6), rate is 66700000
[ 0.000000] sclk_mixer: source is sclk_dac (0), rate is 54000000
[ 0.000000] sclk_fimc: source is ext_xtal (0), rate is 24000000
[ 0.000000] sclk_fimc: source is ext_xtal (0), rate is 24000000
[ 0.000000] sclk_fimc: source is ext_xtal (0), rate is 24000000
[ 0.000000] sclk_cam0: source is ext_xtal (0), rate is 24000000
[ 0.000000] sclk_cam1: source is ext_xtal (0), rate is 24000000
[ 0.000000] sclk_fimd: source is ext_xtal (0), rate is 24000000
[ 0.000000] sclk_mmc: source is mout_mpll (6), rate is 47642857
[ 0.000000] sclk_mmc: source is mout_mpll (6), rate is 47642857
[ 0.000000] sclk_mmc: source is mout_epll (7), rate is 80000000
[ 0.000000] sclk_mmc: source is mout_epll (7), rate is 80000000
[ 0.000000] sclk_mfc: source is sclk_a2m (0), rate is 200000000
[ 0.000000] sclk_g2d: source is sclk_a2m (0), rate is 200000000
[ 0.000000] sclk_g3d: source is sclk_a2m (0), rate is 200000000
[ 0.000000] sclk_csis: source is ext_xtal (0), rate is 24000000
[ 0.000000] sclk_spi: source is ext_xtal (0), rate is 24000000
[ 0.000000] sclk_spi: source is ext_xtal (0), rate is 24000000
[ 0.000000] sclk_pwi: source is ext_xtal (0), rate is 24000000
[ 0.000000] sclk_pwm: source is ext_xtal (0), rate is 24000000
[ 0.000000] s5p: 36864 kbytes system memory reserved for mfc at 0x3dbf6000, 0-bank base(0x3dbf6000)
[ 0.000000] s5p: 36864 kbytes system memory reserved for mfc at 0x3b7f6000, 1-bank base(0x00000000)
[ 0.000000] s5p: 6144 kbytes system memory reserved for fimc0 at 0x3b1f6000, 1-bank base(0x00000000)
[ 0.000000] s5p: 16 kbytes system memory reserved for fimc1 at 0x3b1f2000, 1-bank base(0x00000000)
[ 0.000000] s5p: 6144 kbytes system memory reserved for fimc2 at 0x3abf2000, 1-bank base(0x00000000)
[ 0.000000] s5p: 8192 kbytes system memory reserved for jpeg at 0x3a3f2000, 0-bank base(0x3a3f2000)
[ 0.000000] s5p: 7132 kbytes system memory reserved for fimd at 0x39cfb000, 1-bank base(0x00000000)
[ 0.000000] s5p: 8192 kbytes system memory reserved for g2d at 0x394fb000, 0-bank base(0x394fb000)
[ 0.000000] Built 1 zonelists in Zone order, mobility grouping on. Total pages: 102661
[ 0.000000] Kernel command line: console=ttySAC0,115200n8 noinitrd root=/dev/mmcblk0p2 rw rootfstype=ext4 init=/linuxrc lcd=H43 ctp=2
[ 0.000000] PID hash table entries: 2048 (order: 1, 8192 bytes)
[ 0.000000] Dentry cache hash table entries: 65536 (order: 6, 262144 bytes)
[ 0.000000] Inode-cache hash table entries: 32768 (order: 5, 131072 bytes)
[ 0.000000] Memory: 404MB 0M