Chinaunix首页 | 论坛 | 博客
  • 博客访问: 2295898
  • 博文数量: 218
  • 博客积分: 5767
  • 博客等级: 大校
  • 技术积分: 5883
  • 用 户 组: 普通用户
  • 注册时间: 2008-03-01 14:44
文章存档

2012年(53)

2011年(131)

2009年(1)

2008年(33)

分类: LINUX

2011-09-16 09:22:35

作者:mutes
硬件环境:ST2410X开发板(CPU:S3C2410X)
内核版本:linux2.6.36
运行环境:Window7  Vmware workstation7.1   FC13
交叉编译环境:Arm-linux-gcc-4.3.2 with EABI
移植时间:2011.09.15

1. 准备必要的文件
首先去官方网站下载最新的 linux 内核
ftp://ftp.kernel.org/pub/linux/kernel/v2.6/linux-2.6.36.tar.bz2
因为 linux-2.6.36内核需要更新版本的编译器,所以需要下载交叉编译器
2. 安装文件
把 arm-linux-gcc 安装在 /opt 目录下,安装方法和安装 gcc2.95.3 和 gcc3.3.2 是相同的!
接下来需要解压 linux 内核,输入命令:
 tar jxvf linux-2.6.36.tar. bz2
内核被解压到 linux-2.6.36 目录下。
3. 修改 makefile 文件
内核的编译是根据 makefile 文件的指示进行的, Makefile 文件来组织内核的各模块之间的关系,记录了各个模块之间的相互联系和依赖关系。
我们首先修改 linux-2.6.36 的根目录下的 makfile 文件,须改的主要内容是目标代码的类型和为编译内核指定一个编译器。将以下内容
#ARCH   ?= $(SUBARCH)
#CROSS_COMPILE     ?=
更改为如下内容:
ARCH   ?= arm
CROSS_COMPILE ?=/opt/usr/local/arm/4.3.2/bin/arm-linux-

4make s3c2410_defconfig;make uImage;

uboot一般使用mkimage工具先制作一个启动映象文件来引导识别内核的,uboot源代码的tools/目录下有mkimage工具,这个工具可以用来制作不压缩或者压缩的多种可启动映象文件。mkimage在制作映象文件的时候,要先编译uboot,然后将u-boot-1.1.6/tools/mkimage拷贝到/usr/sbin目录下

最后
 cp arch/arm/boot/uImage /tftpboot/
ok可以启动试一下了。

5 修改 arch/arm/plat-s3c24xx/common-smdk.c 文件
说明:这里linux-2.6.36的设置分区与其他版本如2.6.14或2.6.11有点区别,其他版本是修改arch/arm/machs3c2410/devs.c和arch/arm/machs3c2410/mach-smdk2410.c 但linux-2.6.36设置这些文件无效。
设置Nand Flash的分区和信息,下面是我的分区结构(与BIOS的分区保持一至):
name: 代表分区名字
size: 代表flash分区大小(单位:字节)
offset: 代表flash分区的起始地址(相对于0x0的偏移)
目标板计划分4个区,分别存放loader, param,kernel, root以及以便以后扩展使用的用户文件系统空间。
注:分区表信息要参考你自己的内核和文件系统的大小,排布来设置,BIOS中的分区信息要和mtd分区信息一致,分多少个区由你自己决定,我的就只分了4个区^_^。
static struct mtd_partition smdk_default_nand_part[] = {
        [0] = {
                .name   = "loader",
                .size   = SZ_256K,
                .offset = 0,
        },
        [1] = {
                .name   = "kernel",
                .offset = MTDPART_OFS_APPEND,
                .size   = SZ_1M + SZ_256K + SZ_512K,
        },
        [2] = {
                .name   = "root",
                .offset = SZ_2M,
                .size   = SZ_32M,
        },
        [3] = {
                .name   = "user1",
                .offset = MTDPART_OFS_APPEND,
                .size   = MTDPART_SIZ_FULL,
        }
};
修改nand flash的参数:
在同一个文件中找到
static struct s3c2410_platform_nand smdk_nand_info = {
    .tacls        = 20,
    .twrph0        = 60,
    .twrph1        = 20,
    .nr_sets    = ARRAY_SIZE(smdk_nand_sets),
    .sets        = smdk_nand_sets,
};
改成
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
839                 chip->ecc.mode      = NAND_ECC_NONE;//NAND_ECC_SOFT;

开发环境必须的网卡驱动。开发板用的是cs8900的网卡。

6.将准备好的cs8900.c/cs8900.h两个文件复制到drivers/net/arm目录下

7.在include/net/目录下创建文件smdk2410.h,并添加如下代码:
  #define pSMDK2410_ETH_IO        __phys_to_pfn(0x19000000)
  #define vSMDK2410_ETH_IO        0xE0000000
  #define SMDK2410_EHT_IRQ        IRQ_EINT9

8.在arch/arm/mach-s3c2410/mach-smdk2410.c中加入"#include "
在struct map_desc smdk2410_iodesc[]中添加cs8900相应的io空间映射:
   {vSMDK2410_ETH_IO, pSMDK2410_ETH_IO, SZ_1M, MT_DEVICE}


9.在drivers/net/arm/目录下的Makefile中加入cs8900相关项:
    obj-$(CONFIG_ARM_CS8900)    += cs8900.o
 在drivers/net/arm/目录下的Kconfig中加入cs8900相关项:
config ARM_CS8900
    tristate "CS8900 support"
    depends on NET_ETHERNET && ARM && (ARCH_SMDK2410 || ARCH_ZL2440 || MACH_MINI2440)
    help
      Support for CS8900A chipset based Ethernet cards. If you have a
      network (Ethernet) card of this type, say Y and read the
      Ethernet-HOWTO, available from
      < as well as .
   
      To compile this driver as a module, choose M here and read
      .  The module will be called   

10.make menuconfig选中cs8900选项,去掉dm9000选项。

11.make 之后加载到开发板,提示
NET: Registered protocol family 17                                                                                                              
drivers/rtc/hctosys.c: unable to open rtc device (rtc0)                                                                                         
Root-NFS: No NFS server available, giving up.                                                                                                   
VFS: Unable to mount root fs via NFS, trying floppy.                                                                                            
VFS: Cannot open root device "hda1" or unknown-block(2,0)                                                                                       
Please append a correct "root=" boot option; here are the available partitions:                                                                 
1f00             256 mtdblock0 (driver?)                                                                                                        
1f01            1792 mtdblock1 (driver?)                                                                                                        
1f02           32768 mtdblock2 (driver?)                                                                                                        
1f03           30720 mtdblock3 (driver?)                                                                                                        
Kernel panic - not syncing: VFS: Unable to mount root fs on unknown-block(2,0)                                                                  
Backtrace:                                                                                                                                      
[] (dump_backtrace+0x0/0x114) from [] (dump_stack+0x18/0x1c)                                                                
 r7:00008001 r6:c389f000 r5:c012aa14 r4:c052dc04                                                                                                
[] (dump_stack+0x0/0x1c) from [] (panic+0x60/0x184)                                                                         
[] (panic+0x0/0x184) from [] (mount_block_root+0x1e0/0x220)                                                                 
 r3:00000000 r2:20000013 r1:c3819f6c r0:c04a6b7c                                                                                                
[] (mount_block_root+0x0/0x220) from [] (mount_root+0xc4/0xfc)                                                              
 r8:00000000 r7:00000013 r6:c015753c r5:00000000 r4:00200000                                                                                    
[] (mount_root+0x0/0xfc) from [] (prepare_namespace+0x170/0x1c4)                                                            
 r5:c012aa14 r4:c052d2e4                                                                                                                        
[] (prepare_namespace+0x0/0x1c4) from [] (kernel_init+0x110/0x150)                                                          
 r5:c0108550 r4:c052d280                                                                                                                        
[] (kernel_init+0x0/0x150) from [] (do_exit+0x0/0x5a0)                                                                      
 r4:00000000 
无法挂载NFS文件系统,在肉核启动信息中可以找到下面信息
Kernel command line: root=/dev/hda1 ro init=/bin/bash console=ttySAC0
原来uboot没有将设置好的命令行参数传递到内核,因为在uboot中我已经设置了
bootargs=root=/dev/nfs rw nfsroot=192.168.1.54:/opt/nfs/filesys ip=192.168.1.56:192.168.1.54:192.168.1.1:255.255.255.0 console=ttySAC0,115200
修改内核源码中的.config文件,设置好CONFIG_CMDLINE为
CONFIG_CMDLINE="root=/dev/nfs rw nfsroot=192.168.1.54:/opt/nfs/filesys ip=192.168.1.56:192.168.1.54:192.168.1.1:255.255.255.0 init=/linuxrc console=ttySAC0,115200"

可以启动了。

下面说一下内核中网卡和cs8900驱动相关的话题:
由于内核更新后,struct net_device结构体及相关宏定义有变化,或造成在2.6.16/2.6.22/2.6.24内核工作的cs8900驱动在2.6.36上不能编译通过。主要修改如下:
    1>"IRQT_RISING"改成"IRQ_TYPE_EDGE_RISING"
    2>2.6.36内核的net_device中没有“priv“和"mc_list"项”。代码都要作相应修改。
    3>以前内核(2.6.16/2.6.22/2.6.24)struct net_device中的函数指针域在2.6.36中都放在struct net_device_ops类型的指针netdev_ops指向的结构体中。也要作相应修改。


附件是修改后的cs8900.c和cs8900.h文件。
文件传不上来。贴上吧。
下面是cs8900.c文件:



 
#define VERSION_STRING "Cirrus Logic CS8900A driver for Linux (Modified for ZL2440)"





#include
#include
#include
#include
#include
#include
#include
#include
#include
#include
//#include

#include
#include
#include
#include
#include

// Added BSt

#include



//#ifdef CONFIG_ARCH_SMDK2410

#if 1
//#include "asm/arch-s3c2410/regs-irq.h"

#include "mach/regs-mem.h"
//#include "asm/arch/smdk2410.h"

#include "net/smdk2410.h"

#endif

#include "cs8900.h"

//#define FULL_DUPLEX

//#define DEBUG


typedef struct {
    struct net_device_stats stats;
    u16 txlen;
    int char_devnum;

        spinlock_t lock;
} cs8900_t;

int cs8900_probe (struct net_device *dev);
static struct net_device *cs8900_dev ;



#define MAX_EEPROM_SIZE        256





static inline u16 cs8900_read (struct net_device *dev,u16 reg)
{
    outw (reg,dev->base_addr + PP_Address);
    return (inw (dev->base_addr + PP_Data));
}

static inline void cs8900_write (struct net_device *dev,u16 reg,u16 value)
{
    outw (reg,dev->base_addr + PP_Address);
    outw (value,dev->base_addr + PP_Data);
}

static inline void cs8900_set (struct net_device *dev,u16 reg,u16 value)
{
    cs8900_write (dev,reg,cs8900_read (dev,reg) | value);
}

static inline void cs8900_clear (struct net_device *dev,u16 reg,u16 value)
{
    cs8900_write (dev,reg,cs8900_read (dev,reg) & ~value);
}

static inline void cs8900_frame_read (struct net_device *dev,struct sk_buff *skb,u16 length)
{
    insw (dev->base_addr,skb_put (skb,length),(length + 1) / 2);
}

static inline void cs8900_frame_write (struct net_device *dev,struct sk_buff *skb)
{
    outsw (dev->base_addr,skb->data,(skb->len + 1) / 2);
}



#ifdef DEBUG
static inline int printable (int c)
{
    return ((c >= 32 && c <= 126) ||
            (c >= 174 && c <= 223) ||
            (c >= 242 && c <= 243) ||
            (c >= 252 && c <= 253));
}

