该楼层疑似违规已被系统折叠 隐藏此楼查看此楼
视频来自:优酷
一、ARM+Linux硬件操作流程及对代码的简单理解
二、NFS挂载网络文件系统
①准备NFS文件系统目录
1. 准备 NFS 文件系统目录
启动 nfs 服务之前,必须在 Ubuntu 上准备好 NFS 共享目录。
例如 , 我们采用 Ubuntu 的 “ /jingjing/root ” 作为 NFS 共享目录 , 就需要将FileSystem-Yaffs2.tar.gz 压缩文件拷贝到这个目录下,然后解压缩,得到根文件系统所需要的目录。
在 Ubuntu 上打开一个终端,输入以下命令:
#mkdir /forlinx/root
将 FileSystem-Yaffs2.tar.gz 文件拷贝到该目录下,解压:
#tar – zxf FileSystem-Yaffs2.tar.gz
2. 设置主机 IP
这里我们将 Ubuntu 的 IP 设置为 192.168.0.231
3. 配置 NFS 服务
在 Ubuntu 上新建一个终端,依次输入以下命令:
#sudo apt-get install portmap
#sudo apt-get install nfs-kernel-server
#sudo gedit /etc/exports
在弹出的文本编辑器中编辑 exports 文件,在最后一行添加:
/forlinx *(rw,sync,no_root_squash)
4. 启动 NFS 服务
#sudo /etc/init.d/portmap restart
#sudo /etc/init.d/nfs-kernel-server restart
5 检查服务是否已经运行
#service portmap status
#service nfs-kernel-server status
如果这里显示已经成功运行,那么就开始接下来的操作吧~
②挂载根文件系统到宿主机
在 u-boot 命令行下输入以下命令设置 U-boot 启动参数:
#setenv bootargs"root=/dev/nfsnfsroot=192.168.0.231:/forlinx/root/FileSystem-Yaffs2 ip=192.168.0.232:192.168.0.231:192.168.0.201:255.255.255.0:witech.com.cn:eth0:off console=ttySAC0,115200"
保存:
#saveenv
注意: setenv 和 bootargs 之间不是回车,而是空格。当然也不要忘了执行 saveenv 保存参数设置命令哦。
重新启动开发板, Linux 内核启动后会自动挂载 NFS 文件系统。
在这,解释一下 bootargs 参数中 IP ,以上述设置为例。在实际使用过程当中,请以实际网络环境进行修改:
192.168.0.231 PC 端 Ubuntu 的 IP
192.168.0.232 开发板 IP ,开发板的 IP 必须和 PC 端的 IP 在同一个网段,这里都是 0 网段
192.168.0.201 网关
255.255.255.0 子网掩码
nfs 挂载成功,需要开发板网络设置、 PC Linux 网络设置、硬件网线连接、开发板 mount这几部分都没有问题。如果没有成功挂载,需要从这几部分查找原因。如果是使用虚拟机安装Linux ,在挂载 nfs 的时候,建议关闭 Windows 的杀毒软件和防火墙。
③挂在目录文件到宿主机
步骤 1. 根据实际情况,设置 PC 端 Linux 的 nfs 服务器。这里我使用的 /etc/exports 内容为 “ / * ”
/ 代表 PC Linux 根目录和子目录都可以被挂载。
* 代表挂载的时候权限为最大
将 PC Linux 的 IP 设置为 192.168.0.1
步骤 2. 正确设置开发板的 IP 等网络环境,注意要使开发板的 IP 和 PC Llinux 在同一网段。
步骤 3.关闭 PC 所有的杀毒软件和防火墙 ( 尤其是 xp 虚拟 linux 时 , xp 下的防火墙和杀毒软件 )。如不关闭,有可能无法挂载。
步骤 4. 挂载 nfs 到开发板的 /temp 。
#mount – t nfs -o nolock 192.168.0.1:/mnt /temp
命令执行成功后, 开发板的 /temp 目录就和 Linux 宿主机的 /mnt 目录建立了共享关系,在超级终端或者 DNW 中执行 ls – al /temp ,可以看到宿主机 /mnt 文件目录下面的所有内容。另外可以在 PC Linux 上编译应用程序,放到 PC 机的 /mnt 目录,在超级终端或者 DN W中 执行 cd / temp 命令进入到 temp 目录下面 ,执行应用程序 ,这样可以加快调试进度。
八、驱动代码及应用代码
1.驱动代码:
#include
#include
#include
#include
#include
#include
#include
#include
#include
#include
#include
#include
#include
#include
#include
#include
#include
#include
#include
#include
#include
#include
#include
#include
#include
#include
#include
#include
#define DEVICE_NAME "leds"
static long s3c6410_leds_ioctl(struct file *filp, unsigned int cmd, unsigned long arg)
{
switch(cmd) {
unsigned tmp;
case 0:
case 1:
if (arg > 4)
{
return -EINVAL;
}
tmp = readl(S3C64XX_GPMDAT);
if(cmd==0)
{
tmp &= (~(1<
}
else
{
tmp |= (1<
}
writel(tmp,S3C64XX_GPMDAT);
//printk (DEVICE_NAME": %d %d\n", arg, cmd);
return 0;
default:
return -EINVAL;
}
}
static struct file_operations dev_fops = {
.owner = THIS_MODULE,//设备所有者
.unlocked_ioctl = s3c6410_leds_ioctl,//需要自己实现
};
static struct miscdevice misc = {
.minor = MISC_DYNAMIC_MINOR,//注册设备号
.name = DEVICE_NAME,//注册设备名称
.fops = &dev_fops,//设备操作
};
static int __init dev_init(void)
{
int ret;
unsigned tmp;
//gpm0-3 output mode 初始化控制寄存器
tmp =readl(S3C64XX_GPMCON);
tmp &= (~0xFFFF);
tmp |= 0x1111;
writel(tmp,S3C64XX_GPMCON);
//gpm0-3 output 0 初始化数据寄存器
tmp = __raw_readl(S3C64XX_GPMDAT);
tmp |= 0x10;
writel(tmp,S3C64XX_GPMDAT);
//注册设备
ret = misc_register(&misc);
return ret;
}
static void __exit dev_exit(void)
{
misc_deregister(&misc);
}
module_init(dev_init);//模块的初始化及注册
module_exit(dev_exit);//模块的卸载
2.应用代码:
#include
#include
#include
#include
#define LEDS "/dev/leds"
int fd;
int main(void)
{
fd = open("/dev/leds", O_RDWR);
if (fd < 0)
{
perror("Open /dev/leds failed");
exit(1);
}
int i = 0;
while(1)
{
for(i = 0; i < 4; i++)
{
ioctl(fd, 0, i);
sleep(1);
ioctl(fd, 1, i);
}
}
close(fd);
return 0;
}
好啦,又是一个长长的帖子,希望大家看完之后可以有所收获~
今天就到这里了,祝大家心情愉快~~