-
Notifications
You must be signed in to change notification settings - Fork 1
/
flash_vf2
executable file
·58 lines (49 loc) · 1.45 KB
/
flash_vf2
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
#!/bin/sh
# Variable(s)
typeset DEV=$1
typeset -l DEV_LABEL
typeset BBL_DEV FSBL_DEV
# DEV should be specified
if [[ -z "${DEV}" ]]; then
echo "Device is missing!" >&2
exit 1
fi
# Sudo is needed here!
if ! sudo id -u >/dev/null 2>&1; then
echo "root permissions are needed! Please configure sudo!" >&2
exit 1
fi
# GPT should be configured
DEV_LABEL=$(sudo fdisk -l ${DEV} 2>/dev/null \
| awk '/Disklabel type:/ { print $NF }')
if [[ ${DEV_LABEL} != "gpt" ]]; then
echo "GPT disklabel should be configured on ${DEV}!" >&2
exit 1
fi
# Automatically get the partition numbers
BBL_DEV=$(sudo fdisk -l ${DEV} 2>/dev/null \
| awk '/HiFive BBL/ { print $1 }')
FSBL_DEV=$(sudo fdisk -l ${DEV} 2>/dev/null \
| awk '/(HiFive FSBL|Linux extended boot)/ { print $1 }')
# Abort if there is no BBL/EXTBOOT device
if [[ -z "${BBL_DEV}" || -z "${FSBL_DEV}" ]]; then
echo "BBL and/or FSBL partitions are not correctly configured!" >&2
exit 1
fi
# Flash firmwares
echo -e "Flashing VisionFive2 SPL firmware on ${DEV}...\t\c"
dd if=u-boot-spl.bin.normal.out \
of=${BBL_DEV} \
conv=fsync \
iflag=fullblock,sync \
oflag=direct >/dev/null 2>&1 && sync
(( $? == 0 )) && echo "OK!" || echo "ERROR!"
echo -e "Flashing VisionFive2 U-Boot firmware on ${DEV}...\t\c"
dd if=u-boot.itb \
of=${FSBL_DEV} \
conv=fsync \
iflag=fullblock,sync \
oflag=direct >/dev/null 2>&1 && sync
(( $? == 0 )) && echo "OK!" || echo "ERROR!"
# Clean exit
exit $?