static void dump16 (struct net_device *dev,const u8 *s,size_t len)
{
    int i;
    char str[128];

    if (!len) return;

    *str = '\0';

    for (i = 0; i < len; i++) {
        if (i && !(i % 4)) strcat (str," ");
        sprintf (str,"%s%.2x ",str,s[i]);
    }

    for ( ; i < 16; i++) {
        if (i && !(i % 4)) strcat (str," ");
        strcat (str," ");
    }

    strcat (str," ");
    for (i = 0; i < len; i++) sprintf (str,"%s%c",str,printable (s[i]) ? s[i] : '.');

    printk (KERN_DEBUG "%s: %s\n",dev->name,str);
}

static void hexdump (struct net_device *dev,const void *ptr,size_t size)
{
    const u8 *s = (u8 *) ptr;
    int i;
    for (i = 0; i < size / 16; i++, s += 16) dump16 (dev,s,16);
    dump16 (dev,s,size % 16);
}

static void dump_packet (struct net_device *dev,struct sk_buff *skb,const char *type)
{
    printk (KERN_INFO "%s: %s %d byte frame %.2x:%.2x:%.2x:%.2x:%.2x:%.2x to %.2x:%.2x:%.2x:%.2x:%.2x:%.2x type %.4x\n",
            dev->name,
            type,
            skb->len,
            skb->data[0],skb->data[1],skb->data[2],skb->data[3],skb->data[4],skb->data[5],
            skb->data[6],skb->data[7],skb->data[8],skb->data[9],skb->data[10],skb->data[11],
            (skb->data[12] << 8) | skb->data[13]);
    if (skb->len < 0x100) hexdump (dev,skb->data,skb->len);
}


#endif    



static void cs8900_receive (struct net_device *dev)
{
    //cs8900_t *priv = (cs8900_t *) dev->priv;

    cs8900_t *priv = (cs8900_t *)netdev_priv(dev);
    struct sk_buff *skb;
    u16 status,length;

    status = cs8900_read (dev,PP_RxStatus);
    length = cs8900_read (dev,PP_RxLength);

    if (!(status & RxOK)) {
        priv->stats.rx_errors++;
        if ((status & (Runt | Extradata))) priv->stats.rx_length_errors++;
        if ((status & CRCerror)) priv->stats.rx_crc_errors++;
        return;
    }

    if ((skb = dev_alloc_skb (length + 4)) == NULL) {
        priv->stats.rx_dropped++;
        return;
    }

    skb->dev = dev;
    skb_reserve (skb,2);

    cs8900_frame_read (dev,skb,length);

#ifdef FULL_DUPLEX
    dump_packet (dev,skb,"recv");
#endif    

    skb->protocol = eth_type_trans (skb,dev);

    netif_rx (skb);
    dev->last_rx = jiffies;

    priv->stats.rx_packets++;
    priv->stats.rx_bytes += length;
}

static int cs8900_send_start (struct sk_buff *skb,struct net_device *dev)
{
    //cs8900_t *priv = (cs8900_t *) dev->priv;

    cs8900_t *priv = (cs8900_t *)netdev_priv(dev);
    u16 status;

    spin_lock_irq(&priv->lock);
    netif_stop_queue (dev);

    cs8900_write (dev,PP_TxCMD,TxStart (After5));
    cs8900_write (dev,PP_TxLength,skb->len);

    status = cs8900_read (dev,PP_BusST);

    if ((status & TxBidErr)) {
        spin_unlock_irq(&priv->lock);
        printk (KERN_WARNING "%s: Invalid frame size %d!\n",dev->name,skb->len);
        priv->stats.tx_errors++;
        priv->stats.tx_aborted_errors++;
        priv->txlen = 0;
        return (1);
    }

    if (!(status & Rdy4TxNOW)) {
        spin_unlock_irq(&priv->lock);
        printk (KERN_WARNING "%s: Transmit buffer not free!\n",dev->name);
        priv->stats.tx_errors++;
        priv->txlen = 0;
        
        return (1);
    }

    cs8900_frame_write (dev,skb);
    spin_unlock_irq(&priv->lock);

#ifdef DEBUG
    dump_packet (dev,skb,"send");
#endif    

    dev->trans_start = jiffies;

    dev_kfree_skb (skb);

    priv->txlen = skb->len;

    return (0);
}

static irqreturn_t cs8900_interrupt (int irq,void *id)
{
    struct net_device *dev = (struct net_device *) id;
    cs8900_t *priv;
    volatile u16 status;
     irqreturn_t handled = 0;

#if 0
    if (dev->priv == NULL) {
        printk (KERN_WARNING "%s: irq %d for unknown device.\n",dev->name,irq);
        return 0;
    }
#endif

    //priv = (cs8900_t *) dev->priv;

    priv = (cs8900_t *)netdev_priv(dev);
    
    while ((status = cs8900_read (dev, PP_ISQ))) {
        handled = 1;
        switch (RegNum (status)) {
        case RxEvent:
            cs8900_receive (dev);
            break;

        case TxEvent:
            priv->stats.collisions += ColCount (cs8900_read (dev,PP_TxCOL));
            if (!(RegContent (status) & TxOK)) {
                priv->stats.tx_errors++;
                if ((RegContent (status) & Out_of_window)) priv->stats.tx_window_errors++;
                if ((RegContent (status) & Jabber)) priv->stats.tx_aborted_errors++;
                break;
            } else if (priv->txlen) {
                priv->stats.tx_packets++;
                priv->stats.tx_bytes += priv->txlen;
            }
            priv->txlen = 0;
            netif_wake_queue (dev);
            break;

        case BufEvent:
            if ((RegContent (status) & RxMiss)) {
                u16 missed = MissCount (cs8900_read (dev,PP_RxMISS));
                priv->stats.rx_errors += missed;
                priv->stats.rx_missed_errors += missed;
            }
            if ((RegContent (status) & TxUnderrun)) {
                priv->stats.tx_errors++;
                priv->stats.tx_fifo_errors++;

                priv->txlen = 0;
                netif_wake_queue (dev);
            }
            
            break;

        case TxCOL:
            priv->stats.collisions += ColCount (cs8900_read (dev,PP_TxCOL));
            break;

        case RxMISS:
            status = MissCount (cs8900_read (dev,PP_RxMISS));
            priv->stats.rx_errors += status;
            priv->stats.rx_missed_errors += status;
            break;
        }
    }
    return IRQ_RETVAL(handled);
}

