Linux3.6.7在OK6410下的移植
- 这是在本学期期末整项目时习得的,不知道以后会不会有用。
- 一个天天整js+css+html的,突然弄Linux C,学到的确实不少。
- 遗憾的是,虽然努力了,导师还是觉得我进度慢把这部分砍掉了,唉。
前言
对于我这个新手而言,第一次学习linux,面对庞大的代码,复杂的程序结构和自身对linux知识的严重缺乏,一下子还真不知道该做什么。想想开发板厂家提供的演示程序,其过程是这样:先运行bootloader,bootloade引导linux内核启动,启动后再运行UI程序。对应的程序也有三个分别为u-boot.bin zImage 和rootfs.yaffs2.最初的想法是linux内核启动就是这个zImage,但这个rootfs.yaffs到底是何方妖怪?来这里做甚?初步认为是一个UI(用户界面),后面随着移植的深入,才明白这是一个根文件系统,当然里面包含了UI的应用程序。好吧,一直在linux门外徘徊也不是办法,不管怎样,硬着头皮进去看看再说。于是我决定先编译一个能够启动的linux内核,这个内核对于开发板上一些外部设备的驱动先不去管它,主要达到的目的是能够启动。我当时对“启动”的理解就是能够运行到有一个shell界面。后面对文件系统,根文件系统等等概念稍微理解后才明白“启动”和shell界面还是两个部分。启动包括linux必要的一些初始化,系统的或外部设备的。初始化完成后linux还要通过读取某些文件才能够运行shell程序。而这些文件就包含在这个rootfs.yaffs2中(其实shell程序也包含在这个文件中)。这就涉及到几个概念,文件系统,根文件系统,yaffs2文件系统,yaffs2根文件系统。。。。。在网上稍微了解后,对这几个概念有了初步的理解:linux内核启动后需要读取的这些文件需要放在某个地方(SDRAM或者NANDflash或者是宿主机的硬盘上)中。放在SDRAM中的比如有个ramdisk,它是一个设备,相当于在SDRAM中建立了一个“硬盘”,里面就放好了这些运行文件(初步印象,未进一步了解);放在NAND flash的有cramfs或者yaffs等等,而cramfs比较适合用于Nor flash上,yaffs适合Nand flash上;放在宿主机上的有NFS根文件系统。那么,yaffs2文件系统和yaff2根文件系统不是一回事吗?想想以前用过STM32做一些实验时有个FATFS,好像也是文件系统,当时用这个系统从SD卡中读取图片、文档,而SD卡首先必须格式化为FAT32(FAT)类型。yaffs2文件系统就有点像这个fatfs,我们把它包含在linux程序中意味着linux能够采用这种格式去读取一些文件。yaff2根文件系统就是把包含有linux启动必须的脚本和目录的这些文件采用yaffs2这种格式打包,然后放在Nand flash中。简单理解就相当于先把NAND的某个区域“格式化”为yaffs2格式,再把这些文件放在NAND上面。
最初的理解就是这样了,那么,接下来我们要做的事就是先“启动”,再运行“shell”。
编译配置linux3.6.7
1.修改主目录下Makefile:
ARCH ?= $(SUBARCH) CROSS_COMPILE ?= $(CONFIG_CROSS_COMPILE:"%"=%)改为: ARCH ?= arm CROSS_COMPILE ?= /usr/local/arm/4.5.1/bin/arm-linux-
2.arch/arm/mach-s3c64xx目录下
2.1 拷贝个mach-mini6410.c重命名为mach-ok6410.c并修改其内容:
2.1.1 把所有mini6410字样都替换为ok6410,注意是小写
2.1.2 把所有MINI6410字样都替换为OK6410,注意是大写
2.1.3 修改static struct mtd_partition ok6410_nand_part
/* [0] = { .name = "uboot", .size = SZ_1M, .offset = 0, }, [1] = { .name = "kernel", .size = SZ_2M, .offset = SZ_1M, }, [2] = { .name = "rootfs", .size = MTDPART_SIZ_FULL, .offset = SZ_1M + SZ_2M, },*/
改为
{ .name = "Bootloader", .offset = 0, .size = (2 * SZ_1M), .mask_flags = MTD_CAP_NANDFLASH, }, { .name = "Kernel", .offset = (2 * SZ_1M), .size = (5*SZ_1M) , .mask_flags = MTD_CAP_NANDFLASH, }, { .name = "File System", .offset = (7 * SZ_1M), .size = (200*SZ_1M) , }, { .name = "User", .offset = MTDPART_OFS_APPEND, .size = MTDPART_SIZ_FULL, }
2.2修改Kconfig文件,参照Mini6410的配置,加入OK6410如下:
config MACH_OK6410 bool "OK6410" select CPU_S3C6410 select S3C_DEV_HSMMC select S3C_DEV_HSMMC1 select S3C64XX_SETUP_SDHCI select S3C_DEV_USB_HOST select S3C_DEV_NAND select S3C_DEV_FB select S3C64XX_SETUP_FB_24BPP select SAMSUNG_DEV_ADC select SAMSUNG_DEV_TS help Machine support for the FORLINX OK6410
2.3 修改Makefile文件,参照MINI6410,加入OK6410如下:
obj-$(CONFIG_MACH_OK6410) += mach-ok6410.o
3. 修改arch/arm/tools/mach-types文件,加入OK6410的mach-type,这个必须和U-BOOT中的MACH-TYPE一致,这里选用smdk6410的mach-type:1626。如下:
ok6410 MACH_OK6410 OK6410 1626
4.回到主目录下执行Make menuconfig
root@ubuntu:/home/my# cd linux-3.6.7/ root@ubuntu:/home/my/linux-3.6.7# make menuconfig
配置如下:
4.1 先选择Load an Alternate Configuration File,输入arch/arm/configs/s3c6400_defconfig
4.2 选择General Setup,打开Cross_compiler tool perfix,输入
/usr/local/arm/4.5.1/bin/arm-linux- 4.3选择System Type,取消SMDK6400 ,A&W6410,SMDK6410等平台,只选择OK6410
4.4 选择Save an Alternate Configuration File,保存为.config然后退出。
5.回到主目录下执行make zImage生成zImage文件
6.回到主目录下执行make uImage生成uImage文件
uImage文件是u boot 所支持的文件格式。
6.1 拷贝u-boot-2012.10/tools/目录下的mkimage文件到主机/usr/bin目录下
6.2 修改Entry_Point问题,参考另一篇文章:
Linux3.6.7中Make uImage的load address 和 Entry Point相同的问题
6.3 回到主目录下执行make uImage生成uImage文件
7. 把uImage烧写到NAND中运行,NAND flash放置程序的结构如下:
0000 0000 ---0020 0000 大小2M 放置uboot 0020 0000 ---0070 0000 大小5M 放置uImage 0070 0000 ---0CF0 0000 大小200M 放置 rootfs
结果如下:
NAND read: device 0 offset 0x200000, size 0x500000 5242880 bytes read: OK ## Booting kernel from Legacy Image at 50008000 ... Image Name: Linux-3.6.7 Image Type: ARM Linux Kernel Image (uncompressed) Data Size: 1476616 Bytes = 1.4 MiB Load Address: 50008000 Entry Point: 50008040 Verifying Checksum ... OK XIP Kernel Image ... OK OK Starting kernel ... Uncompressing Linux... done, booting the kernel. Booting Linux on physical CPU 0 Linux version 3.6.7 (root@ubuntu) (gcc version 4.5.1 (ctng-1.8.1-FA) ) #1 Mon Dec 3 15:54:25 CST 2012 CPU: ARMv6-compatible processor [410fb766] revision 6 (ARMv7), cr=00c5387d CPU: PIPT / VIPT nonaliasing data cache, VIPT nonaliasing instruction cache Machine: OK6410 Memory policy: ECC disabled, Data cache writeback CPU S3C6410 (id 0x36410101) S3C24XX Clocks, Copyright 2004 Simtec Electronics camera: no parent clock specified S3C64XX: PLL settings, A=533000000, M=533000000, E=24000000 S3C64XX: HCLK2=266500000, HCLK=133250000, PCLK=66625000 www.it165.net mout_apll: source is fout_apll (1), rate is 533000000 mout_epll: source is epll (1), rate is 24000000 mout_mpll: source is mpll (1), rate is 533000000 usb-bus-host: source is clk_48m (0), rate is 48000000 audio-bus: source is mout_epll (0), rate is 24000000 audio-bus: source is mout_epll (0), rate is 24000000 audio-bus: source is mout_epll (0), rate is 24000000 irda-bus: source is mout_epll (0), rate is 24000000 camera: no parent clock specified CPU: found DTCM0 8k @ 00000000, not enabled CPU: moved DTCM0 8k to fffe8000, enabled CPU: found DTCM1 8k @ 00000000, not enabled CPU: moved DTCM1 8k to fffea000, enabled CPU: found ITCM0 8k @ 00000000, not enabled CPU: moved ITCM0 8k to fffe0000, enabled CPU: found ITCM1 8k @ 00000000, not enabled CPU: moved ITCM1 8k to fffe2000, enabled Built 1 zonelists in Zone order, mobility grouping on. Total pages: 65024 Kernel command line: noinitrd root=/dev/mtdblock2 rootfstype=yaffs2 init=/linuxrc console=ttySAC0,115200 PID hash table entries: 1024 (order: 0, 4096 bytes) Dentry cache hash table entries: 32768 (order: 5, 131072 bytes) Inode-cache hash table entries: 16384 (order: 4, 65536 bytes) Memory: 256MB = 256MB total Memory: 256784k/256784k available, 5360k reserved, 0K highmem Virtual kernel memory layout: vector : 0xffff0000 - 0xffff1000 ( 4 kB) DTCM : 0xfffe8000 - 0xfffec000 ( 16 kB) ITCM : 0xfffe0000 - 0xfffe4000 ( 16 kB) fixmap : 0xfff00000 - 0xfffe0000 ( 896 kB) vmalloc : 0xd0800000 - 0xff000000 ( 744 MB) lowmem : 0xc0000000 - 0xd0000000 ( 256 MB) modules : 0xbf000000 - 0xc0000000 ( 16 MB) .text : 0xc0008000 - 0xc02818ac (2535 kB) .init : 0xc0282000 - 0xc029cb54 ( 107 kB) .data : 0xc029e000 - 0xc02c7f20 ( 168 kB) .bss : 0xc02c8024 - 0xc02f9064 ( 197 kB) SLUB: Genslabs=13, HWalign=32, Order=0-3, MinObjects=0, CPUs=1, Nodes=1 NR_IRQS:246 VIC @f6000000: id 0x00041192, vendor 0x41 VIC @f6010000: id 0x00041192, vendor 0x41 sched_clock: 32 bits at 100 Hz, resolution 10000000ns, wraps every 4294967286ms Console: colour dummy device 80x30 Calibrating delay loop... 353.89 BogoMIPS (lpj=1769472) pid_max: default: 32768 minimum: 301 Mount-cache hash table entries: 512 CPU: Testing write buffer coherency: ok Setting up static identity map for 0x501dd240 - 0x501dd29c DMA: preallocated 256 KiB pool for atomic coherent allocations OK6410: Option string ok6410=0 OK6410: selected LCD display is 480x272 s3c64xx_dma_init: Registering DMA channels PL080: IRQ 73, at d0846000, channels 0..8 PL080: IRQ 74, at d0848000, channels 8..16 S3C6410: Initialising architecture bio: create slab <bio-0> at 0 usbcore: registered new interface driver usbfs usbcore: registered new interface driver hub usbcore: registered new device driver usb ROMFS MTD (C) 2007 Red Hat, Inc. io scheduler noop registered io scheduler deadline registered io scheduler cfq registered (default) start plist test end plist test s3c-fb s3c-fb: window 0: fb Serial: 8250/16550 driver, 4 ports, IRQ sharing disabled s3c6400-uart.0: ttySAC0 at MMIO 0x7f005000 (irq = 69) is a S3C6400/10 console [ttySAC0] enabled s3c6400-uart.1: ttySAC1 at MMIO 0x7f005400 (irq = 70) is a S3C6400/10 s3c6400-uart.2: ttySAC2 at MMIO 0x7f005800 (irq = 71) is a S3C6400/10 s3c6400-uart.3: ttySAC3 at MMIO 0x7f005c00 (irq = 72) is a S3C6400/10 brd: module loaded loop: module loaded S3C24XX NAND Driver, (c) 2004 Simtec Electronics s3c24xx-nand s3c6400-nand: Tacls=4, 30ns Twrph0=8 60ns, Twrph1=6 45ns s3c24xx-nand s3c6400-nand: System booted from NAND s3c24xx-nand s3c6400-nand: NAND soft ECC NAND device: Manufacturer ID: 0xec, Chip ID: 0xd5 (Samsung NAND 2GiB 3,3V 8-bit), page size: 4096, OOB size: 218 No oob scheme defined for oobsize 218 ------------[ cut here ]------------ kernel BUG at drivers/mtd/nand/nand_base.c:3278! Internal error: Oops - BUG: 0 [#1] ARM Modules linked in: CPU: 0 Not tainted (3.6.7 #1) PC is at nand_scan_tail+0x580/0x67c LR is at nand_scan_tail+0x580/0x67c pc : [<c017b410>] lr : [<c017b410>] psr: 60000013 sp : cf82fe98 ip : 00000001 fp : cf80a210 r10: c0181530 r9 : c0181524 r8 : 00000001 r7 : 00000000 r6 : cfa2fa80 r5 : cf80a000 r4 : cf80a210 r3 : c02ae464 r2 : c02ae464 r1 : 20000093 r0 : 00000025 Flags: nZCv IRQs on FIQs on Mode SVC_32 ISA ARM Segment kernel Control: 00c5387d Table: 50004008 DAC: 00000017 Process swapper (pid: 1, stack limit = 0xcf82e268) Stack: (0xcf82fe98 to 0xcf830000) fe80: cf80a000 cf854300 fea0: cfa2fa80 c01816fc 00000000 cfa2f9c0 cf827fc0 00000000 c02f8900 c02f88f8 fec0: c02f8900 c02ad1ac c02ad178 c02c48e8 c029c8b8 c0295ce0 00000000 c01658a0 fee0: c0165888 c0164634 00000000 c02ad178 c02c48e8 c02ad1ac 00000000 00000049 ff00: c0295ce0 c0164844 c02c48e8 cf82ff18 c01647b8 c0162f3c cf803878 cf8238e0 ff20: c02c48e8 c02c48e8 c02c1288 cfa2f9c0 00000000 c0163e60 c0250c40 c02c48e8 ff40: c02c48e8 c02c8040 cf82e000 00000000 00000049 c0164d68 00000000 c0298b6c ff60: c02c8040 cf82e000 00000000 00000049 c0295ce0 c0008704 c02af678 00000000 ff80: c026fb28 c0295ce0 00000049 c0035fac c0253f3c c026f698 00000006 00000006 ffa0: c02af678 c0298b6c 00000006 c0298b4c c02c8040 00000049 c029c8b8 c0282168 ffc0: 00000000 c0282840 00000006 00000006 c0282168 00000000 00000000 c0282758 ffe0: c000f10c 00000013 00000000 00000000 00000000 c000f10c ffffffff ffffffff [<c017b410>] (nand_scan_tail+0x580/0x67c) from [<c01816fc>] (s3c24xx_nand_probe+0x1c0/0x480) [<c01816fc>] (s3c24xx_nand_probe+0x1c0/0x480) from [<c01658a0>] (platform_drv_probe+0x18/0x1c) [<c01658a0>] (platform_drv_probe+0x18/0x1c) from [<c0164634>] (driver_probe_device+0x7c/0x200) [<c0164634>] (driver_probe_device+0x7c/0x200) from [<c0164844>] (__driver_attach+0x8c/0x90) [<c0164844>] (__driver_attach+0x8c/0x90) from [<c0162f3c>] (bus_for_each_dev+0x54/0x80) [<c0162f3c>] (bus_for_each_dev+0x54/0x80) from [<c0163e60>] (bus_add_driver+0x170/0x240) [<c0163e60>] (bus_add_driver+0x170/0x240) from [<c0164d68>] (driver_register+0x78/0x144) [<c0164d68>] (driver_register+0x78/0x144) from [<c0008704>] (do_one_initcall+0x34/0x180) [<c0008704>] (do_one_initcall+0x34/0x180) from [<c0282840>] (kernel_init+0xe8/0x1b0) [<c0282840>] (kernel_init+0xe8/0x1b0) from [<c000f10c>] (kernel_thread_exit+0x0/0x8) Code: 0a000003 e1a01003 e59f00e4 eb017dbe (e7f001f2) ---[ end trace 707c2cde67d9c275 ]--- Kernel panic - not syncing: Attempted to kill init! exitcode=0x0000000b
内核启动了,但由于NAND驱动的问题使得内核初始化没有完成。接下来就是要改NAND驱动了。
未完
郑重声明:本站内容如果来自互联网及其他传播媒体,其版权均属原媒体及文章作者所有。转载目的在于传递更多信息及用于网络分享,并不代表本站赞同其观点和对其真实性负责,也不构成任何其他建议。