-
Notifications
You must be signed in to change notification settings - Fork 1
/
build_example.sh
executable file
·240 lines (187 loc) · 7.38 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
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
#!/bin/bash
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=bk7258
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`
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 t5_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
APP_PATH=../../$APP_DIR
cd t5_os
tmp_gen_files_list=bk_idk/tools/build_tools/part_table_tools/config/gen_files_list.txt
if [ -f $tmp_gen_files_list ]; then
rm $tmp_gen_files_list
fi
touch $tmp_gen_files_list
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
make clean -C ./bk_idk/
echo "AUTO CLEAN SUCCESS"
fi
if [ x$USER_CMD = "xclean" ];then
make clean
make clean -C ./bk_idk/
# git checkout build/*
echo "*************************************************************************"
echo "************************CLEAN SUCCESS************************************"
echo "*************************************************************************"
exit 0
fi
TARGET_PROJECT=projects/tuya_app
echo "check bootloader.bin"
boot_file=bk_idk/components/bk_libs/bk7258/bootloader/normal_bootloader/bootloader.bin
check_value=$(md5sum ${boot_file} | awk '{print $1}')
ori_value=349ed5c2be62376f843cae86dc913713
if [ "x${check_value}" != "x${ori_value}" ]; then
echo -e "\033[1;31m bootloader.bin check failed, the file had been changed, please update md5 value in build.sh \033[0m"
exit
else
echo "bootloader check ok"
fi
echo "Start Compile"
make ${TARGET_PLATFORM} PROJECT_DIR=../${TARGET_PROJECT} BUILD_DIR=../build APP_NAME=$APP_BIN_NAME APP_VERSION=$USER_SW_VER -j
res=$(echo $?)
rm $tmp_gen_files_list
# 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
else
rm -rf ../tuyaos/tuya_os_adapter/lwip_intf_v2_1
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 [ ! -d "${DEBUG_FILE_PATH}/${TARGET_PLATFORM}" ]; then
# mkdir -p ${DEBUG_FILE_PATH}/${TARGET_PLATFORM}
# fi
# if [ ! -d "${DEBUG_FILE_PATH}/${TARGET_PLATFORM}_cp1" ]; then
# mkdir -p ${DEBUG_FILE_PATH}/${TARGET_PLATFORM}_cp1
# fi
#if [ ! -d "${DEBUG_FILE_PATH}/${TARGET_PLATFORM}_cp2" ]; then
# mkdir -p ${DEBUG_FILE_PATH}/${TARGET_PLATFORM}_cp2
#fi
if [ -e "./build/${TARGET_PLATFORM}/all-app.bin" ]; then
ofs=$(stat -c %s ./build/${TARGET_PLATFORM}/app.bin)
# TODO 1920k = 1966080 bytes
app0_max_size=1966080
if [ $ofs -gt $app0_max_size ]; then
echo "app0 file is too big, limit $app0_max_size, act $ofs"
exit -1
fi
pad_bytes_size=$(expr $app0_max_size - $ofs)
dd if=/dev/zero bs=1 count=${pad_bytes_size} | tr "\000" "\377" > pad_bin_file
cat ./build/${TARGET_PLATFORM}/app.bin pad_bin_file ./build/${TARGET_PLATFORM}/app1.bin > ./build/${TARGET_PLATFORM}/ua_file.bin
total_size=$(stat -c %s ./build/${TARGET_PLATFORM}/ua_file.bin)
echo "ofs: ${ofs}"
echo "pad_bytes_size: ${pad_bytes_size}"
echo "total_size: ${total_size}"
TUYA_FORMAT_BIN_TOOL=${TARGET_PROJECT}/tuya_scripts/format_up_bin.py
TUYA_DIFF_OTA_BIN_TOOL=${TARGET_PROJECT}/tuya_scripts/diff2ya
python3 ${TUYA_FORMAT_BIN_TOOL} ./build/${TARGET_PLATFORM}/ua_file.bin ./build/${TARGET_PLATFORM}/app_ug.bin 500000 1000 0 1000 18D0 $app0_max_size -v
./${TUYA_DIFF_OTA_BIN_TOOL} ./build/${TARGET_PLATFORM}/app_ug.bin ./build/${TARGET_PLATFORM}/app_ug.bin ./build/${TARGET_PLATFORM}/app_ota_ug.bin 0
rm pad_bin_file
cp ./build/${TARGET_PLATFORM}/all-app.bin $OUTPUT_DIR/$APP_BIN_NAME"_QIO_"$USER_SW_VER.bin
cp ./build/${TARGET_PLATFORM}/ua_file.bin $OUTPUT_DIR/$APP_BIN_NAME"_UA_"$USER_SW_VER.bin
cp ./build/${TARGET_PLATFORM}/app_ota_ug.bin $OUTPUT_DIR/$APP_BIN_NAME"_UG_"$USER_SW_VER.bin
cp ./build/${TARGET_PLATFORM}/app.elf $OUTPUT_DIR/$APP_BIN_NAME"_"$USER_SW_VER.elf
cp ./build/${TARGET_PLATFORM}/app.map $OUTPUT_DIR/$APP_BIN_NAME"_"$USER_SW_VER.map
cp ./build/${TARGET_PLATFORM}/app.nm $OUTPUT_DIR/$APP_BIN_NAME"_"$USER_SW_VER.nm
cp ./build/${TARGET_PLATFORM}/app.txt $OUTPUT_DIR/$APP_BIN_NAME"_"$USER_SW_VER.txt
cp ./build/${TARGET_PLATFORM}/size_map* $OUTPUT_DIR/
fi
echo "*************************************************************************"
echo "*************************************************************************"
echo "*************************************************************************"
echo "*********************${APP_BIN_NAME}_$APP_VERSION.bin********************"
echo "*************************************************************************"
echo "**********************COMPILE SUCCESS************************************"
echo "*************************************************************************"