此次,仍是把基本的基於我目前最新的Linux源碼進行移植到OK6410吧,同時也寫下我移植過程當中遇到的問題及解決方法,不過有些方法是借鑑網上的,有些是本身加的,會有一些小bug。node
1、基本工做linux
1. 源碼下載 https://www.kernel.org/ ,最好是下載stable版本,不然會有小bug。(我如今調試的是stable版本, linux-3.14.4)git
2. 拷到本身的文件夾下解壓,我下的是.xz後綴的,這樣文件比較小,只是解壓時多一個步驟。shell
$ xz –d linux-3.14.4.tar.xzapp
$ tar xvf linux-3.14.4.taride
3. 解壓完後,進入解壓後的目錄svn
2、源碼修改工具
1. 修改根目錄下的Makefile,針對修改arch和cross_compile,以下:oop
ARCH ?= arm
CROSS_COMPILE ?= arm-linux-
2. 添加相關型號mach文件佈局
目前最新內核已經支持好幾種開發板,咱們先從最基本的6410開始,選擇mini6410,基於mini6410來修改配置,所以,進入arch/arm/mach-s3c64xx目錄,拷貝mach-mini6410.c,重命名爲mach-ok6410.c,下面須要對該文件進行一些修改:
2.1 將代碼中替換爲6410, 以下: mini6410->ok6410; MINI6410->OK6410
2.2 而後修改nand分區信息,修改static struct mtd_partition ok6410_nand_part[],這個修改須要結合你以前移植Uboot及你本身定義的分區佈局。個人是這樣的。
static struct mtd_partition ok6410_nand_part[] = {
[0] = {
.name = "Bootloader",
.size = SZ_1M,
.offset = 0,
.mask_flags = MTD_CAP_NANDFLASH,
},
[1] = {
.name = "Linux Kernel",
.size = (5 * SZ_1M),
.offset = SZ_1M,
.mask_flags = MTD_CAP_NANDFLASH,
},
[2] = {
.name = "File System",
.size = (200 * SZ_1M),
.offset = (6 * SZ_1M),
},
[3] = {
.name = "User",
.offset = MTDPART_OFS_APPEND,
.size = MTDPART_SIZ_FULL,
}
};
2.3 既然咱們添加了一個文件,依據linux添加文件的規則,咱們還修改相對應目錄下Makefile和Kconfig
修改kconfig,參照MINI6410的配置,添加OK6410,以下:
config MACH_OK6410
bool "OK6410"
select CPU_S3C6410
select S3C64XX_SETUP_FB_24BPP
select S3C64XX_SETUP_SDHCI
select S3C64XX_SETUP_IDE
select S3C_DEV_FB
select S3C_DEV_HSMMC
select S3C_DEV_HSMMC1
select S3C_DEV_NAND
select S3C_DEV_USB_HOST
select SAMSUNG_DEV_ADC
select SAMSUNG_DEV_TS
select SAMSUNG_DEV_BACKLIGHT
select SAMSUNG_DEV_IDE
select SAMSUNG_DEV_PWM
help
Machine support for the LXM OK6410
修改Makefile,加入ok6410
# Machine support
obj-$(CONFIG_MACH_ANW6410) += mach-anw6410.o
obj-$(CONFIG_MACH_HMT) += mach-hmt.o
obj-$(CONFIG_MACH_MINI6410) += mach-mini6410.o
obj-$(CONFIG_MACH_OK6410) += mach-ok6410.o
obj-$(CONFIG_MACH_NCP) += mach-ncp.o
obj-$(CONFIG_MACH_REAL6410) += mach-real6410.o
3. 修改arch/arm/tools/mach-types文件,加入OK6410的mach-type,這個必須和U-BOOT中的MACH-TYPE一致,這裏選用smdk6410的mach-type:1626
ok6410 MACH_OK6410 OK6410 1626
4. Menuconfig配置
回到主目錄下,咱們選用針對6400的默認配置,在此基礎上進行配置。複製config下的s3c6400_defconfig到主目錄並重命名爲.config文件
$ cp arch/arm/configs/s3c6400_defconfig ./.config
$ make menuconfig
進入後作以下配置:(這裏說一下:此狀況下刪除你的輸入,須要按delete+shift,按backspace是沒用的)
4.1 選擇General Setup,打開Cross_compiler tool perfix,輸入arm-linux-
4.4 選擇System Type, 取消其餘6410,只選擇OK6410
4.3 選擇Kernel Features , 選擇如下兩項
4.4 爲了調試方便,咱們順便把nand flash的debug也打開,並選擇硬件ECC。
Device Drivers—>Memory Technology Device(MTD) support—>NAND Device Support—>
完成以上配置後,保存退出!
在主目錄下執行,make uImage( 前提是你已經把Uboot tools/下的mkimage工具拷貝到/bin目錄下)
最後在編譯完成後,輸出信息以下:
經過tftp下載到板子上,運行後界面以下:
從上面咱們能夠看出,內核加載地址和入口地址是同樣的:50008000,這是不合理的,入口地址應該是50008000,由於是uImage,須要在入口處添加文件頭。
所以咱們進行以下修改:
修改scripts/下的makefile.lib文件:將UIMAGE_ENTRYADDR ?= $(UIMAGE_LOADADDR) 改成:
IMAGE_ENTRYADDR ?= $(shell echo $(UIMAGE_LOADADDR) | sed -e "s/..$$/40/")
# U-Boot mkimage
# ---------------------------------------------------------------------------
MKIMAGE := $(srctree)/scripts/mkuboot.sh
# SRCARCH just happens to match slightly more than ARCH (on sparc), so reduces
# the number of overrides in arch makefiles
UIMAGE_ARCH ?= $(SRCARCH)
UIMAGE_COMPRESSION ?= $(if $(2),$(2),none)
UIMAGE_OPTS-y ?=
UIMAGE_TYPE ?= kernel
UIMAGE_LOADADDR ?= arch_must_set_this
#UIMAGE_ENTRYADDR ?= $(UIMAGE_LOADADDR)
UIMAGE_ENTRYADDR ?= $(shell echo $(UIMAGE_LOADADDR) | sed -e "s/..$$/40/")
UIMAGE_NAME ?= 'Linux-$(KERNELRELEASE)'
UIMAGE_IN ?= $<
UIMAGE_OUT ?= $@
修改後,再次make uImage, 編譯完後的輸出信息以下:
從上面咱們能夠看出,入口地址已經變爲50008040,
下載到板子上,已經能夠引導內核了。
從log能夠看出,咱們的nand flash並無識別到,由於出錯在這裏:
[06/08-11:25:41:371]s3c24xx-nand s3c6400-nand: failed to get clock
[06/08-11:25:41:371]s3c24xx-nand: probe of s3c6400-nand failed with error –2
爲了方便閱讀,我仍是在下一篇文章寫吧,目前這個問題是須要解決的。
完整啓動log以下:
[06/08-11:25:33:478]U-Boot 2010.03-svn3 (May 06 2014 - 22:13:20) for SMDK6410
[06/08-11:25:33:478]
[06/08-11:25:33:478]*******************************************************
[06/08-11:25:33:492] Welcome to Embedded System
[06/08-11:25:33:494] Base On S3C6410 Devolopment
[06/08-11:25:33:494] Date: 2014/4/15 22:00 PM
[06/08-11:25:33:503]*******************************************************
[06/08-11:25:33:503]
[06/08-11:25:33:504]CPU: S3C6410@533MHz
[06/08-11:25:33:531] Fclk = 533MHz, Hclk = 133MHz, Pclk = 66MHz (ASYNC Mode)
[06/08-11:25:33:531]Board: SMDK6410
[06/08-11:25:33:533]DRAM: 256 MB
[06/08-11:25:33:549]Flash: 0 kB
[06/08-11:25:33:549]NAND Flash: 2048 MB
[06/08-11:25:34:671]********************************************************
[06/08-11:25:34:671]Initial LCD controller
[06/08-11:25:34:684] clk_freq:9 MHz, div_freq:13 ,rea_freq:9 MHz
[06/08-11:25:34:684]
[06/08-11:25:34:685] HBP = 2 HFP = 2 HSW = 41,Hpixs:480
[06/08-11:25:34:685] VBP = 2 VFP = 2 VSW = 10,Vpixs:272
[06/08-11:25:34:703]FrameBuff:57e7a000
[06/08-11:25:34:703] LCD initialization Finished.
[06/08-11:25:34:704]********************************************************
[06/08-11:25:34:724]In: serial
[06/08-11:25:34:724]
[06/08-11:25:34:724]Out: lcd
[06/08-11:25:34:726]
[06/08-11:25:34:726]Err: lcd
[06/08-11:25:34:728]
[06/08-11:25:35:082]Net: DM9000
[06/08-11:25:36:099]Hit any key to stop autoboot: 0
[06/08-11:25:36:099]
[06/08-11:25:36:099]NAND read:
[06/08-11:25:36:100]device 0 offset 0x100000, size 0x500000
[06/08-11:25:36:101]
[06/08-11:25:39:365] 5242880 bytes read: OK
[06/08-11:25:39:365]
[06/08-11:25:39:365]## Booting kernel from Legacy Image at 50008000 ...
[06/08-11:25:39:365]
[06/08-11:25:39:367] Image Name: Linux-3.14.4
[06/08-11:25:39:383]
[06/08-11:25:39:385] Image Type: ARM Linux Kernel Image (uncompressed)
[06/08-11:25:39:402]
[06/08-11:25:39:403] Data Size: 1638488 Bytes = 1.6 MB
[06/08-11:25:39:418]
[06/08-11:25:39:419] Load Address: 50008000
[06/08-11:25:39:443]
[06/08-11:25:39:443] Entry Point: 50008040
[06/08-11:25:39:456]
[06/08-11:25:39:780] Verifying Checksum ... OK
[06/08-11:25:39:798]
[06/08-11:25:39:799] XIP Kernel Image ... OK
[06/08-11:25:39:811]
[06/08-11:25:39:812]OK
[06/08-11:25:39:829]
[06/08-11:25:39:830]
[06/08-11:25:39:830]Starting kernel ...
[06/08-11:25:39:830]
[06/08-11:25:39:842]
[06/08-11:25:39:860]
[06/08-11:25:39:874]
[06/08-11:25:40:162]Uncompressing Linux... done, booting the kernel.
[06/08-11:25:40:960]Booting Linux on physical CPU 0x0
[06/08-11:25:40:972]Linux version 3.14.4 (simiar@Embedded) (gcc version 4.4.3 (ctng-1.6.1) ) #1 Sun Jun 8 11:10:52 CST 2014
[06/08-11:25:40:976]CPU: ARMv6-compatible processor [410fb766] revision 6 (ARMv7), cr=00c5387d
[06/08-11:25:40:984]CPU: PIPT / VIPT nonaliasing data cache, VIPT nonaliasing instruction cache
[06/08-11:25:40:984]Machine: OK6410
[06/08-11:25:40:985]Ignoring unrecognised tag 0x54410008
[06/08-11:25:40:995]Memory policy: Data cache writeback
[06/08-11:25:40:995]CPU S3C6410 (id 0x36410101)
[06/08-11:25:40:995]CPU: found DTCM0 8k @ 00000000, not enabled
[06/08-11:25:40:996]CPU: moved DTCM0 8k to fffe8000, enabled
[06/08-11:25:41:006]CPU: found DTCM1 8k @ 00000000, not enabled
[06/08-11:25:41:006]CPU: moved DTCM1 8k to fffea000, enabled
[06/08-11:25:41:006]CPU: found ITCM0 8k @ 00000000, not enabled
[06/08-11:25:41:017]CPU: moved ITCM0 8k to fffe0000, enabled
[06/08-11:25:41:017]CPU: found ITCM1 8k @ 00000000, not enabled
[06/08-11:25:41:018]CPU: moved ITCM1 8k to fffe2000, enabled
[06/08-11:25:41:027]Built 1 zonelists in Zone order, mobility grouping on. Total pages: 65024
[06/08-11:25:41:038]Kernel command line: root=/dev/nfs nfsroot=192.168.1.100:/home/simiar/share/myproject/ok6410/filesystem/ok6410_fs ip=192.168.1.50:192.168.1.100:192.168.1.1:255.255.255.0::eth0:off console=ttySAC0,115200
[06/08-11:25:41:050]PID hash table entries: 1024 (order: 0, 4096 bytes)
[06/08-11:25:41:061]Dentry cache hash table entries: 32768 (order: 5, 131072 bytes)
[06/08-11:25:41:061]Inode-cache hash table entries: 16384 (order: 4, 65536 bytes)
[06/08-11:25:41:077]Memory: 256464K/262144K available (2173K kernel code, 175K rwdata, 664K rodata, 118K init, 198K bss, 5680K reserved)
[06/08-11:25:41:080]Virtual kernel memory layout:
[06/08-11:25:41:084] vector : 0xffff0000 - 0xffff1000 ( 4 kB)
[06/08-11:25:41:084] DTCM : 0xfffe8000 - 0xfffec000 ( 16 kB)
[06/08-11:25:41:085] ITCM : 0xfffe0000 - 0xfffe4000 ( 16 kB)
[06/08-11:25:41:094] fixmap : 0xfff00000 - 0xfffe0000 ( 896 kB)
[06/08-11:25:41:095] vmalloc : 0xd0800000 - 0xff000000 ( 744 MB)
[06/08-11:25:41:106] lowmem : 0xc0000000 - 0xd0000000 ( 256 MB)
[06/08-11:25:41:106] modules : 0xbf000000 - 0xc0000000 ( 16 MB)
[06/08-11:25:41:107] .text : 0xc0008000 - 0xc02cd674 (2838 kB)
[06/08-11:25:41:117] .init : 0xc02ce000 - 0xc02eb99c ( 119 kB)
[06/08-11:25:41:118] .data : 0xc02ec000 - 0xc0317f00 ( 176 kB)
[06/08-11:25:41:128] .bss : 0xc0318000 - 0xc0349ac8 ( 199 kB)
[06/08-11:25:41:128]SLUB: HWalign=32, Order=0-3, MinObjects=0, CPUs=1, Nodes=1
[06/08-11:25:41:128]NR_IRQS:246
[06/08-11:25:41:139]S3C6410 clocks: apll = 533000000, mpll = 533000000
[06/08-11:25:41:139] epll = 24000000, arm_clk = 533000000
[06/08-11:25:41:140]VIC @f6000000: id 0x00041192, vendor 0x41
[06/08-11:25:41:151]VIC @f6010000: id 0x00041192, vendor 0x41
[06/08-11:25:41:151]sched_clock: 32 bits at 33MHz, resolution 30ns, wraps every 128929599457ns
[06/08-11:25:41:152]Console: colour dummy device 80x30
[06/08-11:25:41:161]Calibrating delay loop... 531.66 BogoMIPS (lpj=2658304)
[06/08-11:25:41:161]pid_max: default: 32768 minimum: 301
[06/08-11:25:41:172]Mount-cache hash table entries: 1024 (order: 0, 4096 bytes)
[06/08-11:25:41:172]Mountpoint-cache hash table entries: 1024 (order: 0, 4096 bytes)
[06/08-11:25:41:173]CPU: Testing write buffer coherency: ok
[06/08-11:25:41:187]Setting up static identity map for 0x50214f90 - 0x50214fec
[06/08-11:25:41:194]VFP support v0.3: implementor 41 architecture 1 part 20 variant b rev 5
[06/08-11:25:41:194]DMA: preallocated 256 KiB pool for atomic coherent allocations
[06/08-11:25:41:195]OK6410: Option string ok6410=0
[06/08-11:25:41:205]OK6410: selected LCD display is 480x272
[06/08-11:25:41:205]S3C6410: Initialising architecture
[06/08-11:25:41:206]bio: create slab <bio-0> at 0
[06/08-11:25:41:217]pl08xdmac dma-pl080s.0: initialized 8 virtual memcpy channels
[06/08-11:25:41:217]pl08xdmac dma-pl080s.0: initialized 16 virtual slave channels
[06/08-11:25:41:227]pl08xdmac dma-pl080s.0: DMA: PL080s rev1 at 0x75000000 irq 73
[06/08-11:25:41:228]pl08xdmac dma-pl080s.1: initialized 8 virtual memcpy channels
[06/08-11:25:41:239]pl08xdmac dma-pl080s.1: initialized 12 virtual slave channels
[06/08-11:25:41:239]pl08xdmac dma-pl080s.1: DMA: PL080s rev1 at 0x75100000 irq 74
[06/08-11:25:41:240]usbcore: registered new interface driver usbfs
[06/08-11:25:41:250]usbcore: registered new interface driver hub
[06/08-11:25:41:251]usbcore: registered new device driver usb
[06/08-11:25:41:261]Switched to clocksource samsung_clocksource_timer
[06/08-11:25:41:262]futex hash table entries: 256 (order: 0, 7168 bytes)
[06/08-11:25:41:262]ROMFS MTD (C) 2007 Red Hat, Inc.
[06/08-11:25:41:263]io scheduler noop registered
[06/08-11:25:41:272]io scheduler deadline registered
[06/08-11:25:41:273]io scheduler cfq registered (default)
[06/08-11:25:41:278]s3c-fb s3c-fb: window 0: fb
[06/08-11:25:41:285]Serial: 8250/16550 driver, 4 ports, IRQ sharing disabled
[06/08-11:25:41:286]s3c6400-uart.0: ttySAC0 at MMIO 0x7f005000 (irq = 69, base_baud = 0) is a S3C6400/10
[06/08-11:25:41:301]console [ttySAC0] enabled
[06/08-11:25:41:302]s3c6400-uart.1: ttySAC1 at MMIO 0x7f005400 (irq = 70, base_baud = 0) is a S3C6400/10
[06/08-11:25:41:305]s3c6400-uart.2: ttySAC2 at MMIO 0x7f005800 (irq = 71, base_baud = 0) is a S3C6400/10
[06/08-11:25:41:311]s3c6400-uart.3: ttySAC3 at MMIO 0x7f005c00 (irq = 72, base_baud = 0) is a S3C6400/10
[06/08-11:25:41:343]brd: module loaded
[06/08-11:25:41:362]loop: module loaded
[06/08-11:25:41:371]s3c24xx-nand s3c6400-nand: failed to get clock
[06/08-11:25:41:371]s3c24xx-nand: probe of s3c6400-nand failed with error -2
[06/08-11:25:41:383]ohci_hcd: USB 1.1 'Open' Host Controller (OHCI) Driver
[06/08-11:25:41:383]ohci-s3c2410: OHCI S3C2410 driver
[06/08-11:25:41:384]s3c2410-ohci s3c2410-ohci: OHCI Host Controller
[06/08-11:25:41:398]s3c2410-ohci s3c2410-ohci: new USB bus registered, assigned bus number 1
[06/08-11:25:41:401]s3c2410-ohci s3c2410-ohci: irq 79, io mem 0x74300000
[06/08-11:25:41:454]s3c2410-ohci s3c2410-ohci: init err (00000000 0000)
[06/08-11:25:41:456]s3c2410-ohci s3c2410-ohci: can't start
[06/08-11:25:41:468]s3c2410-ohci s3c2410-ohci: startup error -75
[06/08-11:25:41:469]s3c2410-ohci s3c2410-ohci: USB bus 1 deregistered
[06/08-11:25:41:470]s3c2410-ohci: probe of s3c2410-ohci failed with error -75
[06/08-11:25:41:479]mousedev: PS/2 mouse device common for all mice
[06/08-11:25:41:479]i2c /dev entries driver
[06/08-11:25:41:487]sdhci: Secure Digital Host Controller Interface driver
[06/08-11:25:41:494]sdhci: Copyright(c) Pierre Ossman
[06/08-11:25:41:495]s3c-sdhci s3c-sdhci.0: clock source 0: mmc_busclk.0 (133250000 Hz)
[06/08-11:25:41:498]s3c-sdhci s3c-sdhci.0: clock source 2: mmc_busclk.2 (24000000 Hz)
[06/08-11:25:41:534]mmc0: SDHCI controller on samsung-hsmmc [s3c-sdhci.0] using ADMA
[06/08-11:25:41:546]s3c-sdhci s3c-sdhci.1: clock source 0: mmc_busclk.0 (133250000 Hz)
[06/08-11:25:41:548]s3c-sdhci s3c-sdhci.1: clock source 2: mmc_busclk.2 (24000000 Hz)
[06/08-11:25:41:585]mmc1: SDHCI controller on samsung-hsmmc [s3c-sdhci.1] using ADMA
[06/08-11:25:41:597]usbcore: registered new interface driver usbhid
[06/08-11:25:41:598]usbhid: USB HID core driver
[06/08-11:25:41:608]drivers/rtc/hctosys.c: unable to open rtc device (rtc0)
[06/08-11:25:41:609]VFS: Cannot open root device "nfs" or unknown-block(0,255): error -6
[06/08-11:25:41:629]Please append a correct "root=" boot option; here are the available partitions:
[06/08-11:25:41:630]Kernel panic - not syncing: VFS: Unable to mount root fs on unknown-block(0,255)
[06/08-11:25:41:636]CPU: 0 PID: 1 Comm: swapper Not tainted 3.14.4 #1
[06/08-11:25:41:636][<c0014238>] (unwind_backtrace) from [<c0011c74>] (show_stack+0x10/0x14)
[06/08-11:25:41:641][<c0011c74>] (show_stack) from [<c0211148>] (panic+0x8c/0x1dc)
[06/08-11:25:41:642][<c0211148>] (panic) from [<c02cf0a4>] (mount_block_root+0x220/0x2e8)
[06/08-11:25:41:652][<c02cf0a4>] (mount_block_root) from [<c02cf330>] (prepare_namespace+0x160/0x1b8)
[06/08-11:25:41:663][<c02cf330>] (prepare_namespace) from [<c02ce580>] (kernel_init_freeable+0x168/0x1ac)
[06/08-11:25:41:664][<c02ce580>] (kernel_init_freeable) from [<c0210b7c>] (kernel_init+0x8/0xec)
[06/08-11:25:41:672][<c0210b7c>] (kernel_init) from [<c000e838>] (ret_from_fork+0x14/0x3c)