libressl: update to 2.6.3
[openadk.git] / scripts / install.sh
blob7e3245c3109fd7957d092e4b16c8fa16e4ff6838
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
66 paragon_ext=0
67 datapartcontent=""
69 function usage {
70 cat >&2 <<EOF
71 Syntax: $me [-f filesystem] [-c cfgfssize] [-d datafssize] [-D datafscontent] [-k] [-n] [-g]
72 [-p panictime] [±q] [-s serialspeed] [±t] <target> <device> <archive>
73 Partition sizes are in MiB. Filesystem type is currently ignored (ext4).
74 To keep filesystem on data partition use -k.
75 Use -n to not format boot/root partition.
76 Defaults: -c 1 -p 10 -s 115200; -t = enable serial console
77 EOF
78 exit $1
80 while getopts "c:d:D:ef:ghknp:qs:tx:" ch; do
81 case $ch {
82 (c) if (( (cfgfs = OPTARG) < 0 || cfgfs > 16 )); then
83 print -u2 "$me: -c $OPTARG out of bounds"
84 exit 1
85 fi ;;
86 (d) if (( (datafssz = OPTARG) < 0 )); then
87 print -u2 "$me: -d $OPTARG out of bounds"
88 exit 1
89 fi ;;
90 (e) paragon_ext=1 ;;
91 (f) if [[ $OPTARG != @(ext2|ext3|ext4|xfs) ]]; then
92 print -u2 "$me: filesystem $OPTARG invalid"
93 exit 1
95 fs=$OPTARG ;;
96 (h) usage 0 ;;
97 (k) keep=1 ;;
98 (g) grub=1 ;;
99 (p) if (( (panicreboot = OPTARG) < 0 || panicreboot > 300 )); then
100 print -u2 "$me: -p $OPTARG out of bounds"
101 exit 1
102 fi ;;
103 (q) quiet=1 ;;
104 (+q) quiet=0 ;;
105 (s) if [[ $OPTARG != @(96|192|384|576|1152)00 ]]; then
106 print -u2 "$me: serial speed $OPTARG invalid"
107 exit 1
109 speed=$OPTARG ;;
110 (n) noformat=1 ;;
111 (t) serial=1 ;;
112 (+t) serial=0 ;;
113 (D) if [[ ! -d $OPTARG ]]; then
114 print -u2 "$me: -D $OPTARG must be an existing directory"
115 exit 1
117 datapartcontent=$OPTARG;;
118 (*) usage 1 ;;
120 done
121 shift $((OPTIND - 1))
123 (( $# == 3 )) || usage 1
126 case $ostype {
127 (Linux)
128 tools="bc mkfs.ext4 mkfs.vfat tune2fs partprobe"
130 (Darwin)
131 tools="bc diskutil"
132 if [[ $paragon_ext == 0 ]]; then
133 export PATH=/usr/local/opt/e2fsprogs/sbin:/usr/local/opt/e2fsprogs/bin:$PATH
134 tools="$tools fuse-ext2 umount mkfs.ext4 tune2fs"
138 print -u2 Sorry, not ported to the OS "'$ostype'" yet.
139 exit 1
142 for tool in $tools; do
143 print -n Checking if $tool is installed...
144 if whence -p $tool >/dev/null; then
145 print " okay"
146 else
147 print " failed"
150 done
151 (( f )) && exit 1
153 target=$1
154 tgt=$2
155 src=$3
157 case $target {
158 (banana-pro|orange-pi0|pcengines-apu|phytec-wega|raspberry-pi|raspberry-pi0|raspberry-pi2|raspberry-pi3|raspberry-pi3-64|solidrun-imx6|solidrun-clearfog|default) ;;
160 print -u2 "Unknown target '$target', exiting"
161 exit 1 ;;
163 if [[ ! -b $tgt ]]; then
164 print -u2 "'$tgt' is not a block device, exiting"
165 exit 1
167 if [[ ! -f $src ]]; then
168 print -u2 "'$src' is not a file, exiting"
169 exit 1
171 (( quiet )) || print "Installing $src on $tgt."
173 case $ostype {
174 (Darwin)
175 R=/Volumes/ADKROOT; diskutil unmount $R || umount $R
176 B=/Volumes/ADKBOOT; diskutil unmount $B || umount $B
177 D=/Volumes/ADKDATA; diskutil unmount $D || umount $D
178 basedev=$tgt
179 rootpart=${basedev}s1
180 datapart=${basedev}s2
181 if [[ $target = raspberry-pi || $target = raspberry-pi0 || $target = raspberry-pi2 || $target = raspberry-pi3 || $target = raspberry-pi3-64 || $target = phytec-wega ]]; then
182 bootpart=${basedev}s1
183 rootpart=${basedev}s2
184 datapart=${basedev}s3
186 match=\'${basedev}\''?(s+([0-9]))'
187 function mount_fs {
188 if [[ $paragon_ext == 0 && $3 = ext4 ]]; then
189 mkdir -p $2
190 fuse-ext2 "$1" "$2" -o rw+
193 function umount_fs {
194 (( quiet )) || print "Unmounting filesystem on ${1}..."
195 if [[ $paragon_ext == 0 ]]; then
196 umount "$1" || diskutil unmount "$1" || true
197 rmdir $2 || true
198 else
199 diskutil unmount "$1"
202 function create_fs {
203 (( quiet )) || printf "Creating filesystem on ${1}"
204 if [[ $paragon_ext == 0 && $3 = ext4 ]]; then
205 mkfs.ext4 -L "$2" "$1"
206 else
207 if [[ $3 = ext4 ]]; then
208 fstype=UFSD_EXTFS4
210 if [[ $3 = vfat ]]; then
211 fstype=fat32
213 diskutil eraseVolume $fstype "$2" "$1"
216 function tune_fs {
217 if [[ $paragon_ext == 0 && $3 = ext4 ]]; then
218 tune2fs -c 0 -i 0 "$1"
222 (Linux)
223 basedev=$tgt
224 partitionsep=""
225 if [[ $basedev = /dev/loop* ]]; then
226 (( quiet )) || print "${tgt} is a loop device"
227 partitionsep=p
230 rootpart=${basedev}${partitionsep}1
231 datapart=${basedev}${partitionsep}2
232 if [[ $target = raspberry-pi || $target = raspberry-pi0 || $target = raspberry-pi2 || $target = raspberry-pi3 || $target = raspberry-pi3-64 ]]; then
233 bootpart=${basedev}${partitionsep}1
234 rootpart=${basedev}${partitionsep}2
235 datapart=${basedev}${partitionsep}3
238 match=\'${basedev}${partitionsep}\''+([0-9])'
239 function mount_fs {
240 (( quiet )) || print "Mounting filesystem on ${1}..."
241 mount -t "$3" "$1" "$2"
243 function umount_fs {
244 (( quiet )) || print "Unmounting filesystem on ${1}..."
245 umount "$1"
247 function create_fs {
248 (( quiet )) || print "Creating filesystem on ${1}..."
249 mkfs.$3 "$1"
251 function tune_fs {
252 tune2fs -c 0 -i 0 "$1"
257 mount |&
258 while read -p dev rest; do
259 eval [[ \$dev = $match ]] || continue
260 print -u2 "Block device $tgt is in use, please umount first."
261 exit 1
262 done
264 if (( !quiet )); then
265 print "WARNING: This will overwrite $basedev - type Yes to continue!"
266 read x
267 [[ $x = Yes ]] || exit 0
270 if ! T=$(mktemp -d /tmp/openadk.XXXXXXXXXX); then
271 print -u2 Error creating temporary directory.
272 exit 1
274 if [[ $ostype != Darwin ]]; then
275 R=$T/rootmnt
276 B=$T/bootmnt
277 D=$T/datamnt
278 mkdir -p "$R" "$B" "$D"
281 # get disk size
282 dksz=$(dkgetsz "$tgt")
284 # partition layouts:
285 # n̲a̲m̲e̲ p̲a̲r̲t̲#̲0̲ p̲̲a̲r̲t̲#̲1̲ p̲̲a̲r̲t̲#̲2̲ p̲̲a̲r̲t̲#̲3̲
286 # default: 0x83(system) 0x83(?data) -(unused) 0x88(cfgfs)
287 # raspberry: 0x0B(boot) 0x83(system) 0x83(?data) 0x88(cfgfs)
289 syspartno=0
291 # sizes:
292 # boot(raspberry) - fixed (100 MiB)
293 # cfgfs - fixed (parameter, max. 16 MiB)
294 # data - flexible (parameter)
295 # system - everything else
297 if [[ $target = raspberry-pi || $target = raspberry-pi0 || $target = raspberry-pi2 || $target = raspberry-pi3 || $target = raspberry-pi3-64 || $target = phytec-wega ]]; then
298 syspartno=1
299 bootfssz=100
300 if (( grub )); then
301 print -u2 "Cannot combine GRUB with $target"
302 rm -rf "$T"
303 exit 1
305 else
306 bootfssz=0
309 heads=64
310 secs=32
311 (( cyls = dksz / heads / secs ))
312 if (( cyls < (bootfssz + cfgfs + datafssz + 2) )); then
313 print -u2 "Size of $tgt is $dksz, this looks fishy?"
314 rm -rf "$T"
315 exit 1
318 if stat -qs .>/dev/null 2>&1; then
319 statcmd='stat -f %z' # BSD stat (or so we assume)
320 else
321 statcmd='stat -c %s' # GNU stat
324 if (( grub )); then
325 tar -xOf "$src" boot/grub/core.img >"$T/core.img"
326 integer coreimgsz=$($statcmd "$T/core.img")
327 else
328 coreimgsz=65024
330 if (( coreimgsz < 1024 )); then
331 print -u2 core.img is probably too small: $coreimgsz
332 rm -rf "$T"
333 exit 1
335 if (( coreimgsz > 65024 )); then
336 print -u2 core.img is larger than 64K-512: $coreimgsz
337 rm -rf "$T"
338 exit 1
340 (( coreendsec = (coreimgsz + 511) / 512 ))
341 if [[ $basedev = /dev/svnd+([0-9]) ]]; then
342 # BSD svnd0 mode: protect sector #1
343 corestartsec=2
344 (( ++coreendsec ))
345 corepatchofs=$((0x614))
346 else
347 corestartsec=1
348 corepatchofs=$((0x414))
350 # partition offset: at least coreendsec+1 but aligned on a multiple of secs
351 #(( partofs = ((coreendsec / secs) + 1) * secs ))
352 # we just use 2048 all the time, since some loaders are longer
353 partofs=2048
354 if [[ $target = raspberry-pi || $target = raspberry-pi0 || $target = raspberry-pi2 || $target = raspberry-pi3 || $target = raspberry-pi3-64 || $target = phytec-wega ]]; then
355 (( spartofs = partofs + (100 * 2048) ))
356 else
357 spartofs=$partofs
360 (( quiet )) || if (( grub )); then
361 print Preparing MBR and GRUB2...
362 else
363 print Preparing MBR...
365 dd if=/dev/zero of="$T/firsttrack" count=$partofs 2>/dev/null
366 # add another MiB to clear the first partition
367 dd if=/dev/zero bs=1048576 count=1 >>"$T/firsttrack" 2>/dev/null
368 echo $corestartsec $coreendsec | mksh "$ADK_TOPDIR/scripts/bootgrub.mksh" \
369 -A -g $((cyls - bootfssz - cfgfs - datafssz)):$heads:$secs -M 1:0x83 \
370 -O $spartofs | dd of="$T/firsttrack" conv=notrunc 2>/dev/null
371 (( grub )) && dd if="$T/core.img" of="$T/firsttrack" conv=notrunc \
372 seek=$corestartsec 2>/dev/null
373 # set partition where it can find /boot/grub
374 (( grub )) && print -n '\0\0\0\0' | \
375 dd of="$T/firsttrack" conv=notrunc bs=1 seek=$corepatchofs 2>/dev/null
377 # create cfgfs partition (mostly taken from bootgrub.mksh)
378 set -A thecode
379 typeset -Uui8 thecode
380 mbrpno=0
381 set -A g_code $cyls $heads $secs
382 (( psz = g_code[0] * g_code[1] * g_code[2] ))
383 (( pofs = (cyls - cfgfs) * g_code[1] * g_code[2] ))
384 set -A o_code # g_code equivalent for partition offset
385 (( o_code[2] = pofs % g_code[2] + 1 ))
386 (( o_code[1] = pofs / g_code[2] ))
387 (( o_code[0] = o_code[1] / g_code[1] + 1 ))
388 (( o_code[1] = o_code[1] % g_code[1] + 1 ))
389 # boot flag; C/H/S offset
390 thecode[mbrpno++]=0x00
391 (( thecode[mbrpno++] = o_code[1] - 1 ))
392 (( cylno = o_code[0] > 1024 ? 1023 : o_code[0] - 1 ))
393 (( thecode[mbrpno++] = o_code[2] | ((cylno & 0x0300) >> 2) ))
394 (( thecode[mbrpno++] = cylno & 0x00FF ))
395 # partition type; C/H/S end
396 (( thecode[mbrpno++] = 0x88 ))
397 (( thecode[mbrpno++] = g_code[1] - 1 ))
398 (( cylno = g_code[0] > 1024 ? 1023 : g_code[0] - 1 ))
399 (( thecode[mbrpno++] = g_code[2] | ((cylno & 0x0300) >> 2) ))
400 (( thecode[mbrpno++] = cylno & 0x00FF ))
401 # partition offset, size (LBA)
402 (( thecode[mbrpno++] = pofs & 0xFF ))
403 (( thecode[mbrpno++] = (pofs >> 8) & 0xFF ))
404 (( thecode[mbrpno++] = (pofs >> 16) & 0xFF ))
405 (( thecode[mbrpno++] = (pofs >> 24) & 0xFF ))
406 (( pssz = psz - pofs ))
407 (( thecode[mbrpno++] = pssz & 0xFF ))
408 (( thecode[mbrpno++] = (pssz >> 8) & 0xFF ))
409 (( thecode[mbrpno++] = (pssz >> 16) & 0xFF ))
410 (( thecode[mbrpno++] = (pssz >> 24) & 0xFF ))
411 # write partition table entry
412 ostr=
413 curptr=0
414 while (( curptr < 16 )); do
415 ostr=$ostr\\0${thecode[curptr++]#8#}
416 done
417 print -n "$ostr" | \
418 dd of="$T/firsttrack" conv=notrunc bs=1 seek=$((0x1EE)) 2>/dev/null
420 if (( datafssz )); then
421 # create data partition (copy of the above :)
422 set -A thecode
423 typeset -Uui8 thecode
424 mbrpno=0
425 set -A g_code $cyls $heads $secs
426 (( psz = (cyls - cfgfs) * g_code[1] * g_code[2] ))
427 (( pofs = (cyls - cfgfs - datafssz) * g_code[1] * g_code[2] ))
428 set -A o_code # g_code equivalent for partition offset
429 (( o_code[2] = pofs % g_code[2] + 1 ))
430 (( o_code[1] = pofs / g_code[2] ))
431 (( o_code[0] = o_code[1] / g_code[1] + 1 ))
432 (( o_code[1] = o_code[1] % g_code[1] + 1 ))
433 # boot flag; C/H/S offset
434 thecode[mbrpno++]=0x00
435 (( thecode[mbrpno++] = o_code[1] - 1 ))
436 (( cylno = o_code[0] > 1024 ? 1023 : o_code[0] - 1 ))
437 (( thecode[mbrpno++] = o_code[2] | ((cylno & 0x0300) >> 2) ))
438 (( thecode[mbrpno++] = cylno & 0x00FF ))
439 # partition type; C/H/S end
440 (( thecode[mbrpno++] = 0x83 ))
441 (( thecode[mbrpno++] = g_code[1] - 1 ))
442 (( cylno = (g_code[0] - cfgfs) > 1024 ? 1023 : g_code[0] - cfgfs - 1 ))
443 (( thecode[mbrpno++] = g_code[2] | ((cylno & 0x0300) >> 2) ))
444 (( thecode[mbrpno++] = cylno & 0x00FF ))
445 # partition offset, size (LBA)
446 (( thecode[mbrpno++] = pofs & 0xFF ))
447 (( thecode[mbrpno++] = (pofs >> 8) & 0xFF ))
448 (( thecode[mbrpno++] = (pofs >> 16) & 0xFF ))
449 (( thecode[mbrpno++] = (pofs >> 24) & 0xFF ))
450 (( pssz = psz - pofs ))
451 (( thecode[mbrpno++] = pssz & 0xFF ))
452 (( thecode[mbrpno++] = (pssz >> 8) & 0xFF ))
453 (( thecode[mbrpno++] = (pssz >> 16) & 0xFF ))
454 (( thecode[mbrpno++] = (pssz >> 24) & 0xFF ))
455 # write partition table entry
456 ostr=
457 curptr=0
458 while (( curptr < 16 )); do
459 ostr=$ostr\\0${thecode[curptr++]#8#}
460 done
461 print -n "$ostr" | \
462 dd of="$T/firsttrack" conv=notrunc bs=1 seek=$((0x1CE)) 2>/dev/null
465 if [[ $target = raspberry-pi || $target = raspberry-pi0 || $target = raspberry-pi2 || $target = raspberry-pi3 || $target = raspberry-pi3-64 || $target = phytec-wega ]]; then
466 # move system and data partition from #0/#1 to #1/#2
467 dd if="$T/firsttrack" bs=1 skip=$((0x1BE)) count=32 of="$T/x" 2>/dev/null
468 dd of="$T/firsttrack" conv=notrunc bs=1 seek=$((0x1CE)) if="$T/x" 2>/dev/null
469 # create boot partition (copy of the above :)
470 set -A thecode
471 typeset -Uui8 thecode
472 mbrpno=0
473 set -A g_code $cyls $heads $secs
474 psz=$spartofs
475 pofs=$partofs
476 set -A o_code # g_code equivalent for partition offset
477 (( o_code[2] = pofs % g_code[2] + 1 ))
478 (( o_code[1] = pofs / g_code[2] ))
479 (( o_code[0] = o_code[1] / g_code[1] + 1 ))
480 (( o_code[1] = o_code[1] % g_code[1] + 1 ))
481 # boot flag; C/H/S offset
482 thecode[mbrpno++]=0x00
483 (( thecode[mbrpno++] = o_code[1] - 1 ))
484 (( cylno = o_code[0] > 1024 ? 1023 : o_code[0] - 1 ))
485 (( thecode[mbrpno++] = o_code[2] | ((cylno & 0x0300) >> 2) ))
486 (( thecode[mbrpno++] = cylno & 0x00FF ))
487 # partition type; C/H/S end
488 (( thecode[mbrpno++] = 0x0B ))
489 (( thecode[mbrpno++] = g_code[1] - 1 ))
490 (( cylno = (spartofs / 2048) > 1024 ? 1023 : (spartofs / 2048) - 1 ))
491 (( thecode[mbrpno++] = g_code[2] | ((cylno & 0x0300) >> 2) ))
492 (( thecode[mbrpno++] = cylno & 0x00FF ))
493 # partition offset, size (LBA)
494 (( thecode[mbrpno++] = pofs & 0xFF ))
495 (( thecode[mbrpno++] = (pofs >> 8) & 0xFF ))
496 (( thecode[mbrpno++] = (pofs >> 16) & 0xFF ))
497 (( thecode[mbrpno++] = (pofs >> 24) & 0xFF ))
498 (( pssz = psz - pofs ))
499 (( thecode[mbrpno++] = pssz & 0xFF ))
500 (( thecode[mbrpno++] = (pssz >> 8) & 0xFF ))
501 (( thecode[mbrpno++] = (pssz >> 16) & 0xFF ))
502 (( thecode[mbrpno++] = (pssz >> 24) & 0xFF ))
503 # write partition table entry
504 ostr=
505 curptr=0
506 while (( curptr < 16 )); do
507 ostr=$ostr\\0${thecode[curptr++]#8#}
508 done
509 print -n "$ostr" | \
510 dd of="$T/firsttrack" conv=notrunc bs=1 seek=$((0x1BE)) 2>/dev/null
513 # disk signature
514 rnddev=/dev/urandom
515 [[ -c /dev/arandom ]] && rnddev=/dev/arandom
516 dd if=$rnddev bs=4 count=1 2>/dev/null | \
517 dd of="$T/firsttrack" conv=notrunc bs=1 seek=$((0x1B8)) 2>/dev/null
518 print -n '\0\0' | \
519 dd of="$T/firsttrack" conv=notrunc bs=1 seek=$((0x1BC)) 2>/dev/null
520 partuuid=$(dd if="$T/firsttrack" bs=1 count=4 skip=$((0x1B8)) 2>/dev/null | \
521 hexdump -e '1/4 "%08x"')-0$((syspartno+1))
523 ((keep)) || if (( datafssz )); then
524 (( quiet )) || print Cleaning out data partition...
525 dd if=/dev/zero of="$tgt" bs=1048576 count=1 seek=$((cyls - cfgfs - datafssz)) > /dev/null 2>&1
527 (( quiet )) || print Cleaning out root partition...
528 dd if=/dev/zero bs=1048576 of="$tgt" count=1 seek=$((spartofs / 2048)) > /dev/null 2>&1
530 (( quiet )) || if (( grub )); then
531 print Writing MBR and GRUB2 to target device... system PARTUUID=$partuuid
532 else
533 print Writing MBR to target device... system PARTUUID=$partuuid
535 dd if="$T/firsttrack" of="$tgt" > /dev/null 2>&1
537 if [[ $ostype = Linux ]]; then
538 echo partprobe $tgt
539 partprobe -s $tgt
540 sync
541 fdisk -l $tgt
542 ls -la ${tgt}*
545 fwdir=$(dirname "$src")
547 case $target {
548 (banana-pro|orange-pi0)
549 dd if="$fwdir/u-boot-sunxi-with-spl.bin" of="$tgt" bs=1024 seek=8 > /dev/null 2>&1
551 (solidrun-clearfog)
552 dd if="$fwdir/u-boot-spl.kwb" of="$tgt" bs=512 seek=1 > /dev/null 2>&1
554 (solidrun-imx6)
555 dd if="$fwdir/SPL" of="$tgt" bs=1024 seek=1 > /dev/null 2>&1
556 dd if="$fwdir/u-boot.img" of="$tgt" bs=1024 seek=69 > /dev/null 2>&1
558 (raspberry-pi|raspberry-pi0|raspberry-pi2|raspberry-pi3|raspberry-pi3-64)
559 (( noformat )) || create_fs "$bootpart" ADKBOOT vfat
561 (phytec-wega)
562 (( noformat )) || create_fs "$bootpart" ADKBOOT ext4
566 (( noformat )) || create_fs "$rootpart" ADKROOT ext4
567 (( noformat )) || tune_fs "$rootpart"
569 (( quiet )) || print Extracting installation archive...
570 mount_fs "$rootpart" "$R" ext4
571 xz -dc "$src" | (cd "$R"; tar -xpf -)
573 if (( datafssz )); then
574 mkdir -m0755 "$R"/data
575 ((keep)) || create_fs "$datapart" ADKDATA ext4
576 ((keep)) || tune_fs "$datapart"
577 case $target {
578 (raspberry-pi|raspberry-pi0|raspberry-pi2|raspberry-pi3|raspberry-pi3-64|phytec-wega)
579 echo "/dev/mmcblk0p3 /data ext4 rw 0 0" >> "$R"/etc/fstab
581 (banana-pro|orange-pi0|solidrun-imx6|solidrun-clearfog)
582 echo "/dev/mmcblk0p2 /data ext4 rw 0 0" >> "$R"/etc/fstab
585 if [[ -d $datapartcontent ]]; then
586 mount_fs "$datapart" "$D" ext4
587 # strip trailing slash
588 case $datapartcontent in
589 *[!/]*/) datapartcontent=${datapartcontent%"${x##*[!/]}"};;
590 esac
591 cp -R $datapartcontent/* "$D"
595 (( quiet )) || print Finishing up with bootloader and kernel ...
596 case $target {
597 (raspberry-pi|raspberry-pi0|raspberry-pi2|raspberry-pi3|raspberry-pi3-64)
598 mount_fs "$bootpart" "$B" vfat
599 for x in "$R"/boot/*; do
600 [[ -e "$x" ]] && mv -f "$R"/boot/* "$B/"
601 break
602 done
603 for x in "$fwdir"/*.dtb; do
604 [[ -e "$x" ]] && cp "$fwdir"/*.dtb "$B/"
605 break
606 done
607 # use static dtoverlay, rename to *.dtb
608 mkdir "$B/"overlays
609 for x in "$fwdir"/overlays/*.dtbo; do
610 y=$(basename ${x} .dtbo)
611 [[ -e "$x" ]] && cp "$fwdir"/overlays/${y}.dtbo "$B/"overlays/${y}.dtb
612 done
613 umount_fs "$B"
615 (phytec-wega)
616 mount_fs "$bootpart" "$B" ext4
617 for x in "$R"/boot/*; do
618 [[ -e "$x" ]] && mv -f "$R"/boot/* "$B/"
619 break
620 done
621 for x in "$fwdir"/*.dtb; do
622 [[ -e "$x" ]] && cp "$fwdir"/*.dtb "$B/"
623 break
624 done
625 umount_fs "$B"
627 (solidrun-clearfog)
628 for x in "$fwdir"/*.dtb; do
629 [[ -e "$x" ]] && cp "$fwdir"/*.dtb "$R/boot/"
630 break
631 done
632 mkimage -A arm -O linux -T script -C none -a 0 -e 0 \
633 -n "SolidrunClearfog" \
634 -d $fwdir/boot.script.clearfog $R/boot/boot.scr.uimg
636 (solidrun-imx6)
637 for x in "$fwdir"/*.dtb; do
638 [[ -e "$x" ]] && cp "$fwdir"/*.dtb "$R/boot/"
639 break
640 done
641 mkimage -A arm -O linux -T script -C none -a 0 -e 0 \
642 -n "SolidrunImx6" \
643 -d $fwdir/boot.script.imx6 $R/boot/boot.scr.uimg
645 (orange-pi0)
646 for x in "$fwdir"/*.dtb; do
647 [[ -e "$x" ]] && cp "$fwdir"/*.dtb "$R/boot/"
648 break
649 done
650 mkimage -A arm -O linux -T script -C none -a 0 -e 0 \
651 -n "OrangePI Zero" \
652 -d $fwdir/boot.script.opi $R/boot/boot.scr.uimg
654 (banana-pro)
655 for x in "$fwdir"/*.dtb; do
656 [[ -e "$x" ]] && cp "$fwdir"/*.dtb "$R/boot/"
657 break
658 done
659 mkimage -A arm -O linux -T script -C none -a 0 -e 0 \
660 -n "BananaPro" \
661 -d $fwdir/boot.script.bpi $R/boot/boot.scr.uimg
665 cd "$R"
666 dd if=$rnddev bs=16 count=1 >>etc/.rnd 2>/dev/null
667 (( quiet )) || print Fixing up permissions...
668 chown 0:0 tmp
669 chmod 1777 tmp
670 [[ -f usr/bin/sudo ]] && chmod 4755 usr/bin/sudo
672 if (( grub )); then
673 (( quiet )) || print Configuring GRUB2 bootloader...
674 mkdir -p boot/grub
676 print set default=0
677 print set timeout=1
678 if (( serial )); then
679 print serial --unit=0 --speed=$speed
680 print terminal_output serial
681 print terminal_input serial
682 consargs="console=ttyS0,$speed console=tty0"
683 else
684 print terminal_output console
685 print terminal_input console
686 consargs="console=tty0"
688 print
689 print 'menuentry "GNU/Linux (OpenADK)" {'
690 linuxargs="root=PARTUUID=$partuuid $consargs"
691 (( panicreboot )) && linuxargs="$linuxargs panic=$panicreboot"
692 print "\tlinux /boot/kernel $linuxargs"
693 print '}'
694 ) >boot/grub/grub.cfg
697 (( quiet )) || print Finishing up...
698 cd "$ADK_TOPDIR"
699 umount_fs "$R"
700 if (( datafssz )); then
701 umount_fs $datapart
703 rm -rf "$T"
704 exit 0