平台简介
开发板:tiny4412ADK + S700 + 4GB Flash
要移植的内核版本:Linux-4.4.0 (支持device tree)
u-boot版本:友善之臂自带的 U-Boot 2010.12 (为支持uImage启动,做了少许改动)
busybox版本:busybox 1.25
交叉编译工具链: arm-none-linux-gnueabi-gcc
(gcc version 4.8.3 20140320 (prerelease) (Sourcery CodeBench Lite 2014.05-29))
步骤
继续上文。
由于Linux-4.4.0对tiny4412已经有了很好的支持,所以留给我们的工作就很少了。
一、修改arch/arm/boot/dts/exynos4412-tiny4412.dts
diff --git a/arch/arm/boot/dts/exynos4412-tiny4412.dts b/arch/arm/boot/dts/exynos4412-tiny4412.dts
index 4840bbd..aeca42a 100644
--- a/arch/arm/boot/dts/exynos4412-tiny4412.dts
+++ b/arch/arm/boot/dts/exynos4412-tiny4412.dts
@@ -21,6 +21,7 @@
chosen {
stdout-path = &;serial_0;
+ bootargs = "root=/dev/ram0 rw rootfstype=ext4 console=ttySAC0,115200 init=/linuxrc earlyprintk";
};
memory {
@@ -78,7 +79,7 @@
bus-width = ;
pinctrl-0 = ;
pinctrl-names = "default";
- status = "okay";
+ status = "disabled";
};
&;serial_0 {
这里关键的一点是在chosen中增加了bootargs的设置,上面设置bootargs表示的意思是:根文件系统是ramdisk,可读写,文件系统类型是ext4格式,串口终端使用ttySAC0,波特率是115200,earlyprintk用于打印内核启动早期的一些log,它会把printk的信息打印到一个叫做bootconsole的终端上,在真正的console注册后,bootconsole会被disable掉,要想使用earlyprintk,需要在内核中做相关的配置,这个下面再说。bootargs的设置很灵活,既可以在内核的设备树中设置,也可以在u-boot中设置,需要注意的是:如果在u-boot中设置了bootargs的话,在bootm的时候u-boot会用自己的bootargs来覆盖设备树里的bootargs( do_bootm_linux -> bootm_linux_fdt -> fdt_chosen)。还有一点是把SD卡控制器2给禁掉了,目前SD控制器的初始化还有些问题,会导致内核挂掉,这个以后再解决,因为我们将来先用ramdisk做根文件系统,跟eMMC和SD卡都没有关系。
二、制作ramdisk根文件系统
1、制作ramdisk,首先需要下载busybox的代码,可以从https://busybox.net/downloads/下载,然后编译出根文件系统,具体过程我这里就不写了,网上有很多这方面的资料。我已经制作好了一个可用了文件系统,可以从下面的地址处下载:
https://files.cnblogs.com/files/pengdonglin137/rootfs.tar.gz
下载完成后,解压缩,开始制作ramdisk,制作的过程我写了一个脚本 mk_ramdisk.sh
#!/bin/bash
rm -rf ramdisk*
sudo dd if=/dev/zero of=ramdisk bs=1k count=8192
sudo mkfs.ext4 -F ramdisk
sudo mkdir -p ./initrd
sudo mount -t ext4 ramdisk ./initrd
sudo cp rootfs/* ./initrd -raf
sudo mknod initrd/dev/console c 5 1
sudo mknod initrd/dev/null c 1 3
sudo umount ./initrd
sudo gzip --best -c ramdisk >; ramdisk.gz
sudo mkimage -n "ramdisk" -A arm -O linux -T ramdisk -C gzip -d ramdisk.gz ramdisk.img
最后生成的ramdisk.img就是我们需要的,在上面的脚本中生成的ramdisk镜像也可以作为ramdisk使用,用法下面再说。
下面的链接是一个已经制作好的ramdisk镜像,解压后即可使用:
https://files.cnblogs.com/files/pengdonglin137/ramdisk.zip
2、配置内核,支持ramdisk
make menuconfig
File systems --->;
Second extended fs support
Device Drivers
SCSI device support --->;
SCSI disk support
Block devices --->;
RAM block device support
(16)Default number of RAM disks
(8192) Default RAM disk size (kbytes) (修改为8M)
General setup --->;
[*] Initial RAM filesystem and RAM disk (initramfs/initrd) support
这个exynos的默认配置就已经支持了。
3、配置内核,使其支持tmpfs
$ make menuconfig
File systems --->;
Pseudo filesystems --->
[*] Virtual memory file system support (former shm fs)
[*] Tmpfs POSIX Access Control Lists
这个exynos的默认配置也已经支持了。
三、编译内核
1、首先要设置使用的交叉编译工具链
diff --git a/Makefile b/Makefile
index 70dea02..5d96411 100644
--- a/Makefile
+++ b/Makefile
@@ -248,8 +248,8 @@ SUBARCH := $(shell uname -m | sed -e s/i.86/x86/ -e s/x86_64/x86/
# "make" in the configured kernel build directory always uses that.
# Default value for CROSS_COMPILE is not to prefix executables
# Note: Some architectures assign CROSS_COMPILE in their arch/*/Makefile
-ARCH ?= $(SUBARCH)
-CROSS_COMPILE ?= $(CONFIG_CROSS_COMPILE:"%"=%)
+ARCH ?= arm
+CROSS_COMPILE ?= /root/tiny4412_android5/SysPort/cross_compile/arm-2014.05/bin/arm-none-linux-gnueabi-
2、编译
make exynos_defconfig
make uImage LOADADDR=0x40008000 -j2
生成的uImage在arch/arm/boot下。
四、编译设备树
make dtbs
然后在 arch/arm/boot/dts/会生成tiny4412上用的设备树镜像文件exynos4412-tiny4412.dtb。
五、测试
由于tiny4412的u-boot目前还不支持usb网卡,只能使用dnw来下载,并且tiny4412的u-boot中已经自带了dnw命令了。开发机上运行的dnw的代码可以到下面的链接下载:
https://files.cnblogs.com/files/pengdonglin137/dnw.tar.gz
下载完成后解压,在压缩包里已经有一个编译好的dnw可执行程序。也可执行make,会自动编译生成一个dnw可执行程序,要编译的话,机器上要安装usb相关的库,安装命令如下:
sudo apt-get install libusb-dev
有了dnw,下面开始测试。
启动开发板,进入u-boot命令模式;
下载uImage
在u-boot里执行下载uImage的命令: dnw 0x40600000 (这个地址不唯一)
在开发机中执行:dnw arch/arm/boot/uImage
下载ramdisk
在u-boot里执行下载uImage的命令: dnw 0x41000000 (这个地址不唯一)
在开发机中执行:dnw ramdisk.img
下载设备树镜像
在u-boot里执行下载uImage的命令: dnw 0x42000000 (这个地址不唯一)
在开发机中执行:dnw arch/arm/boot/dts/exynos4412-tiny4412.dtb
启动内核
使用bootm启动内核:bootm 0x40600000 0x41000000 0x42000000
下面是完整的启动log:
U-Boot 2010.12-00000-gb391276-dirty (Jan 17 2016 - 06:03:22) for TINY4412
CPU: S5PC220 [Samsung SOC on SMP Platform Base on ARM CortexA9]
APLL = 1400MHz, MPLL = 800MHz
Board: TINY4412
DRAM: 1023 MiB
vdd_arm: 1.2
vdd_int: 1.0
vdd_mif: 1.1
BL1 version: N/A (TrustZone Enabled BSP)
Checking Boot Mode ... SDMMC
REVISION: 1.1
MMC Device 0: 3803 MB
MMC Device 1: 3728 MB
MMC Device 2: N/A
*** Warning - using default environment
Net: No ethernet found.
Hit any key to stop autoboot: 0
TINY4412 # dnw 0x41000000
OTG cable Connected!
Now, Waiting for DNW to transmit data
Download Done!! Download Address: 0x41000000, Download Filesize:0x27752e
Checksum is being calculated...
Checksum O.K.
TINY4412 # dnw 0x42000000
OTG cable Connected!
Now, Waiting for DNW to transmit data
Download Done!! Download Address: 0x42000000, Download Filesize:0xa53a
Checksum is being calculated.
Checksum O.K.
TINY4412 # dnw 0x40600000
OTG cable Connected!
Now, Waiting for DNW to transmit data
Download Done!! Download Address: 0x40600000, Download Filesize:0x43b5d0
Checksum is being calculated.....
Checksum O.K.
TINY4412 # bootm 0x40600000 0x41000000 0x42000000
## Booting kernel from Legacy Image at 40600000 ...
Image Name: Linux-4.4.0-gbd49c0f-dirty
Image Type: ARM Linux Kernel Image (uncompressed)
Data Size: 4437392 Bytes = 4333 KiB
Load Address: 40008000
Entry Point: 40008000
Verifying Checksum ... OK
## Loading init Ramdisk from Legacy Image at 41000000 ...
Image Name: ramdisk
Image Type: ARM Linux RAMDisk Image (gzip compressed)
Data Size: 2585838 Bytes = 2525 KiB
Load Address: 00000000
Entry Point: 00000000
Verifying Checksum ... OK
## Flattened Device Tree blob at 42000000
Booting using the fdt blob at 0x42000000
Loading Kernel Image ... OK
OK
## Loading init Ramdisk from Legacy Image at 41000000 ...
Image Name: ramdisk
Image Type: ARM Linux RAMDisk Image (gzip compressed)
Data Size: 2585838 Bytes = 2525 KiB
Load Address: 00000000
Entry Point: 00000000
Verifying Checksum ... OK
Loading Ramdisk to 43a84000, end 43cfb4ee ... OK
Loading Device Tree to 413f2000, end 413ff539 ... OK
Starting kernel ...
Uncompressing Linux... done, booting the kernel.
[ 0.000000] Booting Linux on physical CPU 0xa00
[ 0.000000] Linux version 4.4.0-gbd49c0f-dirty (root@ubuntu) (gcc version 4.8.3 20140320 (prerelease) (Sourcery CodeBench Lite 2014.05-29) ) #24 SMP PREEMPT Tue Jan 19 05:39:48 PST 2016
[ 0.000000] CPU: ARMv7 Processor [413fc090] revision 0 (ARMv7), cr=10c5387d
[ 0.000000] CPU: PIPT / VIPT nonaliasing data cache, VIPT aliasing instruction cache
[ 0.000000] Machine model: FriendlyARM TINY4412 board based on Exynos4412
[ 0.000000] bootconsole [earlycon0] enabled
[ 0.000000] cma: Reserved 64 MiB at 0x7bc00000
[ 0.000000] Memory policy: Data cache writealloc
[ 0.000000] Samsung CPU ID: 0xe4412011
[ 0.000000] PERCPU: Embedded 12 pages/cpu @ef79b000 s18816 r8192 d22144 u49152
[ 0.000000] Built 1 zonelists in Zone order, mobility grouping on. Total pages: 260352
[ 0.000000] Kernel command line: root=/dev/ram0 rw rootfstype=ext4 console=ttySAC0,115200 init=/linuxrc earlyprintk
[ 0.000000] PID hash table entries: 4096 (order: 2, 16384 bytes)
[ 0.000000] Dentry cache hash table entries: 131072 (order: 7, 524288 bytes)
[ 0.000000] Inode-cache hash table entries: 65536 (order: 6, 262144 bytes)
[ 0.000000] Memory: 960832K/1047552K available (5863K kernel code, 292K rwdata, 2284K rodata, 440K init, 315K bss, 21184K reserved, 65536K cma-reserved, 195584K highmem)
[ 0.000000] Virtual kernel memory layout:
[ 0.000000] vector : 0xffff0000 - 0xffff1000 ( 4 kB)
[ 0.000000] fixmap : 0xffc00000 - 0xfff00000 (3072 kB)
[ 0.000000] vmalloc : 0xf0800000 - 0xff800000 ( 240 MB)
[ 0.000000] lowmem : 0xc0000000 - 0xf0000000 ( 768 MB)
[ 0.000000] pkmap : 0xbfe00000 - 0xc0000000 ( 2 MB)
[ 0.000000] modules : 0xbf000000 - 0xbfe00000 ( 14 MB)
[ 0.000000] .text : 0xc0008000 - 0xc07fd188 (8149 kB)