install.sh 18 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631
  1. #!/usr/bin/env bash
  2. #-
  3. # Copyright © 2010-2016
  4. # Waldemar Brodkorb <wbx@openadk.org>
  5. # Thorsten Glaser <tg@mirbsd.org>
  6. #
  7. # Provided that these terms and disclaimer and all copyright notices
  8. # are retained or reproduced in an accompanying document, permission
  9. # is granted to deal in this work without restriction, including un‐
  10. # limited rights to use, publicly perform, distribute, sell, modify,
  11. # merge, give away, or sublicence.
  12. #
  13. # This work is provided “AS IS” and WITHOUT WARRANTY of any kind, to
  14. # the utmost extent permitted by applicable law, neither express nor
  15. # implied; without malicious intent or gross negligence. In no event
  16. # may a licensor, author or contributor be held liable for indirect,
  17. # direct, other damage, loss, or other issues arising in any way out
  18. # of dealing in the work, even if advised of the possibility of such
  19. # damage or existence of a defect, except proven that it results out
  20. # of said person’s immediate fault when using the work as intended.
  21. #
  22. # Alternatively, this work may be distributed under the terms of the
  23. # General Public License, any version, as published by the Free Soft-
  24. # ware Foundation.
  25. #-
  26. # Prepare a USB stick or CF/SD/MMC card or hard disc for installation
  27. # of OpenADK
  28. ADK_TOPDIR=$(pwd)
  29. HOST=$(gcc -dumpmachine)
  30. me=$0
  31. case :$PATH: in
  32. (*:$ADK_TOPDIR/host_$HOST/usr/bin:*) ;;
  33. (*) export PATH=$PATH:$ADK_TOPDIR/host_$HOST/usr/bin ;;
  34. esac
  35. test -n "$KSH_VERSION" || exec mksh "$me" "$@"
  36. if test -z "$KSH_VERSION"; then
  37. echo >&2 Fatal error: could not run myself with mksh!
  38. exit 255
  39. fi
  40. ### run with mksh from here onwards ###
  41. me=${me##*/}
  42. if (( USER_ID )); then
  43. print -u2 Installation is only possible as root!
  44. exit 1
  45. fi
  46. ADK_TOPDIR=$(realpath .)
  47. ostype=$(uname -s)
  48. fs=ext4
  49. cfgfs=1
  50. datafssz=0
  51. noformat=0
  52. quiet=0
  53. serial=0
  54. speed=115200
  55. panicreboot=10
  56. keep=0
  57. grub=0
  58. function usage {
  59. cat >&2 <<EOF
  60. Syntax: $me [-f filesystem] [-c cfgfssize] [-d datafssize] [-k] [-n] [-g]
  61. [-p panictime] [±q] [-s serialspeed] [±t] <target> <device> <archive>
  62. Partition sizes are in MiB. Filesystem type is currently ignored (ext4).
  63. To keep filesystem on data partition use -k.
  64. Use -n to not format boot/root partition.
  65. Defaults: -c 1 -p 10 -s 115200; -t = enable serial console
  66. EOF
  67. exit $1
  68. }
  69. while getopts "c:d:f:ghknp:qs:t" ch; do
  70. case $ch {
  71. (c) if (( (cfgfs = OPTARG) < 0 || cfgfs > 16 )); then
  72. print -u2 "$me: -c $OPTARG out of bounds"
  73. exit 1
  74. fi ;;
  75. (d) if (( (datafssz = OPTARG) < 0 )); then
  76. print -u2 "$me: -d $OPTARG out of bounds"
  77. exit 1
  78. fi ;;
  79. (f) if [[ $OPTARG != @(ext2|ext3|ext4|xfs) ]]; then
  80. print -u2 "$me: filesystem $OPTARG invalid"
  81. exit 1
  82. fi
  83. fs=$OPTARG ;;
  84. (h) usage 0 ;;
  85. (k) keep=1 ;;
  86. (g) grub=1 ;;
  87. (p) if (( (panicreboot = OPTARG) < 0 || panicreboot > 300 )); then
  88. print -u2 "$me: -p $OPTARG out of bounds"
  89. exit 1
  90. fi ;;
  91. (q) quiet=1 ;;
  92. (+q) quiet=0 ;;
  93. (s) if [[ $OPTARG != @(96|192|384|576|1152)00 ]]; then
  94. print -u2 "$me: serial speed $OPTARG invalid"
  95. exit 1
  96. fi
  97. speed=$OPTARG ;;
  98. (n) noformat=1 ;;
  99. (t) serial=1 ;;
  100. (+t) serial=0 ;;
  101. (*) usage 1 ;;
  102. }
  103. done
  104. shift $((OPTIND - 1))
  105. (( $# == 3 )) || usage 1
  106. f=0
  107. case $ostype {
  108. (Linux)
  109. tools="bc mkfs.$fs tune2fs partprobe"
  110. ;;
  111. (Darwin)
  112. tools="bc diskutil"
  113. ;;
  114. (*)
  115. print -u2 Sorry, not ported to the OS "'$ostype'" yet.
  116. exit 1
  117. ;;
  118. }
  119. for tool in $tools; do
  120. print -n Checking if $tool is installed...
  121. if whence -p $tool >/dev/null; then
  122. print " okay"
  123. else
  124. print " failed"
  125. f=1
  126. fi
  127. done
  128. (( f )) && exit 1
  129. target=$1
  130. tgt=$2
  131. src=$3
  132. case $target {
  133. (banana-pro|pcengines-apu|raspberry-pi|raspberry-pi2|raspberry-pi3|raspberry-pi3-64|solidrun-imx6|solidrun-clearfog|default) ;;
  134. (*)
  135. print -u2 "Unknown target '$target', exiting"
  136. exit 1 ;;
  137. }
  138. if [[ ! -b $tgt ]]; then
  139. print -u2 "'$tgt' is not a block device, exiting"
  140. exit 1
  141. fi
  142. if [[ ! -f $src ]]; then
  143. print -u2 "'$src' is not a file, exiting"
  144. exit 1
  145. fi
  146. (( quiet )) || print "Installing $src on $tgt."
  147. case $ostype {
  148. (Darwin)
  149. R=/Volumes/ADKROOT; diskutil unmount $R
  150. B=/Volumes/ADKBOOT; diskutil unmount $B
  151. D=/Volumes/ADKDATA; diskutil unmount $D
  152. basedev=$tgt
  153. rootpart=${basedev}s1
  154. datapart=${basedev}s2
  155. if [[ $target = raspberry-pi || $target = raspberry-pi2 || $target = raspberry-pi3 || $target = raspberry-pi3-64 ]]; then
  156. bootpart=${basedev}s1
  157. rootpart=${basedev}s2
  158. datapart=${basedev}s3
  159. fi
  160. match=\'${basedev}\''?(s+([0-9]))'
  161. function mount_fs {
  162. }
  163. function umount_fs {
  164. diskutil unmount "$1"
  165. }
  166. function create_fs {
  167. if [[ $3 = ext4 ]]; then
  168. fstype=UFSD_EXTFS4
  169. fi
  170. if [[ $3 = vfat ]]; then
  171. fstype=fat32
  172. fi
  173. diskutil eraseVolume $fstype "$2" "$1"
  174. }
  175. function tune_fs {
  176. }
  177. ;;
  178. (Linux)
  179. basedev=$tgt
  180. rootpart=${basedev}1
  181. datapart=${basedev}2
  182. if [[ $target = raspberry-pi || $target = raspberry-pi2 || $target = raspberry-pi3 || $target = raspberry-pi3-64 ]]; then
  183. bootpart=${basedev}1
  184. rootpart=${basedev}2
  185. datapart=${basedev}3
  186. fi
  187. match=\'${basedev}\''+([0-9])'
  188. function mount_fs {
  189. mount -t "$3" "$1" "$2"
  190. }
  191. function umount_fs {
  192. umount "$1"
  193. }
  194. function create_fs {
  195. (( quiet )) || print "Creating filesystem on ${1}..."
  196. mkfs.$3 "$1"
  197. }
  198. function tune_fs {
  199. tune2fs -c 0 -i 0 "$1"
  200. }
  201. ;;
  202. }
  203. mount |&
  204. while read -p dev rest; do
  205. eval [[ \$dev = $match ]] || continue
  206. print -u2 "Block device $tgt is in use, please umount first."
  207. exit 1
  208. done
  209. if (( !quiet )); then
  210. print "WARNING: This will overwrite $basedev - type Yes to continue!"
  211. read x
  212. [[ $x = Yes ]] || exit 0
  213. fi
  214. if ! T=$(mktemp -d /tmp/openadk.XXXXXXXXXX); then
  215. print -u2 Error creating temporary directory.
  216. exit 1
  217. fi
  218. if [[ $ostype != Darwin ]]; then
  219. R=$T/rootmnt
  220. B=$T/bootmnt
  221. D=$T/datamnt
  222. mkdir -p "$R" "$B" "$D"
  223. fi
  224. # get disk size
  225. dksz=$(dkgetsz "$tgt")
  226. # partition layouts:
  227. # n̲a̲m̲e̲ p̲a̲r̲t̲#̲0̲ p̲̲a̲r̲t̲#̲1̲ p̲̲a̲r̲t̲#̲2̲ p̲̲a̲r̲t̲#̲3̲
  228. # default: 0x83(system) 0x83(?data) -(unused) 0x88(cfgfs)
  229. # raspberry: 0x0B(boot) 0x83(system) 0x83(?data) 0x88(cfgfs)
  230. syspartno=0
  231. # sizes:
  232. # boot(raspberry) - fixed (100 MiB)
  233. # cfgfs - fixed (parameter, max. 16 MiB)
  234. # data - flexible (parameter)
  235. # system - everything else
  236. if [[ $target = raspberry-pi || $target = raspberry-pi2 || $target = raspberry-pi3 || $target = raspberry-pi3-64 ]]; then
  237. syspartno=1
  238. bootfssz=100
  239. if (( grub )); then
  240. print -u2 "Cannot combine GRUB with $target"
  241. rm -rf "$T"
  242. exit 1
  243. fi
  244. else
  245. bootfssz=0
  246. fi
  247. heads=64
  248. secs=32
  249. (( cyls = dksz / heads / secs ))
  250. if (( cyls < (bootfssz + cfgfs + datafssz + 2) )); then
  251. print -u2 "Size of $tgt is $dksz, this looks fishy?"
  252. rm -rf "$T"
  253. exit 1
  254. fi
  255. if stat -qs .>/dev/null 2>&1; then
  256. statcmd='stat -f %z' # BSD stat (or so we assume)
  257. else
  258. statcmd='stat -c %s' # GNU stat
  259. fi
  260. if (( grub )); then
  261. tar -xOf "$src" boot/grub/core.img >"$T/core.img"
  262. integer coreimgsz=$($statcmd "$T/core.img")
  263. else
  264. coreimgsz=65024
  265. fi
  266. if (( coreimgsz < 1024 )); then
  267. print -u2 core.img is probably too small: $coreimgsz
  268. rm -rf "$T"
  269. exit 1
  270. fi
  271. if (( coreimgsz > 65024 )); then
  272. print -u2 core.img is larger than 64K-512: $coreimgsz
  273. rm -rf "$T"
  274. exit 1
  275. fi
  276. (( coreendsec = (coreimgsz + 511) / 512 ))
  277. if [[ $basedev = /dev/svnd+([0-9]) ]]; then
  278. # BSD svnd0 mode: protect sector #1
  279. corestartsec=2
  280. (( ++coreendsec ))
  281. corepatchofs=$((0x614))
  282. else
  283. corestartsec=1
  284. corepatchofs=$((0x414))
  285. fi
  286. # partition offset: at least coreendsec+1 but aligned on a multiple of secs
  287. #(( partofs = ((coreendsec / secs) + 1) * secs ))
  288. # we just use 2048 all the time, since some loaders are longer
  289. partofs=2048
  290. if [[ $target = raspberry-pi || $target = raspberry-pi2 || $target = raspberry-pi3 || $target = raspberry-pi3-64 ]]; then
  291. (( spartofs = partofs + (100 * 2048) ))
  292. else
  293. spartofs=$partofs
  294. fi
  295. (( quiet )) || if (( grub )); then
  296. print Preparing MBR and GRUB2...
  297. else
  298. print Preparing MBR...
  299. fi
  300. dd if=/dev/zero of="$T/firsttrack" count=$partofs 2>/dev/null
  301. # add another MiB to clear the first partition
  302. dd if=/dev/zero bs=1048576 count=1 >>"$T/firsttrack" 2>/dev/null
  303. echo $corestartsec $coreendsec | mksh "$ADK_TOPDIR/scripts/bootgrub.mksh" \
  304. -A -g $((cyls - bootfssz - cfgfs - datafssz)):$heads:$secs -M 1:0x83 \
  305. -O $spartofs | dd of="$T/firsttrack" conv=notrunc 2>/dev/null
  306. (( grub )) && dd if="$T/core.img" of="$T/firsttrack" conv=notrunc \
  307. seek=$corestartsec 2>/dev/null
  308. # set partition where it can find /boot/grub
  309. (( grub )) && print -n '\0\0\0\0' | \
  310. dd of="$T/firsttrack" conv=notrunc bs=1 seek=$corepatchofs 2>/dev/null
  311. # create cfgfs partition (mostly taken from bootgrub.mksh)
  312. set -A thecode
  313. typeset -Uui8 thecode
  314. mbrpno=0
  315. set -A g_code $cyls $heads $secs
  316. (( psz = g_code[0] * g_code[1] * g_code[2] ))
  317. (( pofs = (cyls - cfgfs) * g_code[1] * g_code[2] ))
  318. set -A o_code # g_code equivalent for partition offset
  319. (( o_code[2] = pofs % g_code[2] + 1 ))
  320. (( o_code[1] = pofs / g_code[2] ))
  321. (( o_code[0] = o_code[1] / g_code[1] + 1 ))
  322. (( o_code[1] = o_code[1] % g_code[1] + 1 ))
  323. # boot flag; C/H/S offset
  324. thecode[mbrpno++]=0x00
  325. (( thecode[mbrpno++] = o_code[1] - 1 ))
  326. (( cylno = o_code[0] > 1024 ? 1023 : o_code[0] - 1 ))
  327. (( thecode[mbrpno++] = o_code[2] | ((cylno & 0x0300) >> 2) ))
  328. (( thecode[mbrpno++] = cylno & 0x00FF ))
  329. # partition type; C/H/S end
  330. (( thecode[mbrpno++] = 0x88 ))
  331. (( thecode[mbrpno++] = g_code[1] - 1 ))
  332. (( cylno = g_code[0] > 1024 ? 1023 : g_code[0] - 1 ))
  333. (( thecode[mbrpno++] = g_code[2] | ((cylno & 0x0300) >> 2) ))
  334. (( thecode[mbrpno++] = cylno & 0x00FF ))
  335. # partition offset, size (LBA)
  336. (( thecode[mbrpno++] = pofs & 0xFF ))
  337. (( thecode[mbrpno++] = (pofs >> 8) & 0xFF ))
  338. (( thecode[mbrpno++] = (pofs >> 16) & 0xFF ))
  339. (( thecode[mbrpno++] = (pofs >> 24) & 0xFF ))
  340. (( pssz = psz - pofs ))
  341. (( thecode[mbrpno++] = pssz & 0xFF ))
  342. (( thecode[mbrpno++] = (pssz >> 8) & 0xFF ))
  343. (( thecode[mbrpno++] = (pssz >> 16) & 0xFF ))
  344. (( thecode[mbrpno++] = (pssz >> 24) & 0xFF ))
  345. # write partition table entry
  346. ostr=
  347. curptr=0
  348. while (( curptr < 16 )); do
  349. ostr=$ostr\\0${thecode[curptr++]#8#}
  350. done
  351. print -n "$ostr" | \
  352. dd of="$T/firsttrack" conv=notrunc bs=1 seek=$((0x1EE)) 2>/dev/null
  353. if (( datafssz )); then
  354. # create data partition (copy of the above :)
  355. set -A thecode
  356. typeset -Uui8 thecode
  357. mbrpno=0
  358. set -A g_code $cyls $heads $secs
  359. (( psz = (cyls - cfgfs) * g_code[1] * g_code[2] ))
  360. (( pofs = (cyls - cfgfs - datafssz) * g_code[1] * g_code[2] ))
  361. set -A o_code # g_code equivalent for partition offset
  362. (( o_code[2] = pofs % g_code[2] + 1 ))
  363. (( o_code[1] = pofs / g_code[2] ))
  364. (( o_code[0] = o_code[1] / g_code[1] + 1 ))
  365. (( o_code[1] = o_code[1] % g_code[1] + 1 ))
  366. # boot flag; C/H/S offset
  367. thecode[mbrpno++]=0x00
  368. (( thecode[mbrpno++] = o_code[1] - 1 ))
  369. (( cylno = o_code[0] > 1024 ? 1023 : o_code[0] - 1 ))
  370. (( thecode[mbrpno++] = o_code[2] | ((cylno & 0x0300) >> 2) ))
  371. (( thecode[mbrpno++] = cylno & 0x00FF ))
  372. # partition type; C/H/S end
  373. (( thecode[mbrpno++] = 0x83 ))
  374. (( thecode[mbrpno++] = g_code[1] - 1 ))
  375. (( cylno = (g_code[0] - cfgfs) > 1024 ? 1023 : g_code[0] - cfgfs - 1 ))
  376. (( thecode[mbrpno++] = g_code[2] | ((cylno & 0x0300) >> 2) ))
  377. (( thecode[mbrpno++] = cylno & 0x00FF ))
  378. # partition offset, size (LBA)
  379. (( thecode[mbrpno++] = pofs & 0xFF ))
  380. (( thecode[mbrpno++] = (pofs >> 8) & 0xFF ))
  381. (( thecode[mbrpno++] = (pofs >> 16) & 0xFF ))
  382. (( thecode[mbrpno++] = (pofs >> 24) & 0xFF ))
  383. (( pssz = psz - pofs ))
  384. (( thecode[mbrpno++] = pssz & 0xFF ))
  385. (( thecode[mbrpno++] = (pssz >> 8) & 0xFF ))
  386. (( thecode[mbrpno++] = (pssz >> 16) & 0xFF ))
  387. (( thecode[mbrpno++] = (pssz >> 24) & 0xFF ))
  388. # write partition table entry
  389. ostr=
  390. curptr=0
  391. while (( curptr < 16 )); do
  392. ostr=$ostr\\0${thecode[curptr++]#8#}
  393. done
  394. print -n "$ostr" | \
  395. dd of="$T/firsttrack" conv=notrunc bs=1 seek=$((0x1CE)) 2>/dev/null
  396. fi
  397. if [[ $target = raspberry-pi || $target = raspberry-pi2 || $target = raspberry-pi3 || $target = raspberry-pi3-64 ]]; then
  398. # move system and data partition from #0/#1 to #1/#2
  399. dd if="$T/firsttrack" bs=1 skip=$((0x1BE)) count=32 of="$T/x" 2>/dev/null
  400. dd of="$T/firsttrack" conv=notrunc bs=1 seek=$((0x1CE)) if="$T/x" 2>/dev/null
  401. # create boot partition (copy of the above :)
  402. set -A thecode
  403. typeset -Uui8 thecode
  404. mbrpno=0
  405. set -A g_code $cyls $heads $secs
  406. psz=$spartofs
  407. pofs=$partofs
  408. set -A o_code # g_code equivalent for partition offset
  409. (( o_code[2] = pofs % g_code[2] + 1 ))
  410. (( o_code[1] = pofs / g_code[2] ))
  411. (( o_code[0] = o_code[1] / g_code[1] + 1 ))
  412. (( o_code[1] = o_code[1] % g_code[1] + 1 ))
  413. # boot flag; C/H/S offset
  414. thecode[mbrpno++]=0x00
  415. (( thecode[mbrpno++] = o_code[1] - 1 ))
  416. (( cylno = o_code[0] > 1024 ? 1023 : o_code[0] - 1 ))
  417. (( thecode[mbrpno++] = o_code[2] | ((cylno & 0x0300) >> 2) ))
  418. (( thecode[mbrpno++] = cylno & 0x00FF ))
  419. # partition type; C/H/S end
  420. (( thecode[mbrpno++] = 0x0B ))
  421. (( thecode[mbrpno++] = g_code[1] - 1 ))
  422. (( cylno = (spartofs / 2048) > 1024 ? 1023 : (spartofs / 2048) - 1 ))
  423. (( thecode[mbrpno++] = g_code[2] | ((cylno & 0x0300) >> 2) ))
  424. (( thecode[mbrpno++] = cylno & 0x00FF ))
  425. # partition offset, size (LBA)
  426. (( thecode[mbrpno++] = pofs & 0xFF ))
  427. (( thecode[mbrpno++] = (pofs >> 8) & 0xFF ))
  428. (( thecode[mbrpno++] = (pofs >> 16) & 0xFF ))
  429. (( thecode[mbrpno++] = (pofs >> 24) & 0xFF ))
  430. (( pssz = psz - pofs ))
  431. (( thecode[mbrpno++] = pssz & 0xFF ))
  432. (( thecode[mbrpno++] = (pssz >> 8) & 0xFF ))
  433. (( thecode[mbrpno++] = (pssz >> 16) & 0xFF ))
  434. (( thecode[mbrpno++] = (pssz >> 24) & 0xFF ))
  435. # write partition table entry
  436. ostr=
  437. curptr=0
  438. while (( curptr < 16 )); do
  439. ostr=$ostr\\0${thecode[curptr++]#8#}
  440. done
  441. print -n "$ostr" | \
  442. dd of="$T/firsttrack" conv=notrunc bs=1 seek=$((0x1BE)) 2>/dev/null
  443. fi
  444. # disk signature
  445. rnddev=/dev/urandom
  446. [[ -c /dev/arandom ]] && rnddev=/dev/arandom
  447. dd if=$rnddev bs=4 count=1 2>/dev/null | \
  448. dd of="$T/firsttrack" conv=notrunc bs=1 seek=$((0x1B8)) 2>/dev/null
  449. print -n '\0\0' | \
  450. dd of="$T/firsttrack" conv=notrunc bs=1 seek=$((0x1BC)) 2>/dev/null
  451. partuuid=$(dd if="$T/firsttrack" bs=1 count=4 skip=$((0x1B8)) 2>/dev/null | \
  452. hexdump -e '1/4 "%08x"')-0$((syspartno+1))
  453. ((keep)) || if (( datafssz )); then
  454. (( quiet )) || print Cleaning out data partition...
  455. dd if=/dev/zero of="$tgt" bs=1048576 count=1 seek=$((cyls - cfgfs - datafssz)) > /dev/null 2>&1
  456. fi
  457. (( quiet )) || print Cleaning out root partition...
  458. dd if=/dev/zero bs=1048576 of="$tgt" count=1 seek=$((spartofs / 2048)) > /dev/null 2>&1
  459. (( quiet )) || if (( grub )); then
  460. print Writing MBR and GRUB2 to target device... system PARTUUID=$partuuid
  461. else
  462. print Writing MBR to target device... system PARTUUID=$partuuid
  463. fi
  464. dd if="$T/firsttrack" of="$tgt" > /dev/null 2>&1
  465. if [[ $ostype = Linux ]]; then
  466. partprobe $tgt
  467. sync
  468. fi
  469. fwdir=$(dirname "$src")
  470. case $target {
  471. (banana-pro)
  472. dd if="$fwdir/u-boot-sunxi-with-spl.bin" of="$tgt" bs=1024 seek=8 > /dev/null 2>&1
  473. ;;
  474. (solidrun-clearfog)
  475. dd if="$fwdir/u-boot-spl.kwb" of="$tgt" bs=512 seek=1 > /dev/null 2>&1
  476. ;;
  477. (solidrun-imx6)
  478. dd if="$fwdir/SPL" of="$tgt" bs=1024 seek=1 > /dev/null 2>&1
  479. dd if="$fwdir/u-boot.img" of="$tgt" bs=1024 seek=69 > /dev/null 2>&1
  480. ;;
  481. (raspberry-pi|raspberry-pi2|raspberry-pi3|raspberry-pi3-64)
  482. (( noformat )) || create_fs "$bootpart" ADKBOOT vfat
  483. ;;
  484. }
  485. (( noformat )) || create_fs "$rootpart" ADKROOT ext4
  486. (( noformat )) || tune_fs "$rootpart"
  487. (( quiet )) || print Extracting installation archive...
  488. mount_fs "$rootpart" "$R" ext4
  489. xz -dc "$src" | (cd "$R"; tar -xpf -)
  490. if (( datafssz )); then
  491. mkdir -m0755 "$R"/data
  492. ((keep)) || create_fs "$datapart" ADKDATA ext4
  493. ((keep)) || tune_fs "$datapart"
  494. case $target {
  495. (raspberry-pi|raspberry-pi2|raspberry-pi3|raspberry-pi3-64)
  496. echo "/dev/mmcblk0p3 /data ext4 rw 0 0" >> "$R"/etc/fstab
  497. ;;
  498. (banana-pro|solidrun-imx6|solidrun-clearfog)
  499. echo "/dev/mmcblk0p2 /data ext4 rw 0 0" >> "$R"/etc/fstab
  500. ;;
  501. }
  502. fi
  503. case $target {
  504. (raspberry-pi|raspberry-pi2|raspberry-pi3|raspberry-pi3-64)
  505. mount_fs "$bootpart" "$B" vfat
  506. for x in "$R"/boot/*; do
  507. [[ -e "$x" ]] && mv -f "$R"/boot/* "$B/"
  508. break
  509. done
  510. for x in "$fwdir"/*.dtb; do
  511. [[ -e "$x" ]] && cp "$fwdir"/*.dtb "$B/"
  512. break
  513. done
  514. # use static dtoverlay, rename to *.dtb
  515. mkdir "$B/"overlays
  516. for x in "$fwdir"/overlays/*.dtbo; do
  517. y=$(basename ${x} .dtbo)
  518. [[ -e "$x" ]] && cp "$fwdir"/overlays/${y}.dtbo "$B/"overlays/${y}.dtb
  519. done
  520. umount_fs "$B"
  521. ;;
  522. (solidrun-clearfog)
  523. for x in "$fwdir"/*.dtb; do
  524. [[ -e "$x" ]] && cp "$fwdir"/*.dtb "$R/boot/"
  525. break
  526. done
  527. mkimage -A arm -O linux -T script -C none -a 0 -e 0 \
  528. -n "SolidrunClearfog" \
  529. -d $fwdir/boot.script.clearfog $R/boot/boot.scr.uimg
  530. ;;
  531. (solidrun-imx6)
  532. for x in "$fwdir"/*.dtb; do
  533. [[ -e "$x" ]] && cp "$fwdir"/*.dtb "$R/boot/"
  534. break
  535. done
  536. mkimage -A arm -O linux -T script -C none -a 0 -e 0 \
  537. -n "SolidrunImx6" \
  538. -d $fwdir/boot.script.imx6 $R/boot/boot.scr.uimg
  539. ;;
  540. (banana-pro)
  541. for x in "$fwdir"/*.dtb; do
  542. [[ -e "$x" ]] && cp "$fwdir"/*.dtb "$R/boot/"
  543. break
  544. done
  545. mkimage -A arm -O linux -T script -C none -a 0 -e 0 \
  546. -n "BananaPro" \
  547. -d $fwdir/boot.script.bpi $R/boot/boot.scr.uimg
  548. ;;
  549. }
  550. cd "$R"
  551. dd if=$rnddev bs=16 count=1 >>etc/.rnd 2>/dev/null
  552. (( quiet )) || print Fixing up permissions...
  553. chown 0:0 tmp
  554. chmod 1777 tmp
  555. [[ -f usr/bin/sudo ]] && chmod 4755 usr/bin/sudo
  556. if (( grub )); then
  557. (( quiet )) || print Configuring GRUB2 bootloader...
  558. mkdir -p boot/grub
  559. (
  560. print set default=0
  561. print set timeout=1
  562. if (( serial )); then
  563. print serial --unit=0 --speed=$speed
  564. print terminal_output serial
  565. print terminal_input serial
  566. consargs="console=ttyS0,$speed console=tty0"
  567. else
  568. print terminal_output console
  569. print terminal_input console
  570. consargs="console=tty0"
  571. fi
  572. print
  573. print 'menuentry "GNU/Linux (OpenADK)" {'
  574. linuxargs="root=PARTUUID=$partuuid $consargs"
  575. (( panicreboot )) && linuxargs="$linuxargs panic=$panicreboot"
  576. print "\tlinux /boot/kernel $linuxargs"
  577. print '}'
  578. ) >boot/grub/grub.cfg
  579. fi
  580. (( quiet )) || print Finishing up...
  581. cd "$ADK_TOPDIR"
  582. umount_fs "$R"
  583. if (( datafssz )); then
  584. umount_fs $datapart
  585. fi
  586. rm -rf "$T"
  587. exit 0