1. 程式人生 > >基於tiny4412的Linux核心移植(支援device tree)(二)

基於tiny4412的Linux核心移植(支援device tree)(二)

https://www.cnblogs.com/pengdonglin137/p/5143516.html
閱讀目錄(Content)

作者資訊
平臺簡介
步驟
回到頂部(go to top)
作者資訊
作者: 彭東林

郵箱:[email protected]

QQ:405728433

回到頂部(go to top)
平臺簡介
開發板: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))

回到頂部(go to top)
步驟
繼續上文。

由於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-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 ([email protected]) (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)
[ 0.000000] .init : 0xc07fe000 - 0xc086c000 ( 440 kB)
[ 0.000000] .data : 0xc086c000 - 0xc08b52f0 ( 293 kB)
[ 0.000000] .bss : 0xc08b8000 - 0xc0906d28 ( 316 kB)
[ 0.000000] SLUB: HWalign=64, Order=0-3, MinObjects=0, CPUs=4, Nodes=1
[ 0.000000] Preemptible hierarchical RCU implementation.
[ 0.000000] Build-time adjustment of leaf fanout to 32.
[ 0.000000] RCU restricting CPUs from NR_CPUS=8 to nr_cpu_ids=4.
[ 0.000000] RCU: Adjusting geometry for rcu_fanout_leaf=32, nr_cpu_ids=4
[ 0.000000] NR_IRQS:16 nr_irqs:16 16
[ 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-310 enabling early BRESP for Cortex-A9
[ 0.000000] L2C-310: enabling full line of zeros but not enabled in Cortex-A9
[ 0.000000] L2C-310 dynamic clock gating enabled, standby mode enabled
[ 0.000000] L2C-310 cache controller enabled, 16 ways, 1024 kB
[ 0.000000] L2C-310: CACHE_ID 0x4100c4c8, AUX_CTRL 0x4e470001
[ 0.000000] Exynos4x12 clocks: sclk_apll = 466666667, sclk_mpll = 800000000
[ 0.000000] sclk_epll = 96000000, sclk_vpll = 108000000, arm_clk = 1400000000
[ 0.000000] Switching to timer-based delay loop, resolution 41ns
[ 0.000000] clocksource: mct-frc: mask: 0xffffffff max_cycles: 0xffffffff, max_idle_ns: 79635851949 ns
[ 0.000003] sched_clock: 32 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=120000)
[ 0.022827] pid_max: default: 32768 minimum: 301
[ 0.027579] Mount-cache hash table entries: 2048 (order: 1, 8192 bytes)
[ 0.034206] Mountpoint-cache hash table entries: 2048 (order: 1, 8192 bytes)
[ 0.041686] CPU: Testing write buffer coherency: ok
[ 0.046640] CPU0: thread -1, cpu 0, socket 10, mpidr 80000a00
[ 0.052536] Setting up static identity map for 0x400082c0 - 0x40008318
[ 0.099784] CPU1: thread -1, cpu 1, socket 10, mpidr 80000a01
[ 0.114774] CPU2: thread -1, cpu 2, socket 10, mpidr 80000a02
[ 0.129775] CPU3: thread -1, cpu 3, socket 10, mpidr 80000a03
[ 0.129815] Brought up 4 CPUs
[ 0.150143] SMP: Total of 4 processors activated (192.00 BogoMIPS).
[ 0.156477] CPU: All CPU(s) started in SVC mode.
[ 0.161676] devtmpfs: initialized
[ 0.173957] VFP support v0.3: implementor 41 architecture 3 part 30 variant 9 rev 4
[ 0.181783] [email protected] has as child subdomain: [email protected]
[ 0.190155] clocksource: jiffies: mask: 0xffffffff max_cycles: 0xffffffff, max_idle_ns: 9556302231375000 ns
[ 0.201755] pinctrl core: initialized pinctrl subsystem
[ 0.207668] NET: Registered protocol family 16
[ 0.213539] DMA: preallocated 256 KiB pool for atomic coherent allocations
[ 0.234740] cpuidle: using governor ladder
[ 0.249735] cpuidle: using governor menu
[ 0.254286] exynos-audss-clk 3810000.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: -2
[ 0.359566] NET: Registered protocol family 2
[ 0.364266] TCP established hash table entries: 8192 (order: 3, 32768 bytes)
[ 0.371286] TCP bind hash table entries: 8192 (order: 5, 163840 bytes)
[ 0.377936] TCP: Hash tables configured (established 8192 bind 8192)
[ 0.384305] UDP hash table entries: 512 (order: 2, 24576 bytes)
[ 0.390258] UDP-Lite hash table entries: 512 (order: 2, 24576 bytes)
[ 0.396795] NET: Registered protocol family 1
[ 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.1 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: 1024 (order: 4, 65536 bytes)
[ 0.465272] romfs: ROMFS MTD © 2007 Red Hat, Inc.
[ 0.470817] bounce: pool size: 64 pages
[ 0.474564] io scheduler noop registered
[ 0.478570] io scheduler deadline registered
[ 0.483072] io scheduler cfq registered (default)
[ 0.492532] dma-pl330 12680000.pdma: Loaded driver for PL330 DMAC-141330
[ 0.499160] dma-pl330 12680000.pdma: DBUFF-32x4bytes Num_Chans-8 Num_Peri-32 Num_Events-32
[ 0.510651] dma-pl330 12690000.pdma: Loaded driver for PL330 DMAC-141330
[ 0.517272] dma-pl330 12690000.pdma: DBUFF-32x4bytes Num_Chans-8 Num_Peri-32 Num_Events-32
[ 0.526575] dma-pl330 12850000.mdma: Loaded driver for PL330 DMAC-141330
[ 0.533201] dma-pl330 12850000.mdma: DBUFF-64x8bytes Num_Chans-8 Num_Peri-1 Num_Events-32
[ 0.601269] Serial: 8250/16550 driver, 4 ports, IRQ sharing disabled
[ 0.608816] 13800000.serial: ttySAC0 at MMIO 0x13800000 (irq = 44, base_baud = 0) is a S3C6400/10
[ 0.617669] console [ttySAC0] enabled
[ 0.617669] console [ttySAC0] enabled
[ 0.624994] bootconsole [earlycon0] disabled
[ 0.624994] bootconsole [earlycon0] disabled
[ 0.633916] 13810000.serial: ttySAC1 at MMIO 0x13810000 (irq = 45, base_baud = 0) is a S3C6400/10
[ 0.634277] 13820000.serial: ttySAC2 at MMIO 0x13820000 (irq = 46, base_baud = 0) is a S3C6400/10
[ 0.634631] 13830000.serial: ttySAC3 at MMIO 0x13830000 (irq = 47, base_baud = 0) is a S3C6400/10
[ 0.639182] [drm] Initialized drm 1.1.0 20060810
[ 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/2 mouse device common for all mice
[ 0.739205] s3c-rtc 10070000.rtc: failed to find rtc source clock
[ 0.744539] s3c-rtc: probe of 10070000.rtc failed with error -2
[ 0.750636] i2c /dev entries driver
[ 0.755967] device-mapper: ioctl: 4.34.0-ioctl (2015-10-28) initialised: [email protected]
[ 0.763141] sdhci: Secure Digital Host Controller Interface driver
[ 0.768478] sdhci: Copyright© 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 10
[ 0.793128] sit: IPv6 over IPv4 tunneling driver
[ 0.797746] NET: Registered protocol family 17
[ 0.801655] NET: Registered protocol family 15
[ 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
[ 0.970206] EXT4-fs (ram0): mounted filesystem wirdered data mode. Opts: (null)
[ 0.970301] VFS: Mounted root (ext4 filesystem) on device 1:0.
[ 0.970419] devtmpfs: mounted
[ 0.970694] Freeing unused kernel memory: 440K (c07fe000 - c086c000)

Please press Enter to activate this console.
[[email protected] ]#
複製程式碼

未完待續。