Chinaunix首页 | 论坛 | 博客
  • 博客访问: 181518
  • 博文数量: 54
  • 博客积分: 0
  • 博客等级: 民兵
  • 技术积分: 2018
  • 用 户 组: 普通用户
  • 注册时间: 2013-03-31 23:14
文章存档

2014年(2)

2013年(52)

分类: 嵌入式

2013-05-27 20:21:29

         忙了一两天,我这个菜鸟总算对简单驱动开发流程建立起了一个框架。现在还没具体在程序编写上,相信这些前期工作有了是个好的开端。
        从裸机驱动开发学习到挂载系统开发驱动,开发环境的变化有必要说一下。
        
        首先在这里推荐一个linux版本fedora 9之前所用为ubuntu7.10及韦东山教程上讲的版本,自开发以来就一直没用顺手。ubuntu是简单版有很多编译环境之类的工作需要手动完成,而且源也不好找。红帽子的这个版本安装时就可以把一些编译环境也安装齐备,在学习时只需把arm-linux-gcc配置上就没撒问题了,在这里用的是VMware-workstation-6.5.1  +     fedora 9    +  xp   用着顺手多了(具体安装细节在网上多找找应该没撒问题,主要是共享撒的)主要是安装系统是有一些麻烦,不过网上资料对照着也好解决。
       这里总结一下fedora 9安装问题解决:
      1,VM TOOLS安装。转载:http://blog.sina.com.cn/s/blog_4ed5ebd00100k4io.html
         内容如下:

首先说明一下软件情况:
vmware workstation 5.5.1
FC9

安装Vmwar Tools
选择VM-->install VMware Tools
[root@localhost ~]# mkdir /mnt/cdrom
[root@localhost ~]#mount /dev/cdrom /mnt/cdrom/
[root@localhost ~]# cd /mnt/cdrom/

[root@localhost cdrom]# ls 后有
VMwareTools-6.5.0-118166.i386.rpm
VMwareTools-6.5.0-118166.tar.gz


[root@localhost cdrom]# cp VMwareTools-6.5.0-118166.tar.gz /tmp //拷贝到/tmp下
[root@localhost cdrom]# cd /tmp/
[root@localhost tmp]# tar zxvf VMwareTools-6.5.0-118166.tar.gz //解包文件
[root@localhost tmp]# cd vmware-tools-distrib/
[root@localhost vmware-tools-distrib]# ./vmware-install.pl   //安装开始

一路回车之后出现:


What is the location of the directory of C header files that match your running kernel? [/usr/src/linux/include]
The path "/usr/src/linux/include" is not an existing directory.
查看目录/usr/src/ 根本没有linux这个目录
只有/usr/src/redhat

 

安装kernel devel包

先查看内核版本号
[root@localhost ~]# uname -r 
2.6.25-14.fc9.i686
[root@localhost ~]# rpm -q kernel-i686-devel
package kernel-xen-devel is not installed

 

这是i686的内核,所以,要安装对应版本号的 kernel-i686-devel rpm包:

下载地址:
http://rpm.pbone.net/index.php3/stat/4/idpl/7201713/com/kernel-devel-2.6.25-14.fc9.i686.rpm.html

安装:
[root@localhost ~]# rpm -ivh 
kernel-devel-2.6.25-14.fc9.i686.rpm

完成安装后,在/usr/src/下已经多出了一个kernels目录
[root@localhost ~]# cd /usr/src/
[root@localhost src]# ls

kernels redhat

[root@localhost src]# cd kernels
[root@localhost kernels]# ls
2.6.20-2925.9.fc7.i686.rpm

表明kernel-xen-devel已经装好了
再次使用vmware-install.pl安装,

./vmware-install.pl

 

就一直enter,装完VMware Tools
(可自动找到配套的the directory of C header files了,哈)

在安装的最后阶段,会出现:
Do you want to change your guest X resolution? (yes/no) [no] y

Please choose one of the following display sizes (1 - 13):

[1] "640x480"
[2]< "800x600"
[3] "1024x768"
[4] "1152x864"
[5] "1280x800"
[6] "1152x900"
[7] "1280x1024"
[8] "1376x1032"
[9] "1400x1050"
[10] "1680x1050"
[11] "1600x1200"
[12] "1920x1200"
[13] "2364x1773"

Please enter a number between 1 and 13:

[3]

 

重启系统,OK了



