forked from project-chip/connectedhomeip
-
Notifications
You must be signed in to change notification settings - Fork 0
/
mbed_example.sh
executable file
·125 lines (102 loc) · 3.67 KB
/
mbed_example.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
#!/usr/bin/env bash
#
# Copyright (c) 2020 Project CHIP Authors
#
# Licensed under the Apache License, Version 2.0 (the "License");
# you may not use this file except in compliance with the License.
# You may obtain a copy of the License at
#
# http://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writing, software
# distributed under the License is distributed on an "AS IS" BASIS,
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
# See the License for the specific language governing permissions and
# limitations under the License.
#
cd "$(dirname "$0")"/../..
CHIP_ROOT=$PWD
cd "$CHIP_ROOT"/examples
SUPPORTED_TOOLCHAIN=(GCC_ARM ARM)
SUPPORTED_TARGET_BOARD=(CY8CPROTO_062_4343W)
SUPPORTED_APP=(lock-app lighting-app pigweed-app all-clusters-app shell)
SUPPORTED_PROFILES=(release develop debug)
SUPPORTED_COMMAND=(build flash build-flash)
COMMAND=build
APP=lock-app
TARGET_BOARD=CY8CPROTO_062_4343W
TOOLCHAIN=GCC_ARM
PROFILE=release
for i in "$@"; do
case $i in
-a=* | --app=*)
APP="${i#*=}"
shift
;;
-b=* | --board=*)
TARGET_BOARD="${i#*=}"
shift
;;
-t=* | --toolchain=*)
TOOLCHAIN="${i#*=}"
shift
;;
-p=* | --profile=*)
PROFILE="${i#*=}"
shift
;;
-c=* | --command=*)
COMMAND="${i#*=}"
shift
;;
*)
# unknown option
;;
esac
done
if [[ ! " ${SUPPORTED_COMMAND[@]} " =~ " ${COMMAND} " ]]; then
echo "ERROR: Command $COMMAND not supported"
exit 1
fi
if [[ ! " ${SUPPORTED_TARGET_BOARD[@]} " =~ " ${TARGET_BOARD} " ]]; then
echo "ERROR: Target $TARGET_BOARD not supported"
exit 1
fi
if [[ ! " ${SUPPORTED_APP[@]} " =~ " ${APP} " ]]; then
echo "ERROR: Application $APP not supported"
exit 1
fi
if [[ ! " ${SUPPORTED_TOOLCHAIN[@]} " =~ " ${TOOLCHAIN} " ]]; then
echo "ERROR: Toolchain $TOOLCHAIN not supported"
exit 1
fi
if [[ ! " ${SUPPORTED_PROFILES[@]} " =~ " ${PROFILE} " ]]; then
echo "ERROR: Profile $PROFILE not supported"
exit 1
fi
set -e # Exit immediately if a command exits with a non-zero status.
# Activate Matter environment
source "$CHIP_ROOT"/scripts/activate.sh
# Build directory setup
BUILD_DIRECTORY="$APP"/mbed/build-"$TARGET_BOARD"/"$PROFILE"/
if [[ "$COMMAND" == *"build"* ]]; then
echo "Build $APP app for $TARGET_BOARD target with $TOOLCHAIN toolchain and $PROFILE profile"
# Set Mbed OS path
MBED_OS_PATH="$CHIP_ROOT"/third_party/mbed-os/repo
# Set Mbed OS posix socket submodule path
MBED_OS_POSIX_SOCKET_PATH="$CHIP_ROOT"/third_party/mbed-os-posix-socket/repo
# Generate config file for selected target, toolchain and hardware
mbed-tools configure -t "$TOOLCHAIN" -m "$TARGET_BOARD" -p "$APP"/mbed/ -o "$BUILD_DIRECTORY" --mbed-os-path "$MBED_OS_PATH"
# Remove old artifacts to force linking
rm -rf "$BUILD_DIRECTORY/chip-"*
# Build application
cmake -S "$APP/mbed" -B "$BUILD_DIRECTORY" -GNinja -DCMAKE_BUILD_TYPE="$PROFILE" -DMBED_OS_PATH="$MBED_OS_PATH" -DMBED_OS_POSIX_SOCKET_PATH="$MBED_OS_POSIX_SOCKET_PATH"
cmake --build "$BUILD_DIRECTORY"
fi
if [[ "$COMMAND" == *"flash"* ]]; then
echo "Flash $APP app to $TARGET_BOARD target [$TOOLCHAIN toolchain, $PROFILE profile]"
# Flash scripts path setup
MBED_FLASH_SCRIPTS_PATH=$CHIP_ROOT/config/mbed/scripts
# Flash application
"$OPENOCD_PATH"/bin/openocd -f "$MBED_FLASH_SCRIPTS_PATH/$TARGET_BOARD".tcl -c "program $BUILD_DIRECTORY/chip-mbed-$APP-example.elf verify reset exit"
fi