Porting PN7160 to Android 14 on i.MX8M Nano board

cancel
Showing results for 
Show  only  | Search instead for 
Did you mean: 

Porting PN7160 to Android 14 on i.MX8M Nano board

Porting PN7160 to Android 14 on i.MX8M Nano board

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

8mn.jpg 

OM27160| Development Kits for PN7160 Plug’n Play NFC Controller | NXP Semiconductors

 

7160.jpg

 

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

 
danielchen_23-1738394964705.png

 

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.

 

danielchen_24-1738395033337.png

 

 

 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.

 

danielchen_1-1732538499804.png

 

.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 ..

danielchen_9-1738393932366.png

 

 

.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 ..

danielchen_10-1738393932389.png

 

 

.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 ..

 

danielchen_11-1738393932410.png

 

 

.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 ..

danielchen_12-1738393932434.png

 

 

.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 ..

danielchen_13-1738393932472.png

 

 

.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 ..

danielchen_14-1738393932494.png

 

 

.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 ../..

danielchen_15-1738393932522.png

 

 

.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 ..

danielchen_16-1738393932548.png

 

 

After AOSP adaptation, folder is like below.

danielchen_17-1738393932554.png

 

 

 

 4   Apply AOSP patches

please see AN14430, page10

 danielchen_2-1732538683728.png

# 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

danielchen_4-1732538759932.png

 

 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 ..

danielchen_22-1738394453607.png

 

.5.2Create a folder named pn7160 under android_build/vendor/nxp-opensource/kernel_imx/drivers/nfc

 

danielchen_5-1732538861565.png

 

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:

danielchen_6-1732538987249.png

 

 

.5.3 Modify makefile

Replace Makefile default code with following code,  only add i2c for simplifying.

 

danielchen_7-1732539043196.png

 

 Now we need to add pn7160 Makefile and Kconfig to main Makefile and Kconfig

 

danielchen_8-1732539089136.png

 

Makefile

 

danielchen_9-1732539136098.png

 

Kconfig

 

danielchen_10-1732539167244.png

 

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:

 

danielchen_11-1732539249939.png

 

 

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:

danielchen_12-1732539303166.png

 

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:

 

danielchen_13-1732539339523.png

 

7    Add device specific changes

         The location of the device specific changes in under folder

           . device/nxp/imx8m/evk_8mn

7.1 BoardConfig.mk

 danielchen_14-1732539411816.png

  danielchen_15-1732539466661.png

 danielchen_16-1732539510369.png

 

7.2 ShareBoardConfig.mk

danielchen_17-1732539566160.png

 

danielchen_19-1732539662019.png

 

 7.3 compatibility_matrix.xml

danielchen_20-1732539715434.png

 

 7.4 device_framework_matrix.xml

 

danielchen_21-1732539759365.png

 

 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.

 danielchen_22-1732539833373.png

danielchen_23-1732539859881.png

 

 

7.6 init.rc

 

danielchen_24-1732539894988.png

 

 

7.7manifest.xml

danielchen_25-1732539940498.png

 

 

7.8 ueventd.nxp.rc

       Add permissions for drivers

 danielchen_26-1732540013940.png

 

 8    Additional change in compatibility matrix

Put changes into hardware/interfaces/compatibility_matrices

Compatibility_matrix_8.xml

 

danielchen_27-1732540098909.png

 

 9    add changes into NXP mk files

. android_build/vendor/nxp/nfc/device-nfc.mk

 

danielchen_28-1732540184997.png

 

 

danielchen_29-1732540215144.png

 

 .android_build/vendor/nxp/emvco/device-emvco.mk

 danielchen_30-1732540257962.png

 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

danielchen_31-1732540449014.png

 

This error resulted from the incompatibility of file Kconfig, please use dos2unix command to fix it.

danielchen_32-1732540505205.png

 

 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

 danielchen_34-1732540724837.png

.in uuu_imx_android_flash.bat

 danielchen_35-1732540776703.png

Change switches on i.MX8M Nano

danielchen_36-1732540836787.png

.    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

danielchen_37-1732540883865.png

 

12  Firmware update

 

Download the FW from Github

Open terminal at the FW location

Run the following commands

 

  • • adb push libpn7160_fw.so vendor/lib64/libpn7160_fw.so (for 64-bit version) and adb

                 push libpn7160_fw.so vendor/lib/libpn7160_fw.so (for 32-bit version)

  • • adb shell svc nfc disable
  • • adb shell svc nfc enable

  

danielchen_38-1732540976369.png

 

 

References:

 

PN7160/PN7220 – Android 14 porting guide

UG10156 : Android User’s Guide

 Build Andriod image for PN7160 on i.MX8M Nano:  Andraz


 

Labels (1)
100% helpful (1/1)
Version history
Last update:
‎08-11-2025 05:32 PM
Updated by: