/***********************************************************************
* I.MX6 Linux udev porting
* 声明:
* 在嵌入式产品上,我们可以使用mdev来解决热插拔的问题,同时也经常看到
* udev,所以尝试来移植一下,但是最终发现她会丢失内核阶段产生的uevent,
* 这导致无法生成内核阶段产生的设备节点,目前采用了mdev来做完成内核阶段的
* 设备节点生成,之后使用udev完成热插拔,这个问题后续有空再解决。
*
* 2016-1-17 深圳 南山平山村 曾剑锋
**********************************************************************/一、参考文档:1.“configure: error: Package requirements (blkid) were not met”
http://unix.stackexchange.com/questions/215406/configure-error-package-requirements-blkid-were-not-met
2. 建立ARM交叉编译环境arm-none-linux-gnueabi-gcc
http://blog.sina.com.cn/s/blog_a000da9d0101436p.html
3. [原创]嵌入式系统UDEV的移植
http://blog.chinaaet.com/snifer/p/38942
4. 用Busybox制作嵌入式Linux的文件系统
http://www.jiancool.com/article/6782467490/
5. 编译busybox,动态链接与静态链接的选择
http://blog.csdn.net/newnewman80/article/details/7971317
6. busybox 制作动态库文件系统
http://www.xuebuyuan.com/913205.html
7. 第 12章使用 udev 进行动态内核设备管理
https://www.suse.com/zh-cn/documentation/sles11/singlehtml/book_sle_admin/cha.udev.html
二、Download:1. 网址:http://pkgs.fedoraproject.org/repo/pkgs/udev/
2. 目标:udev-070.tar.gz 或者 udev-126.tar.gz
三、udev-070.tar.gz 编译:1. Makefile 修改:
将142行:
CROSS= #/usr/i386-linux-uclibc/usr/bin/i386-uclibc-修改为:
CROSS= arm-linux-gnueabihf-
2. make
四、udev-126.tar.gz编译:1. ./configure --prefix= --target=arm-linux-gnueabihf --host=arm-linux-gnueabihf2. 上面的会保存在udevd程序中;3. 可以考虑先找个地方编译安装一次,得到一些配置文件,再编译一次不指定位置的,替换udev等可执行文件。4. ./configure --prefix= --target=arm-linux-gnueabihf --host=arm-linux-gnueabihf5. cp udev/test-udev udev/udevd udev/udevadm /sbin
五、Error:1. 编译udev-182.tar.bz2不通过:1. 错误如下:
checkingfor xsltproc... /usr/bin/xsltproc
checkingfor library containing clock_gettime... -lrt
checkingforBLKID... no
configure: error: Package requirements (blkid>= 2.20) were not met:
No package'blkid'found
Consider adjusting the PKG_CONFIG_PATH environment variableifyou
installed softwarein a non-standard prefix.
Alternatively, you maysetthe environment variables BLKID_CFLAGS
and BLKID_LIBS to avoid the need to call pkg-config.
See the pkg-config man page formore details.2. 未能解决,换低版本。2. 编译udev-070.tar.gz错误:1. 现象:
Running arm-linux-gnueabihf-ar: [OK]
Running arm-linux-gnueabihf-ranlib: [OK]
Compiling udev.c: [OK]
Linking udev: [ERROR]
arm-linux-gnueabihf-gcc -s -Wl -Wl,-warn-common udev.o -o udev libudev.a libs
ysfs/libsysfs.a
arm-linux-gnueabihf-gcc: error: unrecognized command line option ‘-Wl’
make:*** [udev] Error 1
2. 解决办法:1. 注释187行:LDFLAGS += -s -Wl2. 注释204行:LDFLAGS += -Wl,-warn-common3. 运行依赖动态库程序错误:1. 现象:
[^_^ bin]# ls udev main mainso -al-rwxrwxr-x 1 1001 1001 463813 Jan 16 2016main-rwxrwxr-x 1 1001 1001 5970 Jan 16 2016mainso-rwxrwxr-x 1 1001 1001 35268 Jan 16 2016udev
[^_^ bin]# ./udev-/bin/sh: ./udev: not found
[^_^ bin]# ./main
hello world.
[^_^ bin]# ./mainso-/bin/sh: ./mainso: not found
[^_^bin]#2. 采用的编译方式:1. udev、mainso采用的共享库的方式编译的;2. main采用的静态编译的。3. 解决方法:
由于busybox采用了静态编译的方式进行编译,这样可以在不依赖库的情况下运行,
所以自己对busybox进行重现编译,采用动态库共享库的方式进行编译,程序运行正常。4. 使用udev-070.tar.gz热插拔无效果:1. 配置没写好,本例以miniSD卡为例;2. cat /etc/udev/udev.conf
# Whereinthe filesystem to place the device nodes
udev_root="/dev"# The name and location of the udev database.
udev_db="/dev/.udevdb"# The name and location of the udev rules file(s).
udev_rules="/etc/udev/rules.d"# The syslog(3) priority: "err", "info", or the numerical value.
udev_log="err"
3. cat /etc/udev/rules.d/udev-devfs.rules
......
ACTION=="add", KERNEL=="mmcblk[0-9][b-z][0-9]", RUN+="/bin/mkdir -p /mnt/mmc%n"ACTION=="remove", KERNEL=="mmcblk[0-9][b-z][0-9]", RUN+="/bin/rm -rf /mnt/mmc%n"......4. cat /etc/init.d/rcS
......
# 这个用于找回内核启动阶段的设备节点,要不然连ttymxc0(debug口)节点都没有。/sbin/mdev -s
......
udevd--daemon &udevstart
......5. 效果如下:
[zengjf@root ]# ls/mnt
[zengjf@root ]# mmc1: host does not support reading read-only switch. assuming write-enable.
mmc1:newhigh speed SDHC card at address aaaa
UEVENT[946688081] add@/devices/plmmcblk1: mmc1:aaaa SS08G 7.40GiB
atform/sdhci-esdhc-imx.2/mmc_host/mmc1/mmc1:aaaa
UEVENT[946688081] add@/devices/virtual/bdi/179:24mmcblk1: p1 p2 p3
UEVENT[946688081] add@/devices/platform/sdhci-esdhc-imx.2/mmc_host/mmc1/mmc1:aaaa/block/mmcblk1
UEVENT[946688081] add@/devices/platform/sdhci-esdhc-imx.2/mmc_host/mmc1/mmc1:aaaa/block/mmcblk1/mmcblk1p1
UEVENT[946688081] add@/devices/platform/sdhci-esdhc-imx.2/mmc_host/mmc1/mmc1:aaaa/block/mmcblk1/mmcblk1p2
UEVENT[946688081] add@/devices/platform/sdhci-esdhc-imx.2/mmc_host/mmc1/mmc1:aaaa/block/mmcblk1/mmcblk1p3
[zengjf@root ]# ps|grep udev1417 root 0:00 udevd --daemon1509 root 0:00udevmonitor1743 root 0:00udev mmc1746 root 0:00udev bdi1753 root 0:00grep udev
[zengjf@root ]# ls/mnt
mmc1 mmc2 mmc3
[zengjf@root ]# mmc1: card aaaa removed
UEVENT[946688175] remove@/devices/platform/sdhci-esdhc-imx.2/mmc_host/mmc1/mmc1:aaaa/block/mmcblk1/mmcblk1p3
UEVENT[946688175] remove@/devices/platform/sdhci-esdhc-imx.2/mmc_host/mmc1/mmc1:aaaa/block/mmcblk1/mmcblk1p2
UEVENT[946688175] remove@/devices/platform/sdhci-esdhc-imx.2/mmc_host/mmc1/mmc1:aaaa/block/mmcblk1/mmcblk1p1
UEVENT[946688175] remove@/devices/virtual/bdi/179:24UEVENT[946688175] remove@/devices/platform/sdhci-esdhc-imx.2/mmc_host/mmc1/mmc1:aaaa/block/mmcblk1
UEVENT[946688175] remove@/devices/platform/sdhci-esdhc-imx.2/mmc_host/mmc1/mmc1:aaaa
[zengjf@root ]# ls/mnt
[zengjf@root ]#6. udev丢失kernel阶段设备事件:
如上,如果不使用/sbin/mdev -s 获取内核阶段的的设备节点,udev无法获取到内核阶段的。
目前还没找到什么更好的办法来解决,也许以后不小心就解决了。5. udev-126.tar.gz udevd运行错误:1. 错误现象:
......
udevd[1468]: lookup_group: specified group 'tty'unknown
......
udevd[1468]: lookup_group: specified group 'uucp'unknown
udevd[1468]: lookup_group: specified group 'kmem'unknown
udevd[1468]: lookup_group: specified group 'lp'unknown
......
udevd[1468]: lookup_group: specified group 'disk'unknown
udevd[1468]: lookup_group: specified group 'floppy'unknown
......
udevd[1468]: lookup_group: specified group 'disk'unknown
......2. 解决办法:
cat/etc/group
......
tty:x:1:tty
uucp:x:2:uucp
kmem:x:3:kmem
lp:x:4:lp
disk:x:5:disk
floppy:x:6:floppy
disk:x:7:disk
......3. cat /etc/udev/rules.d/udev-devfs.rules
......
ACTION=="add", KERNEL=="mmcblk[0-9][b-z][0-9]", RUN+="/bin/mkdir -p /mnt/mmc%n"ACTION=="remove", KERNEL=="mmcblk[0-9][b-z][0-9]", RUN+="/bin/rm -rf /mnt/mmc%n"......4. 运行正常效果:
input: USB OPTICAL MOUSEas /devices/platform/fsl-ehci.1/usb2/2-1/2-1.2/2-1.2:1.0/input/input4
generic-usb 0003:0000:0538.0001: input,hidraw0: USB HID v1.11 Mouse [ USB OPTICAL MOUSE] on usb-fsl-ehci.1-1.2/input0
udevd (1426): /proc/1426/oom_adj is deprecated, please use /proc/1426/oom_score_adj instead.
udevd version126started
zengjf login: root
login[1429]: root login on 'ttymxc0'[zengjf@root~]# ls /mnt
[zengjf@root~]# mmc1: host does not support reading read-only switch. assuming write-enable.
mmc1:newhigh speed SDHC card at address aaaa
mmcblk1: mmc1:aaaa SS08G7.40GiB
mmcblk1: p1 p2 p3
[zengjf@root~]# ps
......1408 root 0:00[kjournald]1426 root 0:00 udevd --daemon1427 root 0:00 [flush-179:0]1429 root 0:00 -sh1433 root 0:00 [mmcqd/1]1461 root 0:00ps
[zengjf@root~]# ls /mnt
mmc1 mmc2 mmc3
[zengjf@root~]# mmc1: card aaaa removed
[zengjf@root~]# ls /mnt
[zengjf@root~]#