Chinaunix首页 | 论坛 | 博客
  • 博客访问: 120940
  • 博文数量: 31
  • 博客积分: 0
  • 博客等级: 民兵
  • 技术积分: 296
  • 用 户 组: 普通用户
  • 注册时间: 2015-01-10 21:57
文章分类

全部博文(31)

文章存档

2016年(4)

2015年(27)

我的朋友

分类: LINUX

2015-03-02 17:24:51

linux内核:2.6.39

参考文档:http://blog.sina.com.cn/s/blog_63ac1cef0100ute3.html


 1) 添加网卡驱动的平台数据信息,包括:网卡的资源(地址资源、数据资源以及中断号等)、数据位数、网卡名称等。编辑文件arch/arm/plat-s3c24xx/devs.c,具体添加内容如下:
 
在文件开头添加:
38行: #include//在引用头文件处添加dm9000.h头文件,该文件包含S3C2410_CS4等定义 
 
在最后添加:

点击(此处)折叠或打开

  1. /* DM9000AEP 10/100 ethernet controller */
  2. #define MACH_MY2440_DM9K_BASE (S3C2410_CS4 + 0x300)

  3. static struct resource my2440_dm9k_resource[] = {
  4.         [0] = {
  5.                 .start = MACH_MY2440_DM9K_BASE,
  6.                 .end = MACH_MY2440_DM9K_BASE + 3,
  7.                 .flags = IORESOURCE_MEM
  8.         },
  9.         [1] = {
  10.                 .start = MACH_MY2440_DM9K_BASE + 4,
  11.                 .end = MACH_MY2440_DM9K_BASE + 7,
  12.                 .flags = IORESOURCE_MEM
  13.         },
  14.         [2] = {
  15.                 .start = IRQ_EINT7,
  16.                 .end = IRQ_EINT7,
  17.                 .flags = IORESOURCE_IRQ | IORESOURCE_IRQ_HIGHEDGE,
  18.         }
  19. };

  20. /*
  21.  * * The DM9000 has no eeprom, and it's MAC address is set by
  22.  * * the bootloader before starting the kernel.
  23.  * */
  24. static struct dm9000_plat_data my2440_dm9k_pdata = {
  25.         .flags = (DM9000_PLATF_16BITONLY | DM9000_PLATF_NO_EEPROM),
  26. };

  27. struct platform_device my2440_device_eth = {
  28.         .name = "dm9000",
  29.         .id = -1,
  30.         .num_resources = ARRAY_SIZE(my2440_dm9k_resource),
  31.         .resource = my2440_dm9k_resource,
  32.         .dev = {
  33.                 .platform_data = &my2440_dm9k_pdata,
  34.         },
  35. };

  36. EXPORT_SYMBOL(my2440_device_eth);
2) 导出my2440_device_eth变量。编辑arch/arm/plat-samsung/include/plat/devs.h文件,具体添加内容如下:

点击(此处)折叠或打开

  1. extern struct platform_device my2440_device_eth;
3) 添加my2440_device_eth到平台设备数组。编辑arch/arm/mach-s3c2440/mach-my2440.c文件,具体添加内容如下:

点击(此处)折叠或打开

  1. static struct platform_device *my2440_devices[] __initdata = {
  2.     &s3c_device_ohci,
  3.     &s3c_device_lcd,
  4.     &s3c_device_wdt,
  5.     &s3c_device_i2c0,
  6.     &s3c_device_iis,
  7. //lisi
  8.     &s3c_device_nand,
  9.     &s3c_device_rtc,
  10.     &my2440_device_eth,
  11. };
4)修改/drivers/net/dm9000.c文件。由于在common-smdk.c中设置了dm9000使用的系统资源是CS4,因此需要根据dm9000的芯片手册来设置BWSCON和BANKCON4寄存器。另外由于dm9000网卡中断信号为上升沿,因此需要在网卡注册中断前设置中断信号为上升沿有效。具体修改内容如下:
(1)添加处理s3c2440寄存器头文件,红色为增加部分的代码。

点击(此处)折叠或打开

  1. #include <asm/delay.h>
  2. #include <asm/irq.h>
  3. #include <asm/io.h>

  4. #if defined(CONFIG_ARCH_S3C2410)
  5. #include <mach/regs-mem.h>
  6. #endif
(2) dm9000_open()函数中添加对中断类型的处理

点击(此处)折叠或打开

  1. if (netif_msg_ifup(db))
  2.         dev_dbg(db->dev, "enabling %s\n", dev->name);

  3.     /* If there is no IRQ type specified, default to something that
  4.      * may work, and tell the user that this is a problem */

  5. #ifdef CONFIG_ARCH_S3C2410
  6.     irqflags = IRQF_SHARED | IRQF_TRIGGER_RISING;
  7. #else
  8.     if (irqflags == IRQF_TRIGGER_NONE)
  9.         dev_warn(db->dev, "WARNING: no IRQ resource flags set.\n");

  10.     irqflags |= IRQF_SHARED;
  11. #endif

  12.     if (request_irq(dev->irq, dm9000_interrupt, irqflags, dev->name, dev))
  13.         return -EAGAIN;
(3)dm9000_probe()函数中添加对BWSCON和BANKCON4寄存器的处理,具体的数值请查阅s3c2440A芯片手册