static void cs8900_transmit_timeout (struct net_device *dev)
{
    //cs8900_t *priv = (cs8900_t *) dev->priv;

    cs8900_t *priv = (cs8900_t *)netdev_priv(dev);
    priv->stats.tx_errors++;
    priv->stats.tx_heartbeat_errors++;
    priv->txlen = 0;
    netif_wake_queue (dev);
}

static int cs8900_start (struct net_device *dev)
{
    int result;

    //set_irq_type(dev->irq, IRQT_RISING);

    set_irq_type(dev->irq, IRQ_TYPE_EDGE_RISING);

    
    cs8900_set (dev,PP_RxCFG,RxOKiE | BufferCRC | CRCerroriE | RuntiE | ExtradataiE);
    cs8900_set (dev,PP_RxCTL,RxOKA | IndividualA | BroadcastA);
    cs8900_set (dev,PP_TxCFG,TxOKiE | Out_of_windowiE | JabberiE);
    cs8900_set (dev,PP_BufCFG,Rdy4TxiE | RxMissiE | TxUnderruniE | TxColOvfiE | MissOvfloiE);
    cs8900_set (dev,PP_LineCTL,SerRxON | SerTxON);
    cs8900_set (dev,PP_BusCTL,EnableRQ);

#ifdef FULL_DUPLEX
    cs8900_set (dev,PP_TestCTL,FDX);
#endif    
    udelay(200);    
    
    if ((result = request_irq (dev->irq, &cs8900_interrupt, 0, dev->name, dev)) < 0) {
        printk (KERN_ERR "%s: could not register interrupt %d\n",dev->name, dev->irq);
        return (result);
    }
    
    
    netif_start_queue (dev);

    return (0);
}

static int cs8900_stop (struct net_device *dev)
{
    
    cs8900_write (dev,PP_BusCTL,0);
    cs8900_write (dev,PP_TestCTL,0);
    cs8900_write (dev,PP_SelfCTL,0);
    cs8900_write (dev,PP_LineCTL,0);
    cs8900_write (dev,PP_BufCFG,0);
    cs8900_write (dev,PP_TxCFG,0);
    cs8900_write (dev,PP_RxCTL,0);
    cs8900_write (dev,PP_RxCFG,0);

    
    free_irq (dev->irq,dev);

    
    netif_stop_queue (dev);

    return (0);
}

static struct net_device_stats *cs8900_get_stats (struct net_device *dev)
{
    //cs8900_t *priv = (cs8900_t *) dev->priv;

    cs8900_t *priv = (cs8900_t *)netdev_priv(dev);
    return (&priv->stats);
}

static void cs8900_set_receive_mode (struct net_device *dev)
{
    if ((dev->flags & IFF_PROMISC))
        cs8900_set (dev,PP_RxCTL,PromiscuousA);
    else
        cs8900_clear (dev,PP_RxCTL,PromiscuousA);

    //if ((dev->flags & IFF_ALLMULTI) && dev->mc_list)

    if ((dev->flags & IFF_ALLMULTI) && !netdev_mc_empty(dev))
        cs8900_set (dev,PP_RxCTL,MulticastA);
    else
        cs8900_clear (dev,PP_RxCTL,MulticastA);
}




int __init cs8900_probe (struct net_device *dev)
{
    static cs8900_t *priv;
    int i,result;
    u16 value;

    printk (VERSION_STRING"\n");

    memset (&priv,0,sizeof (cs8900_t));

    //+kevin

    __raw_writel(0x2211d110,S3C2410_BWSCON);
    __raw_writel(0x1f7c,S3C2410_BANKCON3);



//#if defined(CONFIG_ARCH_SMDK2410)

#if 1
    dev->dev_addr[0] = 0x00;
    dev->dev_addr[1] = 0x00;
    dev->dev_addr[2] = 0x3e;
    dev->dev_addr[3] = 0x26;
    dev->dev_addr[4] = 0x0a;
    dev->dev_addr[5] = 0x00;

#endif

    dev->if_port = IF_PORT_10BASET;
    //dev->priv = (void *) &priv;

    priv = (cs8900_t *)netdev_priv(dev);
    spin_lock_init(&priv->lock);

    //hejiasheng SET_MODULE_OWNER (dev);



//#if defined(CONFIG_ARCH_SMDK2410)

#if 1
    dev->base_addr = vSMDK2410_ETH_IO + 0x300;
    dev->irq = IRQ_EINT9;
    printk("debug:[%s-%d]\n", __func__, __LINE__);
#endif

    if ((result = check_mem_region (dev->base_addr, 16))) {
        printk (KERN_ERR "%s: can't get I/O port address 0x%lx\n",dev->name,dev->base_addr);
        return (result);
    }
    request_mem_region (dev->base_addr, 16, dev->name);
    
    printk("debug:[%s-%d]\n", __func__, __LINE__);
     
    if ((value = cs8900_read (dev,PP_ProductID)) != EISA_REG_CODE) {
        printk (KERN_ERR "%s: incorrect signature 0x%.4x\n",dev->name,value);
        return (-ENXIO);
    }
    printk("debug:[%s-%d]\n", __func__, __LINE__);

    
    value = cs8900_read (dev,PP_ProductID + 2);
    if (VERSION (value) != CS8900A) {
        printk (KERN_ERR "%s: unknown chip version 0x%.8x\n",dev->name,VERSION (value));
        return (-ENXIO);
    }
    
    cs8900_write (dev,PP_IntNum,0);


    printk (KERN_INFO "%s: CS8900A rev %c at %#lx irq=%d",
        dev->name,'B' + REVISION (value) - REV_B, dev->base_addr, dev->irq);

    for (i = 0; i < ETH_ALEN; i += 2)
        cs8900_write (dev,PP_IA + i,dev->dev_addr[i] | (dev->dev_addr[i + 1] << 8));

    printk (", addr:");
    for (i = 0; i < ETH_ALEN; i += 2)
    {
        u16 mac = cs8900_read (dev,PP_IA + i);
        printk ("%cX:%2X", (i==0)?' ':':', mac & 0xff, (mac >> 8));
    }
    printk ("\n");

    return (0);
}


static const struct net_device_ops net_ops = {
    .ndo_init = cs8900_probe,
    .ndo_open        = cs8900_start,
    .ndo_stop        = cs8900_stop,
    .ndo_tx_timeout        = cs8900_transmit_timeout,
    .ndo_start_xmit     = cs8900_send_start,
    .ndo_get_stats        = cs8900_get_stats,
    .ndo_set_multicast_list = cs8900_set_receive_mode,
#if 0
    .ndo_set_mac_address     = set_mac_address,
    .ndo_poll_controller    = net_poll_controller,
    .ndo_change_mtu        = eth_change_mtu,
    .ndo_validate_addr    = eth_validate_addr,
#endif
};


static int __init cs8900_init (void)
{
    struct net_device *ndev;

    ndev = alloc_etherdev(sizeof (cs8900_t));
    if (!ndev) {
        printk("%s: could not allocate device.\n", "cs8900");
        return -ENOMEM;
    }
    printk("allocate cs8900 device ok.\n");

    cs8900_dev = ndev;
    //cs8900_dev->init = cs8900_probe;

    ether_setup (ndev);
#if 0
    ndev->open = cs8900_start;
    ndev->stop = cs8900_stop;
    ndev->hard_start_xmit = cs8900_send_start;
    ndev->get_stats = cs8900_get_stats;
    ndev->set_multicast_list = cs8900_set_receive_mode;
    ndev->tx_timeout = cs8900_transmit_timeout;
#endif
    ndev->netdev_ops = &net_ops;
    ndev->watchdog_timeo = HZ;



    return (register_netdev (cs8900_dev));
}

static void __exit cs8900_cleanup (void)
{
//    cs8900_t *priv = (cs8900_t *) cs8900_dev->priv;

    cs8900_t *priv = (cs8900_t *)netdev_priv(cs8900_dev);
    if( priv->char_devnum)
    {
        unregister_chrdev(priv->char_devnum,"cs8900_eeprom");
    }
    release_mem_region (cs8900_dev->base_addr,16);
    unregister_netdev (cs8900_dev);
}

MODULE_AUTHOR ("Abraham van der Merwe ");
MODULE_DESCRIPTION (VERSION_STRING);
MODULE_LICENSE ("GPL");

module_init (cs8900_init);
module_exit (cs8900_cleanup);


下面是cs8900.h

#ifndef CS8900_H
#define CS8900_H





#define PP_Address        0x0a    
#define PP_Data            0x0c    



#define PP_ProductID        0x0000    
#define PP_MemBase            0x002c    
#define PP_IntNum            0x0022    
#define PP_EEPROMCommand    0x0040    
#define PP_EEPROMData        0x0042    
#define PP_RxCFG            0x0102    
#define PP_RxCTL            0x0104    
#define PP_TxCFG            0x0106    
#define PP_BufCFG            0x010a    
#define PP_LineCTL            0x0112    
#define PP_SelfCTL            0x0114    
#define PP_BusCTL            0x0116    
#define PP_TestCTL            0x0118    
#define PP_ISQ                0x0120    
#define PP_TxEvent            0x0128    
#define PP_BufEvent            0x012c    
#define PP_RxMISS            0x0130    
#define PP_TxCOL            0x0132    
#define PP_SelfST            0x0136    
#define PP_BusST            0x0138    
#define PP_TxCMD            0x0144    
#define PP_TxLength            0x0146    
#define PP_IA                0x0158    
#define PP_RxStatus            0x0400    
#define PP_RxLength            0x0402    
#define PP_RxFrame            0x0404    
#define PP_TxFrame            0x0a00    




#define INTRQ0            0x0000
#define INTRQ1            0x0001
#define INTRQ2            0x0002
#define INTRQ3            0x0003


#define EISA_REG_CODE    0x630e
#define REVISION(x)        (((x) & 0x1f00) >> 8)
#define VERSION(x)        ((x) & ~0x1f00)

#define CS8900A            0x0000
#define REV_B            7
#define REV_C            8
#define REV_D            9


#define Skip_1            0x0040
#define StreamE            0x0080
#define RxOKiE            0x0100
#define RxDMAonly        0x0200
#define AutoRxDMAE        0x0400
#define BufferCRC        0x0800
#define CRCerroriE        0x1000
#define RuntiE            0x2000
#define ExtradataiE        0x4000


#define IAHashA            0x0040
#define PromiscuousA    0x0080
#define RxOKA            0x0100
#define MulticastA        0x0200
#define IndividualA        0x0400
#define BroadcastA        0x0800
#define CRCerrorA        0x1000
#define RuntA            0x2000
#define ExtradataA        0x4000


#define Loss_of_CRSiE    0x0040
#define SQErroriE        0x0080
#define TxOKiE            0x0100
#define Out_of_windowiE    0x0200
#define JabberiE        0x0400
#define AnycolliE        0x0800
#define T16colliE        0x8000


#define SWint_X            0x0040
#define RxDMAiE            0x0080
#define Rdy4TxiE        0x0100
#define TxUnderruniE    0x0200
#define RxMissiE        0x0400
#define Rx128iE            0x0800
#define TxColOvfiE        0x1000
#define MissOvfloiE        0x2000
#define RxDestiE        0x8000


