linux最新稳定版的内核是2.6.39.2,由于yaffs补丁对它还没有支持,故选用linux-2.6.38.8。
平台:Vmware-7.1.4 ,Ubuntu 10.04
硬件:mini2440
交叉编译器:arm-linux-gcc 4.1.2(openmoko制作)
移植目标:
移植基本内核,支持yaffs文件系统。
移植步骤:
1.下载解压linux-2.6.38.8.tar.bz2,修改Makefile使其支持arm。
#vi Makefile
- ARCH ?= arm
- CROSS_COMPILE ?= arm-linux-
2.修改机器码,以匹配bootloader的机器码
#vi arch/arm/tools/mach-types
- mini2440 MACH_MINI2440 MINI2440 1999
由于现在使用的mini2440开发板,在此可以选择默认的MACHINE_TYPE
3.修改kernel的MACH_TYPE代码引用部分 ,确定kernel的MACH_TYPE,并修改时钟。
#vi arch/arm/mach-s3c2440/mach-smdk2440.c
- //MACHINE_START(S3C2440, "SMDK2440")
改为:
- MACHINE_START(MINI2440, "MXH2440")
显示换成自己的logo,O(∩_∩)O~
修改时钟:
- static void __init smdk2440_map_io(void)
- {
- s3c24xx_init_io(smdk2440_iodesc, ARRAY_SIZE(smdk2440_iodesc));
- s3c24xx_init_clocks(12000000);
- s3c24xx_init_uarts(smdk2440_uartcfgs, ARRAY_SIZE(smdk2440_uartcfgs));
- }
4.修改Nand Flash分区。这里只创建三个分区,其他多余的分区屏蔽掉
#vi arch/arm/plat-s3c24xx/common-smdk.c
- /* NAND parititon from 2.4.18-swl5 */
- static struct mtd_partition smdk_default_nand_part[] = {
- [0] = {
- .name = "mxh_uboot",
- .size = 0x60000,//大小对应与u-boot里的分区大小384k
- .offset = 0,
- },
- [1] = {
- .name = "mxh_kernel",
- .offset = 0x100000,
- .size = 0x500000,//内核区间的大小给5M,起始地址为0x100000,结束地址为0x600000,那么0x60000-->0x100000这段哪里去了?在u-boot里60000-->80000是给param参数区了,我将80000-->100000这段空闲起来了
- },
- [2] = {
- .name = "mxh_yaffs2",
- .offset = 0x600000,
- .size = 0xfa00000,// nandflash的剩余大小为250M
- }
- };
5.接下来做yaffs支持,注意老版本的yaffs已经不支持linux-2.6.36以上内核了,需要最新版本yaffs,
首先下载git,然后用git下载,为内核打上补丁。
#apt-get install git-core
#git clone git://www.aleph1.co.uk/yaffs2
#cd yaffs2
#patch-ker.sh c m [linux-kernel]
6.复制s3c2410的配置文件到当前目录下
#cp arch/arm/configs/s3c2410_defconfig ./mxh_config
7.配置内核选项,加载mxh_config
#make menuconfig
新版yaffs2补丁有点问题,如果我们先选中General setup选项中的
配置时,则文件系统中将不会见到yaffs的配置。反之,如果我们先选择文件系统yaffs2配置时就不会出现这个问题:
所以我选择第二种方法,先配置文件系统,保存配置文件mxh_config.这是我经过一次无意的实验得出的结论,应该这是yaffs的Kconfig和Makefile的问题了,但是我没有深入研究,先移植了再说。
啰嗦了半天,其实我想说的是:
#make menuconfig
-->load mxh_config-->File systems-->Miscellaneous filesystems-->yaffs2 support-->save mxh_config-->Exit
#make menuconfig
-->load mxh_config-->General setup-->Configure standard kernel features (expert users)
8.配置System Type:
9.配置Kernel Features:
选中Use the ARM EABI to compile the kerne
11.save mxh_config
#cp mxh_config .config
12.编译内核
#make zImage
如果没有任何错误,编译出来的内核在arch/arm/boot/目录下,文件zImage即是。
13.u-boot支持uImage,不直接支持zImage,因此还要将zImage转换成uImage格式: 经过编译后的u-boot在根目录下的tools目录中,会有个叫做mkimage的工具,他可以给zImage添加一个header,也就是说使得通常我们编译的内核zImage添加一个数据头信息部分,我们把添加头后的image通常叫uImage,uImage是可以被u-boot直接引导的内核镜像。
mkimage工具的使用介绍如下:
使用: 中括号括起来的是可选的
mkimage [-x] -A arch -O os -T type -C comp -a addr -e ep -n name -d data_file[:data_file...] image
选项: -A:set architecture to 'arch' //用于指定CPU类型,比如ARM -O:set operating system to 'os' //用于指定操作系统,比如Linux -T:set image type to 'type' //用于指定image类型,比如Kernel -C:set compression type 'comp' //指定压缩类型 -a:set load address to 'addr' (hex) //指定image的载入地址 -e:set entry point to 'ep' (hex) //内核的入口地址,一般为image的载入地址+0x40(信息头的大小) -n:set image name to 'name' //image在头结构中的命名 -d:use image data from 'datafile' //无头信息的image文件名 -x:set XIP (execute in place) //设置执行位置
先将u-boot下的tools中的mkimage复制到主机的/usr/local/bin目录下,这样就可以在主机的任何目录下使用该工具了。现在我们进入kernel生成目录(一般是arch/arm/boot目录),然后执行如下命令,就会在该目录下生成一个uImage.img的镜像文件,把他复制到tftp目录下,这就是我们所说的uImage。
mkimage -n 'linux-2.6.38' -A arm -O linux -T kernel -C none -a 0x30008000 -e 0x30008040 -d zImage uImage
为了方便我们可以把上面这句写成一个脚本叫做mkkernel.sh,并给它加上可执行权限
#vi mkkernel.sh
- mkimage -n 'linux-2.6.38' -A arm -O linux -T kernel -C none -a 0x30008000 -e 0x30008040 -d zImage uImage
#chmod +x mkkernel.sh
14.下载uImage运行
- #################################################
- ## boot from NAND flash ##
- ## ##
- ## U-Boot 2010.06 (Jul 01 2011 - 22:10:39) ##
- ## ##
- ## My Blog : http://xurafreedom.cublog.cn ##
- ## ##
- #################################################
- DRAM: 64 MiB
- Flash: 2 MiB
- NAND: 256 MiB
- NAND read: mtdparts variable not set, see 'help mtdparts'
- incorrect device type in logo
- 'logo' is not a number
- Video: 320x240x16 15kHz 52Hz
- In: serial
- Out: serial
- Err: serial
- USB slave is enable!
- Net: dm9000
- nand read 0x30008000 0x100000 0x500000; bootm 0x30008000
- Hit any key to stop autoboot: 0
- NAND read: device 0 offset 0x100000, size 0x500000
- 5242880 bytes read: OK
- ## Booting kernel from Legacy Image at 30008000 ...
- Image Name: linux-2.6.38
- Created: 2011-07-03 2:47:37 UTC
- Image Type: ARM Linux Kernel Image (uncompressed)
- Data Size: 2149028 Bytes = 2 MiB
- Load Address: 30008000
- Entry Point: 30008040
- Verifying Checksum ... OK
- XIP Kernel Image ... OK
- OK
- Starting kernel ...
- Uncompressing Linux... done, booting the kernel.
- Linux version 2.6.38.8 (xura@ubuntu) (gcc version 4.1.2) #1 Sat Jul 2 01:19:36 PDT 2011
- CPU: ARM920T [41129200] revision 0 (ARMv4T), cr=c0007177
- CPU: VIVT data cache, VIVT instruction cache
- Machine: MXH2440
- Memory policy: ECC disabled, Data cache writeback
- CPU S3C2440A (id 0x32440001)
- S3C24XX Clocks, Copyright 2004 Simtec Electronics
- S3C244X: core 400.000 MHz, memory 100.000 MHz, peripheral 50.000 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/mtdblock2 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: 60472k/60472k available, 5064k reserved, 0K highmem
- Virtual kernel memory layout:
- vector : 0xffff0000 - 0xffff1000 ( 4 kB)
- fixmap : 0xfff00000 - 0xfffe0000 ( 896 kB)
- DMA : 0xffc00000 - 0xffe00000 ( 2 MB)
- vmalloc : 0xc4800000 - 0xf6000000 ( 792 MB)
- lowmem : 0xc0000000 - 0xc4000000 ( 64 MB)
- modules : 0xbf000000 - 0xc0000000 ( 16 MB)
- .init : 0xc0008000 - 0xc0029000 ( 132 kB)
- .text : 0xc0029000 - 0xc0402404 (3942 kB)
- .data : 0xc0404000 - 0xc0429fc0 ( 152 kB)
- NR_IRQS:85
- irq: clearing subpending status 00000002
- Console: colour dummy device 80x30
- console [ttySAC0] enabled
- Calibrating delay loop... 199.47 BogoMIPS (lpj=498688)
- pid_max: default: 32768 minimum: 301
- Mount-cache hash table entries: 512
- CPU: Testing write buffer coherency: ok
- gpiochip_add: gpios 288..303 (GPIOK) failed to register
- gpiochip_add: gpios 320..334 (GPIOL) failed to register
- gpiochip_add: gpios 352..353 (GPIOM) failed to register
- NET: Registered protocol family 16
- S3C Power Management, Copyright 2004 Simtec Electronics
- S3C2440: Initialising architecture
- S3C2440: IRQ Support
- S3C244X: Clock Support, DVS off
- bio: create slab <bio-0> at 0
- i2c-core: driver [pcf50633] using legacy suspend method
- i2c-core: driver [pcf50633] using legacy resume method
- SCSI subsystem initialized
- 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 97 KHz
- s3c-i2c s3c2440-i2c: i2c-0: S3C I2C adapter
- Advanced Linux Sound Architecture Driver Version 1.0.23.
- 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
- UDP hash table entries: 256 (order: 0, 4096 bytes)
- UDP-Lite hash table entries: 256 (order: 0, 4096 bytes)
- NET: Registered protocol family 1
- RPC: Registered udp transport module.
- RPC: Registered tcp transport module.
- RPC: Registered tcp NFSv4.1 backchannel transport module.
- NetWinder Floating Point Emulator V0.97 (extended precision)
- JFFS2 version 2.2. (NAND) (SUMMARY) ?? 2001-2006 Red Hat, Inc.
- ROMFS MTD (C) 2007 Red Hat, Inc.
- msgmni has been set to 118
- io scheduler noop registered
- io scheduler deadline registered
- io scheduler cfq registered (default)
- Console: switching to colour frame buffer device 30x40
- fb0: s3c2410fb frame buffer device
- Serial: 8250/16550 driver, 4 ports, IRQ sharing enabled
- s3c2440-uart.0: ttySAC0 at MMIO 0x50000000 (irq = 70) is a S3C2440
- s3c2440-uart.1: ttySAC1 at MMIO 0x50004000 (irq = 73) is a S3C2440
- s3c2440-uart.2: ttySAC2 at MMIO 0x50008000 (irq = 76) is a S3C2440
- lp: driver loaded but no devices found
- ppdev: user-space parallel port driver
- brd: module loaded
- loop: module loaded
- Uniform Multi-Platform E-IDE driver
- ide-gd driver 1.18
- ide-cd driver 5.00
- S3C24XX NAND Driver, (c) 2004 Simtec Electronics
- s3c24xx-nand s3c2440-nand: Tacls=2, 20ns Twrph0=6 60ns, Twrph1=2 20ns
- s3c24xx-nand s3c2440-nand: NAND soft ECC
- NAND device: Manufacturer ID: 0xec, Chip ID: 0xda (Samsung NAND 256MiB 3,3V 8-bit)
- Scanning device for bad blocks
- Bad eraseblock 1461 at 0x00000b6a0000
- Creating 3 MTD partitions on "NAND":
- 0x000000000000-0x000000060000 : "mxh_uboot"
- 0x000000100000-0x000000600000 : "mxh_kernel"
- 0x000000600000-0x000010000000 : "mxh_yaffs2"
- dm9000 Ethernet Driver, V1.31
- usbmon: debugfs is not available
- 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
- hub 1-0:1.0: USB hub found
- hub 1-0:1.0: 2 ports detected
- usbcore: registered new interface driver libusual
- usbcore: registered new interface driver usbserial
- USB Serial support registered for generic
- usbcore: registered new interface driver usbserial_generic
- usbserial: USB Serial Driver core
- USB Serial support registered for FTDI USB Serial Device
- usbcore: registered new interface driver ftdi_sio
- ftdi_sio: v1.6.0:USB FTDI Serial Converters Driver
- USB Serial support registered for pl2303
- usbcore: registered new interface driver pl2303
- pl2303: Prolific PL2303 USB to serial adaptor driver
- mousedev: PS/2 mouse device common for all mice
- S3C24XX RTC, (c) 2004,2006 Simtec Electronics
- S3C2410 Watchdog Timer, (c) 2004 Simtec Electronics
- s3c2410-wdt s3c2410-wdt: watchdog inactive, reset disabled, irq enabled
- 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 32505858 name is "mtdblock2" rw
- yaffs: passed flags ""
- VFS: Mounted root (yaffs filesystem) on device 31:2.
- Freeing init memory: 132K
- Failed to execute /linuxrc. Attempting defaults...
- Kernel panic - not syncing: No init found. Try passing init= option to kernel. See Linux Documentation/init.txt for guidance.
- [<c003a410>] (unwind_backtrace+0x0/0xe4) from [<c0048804>] (panic+0x54/0x18c)
- [<c0048804>] (panic+0x54/0x18c) from [<c002958c>] (init_post+0x9c/0xc4)
- [<c002958c>] (init_post+0x9c/0xc4) from [<c000888c>] (kernel_init+0xfc/0x138)
- [<c000888c>] (kernel_init+0xfc/0x138) from [<c0035c78>] (kernel_thread_exit+0x0/0x8)
还没有文件系统,故下面出现错误,移植yaffs2文件系统,http://blog.chinaunix.net/space.php?uid=20788517&do=blog&id=34708 |