coldfire: add generic support for 54418
[openadk.git] / scripts / install.sh
blobe3494d5d61714bf1efed57cdc1c6c44de506815e
1 #!/usr/bin/env bash
2 #-
3 # Copyright © 2010-2023
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 (atmel-ngw100|banana-pro|banana-pro-zero|orange-pi0|pcengines-apu|phytec-imx6|phytec-wega|raspberry-pi|raspberry-pi0|raspberry-pi2|raspberry-pi3|raspberry-pi3-64|raspberry-pi4|raspberry-pi4-64|raspberry-pi5|rockpi4-plus|solidrun-imx6|solidrun-clearfog|imgtec-ci20|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 = raspberry-pi4 || $target = raspberry-pi4-64 || $target = raspberry-pi5 || $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
225 if [[ "$tgt" == *"nvme0n1"* ]] || [[ "$tgt" == *"mmcblk"* ]]; then
226 partitionsep="p"
227 else
228 partitionsep=""
231 if [[ $basedev = /dev/loop* ]]; then
232 (( quiet )) || print "${tgt} is a loop device"
233 partitionsep=p
236 rootpart=${basedev}${partitionsep}1
237 datapart=${basedev}${partitionsep}2
238 if [[ $target = raspberry-pi || $target = raspberry-pi0 || $target = raspberry-pi2 || $target = raspberry-pi3 || $target = raspberry-pi3-64 || $target = raspberry-pi4 || $target = raspberry-pi4-64 || $target = raspberry-pi5 ]]; then
239 bootpart=${basedev}${partitionsep}1
240 rootpart=${basedev}${partitionsep}2
241 datapart=${basedev}${partitionsep}3
244 match=\'${basedev}${partitionsep}\''+([0-9])'
245 function mount_fs {
246 (( quiet )) || print "Mounting filesystem on ${1}..."
247 mount -t "$3" "$1" "$2"
249 function umount_fs {
250 (( quiet )) || print "Unmounting filesystem on ${1}..."
251 umount "$1"
253 function create_fs {
254 (( quiet )) || print "Creating filesystem on ${1}..."
255 mkfs.$3 "$1"
257 function tune_fs {
258 tune2fs -c 0 -i 0 "$1"
263 mount |&
264 while read -p dev rest; do
265 eval [[ \$dev = $match ]] || continue
266 print -u2 "Block device $tgt is in use, please umount first."
267 exit 1
268 done
270 if (( !quiet )); then
271 print "WARNING: This will overwrite $basedev - type Yes to continue!"
272 read x
273 [[ $x = Yes ]] || exit 0
276 if ! T=$(mktemp -d /tmp/openadk.XXXXXXXXXX); then
277 print -u2 Error creating temporary directory.
278 exit 1
280 if [[ $ostype != Darwin ]]; then
281 R=$T/rootmnt
282 B=$T/bootmnt
283 D=$T/datamnt
284 mkdir -p "$R" "$B" "$D"
287 # get disk size
288 dksz=$(dkgetsz "$tgt")
290 # partition layouts:
291 # n̲a̲m̲e̲ p̲a̲r̲t̲#̲0̲ p̲̲a̲r̲t̲#̲1̲ p̲̲a̲r̲t̲#̲2̲ p̲̲a̲r̲t̲#̲3̲
292 # default: 0x83(system) 0x83(?data) -(unused) 0x88(cfgfs)
293 # raspberry: 0x0B(boot) 0x83(system) 0x83(?data) 0x88(cfgfs)
295 syspartno=0
297 # sizes:
298 # boot(raspberry) - fixed (100 MiB)
299 # cfgfs - fixed (parameter, max. 16 MiB)
300 # data - flexible (parameter)
301 # system - everything else
303 if [[ $target = raspberry-pi || $target = raspberry-pi0 || $target = raspberry-pi2 || $target = raspberry-pi3 || $target = raspberry-pi3-64 || $target = raspberry-pi4 || $target = raspberry-pi4-64 || $target = raspberry-pi5 || $target = phytec-wega ]]; then
304 syspartno=1
305 bootfssz=100
306 if (( grub )); then
307 print -u2 "Cannot combine GRUB with $target"
308 rm -rf "$T"
309 exit 1
311 else
312 bootfssz=0
315 heads=64
316 secs=32
317 (( cyls = dksz / heads / secs ))
318 if (( cyls < (bootfssz + cfgfs + datafssz + 2) )); then
319 print -u2 "Size of $tgt is $dksz, this looks fishy?"
320 rm -rf "$T"
321 exit 1
324 if stat -qs .>/dev/null 2>&1; then
325 statcmd='stat -f %z' # BSD stat (or so we assume)
326 else
327 statcmd='stat -c %s' # GNU stat
330 if (( grub )); then
331 tar -xOf "$src" boot/grub/core.img >"$T/core.img"
332 integer coreimgsz=$($statcmd "$T/core.img")
333 else
334 coreimgsz=65024
336 if (( coreimgsz < 1024 )); then
337 print -u2 core.img is probably too small: $coreimgsz
338 rm -rf "$T"
339 exit 1
341 if (( coreimgsz > 65024 )); then
342 print -u2 core.img is larger than 64K-512: $coreimgsz
343 rm -rf "$T"
344 exit 1
346 (( coreendsec = (coreimgsz + 511) / 512 ))
347 if [[ $basedev = /dev/svnd+([0-9]) ]]; then
348 # BSD svnd0 mode: protect sector #1
349 corestartsec=2
350 (( ++coreendsec ))
351 corepatchofs=$((0x614))
352 else
353 corestartsec=1
354 corepatchofs=$((0x414))
356 # partition offset: at least coreendsec+1 but aligned on a multiple of secs
357 #(( partofs = ((coreendsec / secs) + 1) * secs ))
358 # we just use 2048 all the time, since some loaders are longer
359 partofs=2048
360 if [[ $target = raspberry-pi || $target = raspberry-pi0 || $target = raspberry-pi2 || $target = raspberry-pi3 || $target = raspberry-pi3-64 || $target = raspberry-pi4 || $target = raspberry-pi4-64 || $target = raspberry-pi5 || $target = phytec-wega || $target = rockpi4-plus ]]; then
361 (( spartofs = partofs + (100 * 2048) ))
362 else
363 spartofs=$partofs
366 (( quiet )) || if (( grub )); then
367 print Preparing MBR and GRUB2...
368 else
369 print Preparing MBR...
371 dd if=/dev/zero of="$T/firsttrack" count=$partofs 2>/dev/null
372 # add another MiB to clear the first partition
373 dd if=/dev/zero bs=1048576 count=1 >>"$T/firsttrack" 2>/dev/null
374 echo $corestartsec $coreendsec | mksh "$ADK_TOPDIR/scripts/bootgrub.mksh" \
375 -A -g $((cyls - bootfssz - cfgfs - datafssz)):$heads:$secs -M 1:0x83 \
376 -O $spartofs | dd of="$T/firsttrack" conv=notrunc 2>/dev/null
377 (( grub )) && dd if="$T/core.img" of="$T/firsttrack" conv=notrunc \
378 seek=$corestartsec 2>/dev/null
379 # set partition where it can find /boot/grub
380 (( grub )) && print -n '\0\0\0\0' | \
381 dd of="$T/firsttrack" conv=notrunc bs=1 seek=$corepatchofs 2>/dev/null
383 # create cfgfs partition (mostly taken from bootgrub.mksh)
384 set -A thecode
385 typeset -Uui8 thecode
386 mbrpno=0
387 set -A g_code $cyls $heads $secs
388 (( psz = g_code[0] * g_code[1] * g_code[2] ))
389 (( pofs = (cyls - cfgfs) * g_code[1] * g_code[2] ))
390 set -A o_code # g_code equivalent for partition offset
391 (( o_code[2] = pofs % g_code[2] + 1 ))
392 (( o_code[1] = pofs / g_code[2] ))
393 (( o_code[0] = o_code[1] / g_code[1] + 1 ))
394 (( o_code[1] = o_code[1] % g_code[1] + 1 ))
395 # boot flag; C/H/S offset
396 thecode[mbrpno++]=0x00
397 (( thecode[mbrpno++] = o_code[1] - 1 ))
398 (( cylno = o_code[0] > 1024 ? 1023 : o_code[0] - 1 ))
399 (( thecode[mbrpno++] = o_code[2] | ((cylno & 0x0300) >> 2) ))
400 (( thecode[mbrpno++] = cylno & 0x00FF ))
401 # partition type; C/H/S end
402 (( thecode[mbrpno++] = 0x88 ))
403 (( thecode[mbrpno++] = g_code[1] - 1 ))
404 (( cylno = g_code[0] > 1024 ? 1023 : g_code[0] - 1 ))
405 (( thecode[mbrpno++] = g_code[2] | ((cylno & 0x0300) >> 2) ))
406 (( thecode[mbrpno++] = cylno & 0x00FF ))
407 # partition offset, size (LBA)
408 (( thecode[mbrpno++] = pofs & 0xFF ))
409 (( thecode[mbrpno++] = (pofs >> 8) & 0xFF ))
410 (( thecode[mbrpno++] = (pofs >> 16) & 0xFF ))
411 (( thecode[mbrpno++] = (pofs >> 24) & 0xFF ))
412 (( pssz = psz - pofs ))
413 (( thecode[mbrpno++] = pssz & 0xFF ))
414 (( thecode[mbrpno++] = (pssz >> 8) & 0xFF ))
415 (( thecode[mbrpno++] = (pssz >> 16) & 0xFF ))
416 (( thecode[mbrpno++] = (pssz >> 24) & 0xFF ))
417 # write partition table entry
418 ostr=
419 curptr=0
420 while (( curptr < 16 )); do
421 ostr=$ostr\\0${thecode[curptr++]#8#}
422 done
423 print -n "$ostr" | \
424 dd of="$T/firsttrack" conv=notrunc bs=1 seek=$((0x1EE)) 2>/dev/null
426 if (( datafssz )); then
427 # create data partition (copy of the above :)
428 set -A thecode
429 typeset -Uui8 thecode
430 mbrpno=0
431 set -A g_code $cyls $heads $secs
432 (( psz = (cyls - cfgfs) * g_code[1] * g_code[2] ))
433 (( pofs = (cyls - cfgfs - datafssz) * g_code[1] * g_code[2] ))
434 set -A o_code # g_code equivalent for partition offset
435 (( o_code[2] = pofs % g_code[2] + 1 ))
436 (( o_code[1] = pofs / g_code[2] ))
437 (( o_code[0] = o_code[1] / g_code[1] + 1 ))
438 (( o_code[1] = o_code[1] % g_code[1] + 1 ))
439 # boot flag; C/H/S offset
440 thecode[mbrpno++]=0x00
441 (( thecode[mbrpno++] = o_code[1] - 1 ))
442 (( cylno = o_code[0] > 1024 ? 1023 : o_code[0] - 1 ))
443 (( thecode[mbrpno++] = o_code[2] | ((cylno & 0x0300) >> 2) ))
444 (( thecode[mbrpno++] = cylno & 0x00FF ))
445 # partition type; C/H/S end
446 (( thecode[mbrpno++] = 0x83 ))
447 (( thecode[mbrpno++] = g_code[1] - 1 ))
448 (( cylno = (g_code[0] - cfgfs) > 1024 ? 1023 : g_code[0] - cfgfs - 1 ))
449 (( thecode[mbrpno++] = g_code[2] | ((cylno & 0x0300) >> 2) ))
450 (( thecode[mbrpno++] = cylno & 0x00FF ))
451 # partition offset, size (LBA)
452 (( thecode[mbrpno++] = pofs & 0xFF ))
453 (( thecode[mbrpno++] = (pofs >> 8) & 0xFF ))
454 (( thecode[mbrpno++] = (pofs >> 16) & 0xFF ))
455 (( thecode[mbrpno++] = (pofs >> 24) & 0xFF ))
456 (( pssz = psz - pofs ))
457 (( thecode[mbrpno++] = pssz & 0xFF ))
458 (( thecode[mbrpno++] = (pssz >> 8) & 0xFF ))
459 (( thecode[mbrpno++] = (pssz >> 16) & 0xFF ))
460 (( thecode[mbrpno++] = (pssz >> 24) & 0xFF ))
461 # write partition table entry
462 ostr=
463 curptr=0
464 while (( curptr < 16 )); do
465 ostr=$ostr\\0${thecode[curptr++]#8#}
466 done
467 print -n "$ostr" | \
468 dd of="$T/firsttrack" conv=notrunc bs=1 seek=$((0x1CE)) 2>/dev/null
471 if [[ $target = raspberry-pi || $target = raspberry-pi0 || $target = raspberry-pi2 || $target = raspberry-pi3 || $target = raspberry-pi3-64 || $target = raspberry-pi4 || $target = raspberry-pi4-64 || $target = raspberry-pi5 || $target = phytec-wega ]]; then
472 # move system and data partition from #0/#1 to #1/#2
473 dd if="$T/firsttrack" bs=1 skip=$((0x1BE)) count=32 of="$T/x" 2>/dev/null
474 dd of="$T/firsttrack" conv=notrunc bs=1 seek=$((0x1CE)) if="$T/x" 2>/dev/null
475 # create boot partition (copy of the above :)
476 set -A thecode
477 typeset -Uui8 thecode
478 mbrpno=0
479 set -A g_code $cyls $heads $secs
480 psz=$spartofs
481 pofs=$partofs
482 set -A o_code # g_code equivalent for partition offset
483 (( o_code[2] = pofs % g_code[2] + 1 ))
484 (( o_code[1] = pofs / g_code[2] ))
485 (( o_code[0] = o_code[1] / g_code[1] + 1 ))
486 (( o_code[1] = o_code[1] % g_code[1] + 1 ))
487 # boot flag; C/H/S offset
488 thecode[mbrpno++]=0x00
489 (( thecode[mbrpno++] = o_code[1] - 1 ))
490 (( cylno = o_code[0] > 1024 ? 1023 : o_code[0] - 1 ))
491 (( thecode[mbrpno++] = o_code[2] | ((cylno & 0x0300) >> 2) ))
492 (( thecode[mbrpno++] = cylno & 0x00FF ))
493 # partition type; C/H/S end
494 (( thecode[mbrpno++] = 0x0B ))
495 (( thecode[mbrpno++] = g_code[1] - 1 ))
496 (( cylno = (spartofs / 2048) > 1024 ? 1023 : (spartofs / 2048) - 1 ))
497 (( thecode[mbrpno++] = g_code[2] | ((cylno & 0x0300) >> 2) ))
498 (( thecode[mbrpno++] = cylno & 0x00FF ))
499 # partition offset, size (LBA)
500 (( thecode[mbrpno++] = pofs & 0xFF ))
501 (( thecode[mbrpno++] = (pofs >> 8) & 0xFF ))
502 (( thecode[mbrpno++] = (pofs >> 16) & 0xFF ))
503 (( thecode[mbrpno++] = (pofs >> 24) & 0xFF ))
504 (( pssz = psz - pofs ))
505 (( thecode[mbrpno++] = pssz & 0xFF ))
506 (( thecode[mbrpno++] = (pssz >> 8) & 0xFF ))
507 (( thecode[mbrpno++] = (pssz >> 16) & 0xFF ))
508 (( thecode[mbrpno++] = (pssz >> 24) & 0xFF ))
509 # write partition table entry
510 ostr=
511 curptr=0
512 while (( curptr < 16 )); do
513 ostr=$ostr\\0${thecode[curptr++]#8#}
514 done
515 print -n "$ostr" | \
516 dd of="$T/firsttrack" conv=notrunc bs=1 seek=$((0x1BE)) 2>/dev/null
519 # disk signature
520 rnddev=/dev/urandom
521 [[ -c /dev/arandom ]] && rnddev=/dev/arandom
522 dd if=$rnddev bs=4 count=1 2>/dev/null | \
523 dd of="$T/firsttrack" conv=notrunc bs=1 seek=$((0x1B8)) 2>/dev/null
524 print -n '\0\0' | \
525 dd of="$T/firsttrack" conv=notrunc bs=1 seek=$((0x1BC)) 2>/dev/null
526 partuuid=$(dd if="$T/firsttrack" bs=1 count=4 skip=$((0x1B8)) 2>/dev/null | \
527 hexdump -e '1/4 "%08x"')-0$((syspartno+1))
529 ((keep)) || if (( datafssz )); then
530 (( quiet )) || print Cleaning out data partition...
531 dd if=/dev/zero of="$tgt" bs=1048576 count=1 seek=$((cyls - cfgfs - datafssz)) > /dev/null 2>&1
533 (( quiet )) || print Cleaning out root partition...
534 dd if=/dev/zero bs=1048576 of="$tgt" count=1 seek=$((spartofs / 2048)) > /dev/null 2>&1
536 (( quiet )) || if (( grub )); then
537 print Writing MBR and GRUB2 to target device... system PARTUUID=$partuuid
538 else
539 print Writing MBR to target device... system PARTUUID=$partuuid
541 dd if="$T/firsttrack" of="$tgt" > /dev/null 2>&1
543 if [[ $ostype = Linux ]]; then
544 echo partprobe $tgt
545 partprobe -s $tgt
546 sync
547 fdisk -l $tgt
548 ls -la ${tgt}*
551 fwdir=$(dirname "$src")
553 case $target {
554 (rockpi4-plus)
555 dd if="$fwdir/idbloader.img" of="$tgt" bs=512 seek=64 > /dev/null 2>&1
556 dd if="$fwdir/u-boot.itb" of="$tgt" bs=512 seek=16384 > /dev/null 2>&1
558 (imgtec-ci20)
559 dd if="$fwdir/u-boot-spl.bin" of="$tgt" obs=512 seek=1 > /dev/null 2>&1
560 dd if="$fwdir/u-boot-dtb.img" of="$tgt" obs=1k seek=14 > /dev/null 2>&1
562 (banana-pro|banana-pro-zero|orange-pi0)
563 dd if="$fwdir/u-boot-sunxi-with-spl.bin" of="$tgt" bs=1024 seek=8 > /dev/null 2>&1
565 (solidrun-clearfog)
566 dd if="$fwdir/u-boot-spl.kwb" of="$tgt" bs=512 seek=1 > /dev/null 2>&1
568 (solidrun-imx6|phytec-imx6)
569 dd if="$fwdir/SPL" of="$tgt" bs=1024 seek=1 > /dev/null 2>&1
570 dd if="$fwdir/u-boot.img" of="$tgt" bs=1024 seek=69 > /dev/null 2>&1
572 (raspberry-pi|raspberry-pi0|raspberry-pi2|raspberry-pi3|raspberry-pi3-64|raspberry-pi4|raspberry-pi4-64|raspberry-pi5)
573 (( noformat )) || create_fs "$bootpart" ADKBOOT vfat
575 (phytec-wega)
576 (( noformat )) || create_fs "$bootpart" ADKBOOT ext4
580 case $target {
581 (atmel-ngw100)
582 (( noformat )) || create_fs "$rootpart" ADKROOT ext2
583 (( noformat )) || tune_fs "$rootpart"
586 (( noformat )) || create_fs "$rootpart" ADKROOT ext4
587 (( noformat )) || tune_fs "$rootpart"
590 (( quiet )) || print Extracting installation archive...
591 mount_fs "$rootpart" "$R" ext4
592 gzip -dc "$src" | (cd "$R"; tar -xpf -)
594 if (( datafssz )); then
595 mkdir -m0755 "$R"/data
596 ((keep)) || create_fs "$datapart" ADKDATA ext4
597 ((keep)) || tune_fs "$datapart"
598 case $target {
599 (raspberry-pi|raspberry-pi0|raspberry-pi2|raspberry-pi3|raspberry-pi3-64|raspberry-pi4|raspberry-pi4-64|raspberry-pi5|phytec-wega)
600 echo "/dev/mmcblk0p3 /data ext4 rw 0 0" >> "$R"/etc/fstab
602 (banana-pro|orange-pi0|solidrun-clearfog|rockpi4-plus)
603 echo "/dev/mmcblk0p2 /data ext4 rw 0 0" >> "$R"/etc/fstab
605 (solidrun-imx6|phytec-imx6)
606 echo "/dev/mmcblk1p2 /data ext4 rw 0 0" >> "$R"/etc/fstab
609 if [[ -d $datapartcontent ]]; then
610 mount_fs "$datapart" "$D" ext4
611 # strip trailing slash
612 case $datapartcontent in
613 *[!/]*/) datapartcontent=${datapartcontent%"${x##*[!/]}"};;
614 esac
615 cp -R $datapartcontent/* "$D"
619 (( quiet )) || print Finishing up with bootloader and kernel ...
620 case $target {
621 (raspberry-pi|raspberry-pi0|raspberry-pi2|raspberry-pi3|raspberry-pi3-64|raspberry-pi4|raspberry-pi4-64|raspberry-pi5)
622 mount_fs "$bootpart" "$B" vfat
623 for x in "$R"/boot/*; do
624 [[ -e "$x" ]] && mv -f "$R"/boot/* "$B/"
625 break
626 done
627 for x in "$fwdir"/*.dtb; do
628 [[ -e "$x" ]] && cp "$fwdir"/*.dtb "$B/"
629 break
630 done
631 # use static dtoverlay, rename to *.dtb
632 mkdir "$B/"overlays
633 for x in "$fwdir"/overlays/*.dtbo; do
634 y=$(basename ${x} .dtbo)
635 [[ -e "$x" ]] && cp "$fwdir"/overlays/${y}.dtbo "$B/"overlays/${y}.dtbo
636 done
637 for x in "$fwdir"/overlays/*.dtb; do
638 y=$(basename ${x} .dtb)
639 [[ -e "$x" ]] && cp "$fwdir"/overlays/${y}.dtb "$B/"overlays/${y}.dtb
640 done
641 umount_fs "$B"
643 (phytec-wega)
644 mount_fs "$bootpart" "$B" ext4
645 for x in "$R"/boot/*; do
646 [[ -e "$x" ]] && mv -f "$R"/boot/* "$B/"
647 break
648 done
649 for x in "$fwdir"/*.dtb; do
650 [[ -e "$x" ]] && cp "$fwdir"/*.dtb "$B/"
651 break
652 done
653 umount_fs "$B"
655 (rockpi4-plus)
656 for x in "$fwdir"/*.dtb; do
657 [[ -e "$x" ]] && cp "$fwdir"/*.dtb "$R/boot/"
658 break
659 done
660 mkimage -A arm64 -O linux -T script -C none -a 0 -e 0 \
661 -n "RockPI4-Plus" \
662 -d $fwdir/boot.script.rockpi4 $R/boot/boot.scr.uimg
664 (solidrun-clearfog)
665 for x in "$fwdir"/*.dtb; do
666 [[ -e "$x" ]] && cp "$fwdir"/*.dtb "$R/boot/"
667 break
668 done
669 mkimage -A arm -O linux -T script -C none -a 0 -e 0 \
670 -n "SolidrunClearfog" \
671 -d $fwdir/boot.script.clearfog $R/boot/boot.scr.uimg
673 (solidrun-imx6)
674 for x in "$fwdir"/*.dtb; do
675 [[ -e "$x" ]] && cp "$fwdir"/*.dtb "$R/boot/"
676 break
677 done
678 mkimage -A arm -O linux -T script -C none -a 0 -e 0 \
679 -n "SolidrunImx6" \
680 -d $fwdir/boot.script.imx6 $R/boot/boot.scr.uimg
682 (phytec-imx6)
683 for x in "$fwdir"/*.dtb; do
684 [[ -e "$x" ]] && cp "$fwdir"/*.dtb "$R/boot/"
685 break
686 done
687 mkimage -A arm -O linux -T script -C none -a 0 -e 0 \
688 -n "PhytecImx6" \
689 -d $fwdir/boot.script.phytec $R/boot/boot.scr.uimg
691 (orange-pi0)
692 for x in "$fwdir"/*.dtb; do
693 [[ -e "$x" ]] && cp "$fwdir"/*.dtb "$R/boot/"
694 break
695 done
696 mkimage -A arm -O linux -T script -C none -a 0 -e 0 \
697 -n "OrangePI Zero" \
698 -d $fwdir/boot.script.opi $R/boot/boot.scr.uimg
700 (banana-pro)
701 for x in "$fwdir"/*.dtb; do
702 [[ -e "$x" ]] && cp "$fwdir"/*.dtb "$R/boot/"
703 break
704 done
705 mkimage -A arm -O linux -T script -C none -a 0 -e 0 \
706 -n "BananaPro" \
707 -d $fwdir/boot.script.bpi $R/boot/boot.scr.uimg
709 (banana-pro-zero)
710 for x in "$fwdir"/*.dtb; do
711 [[ -e "$x" ]] && cp "$fwdir"/*.dtb "$R/boot/"
712 break
713 done
714 mkimage -A arm -O linux -T script -C none -a 0 -e 0 \
715 -n "BananaProZero" \
716 -d $fwdir/boot.script.bpizero $R/boot/boot.scr.uimg
720 cd "$R"
721 dd if=$rnddev bs=16 count=1 >>etc/.rnd 2>/dev/null
722 (( quiet )) || print Fixing up permissions...
723 chown 0:0 tmp
724 chmod 1777 tmp
725 [[ -f usr/bin/sudo ]] && chmod 4755 usr/bin/sudo
727 if (( grub )); then
728 (( quiet )) || print Configuring GRUB2 bootloader...
729 mkdir -p boot/grub
731 print set default=0
732 print set timeout=1
733 if (( serial )); then
734 print serial --unit=0 --speed=$speed
735 print terminal_output serial
736 print terminal_input serial
737 consargs="console=ttyS0,$speed console=tty0"
738 else
739 print terminal_output console
740 print terminal_input console
741 consargs="console=tty0"
743 print
744 print 'menuentry "GNU/Linux (OpenADK)" {'
745 linuxargs="root=PARTUUID=$partuuid $consargs rootwait"
746 (( panicreboot )) && linuxargs="$linuxargs panic=$panicreboot"
747 print "\tlinux /boot/kernel $linuxargs"
748 print '}'
749 ) >boot/grub/grub.cfg
752 (( quiet )) || print Finishing up...
753 cd "$ADK_TOPDIR"
754 umount_fs "$R"
755 if (( datafssz )); then
756 umount_fs $datapart
758 rm -rf "$T"
759 exit 0