I need to find a way to detect when a usb device is plugged in C on an old embedded Linux (CentOs 4).
libudev and libusb are not available so I'm a little clueless with my options here. There is dbus, however I cannot use udisks as the device I need to detect is not a storage device.
Thanks.
You can try to write a custom script and register it in /proc/sys/kernel/hotplug. When a uevent occurs, the kernel will invoke your script and pass the subsystem (usb in your case) as an argument. Then you will have to match the device (I don't know how to do that, that's probably the most tricky part).
Skeleton for your custom hotplug script that matches the USB subsystem:
$ cat my_hotplug.sh
#!/bin/sh
[ "$1" = usb ] || exit 0
echo "Do something here"
Registering your hotplug script as the uevent helper:
echo /path/to/my_hotplug.sh > /proc/sys/kernel/hotplug
Related
If I have Android phone connected via USB, how do I know the commands I can send via USB to get Information like
core temperature of the device,
version of android,
power consumption details, etc.
Can I then use ADB logs, command to interact with Android mobile. Please may i know the process apart from commands if I have to send commands via ADB.
To get information from an android device, you can always use the following tools.
Use utilities like dumpsys or getprop.
Query from /sys/ or /proc/.
Eventually all utilities, fetch information from /proc or /sys, so you can directly investigate into these.
You could use dumpsys tools to get information:
Core temperature of the device
I'm not sure, what exactly do you mean by core temperature of the device.
Temperature of Device: Note
$ adb shell cat /sys/class/thermal/thermal_zone0/temp
37
Temperature of Battery:
$ adb shell cat /sys/class/power_supply/battery/device/power_supply/battery/temp
285
or
$ adb shell dumpsys battery
Current Battery Service state:
AC powered: false
USB powered: true
Wireless powered: false
status: 2
health: 2
present: true
level: 15
scale: 100
voltage: 3768
current now: -357254
temperature: 285 # <---- Temparature.
technology: Li-ion
Version of android
$ getprop ro.build.version.release
4.4.4 #<--- Android Kitkat 4.4.4
I'm not completely sure how you can get exact information:
You could start with,
$ adb shell dumpsys power
POWER MANAGER (dumpsys power)
Power Manager State:
....
Note: Results on a Linux System.
$ acpi -t # <--- apci power utility/tool.
Thermal 0: ok, 29.8 degrees C
Thermal 1: ok, 27.8 degrees C
$ cat /sys/class/thermal/thermal_zone0/temp
27800
I want this to be executed every 50 ms ?
You could write a script with above commands, that queries every 50ms.
Set-up ADB on Windows ?
A quick Google search should help you out.
Set Up Android ADB On Windows
To make proper use of Dumpsys,
See What's the Android ADB shell "dumpsys" tool and what are its benefits?
http://android-test-tw.blogspot.in/2012/10/dumpsys-information-android-open-source.html
Getprop : Android ADB commands to get the device properties
I hope this should give you a good start.
You will get the Android device properties using getprop command.
Please go through this blog .Here I am listing some of the major ADB commands. Feel free to ask doubts regarding these commands.
DFU does not seem to work on a development board (Hitex LPC1850 or Keil MCB1800), but the manual states that it should work.
I could not find the same problem on the internet, so I posted my problem here.
(I manually compiled dfu-util 0.7, but the lpcXpresso bundled binary gives similar result)
tijs#debian:~/u-boot$ sudo ../dfu-util/src/dfu-util -R -D u-boot-dfu.bin boot/u-boot/u-boot-dfu.bin dfu-util 0.7
Copyright 2005-2008 Weston Schmidt, Harald Welte and OpenMoko Inc. Copyright 2010-2012 Tormod Volden and Stefan Schmidt This program is Free Software and has ABSOLUTELY NO WARRANTY Please report bugs to dfu-util#lists.gnumonks.org
Opening DFU capable USB device...
ID 1fc9:000c Run-time device DFU version 0100
Claiming USB DFU Runtime Interface...
Determining device status: state = dfuIDLE, status = 0
dfu-util: WARNING: Runtime device already in DFU state ?!?
Claiming USB DFU Interface...
Setting Alternate Setting #0 ...
Determining device status: state = dfuIDLE, status = 0
dfuIDLE, continuing
DFU mode device DFU version 0100
Device returned transfer size 2048
Copying data from PC to DFU device
Download [=========================] 100%
90640 bytes Download done.
dfu-util: unable to read DFU status
The problem is, that I am not sure if u-boot has been executed.
Reset (-R) should do that, but it tells me that it is 'unable to read dfu status'.
Am I missing something here?
Does anyone know what might be the problem here?
I already used dfu-util and this message has always been displayed but it doesn't affect the Reset. Once you execute
dfu-util -R -D u-boot-dfu.bin
you should get U-Boot console through serial port (ttyS0... or ttyUSB0 if you are using a Serial to USB dongle...) using minicom or a similar tool.
I ported U-Boot on the Hitex board in SPI Flash and using USB to get the console during a internship, so maybe I can help you further.
Thanks for helping.
It seems that the message "dfu-util: unable to read DFU status" is normal.
The problem was that my bootloader was not working because it was for a similar board with more internal SRAM. I just had to port my bootloader first, console is now working.
I am trying to setup linux kernel module debugging, using two machines - target and host. On target machine, I have compiled and installed a 3.5.0 kernel with CONFIG_MAGIC_SYSRQ=y flag and other flags for over the serial console debugging.
When I want to break the kernel to attach remote gdb, I use
$ echo g > /proc/sysrq-trigger
But above command is not breaking the kernel.
$ cat /proc/sys/kernel/sysrq"
Above command is returning 1, hence magic sysrq keys are enabled. Even "echo b > /proc/sysrq-trigger" is working and rebooting the machine. Can anybody please point out what I may be missing?
Thanks
You have first configure your target kernel as follows
CONFIG_FRAME_POINTER=y
CONFIG_DEBUG_KERNEL=y
CONFIG_KGDB=y
CONFIG_DEBUG_INFO=y
CONFIG_KGDB_SERIAL_CONSOLE=y (here I am using serial port for kgdb)
CONFIG_MAGIC_SYSRQ= y (for sysrq functions).
Now compile kernel with imx6 configuration file.
Boot the target with this compiled kernel.You have to tell tell target which serial port you are going to use for kgdb pupose.In my case I am using the same console port for kgdb also.This settings you can do either through kernel parameters or via sysfs entry.For imx6 sabrelite board,I am using ttymxc1 for console.This will change depending on your target
1) As a kernel parameter
Add the following parameter to bootargs
kgdboc=/dev/ttymxc1,115200 to your arguments.
2) If you are using sysfs entry, do like this
echo /dev/ttymxc1,115200 > /sys/module/kgdboc/parameters/kgdboc
Since same serial port is used for both the console and debugging, we use agent proxy. Through agent proxy we get the target console as well as we do the debugging.
Source for compiling agentproxy is available at the following link
"https://kernel.googlesource.com/pub/scm/utils/kernel/kgdb/agent-proxy/+/agent-proxy-1.96"
After compiling for host pc ,run it as follows
sudo ./agent-proxy 5550^5551 0 /dev/ttyS0,15200
Now you can see target terminal through telnet with this agentproxy support
sudo telnet localhost 5550
(It is better to use this telnet instead of minicom where only this agent proxy support comes.)
When you want to start debugging, the target system has to enter debug mode from normal mode. We can do that in this way in target
echo g > /proc/sysrq-trigger
Now it will enter debugger mode.
Now from host side run gdb on vmlinux of the arm compiled kernel.
Go to the corresponding kernel source directory and do like this
arm-fsl-linux-gnueabi-gdb ./vmlinux
Now it will show gdb terminal .From there you have to connect to target for kgdb,
$target remote /dev/ttyS0
In my case my host serial port is /dev/ttyS0.
Now it will get connected to target. Here after you can use gdb commands to debug the kernel.
You try this way.
I am working with QEMU 1.1.0, emulating Versatile Express board with ARM Cortex-A9. I have managed to launch simple "Hello World" example following this instructions:
http://balau82.wordpress.com/2012/03/31/compile-linux-kernel-3-2-for-arm-and-emulate-with-qemu/
but now I want to create filesystem by myself.
I decided to use buildroot, version 2012.05. and I've configured it to create toolchain, kernel and filesystem image for ARM Cortex-A9 target.
Kernel is of version 3.3.7 and for the filesystem I've selected to be cpio, non-compressed. The initrd argument in call to qemu-system-arm is pointing to
/output/images/rootfs.cpio
When I launch QEMU kernel boots, but then I get this message:
Initializing random number generator... done.
Starting network...
can't open /dev/ttyS0: No such device or address
can't open /dev/ttyS0: No such device or address
can't open /dev/ttyS0: No such device or address
...
All I can do is to terminate QEMU.
I have checked the contents of rootfs.cpio like this:
cpio -t < rootfs.cpio
and saw that there is /dev/ttyS0.
Have I missed something in configuring the filesystem? Or should I use filesystem in
/output/target
to somehow create device(s) there (Buildroot does not do that), and then rebuild the filesystem?
I'm new to Buildroot, so any hint or suggestion is more than welcome.
Extract rootfs and type ls -all /dev/ttyS0 and check it's major and minor number. Because if your major number is not the required one then it will not invoke respective kernel functionality and in that case it will only be a junk character device.
Also can you post the whole log file (copy all those dmesg and post those somewhere and give link here.)
And if you are sure that /dev/ttyS0 is there then do the following steps :
extract(unpack using cpio) rootfs
find out which init file kernel is using as parent process. If you are lucky then it would be lying in root directory. named init or initrc
open init file in your favorite editor.
starting few lines of your init would be like
::respawn:/sbin/getty -L 38400 tty1
::respawn:/sbin/getty -L 38400 tty2
::respawn:/sbin/getty -L 38400 tty3
::respawn:/sbin/getty -L 38400 tty4
add ::respawn:/sbin/ls -all /dev and save the file. (We have added list command to see what is there inside /dev directory)
reboot your system and check the dmesg. See if /dev/ttyS0 is really missing ?
I am making a module to do some basic stuff in my pen drive following the example here . its stating that the usb storage(in my case pen drive) device uses usb-storage driver . I saw in hardware info that its usb_storage(which is same as usb-storage as when i do rmmod usb -storage it states that ERROR: Module usb_storage does not exist in /proc/modules) . I have done even lsmod with and without device its not showing any module name usb-storage.
My doubt is simple how to know which module controles which device and i know it could be unloaded by rmmod (module name).
Assuming that your kernel actually has usb-storage support this means the module is built in to the kernel and cannot be removed.
Try rebuilding your kernel after changing the usb-storage support to be built as a module, rather than directly into the kernel.
There should be no problem removing the module if you are the Super user. Otherwise, change to super user then try to remove it. It can be done by sudo su command.
And for the list of modules being used, you can view the device log by dmesg and check out.