{"id":36,"date":"2009-07-22T21:21:24","date_gmt":"2009-07-22T10:21:24","guid":{"rendered":"http:\/\/menhennitt.com.au\/wordpress\/?p=36"},"modified":"2011-06-22T22:52:47","modified_gmt":"2011-06-22T11:52:47","slug":"printing-to-an-hp-laserjet-1020-from-freebsd-using-cups-and-foo2zjs","status":"publish","type":"post","link":"https:\/\/menhennitt.com.au\/wordpress\/2009\/07\/22\/printing-to-an-hp-laserjet-1020-from-freebsd-using-cups-and-foo2zjs","title":{"rendered":"Printing to an HP Laserjet 1020 from FreeBSD using CUPS and foo2zjs"},"content":{"rendered":"<p>I&#8217;m setting up my <a href=\"http:\/\/menhennitt.com.au\/wordpress\/2009\/07\/05\/installing-freebsd-on-a-soekris-net5501-using-pxe-and-dnsmasq\">Soekris box<\/a> as a printer server. The printer is a Hewlett Packard Laserjet 1020. I&#8217;m running <a href=\"http:\/\/freebsd.org\">FreeBSD<\/a> 7-Stable as the operating system and I want to use <a href=\"http:\/\/cups.org\/\">CUPS<\/a> as the print manager.<\/p>\n<p>There are a few guides around that show parts of how to do this, but I didn&#8217;t find one that had it all in one place. Hence this post.<\/p>\n<p><!--more--><\/p>\n<h2>Custom Kernel<\/h2>\n<p>Firstly, you need to build a custom kernel. I&#8217;m building one anyway, since it&#8217;s customised for the Soekris box. The important thing is that it does <strong>not<\/strong> have &#8220;device ulpt&#8221; in it. If you have that, the printer gets recognised as \/dev\/ulpt0 which doesn&#8217;t work. Instead we have &#8220;device ugen&#8221; and it gets recognised as \/dev\/ugen0 which works correctly. There may be a better way of doing this, but I don&#8217;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 &#8220;dmesg&#8221;.<\/p>\n<h2>Build and install ports<\/h2>\n<p>Then install the CUPS and foo2zjs ports using the standard &#8220;make install&#8221;. 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: &#8220;getweb&#8221; and &#8220;make install-hotplug&#8221;. Skip the hotplug bit as that doesn&#8217;t seem to work on FreeBSD. The printer needs to have firmware downloaded to it and that&#8217;s what the hotplug business is for. On FreeBSD, we do that in a different way that we&#8217;ll see below.<\/p>\n<h2>Set device permissions<\/h2>\n<p>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&#8217;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&#8217;s &#8220;cups&#8221;. 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:<\/p>\n<p style=\"padding-left: 30px;\"><code>[printers=10]<br \/>\nadd path 'ugen0.1' mode 0660 group cups<\/code><\/p>\n<p>Substitute your correct device name in there. Now, that entry needs to be activated by adding a line:\n<\/p>\n<p style=\"padding-left: 30px;\"><code>devfs_system_ruleset=\"printers\"<\/code><\/p>\n<p>to \/etc\/rc.conf. You then need to restart the devfs daemon.<\/p>\n<h2>Install firmware<\/h2>\n<p>You do need to download the firmware: cd to the foo2zjs port&#8217;s work\/foo2zjs* directory and do &#8220;.\/getweb 1020&#8221;. If you have a different but similar printer, there are lots of things that you can &#8220;getweb&#8221; &#8211; they&#8217;ll probably work the same as the 1020. Anyway, the &#8220;getweb&#8221; command downloads a file: sihp1020.img. Then run &#8220;arm2hpdl &lt; sihp1020.img &gt; sihp1020.dl&#8221;. 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&#8217;s as simple as:<\/p>\n<p style=\"padding-left: 30px;\"><code>cat \/usr\/local\/share\/foo2zjs\/firmware\/sihp1020.dl &gt; \/dev\/ugen0.1<\/code><\/p>\n<p>During the download, the LEDs on the printer should flash. At the end, the printer will make a few noises. It&#8217;s then ready to print.<\/p>\n<p>The firmware needs to be downloaded every time the printer is powered on. To automate this, add a section to \/etc\/devd.conf:<\/p>\n<p style=\"padding-left: 30px;\"><code># Firmware download HP Laserjet 1020 printer<br \/>\nattach 100 {<br \/>\ndevice-name \"ugen[0-9]+\";<br \/>\nmatch \"vendor\"\u00a0 \"0x03f0\";<br \/>\nmatch \"product\" \"0x2b17\";<br \/>\naction \"cat \/usr\/local\/share\/foo2zjs\/firmware\/sihp1020.dl &gt; \/dev\/$device-name.1\";<br \/>\n};<\/code><\/p>\n<p>This tells it to execute the download command whenever a device is attached that matches the correct USB vendor and device identifiers. Note the &#8220;.1&#8221; at the end of the command so that the correct device name is used. I&#8217;m sure that there&#8217;s a better way of doing this, but I can&#8217;t find it.<\/p>\n<h2>Configure CUPS to use the printer<\/h2>\n<p>Finally, add the printer in CUPS. When it asks for the device URI, enter &#8220;usb:\/dev\/ugen0.1&#8221;. Then try printing a test page. If it&#8217;s all worked, you should hear the printer fire up and see your page printed!<\/p>\n<p>&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;-<br \/>\nUpdate: I&#8217;ve updated this for FreeBSD 8 <a href=\"http:\/\/menhennitt.com.au\/wordpress\/2009\/09\/27\/printing-to-an-hp-laserjet-1020-from-freebsd-8-using-cups-and-foo2zjs\">here<\/a>.<\/p>\n","protected":false},"excerpt":{"rendered":"<p>I&#8217;m setting up my Soekris box as a printer server. The printer is a Hewlett Packard Laserjet 1020. I&#8217;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&#8217;t find one [&hellip;]<\/p>\n","protected":false},"author":2,"featured_media":0,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[3],"tags":[15,17,7,16,14],"class_list":["post-36","post","type-post","status-publish","format-standard","hentry","category-computing","tag-cups","tag-foo2zjs","tag-freebsd","tag-laserjet-1020","tag-print"],"_links":{"self":[{"href":"https:\/\/menhennitt.com.au\/wordpress\/wp-json\/wp\/v2\/posts\/36","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/menhennitt.com.au\/wordpress\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/menhennitt.com.au\/wordpress\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/menhennitt.com.au\/wordpress\/wp-json\/wp\/v2\/users\/2"}],"replies":[{"embeddable":true,"href":"https:\/\/menhennitt.com.au\/wordpress\/wp-json\/wp\/v2\/comments?post=36"}],"version-history":[{"count":34,"href":"https:\/\/menhennitt.com.au\/wordpress\/wp-json\/wp\/v2\/posts\/36\/revisions"}],"predecessor-version":[{"id":96,"href":"https:\/\/menhennitt.com.au\/wordpress\/wp-json\/wp\/v2\/posts\/36\/revisions\/96"}],"wp:attachment":[{"href":"https:\/\/menhennitt.com.au\/wordpress\/wp-json\/wp\/v2\/media?parent=36"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/menhennitt.com.au\/wordpress\/wp-json\/wp\/v2\/categories?post=36"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/menhennitt.com.au\/wordpress\/wp-json\/wp\/v2\/tags?post=36"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}