-
Notifications
You must be signed in to change notification settings - Fork 14
/
Copy pathconfigure_build.sh
executable file
·197 lines (170 loc) · 5.43 KB
/
configure_build.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
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
184
185
186
187
188
189
190
191
192
193
194
195
196
197
#!/bin/bash
# Copyright 2021 The IREE bare-metal Arm Authors
#
# Licensed under the Apache License v2.0 with LLVM Exceptions.
# See https://llvm.org/LICENSE.txt for license information.
# SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
# Bash script to configure a build for stm32f4.
if [[ $# -ne 2 && $# -ne 3 ]] ; then
echo "Usage: $0 <lib> <device>"
echo " or: $0 <lib> <device> <build type>"
exit 1
fi
if [[ $# -eq 3 ]] ; then
export BUILD_TYPE=$3
else
export BUILD_TYPE=MinSizeRel
fi
# Set the path to the GNU Arm Embedded Toolchain
if [ -z ${PATH_TO_ARM_TOOLCHAIN+x} ]; then
export PATH_TO_ARM_TOOLCHAIN="/usr/local/arm-gnu-toolchain-13.2.Rel1-x86_64-arm-none-eabi"
fi
# Set linker flags
case $1 in
cmsis)
echo "Building with CMSIS"
export CUSTOM_ARM_LINKER_FLAGS=""
export BUILD_WITH="CMSIS"
;;
libopencm3)
echo "Building with libopencm3"
export CUSTOM_ARM_LINKER_FLAGS="-nostartfiles"
export BUILD_WITH="LIBOPENCM3"
;;
*)
echo "Unknown lib. Use 'cmsis' or 'libopencm3"
exit 1
;;
esac
# Get path
PATH_TO_SCRIPT="`dirname $0`"
PATH_TO_REPO="`realpath ${PATH_TO_SCRIPT}/../`"
# Set path to linker script
case $2 in
nrf52840)
echo "Building for NRF52840"
export ARM_CPU="cortex-m4"
if [ -z ${PATH_TO_LINKER_SCRIPT+x} ]; then
export PATH_TO_LINKER_SCRIPT="${PATH_TO_REPO}/third_party/nrfx-custom/nrf52840_xxaa.ld"
fi
;;
nrf5340)
echo "Building for NRF5340"
export ARM_CPU="cortex-m33"
if [ -z ${PATH_TO_LINKER_SCRIPT+x} ]; then
export PATH_TO_LINKER_SCRIPT="${PATH_TO_REPO}/third_party/nrfx-custom/nrf5340_xxaa_application.ld"
fi
;;
stm32f407)
echo "Building for STM32F407"
export ARM_CPU="cortex-m4"
if [ "$1" == "cmsis" ]; then
export PATH_TO_LINKER_SCRIPT="${PATH_TO_REPO}/build_tools/stm32f407xg-cmsis.ld"
else
export PATH_TO_LINKER_SCRIPT="${PATH_TO_REPO}/third_party/libopencm3-custom/stm32f407xg.ld"
fi
;;
stm32f411xe)
echo "Building for STM32F411xE"
export ARM_CPU="cortex-m4"
if [ "$1" == "cmsis" ]; then
export PATH_TO_LINKER_SCRIPT="${PATH_TO_REPO}/build_tools/stm32f446xe-cmsis.ld"
else
export PATH_TO_LINKER_SCRIPT="${PATH_TO_REPO}/third_party/libopencm3-custom/stm32f446xe.ld"
fi
;;
stm32f446)
echo "Building for STM32F446"
export ARM_CPU="cortex-m4"
if [ "$1" == "cmsis" ]; then
export PATH_TO_LINKER_SCRIPT="${PATH_TO_REPO}/build_tools/stm32f446xe-cmsis.ld"
else
export PATH_TO_LINKER_SCRIPT="${PATH_TO_REPO}/third_party/libopencm3-custom/stm32f446xe.ld"
fi
;;
stm32f4xx)
echo "Building for STM32F4xx, high memory"
export ARM_CPU="cortex-m4"
if [ "$1" == "cmsis" ]; then
export PATH_TO_LINKER_SCRIPT="${PATH_TO_REPO}/build_tools/stm32f4xxxx-cmsis.ld"
else
export PATH_TO_LINKER_SCRIPT="${PATH_TO_REPO}/third_party/libopencm3-custom/stm32f4xxxx.ld"
fi
;;
stm32f746)
echo "Building for STM32F746"
export ARM_CPU="cortex-m7"
export PATH_TO_LINKER_SCRIPT="${PATH_TO_REPO}/build_tools/stm32f746xg-cmsis.ld"
;;
stm32l4r5)
echo "Building for STM32L4R5"
export ARM_CPU="cortex-m4"
export PATH_TO_LINKER_SCRIPT="${PATH_TO_REPO}/build_tools/stm32l4r5xi-cmsis.ld"
;;
stm32l476)
echo "Building for STM32L476"
export ARM_CPU="cortex-m4"
export PATH_TO_LINKER_SCRIPT="${PATH_TO_REPO}/build_tools/stm32l476xg-cmsis.ld"
;;
corstone-300)
echo "Building for Corstone-300"
export ARM_CPU="cortex-m55"
${PATH_TO_ARM_TOOLCHAIN}/bin/arm-none-eabi-gcc -E -x c -P -C -o platform_parsed.ld "${PATH_TO_REPO}/third_party/ethos-u-core-platform/targets/corstone-300/platform.ld"
export PATH_TO_LINKER_SCRIPT="`realpath platform_parsed.ld`"
patch platform_parsed.ld ${PATH_TO_REPO}/build_tools/platform_parsed.patch
;;
*)
echo "Unknown device. Supported devices are"
echo " 'nrf52840'"
echo " 'nrf5340'"
echo " 'stm32f407'"
echo " 'stm32f411xe'"
echo " 'stm32f446'"
echo " 'stm32f4xx'"
echo " 'stm32f746'"
echo " 'stm32l4r5'"
echo " 'stm32l476'"
echo " 'corstone-300'"
exit 1
;;
esac
# Set UART to use
case $2 in
nrf52840)
UART=0
;;
nrf5340)
UART=0
;;
*)
UART=2
;;
esac
# Set the path to the IREE host binary
export PATH_TO_IREE_HOST_BIN_DIR="`realpath ../build-iree-host-install/bin`"
# Check paths
if ! [ -f "$PATH_TO_LINKER_SCRIPT" ]; then
echo "Expected the path to linker script to be set correctly (got '$PATH_TO_LINKER_SCRIPT'): can't find linker script"
exit 1
fi
if ! [ -d "$PATH_TO_IREE_HOST_BIN_DIR" ]; then
echo "Expected the path to IREE host binary to be set correctly (got '$PATH_TO_IREE_HOST_BIN_DIR'): can't find directory"
exit 1
fi
# Configure project
cmake -GNinja \
-DBUILD_WITH_${BUILD_WITH}=ON \
-DCMAKE_TOOLCHAIN_FILE="${PATH_TO_REPO}/build_tools/cmake/arm-none-eabi-gcc.cmake" \
-DARM_TOOLCHAIN_ROOT="${PATH_TO_ARM_TOOLCHAIN}" \
-DARM_CPU="${ARM_CPU}" \
-DARM_TARGET="${2^^}" \
-DIREE_ERROR_ON_MISSING_SUBMODULES=OFF \
-DIREE_HAL_DRIVER_LOCAL_SYNC=ON \
-DIREE_HAL_EXECUTABLE_LOADER_EMBEDDED_ELF=ON \
-DIREE_HAL_EXECUTABLE_LOADER_VMVX_MODULE=ON \
-DIREE_HOST_BIN_DIR="${PATH_TO_IREE_HOST_BIN_DIR}" \
-DCUSTOM_ARM_LINKER_FLAGS="${CUSTOM_ARM_LINKER_FLAGS}" \
-DLINKER_SCRIPT="${PATH_TO_LINKER_SCRIPT}" \
-DUSE_UART${UART}=ON \
-DCMAKE_BUILD_TYPE=${BUILD_TYPE} \
..