Hi,
I am trying to crosscompile libudev library on the imx28. I followed the older post but this did not work for me as well ie.,
https://community.freescale.com/message/320397#320397
I need this library so I can monitor USB-stick insertion in my attached c application.
So could you please anybody please kindly let me know how to do this correctly with appropriate steps as early as possible, as am stuck with this from long time with the existing ltib by following the older link
Kindly do the needful,
Awaiting for your replies
Many Many Thanks in advance!
Original Attachment has been moved to: libudev-test.c.zip
解決済! 解決策の投稿を見る。
I am sorry there is a software bug in my previous example. If the "/dev/my_udisk" does not appear to be the first element in the "ENV{DEVLINKS}" the udev rule matching will fail and this rule will never run. To solve this problem, I use the key "ENV{DEVPATH}" in my new example instead.
If you run "udevinfo -a -p /sys/block/sda" on EVK's OTG port and HOST port, you will see that they can be distinguished by the udev key "KERNELS'. "KERNELS" is "fsl-ehci" for OTG port and is "fsl-ehci.0" for HOST port.
Attached 99-my.rules is the revised udev rules. If memory stick is plugged to the OTG port, device node "/dev/otg_udisk" will create and script "/unit_tests/my_test.sh" will run. If memory stick is plugged to the HOST port, device node "/dev/host_udisk" will create and the new script "/unit_tests/my_test2.sh" will run.
The "date -s 12:00:00" is merely an example to show how to run program when device node changes. Actually, any other programs can be used. In the new example, we change the "proc/sys/kernel/printk_ratelimit_burst" value.
LTIB has already included the udev-117 package. You can extract the source code to rpm/BUILD by command "./ltib -m prep -p udev.spec". Is there any reason that an update libudev package must be used?
By default udev-117 package is enabled, but still am unable to crosscompile the above testapp
Basically I need to monitor USB-stick insertion in C application, & am using the above testapp as because I was not able to succeed through libudev & am using I.MX28 BSP,
I guess udev-117 does not support usb monitoring feature because of which am unable to cross compile the above testapp
kindly do the needful as I had spent enough time in trying with libudev
Many Thanks in advance,
Your libudev-test.c cannot pass the cross-compilation because the libudev.h header is missing and the required APIs are not supported by udev-117. You should either get the udev source code from a later version and cross compile the libudev first or rewrite the libudev-test.c to make use of the APIs and structure in udev-117.
Otherwise, try the approach suggested in https://community.freescale.com/message/369700#369700,
When a usb device is plugged, /sbin/hotplug binary will be called with the following arguments:
[0] = hotplug path
[1] = "usb"
[2] = 0
And the hotplug environment variables to be set are:
ACTION=action
PRODUCT=idVendor/idProduct/bcdDevice
TYPE=device_class/device_subclass/device_protocol
Hi Peter,
Please let me know if you find any updates in how to use the above feature with detailed information & necessary configurations that needs to be done in ltib & how to set the hot plug environment variables, & how this can be tested & utilized in my application
Hello Srinivasan,
I would like to show you an example how to monitor a USB memory stick in i.MX28 kernel by writing udev rules. In this example, assuming you need to run a program when a USB memory stick is plugged to the USB host port on i.MX28 EVK.
udev provides a dynamic device directory such that when new device is present or removed, device node files will be created/removed dynamically according to the udev rules. When a USB memory stick is plugged, the respective device node files are created and partition "sda" is mounted.
To inspect the device info and hierarchy, try "udevinfo -a -p /sys/block/sda". Here you should see all possible device keys that can be used to create your own rule file relating to this device.
The udev rules are parsed in lexical order in the /etc/udev/rule.d. In this example, a file named "99-my.rules" is created at /etc/udev/rule.d with the following content:
FILE:/etc/udev/rule.d/99-my.rules
_____________________________________________________________
ACTION=="add", KERNEL=="sd*", SUBSYSTEM=="block", SUBSYSTEMS=="scsi", KERNELS=="host*", SYMLINK+="my_udisk%n" RUN+="/unit_tests/my_test.sh"
ACTION=="remove", ENV{DEVLINKS}=="/dev/my_udisk", RUN+="/unit_tests/my_test.sh"
_____________________________________________________________
* The first line is wrapped by the editor and is shown as 2 lines here. This is not correct and please use 1 line in your actual rule file.
The first line says:
If all these conditions are matched
1) event action = "add"
2) kernel name of the device begins with "sd"
3) subsystem of the device is "block"
4) any parents' device name in the hierarchy begins with "host"
5) any parents' subsystem is "scsi"
Then
1) create symbolic linked device files begins with /dev/my_udisk according to the kernel number of this device
2) run the program (shell script here) "/unit_tests/my_test.sh"
The second line says:
If event action is "remove" and device property DEVLINKS is "/dev/my_udisk", then run the program "/unit_tests/my_test.sh"
In this example, the my_test.sh is nothing more than setting the time to 12:00:00 when added and to 13:00:00 when removed.
FILE: /unit_tests/my_test.sh
__________________________________________________________
#!/bin/sh
if [ "$ACTION" = "add" ]
then
date -s 12:00:00
else
date -s 13:00:00
fi
_____________________________________________________________
To see what udev environment variables are receiving the "remove" event when unplug, use "udevmonitor --env".
With the above procedure, you should see the time is reset to 12:00:00 when the USB stick is plugged to USB host1, and changed to 13:00:00 when the USB stick is removed.
Here are the suggested readings about udev where the example here is derived from them.
http://www.reactivated.net/writing_udev_rules.html#udevinfo
http://ubuntuforums.org/showthread.php?t=168221
https://wiki.archlinux.org/index.php/udev
http://www.linuxquestions.org/questions/linux-desktop-74/udev-not-doing-remove-rules-841733/
udev man page
Thanks a lot for your replies Peter,
It is really helpful for me & for others as well
I feel using date -s 12:00:00 & date -s 13:00:00 would affect the clock of the system, could youplease let me know whether any other unique parameter that can be considered apart from this date,
And more over I have two USB ports in my custom board, could you please help me how this can be achieved for add & remove of the of the two usb sticks ie., pls let me know if there are any necessary changes to be done in the usb rules and also any other dependency configurations needs to be done apart from this
Kindly do the needful as early as possible
Thanks a lot again for your detailed explanation
I am sorry there is a software bug in my previous example. If the "/dev/my_udisk" does not appear to be the first element in the "ENV{DEVLINKS}" the udev rule matching will fail and this rule will never run. To solve this problem, I use the key "ENV{DEVPATH}" in my new example instead.
If you run "udevinfo -a -p /sys/block/sda" on EVK's OTG port and HOST port, you will see that they can be distinguished by the udev key "KERNELS'. "KERNELS" is "fsl-ehci" for OTG port and is "fsl-ehci.0" for HOST port.
Attached 99-my.rules is the revised udev rules. If memory stick is plugged to the OTG port, device node "/dev/otg_udisk" will create and script "/unit_tests/my_test.sh" will run. If memory stick is plugged to the HOST port, device node "/dev/host_udisk" will create and the new script "/unit_tests/my_test2.sh" will run.
The "date -s 12:00:00" is merely an example to show how to run program when device node changes. Actually, any other programs can be used. In the new example, we change the "proc/sys/kernel/printk_ratelimit_burst" value.
Hi Peter,
Am using your above below rules modified as below fro monitoring USB insertion, this is working fine
ACTION=="add", KERNEL=="sd[a-z]*", SUBSYSTEM=="block", KERNELS=="fsl-ehci",RUN+="/usr/bin/usb_init add %k 1"
ACTION=="add", KERNEL=="sd[a-z]*", SUBSYSTEM=="block", KERNELS=="fsl-ehci.0",RUN+="/usr/bin/usb_init add %k 2"
For monitoring USB removal,
ACTION=="remove", ENV{DEVPATH}=="/devices/platform/fsl-ehci/usb1/1-1", RUN+="/usr/bin/usb_init remove %k 1"
ACTION=="remove", ENV{DEVPATH}=="/devices/platform/fsl-ehci.0/usb2/2-1", RUN+="/usr/bin/usb_init remove %k 2"
ACTION=="remove", ENV{DEVPATH}=="/devices/platform/fsl-ehci/usb1/1-1", RUN+="/bin/umount -l /media1/%k"
ACTION=="remove", ENV{DEVPATH}=="/devices/platform/fsl-ehci.0/usb2/2-1", RUN+="/bin/umount -l /media2/%k"
When I remove & insert frequently I get the following errors
FAT: Directory bread(block 30509) failed
FAT: Directory bread(block 30510) failed
FAT: Directory bread(block 30511) failed
FAT: Directory bread(block 30512) failed
FAT: Directory bread(block 30513) failed
FAT: Directory bread(block 30514) failed
FAT: Directory bread(block 30515) failed
FAT: Directory bread(block 1151804) failed
FAT: Directory bread(block 1151805) failed
FAT: Directory bread(block 1151806) failed
FAT: Directory bread(block 1151807) failed
FAT: Directory bread(block 1151808) failed
FAT: Directory bread(block 1151809) failed
FAT: Directory bread(block 1151810) failed
FAT: Directory bread(block 1151811) failed
When I tried to manually umount as below am unbale to umount
root@CMS5 /media1$ umount -l *
umount: can't forcibly umount sdb: Invalid argument
umount: can't forcibly umount sdc: Invalid argument
umount: can't forcibly umount sdd: Invalid argument
umount: can't forcibly umount sde: Invalid argument
umount: can't forcibly umount sdf: Invalid argument
umount: can't forcibly umount sdh: Invalid argument
umount: can't forcibly umount sdi: Invalid argument
umount: can't forcibly umount sdj: Invalid argument
umount: can't forcibly umount sdl: Invalid argument
root@CMS5 /media1$
Could you please help me in resolving the above errors as early as possible
Kindly do the needful as early as possible
Awaiting for your replies
Many Many Thanks in advance
Thanks a lot Peter for your detailed explanation it was very useful for me & would be very useful to others as well
Many Many Thanks once again
Thanks a lot for your replies Peter,
As am new to this USB & hotplug feature concept, could you please help how to use this hotplug feature with detailed information & where to set the hotplug environment variables, & how this can be utilized for my usb insertion/removal application
sorry if this seems to be silly question
Thanks a lot in advance again