Linux-2.6.12移植到斯道s3c2410
硬件設(shè)備:網(wǎng)卡:dm9000NandFlash:K9F1208U0C 64M
1, 下載并解壓縮內(nèi)核,修改頂層Makefile的編譯器選項(xiàng):
ARCH ?=arm
CROSS_COMPILE ?=arm-softfloat-linux-gnu-
2, 修改linux-2.6.12/arch/arm/mach-s3c2410/devs.c, 使其支持NandFlash和DM9000網(wǎng)卡:
添加頭文件:
#include //該頭文件將從linux-2.6.14的內(nèi)核中copy到include/linux中去
#include
#include
#include
添加dm9000網(wǎng)卡設(shè)備的支持
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, 中斷線(xiàn)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,導(dǎo)出dm9000設(shè)備:
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的內(nèi)核中拷貝driver/net/dm9000.c和dm9000.h到相應(yīng)目錄,同時(shí)拷貝
linux-2.6.14/include/linux/dm9000.h到linux-2.6.12的相應(yīng)目錄.修改driver/net/dm9000.c如下:
在文件開(kāi)始處添加:
#define INTMOD (0x4A000004) //These two line add by guowenxue 2008.11.15
static void *intmod;
在static int dm9000_probe(struct device *dev)函數(shù)申明完變量后添加:
intmod=ioremap_nocache(INTMOD,0x0000004);
writel(0x0,intmod);
同樣在該函數(shù)中,注釋掉從ROM中讀MAC地址,改為我們自己設(shè)置的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
在函數(shù)static int dm9000_open(struct net_device *dev)中添加set_irq_tye():
set_irq_type(dev->irq, IRQT_RISING); // 申請(qǐng)類(lèi)型為上升沿中斷,否則PC ping不通開(kāi)發(fā)板.
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"
修改結(jié)構(gòu)體static struct uart_driver s3c24xx_uart_drv的成員.dev_name為:
// .dev_name = "s3c2410_serial",
.dev_name = "ttyS",
之前編譯的內(nèi)核,怎么都不能初始化console,進(jìn)入busybox,原來(lái)s3c2410默認(rèn)的串口名并不是
ttyS0或tySAC0. 另外S3C2410的串口主設(shè)備號(hào)注冊(cè)為204,次設(shè)備號(hào)為64.這樣我們?cè)诟募?br/>系統(tǒng)里就要注意了:#mknod –mode=755 ttyS0 c 204 64
7, 修改文件drivers/net/arm/Kconfig,添加dm9000驅(qū)動(dòng)選項(xiàng):
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的編譯選項(xiàng).
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)
移植過(guò)程中碰到的主要問(wèn)題及解決方法
1, NAND_ECC_NONE selected by board driver. This is not recommended !!
和Reading data from NAND FLASH without ECC is not recommended
這是因?yàn)殛P(guān)閉了mtd/nand/s3c2410.c中的ECC檢測(cè):
不要在函數(shù)s3c2410_nand_init_chip()的最后添加下面這行代碼:
Chip->eccmode = NAND_ECC_NONE;
不關(guān)閉硬件ECC, 使用cramfs和jffs2文件系統(tǒng)很正常,對(duì)于yaffs2還沒(méi)試過(guò).
2, ftl_cs: FTL header not found.
Make menuconfig時(shí):
Device Drivers -?
Memory Technology Devices (MTD) -?不要選擇下面這三個(gè)選項(xiàng)
<>FTL (Flash Translation Layer) support
<> NFTL (NAND Flash Translation Layer) support
<>INFTL (Inverse NAND Flash Translation Layer) support
3, linux啟動(dòng)busybox時(shí)提示: Can't open /dev/ttyS0: No such file or directory
這是因?yàn)閮?nèi)核里s3c2410的串口驅(qū)動(dòng),注冊(cè)的串口設(shè)備名并不是ttyS0,并且串口設(shè)備的
主,次設(shè)備號(hào)也不是根文件系統(tǒng)/dev目錄下的設(shè)備. 按照上面移植內(nèi)核的方法,修改s3c2410
的串口驅(qū)動(dòng)程序(linux-2.6.12/drivers/serial/s3c2410.c)就OK了.
4, 關(guān)于dm9000網(wǎng)卡驅(qū)動(dòng)的幾個(gè)問(wèn)題:
dm9000 Ethernet Driver
dm9000: read wrong id 0x2b2a2928
dm9000: read wrong id 0x2b2a2928
dm9000: wrong id: 0x2b2a2928
dm9000: not found (0).
主要是最開(kāi)始按照網(wǎng)上移植dm9000的驅(qū)動(dòng)方法,在文件linux-2.6.12/arch/arm/mach-s3c2410/devs.c
中沒(méi)有設(shè)置正確的片選線(xiàn)(NGCS3),中斷線(xiàn)(INT9)以及那個(gè)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驅(qū)動(dòng)的源代碼(driver/net/dm9000.c)中,默認(rèn)是從ROM中讀取MAC地址,而我的開(kāi)發(fā)板
上沒(méi)有ROM,所以在上面的驅(qū)動(dòng)中我自己設(shè)置MAC地址就OK了.
在busybox里使用tftp下載文件時(shí),總是提示timeout.后來(lái)又發(fā)現(xiàn):開(kāi)發(fā)板能ping通PC,而PC確不
能ping通開(kāi)發(fā)板,若開(kāi)發(fā)板ping PC的時(shí)候, PC確可以ping通開(kāi)發(fā)板.
在驅(qū)動(dòng)文件(driver/net/dm9000.c)的函數(shù)static int dm9000_open(struct net_device *dev)中,在申請(qǐng)
中斷之前,指定申請(qǐng)的中斷類(lèi)型為上升沿中斷.詳細(xì)方法參考上面的代碼.
關(guān)于jffs2文件系統(tǒng)的問(wèn)題:
在使用下面這個(gè)命令創(chuàng)建的jffs2.img時(shí)會(huì)報(bào)錯(cuò):
PC上: #mkfs.jffs2 -r jfss2 -o jffs2.img
開(kāi)發(fā)板上:
>: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
使用下面這個(gè)命令創(chuàng)建的jffs2.img燒入很正常:
mkfs.jffs2 -r jffs2 -o jffs2.img -e 0x4000 --pad=0x1B00000 -s 0x200 –n
mkfs.jffs2的幾個(gè)選項(xiàng)說(shuō)明:
(1)-r : 指定要做成image的源資料夾.
(2)-o : 指定輸出image檔案的文件名.
(3)-e : 每一塊要抹除的block size,預(yù)設(shè)是64KB.要注意,不同的flash, 其block size會(huì)不一樣.我的是三星的K9F1208U0B.
(4)--pad (-p): 用16進(jìn)制來(lái)表示所要輸出檔案的大小,也就是jffs2.img的size。很重要的是, 為了不浪費(fèi)flash空間, 這個(gè)值最好符合flash driver所規(guī)劃的區(qū)塊大小.以我的板子來(lái)說(shuō),就是27MB(0x1B00000).
(5)如果掛載后會(huì)出現(xiàn)類(lèi)似:CLEANMARKER node found at 0x0042c000 has totlen 0xc != normal 0x0 的警告,則加上 -n 就會(huì)消失。