Chinaunix首页 | 论坛 | 博客
  • 博客访问: 17947
  • 博文数量: 8
  • 博客积分: 10
  • 博客等级: 民兵
  • 技术积分: 50
  • 用 户 组: 普通用户
  • 注册时间: 2012-09-08 19:10
文章分类
文章存档

2013年(5)

2012年(3)

我的朋友

分类:

2012-10-30 14:44:55

    使用NFS挂载根文件系统,在开发阶段有很多的好处,对根文件系统进行修改后不用每次都下载到NandFlash中,可以把制作的根文件系统放到主机中的NFS输出目录中,在正式成为产品以后在烧写到开发板中,这样可以方便很多,也可以把编译生成的内核也放到NFS输出目录中这样也可以引导内核,很是方便,还等什么开始吧!
   NFS服务器端的配置已经在上一篇文章中写到过了。U-boot中使用tftp协议也在另一篇文章中。按道理来说NFS命令也是可以是使用的,因为都是基于网卡的,只要网卡驱动移植的没有问题,NFS也就直接可以使用了,不过在我这里可是行不通,在使用NFS传输文件中,一直出现下面的错误类型,提示挂载不上:

U-Boot@mini2440]#nfs 0x30000000 10.27.10.48:/home/ubuntu/kernel/fs/u-boot.bin
dm9000 i/o: 0x20000300, id: 0x90000a46
DM9000: running in 16 bit mode
MAC: 08:00:3e:26:0a:5b
operating at 100M full duplex mode
Using dm9000 device
File transfer via NFS from server 10.27.10.48; our IP address is 10.27.10.23
Filename '/home/ubuntu/kernel/fs/u-boot.bin'.
Load address: 0x30000000
Loading: *** ERROR: Cannot mount //仅仅提示挂载不上

可还有下面的错误:

[U-Boot@mini2440]#nfs 0x30000000 10.27.10.48:/home/ubuntu/kernel/fs/u-boot.bin
dm9000 i/o: 0x20000300, id: 0x90000a46
DM9000: running in 16 bit mode
MAC: 08:00:3e:26:0a:5b
operating at 100M full duplex mode
Using dm9000 device
File transfer via NFS from server 10.27.10.48; our IP address is 10.27.10.23
Filename '/home/ubuntu/kernel/fs/u-boot.bin'.
Load address: 0x30000000
Loading: *** ERROR: Cannot mount
*** ERROR: Cannot umount //这里还提示了不能卸载

   在网上查找资料,出现 Cannot umount错误的解决方法是修改u-boot-2009.08/net/nfs.c文件,在大约453行附近的位置:

