移植NFC到android

OS:android7.1


代码移植

一.驱动部分
    1.dts:

&i2c4 {
        status = "okay";
        
        nfc: nfc@28 {
            compatible = "firefly,pn544"; 
            reg = <0x28>;
            ven-gpio = <&gpio5 18 GPIO_ACTIVE_HIGH>;
            irq-gpio = <&gpio8 1 IRQ_TYPE_LEVEL_HIGH>;
            rst-gpio = <&gpio8 2 GPIO_ACTIVE_HIGH>;
        };
    };

    2.驱动代码,直接用之前5.1时候调的,代码路径如下:kernel/drivers/nfc/pn544/pn544.c、pn544.h
        
    3.驱动 移植完后,在 dev 目录下会生成一个 pn544 的节点:
        crw-rw---- 1 nfc       nfc           10,  58 2020-03-20 19:12 pn544


二.上层的移植
请在驱动的通的情况下移植上层代码

1.    external\libnfc-nci 直接替换对应目录的
2.    packages\apps\Nfc 直接替换对应目录的
3.    frameworks\base\nxp-nfc-gsma 放到frameworks\base\ 目录下
4.    frameworks\base\core\java\android\nfc直接替换对应目录的
5   frameworks\base\core\java\com\nxp 直接放到frameworks\base\core\java\com\
6   frameworks\base\core\java\com\vzw直接放到frameworks\base\core\java\com\
7.  hardware\libhardware\include\hardware\nfc.h 与对应目录下的 nfc.h 对比将差异部分合入
8.  frameworks\base\Android.mk 与原来的对比 将 NFC 相关的合入,如下,请检查

  core/java/android/nfc/IAppCallback.aidl \
    core/java/com/nxp/nfc/gsma/internal/INxpNfcController.aidl \
    core/java/com/nxp/nfc/INxpNfcAdapter.aidl \
    core/java/com/nxp/nfc/INxpNfcAdapterExtras.aidl \
    core/java/com/nxp/nfc/INfcVzw.aidl \
    core/java/android/nfc/INfcAdapter.aidl \
    core/java/android/nfc/INfcAdapterExtras.aidl \
    core/java/android/nfc/INfcTag.aidl \
    core/java/android/nfc/INfcCardEmulation.aidl \
    core/java/android/nfc/INfcFCardEmulation.aidl \
    core/java/com/nxp/nfc/INfcDta.aidl \
    core/java/com/nxp/nfc/INxpNfcAccessExtras.aidl \
    core/java/android/nfc/INfcUnlockHandler.aidl \
    core/java/android/nfc/ITagRemovedCallback.aidl \
    frameworks/base/core/java/android/nfc/Tag.aidl \
    frameworks/base/core/java/android/nfc/NdefRecord.aidl \
    frameworks/base/core/java/android/nfc/NdefMessage.aidl \
    
    packages_to_document := \
    android \
    com/nxp/nfc \
    com/nxp/intf \
    com/nxp/nfc/gsma/internal \  // 这里有三项
    javax/microedition/khronos \
    org/apache/http/conn \
    org/apache/http/params

9.device\rockchip\common\device.mk添加如下编译规则:

 #NFC MODULE        wmc add for nfc
    # NFC packages
    PRODUCT_PACKAGES += \
        NfcNci \
        libnfc-nci \
        libnfc_nci_jni \
        nfc_nci.pn54x.default \
        com.gsma.services.nfc \
        com.android.nfc_extras
    PRODUCT_COPY_FILES += \
        frameworks/native/data/etc/com.nxp.mifare.xml:system/etc/permissions/com.nxp.mifare.xml \
        frameworks/native/data/etc/android.hardware.nfc.xml:system/etc/permissions/android.hardware.nfc.xml \
        frameworks/native/data/etc/com.android.nfc_extras.xml:system/etc/permissions/com.android.nfc_extras.xml \
        frameworks/native/data/etc/android.hardware.nfc.hce.xml:system/etc/permissions/android.hardware.nfc.hce.xml    \
        frameworks/native/data/etc/android.hardware.nfc.hcef.xml:system/etc/permissions/android.hardware.nfc.hcef.xml
        
    PRODUCT_COPY_FILES += \
            external/libnfc-nci/halimpl/pn54x/libpn548ad_fw.so:vendor/lib/libpn548ad_fw.so \(注意这个路径,接下面12点详述)
            external/libnfc-nci/halimpl/pn54x/libnfc-nxp.conf:system/etc/libnfc-nxp.conf \
            external/libnfc-nci/halimpl/pn54x/libnfc-brcm.conf:system/etc/libnfc-brcm.conf   

10.system/core/rootdir/init.rc中添加如下:

    on post-fs-data
    #NFC    wmc add for nfc
    mkdir /data/nfc 0770 nfc nfc
    mkdir /etc/param
    
    on boot
    #NFC
    setprop ro.nfc.port "I2C"
    chmod 0660 /dev/pn544
    chown nfc nfc /dev/pn544

 

11.libpn548ad_fw_1A_32bit.so 改名成 libpn548ad_fw.so 和 libnfc-nxp.conf、libnfc-brcm.conf
    放到 external\libnfc-nci\halimpl\pn54x 目录下。
    
12.厂家提供的文档和以往的5.1系统移植,都是把libpn548ad_fw.so拷贝到system/vendor/firmware路径下,但是现在7.1的sdk,
    并没有对应的这个目录。解决办法是修改源码,修改对应的路径让它可以找到libpn548ad_fw.so就可以了。现定把
    libpn548ad_fw.so拷贝到vendor/lib下面,对应的源码修改如下:

  1.external\libnfc-nci\halimpl\pn54x\common\phNfcCommon.h
        -//#define FW_DLL_ROOT_DIR "/system/vendor/firmware/"
        +#define FW_DLL_ROOT_DIR "/vendor/lib/"
    2.external\libnfc-nci\halimpl\pn54x\dnld\phDnldNfc.c
        把所有的pathName = "/system/vendor/firmware/libpn548ad_fw.so"(有两处)
        改为:pathName = "/vendor/lib/libpn548ad_fw.so";


13.编译的时候发现,报错一大堆,无法识别一些添加的包名,解决方法如下:
    build\core\tasks\check_boot_jars\package_whitelist.txt下添加:

    com\.vzw\.nfc\.dos
    com\.vzw\.nfc
    com\.nxp\.nfc
    com\.nxp\.nfc\.gsma\.internal
    com\.nxp\.intf

    这样就可以顺利编译过了。

注:移植完后,请务必 make clean后,再全编



posted @ 2020-06-03 18:52  M-kobe  阅读(1435)  评论(0编辑  收藏  举报