泰晓科技 -- 聚焦 Linux - 追本溯源,见微知著!
网站地址:https://tinylab.org

泰晓Linux知识星球:1300+知识点,520+用户
请稍侯

ArchLinux AUR 打包实战:以 LPCScrypt 工具为例

taotieren 创作于 2021/08/29

By taotieren of TinyLab.org Jul 08, 2021

注意:以下所有命令行操作都是在 用户模式 下进行,需要 root 权限的地方会使用 sudo 命令。

1 背景简介

NXP 提供的 LPCScrypt 工具支持 Linux、macOS 和 Windows,详情阅读 LPCScrypt 上的介绍。

官网给的 Linux 版本的 lpcscrypt-2.1.2_57.x86_64.deb.bin 工具看名称是 Debian/Ubuntu 衍生版才能安装使用。

Arch 用户或其他 Linux 发行版用户想使用怎么办?

2 待打包软件分析

本节先分析原始包:lpcscrypt-2.1.2_57.x86_64.deb.bin,拆解包结构,得到核心二进制工具。

第1步,注册 NXP 官网下载相应的 Linux 版本文件,访问 NXP LPCScrypt 进行注册即可。

第2步,用文本编辑器打开查看里面的内容(内容较多,大体翻阅一下就好):

  1. #!/bin/sh
  2. # This script was generated using Makeself 2.2.0
  3. umask 077
  4. CRCsum="4237188651"
  5. MD5="6c85e5870f1db1e3c66128409ecc8cb5"
  6. TMPROOT=${TMPDIR:=/tmp}
  7. label="lpcscrypt installer"
  8. script="./install.sh"
  9. scriptargs=""
  10. licensetxt=""
  11. targetdir="installer"
  12. filesizes="1736969"
  13. keep="n"
  14. quiet="n"
  15. print_cmd_arg=""
  16. if type printf > /dev/null; then
  17. print_cmd="printf"
  18. elif test -x /usr/ucb/echo; then
  19. print_cmd="/usr/ucb/echo"
  20. else
  21. print_cmd="echo"
  22. fi
  23. unset CDPATH
  24. MS_Printf()
  25. {
  26. $print_cmd $print_cmd_arg "$1"
  27. }
  28. MS_PrintLicense()
  29. {
  30. if test x"$licensetxt" != x; then
  31. echo $licensetxt
  32. while true
  33. do
  34. MS_Printf "Please type y to accept, n otherwise: "
  35. read yn
  36. if test x"$yn" = xn; then
  37. keep=n
  38. eval $finish; exit 1
  39. break;
  40. elif test x"$yn" = xy; then
  41. break;
  42. fi
  43. done
  44. fi
  45. }
  46. MS_diskspace()
  47. {
  48. (
  49. if test -d /usr/xpg4/bin; then
  50. PATH=/usr/xpg4/bin:$PATH
  51. fi
  52. df -kP "$1" | tail -1 | awk '{ if ($4 ~ /%/) {print $3} else {print $4} }'
  53. )
  54. }
  55. MS_dd()
  56. {
  57. blocks=`expr $3 / 1024`
  58. bytes=`expr $3 % 1024`
  59. dd if="$1" ibs=$2 skip=1 obs=1024 conv=sync 2> /dev/null | \
  60. { test $blocks -gt 0 && dd ibs=1024 obs=1024 count=$blocks ; \
  61. test $bytes -gt 0 && dd ibs=1 obs=1024 count=$bytes ; } 2> /dev/null
  62. }
  63. MS_dd_Progress()
  64. {
  65. if test "$noprogress" = "y"; then
  66. MS_dd $@
  67. return $?
  68. fi
  69. file="$1"
  70. offset=$2
  71. length=$3
  72. pos=0
  73. bsize=4194304
  74. while test $bsize -gt $length; do
  75. bsize=`expr $bsize / 4`
  76. done
  77. blocks=`expr $length / $bsize`
  78. bytes=`expr $length % $bsize`
  79. (
  80. dd bs=$offset count=0 skip=1 2>/dev/null
  81. pos=`expr $pos \+ $bsize`
  82. MS_Printf " 0%% " 1>&2
  83. if test $blocks -gt 0; then
  84. while test $pos -le $length; do
  85. dd bs=$bsize count=1 2>/dev/null
  86. pcent=`expr $length / 100`
  87. pcent=`expr $pos / $pcent`
  88. if test $pcent -lt 100; then
  89. MS_Printf "\b\b\b\b\b\b\b" 1>&2
  90. if test $pcent -lt 10; then
  91. MS_Printf " $pcent%% " 1>&2
  92. else
  93. MS_Printf " $pcent%% " 1>&2
  94. fi
  95. fi
  96. pos=`expr $pos \+ $bsize`
  97. done
  98. fi
  99. if test $bytes -gt 0; then
  100. dd bs=$bytes count=1 2>/dev/null
  101. fi
  102. MS_Printf "\b\b\b\b\b\b\b" 1>&2
  103. MS_Printf " 100%% " 1>&2
  104. ) < "$file"
  105. }
  106. MS_Help()
  107. {
  108. cat << EOH >&2
  109. Makeself version 2.2.0
  110. 1) Getting help or info about $0 :
  111. $0 --help Print this message
  112. $0 --info Print embedded info : title, default target directory, embedded script ...
  113. $0 --lsm Print embedded lsm entry (or no LSM)
  114. $0 --list Print the list of files in the archive
  115. $0 --check Checks integrity of the archive
  116. 2) Running $0 :
  117. $0 [options] [--] [additional arguments to embedded script]
  118. with following options (in that order)
  119. --confirm Ask before running embedded script
  120. --quiet Do not print anything except error messages
  121. --noexec Do not run embedded script
  122. --keep Do not erase target directory after running
  123. the embedded script
  124. --noprogress Do not show the progress during the decompression
  125. --nox11 Do not spawn an xterm
  126. --nochown Do not give the extracted files to the current user
  127. --target dir Extract directly to a target directory
  128. directory path can be either absolute or relative
  129. --tar arg1 [arg2 ...] Access the contents of the archive through the tar command
  130. -- Following arguments will be passed to the embedded script
  131. EOH
  132. }
  133. MS_Check()
  134. {
  135. OLD_PATH="$PATH"
  136. PATH=${GUESS_MD5_PATH:-"$OLD_PATH:/bin:/usr/bin:/sbin:/usr/local/ssl/bin:/usr/local/bin:/opt/openssl/bin"}
  137. MD5_ARG=""
  138. MD5_PATH=`exec <&- 2>&-; which md5sum || type md5sum`
  139. test -x "$MD5_PATH" || MD5_PATH=`exec <&- 2>&-; which md5 || type md5`
  140. test -x "$MD5_PATH" || MD5_PATH=`exec <&- 2>&-; which digest || type digest`
  141. PATH="$OLD_PATH"
  142. if test "$quiet" = "n";then
  143. MS_Printf "Verifying archive integrity..."
  144. fi
  145. offset=`head -n 498 "$1" | wc -c | tr -d " "`
  146. verb=$2
  147. i=1
  148. for s in $filesizes
  149. do
  150. crc=`echo $CRCsum | cut -d" " -f$i`
  151. if test -x "$MD5_PATH"; then
  152. if test `basename $MD5_PATH` = digest; then
  153. MD5_ARG="-a md5"
  154. fi
  155. md5=`echo $MD5 | cut -d" " -f$i`
  156. if test $md5 = "00000000000000000000000000000000"; then
  157. test x$verb = xy && echo " $1 does not contain an embedded MD5 checksum." >&2
  158. else
  159. md5sum=`MS_dd "$1" $offset $s | eval "$MD5_PATH $MD5_ARG" | cut -b-32`;
  160. if test "$md5sum" != "$md5"; then
  161. echo "Error in MD5 checksums: $md5sum is different from $md5" >&2
  162. exit 2
  163. else
  164. test x$verb = xy && MS_Printf " MD5 checksums are OK." >&2
  165. fi
  166. crc="0000000000"; verb=n
  167. fi
  168. fi
  169. if test $crc = "0000000000"; then
  170. test x$verb = xy && echo " $1 does not contain a CRC checksum." >&2
  171. else
  172. sum1=`MS_dd "$1" $offset $s | CMD_ENV=xpg4 cksum | awk '{print $1}'`
  173. if test "$sum1" = "$crc"; then
  174. test x$verb = xy && MS_Printf " CRC checksums are OK." >&2
  175. else
  176. echo "Error in checksums: $sum1 is different from $crc" >&2
  177. exit 2;
  178. fi
  179. fi
  180. i=`expr $i + 1`
  181. offset=`expr $offset + $s`
  182. done
  183. if test "$quiet" = "n";then
  184. echo " All good."
  185. fi
  186. }
  187. UnTAR()
  188. {
  189. if test "$quiet" = "n"; then
  190. tar $1vf - 2>&1 || { echo Extraction failed. > /dev/tty; kill -15 $$; }
  191. else
  192. tar $1f - 2>&1 || { echo Extraction failed. > /dev/tty; kill -15 $$; }
  193. fi
  194. }
  195. finish=true
  196. xterm_loop=
  197. noprogress=n
  198. nox11=n
  199. copy=none
  200. ownership=y
  201. verbose=n
  202. initargs="$@"
  203. while true
  204. do
  205. case "$1" in
  206. -h | --help)
  207. MS_Help
  208. exit 0
  209. ;;
  210. -q | --quiet)
  211. quiet=y
  212. noprogress=y
  213. shift
  214. ;;
  215. --info)
  216. echo Identification: "$label"
  217. echo Target directory: "$targetdir"
  218. echo Uncompressed size: 3916 KB
  219. echo Compression: gzip
  220. echo Date of packaging: Wed Nov 25 13:12:38 CET 2020
  221. echo Built with Makeself version 2.2.0 on
  222. echo Build command was: "/usr/bin/makeself \\
  223. \"./installer\" \\
  224. \"./lpcscrypt-2.1.2_57.x86_64.deb.bin\" \\
  225. \"lpcscrypt installer\" \\
  226. \"./install.sh\""
  227. if test x$script != x; then
  228. echo Script run after extraction:
  229. echo " " $script $scriptargs
  230. fi
  231. if test x"" = xcopy; then
  232. echo "Archive will copy itself to a temporary location"
  233. fi
  234. if test x"n" = xy; then
  235. echo "directory $targetdir is permanent"
  236. else
  237. echo "$targetdir will be removed after extraction"
  238. fi
  239. exit 0
  240. ;;
  241. --dumpconf)
  242. echo LABEL=\"$label\"
  243. echo SCRIPT=\"$script\"
  244. echo SCRIPTARGS=\"$scriptargs\"
  245. echo archdirname=\"installer\"
  246. echo KEEP=n
  247. echo COMPRESS=gzip
  248. echo filesizes=\"$filesizes\"
  249. echo CRCsum=\"$CRCsum\"
  250. echo MD5sum=\"$MD5\"
  251. echo OLDUSIZE=3916
  252. echo OLDSKIP=499
  253. exit 0
  254. ;;
  255. --lsm)
  256. cat << EOLSM
  257. No LSM.
  258. EOLSM
  259. exit 0
  260. ;;
  261. --list)
  262. echo Target directory: $targetdir
  263. offset=`head -n 498 "$0" | wc -c | tr -d " "`
  264. for s in $filesizes
  265. do
  266. MS_dd "$0" $offset $s | eval "gzip -cd" | UnTAR t
  267. offset=`expr $offset + $s`
  268. done
  269. exit 0
  270. ;;
  271. --tar)
  272. offset=`head -n 498 "$0" | wc -c | tr -d " "`
  273. arg1="$2"
  274. if ! shift 2; then MS_Help; exit 1; fi
  275. for s in $filesizes
  276. do
  277. MS_dd "$0" $offset $s | eval "gzip -cd" | tar "$arg1" - $*
  278. offset=`expr $offset + $s`
  279. done
  280. exit 0
  281. ;;
  282. --check)
  283. MS_Check "$0" y
  284. exit 0
  285. ;;
  286. --confirm)
  287. verbose=y
  288. shift
  289. ;;
  290. --noexec)
  291. script=""
  292. shift
  293. ;;
  294. --keep)
  295. keep=y
  296. shift
  297. ;;
  298. --target)
  299. keep=y
  300. targetdir=${2:-.}
  301. if ! shift 2; then MS_Help; exit 1; fi
  302. ;;
  303. --noprogress)
  304. noprogress=y
  305. shift
  306. ;;
  307. --nox11)
  308. nox11=y
  309. shift
  310. ;;
  311. --nochown)
  312. ownership=n
  313. shift
  314. ;;
  315. --xwin)
  316. finish="echo Press Return to close this window...; read junk"
  317. xterm_loop=1
  318. shift
  319. ;;
  320. --phase2)
  321. copy=phase2
  322. shift
  323. ;;
  324. --)
  325. shift
  326. break ;;
  327. -*)
  328. echo Unrecognized flag : "$1" >&2
  329. MS_Help
  330. exit 1
  331. ;;
  332. *)
  333. break ;;
  334. esac
  335. done
  336. if test "$quiet" = "y" -a "$verbose" = "y";then
  337. echo Cannot be verbose and quiet at the same time. >&2
  338. exit 1
  339. fi
  340. MS_PrintLicense
  341. case "$copy" in
  342. copy)
  343. tmpdir=$TMPROOT/makeself.$RANDOM.`date +"%y%m%d%H%M%S"`.$$
  344. mkdir "$tmpdir" || {
  345. echo "Could not create temporary directory $tmpdir" >&2
  346. exit 1
  347. }
  348. SCRIPT_COPY="$tmpdir/makeself"
  349. echo "Copying to a temporary location..." >&2
  350. cp "$0" "$SCRIPT_COPY"
  351. chmod +x "$SCRIPT_COPY"
  352. cd "$TMPROOT"
  353. exec "$SCRIPT_COPY" --phase2 -- $initargs
  354. ;;
  355. phase2)
  356. finish="$finish ; rm -rf `dirname $0`"
  357. ;;
  358. esac
  359. if test "$nox11" = "n"; then
  360. if tty -s; then # Do we have a terminal?
  361. :
  362. else
  363. if test x"$DISPLAY" != x -a x"$xterm_loop" = x; then # No, but do we have X?
  364. if xset q > /dev/null 2>&1; then # Check for valid DISPLAY variable
  365. GUESS_XTERMS="xterm rxvt dtterm eterm Eterm kvt konsole aterm"
  366. for a in $GUESS_XTERMS; do
  367. if type $a >/dev/null 2>&1; then
  368. XTERM=$a
  369. break
  370. fi
  371. done
  372. chmod a+x $0 || echo Please add execution rights on $0
  373. if test `echo "$0" | cut -c1` = "/"; then # Spawn a terminal!
  374. exec $XTERM -title "$label" -e "$0" --xwin "$initargs"
  375. else
  376. exec $XTERM -title "$label" -e "./$0" --xwin "$initargs"
  377. fi
  378. fi
  379. fi
  380. fi
  381. fi
  382. if test "$targetdir" = "."; then
  383. tmpdir="."
  384. else
  385. if test "$keep" = y; then
  386. if test "$quiet" = "n";then
  387. echo "Creating directory $targetdir" >&2
  388. fi
  389. tmpdir="$targetdir"
  390. dashp="-p"
  391. else
  392. tmpdir="$TMPROOT/selfgz$$$RANDOM"
  393. dashp=""
  394. fi
  395. mkdir $dashp $tmpdir || {
  396. echo 'Cannot create target directory' $tmpdir >&2
  397. echo 'You should try option --target dir' >&2
  398. eval $finish
  399. exit 1
  400. }
  401. fi
  402. location="`pwd`"
  403. if test x$SETUP_NOCHECK != x1; then
  404. MS_Check "$0"
  405. fi
  406. offset=`head -n 498 "$0" | wc -c | tr -d " "`
  407. if test x"$verbose" = xy; then
  408. MS_Printf "About to extract 3916 KB in $tmpdir ... Proceed ? [Y/n] "
  409. read yn
  410. if test x"$yn" = xn; then
  411. eval $finish; exit 1
  412. fi
  413. fi
  414. if test "$quiet" = "n";then
  415. MS_Printf "Uncompressing $label"
  416. fi
  417. res=3
  418. if test "$keep" = n; then
  419. trap 'echo Signal caught, cleaning up >&2; cd $TMPROOT; /bin/rm -rf $tmpdir; eval $finish; exit 15' 1 2 3 15
  420. fi
  421. leftspace=`MS_diskspace $tmpdir`
  422. if test -n "$leftspace"; then
  423. if test "$leftspace" -lt 3916; then
  424. echo
  425. echo "Not enough space left in "`dirname $tmpdir`" ($leftspace KB) to decompress $0 (3916 KB)" >&2
  426. if test "$keep" = n; then
  427. echo "Consider setting TMPDIR to a directory with more free space."
  428. fi
  429. eval $finish; exit 1
  430. fi
  431. fi
  432. for s in $filesizes
  433. do
  434. if MS_dd_Progress "$0" $offset $s | eval "gzip -cd" | ( cd "$tmpdir"; UnTAR x ) 1>/dev/null; then
  435. if test x"$ownership" = xy; then
  436. (PATH=/usr/xpg4/bin:$PATH; cd "$tmpdir"; chown -R `id -u` .; chgrp -R `id -g` .)
  437. fi
  438. else
  439. echo >&2
  440. echo "Unable to decompress $0" >&2
  441. eval $finish; exit 1
  442. fi
  443. offset=`expr $offset + $s`
  444. done
  445. if test "$quiet" = "n";then
  446. echo
  447. fi
  448. cd "$tmpdir"
  449. res=0
  450. if test x"$script" != x; then
  451. if test x"$verbose" = xy; then
  452. MS_Printf "OK to execute: $script $scriptargs $* ? [Y/n] "
  453. read yn
  454. if test x"$yn" = x -o x"$yn" = xy -o x"$yn" = xY; then
  455. eval $script $scriptargs $*; res=$?;
  456. fi
  457. else
  458. eval $script $scriptargs $*; res=$?
  459. fi
  460. if test $res -ne 0; then
  461. test x"$verbose" = xy && echo "The program '$script' returned an error code ($res)" >&2
  462. fi
  463. fi
  464. if test "$keep" = n; then
  465. cd $TMPROOT
  466. /bin/rm -rf $tmpdir
  467. fi
  468. eval $finish; exit $res
  469. �6J綺燧\曽炶夯Eww�wI 逸澮!妸€倀wùt)J妧历击9g遱嫖湙�}蛙遺褛 箈啧y� .n�/<�.聜偪=�潲雜_� /堪牥€€ 彁///� L峥囹浪勐Cp磓urp斛7唢遻�� 鳢o售沦櫵塔翼�+烂/n~^~庚!�0衠[:竢[Zx賑1纞=苫果{:刭{螟xxEaZF:拷肆fT辑狜鉻祦窭頲羆搛6�0+{7綆硩厳
  470. 腆�+搪 骈骀MG�=l�急l~ �钷�0NNoog絾儠嶋�摰蟠眖眖觜踬9齧糪}FFV+ o槑�+锟�#椃�7�纟鯙^V瀗挝�6縙u龙�开� 0N;镞鴂�鹵押璱�#�'扇瘥]沖W岱o嫍F' '斫~# f踣访� sp+`0N{X喁痡o沆析椬{7皐饌/拲'熳碟鮹L6^0W7o樂厯
  471. 搪�鎛醝醔鉳汩E晴/忖紤濏_抉/_鸲珦珱鷦t0%7O豲W 鲟渍E/讛霟}n�涫豿YXE/{[镞_秜s爹趼o凤弋氷_\砀竳抑頝v0N嘷灼滞邮営谄萜遮 骒n� 蔬輿搹嫍嬒LP標OD萀H€粟乞浊Y鼁嫕�7層�o禭6蝆6|%房浸窙纩桝侚�=€賉兰輅繊誳/��5嬁挖�齯�緋q記挲�+黭狍 瘕孆/((( �艆N侣邮^
  472. 胱m韅崾纠掠�鰇q 线齏H@圜�颊嫃�耸驼*纡吷e例飤�熜O弫 犞f唨�5缶�4I悦痜瑡��;idb�7TF�冉Xo鳫-^髫E褚癄F�!"1遀C,賭I3)y�'铻k�%躍U�kc_淓 fB堠p┭: �4仜,雸�5_Wx噭
  473. �-\)z5耠�.�:jKa~)熶'Wv`轜圄^晪�'洫:蚙偵儆�WW挊莵騝壚E€�9丟7I畨C虸>E�-7
  474. Q 綗�>h碦�t靸塡斶8~
  475. 拰_V1鸃(|鸕|崎桴壟泳◣vf

可以看到,前半部分是 shell 脚本,从 499 行开始就是乱码了。

437 行有这个提示:

  1. offset=`head -n 498 "$0" | wc -c | tr -d " "`

推测 NXP 是使用 gzexe 进行了压缩和简单的加密处理

第3步,开始解密 lpcscrypt-2.1.2_57.x86_64.deb.bin:

  1. $ tail -n +499 lpcscrypt-2.1.2_57.x86_64.deb.bin > lpcscrypt-2.1.2_57.x86_64.deb

得到一个 deb 包(不知道是不是正常的 deb 包,进行下一步验证)

第4步,尝试当 deb 解压

  1. $ bsdtar -xf lpcscrypt-2.1.2_57.x86_64.deb

解压成功(狗头保命。如果不是 deb,可能得尝试其他格式了,这里不做进一步说明。

第5步,解压 data.tar.gz

  1. $ mkdir -p build
  2. $ tar -xf data.tar.gz -C build

最后,顺利得到了 NXP 的编译后的二进制文件:

  1. tree build
  2. build
  3. ├── lib
  4. └── udev
  5. └── rules.d
  6. └── 99-lpcscrypt.rules
  7. └── usr
  8. └── local
  9. └── lpcscrypt-2.1.2_57
  10. ├── bin
  11. ├── LPCScrypt_240.bin.hdr
  12. ├── image_manager
  13. └── lpcscrypt
  14. ├── docs
  15. ├── Debug_Probe_Firmware_Programming.pdf
  16. └── LPCScrypt_User_Guide.pdf
  17. ├── eula
  18. ├── SoftwareContentRegister.txt
  19. ├── licenses
  20. ├── Apache-2.0.txt
  21. ├── BSD-3-clause.txt
  22. ├── BSD-4-clause.txt
  23. ├── GPLV2.txt
  24. ├── LGPLV2.1.txt
  25. └── Zlib.txt
  26. ├── lpcscrypt_eula.docx
  27. ├── lpcscrypt_eula.rtf
  28. └── lpcscrypt_eula.txt
  29. ├── images
  30. ├── Link2_Fill_SPIFI.bin
  31. ├── Link2_Medium_SPIFI.bin
  32. ├── Link2_Small_SPIFI.bin
  33. ├── MCB1800_FillBlinky_BankA.bin
  34. ├── MCB1800_FillBlinky_BankB.bin
  35. ├── MCB1800_FillBlinky_SPIFI.bin
  36. ├── MCB1800_LargeBlinky_BankA.bin
  37. ├── MCB1800_LargeBlinky_BankB.bin
  38. ├── MCB1800_LargeBlinky_RAM.bin
  39. ├── MCB1800_LargeBlinky_SPIFI.bin
  40. ├── MCB1800_blinky_BankA.bin
  41. ├── MCB1800_blinky_BankB.bin
  42. ├── MCB1800_blinky_RAM.bin
  43. └── MCB1800_blinky_SPIFI.bin
  44. ├── probe_firmware
  45. ├── LPCLink2
  46. ├── Firmware_JLink_LPC-Link2_20190404.bin
  47. ├── LPC432x_CMSIS_DAP_NB_V5_224.bin.hdr
  48. ├── LPC432x_CMSIS_DAP_NB_V5_361.bin.hdr
  49. ├── LPC432x_CMSIS_DAP_SER_V5_224.bin.hdr
  50. ├── LPC432x_CMSIS_DAP_SER_V5_361.bin.hdr
  51. ├── LPC432x_CMSIS_DAP_V5_224.bin.hdr
  52. └── LPC432x_CMSIS_DAP_V5_361.bin.hdr
  53. └── LPCXpressoV2
  54. ├── Firmware_JLink_LPCXpressoV2_20190404.bin
  55. ├── LPC432x_IAP_CMSIS_DAP_NB_V5_224.bin
  56. ├── LPC432x_IAP_CMSIS_DAP_NB_V5_361.bin
  57. ├── LPC432x_IAP_CMSIS_DAP_SER_V5_224.bin
  58. ├── LPC432x_IAP_CMSIS_DAP_SER_V5_361.bin
  59. ├── LPC432x_IAP_CMSIS_DAP_V5_224.bin
  60. └── LPC432x_IAP_CMSIS_DAP_V5_361.bin
  61. └── scripts
  62. ├── 99-lpcscrypt.rules
  63. ├── LPCScrypt_CLI
  64. ├── aeskey
  65. ├── boot_lpcscrypt
  66. ├── dfu_boot
  67. ├── encrypt_and_program
  68. ├── encrypt_and_program.scy
  69. ├── install_udev_rules
  70. ├── program_CMSIS
  71. └── program_JLINK
  72. 15 directories, 54 files

3 编写 PKGBUILD 打包脚本

接下来,按 Arch 的打包规范编写 PKGBUILD 打包脚本。

注意:需要根据 NXP 的介绍需要依赖最新版 jlink 软件包,Arch 下是 jlink-software-and-documentation,其他 Linux 可能在软件商店有,也可能没有,那就需要自行去 Segger 官网下载 Jlink 的软件包了。

  1. # Maintainer: taotieren <admin@taotieren.com>
  2. # Contributor:
  3. pkgname="lpcscrypt-bin"
  4. pkgver=2.1.2
  5. pkgrel=1
  6. pkgdesc="LPCScrypt is the recommended tool for programming the latest versions of CMSIS-DAP and J-Link firmware onto boards with Link2/LPC-Link2 debug probes."
  7. arch=("x86_64")
  8. makedepends=('imagemagick')
  9. depends=('jlink-software-and-documentation')
  10. optdepends=()
  11. conflicts=()
  12. url="https://www.nxp.com/design/microcontrollers-developer-resources/lpcscrypt-v2-1-2:LPCSCRYPT"
  13. license=('Commercial' 'Apache-2.0' 'BSD-4-clause' 'BSD-3-clause' 'LGPLV2.1' 'GPLV2' 'Zlib')
  14. options=(!strip)
  15. _pkgver_ext=${pkgver}_57
  16. _pkg_file_name=${pkgname%-bin}-${_pkgver_ext}.${arch}.deb.bin
  17. _deb_file_name=${pkgname%-bin}-${_pkgver_ext}.${arch}.deb
  18. _DOWNLOADS_DIR=`xdg-user-dir DOWNLOAD`
  19. if [ ! -f ${PWD}/${_pkg_file_name} ]; then
  20. if [ -f $_DOWNLOADS_DIR/${_pkg_file_name} ]; then
  21. ln -sfn $_DOWNLOADS_DIR/${_pkg_file_name} ${PWD}
  22. else
  23. msg2 ""
  24. msg2 "The package can be downloaded here: "
  25. msg2 "Please remember to put a downloaded package ${_pkg_file_name} into the build directory ${PWD} or $_DOWNLOADS_DIR"
  26. msg2 ""
  27. fi
  28. fi
  29. source=("local://${_pkg_file_name}")
  30. sha256sums=('379c63b788a72e64571af870d760ad6b3be32e4c863d29ca58276f750e416750')
  31. noextract=(${_pkg_file_name})
  32. prepare(){
  33. cd "$srcdir"
  34. tail -n +499 ${_pkg_file_name} > ${_deb_file_name}
  35. mkdir -p build
  36. bsdtar xf ${_deb_file_name} -C build
  37. bsdtar xf build/${_deb_file_name} -C build
  38. }
  39. package() {
  40. cd "$srcdir"
  41. msg2 'Installing LPCScrypt'
  42. tar xf "build/data.tar.gz" -C "${pkgdir}/"
  43. mv "${pkgdir}/lib" "${pkgdir}/usr"
  44. msg2 'Instalation of binary file'
  45. install -Dm0755 /dev/stdin "${pkgdir}/usr/bin/${pkgname%-bin}" <<END
  46. #!/bin/sh
  47. /usr/local/lpcscrypt-2.1.2_57/bin/lpcscrypt "\$@"
  48. END
  49. msg2 'Instalation of license file'
  50. install -dm0755 "${pkgdir}/usr/share/licenses/${pkgname%-bin}/"
  51. cp -rv "${pkgdir}/usr/local/lpcscrypt-2.1.2_57/eula" "${pkgdir}/usr/share/licenses/${pkgname%-bin}/"
  52. }
  53. #
  54. # makepkg --printsrcinfo > .SRCINFO
  55. #
  56. # vim: set ts=8 sw=8 tw=0 noet:

4 编译 PKGBUILD 并安装验证

如果需要更新 PKGBUILDsha256sums 校验值,请运行:

  1. $ updpkgsums

然后创建 .SRCINFO 文件:

  1. $ makepkg --printsrcinfo > .SRCINFO

接着编译 PKGBUILD

  1. $ makepkg -sf
  2. ==> 正在创建软件包:lpcscrypt-bin 2.1.2-1 (20210704 星期日 140410秒)
  3. ==> 正在检查运行时依赖关系...
  4. ==> 正在检查编译时依赖关系
  5. ==> 获取源代码...
  6. -> 找到 lpcscrypt-2.1.2_57.x86_64.deb.bin
  7. ==> 正在验证 source 文件,使用sha256sums...
  8. lpcscrypt-2.1.2_57.x86_64.deb.bin ... 通过
  9. ==> 正在释放源码...
  10. ==> 正在开始 prepare()...
  11. ==> 正在删除现存的 $pkgdir/ 目录...
  12. ==> 正在进入 fakeroot 环境...
  13. ==> 正在开始 package()...
  14. -> Installing LPCScrypt
  15. -> Instalation of binary file
  16. -> Instalation of license file
  17. '/home/taotieren/git_clone/aur/lpcscrypt-bin/pkg/lpcscrypt-bin/usr/local/lpcscrypt-2.1.2_57/eula' -> '/home/taotieren/git_clone/aur/lpcscrypt-bin/pkg/lpcscrypt-bin/usr/share/licenses/lpcscrypt/eula'
  18. '/home/taotieren/git_clone/aur/lpcscrypt-bin/pkg/lpcscrypt-bin/usr/local/lpcscrypt-2.1.2_57/eula/lpcscrypt_eula.txt' -> '/home/taotieren/git_clone/aur/lpcscrypt-bin/pkg/lpcscrypt-bin/usr/share/licenses/lpcscrypt/eula/lpcscrypt_eula.txt'
  19. '/home/taotieren/git_clone/aur/lpcscrypt-bin/pkg/lpcscrypt-bin/usr/local/lpcscrypt-2.1.2_57/eula/lpcscrypt_eula.docx' -> '/home/taotieren/git_clone/aur/lpcscrypt-bin/pkg/lpcscrypt-bin/usr/share/licenses/lpcscrypt/eula/lpcscrypt_eula.docx'
  20. '/home/taotieren/git_clone/aur/lpcscrypt-bin/pkg/lpcscrypt-bin/usr/local/lpcscrypt-2.1.2_57/eula/lpcscrypt_eula.rtf' -> '/home/taotieren/git_clone/aur/lpcscrypt-bin/pkg/lpcscrypt-bin/usr/share/licenses/lpcscrypt/eula/lpcscrypt_eula.rtf'
  21. '/home/taotieren/git_clone/aur/lpcscrypt-bin/pkg/lpcscrypt-bin/usr/local/lpcscrypt-2.1.2_57/eula/licenses' -> '/home/taotieren/git_clone/aur/lpcscrypt-bin/pkg/lpcscrypt-bin/usr/share/licenses/lpcscrypt/eula/licenses'
  22. '/home/taotieren/git_clone/aur/lpcscrypt-bin/pkg/lpcscrypt-bin/usr/local/lpcscrypt-2.1.2_57/eula/licenses/Zlib.txt' -> '/home/taotieren/git_clone/aur/lpcscrypt-bin/pkg/lpcscrypt-bin/usr/share/licenses/lpcscrypt/eula/licenses/Zlib.txt'
  23. '/home/taotieren/git_clone/aur/lpcscrypt-bin/pkg/lpcscrypt-bin/usr/local/lpcscrypt-2.1.2_57/eula/licenses/Apache-2.0.txt' -> '/home/taotieren/git_clone/aur/lpcscrypt-bin/pkg/lpcscrypt-bin/usr/share/licenses/lpcscrypt/eula/licenses/Apache-2.0.txt'
  24. '/home/taotieren/git_clone/aur/lpcscrypt-bin/pkg/lpcscrypt-bin/usr/local/lpcscrypt-2.1.2_57/eula/licenses/GPLV2.txt' -> '/home/taotieren/git_clone/aur/lpcscrypt-bin/pkg/lpcscrypt-bin/usr/share/licenses/lpcscrypt/eula/licenses/GPLV2.txt'
  25. '/home/taotieren/git_clone/aur/lpcscrypt-bin/pkg/lpcscrypt-bin/usr/local/lpcscrypt-2.1.2_57/eula/licenses/BSD-3-clause.txt' -> '/home/taotieren/git_clone/aur/lpcscrypt-bin/pkg/lpcscrypt-bin/usr/share/licenses/lpcscrypt/eula/licenses/BSD-3-clause.txt'
  26. '/home/taotieren/git_clone/aur/lpcscrypt-bin/pkg/lpcscrypt-bin/usr/local/lpcscrypt-2.1.2_57/eula/licenses/BSD-4-clause.txt' -> '/home/taotieren/git_clone/aur/lpcscrypt-bin/pkg/lpcscrypt-bin/usr/share/licenses/lpcscrypt/eula/licenses/BSD-4-clause.txt'
  27. '/home/taotieren/git_clone/aur/lpcscrypt-bin/pkg/lpcscrypt-bin/usr/local/lpcscrypt-2.1.2_57/eula/licenses/LGPLV2.1.txt' -> '/home/taotieren/git_clone/aur/lpcscrypt-bin/pkg/lpcscrypt-bin/usr/share/licenses/lpcscrypt/eula/licenses/LGPLV2.1.txt'
  28. '/home/taotieren/git_clone/aur/lpcscrypt-bin/pkg/lpcscrypt-bin/usr/local/lpcscrypt-2.1.2_57/eula/SoftwareContentRegister.txt' -> '/home/taotieren/git_clone/aur/lpcscrypt-bin/pkg/lpcscrypt-bin/usr/share/licenses/lpcscrypt/eula/SoftwareContentRegister.txt'
  29. ==> 正在清理安装...
  30. -> 正在删除 libtool 文件...
  31. -> 正在清除不打算要的文件...
  32. -> 正在移除静态库文件...
  33. -> 正在压缩 man info 文档...
  34. ==> 正在检查打包问题...
  35. ==> 正在构建软件包"lpcscrypt-bin"...
  36. -> 正在生成 .PKGINFO 文件...
  37. -> 正在生成 .BUILDINFO 文件...
  38. -> 正在生成 .MTREE 文件...
  39. -> 正在压缩软件包...
  40. ==> 正在离开 fakeroot 环境。
  41. ==> 完成创建:lpcscrypt-bin 2.1.2-1 (20210704 星期日 140412秒)

接下来,安装 lpcscrypt-bin 2.1.2-1.pkg.tar.zst

  1. $ sudo pacman -U lpcscrypt-bin 2.1.2-1.pkg.tar.zst
  2. # 或
  3. $ yay -U lpcscrypt-bin 2.1.2-1.pkg.tar.zst
  4. 正在加载软件包...
  5. 正在解析依赖关系...
  6. 正在查找软件包冲突...
  7. 软件包 (1) lpcscrypt-bin-2.1.2-1
  8. 全部安装大小: 9.34 MiB
  9. :: 进行安装吗? [Y/n]
  10. (1/1) 正在检查密钥环里的密钥 [##########################] 100%
  11. (1/1) 正在检查软件包完整性 [##########################] 100%
  12. (1/1) 正在加载软件包文件 [##########################] 100%
  13. (1/1) 正在检查文件冲突 [##########################] 100%
  14. (1/1) 正在检查可用存储空间 [##########################] 100%
  15. :: 正在处理软件包的变化...
  16. (1/1) 正在安装 lpcscrypt-bin [##########################] 100%
  17. :: 正在运行事务后钩子函数...
  18. (1/3) Reloading device manager configuration...
  19. (2/3) Arming ConditionNeedsUpdate...
  20. (3/3) Refreshing PackageKit...

最后,运行并验证 lpcscrypt

  1. $ lpcscrypt
  2. lpcscrypt: NXP LPC Scripting tool. v2.1.2 (Build 44) (Nov 25 2020 13:01:49)
  3. usage: lpcscrypt [-d serial_port] [-e dnqst] [-g usec] [-hp] [-v var=value]
  4. [-s script]|[-t]|[[-x] command]
  5. where:
  6. -h display this help message
  7. -d serial_port use 'serial_port' (device) as target
  8. use ? to list available ports
  9. -s script read script from file
  10. -t read script from terminal (stdin)
  11. -x command execute 'command' only
  12. the -s, -t and -x options and/or immediate commands
  13. are mutually exclusive
  14. -v name=value assign variable 'name' the value 'value'
  15. Use [name] to reference the variable in the script
  16. Simple text replacement is performed on each script line
  17. -p pause before each script command
  18. -e denqst set command echo options:
  19. q - quiet - echo nothing [default]
  20. d - debug - echo additional debug information
  21. n - noisy - echo everything
  22. s - script - echo script commands
  23. t - target - echo target commands
  24. b - buffer - dump raw target buffer
  25. e - exit - display message on exit
  26. Supported high-level commands (implemented by this tool) are:
  27. program program [+c|+wN] (<file>|<fill_value>) <baseAddress>
  28. [<fill_length>].
  29. where: +c==calculate checksum
  30. +wN==width of fill_value, where N is 1, 2 or 4
  31. program file or value into flash at baseAddress
  32. verify verify [+c|+i|+wN] (<file>|<fill_value>) <baseAddress>
  33. [<fill_length>].
  34. where: +c==calculate checksum, +i==ignore checksum
  35. +wN==width of fill_value, where N is 1, 2 or 4
  36. verify that flash contents matches the file or value
  37. erase erase <baseAddress>
  38. erase flash contents
  39. blankCheck blankCheck <baseAddress>
  40. blankcheck
  41. setBoot setBoot [BankA|BankB|0|1]
  42. set the active boot flash bank
  43. setVidPid setVidPid <vid> <pid>
  44. program the OTP VID and PID
  45. echo echo <parameters>*
  46. echo all parameters to the output stream
  47. delay delay <microseconds>
  48. delay for number of microseconds
  49. pause pause [on|off] | message
  50. if on or off, switch autoPause on,
  51. else display message and wait for <ENTER>.
  52. (Not possible if script is from stdin)
  53. timer timer <start|stop|print>
  54. start/stop a timer
  55. var var name=value
  56. create a local variable
  57. <other> Any command supported by the target
  58. Multiple serial ports found:
  59. /dev/ttyACM1
  60. /dev/ttyUSB0
  61. /dev/ttyACM0

5 发布 AUR 包

接下来把打好的软件包上传到 AUR 仓库。

首先,从 AUR 上创建一个空仓库:

  1. $ git clone ssh://aur@aur.archlinux.org/lpcscrypt-bin.git

添加刚才的 PKGBUILD .SRCINFO 文件到仓库中:

  1. $ git add PKGBUILD
  2. $ git add .SRCINFO
  3. $ cat > .gitignore << EOF
  4. *
  5. *.*
  6. EOF
  7. $ git add .gitignore -f
  8. $ git commit -am "Update lpcscrypt-bin"
  9. $ git push

发布后,就得到了 lpcscrypt-bin AUR 包。



Read Related:

Read Latest: