MAN_NFC_1204-313 Open NFC - Android ICS 4.0.3 - Quick Porting Guide v0.1
-
Upload
igede-tirta-nata -
Category
Documents
-
view
115 -
download
2
Transcript of MAN_NFC_1204-313 Open NFC - Android ICS 4.0.3 - Quick Porting Guide v0.1
Check document version before use. Copyright © 2012 Inside Secure
Open NFC - Android ICS 4.0.3 - Quick Porting Guide
Document Type: Manual
Reference: MAN_NFC_1204-313 Version 0.1 (13736)
Release Date: April 2, 2012
File Name: MAN_NFC_1204-313 Open NFC - Android ICS 4.0.3 - Quick Porting Guide v0.1.pdf
Security Level: General Business Use
Open NFC - Android ICS 4.0.3 - Quick Porting Guide General Business Use
Page : 2/16
Date : April 2, 2012
Ref. : MAN_NFC_1204-313 v0.1(13736)
Check document version before use. Copyright © 2012 Inside Secure
Disclaimer This document is licensed under the Creative Commons Attribution 3.0 license (http://creativecommons.org/licenses/by/3.0/). (You may use the content of this document in any way that is consistent with this license and if you give proper attribution (http://www.open-nfc.org/license.html#attribution). Copyright © 2012 Inside Secure Open NFC and the Open NFC logo are trademarks or registered trademarks of Inside Secure. Other brand, product and company names mentioned herein may be trademarks, registered trademarks or trade names of their respective owners.
Open NFC - Android ICS 4.0.3 - Quick Porting Guide General Business Use
Page : 3/16
Date : April 2, 2012
Ref. : MAN_NFC_1204-313 v0.1(13736)
Check document version before use. Copyright © 2012 Inside Secure
History
Version Date Comments
0.1 April 2, 2012 First Release
Open NFC - Android ICS 4.0.3 - Quick Porting Guide General Business Use
Page : 4/16
Date : April 2, 2012
Ref. : MAN_NFC_1204-313 v0.1(13736)
Check document version before use. Copyright © 2012 Inside Secure
Summary of Contents
1 Introduction ........................................................................................................ 5
2 Building Instructions ......................................................................................... 6
2.1 Create bin/ directory and include it in path ........................................................... 6
2.2 Download the Repo script and ensure it is executable ........................................ 6
2.3 Make a New working directory (i.e. android-4.0.3_r1 ) ........................................ 6
2.4 Run repo init to bring down the latest version of Repo ........................................ 6
2.5 Run repo sync to pull down files .......................................................................... 6
2.6 Getting last Open NFC sources ........................................................................... 6
2.7 Modify Android source code ................................................................................ 6
2.7.1 Modifications of the Android source code by patches ....................................... 6
2.7.2 Manual modifications of the Android source code ............................................. 8
2.8 Check in tree ........................................................................................................ 9
2.9 Kernel Compilation ............................................................................................ 10
2.10 Final Compilation ............................................................................................... 12
3 Annex 1 ............................................................................................................. 14
4 License ............................................................................................................. 16
Open NFC - Android ICS 4.0.3 - Quick Porting Guide General Business Use
Page : 5/16
Date : April 2, 2012
Ref. : MAN_NFC_1204-313 v0.1(13736)
Check document version before use. Copyright © 2012 Inside Secure
1 Introduction This document is the quick version of Android porting guide for the NFC software stack “Open NFC 4.4.1”. This document describes the porting of Android ICS platform release 4.0.3_r1 for OpenNFC, and it must be adapted for a real hardware platform. The main components of the android porting are: An Android service, named OpenNFCService, which controls the NFC controller and deals with the multi-application management. A driver, named open_nfc_driver.ko, is used for the low level communication with the NFC controller.
Open NFC - Android ICS 4.0.3 - Quick Porting Guide General Business Use
Page : 6/16
Date : April 2, 2012
Ref. : MAN_NFC_1204-313 v0.1(13736)
Check document version before use. Copyright © 2012 Inside Secure
2 Building Instructions How to compile the Android sources with Open NFC
2.1 Create bin/ directory and include it in path
$ mkdir ~/bin
$ PATH=~/bin:$PATH
2.2 Download the Repo script and ensure it is executable $ curl https://dl-ssl.google.com/dl/googlesource/git-repo/repo > ~/bin/repo
$ chmod a+x ~/bin/repo
2.3 Make a New working directory (i.e. android-4.0.3_r1 )
mkdir android-4.0.3_r1 && cd android-4.0.3_r1
2.4 Run repo init to bring down the latest version of Repo
$ repo init -u https://android.googlesource.com/platform/manifest -b android-4.0.3_r1
2.5 Run repo sync to pull down files
$ repo sync
2.6 Getting last Open NFC sources
Retrieve from the delivery website the archive file: OpenNFC_4.4.1_Android_4.0.3_2012_04_12_12_30_8b2088e129f5bc063ec89050e941f4b9.tar.gz
and put it under packages/apps:
$ cd packages/apps
$ cp <path>/OpenNFC_4.4.1_Android_4.0.3_2012_04_12_12_30_8b2088e129f5bc063ec89050e941f4b9.tar.gz .
$ tar zxvf OpenNFC_4.4.1_Android_4.0.3_2012_04_12_12_30_8b2088e129f5bc063ec89050e941f4b9.tar.gz
2.7 Modify Android source code
The following section explains which modifications should be done for the Android source code. If a developer uses the original source code from AOSP, he can utilize the patches included in the Open NFC package. All details are explained in the section “Modifications of the Android source code by patches”. If a developer uses already modified Android source code, he should change it manually in accordance with the instructions provided below in the section “Manual modifications of the Android source code”. Thus a developer should follow only one set of instructions: either Modifications of the Android source code by patches or Manual modifications of the Android source code.
2.7.1 Modifications of the Android source code by patches
Open NFC - Android ICS 4.0.3 - Quick Porting Guide General Business Use
Page : 7/16
Date : April 2, 2012
Ref. : MAN_NFC_1204-313 v0.1(13736)
Check document version before use. Copyright © 2012 Inside Secure
The following patches can be used to modify the original Android source code only:
build.patch
frameworks_base.patch
system_core.patch
These patches are included in the Open NFC package in the sub-directory patches, please
take a look at the Open NFC’s tree below.
2.7.1.1 Apply build.patch
cd android-4.0.3_r1/build
android-4.0.3_r1/build$ cp ../packages/apps/OpenNFC/patches/build.patch .
android-4.0.3_r1/build$ git apply --check build.patch
android-4.0.3_r1/build$ git apply --stat build.patch
core/base_rules.mk | 2 +-
core/main.mk | 4 +++-
2 files changed, 4 insertions(+), 2 deletions(-)
android-4.0.3_r1/build$ git status
# Not currently on any branch.
# Untracked files:
# (use "git add <file>..." to include in what will be committed)
#
# build.patch
nothing added to commit but untracked files present (use "git add" to track)
android-4.0.3_r1/build$ git apply --whitespace=nowarn build.patch
android-4.0.3_r1/build$ git status
# Not currently on any branch.
# Changed but not updated:
# (use "git add <file>..." to update what will be committed)
# (use "git checkout -- <file>..." to discard changes in working directory)
#
# modified: core/base_rules.mk
#
# Untracked files:
# (use "git add <file>..." to include in what will be committed)
#
# build.patch
no changes added to commit (use "git add" and/or "git commit -a")
2.7.1.2 Apply system_core.patch
android-4.0.3_r1/system/core$ cp ../../packages/apps/OpenNFC/patches/system_core.patch .
android-4.0.3_r1/system/core$ git apply --check system_core.patch
android-4.0.3_r1/system/core$ git apply --stat system_core.patch
rootdir/init.rc | 3 +++
rootdir/ueventd.rc | 3 +++
2 files changed, 6 insertions(+), 0 deletions(-)
android-4.0.3_r1/system/core$ git apply --whitespace=nowarn system_core.patch
android-4.0.3_r1/system/core$ git status
# Not currently on any branch.
# Changed but not updated:
# (use "git add <file>..." to update what will be committed)
# (use "git checkout -- <file>..." to discard changes in working directory)
#
# modified: rootdir/init.rc
# modified: rootdir/ueventd.rc
#
# Untracked files:
# (use "git add <file>..." to include in what will be committed)
#
# system_core.patch
no changes added to commit (use "git add" and/or "git commit -a")
Open NFC - Android ICS 4.0.3 - Quick Porting Guide General Business Use
Page : 8/16
Date : April 2, 2012
Ref. : MAN_NFC_1204-313 v0.1(13736)
Check document version before use. Copyright © 2012 Inside Secure
2.7.1.3 Apply the patch frameworks_base.patch
android-4.0.3_r1/frameworks/base$ cp ../../packages/apps/OpenNFC/patches/frameworks_base.patch .
android-4.0.3_r1/frameworks/base$ git apply --check frameworks_base.patch
android-4.0.3_r1/frameworks/base$ git apply --stat frameworks_base.patch
data/etc/platform.xml | 5 +++++
1 files changed, 5 insertions(+), 0 deletions(-)
android-4.0.3_r1/frameworks/base$ git apply --whitespace=nowarn frameworks_base.patch
2.7.2 Manual modifications of the Android source code
If a developer uses already modified Android source code, he should change it manually in accordance with the instructions provided below.
2.7.2.1 Modifications for build/core/base_rules.mk
The following error message ifneq ($(strip $(LOCAL_BUILT_MODULE)$(LOCAL_INSTALLED_MODULE)),) $(error $(LOCAL_PATH): LOCAL_BUILT_MODULE and LOCAL_INSTALLED_MODULE must not be defined by component makefiles) endif
should be changed to a warning like ifneq ($(strip $(LOCAL_BUILT_MODULE)$(LOCAL_INSTALLED_MODULE)),) $(warning $(LOCAL_PATH): LOCAL_BUILT_MODULE and LOCAL_INSTALLED_MODULE must not be defined by component makefiles) endif
2.7.2.2 Modifications for build/core/main.mk
The following code ifeq ($(stash_product_vars),true) $(call assert-product-vars, __STASHED) endif
should be commented out like ifeq ($(stash_product_vars),true) # $(call assert-product-vars, __STASHED) endif
2.7.2.3 Modifications for frameworks/base/data/etc/platform.xml
The following lines should be added inside the <permissions> </permissions> block: <!-- Feature NFC --> <feature name="android.hardware.nfc" />
f.e. just above the line </permissions>
2.7.2.4 Modifications for system/core/rootdir/init.rc
The following lines should be added at the end of the <on post-fs-data> section: #insmod for Open NFC insmod /system/lib/open_nfc_driver.ko
Open NFC - Android ICS 4.0.3 - Quick Porting Guide General Business Use
Page : 9/16
Date : April 2, 2012
Ref. : MAN_NFC_1204-313 v0.1(13736)
Check document version before use. Copyright © 2012 Inside Secure
2.7.2.5 Modifications for system/core/rootdir/ueventd.rc
The following lines should be added at the end of the </dev> section: #NFC device
/dev/nfcc 0600 system system
2.8 Check in tree
In <ANDROID_ROOT>/packages/apps you must have the following hierarchy : (Hints: In <ANDROID_ROOT>/packages/apps you can use tree -d OpenNFC) OpenNFC/
├── frameworks
│ ├── libs
│ │ └── open_nfc
│ │ ├── interfaces
│ │ ├── porting
│ │ │ ├── client
│ │ │ │ └── jni
│ │ │ │ └── headers
│ │ │ ├── common
│ │ │ └── server
│ │ │ └── jni
│ │ └── sources
│ ├── OpenNFCLibrary
│ │ ├── docs
│ │ │ └── html
│ │ │ ├── Explanations_files
│ │ │ └── reference
│ │ │ └── org
│ │ │ └── opennfc
│ │ │ ├── cardemulation
│ │ │ │ └── doc-files
│ │ │ ├── cardlistener
│ │ │ │ └── doc-files
│ │ │ └── nfctag
│ │ │ └── doc-files
│ │ └── java
│ │ └── org
│ │ ├── opennfc
│ │ │ ├── android
│ │ │ │ └── tools
│ │ │ ├── cardemulation
│ │ │ │ └── doc-files
│ │ │ ├── cardlistener
│ │ │ │ └── doc-files
│ │ │ ├── hardware
│ │ │ ├── nfctag
│ │ │ │ └── doc-files
│ │ │ ├── p2p
│ │ │ ├── p2pHo
│ │ │ └── se
│ │ └── simalliance
│ │ └── openmobileapi
│ └── OpenNFCService
│ ├── assets
│ ├── res
│ │ ├── drawable-hdpi
│ │ ├── drawable-mdpi
│ │ ├── layout
│ │ ├── raw
│ │ ├── values
│ │ └── xml
│ └── src
│ └── org
│ └── opennfc
│ ├── service
│ │ ├── communication
│ │ │ ├── npp
│ │ │ └── snep
│ │ ├── p2pEvent
│ │ └── P2PHandover
│ ├── tests
Open NFC - Android ICS 4.0.3 - Quick Porting Guide General Business Use
Page : 10/16
Date : April 2, 2012
Ref. : MAN_NFC_1204-313 v0.1(13736)
Check document version before use. Copyright © 2012 Inside Secure
│ │ ├── generic
│ │ ├── TestLibJava
│ │ │ ├── NdefMessage
│ │ │ ├── NdefRecord
│ │ │ ├── NfcTagConnection
│ │ │ └── utils
│ │ │ └── tag
│ │ └── unit
│ └── tools
│ ├── opennfcsettings
│ └── securityStack
├── hardware
│ └── libhardware
│ ├── include
│ │ └── hardware
│ └── modules
│ └── nfcc
│ ├── nfcc
│ ├── nfc_hal_microread
│ │ ├── driver
│ │ ├── interfaces
│ │ ├── porting
│ │ └── sources
│
│ └── nfc_hal_simulator
│ ├── interfaces
│ ├── porting
│ └── sources
└── patches
Note: In case of
1) Porting for the emulator In the (ANDROID_ROOT_DIR)/packages/apps/OpenNFC/frameworks/OpenNFCService/AndroidManifest.xml, the
following part must be added. This application allows assigning an IP address to the emulator which can then be connected by ConnectCenter.
<!-- Remove this activity for a real phone -->
<activity
android:clearTaskOnLaunch="true"
android:label="@string/nfc_settings_title"
android:name="org.opennfc.tools.opennfcsettings.OpenNfcSettings" >
<intent-filter >
<action android:name="android.intent.action.MAIN" />
<category android:name="android.intent.category.LAUNCHER" />
</intent-filter>
</activity>
2) Porting for a real device
The above part must be removed if it exists in the file: (ANDROID_ROOT_DIR)/packages/apps/OpenNFC/frameworks/OpenNFCService/AndroidManifest.xml. The default address 127.0.0.1 has been assigned in the file: (ANDROID_ROOT_DIR)/packages/apps/OpenNFC/frameworks/OpenNFCService/res/raw/default_address_connect.bin
2.9 Kernel Compilation
Firstly, you should download the source code of the linux kernel: mkdir kernel
cd kernel
git clone https://android.googlesource.com/kernel/goldfish.git .
git checkout -b android-goldfish-2.6.29
git pull origin android-goldfish-2.6.29
The default android emulator Linux kernel configuration can be generated using the following commands:
Open NFC - Android ICS 4.0.3 - Quick Porting Guide General Business Use
Page : 11/16
Date : April 2, 2012
Ref. : MAN_NFC_1204-313 v0.1(13736)
Check document version before use. Copyright © 2012 Inside Secure
cd (ANDROID_ROOT_DIR)
export PATH=$PATH:$PWD/prebuilt/linux-x86/toolchain/arm-eabi-4.4.3/bin
export ANDROID_BUILD_TOP=$PWD
export CROSS_COMPILE=arm-eabi- ARCH=arm
cd (ANDROID_ROOT_DIR)/kernel
make goldfish_armv7_defconfig
Then, the loadable support module should be enabled. make menuconfig
Choose “Enable loadable module support” and press <Space>
Open NFC - Android ICS 4.0.3 - Quick Porting Guide General Business Use
Page : 12/16
Date : April 2, 2012
Ref. : MAN_NFC_1204-313 v0.1(13736)
Check document version before use. Copyright © 2012 Inside Secure
Enable “Forced module loading” Then, compile the new kernel $ make -j`cat /proc/cpuinfo | grep -E '^processor' | wc -l`
The open_nfc_driver kernel sources can be found in the directory: $ cd
(ANDROID_ROOT_DIR)/packages/apps/OpenNFC/hardware/libhardware/modules/nfcc/
nfc_hal_microread/driver
Assuming the kernel sources have been downloaded into the (ANDROID_ROOT_DIR)/kernel directory, the kernel module compilation can be done by issuing a make command in the driver directory. $ make -j`cat /proc/cpuinfo | grep -E '^processor' | wc -l`
Recommendation: enable CCACHE and export the following variable USE_CCACHE and enhance the ccache size following your available space disk. $ export USE_CCACHE=1
$ ./prebuilt/linux-x86/ccache/ccache –M15G
2.10 Final Compilation
Once Open NFC Android successfully installed in the standard AOSP sources, lunch command in the AOSP tree: $ . ./build/envsetup.sh
Open NFC - Android ICS 4.0.3 - Quick Porting Guide General Business Use
Page : 13/16
Date : April 2, 2012
Ref. : MAN_NFC_1204-313 v0.1(13736)
Check document version before use. Copyright © 2012 Inside Secure
$ lunch
You're building on Linux
Lunch menu... pick a combo:
1. full-eng
2. full_x86-eng
3. vbox_x86-eng
4. full_maguro-userdebug
5. full_tuna-userdebug
6. full_panda-eng
Which would you like? [full-eng] 1 (for emulator)
$ make –j2 ARCH=arm CROSS_COMPILE=arm-eabi-
Tips: These targets are based on the aosp_emulator target. Once the correct target selected, a simple make command on the android top dir will build the entire project.
Open NFC - Android ICS 4.0.3 - Quick Porting Guide General Business Use
Page : 14/16
Date : April 2, 2012
Ref. : MAN_NFC_1204-313 v0.1(13736)
Check document version before use. Copyright © 2012 Inside Secure
3 Annex 1
Open NFC - Android ICS 4.0.3 - Quick Porting Guide General Business Use
Page : 15/16
Date : April 2, 2012
Ref. : MAN_NFC_1204-313 v0.1(13736)
Check document version before use. Copyright © 2012 Inside Secure
Open NFC - Android ICS 4.0.3 - Quick Porting Guide General Business Use
Page : 16/16
Date : April 2, 2012
Ref. : MAN_NFC_1204-313 v0.1(13736)
Check document version before use. Copyright © 2012 Inside Secure
4 License The source files of the driver sample of the "Open NFC for Linux" are distributed using the "Apache v2.0" license. They can be freely adapted or modified and used to create a dynamic driver module or to be statically linked with the kernel without any license issue. The remaining of the Open NFC core source code and the source code of the "Open NFC for Android" are distributed under Apache v2.0 license.