PowerWalker UPS Problem

unseen

Contributor
Joined
Aug 25, 2017
Messages
103
I use a "PowerWalker under another name" UPS on my TrueNAS 13 system. I have had this unit for ages and it works just fine - the only thing I have had to do is replace the battery once as it wore out over the course of about six or seven years. The electronics are well built and are still working perfectly. The UPS has a USB connection which implements a simple serial interface which is handled in NUT via the blazer_usb driver. When you connect the UPS, it reports itself as: "ugen0.5: <INNO TECH USB to Serial> at usbus0", with ugen0.5 varying according to the USB port number used. It should be noted that this type of UPS will not work if you plug it in to a USB3 port - it must be USB 1.1 or USB 2.

Anyway, since upgrading to TrueNAS 13, an old problem has returned. The problem is that everything works fine at first, but sooner or later (normally after a few days), the blazer_usb driver will die with the following message:

blazer_usb 1417 - - Permissions problem: Input/output error

The problem is caused by the UPS occasionally returning a bad status to the blazer_usb driver. This is caused by firmware bugs in the UPS and as it's old and not supported by the manufacturer with firmware updates, there's no way to fix the firmware. The error message is also misleading as there is no permissions problem involved.

In previous versions of freenas/truenas, I was able to make some simple changes to the blazer_usb driver which made it simply ignore the error instead of shutting down the driver. When the driver tries to talk to the UPS the next time, it gets a valid response again and everything continues to work. In FreeBSD 13.1, the blazer_usb driver has been updated and the problem has come back. I have just compiled a new version of blazer_usb with my old fix re-implemented for the 2.8.0 version of NUT which is included with FreeBSD 13.1 and am currently testing the fix.

If my UPS is still running without the driver crashing out in a week from now, I'd say that my fix also works on the latest version. In that case, I'll update this post with the details of the fix for those who are also having the same problem and who want to compile their own replacement blazer_usb driver. I'll also be able to provide the fixed driver as a binary file for anyone who is prepared to trust some stranger from the Internet. ;)
 
Last edited:

unseen

Contributor
Joined
Aug 25, 2017
Messages
103
I let my patched driver run for two weeks now and I think I can finally declare it as stable. I have had no problems with the driver exiting and all UPS reporting has continued without problems.

If you are affected by the driver issue, here's how to fix it.
  • Create yourself a 'porting' jail. This is a clone jail of the latest 13.1-RELEASE
  • Get a root console in your jail (iocage console porting)
  • Install the ports tree. (portsnap fetch, portsnap extract)
  • Install the pkg utility (run 'pkg' and answer Y to install it)
  • Enter the /usr/ports/sysutils/nut directory
  • Install dependencies for building (make install-missing-packages)
    Answer Y to all questions, including those about conflicts
  • Get the files for the nut port (make fetch)
  • Extract the files and configure nut (make extract)
    Answer OK to the presented default options
Once you get to this point, you are ready to modify the blazer_usb.c source file to fix the problem.

Change directory to /usr/ports/sysutils/nut/work/nut-2.8.0/drivers

Edit blazer_usb.c and search for "EPERM" (it only appears once in the file).
Change the code at the "case -EPERM:" section to what you see below:
Code:
#if WITH_LIBUSB_0_1 /* limit to libusb 0.1 implementation */
        case -EPERM:            /* Operation not permitted */
           // fatal_with_errno(EXIT_FAILURE, "Permissions problem");
           upsdebugx(1, "Permission problem. Retry");
           break;              
#endif /* WITH_LIBUSB_0_1 */

All we have done here is to comment out the line which causes an exit_failure when EPERM is received and added a debug message to indicate that we will retry instead of blowing up.

To compile the new driver:
  • Change to the port's top level directory (cd /usr/ports/sysutils/nut)
  • Build the nut port (make)
  • Grab a copy of the new executable from the drivers directory (/usr/ports/sysutils/nut/work/nut-2.8.0/drivers/blazer_usb)
Your existing blazer_usb driver is installed on your truenas server under /usr/local/libexec/nut so installing the new driver is a simple matter of:
  • Log in to truenas as root
  • Change directory to /usr/local/libexec/nut
  • If blazer_usb is running, kill it (killall blazer_usb)
  • Rename the current executable (mv blazer_usb blazer_usb.org)
  • Copy your new, fixed driver here as blazer_usb
  • Make sure that the new file's permissions and ownership are 555 root:wheel
  • Start the new driver (./blazer_usb -a myups)
    "myups" should be changed to whatever the identifier of your UPS is in the Services->UPS configuration page
The new driver should now be running and will stay running, despite the broken firmware on the PowerWalker UPS.
If you can't be bothered going through the installation of the ports tree in a jail and you trust some random person on the Internet who you have never met, I've attached the fixed blazer_usb driver to this message in a ZIP file.

I hope this helps someone and please let me know if it does!
 

Attachments

  • blazer_usb.zip
    43.3 KB · Views: 137
Top