kernel(二)网卡(DM9000)及nfs文件系统

参考帮助文档: Documentation/networking/dm9000.txt
        在 arch/arm/mach-s5pv210/mach-smdkv210.c 中已经配置了 DM9000 的平台设备相关的数据,我们只需要修改就行了。

        在 arch/arm/mach-s5pv210/include/mach/map.h 中只定义了 S5PV210_PA_SROM_BANK5 的基地址,TQ210 开发板的 DM9000 接在 BANK1,因此我们需要在这个文件中定义 S5PV210_PA_SROM_BANK1 的基地址

/*片选信号使用的是XM0CSn1,查看S5PV210的芯片手册内存映射一节可以找到SROM BANK1的地址范围是0x8800_0000 --0x8FFF_FFFF,    则访问这个范围的地址时会激活片选使能信号XM0CSn1*/


然后修改 arch/arm/mach-s5pv210/mach-smdkv210.c 中的 DM9000 配置

TQ210 开发板的 DM9000 使用外部中断 10,另外,在 smdkv210_machine_init 函数中调用了smdkv210_dm9000_init 函数,这个函数进行 SROM 控制器的初始化,由于我在 u-boot 中已经初始化了,所以把它屏蔽掉

然后配置内核支持网络,由于现在还没移植 NAND FLASH,因此只有使用网络文件系统来启动开发板,所以需要配置内核支持网络文件系统(NFS

# make menuconfig
[*] Networking support --->
	Networking options --->
		<*> Packet socket
		<*> Packet: sockets monitoring interface
		<*> Unix domain sockets
		<*> UNIX: socket monitoring interface
		        [*] TCP/IP networking
			[*] IP: multicasting
			[*] IP: advanced router
			[*] IP: kernel level autoconfiguration
			[*] IP: DHCP support
			[*] IP: BOOTP support
			[*] IP: RARP support
Device Drivers --->
	[*] Network device support --->
		[*] Ethernet driver support (NEW) --->
		    <*> DM9000 support
将其他的设备全部去掉,只保留 DM9000
File systems --->
	[*] Network File Systems (NEW) --->
		<*> NFS client support
			[*] Root file system on NFS
执行 make uImage 编译,成功生成 uImage


现在需要从 NFS 启动开发板,因此需要先制作一个根文件系统
首先需要下载
busybox,我下载的是 busybox-1.21.1.tar.bz2
root@ubuntu:~/code# tar -xf busybox-1.21.0.tar.bz2
root@ubuntu:~/code# cd busybox-1.21.1
root@ubuntu:~/code/busybox-1.21.0# make menuconfig
Busybox Settings --->
    General Configuration --->
        [ ] Enable options for full-blown desktop systems
我们使用的是嵌入式系统,如果不取消,在执行 ps 命令时不会显示进程状态

Busybox Settings --->   
    Build Options --->
        (arm-linux-) Cross Compiler prefix
指定交叉编译器前缀

Busybox Settings ---> 
    Installation Options ("make install" behavior) --->
        (./_install) BusyBox installation prefix (NEW)
指定安装路径(我使用的是默认路径)

Init Utilities --->
    [ ] Be _extra_ quiet on boot
取消可以在系统启动时显示 busybox 版本号加载和卸载内核模块

Linux Module Utilities --->
    [ ] Simplified modutils
我们不适应简单的,我们需要使用 insmod 等工具
    [*] insmod
    [*] rmmod
    [*] lsmod
    [*] modprobe
    [*] depmod

配置完毕,现在编译和安装
root@ubuntu:~/code/busybox-1.21.0# make && make install

创建根文件系统目录结构,可以使用如下脚本mkrootfs.sh,给脚本加可执行权限(即chmod a+x mkrootfs)并运行脚本:

#!/bin/sh
echo "------Create rootfs directons start...--------"
mkdir rootfs
cd rootfs
echo "--------Create root,dev....----------"
mkdir root dev etc boot tmp var sys proc lib mnt home usr 
mkdir etc/init.d etc/rc.d etc/sysconfig
mkdir usr/sbin usr/bin usr/lib usr/modules
echo "make node in dev/console dev/null"
sudo mknod -m 600 dev/console c 5 1
sudo mknod -m 600 dev/null  c 1 3
mkdir mnt/etc mnt/jffs2 mnt/yaffs mnt/data mnt/temp
mkdir var/lib var/lock var/run var/tmp
chmod 1777 tmp
chmod 1777 var/tmp
echo "-------make direction done---------"
然后拷贝 busybox 生成的内容到 rootfs
root@ubuntu:~/code# cp busybox-1.21.0/_install/* rootfs/ -a
root@ubuntu:~/code# cp busybox-1.21.0/examples/bootfloppy/etc/ rootfs/ -r

拷贝虚拟机系统的 passwd、 group、 shadow 到根文件系统
root@ubuntu:~/code/rootfs# cp /etc/passwd etc/
root@ubuntu:~/code/rootfs# cp /etc/group etc/
root@ubuntu:~/code/rootfs# cp /etc/shadow etc/

把 passwd 文件中的第一行: root:x:0:0:root:/root:/bin/bash 中的/bin/bash,改成/bin/ash
root:x:0:0:root:/root:/bin/ash

因为文件系统的 bin 目录下没有 bash 这个命令,而是用 ash 代替 bash,所以在用用户名密
码登录的时候(如 telnet),会出现“cannot run /bin/bash: No such file or directory”的错误
进入 rootfs 目录,创建相关目录

然后从交叉编译器拷贝库到 rootfs 的 lib 目录,交叉编译器的库所在路径为
/opt/arm-cortex_a8-linux-gnueabi-4.7.3/arm-cortex_a8-linux-gnueabi/sysroot/usr/lib/


对库进行瘦身以减小文件系统的大小
root@ubuntu:~/code/rootfs# arm-linux-strip lib/*

修改 rootfs/etc/inittab 文件
root@ubuntu:~/code/rootfs# vim etc/inittab
# /etc/inittab
# This is run first except when booting in single-user mode.
::sysinit:/etc/init.d/rcS
# Note below that we prefix the shell commands with a "-" to indicate to the
# shell that it is supposed to be a login shell
# Start an "askfirst" shell on the console (whatever that may be)
::askfirst:-/bin/sh
# Start an "askfirst" shell on /dev/tty2
#tty2::askfirst:-/bin/sh
# Stuff to do before rebooting
::ctrlaltdel:/sbin/reboot
::shutdown:/bin/umount -a –r

修改 rootfs/ etc/fstab
root@ubuntu:~/code/rootfs# vim etc/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
tmpfs /dev tmpfs defaults 0 0

修改 rootfs/etc/init.d/rcS
root@ubuntu:~/code/rootfs# vim etc/init.d/rcS
#!/bin/sh
#This is the first script called by init process
mount -a
mkdir /dev/pts
mount -t devpts devpts /dev/pts
echo /sbin/mdev>/proc/sys/kernel/hotplug
mdev –s

修改 rootfs/etc/profile
root@ubuntu:~/code/rootfs# vim etc/profile
# /etc/profile: system-wide .profile file for the Bourne shells

echo
echo -n "Processing /etc/profile... "
# no-op
#!/bin/sh
`hostname Louis`
HOSTNAME=`hostname`
USER=`id -un`
LOGNAME=$USER
HOME=$USER
PS1="[\u@$\h: \W]\# "
PATH=/bin:/sbin:/usr/bin:/usr/sbin
LD_LIBRARY_PATH=/lib:/usr/lib:$LD_LIBRARY_PATH
export PATH LD_LIBRARY_PATH HOSTNAME USER PS1 LOGNAME HOME
alias ll="ls -l"
echo "Processing /etc/profile... "
echo "Done"

参考 Documentation/filesystems/nfs/nfsroot.txt 给 u-boot 设置传给内核的命令行参数。

set bootargs root=/dev/nfs nfsroot=192.168.5.136:/root/code/rootfs ip=192.168.5.187 init=/init console=ttySAC0,115200

nfsroot 指定了服务器的 IP 和根文件系统在服务器的路径, ip 指定了开发板中的 Linux 内核的 IP

现在开启虚拟机中 ubuntu 系统的 NFS 服务

root@ubuntu:~/code/rootfs# apt-get install nfs-kernel-server
root@ubuntu:~/code/rootfs# vi /etc/exports

        在 exports 配置文件中指定根文件系统的路径,如果不指定 no_root_squash,客户端(开发板)没法修改网络文件系统的内容。


成功启动,有个小问题: dm9000 dm9000: read wrong id 0x01010101
这是 dm9000 驱动在读取 ID 时的错误,驱动中会连续读取 8 次,这里第一次读取错误,我们可以在
第一次读取之前加上一个延时,就可以解决这个错误。 在移植
u-boot 中就加了一个延时。

我制作的根文件系统下载:https://download.csdn.net/download/jerrygou/10484876


猜你喜欢

转载自blog.csdn.net/jerrygou/article/details/80714976
今日推荐