1
0

install.sh 16 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608
  1. #!/usr/bin/env bash
  2. #-
  3. # Copyright © 2010-2015
  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|solidrun-imx6|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 ]]; 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 ]]; 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. partprobe $tgt
  197. mkfs.$3 "$1"
  198. }
  199. function tune_fs {
  200. tune2fs -c 0 -i 0 "$1"
  201. }
  202. ;;
  203. }
  204. mount |&
  205. while read -p dev rest; do
  206. eval [[ \$dev = $match ]] || continue
  207. print -u2 "Block device $tgt is in use, please umount first."
  208. exit 1
  209. done
  210. if (( !quiet )); then
  211. print "WARNING: This will overwrite $basedev - type Yes to continue!"
  212. read x
  213. [[ $x = Yes ]] || exit 0
  214. fi
  215. if ! T=$(mktemp -d /tmp/openadk.XXXXXXXXXX); then
  216. print -u2 Error creating temporary directory.
  217. exit 1
  218. fi
  219. if [[ $ostype != Darwin ]]; then
  220. R=$T/rootmnt
  221. B=$T/bootmnt
  222. D=$T/datamnt
  223. mkdir -p "$R" "$B" "$D"
  224. fi
  225. # get disk size
  226. dksz=$(dkgetsz "$tgt")
  227. # partition layouts:
  228. # n̲a̲m̲e̲ p̲a̲r̲t̲#̲0̲ p̲̲a̲r̲t̲#̲1̲ p̲̲a̲r̲t̲#̲2̲ p̲̲a̲r̲t̲#̲3̲
  229. # default: 0x83(system) 0x83(?data) -(unused) 0x88(cfgfs)
  230. # raspberry: 0x0B(boot) 0x83(system) 0x83(?data) 0x88(cfgfs)
  231. syspartno=0
  232. # sizes:
  233. # boot(raspberry) - fixed (100 MiB)
  234. # cfgfs - fixed (parameter, max. 16 MiB)
  235. # data - flexible (parameter)
  236. # system - everything else
  237. if [[ $target = raspberry-pi || $target = raspberry-pi2 ]]; then
  238. syspartno=1
  239. bootfssz=100
  240. if (( grub )); then
  241. print -u2 "Cannot combine GRUB with $target"
  242. rm -rf "$T"
  243. exit 1
  244. fi
  245. else
  246. bootfssz=0
  247. fi
  248. heads=64
  249. secs=32
  250. (( cyls = dksz / heads / secs ))
  251. if (( cyls < (bootfssz + cfgfs + datafssz + 2) )); then
  252. print -u2 "Size of $tgt is $dksz, this looks fishy?"
  253. rm -rf "$T"
  254. exit 1
  255. fi
  256. if stat -qs .>/dev/null 2>&1; then
  257. statcmd='stat -f %z' # BSD stat (or so we assume)
  258. else
  259. statcmd='stat -c %s' # GNU stat
  260. fi
  261. if (( grub )); then
  262. tar -xOf "$src" boot/grub/core.img >"$T/core.img"
  263. integer coreimgsz=$($statcmd "$T/core.img")
  264. else
  265. coreimgsz=65024
  266. fi
  267. if (( coreimgsz < 1024 )); then
  268. print -u2 core.img is probably too small: $coreimgsz
  269. rm -rf "$T"
  270. exit 1
  271. fi
  272. if (( coreimgsz > 65024 )); then
  273. print -u2 core.img is larger than 64K-512: $coreimgsz
  274. rm -rf "$T"
  275. exit 1
  276. fi
  277. (( coreendsec = (coreimgsz + 511) / 512 ))
  278. if [[ $basedev = /dev/svnd+([0-9]) ]]; then
  279. # BSD svnd0 mode: protect sector #1
  280. corestartsec=2
  281. (( ++coreendsec ))
  282. corepatchofs=$((0x614))
  283. else
  284. corestartsec=1
  285. corepatchofs=$((0x414))
  286. fi
  287. # partition offset: at least coreendsec+1 but aligned on a multiple of secs
  288. #(( partofs = ((coreendsec / secs) + 1) * secs ))
  289. # we just use 2048 all the time, since some loaders are longer
  290. partofs=2048
  291. if [[ $target = raspberry-pi || $target = raspberry-pi2 ]]; then
  292. (( spartofs = partofs + (100 * 2048) ))
  293. else
  294. spartofs=$partofs
  295. fi
  296. (( quiet )) || if (( grub )); then
  297. print Preparing MBR and GRUB2...
  298. else
  299. print Preparing MBR...
  300. fi
  301. dd if=/dev/zero of="$T/firsttrack" count=$partofs 2>/dev/null
  302. # add another MiB to clear the first partition
  303. dd if=/dev/zero bs=1048576 count=1 >>"$T/firsttrack" 2>/dev/null
  304. echo $corestartsec $coreendsec | mksh "$ADK_TOPDIR/scripts/bootgrub.mksh" \
  305. -A -g $((cyls - bootfssz - cfgfs - datafssz)):$heads:$secs -M 1:0x83 \
  306. -O $spartofs | dd of="$T/firsttrack" conv=notrunc 2>/dev/null
  307. (( grub )) && dd if="$T/core.img" of="$T/firsttrack" conv=notrunc \
  308. seek=$corestartsec 2>/dev/null
  309. # set partition where it can find /boot/grub
  310. (( grub )) && print -n '\0\0\0\0' | \
  311. dd of="$T/firsttrack" conv=notrunc bs=1 seek=$corepatchofs 2>/dev/null
  312. # create cfgfs partition (mostly taken from bootgrub.mksh)
  313. set -A thecode
  314. typeset -Uui8 thecode
  315. mbrpno=0
  316. set -A g_code $cyls $heads $secs
  317. (( psz = g_code[0] * g_code[1] * g_code[2] ))
  318. (( pofs = (cyls - cfgfs) * g_code[1] * g_code[2] ))
  319. set -A o_code # g_code equivalent for partition offset
  320. (( o_code[2] = pofs % g_code[2] + 1 ))
  321. (( o_code[1] = pofs / g_code[2] ))
  322. (( o_code[0] = o_code[1] / g_code[1] + 1 ))
  323. (( o_code[1] = o_code[1] % g_code[1] + 1 ))
  324. # boot flag; C/H/S offset
  325. thecode[mbrpno++]=0x00
  326. (( thecode[mbrpno++] = o_code[1] - 1 ))
  327. (( cylno = o_code[0] > 1024 ? 1023 : o_code[0] - 1 ))
  328. (( thecode[mbrpno++] = o_code[2] | ((cylno & 0x0300) >> 2) ))
  329. (( thecode[mbrpno++] = cylno & 0x00FF ))
  330. # partition type; C/H/S end
  331. (( thecode[mbrpno++] = 0x88 ))
  332. (( thecode[mbrpno++] = g_code[1] - 1 ))
  333. (( cylno = g_code[0] > 1024 ? 1023 : g_code[0] - 1 ))
  334. (( thecode[mbrpno++] = g_code[2] | ((cylno & 0x0300) >> 2) ))
  335. (( thecode[mbrpno++] = cylno & 0x00FF ))
  336. # partition offset, size (LBA)
  337. (( thecode[mbrpno++] = pofs & 0xFF ))
  338. (( thecode[mbrpno++] = (pofs >> 8) & 0xFF ))
  339. (( thecode[mbrpno++] = (pofs >> 16) & 0xFF ))
  340. (( thecode[mbrpno++] = (pofs >> 24) & 0xFF ))
  341. (( pssz = psz - pofs ))
  342. (( thecode[mbrpno++] = pssz & 0xFF ))
  343. (( thecode[mbrpno++] = (pssz >> 8) & 0xFF ))
  344. (( thecode[mbrpno++] = (pssz >> 16) & 0xFF ))
  345. (( thecode[mbrpno++] = (pssz >> 24) & 0xFF ))
  346. # write partition table entry
  347. ostr=
  348. curptr=0
  349. while (( curptr < 16 )); do
  350. ostr=$ostr\\0${thecode[curptr++]#8#}
  351. done
  352. print -n "$ostr" | \
  353. dd of="$T/firsttrack" conv=notrunc bs=1 seek=$((0x1EE)) 2>/dev/null
  354. if (( datafssz )); then
  355. # create data partition (copy of the above :)
  356. set -A thecode
  357. typeset -Uui8 thecode
  358. mbrpno=0
  359. set -A g_code $cyls $heads $secs
  360. (( psz = (cyls - cfgfs) * g_code[1] * g_code[2] ))
  361. (( pofs = (cyls - cfgfs - datafssz) * g_code[1] * g_code[2] ))
  362. set -A o_code # g_code equivalent for partition offset
  363. (( o_code[2] = pofs % g_code[2] + 1 ))
  364. (( o_code[1] = pofs / g_code[2] ))
  365. (( o_code[0] = o_code[1] / g_code[1] + 1 ))
  366. (( o_code[1] = o_code[1] % g_code[1] + 1 ))
  367. # boot flag; C/H/S offset
  368. thecode[mbrpno++]=0x00
  369. (( thecode[mbrpno++] = o_code[1] - 1 ))
  370. (( cylno = o_code[0] > 1024 ? 1023 : o_code[0] - 1 ))
  371. (( thecode[mbrpno++] = o_code[2] | ((cylno & 0x0300) >> 2) ))
  372. (( thecode[mbrpno++] = cylno & 0x00FF ))
  373. # partition type; C/H/S end
  374. (( thecode[mbrpno++] = 0x83 ))
  375. (( thecode[mbrpno++] = g_code[1] - 1 ))
  376. (( cylno = (g_code[0] - cfgfs) > 1024 ? 1023 : g_code[0] - cfgfs - 1 ))
  377. (( thecode[mbrpno++] = g_code[2] | ((cylno & 0x0300) >> 2) ))
  378. (( thecode[mbrpno++] = cylno & 0x00FF ))
  379. # partition offset, size (LBA)
  380. (( thecode[mbrpno++] = pofs & 0xFF ))
  381. (( thecode[mbrpno++] = (pofs >> 8) & 0xFF ))
  382. (( thecode[mbrpno++] = (pofs >> 16) & 0xFF ))
  383. (( thecode[mbrpno++] = (pofs >> 24) & 0xFF ))
  384. (( pssz = psz - pofs ))
  385. (( thecode[mbrpno++] = pssz & 0xFF ))
  386. (( thecode[mbrpno++] = (pssz >> 8) & 0xFF ))
  387. (( thecode[mbrpno++] = (pssz >> 16) & 0xFF ))
  388. (( thecode[mbrpno++] = (pssz >> 24) & 0xFF ))
  389. # write partition table entry
  390. ostr=
  391. curptr=0
  392. while (( curptr < 16 )); do
  393. ostr=$ostr\\0${thecode[curptr++]#8#}
  394. done
  395. print -n "$ostr" | \
  396. dd of="$T/firsttrack" conv=notrunc bs=1 seek=$((0x1CE)) 2>/dev/null
  397. fi
  398. if [[ $target = raspberry-pi || $target = raspberry-pi2 ]]; then
  399. # move system and data partition from #0/#1 to #1/#2
  400. dd if="$T/firsttrack" bs=1 skip=$((0x1BE)) count=32 of="$T/x" 2>/dev/null
  401. dd of="$T/firsttrack" conv=notrunc bs=1 seek=$((0x1CE)) if="$T/x" 2>/dev/null
  402. # create boot partition (copy of the above :)
  403. set -A thecode
  404. typeset -Uui8 thecode
  405. mbrpno=0
  406. set -A g_code $cyls $heads $secs
  407. psz=$spartofs
  408. pofs=$partofs
  409. set -A o_code # g_code equivalent for partition offset
  410. (( o_code[2] = pofs % g_code[2] + 1 ))
  411. (( o_code[1] = pofs / g_code[2] ))
  412. (( o_code[0] = o_code[1] / g_code[1] + 1 ))
  413. (( o_code[1] = o_code[1] % g_code[1] + 1 ))
  414. # boot flag; C/H/S offset
  415. thecode[mbrpno++]=0x00
  416. (( thecode[mbrpno++] = o_code[1] - 1 ))
  417. (( cylno = o_code[0] > 1024 ? 1023 : o_code[0] - 1 ))
  418. (( thecode[mbrpno++] = o_code[2] | ((cylno & 0x0300) >> 2) ))
  419. (( thecode[mbrpno++] = cylno & 0x00FF ))
  420. # partition type; C/H/S end
  421. (( thecode[mbrpno++] = 0x0B ))
  422. (( thecode[mbrpno++] = g_code[1] - 1 ))
  423. (( cylno = (spartofs / 2048) > 1024 ? 1023 : (spartofs / 2048) - 1 ))
  424. (( thecode[mbrpno++] = g_code[2] | ((cylno & 0x0300) >> 2) ))
  425. (( thecode[mbrpno++] = cylno & 0x00FF ))
  426. # partition offset, size (LBA)
  427. (( thecode[mbrpno++] = pofs & 0xFF ))
  428. (( thecode[mbrpno++] = (pofs >> 8) & 0xFF ))
  429. (( thecode[mbrpno++] = (pofs >> 16) & 0xFF ))
  430. (( thecode[mbrpno++] = (pofs >> 24) & 0xFF ))
  431. (( pssz = psz - pofs ))
  432. (( thecode[mbrpno++] = pssz & 0xFF ))
  433. (( thecode[mbrpno++] = (pssz >> 8) & 0xFF ))
  434. (( thecode[mbrpno++] = (pssz >> 16) & 0xFF ))
  435. (( thecode[mbrpno++] = (pssz >> 24) & 0xFF ))
  436. # write partition table entry
  437. ostr=
  438. curptr=0
  439. while (( curptr < 16 )); do
  440. ostr=$ostr\\0${thecode[curptr++]#8#}
  441. done
  442. print -n "$ostr" | \
  443. dd of="$T/firsttrack" conv=notrunc bs=1 seek=$((0x1BE)) 2>/dev/null
  444. fi
  445. # disk signature
  446. rnddev=/dev/urandom
  447. [[ -c /dev/arandom ]] && rnddev=/dev/arandom
  448. dd if=$rnddev bs=4 count=1 2>/dev/null | \
  449. dd of="$T/firsttrack" conv=notrunc bs=1 seek=$((0x1B8)) 2>/dev/null
  450. print -n '\0\0' | \
  451. dd of="$T/firsttrack" conv=notrunc bs=1 seek=$((0x1BC)) 2>/dev/null
  452. partuuid=$(dd if="$T/firsttrack" bs=1 count=4 skip=$((0x1B8)) 2>/dev/null | \
  453. hexdump -e '1/4 "%08x"')-0$((syspartno+1))
  454. ((keep)) || if (( datafssz )); then
  455. (( quiet )) || print Cleaning out data partition...
  456. dd if=/dev/zero of="$tgt" bs=1048576 count=1 seek=$((cyls - cfgfs - datafssz)) > /dev/null 2>&1
  457. fi
  458. (( quiet )) || print Cleaning out root partition...
  459. dd if=/dev/zero bs=1048576 of="$tgt" count=1 seek=$((spartofs / 2048)) > /dev/null 2>&1
  460. (( quiet )) || if (( grub )); then
  461. print Writing MBR and GRUB2 to target device... system PARTUUID=$partuuid
  462. else
  463. print Writing MBR to target device... system PARTUUID=$partuuid
  464. fi
  465. dd if="$T/firsttrack" of="$tgt" > /dev/null 2>&1
  466. fwdir=$(dirname "$src")
  467. case $target {
  468. (banana-pro)
  469. dd if="$fwdir/u-boot-sunxi-with-spl.bin" of="$tgt" bs=1024 seek=8 > /dev/null 2>&1
  470. ;;
  471. (solidrun-imx6)
  472. dd if="$fwdir/SPL" of="$tgt" bs=1024 seek=1 > /dev/null 2>&1
  473. dd if="$fwdir/u-boot.img" of="$tgt" bs=1024 seek=42 > /dev/null 2>&1
  474. ;;
  475. (raspberry-pi|raspberry-pi2)
  476. (( noformat )) || create_fs "$bootpart" ADKBOOT vfat
  477. ;;
  478. }
  479. (( noformat )) || create_fs "$rootpart" ADKROOT ext4
  480. (( noformat )) || tune_fs "$rootpart"
  481. (( quiet )) || print Extracting installation archive...
  482. mount_fs "$rootpart" "$R" ext4
  483. xz -dc "$src" | (cd "$R"; tar -xpf -)
  484. if (( datafssz )); then
  485. mkdir -m0755 "$R"/data
  486. ((keep)) || create_fs "$datapart" ADKDATA ext4
  487. ((keep)) || tune_fs "$datapart"
  488. case $target {
  489. (raspberry-pi|raspberry-pi2)
  490. echo "/dev/mmcblk0p3 /data ext4 rw 0 0" >> "$R"/etc/fstab
  491. ;;
  492. (banana-pro|solidrun-imx6)
  493. echo "/dev/mmcblk0p2 /data ext4 rw 0 0" >> "$R"/etc/fstab
  494. ;;
  495. }
  496. fi
  497. case $target {
  498. (raspberry-pi|raspberry-pi2)
  499. mount_fs "$bootpart" "$B" vfat
  500. for x in "$R"/boot/*; do
  501. [[ -e "$x" ]] && mv -f "$R"/boot/* "$B/"
  502. break
  503. done
  504. for x in "$fwdir"/*.dtb; do
  505. [[ -e "$x" ]] && cp "$fwdir"/*.dtb "$B/"
  506. break
  507. done
  508. mkdir "$B/"overlays
  509. for x in "$fwdir"/overlays/*.dtb; do
  510. [[ -e "$x" ]] && cp "$fwdir"/overlays/*.dtb "$B/"overlays
  511. break
  512. done
  513. umount_fs "$B"
  514. ;;
  515. (solidrun-imx6)
  516. for x in "$fwdir"/*.dtb; do
  517. [[ -e "$x" ]] && cp "$fwdir"/*.dtb "$R/boot/"
  518. break
  519. done
  520. ;;
  521. (banana-pro)
  522. for x in "$fwdir"/*.dtb; do
  523. [[ -e "$x" ]] && cp "$fwdir"/*.dtb "$R/boot/"
  524. break
  525. done
  526. mkimage -A arm -O linux -T script -C none -a 0 -e 0 \
  527. -n "BananaPro" \
  528. -d $fwdir/boot.script.bpi $R/boot/boot.scr.uimg
  529. ;;
  530. }
  531. cd "$R"
  532. dd if=$rnddev bs=16 count=1 >>etc/.rnd 2>/dev/null
  533. (( quiet )) || print Fixing up permissions...
  534. chown 0:0 tmp
  535. chmod 1777 tmp
  536. [[ -f usr/bin/sudo ]] && chmod 4755 usr/bin/sudo
  537. if (( grub )); then
  538. (( quiet )) || print Configuring GRUB2 bootloader...
  539. mkdir -p boot/grub
  540. (
  541. print set default=0
  542. print set timeout=1
  543. if (( serial )); then
  544. print serial --unit=0 --speed=$speed
  545. print terminal_output serial
  546. print terminal_input serial
  547. consargs="console=ttyS0,$speed console=tty0"
  548. else
  549. print terminal_output console
  550. print terminal_input console
  551. consargs="console=tty0"
  552. fi
  553. print
  554. print 'menuentry "GNU/Linux (OpenADK)" {'
  555. linuxargs="root=PARTUUID=$partuuid $consargs"
  556. (( panicreboot )) && linuxargs="$linuxargs panic=$panicreboot"
  557. print "\tlinux /boot/kernel $linuxargs"
  558. print '}'
  559. ) >boot/grub/grub.cfg
  560. fi
  561. (( quiet )) || print Finishing up...
  562. cd "$ADK_TOPDIR"
  563. umount_fs "$R"
  564. rm -rf "$T"
  565. exit 0