Using a CanoScan LiDE20 USB scanner under FreeBSD 4.8

I purchased a CanoScan LiDE20 USB scanner in January 2003, and was initially forced to use it under Windows. Then in 3Q 2003 I noticed that the SANE package of open-source support for scanners had evolved to support this type of scanner. My main home machine was running FreeBSD 4.8 at the time. The main complexity was two short kernel usb driver patches to recognize the LiDE20’s vendor and product codes. There were also some problems with gamma settings for the LiDE20 – the community that supports this scanner was still working on identifying an optimal set of configuration codes in 4Q 2003. Nevertheless, my LiDE20 scanner is now connected by USB port to my FreeBSD 4.8 host and I’m scanning photos!


There are three key components to this little saga:

My first step was to install SANE’s “backends” (the user-space libraries to drive a range of different scanners). For simplicity I installed the FreeBSD package version with:

pkg_add -r sane-backends

(This pulled in sane-backends-1.0.11, the latest pre-built package under FreeBSD 4.8 at the time. As it turns out a later version was available through FreeBSD Ports, and was required in order to get good colour calibration from the LiDE20. See below for more details.)

With the scanner plugged into the FreeBSD host I ran sane-find-scanner, which reported the vendor (Canon, 0x04A9) and the model (0x220D).

Unfortunately FreeBSD 4.8’s drivers recognize the vendor but not the model. When the scanner was first plugged into the USB port, the kernel’s generic USB driver attached to it as ugen0:

 ugen0: Canon CanoScan, rev 1.10/1.00, addr 2

The next step was to patch /usr/src/sys/dev/usb/usbdevs and /usr/src/sys/dev/usb/uscanner.c to recognize the new model, and upgrade sane-backends.

Patching the kernel

  • Patch /usr/src/sys/dev/usb/usbdevs with this patch file (Use ‘save link as’ from your browser to copy the patch file, then run “patch < patchfile” from within /usr/src/sys/dev/usb/. If the patch operation fails, try “patch -l < patchfile” instead)
  • *** usbdevs-orig Sun Nov 2 22:27:26 2003
    --- usbdevs Sun Nov 2 22:28:47 2003
    *** 486,491 ****
    --- 486,493 ----
     product CANON N656U 0x2206 CANOSCAN N656U
     product CANON S10 0x3041 PowerShot S10
     product CANON S100 0x3045 PowerShot S100
    + /* Added by gja, Oct 21st 2003 */
    + product CANON N670U 0x220D Canon N670U/N676U/LiDE20
     /* CATC products */
     product CATC NETMATE 0x000a Netmate ethernet adapter
  • Patch /usr/src/sys/dev/usb/uscanner.c with this patch file
  • *** uscanner.c-orig Sun Nov 2 22:30:11 2003
    --- uscanner.c Sun Nov 2 22:31:01 2003
    *** 111,116 ****
    --- 111,117 ----
     /* Canon */
     /* Kye */
  • In /usr/src/sys/dev/usb/ run “make -f Makefile.usbdevs” (rebuilds the files that usb drivers use for header information)
  • Do “cd ../../modules/usb && make” to ensure the new uscanner module compiles okay
  • Rebuild kernel to include new uscanner code
  • cd /sys/i386/conf/
  • config GJA_XPST450 (my kernel config file is GJA_XPST450, yours will differ)
  • cd ../../compile/GJA_XPST450
  • make depend && make && make install
  • Reboot FreeBSD host

With the kernel patched, plugging the scanner into a USB port results in the kernel detecting it as:

uscanner0: Canon CanoScan, rev 1.10/1.00, addr 2

and attaching it to /dev/uscanner0

(Note that model 0x220D applies to three CanoScan models – N670U, N676U and LiDE 20. This patch will enable the use of all three types of scanners under FreeBSD 4.8.)

[Dec 2003 update: I expect (although I have not tried) that the same two patches will work under FreeBSD 4.9, since Canon model 0x220D is similarly unrecognized by the 4.9 kernel.]

Configuring plustek.conf

The SANE plustek drivers provide the necessary support for LiDE20 scanners, so I editted /usr/local/etc/sane.d/plustek.conf to include the lines:

[usb] 0x04A9 0x220D


device /dev/uscanner0

SANE’s “scanimage -L” command now finds the LiDE20 scanner. To test the scanner I installed xsane, an X11-based scanner frontend, using the binary package method

pkg_add -r xsane

Xsane just worked out of the box, and I was quickly scanning images!

Upgrading sane-backends and the Plustek driver

Under sane-backends-1.0.11 the LiDE20 colour calibrations were pretty poor. I found a beta-quality patch for the plustek USB sane-backend (plustek-0.46-TEST1.tar.gz) from the Plustek driver development community. that made a significant difference to my scan quality.

First I used FreeBSD’s “portupgrade” and upgraded sane-backends to version 1.0.12_3 (the latest official FreeBSD port at the time, and one that used plustek backend 0.45).

Building from a port means the source code for sane-backends is sucked over and built locally. After letting portupgrade do its stuff (it can fix/upgrade dependencies along the way) I did these steps:

  • Untar’d plustek-0.46-TEST1.tar.gz into a temporary location
  • Copied ./backend/plustek* files from plustek-0.46-TEST1.tar.gz over the top of /usr/ports/graphics/sane-backends/work/sane-backends-1.0.12/backend
  • Rebuilt/reinstalled the /usr/ports/graphics/sane-backends/ port (“make deinstall && make install”)

(Rebuilding sane-backeneds from the ports collection also means the plustek backend can automatically detect the Lide20 scanner without it being explicitly listed by device/vendor code in plustek.conf)

Adjusted gamma

I found that the following adjustment should be made within XSANE to get somewhat decent scanned photos:

  • “gamma” enhancement of 1.85
  • RGB gamma enhancements at 1.0
  • Bright/contrast enhancements at 0


The CanoScane LiDE20 USB scanner can be made to work reasonably well under FreeBSD 4.8 with two small kernel patches, the sane-backends-1.0.12_2 port and the plustek-0.46-TEST1.tar.gz plustek backend patch.

Historical note: This blog entry was actually made on June 12th 2012, to archive a web page I wrote in October 2003 then updated December 2003. Although largely for my own benefit, I’ve archived it in the hope it will be useful to others (like you, if you’re reading this page and you aren’t me).


Leave a Reply

Fill in your details below or click an icon to log in: Logo

You are commenting using your account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s

%d bloggers like this: