-
Notifications
You must be signed in to change notification settings - Fork 9
Expand file tree
/
Copy pathbuild-images.sh
More file actions
executable file
·69 lines (58 loc) · 2.3 KB
/
build-images.sh
File metadata and controls
executable file
·69 lines (58 loc) · 2.3 KB
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
#!/bin/bash
: "${UBOOT_OUT:=prebuilt/u-boot}"
: "${IMG_OUT:=out}"
: "${IMGSIZE:=4GiB}"}
set -e
TIMESTAMP=`date -u '+%Y%m%d-%H%M'`
: "${BUILD_ID:=$TIMESTAMP}"
mkdir -p "$IMG_OUT"
if [ ! -f "$IMG_OUT"/debian-rootfs.img.zst -o "$UPDATE_ROOTFS" ]; then
./build-rootfs-img.sh
fi
TMPDIR=`mktemp -d`
for s in 512 4096; do
echo "Creating images for $s-byte sector size"
truncate -s "$IMGSIZE" "$TMPDIR"/debian-"$s"-nobootloader-"$BUILD_ID".img
if [ -c /dev/kvm -a -w /dev/kvm ]; then
cp -f partitions-script.sh "$IMG_OUT"/partitions-script.sh
fakemachine \
-b kvm \
-S "$s" \
-i "$TMPDIR"/debian-"$s"-nobootloader-"$BUILD_ID".img \
-e IMG:/artifacts/debian-rootfs.img.zst \
-e DISK:/dev/disk/by-fakemachine-label/fakedisk-0 \
-e PART:/dev/disk/by-fakemachine-label/fakedisk-0-part2 \
-e BUILD_ID:\""$BUILD_ID"\" \
-v "$IMG_OUT":/artifacts \
-- /artifacts/partitions-script.sh
rm -f "$IMG_OUT"/partitions-script.sh
else
LOOPDEV=`sudo losetup -b "$s" -fP --show "$TMPDIR"/debian-"$s"-nobootloader-"$BUILD_ID".img`
sudo \
IMG="$IMG_OUT"/debian-rootfs.img.zst \
DISK="$LOOPDEV" \
PART="$LOOPDEV"p2 \
BUILD_ID="$BUILD_ID" \
./partitions-script.sh
sudo losetup -d "$LOOPDEV"
fi
for i in `basename -a "$UBOOT_OUT"/*`; do
echo "$i board:"
echo " - Copying the base image"
cp "$TMPDIR"/debian-"$s"-nobootloader-"$BUILD_ID".img "$TMPDIR"/debian-"$s"-"$i"-"$BUILD_ID".img
echo " - Adding a board-specific bootloader"
dd if="$UBOOT_OUT"/"$i"/u-boot-rockchip.bin of="$TMPDIR"/debian-"$s"-"$i"-"$BUILD_ID".img seek=64 conv=notrunc
echo " - Creating a block map"
bmaptool create -o "$IMG_OUT"/debian-"$s"-"$i"-"$BUILD_ID".img.bmap "$TMPDIR"/debian-"$s"-"$i"-"$BUILD_ID".img
echo " - Compressing the final image"
pigz -c "$TMPDIR"/debian-"$s"-"$i"-"$BUILD_ID".img > "$IMG_OUT"/debian-"$s"-"$i"-"$BUILD_ID".img.gz
rm -f "$TMPDIR"/debian-"$s"-"$i"-"$BUILD_ID".img
done
echo "nobootloader image:"
echo " - Creating a block map"
bmaptool create -o "$IMG_OUT"/debian-"$s"-nobootloader-"$BUILD_ID".img.bmap "$TMPDIR"/debian-"$s"-nobootloader-"$BUILD_ID".img
echo " - Compressing the final image"
pigz -c "$TMPDIR"/debian-"$s"-nobootloader-"$BUILD_ID".img > "$IMG_OUT"/debian-"$s"-nobootloader-"$BUILD_ID".img.gz
rm -f "$TMPDIR"/debian-"$s"-nobootloader-"$BUILD_ID".img
done
rm -rf "$TMPDIR"