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

danielchen_0-1732538331910.png

 

 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.

danielchen_1-1732538499804.png

 

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

 danielchen_2-1732538683728.png

 

danielchen_4-1732538759932.png

 

 4    Adding the driver support.

Create 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

 

 

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

 

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:

 

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

 

6    Add device specific changes

         The location of the device specific changes in under folder

           . device/nxp/imx8m/evk_8mn

6.1 BoardConfig.mk

 danielchen_14-1732539411816.png

  danielchen_15-1732539466661.png

 danielchen_16-1732539510369.png

 

6.2 ShareBoardConfig.mk

danielchen_17-1732539566160.png

 

danielchen_19-1732539662019.png

 

 6.3 compatibility_matrix.xml

danielchen_20-1732539715434.png

 

 6.4 device_framework_matrix.xml

 

danielchen_21-1732539759365.png

 

 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.

 danielchen_22-1732539833373.png

danielchen_23-1732539859881.png

 

 

6.6 init.rc

 

danielchen_24-1732539894988.png

 

 

6.7manifest.xml

danielchen_25-1732539940498.png

 

 

6.8 ueventd.nxp.rc

       Add permissions for drivers

 danielchen_26-1732540013940.png

 

 7    Additional change in compatibility matrix

Put changes into hardware/interfaces/compatibility_matrices

Compatibility_matrix_8.xml

 

danielchen_27-1732540098909.png

 

 8    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

 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

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 Hardware setup

 

danielchen_33-1732540594010.png

 

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

 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

 

13  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

 

Labels (1)
No ratings
Version history
Last update:
‎11-25-2024 06:32 AM
Updated by: