arm-linux移植手记(三)Linux内核移植

转载:http://blog.csdn.net/w7849516230/article/details/6904677


其实已经弄完了,可以把linux内核以及基于busybox1.16.0制作的文件系统结合。从总的来看是可以用自己的工具链编译生成的u-boot作为Boot Loader,Linux2.6.32.2内核和基于busybox1.16.0的根文件系统,只是还缺少很多相关的驱动,以后要是想继续的话再补全啦!这一过程碰到很多问题,包括自己的粗心和记录不全,当然也包括别人的粗心,让自己也反反复复折腾了好久。令人高兴的是终于可以先舒口气了。
    先说内核的移植,下载了《Mini2440_Linux移植开发实战指南.pdf》,发现《第三章 Linux-2.6.32.2 内核移植详细步骤》讲得很详细,以为自己可以很轻松的照着做就可以了,没想到还是有些问题,现在稍微改些,以生成micro2440记录如下:

    基本的步骤可以是配置为交叉编译,克隆自己的目标平台,识别nand分区,增加识别yaffs文件系统

环境介绍:

内核版本:linux2.6.32.2
Linux平台:虚拟机下Fedora 11  自己原来编译的gcc在debian6下,因此在debian6下也顺利
交叉编译工具:fedora 11 :gcc-4.3.2   debian 6 :gcc 4.4.5  
arm开发板:mini2440(CPU:S3C2440 ,SDRAM:64M,Nor Flash:2M,Nand Flash:256M,网卡:DM9000EP)

这里主要还是debian下的过程,发现有问题的时候在Fedora下测试排除编译器的问题。

    1.下载源码
    linux内核官方网站,下载linux内核2.6.32.2  http://www.kernel.org/pub/linux/kernel/v2.6/
    yaffs源码:http://www.yaffs.net    但是必须用git下载,命令:git clone git://www.aleph1.co.uk/yaffs2 
    2.克隆自己的目标平台
    (1)配置为交叉编译

export KBUILD_BUILDHOST := $(SUBARCH)
ARCH ?= $(SUBARCH)
CROSS_COMPILE ?=
改为
export KBUILD_BUILDHOST := $(SUBARCH)
ARCH ?= arm
CROSS_COMPILE ?= arm-linux-

    (2)增加配置目录
    在 linux-2.6.32.2/arch/arm/configs下增加defconfig配置目录,自己现在还不打算详细的去看配置选项,因此直接拷贝的mini2440的,有兴趣的可以寻找类似自己的平台,然后修改。
    (3)在linux-2.6.32.2/arch/arm/mach-s3c2440下复制smdk2440.c建立micro2440.c,参考的文章已说明:linux2.6.32.2内核直接支持mini2440,防止与原有的冲突而删除。我为了有对照并没有删除match-mini2440,而是新建了 match-micro2440.c,因此,对应的修改其目录下的Makefile:
#obj-$(CONFIG_MACH_MINI2440) += mach-mini2440.o
obj-$(CONFIG_MACH_MINI2440) += mach-micro2440.o
    (4)修改match-micro2440.c
    a.首先对应机器码
    因为我们的micro2440在linux-2.6.32.2/arch/arm/tools/mach_types 文件中是没有机器码的(比较详细理解的可以搜索下或者看参考手册),而且为了与U-boot中的一致,还是保留了mini2440,
找到MACHINE_START( S3C2440, "SMDK2440") , 
修改为MACHINE_START( MINI2440, "Micro2440 test board")
    b.增加头文件
    参考的手册上还是少了些东西的,我这里补上些:
