-
-
Notifications
You must be signed in to change notification settings - Fork 6
/
image.sh
executable file
·85 lines (77 loc) · 1.96 KB
/
image.sh
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
#!/bin/bash
#
# SPDX-License-Identifier: GPL-3.0-or-later
# myMPDos (c) 2020-2023 Juergen Mang <mail@jcgames.de>
# https://github.com/jcorporation/myMPDos
#
#save script path and change to it
STARTPATH=$(dirname "$(realpath "$0")")
cd "$STARTPATH" || exit 1
source config || { echo "config not found"; exit 1; }
IMAGE=$(ls -t "$STARTPATH"/images/myMPDos-"$ARCH"-*.img 2>/dev/null | head -1)
if [ "$IMAGE" = "" ]
then
echo "No image found, build it with ./build.sh"
exit 1
else
echo "Image: $IMAGE"
fi
mountimage() {
install -d "$STARTPATH/tmp/mnt"
LOOP=$(sudo losetup --partscan --show -f "$IMAGE")
echo "Mounting image on $STARTPATH/tmp/mnt"
sudo mount -ouid="$BUILDUSER" "${LOOP}p1" "$STARTPATH/tmp/mnt" || exit 1
return 0
}
umountimage() {
./build.sh umountbuild
}
burnimage() {
SDCARD=$1
[ "$SDCARD" = "" ] && exit 1
if mount | grep -q "$SDCARD"
then
echo "$SDCARD seems to be mounted"
exit 1
fi
echo "Transfering $IMAGE to $SDCARD"
sudo dd status=progress bs=4M oflag=sync if="$IMAGE" of="$SDCARD"
}
startimage() {
mountimage
rm "$STARTPATH"/tmp/mnt/boot/modloop-*
cp "$STARTPATH/tmp/$ARCH/netboot/boot/modloop-lts" tmp/mnt/boot/
umountimage
$QEMU \
-M virt -m "$BUILDRAM" -cpu "$CPU" -smp "$BUILDCPUS" \
-kernel "$STARTPATH/tmp/$ARCH/netboot/boot/$KERNEL" \
-initrd "$STARTPATH/tmp/$ARCH/netboot/boot/$INITRAMFS" \
-append "console=ttyAMA0 ip=dhcp" \
-nographic \
-drive "file=${IMAGE},format=raw" \
-nic user,id=mynet0,net=192.168.76.0/24,dhcpstart=192.168.76.9
}
case "$1" in
start)
startimage
;;
mount)
mountimage
;;
umount)
umountimage
;;
burn)
if [ "$2" = "" ]
then
echo "Usage: $0 burn <sdcard device>"
exit 1
fi
burnimage "$2"
;;
*)
echo "Usage: $0 (start|mount|umount|burn)"
exit 1
;;
esac
exit 0