install.sh 16 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583
  1. #!/usr/bin/env bash
  2. #-
  3. # Copyright © 2010-2014
  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. function usage {
  57. cat >&2 <<EOF
  58. Syntax: $me [-f filesystem] [-c cfgfssize] [-d datafssize] [-n]
  59. [-p panictime] [±q] [-s serialspeed] [±t] <target> <device> <archive>
  60. Partition sizes are in MiB. Filesystem type is currently ignored (ext4).
  61. Defaults: -c 1 -p 10 -s 115200; -t = enable serial console
  62. EOF
  63. exit $1
  64. }
  65. while getopts "c:d:f:hnp:qs:t" ch; do
  66. case $ch {
  67. (c) if (( (cfgfs = OPTARG) < 0 || cfgfs > 16 )); then
  68. print -u2 "$me: -c $OPTARG out of bounds"
  69. exit 1
  70. fi ;;
  71. (d) if (( (datafssz = OPTARG) < 0 )); then
  72. print -u2 "$me: -d $OPTARG out of bounds"
  73. exit 1
  74. fi ;;
  75. (f) if [[ $OPTARG != @(ext2|ext3|ext4|xfs) ]]; then
  76. print -u2 "$me: filesystem $OPTARG invalid"
  77. exit 1
  78. fi
  79. fs=$OPTARG ;;
  80. (h) usage 0 ;;
  81. (p) if (( (panicreboot = OPTARG) < 0 || panicreboot > 300 )); then
  82. print -u2 "$me: -p $OPTARG out of bounds"
  83. exit 1
  84. fi ;;
  85. (q) quiet=1 ;;
  86. (+q) quiet=0 ;;
  87. (s) if [[ $OPTARG != @(96|192|384|576|1152)00 ]]; then
  88. print -u2 "$me: serial speed $OPTARG invalid"
  89. exit 1
  90. fi
  91. speed=$OPTARG ;;
  92. (n) noformat=1 ;;
  93. (t) serial=1 ;;
  94. (+t) serial=0 ;;
  95. (*) usage 1 ;;
  96. }
  97. done
  98. shift $((OPTIND - 1))
  99. (( $# == 3 )) || usage 1
  100. f=0
  101. case $ostype {
  102. (Linux)
  103. tools="bc mkfs.$fs tune2fs"
  104. ;;
  105. (Darwin)
  106. tools="bc diskutil"
  107. ;;
  108. (*)
  109. print -u2 Sorry, not ported to the OS "'$ostype'" yet.
  110. exit 1
  111. ;;
  112. }
  113. for tool in $tools; do
  114. print -n Checking if $tool is installed...
  115. if whence -p $tool >/dev/null; then
  116. print " okay"
  117. else
  118. print " failed"
  119. f=1
  120. fi
  121. done
  122. (( f )) && exit 1
  123. target=$1
  124. tgt=$2
  125. src=$3
  126. case $target {
  127. (raspberry-pi|solidrun-imx6|default) ;;
  128. (*)
  129. print -u2 "Unknown target '$target', exiting"
  130. exit 1 ;;
  131. }
  132. if [[ ! -b $tgt ]]; then
  133. print -u2 "'$tgt' is not a block device, exiting"
  134. exit 1
  135. fi
  136. if [[ ! -f $src ]]; then
  137. print -u2 "'$src' is not a file, exiting"
  138. exit 1
  139. fi
  140. (( quiet )) || print "Installing $src on $tgt."
  141. case $ostype {
  142. (Darwin)
  143. R=/Volumes/ADKROOT; diskutil unmount $R
  144. B=/Volumes/ADKBOOT; diskutil unmount $B
  145. D=/Volumes/ADKDATA; diskutil unmount $D
  146. basedev=$tgt
  147. rootpart=${basedev}s1
  148. datapart=${basedev}s2
  149. if [[ $target = raspberry-pi ]]; then
  150. bootpart=${basedev}s1
  151. rootpart=${basedev}s2
  152. datapart=${basedev}s3
  153. fi
  154. match=\'${basedev}\''?(s+([0-9]))'
  155. function mount_fs {
  156. }
  157. function umount_fs {
  158. diskutil unmount "$1"
  159. }
  160. function create_fs {
  161. if [[ $3 = ext4 ]]; then
  162. fstype=UFSD_EXTFS4
  163. fi
  164. if [[ $3 = vfat ]]; then
  165. fstype=fat32
  166. fi
  167. diskutil eraseVolume $fstype "$2" "$1"
  168. }
  169. ;;
  170. (Linux)
  171. basedev=$tgt
  172. rootpart=${basedev}1
  173. datapart=${basedev}2
  174. if [[ $target = raspberry-pi ]]; then
  175. bootpart=${basedev}1
  176. rootpart=${basedev}2
  177. datapart=${basedev}3
  178. fi
  179. match=\'${basedev}\''+([0-9])'
  180. function mount_fs {
  181. mount -t "$3" "$1" "$2"
  182. }
  183. function umount_fs {
  184. umount "$1"
  185. }
  186. function create_fs {
  187. mkfs.$3 "$1"
  188. tune2fs -c 0 -i 0 "$1"
  189. }
  190. ;;
  191. }
  192. mount |&
  193. while read -p dev rest; do
  194. eval [[ \$dev = $match ]] || continue
  195. print -u2 "Block device $tgt is in use, please umount first."
  196. exit 1
  197. done
  198. if (( !quiet )); then
  199. print "WARNING: This will overwrite $basedev - type Yes to continue!"
  200. read x
  201. [[ $x = Yes ]] || exit 0
  202. fi
  203. if ! T=$(mktemp -d /tmp/openadk.XXXXXXXXXX); then
  204. print -u2 Error creating temporary directory.
  205. exit 1
  206. fi
  207. if [[ $ostype != Darwin ]]; then
  208. R=$T/rootmnt
  209. B=$T/bootmnt
  210. D=$T/datamnt
  211. mkdir -p "$R" "$B" "$D"
  212. fi
  213. # get disk size
  214. dksz=$(dkgetsz "$tgt")
  215. # partition layouts:
  216. # n̲a̲m̲e̲ p̲a̲r̲t̲#̲0̲ p̲̲a̲r̲t̲#̲1̲ p̲̲a̲r̲t̲#̲2̲ p̲̲a̲r̲t̲#̲3̲
  217. # default: 0x83(system) 0x83(?data) -(unused) 0x88(cfgfs)
  218. # raspberry: 0x0B(boot) 0x83(system) 0x83(?data) 0x88(cfgfs)
  219. syspartno=0
  220. # sizes:
  221. # boot(raspberry) - fixed (100 MiB)
  222. # cfgfs - fixed (parameter, max. 16 MiB)
  223. # data - flexible (parameter)
  224. # system - everything else
  225. if [[ $target = raspberry-pi ]]; then
  226. syspartno=1
  227. bootfssz=100
  228. if (( grub )); then
  229. print -u2 "Cannot combine GRUB with $target"
  230. rm -rf "$T"
  231. exit 1
  232. fi
  233. else
  234. bootfssz=0
  235. fi
  236. heads=64
  237. secs=32
  238. (( cyls = dksz / heads / secs ))
  239. if (( cyls < (bootfssz + cfgfs + datafssz + 2) )); then
  240. print -u2 "Size of $tgt is $dksz, this looks fishy?"
  241. rm -rf "$T"
  242. exit 1
  243. fi
  244. if stat -qs .>/dev/null 2>&1; then
  245. statcmd='stat -f %z' # BSD stat (or so we assume)
  246. else
  247. statcmd='stat -c %s' # GNU stat
  248. fi
  249. if (( grub )); then
  250. tar -xOzf "$src" boot/grub/core.img >"$T/core.img"
  251. integer coreimgsz=$($statcmd "$T/core.img")
  252. else
  253. coreimgsz=65024
  254. fi
  255. if (( coreimgsz < 1024 )); then
  256. print -u2 core.img is probably too small: $coreimgsz
  257. rm -rf "$T"
  258. exit 1
  259. fi
  260. if (( coreimgsz > 65024 )); then
  261. print -u2 core.img is larger than 64K-512: $coreimgsz
  262. rm -rf "$T"
  263. exit 1
  264. fi
  265. (( coreendsec = (coreimgsz + 511) / 512 ))
  266. if [[ $basedev = /dev/svnd+([0-9]) ]]; then
  267. # BSD svnd0 mode: protect sector #1
  268. corestartsec=2
  269. (( ++coreendsec ))
  270. corepatchofs=$((0x614))
  271. else
  272. corestartsec=1
  273. corepatchofs=$((0x414))
  274. fi
  275. # partition offset: at least coreendsec+1 but aligned on a multiple of secs
  276. #(( partofs = ((coreendsec / secs) + 1) * secs ))
  277. # we just use 2048 all the time, since some loaders are longer
  278. partofs=2048
  279. if [[ $target = raspberry-pi ]]; then
  280. (( spartofs = partofs + (100 * 2048) ))
  281. else
  282. spartofs=$partofs
  283. fi
  284. (( quiet )) || if (( grub )); then
  285. print Preparing MBR and GRUB2...
  286. else
  287. print Preparing MBR...
  288. fi
  289. dd if=/dev/zero of="$T/firsttrack" count=$partofs 2>/dev/null
  290. # add another MiB to clear the first partition
  291. dd if=/dev/zero bs=1048576 count=1 >>"$T/firsttrack" 2>/dev/null
  292. echo $corestartsec $coreendsec | mksh "$ADK_TOPDIR/scripts/bootgrub.mksh" \
  293. -A -g $((cyls - bootfssz - cfgfs - datafssz)):$heads:$secs -M 1:0x83 \
  294. -O $spartofs | dd of="$T/firsttrack" conv=notrunc 2>/dev/null
  295. (( grub )) && dd if="$T/core.img" of="$T/firsttrack" conv=notrunc \
  296. seek=$corestartsec 2>/dev/null
  297. # set partition where it can find /boot/grub
  298. (( grub )) && print -n '\0\0\0\0' | \
  299. dd of="$T/firsttrack" conv=notrunc bs=1 seek=$corepatchofs 2>/dev/null
  300. # create cfgfs partition (mostly taken from bootgrub.mksh)
  301. set -A thecode
  302. typeset -Uui8 thecode
  303. mbrpno=0
  304. set -A g_code $cyls $heads $secs
  305. (( psz = g_code[0] * g_code[1] * g_code[2] ))
  306. (( pofs = (cyls - cfgfs) * g_code[1] * g_code[2] ))
  307. set -A o_code # g_code equivalent for partition offset
  308. (( o_code[2] = pofs % g_code[2] + 1 ))
  309. (( o_code[1] = pofs / g_code[2] ))
  310. (( o_code[0] = o_code[1] / g_code[1] + 1 ))
  311. (( o_code[1] = o_code[1] % g_code[1] + 1 ))
  312. # boot flag; C/H/S offset
  313. thecode[mbrpno++]=0x00
  314. (( thecode[mbrpno++] = o_code[1] - 1 ))
  315. (( cylno = o_code[0] > 1024 ? 1023 : o_code[0] - 1 ))
  316. (( thecode[mbrpno++] = o_code[2] | ((cylno & 0x0300) >> 2) ))
  317. (( thecode[mbrpno++] = cylno & 0x00FF ))
  318. # partition type; C/H/S end
  319. (( thecode[mbrpno++] = 0x88 ))
  320. (( thecode[mbrpno++] = g_code[1] - 1 ))
  321. (( cylno = g_code[0] > 1024 ? 1023 : g_code[0] - 1 ))
  322. (( thecode[mbrpno++] = g_code[2] | ((cylno & 0x0300) >> 2) ))
  323. (( thecode[mbrpno++] = cylno & 0x00FF ))
  324. # partition offset, size (LBA)
  325. (( thecode[mbrpno++] = pofs & 0xFF ))
  326. (( thecode[mbrpno++] = (pofs >> 8) & 0xFF ))
  327. (( thecode[mbrpno++] = (pofs >> 16) & 0xFF ))
  328. (( thecode[mbrpno++] = (pofs >> 24) & 0xFF ))
  329. (( pssz = psz - pofs ))
  330. (( thecode[mbrpno++] = pssz & 0xFF ))
  331. (( thecode[mbrpno++] = (pssz >> 8) & 0xFF ))
  332. (( thecode[mbrpno++] = (pssz >> 16) & 0xFF ))
  333. (( thecode[mbrpno++] = (pssz >> 24) & 0xFF ))
  334. # write partition table entry
  335. ostr=
  336. curptr=0
  337. while (( curptr < 16 )); do
  338. ostr=$ostr\\0${thecode[curptr++]#8#}
  339. done
  340. print -n "$ostr" | \
  341. dd of="$T/firsttrack" conv=notrunc bs=1 seek=$((0x1EE)) 2>/dev/null
  342. if (( datafssz )); then
  343. # create data partition (copy of the above :)
  344. set -A thecode
  345. typeset -Uui8 thecode
  346. mbrpno=0
  347. set -A g_code $cyls $heads $secs
  348. (( psz = (cyls - cfgfs) * g_code[1] * g_code[2] ))
  349. (( pofs = (cyls - cfgfs - datafssz) * g_code[1] * g_code[2] ))
  350. set -A o_code # g_code equivalent for partition offset
  351. (( o_code[2] = pofs % g_code[2] + 1 ))
  352. (( o_code[1] = pofs / g_code[2] ))
  353. (( o_code[0] = o_code[1] / g_code[1] + 1 ))
  354. (( o_code[1] = o_code[1] % g_code[1] + 1 ))
  355. # boot flag; C/H/S offset
  356. thecode[mbrpno++]=0x00
  357. (( thecode[mbrpno++] = o_code[1] - 1 ))
  358. (( cylno = o_code[0] > 1024 ? 1023 : o_code[0] - 1 ))
  359. (( thecode[mbrpno++] = o_code[2] | ((cylno & 0x0300) >> 2) ))
  360. (( thecode[mbrpno++] = cylno & 0x00FF ))
  361. # partition type; C/H/S end
  362. (( thecode[mbrpno++] = 0x83 ))
  363. (( thecode[mbrpno++] = g_code[1] - 1 ))
  364. (( cylno = (g_code[0] - cfgfs) > 1024 ? 1023 : g_code[0] - cfgfs - 1 ))
  365. (( thecode[mbrpno++] = g_code[2] | ((cylno & 0x0300) >> 2) ))
  366. (( thecode[mbrpno++] = cylno & 0x00FF ))
  367. # partition offset, size (LBA)
  368. (( thecode[mbrpno++] = pofs & 0xFF ))
  369. (( thecode[mbrpno++] = (pofs >> 8) & 0xFF ))
  370. (( thecode[mbrpno++] = (pofs >> 16) & 0xFF ))
  371. (( thecode[mbrpno++] = (pofs >> 24) & 0xFF ))
  372. (( pssz = psz - pofs ))
  373. (( thecode[mbrpno++] = pssz & 0xFF ))
  374. (( thecode[mbrpno++] = (pssz >> 8) & 0xFF ))
  375. (( thecode[mbrpno++] = (pssz >> 16) & 0xFF ))
  376. (( thecode[mbrpno++] = (pssz >> 24) & 0xFF ))
  377. # write partition table entry
  378. ostr=
  379. curptr=0
  380. while (( curptr < 16 )); do
  381. ostr=$ostr\\0${thecode[curptr++]#8#}
  382. done
  383. print -n "$ostr" | \
  384. dd of="$T/firsttrack" conv=notrunc bs=1 seek=$((0x1CE)) 2>/dev/null
  385. fi
  386. if [[ $target = raspberry-pi ]]; then
  387. # move system and data partition from #0/#1 to #1/#2
  388. dd if="$T/firsttrack" bs=1 skip=$((0x1BE)) count=32 of="$T/x" 2>/dev/null
  389. dd of="$T/firsttrack" conv=notrunc bs=1 seek=$((0x1CE)) if="$T/x" 2>/dev/null
  390. # create boot partition (copy of the above :)
  391. set -A thecode
  392. typeset -Uui8 thecode
  393. mbrpno=0
  394. set -A g_code $cyls $heads $secs
  395. psz=$spartofs
  396. pofs=$partofs
  397. set -A o_code # g_code equivalent for partition offset
  398. (( o_code[2] = pofs % g_code[2] + 1 ))
  399. (( o_code[1] = pofs / g_code[2] ))
  400. (( o_code[0] = o_code[1] / g_code[1] + 1 ))
  401. (( o_code[1] = o_code[1] % g_code[1] + 1 ))
  402. # boot flag; C/H/S offset
  403. thecode[mbrpno++]=0x00
  404. (( thecode[mbrpno++] = o_code[1] - 1 ))
  405. (( cylno = o_code[0] > 1024 ? 1023 : o_code[0] - 1 ))
  406. (( thecode[mbrpno++] = o_code[2] | ((cylno & 0x0300) >> 2) ))
  407. (( thecode[mbrpno++] = cylno & 0x00FF ))
  408. # partition type; C/H/S end
  409. (( thecode[mbrpno++] = 0x0B ))
  410. (( thecode[mbrpno++] = g_code[1] - 1 ))
  411. (( cylno = (spartofs / 2048) > 1024 ? 1023 : (spartofs / 2048) - 1 ))
  412. (( thecode[mbrpno++] = g_code[2] | ((cylno & 0x0300) >> 2) ))
  413. (( thecode[mbrpno++] = cylno & 0x00FF ))
  414. # partition offset, size (LBA)
  415. (( thecode[mbrpno++] = pofs & 0xFF ))
  416. (( thecode[mbrpno++] = (pofs >> 8) & 0xFF ))
  417. (( thecode[mbrpno++] = (pofs >> 16) & 0xFF ))
  418. (( thecode[mbrpno++] = (pofs >> 24) & 0xFF ))
  419. (( pssz = psz - pofs ))
  420. (( thecode[mbrpno++] = pssz & 0xFF ))
  421. (( thecode[mbrpno++] = (pssz >> 8) & 0xFF ))
  422. (( thecode[mbrpno++] = (pssz >> 16) & 0xFF ))
  423. (( thecode[mbrpno++] = (pssz >> 24) & 0xFF ))
  424. # write partition table entry
  425. ostr=
  426. curptr=0
  427. while (( curptr < 16 )); do
  428. ostr=$ostr\\0${thecode[curptr++]#8#}
  429. done
  430. print -n "$ostr" | \
  431. dd of="$T/firsttrack" conv=notrunc bs=1 seek=$((0x1BE)) 2>/dev/null
  432. fi
  433. # disk signature
  434. rnddev=/dev/urandom
  435. [[ -c /dev/arandom ]] && rnddev=/dev/arandom
  436. dd if=$rnddev bs=4 count=1 2>/dev/null | \
  437. dd of="$T/firsttrack" conv=notrunc bs=1 seek=$((0x1B8)) 2>/dev/null
  438. print -n '\0\0' | \
  439. dd of="$T/firsttrack" conv=notrunc bs=1 seek=$((0x1BC)) 2>/dev/null
  440. partuuid=$(dd if="$T/firsttrack" bs=1 count=4 skip=$((0x1B8)) 2>/dev/null | \
  441. hexdump -e '1/4 "%08x"')-0$((syspartno+1))
  442. (( quiet )) || print Cleaning out partitions...
  443. (( datafssz )) && dd if=/dev/zero of="$tgt" bs=1048576 count=1 \
  444. seek=$((cyls - cfgfs - datafssz)) > /dev/null 2>&1
  445. dd if=/dev/zero bs=1048576 of="$tgt" count=1 seek=$((spartofs / 2048)) > /dev/null 2>&1
  446. (( quiet )) || if (( grub )); then
  447. print Writing MBR and GRUB2 to target device... system PARTUUID=$partuuid
  448. else
  449. print Writing MBR to target device... system PARTUUID=$partuuid
  450. fi
  451. dd if="$T/firsttrack" of="$tgt" > /dev/null 2>&1
  452. case $target {
  453. (solidrun-imx6)
  454. fwdir=$(dirname "$src")
  455. dd if="$fwdir/SPL" of="$tgt" bs=1024 seek=1 > /dev/null 2>&1
  456. dd if="$fwdir/u-boot.img" of="$tgt" bs=1024 seek=42 > /dev/null 2>&1
  457. ;;
  458. (raspberry-pi)
  459. (( quiet )) || print "Creating filesystem on ${bootpart}..."
  460. (( noformat )) || create_fs "$bootpart" ADKBOOT vfat
  461. ;;
  462. }
  463. (( quiet )) || print "Creating filesystem on ${rootpart}..."
  464. (( noformat )) || create_fs "$rootpart" ADKROOT ext4
  465. (( quiet )) || print Extracting installation archive...
  466. mount_fs "$rootpart" "$R" ext4
  467. gzip -dc "$src" | (cd "$R"; tar -xpf -)
  468. if (( datafssz )); then
  469. (( quiet )) || print "Creating filesystem on ${datapart}..."
  470. mkdir -m0755 "$R"/data
  471. (( noformat )) || create_fs "$datapart" ADKDATA ext4
  472. mount_fs "$datapart" "$D" ext4
  473. mkdir -m0755 "$D/mpd" "$D/xbmc"
  474. umount_fs "$D"
  475. case $target {
  476. (raspberry-pi)
  477. echo "/dev/mmcblk0p3 /data ext4 rw 0 0" >> "$R"/etc/fstab
  478. ;;
  479. (solidrun-imx6)
  480. echo "/dev/mmcblk0p3 /data ext4 rw 0 0" >> "$R"/etc/fstab
  481. ;;
  482. }
  483. fi
  484. case $target {
  485. (raspberry-pi)
  486. mount_fs "$bootpart" "$B" vfat
  487. for x in "$R"/boot/.*; do
  488. [[ -e "$x" ]] && mv -f "$R"/boot/.* "$B/"
  489. break
  490. done
  491. for x in "$R"/boot/*; do
  492. [[ -e "$x" ]] && mv -f "$R"/boot/* "$B/"
  493. break
  494. done
  495. umount_fs "$B"
  496. ;;
  497. (solidrun-imx6)
  498. for x in "$fwdir"/*.dtb; do
  499. [[ -e "$x" ]] && cp "$fwdir"/*.dtb "$R/boot/"
  500. break
  501. done
  502. ;;
  503. }
  504. cd "$R"
  505. dd if=$rnddev bs=16 count=1 >>etc/.rnd 2>/dev/null
  506. (( quiet )) || print Fixing up permissions...
  507. chown 0:0 tmp
  508. chmod 1777 tmp
  509. [[ -f usr/bin/sudo ]] && chmod 4755 usr/bin/sudo
  510. if (( grub )); then
  511. (( quiet )) || print Configuring GRUB2 bootloader...
  512. mkdir -p boot/grub
  513. (
  514. print set default=0
  515. print set timeout=1
  516. if (( serial )); then
  517. print serial --unit=0 --speed=$speed
  518. print terminal_output serial
  519. print terminal_input serial
  520. consargs="console=ttyS0,$speed console=tty0"
  521. else
  522. print terminal_output console
  523. print terminal_input console
  524. consargs="console=tty0"
  525. fi
  526. print
  527. print 'menuentry "GNU/Linux (OpenADK)" {'
  528. linuxargs="root=PARTUUID=$partuuid $consargs"
  529. (( panicreboot )) && linuxargs="$linuxargs panic=$panicreboot"
  530. print "\tlinux /boot/kernel $linuxargs"
  531. print '}'
  532. ) >boot/grub/grub.cfg
  533. fi
  534. (( quiet )) || print Finishing up...
  535. cd "$ADK_TOPDIR"
  536. sync
  537. umount_fs "$R"
  538. sync
  539. rm -rf "$T"
  540. exit 0