0
votes

I created a simple module that controls wheter a USB supplies power for a device when in host mode or not. When loaded, this module cuts off the power to any device connected until told otherwise.

It is also desired that when booted, the system comes with both my module loaded, and the USB supply cut off. To this end, so far I've tried:

  1. Setting my module as a kernel built-in: had no effect, modules that are loaded later overrun my configuration;
  2. Creating an init.d script: Created the script, and set it up to run on rc5. No luck as well, I run into multiple problems with USB devices (such as usb 2-1: device descriptor read/64, error -110);

I'm running Kernel 3.12 on a custom board, and I've tested that the module works as intended if I load it manually (via modprobe) into the system, after logging in.

Ideally, I want to keep these configurations to be done during boot, without any need of logins and such.

So, my question is: how can I postpone the module loading until the last possible minute, assuring that any other configuration is already finished? Also, is udev a good solution for this sort of thing? From what I read, I had the impression it wouldn't be the best fit...

Regards,

Guilherme

1
Your module seems missing to declare proper dependencies. - hek2mgl
I'm using sysv init. Also, I made a small typo: I added it to rc5, not rc6. Fixed it =] - Guilherme Costa
@GuilhermeCosta Check out the chkconfig utility. You can configure a range of rcN init scripts to load/start your module later in the boot cycle. Note that your script will look something like /etc/rc5.d/S80mystart, which will be a symbolic link to where your real script is located. S80 means on start and the 80 is a late number. - Peter L.
@GuilhermeCosta There is also a module late load option in the kernel. It is a list of modules to be loaded after others. - Peter L.
@PeterL. I was doing exactly that, which was when I got those weird errors I mentioned. Fortunately, I figured out that they can be avoided by unbinding the USB device i want to power off first (which is weird, seeing as if I load the module myself, there is no need for that, but I believe it has something to do with udev). - Guilherme Costa

1 Answers

1
votes

So, I've figured out how to get rid of the errors when using an init.d script. All that is needed is to unbind the devices before loading the module. the following line before the modprobe did the trick for me:

echo "2-1" > /sys/bus/usb/drivers/usb/unbind

Regards,

Guilherme