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). This article is a step-by-step guide on how to build AOSP for PN7160 with the new combined NCI stack.
1 Hardware setup
i.MX 8M Nano Evaluation Kit | NXP Semiconductors
OM27160| Development Kits for PN7160 Plug’n Play NFC Controller | NXP Semiconductors
The connection between i.MX8M Nano and PN7160 OM29110ARD-B
i.MX8M Nano EVK |
pin |
PN7160 |
OM29110ARD-B |
3.3V |
J1003-1 |
VDD(3.3v) |
J1-4 |
5V |
J1003-2 |
VBAT (5v) |
J1-5 |
SDA.1 |
J1003-3 |
SDA |
J2-2 |
SCL.1 |
J1003-5 |
SCL |
J2-1 |
GPIO.25 |
J1003-37 |
IRQ |
J2-10 |
GPIO.28 |
J1003-38 |
REQ |
J4-2 |
GND |
J1003-39 |
GND |
J1-6 |
GPIO.29 |
J1003-40 |
VEN |
J4-1 |
2 Get AOSP for i.MX Nano
Follow Android porting guide.
https://www.nxp.com/docs/en/user-guide/ANDROID_USERS_GUIDE.pdf
.2.1 Download i.MX Android BSP (Android14.0.0_1.2.0) from below link.
Android OS for i.MX Applications Processors | NXP Semiconductors
You will get the package imx-android-14.0.0_1.2.0.tar.gz
.2.2 Decompressing android BSP
# tar -xvzf imx-android-1c4.0.0_1.2.0.tar.gz
When decompression is done, imx-android-14.0.0_1.2.0 subdirectory is created, in the folder, we can find imx_android_setup.sh, which is script for downloading android source code and commands for patching i.MX android bsp to AOSP.
.2.3 Downloading Android source code
# source ./imx-android-14.0.0_1.2.0/imx_android_setup.sh
The folder structure after AOSP downloading complete.
3 AOSP Adaptation
NXP adds modifications to the AOSP code. Next, we add them step by step according to AN14430, move the content of them into correct folder in AOSP code base.
.3.1 nxp_nci_hal_nfc
#git clone "https://github.com/nxp-nfc-infra/nxp_nci_hal_nfc.git"
#cd nxp_nci_hal_nfc
#git checkout br_ar_14_comm_infra_dev
#cp -rf * ../android_build/packages/apps/Nfc/
#cd ..
.3.2 nxp_nci_hal_libnfc-nci
#git clone "https://github.com/nxp-nfc-infra/nxp_nci_hal_libnfc-nci.git"
#cd nxp_nci_hal_libnfc-nci
#git checkout br_ar_14_comm_infra_dev
#cp -rf * ../android_build/system/nfc/
#cd ..
.3.3 nfcandroid_nfc_hidlimpl
#git clone "https://github.com/nxp-nfc-infra/nfcandroid_nfc_hidlimpl.git"
#cd nfcandroid_nfc_hidlimpl
#git checkout br_ar_14_comm_infra_dev
#cp -rf * ../android_build/hardware/nxp/nfc
#cd ..
.3.4 nfcandroid_frameworks
#git clone "https://github.com/nxp-nfc-infra/nfcandroid_frameworks.git"
#cd nfcandroid_frameworks
#git checkout br_ar_14_comm_infra_dev
#mkdir ../android_build/vendor/nxp/frameworks
#cp -rf * ../android_build/vendor/nxp/frameworks
#cd ..
.3.5 nfcandroid_emvco_aidlimpl
#git clone "https://github.com/nxp-nfc-infra/nfcandroid_emvco_aidlimpl.git"
#cd nfcandroid_emvco_aidlimpl
#git checkout br_ar_14_comm_infra_dev
#mkdir ../android_build/hardware/nxp/emvco
#cp -rf * ../android_build/hardware/nxp/emvco
#cd ..
.3.6 nfcandroid_platform_reference
#git clone "https://github.com/nxp-nfc-infra/nfcandroid_platform_reference.git"
#cd nfcandroid_platform_reference
#git checkout br_ar_14_comm_infra_dev
#cp -rf vendor/nxp/* ../android_build/vendor/nxp/
#cd ..
.3.7 nfcandroid_infra_test_apps
# git clone https://github.com/nxp-nfc-infra/nfcandroid_infra_test_apps.git
# cd nfcandroid_infra_test_apps/
# git checkout br_ar_14_comm_infra_dev
# cd test_apps/
# cp -rf SMCU_Switch/ ../../android_build/packages/apps/
# cp -rf EMVCoModeSwitchApp/ ../../android_build/packages/apps/Nfc/
# cd ../..
.3.8 nfcandroid_infra_comm_libs
#git clone "https://github.com/nxp-nfc-infra/nfcandroid_infra_comm_libs.git"
#cd nfcandroid_infra_comm_libs
#git checkout br_ar_14_comm_infra_dev
#cp -rf nfc_tda/ ../android_build/system/
#cp -rf emvco_tda/ emvco_tda_test/ ../android_build/hardware/nxp/emvco/
#cp -rf NfcTdaTestApp/ ../android_build/packages/apps/Nfc/
#cd ..
After AOSP adaptation, folder is like below.
4 Apply AOSP patches
please see AN14430, page10
# patch -p1 < ../../../nfcandroid_platform_reference/build_cfg/build_pf_patches/AROOT_build_bazel.patch
#patch -p1 < ../../../nfcandroid_platform_reference/build_cfg/build_pf_patches/AROOT_build_make.patch
# patch -p1 < ../../../nfcandroid_platform_reference/build_cfg/build_pf_patches/AROOT_build_soong.patch
# patch -p1 < ../../../nfcandroid_platform_reference/build_cfg/build_pf_patches/AROOT_frameworks_base.patch
#patch -p1 < ../../../nfcandroid_platform_reference/build_cfg/build_pf_patches/AROOT_frameworks_native.patch
#patch -p1 < ../../../nfcandroid_platform_reference/build_cfg/build_pf_patches/AROOT_frameworks_proto_logging.patch
#patch -p1 < ../../../nfcandroid_platform_reference/build_cfg/build_pf_patches/AROOT_system_logging.patch
#patch -p1 < ../../../../nfcandroid_platform_reference/build_cfg/build_pf_patches/AROOT_packages_modules_Bluetooth.patch
5 Adding the driver support.
.5.1 get nfcandroid_platform_drivers from github
#git clone "https://github.com/nxp-nfc-infra/nfcandroid_platform_drivers.git"
#cd nfcandroid_platform_drivers
#git checkout br_ar_14_comm_infra_dev
#cd ..
.5.2Create 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:
.5.3 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
6 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:
7 Add device specific changes
The location of the device specific changes in under folder
. device/nxp/imx8m/evk_8mn
7.1 BoardConfig.mk
7.2 ShareBoardConfig.mk
7.3 compatibility_matrix.xml
7.4 device_framework_matrix.xml
7.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.
7.6 init.rc
7.7manifest.xml
7.8 ueventd.nxp.rc
Add permissions for drivers
8 Additional change in compatibility matrix
Put changes into hardware/interfaces/compatibility_matrices
Compatibility_matrix_8.xml
9 add changes into NXP mk files
. android_build/vendor/nxp/nfc/device-nfc.mk
.android_build/vendor/nxp/emvco/device-emvco.mk
10 Build Android
First , the source build/envsetup.sh command is executed to import shell functions that are defined in ${MY_ANDROID}/build/envsetup.sh.
Then, the lunch evk_8mn-userdebug command is executed to set up the build configuration.
#source build/envsetup.sh
#lunch evk_8mn-userdebug
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 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
12 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
UG10156 : Android User’s Guide
Build Andriod image for PN7160 on i.MX8M Nano: Andraz