移植路上真是荆棘满路,时不时让你疯狂一两天,却无可奈何...

        网上已有很多相关的移植教程,第一步,当然是照着做。问题是我的Linux是2.6.19.2,与前些版本相比(据查,2.6.17版还在),在移植过程中,我发现有两个变化。一是 include/asm-arm/irq.h 里已删除一些irq操作的预定义,如:

extern void disable_irq(unsigned int);
extern void enable_irq(unsigned int);
int set_irq_type(unsigned int irq, unsigned int type);

而网上的那个cs8900.c驱动比较老,与Linux-2.6.19.2带的cs89x0相差很大(据说这个驱动也没有使用新的驱动模型,不知道,这里应该与dm9000比较一下)。导致出现很多错误,不能编译 cs8900.c ,一天就这样在郁闷中过去...

      旧的不去,新的不来,干脆就直接用cs89x0.c ^_^ google到一个 pathch-cs89x0 ,哪个开心啊...可惜这个patch是针对2.6.14,自动patch失败,手动补齐后再添一些头文件、修改一些小错误,终于编译通过。可是,狂跳几下后又得郁闷了,出现了内核编程常见错误oops:

cs89x0:cs89x0_probe(0x0)
Unable to handle kernel paging request at virtual address f400030a
pgd = c0004000
[f400030a] *pgd=00000000
Internal error: Oops: 5 [#1]
Modules linked in:
CPU: 0
PC is at readword+0x1c/0x2c
LR is at cs89x0_probe1+0xec/0x874
pc : [ ]    lr : [ ]    Not tainted
sp : c032feb0  ip : c032fec0  fp : c032febc
r10: f4000300  r9 : 00000000  r8 : 00000000
r7 : c0f3b800  r6 : c0f3ba60  r5 : c0f3b800  r4 : f4000300
r3 : f400030a  r2 : 00000000  r1 : f400030a  r0 : f4000300
Flags: NzCv  IRQs on  FIQs on  Mode SVC_32  Segment kernel
Control: 717F
Table: 30004000  DAC: 00000017
Process swapper (pid: 1, stack limit = 0xc032e250)
Stack: (0xc032feb0 to 0xc0330000)
fea0:                                     c032ff4c c032fec0 c001bec8 c0139fa8
fec0: ffffffff c0f3b803 0000000a c032ff4c ffffffff 00000002 c0f3b800 ffffffff
fee0: c032ff30 c032fef0 c00fa694 c00f9e88 0000000a ffffffff ffffffff 00000002
ff00: 3f0c47ff 00000000 c0f3b800 00000000 00000000 00000000 00000000 c0021290
ff20: c032ff3c c002619c c0f3b800 00000000 00000000 00000000 00000000 c0021290
ff40: c032ff6c c032ff50 c001c6e0 c001bdec c0026164 00000001 00000000 c00217a4
ff60: c032ff88 c032ff70 c001bb04 c001c660 00000001 00000000 c032e000 c032ffa0
ff80: c032ff8c c001bbd0 c001bad0 00000000 c0021208 c032fff4 c032ffa4 c0027100
ffa0: c001bb48 00000001 c0027e24 c003caf4 00000000 00000000 c0027058 c0043128
ffc0: 00000000 00000000 00000000 00000000 00000000 00000000 00000000 00000000
ffe0: 00000000 00000000 00000000 c032fff8 c0043128 c0027068 0a00003e e5dc3001
Backtrace:
[ ] (readword+0x0/0x2c) from [ ] (cs89x0_probe1+0xec/0x874)
[ ] (cs89x0_probe1+0x0/0x874) from [ ] (cs89x0_probe+0x90/0x1)
[ ] (cs89x0_probe+0x0/0x108) from [ ] (probe_list2+0x44/0x78)
 r7 = C00217A4  r6 = 00000000  r5 = 00000001  r4 = C0026164
[ ] (probe_list2+0x0/0x78) from [ ] (net_olddevs_init+0x98/0x)
 r6 = C032E000  r5 = 00000000  r4 = 00000001
[ ] (net_olddevs_init+0x0/0xdc) from [ ] (init+0xa8/0x274)
 r5 = C0021208  r4 = 00000000
[ ] (init+0x0/0x274) from [ ] (do_exit+0x0/0x7d8)
Code: e0801001 e3510201 e1a03001 328334f2 (e1d300b0)
 <0>Kernel panic - not syncing: Attempted to kill init!

      前两天才在《Linux内核设计与实现》里看到的常见错误,想不到这么快就被我遇上...这里就是新版Linux第二个变化引起的错误。尝试更改映射的虚地址,无效。就在准备回去冲凉的瞬间,google里又出现一个好东西 ARM Linux Kernel Porting , 有原理图,有cs8900的实地址为0x19000000的解析(大致就是A24脚的高低电平控制cs8900开关,故+1000000),可惜是韩文, 里面的文字不知说什么,但错误现象一样,根据里面的代码再修改cs89x0一遍(这个文件真的很乱了^_^)。十分可惜,还是不能在我睡前干一件好 事...

      早上精神好啊,又经过一番搜索,终于发现问题,原来实地址与虚地址的映射结构 smdk2410_iodesc 里有所变化。第二个参数从原来的 unsigned long physical 变为 unsigned long pfn 。而从 smdk2410_iodesc 传入的SMDK2410_PA_CS8900A_BASE 仍然是一个 physical 值,因此出现 Unable to handle kernel paging request 错误。这里很感谢http://bibu.blogchina.com/bibu/4914641.html的作者,根据提示,将实地址作一个小小变化就Ok了 ^_^

#ifndef __ASM_ARCH_SMDK2410_H
#define __ASM_ARCH_SMDK2410_H

#define SMDK2410_PA_CS8900A_BASE       __phys_to_pfn(S3C2410_CS3 + 0x01000000) /* nGCS3 +0x01000000 */
#define SMDK2410_VA_CS8900A_BASE       S3C2410_ADDR(0x04000000)  /* 0xF4000000 */

#endif /* __ASM_ARCH_SMDK2410_H */

虚地址改多少无所谓,如0xE0000000,只要不和其它设备冲突就行。

      下面总结一下整个移植过程:

1. include/asm-arm/arch-s3c2410/map.h 

添加:
 /* CS8900 */
 #define S3C24XX_VA_CS8900   S3C2410_ADDR(0x04000000)
 #define S3C2410_PA_CS8900     __phys_to_pfn(0x19000000)
 #define S3C24XX_SZ_CS8900    SZ_1M
 #define S3C24XX_PA_CS8900    S3C2410_PA_CS8900

2. arch/arm/mach-s3c2410/mach-smdk2410.c 

修改

static struct map_desc smdk2410_iodesc[] __initdata={
        {S3C24XX_VA_CS8900IO, S3C2410_PA_CS8900, S3C24XX_SZ_CS8900, S3C24XX_SZ_CS8900, MT_DEVICE}
};

3. include/asm-arm/irq.h 

添加

int set_irq_type(unsigned int irq, unsigned int type);

4.  drivers/net/cs89x0.c

下面是我的 diff

--- ../linux2/linux-2.6.19.2/drivers/net/cs89x0.c 2007-01-11 03:10:37.000000000 +0800
+++ drivers/net/cs89x0.c 2007-02-04 21:16:42.000000000 +0800
@@ -96,6 +96,9 @@
   Dmitry Pervushin  : dpervushin@ru.mvista.com
                     : PNX010X platform support
 
+  Christian Pell    : chripell@gmail.com
+                    : SMDK2410 platform support, fixed bug with signed ioaddr
+
 */
 
 /* Always include 'config.h' first in case the user wants to turn on
@@ -194,6 +197,27 @@
 #define CIRRUS_DEFAULT_IRQ VH_INTC_INT_NUM_CASCADED_INTERRUPT_1 /* Event inputs bank 1 - ID 35/bit 3 */
 static unsigned int netcard_portlist[] __initdata = {CIRRUS_DEFAULT_BASE, 0};
 static unsigned int cs8900_irq_map[] = {CIRRUS_DEFAULT_IRQ, 0, 0, 0};
+
+#elif defined(CONFIG_ARCH_S3C2410) //Added weibing
+#include <linux/irq.h>
+#include <asm/irq.h>
+#include <asm/arch/irqs.h>
+#include <asm/arch/regs-mem.h>
+#include <asm/arch/regs-gpio.h>
+#include <asm/arch/smdk2410-map.h>
+
+static unsigned int netcard_portlist[] __initdata = {S3C24XX_VA_CS8900+0x300, 0};
+static unsigned int cs8900_irq_map[] = {IRQ_EINT9, 0, 0, 0};
+/*
+#ifdef request_region
+#undef request_region
+#endif
+#ifdef release_region
+#undef release_region
+#endif
+#define request_region(a,s,n) request_mem_region(a,s,n)
+#define release_region(a,s) release_mem_region(a,s)
+*/
 #else
 static unsigned int netcard_portlist[] __initdata =
    { 0x300, 0x320, 0x340, 0x360, 0x200, 0x220, 0x240, 0x260, 0x280, 0x2a0, 0x2c0, 0x2e0, 0};
@@ -246,7 +270,7 @@
 
 /* Index to functions, as function prototypes. */
 
-static int cs89x0_probe1(struct net_device *dev, int ioaddr, int modular);
+static int cs89x0_probe1(struct net_device *dev, unsigned int ioaddr, int modular);
 static int net_open(struct net_device *dev);
 static int net_send_packet(struct sk_buff *skb, struct net_device *dev);
 static irqreturn_t net_interrupt(int irq, void *dev_id);
@@ -324,6 +348,10 @@
  io = dev->base_addr;
  irq = dev->irq;
 
+#ifdef CONFIG_ARCH_S3C2410 //Added weibing
+ __raw_writel((__raw_readl(S3C2410_GPGCON)&~(0x3<<2))|(0x2<<2),S3C2410_GPGCON);
+ __raw_writel((__raw_readl(S3C2410_EXTINT1)&~(0x7<<4))|(0x4<<4),S3C2410_EXTINT1);
+#endif
  if (net_debug)
   printk("cs89x0:cs89x0_probe(0x%x)/n", io);
 
@@ -386,6 +414,18 @@
 {
  outw(value, base_addr + (portno << 1));
 }
+#elif defined(CONFIG_ARCH_S3C2410) //Added weibing
+static u16
+readword(unsigned long base_addr, int portno)
+{
+ return __raw_readw(base_addr+portno);
+}
+
+static void
+writeword(unsigned long base_addr, int portno,u16 value)
+{
+ __raw_writew(value,base_addr+portno);
+}
 #else
 static u16
 readword(unsigned long base_addr, int portno)
@@ -507,7 +547,7 @@
  */
 
 static int __init
-cs89x0_probe1(struct net_device *dev, int ioaddr, int modular)
+cs89x0_probe1(struct net_device *dev, unsigned int ioaddr, int modular)
 {
  struct net_local *lp = netdev_priv(dev);
  static unsigned version_printed;
@@ -638,7 +678,18 @@
     the driver will always do *something* instead of complain that
     adapter_cnf is 0. */
 
-#ifdef CONFIG_SH_HICOSH4
+#if defined CONFIG_ARCH_S3C2410
+ lp->force=FORCE_RJ45;
+ lp->auto_neg_cnf=IMM_BIT;
+
+ dev->dev_addr[0]=0x09; /*setMACaddress*/
+ dev->dev_addr[1]=0x90;
+ dev->dev_addr[2]=0x99;
+ dev->dev_addr[3]=0x09;
+ dev->dev_addr[4]=0x90;
+ dev->dev_addr[5]=0x99;
+
+#elif defined CONFIG_SH_HICOSH4
  if (1) {
   /* For the HiCO.SH4 board, things are different: we don't
      have EEPROM, but there is some data in flash, so we go
@@ -1036,7 +1087,7 @@
 {
 #if !defined(CONFIG_MACH_IXDP2351) && !defined(CONFIG_ARCH_IXDP2X01)
  struct net_local *lp = netdev_priv(dev);
- int ioaddr = dev->base_addr;
+ unsigned int ioaddr = dev->base_addr;
 #endif
  int reset_start_time;
 
@@ -1278,7 +1329,7 @@
  int i;
  int ret;
 
-#if !defined(CONFIG_SH_HICOSH4) && !defined(CONFIG_ARCH_PNX010X) /* uses irq#1, so this won't work */
+#if !defined(CONFIG_SH_HICOSH4) && !defined(CONFIG_ARCH_PNX010X) && !defined(CONFIG_ARCH_S3C2410) /* uses irq#1, so this won't work */
  if (dev->irq < 2) {
   /* Allow interrupts to be generated by the chip */
 /* Cirrus' release had this: */
@@ -1309,7 +1360,7 @@
  else
 #endif
  {
-#if !defined(CONFIG_MACH_IXDP2351) && !defined(CONFIG_ARCH_IXDP2X01) && !defined(CONFIG_ARCH_PNX010X)
+#if !defined(CONFIG_MACH_IXDP2351) && !defined(CONFIG_ARCH_IXDP2X01) && !defined(CONFIG_ARCH_PNX010X) && !defined(CONFIG_ARCH_S3C2410)
   if (((1 << dev->irq) & lp->irq_map) == 0) {
    printk(KERN_ERR "%s: IRQ %d is not in our map of allowable IRQs, which is %x/n",
                                dev->name, dev->irq, lp->irq_map);
@@ -1324,6 +1375,9 @@
   writereg(dev, PP_BusCTL, ENABLE_IRQ | MEMORY_ON);
 #endif
   write_irq(dev, lp->chip_type, dev->irq);
+#if defined(CONFIG_ARCH_S3C2410)
+  set_irq_type(dev->irq, IRQT_RISING);
+#endif
   ret = request_irq(dev->irq, &net_interrupt, 0, dev->name, dev);
   if (ret) {
    if (net_debug)
@@ -1394,7 +1448,7 @@
  case A_CNF_MEDIA_10B_2: result = lp->adapter_cnf & A_CNF_10B_2; break;
         default: result = lp->adapter_cnf & (A_CNF_10B_T | A_CNF_AUI | A_CNF_10B_2);
         }
-#ifdef CONFIG_ARCH_PNX010X
+#if defined(CONFIG_ARCH_PNX0105) || defined(CONFIG_ARCH_S3C2410)
  result = A_CNF_10B_T;
 #endif
         if (!result) {
@@ -1577,7 +1631,8 @@
 {
  struct net_device *dev = dev_id;
  struct net_local *lp;
- int ioaddr, status;
+ unsigned int ioaddr;
+ int status;
   int handled = 0;
 
  ioaddr = dev->base_addr;
@@ -1683,7 +1738,7 @@
  struct sk_buff *skb;
  int status, length;
 
- int ioaddr = dev->base_addr;
+ unsigned int ioaddr = dev->base_addr;
  status = readword(ioaddr, RX_FRAME_PORT);
  length = readword(ioaddr, RX_FRAME_PORT);

5.重新编译,重新启动,重新happy...

好了,现在可以挂NFS了,玩玩去...

...... ......

现在又有一不像问题的问题,网卡工作正常,但启动是提示申请 io 注册失败,request_region(0xf4000300, 0x10) failed 。

cs89x0:cs89x0_probe(0x0)
cs89x0.c: v2.4.3-pre1 Russell Nelson <nelson@crynwr.com>, Andrew Morton
eth0: cs8900 rev K found at 0xf4000300
cs89x0: Extended EEPROM checksum bad and no Cirrus EEPROM, relying on command le
cs89x0 media RJ-45, IRQ 53, programmed I/O, MAC 09:90:99:09:90:99
cs89x0_probe1() successful
cs89x0:cs89x0_probe(0x0)
cs89x0: request_region(0xf4000300, 0x10) failed
cs89x0: no cs8900 or cs8920 detected.  Be sure to disable PnP with SETUP

更改虚地址也无效,追踪一下,在 kernel/resource.c 里出现问题。不知为什么资源冲突了,我看网上移植cs8900到2.4版也有这个问题...不理,先向下跳,回过头来在处理它...

443                 for (;;) {
444                         struct resource *conflict;
445
446                         conflict = __request_resource(parent, res);
447                         if (!conflict)
448                                 break;
449 if (conflict != parent) {
450                                 parent = conflict;
451                                 if (!(conflict->flags & IORESOURCE_BUSY))
452                                         continue;
453                         }
454
455                         /* Uhhuh, that didn't work out.. */
456                         kfree(res);
457                         res = NULL;
458                         break;
459                 }

评论
  • 我按你的方法移植cs89x0.c 发现宏S3C2410_ADDR(X)不能正确转换虚地址。不得不手工强制smdk2410_iodesc[]中的内容为
    {
    (unsigned long) 0xF4000000,
    /*(unsigned long)S3C24XX_VA_CS8900,*/
    (unsigned long)S3C2410_PA_CS8900,
    (unsigned long)S3C24XX_SZ_CS8900,
    MT_DEVICE}
    请问weibin遇到过类似问题没有? 我的st2410板启动时也有request_region(0xf4000300, 0x10) failed 问题。

    weibing 回复 jjasonbao 说:
    S3C2410_ADDR(X) 在nclude/asm-arm/arch-s3c2410/map.h中定于如下:

    34 #ifndef __ASSEMBLY__
    35 #define S3C2410_ADDR(x) ((void __iomem *)0xF0000000 + (x))
    36 #else
    37 #define S3C2410_ADDR(x) (0xF0000000 + (x))
    38 #endif

    如果你的X不超过0x0FFFFFFF的话,就不存在“不能正确转换虚地址”的问题,还要注意不要与其它设备的地址相冲突。

    region(0xf4000300, 0x10) failed 的提示语句我也存在,但我cat /proc/iomem可以看到io资源已分配给cs8900,如下:

    55000000-550fffff : s3c2410-iis
    f0600000-f06fffff : s3c2410-lcd
    f1300300-f130030f : cs89x0

    注意这一句 +#define request_region(a,s,n) request_mem_region(a,s,n)
    我申请的是request_mem_region,所以用cat /proc/iomem查看,如果是request_region(a,s,n),应该用cat /proc/ioports查看...
    (2007-03-01 11:05:33)
    jjasonbao () 发表于 2007-03-01 00:15:19
  • cs8900终于搞定!真搞笑,苦苦调试了几天,一无所获。今早relax一 下,到处逛(在网上^_^),意外在u-boot的FAQ里看到这个 Ethernet does not work in Linux 。他说是不能获得MAC地址的问题,但我的网卡命名有一个09:90:99:09:90:99的地址!随便改一下,00:90:99:00:90:33, 想不到问题就这样解决...
    [root@RHAS linux-2.6.19.2]# telnet 202.192.33.120 99
    Trying 202.192.33.120...
    Connected to 202.192.33.120 (202.192.33.120).
    Escape character is '^]'.

    bb login: root


    BusyBox v1.4.1 (2007-02-08 00:35:21 CST) Built-in shell (ash)
    Enter 'help' for a list of built-in commands.

    Set search library path int /etc/profile
    Set user path in /etc/profile

    weibing 回复 weibing 说:
    奇怪,难道这样的MAC地址也冲突?唉,老样子,不理,先继续调触摸屏...
    (2007-02-12 11:27:17)
    weibing () 发表于 2007-02-12 11:22:31
  • 我刚开始时遇到和你完全一样的错误,
    按你的方法patch之后,
    居然
    cs89x0: no cs8900 or cs8920 detected.
    昏迷了~
    uboot驱动是成功的,所以硬件没有问题
    不知道问题出在何处,
    /linux/irq.h加到cs89x0.c里会有错误,
    不加可以编译通过,不知道和这个有无关系...

    weibing 回复 sanicle 说:
    恩, 我这几天都在查这个问题,挂nfs根文件系统一切正常,也可以ping,但其它通信都有问题。 request_region这一句申请io资源失败,cat /proc/iomem可以看到io资源已分配给cs8900... 55000000-550fffff : s3c2410-iis f0600000-f06fffff : s3c2410-lcd f1300300-f130030f : cs89x0 关于编译失败,与你的linux和交叉链版本有关,我用3.4.1的交叉链编译alsa声卡驱动提示一大堆错误,2.95.3没有这些错误,但我的 linux-2.6.19.2不让它编译,说 Sorry, your compiler is too old/not recognized. 实在没办法,我继续测试一下... BTW,你的小窝很不错 ^_^
    (2007-02-12 09:00:08)
    sanicle ( 3mn.net) 发表于 2007-02-12 00:22:19
  • 汗,Linux改变 map_desc 结构的同时也提供一个
    #define IODESC_ENT(x) { (unsigned long)S3C24XX_VA_##x, __phys_to_pfn(S3C24XX_PA_##x), S3C24XX_SZ_##x, MT_DEVICE }
    这样的宏。
    {S3C24XX_VA_CS8900IO, S3C2410_PA_CS8900, S3C24XX_SZ_CS8900, S3C24XX_SZ_CS8900, MT_DEVICE} 改为 IODESC_ENT(cs8900) 就搞定了...

    weibing () 发表于 2007-02-07 20:56:35
 
Logo

更多推荐