Printing to an HP Laserjet 1020 from FreeBSD using CUPS and foo2zjs


I’m setting up my Soekris box as a printer server. The printer is a Hewlett Packard Laserjet 1020. I’m running FreeBSD 7-Stable as the operating system and I want to use CUPS as the print manager.

There are a few guides around that show parts of how to do this, but I didn’t find one that had it all in one place. Hence this post.

Custom Kernel

Firstly, you need to build a custom kernel. I’m building one anyway, since it’s customised for the Soekris box. The important thing is that it does not have “device ulpt” in it. If you have that, the printer gets recognised as /dev/ulpt0 which doesn’t work. Instead we have “device ugen” and it gets recognised as /dev/ugen0 which works correctly. There may be a better way of doing this, but I don’t know. So build, install, and reboot the new kernel. You should see the printer mentioned in the boot messages and in the output of “dmesg”.

Build and install ports

Then install the CUPS and foo2zjs ports using the standard “make install”. Make sure you select the LIBUSB option in the cups-base port to be able to print to USB printers. The foo2zjs one tells you to do some extra stuff: “getweb” and “make install-hotplug”. Skip the hotplug bit as that doesn’t seem to work on FreeBSD. The printer needs to have firmware downloaded to it and that’s what the hotplug business is for. On FreeBSD, we do that in a different way that we’ll see below.

Set device permissions

When the printer is plugged in or switched on, two devices will be created: /dev/ugenX and /dev/ugenX.1 where X is an integer. In my case X is 0. It’s the latter of these two that we need to use: in my case /dev/ugen0.1. These devices need to be owned by the same owner as the CUPS program. By defaults that’s “cups”. To set the ownership, edit /etc/devfs.rules. This file may not already exist, in which case you can create a new one. It should contain:

[printers=10]
add path 'ugen0.1' mode 0660 group cups

Substitute your correct device name in there. Now, that entry needs to be activated by adding a line:

devfs_system_ruleset="printers"

to /etc/rc.conf. You then need to restart the devfs daemon.

Install firmware

You do need to download the firmware: cd to the foo2zjs port’s work/foo2zjs* directory and do “./getweb 1020”. If you have a different but similar printer, there are lots of things that you can “getweb” – they’ll probably work the same as the 1020. Anyway, the “getweb” command downloads a file: sihp1020.img. Then run “arm2hpdl < sihp1020.img > sihp1020.dl”. This converts the firmware image into a file suitable for downloading to the printer. The output file sihp1020.dl needs to be be put somewhere it can be downloaded from: I put it in /usr/local/share/foo2zjs/firmware. To download it to the printer, it’s as simple as:

cat /usr/local/share/foo2zjs/firmware/sihp1020.dl > /dev/ugen0.1

During the download, the LEDs on the printer should flash. At the end, the printer will make a few noises. It’s then ready to print.

The firmware needs to be downloaded every time the printer is powered on. To automate this, add a section to /etc/devd.conf:

# Firmware download HP Laserjet 1020 printer
attach 100 {
device-name "ugen[0-9]+";
match "vendor"  "0x03f0";
match "product" "0x2b17";
action "cat /usr/local/share/foo2zjs/firmware/sihp1020.dl > /dev/$device-name.1";
};

This tells it to execute the download command whenever a device is attached that matches the correct USB vendor and device identifiers. Note the “.1” at the end of the command so that the correct device name is used. I’m sure that there’s a better way of doing this, but I can’t find it.

Configure CUPS to use the printer

Finally, add the printer in CUPS. When it asks for the device URI, enter “usb:/dev/ugen0.1”. Then try printing a test page. If it’s all worked, you should hear the printer fire up and see your page printed!

—————————-
Update: I’ve updated this for FreeBSD 8 here.

, , , ,

  1. No comments yet.

You must be logged in to post a comment.