点击(此处)折叠或打开

  1. static int __devinit
  2. dm9000_probe(struct platform_device *pdev)
  3. {
  4.     struct dm9000_plat_data *pdata = pdev->dev.platform_data;
  5.     struct board_info *db;    /* Point a board information structure */
  6.     struct net_device *ndev;
  7.     const unsigned char *mac_src;
  8.     int ret = 0;
  9.     int iosize;
  10.     int i;
  11.     u32 id_val;
  12.     
  13. #if defined(CONFIG_ARCH_S3C2410)
  14.     unsigned int oldval_bwscon;
  15.     unsigned int oldval_bankcon4;
  16. #endif

  17.     /* Init network device */
  18.     ndev = alloc_etherdev(sizeof(struct board_info));
  19.     if (!ndev) {
  20.         dev_err(&pdev->dev, "could not allocate device.\n");
  21.         return -ENOMEM;
  22.     }

  23.     SET_NETDEV_DEV(ndev, &pdev->dev);
  24.     
  25. #if defined(CONFIG_ARCH_S3C2410)
  26.     oldval_bwscon = *((volatile unsigned int *)S3C2410_BWSCON);
  27.     *((volatile unsigned int *)S3C2410_BWSCON) = (oldval_bwscon & ~(3<<16)) |
  28.         S3C2410_BWSCON_DW4_16 | S3C2410_BWSCON_WS4 | S3C2410_BWSCON_ST4;
  29.     oldval_bankcon4 = *((volatile unsigned int *)S3C2410_BANKCON4);
  30.     *((volatile unsigned int *)S3C2410_BANKCON4) = 0x1f7c;
  31. #endif

  32.     dev_dbg(&pdev->dev, "dm9000_probe()\n");

点击(此处)折叠或打开

  1. out:
  2.     dev_err(db->dev, "not found (%d).\n", ret);

  3. #if defined(CONFIG_ARCH_S3C2410)
  4.     *((volatile unsigned int *)S3C2410_BWSCON) = oldval_bwscon;
  5.     *((volatile unsigned int *)S3C2410_BANKCON4) = oldval_bankcon4;
  6. #endif
  7.     
  8.     dm9000_release_board(pdev, db);
  9.     free_netdev(ndev);

  10.     return ret;
 由于s3c2440不能很好的从eeprom中读取网卡的MAC地址,因此需要在probe函数中手动设置网卡的MAC地址,即:在设置网卡MAC地址出屏蔽掉原来代码,手动添加自己的MAC

点击(此处)折叠或打开

  1. #ifdef CONFIG_ARCH_S3C2410
  2.     mac_src = "handy";
  3.     ndev->dev_addr[0] = 0x01;
  4.     ndev->dev_addr[1] = 0x23;
  5.     ndev->dev_addr[2] = 0x45;
  6.     ndev->dev_addr[3] = 0x67;
  7.     ndev->dev_addr[4] = 0x89;
  8.     ndev->dev_addr[5] = 0xab;
  9. #else
  10.     
  11.     mac_src = "eeprom";

  12.     /* try reading the node address from the attached EEPROM */
  13.     for (i = 0; i < 6; i += 2)
  14.         dm9000_read_eeprom(db, i / 2, ndev->dev_addr+i);

  15.     if (!is_valid_ether_addr(ndev->dev_addr) && pdata != NULL) {
  16.         mac_src = "platform data";
  17.         memcpy(ndev->dev_addr, pdata->dev_addr, 6);
  18.     }

  19.     if (!is_valid_ether_addr(ndev->dev_addr)) {
  20.         /* try reading from mac */
  21.         
  22.         mac_src = "chip";
  23.         for (i = 0; i < 6; i++)
  24.             ndev->dev_addr[i] = ior(db, i+DM9000_PAR);
  25.     }
  26. #endif

5)编译并配置内核
  [*] Networking support --->
        Networking options --->
              <*> Unix domain sockets
              [*] TCP/IP networking
              [*] IP:kernel level autoconfiguration
              [*] IP:DHCP support
  [*] Devices Drivers --->
         [*] Network device support --->
              [*] Ethernet(10 or 100Mbit) --->
                        <*> DM9000 support

6)DM9000网卡的配置
1.修改文件系统的“/etc/init.d/rcS”,添加如下所示内容:
     ifconfig lo 127.0.0.1  //设置本地回环设备IP地址
     net_set&               //调用网络配置文件
2.在文件系统的/sbin目录下新建一个可执行文件“net_set”,其内容如下:
       #!/bin/sh
       echo Try to bring eth0 interface up ...>/dev/tq2440_serial0
      
       if [ -f /etc/net.conf ];then
              source /etc/net.conf
             
              ifconfig eth0 down
              ifconfig eth0 hw ether $MAC
              echo ifconfig eth0 hw ether $MAC > /dev/tq2440_serial0
              ifconfig eth0 $IPADDR netmask $NETMASK up
              echo ifconfig eth0 $IPADDR netmask $NETMASK up >      
                                                 /dev/tq2440_serial0
              route add default gw $GATEWAY
              echo add default gw $GATEWAY > /dev/tq2440_serial0
       else
              ifconfig eth0 hw ether 10:23:45:67:89:ab
              ifconfig eth0 192.168.1.6 netmask 255.255.255.0 up
              route add default gw 192.128.1.2
              echo ifconfig eth0 hw ether 10:23:45:67:89:ab >
                                                  /dev/tq2440_serial0
              echo ifconfig eth0 192.168.1.6 netmask 255.255.255.0 up>
                                                 /dev/tq2440_serial0
              echo route add default gw 192.128.1.2 >/dev/tq2440_serial0
       fi
 
       echo Done > /dev/tq2440_serial0
 
3.然后在文件系统的/etc目录下新建“net.conf”文件用于存放网络配置信息
       IPADDR=192.168.1.6
       NETMASK=255.255.255.0
       GATEWAY=192.168.1.2
       MAC=10:23:45:67:89:ab
  当要修改网卡的IP地址时,只需要修改“/etc/net.conf”文件的内容后,执行一下net_set命令即可
然后,重新制作根文件系统,烧到开发板。




阅读(1361) | 评论(0) | 转发(0) |
给主人留下些什么吧!~~