#include <plat/common-smdk.h>
#include <linux/mtd/mtd.h>
#include <linux/mtd/nand.h>
#include <linux/mtd/nand_ecc.h>
#include <linux/mtd/partitions.h>
#include <plat/nand.h>
    c.替换“smdk2440”字符串
    将match-micro2440.c中的smdk2440替换,就是方便自己查看,不替换也不影响(去掉#include <plat/common-smdk.h>,替换了可不去)。
    d.修改时钟
static void __init micro2440_map_io(void)
{
s3c24xx_init_io(micro2440_iodesc, ARRAY_SIZE(micro2440_iodesc));
s3c24xx_init_clocks( 12000000);
s3c24xx_init_uarts(micro2440_uartcfgs, ARRAY_SIZE(micro2440_uartcfgs));
}
    e.增加对nand flash的识别
自己对应着修改有区别的地方吧:
static struct platform_device *micro2440_devices[] __initdata = {
&s3c_device_usb,
&s3c_device_lcd,
&s3c_device_wdt,
&s3c_device_i2c0,
&s3c_device_iis,
&s3c_device_nand, //把nand flash 设备添加到开发板的设备列表结构    
};
分区信息:
/* NAND Flash on micro2440 board */


static struct mtd_partition micro2440_default_nand_part[]  = {
[0] = {
.name = "u-boot",
.size = 0x00040000,
.offset = 0,
},
[1] = {
.name = "param",
.size = 0x00020000,
.offset = 0x00040000,
},
[2] = {
.name = "kernel",
/* 5 megabytes, for a kernel with no modules
* or a uImage with a ramdisk attached */
.size = 0x00500000,
.offset = 0x00060000,
},
[3] = {
.name = "root",
.offset = 0x00560000,
.size = 1024 * 1024 * 1024, //
},
        [4] = {
.name = "nand", //此区域代表了整片的nand flash,主要是预留使用,比如以后可以通过应用程序访
//问读取/dev/mtdblock4 就能实现备份整片nand flash 了。
.offset = 0x00000000,
.size = 1024 * 1024 * 1024, //
},
};


static struct s3c2410_nand_set micro2440_nand_sets[] = {
[0] = {
.name = "nand",
.nr_chips = 1,
.nr_partitions = ARRAY_SIZE(micro2440_default_nand_part),
.partitions = micro2440_default_nand_part,
//.flash_bbt = 1, /* we use u-boot to create a BBT */
},
};


static struct s3c2410_platform_nand micro2440_nand_info  = {
.tacls = 20,
.twrph0 = 60,
.twrph1 = 20,
.nr_sets = ARRAY_SIZE(micro2440_nand_sets),
.sets = micro2440_nand_sets,
.ignore_unset_ecc = 1,
};
修改machineinit函数 
static void __init micro2440_machine_init(void)
{
s3c24xx_fb_set_platdata(&micro2440_fb_info);
s3c_i2c0_set_platdata(NULL);


platform_add_devices(micro2440_devices, ARRAY_SIZE(micro2440_devices));
s3c_device_nand.dev.platform_data = &micro2440_nand_info;


}   
这样一改:#make micro2440_defconfig     #make zImage一下,以及可以被原来supervivi引导了,但是到最后会因为不支持yaffs而无法引导文件系统
    3.增加对yaffs的支持
    在下载的yaffs文件夹下执行patch-ker.sh脚本,其中c 选项表示拷贝,m表示多版本,help中有说明。
./patch-ker.sh c m  ../linux-2.6.32.2
输出:
Updating ../linux-2.6.32.2/fs/Kconfig
Updating ../linux-2.6.32.2/fs/Makefile
    然后,在内核目录下运行make menuconfig,添加对yaffs的支持
File systems  ---> 
    [*] Miscellaneous filesystems  ---> 
          <*>   yaffs2 file system support                                               
          -*-     512 byte / page devices                                                
          [ ]       Use older-style on-NAND data format with pageStatus byte (NEW)       
          [ ]         Lets yaffs do its own ECC (NEW)                                     
          -*-     2048 byte (or larger) / page devices                                    
          [*]       Autoselect yaffs2 format (NEW)                                        
          [ ]       Disable yaffs from doing ECC on tags by default (NEW)                 
          [ ]     Force chunk erase check (NEW)                                          
          [ ]     Empty lost and found on boot (NEW)                                      
          [ ]     Disable yaffs2 block refreshing (NEW)                                   
          [ ]     Disable yaffs2 background processing (NEW)                            
          [*]     Enable yaffs2 xattr support (NEW) 
如果运行过make micro2440_defconfig,则直接make zImage;如果没有,那应该先运行make micro2440_defconfig,再配置yaffs支持,最后make zImage
    如果提示类似fs/yaffs2/Kconfig:131: unknown option "If"的错误,可以把fs/yaffs2/Kconfig文件中的help选项后的说明文字的空行删除。
    如果有类似于:
  CC      fs/yaffs2/yaffs_vfs.o
fs/yaffs2/yaffs_vfs.c: In function 'yaffs_setattr':
fs/yaffs2/yaffs_vfs.c:522: error: implicit declaration of function 'setattr_copy'
fs/yaffs2/yaffs_vfs.c:525: error: implicit declaration of function 'truncate_setsize'
这样的错误,可能是由于在执行patch-ker.sh的脚本时,使用选项s的原因。
如果一切OK,那么将在arch/arm/boot目录下的zImage用k命令下载看看(Boot Loader和文件系统为原厂),我的这样了:
MACH_TYPE = 1999
NOW, Booting Linux......
Uncompressing Linux.............................................................
...................................................................... done, boo
ting the kernel.
Linux version 2.6.32.2 (root@debian6) (gcc version 4.4.5 (GCC) ) #17 Mon Oct 24
11:31:33 CST 2011
CPU: ARM920T [41129200] revision 0 (ARMv4T), cr=c0007177
CPU: VIVT data cache, VIVT instruction cache
Machine: micro2440 board test
ATAG_INITRD is deprecated; please update your bootloader.
Memory policy: ECC disabled, Data cache writeback
CPU S3C2440A (id 0x32440001)
S3C24XX Clocks, (c) 2004 Simtec Electronics
S3C244X: core 405.000 MHz, memory 101.250 MHz, peripheral 50.625 MHz
CLOCK: Slow mode (1.500 MHz), fast, MPLL on, UPLL on
Built 1 zonelists in Zone order, mobility grouping on.  Total pages: 16256
Kernel command line: noinitrd root=/dev/mtdblock3 init=/linuxrc console=ttySAC0
PID hash table entries: 256 (order: -2, 1024 bytes)
Dentry cache hash table entries: 8192 (order: 3, 32768 bytes)
Inode-cache hash table entries: 4096 (order: 2, 16384 bytes)
Memory: 64MB = 64MB total
Memory: 60524KB available (3688K code, 418K data, 132K init, 0K highmem)
SLUB: Genslabs=11, HWalign=32, Order=0-3, MinObjects=0, CPUs=1, Nodes=1
Hierarchical RCU implementation.
NR_IRQS:85
irq: clearing subpending status 00000003
irq: clearing subpending status 00000002
Console: colour dummy device 80x30
console [ttySAC0] enabled
Calibrating delay loop... 201.93 BogoMIPS (lpj=504832)
Mount-cache hash table entries: 512
CPU: Testing write buffer coherency: ok
NET: Registered protocol family 16
S3C2440: Initialising architecture
S3C2440: IRQ Support
S3C24XX DMA Driver, (c) 2003-2004,2006 Simtec Electronics
DMA channel 0 at c4808000, irq 33
DMA channel 1 at c4808040, irq 34
DMA channel 2 at c4808080, irq 35
DMA channel 3 at c48080c0, irq 36
S3C244X: Clock Support, DVS off
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
s3c-i2c s3c2440-i2c: slave address 0x10
s3c-i2c s3c2440-i2c: bus frequency set to 98 KHz
s3c-i2c s3c2440-i2c: i2c-0: S3C I2C adapter
NET: Registered protocol family 2
IP route cache hash table entries: 1024 (order: 0, 4096 bytes)
TCP established hash table entries: 2048 (order: 2, 16384 bytes)
TCP bind hash table entries: 2048 (order: 1, 8192 bytes)
TCP: Hash tables configured (established 2048 bind 2048)
TCP reno registered
NET: Registered protocol family 1
RPC: Registered udp transport module.
RPC: Registered tcp transport module.
RPC: Registered tcp NFSv4.1 backchannel transport module.
JFFS2 version 2.2. (NAND) 漏 2001-2006 Red Hat, Inc.
ROMFS MTD (C) 2007 Red Hat, Inc.
msgmni has been set to 118
alg: No test for stdrng (krng)
io scheduler noop registered
io scheduler anticipatory registered (default)
io scheduler deadline registered
io scheduler cfq registered
Console: switching to colour frame buffer device 60x53
fb0: s3c2410fb frame buffer device
s3c2440-uart.0: s3c2410_serial0 at MMIO 0x50000000 (irq = 70) is a S3C2440
s3c2440-uart.1: s3c2410_serial1 at MMIO 0x50004000 (irq = 73) is a S3C2440
s3c2440-uart.2: s3c2410_serial2 at MMIO 0x50008000 (irq = 76) is a S3C2440
brd: module loaded
S3C24XX NAND Driver, (c) 2004 Simtec Electronics
s3c24xx-nand s3c2440-nand: Tacls=3, 29ns Twrph0=7 69ns, Twrph1=3 29ns
s3c24xx-nand s3c2440-nand: NAND soft ECC
NAND device: Manufacturer ID: 0xec, Chip ID: 0xda (Samsung NAND 256MiB 3,3V 8-bi
t)
Scanning device for bad blocks
Bad eraseblock 384 at 0x000003000000
Bad eraseblock 385 at 0x000003020000
Bad eraseblock 431 at 0x0000035e0000
Bad eraseblock 447 at 0x0000037e0000
Bad eraseblock 950 at 0x0000076c0000
Bad eraseblock 1098 at 0x000008940000
Creating 5 MTD partitions on "NAND 256MiB 3,3V 8-bit":
0x000000000000-0x000000040000 : "u-boot"
0x000000040000-0x000000060000 : "param"
ftl_cs: FTL header not found.
0x000000060000-0x000000560000 : "kernel"
uncorrectable error :
0x000000560000-0x000040560000 : "root"

mtd: partition "root" extends beyond the end of device "NAND 256MiB 3,3V 8-bit"
-- size truncated to 0xfaa0000
ftl_cs: FTL header not found.
0x000000000000-0x000040000000 : "nand"
mtd: partition "nand" extends beyond the end of device "NAND 256MiB 3,3V 8-bit"
-- size truncated to 0x10000000
dm9000 Ethernet Driver, V1.31
ohci_hcd: USB 1.1 'Open' Host Controller (OHCI) Driver
s3c2410-ohci s3c2410-ohci: S3C24XX OHCI
s3c2410-ohci s3c2410-ohci: new USB bus registered, assigned bus number 1
s3c2410-ohci s3c2410-ohci: irq 42, io mem 0x49000000
usb usb1: configuration #1 chosen from 1 choice
hub 1-0:1.0: USB hub found
hub 1-0:1.0: 2 ports detected
usbcore: registered new interface driver libusual
mice: PS/2 mouse device common for all mice
S3C24XX RTC, (c) 2004,2006 Simtec Electronics
i2c /dev entries driver
S3C2410 Watchdog Timer, (c) 2004 Simtec Electronics
s3c2410-wdt s3c2410-wdt: watchdog inactive, reset disabled, irq enabled
cpuidle: using governor ladder
sdhci: Secure Digital Host Controller Interface driver
sdhci: Copyright(c) Pierre Ossman
usbcore: registered new interface driver hiddev
usbcore: registered new interface driver usbhid
usbhid: v2.6:USB HID core driver
Advanced Linux Sound Architecture Driver Version 1.0.21.
No device for DAI UDA134X
No device for DAI s3c24xx-i2s
ALSA device list:
  No soundcards found.
TCP cubic registered
NET: Registered protocol family 17
drivers/rtc/hctosys.c: unable to open rtc device (rtc0)
yaffs: dev is 32505859 name is "mtdblock3" rw
yaffs: passed flags ""
usb 1-1: new full speed USB device using s3c2410-ohci and address 2
usb 1-1: configuration #1 chosen from 1 choice
hub 1-1:1.0: USB hub found
hub 1-1:1.0: 4 ports detected
VFS: Mounted root (yaffs filesystem) on device 31:3.
Freeing init memory: 132K
hwclock: can't open '/dev/misc/rtc': No such file or directory
[01/Jan/1970:00:00:12 +0000] boa: server version Boa/0.94.13
[01/Jan/1970:00:00:12 +0000] boa: server built Mar 26 2009 at 15:28:42.
[01/Jan/1970:00:00:12 +0000] boa: starting server pid=751, port 80


open device leds: No such file or directory
Try to bring eth0 interface up......ifconfig: SIOCGIFFLAGS: No such device
ifconfig: SIOCSIFHWADDR: No such device
ifconfig: SIOCSIFADDR: No such device
route: SIOCADDRT: No such process
Done

你可能感兴趣的:(initramfs文件系统制作)