Skip to content

Commit cb9a6fb

Browse files
committed
Update flashtool and t-head toolchain
1 parent 45fffc8 commit cb9a6fb

File tree

7 files changed

+116
-44
lines changed

7 files changed

+116
-44
lines changed

config/bouffalolab/toolchain/riscv_toolchain.gni

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -25,7 +25,7 @@ template("riscv_toolchain") {
2525

2626
if ("linux" == host_os) {
2727
if (chip_device_platform == "bl616") {
28-
_tool_name_root = "${bouffalolab_sdk_root}/toolchain/riscv/Thead_riscv/Linux_x86_64/bin/riscv64-unknown-elf-"
28+
_tool_name_root = "${bouffalolab_sdk_root}/toolchain/t-head-riscv/gcc_t-head_v2.6.1/bin/riscv64-unknown-elf-"
2929
} else {
3030
_tool_name_root = "${bouffalolab_sdk_root}/toolchain/riscv/Linux/bin/riscv64-unknown-elf-"
3131
}

examples/lighting-app/bouffalolab/README.md

Lines changed: 3 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -80,24 +80,19 @@ Mac OS.
8080
source ./scripts/activate.sh -p bouffalolab
8181
```
8282
83-
> After environment setup `Bouffalo Lab` flash tool, `bflb-iot-tool`,
84-
> imports under this environment. If not, please try
85-
> `scripts/bootstrap.sh -p bouffalolab` for matter environment update.
86-
8783
- Setup build environment for `Bouffalo Lab` SoC
8884
89-
Run `setup.sh` to install `Bouffalo Lab` SDK to /opt/bouffalolab_sdk
85+
Run `env-setup.sh` to install `Bouffalo Lab` toolchain.
9086
9187
```
92-
cd third_party/bouffalolab/repo
93-
sudo bash scripts/setup.sh
88+
./third_party/bouffalolab/env-setup.sh
9489
```
9590
9691
Please execute following command to export `BOUFFALOLAB_SDK_ROOT` before
9792
building.
9893
9994
```
100-
export BOUFFALOLAB_SDK_ROOT=/opt/bouffalolab_sdk
95+
export BOUFFALOLAB_SDK_ROOT="Your install path"
10196
```
10297
10398
## Build CHIP Lighting App example

scripts/build/builders/bouffalolab.py

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -223,12 +223,12 @@ def __init__(self,
223223

224224
def print_enviroment_error(self):
225225
logging.fatal('*' * 80)
226+
logging.error('Flashtool is not installed, or environment variable BOUFFALOLAB_SDK_ROOT is not exported.')
226227
logging.fatal('\tPlease make sure Bouffalo Lab SDK installs as below:')
227-
logging.fatal('\t\tcd third_party/bouffalolab/repo')
228-
logging.fatal('\t\tsudo bash scripts/setup.sh')
228+
logging.fatal('\t\t./third_party/bouffalolab/env-setup.sh')
229229

230230
logging.fatal('\tPlease make sure BOUFFALOLAB_SDK_ROOT exports before building as below:')
231-
logging.fatal('\t\texport BOUFFALOLAB_SDK_ROOT=/opt/bouffalolab_sdk')
231+
logging.fatal('\t\texport BOUFFALOLAB_SDK_ROOT="your install path"')
232232
logging.fatal('*' * 80)
233233

234234
def GnBuildArgs(self):

scripts/flashing/bouffalolab_firmware_utils.py

Lines changed: 22 additions & 30 deletions
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,7 @@
2020
import re
2121
import shutil
2222
import sys
23+
import subprocess
2324

2425
import coloredlogs
2526
import firmware_utils
@@ -169,36 +170,23 @@ def actions(self):
169170
"""Perform actions on the device according to self.option."""
170171
self.log(3, 'Options:', self.option)
171172

172-
try:
173-
import bflb_iot_tool
174-
import bflb_iot_tool.__main__
173+
flashtool_path = os.environ.get('BOUFFALOLAB_SDK_ROOT') + "/flashtool/BouffaloLabDevCube-v1.8.9"
174+
flashtool_exe = flashtool_path + "/bflb_iot_tool-ubuntu"
175175

176-
# version_target_str = "1.8.9"
177-
# version_target = version_target_str.split('.')
178-
# version_target = "".join(["%03d" % int(var) for var in version_target])
179-
180-
# version_current_str = importlib.metadata.version("bflb_iot_tool")
181-
# version_current = version_current_str.split('.')
182-
# version_current = "".join(["%03d" % int(var) for var in version_current])
183-
184-
# if version_current < version_target:
185-
# raise Exception("bflb_iot_tool {} version is less than {}".format(version_current_str, version_target_str))
186-
187-
except Exception as e:
188-
189-
# logging.error('Please try the following command to setup or upgrade Bouffalo Lab environment:')
190-
# logging.error('source scripts/activate.sh -p bouffalolab')
191-
# logging.error('Or')
192-
# logging.error('source scripts/bootstrap.sh -p bouffalolab')
193-
194-
# logging.error('If upgrade bflb_iot_tool failed, try pip uninstall bflb_iot_tool first.')
176+
if not os.path.exists(flashtool_exe):
177+
logging.fatal('*' * 80)
178+
logging.error('Flashtool is not installed, or environment variable BOUFFALOLAB_SDK_ROOT is not exported.')
179+
logging.fatal('\tPlease make sure Bouffalo Lab SDK installs as below:')
180+
logging.fatal('\t\t./third_party/bouffalolab/env-setup.sh')
195181

182+
logging.fatal('\tPlease make sure BOUFFALOLAB_SDK_ROOT exports before building as below:')
183+
logging.fatal('\t\texport BOUFFALOLAB_SDK_ROOT="your install path"')
184+
logging.fatal('*' * 80)
196185
raise Exception(e)
197186

198-
tool_path = os.path.dirname(bflb_iot_tool.__file__)
199-
200187
options_keys = BOUFFALO_OPTIONS["configuration"].keys()
201-
arguments = [__file__]
188+
# arguments = [__file__]
189+
arguments = [flashtool_exe]
202190
work_dir = None
203191

204192
if self.option.reset:
@@ -285,22 +273,22 @@ def actions(self):
285273
raise Exception("Wrong key pair.")
286274

287275
if not dts_path and xtal_value:
288-
chip_config_path = os.path.join(tool_path, "chips", chip_name, "device_tree")
276+
chip_config_path = os.path.join(flashtool_path, "chips", chip_name, "device_tree")
289277
dts_path = self.get_dts_file(chip_config_path, xtal_value, chip_name)
290278
arguments.append("--dts")
291279
arguments.append(dts_path)
292280

293281
if boot2_image:
294-
chip_config_path = os.path.join(tool_path, "chips", chip_name, "builtin_imgs")
282+
chip_config_path = os.path.join(flashtool_path, "chips", chip_name, "builtin_imgs")
295283
boot2_image = self.get_boot_image(chip_config_path, boot2_image)
296284
arguments.append("--boot2")
297285
arguments.append(boot2_image)
298286
else:
299287
if self.option.erase:
300288
arguments.append("--erase")
301289

302-
if chip_name in {"bl602", "bl702"}:
303-
chip_config_path = os.path.join(tool_path, "chips", chip_name, "builtin_imgs")
290+
if chip_name in {"bl602", "bl702", "bl616"}:
291+
chip_config_path = os.path.join(flashtool_path, "chips", chip_name, "builtin_imgs")
304292
boot2_image = self.get_boot_image(chip_config_path, boot2_image)
305293
arguments.append("--boot2")
306294
arguments.append(boot2_image)
@@ -315,7 +303,11 @@ def actions(self):
315303
os.mkdir(ota_output_folder)
316304

317305
logging.info("Arguments {}".format(arguments))
318-
bflb_iot_tool.__main__.run_main()
306+
process = subprocess.Popen(arguments, stdout=subprocess.PIPE, stderr=subprocess.PIPE)
307+
while process.poll() is None:
308+
line = process.stdout.readline().decode('utf-8').rstrip()
309+
if line:
310+
logging.info(line)
319311

320312
if ota_output_folder:
321313
ota_images = os.listdir(ota_output_folder)

scripts/setup/requirements.bouffalolab.txt

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,3 @@
1-
bflb-iot-tool>=1.8.6
21
jsonschema>=4.4.0
32
cbor2>=5.4.3
43
ecdsa>=0.18.0

third_party/bouffalolab/common/bouffalolab_executable.gni

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -27,7 +27,7 @@ template("bouffalolab_executable") {
2727
objcopy = "riscv64-unknown-elf-objcopy"
2828
if ("linux" == host_os) {
2929
if (invoker.bl_plat_name == "bl616") {
30-
objcopy = "${bouffalolab_sdk_root}/toolchain/riscv/Thead_riscv/Linux_x86_64/bin/riscv64-unknown-elf-objcopy"
30+
objcopy = "${bouffalolab_sdk_root}/toolchain/t-head-riscv/gcc_t-head_v2.6.1/bin/riscv64-unknown-elf-objcopy"
3131
} else {
3232
objcopy = "${bouffalolab_sdk_root}/toolchain/riscv/Linux/bin/riscv64-unknown-elf-objcopy"
3333
}
Lines changed: 86 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,86 @@
1+
#!/usr/bin/env bash
2+
3+
set -x
4+
CURRENT_DIR=$(
5+
cd "$(dirname "$0")"
6+
pwd
7+
)
8+
9+
user=`stat -c %U $0`
10+
11+
SDK_ROOT=/opt/bouffalolab_sdk
12+
13+
echo "Please input path to install toolchain, or type Enter to install under ${SDK_ROOT}"
14+
read TOOLCHAIN_SETUP_ROOT
15+
if [[ ${TOOLCHAIN_SETUP_ROOT} == "" ]]; then
16+
TOOLCHAIN_SETUP_ROOT=$SDK_ROOT
17+
fi
18+
echo "Toolchain will install under ${TOOLCHAIN_SETUP_ROOT}"
19+
flash_tool_postfix=
20+
21+
flash_tool=BouffaloLabDevCube-v1.8.9
22+
flash_tool_url=https://dev.bouffalolab.com/media/upload/download/${flash_tool}.zip
23+
thead_toolchain=gcc_t-head_v2.6.1
24+
thead_toolchain_url=https://codeload.github.com/bouffalolab/toolchain_gcc_t-head_linux/zip/c4afe91cbd01bf7dce525e0d23b4219c8691e8f0
25+
thead_toolchain_unzip=toolchain_gcc_t-head_linux-c4afe91cbd01bf7dce525e0d23b4219c8691e8f0
26+
27+
if [[ "$OSTYPE" == "linux-gnu"* ]]; then
28+
toolchains_url=(
29+
"toolchain/riscv" "https://dev.bouffalolab.com/media/upload/download/toolchain_riscv_sifive_linux64.zip" Linux toolchain_riscv_sifive_linux
30+
"toolchain/t-head-riscv" ${thead_toolchain_url} ${thead_toolchain} ${thead_toolchain_unzip}
31+
"flashtool" ${flash_tool_url} ${flash_tool} ""
32+
)
33+
flash_tool_postfix=ubuntu
34+
elif [[ "$OSTYPE" == "darwin"* ]]; then
35+
toolchains_url=(
36+
"toolchain/riscv/Darwin" "https://dev.bouffalolab.com/media/upload/download/toolchain_riscv_sifive_macos.zip"
37+
)
38+
flash_tool_postfix=macos
39+
else
40+
echo "Not support for ""$OSTYPE"
41+
fi
42+
43+
if [ ! -d "$TOOLCHAIN_SETUP_ROOT" ]; then
44+
mkdir -p "$TOOLCHAIN_SETUP_ROOT"
45+
fi
46+
rm -rf "$TOOLCHAIN_SETUP_ROOT"/*.zip
47+
48+
for ((i = 0; i < ${#toolchains_url[@]}; i += 4)); do
49+
path=${toolchains_url[i]}
50+
url=${toolchains_url[i + 1]}
51+
out=${toolchains_url[i + 2]}
52+
unzip_name=${toolchains_url[i + 3]}
53+
54+
if [ -d "$TOOLCHAIN_SETUP_ROOT/$path/$out" ]; then
55+
continue
56+
fi
57+
rm -rf "$TOOLCHAIN_SETUP_ROOT/$path"
58+
mkdir -p "$TOOLCHAIN_SETUP_ROOT/$path"
59+
60+
wget -P "$TOOLCHAIN_SETUP_ROOT"/ "$url"
61+
toolchain_zip=$(basename "$url")
62+
toolchain_zip=`find $TOOLCHAIN_SETUP_ROOT -maxdepth 1 -name *${toolchain_zip}*`
63+
toolchain_zip=$(basename "$toolchain_zip")
64+
if [ ! -f "$TOOLCHAIN_SETUP_ROOT/$toolchain_zip" ]; then
65+
exit 1
66+
fi
67+
68+
unzip -q "$TOOLCHAIN_SETUP_ROOT/$toolchain_zip" -d "$TOOLCHAIN_SETUP_ROOT/$path/tmp"
69+
mv $TOOLCHAIN_SETUP_ROOT/$path/tmp/$unzip_name $TOOLCHAIN_SETUP_ROOT/$path/$out
70+
71+
rm -rf $TOOLCHAIN_SETUP_ROOT/$path/tmp
72+
rm -rf $TOOLCHAIN_SETUP_ROOT/$toolchain_zip
73+
74+
if [ -f "$TOOLCHAIN_SETUP_ROOT/$path"/$out/chmod755.sh ]; then
75+
cd "$TOOLCHAIN_SETUP_ROOT/$path"/$out
76+
bash chmod755.sh
77+
cd "$CURRENT_DIR"
78+
fi
79+
done
80+
81+
chmod +x ${TOOLCHAIN_SETUP_ROOT}/flashtool/${flash_tool}/BLDevCube-${flash_tool_postfix}
82+
chmod +x ${TOOLCHAIN_SETUP_ROOT}/flashtool/${flash_tool}/bflb_iot_tool-${flash_tool_postfix}
83+
84+
if [[ "$user" != "root" ]]; then
85+
chown $user ${TOOLCHAIN_SETUP_ROOT}/flashtool/${flash_tool}/ -R
86+
fi

0 commit comments

Comments
 (0)