2020import re
2121import shutil
2222import sys
23+ import subprocess
2324
2425import coloredlogs
2526import 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 ('\t Please make sure Bouffalo Lab SDK installs as below:' )
180+ logging .fatal ('\t \t ./third_party/bouffalolab/env-setup.sh' )
195181
182+ logging .fatal ('\t Please make sure BOUFFALOLAB_SDK_ROOT exports before building as below:' )
183+ logging .fatal ('\t \t export 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 )
0 commit comments