Note on getting NFC support for BuildRoot #2

Today I managed to debug the libusb-1.0.8-git  and also pcsc-lite-1.7.4 and from the debug log, there is something wrong with libusb_init with error code -99 which is LIBUSB_ERROR_OTHER. As I said before, the error came from the backend of libusb. Giving LIBUSB_DEBUG environment variable, I can see the error log that come from the backend.

# export LIBUSB_DEBUG=3
# /usr/sbin/pcscd --foreground --debug --apdu
00000000 debuglog.c:269:DebugLogSetLevel() debug level=debug
00000664 debuglog.c:298:DebugLogSetCategory() Debug options: APDU
00119338 pcscdaemon.c:552:main() pcsc-lite 1.7.4-svn-5823 daemon ready.
libusb:error [op_init]
libusb:error [op_init] could not find usbfs
usbi_backend->init return value = -99
libusb_init rv = -99
error initialise libusb

And there is the needle in the haystack! libusb could not find usbfs, which means there should be nothing inside /proc/bus/usb on the other words, usbfs is not mounted during bootstrap. So, I only need to mount /proc/bus/usb as usbfs and it works flawlessly.

# mount -t usbfs usbfs /proc/bus/usb

Then restart the pcscd daemon!

# /usr/sbin/pcscd --foreground --debug --apdu
00000000 debuglog.c:269:DebugLogSetLevel() debug level=debug
00000648 debuglog.c:298:DebugLogSetCategory() Debug options: APDU
00198151 pcscdaemon.c:552:main() pcsc-lite 1.7.4-svn-5823 daemon ready.
libusb:error [op_init]
libusb:error [op_init] before support_flag_bulk_continuation()
libusb:error [op_init] before checking bulk continuation support
usbi_backend->init return value = 0
usbi_io_init(ctx) return value = 0
libusb_init rv = 0
00299846 hotplug_libusb.c:510:HPAddHotPluggable() Adding USB device: 1:2:0
00300163 readerfactory.c:934:RFInitializeReader() Attempting startup of ACS ACR122U PICC Interface 00 00 using /usr/lib/pcsc/drivers/ifd-ccid.bundle/Contents/Linux/libccid.so
00303180 readerfactory.c:824:RFBindFunctions() Loading IFD Handler 3.0
00303995 ifdhandler.c:1732:init_driver() Driver version: 1.4.3-svn-5706
00311245 ifdhandler.c:1750:init_driver() LogLevel: 0x0003
00311450 ifdhandler.c:1771:init_driver() DriverOptions: 0x0004
00312736 ifdhandler.c:79:IFDHCreateChannelByName() lun: 0, device: usb:072f/2200:libusb-1.0:1:2:0
00319032 ccid_usb.c:245:OpenUSBByName() ifdManufacturerString: Ludovic Rousseau (ludovic.rousseau@free.fr)
00319183 ccid_usb.c:246:OpenUSBByName() ifdProductString: Generic CCID driver
00319298 ccid_usb.c:247:OpenUSBByName() Copyright: This driver is protected by terms of the GNU Lesser General Public License version 2.1, or (at your option) any later version.
libusb:error [op_init]
libusb:error [op_init] before support_flag_bulk_continuation()
usbi_backend->init return value = 0
usbi_io_init(ctx) return value = 0
00325727 ccid_usb.c:486:OpenUSBByName() Found Vendor/Product: 072F/2200 (ACS ACR122U PICC Interface)
00325839 ccid_usb.c:488:OpenUSBByName() Using USB bus/device: 1/2
00325922 ccid_usb.c:879:ccid_check_firmware() Firmware (2.05) is bogus! but you choosed to use it
00326752 ccid_usb.c:918:get_data_rates() IFD does not support GET_DATA_RATES request: 0
00430676 ifdhandler.c:401:IFDHGetCapabilities() tag: 0xFB3, usb:072f/2200:libusb-1.0:1:2:0 (lun: 0)
00430800 readerfactory.c:295:RFAddReader() Using the reader polling thread
00434930 ifdhandler.c:401:IFDHGetCapabilities() tag: 0xFAE, usb:072f/2200:libusb-1.0:1:2:0 (lun: 0)
00435046 ifdhandler.c:489:IFDHGetCapabilities() Reader supports 1 slot(s)
00435353 readerfactory.c:1301:RFWaitForReaderInit() Waiting init for reader: ACS ACR122U PICC Interface 00 00
00435617 hotplug_libusb.c:417:HPEstablishUSBNotifications() Driver ifd-ccid.bundle does not support IFD_GENERATE_HOTPLUG. Using active polling instead.
00435726 hotplug_libusb.c:426:HPEstablishUSBNotifications() Polling forced every 1 second(s)
00442686 ifdhandler.c:1151:IFDHPowerICC() action: PowerUp, usb:072f/2200:libusb-1.0:1:2:0 (lun: 0)
00446657 readerfactory.c:1301:RFWaitForReaderInit() Waiting init for reader: ACS ACR122U PICC Interface 00 00
00447037 eventhandler.c:256:EHStatusHandlerThread() powerState: POWER_STATE_POWERED
00447250 Card ATR: 3B 8E 80 01 13 78 80 82 02 80 31 80 66 B0 84 0C 01 FF F5
05450505 ifdhandler.c:1151:IFDHPowerICC() action: PowerDown, usb:072f/2200:libusb-1.0:1:2:0 (lun: 0)
05454495 eventhandler.c:446:EHStatusHandlerThread() powerState: POWER_STATE_UNPOWERED
12916344 eventhandler.c:325:EHStatusHandlerThread() Card Removed From ACS ACR122U PICC Interface 00 00
15638373 ifdhandler.c:1151:IFDHPowerICC() action: PowerUp, usb:072f/2200:libusb-1.0:1:2:0 (lun: 0)
15642375 eventhandler.c:372:EHStatusHandlerThread() powerState: POWER_STATE_POWERED
15642485 eventhandler.c:387:EHStatusHandlerThread() Card inserted into ACS ACR122U PICC Interface 00 00
15642632 Card ATR: 3B 8F 80 01 80 4F 0C A0 00 00 03 06 03 00 02 00 00 00 00 69

After days and nights looking for the needle, I found that the root cause is very very trivial, usbfs is not mounted, but why this trivial issue was not identified earlier, instead it got wider suspects which are related to toolchain, pthread, libusb, etc? The answer is really simple, because sometimes, we forget small things.

So, I think that’s all for the crapy notes. Just in case you want to reproduce, following my recipe:

  1.  ARC122U NFC reader from ACS
  2. Linux 2.6.32.6 armv6l (This one came from the hardware vendor)
  3. BuildRoot git 2011.02
  4. libusb-1.0.8
  5. pcsc-lite-1.7.4 (not available yet, just a simple patch for buildroot)
  6. ccid 1.4.3-svn-5706
  7. Allow bogus firmware for ACR122U by editing the usr/lib/pcsc/drivers/ifd-ccid.bundle/Contents/Info.plist
<key>ifdDriverOptions</key>
<string>0x0004</string>

Any tips?

  1. Make sure that usbfs is mounted during bootstrap, can be done by patch udev rules inside /etc/init.d/S10udev

UPDATED: libusb_init() patch is applied, you can check it here:

http://archives.neohapsis.com/archives/dev/muscle/2011-q3/0014.html

http://lists.alioth.debian.org/pipermail/pcsclite-cvs-commit/2011-July/005403.html

Advertisements

One thought on “Note on getting NFC support for BuildRoot #2

  1. RaspberryPi and NFC – stubborn

Leave a Reply

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

WordPress.com Logo

You are commenting using your WordPress.com 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