kasual

Matt Mower's pnfw (nfc firmware)

Oct 19th, 2017
155
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 6.45 KB | None | 0 0
  1. Ubuntu Pastebin
  2. - This is Matt Mower's pnfw https://paste.ubuntu.com/18137835/
  3. Paste from pnfw instructions at Thu, 30 Jun 2016 00:54:13 +0000
  4.  
  5.  
  6.  
  7. I read the contents of nxp_nfc_full_version[] and nxp_nfc_fw[] using a simple executable linked to
  8. libpn544_fw.so. I didn't want to deal with Android denying me the ability to load the library,
  9. but I needed a linker available, so I prepared these instructions for use with TWRP.
  10.  
  11. 1) Save http://paste.ubuntu.com/18137145/ as a patch (e.g. pnfw.patch)
  12.  
  13. 2) In your device tree:
  14. $ git am /path/to/pnfw.patch
  15.  
  16. 3) Copy the libpn544_fw.so blob to the pnfw/ subdirectory
  17.  
  18. 4) Read the symbols from the libpn544_fw.so blob:
  19. $ /path/to/cm/prebuilts/gcc/linux-x86/arm/arm-eabi-4.8/bin/arm-eabi-readelf -Ws /path/to/libpn544_fw.so
  20. Sample output: http://paste.ubuntu.com/18137244/
  21.  
  22. 5) What matters to me is:
  23. a) nxp_nfc_fw has size 51397
  24. b) nxp_nfc_full_version has size 12
  25.  
  26. 6) Edit pnfw/pnfw.c to adjust the size of nxp_nfc_fw_len and nxp_nfc_full_version_len accordingly
  27.  
  28. 7) From the top of your cm tree, lunch for your device and then build the module: mka pnfw
  29.  
  30. 8) For reasons unknown to me, the linker renames the shared lib in the executable, so the following
  31. replacement was necessary:
  32. $ strings $OUT/recovery/root/sbin/pnfw | grep libpn544_fw
  33. libpn544_fw_C3_1_41_SP.so
  34. $ 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
  35. Make sure the replacement string is the same length as the original, hence the \x0 fillers.
  36.  
  37. 9) In TWRP, the linker is in /sbin:
  38. $ sed -i "s|/system/bin/linker\x0|/sbin/linker\x0\x0\x0\x0\x0\x0\x0|g" $OUT/recovery/root/sbin/pnfw
  39.  
  40. 10) Push the files to your device
  41. $ adb push $OUT/recovery/root/sbin/pnfw /sbin/pnfw
  42. $ adb push $OUT/recovery/root/sbin/libpn544_fw.so /sbin/libpn544_fw.so
  43.  
  44. 10) Run the executable (in TWRP):
  45. $ adb shell
  46. $ pnfw > /tmp/fw.c
  47. $ exit
  48. $ adb pull /tmp/fw.c
  49.  
  50.  
  51.  
  52.  
  53.  
  54.  
  55.  
  56.  
  57.  
  58.  
  59.  
  60.  
  61.  
  62.  
  63.  
  64.  
  65.  
  66.  
  67.  
  68.  
  69.  
  70.  
  71.  
  72.  
  73.  
  74. From 7d7530016736767ebcbf171872e5306eb9a9bb12 Mon Sep 17 00:00:00 2001
  75. From: Matt Mower <[email protected]>
  76. Date: Sat, 25 Jun 2016 16:39:09 -0500
  77. Subject: [PATCH] pn544 firmware creation
  78.  
  79. Change-Id: I382a83c26f277a31c20c7d1b55d969322a8093b0
  80. ---
  81. pnfw/Android.mk | 32 +++++++++++++++++++++++++++++
  82. pnfw/pnfw.c | 63 +++++++++++++++++++++++++++++++++++++++++++++++++++++++++
  83. 2 files changed, 95 insertions(+)
  84. create mode 100644 pnfw/Android.mk
  85. create mode 100644 pnfw/pnfw.c
  86.  
  87. diff --git a/pnfw/Android.mk b/pnfw/Android.mk
  88. new file mode 100644
  89. index 0000000..35bede8
  90. --- /dev/null
  91. +++ b/pnfw/Android.mk
  92. @@ -0,0 +1,32 @@
  93. +# Copyright (C) 2016 The CyanogenMod Project
  94. +#
  95. +# Licensed under the Apache License, Version 2.0 (the "License");
  96. +# you may not use this file except in compliance with the License.
  97. +# You may obtain a copy of the License at
  98. +#
  99. +# http://www.apache.org/licenses/LICENSE-2.0
  100. +#
  101. +# Unless required by applicable law or agreed to in writing, software
  102. +# distributed under the License is distributed on an "AS IS" BASIS,
  103. +# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
  104. +# See the License for the specific language governing permissions and
  105. +# limitations under the License.
  106. +
  107. +LOCAL_PATH := $(call my-dir)
  108. +
  109. +include $(CLEAR_VARS)
  110. +LOCAL_MODULE := pnfw
  111. +LOCAL_SRC_FILES := pnfw.c
  112. +LOCAL_SHARED_LIBRARIES := libpn544_fw libc
  113. +LOCAL_PACK_MODULE_RELOCATIONS := false
  114. +LOCAL_MODULE_PATH := $(TARGET_RECOVERY_ROOT_OUT)/sbin
  115. +include $(BUILD_EXECUTABLE)
  116. +
  117. +include $(CLEAR_VARS)
  118. +LOCAL_MODULE := libpn544_fw
  119. +LOCAL_MODULE_CLASS := SHARED_LIBRARIES
  120. +LOCAL_MODULE_SUFFIX := .so
  121. +LOCAL_MODULE_TAGS := optional
  122. +LOCAL_SRC_FILES := libpn544_fw.so
  123. +LOCAL_MODULE_PATH := $(TARGET_RECOVERY_ROOT_OUT)/sbin
  124. +include $(BUILD_PREBUILT)
  125. diff --git a/pnfw/pnfw.c b/pnfw/pnfw.c
  126. new file mode 100644
  127. index 0000000..3a27cfd
  128. --- /dev/null
  129. +++ b/pnfw/pnfw.c
  130. @@ -0,0 +1,63 @@
  131. +#include <stdio.h>
  132. +
  133. +/* Quick build instructions
  134. +
  135. +mka pnfw
  136. +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
  137. +sed -i "s|/system/bin/linker\x0|/sbin/linker\x0\x0\x0\x0\x0\x0\x0|g" $OUT/recovery/root/sbin/pnfw
  138. +adb push $OUT/recovery/root/sbin/pnfw /sbin/pnfw
  139. +*/
  140. +
  141. +/* Example readelf output from grouper libpn544_fw.so
  142. +
  143. +$ arm-eabi-readelf -Ws libpn544_fw.so
  144. +
  145. +Symbol table '.dynsym' contains 18 entries:
  146. + Num: Value Size Type Bind Vis Ndx Name
  147. + 0: 00000000 0 NOTYPE LOCAL DEFAULT UND
  148. + 1: 000003d4 12 OBJECT GLOBAL DEFAULT 8 nxp_nfc_full_version
  149. + 2: 000003e0 51397 OBJECT GLOBAL DEFAULT 8 nxp_nfc_fw
  150. + 3: 00000000 0 FUNC GLOBAL DEFAULT UND __cxa_finalize
  151. + 4: 000110f0 0 NOTYPE GLOBAL DEFAULT 13 __dso_handle
  152. + 5: 00011000 0 NOTYPE GLOBAL DEFAULT 9 __INIT_ARRAY__
  153. + 6: 00011008 0 NOTYPE GLOBAL DEFAULT 10 __FINI_ARRAY__
  154. + 7: 000107a8 0 NOTYPE GLOBAL DEFAULT ABS __exidx_start
  155. + 8: 000107a8 0 NOTYPE GLOBAL DEFAULT ABS __exidx_end
  156. + 9: 000110ec 0 NOTYPE GLOBAL DEFAULT ABS __data_start
  157. + 10: 000110ec 0 NOTYPE GLOBAL DEFAULT ABS _edata
  158. + 11: 000110ec 0 NOTYPE GLOBAL DEFAULT ABS __bss_start
  159. + 12: 000110ec 0 NOTYPE GLOBAL DEFAULT ABS __bss_start__
  160. + 13: 00011100 0 NOTYPE GLOBAL DEFAULT ABS _bss_end__
  161. + 14: 00011100 0 NOTYPE GLOBAL DEFAULT ABS __bss_end__
  162. + 15: 00011100 0 NOTYPE GLOBAL DEFAULT ABS __end__
  163. + 16: 00011100 0 NOTYPE GLOBAL DEFAULT ABS _end
  164. + 17: 00080000 0 NOTYPE GLOBAL DEFAULT ABS _stack
  165. +*/
  166. +
  167. +const unsigned long nxp_nfc_fw_len = 51397;
  168. +const unsigned long nxp_nfc_full_version_len = 12;
  169. +
  170. +extern const unsigned char nxp_nfc_fw[];
  171. +extern const unsigned char nxp_nfc_full_version[];
  172. +
  173. +int main() {
  174. + unsigned long i = 0;
  175. +
  176. + printf("const unsigned char nxp_nfc_fw[] = {\n ");
  177. + for (i = 0; i < nxp_nfc_fw_len; i++) {
  178. + if (i == nxp_nfc_fw_len-1)
  179. + printf("0x%02x", nxp_nfc_fw[i]);
  180. + else if ((i+1)%12 == 0)
  181. + printf("0x%02x,\n ", nxp_nfc_fw[i]);
  182. + else
  183. + printf("0x%02x, ", nxp_nfc_fw[i]);
  184. + }
  185. + printf("\n};\n\n");
  186. +
  187. + printf("const unsigned char nxp_nfc_full_version[] = {\n ");
  188. + for (i = 0; i < nxp_nfc_full_version_len; i++)
  189. + printf("0x%02x, ", nxp_nfc_full_version[i]);
  190. + printf("\n};\n");
  191. +
  192. + return 0;
  193. +}
  194. --
  195. 2.7.4
Advertisement
Add Comment
Please, Sign In to add comment