S3C6410嵌入式应用平台构建(四)——linux-3.14.4移植到OK6410-(初步启动)
这次,还是把基本的基于我目前最新的Linux源码进行移植到OK6410吧,同时也写下我移植过程中遇到的问题及解决方法,不过有些方法是借鉴网上的,有些是自己加的,会有一些小bug。
一、基本工作
1. 源码下载 https://www.kernel.org/ ,最好是下载stable版本,否则会有小bug。(我现在调试的是stable版本, linux-3.14.4)
2. 拷到自己的文件夹下解压,我下的是.xz后缀的,这样文件比较小,只是解压时多一个步骤。
$ xz –d linux-3.14.4.tar.xz
$ tar xvf linux-3.14.4.tar
3. 解压完后,进入解压后的目录
二、源码修改
1. 修改根目录下的Makefile,针对修改arch和cross_compile,如下:
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及你自己定义的分区布局。我的是这样的。
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, 编译完后的输出信息如下:
下载到板子上,已经可以引导内核了。
从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如下:
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)