-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathwrite-sdcard
More file actions
executable file
·65 lines (51 loc) · 1.62 KB
/
write-sdcard
File metadata and controls
executable file
·65 lines (51 loc) · 1.62 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
#!/bin/bash
set -e
bin_dir="bin"
if [[ $EUID -ne 0 ]]; then
echo "This script must be run as root"
exit 1
fi
unzip smartcross-boot.zip -d $bin_dir
device="/dev/disk/by-id/usb-Prolific_Technology_Inc._SD_Card_Reader_ABCDEF0123456789AB-0:0"
for file in $bin_dir/idbloader.img $bin_dir/trust.img $bin_dir/uboot.img; do
if [ ! -e "$file" ]; then
echo "Error: $file does not exist, please run prepare-files script first"
exit 1
fi
done
if [ ! -e "$file" ]; then
echo "Error: sdcard not found"
exit 1
fi
device=$(realpath $device)
size=$(lsblk -nd --output SIZE -b "$device" | awk '{$1=int($1/(1024*1024*1024)); print $1}') # Calculate size in GB
echo "About to format $device (disk size $size GB)"
read -p "Continue (y/n)? " CONT
if [ "x$CONT" != "xy" ]; then
exit 0
fi
echo Creating partition table on device...
sgdisk -o -n 1:100M:1636M -c 1:"rootfs-a" -t 1:8300 -n 2:1637M:3173M -c 2:"rootfs-b" -t 2:8300 $device
echo Writing idbloader...
dd if=$bin_dir/idbloader.img of=$device seek=64
echo Writing uboot...
dd if=$bin_dir/uboot.img of=$device seek=16384
echo Writing trust...
dd if=$bin_dir/trust.img of=$device seek=24576
get_partition_path() {
disk_path="$1"
index="$2"
if [[ $disk_path =~ [0-9]$ ]]; then
partition_path="${disk_path}p${index}"
else
partition_path="${disk_path}${index}"
fi
echo "$partition_path"
}
echo Clearing uboot env...
dd if=/dev/zero of=$device seek=8064 count=128
part_dev=$(get_partition_path $device 1)
echo Writing rootfs image to $part_dev...
curl https://pgw-ray.t123yh.xyz:3/images/rootfs.ext2.gz | gzip -d | dd of=$part_dev bs=128k
echo Ejecting card...
eject $device