install.sh 16 KB

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