Skip to content
This repository has been archived by the owner on Sep 16, 2024. It is now read-only.

V1.18.2.r8 update #359

Open
wants to merge 12 commits into
base: Release/v1.18
Choose a base branch
from
80 changes: 49 additions & 31 deletions esp32/frozen/LTE/sqnsupgrade.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
#!/usr/bin/env python
VERSION = "1.2.5"
VERSION = "1.2.6"

# Copyright (c) 2019, Pycom Limited.
#
Expand Down Expand Up @@ -339,7 +339,7 @@ def __get_wait_msg(self, load_fff=True):



def __run(self, file_path=None, baudrate=921600, port=None, resume=False, load_ffh=False, mirror=False, switch_ffh=False, bootrom=False, rgbled=0x050505, debug=False, pkgdebug=False, atneg=True, max_try=10, direct=True, atneg_only=False, info_only=False, expected_smod=None, verbose=False, load_fff=False, mtools=False):
def __run(self, file_path=None, baudrate=921600, port=None, resume=False, load_ffh=False, mirror=False, switch_ffh=False, bootrom=False, rgbled=0x050505, debug=False, pkgdebug=False, atneg=True, max_try=10, direct=True, atneg_only=False, info_only=False, expected_smod=None, verbose=False, load_fff=False, mtools=False, fc=False):
self.__wait_msg = False
mirror = True if atneg_only else mirror
recover = True if atneg_only else load_ffh
Expand All @@ -365,7 +365,7 @@ def __run(self, file_path=None, baudrate=921600, port=None, resume=False, load_f
external = True
br = 115200 if recover and not direct else baudrate
if debug: print('Setting baudrate to {}'.format(br))
self.__serial = serial.Serial(port, br, bytesize=serial.EIGHTBITS, timeout=1 if info_only else 0.1)
self.__serial = serial.Serial(port, br, bytesize=serial.EIGHTBITS, timeout=1 if info_only else 0.1, rtscts=fc)
self.__serial.reset_input_buffer()
self.__serial.reset_output_buffer()

Expand Down Expand Up @@ -408,7 +408,7 @@ def __run(self, file_path=None, baudrate=921600, port=None, resume=False, load_f
if blobsize < 128:
print('Firmware file is too small!')
reconnect_uart()
sys.exit(1)
return False
if blobsize > 4194304:
if load_fff:
print("Firmware file is too big to load via FFF method. Using ON_THE_FLY")
Expand Down Expand Up @@ -447,7 +447,7 @@ def __run(self, file_path=None, baudrate=921600, port=None, resume=False, load_f

if verbose: print('Sending AT+FSRDFILE="/fs/crashdump"')
self.__serial.write(b'AT+FSRDFILE="/fs/crashdump"\r\n')
response = self.read_rsp(size=100)
response = self.read_rsp(size=1024)
if verbose: print('AT+FSRDFILE="/fs/crashdump" returned {}'.format(response))
self.__serial.read()

Expand Down Expand Up @@ -484,7 +484,7 @@ def __run(self, file_path=None, baudrate=921600, port=None, resume=False, load_f
else:
print('Received ERROR from AT+SMSWBOOT=3,1! Aborting!')
reconnect_uart()
sys.exit(1)
return False
time.sleep(3)
resp = self.__serial.read()
if debug: print("Response after reset: {}".format(resp))
Expand Down Expand Up @@ -548,7 +548,10 @@ def __run(self, file_path=None, baudrate=921600, port=None, resume=False, load_f
response = self.read_rsp(size=4)
if response != b'OK\r\n' and response != b'\r\nOK' and response != b'\nOK':
raise OSError("Invalid answer '%s' from the device" % response)
blob.close()
try:
blob.close()
except:
pass

self.__serial.read()
elif recover and (not direct):
Expand All @@ -571,7 +574,7 @@ def __run(self, file_path=None, baudrate=921600, port=None, resume=False, load_f
if not b'OK' in response:
print('Failed to start STP mode!')
reconnect_uart()
sys.exit(1)
return False
else:
print('AT auto-negotiation failed! Exiting.')
return False
Expand All @@ -582,13 +585,18 @@ def __run(self, file_path=None, baudrate=921600, port=None, resume=False, load_f
if not b'OK' in response:
print('Failed to start STP mode!')
reconnect_uart()
sys.exit(1)
return False

try:
if debug:
if verbose: print('Starting STP code upload')
if stp.start(blob, blobsize, self.__serial, baudrate, AT=False, debug=debug, pkgdebug=pkgdebug):
blob.close()
start = stp.start(blob, blobsize, self.__serial, baudrate, AT=False, debug=debug, pkgdebug=pkgdebug)
if debug: print('start returned {} type {}'.format(start, type(start)))
if start == True:
try:
blob.close()
except:
pass
self.__serial.read()
if switch_ffh:
if verbose: print('Bootrom updated successfully, switching to recovery mode')
Expand All @@ -602,12 +610,19 @@ def __run(self, file_path=None, baudrate=921600, port=None, resume=False, load_f
if verbose: print('Code download done, returning to user mode')
abort = recover
else:
blob.close()
print('Code download failed, aborting!')
try:
blob.close()
except:
pass
print('Code download failed[1], aborting!')
return False
except:
blob.close()
print('Code download failed, aborting!')
except Exception as ex:
try:
blob.close()
except:
pass
print('Exception: {}'.format(ex))
print('Code download failed [2], aborting!')
abort = True

time.sleep(1.5)
Expand Down Expand Up @@ -638,7 +653,7 @@ def __run(self, file_path=None, baudrate=921600, port=None, resume=False, load_f
if not self.wakeup_modem(baudrate, port, 100, 1, debug, self.__get_wait_msg(load_fff=load_fff)):
print("Timeout while waiting for modem to finish updating!")
reconnect_uart()
sys.exit(1)
return False

start = time.time()
while True:
Expand Down Expand Up @@ -708,7 +723,7 @@ def __run(self, file_path=None, baudrate=921600, port=None, resume=False, load_f
else:
print("Invalid response after upgrade... aborting.")
reconnect_uart()
sys.exit(1)
return False

self.__serial.write(b"AT\r\n")
self.__serial.write(b"AT\r\n")
Expand Down Expand Up @@ -819,7 +834,7 @@ def at_negotiation(self, baudrate, port, max_try, mirror, atneg_only, debug, tar
self.__serial = UART(1, baudrate=target_baudrate, pins=self.__pins, timeout_chars=100)
else:
self.__serial = None
self.__serial = serial.Serial(port, target_baudrate, bytesize=serial.EIGHTBITS, timeout=0.1)
self.__serial = serial.Serial(port, target_baudrate, bytesize=serial.EIGHTBITS, timeout=0.1, rtscts=fc)
self.__serial.reset_input_buffer()
self.__serial.reset_output_buffer()
self.__serial.flush()
Expand Down Expand Up @@ -882,10 +897,11 @@ def upgrade(self, ffile, mfile=None, baudrate=921600, retry=False, resume=False,
if success:
if self.__run(file_path=ffile, resume=True if mfile is not None else resume, baudrate=baudrate, direct=False, debug=debug, pkgdebug=pkgdebug, verbose=verbose, load_fff=False if mfile else load_fff, mtools=mtools):
if self.__check_br(verbose=verbose, debug=debug):
self.__run(bootrom=True, debug=debug, direct=False, pkgdebug=pkgdebug, verbose=verbose, load_fff=True)
success = self.__run(bootrom=True, debug=debug, direct=False, pkgdebug=pkgdebug, verbose=verbose, load_fff=True)
self.success_message(verbose=verbose, debug=debug)
else:
print('Unable to load updater from {}'.format(mfile))
return success

def upgrade_uart(self, ffh_mode=False, mfile=None, retry=False, resume=False, color=0x050505, debug=False, pkgdebug=False, verbose=False, load_fff=True):
success = False
Expand All @@ -896,7 +912,7 @@ def upgrade_uart(self, ffh_mode=False, mfile=None, retry=False, resume=False, co
if not success:
print('Firmware does not support LTE.modem_upgrade_mode()!')
reconnect_uart()
sys.exit(1)
return False
print('Preparing modem for upgrade...')
if not retry and ffh_mode:
success = False
Expand All @@ -923,16 +939,16 @@ def upgrade_uart(self, ffh_mode=False, mfile=None, retry=False, resume=False, co
else:
print('Unable to upgrade bootrom.')

def show_info(self, port=None, debug=False, verbose=False):
self.__run(port=port, debug=debug, info_only=True, verbose=verbose)
def show_info(self, port=None, debug=False, verbose=False, fc=False):
self.__run(port=port, debug=debug, info_only=True, verbose=verbose, fc=fc)

def upgrade_ext(self, port, ffile, mfile, resume=False, debug=False, pkgdebug=False, verbose=False, load_fff=True):
def upgrade_ext(self, port, ffile, mfile, resume=False, debug=False, pkgdebug=False, verbose=False, load_fff=True, fc=False):
success = True
if mfile is not None:
success = False
success = self.__run(file_path=mfile, load_ffh=True, port=port, debug=debug, pkgdebug=pkgdebug, verbose=verbose)
success = self.__run(file_path=mfile, load_ffh=True, port=port, debug=debug, pkgdebug=pkgdebug, verbose=verbose, fc=fc)
if success:
if self.__run(file_path=ffile, resume=True if mfile is not None else resume, direct=False, port=port, debug=debug, pkgdebug=pkgdebug, verbose=verbose, load_fff=load_fff):
if self.__run(file_path=ffile, resume=True if mfile is not None else resume, direct=False, port=port, debug=debug, pkgdebug=pkgdebug, verbose=verbose, load_fff=load_fff, fc=fc):
self.success_message(port=port, verbose=verbose, debug=debug)
else:
print('Unable to load updater from {}'.format(mfile))
Expand All @@ -941,7 +957,7 @@ def detect_error():
print('Could not detect your modem!')
print('Please try to power off your device and restart in safeboot mode.')
reconnect_uart()
sys.exit(1)
return False

def print_welcome():
print('<<< Welcome to the SQN3330 firmware updater [{}] >>>'.format(VERSION))
Expand Down Expand Up @@ -973,6 +989,7 @@ def run(ffile, mfile=None, baudrate=921600, verbose=False, debug=False, load_fff
retry = False
resume = False
mtools = False
success = False
sqnup = sqnsupgrade()
if sqnup.check_files(ffile, mfile, debug):
state = sqnup.detect_modem_state(debug=debug, hangup=hangup)
Expand All @@ -984,15 +1001,16 @@ def run(ffile, mfile=None, baudrate=921600, verbose=False, debug=False, load_fff
if mfile is None:
print('Your modem is in recovery mode. Please specify updater.elf file')
reconnect_uart()
sys.exit(1)
return False
elif state == 4:
resume = True
elif state == 1:
mtools = True
elif state == -1:
detect_error()
sqnup.upgrade(ffile=ffile, mfile=mfile, baudrate=baudrate, retry=retry, resume=resume, debug=debug, pkgdebug=False, verbose=verbose, load_fff=load_fff, mtools=mtools)
success = sqnup.upgrade(ffile=ffile, mfile=mfile, baudrate=baudrate, retry=retry, resume=resume, debug=debug, pkgdebug=False, verbose=verbose, load_fff=load_fff, mtools=mtools)
reconnect_uart()
return success

def uart(ffh_mode=False, mfile=None, color=0x050505, verbose=False, debug=False, hangup=True):
print_welcome()
Expand Down Expand Up @@ -1054,12 +1072,12 @@ def state(verbose=False, debug=False, retry=5, hangup=False):
return sqnup.detect_modem_state(debug=debug, hangup=hangup, retry=retry)

else:
def run(port, ffile, mfile=None, resume=False, debug=False, verbose=False, load_fff=True):
def run(port, ffile, mfile=None, resume=False, debug=False, verbose=False, load_fff=True, fc=False):
print_welcome()
sqnup = sqnsupgrade()
if sqnup.check_files(ffile, mfile, debug):
sqnup.upgrade_ext(port=port, ffile=ffile, mfile=mfile, resume=resume, debug=debug, pkgdebug=False, verbose=verbose, load_fff=load_fff)

def version(port, verbose=False, debug=False):
def version(port, verbose=False, debug=False, fc=False):
sqnup = sqnsupgrade()
sqnup.show_info(port=port, debug=debug, verbose=verbose)
Loading