Ubuntu Pastebin
- This is Matt Mower's pnfw https://paste.ubuntu.com/18137835/
Paste from pnfw instructions at Thu, 30 Jun 2016 00:54:13 +0000
I read the contents of nxp_nfc_full_version[] and nxp_nfc_fw[] using a simple executable linked to
libpn544_fw.so. I didn't want to deal with Android denying me the ability to load the library,
but I needed a linker available, so I prepared these instructions for use with TWRP.
1) Save http://paste.ubuntu.com/18137145/ as a patch (e.g. pnfw.patch)
2) In your device tree:
$ git am /path/to/pnfw.patch
3) Copy the libpn544_fw.so blob to the pnfw/ subdirectory
4) Read the symbols from the libpn544_fw.so blob:
$ /path/to/cm/prebuilts/gcc/linux-x86/arm/arm-eabi-4.8/bin/arm-eabi-readelf -Ws /path/to/libpn544_fw.so
Sample output: http://paste.ubuntu.com/18137244/
5) What matters to me is:
a) nxp_nfc_fw has size 51397
b) nxp_nfc_full_version has size 12
6) Edit pnfw/pnfw.c to adjust the size of nxp_nfc_fw_len and nxp_nfc_full_version_len accordingly
7) From the top of your cm tree, lunch for your device and then build the module: mka pnfw
8) For reasons unknown to me, the linker renames the shared lib in the executable, so the following
replacement was necessary:
$ strings $OUT/recovery/root/sbin/pnfw | grep libpn544_fw
libpn544_fw_C3_1_41_SP.so
$ sed -i "s|libpn544_fw_C3_1_41_SP.so|libpn544_fw.so\x0\x0\x0\x0\x0\x0\x0\x0\x0\x0\x0|g" $OUT/recovery/root/sbin/pnfw
Make sure the replacement string is the same length as the original, hence the \x0 fillers.
9) In TWRP, the linker is in /sbin:
$ sed -i "s|/system/bin/linker\x0|/sbin/linker\x0\x0\x0\x0\x0\x0\x0|g" $OUT/recovery/root/sbin/pnfw
10) Push the files to your device
$ adb push $OUT/recovery/root/sbin/pnfw /sbin/pnfw
$ adb push $OUT/recovery/root/sbin/libpn544_fw.so /sbin/libpn544_fw.so
10) Run the executable (in TWRP):
$ adb shell
$ pnfw > /tmp/fw.c
$ exit
$ adb pull /tmp/fw.c
From 7d7530016736767ebcbf171872e5306eb9a9bb12 Mon Sep 17 00:00:00 2001
From: Matt Mower <[email protected]>
Date: Sat, 25 Jun 2016 16:39:09 -0500
Subject: [PATCH] pn544 firmware creation
Change-Id: I382a83c26f277a31c20c7d1b55d969322a8093b0
---
pnfw/Android.mk | 32 +++++++++++++++++++++++++++++
pnfw/pnfw.c | 63 +++++++++++++++++++++++++++++++++++++++++++++++++++++++++
2 files changed, 95 insertions(+)
create mode 100644 pnfw/Android.mk
create mode 100644 pnfw/pnfw.c
diff --git a/pnfw/Android.mk b/pnfw/Android.mk
new file mode 100644
index 0000000..35bede8
--- /dev/null
+++ b/pnfw/Android.mk
@@ -0,0 +1,32 @@
+# Copyright (C) 2016 The CyanogenMod Project
+#
+# Licensed under the Apache License, Version 2.0 (the "License");
+# you may not use this file except in compliance with the License.
+# You may obtain a copy of the License at
+#
+# http://www.apache.org/licenses/LICENSE-2.0
+#
+# Unless required by applicable law or agreed to in writing, software
+# distributed under the License is distributed on an "AS IS" BASIS,
+# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+# See the License for the specific language governing permissions and
+# limitations under the License.
+
+LOCAL_PATH := $(call my-dir)
+
+include $(CLEAR_VARS)
+LOCAL_MODULE := pnfw
+LOCAL_SRC_FILES := pnfw.c
+LOCAL_SHARED_LIBRARIES := libpn544_fw libc
+LOCAL_PACK_MODULE_RELOCATIONS := false
+LOCAL_MODULE_PATH := $(TARGET_RECOVERY_ROOT_OUT)/sbin
+include $(BUILD_EXECUTABLE)
+
+include $(CLEAR_VARS)
+LOCAL_MODULE := libpn544_fw
+LOCAL_MODULE_CLASS := SHARED_LIBRARIES
+LOCAL_MODULE_SUFFIX := .so
+LOCAL_MODULE_TAGS := optional
+LOCAL_SRC_FILES := libpn544_fw.so
+LOCAL_MODULE_PATH := $(TARGET_RECOVERY_ROOT_OUT)/sbin
+include $(BUILD_PREBUILT)
diff --git a/pnfw/pnfw.c b/pnfw/pnfw.c
new file mode 100644
index 0000000..3a27cfd
--- /dev/null
+++ b/pnfw/pnfw.c
@@ -0,0 +1,63 @@
+#include <stdio.h>
+
+/* Quick build instructions
+
+mka pnfw
+sed -i "s|libpn544_fw_C3_1_41_SP.so|libpn544_fw.so\x0\x0\x0\x0\x0\x0\x0\x0\x0\x0\x0|g" $OUT/recovery/root/sbin/pnfw
+sed -i "s|/system/bin/linker\x0|/sbin/linker\x0\x0\x0\x0\x0\x0\x0|g" $OUT/recovery/root/sbin/pnfw
+adb push $OUT/recovery/root/sbin/pnfw /sbin/pnfw
+*/
+
+/* Example readelf output from grouper libpn544_fw.so
+
+$ arm-eabi-readelf -Ws libpn544_fw.so
+
+Symbol table '.dynsym' contains 18 entries:
+ Num: Value Size Type Bind Vis Ndx Name
+ 0: 00000000 0 NOTYPE LOCAL DEFAULT UND
+ 1: 000003d4 12 OBJECT GLOBAL DEFAULT 8 nxp_nfc_full_version
+ 2: 000003e0 51397 OBJECT GLOBAL DEFAULT 8 nxp_nfc_fw
+ 3: 00000000 0 FUNC GLOBAL DEFAULT UND __cxa_finalize
+ 4: 000110f0 0 NOTYPE GLOBAL DEFAULT 13 __dso_handle
+ 5: 00011000 0 NOTYPE GLOBAL DEFAULT 9 __INIT_ARRAY__
+ 6: 00011008 0 NOTYPE GLOBAL DEFAULT 10 __FINI_ARRAY__
+ 7: 000107a8 0 NOTYPE GLOBAL DEFAULT ABS __exidx_start
+ 8: 000107a8 0 NOTYPE GLOBAL DEFAULT ABS __exidx_end
+ 9: 000110ec 0 NOTYPE GLOBAL DEFAULT ABS __data_start
+ 10: 000110ec 0 NOTYPE GLOBAL DEFAULT ABS _edata
+ 11: 000110ec 0 NOTYPE GLOBAL DEFAULT ABS __bss_start
+ 12: 000110ec 0 NOTYPE GLOBAL DEFAULT ABS __bss_start__
+ 13: 00011100 0 NOTYPE GLOBAL DEFAULT ABS _bss_end__
+ 14: 00011100 0 NOTYPE GLOBAL DEFAULT ABS __bss_end__
+ 15: 00011100 0 NOTYPE GLOBAL DEFAULT ABS __end__
+ 16: 00011100 0 NOTYPE GLOBAL DEFAULT ABS _end
+ 17: 00080000 0 NOTYPE GLOBAL DEFAULT ABS _stack
+*/
+
+const unsigned long nxp_nfc_fw_len = 51397;
+const unsigned long nxp_nfc_full_version_len = 12;
+
+extern const unsigned char nxp_nfc_fw[];
+extern const unsigned char nxp_nfc_full_version[];
+
+int main() {
+ unsigned long i = 0;
+
+ printf("const unsigned char nxp_nfc_fw[] = {\n ");
+ for (i = 0; i < nxp_nfc_fw_len; i++) {
+ if (i == nxp_nfc_fw_len-1)
+ printf("0x%02x", nxp_nfc_fw[i]);
+ else if ((i+1)%12 == 0)
+ printf("0x%02x,\n ", nxp_nfc_fw[i]);
+ else
+ printf("0x%02x, ", nxp_nfc_fw[i]);
+ }
+ printf("\n};\n\n");
+
+ printf("const unsigned char nxp_nfc_full_version[] = {\n ");
+ for (i = 0; i < nxp_nfc_full_version_len; i++)
+ printf("0x%02x, ", nxp_nfc_full_version[i]);
+ printf("\n};\n");
+
+ return 0;
+}
--
2.7.4
Comments