-
Notifications
You must be signed in to change notification settings - Fork 1
/
compile_mainline_u-boot
executable file
·142 lines (119 loc) · 3.36 KB
/
compile_mainline_u-boot
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
#!/bin/sh
# Usage function
function usage() {
cat >&2 <<EOF
${SH_FILE} is used to compile official U-Boot binary
Usage: ${SH_FILE} -a <arch> -b <board model> [-h] [-s dir]
Where:
-a type of architecture (for example: arm64, riscv64, etc.)
-b name of the board to configure (for example: khadas-vim, libretech_all_h3_cc_h5, etc.)
-s U-Boot source directory
-h this help page
EOF
exit 0
}
# Error function
function error() {
echo -e "$@" >&2
exit 1
}
# 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/u-boot-tmp
typeset -x U_BOOT_DIR=~/git/github/u-boot
typeset -x ATF_FW_FILE=$(ls ${PWD}/atf-bl31.* 2>/dev/null)
typeset -x CRUST_FW_FILE=$(ls ${PWD}/scp.* 2>/dev/null)
typeset -x SCP=/dev/null
typeset -x ARCH BOARD U_BOOT_BRANCH
# Get options
while getopts "a:b:s:h" ARG; do
case ${ARG} in
a) ARCH=${OPTARG}
;;
b) BOARD=${OPTARG}
;;
s) U_BOOT_DIR=${OPTARG}
;;
h|*) usage
;;
esac
done
shift $((OPTIND-1))
# Arch must be filled!
[[ -z "${ARCH}" ]] \
&& error "Architecture must be filled!\n"
# Board model must be filled!
[[ -z "${BOARD}" ]] \
&& error "Board model must be filled!\n"
# Define some vars according to the arch
typeset -x CROSS_COMPILE=${ARCH}-elf-
case ${ARCH} in
aarch64)
typeset -x PATH=~/cross-compile/aarch64/gcc-linaro-7.5.0-2019.12-x86_64_aarch64-elf/bin:$PATH
;;
riscv64)
# Current version uses cross-compiler provided by the OS
# Packages cross-riscv64-elf-gcc* or cross-riscv64-gcc* and cross-riscv64-binutils
CROSS_COMPILE=${ARCH}-suse-linux-
;;
*)
error "Unknown architecture '${ARCH}'!\n"
;;
esac
# Define some options according to the board
case ${BOARD} in
visionfive2)
echo "- OpenSBI Firmware detected!"
BOARD=starfive_visionfive2
export OPENSBI=${TMPFS}/../opensbi-tmp/build/platform/generic/firmware/fw_dynamic.bin
;;
esac
# Extract git branch if provided
if [[ "${U_BOOT_DIR#*:}" != "${U_BOOT_DIR}" ]]; then
U_BOOT_BRANCH=${U_BOOT_DIR#*:}
U_BOOT_DIR=${U_BOOT_DIR%:*}
fi
# Is ATF firmware detected?
if [[ -s "${ATF_FW_FILE}" ]]; then
echo "- ATF Firmware detected!"
export BL31=${ATF_FW_FILE}
fi
# Is CRUST firmware detected?
# SCP is the variable used by U-Boot
if [[ -s "${CRUST_FW_FILE}" ]]; then
echo "- CRUST Firmware detected!"
export SCP=${CRUST_FW_FILE}
fi
# Remove old TMPFS and re-create it
echo "- Cleaning/Creating ${TMPFS} directory..."
rm -rf ${TMPFS} \
|| error "Cannot clean temporary directory ${TMPFS}!"
mkdir -p ${TMPFS} \
|| error "Cannot create temporary directory ${TMPFS}!"
# Copy u-boot source in the tmpfs directory
rsync -aq ${U_BOOT_DIR}/ ${TMPFS} \
|| error "Cannot copy ${U_BOOT_DIR}/* in ${TMPFS}!"
# Go to build directory
cd ${TMPFS}
# Change branch if needed
if [[ -n "${U_BOOT_BRANCH}" ]]; then
echo "- Checking out branch ${U_BOOT_BRANCH}..."
git checkout ${U_BOOT_BRANCH}
fi
# Cleanup U-Boot build
echo "- Cleaning U-Boot build directory..."
make clean && make mrproper && make distclean
# Compile U-Boot
echo "- Compile U-Boot for ${BOARD} board..."
make ${BOARD}_defconfig all || error "Failed to compile U-Boot!"
# We need to go back into original directory
cd ${OLDPWD}
# Clean exit
exit 0