Skip to content

Commit

Permalink
REL-1.2.5 (#108)
Browse files Browse the repository at this point in the history
resolve multiple threads accessing firmware_tmp file issue.
  • Loading branch information
changtengfei authored Aug 22, 2019
1 parent 2c0f83b commit 1c667ba
Showing 1 changed file with 12 additions and 4 deletions.
16 changes: 12 additions & 4 deletions otbox.py
Original file line number Diff line number Diff line change
Expand Up @@ -42,10 +42,12 @@
DEVICETYPE_MOTE
]

OTBOX_VERSION = "1.2.4"
OTBOX_VERSION = "1.2.5"

IMAGE_THREAD_NAME = 'image_thread'
HEARTBEAT_THREAD_NAME = 'heartbeat_thread'

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

def _getThreadsName():
Expand Down Expand Up @@ -91,6 +93,7 @@ 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 @@ -99,17 +102,20 @@ def bootload_mote(self, serialport, firmware_file):
# refer to: https://en.wikipedia.org/wiki/Intel_HEX#Record_types

# looking for upper 16bit address 0027
if line[:15] == ':020000040027D3':
if len(line)>=15 and line[:15] == ':020000040027D3':
extended_linear_address_found = True

# check the lower 16bit address FFD4

# | 1:3 byte count | 3:7 address | 9:17 32-bit field of the lock bit page (the last byte is backdoor configuration) |
# 'F6' = 111 1 0 110
# reserved backdoor and bootloader enable active low PA pin used for backdoor enabling (PA6)
if extended_linear_address_found and line[3:7] == 'FFD4' and int(line[1:3], 16)>4 and line[9:17] == 'FFFFFFF6':
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

return subprocess.Popen(
Expand Down Expand Up @@ -581,6 +587,7 @@ def _mqtt_handler_program(self, deviceType, deviceId, payload):
urllib.urlretrieve(payload['url'],self.tb.firmware_temp)
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:
if 'url' in payload: # download file from url if present
Expand All @@ -590,6 +597,7 @@ def _mqtt_handler_program(self, deviceType, deviceId, payload):
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(
Expand Down

0 comments on commit 1c667ba

Please sign in to comment.