6

This question can be decomposed into multiple smaller problems. The end result would be to be able to set a breakpoint in the C/C++ NFC implementation of a Galaxy Nexus (Android 4.1) device using a debugger such as gdb to examine it's internal state.

  1. Is it possible to replace the libraries on a Galaxy Nexus devices with ones that contain debugging symbols?
  2. Is it possible to use gdb to debug the C/C++ implementation of an Android device?
  3. Is it possible to cross-compile the NFC implementation of Android?
  4. Are there any examples of somebody trying something similar maybe with another library?

Update: Rooting the device and compiling Jellybean went well overall with some minor errors. In fact there are some very nice flags in the libnfc makefile which enable extensive output while communicating.

However there there is still a debugging problem. To debug libnfc (external/libnfc-nxp) i must attach myself to the process using the library which most likely is the Nfc Manager (packages/apps/Nfc). To debug an application i have to set the debuggable flag. If i rebuild the Nfc Manager the signature does not match the one already installed on the device which means adb install -r <file> won't work. adb uninstall com.android.nfc doesn't work either. Using the hard way of simply deleting the apk from /system/app creates the error INSTALL_FAILED_SHARED_USER_INCOMPATIBLE when i try to install the new one. At this point Nfc didn't work at all anymore and i had to reflash the stock image.

Any other ideas how to debug the libnfc library?

mibollma
  • 14,959
  • 6
  • 52
  • 69
  • If you built a complete Jelly Bean image already, why not flash that onto the device, using `adb reboot bootloader; fastboot flashall`? Than you have full control over the device. – NFC guy Sep 01 '12 at 10:40
  • Yes that would be an option. Although if there is a less intrusive way leaving most of the device as it is delivered to the end-user i would prefer that one. After all i just want to monitor closely not modify. – mibollma Sep 01 '12 at 10:49
  • You can find the exact source code tags at http://source.android.com/source/build-numbers.html. If you check out the proper one (check for the right tag in "Settings" -> "About phone" on your phone), you can recreate the exact same image as is currently on your phone. – NFC guy Sep 01 '12 at 11:55
  • That it correct in "theory". The first thing that makes me suspicious is the sentence in the xda post saying "This will NOT make a fully functional ROM". Also experience tells me that in a big project like that there might be quite some differences which starts with the proprietary google applications not being part of AOP and ends with i don't know what. So i'm still looking for a solution that does not involve replacing 100% because of an interest in 1%. – mibollma Sep 01 '12 at 22:29
  • To be frank, I don't see your problem. Building an AOSP image will normally result in a fully functional ROM. I worked on the team that did the integration of NFC in Android and the implementation of the NFC API and that is the way we did it. If you really need the Google apps, you can download a zip file containing them from [CyanogenMod](http://wiki.cyanogenmod.com/wiki/Latest_Version/Google_Apps). – NFC guy Sep 01 '12 at 22:38
  • Even though i won't try it i guess there is no other way to do it. By now i got all my questions answered using a different controller (PN533) compared to the one built into the phone (PN544) so i don't need that debugging functionality anymore. Thanks anyway :). – mibollma Sep 08 '12 at 06:55
  • Great to hear that you managed to find out what you wanted to know. – NFC guy Sep 08 '12 at 19:24

1 Answers1

10

In general, the answer is yes. The complete Android NFC implementation is part of the Android Open Source Project. Answers to the specific parts of your question:

  1. Yes, you need to unlock the bootloader and root your device to be able to mount the system partition in read/write mode, so you can replace the NFC library.
  2. Yes, you should be able to do remote debugging using gdb. I have never actually done this, though.
  3. Yes, just download the Android source and compile the relevant parts of the NFC stack. The relevant parts are in packages/apps/Nfc (NFC manager), external/libnfc-nxp (C library), frameworks/base/core/java/android/nfc (Java NFC API) and vendor/nxp (NFC chip firmware).
  4. Yes, see e.g. How to debug an App on Android with GDBSERVER? or https://www.google.com/search?q=remote+gdb+android. (This question may be relevant, too: Remote debugging with Android emulator)
Community
  • 1
  • 1
NFC guy
  • 10,151
  • 3
  • 27
  • 58