static intnfs_umountall_reply (uchar *pkt, unsigned len)
{
    struct rpc_t rpc_pkt;
    debug("%s\n", __func__);
    memcpy ((unsigned char *)&rpc_pkt, pkt, len);
    //if (ntohl(rpc_pkt.u.reply.id) != rpc_id) //原来的这一行修改成下面的一行
     if ((ntohl(rpc_pkt.u.reply.id)+1) != rpc_id)
        return -1;
    if (rpc_pkt.u.reply.rstatus ||
   ..................
}

   可是在我这里修改完以后还是不可以使用,一样出现上面的错误。这是就想到了是不是和tftp时出现的错误是一样的,也是因为超时的原因,虽然这里面没有出现超时的提示,不管怎么样还是先改了再说;还是在/nfs.c文件中修改下面的超时的宏定义:

#define HASHES_PER_LINE 65    /* Number of "loading" hashes per line    */
#define NFS_RETRY_COUNT 30
#define NFS_TIMEOUT (30*2000UL) //把原来的2000UL改成 30*2000UL,

   修改完上面的宏定义以后,再使用NFS传输文件,一开始有几次还是不成功,不过后面再使用时大部分情况下都是成功的,不再像上面一次也没有成功过:

[U-Boot@mini2440]#nfs 0x30000000 10.27.10.48:/home/zfz/kernel/fs/u-boot.bin
dm9000 i/o: 0x20000300, id: 0x90000a46
DM9000: running in 16 bit mode
MAC: 08:00:3e:26:0a:5b
operating at 100M full duplex mode
Using dm9000 device
File transfer via NFS from server 10.27.10.48; our IP address is 10.27.10.23
Filename '/home/zfz/kernel/fs/u-boot.bin'.
Load address: 0x30000000
Loading: ###############################
done
Bytes transferred = 155016 (25d88 hex)

    既然NFS可以使用了,那就可以用NFS挂载根文件系统了。根文件系统的制作在另一篇文章中也已经写了,这里就还是使用上次的根文件系统,只是不再用工具制作成Yaffs2的镜像了,直接使用Busybox,制作成功的noot_nfs目录下的各个文件就可以了,如果要下载到NandFlash中,再使用Yaffs2格式的镜像文件。
可以先用NFS把Linux内核下载到内存中,然后设置传递给内核的参数,在u-boot-2009.08/include/configs/mini2440.h文件中,修改原来使用nand read 方式,修改成使用NFS方式的;

//#define CONFIG_BOOTCOMMAND    "nand read 0x32000000 0x60000 0x560000;bootm 0x32000000"
//把上面的注释掉,修改成下面的方式
#define CONFIG_BOOTCOMMAND "nfs 0x30000800 10.27.10.48:/home/zfz/kernel/fs/uImage.img;bootm"

   这样,在用U-boot引导时就可以把Linux的内核首先复制到内存中了,这样也不用把Linux 内核下载到开发板中了。然后在修改传递给内核的参数,修改为下面的:

//#define CONFIG_BOOTARGS    "noinitrd root=/dev/mtdblock3 init=/linuxrc console=ttySAC0,115200 mem=64M"
//把上面的修改成下面的这句
#define CONFIG_BOOTARGS "noinitrd root=/dev/nfs rw nfsroot=10.27.10.48:/home/ubuntu/kernel/fs/root_nfs ip=10.27.10.23:10.27.10.48::255.255.255.0 console=ttySAC0,115200 init=/linuxrc mem=64M"

   可不要忘记把你的Linux内核的镜像文件和你制作的根文件系统的放到NFS的输出目录中;在配置内核中要选中支持NFS文件系统:支持网卡驱动,还用NetWorking Support如下图所示:


Network File System的支持

这样内核配置完以后启动U-boot出现下面的错误:

...........

No device for DAI UDA134X
No device for DAI s3c24xx-i2s
ALSA device list:
  No soundcards found.
TCP cubic registered
NET: Registered protocol family 17
drivers/rtc/hctosys.c: unable to open rtc device (rtc0)
IP-Config: No network devices available. //这里没有找到网卡的驱动
Looking up port of RPC 100003/2 on 10.27.10.48
rpcbind: server 10.27.10.48 not responding, timed out
Root-NFS: Unable to get nfsd port number from server, using default
Looking up port of RPC 100005/1 on 10.27.10.48
rpcbind: server 10.27.10.48 not responding, timed out
Root-NFS: Unable to get mountd port number from server, using default
Root-NFS: Server returned error -5 while mounting /home/zfz/kernel/fs/root_nfs
VFS: Unable to mount root fs via NFS, trying floppy.
VFS: Cannot open root device "nfs" or unknown-block(2,0)
Please append a correct "root=" boot option; here are the available partitions:
1f00 256 mtdblock0 (driver?)
1f01 128 mtdblock1 (driver?)
1f02 5120 mtdblock2 (driver?)
1f03 125568 mtdblock3 (driver?)
1f04 131072 mtdblock4 (driver?)
Kernel panic - not syncing: VFS: Unable to mount root fs on unknown-block(2,0)
[<c002e9f8>] (unwind_backtrace+0x0/0xdc) from [<c02e0190>] (panic+0x40/0x120)
[<c02e0190>] (panic+0x40/0x120) from [<c0008e84>] (mount_block_root+0x1d0/0x210)
[<c0008e84>] (mount_block_root+0x1d0/0x210) from [<c000911c>] (prepare_namespac)
[<c000911c>] (prepare_namespace+0x164/0x1bc) from [<c000843c>] (kernel_init+0xd)
[<c000843c>] (kernel_init+0xd8/0x10c) from [<c002a854>] (kernel_thread_exit+0x0)

   在使用NFS挂载根文件系统时,需要在系统启动到后面时,使用NFS传送根文件系统,这是需要了DM9000网卡的驱动,虽然我们在u-boot中移植了DM9000网卡的驱动,不过现在已经进入到了Linux中,在配置Linux内核中虽然我们也选择了支持DM9000网卡的驱动,不过还是需要在Linux内核中改动才能适应开发板上的网卡,下面就要在Linux中移植DM9000网卡的驱动程序。
    Linux2.6.32已经对DM9000网卡有着比较完善的支持了,在:linux-2.6.32.2/
drivers/net/dm9000.c文件中,只需要在目标平台初始化代码中,填写完相应的结构表就可以了,在另一篇文章中,Linux2.6.32.2移植到MINI2440中,我们在linux-2.6.32.2/arch/arm/mach-s3c2440目录下建立了我们自己的文件mach-mini2440.c,主要在这个文件下添加修改;首先添加驱动所需要的头文件:

#include <linux/dm9000.h>

  然后定义 DM9000网卡的物理基地址

#define MACH_MINI2440_DM9K_BASE (S3C2410_CS4 + 0x300)

  再填写该平台设备的资源设置,以便和 DM9000 网卡驱动接口配合起来;

static struct resource mini2440_dm9k_resource[] = {
        [0] = {
                .start = MACH_MINI2440_DM9K_BASE,
                .end = MACH_MINI2440_DM9K_BASE + 3,
                .flags = IORESOURCE_MEM
        },
        [1] = {
                .start = MACH_MINI2440_DM9K_BASE + 4,
                .end = MACH_MINI2440_DM9K_BASE + 7,
                .flags = IORESOURCE_MEM
        },
        [2] = {
                .start = IRQ_EINT7,
                .end = IRQ_EINT7,
                .flags = IORESOURCE_IRQ | IORESOURCE_IRQ_HIGHEDGE,
        }
};
/*
 * * * The DM9000 has no eeprom, and it's MAC address is set by
 * * * the bootloader before starting the kernel.
 * * */

static struct dm9000_plat_data mini2440_dm9k_pdata = {
        .flags = (DM9000_PLATF_16BITONLY | DM9000_PLATF_NO_EEPROM),
};
 
static struct platform_device mini2440_device_eth = {
        .name = "dm9000",
        .id = -1,
        .num_resources = ARRAY_SIZE(mini2440_dm9k_resource),
        .resource = mini2440_dm9k_resource,
        .dev = {
                .platform_data = &mini2440_dm9k_pdata,
        },
};

 然后在 mini2440 设备集中添加上面做好的网卡平台设备,如下红色部分

static struct platform_device *mini2440_devices[] __initdata = {
    &s3c_device_usb,
    &s3c_device_lcd,
    &s3c_device_wdt,
    &s3c_device_i2c0,
    &s3c_device_iis,
    &mini2440_device_eth,
    &s3c_device_nand,  
};

   因为 Linux-2.6.32.2 中虽然有 DM9000 网卡驱动,但并不是完全的适合mini2440,所以还是需要修改,修改DM9000 所用的位宽寄存器,在linux-2.6.32.2/ drivers/net/dm9000.c,添加下面的头文件

#if defined (CONFIG_ARCH_S3C2410)
#include <mach/regs-mem.h>
#endif

   在dm9000设备的初始化函数中添加如下红色部分,这里是配置 DM9000 所用片选总线的时序,大约在1557行附近的位置,

static int __init
dm9000_init(void)
{
    #if defined(CONFIG_ARCH_S3C2410)
        unsigned int oldval_bwscon = *(volatile unsigned int*)S3C2410_BWSCON;
        unsigned int oldval_bankcon4 = *(volatile unsigned int*)S3C2410_BANKCON4;
        *((volatile unsigned int *)S3C2410_BWSCON) =
                        (oldval_bwscon & ~(3<<16)) | S3C2410_BWSCON_DW4_16 |
S3C2410_BWSCON_WS4 | S3C2410_BWSCON_ST4;
        oldval_bankcon4 = 0x1f7c;
#endif
    printk(KERN_INFO "%s Ethernet Driver, V%s\n", CARDNAME, DRV_VERSION);
    return platform_driver_register(&dm9000_driver);
}

   在配置Linux内核中,加入对DM9000网卡的支持如下图;


   这样DM9000网卡的驱动就基本已经移植完成了,这样就可以使用NFS挂载根文件系统了,启动的信息如下:


U-Boot 2009.08 ( 4??月 30 2010 - 20:01:00)
                                                                                
DRAM: 64 MB
Flash: 2 MB
NAND Device: Manufacturer ID: 0xec, Chip ID: 0xf1 (Samsung NAND 128MiB 3,3V 8-b)
NAND: 128 MiB
*** Warning - bad CRC or NAND, using default environment
                                                                                
In: serial
Out: serial
Err: serial
Net: dm9000
Hit any key to stop autoboot: 0
dm9000 i/o: 0x20000300, id: 0x90000a46
DM9000: running in 16 bit mode
MAC: 08:00:3e:26:0a:5b
operating at 100M full duplex mode
Using dm9000 device
File transfer via NFS from server 10.27.10.48; our IP address is 10.27.10.23
Filename '/home/zfz/kernel/fs/uImage.img'.
Load address: 0x32000000
Loading: #################################################################
         #################################################################
         #################################################################
         #################################################################
         #################################################################
         #################################################################
         #####################
done
Bytes transferred = 2104236 (201bac hex)
## Booting kernel from Legacy Image at 32000000 ...
   Image Name: linux-2.6.32.2
   Created: 2010-04-30 15:40:47 UTC
   Image Type: ARM Linux Kernel Image (uncompressed)
   Data Size: 2104172 Bytes = 2 MB
   Load Address: 31000000
   Entry Point: 31000000
   Verifying Checksum ... OK
   Loading Kernel Image ... OK
OK
                                                                                
Starting kernel ...
                                                                                
Uncompressing Linux.............................................................
Linux version 2.6.32.2 (zfz@zfz) (gcc version 4.3.2 (Sourcery G++ Lite 2008q3-70
CPU: ARM920T [41129200] revision 0 (ARMv4T), cr=c0007177
CPU: VIVT data cache, VIVT instruction cache
Machine: FriendlyARM MINI2440 development board
Memory policy: ECC disabled, Data cache writeback
CPU S3C2440A (id 0x32440001)
S3C24XX Clocks, (c) 2004 Simtec Electronics
S3C244X: core 405.000 MHz, memory 101.250 MHz, peripheral 50.625 MHz
CLOCK: Slow mode (1.500 MHz), fast, MPLL on, UPLL on
Built 1 zonelists in Zone order, mobility grouping on. Total pages: 16256
Kernel command line: noinitrd root=/dev/nfs rw nfsroot=10.27.10.48:/home/zfz/keM
PID hash table entries: 256 (order: -2, 1024 bytes)
Dentry cache hash table entries: 8192 (order: 3, 32768 bytes)
Inode-cache hash table entries: 4096 (order: 2, 16384 bytes)
Memory: 64MB = 64MB total
Memory: 60480KB available (3696K code, 418K data, 132K init, 0K highmem)
SLUB: Genslabs=11, HWalign=32, Order=0-3, MinObjects=0, CPUs=1, Nodes=1
Hierarchical RCU implementation.
NR_IRQS:85
irq: clearing subpending status 00000002
Console: colour dummy device 80x30
console [ttySAC0] enabled
Calibrating delay loop... 201.93 BogoMIPS (lpj=504832)
Mount-cache hash table entries: 512
CPU: Testing write buffer coherency: ok
NET: Registered protocol family 16
S3C2440: Initialising architecture
S3C2440: IRQ Support
S3C24XX DMA Driver, (c) 2003-2004,2006 Simtec Electronics
DMA channel 0 at c4808000, irq 33
DMA channel 1 at c4808040, irq 34
DMA channel 2 at c4808080, irq 35
DMA channel 3 at c48080c0, irq 36
S3C244X: Clock Support, DVS off
bio: create slab <bio-0> at 0
usbcore: registered new interface driver usbfs
usbcore: registered new interface driver hub
usbcore: registered new device driver usb
s3c-i2c s3c2440-i2c: slave address 0x10
s3c-i2c s3c2440-i2c: bus frequency set to 98 KHz
s3c-i2c s3c2440-i2c: i2c-0: S3C I2C adapter
NET: Registered protocol family 2
IP route cache hash table entries: 1024 (order: 0, 4096 bytes)
TCP established hash table entries: 2048 (order: 2, 16384 bytes)
TCP bind hash table entries: 2048 (order: 1, 8192 bytes)
TCP: Hash tables configured (established 2048 bind 2048)
TCP reno registered
NET: Registered protocol family 1
RPC: Registered udp transport module.
RPC: Registered tcp transport module.
RPC: Registered tcp NFSv4.1 backchannel transport module.
JFFS2 version 2.2. (NAND) ?&#169; 2001-2006 Red Hat, Inc.
ROMFS MTD (C) 2007 Red Hat, Inc.
yaffs Apr 20 2010 11:10:26 Installing.
msgmni has been set to 118
alg: No test for stdrng (krng)
io scheduler noop registered
io scheduler anticipatory registered (default)
io scheduler deadline registered
io scheduler cfq registered
s3c2410-lcd s3c2410-lcd: no platform data for lcd, cannot attach
s3c2410-lcd: probe of s3c2410-lcd failed with error -22
s3c2440-uart.0: s3c2410_serial0 at MMIO 0x50000000 (irq = 70) is a S3C2440
s3c2440-uart.1: s3c2410_serial1 at MMIO 0x50004000 (irq = 73) is a S3C2440
s3c2440-uart.2: s3c2410_serial2 at MMIO 0x50008000 (irq = 76) is a S3C2440
brd: module loaded
S3C24XX NAND Driver, (c) 2004 Simtec Electronics
s3c24xx-nand s3c2440-nand: Tacls=3, 29ns Twrph0=7 69ns, Twrph1=3 29ns
s3c24xx-nand s3c2440-nand: NAND soft ECC
NAND device: Manufacturer ID: 0xec, Chip ID: 0xf1 (Samsung NAND 128MiB 3,3V 8-b)
Scanning device for bad blocks
Creating 5 MTD partitions on "NAND 128MiB 3,3V 8-bit":
0x000000000000-0x000000040000 : "U-boot"
0x000000040000-0x000000060000 : "param"
ftl_cs: FTL header not found.
0x000000060000-0x000000560000 : "Kernel"
ftl_cs: FTL header not found.
0x000000560000-0x000040560000 : "root"
mtd: partition "root" extends beyond the end of device "NAND 128MiB 3,3V 8-bit"0
ftl_cs: FTL header not found.
0x000000000000-0x000040000000 : "nand"
mtd: partition "nand" extends beyond the end of device "NAND 128MiB 3,3V 8-bit"0
dm9000 Ethernet Driver, V1.31
eth0: dm9000e at c486e300,c4872304 IRQ 51 MAC: 08:00:3e:26:0a:5b (chip)
ohci_hcd: USB 1.1 'Open' Host Controller (OHCI) Driver
s3c2410-ohci s3c2410-ohci: S3C24XX OHCI
s3c2410-ohci s3c2410-ohci: new USB bus registered, assigned bus number 1
s3c2410-ohci s3c2410-ohci: irq 42, io mem 0x49000000
usb usb1: configuration #1 chosen from 1 choice
hub 1-0:1.0: USB hub found
hub 1-0:1.0: 2 ports detected
usbcore: registered new interface driver libusual
mice: PS/2 mouse device common for all mice
S3C24XX RTC, (c) 2004,2006 Simtec Electronics
i2c /dev entries driver
S3C2410 Watchdog Timer, (c) 2004 Simtec Electronics
s3c2410-wdt s3c2410-wdt: watchdog inactive, reset disabled, irq enabled
cpuidle: using governor ladder
sdhci: Secure Digital Host Controller Interface driver
sdhci: Copyright(c) Pierre Ossman
usbcore: registered new interface driver hiddev
usbcore: registered new interface driver usbhid
usbhid: v2.6:USB HID core driver
Advanced Linux Sound Architecture Driver Version 1.0.21.
No device for DAI UDA134X
No device for DAI s3c24xx-i2s
ALSA device list:
  No soundcards found.
TCP cubic registered
NET: Registered protocol family 17
drivers/rtc/hctosys.c: unable to open rtc device (rtc0)
eth0: link up, 100Mbps, full-duplex, lpa 0x45E1
IP-Config: Complete:
     device=eth0, addr=10.27.10.23, mask=255.255.255.0, gw=10.27.10.1,
     host=10.27.10.23, domain=, nis-domain=(none),
     bootserver=10.27.10.48, rootserver=10.27.10.48, rootpath= //这里和上次的不同
Looking up port of RPC 100003/2 on 10.27.10.48
Looking up port of RPC 100005/1 on 10.27.10.48
VFS: Mounted root (nfs filesystem) on device 0:14.
Freeing init memory: 132K
--------- munt all--------
-------- Starting mdev ---------
*************************
**********************Frankzfz ARM Embedded **************
Kernel version:linux-2.32.2
Author:zfz
Date:2010,4,29
***********************
                                                                                
Please press Enter to activate this console.
Set PS1 in /etc/profile
[root@mini2440]#

我们可以通过ifconfig命令查看如下:

Please press Enter to activate this console.
Set PS1 in /etc/profile
[root@mini2440]#ifconfig
eth0 Link encap:Ethernet HWaddr 08:00:3E:26:0A:5B  //这里是在u-boot中指定的IP地址
          inet addr:10.27.10.23 Bcast:10.27.10.255 Mask:255.255.255.0
          UP BROADCAST RUNNING MULTICAST MTU:1500 Metric:1
          RX packets:1953 errors:0 dropped:0 overruns:0 frame:0
          TX packets:1005 errors:0 dropped:0 overruns:0 carrier:0
          collisions:0 txqueuelen:1000
          RX bytes:2112429 (2.0 MiB) TX bytes:155582 (151.9 KiB)
          Interrupt:51 Base address:0xe300
                                                                                
lo Link encap:Local Loopback
          inet addr:127.0.0.1 Mask:255.0.0.0
          UP LOOPBACK RUNNING MTU:16436 Metric:1
          RX packets:0 errors:0 dropped:0 overruns:0 frame:0
          TX packets:0 errors:0 dropped:0 overruns:0 carrier:0
          collisions:0 txqueuelen:0
          RX bytes:0 (0.0 B) TX bytes:0 (0.0 B)

   到这里在Linux内核下通过NFS挂载根文件系统就已经完成了。这样在修改和完善Linux内核,根文件系统的时候就不需要每次下载进行验证了,很是方便!
阅读(970) | 评论(0) | 转发(0) |
给主人留下些什么吧!~~