Skip to content

Commit

Permalink
otbox.py: use --erase-write
Browse files Browse the repository at this point in the history
  • Loading branch information
fjmolinas committed Jan 25, 2021
1 parent 190d343 commit 613aec8
Showing 1 changed file with 14 additions and 12 deletions.
26 changes: 14 additions & 12 deletions otbox.py
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@
import argparse
import logging

try:
try:
from PIL import Image
from PIL import ImageFont
from PIL import ImageDraw
Expand Down Expand Up @@ -87,7 +87,7 @@ def __init__(self, otbox):
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

Expand All @@ -112,10 +112,12 @@ def bootload_mote(self, serialport, firmware_file):
break

assert bootloader_backdoor_enabled

return subprocess.Popen(
['python', 'bootloaders/cc2538-bsl.py', '-e', '--bootloader-invert-lines', '-w', '-b', '400000',
'-p', serialport, firmware_file], stdout=subprocess.PIPE, stderr=subprocess.PIPE)
['python3', 'bootloaders/cc2538-bsl.py',
'--bootloader-invert-lines', '--erase-write',
'-v', '-b', '400000', '-p',
serialport, firmware_file], stdout=subprocess.PIPE, stderr=subprocess.PIPE)

def _display_image(self):
import pygame
Expand Down Expand Up @@ -317,7 +319,7 @@ def _on_mqtt_connect(self, client, userdata, flags, rc):
self.mqttconnected = True

# subscribe to box commands (device-specific and 'all')
# note that unknown commands will be ignored by _execute_command_safely
# note that unknown commands will be ignored by _execute_command_safely
client.subscribe('{0}/#'.format(self.mqtttopic_box_cmd_prefix))
client.subscribe('{0}/deviceType/box/deviceId/all/cmd/#'.format(self.testbed))

Expand Down Expand Up @@ -572,11 +574,11 @@ def _mqtt_handler_program(self, deviceType, deviceId, payload):

payload = json.loads(payload) # shorthand
mote = self._eui64_to_moteinfoelem(deviceId)

# disconnect from the serialports
self.SerialportHandlers[mote['serialport']].disconnectSerialPort()
time.sleep(2) # wait 2 seconds to release the serial ports

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.format(deviceId))
Expand Down Expand Up @@ -679,22 +681,22 @@ def _bootload_motes(self, serialports, firmware_file):
'''
bootloads firmware_file onto multiple motes in parallel
'''

# start bootloading each mote
ongoing_bootloads = {}
for serialport in serialports:

# simply the name
port = serialport.split('/')[-1]

# stop serial reader
ongoing_bootloads[port] = self.tb.bootload_mote(serialport, firmware_file)

returnVal = []
for ongoing_bootload in ongoing_bootloads:
# wait for this bootload process to finish
(stdout, stderr) = ongoing_bootloads[ongoing_bootload].communicate()

# record the last output of bootload process
with open("log_{0}.txt".format(ongoing_bootload),'w') as f:
f.write("stdout: {0} stderr {1}".format(stdout,stderr))
Expand Down

0 comments on commit 613aec8

Please sign in to comment.