Skip to content

Commit

Permalink
Use different firmware file name for each mote to program (#109)
Browse files Browse the repository at this point in the history
use different name of firmware of each mote.
  • Loading branch information
changtengfei authored Aug 22, 2019
1 parent 1c667ba commit f958291
Showing 1 changed file with 7 additions and 14 deletions.
21 changes: 7 additions & 14 deletions otbox.py
Original file line number Diff line number Diff line change
Expand Up @@ -42,12 +42,10 @@
DEVICETYPE_MOTE
]

OTBOX_VERSION = "1.2.5"
OTBOX_VERSION = "1.2.6"

IMAGE_THREAD_NAME = 'image_thread'
HEARTBEAT_THREAD_NAME = 'heartbeat_thread'

firmware_temp_lock = threading.Lock()
#============================ classes =========================================

def _getThreadsName():
Expand Down Expand Up @@ -86,14 +84,13 @@ def __init__(self, otbox):

self.firmware_eui64_retrieval = os.path.join(os.path.dirname(__file__), 'bootloaders', 'opentestbed',
'01bsp_eui64_prog.ihex')
self.firmware_temp = os.path.join(os.path.dirname(__file__), 'bootloaders', 'opentestbed', 'firmware_mote.ihex')
self.firmware_temp = os.path.join(os.path.dirname(__file__), 'bootloaders', 'opentestbed', 'firmware_mote_{0}.ihex')

def bootload_mote(self, serialport, firmware_file):

bootloader_backdoor_enabled = False
extended_linear_address_found = False

firmware_temp_lock.acquire()
# make sure bootloader backdoor is configured correctly
with open(firmware_file,'r') as f:
for line in f:
Expand All @@ -113,8 +110,6 @@ def bootload_mote(self, serialport, firmware_file):
if len(line)>=17 and extended_linear_address_found and line[3:7] == 'FFD4' and int(line[1:3], 16)>4 and line[9:17] == 'FFFFFFF6':
bootloader_backdoor_enabled = True
break

firmware_temp_lock.release()

assert bootloader_backdoor_enabled

Expand Down Expand Up @@ -195,7 +190,7 @@ def __init__(self, otbox):

self.firmware_eui64_retrieval = os.path.join(os.path.dirname(__file__), 'bootloaders', 'iotlab',
'01bsp_eui64_prog')
self.firmware_temp = os.path.join(os.path.dirname(__file__), 'bootloaders', 'iotlab', '03oos_openwsn_prog')
self.firmware_temp = os.path.join(os.path.dirname(__file__), 'bootloaders', 'iotlab', '03oos_openwsn_prog_{0}')

def bootload_mote(self, serialport, firmware_file):
return subprocess.Popen(['flash_a8_m3', firmware_file], stdout=subprocess.PIPE,
Expand Down Expand Up @@ -224,7 +219,7 @@ def __init__(self, otbox):
self.firmware_eui64_retrieval = os.path.join(os.path.dirname(__file__), 'bootloaders', 'wilab',
'eui64-retriever.hex')
self.firmware_temp = os.path.join(os.path.dirname(__file__), 'bootloaders', 'wilab',
'firmware.hex')
'firmware_{0}.hex')

def bootload_mote(self, serialport, firmware_file):
cmd = ['python', 'bootloaders/cc2538-bsl.py', '-e', '-w', '-v', '-b', '460800', '-a', '0x00202000',
Expand Down Expand Up @@ -584,25 +579,23 @@ def _mqtt_handler_program(self, deviceType, deviceId, payload):

if 'url' in payload and payload['url'].startswith("ftp://"):
# use urllib to get firmware from ftp server (requests doesn't support for ftp)
urllib.urlretrieve(payload['url'],self.tb.firmware_temp)
urllib.urlretrieve(payload['url'],self.tb.firmware_temp.format(deviceId))
urllib.urlcleanup()
else:
firmware_temp_lock.acquire()
# store the firmware to load into a temporary file
with open(self.tb.firmware_temp, 'wb') as f:
with open(self.tb.firmware_temp.format(deviceId), 'wb') as f:
if 'url' in payload: # download file from url if present
file = requests.get(payload['url'], allow_redirects=True)
f.write(file.content)
elif 'hex' in payload: # export hex file received if present
f.write(base64.b64decode(payload['hex']))
else:
assert "The supported keys {0}, {1} are not in the payload. ".format('url','hex')
firmware_temp_lock.release()

# bootload the mote
bootload_success = self._bootload_motes(
serialports = [mote['serialport']],
firmware_file = self.tb.firmware_temp,
firmware_file = self.tb.firmware_temp.format(deviceId),
)

assert len(bootload_success)==1
Expand Down

0 comments on commit f958291

Please sign in to comment.