forked from doniks/pycom-examples
-
Notifications
You must be signed in to change notification settings - Fork 1
/
sqnsup_uart.py
103 lines (88 loc) · 2.82 KB
/
sqnsup_uart.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
import sqnsupgrade
import os
import time
###########
# Sequans modem firmware update per UART
# 1. adjust the CONFIG variables below
# 2. run this script on the device (e.g., via Atom Pymakr)
# 3. close Pymakr as instructed
# 4. run this script on the laptop:
# ```
# cd ~/docs/sqnsupgrade/flash
# PYTHONPATH=. python3 ~/docs/pycom-examples/sqnsup_uart.py
# ```
# 5. wait
print("sqnsup_uart.py")
########### CONFIG
# choose whether you want recovery update method, or normal update method
use_recovery = True
use_updater = True
# choose whether you want to use full image or diff image
use_full = True
# target version
# ver = 'NB1-41019'
ver = 'CATM1-41065'
# run upgrade in debug mode or not
dbg = True
# serial port
serial_port = '/dev/ttyACM0'
serial_port = '/dev/ttyACM1'
serial_port = '/dev/ttyUSB2'
#serial_port = '/dev/ttyUSB6'
# where are the FW images stored
dir='/home/peter/docs/FirmwareReleases/sequans'
dv = dir + "/" + ver + "/"
full = dv + ver + ".dup"
# choose diff file
diff = dv + "upgdiff_33080-to-41019.dup"
updater = dv + "updater.elf"
# list and let it raise an exception if it doesn't exist
if use_recovery and use_updater:
print("updater", updater, os.stat(updater)[6]/1024, "KB")
########### MAIN
print("dbg", dbg)
try:
import pycom
print("sqnsup_uart.py is running on device")
import pycom
import binascii
import machine
print("sys", os.uname().sysname)
print("unique_id", binascii.hexlify(machine.unique_id()))
print("release", os.uname().release)
sqnsupgrade.info(debug=True)
# state 2 .. Application mode
if use_recovery:
import sqnsupgrade
if use_updater:
sqnsupgrade.uart(True, updater, debug=dbg)
else:
sqnsupgrade.uart(True, debug=dbg)
else:
import sqnsupgrade
sqnsupgrade.uart(debug=dbg)
except:
print("sqnsup_uart.py is running on desktop")
if use_full:
print("full", full, os.stat(full)[6]/1024, "KB")
else:
print("diff", diff, os.stat(diff)[6]/1024, "KB")
x = time.time()
if use_full:
if use_recovery:
if use_updater:
print("full, recovery", serial_port, full, updater)
sqnsupgrade.run(serial_port, full, updater, debug=dbg)
else:
print("full, recovery", serial_port, full)
sqnsupgrade.run(serial_port, full, debug=dbg)
else:
print("full, normal", serial_port, full)
sqnsupgrade.run(serial_port, full, debug=dbg)
else:
if use_recovery:
print("diff update with recovery is NOT SUPPORTED (I think :-P) .... actually I think it should be!")
else:
print("diff, normal", serial_port, diff)
sqnsupgrade.run(serial_port, diff, debug=dbg)
print("upgrade finished after", time.time() - x , "seconds")