黑盒移植,即在不用理解驱动程序的细节基础上进行移植
驱动移植的主要流程如下:
一、黑盒移植
1、将驱动编译进内核
如果内核中已经有了已经支持的驱动,那直接在menu上选配即可。若没有,则需要第三方的驱动或者自己写一个驱动,移植进内核。
1)将第三方驱动放到linux源码的driver目录中
拷贝LED驱动程序至drivers目录
LED属于字符设备,所以放在drivers/char/目录下
2)修改Makefile让驱动编译进内核(对应目录下的Makefile)
make uImage编译内核
3)测试·驱动
烧写镜像到开发板
在ubuntu上编译驱动程序测试代码, 并拷贝到根文件系统
1 #include <stdio.h> 2 #include <fcntl.h> 3 #include <unistd.h> 4 #include <stdlib.h> 5 #include <sys/ioctl.h> 6 7 #define LED_MAGIC 'L' 8 #define LED_ON _IOW(LED_MAGIC, 1, int) 9 #define LED_OFF _IOW(LED_MAGIC, 2, int) 10 11 int main(int argc, char **argv) 12 { 13 int fd; 14 15 fd = open("/dev/led", O_RDWR); 16 if (fd < 0) { 17 perror("open"); 18 exit(1); 19 } 20 21 printf("open led ok\n"); 22 23 //实现LED灯闪烁 24 while(1) 25 { 26 ioctl(fd, LED_ON); //点亮灯 27 usleep(100000); 28 ioctl(fd, LED_OFF); //灭灯 29 usleep(100000); 30 } 31 32 return 0; 33 }