硬件渠道:FL2440
内核版别:2.6.28
主机渠道:Ubuntu 11.04
内核版别:2.6.39
1、首要装备busybox
busybox
Linux System Utilities —>
[*] mdev
[*] Support /etc/mdev.conf
[*] Support command execution at device addition/removal
2、装备内核
3、修正文件体系里的/etc/init.d/rcS
#!/bin/sh
/bin/mount -a
/sbin/ifconfig eth0 192.168.0.3 up
#exec /usr/etc/rc.mouse
4、修正文件体系中/linuxrc文件
#!/bin/sh
#echo “mount /etc as ramfs”
#/bin/mount -n -t ramfs ramfs /etc
#/bin/cp -a /mnt/etc/* /etc
#/bin/mount -n -t ramfs ramfs /var/state/dhcp
#/bin/mount -n -t ramfs ramfs /var/log/boa
#/bin/mount -n -t ramfs ramfs /usr/Setting
#/bin/cp -a /mnt/Setting/* /usr/Setting
#/bin/mount -n -t ramfs ramfs /tmp
#/bin/cp -a /mnt/etc/* /etc
/bin/mount -t proc proc /proc
/bin/mount -t sysfs sysfs /sys
/bin/mount -t tmpfs tmpfs /dev
mkdir /dev/pts
mkdir /dev/shm
/bin/echo /sbin/mdev > /proc/sys/kernel/hotplug
/sbin/mdev -s
exec /sbin/init
4、修正/etcfstab
vi ./etc/fstab
#device mount-point type options dump fsck order
none /dev/pts devpts mode=0622 0 0
tmpfs /dev/shm tmpfs defaults 0 0
这样编写驱动时不必手动创立设备结点文件了
下面是改写的运用稠浊设备的ADC驱动程序,这样能够主动创立和删去设备结点了
- #include
- #include
- #include
- #include
/*创立设备节点*/ - #include
- #include
/*界说DECLARE_WAIT_QUEUE_HEAD*/ - #include
/*界说了irqreturn_t等*/ - #include
interrupt.h>/*request_irqdisable_irqenable_irq*/ - #include
- #include
- #include/*其间包含了#include”mach/irqs.h”*/
- #include
adc.h> - #include
- #defineADC_MAJOR102
- #defineADC_NAME”my_adc”
- #defineSUCCESS0
- staticintadc_open(structinode*,structfile*);
- staticintadc_release(structinode*,structfile*);
- staticint__initadc_init(void);
- staticint__exitadc_exit(void);
- staticssize_tadc_read(structfile*,char*,size_t,loff_t*);
- volatileunsignedlongadc_con;
- unsignedlongadc_dat0;
- intflag;//等候使命完结标志
- unsignedlongbuf;//寄存转化完结的数据
- //声明等候行列
- DECLARE_WAIT_QUEUE_HEAD(adc_wait);
- structclk*adc_clk;
- staticirqreturn_tadc_interrupt(intirq,void*dev_id)//中止处理程序
- {
- if(flag==0)
- {
- buf=(readw(adc_dat0)&0x3ff);//读取转化完结的数据
- flag=1;
- wake_up_interruptible(&adc_wait);//唤醒等候其上的进程
- printk(“Readvalueis%ld\n”,buf);
- }
- returnIRQ_HANDLED;
- }
- staticstructfile_operationsadc_ops=
- {
- .owner=THIS_MODULE,
- .read=adc_read,
- .open=adc_open,
- .release=adc_release,
- };
- staticstructmiscdeviceadc_misc=
- {
- .name=ADC_NAME,
- .minor=ADC_MAJOR,
- .fops=&adc_ops,
- };
- staticint__initadc_init(void)
- {
- intret;
- adc_clk=clk_get(NULL,”adc”);//获取时钟
- clk_enable(adc_clk);//使能时钟
- ret=misc_register(&adc_misc);//注册设备
- if(ret<0)
- {
- printk(“registerdevicefail\n”);
- returnret;
- }
- adc_con=(unsignedlong)ioremap(0x58000000,4);
- adc_dat0=(volatileunsignedlong)ioremap(0x58000000+S3C2410_ADCDAT0,4);
- if(!(adc_con&adc_dat0))
- {
- printk(“Failedtoioremap\n”);
- gotohandle;
- }
- printk(“Initialized…\n”);
- returnSUCCESS;
- handle:
- misc_deregister(&adc_misc);
- return-1;
- }
- staticintadc_open(structinode*inode,structfile*file)//翻开设备函数
- {
- //注册中止
- intret;
- //disable_irq(IRQ_ADC);
- //enable_irq(IRQ_ADC);
- ret=request_irq(IRQ_ADC,adc_interrupt,IRQF_SHARED,ADC_NAME,1);//注册中止IRQ_ADC在mach/irqs.h中界说
- if(ret<0)
- {
- printk(“IRQ%dcannotrequest\n”,IRQ_ADC);
- returnret;
- }
- returnSUCCESS;
- }
- staticintadc_release(structinode*inode,structfile*file)//封闭设备函数
- {
- free_irq(IRQ_ADC,1);//开释中止
- returnSUCCESS;
- }
- staticssize_tadc_read(structfile*file,
- char*buffer,
- size_tlength,
- loff_t*offset)//设备读取函数
- {
- writew((1<<14)|(0x31<<6),adc_con);//设置ADCCON
- writew((readw(adc_con)|0x1),adc_con);//发动AD转化
- wait_event_interruptible(adc_wait,flag);
- flag=0;
- }
- staticint__exitadc_exit(void)//驱动卸载函数
- {
- iounmap(adc_con);
- iounmap(adc_dat0);
- misc_deregister(&adc_misc);
- clk_disable(adc_clk);
- clk_put(adc_clk);
- printk(“Theadcisunintialized\n”);
- returnSUCCESS;
- }
- module_init(adc_init);
- module_exit(adc_exit);
- MODULE_L%&&&&&%ENSE(“GPL”);