Controlling USB device power off/save at boot?

On the command line I can use usbconfig like so;

Code:
# usbconfig -d ugen0.3 power_off
# usbconfig -d ugen0.4 power_save

However I would like this to happen automatically when booting, I could only find device hints for loader.conf to disable the drivers, not set the usb power status?

Thanks,
James
 
You'll have to write your own rc(8) script for that.
When a script is executed at boot time, it is passed the string
``start'' as its first and only argument. At shutdown time, it is
passed the string ``stop'' as its first and only argument.

You can follow /etc/rc.d/swap for an example.
 
  • Thanks
Reactions: JAW
Phishfry - devd is the better choice here, you are right. A usb device can come and go after a boot.

I've actually been playing with devd today to automatically attach an encrypted disk with geli, then mount that into my filesystem, then nullfs mount that into my bacula jail.
 
  • Thanks
Reactions: JAW
Thanks for the suggestions. My idea of using usbconfig during boot was completely flawed due to the differing enumeration of usb devices depending on what is plugged in to the USB ports... doh!

My aim is to save some power on my laptop by disabling the devices I never use, such as the Bluetooth Hub (ugen0.3/6) and SD card reader (ugen0.8), seen below;

Code:
ugen0.2: <product 0x7811 vendor 0x7392> at usbus0, cfg=0 md=HOST spd=HIGH (480Mbps) pwr=ON (500mA)
ugen0.3: <BRCM20702 Hub Apple Inc.> at usbus0, cfg=0 md=HOST spd=FULL (12Mbps) pwr=SAVE (94mA)
ugen0.6: <Bluetooth USB Host Controller Apple Inc.> at usbus0, cfg=0 md=HOST spd=FULL (12Mbps) pwr=ON (0mA)
ugen0.7: <Apple Internal Keyboard  Trackpad Apple Inc.> at usbus0, cfg=0 md=HOST spd=FULL (12Mbps) pwr=ON (500mA)
ugen0.8: <Card Reader Apple> at usbus0, cfg=0 md=HOST spd=SUPER (5.0Gbps) pwr=ON (224mA)

I first tried disabling drivers with device.hints in /boot/loader.conf such as the umass driver, but then no usb flash storage will work at all! So perhaps the /etc/devd.conf approach targetting the specific vendor/product id's of the above devices is the way to go?

Many Thanks,
James
 
targetting the specific vendor/product id's of the above devices is the way to go?
That or drive serial number or some other unique identifier. devd would allow a finer grained approach.

I would be interested in what you come up with. I plan on using some Pi3's on batteries and this would be useful for power consumption.

I ran a check on a drive laying around and it looks like iSerialNumber might be something to check.
Code:
@DELL:~ # usbconfig -u 1 -a 5 dump_device_desc
ugen1.5: <Ultra USB 3.0 SanDisk> at usbus1, cfg=0 md=HOST spd=HIGH (480Mbps) pwr=ON (224mA)

  bLength = 0x0012
  bDescriptorType = 0x0001
  bcdUSB = 0x0210
  bDeviceClass = 0x0000  <Probed by interface class>
  bDeviceSubClass = 0x0000
  bDeviceProtocol = 0x0000
  bMaxPacketSize0 = 0x0040
  idVendor = 0x0781
  idProduct = 0x5591
  bcdDevice = 0x0100
  iManufacturer = 0x0001  <SanDisk>
  iProduct = 0x0002  <Ultra USB 3.0>
  iSerialNumber = 0x0003  <4C530001070110116052>
  bNumConfigurations = 0x0001
 
If you want to run a script at boot time on FreeBSD, you can let rc run it. rc is a built-in utility that controls the automatic boot process. The manual has a detailed description of its configuration files and features. man rc.

power_save - Turn the automatic suspend and resume on
power_off - Turn the device off.

cat >> /usr/local/etc/rc.d/usb_script.sh <<EOF
#!/bin/sh
/usr/sbin/usbconfig -u 0 -a 6 power_save
sleep 2
EOF

# chmod 0755 usb_script.sh

Have a nice day
 
Back
Top