-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathbuild_example.sh
executable file
·213 lines (167 loc) · 6.48 KB
/
build_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
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
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
#!/bin/bash
# 参数说明:
# $1 - example name: echo_app_top
# $2 - example version: 1.0.0
# $3 - header files directory:
# $4 - libs directory:
# $5 - libs: tuyaos tuyaapp
# $6 - output directory:
set -e
cd `dirname $0`
APP_BIN_NAME=$1
APP_VERSION=$2
HEADER_DIR=$3
LIBS_DIR=$4
LIBS=$5
OUTPUT_DIR=$6
USER_CMD=$7
TARGET_PLATFORM=bk7236
# echo APP_BIN_NAME=$APP_BIN_NAME
# echo APP_VERSION=$APP_VERSION
# echo USER_CMD=$USER_CMD
# echo LIBS_DIR=$LIBS_DIR
# echo LIBS=$LIBS
# echo OUTPUT_DIR=$OUTPUT_DIR
# echo HEADER_DIR=$HEADER_DIR
# echo TARGET_PLATFORM=$TARGET_PLATFORM
USER_SW_VER=`echo $APP_VERSION | cut -d'-' -f1`
APP_PATH=../../example
PYTHON_CMD="python3"
PIP_CMD="pip3"
enable_python_env() {
if [ -z $1 ]; then
echo "Please input virtual environment name."
exit 1
fi
VIRTUAL_NAME=$1
SCRIPT_DIR=$PWD
VIRTUAL_ENV=$SCRIPT_DIR/$VIRTUAL_NAME
echo "SCRIPT_DIR $VIRTUAL_ENV"
if command -v python3 &>/dev/null; then
PYTHON_CMD=python3
elif command -v python &>/dev/null && python --version | grep -q '^Python 3'; then
PYTHON_CMD=python
else
echo "Python 3 is not installed."
exit 1
fi
if [ ! -d "${VIRTUAL_ENV}" ]; then
echo "Virtual environment not found. Creating one..."
$PYTHON_CMD -m venv "${VIRTUAL_ENV}" || { echo "Failed to create virtual environment."; exit 1; }
echo "Virtual environment created at ${VIRTUAL_ENV}"
else
echo "Virtual environment already exists."
fi
ACTIVATE_SCRIPT=${VIRTUAL_ENV}/bin/activate
PYTHON_CMD="${VENV_DIR}/bin/python3"
if [ -f "$ACTIVATE_SCRIPT" ]; then
echo "Activate python virtual environment."
source ${ACTIVATE_SCRIPT} || { echo "Failed to activate virtual environment."; exit 1; }
${PIP_CMD} install -r "requirements.txt" || { echo "Failed to install required Python packages."; deactivate; exit 1; }
else
echo "Activate script not found."
exit 1
fi
}
disable_python_env() {
if [ -z $1 ]; then
echo "Please input virtual environment name."
exit 1
fi
VIRTUAL_NAME=$1
SCRIPT_DIR=$PWD
VIRTUAL_ENV=$SCRIPT_DIR/$VIRTUAL_NAME
echo "SCRIPT_DIR $VIRTUAL_ENV"
if [ -n "$VIRTUAL_ENV" ]; then
echo "Deactivate python virtual environment."
deactivate
else
echo "No virtual environment is active."
fi
}
bash t3_os/toolchain_get.sh $(pwd)/../tools || { echo "Failed to setup toolchain."; exit 1; }
enable_python_env "tuya_build_env" || { echo "Failed to enable python virtual environment."; exit 1; }
export TUYA_APP_PATH=$APP_PATH
export TUYA_APP_NAME=$APP_BIN_NAME
export TUYA_PROJECT_DIR=$(pwd)
export TUYA_HEADER_DIR=$HEADER_DIR
export TUYA_LIBS_DIR=$LIBS_DIR
export TUYA_LIBS=$LIBS
# Remove TUYA APP OBJs first
if [ -e "${APP_OBJ_PATH}/$APP_BIN_NAME/src" ]; then
for i in `find ${APP_OBJ_PATH}/$APP_BIN_NAME/src -type d`; do
echo "Deleting $i"
rm -rf $i/*.o
done
fi
TOP_DIR=$(pwd)
if [ -f ${TOP_DIR}/.app ]; then
OLD_APP_BIN_NAME=$(cat ${TOP_DIR}/.app)
echo OLD_APP_BIN_NAME: ${OLD_APP_BIN_NAME}
fi
echo ${APP_BIN_NAME} > ${TOP_DIR}/.app
if [ "$OLD_APP_BIN_NAME" != "$APP_BIN_NAME" ]; then
make clean -C ./t3_os/armino/
rm -rf ./t3_os/tuya_build
echo "AUTO CLEAN SUCCESS"
fi
if [ x$USER_CMD = "xclean" ];then
make clean -C ./t3_os/armino/
rm -rf ./t3_os/tuya_build
echo "*************************************************************************"
echo "************************CLEAN SUCCESS************************************"
echo "*************************************************************************"
exit 0
fi
cd t3_os
TARGET_PROJECT=tuya_app
echo "Start Compile"
make ${TARGET_PLATFORM} PROJECT=app PROJECT_DIR=../${TARGET_PROJECT} BUILD_DIR=../tuya_build PROJECT_LIBS=app APP_NAME=$APP_BIN_NAME APP_VERSION=$USER_SW_VER APP_DIR=$APP_PATH -j -C ./armino/ APP_VERSION=${APP_VERSION}
res=$(echo $?)
# delete file whether it exists
rm -f ${TARGET_PROJECT}/.tmp_component_desc
if [ "x${TUYA_LWIP_STACK_USED}" = "xlwip_bk" ]; then
mv .${TARGET_PLATFORM}_config.save ${TARGET_PROJECT}/config/${TARGET_PLATFORM}/config
fi
if [ $res -ne 0 ]; then
echo "make failed"
exit -1
fi
echo "Start Combined"
if [ ! -d "$OUTPUT_DIR" ]; then
mkdir -p $OUTPUT_DIR
fi
DEBUG_FILE_PATH=${OUTPUT_DIR}/debug
if [ ! -d "$DEBUG_FILE_PATH" ]; then
mkdir -p $DEBUG_FILE_PATH
fi
if [ -e "./tuya_build/${TARGET_PLATFORM}/all-app.bin" ]; then
# B_OFFSET=$(grep "_ty_section_start" -r ./tuya_build/${TARGET_PLATFORM}/app.map | awk '{print strtonum($1)}')
# B_OFFSET_NUM=$(printf "%d" "$((${B_OFFSET}-65536))")
B_OFFSET=$(python3 ./get_map_section.py ./tuya_build/${TARGET_PLATFORM}/app.map "_ty_section_start")
if [ $? -ne 0 ]; then
echo "get map section failed"
exit -1
fi
OFFSET=65536
B_OFFSET_NUM=$(expr $B_OFFSET - $OFFSET)
echo $B_OFFSET_NUM
python3 ./format_up_bin.py ./tuya_build/${TARGET_PLATFORM}/app_pack.bin ./tuya_build/${TARGET_PLATFORM}/app_ug.bin 3B6000 1000 0 1000 18D0 ${B_OFFSET_NUM} -v
./diff2ya ./tuya_build/${TARGET_PLATFORM}/app_ug.bin ./tuya_build/${TARGET_PLATFORM}/app_ug.bin ./tuya_build/${TARGET_PLATFORM}/app_ota_ug.bin 0
cp ./tuya_build/${TARGET_PLATFORM}/app_ota_ug.bin $OUTPUT_DIR/$APP_BIN_NAME"_UG_"$USER_SW_VER.bin
cp ./tuya_build/${TARGET_PLATFORM}/app_pack.bin $OUTPUT_DIR/$APP_BIN_NAME"_UA_"$USER_SW_VER.bin
cp ./tuya_build/${TARGET_PLATFORM}/all-app.bin $OUTPUT_DIR/$APP_BIN_NAME"_QIO_"$USER_SW_VER.bin
cp ./tuya_build/${TARGET_PLATFORM}/app.elf $OUTPUT_DIR/$APP_BIN_NAME"_"$USER_SW_VER.elf
cp ./tuya_build/${TARGET_PLATFORM}/app.map $OUTPUT_DIR/$APP_BIN_NAME"_"$USER_SW_VER.map
cp ./tuya_build/${TARGET_PLATFORM}/app.nm $OUTPUT_DIR/$APP_BIN_NAME"_"$USER_SW_VER.nm
cp ./tuya_build/${TARGET_PLATFORM}/app.txt $OUTPUT_DIR/$APP_BIN_NAME"_"$USER_SW_VER.txt
cp ./tuya_build/${TARGET_PLATFORM}/size_map* $OUTPUT_DIR/
fi
echo "*************************************************************************"
echo "*************************************************************************"
echo "*************************************************************************"
echo "*********************${APP_BIN_NAME}_$APP_VERSION.bin********************"
echo "*************************************************************************"
echo "**********************COMPILE SUCCESS************************************"
echo "*************************************************************************"
disable_python_env "build_env"