You are not logged in.

#1 2021-10-30 11:01:31

jose1711
Member
Registered: 2006-07-08
Posts: 144

Correct way to load firmware into printer via udev

Hello,

every time my old HP1020 printer is started it needs firmware code loaded from a PC - otherwise it simply won't work. To accomplish that I made a simple udev rule which goes like this:

# /etc/udev/rules.d/load_printer_firmware.rules
SUBSYSTEMS=="usb", ENV{ID_VENDOR_ID}=="03f0", ENV{ID_MODEL_ID}=="2b17", ACTION=="add", RUN+="/path/to/load_printer_firmware.sh"

The script itself waits 10 seconds, then it sends the firmware via USB.

# load_printer_firmware.sh
sleep 10
/usr/bin/cat /path/to/hplj_sihp1020.dl > /dev/usb/lp0

The problem is that at the time when cat is executed there is no /dev/usb/lp0 hence the whole operation fails. From systemd point of view it looks like this:

okt 30 11:28:46 hppro kernel: usb 5-1: new high-speed USB device number 2 using xhci_hcd
okt 30 11:28:46 hppro kernel: usb 5-1: New USB device found, idVendor=03f0, idProduct=2b17, bcdDevice= 1.00
okt 30 11:28:46 hppro kernel: usb 5-1: New USB device strings: Mfr=1, Product=2, SerialNumber=3
okt 30 11:28:46 hppro kernel: usb 5-1: Product: HP LaserJet 1020
okt 30 11:28:46 hppro kernel: usb 5-1: Manufacturer: Hewlett-Packard
okt 30 11:28:46 hppro kernel: usb 5-1: SerialNumber: FN1W674
okt 30 11:28:56 hppro systemd-udevd[2428]: 5-1: Process '/path/to/load_printer_firmware.sh' failed with exit code 1.
okt 30 11:28:56 hppro systemd[571]: Reached target Printer.
okt 30 11:28:56 hppro systemd[1]: Reached target Printer Support.

Increasing the wait time did not helps as it seems that the /dev/usb/lp0 is created after the script finishes executing. I've checked Arch wiki but could not find a solution to this problem.

Cheers,

jose

Offline

#2 2021-10-30 14:06:05

korikori
Member
Registered: 2020-09-30
Posts: 10

Re: Correct way to load firmware into printer via udev

There is a hotplug script for this that comes with the Debian package of foo2zjs, but is either missing from or not installed automatically (more likely) with the packages in AUR. The script itself is available at https://github.com/koenkooi/foo2zjs/blo … r/hplj1000, and the udev rule that detects your version of 10** is at https://github.com/koenkooi/foo2zjs/blo … 10xx.rules.

Offline

#3 2021-10-30 19:33:54

jose1711
Member
Registered: 2006-07-08
Posts: 144

Re: Correct way to load firmware into printer via udev

Thank you, you'currently foo2zjs-nightly in AUR is broken and while foo2zjs-minimal-nightly it indeed lacks hotplug part. I am not sure if the referenced script would work since I can see it relies on presence of /dev/usb which does not exist on my system at the time the rule is activated.

I worked around the issue by making a dedicated .service file with printer.target dependency.

# /etc/systemd/system/load_printer_fw.service 
[Unit]
Description=Load printer firmware
After=printer.target
StartLimitIntervalSec=20
StartLimitBurst=4

[Service]
Type=oneshot
ExecStart=/path/to/load_printer_firmware_systemd.sh

[Install]
WantedBy=printer.target

It calls the same script as udev does. Now systemd handles situations where printer is first started (/dev/usb does not exist yet) and udev works when printer is further recycled (and /dev/usb is already present) while the PC is running. It's bit of a weird solution but at least it seemed to work reliably.

Offline

Board footer

Powered by FluxBB