--------------------------------------------------------------------------------
一、将Linux2.6.22.2内核源码放到工作目录的kernel文件夹下,并解压。
#tar xzvf linux2.6.22.2.tar.gz
#pwd
/home/tekkaman/working/kernel
# cd linux2.6.22.2
进入内核解压后的目录,以后示例中,只要是相对路径全部是相对于
/home/tekkaman/working/kernel/linux2.6.22.2/此目录
--------------------------------------------------------------------------------
二、修改内核源码根目录下的Makefile文件(CROSS_COMPILE =的值因个人情况而定,其他可以照做。)
#vi Makefile
......
#SUBARCH := $(shell uname -m | sed -e s/i.86/i386/ -e s/sun4u/sparc64/ \
# -e s/arm.*/arm/ -e s/sa110/arm/ \
# -e s/s390x/s390/ -e s/parisc64/parisc/ \
# -e s/ppc.*/powerpc/ -e s/mips.*/mips/ )
......
#ARCH ?= $(SUBARCH)
#CROSS_COMPILE ?=
ARCH = arm
CROSS_COMPILE = /home/tekkaman/working/crosstool-gcc410-k26222/gcc-4.1.0-glibc-2.3.2/arm-9tdmi-linux-gnu/bin/arm-9tdmi-linux-gnu-
--------------------------------------------------------------------------------
三、修改arch/arm/plat-s3c24xx/common-smdk.c文件,修改Nand Flash的分区信息和Nand Flash的硬件信息。
(LED 器件的初始化也在这个文件里,但是博创的平台没有那四个LED管,所以要不要那些程序都无所谓。我就把它们放在那里,反正启动时不会有影响,也没有出错信息。)
......
/* NAND parititon from 2.4.18-swl5 */
static struct mtd_partition smdk_default_nand_part[] = {
[0] = {
.name = "U-Boot-1.2.0",
.size = SZ_128K,
.offset = 0,
},
[1] = {
.name = "U-Boot-1.2.0 Parameter",
.offset = SZ_128K,
.size = SZ_64K,
},
[2] = {
.name = "Linux2.6.22.2 Kernel",
.offset = SZ_128K+SZ_64K,
.size = SZ_4M+(SZ_1M-SZ_128K-SZ_64K),
},
[3] = {
.name = "Root-JFFS2",
.offset = SZ_1M * 5,
.size = SZ_1M * 5,
},
[4] = {
.name = "Boot-Root(cramfs)",
.offset = SZ_1M * 10,
.size = SZ_1M * 10,
},
[5] = {
.name = "YAFFS",
.offset = SZ_1M * 20,
.size = SZ_1M * 44,
}
/*,
[6] = {
.name = "S3C2410 flash partition 6",
.offset = SZ_1M * 24,
.size = SZ_1M * 24,
},
[7] = {
.name = "S3C2410 flash partition 7",
.offset = SZ_1M * 48,
.size = SZ_16M,
}
*/
};
......
static struct s3c2410_platform_nand smdk_nand_info = {
.tacls = 0,
.twrph0 = 30,
.twrph1 = 0,
.nr_sets = ARRAY_SIZE(smdk_nand_sets),
.sets = smdk_nand_sets,
};
......
--------------------------------------------------------------------------------
四、 修改drivers/mtd/nand/s3c2410.c,去掉nand flash 的ECC。
我的内核是通过U-BOOT写到Nand Flash的, U-BOOT 通过的软件ECC算法产生ECC校验码, 这与内核校验的ECC码不一样, 内核中的ECC码是由S3C2410中Nand Flash控制器产生的。所以,我在这里选择禁止内核ECC校验。
“第三步:修改ECC校验:
根据kernel官方网站上的说明,从2.6.22.3已经修改了ECC校验的问题(这也是我移植2.6.22.3的一个重要原因)。但实验下来发现,不管是用软件ECC还是硬件ECC都不行。只好改成NAND_ECC_NONE:
在driver/mtd/nand/s3c2410.c中找到s3c2410_nand_init_chip()函数,将其中的
chip->ecc.mode=NAND_ECC_SOFT;
改成
chip->ecc.mode=NAND_ECC_NONE; ”
后来我就到网上找关于2.6.22.3的ECC校验的资料,始终没找到上面所说的修改,那位高人看到了通知一声。看来要好好看看这方面的内容了。)
搜索关键字NAND_ECC_SOFT,在s3c2410_nand_init_chip函数里,修改NAND_ECC_SOFT为NAND_ECC_NONE
五、增加Yaffs2文件系统的支持
对于YAFFS文件系统,我在移植时查阅了许多资料。有的博客上说没有必要移植YAFFS2,因为它是为每页大于1024B的NAND Flash设计的。即使移植了YAFFS2,如果你的NAND Flash是每页512+16B的那系统也会自动挂载YAFFS。所以在这里要移植YAFFS2或是YAFFS 随你的便。我移植的是YAFFS2。
1、下载Yaffs2
2、解压Yaffs2并将其加入Linux内核(打补丁的方式)
#cd yaffs2
#./patch-ker.sh c /home/tekkaman/working/kernel/linux-2.6.22.2/
六、博创2410-S所配网卡AX88796(NE2000兼容网卡)驱动的移植。
(1)修改arch/arm/目录下的Kconfig文件,增加ISA总线支持,使其在make menuconfig 时出现NE2000的网卡配置选项。
config ARCH_S3C2410
bool "Samsung S3C2410, S3C2412, S3C2413, S3C2440, S3C2442, S3C2443"
select GENERIC_GPIO
select ISA
help
Samsung S3C2410X CPU based systems, such as the Simtec Electronics
BAST (<>), the IPAQ 1940 or
the Samsung SMDK2410 development board (and derivatives).
(2)修改include/asm-arm/arch-s3c2410文件夹下的map.h文件。加入AX88796的地址映射。
/***************tekkaman****************************/
#define S3C2410_VA_ISA_NET S3C2410_ADDR(0x02100000)
#define S3C2410_PA_ISA_NET __phys_to_pfn(0x10000000)
#define S3C2410_SZ_ISA_NET SZ_1M
/**********************tekkaman********************/
说明:
a、根据网上的资料,“#define S3C2410_VA_ISA_NET S3C2410_ADDR(0x02100000)”的地址可以自己修改,只要不和别的虚拟地址冲突就行。我有试过将起改成“#define S3C2410_VA_ISA_NET (0xd1000000)”,也就是博创的2.6.18的定义,也可以正常启动。
b、“#define S3C2410_PA_ISA_NET __phys_to_pfn(0x10000000)”这句困扰了我很久。一开始我的定义是“#define S3C2410_PA_ISA_NET (0x10000000)”,所以启动后系统就死在了网卡的初始化上,出现“Unable to handle kernel paging request at virtual address ”的错误。后来我上网查找资料,才知道:原来实地址与虚地址的映射结构 smdk2410_iodesc 里有所变化。第二个参数从原来的 unsigned long physical 变为 unsigned long pfn (Page Frame Number 页帧号)。而从 smdk2410_iodesc 传入的S3C2410_PA_ISA_NET 仍然是一个 physical 值,因此出现以上的错误。只要在物理地址前加上“__phys_to_pfn”就可以解决这个问题。较详细的讲解请看我的参考资料(文章前面有链接地址)。
(3)修改arch/arm/mach-s3c2410文件夹下的mach-smdk2410.c文件。在smdk2410_iodesc 中加入AX88796的地址信息。
static struct map_desc smdk2410_iodesc[] __initdata = {
/* nothing here yet */
{
.virtual = S3C2410_VA_ISA_NET,
.pfn = S3C2410_PA_ISA_NET,
.length = S3C2410_SZ_ISA_NET,
.type = MT_DEVICE,
}
};
以下修改为选做,可以不改:
随便在这里取消LCD的初始化,不然启动时会有出错信息(因为我现在的项目用不到,以后有空我会添上LCD的移植和GUI的移植):
static struct platform_device *smdk2410_devices[] __initdata = {
&s3c_device_usb,
// &s3c_device_lcd,
&s3c_device_wdt,
&s3c_device_i2c,
&s3c_device_iis,
};
修改开发板的名称(可以自定义):
MACHINE_START(SMDK2410, "Tekkaman2410")
(4)修改网卡驱动的主要文件drivers/net/ne.c。
a、添加头文件和定义
//**********************tekkaman*************************
#include
#define AX88796_BASE (vAX88796_BASE+0x200)
#define AX88796_IRQ IRQ_EINT2
#define pAX88796_BASE S3C2410_PA_ISA_NET
#define vAX88796_BASE S3C2410_VA_ISA_NET
#define EXTINT_OFF (IRQ_EINT4 - 4)
//**********************tekkaman*****************************
......
在static struct { const char *name8, *name16; unsigned char SAprefix[4];}
bad_clone_list[] __initdata 中增加AX88796 的MAC地址前三位(不一定需要):
{"AX88796", "NE2000-compatible", {0x08, 0x08, 0x08}},
b、确保定义总线宽度为16位。
将
#if defined(CONFIG_PLAT_MAPPI)
# define DCR_VAL 0x4b
#elif defined(CONFIG_PLAT_OAKS32R) || \
defined(CONFIG_TOSHIBA_RBTX4927) || defined(CONFIG_TOSHIBA_RBTX4938)
# define DCR_VAL 0x48 /* 8-bit mode */
#else
# define DCR_VAL 0x49
#endif
修改为
#if 0
#if defined(CONFIG_PLAT_MAPPI)
# define DCR_VAL 0x4b
#elif defined(CONFIG_PLAT_OAKS32R) || \
defined(CONFIG_TOSHIBA_RBTX4927) || defined(CONFIG_TOSHIBA_RBTX4938)
# define DCR_VAL 0x48 /* 8-bit mode */
#else
#endif
#endif
# define DCR_VAL 0x49
c、在do_ne_probe函数中增加配置总线参数、基地址和中断的语句(其参数参考 刘淼 的书)
static int __init do_ne_probe(struct net_device *dev)
{
unsigned long base_addr = dev->base_addr;
#ifdef NEEDS_PORTLIST
int orig_irq = dev->irq;
#endif
//******************************tekkaman********************************
static int once=0;
if (once) {
return -ENXIO;
}
unsigned int value;
value = __raw_readl(S3C2410_BWSCON);
value &= ~(S3C2410_BWSCON_WS2|S3C2410_BWSCON_ST2|S3C2410_BWSCON_DW2_32);
value |= (S3C2410_BWSCON_ST2|S3C2410_BWSCON_DW2_16);
__raw_writel(value, S3C2410_BWSCON);
value=0;
value = (S3C2410_BANKCON_Tacs4|S3C2410_BANKCON_Tcos4|S3C2410_BANKCON_Tacc14|S3C2410_BANKCON_Tcoh4|S3C2410_BANKCON_Tcah4|S3C2410_BANKCON_Tacp6|S3C2410_BANKCON_PMCnorm);
__raw_writel(value,S3C2410_BANKCON2);
set_irq_type(AX88796_IRQ,IRQ_TYPE_LEVEL_LOW );
s3c2410_gpio_cfgpin(S3C2410_GPF2, S3C2410_GPF2_EINT2);
s3c2410_gpio_pullup(S3C2410_GPF2, 0);
if(base_addr==0){
dev->base_addr = base_addr = AX88796_BASE ;
dev->irq = AX88796_IRQ;
once++;
}
//***********************************tekkaman************************************
SET_MODULE_OWNER(dev);
/* First check any supplied i/o locations. User knows best. */
if (base_addr > 0x1ff) /* Check a single specified location. */
return ne_probe1(dev, base_addr);
else if (base_addr != 0) /* Don't probe at all. */
return -ENXIO;
......
d、修改ne_probe1函数
增加自定义的网卡MAC地址(这个地址可以自行修改,但是MAC也有一定的规则,最重要的是千万不要把它配置为广播或组播地址,请参考网络的相关书籍):
static int __init ne_probe1(struct net_device *dev, unsigned long ioaddr)
{
int i;
unsigned char ne_defethaddr[]={0x08,0x08,0x08,0x08,0x12,0x27,0};//tekkaman
unsigned char SA_prom[32];
int wordlength = 2;
......
增加网卡MAC地址的配置语句,屏蔽通过EEPROM配置网卡的语句
......
struct {unsigned char value, offset; } program_seq[] =
{
{E8390_NODMA+E8390_PAGE0+E8390_STOP, E8390_CMD}, /* Select page 0*/
{0x48, EN0_DCFG}, /* Set byte-wide (0x48) access. */
{0x00, EN0_RCNTLO}, /* Clear the count regs. */
{0x00, EN0_RCNTHI},
{0x00, EN0_IMR}, /* Mask completion irq. */
{0xFF, EN0_ISR},
{E8390_RXOFF, EN0_RXCR}, /* 0x20 Set to monitor */
{E8390_TXOFF, EN0_TXCR}, /* 0x02 and loopback mode. */
{32, EN0_RCNTLO},
{0x00, EN0_RCNTHI},
{0x00, EN0_RSARLO}, /* DMA starting at 0x0000. */
{0x00, EN0_RSARHI},
{E8390_RREAD+E8390_START, E8390_CMD},
};
for (i = 0; i < sizeof(program_seq)/sizeof(program_seq[0]); i++)
outb_p(program_seq[i].value, ioaddr + program_seq[i].offset);
}
//****************************************tekkaman*********************************
{
unsigned char *ep;
ep = (unsigned char * ) &ne_defethaddr[0];
ne_defethaddr[5]++;
for(i=0;i<6;i++) {
SA_prom[i] = ep[i];
}
SA_prom[14] = SA_prom[15]=0x57;
wordlength =2;
}
//****************************************tekkaman*********************************
#if 0 //tekkaman
for(i = 0; i < 32 /*sizeof(SA_prom)*/; i+=2) {
SA_prom[i] = inb(ioaddr + NE_DATAPORT);
SA_prom[i+1] = inb(ioaddr + NE_DATAPORT);
if (SA_prom[i] != SA_prom[i+1])
wordlength = 1;
}
#endif //tekkaman
if (wordlength == 2)
{
#if 0 //tekkaman
for (i = 0; i < 16; i++)
SA_prom[i] = SA_prom[i+i];
/* We must set the 8390 for word mode. */
outb_p(DCR_VAL, ioaddr + EN0_DCFG);
start_page = NESM_START_PG;
/*
* Realtek RTL8019AS datasheet says that the PSTOP register
* shouldn't exceed 0x60 in 8-bit mode.
* This chip can be identified by reading the signature from
* the remote byte count registers (otherwise write-only)...
*/
if ((DCR_VAL & 0x01) == 0 && /* 8-bit mode */
inb(ioaddr + EN0_RCNTLO) == 0x50 &&
inb(ioaddr + EN0_RCNTHI) == 0x70)
stop_page = 0x60;
else
stop_page = NESM_STOP_PG;
#endif //tekkaman
outb_p(0x49, ioaddr + EN0_DCFG);
start_page = NESM_START_PG;
stop_page = NESM_STOP_PG;
} else {
start_page = NE1SM_START_PG;
stop_page = NE1SM_STOP_PG;
}
......
屏蔽自定检测中断号的语句(参考 刘淼 的书):
......
#if 0 //tekkaman
if (dev->irq < 2)
{
unsigned long cookie = probe_irq_on();
outb_p(0x50, ioaddr + EN0_IMR); /* Enable one interrupt. */
outb_p(0x00, ioaddr + EN0_RCNTLO);
outb_p(0x00, ioaddr + EN0_RCNTHI);
outb_p(E8390_RREAD+E8390_START, ioaddr); /* Trigger it... */
mdelay(10); /* wait 10ms for interrupt to propagate */
outb_p(0x00, ioaddr + EN0_IMR); /* Mask it again. */
dev->irq = probe_irq_off(cookie);
if (ei_debug > 2)
printk(" autoirq is %d\n", dev->irq);
} else if (dev->irq == 2)
/* Fixup for users that don't know that IRQ 2 is really IRQ 9,
or don't know which one to set. */
dev->irq = 9;
#endif //tekkaman
if (! dev->irq) {
printk(" failed to detect IRQ line.\n");
ret = -EAGAIN;
goto err_out;
}
AX88697的移植到此结束!
移植Linux2.6.22.2到博创2410-S(s3c2410A)
(包括AX88796移植)
七、配置内核
在配置内核前,先拷贝s3c2410开发板的默认配置到内核根目录下,以简化配置过程。
#pwd
/home/tekkaman/working/kernel/linux-2.6.22.2
# cp arch/arm/configs/s3c2410_defconfig .config
# make menuconfig
以下是在 s3c2410_defconfig 基础上要配置的选项(有一些必须的选项在s3c2410_defconfig里已经选上了,所以我没有写出来。以下的选项非特别说明,可能不用选,我没有做实验证明哪些要、哪些不要,所以有兴趣的可以自己做实验看看,欢迎发E-Mail告诉我结果。谢谢)
General setup --->
[*] Configure standard kernel features (for small systems) --->
选上这项,否则文件系统中的一些选项不会出现
System Type --->
S3C2410 Machines --->
[*] SMDK2410/A9M2410 留下这项就够了,其他全部“N”掉
“N”掉 S3C2412 Machines ---> 、 S3C2440 Machines ---> 和 S3C2443 Machines ---> 里的所有选项,都是和2410无关的选项。
Boot options --->
将 (root=/dev/hda1 ro init=/bin/bash console=ttySAC0) Default kernel command string
改成 (noinitrd root=/dev/mtdblock4 rootfstype=cramfs console=ttySAC0,115200 init=/linuxrc mem=64M) Default kernel command string
#说明:
#mtdblock4代表第5个flash分区,用来作根文件系统rootfs;
# console=ttySAC0,115200使kernel启动期间的信息全部输出到串口0上,波特率为115200;
# 2.6内核对于串口的命名改为ttySAC0,但这不影响用户空间的串口编程。
# 用户空间的串口编程针对的仍是/dev/ttyS0等
# mem=64M表示内存是64M,如果是32则设为32M
在实践中,我发现“rootfstype=cramfs”这句还是挺重要的。如果没有这句,系统启动时即使分区挂载正确了,但是文件系统的类型有可能出错。在这里定义过,就不会出错了。这里的选项也和根文件系统的配置有关。(我先使用cramfs做跟文件系统,以后再换JFFS2或是YAFFS)
Userspace binary formats --->
< > Kernel support for a.out and ECOFF binaries (去除该选项,a.out和ECOFF是两种可执行文件的格式,在ARM-Linux下一般都用ELF,所以这两种基本用不上。)
Networking --->
Networking options --->
<*> Packet socket
[*] Packet socket: mmapped IO
-我移植 斯达康 的XI-735 无限网卡,所以我选了WLAN(802.11)的选项,不需的可以不选-
Wireless --->
--- Improved wireless configuration API
--- Wireless extensions
<*> Generic IEEE 802.11 Networking Stack (mac80211)
[*] Enable LED triggers
[ ] Enable debugging output (NEW)
<*> Generic IEEE 802.11 Networking Stack
[ ] Enable full debugging output (NEW)
--- IEEE 802.11 WEP encryption (802.1x)
< > IEEE 802.11i CCMP support (NEW)
< > IEEE 802.11i TKIP encryption (NEW)
<*> Software MAC add-on to the IEEE 802.11 networking stack
[ ] Enable full debugging output (NEW)
Device Drivers --->
“N”掉 Parallel port support ---> 里的所有选项。
Plug and Play support --->里的所有选项一定要“N”掉,不然编译会出错!!!!!!!!
Network device support --->
Ethernet (10 or 100Mbit) --->
“N”掉< > DM9000 support和< > Generic Media Independent Interface device support
-------以下一定要选上,是AX88796的驱动------
[*] Other ISA cards
<*> NE2000/NE1000 support
-----------------------------
“N”掉 [ ] Ethernet (1000 Mbit) --->和 [ ] Ethernet (10000 Mbit) --->
Wireless LAN --->
[*] Wireless LAN (pre-802.11)
[*] Wireless LAN (IEEE 802.11)
USB Network Adapters --->
<*> Multi-purpose USB Networking Framework
<*> MMC/SD card support --->
Real Time Clock --->
“N”掉 [ ] Set system time from RTC on startup and resume
#接下来做的是针对文件系统的设置,我实验时目标箱上要挂的根文件系统是cramfs,故做如下配置
!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!
(注意:不要试图按照旧内核的方法增加 devfs 的支持,因为在这个内核里已经彻底删除了
devfs的源代码。我曾试图将旧内核的devfs源代码复制过来,不过编译会出错!
补救的办法就是用U-Boot的mdev来代替,在讲根文件系统的建立时我会说明,你也可以到网上找mdev的资料。)
!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!
File systems -->
< > Second extended fs support #去除对ext2的支持
< > Ext3 journalling file system support #去除对ext3的支持
<*> Kernel automounter support
<*> Kernel automounter version 4 support (also supports v3)
<*> Filesystem in Userspace support
Pseudo filesystems -->
[*] Virtual memory file system support (former shm fs)
<*> Userspace-driven configuration filesystem (EXPERIMENTAL)
Miscellaneous filesystems -->
<*> YAFFS2 file system support
“N”掉[ ]Autoselect yaffs2 format 和
[ ]Cache short names in RAM ,因为这是给每页大于1024B的NAND Flash设计的
<*> Journalling Flash File System v2 (JFFS2) support
(0) JFFS2 debugging verbosity (0 = quiet, 2 = noisy)
[*] JFFS2 write-buffering support
[ ] JFFS2 summary support (EXPERIMENTAL)
[ ] JFFS2 XATTR support (EXPERIMENTAL)
[*] Advanced compression options for JFFS2
[*] JFFS2 ZLIB compression support
[*] JFFS2 RTIME compression support
[*] JFFS2 RUBIN compression support
JFFS2 default compression mode (priority) --->
Network File Systems -->
<*> NFS file system support
--以下最好选上,因为在挂载NFS时可能出现protocol不支持的情况--
[*]Provide NFSv3 client support
[*]Provide client support for the NFSv3 ACL protocol extension
[*] Provide NFSv4 client support (EXPERIMENTAL)
[*] Allow direct I/O on NFS files
-------------------------------------------------------------------------
<*> NFS server support
[*] Provide NFSv3 server support
[*]Provide server support for the NFSv3 ACL protocol extension
[*] Provide NFSv4 server support (EXPERIMENTAL)
--- Provide NFS server over TCP support
[*] Root file system on NFS
保存退出,产生.config文件。
--------------------------------------------------------------------------------
八、编译内核
#make zImage
本文来自CSDN博客,转载请标明出处:学习笔记/内核移植/移植Linux2_6_22_2到博创2410-S(s3c2410A).mht