Recently NXP released a combined NCI stack for both PN7160 and Pn7220. The newest Android 14 porting guide AN14430 brings the two (PN7160 and PN7220) together. The pros are it is easy to maintain, and faster integration and switching between products. The cons are when you are using PN7160, you will see for APIs for PN7220, including EMVCo and TDA API. When you are using PN7220 also APIs for PN7160 can be seen (card emulation on PN7160). Some customers maybe have some compile issues. This article is a step-by-step guide on how to build AOSP for PN7160 with the new combined NCI stack.
1 Get AOSP for i.MX Nano
Follow Android porting guide.
https://www.nxp.com/docs/en/user-guide/ANDROID_USERS_GUIDE.pdf
The folder structure after AOSP download.
2 Add AOSP changes.
Now we need to add NFC changes into AOSP. This is the same for all AOSP codebases. (not device specific)
User needs to copy the following folders to specific location.
Those directories we cloned according to AN14430, now we will move the content of them into correct folder in AOSP code.
nfcandroid_platform_reference
. cd nfcandroid_platform_reference
. cp -rf vendor/nxp/* ../android_build/vendor/nxp/
.nxp_nci_hal_libnfc-nci
. cd nxp_nci_hal_libnfc-nci
. cp -rf * ../android_build/system/nfc/
.nxp_nci_hal_nfc
. cd nxp_nci_hal_nfc
. cp -rf * ../android_build/packages/apps/Nfc/
.nfcandroid_frameworks
. cd nfcandroid_frameworks
. mkdir ../android_build/vendor/nxp/frameworks
. cp -rf * ../android_build/vendor/nxp/frameworks
.nfcandroid_emvco_aidlimpl
. cd nfcandroid_frameworks
. mkdir ../android_build/hardware/nxp/emvco
. cp -rf * ../android_build/hardware/nxp/emvco
.nfcandroid_nfc_hidlimpl
. cd nfcandroid_nfc_hidlimpl
. cp -rf * ../android_build/hardware/nxp/nfc
.nfcandroid_infra_comm_libs
. cd nfcandroid_infra_comm_libs
. cp -rf nfc_tda/ ${MY_ANDROID}/system
. cp -rf emvco_tda/emvco_tda_test/ ${MY_ANDROID}/hardware/nxp/emvco/
3 Apply AOSP patches
please see AN14430, page10
4 Adding the driver support.
Create a folder named pn7160 under android_build/vendor/nxp-opensource/kernel_imx/drivers/nfc
Copy below kernel drivers file from “nfcandroid_platform_drivers/drivers/pn7160/nfc/nfc “ into “android_build/vendor/nxp-opensource/kernel_imx/drivers/nfc/pn7160/”
Common.c common.h i2c_drv.c i2c_drv.h spi_drv.h spi_drv.c Makefile Kconfig
Result of copying:
Modify makefile
Replace Makefile default code with following code, only add i2c for simplifying.
Now we need to add pn7160 Makefile and Kconfig to main Makefile and Kconfig
Makefile
Kconfig
5 Adding device tree
Device tree is important since we need to tell our controller which pins we want to use for communication (this is always different between host controllers)
The device tree need to be added into:
“vendor/nxp-opensource/kernel_imx/arch/arm64/boot/dts/freescale”
Create file with name “imx8mn-evk-pn7160.dts”, open the file and add following lines:
Next task is to add .dts file into Makefile in the following location:
. vendor/nxp-opensource/kernel_imx/arch/arm64/boot/dts/freescale
Open Makefile and add:
Final step is to add NXP_NCI_I2C as module in following file:
. vendor/nxp-opensource/kernel_imx/arch/arm64/configs/imx8mn_gki.fragment
Open imx8mn_gki.fragment and add:
6 Add device specific changes
The location of the device specific changes in under folder
. device/nxp/imx8m/evk_8mn
6.1 BoardConfig.mk
6.2 ShareBoardConfig.mk
6.3 compatibility_matrix.xml
6.4 device_framework_matrix.xml
6.5 evk_8mn.mk
Add .mk files to specific device.mk and some product package directly to device.mk file so everything is build together with Android.
6.6 init.rc
6.7manifest.xml
6.8 ueventd.nxp.rc
Add permissions for drivers
7 Additional change in compatibility matrix
Put changes into hardware/interfaces/compatibility_matrices
Compatibility_matrix_8.xml
8 add changes into NXP mk files
. android_build/vendor/nxp/nfc/device-nfc.mk
.android_build/vendor/nxp/emvco/device-emvco.mk
9 Build Android
This can be different for specific device hosts
.source build/envsetup.sh
.lunch evk_8mn-userdebug
. ./imx-make.sh bootloader kernel -j //This will build driver inside kernel etc.
. make -j //Build AOSP code
10 Possible build failures
This error resulted from the incompatibility of file Kconfig, please use dos2unix command to fix it.
For some other redefine issues, please do the following.
Go into file hardware/nxp/nfc/snxx/
Name Android.bp to _Android.bp
Go into hardware/nxp/nfc/snxx/halimpl/power-tracker/
Name Android.bp to _Android.bp
Go into file hardware/nxp/secure_element/snxxx/aidl/
Name Android.bp to _Android.bp
Remove : pn8xx from hardware/nxp/
Remove : frameworks/base/core/res/res/values/config.xml.orig
11 Hardware setup
12 Download build and flash images
Go into “android_build/out/target/product/evk_8mn” and download all files without folders .
When downloaded, open following two files and add:
.in fastboot_imx_flashall.bat
.in uuu_imx_android_flash.bat
Change switches on i.MX8M Nano
. Flashing Android: when flashing Android images
. Running Android: when images are flashed, put switches to Running Android and Android OS will start.
Flash images
. Put i.MX8 to “Flash Android”
. Open a PowerShell as admin in the location where download images are
. Running following command
. ./uuu_imx_android_flash.bat -f imx8mn -a -d pn7160
13 Firmware update
Download the FW from Github
Open terminal at the FW location
Run the following commands
push libpn7160_fw.so vendor/lib/libpn7160_fw.so (for 32-bit version)
References:
PN7160/PN7220 – Android 14 porting guide