作者信息

作者: 彭东林

邮箱:[email protected]

QQ:405728433

平台简介

开发板: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 = <;4>;
        pinctrl-0 = <;&sd2_clk &sd2_cmd &sd2_cd &sd2_bus4>;
        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/下载,然后编译出根文件系统,具体过程我这里就不写了,网上有很多这方面的资料。我已经制作好了一个可用了文件系统,可以从下面的地址处下载:

http://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镜像,解压后即可使用:

http://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的代码可以到下面的链接下载:

http://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--gb391276-dirty (Jan   - ::) for TINY4412

CPU:    S5PC220 [Samsung SOC on SMP Platform Base on ARM CortexA9]
APLL = 1400MHz, MPLL = 800MHz Board: TINY4412
DRAM: 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 : MB
MMC Device : MB
MMC Device : N/A
*** Warning - using default environment Net: No ethernet found.
Hit any key to stop autoboot:
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 ...
Image Name: Linux-4.4.-gbd49c0f-dirty
Image Type: ARM Linux Kernel Image (uncompressed)
Data Size: Bytes = KiB
Load Address:
Entry Point:
Verifying Checksum ... OK
## Loading init Ramdisk from Legacy Image at ...
Image Name: ramdisk
Image Type: ARM Linux RAMDisk Image (gzip compressed)
Data Size: Bytes = KiB
Load Address:
Entry Point:
Verifying Checksum ... OK
## Flattened Device Tree blob at
Booting using the fdt blob at 0x42000000
Loading Kernel Image ... OK
OK
## Loading init Ramdisk from Legacy Image at ...
Image Name: ramdisk
Image Type: ARM Linux RAMDisk Image (gzip compressed)
Data Size: Bytes = KiB
Load Address:
Entry Point:
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.-gbd49c0f-dirty (root@ubuntu) (gcc version 4.8. (prerelease) (Sourcery CodeBench Lite 2014.05-) ) # SMP PREEMPT Tue Jan :: PST
[ 0.000000] CPU: ARMv7 Processor [413fc090] revision (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 MiB at 0x7bc00000
[ 0.000000] Memory policy: Data cache writealloc
[ 0.000000] Samsung CPU ID: 0xe4412011
[ 0.000000] PERCPU: Embedded pages/cpu @ef79b000 s18816 r8192 d22144 u49152
[ 0.000000] Built zonelists in Zone order, mobility grouping on. Total pages:
[ 0.000000] Kernel command line: root=/dev/ram0 rw rootfstype=ext4 console=ttySAC0, init=/linuxrc earlyprintk
[ 0.000000] PID hash table entries: (order: , bytes)
[ 0.000000] Dentry cache hash table entries: (order: , bytes)
[ 0.000000] Inode-cache hash table entries: (order: , 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 ( kB)
[ 0.000000] fixmap : 0xffc00000 - 0xfff00000 ( kB)
[ 0.000000] vmalloc : 0xf0800000 - 0xff800000 ( MB)
[ 0.000000] lowmem : 0xc0000000 - 0xf0000000 ( MB)
[ 0.000000] pkmap : 0xbfe00000 - 0xc0000000 ( MB)
[ 0.000000] modules : 0xbf000000 - 0xbfe00000 ( MB)
[ 0.000000] .text : 0xc0008000 - 0xc07fd188 ( kB)
[ 0.000000] .init : 0xc07fe000 - 0xc086c000 ( kB)
[ 0.000000] .data : 0xc086c000 - 0xc08b52f0 ( kB)
[ 0.000000] .bss : 0xc08b8000 - 0xc0906d28 ( kB)
[ 0.000000] SLUB: HWalign=, Order=-, MinObjects=, CPUs=, Nodes=
[ 0.000000] Preemptible hierarchical RCU implementation.
[ 0.000000] Build-time adjustment of leaf fanout to .
[ 0.000000] RCU restricting CPUs from NR_CPUS= to nr_cpu_ids=.
[ 0.000000] RCU: Adjusting geometry for rcu_fanout_leaf=, nr_cpu_ids=
[ 0.000000] NR_IRQS: nr_irqs:
[ 0.000000] GIC physical location is 0x10490000
[ 0.000000] L2C: platform modifies aux control register: 0x02070000 ->; 0x3e470001
[ 0.000000] L2C: platform provided aux values permit register corruption.
[ 0.000000] L2C: DT/platform modifies aux control register: 0x02070000 ->; 0x3e470001
[ 0.000000] L2C- enabling early BRESP for Cortex-A9
[ 0.000000] L2C-: enabling full line of zeros but not enabled in Cortex-A9
[ 0.000000] L2C- dynamic clock gating enabled, standby mode enabled
[ 0.000000] L2C- cache controller enabled, ways, kB
[ 0.000000] L2C-: CACHE_ID 0x4100c4c8, AUX_CTRL 0x4e470001
[ 0.000000] Exynos4x12 clocks: sclk_apll = , sclk_mpll =
[ 0.000000] sclk_epll = , sclk_vpll = , arm_clk =
[ 0.000000] Switching to timer-based delay loop, resolution 41ns
[ 0.000000] clocksource: mct-frc: mask: 0xffffffff max_cycles: 0xffffffff, max_idle_ns: ns
[ 0.000003] sched_clock: bits at 24MHz, resolution 41ns, wraps every 89478484971ns
[ 0.008035] Console: colour dummy device 80x30
[ 0.012425] Calibrating delay loop (skipped), value calculated using timer frequency.. 48.00 BogoMIPS (lpj=)
[ 0.022827] pid_max: default: minimum:
[ 0.027579] Mount-cache hash table entries: (order: , bytes)
[ 0.034206] Mountpoint-cache hash table entries: (order: , bytes)
[ 0.041686] CPU: Testing write buffer coherency: ok
[ 0.046640] CPU0: thread -, cpu , socket , mpidr 80000a00
[ 0.052536] Setting up static identity map for 0x400082c0 - 0x40008318
[ 0.099784] CPU1: thread -, cpu , socket , mpidr 80000a01
[ 0.114774] CPU2: thread -, cpu , socket , mpidr 80000a02
[ 0.129775] CPU3: thread -, cpu , socket , mpidr 80000a03
[ 0.129815] Brought up CPUs
[ 0.150143] SMP: Total of processors activated (192.00 BogoMIPS).
[ 0.156477] CPU: All CPU(s) started in SVC mode.
[ 0.161676] devtmpfs: initialized
[ 0.173957] VFP support v0.: implementor architecture part variant rev
[ 0.181783] lcd0-power-domain@10023C80 has as child subdomain: tv-power-domain@10023C20.
[ 0.190155] clocksource: jiffies: mask: 0xffffffff max_cycles: 0xffffffff, max_idle_ns: ns
[ 0.201755] pinctrl core: initialized pinctrl subsystem
[ 0.207668] NET: Registered protocol family
[ 0.213539] DMA: preallocated KiB pool for atomic coherent allocations
[ 0.234740] cpuidle: using governor ladder
[ 0.249735] cpuidle: using governor menu
[ 0.254286] exynos-audss-clk .clock-controller: setup completed
[ 0.306823] SCSI subsystem initialized
[ 0.310855] usbcore: registered new interface driver usbfs
[ 0.316329] usbcore: registered new interface driver hub
[ 0.321714] usbcore: registered new device driver usb
[ 0.327898] Advanced Linux Sound Architecture Driver Initialized.
[ 0.335087] clocksource: Switched to clocksource mct-frc
[ 0.349988] missing cooling_device property
[ 0.354099] failed to build thermal zone cpu-thermal: -
[ 0.359566] NET: Registered protocol family
[ 0.364266] TCP established hash table entries: (order: , bytes)
[ 0.371286] TCP bind hash table entries: (order: , bytes)
[ 0.377936] TCP: Hash tables configured (established bind )
[ 0.384305] UDP hash table entries: (order: , bytes)
[ 0.390258] UDP-Lite hash table entries: (order: , bytes)
[ 0.396795] NET: Registered protocol family
[ 0.401289] RPC: Registered named UNIX socket transport module.
[ 0.407131] RPC: Registered udp transport module.
[ 0.411902] RPC: Registered tcp transport module.
[ 0.416674] RPC: Registered tcp NFSv4. backchannel transport module.
[ 0.423325] Trying to unpack rootfs image as initramfs...
[ 0.429054] rootfs image is not initramfs (no cpio magic); looks like an initrd
[ 0.442728] Freeing initrd memory: 2528K (c3a84000 - c3cfc000)
[ 0.449900] futex hash table entries: (order: , bytes)
[ 0.465272] romfs: ROMFS MTD (C) Red Hat, Inc.
[ 0.470817] bounce: pool size: pages
[ 0.474564] io scheduler noop registered
[ 0.478570] io scheduler deadline registered
[ 0.483072] io scheduler cfq registered (default)
[ 0.492532] dma-pl330 .pdma: Loaded driver for PL330 DMAC-
[ 0.499160] dma-pl330 .pdma: DBUFF-32x4bytes Num_Chans- Num_Peri- Num_Events-
[ 0.510651] dma-pl330 .pdma: Loaded driver for PL330 DMAC-
[ 0.517272] dma-pl330 .pdma: DBUFF-32x4bytes Num_Chans- Num_Peri- Num_Events-
[ 0.526575] dma-pl330 .mdma: Loaded driver for PL330 DMAC-
[ 0.533201] dma-pl330 .mdma: DBUFF-64x8bytes Num_Chans- Num_Peri- Num_Events-
[ 0.601269] Serial: / driver, ports, IRQ sharing disabled
[ 0.608816] .serial: ttySAC0 at MMIO 0x13800000 (irq = , base_baud = ) is a S3C6400/
[ 0.617669] console [ttySAC0] enabled
[ 0.617669] console [ttySAC0] enabled
[ 0.624994] bootconsole [earlycon0] disabled
[ 0.624994] bootconsole [earlycon0] disabled
[ 0.633916] .serial: ttySAC1 at MMIO 0x13810000 (irq = , base_baud = ) is a S3C6400/
[ 0.634277] .serial: ttySAC2 at MMIO 0x13820000 (irq = , base_baud = ) is a S3C6400/
[ 0.634631] .serial: ttySAC3 at MMIO 0x13830000 (irq = , base_baud = ) is a S3C6400/
[ 0.639182] [drm] Initialized drm 1.1.
[ 0.652946] brd: module loaded
[ 0.657821] loop: module loaded
[ 0.658627] usbcore: registered new interface driver r8152
[ 0.658763] usbcore: registered new interface driver asix
[ 0.659855] usbcore: registered new interface driver ax88179_178a
[ 0.665958] usbcore: registered new interface driver cdc_ether
[ 0.671772] usbcore: registered new interface driver smsc75xx
[ 0.677506] usbcore: registered new interface driver smsc95xx
[ 0.683217] usbcore: registered new interface driver net1080
[ 0.688858] usbcore: registered new interface driver cdc_subset
[ 0.694760] usbcore: registered new interface driver zaurus
[ 0.700345] usbcore: registered new interface driver cdc_ncm
[ 0.706295] ehci_hcd: USB 2.0 'Enhanced' Host Controller (EHCI) Driver
[ 0.712416] ehci-exynos: EHCI EXYNOS driver
[ 0.716700] ohci_hcd: USB 1.1 'Open' Host Controller (OHCI) Driver
[ 0.722742] ohci-exynos: OHCI EXYNOS driver
[ 0.727264] usbcore: registered new interface driver usb-storage
[ 0.733431] mousedev: PS/ mouse device common for all mice
[ 0.739205] s3c-rtc .rtc: failed to find rtc source clock
[ 0.744539] s3c-rtc: probe of .rtc failed with error -
[ 0.750636] i2c /dev entries driver
[ 0.755967] device-mapper: ioctl: 4.34.-ioctl (--) initialised: [email protected]
[ 0.763141] sdhci: Secure Digital Host Controller Interface driver
[ 0.768478] sdhci: Copyright(c) Pierre Ossman
[ 0.772952] Synopsys Designware Multimedia Card Interface Driver
[ 0.780793] usbcore: registered new interface driver usbhid
[ 0.784347] usbhid: USB HID core driver
[ 0.791116] NET: Registered protocol family
[ 0.793128] sit: IPv6 over IPv4 tunneling driver
[ 0.797746] NET: Registered protocol family
[ 0.801655] NET: Registered protocol family
[ 0.806225] Registering SWP/SWPB emulation handler
[ 0.812058] hctosys: unable to open rtc device (rtc0)
[ 0.827998] ALSA device list:
[ 0.828035] No soundcards found.
[ 0.828678] RAMDISK: gzip image found at block
[ 0.970206] EXT4-fs (ram0): mounted filesystem wirdered data mode. Opts: (null)
[ 0.970301] VFS: Mounted root (ext4 filesystem) on device :.
[ 0.970419] devtmpfs: mounted
[ 0.970694] Freeing unused kernel memory: 440K (c07fe000 - c086c000) Please press Enter to activate this console.
[root@tiny4412 ]#
未完待续。
05-11 17:25