install.sh 16 KB

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