Linux-2.6.12移植到斯道s3c2410
扫描二维码
随时随地手机看文章
硬件设备:网卡:dm9000NandFlash:K9F1208U0C 64M
1, 下载并解压缩内核,修改顶层Makefile的编译器选项:
ARCH ?=arm
CROSS_COMPILE ?=arm-softfloat-linux-gnu-
2, 修改linux-2.6.12/arch/arm/mach-s3c2410/devs.c, 使其支持NandFlash和DM9000网卡:
添加头文件:
#include //该头文件将从linux-2.6.14的内核中copy到include/linux中去
#include
#include
#include
添加dm9000网卡设备的支持
EXPORT_SYMBOL(s3c_device_usb);
/* NIC DM9000A64 driver,copy from linux-2.6.14. add by guowenxue 2008.08.15 */
/* My board: nETH_CS接NGCS3, 中断线IRQ_LAN接EINT9, CMD接A2 */
#ifndef S3C2410_CS3
#define S3C2410_CS3 (0x18000000)
#endif
/* change 0x08000000 to S3C2410_CS3 */
static struct resource s3c_dm9000_resource[] =
{
[0] = {
.start = S3C2410_CS3 + 0x300,
.end = S3C2410_CS3 + 0x300 + 0x03,
.flags = IORESOURCE_MEM
},
[1] = {
.start = S3C2410_CS3 + 0x300 + 0x04,
.end = S3C2410_CS3 + 0x300 + 0x04 + 0x3f, // It's 0x3f, not 0x3
.flags = IORESOURCE_MEM
},
[2] = {
.start = IRQ_EINT9, // My board use EINT9
.end = IRQ_EINT9,
.flags = IORESOURCE_IRQ
}
};
static struct dm9000_plat_data s3c_device_dm9000_platdata =
{
.flags= DM9000_PLATF_16BITONLY
};
struct platform_device s3c_device_dm9000 =
{
.name= "dm9000",
.id= -1,
.num_resources= ARRAY_SIZE(s3c_dm9000_resource),
.resource= s3c_dm9000_resource,
.dev= {
.platform_data = &s3c_device_dm9000_platdata,
}
};
EXPORT_SYMBOL(s3c_device_dm9000);
/**** Add end *****/
/* LCD Controller */
添加NandFlash的支持:
/* NAND Controller */
static struct resource s3c_nand_resource[] = {
[0] = {
.start = S3C2410_PA_NAND,
.end = S3C2410_PA_NAND + S3C24XX_SZ_NAND,
.flags = IORESOURCE_MEM,
}
};
/******* add by guowenxue 2008.10.28 *********/
static struct mtd_partition partition_info[] =
{
{
name: "mtdblock0 uboot 1M", //mtdblock0 1*1M = 1M
size: 0x00100000,
offset: 0,
}, {
name: "mtdblock1 kernel 3M", //mtdblock1 3.1M = 3M
size: 0x00300000,
offset: 0x00100000,
}, {
name: "mtdblock2 rootfs 6M", //mtdblock2 6*1M = 6M
size: 0x00600000,
offset: 0x00400000,
}, {
name: "mtdblock3 apps 27M", //mtdblock3 27*1M = 27M
size: 0x01B00000,
offset: 0x00A00000,
}, {
name: "mtdblock4 user 27M", //mtdblock4 27*1M = 27M
size: 0x01B00000,
offset: 0x02500000,
}
};
struct s3c2410_nand_set nandset =
{
nr_partitions: 5, /* the number of partitions */
partitions: partition_info, /* partition table */
};
struct s3c2410_platform_nand superlpplatform=
{
tacls:0,
twrph0:30,
twrph1:0,
sets: &nandset,
nr_sets: 1,
};
struct platform_device s3c_device_nand =
{
.name = "s3c2410-nand", /* Device name */
.id = -1, /* Device ID */
.num_resources = ARRAY_SIZE(s3c_nand_resource),
.resource = s3c_nand_resource, /* Nand Flash Controller Registers */
/* Add the Nand Flash device */
.dev = {
.platform_data = &superlpplatform
}
};
/****** add end ********/
3, 修改文件linux-2.6.12/arch/arm/mach-s3c2410/devs.h,导出dm9000设备:
extern struct platform_device s3c_device_sdi;
extern struct platform_device s3c_device_dm9000; //add by guowenxue,2008.11.15
4, 修改文件linux-2.6.12/arch/arm/mach-s3c2410/mach-smdk2410.c, 添加dm9000和nandflash
static struct platform_device *smdk2410_devices[] __initdata = {
&s3c_device_usb,
&s3c_device_lcd,
&s3c_device_wdt,
&s3c_device_i2c,
&s3c_device_iis,
&s3c_device_nand, // this member add by guowenxue 2003.10.28
&s3c_device_dm9000, // this member add by guowenxue 2003.11.15
};
5, 从linux-2.6.14的内核中拷贝driver/net/dm9000.c和dm9000.h到相应目录,同时拷贝
linux-2.6.14/include/linux/dm9000.h到linux-2.6.12的相应目录.修改driver/net/dm9000.c如下:
在文件开始处添加:
#define INTMOD (0x4A000004) //These two line add by guowenxue 2008.11.15
static void *intmod;
在static int dm9000_probe(struct device *dev)函数申明完变量后添加:
intmod=ioremap_nocache(INTMOD,0x0000004);
writel(0x0,intmod);
同样在该函数中,注释掉从ROM中读MAC地址,改为我们自己设置的MAC地址:
#if 0 /* Read SROM content */
for (i = 0; i < 64; i++)
((u16 *) db->srom)[i] = read_srom_word(db, i);
/* Set Node Address, the first 6 bytes is the MAC address */
for (i = 0; i < 6; i++)
ndev->dev_addr[i] = db->srom[i];
#endif
添加:
#if 1 // add by guowenxue, set MAC address by myself 2008.11.17
unsigned char def_eth_mac_addr[]={0x22,0x44,0x66,0x88,0x44,0x66};
for(i=0; i<6; i++)
ndev->dev_addr[i] = def_eth_mac_addr[i];
#endif
在函数static int dm9000_open(struct net_device *dev)中添加set_irq_tye():
set_irq_type(dev->irq, IRQT_RISING); // 申请类型为上升沿中断,否则PC ping不通开发板.
if (request_irq(dev->irq, &dm9000_interrupt, SA_SHIRQ, dev->name, dev))
return -EAGAIN;
6, 修改linux-2.6.12/drivers/serial/s3c2410.c
修改#define S3C24XX_SERIAL_DEVFS “tts/”
为:#define S3C24XX_SERIAL_DEVFS "ttyS"
修改结构体static struct uart_driver s3c24xx_uart_drv的成员.dev_name为:
// .dev_name = "s3c2410_serial",
.dev_name = "ttyS",
之前编译的内核,怎么都不能初始化console,进入busybox,原来s3c2410默认的串口名并不是
ttyS0或tySAC0. 另外S3C2410的串口主设备号注册为204,次设备号为64.这样我们在根文件
系统里就要注意了:#mknod –mode=755 ttyS0 c 204 64
7, 修改文件drivers/net/arm/Kconfig,添加dm9000驱动选项:
config DM9000
tristate "DM9000 support"
depends on ARM && NET_ETHERNET
select CRC32
select MII
---help---
Support for DM9000 chipset.
To compile this driver as a module, choose M here and read
called dm9000.
#config MACE
#tristate "MACE (Power Mac ethernet) support"
#depends on NET_ETHERNET && PPC_PMAC && PPC32
8, 修改文件linux-2.6.12/drivers/net/Makefile, 添加DM9000的编译选项.
obj-$(CONFIG_SMC91X) += smc91x.o
obj-$(CONFIG_DM9000) += dm9000.o
9, make menuconfig生成配置文件:
System Type --->
ARM system type (Samsung S3C2410) --->
S3C24XX Implementations --->
[*] SMDK2410/A9M2410
[*] S3C2410 DMA support
[*] Support Thumb user binaries
Boot options --->
(noinitrdroot=/dev/mtdblock2 init=/linuxrcconsole=ttySAC0,115200) Default kernel command
Floating point emulation --->
[*] NWFPE math emulation
Device Drivers --->
Memory Technology Devices (MTD) --->
<*> Memory Technology Device (MTD) support
<*> MTD concatenating support
[*] MTD partitioning support
[*] Command line partition table parsing
<*> Direct char device access to MTD devices
<*> Caching block device access to MTD devices
RAM/ROM/Flash chip drivers --->
<*> Detect flash chips by Common Flash Interface (CFI) probe
<*> Detect non-CFI AMD/JEDEC-compatible flash chips
<*> Support for Intel/Sharp flash chips
<*> Support for AMD/Fujitsu flash chips
<*> Support for RAM chips in bus mapping
NAND Flash Device Drivers --->
<*> NAND Device Support
<*> NAND Flash support for S3C2410 SoC
Networking support --->
[*] Networking support
[*] Network device support
Ethernet (10 or 100Mbit) --->
[*] Ethernet (10 or 100Mbit)
<*> DM9000 support
Character devices --->
Serial drivers --->
<*> Samsung S3C2410 Serial port support
[*] Support for console on S3C2410 serial port
File systems --->
Pseudo filesystems --->
[*] /proc file system support
可选/dev file system support
[*] /dev/pts Extended Attributes
[*] /dev/pts Security Labels
[*] tmpfs Extended Attributes
[*] tmpfs Security Labels
Miscellaneous filesystems --->
<*> Journalling Flash File System v2 (JFFS2) support
(0) JFFS2 debugging verbosity (0 = quiet, 2 = noisy)
[*] JFFS2 support for NAND flash
[*] Advanced compression options for JFFS2
[*] JFFS2 ZLIB compression support
[*] JFFS2 RTIME compression support
<*> Compressed ROM file system support (cramfs)
<*> FreeVxFS file system support (VERITAS VxFS(TM) compatible)
Network File Systems --->
<*> NFS file system support
[*] Provide NFSv3 client support
[*] Provide NFSv4 client support (EXPERIMENTAL)
移植过程中碰到的主要问题及解决方法
1, NAND_ECC_NONE selected by board driver. This is not recommended !!
和Reading data from NAND FLASH without ECC is not recommended
这是因为关闭了mtd/nand/s3c2410.c中的ECC检测:
不要在函数s3c2410_nand_init_chip()的最后添加下面这行代码:
Chip->eccmode = NAND_ECC_NONE;
不关闭硬件ECC, 使用cramfs和jffs2文件系统很正常,对于yaffs2还没试过.
2, ftl_cs: FTL header not found.
Make menuconfig时:
Device Drivers -?
Memory Technology Devices (MTD) -?不要选择下面这三个选项
<>FTL (Flash Translation Layer) support
<> NFTL (NAND Flash Translation Layer) support
<>INFTL (Inverse NAND Flash Translation Layer) support
3, linux启动busybox时提示: Can't open /dev/ttyS0: No such file or directory
这是因为内核里s3c2410的串口驱动,注册的串口设备名并不是ttyS0,并且串口设备的
主,次设备号也不是根文件系统/dev目录下的设备. 按照上面移植内核的方法,修改s3c2410
的串口驱动程序(linux-2.6.12/drivers/serial/s3c2410.c)就OK了.
4, 关于dm9000网卡驱动的几个问题:
dm9000 Ethernet Driver
dm9000: read wrong id 0x2b2a2928
dm9000: read wrong id 0x2b2a2928
dm9000: wrong id: 0x2b2a2928
dm9000: not found (0).
主要是最开始按照网上移植dm9000的驱动方法,在文件linux-2.6.12/arch/arm/mach-s3c2410/devs.c
中没有设置正确的片选线(NGCS3),中断线(INT9)以及那个CMD连接A2上.
dm9000 Ethernet Driver
eth%d: Invalid ethernet MAC address. Please set using ifconfig
eth0: dm9000 at c4862300,c4864304 IRQ 53 MAC: 00:00:00:00:00:00
在dm9000驱动的源代码(driver/net/dm9000.c)中,默认是从ROM中读取MAC地址,而我的开发板
上没有ROM,所以在上面的驱动中我自己设置MAC地址就OK了.
在busybox里使用tftp下载文件时,总是提示timeout.后来又发现:开发板能ping通PC,而PC确不
能ping通开发板,若开发板ping PC的时候, PC确可以ping通开发板.
在驱动文件(driver/net/dm9000.c)的函数static int dm9000_open(struct net_device *dev)中,在申请
中断之前,指定申请的中断类型为上升沿中断.详细方法参考上面的代码.
关于jffs2文件系统的问题:
在使用下面这个命令创建的jffs2.img时会报错:
PC上: #mkfs.jffs2 -r jfss2 -o jffs2.img
开发板上:
>:echo jffs2.img > /dev/mtdb3
nand_write_ecc: Attempt to write not page aligned data
>: mount -t jffs2 /dev/mtdblock3 /apps/
mtd->read(0x400 bytes from 0x0) returned ECC error
CLEANMARKER node found at 0x00000000 has totlen 0xc != normal 0x0
mtd->read(0x2c bytes from 0xc) returned ECC error
使用下面这个命令创建的jffs2.img烧入很正常:
mkfs.jffs2 -r jffs2 -o jffs2.img -e 0x4000 --pad=0x1B00000 -s 0x200 –n
mkfs.jffs2的几个选项说明:
(1)-r : 指定要做成image的源資料夾.
(2)-o : 指定輸出image檔案的文件名.
(3)-e : 每一塊要抹除的block size,預設是64KB.要注意,不同的flash, 其block size會不一樣.我的是三星的K9F1208U0B.
(4)--pad (-p): 用16進制來表示所要輸出檔案的大小,也就是jffs2.img的size。很重要的是, 為了不浪費flash空間, 這個值最好符合flash driver所規劃的區塊大小.以我的板子來說,就是27MB(0x1B00000).
(5)如果挂载后会出现类似:CLEANMARKER node found at 0x0042c000 has totlen 0xc != normal 0x0 的警告,则加上 -n 就会消失。