2
虚拟机Fedora linux 下鼠标定位不准的解决办法
转载:
3:fedora 9源:ftp://download.fedora.redhat.com/pub/fedora/linux/releases/9/Fedora/i386/iso/Fedora-9-i386-DVD.iso
    
       对应板子配置好的内核文件(2.6.32.2)生成zImage之后,编写驱动程序也要用这个文件,如这里的led字符驱动在linux2.6.32.2/driver/char下编写。
       
      编写好后在同目录makefile中添加obj-m   +=led.o

      根目录make modules    char下生成led.ko
   
      应用程序在任意位置make生成led
   
      应用程序的可执行文件led与led.ko送到板子上我的是( /lib/modules/2.6.32.2-FriendlyARM/)   加载insmod led.ko   
 
     同目录下调用如./led a  b  (a取
0-3,b取0、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
#define DEVICE_NAME "leds"
static unsigned long led_table [] = {
S3C2410_GPB(5),
S3C2410_GPB(6),
S3C2410_GPB(7),
S3C2410_GPB(8),
};
static unsigned int led_cfg_table [] = {
S3C2410_GPIO_OUTPUT,
S3C2410_GPIO_OUTPUT,
S3C2410_GPIO_OUTPUT,
S3C2410_GPIO_OUTPUT,
};
static int sbc2440_leds_ioctl(
struct inode *inode, 
struct file *file, 
unsigned int cmd, 
unsigned long arg)
{
switch(cmd) {
case 0:
case 1:
if (arg > 4) {
return -EINVAL;
}
s3c2410_gpio_setpin(led_table[arg], !cmd);
return 0;
default:
return -EINVAL;
}
}

static struct file_operations dev_fops = {
.owner = THIS_MODULE,
.ioctl = sbc2440_leds_ioctl,
};

static struct miscdevice misc = {
.minor = MISC_DYNAMIC_MINOR,
.name = DEVICE_NAME,
.fops = &dev_fops,
};

static int __init dev_init(void)
{
int ret;
int i;
for (i = 0; i < 4; i++) {
s3c2410_gpio_cfgpin(led_table[i], led_cfg_table[i]);
s3c2410_gpio_setpin(led_table[i], 0);
}

ret = misc_register(&misc);

printk (DEVICE_NAME"\tinitialized\n");

return ret;
}

static void __exit dev_exit(void)
{
misc_deregister(&misc);
}
module_init(dev_init);
module_exit(dev_exit);
MODULE_LICENSE("GPL");
MODULE_AUTHOR("FriendlyARM Inc.");
   
   应用程序:
 #include
#include
#include
#include
int main(int argc, char **argv)
{
int on;
int led_no;
int fd;
if (argc != 3 || sscanf(argv[1], "%d", &led_no) != 1 || sscanf(argv[2],"%d", &on) != 1 ||
   on < 0 || on > 1 || led_no < 0 || led_no > 3) {
fprintf(stderr, "Usage: leds led_no 0|1\n");
exit(1);
}
fd = open("/dev/leds0", 0);
if (fd < 0) {
fd = open("/dev/leds", 0);
}
if (fd < 0) {
perror("open device leds");
exit(1);
}
ioctl(fd, on, led_no);
close(fd);
return 0;
}

应用程序的makefile:
CROSS=arm-linux-
all: led
led: led.c
$(CROSS)gcc -o led led.c
clean:
@rm -vf led *.o *~

下面是一网友开发的全流程:  


步骤一:在内核文件夹的drivers/char下面编写驱动的.c文件,注意要用misc device(杂项设备)来注册;

步骤二:在同目录下的Kconfig和Makefile文件中做相应的修改;(Kconfig用于make menuconfig用,menuconfig实现具体还要makefile支持是否有模块支持)

步骤三:make menuconfig中加载模块,然后编译内核.bin文件;(对于初学这一步跳过)

步骤四:make SUBDIR=drivers/char/ modules,编译出驱动的.ko文件;

步骤五:编写应用测试程序,.c文件可以在任意的目录下,执行make后生成可执行文件;

步骤六:将内核的.bin文件、驱动的.ko文件以及应用程序的可执行文件一同转入PC机,用串口下载入开发板。(同3,.bin无需)

        加入驱动的命令:cd /lib;(/lib/modules/2.6.32.2-FriendlyARM/

                        rz;

                        insmod ***.ko;   //得到加载成功的提示

        加入应用程序的命令:cd /usr/sbin (或者/sbin);  (这一步直接用./led a  b  (a取0-3,b取0、1)即可验证程序

                            rz;

                            chmod 777 ***;  //改变控制级别

                            ***;           



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