-
Notifications
You must be signed in to change notification settings - Fork 1
/
compile_riscv_ddr_init
executable file
·82 lines (66 loc) · 1.73 KB
/
compile_riscv_ddr_init
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
#!/bin/sh
# Usage function
function usage() {
cat >&2 <<EOF
${SH_FILE} is used to compile StarFive DDR Init firmware
Usage: ${SH_FILE} [-c] [-h]
Where:
-c copy firmware file
-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 ARCH=riscv64
typeset -r SH_FILE=${0##*/}
typeset -r TMPFS=/dev/shm/ddr-init-tmp
typeset -r FW_FILE="${TMPFS}/build/ddrinit-2133-$(date +%y%m%d).bin.out"
typeset -x SRC_DIR=~/git/github/starfive/JH7100_ddrinit
typeset COPY
# Get options
while getopts "ch" ARG; do
case ${ARG} in
c) COPY=1
;;
h|*) usage
;;
esac
done
shift $((OPTIND-1))
# Define some vars according to the arch
typeset -x CROSS_COMPILE=${ARCH}-unknown-elf-
typeset -x PATH=~/cross-compile/riscv64/riscv64-unknown-elf-toolchain-10.2.0-2020.12.8-x86_64-linux-ubuntu14/bin:${PATH}
# 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 source in the tmpfs directory
rsync -aq ${SRC_DIR}/ ${TMPFS} \
|| error "Cannot copy ${SRC_DIR}/* in ${TMPFS}!"
# Cleanup build
echo "- Cleaning build directory..."
cd ${TMPFS}/build
make clean && make distclean
# Compile
echo "- Compile DDR Init..."
make || error "Failed to compile U-Boot!"
# Copy firmware file locally if asked
(( COPY )) && copy ${FW_FILE} ${OLDPWD}
# We need to go back into original directory
cd ${OLDPWD}
# Clean exit
exit 0