#define SerRxON            0x0040
#define SerTxON            0x0080
#define AUIonly            0x0100
#define AutoAUI_10BT    0x0200
#define ModBackoffE        0x0800
#define PolarityDis        0x1000
#define L2_partDefDis    0x2000
#define LoRxSquelch        0x4000


#define RESET            0x0040
#define SWSuspend        0x0100
#define HWSleepE        0x0200
#define HWStandbyE        0x0400
#define HC0E            0x1000
#define HC1E            0x2000
#define HCB0            0x4000
#define HCB1            0x8000


#define ResetRxDMA        0x0040
#define DMAextend        0x0100
#define UseSA            0x0200
#define MemoryE            0x0400
#define DMABurst        0x0800
#define IOCHRDYE        0x1000
#define RxDMAsize        0x2000
#define EnableRQ        0x8000


#define DisableLT        0x0080
#define ENDECloop        0x0200
#define AUIloop            0x0400
#define DisableBackoff    0x0800
#define FDX                0x4000


#define RegNum(x) ((x) & 0x3f)
#define RegContent(x) ((x) & ~0x3d)

#define RxEvent            0x0004
#define TxEvent            0x0008
#define BufEvent        0x000c
#define RxMISS            0x0010
#define TxCOL            0x0012


#define IAHash            0x0040
#define Dribblebits        0x0080
#define RxOK            0x0100
#define Hashed            0x0200
#define IndividualAdr    0x0400
#define Broadcast        0x0800
#define CRCerror        0x1000
#define Runt            0x2000
#define Extradata        0x4000

#define HashTableIndex(x) ((x) >> 0xa)


#define After5            0
#define After381        1
#define After1021        2
#define AfterAll        3
#define TxStart(x) ((x) << 6)

#define Force            0x0100
#define Onecoll            0x0200
#define InhibitCRC        0x1000
#define TxPadDis        0x2000


#define TxBidErr        0x0080
#define Rdy4TxNOW        0x0100


#define Loss_of_CRS        0x0040
#define SQEerror        0x0080
#define TxOK            0x0100
#define Out_of_window    0x0200
#define Jabber            0x0400
#define T16coll            0x8000

#define TX_collisions(x) (((x) >> 0xb) & ~0x8000)


#define SWint            0x0040
#define RxDMAFrame        0x0080
#define Rdy4Tx            0x0100
#define TxUnderrun        0x0200
#define RxMiss            0x0400
#define Rx128            0x0800
#define RxDest            0x8000


#define MissCount(x) ((x) >> 6)


#define ColCount(x) ((x) >> 6)


#define T3VActive        0x0040
#define INITD            0x0080
#define SIBUSY            0x0100
#define EEPROMpresent    0x0200
#define EEPROMOK        0x0400
#define ELpresent        0x0800
#define EEsize            0x1000


#define EEWriteEnable 0x00F0
#define EEWriteDisable 0x0000
#define EEWriteRegister    0x0100
#define EEReadRegister    0x0200
#define EEEraseRegister    0x0300
#define ELSEL            0x0400

#endif   




根文件系统的创建
建立 Linux 目录树,创建根文件系统的基本目录结构

我把这个过程做成了shell脚本文件mkrootfs,很方便!
mkrootfs文件如下:

#! /bin/sh
    echo "creatint rootfs dir......"
    mkdir rootfs
    cd rootfs
    echo "making dir : bin dev etc lib proc sbin sys usr"
    mkdir bin dev etc lib proc sbin sys usr
    mkdir usr/bin usr/lib usr/sbin lib/modules
# Don't use mknod ,unless you run this Script as root !
    mknod -m 600 dev/console c 5 1
 mknod -m 666 dev/null c 1 3
    echo "making dir : mnt tmp var"
    mkdir mnt tmp var
    chmod 1777 tmp
    mkdir mnt/udisk mnt/sd mnt/pcshare mnt/data
    echo "making dir : home root "
    mkdir home root
    cp -ar fs_public/* rootfs/
echo "done ok!"

注意创建完成后将其修改为可执行权限,在创建dev/console dev/null时须还要root权限
[root@localhost myroot]# ./mkrootfs  //在 myroot 中建立 Linux 目录树
配置和编译 busybox

1、准备工作
首先从 下载 源码包,
解压
tar jxvf busybox-1.19.2.tar.bz2
进入解压后的目录
cd busybox-1.19.2
2. 修改目录下Makefile文件
注释(第151-154行)
#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/ )
将175-176行的
ARCH        ?= $(SUBARCH)
CROSS_COMPILE    ?=
修改为:
ARCH        ?= arm
CROSS_COMPILE    ?= /opt/usr/local/arm/4.3.2/bin/arm-linux-
 164 #CROSS_COMPILE ?=
 165 CROSS_COMPILE ?= /opt/usr/local/arm/4.3.2/bin/arm-linux-

3、配置busybox
[root@localhost busybox-1.19.2]# make menuconfig
在原有的基础上修改如下:
Busybox Settings --->
      General Configuration  --->   //使用默认
      Build Options  --->
          [ ] Build BusyBox as a static binary (no shared libs)
          /* 将 busybox 编译为静态连接,少了启动时找动态库的麻烦 ,但不能DNS了(即ping www地

址时找不到服务了),故在此我选择动态连接*/              
          [ ] Build shared libbusybox                                          
          [ ] Build with Large File Support (for accessing files > 2 GB)  //可不选    
      Installation Options --->
           [*] Don't use /usr //说明是否也按装到usr目录下,不选表也按装到usr目录下
           (/opt/myroot/rootfs) BusyBox installation prefix  /* 指定busybox编译后按装路径 */
        Busybox Library Tuning  --->
           [*] Support for /etc/networks
           [*]   Additional editing keys    
           [*] Command line editing  在shell中命令的自动补全和命令可编辑还是挺方便的。这些功

