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」。css

##編譯配置linux3.6.7 #1.修改主目錄下Makefile:html

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
/*node

[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 = (5SZ_1M) , .mask_flags = MTD_CAP_NANDFLASH, }, { .name = "File System", .offset = (7 * SZ_1M), .size = (200SZ_1M) , }, { .name = "User", .offset = MTDPART_OFS_APPEND, .size = MTDPART_SIZ_FULL, } 2.2修改Kconfig文件,參照Mini6410的配置,加入OK6410以下:linux

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以下:shell

obj-$(CONFIG_MACH_OK6410)        += mach-ok6410.o

#3. 修改arch/arm/tools/mach-types文件,加入OK6410的mach-type,這個必須和U-BOOT中的MACH-TYPE一致,這裏選用smdk6410的mach-type:1626。以下:ubuntu

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 menuconfigapp

配置以下: 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-ide

4.3選擇System Type,取消SMDK6400 ,A&W6410,SMDK6410等平臺,只選擇OK6410

4.4 選擇Save an Alternate Configuration File,保存爲.config而後退出。oop

#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驅動了。

##未完

相關文章
相關標籤/搜索