frosted: add ADK prefix, separate kernel/userland in the menu
[openadk.git] / scripts / install.sh
blobe843e66a46d94ae84a6baa8188a441bf7c36f643
1 #!/usr/bin/env bash
2 #-
3 # Copyright © 2010-2017
4 # Waldemar Brodkorb <wbx@openadk.org>
5 # Thorsten Glaser <tg@mirbsd.org>
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.
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.
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.
26 # Prepare a USB stick or CF/SD/MMC card or hard disc for installation
27 # of OpenADK
29 ADK_TOPDIR=$(pwd)
30 HOST=$(gcc -dumpmachine)
31 me=$0
33 case :$PATH: in
34 (*:$ADK_TOPDIR/host_$HOST/usr/bin:*) ;;
35 (*) export PATH=$PATH:$ADK_TOPDIR/host_$HOST/usr/bin ;;
36 esac
38 test -n "$KSH_VERSION" || exec mksh "$me" "$@"
39 if test -z "$KSH_VERSION"; then
40 echo >&2 Fatal error: could not run myself with mksh!
41 exit 255
44 ### run with mksh from here onwards ###
46 me=${me##*/}
48 if (( USER_ID )); then
49 print -u2 Installation is only possible as root!
50 exit 1
53 ADK_TOPDIR=$(realpath .)
54 ostype=$(uname -s)
56 fs=ext4
57 cfgfs=1
58 datafssz=0
59 noformat=0
60 quiet=0
61 serial=0
62 speed=115200
63 panicreboot=10
64 keep=0
65 grub=0
67 function usage {
68 cat >&2 <<EOF
69 Syntax: $me [-f filesystem] [-c cfgfssize] [-d datafssize] [-k] [-n] [-g]
70 [-p panictime] [±q] [-s serialspeed] [±t] <target> <device> <archive>
71 Partition sizes are in MiB. Filesystem type is currently ignored (ext4).
72 To keep filesystem on data partition use -k.
73 Use -n to not format boot/root partition.
74 Defaults: -c 1 -p 10 -s 115200; -t = enable serial console
75 EOF
76 exit $1
79 while getopts "c:d:f:ghknp:qs:t" ch; do
80 case $ch {
81 (c) if (( (cfgfs = OPTARG) < 0 || cfgfs > 16 )); then
82 print -u2 "$me: -c $OPTARG out of bounds"
83 exit 1
84 fi ;;
85 (d) if (( (datafssz = OPTARG) < 0 )); then
86 print -u2 "$me: -d $OPTARG out of bounds"
87 exit 1
88 fi ;;
89 (f) if [[ $OPTARG != @(ext2|ext3|ext4|xfs) ]]; then
90 print -u2 "$me: filesystem $OPTARG invalid"
91 exit 1
93 fs=$OPTARG ;;
94 (h) usage 0 ;;
95 (k) keep=1 ;;
96 (g) grub=1 ;;
97 (p) if (( (panicreboot = OPTARG) < 0 || panicreboot > 300 )); then
98 print -u2 "$me: -p $OPTARG out of bounds"
99 exit 1
100 fi ;;
101 (q) quiet=1 ;;
102 (+q) quiet=0 ;;
103 (s) if [[ $OPTARG != @(96|192|384|576|1152)00 ]]; then
104 print -u2 "$me: serial speed $OPTARG invalid"
105 exit 1
107 speed=$OPTARG ;;
108 (n) noformat=1 ;;
109 (t) serial=1 ;;
110 (+t) serial=0 ;;
111 (*) usage 1 ;;
113 done
114 shift $((OPTIND - 1))
116 (( $# == 3 )) || usage 1
119 case $ostype {
120 (Linux)
121 tools="bc mkfs.ext4 mkfs.vfat tune2fs partprobe"
123 (Darwin)
124 tools="bc diskutil"
127 print -u2 Sorry, not ported to the OS "'$ostype'" yet.
128 exit 1
131 for tool in $tools; do
132 print -n Checking if $tool is installed...
133 if whence -p $tool >/dev/null; then
134 print " okay"
135 else
136 print " failed"
139 done
140 (( f )) && exit 1
142 target=$1
143 tgt=$2
144 src=$3
146 case $target {
147 (banana-pro|orange-pi0|pcengines-apu|phytec-wega|raspberry-pi|raspberry-pi0|raspberry-pi2|raspberry-pi3|raspberry-pi3-64|solidrun-imx6|solidrun-clearfog|default) ;;
149 print -u2 "Unknown target '$target', exiting"
150 exit 1 ;;
152 if [[ ! -b $tgt ]]; then
153 print -u2 "'$tgt' is not a block device, exiting"
154 exit 1
156 if [[ ! -f $src ]]; then
157 print -u2 "'$src' is not a file, exiting"
158 exit 1
160 (( quiet )) || print "Installing $src on $tgt."
162 case $ostype {
163 (Darwin)
164 R=/Volumes/ADKROOT; diskutil unmount $R
165 B=/Volumes/ADKBOOT; diskutil unmount $B
166 D=/Volumes/ADKDATA; diskutil unmount $D
167 basedev=$tgt
168 rootpart=${basedev}s1
169 datapart=${basedev}s2
170 if [[ $target = raspberry-pi || $target = raspberry-pi0 || $target = raspberry-pi2 || $target = raspberry-pi3 || $target = raspberry-pi3-64 || $target = phytec-wega ]]; then
171 bootpart=${basedev}s1
172 rootpart=${basedev}s2
173 datapart=${basedev}s3
175 match=\'${basedev}\''?(s+([0-9]))'
176 function mount_fs {
178 function umount_fs {
179 (( quiet )) || print "Unmounting filesystem on ${1}..."
180 diskutil unmount "$1"
182 function create_fs {
183 (( quiet )) || print "Creating filesystem on ${2}..."
184 if [[ $3 = ext4 ]]; then
185 fstype=UFSD_EXTFS4
187 if [[ $3 = vfat ]]; then
188 fstype=fat32
190 diskutil eraseVolume $fstype "$2" "$1"
192 function tune_fs {
195 (Linux)
196 basedev=$tgt
197 partitionsep=""
198 if [[ $basedev = /dev/loop* ]]; then
199 (( quiet )) || print "${tgt} is a loop device"
200 partitionsep=p
203 rootpart=${basedev}${partitionsep}1
204 datapart=${basedev}${partitionsep}2
205 if [[ $target = raspberry-pi || $target = raspberry-pi0 || $target = raspberry-pi2 || $target = raspberry-pi3 || $target = raspberry-pi3-64 ]]; then
206 bootpart=${basedev}${partitionsep}1
207 rootpart=${basedev}${partitionsep}2
208 datapart=${basedev}${partitionsep}3
211 match=\'${basedev}${partitionsep}\''+([0-9])'
212 function mount_fs {
213 (( quiet )) || print "Mounting filesystem on ${1}..."
214 mount -t "$3" "$1" "$2"
216 function umount_fs {
217 (( quiet )) || print "Unmounting filesystem on ${1}..."
218 umount "$1"
220 function create_fs {
221 (( quiet )) || print "Creating filesystem on ${1}..."
222 mkfs.$3 "$1"
224 function tune_fs {
225 tune2fs -c 0 -i 0 "$1"
230 mount |&
231 while read -p dev rest; do
232 eval [[ \$dev = $match ]] || continue
233 print -u2 "Block device $tgt is in use, please umount first."
234 exit 1
235 done
237 if (( !quiet )); then
238 print "WARNING: This will overwrite $basedev - type Yes to continue!"
239 read x
240 [[ $x = Yes ]] || exit 0
243 if ! T=$(mktemp -d /tmp/openadk.XXXXXXXXXX); then
244 print -u2 Error creating temporary directory.
245 exit 1
247 if [[ $ostype != Darwin ]]; then
248 R=$T/rootmnt
249 B=$T/bootmnt
250 D=$T/datamnt
251 mkdir -p "$R" "$B" "$D"
254 # get disk size
255 dksz=$(dkgetsz "$tgt")
257 # partition layouts:
258 # n̲a̲m̲e̲ p̲a̲r̲t̲#̲0̲ p̲̲a̲r̲t̲#̲1̲ p̲̲a̲r̲t̲#̲2̲ p̲̲a̲r̲t̲#̲3̲
259 # default: 0x83(system) 0x83(?data) -(unused) 0x88(cfgfs)
260 # raspberry: 0x0B(boot) 0x83(system) 0x83(?data) 0x88(cfgfs)
262 syspartno=0
264 # sizes:
265 # boot(raspberry) - fixed (100 MiB)
266 # cfgfs - fixed (parameter, max. 16 MiB)
267 # data - flexible (parameter)
268 # system - everything else
270 if [[ $target = raspberry-pi || $target = raspberry-pi0 || $target = raspberry-pi2 || $target = raspberry-pi3 || $target = raspberry-pi3-64 || $target = phytec-wega ]]; then
271 syspartno=1
272 bootfssz=100
273 if (( grub )); then
274 print -u2 "Cannot combine GRUB with $target"
275 rm -rf "$T"
276 exit 1
278 else
279 bootfssz=0
282 heads=64
283 secs=32
284 (( cyls = dksz / heads / secs ))
285 if (( cyls < (bootfssz + cfgfs + datafssz + 2) )); then
286 print -u2 "Size of $tgt is $dksz, this looks fishy?"
287 rm -rf "$T"
288 exit 1
291 if stat -qs .>/dev/null 2>&1; then
292 statcmd='stat -f %z' # BSD stat (or so we assume)
293 else
294 statcmd='stat -c %s' # GNU stat
297 if (( grub )); then
298 tar -xOf "$src" boot/grub/core.img >"$T/core.img"
299 integer coreimgsz=$($statcmd "$T/core.img")
300 else
301 coreimgsz=65024
303 if (( coreimgsz < 1024 )); then
304 print -u2 core.img is probably too small: $coreimgsz
305 rm -rf "$T"
306 exit 1
308 if (( coreimgsz > 65024 )); then
309 print -u2 core.img is larger than 64K-512: $coreimgsz
310 rm -rf "$T"
311 exit 1
313 (( coreendsec = (coreimgsz + 511) / 512 ))
314 if [[ $basedev = /dev/svnd+([0-9]) ]]; then
315 # BSD svnd0 mode: protect sector #1
316 corestartsec=2
317 (( ++coreendsec ))
318 corepatchofs=$((0x614))
319 else
320 corestartsec=1
321 corepatchofs=$((0x414))
323 # partition offset: at least coreendsec+1 but aligned on a multiple of secs
324 #(( partofs = ((coreendsec / secs) + 1) * secs ))
325 # we just use 2048 all the time, since some loaders are longer
326 partofs=2048
327 if [[ $target = raspberry-pi || $target = raspberry-pi0 || $target = raspberry-pi2 || $target = raspberry-pi3 || $target = raspberry-pi3-64 || $target = phytec-wega ]]; then
328 (( spartofs = partofs + (100 * 2048) ))
329 else
330 spartofs=$partofs
333 (( quiet )) || if (( grub )); then
334 print Preparing MBR and GRUB2...
335 else
336 print Preparing MBR...
338 dd if=/dev/zero of="$T/firsttrack" count=$partofs 2>/dev/null
339 # add another MiB to clear the first partition
340 dd if=/dev/zero bs=1048576 count=1 >>"$T/firsttrack" 2>/dev/null
341 echo $corestartsec $coreendsec | mksh "$ADK_TOPDIR/scripts/bootgrub.mksh" \
342 -A -g $((cyls - bootfssz - cfgfs - datafssz)):$heads:$secs -M 1:0x83 \
343 -O $spartofs | dd of="$T/firsttrack" conv=notrunc 2>/dev/null
344 (( grub )) && dd if="$T/core.img" of="$T/firsttrack" conv=notrunc \
345 seek=$corestartsec 2>/dev/null
346 # set partition where it can find /boot/grub
347 (( grub )) && print -n '\0\0\0\0' | \
348 dd of="$T/firsttrack" conv=notrunc bs=1 seek=$corepatchofs 2>/dev/null
350 # create cfgfs partition (mostly taken from bootgrub.mksh)
351 set -A thecode
352 typeset -Uui8 thecode
353 mbrpno=0
354 set -A g_code $cyls $heads $secs
355 (( psz = g_code[0] * g_code[1] * g_code[2] ))
356 (( pofs = (cyls - cfgfs) * g_code[1] * g_code[2] ))
357 set -A o_code # g_code equivalent for partition offset
358 (( o_code[2] = pofs % g_code[2] + 1 ))
359 (( o_code[1] = pofs / g_code[2] ))
360 (( o_code[0] = o_code[1] / g_code[1] + 1 ))
361 (( o_code[1] = o_code[1] % g_code[1] + 1 ))
362 # boot flag; C/H/S offset
363 thecode[mbrpno++]=0x00
364 (( thecode[mbrpno++] = o_code[1] - 1 ))
365 (( cylno = o_code[0] > 1024 ? 1023 : o_code[0] - 1 ))
366 (( thecode[mbrpno++] = o_code[2] | ((cylno & 0x0300) >> 2) ))
367 (( thecode[mbrpno++] = cylno & 0x00FF ))
368 # partition type; C/H/S end
369 (( thecode[mbrpno++] = 0x88 ))
370 (( thecode[mbrpno++] = g_code[1] - 1 ))
371 (( cylno = g_code[0] > 1024 ? 1023 : g_code[0] - 1 ))
372 (( thecode[mbrpno++] = g_code[2] | ((cylno & 0x0300) >> 2) ))
373 (( thecode[mbrpno++] = cylno & 0x00FF ))
374 # partition offset, size (LBA)
375 (( thecode[mbrpno++] = pofs & 0xFF ))
376 (( thecode[mbrpno++] = (pofs >> 8) & 0xFF ))
377 (( thecode[mbrpno++] = (pofs >> 16) & 0xFF ))
378 (( thecode[mbrpno++] = (pofs >> 24) & 0xFF ))
379 (( pssz = psz - pofs ))
380 (( thecode[mbrpno++] = pssz & 0xFF ))
381 (( thecode[mbrpno++] = (pssz >> 8) & 0xFF ))
382 (( thecode[mbrpno++] = (pssz >> 16) & 0xFF ))
383 (( thecode[mbrpno++] = (pssz >> 24) & 0xFF ))
384 # write partition table entry
385 ostr=
386 curptr=0
387 while (( curptr < 16 )); do
388 ostr=$ostr\\0${thecode[curptr++]#8#}
389 done
390 print -n "$ostr" | \
391 dd of="$T/firsttrack" conv=notrunc bs=1 seek=$((0x1EE)) 2>/dev/null
393 if (( datafssz )); then
394 # create data partition (copy of the above :)
395 set -A thecode
396 typeset -Uui8 thecode
397 mbrpno=0
398 set -A g_code $cyls $heads $secs
399 (( psz = (cyls - cfgfs) * g_code[1] * g_code[2] ))
400 (( pofs = (cyls - cfgfs - datafssz) * g_code[1] * g_code[2] ))
401 set -A o_code # g_code equivalent for partition offset
402 (( o_code[2] = pofs % g_code[2] + 1 ))
403 (( o_code[1] = pofs / g_code[2] ))
404 (( o_code[0] = o_code[1] / g_code[1] + 1 ))
405 (( o_code[1] = o_code[1] % g_code[1] + 1 ))
406 # boot flag; C/H/S offset
407 thecode[mbrpno++]=0x00
408 (( thecode[mbrpno++] = o_code[1] - 1 ))
409 (( cylno = o_code[0] > 1024 ? 1023 : o_code[0] - 1 ))
410 (( thecode[mbrpno++] = o_code[2] | ((cylno & 0x0300) >> 2) ))
411 (( thecode[mbrpno++] = cylno & 0x00FF ))
412 # partition type; C/H/S end
413 (( thecode[mbrpno++] = 0x83 ))
414 (( thecode[mbrpno++] = g_code[1] - 1 ))
415 (( cylno = (g_code[0] - cfgfs) > 1024 ? 1023 : g_code[0] - cfgfs - 1 ))
416 (( thecode[mbrpno++] = g_code[2] | ((cylno & 0x0300) >> 2) ))
417 (( thecode[mbrpno++] = cylno & 0x00FF ))
418 # partition offset, size (LBA)
419 (( thecode[mbrpno++] = pofs & 0xFF ))
420 (( thecode[mbrpno++] = (pofs >> 8) & 0xFF ))
421 (( thecode[mbrpno++] = (pofs >> 16) & 0xFF ))
422 (( thecode[mbrpno++] = (pofs >> 24) & 0xFF ))
423 (( pssz = psz - pofs ))
424 (( thecode[mbrpno++] = pssz & 0xFF ))
425 (( thecode[mbrpno++] = (pssz >> 8) & 0xFF ))
426 (( thecode[mbrpno++] = (pssz >> 16) & 0xFF ))
427 (( thecode[mbrpno++] = (pssz >> 24) & 0xFF ))
428 # write partition table entry
429 ostr=
430 curptr=0
431 while (( curptr < 16 )); do
432 ostr=$ostr\\0${thecode[curptr++]#8#}
433 done
434 print -n "$ostr" | \
435 dd of="$T/firsttrack" conv=notrunc bs=1 seek=$((0x1CE)) 2>/dev/null
438 if [[ $target = raspberry-pi || $target = raspberry-pi0 || $target = raspberry-pi2 || $target = raspberry-pi3 || $target = raspberry-pi3-64 || $target = phytec-wega ]]; then
439 # move system and data partition from #0/#1 to #1/#2
440 dd if="$T/firsttrack" bs=1 skip=$((0x1BE)) count=32 of="$T/x" 2>/dev/null
441 dd of="$T/firsttrack" conv=notrunc bs=1 seek=$((0x1CE)) if="$T/x" 2>/dev/null
442 # create boot partition (copy of the above :)
443 set -A thecode
444 typeset -Uui8 thecode
445 mbrpno=0
446 set -A g_code $cyls $heads $secs
447 psz=$spartofs
448 pofs=$partofs
449 set -A o_code # g_code equivalent for partition offset
450 (( o_code[2] = pofs % g_code[2] + 1 ))
451 (( o_code[1] = pofs / g_code[2] ))
452 (( o_code[0] = o_code[1] / g_code[1] + 1 ))
453 (( o_code[1] = o_code[1] % g_code[1] + 1 ))
454 # boot flag; C/H/S offset
455 thecode[mbrpno++]=0x00
456 (( thecode[mbrpno++] = o_code[1] - 1 ))
457 (( cylno = o_code[0] > 1024 ? 1023 : o_code[0] - 1 ))
458 (( thecode[mbrpno++] = o_code[2] | ((cylno & 0x0300) >> 2) ))
459 (( thecode[mbrpno++] = cylno & 0x00FF ))
460 # partition type; C/H/S end
461 (( thecode[mbrpno++] = 0x0B ))
462 (( thecode[mbrpno++] = g_code[1] - 1 ))
463 (( cylno = (spartofs / 2048) > 1024 ? 1023 : (spartofs / 2048) - 1 ))
464 (( thecode[mbrpno++] = g_code[2] | ((cylno & 0x0300) >> 2) ))
465 (( thecode[mbrpno++] = cylno & 0x00FF ))
466 # partition offset, size (LBA)
467 (( thecode[mbrpno++] = pofs & 0xFF ))
468 (( thecode[mbrpno++] = (pofs >> 8) & 0xFF ))
469 (( thecode[mbrpno++] = (pofs >> 16) & 0xFF ))
470 (( thecode[mbrpno++] = (pofs >> 24) & 0xFF ))
471 (( pssz = psz - pofs ))
472 (( thecode[mbrpno++] = pssz & 0xFF ))
473 (( thecode[mbrpno++] = (pssz >> 8) & 0xFF ))
474 (( thecode[mbrpno++] = (pssz >> 16) & 0xFF ))
475 (( thecode[mbrpno++] = (pssz >> 24) & 0xFF ))
476 # write partition table entry
477 ostr=
478 curptr=0
479 while (( curptr < 16 )); do
480 ostr=$ostr\\0${thecode[curptr++]#8#}
481 done
482 print -n "$ostr" | \
483 dd of="$T/firsttrack" conv=notrunc bs=1 seek=$((0x1BE)) 2>/dev/null
486 # disk signature
487 rnddev=/dev/urandom
488 [[ -c /dev/arandom ]] && rnddev=/dev/arandom
489 dd if=$rnddev bs=4 count=1 2>/dev/null | \
490 dd of="$T/firsttrack" conv=notrunc bs=1 seek=$((0x1B8)) 2>/dev/null
491 print -n '\0\0' | \
492 dd of="$T/firsttrack" conv=notrunc bs=1 seek=$((0x1BC)) 2>/dev/null
493 partuuid=$(dd if="$T/firsttrack" bs=1 count=4 skip=$((0x1B8)) 2>/dev/null | \
494 hexdump -e '1/4 "%08x"')-0$((syspartno+1))
496 ((keep)) || if (( datafssz )); then
497 (( quiet )) || print Cleaning out data partition...
498 dd if=/dev/zero of="$tgt" bs=1048576 count=1 seek=$((cyls - cfgfs - datafssz)) > /dev/null 2>&1
500 (( quiet )) || print Cleaning out root partition...
501 dd if=/dev/zero bs=1048576 of="$tgt" count=1 seek=$((spartofs / 2048)) > /dev/null 2>&1
503 (( quiet )) || if (( grub )); then
504 print Writing MBR and GRUB2 to target device... system PARTUUID=$partuuid
505 else
506 print Writing MBR to target device... system PARTUUID=$partuuid
508 dd if="$T/firsttrack" of="$tgt" > /dev/null 2>&1
510 if [[ $ostype = Linux ]]; then
511 echo partprobe $tgt
512 partprobe -s $tgt
513 sync
514 fdisk -l $tgt
515 ls -la ${tgt}*
518 fwdir=$(dirname "$src")
520 case $target {
521 (banana-pro|orange-pi0)
522 dd if="$fwdir/u-boot-sunxi-with-spl.bin" of="$tgt" bs=1024 seek=8 > /dev/null 2>&1
524 (solidrun-clearfog)
525 dd if="$fwdir/u-boot-spl.kwb" of="$tgt" bs=512 seek=1 > /dev/null 2>&1
527 (solidrun-imx6)
528 dd if="$fwdir/SPL" of="$tgt" bs=1024 seek=1 > /dev/null 2>&1
529 dd if="$fwdir/u-boot.img" of="$tgt" bs=1024 seek=69 > /dev/null 2>&1
531 (raspberry-pi|raspberry-pi0|raspberry-pi2|raspberry-pi3|raspberry-pi3-64)
532 (( noformat )) || create_fs "$bootpart" ADKBOOT vfat
534 (phytec-wega)
535 (( noformat )) || create_fs "$bootpart" ADKBOOT ext4
539 (( noformat )) || create_fs "$rootpart" ADKROOT ext4
540 (( noformat )) || tune_fs "$rootpart"
542 (( quiet )) || print Extracting installation archive...
543 mount_fs "$rootpart" "$R" ext4
544 xz -dc "$src" | (cd "$R"; tar -xpf -)
546 if (( datafssz )); then
547 mkdir -m0755 "$R"/data
548 ((keep)) || create_fs "$datapart" ADKDATA ext4
549 ((keep)) || tune_fs "$datapart"
550 case $target {
551 (raspberry-pi|raspberry-pi0|raspberry-pi2|raspberry-pi3|raspberry-pi3-64|phytec-wega)
552 echo "/dev/mmcblk0p3 /data ext4 rw 0 0" >> "$R"/etc/fstab
554 (banana-pro|orange-pi0|solidrun-imx6|solidrun-clearfog)
555 echo "/dev/mmcblk0p2 /data ext4 rw 0 0" >> "$R"/etc/fstab
560 (( quiet )) || print Finishing up with bootloader and kernel ...
561 case $target {
562 (raspberry-pi|raspberry-pi0|raspberry-pi2|raspberry-pi3|raspberry-pi3-64)
563 mount_fs "$bootpart" "$B" vfat
564 for x in "$R"/boot/*; do
565 [[ -e "$x" ]] && mv -f "$R"/boot/* "$B/"
566 break
567 done
568 for x in "$fwdir"/*.dtb; do
569 [[ -e "$x" ]] && cp "$fwdir"/*.dtb "$B/"
570 break
571 done
572 # use static dtoverlay, rename to *.dtb
573 mkdir "$B/"overlays
574 for x in "$fwdir"/overlays/*.dtbo; do
575 y=$(basename ${x} .dtbo)
576 [[ -e "$x" ]] && cp "$fwdir"/overlays/${y}.dtbo "$B/"overlays/${y}.dtb
577 done
578 umount_fs "$B"
580 (phytec-wega)
581 mount_fs "$bootpart" "$B" ext4
582 for x in "$R"/boot/*; do
583 [[ -e "$x" ]] && mv -f "$R"/boot/* "$B/"
584 break
585 done
586 for x in "$fwdir"/*.dtb; do
587 [[ -e "$x" ]] && cp "$fwdir"/*.dtb "$B/"
588 break
589 done
590 umount_fs "$B"
592 (solidrun-clearfog)
593 for x in "$fwdir"/*.dtb; do
594 [[ -e "$x" ]] && cp "$fwdir"/*.dtb "$R/boot/"
595 break
596 done
597 mkimage -A arm -O linux -T script -C none -a 0 -e 0 \
598 -n "SolidrunClearfog" \
599 -d $fwdir/boot.script.clearfog $R/boot/boot.scr.uimg
601 (solidrun-imx6)
602 for x in "$fwdir"/*.dtb; do
603 [[ -e "$x" ]] && cp "$fwdir"/*.dtb "$R/boot/"
604 break
605 done
606 mkimage -A arm -O linux -T script -C none -a 0 -e 0 \
607 -n "SolidrunImx6" \
608 -d $fwdir/boot.script.imx6 $R/boot/boot.scr.uimg
610 (orange-pi0)
611 for x in "$fwdir"/*.dtb; do
612 [[ -e "$x" ]] && cp "$fwdir"/*.dtb "$R/boot/"
613 break
614 done
615 mkimage -A arm -O linux -T script -C none -a 0 -e 0 \
616 -n "OrangePI Zero" \
617 -d $fwdir/boot.script.opi $R/boot/boot.scr.uimg
619 (banana-pro)
620 for x in "$fwdir"/*.dtb; do
621 [[ -e "$x" ]] && cp "$fwdir"/*.dtb "$R/boot/"
622 break
623 done
624 mkimage -A arm -O linux -T script -C none -a 0 -e 0 \
625 -n "BananaPro" \
626 -d $fwdir/boot.script.bpi $R/boot/boot.scr.uimg
630 cd "$R"
631 dd if=$rnddev bs=16 count=1 >>etc/.rnd 2>/dev/null
632 (( quiet )) || print Fixing up permissions...
633 chown 0:0 tmp
634 chmod 1777 tmp
635 [[ -f usr/bin/sudo ]] && chmod 4755 usr/bin/sudo
637 if (( grub )); then
638 (( quiet )) || print Configuring GRUB2 bootloader...
639 mkdir -p boot/grub
641 print set default=0
642 print set timeout=1
643 if (( serial )); then
644 print serial --unit=0 --speed=$speed
645 print terminal_output serial
646 print terminal_input serial
647 consargs="console=ttyS0,$speed console=tty0"
648 else
649 print terminal_output console
650 print terminal_input console
651 consargs="console=tty0"
653 print
654 print 'menuentry "GNU/Linux (OpenADK)" {'
655 linuxargs="root=PARTUUID=$partuuid $consargs"
656 (( panicreboot )) && linuxargs="$linuxargs panic=$panicreboot"
657 print "\tlinux /boot/kernel $linuxargs"
658 print '}'
659 ) >boot/grub/grub.cfg
662 (( quiet )) || print Finishing up...
663 cd "$ADK_TOPDIR"
664 umount_fs "$R"
665 if (( datafssz )); then
666 umount_fs $datapart
668 rm -rf "$T"
669 exit 0