本文主要是介绍JZ2440笔记:热插拔驱动,希望对大家解决编程问题提供一定的参考价值,需要的开发者们随着小编来一起学习吧!
(1)打印环境变量
vi lib/kobject_uevent.c +208
printk("feng: uevent_helper = %s\n",uevent_helper);
for(i=0;envp[i];i++)
{printk("envp[%d] = %s\n",i,envp[i]);
}
使用修改后的uImage启动,测试打印应用程序的环境变量:
# insmod dma.ko
feng: uevent_helper = /sbin/mdev
envp[0] = HOME=/
envp[1] = PATH=/sbin:/bin:/usr/sbin:/usr/bin
envp[2] = ACTION=add
envp[3] = DEVPATH=/module/dma
envp[4] = SUBSYSTEM=module
envp[5] = SEQNUM=743
feng: uevent_helper = /sbin/mdev
envp[0] = HOME=/
envp[1] = PATH=/sbin:/bin:/usr/sbin:/usr/bin
envp[2] = ACTION=add
envp[3] = DEVPATH=/class/s3c_dma/dma
envp[4] = SUBSYSTEM=s3c_dma
envp[5] = SEQNUM=744
envp[6] = MAJOR=252
envp[7] = MINOR=0
# ls /sys/class/s3c_dma/dma
dev subsystem uevent
# cat /sys/class/s3c_dma/dma/dev
252:0
# rmmod dma.ko
feng: uevent_helper = /sbin/mdev
envp[0] = HOME=/
envp[1] = PATH=/sbin:/bin:/usr/sbin:/usr/bin
envp[2] = ACTION=remove
envp[3] = DEVPATH=/class/s3c_dma/dma
envp[4] = SUBSYSTEM=s3c_dma
envp[5] = SEQNUM=745
envp[6] = MAJOR=252
envp[7] = MINOR=0
feng: uevent_helper = /sbin/mdev
envp[0] = HOME=/
envp[1] = PATH=/sbin:/bin:/usr/sbin:/usr/bin
envp[2] = ACTION=remove
envp[3] = DEVPATH=/class/s3c_dma
envp[4] = SUBSYSTEM=class
envp[5] = SEQNUM=746
feng: uevent_helper = /sbin/mdev
envp[0] = HOME=/
envp[1] = PATH=/sbin:/bin:/usr/sbin:/usr/bin
envp[2] = ACTION=remove
envp[3] = DEVPATH=/module/dma
envp[4] = SUBSYSTEM=module
envp[5] = SEQNUM=747
(2)修改mdev.conf(修改后要重启啊,不然不行)
# insmod myleds.ko
myleds_drv_init
# ls -l /dev/led*
crw-rw---- 1 0 0 252, 1 Jun 4 22:31 /dev/led1
crw-rw---- 1 0 0 252, 2 Jun 4 22:31 /dev/led2
crw-rw---- 1 0 0 252, 3 Jun 4 22:31 /dev/led3
crw-rw---- 1 0 0 252, 0 Jun 4 22:31 /dev/leds
# rmmod myleds.ko
myleds_drv_exit
1、# vi /etc/mdev.conf
leds 0:0 777
led1 0:0 777
led2 0:0 777
led3 0:0 777
# insmod myleds.ko
myleds_drv_init
# ls /dev/led* -l
crwxrwxrwx 1 0 0 252, 1 Jun 4 23:05 /dev/led1
crwxrwxrwx 1 0 0 252, 2 Jun 4 23:05 /dev/led2
crwxrwxrwx 1 0 0 252, 3 Jun 4 23:05 /dev/led3
crwxrwxrwx 1 0 0 252, 0 Jun 4 23:05 /dev/leds
2、# vi /etc/mdev.conf
leds?[123]? 0:0 777
# ls -l /dev/led*
ls: /dev/led*: No such file or directory
# insmod myleds.ko
myleds_drv_init
# ls -l /dev/led*
crwxrwxrwx 1 0 0 252, 1 Jun 4 23:41 /dev/led1
crwxrwxrwx 1 0 0 252, 2 Jun 4 23:41 /dev/led2
crwxrwxrwx 1 0 0 252, 3 Jun 4 23:41 /dev/led3
crwxrwxrwx 1 0 0 252, 0 Jun 4 23:41 /dev/leds
3、# vi /etc/mdev.conf
leds?[123]? 0:0 777 @ echo create /dev/$MDEV > /dev/console
# insmod myleds.ko
create /dev/led2
myleds_drv_init
# create /dev/led3
create /dev/leds
create /dev/led1
# vi /etc/mdev.conf
leds?[123]? 0:0 777 * if [ $ACTION = "add" ]; then echo create /dev/$MDEV > /dev/console; else remove create /dev/$MDEV > /dev/console; fi
# insmod myleds.ko
myleds_drv_init
# create /dev/led3
create /dev/led1
create /dev/leds
create /dev/led2
# rmmod myleds
myleds_drv_exit
remove时没有反应,没成功???
原来是驱动中出口函数exit写错了,并且没有卸载所有的led设备文件,呵呵。改好后
# insmod myleds.ko
create /dev/led1
create /dev/led2
myleds_drv_init
# create /dev/led3
create /dev/leds
# rmmod myleds.ko
remove /dev/leds
remove /dev/led3
myleds_drv_exit
remove /dev/led2
# remove /dev/led1
4、vi add_remove_led.sh 添加
#!/bin/sh
if [ $ACTION = "add" ];
then
echo create /dev/$MDEV > /dev/console;
else
echo remove /dev/$MDEV > /dev/console;
fi
#chmod +x /bin/add_remove_led.sh
# vi /etc/mdev.conf
leds?[123]? 0:0 777 * /bin/add_remove_led.sh
# insmod myleds.ko
myleds_drv_init
# create /dev/led1
create /dev/leds
create /dev/led3
create /dev/led2
# rmmod myleds.ko
remove /dev/leds
myleds_drv_exit
# remove /dev/led3
remove /dev/led2
remove /dev/led1
5、# vi /etc/mdev.conf
sda[1-9]+ 0:0 777 * if [ $ACTION = "add" ]; then mount /dev/$MDEV /mnt; else umount /mnt; fi
# ls /dev/sda* -l
brw-rw---- 1 0 0 8, 0 Jun 5 10:06 /dev/sda
brwxrwxrwx 1 0 0 8, 1 Jun 5 10:06 /dev/sda1
# cat /proc/mounts
rootfs / rootfs rw 0 0
/dev/root / yaffs rw 0 0
proc /proc proc rw 0 0
sysfs /sys sysfs rw 0 0
tmpfs /tmp tmpfs rw 0 0
tmpfs /var tmpfs rw 0 0
tmpfs /dev tmpfs rw 0 0
devpts /dev/pts devpts rw 0 0
/dev/sda1 /mnt vfat rw,fmask=0000,dmask=0000,codepage=cp936,iocharset=cp936 0 0
# ls -l /mnt
drwxrwxrwx 2 0 0 32768 May 30 23:15 System Volume Information
drwxrwxrwx 7 0 0 32768 Oct 18 2023 һ▒▒▒Ƽ▒▒▒▒▒▒▒▒▒
# usb 1-1: USB disconnect, address 3
# cat /proc/mounts
rootfs / rootfs rw 0 0
/dev/root / yaffs rw 0 0
proc /proc proc rw 0 0
sysfs /sys sysfs rw 0 0
tmpfs /tmp tmpfs rw 0 0
tmpfs /var tmpfs rw 0 0
tmpfs /dev tmpfs rw 0 0
devpts /dev/pts devpts rw 0 0
6、vi add_remove_udisk.sh 添加#!/bin/sh
if [ $ACTION = "add" ];
then
mount /dev/$MDEV /mnt;
else
umount /mnt;
fi
#chmod +x /bin/add_remove_udisk.sh
# vi /etc/mdev.conf
sda[0-9]+ 0:0 777 * /bin/add_remove_udisk.sh
# ls -l /dev/sda*
ls: /dev/sda*: No such file or directory
# cat /proc/mounts
rootfs / rootfs rw 0 0
/dev/root / yaffs rw 0 0
proc /proc proc rw 0 0
sysfs /sys sysfs rw 0 0
tmpfs /tmp tmpfs rw 0 0
tmpfs /var tmpfs rw 0 0
tmpfs /dev tmpfs rw 0 0
devpts /dev/pts devpts rw 0 0
# cat /proc/mounts
rootfs / rootfs rw 0 0
/dev/root / yaffs rw 0 0
proc /proc proc rw 0 0
sysfs /sys sysfs rw 0 0
tmpfs /tmp tmpfs rw 0 0
tmpfs /var tmpfs rw 0 0
tmpfs /dev tmpfs rw 0 0
devpts /dev/pts devpts rw 0 0
/dev/sda1 /mnt vfat rw,fmask=0000,dmask=0000,codepage=cp936,iocharset=cp936 0 0
# ls -l /dev/sda*
brw-rw---- 1 0 0 8, 0 Jun 5 13:34 /dev/sda
brwxrwxrwx 1 0 0 8, 1 Jun 5 13:34 /dev/sda1
# ls -l /mnt
drwxrwxrwx 2 0 0 32768 May 30 23:15 System Volume Information
drwxrwxrwx 7 0 0 32768 Oct 18 2023 һ▒▒▒Ƽ▒▒▒▒▒▒▒▒▒
# usb 1-1: USB disconnect, address 2
# ls -l /dev/sda*
ls: /dev/sda*: No such file or directory
# cat /proc/mounts
rootfs / rootfs rw 0 0
/dev/root / yaffs rw 0 0
proc /proc proc rw 0 0
sysfs /sys sysfs rw 0 0
tmpfs /tmp tmpfs rw 0 0
tmpfs /var tmpfs rw 0 0
tmpfs /dev tmpfs rw 0 0
devpts /dev/pts devpts rw 0 0
这篇关于JZ2440笔记:热插拔驱动的文章就介绍到这儿,希望我们推荐的文章对编程师们有所帮助!