1,下载源码和补丁
#
AT91Bootstrap1.14.zip
arm-2008q1-126-arm-none-linux-gnueabi-i686-pc-linux-gnu.tar.bz2
u-boot-1.3.4-exp.3.diff
u-boot-1.3.4.tar.bz
22.6.24.at91.2-exp.patch.gz
2.6.24-at91.patch.gz
linux-2.6.24 linux-2.6.24.tar.bz2
2,建立工作目录文件夹,解压源码和打入相应的补丁:
3,开始编译源码:
3.1:编译一级启动代码:
# unzip AT91Bootstrap1.14.zip
# ls
AT91Bootstrap1.14.zip Bootstrap-v1.14
# cd Bootstrap-v1.14/board/at91sam9260ek/nandflash/
# ls
at91sam9260ek.h debug.o main.o nandflash_at91sam9260ek.elf pmc.o udiv.o
at91sam9260ek.o div0.o Makefile nandflash_at91sam9260ek.map sdramc.o _udivsi3.o
crt0_gnu.o gpio.o nandflash_at91sam9260ek.bin nandflash.o string.o _umodsi3.o
# make clean
rm -f *.o *.bin *.elf *.map
# ls
at91sam9260ek.h Makefile
因为9260编译后必须使这个烧入文件小于4K,所以要针对Makefile做修改:
# vim Makefile
修改下面这个地方:
OBJDUMP=$(CROSS_COMPILE)objdump
CCFLAGS=-g -mcpu=arm926ej-s -O1 -Wall -D$(TARGET) -I$(INCL)
ASFLAGS=-g -mcpu=arm926ej-s -c -O1 -Wall -D$(TARGET) -I$(INCL) -DTOP_OF_MEM=$(TOP_OF_MEMORY)
# cd include/
# ls
AT91CAP9_inc.h AT91SAM9263_inc.h AT91SAM9XE128_inc.h debug.h nandflash.h part.h sdramc.h
AT91SAM9260_inc.h AT91SAM9G45_inc.h dataflash.h gpio.h nand_ids.h pmc.h
AT91SAM9261_inc.h AT91SAM9RL_inc.h ddramc.h main.h norflash.h sddrc.h
修改这个文件:
# vim nand_ids.h
#ifndef _NAND_IDS_H
#define _NAND_IDS_H
#include "../include/nandflash.h"
/* Supported NandFlash devices */
static struct SNandInitInfo NandFlash_InitInfo[] = {
{0xecda, 0x800, 0x20000, 0x800, 0x40, 0x0, "K9F2G08U0M\0"},
//{0xecaa, 0x800, 0x20000, 0x800, 0x40, 0x0, "K9F2G08R0A\0"},
//{0x2cca, 0x800, 0x20000, 0x800, 0x40, 0x1, "MT29F2G16AAB\0"},
//{0x2cda, 0x800, 0x20000, 0x800, 0x40, 0x0, "MT29F2G08AAC\0"},
//{0x20aa, 0x800, 0x20000, 0x800, 0x40, 0x0, "STMNAND02GR3B\0"},
//{0x2caa, 0x800, 0x20000, 0x800, 0x40, 0x0, "MT29F2G08ABD\0"},
{0,}
};
#endif
屏蔽掉你不用的nandflash,这样就可以使编译最后的大小小于4K!
# make
# ls -l
total 140
-rwxrwxrwx 1 root root 5118 2008-12-04 19:18 at91sam9260ek.h
-rw-r--r-- 1 root root 5652 2010-05-18 21:26 at91sam9260ek.o
-rw-r--r-- 1 root root 2604 2010-05-18 21:26 crt0_gnu.o
-rw-r--r-- 1 root root 992 2010-05-18 21:26 debug.o
-rw-r--r-- 1 root root 2068 2010-05-18 21:26 div0.o
-rw-r--r-- 1 root root 8336 2010-05-18 21:26 gpio.o
-rw-r--r-- 1 root root 2472 2010-05-18 21:26 main.o
-rwxr--r-- 1 nobody nogroup 3219 2010-05-18 21:22 Makefile
-rwxr-xr-x 1 root root 3972 2010-05-18 21:26 nandflash_at91sam9260ek.bin
-rwxr-xr-x 1 root root 27381 2010-05-18 21:26 nandflash_at91sam9260ek.elf
-rw-r--r-- 1 root root 18270 2010-05-18 21:26 nandflash_at91sam9260ek.map
-rw-r--r-- 1 root root 9924 2010-05-18 21:26 nandflash.o
-rw-r--r-- 1 root root 4092 2010-05-18 21:26 pmc.o
-rw-r--r-- 1 root root 3864 2010-05-18 21:26 sdramc.o
-rw-r--r-- 1 root root 3448 2010-05-18 21:26 string.o
-rw-r--r-- 1 root root 4920 2010-05-18 21:26 udiv.o
-rw-r--r-- 1 root root 1752 2010-05-18 21:26 _udivsi3.o
-rw-r--r-- 1 root root 1828 2010-05-18 21:26 _umodsi3.o
可以看到nandflash_at91sam9260ek.bin小于4K!
将编译出来的文件写入nandflash的0x00000000里面去:
3.2:编译u-boot:
# ls -l
total 7668
-rw-rw-rw- 1 root root 111418 2009-10-23 10:08 u-boot-1.3.4-exp.3.diff
-rw-rw-rw- 1 root root 7714456 2009-05-11 09:51 u-boot-1.3.4.tar.bz2
# tar -xjvf u-boot-1.3.4.tar.bz2
# ls
u-boot-1.3.4 u-boot-1.3.4-exp.3.diff u-boot-1.3.4.tar.bz2
进入u-boot目录:
# cd u-boot-1.3.4
将补丁复制到u-boot目录里:
# cp ../u-boot-1.3.4-exp.3.diff .
打入atmel的补丁:
# cat u-boot-1.3.4-exp.3.diff | patch -p1
# make distclean
# make at91sam9260ek_nandflash_config
... with environment variable in NAND FLASH
Configuring for at91sam9260ek board...
# make
这样就可以编译出u-boot.bin
可以去这个文件来看u-boot烧写进nandflash的地址
# vim at91sam9260ek.h
/* ******************************************************************* */
/* BootStrap Settings */
/* */
/* ******************************************************************* */
#define IMG_ADDRESS 0x20000 /* Image Address in NandFlash */
#define IMG_SIZE 0x40000 /* Image Size in NandFlash */
看到烧到nandflash的地址是:0x20000
然后打开串口,写入进nandflash串口信息如下:
RomBOOT
>
U-Boot 1.3.4 (May 18 2010 - 21:40:34)
DRAM: 64 MB
NAND: 256 MiB
*** Warning - bad CRC or NAND, using default environment
In: serial
Out: serial
Err: serial
Net: macb0
macb0: Starting autonegotiation...
macb0: Autonegotiation complete
macb0: link up, 100Mbps full-duplex (lpa: 0x41e1)
Hit any key to stop autoboot: 0
NAND read: device 0 offset 0xa0000, size 0x200000
2097152 bytes read: OK
Wrong Image Format for bootm command
ERROR: can't get kernel image!
U-Boot>
可以看到u-boot启动起来了:
然后插上网线,看下网络能通吗?
U-Boot> ping 192.168.1.1
macb0: link up, 100Mbps full-duplex (lpa: 0x41e1)
*** ERROR: `ipaddr' not set
ping failed; host 192.168.1.1 is not alive
看到提示没有设置ipaddr:
U-Boot> setenv ipaddr 192.168.1.250
U-Boot> printenv
bootargs=console=ttyS0,115200 root=/dev/mtdblock5 mtdparts=at91_nand:128k(bootstrap)ro,256k(uboot)ro,128k(env1)ro,128k(env2)ro,2M(linux),-(root) rw rootfstype=jffs2
bootcmd=nand read 0x22000000 0xA0000 0x200000; bootm
bootdelay=3
baudrate=115200
stdin=serial
stdout=serial
stderr=serial
ethact=macb0
ipaddr=192.168.1.250
Environment size: 321/131067 bytes
U-Boot> saveenv
Saving Environment to NAND...
Erasing redundant Nand...
Erasing at 0x80000 -- 100% complete.
Writing to redundant Nand... done
U-Boot> setenv ethaddr 3e:36:65:ba:6f:be
U-Boot> setenv netmask 255.255.255.0
U-Boot> setenv gatewayip 192.168.1.1
U-Boot> savenv
Unknown command 'savenv' - try 'help'
U-Boot> saveenv
Saving Environment to NAND...
Erasing Nand...
Erasing at 0x60000 -- 100% complete.
Writing to Nand... done
U-Boot> ping 192.168.1.1
macb0: link up, 100Mbps full-duplex (lpa: 0x41e1)
Using macb0 device
host 192.168.1.1 is alive
现在可以ping通网络了:
我们现在ping下google:
U-Boot> ping 66.249.89.104
macb0: link up, 100Mbps full-duplex (lpa: 0x41e1)
Using macb0 device
host 66.249.89.104 is alive
可以看到也能ping到外网!
3.3移植linux内核:
# tar -xjvf linux-2.6.24.tar.bz2
# ls
2.6.24.at91.2-exp.patch.gz 2.6.24-at91.patch.gz linux-2.6.24.tar.bz2
# zcat 2.6.24.at91.2-exp.patch.gz | patch -p1
# zcat
2.6.24-at91.patch.gz | patch -p1
# cd linux-2.6.24
# ls
arch CREDITS drivers init kernel Makefile net samples sound vmlinux
block crypto fs ipc lib mm README scripts System.map vmlinux.o
COPYING Documentation include Kbuild MAINTAINERS Module.symvers REPORTING-BUGS security usr
# vim Makefile
linux-2.6.24 主目录下有个Makefile 文件,打开,找到185 行左右,修改
ARCH ?= arm
CROSS_COMPILE ?= arm-none-linux-gnueabi-
保存退出。
# make distclean
# make at91sam9261ek_defconfig
# make menuconfig
然后配置:
kernel Features -->选中:
[*]Use the ARM EABI to compile the kernel
[*]Allow old ABI ............
然后编译:
# make uImage
# pwd
/workdir/atmel/at91sam9260/kernel/linux-2.6.24/arch/arm/mach-at91
# vim board-sam9260ek.c
修改这里可以修改为自己想要的:
116行开始:
/*
* NAND flash
*/
static struct mtd_partition __initdata ek_nand_partition[] = {
{
.name = "Bootstrap",
.offset = 0,
.size = 4 * 1024 * 1024,
},
{
.name = "u-boot",
.offset = 4 * 1024 * 1024,
.size = 4 * 1024 * 1024,
},
{
.name = "kernel",
.offset = 8 * 1024 * 1024,
.size = 22 * 1024 * 1024,
},
{
.name = "fs",
.offset = 30 * 1024 * 1024,
.size = 40 * 1024 * 1024,
},
{
.name = "user space0",
.offset = 70 * 1024 * 1024,
.size = 60 * 1024 * 1024,
},
{
.name = "user space2",
.offset = 130 * 1024 * 1024,
.size = MTDPART_SIZ_FULL,
},
};
我的是256M的nandflash!
然后编译写入板子:
串口信息如下:
RomBOOT
>
U-Boot 1.3.4 (May 18 2010 - 21:40:34)
DRAM: 64 MB
NAND: 256 MiB
*** Warning - bad CRC or NAND, using default environment
In: serial
Out: serial
Err: serial
Net: macb0
macb0: Starting autonegotiation...
macb0: Autonegotiation complete
macb0: link up, 100Mbps full-duplex (lpa: 0x41e1)
Hit any key to stop autoboot: 0
NAND read: device 0 offset 0xa0000, size 0x200000
2097152 bytes read: OK
Wrong Image Format for bootm command
ERROR: can't get kernel image!
U-Boot> printenv
bootargs=console=ttyS0,115200 root=/dev/mtdblock5 mtdparts=at91_nand:128k(bootstrap)ro,256k(uboot)ro,128k(env1)ro,128k(env2)ro,2M(linux),-(root) rw rootfstype=jffs2
bootcmd=nand read 0x22000000 0xA0000 0x200000; bootm
bootdelay=3
baudrate=115200
stdin=serial
stdout=serial
stderr=serial
ethact=macb0
Environment size: 300/131067 bytes
U-Boot> nand read 0x22000000 0x800000 0x200000
NAND read: device 0 offset 0x800000, size 0x200000
2097152 bytes read: OK
U-Boot> bootm 0x22000000
## Booting kernel from Legacy Image at 22000000 ...
Image Name: Linux-2.6.24
Image Type: ARM Linux Kernel Image (uncompressed)
Data Size: 1070252 Bytes = 1 MB
Load Address: 20008000
Entry Point: 20008000
Verifying Checksum ... OK
Loading Kernel Image ... OK
OK
Starting kernel ...
Uncompressing Linux....................................................................... done, booting the kernel.
Linux version 2.6.24 () (gcc version 4.2.3 (Sourcery G++ Lite 2008q1-126)) #1 Tue May 18 22:50:41 HKT 2010
CPU: ARM926EJ-S [41069265] revision 5 (ARMv5TEJ), cr=00053177
Machine: Atmel AT91SAM9260-EK
Memory policy: ECC disabled, Data cache writeback
Clocks: CPU 198 MHz, master 99 MHz, main 18.432 MHz
CPU0: D VIVT write-back cache
CPU0: I cache: 8192 bytes, associativity 4, 32 byte lines, 64 sets
CPU0: D cache: 8192 bytes, associativity 4, 32 byte lines, 64 sets
Built 1 zonelists in Zone order, mobility grouping on. Total pages: 16256
Kernel command line: console=ttyS0,115200 root=/dev/mtdblock5 mtdparts=at91_nand:128k(bootstrap)ro,256k(uboot)ro,128k(env1)ro,128k(env2)ro,2M(linux),-(root) rw rootfstype=jffs2
AT91: 96 gpio irqs in 3 banks
PID hash table entries: 256 (order: 8, 1024 bytes)
Console: colour dummy device 80x30
console [ttyS0] enabled
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: 62616KB available (1944K code, 194K data, 100K init)
Mount-cache hash table entries: 512
CPU: Testing write buffer coherency: ok
net_namespace: 64 bytes
NET: Registered protocol family 16
SCSI subsystem initialized
usbcore: registered new interface driver usbfs
usbcore: registered new interface driver hub
usbcore: registered new device driver usb
NET: Registered protocol family 2
Time: pit clocksource has been installed.
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
NetWinder Floating Point Emulator V0.97 (double precision)
io scheduler noop registered
io scheduler anticipatory registered (default)
Internal error: Oops - undefined instruction: 0 [#1]
Modules linked in:
CPU: 0 Not tainted (2.6.24 #1)
PC is at device_create+0x20/0xb8
LR is at tty_register_device+0xb4/0xd0
pc : [] lr : [] psr: a0000013
sp : c3c19ea8 ip : c3c19ed8 fp : c3c19ed0
r10: 00000000 r9 : 00000000 r8 : c3c18000
r7 : c00e8c17 r6 : 00000004 r5 : c3c36bc0 r4 : 00000002
r3 : c3c19ee0 r2 : 00400003 r1 : 00000000 r0 : c3c36bc0
Flags: NzCv IRQs on FIQs on Mode SVC_32 ISA ARM Segment kernel
Control: 0005317f Table: 20004000 DAC: 00000017
Process swapper (pid: 1, stack limit = 0xc3c18268)
Stack: (0xc3c19ea8 to 0xc3c1a000)
9ea0: 00000000 c3c19ea8 c00e8c18 00000002 00000001 00000004
9ec0: 00000000 c3c19f3c c3c19ed8 c00e8c18 c010127c c3c19ee0 0000001c 00000004
9ee0: 33797474 c3c19e00 c010530c c019cf94 00000000 c3c52804 c3c52800 c3cab800
9f00: 00000000 c3c18000 00000000 00000000 c3c19f3c c3c19f20 c007d518 c0105210
9f20: 00000003 c3c52800 c3cab800 00000000 c3c19f64 c3c19f40 c00e9744 c00e8b74
9f40: c3c19f64 00400001 c0234404 c0233ae0 00000000 c001d60c c3c19f7c c3c19f68
9f60: c0017a2c c00e95b0 00000000 c0233ae0 c3c19f94 c3c19f80 c00172c4 c0017988
9f80: c001e000 00000000 c3c19ff4 c3c19f98 c0008934 c0017160 c0035918 c00354d4
9fa0: 00000000 c3c19fb0 c0021e64 c0035910 00000000 00000000 c0008870 c003bbc0
9fc0: 00000000 00000000 00000000 00000000 00000000 00000000 00000000 00000000
9fe0: 00000000 00000000 00000000 c3c19ff8 c003bbc0 c0008880 ffffff7f feffefff
Backtrace:
[] (device_create+0x4/0xb8) from [] (tty_register_device+0xb4/0xd0)
r7:00000000 r6:00000004 r5:00000001 r4:00000002
[] (tty_register_device+0x0/0xd0) from [] (tty_register_driver+0x1a4/0x1e4)
r7:00000000 r6:c3cab800 r5:c3c52800 r4:00000003
[] (tty_register_driver+0x0/0x1e4) from [] (vty_init+0xb4/0xec)
r7:c001d60c r6:00000000 r5:c0233ae0 r4:c0234404
[] (vty_init+0x0/0xec) from [] (tty_init+0x174/0x1cc)
r5:c0233ae0 r4:00000000
[] (tty_init+0x0/0x1cc) from [] (kernel_init+0xc4/0x284)
r5:00000000 r4:c001e000
[] (kernel_init+0x0/0x284) from [] (do_exit+0x0/0x710)
Code: e24dd00c e2505000 e1a07001 e1a06002 (0a000019)
---[ end trace 119d4c116316149b ]---
Kernel panic - not syncing: Attempted to kill init!
可以看到内核是启动起来了!但是还文件系统等还没完全启动,所以还需要进行修改!
4:添加内核对yaffs2的支持
上面可以看到,没有对yaffs2文件系统的支持,现在就添加yaffs2的支持
4.1解压yaffs2文件包
# tar -xzvf yaffs2.tar.gz
# ls
2.6.24.at91.2-exp.patch.gz 2.6.24-at91.patch.gz linux-2.6.24 linux-2.6.24.tar.bz2 yaffs2 yaffs2.tar.gz
# cd linux-2.6.24/fs
# mkdir yaffs
# pwd
/workdir/atmel/at91sam9260/kernel/linux-2.6.24/fs/yaffs
# cp ../../../yaffs/*.h .
# cp ../../../yaffs/*.c .
# ls
devextras.h yaffs_fs.c yaffs_mtdif1.h yaffs_nandemul2k.h yaffs_qsort.c yportenv.h
moduleconfig.h yaffs_getblockinfo.h yaffs_mtdif2.c yaffs_nand.h yaffs_qsort.h
yaffs_checkptrw.c yaffs_guts.c yaffs_mtdif2.h yaffs_packedtags1.c yaffs_tagscompat.c
yaffs_checkptrw.h yaffs_guts.h yaffs_mtdif.c yaffs_packedtags1.h yaffs_tagscompat.h
yaffs_ecc.c yaffsinterface.h yaffs_mtdif.h yaffs_packedtags2.c yaffs_tagsvalidity.c
yaffs_ecc.h yaffs_mtdif1.c yaffs_nand.c yaffs_packedtags2.h yaffs_tagsvalidity.h
# cp ../../../yaffs2/Makefile.kernel .
# ls
devextras.h yaffs_ecc.h yaffs_mtdif1.c yaffs_nand.c yaffs_packedtags2.h yaffs_tagsvalidity.h
Makefile.kernel yaffs_fs.c yaffs_mtdif1.h yaffs_nandemul2k.h yaffs_qsort.c yportenv.h
moduleconfig.h yaffs_getblockinfo.h yaffs_mtdif2.c yaffs_nand.h yaffs_qsort.h
yaffs_checkptrw.c yaffs_guts.c yaffs_mtdif2.h yaffs_packedtags1.c yaffs_tagscompat.c
yaffs_checkptrw.h yaffs_guts.h yaffs_mtdif.c yaffs_packedtags1.h yaffs_tagscompat.h
yaffs_ecc.c yaffsinterface.h yaffs_mtdif.h yaffs_packedtags2.c yaffs_tagsvalidity.c
# mv Makefile.kernel Makefile
# ls
devextras.h yaffs_ecc.h yaffs_mtdif1.c yaffs_nand.c yaffs_packedtags2.h yaffs_tagsvalidity.h
Makefile yaffs_fs.c yaffs_mtdif1.h yaffs_nandemul2k.h yaffs_qsort.c yportenv.h
moduleconfig.h yaffs_getblockinfo.h yaffs_mtdif2.c yaffs_nand.h yaffs_qsort.h
yaffs_checkptrw.c yaffs_guts.c yaffs_mtdif2.h yaffs_packedtags1.c yaffs_tagscompat.c
yaffs_checkptrw.h yaffs_guts.h yaffs_mtdif.c yaffs_packedtags1.h yaffs_tagscompat.h
yaffs_ecc.c yaffsinterface.h yaffs_mtdif.h yaffs_packedtags2.c yaffs_tagsvalidity.c
# pwd
/workdir/atmel/at91sam9260/kernel/linux-2.6.24/fs/yaffs2
# cp ../../../yaffs2/Kconfig .
# cd ..
# pwd
/workdir/atmel/at91sam9260/kernel/linux-2.6.24/fs
119行开始:
obj-$(CONFIG_OCFS2_FS) += ocfs2/
obj-$(CONFIG_GFS2_FS) += gfs2/
obj-$(CONFIG_YAFFS_FS) += yaffs/
# vim Kconfig
修改2119行:
endif # NETWORK_FILESYSTEMS
source "fs/yaffs2/Kconfig"
if BLOCK
menu "Partition Types"
# make distclean
# make at91sam9260ek_defconfig
# make menuconfig
修改配置,去选择支持yaffs!
Device Drivers --> Memory Technology Device(MTD) support
File Systems --> YAFFS2 file system support
Autoselect yaffs2 format
Disable lazy loading
Turn off wide tnodes
Kernel Features --> Use the ARM EABI to compile the kernel
Allow ole ABI binaries to run with this kernel
# make uImage
# pwd
/workdir/atmel/at91sam9260/kernel/yaffs2/utils
# ls
Makefile mkyaffs2image.c mkyaffsimage.c
# make
# ls
Makefile mkyaffs2image.c mkyaffsimage mkyaffsimage.o yaffs_ecc.o yaffs_packedtags2.o yaffs_tagsvalidity.o
mkyaffs2image mkyaffs2image.o mkyaffsimage.c yaffs_ecc.c yaffs_packedtags2.c yaffs_tagsvalidity.c
然后将这个"mkyaffs2image"目录添加到环境变量里面去!
# cd ../../../../
# ls
AT91Bootstrap crosstool filesyetem kernel setenv-9260 Source Insight Workdir u-boot
然后就得到支持yaffs2的内核了!