-
Notifications
You must be signed in to change notification settings - Fork 79
/
build-zephyr.sh
executable file
·116 lines (96 loc) · 2.82 KB
/
build-zephyr.sh
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
#!/bin/bash
if [ "`whoami`" = "root" ]
then
echo "Running the script as root is not permitted"
exit 1
fi
CALLED=$_
[[ "${BASH_SOURCE[0]}" != "${0}" ]] && SOURCED=1 || SOURCED=0
SCRIPT_SRC=$(realpath ${BASH_SOURCE[0]})
SCRIPT_DIR=$(dirname $SCRIPT_SRC)
TOP_DIR=$(realpath $SCRIPT_DIR/..)
if [ $SOURCED = 1 ]; then
echo "You must run this script, rather then try to source it."
echo "$SCRIPT_SRC"
exit 1
fi
if [ -z "$HDMI2USB_ENV" ]; then
echo "You appear to not be inside the HDMI2USB environment."
echo "Please enter environment with:"
echo " source scripts/enter-env.sh"
exit 1
fi
# Imports TARGET, PLATFORM, CPU and TARGET_BUILD_DIR from Makefile
eval $(make --silent env)
make info
source $SCRIPT_DIR/settings.sh
# local version of SDK has a higher priority as it might contain a newer SDK
SDK_LOCAL_LOCATION="$BUILD_DIR/zephyr_sdk"
if [ -d "$SDK_LOCAL_LOCATION" ]; then
export ZEPHYR_SDK_INSTALL_DIR="$SDK_LOCAL_LOCATION"
elif [ -z "$ZEPHYR_SDK_INSTALL_DIR" ]; then
echo "Zephyr SDK not found"
echo "Did you forget to run scripts/download-env.sh?"
exit 1
fi
export ZEPHYR_TOOLCHAIN_VARIANT=zephyr
echo "Using Zephyr SDK from: $ZEPHYR_SDK_INSTALL_DIR"
set -x
set -e
ZEPHYR_REPO=https://github.com/zephyrproject-rtos/zephyr
ZEPHYR_REPO_BRANCH=master
case $CPU in
vexriscv)
case "$CPU_VARIANT" in
lite* | standard* | full* | linux*)
TARGET_BOARD=litex_vexriscv
;;
*)
echo "Zephyr needs a CPU_VARIANT set to at least 'lite' for the support of 'ecall' instruction."
echo "Supported variants: lite, lite+debug, standard, standard+debug, full, full+debug, linux."
echo "Currently selected variant: $CPU_VARIANT"
exit 1
;;
esac
;;
*)
echo "CPU $CPU isn't supported at the moment."
exit 1
;;
esac
if [ "$FIRMWARE" != "zephyr" ]; then
echo "When building Zephyr you should set FIRMWARE to 'zephyr'."
exit 1
fi
ZEPHYR_SRC_DIR=$THIRD_DIR/zephyr
OUTPUT_DIR=$TOP_DIR/$TARGET_BUILD_DIR/software/zephyr
export ZEPHYR_BASE=$ZEPHYR_SRC_DIR/zephyr
ZEPHYR_APP=$ZEPHYR_BASE/samples/${ZEPHYR_APP:-subsys/shell/shell_module}
LITEX_CONFIG_FILE="$TOP_DIR/$TARGET_BUILD_DIR/test/csr.csv"
if [ ! -f "$LITEX_CONFIG_FILE" ]; then
make firmware
fi
if [ ! -d "$ZEPHYR_SRC_DIR" ]; then
mkdir -p $ZEPHYR_SRC_DIR
cd $ZEPHYR_SRC_DIR
west init \
--manifest-url $ZEPHYR_REPO \
--manifest-rev $ZEPHYR_REPO_BRANCH
fi
# generate DTS from LiteX configuration
mkdir -p $OUTPUT_DIR
$THIRD_DIR/litex-renode/generate-zephyr-dts.py \
--dts $OUTPUT_DIR/litex.overlay \
--config $OUTPUT_DIR/config.overlay \
$LITEX_CONFIG_FILE
cat $OUTPUT_DIR/config.overlay | xargs west build \
-b $TARGET_BOARD \
--build-dir $OUTPUT_DIR \
$ZEPHYR_APP \
-- \
-DZEPHYR_SDK_INSTALL_DIR=$ZEPHYR_SDK_INSTALL_DIR \
-DDTC_OVERLAY_FILE=$OUTPUT_DIR/litex.overlay
cd $OUTPUT_DIR
if [ ! -f "firmware.bin" ]; then
ln -s zephyr/zephyr.bin firmware.bin
fi