能在busybox1.5以前shell的'command line editing'项在shell的选项内
           [*]   vi-style line editing command
           (15)  History size 
           [*]   History saving 
           [*]   Tab completion
           [*]     Username completion 
           [*]   Fancy shell prompts
           [ ] Use clock_gettime(CLOCK_MONOTONIC) syscall//选上时编译产生libbb/time.c:20:

error: `CLOCK_MONOTONIC' undeclared 错误
           [ ] Use ioctl names rather than hex values in error messages
      
Debian Utilities  ---> 选项全部N掉
Init Utilities  --->
  [*] init                                                            
  [ ]   debugging aid                                                  
  [*]   Support reading an inittab file /* 支持 init 读取/etc/inittab 配置文件,一定要选上*/

                   
  [*]   Support running commands with a controlling-tt
  [ ]   Enable init to write to syslog                                 
  [*]   Be _extra_ quiet on boot                                      
  [*]   Support dumping core for child processes (debugging only)     
  [*]   Support running init from within an initrd (not initramfs)      
  [*] poweroff, halt, and reboot                                      
  [*] mesg
Login/Password Management Utilities  --->选项全部N掉,后面单独使用TinyLogin。(因为集成的好像不是很好用)
Linux Ext2 FS Progs  --->选项全部N掉
Linux Module Utilities  --->
      [N] Support version 2.2.x to 2.4.x Linux kernels //在此我的内核是2.6的,所以没去除
Linux System Utilities  --->
  [*] fdisk                                                           
  [*]   support over 4GB disks                                        
  [*]   Write support
  [*] mdev                                    //支持mdev                        
  [*]   Support /etc/mdev.conf                                          
  [*]     Support command execution at device addition/removal          
  [*]   Support loading of firmwares
  [*] mount                                                         
  [ ]   Support mount helpers                                       
  [*]   Support mounting NFS file systems            //提供支持NFS挂载                
  [*]   Support mounting CIFS/SMB file systems       //提供支持Samba挂载                 
  [*]   Support lots of -o flags in mount                             
  [*]   Support /etc/fstab and -a    //该项表现在fstab文件中的:mount -a指令,挂载所有文件
  [*] umount                                                          
  [*]   umount -a option              //与mount -a对应                                  
  ---   Common options for mount/umount                              
  [*]   Support loopback mounts       //提供支持-o loop文件挂载                            

    
  [ ]   Support for the old /etc/mtab file //选上后將在/etc/下自动创建mtab文件 用以记录mount

挂载信息
 
Miscellaneous Utilities  --->
  [ ] devfsd (obsolete)                                                 
  [ ]   Use devfs names for all devices (obsolete)
  [ ] makedevs                                                          
       Choose makedevs behaviour (table)  --->
Networking Utilities  --->
  [*] inetd         /* * 支持 inetd 超级服务器 * inetd 的配置文件为/etc/inetd.conf 文件,
                 
  [ ] udhcp Server (udhcpd)                                            
  [*] udhcp Client (udhcpc)      
Shells  --->
 Choose your default shell (ash)  --->
   /* (X) ash 选中 ash,这样生成的时候才会生成 bin/sh 文件
   * 看看我们前头的 linuxrc 脚本的头一句:
   * #!/bin/sh 是由 bin/sh 来解释执行的*/
      --- ash 选择ash
      ---   Ash Shell Options 下的选项全选或采用默认
ipsvd utilities  --->  选项全部N掉   
其它为相关命令根据须要选择,在此我将所有的都选上了。
其它采用默认,保存退出,产生.config文件
4、编译 busybox
[root@localhost busybox-1.19.2]# make
  AR      libbb/lib.a
  LINK    busybox_unstripped
Trying libraries: crypt m
 Library crypt is needed
 Library m is needed
Final link with: crypt m
                                
5.将编译好的命令安装到指定的目录上。
[root@localhost busybox-1.19.2]# make install  将生成 bin,sbin两个文件夹和一个linuxrc文件.
我是动态编译所以查看一下需要的动态库
[root@localhost busybox-1.19.2]# arm-linux-readelf -d busybox


修改和创建必要的文件
inittab 文件如下:
# This is run first except when booting
::sysinit:/etc/init.d/rcS

# Start an "askfirst" shell on the console
::askfirst:-/bin/sh

# Stuff to do when restarting the init process
::restart:/sbin/init

#::once:/usr/sbin/inetd
#::once:/usr/etc/rc.local

# Stuff to do before rebooting
::ctrlaltdel:/sbin/reboot
::shutdown:/bin/umount -a –r
这里有个错误:
/bin/sh: can't access tty; job control turned off
修改inittab文件中
::askfirst:/bin/sh

::askfirst:-/bin/sh

fstab文件如下:
#device         mount-point     type    options       dump fsck order
proc            /proc           proc    defaults        0 0
tmpfs           /tmp            tmpfs   defaults        0 0
sysfs           /sys            sysfs   defaults        0 0
var             /var            tmpfs   defaults        0 0
tmpfs           /dev            tmpfs   defaults        0 0
var             /dev            tmpfs   defaults        0 0
ramfs           /dev            ramfs   defaults        0 0

增加为SHELL导入全局变量的文件profile
profile文件如下:

# Ash profile
# vim: syntax=sh

# No core files by default
#ulimit -S -c 0 > /dev/null 2>&1

USER="`id -un`"
LOGNAME=$USER
PS1='[\u@\h \W]\$ '
#PS1='[$USER@$HOSTNAME$PWD]\$ '
PATH=$PATH

HOSTNAME=`/bin/hostname`

export USER LOGNAME PS1 PATH

init.d/rcS内容如下:
#! /bin/sh

#echo "^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^"
#echo "^     Welcome to YAFFS root filesystem!   ^"
#echo "^                                         ^"
#echo "^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^"

PATH=/sbin:/bin:/usr/sbin:/usr/bin
runlevel=S
prevlevel=N
umask 022
export PATH runlevel prevlevel

#
#       Trap CTRL-C &c only in this shell so we can interrupt subprocesses.
#
trap ":" INT QUIT TSTP


/bin/mount -a

/bin/mkdir -p /var/lib
/bin/mkdir -p /var/run
/bin/mkdir -p /var/log
/bin/mkdir -p /var/lock

#/etc/rc.d/init.d/netd start
#/etc/rc.d/init.d/httpd start
#/etc/profile
/sbin/ifconfig lo 127.0.0.1
#insmod /home/ip_radio/kbdtwos.ko
/bin/hostname -F /etc/sysconfig/HOSTNAME

mkdir /dev/pts
mount -t devpts devpts /dev/pts
echo /sbin/mdev > /proc/sys/kernel/hotplug
mdev -s

ifconfig eth0 up
#cd /home/ip_radio
#iwconfig eth0 essid IP706MR-3
#udhcpc -i eth0
#mount -t cifs -o username=guest //192.168.3.2/arm_dev /mnt/share

mdev.conf 内容如下
sd[a-z]*[0-9]          0:0     0660    @(mount -t vfat -o iocharset=cp936 /dev/$MDEV /mnt/udisk)
sd[a-z]*[0-9]          0:0     0660    @(umount /mnt/udisk)
mmcblk[a-z]*p[0-9]     0:0     0660    @(mount -t vfat -o iocharset=cp936 /dev/$MDEV/mnt/sd)
mmcblk[a-z]*p[0-9]     0:0     0660    @(umount /mnt/sd)

rc.d/init.d/httpd 内容如下
#!/bin/sh

base=boa

#See how we were called.
case "$1" in
        start)
                /sbin/$base
                ;;
        stop)
                pid='/bin/pidof $base'
                if[-n "$pid"];then
                        kill -9 $pid
                fi
                ;;
esac

exit 0

sysconfig/HOSTNAME 内容如下
localhost

resolv.conf内容如下
nameserver 192.168.1.1


hosts 内容如下
127.0.0.1       localhost
services 内容如下
# service-name  port/protocol  [aliases ...]   [# comment]

tcpmux          1/tcp
echo            7/tcp
echo            7/udp
systat          11/tcp          users
daytime         13/tcp
daytime         13/udp
netstat         15/tcp
ftp-data        20/tcp
ftp             21/tcp
ssh             22/tcp
ssh             22/udp
telnet          23/tcp
smtp            25/tcp          mail
time            37/tcp          timserver
time            37/udp          timserver
nameserver      42/tcp          name
whois           43/tcp          nicname
bootps          67/tcp
bootps          67/udp
bootpc          68/tcp
bootpc          68/udp
tftp            69/udp
finger          79/tcp
www             80/tcp          http
www             80/udp
pop3            110/tcp         pop-3
pop3            110/udp         pop-3
sunrpc          111/tcp         portmapper
sunrpc          111/udp         portmapper
auth            113/tcp         authentication tap ident
nntp            119/tcp         readnews untp
ntp             123/tcp
ntp             123/udp
snmp            161/udp
snmp-trap       162/udp         snmptrap

从/opt/4.4.3/arm-none-linux-gnueabi/lib/中拷贝 busybox与TinyLogin用到的库文件到新文件系统的lib
ld-2.9.so      libc-2.9.so      libcrypt.so.1  libm-2.9.so  libnss_dns-2.9.so  libnss_files-2.9.so libresolv-2.9.so  modules ld-linux.so.3  libcrypt-2.9.so  libc.so.6      libm.so.6  libnss_dns.so.2    libnss_files.so.2    libresolv.so.2

制作文件系统时,超级终端出现[\u@\h \W]#
解决方法:
法一:在busybox编译里
make menuconfig
busybox settings->busybox library tuning->username completion、fancy shell prompts选上。
就可以了
法二:处理方法是:/etc/profile:PS1='[$USER@$HOSTNAME $PWD]#


制作文件系统时,无法进入init,超级终端出现
Looking up port of RPC 100003/2 on 192.168.1.54                                                                                                 
Looking up port of RPC 100005/1 on 192.168.1.54                                                                                                 
VFS: Mounted root (nfs filesystem) on device 0:12.                                                                                              
Freeing init memory: 164K                                                                                                                       
Kernel panic - not syncing: Attempted to kill init!                                                                                             
Backtrace:                                                                                                                                      
[] (dump_backtrace+0x0/0x114) from [] (dump_stack+0x18/0x1c)                                                                
 r7:c3815bc0 r6:c3815bc0 r5:c3819ee4 r4:c052dc04                                                                                                
[] (dump_stack+0x0/0x1c) from [] (panic+0x60/0x184)                                                                         
[] (panic+0x0/0x184) from [] (do_exit+0x70/0x5a0)                                                                           
 r3:c05135f8 r2:c3819e5c r1:c3815cb8 r0:c04abe26                                                                                                
[] (do_exit+0x0/0x5a0) from [] (do_group_exit+0x90/0xc4)                                                                    
[] (do_group_exit+0x0/0xc4) from [] (get_signal_to_deliver+0x2f4/0x32c)                                                     
 r4:00000004                                                                                                                                    
[] (get_signal_to_deliver+0x0/0x32c) from [] (do_notify_resume+0x78/0x614)                                                  
[] (do_notify_resume+0x0/0x614) from [] (work_pending+0x24/0x28)
错误原因: 
用arm-linux-gcc 4.00以上的编译器做出都 文件系统老是报这个错 ,
而用rm-linux-gcc 3.xx 版本都都不会,看来一下内核的配置
原来问题在这里

Kernel Features  --->
            [*] Use the ARM EABI to compile the kernel                 
            [*]   Allow old ABI binaries to run with this kernel (EXPERIMENTA)
把这个选上就可以了
阅读(3945) | 评论(0) | 转发(0) |
给主人留下些什么吧!~~