-
Notifications
You must be signed in to change notification settings - Fork 1
/
u-boot_for_starfive
executable file
·183 lines (156 loc) · 4.74 KB
/
u-boot_for_starfive
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
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
#!/bin/sh
# Usage function
function usage() {
cat >&2 <<EOF
${SH_FILE} is used to compile, generate and burn OpenSBI/U-Boot for StarFive RISC-V SoC
Usage: ${SH_FILE} -b board [-c] [-d] [-h]
Where:
-b name of the board to configure
-c copy firmware file
-d compile firmware in debug mode (when allowed)
-h this help page
Currently supported boards are: beaglev/starlight, visionfive and visionfive2/visionfive2-sdk
EOF
exit 0
}
# Error function
function error() {
echo -e "$@" >&2
exit 1
}
# Check binary function
function checkBin() {
typeset -r BIN=$1
which ${BIN} >/dev/null 2>&1 \
|| error "${BIN} not found!"
}
# Copy/Check function
function copy() {
typeset -r FILE=$1
typeset -r DEST=$2
cp ${FILE} ${DEST} >/dev/null 2>&1 \
|| error "Error while copying file ${FILE} to ${DEST}!"
}
# Variable(s)
typeset -r SH_FILE=${0##*/}
typeset -r TMPFS=/dev/shm
typeset -r U_BOOT_TMP=${TMPFS}/u-boot-tmp
typeset -r OPENSBI_TMP=${TMPFS}/opensbi-tmp
typeset -r U_BOOT_FIT=~/git/github/starfive/Tools/uboot_its/visionfive2-uboot-fit-image.its
typeset FW_FILE=${OPENSBI_TMP}/build/platform/generic/firmware/fw_payload.bin
typeset BOARD COPY DEBUG U_BOOT_BOARD U_BOOT_DIR SPL_FILE FW_FILE
# Get options
while getopts "b:cdh" ARG; do
case ${ARG} in
b) BOARD=${OPTARG}
;;
c) COPY="-c"
;;
d) DEBUG="-d"
;;
h|*) usage
;;
esac
done
shift $((OPTIND-1))
# Board model must be filled!
[[ -z "${BOARD}" ]] \
&& error "Board model must be filled!"
case ${BOARD} in
beaglev|starlight)
U_BOOT_DIR=~/git/github/starfive/starfive-tech_u-boot:JH7100_upstream_devel
U_BOOT_BOARD=starfive_jh7100_starlight_smode
OPENSBI_DIR=~/git/github/starfive/opensbi
;;
visionfive)
U_BOOT_DIR=~/git/github/starfive/starfive-tech_u-boot:JH7100_VisionFive_devel
U_BOOT_BOARD=starfive_jh7100_visionfive_smode
OPENSBI_DIR=~/git/github/starfive/opensbi
;;
visionfive2-sdk)
U_BOOT_DIR=~/git/github/starfive/starfive-tech_u-boot:JH7110_VisionFive2_devel
U_BOOT_BOARD=starfive_visionfive2
OPENSBI_DIR=~/git/github/starfive/starfive-tech_opensbi:JH7110_VisionFive2_devel
SPL_FILE=${U_BOOT_TMP}/spl/u-boot-spl.bin
;;
visionfive2)
U_BOOT_DIR=~/git/github/u-boot
U_BOOT_BOARD=visionfive2
OPENSBI_DIR=~/git/github/starfive/opensbi
SPL_FILE=${U_BOOT_TMP}/spl/u-boot-spl.bin
;;
esac
# Compilation order can differ depending on the board and the software used
case ${BOARD} in
beaglev|starlight|visionfive)
# Compile DDRInit, SecondBoot, U-Boot and OpenSBI
compile_riscv_ddr_init ${COPY} \
&& compile_riscv_second_boot ${COPY} \
&& compile_mainline_u-boot -a riscv64 -b ${U_BOOT_BOARD} -s ${U_BOOT_DIR} \
&& compile_mainline_opensbi ${DEBUG} ${COPY} -b ${BOARD} -s ${OPENSBI_DIR}
;;
visionfive2-sdk)
# Compile U-Boot and OpenSBI
compile_mainline_u-boot -a riscv64 -b ${U_BOOT_BOARD} -s ${U_BOOT_DIR} \
&& compile_mainline_opensbi ${DEBUG} ${COPY} -b ${BOARD} -s ${OPENSBI_DIR}
;;
visionfive2)
# Compile OpenSBI and U-Boot
compile_mainline_opensbi ${DEBUG} ${COPY} -b ${BOARD} -s ${OPENSBI_DIR} \
&& compile_mainline_u-boot -a riscv64 -b ${U_BOOT_BOARD} -s ${U_BOOT_DIR}
;;
esac
# Exit if an error occured!
(( $? )) && exit 1
# Go to OpenSBI directory
cd ${OPENSBI_TMPFS}
# Do specific post stuff depending on the board
case ${BOARD} in
beaglev|starlight|visionfive)
# fsz.sh is needed for these boards
checkBin fsz.sh
# Fix firmware file
fsz.sh ${FW_FILE} || error "Failed to fix ${FW_FILE}!"
FW_FILE=${FW_FILE}.out
;;
visionfive2-sdk)
checkBin spl_tool
# Create SPL file
spl_tool -c -f ${SPL_FILE}
SPL_FILE=${SPL_FILE}.normal.out
# Copy OpenSBI firmware/file locally
copy ${FW_FILE} ${PWD}
copy ${U_BOOT_FIT} ${PWD}
# Generate new payload file
FW_FILE=${BOARD}_fw_payload.img
${U_BOOT_TMP}/tools/mkimage \
-A riscv \
-f ${U_BOOT_FIT##*/} \
-T firmware \
-O u-boot \
${FW_FILE} || error "Failed to generate new ${FW_FILE}!"
;;
visionfive2)
# Get U-Boot version
eval $(sed -n 's/^VERSION[[:space:]]*=[[:space:]]\(.*\)/UBOOT_VERSION=\1/p' ${U_BOOT_TMP}/Makefile)
# Newer version of U-Boot already does this trick
if (( UBOOT_VERSION < 2024 )); then
checkBin spl_tool
# Create SPL file
spl_tool -c -f ${SPL_FILE}
fi
# U-Boot FW files
SPL_FILE=${SPL_FILE}.normal.out
FW_FILE=${U_BOOT_TMP}/u-boot.itb
;;
esac
# Copy firmware file(s) locally if asked
if [[ -n "${COPY}" ]]; then
for FILE in ${SPL_FILE} ${FW_FILE}; do
copy ${FILE} ${OLDPWD}
done
fi
# We need to go back into original directory
cd ${OLDPWD}
# Clean exit
exit $?