mirror of
https://github.com/markqvist/Reticulum.git
synced 2024-11-22 21:50:18 +00:00
refactor(rnodeconf): Replace string concatenation
Signed-off-by: nothingbutlucas <69118979+nothingbutlucas@users.noreply.github.com>
This commit is contained in:
parent
acd893a6e6
commit
e47dcae54e
@ -56,12 +56,14 @@ fw_filename = None
|
|||||||
fw_url = None
|
fw_url = None
|
||||||
mapped_model = None
|
mapped_model = None
|
||||||
|
|
||||||
|
# TODO: Create and use constants for megas, kilos, etc (Avoid using magic numbers)
|
||||||
|
|
||||||
class KISS():
|
class KISS():
|
||||||
FEND = 0xC0
|
FEND = 0xC0
|
||||||
FESC = 0xDB
|
FESC = 0xDB
|
||||||
TFEND = 0xDC
|
TFEND = 0xDC
|
||||||
TFESC = 0xDD
|
TFESC = 0xDD
|
||||||
|
|
||||||
CMD_UNKNOWN = 0xFE
|
CMD_UNKNOWN = 0xFE
|
||||||
CMD_DATA = 0x00
|
CMD_DATA = 0x00
|
||||||
CMD_FREQUENCY = 0x01
|
CMD_FREQUENCY = 0x01
|
||||||
@ -102,11 +104,11 @@ class KISS():
|
|||||||
|
|
||||||
DETECT_REQ = 0x73
|
DETECT_REQ = 0x73
|
||||||
DETECT_RESP = 0x46
|
DETECT_RESP = 0x46
|
||||||
|
|
||||||
RADIO_STATE_OFF = 0x00
|
RADIO_STATE_OFF = 0x00
|
||||||
RADIO_STATE_ON = 0x01
|
RADIO_STATE_ON = 0x01
|
||||||
RADIO_STATE_ASK = 0xFF
|
RADIO_STATE_ASK = 0xFF
|
||||||
|
|
||||||
CMD_ERROR = 0x90
|
CMD_ERROR = 0x90
|
||||||
ERROR_INITRADIO = 0x01
|
ERROR_INITRADIO = 0x01
|
||||||
ERROR_TXFAILED = 0x02
|
ERROR_TXFAILED = 0x02
|
||||||
@ -166,7 +168,7 @@ class ROM():
|
|||||||
MODEL_E9 = 0xE9
|
MODEL_E9 = 0xE9
|
||||||
MODEL_E3 = 0xE3
|
MODEL_E3 = 0xE3
|
||||||
MODEL_E8 = 0xE8
|
MODEL_E8 = 0xE8
|
||||||
|
|
||||||
PRODUCT_HMBRW = 0xF0
|
PRODUCT_HMBRW = 0xF0
|
||||||
MODEL_FF = 0xFF
|
MODEL_FF = 0xFF
|
||||||
MODEL_FE = 0xFE
|
MODEL_FE = 0xFE
|
||||||
@ -280,7 +282,7 @@ try:
|
|||||||
os.makedirs(ROM_DIR)
|
os.makedirs(ROM_DIR)
|
||||||
|
|
||||||
except Exception as e:
|
except Exception as e:
|
||||||
print("No access to directory "+str(CNF_DIR)+". This utility needs file system access to store firmware and data files. Cannot continue.")
|
print("".join(["No access to directory ", str(CNF_DIR), ". This utility needs file system access to store firmware and data files. Cannot continue."]))
|
||||||
print("The contained exception was:")
|
print("The contained exception was:")
|
||||||
print(str(e))
|
print(str(e))
|
||||||
exit(99)
|
exit(99)
|
||||||
@ -411,7 +413,7 @@ class RNode():
|
|||||||
command_buffer = command_buffer+bytes([byte])
|
command_buffer = command_buffer+bytes([byte])
|
||||||
if (len(command_buffer) == 4):
|
if (len(command_buffer) == 4):
|
||||||
self.r_frequency = command_buffer[0] << 24 | command_buffer[1] << 16 | command_buffer[2] << 8 | command_buffer[3]
|
self.r_frequency = command_buffer[0] << 24 | command_buffer[1] << 16 | command_buffer[2] << 8 | command_buffer[3]
|
||||||
RNS.log("Radio reporting frequency is "+str(self.r_frequency/1000000.0)+" MHz")
|
RNS.log("".join(["Radio reporting frequency is ", str(self.r_frequency/1000000.0), " MHz"]))
|
||||||
self.updateBitrate()
|
self.updateBitrate()
|
||||||
|
|
||||||
elif (command == KISS.CMD_BANDWIDTH):
|
elif (command == KISS.CMD_BANDWIDTH):
|
||||||
@ -427,7 +429,7 @@ class RNode():
|
|||||||
command_buffer = command_buffer+bytes([byte])
|
command_buffer = command_buffer+bytes([byte])
|
||||||
if (len(command_buffer) == 4):
|
if (len(command_buffer) == 4):
|
||||||
self.r_bandwidth = command_buffer[0] << 24 | command_buffer[1] << 16 | command_buffer[2] << 8 | command_buffer[3]
|
self.r_bandwidth = command_buffer[0] << 24 | command_buffer[1] << 16 | command_buffer[2] << 8 | command_buffer[3]
|
||||||
RNS.log("Radio reporting bandwidth is "+str(self.r_bandwidth/1000.0)+" KHz")
|
RNS.log("".join(["Radio reporting bandwidth is ", str(self.r_bandwidth/1000.0), " KHz"]))
|
||||||
self.updateBitrate()
|
self.updateBitrate()
|
||||||
|
|
||||||
elif (command == KISS.CMD_BT_PIN):
|
elif (command == KISS.CMD_BT_PIN):
|
||||||
@ -501,7 +503,7 @@ class RNode():
|
|||||||
|
|
||||||
elif (command == KISS.CMD_TXPOWER):
|
elif (command == KISS.CMD_TXPOWER):
|
||||||
self.r_txpower = byte
|
self.r_txpower = byte
|
||||||
RNS.log("Radio reporting TX power is "+str(self.r_txpower)+" dBm")
|
RNS.log("".join(["Radio reporting TX power is ", str(self.r_txpower), " dBm"]))
|
||||||
elif (command == KISS.CMD_SF):
|
elif (command == KISS.CMD_SF):
|
||||||
self.r_sf = byte
|
self.r_sf = byte
|
||||||
RNS.log("Radio reporting spreading factor is "+str(self.r_sf))
|
RNS.log("Radio reporting spreading factor is "+str(self.r_sf))
|
||||||
@ -549,17 +551,17 @@ class RNode():
|
|||||||
self.r_random = byte
|
self.r_random = byte
|
||||||
elif (command == KISS.CMD_ERROR):
|
elif (command == KISS.CMD_ERROR):
|
||||||
if (byte == KISS.ERROR_INITRADIO):
|
if (byte == KISS.ERROR_INITRADIO):
|
||||||
RNS.log(str(self)+" hardware initialisation error (code "+RNS.hexrep(byte)+")")
|
RNS.log("".join([str(self), " hardware initialisation error (code ", RNS.hexrep(byte), ")"]))
|
||||||
elif (byte == KISS.ERROR_TXFAILED):
|
elif (byte == KISS.ERROR_TXFAILED):
|
||||||
RNS.log(str(self)+" hardware TX error (code "+RNS.hexrep(byte)+")")
|
RNS.log("".join([str(self), " hardware TX error (code ", RNS.hexrep(byte), ")"]))
|
||||||
else:
|
else:
|
||||||
RNS.log(str(self)+" hardware error (code "+RNS.hexrep(byte)+")")
|
RNS.log("".join([str(self), " hardware error (code ", RNS.hexrep(byte), ")"]))
|
||||||
elif (command == KISS.CMD_DETECT):
|
elif (command == KISS.CMD_DETECT):
|
||||||
if byte == KISS.DETECT_RESP:
|
if byte == KISS.DETECT_RESP:
|
||||||
self.detected = True
|
self.detected = True
|
||||||
else:
|
else:
|
||||||
self.detected = False
|
self.detected = False
|
||||||
|
|
||||||
else:
|
else:
|
||||||
time_since_last = int(time.time()*1000) - last_read_ms
|
time_since_last = int(time.time()*1000) - last_read_ms
|
||||||
if len(data_buffer) > 0 and time_since_last > self.timeout:
|
if len(data_buffer) > 0 and time_since_last > self.timeout:
|
||||||
@ -816,7 +818,7 @@ class RNode():
|
|||||||
from cryptography.hazmat.primitives.serialization import load_der_private_key
|
from cryptography.hazmat.primitives.serialization import load_der_private_key
|
||||||
from cryptography.hazmat.primitives.asymmetric import padding
|
from cryptography.hazmat.primitives.asymmetric import padding
|
||||||
|
|
||||||
# Try loading local signing key for
|
# Try loading local signing key for
|
||||||
# validation of self-signed devices
|
# validation of self-signed devices
|
||||||
if os.path.isdir(FWD_DIR) and os.path.isfile(FWD_DIR+"/signing.key"):
|
if os.path.isdir(FWD_DIR) and os.path.isfile(FWD_DIR+"/signing.key"):
|
||||||
private_bytes = None
|
private_bytes = None
|
||||||
@ -852,7 +854,7 @@ class RNode():
|
|||||||
RNS.log("Could not deserialize local signing key")
|
RNS.log("Could not deserialize local signing key")
|
||||||
RNS.log(str(e))
|
RNS.log(str(e))
|
||||||
|
|
||||||
# Try loading trusted signing key for
|
# Try loading trusted signing key for
|
||||||
# validation of devices
|
# validation of devices
|
||||||
if os.path.isdir(TK_DIR):
|
if os.path.isdir(TK_DIR):
|
||||||
for f in os.listdir(TK_DIR):
|
for f in os.listdir(TK_DIR):
|
||||||
@ -930,7 +932,7 @@ class RNode():
|
|||||||
print(" ")
|
print(" ")
|
||||||
print(" To initialise this device to a verifiable state, please run:")
|
print(" To initialise this device to a verifiable state, please run:")
|
||||||
print(" ")
|
print(" ")
|
||||||
print(" rnodeconf "+str(self.serial.name)+" --autoinstall")
|
print("".join([" rnodeconf ", str(self.serial.name), " --autoinstall"]))
|
||||||
print("")
|
print("")
|
||||||
|
|
||||||
|
|
||||||
@ -965,7 +967,7 @@ class RNode():
|
|||||||
|
|
||||||
selected_version = None
|
selected_version = None
|
||||||
selected_hash = None
|
selected_hash = None
|
||||||
firmware_version_url = "https://unsigned.io/firmware/latest/?v="+program_version+"&variant="
|
firmware_version_url = "".join(["https://unsigned.io/firmware/latest/?v=", program_version, "&variant="])
|
||||||
fallback_firmware_version_url = "https://github.com/markqvist/rnode_firmware/releases/latest/download/release.json"
|
fallback_firmware_version_url = "https://github.com/markqvist/rnode_firmware/releases/latest/download/release.json"
|
||||||
def ensure_firmware_file(fw_filename):
|
def ensure_firmware_file(fw_filename):
|
||||||
global selected_version, selected_hash, upd_nocheck
|
global selected_version, selected_hash, upd_nocheck
|
||||||
@ -981,7 +983,7 @@ def ensure_firmware_file(fw_filename):
|
|||||||
]
|
]
|
||||||
parts_missing = False
|
parts_missing = False
|
||||||
for rf in required_files:
|
for rf in required_files:
|
||||||
if not os.path.isfile(EXT_DIR+"/"+rf):
|
if not os.path.isfile("".join([EXT_DIR, "/", rf])):
|
||||||
parts_missing = True
|
parts_missing = True
|
||||||
|
|
||||||
if parts_missing:
|
if parts_missing:
|
||||||
@ -994,7 +996,7 @@ def ensure_firmware_file(fw_filename):
|
|||||||
release_info = vf.read().decode("utf-8").strip()
|
release_info = vf.read().decode("utf-8").strip()
|
||||||
selected_version = release_info.split()[0]
|
selected_version = release_info.split()[0]
|
||||||
selected_hash = release_info.split()[1]
|
selected_hash = release_info.split()[1]
|
||||||
RNS.log("Using existing firmware file: "+fw_filename+" for version "+selected_version)
|
RNS.log("".join(["Using existing firmware file: ", fw_filename, " for version ", selected_version]))
|
||||||
else:
|
else:
|
||||||
RNS.log("No extracted firmware is available, cannot continue.")
|
RNS.log("No extracted firmware is available, cannot continue.")
|
||||||
RNS.log("Extract a firmware from an existing RNode first, using the --extract-firmware option.")
|
RNS.log("Extract a firmware from an existing RNode first, using the --extract-firmware option.")
|
||||||
@ -1006,17 +1008,19 @@ def ensure_firmware_file(fw_filename):
|
|||||||
try:
|
try:
|
||||||
# if custom firmware url, download latest release
|
# if custom firmware url, download latest release
|
||||||
if selected_version == None and fw_url == None:
|
if selected_version == None and fw_url == None:
|
||||||
version_url = firmware_version_url+fw_filename
|
version_url = firmware_version_url + fw_filename
|
||||||
RNS.log("Retrieving latest version info from "+version_url)
|
RNS.log("Retrieving latest version info from "+version_url)
|
||||||
urlretrieve(firmware_version_url+fw_filename, UPD_DIR+"/"+fw_filename+".version.latest")
|
urlretrieve(version_url, "".join([UPD_DIR, "/", fw_filename, ".version.latest"]))
|
||||||
else:
|
else:
|
||||||
if fw_url != None:
|
if fw_url != None:
|
||||||
if selected_version == None:
|
if selected_version == None:
|
||||||
version_url = fw_url+"latest/download/release.json"
|
version_url = fw_url+"latest/download/release.json"
|
||||||
else:
|
else:
|
||||||
version_url = fw_url+"download/"+selected_version+"/release.json"
|
version_url = "".join([fw_url, "download/", selected_version, "/release.json"])
|
||||||
else:
|
else:
|
||||||
version_url = firmware_update_url+selected_version+"/release.json"
|
if selected_version is None:
|
||||||
|
selected_version = ""
|
||||||
|
version_url = "".join([firmware_update_url, selected_version, "/release.json"])
|
||||||
try:
|
try:
|
||||||
RNS.log("Retrieving specified version info from "+version_url)
|
RNS.log("Retrieving specified version info from "+version_url)
|
||||||
urlretrieve(version_url, UPD_DIR+"/version_release_info.json")
|
urlretrieve(version_url, UPD_DIR+"/version_release_info.json")
|
||||||
@ -1024,8 +1028,9 @@ def ensure_firmware_file(fw_filename):
|
|||||||
with open(UPD_DIR+"/version_release_info.json", "rb") as rif:
|
with open(UPD_DIR+"/version_release_info.json", "rb") as rif:
|
||||||
rdat = json.loads(rif.read())
|
rdat = json.loads(rif.read())
|
||||||
variant = rdat[fw_filename]
|
variant = rdat[fw_filename]
|
||||||
with open(UPD_DIR+"/"+fw_filename+".version.latest", "wb") as verf:
|
with open("".join([UPD_DIR, "/", fw_filename, ".version.latest"]), "wb") as verf:
|
||||||
inf_str = str(variant["version"])+" "+str(variant["hash"])
|
inf_str = str(variant["version"])+" "+str(variant["hash"])
|
||||||
|
inf_str = "".join([str(variant["version"]), " ", str(variant["hash"])])
|
||||||
verf.write(inf_str.encode("utf-8"))
|
verf.write(inf_str.encode("utf-8"))
|
||||||
except Exception as e:
|
except Exception as e:
|
||||||
RNS.log("Failed to retrive version information for your board.")
|
RNS.log("Failed to retrive version information for your board.")
|
||||||
@ -1055,7 +1060,7 @@ def ensure_firmware_file(fw_filename):
|
|||||||
with open(UPD_DIR+"/fallback_release_info.json", "rb") as rif:
|
with open(UPD_DIR+"/fallback_release_info.json", "rb") as rif:
|
||||||
rdat = json.loads(rif.read())
|
rdat = json.loads(rif.read())
|
||||||
variant = rdat[fw_filename]
|
variant = rdat[fw_filename]
|
||||||
with open(UPD_DIR+"/"+fw_filename+".version.latest", "wb") as verf:
|
with open("".join([UPD_DIR, "/", fw_filename, ".version.latest"]), "wb") as verf:
|
||||||
inf_str = str(variant["version"])+" "+str(variant["hash"])
|
inf_str = str(variant["version"])+" "+str(variant["hash"])
|
||||||
verf.write(inf_str.encode("utf-8"))
|
verf.write(inf_str.encode("utf-8"))
|
||||||
|
|
||||||
@ -1064,7 +1069,7 @@ def ensure_firmware_file(fw_filename):
|
|||||||
raise e
|
raise e
|
||||||
|
|
||||||
import shutil
|
import shutil
|
||||||
file = open(UPD_DIR+"/"+fw_filename+".version.latest", "rb")
|
file = open("".join([UPD_DIR, "/", fw_filename, ".version.latest"]), "rb")
|
||||||
release_info = file.read().decode("utf-8").strip()
|
release_info = file.read().decode("utf-8").strip()
|
||||||
selected_version = release_info.split()[0]
|
selected_version = release_info.split()[0]
|
||||||
if selected_version == "not":
|
if selected_version == "not":
|
||||||
@ -1074,7 +1079,7 @@ def ensure_firmware_file(fw_filename):
|
|||||||
selected_hash = release_info.split()[1]
|
selected_hash = release_info.split()[1]
|
||||||
if not os.path.isdir(UPD_DIR+"/"+selected_version):
|
if not os.path.isdir(UPD_DIR+"/"+selected_version):
|
||||||
os.makedirs(UPD_DIR+"/"+selected_version)
|
os.makedirs(UPD_DIR+"/"+selected_version)
|
||||||
shutil.copy(UPD_DIR+"/"+fw_filename+".version.latest", UPD_DIR+"/"+selected_version+"/"+fw_filename+".version")
|
shutil.copy("".join([UPD_DIR, "/", fw_filename, ".version.latest"]), "".join([UPD_DIR, "/", selected_version, "/", fw_filename, ".version"]))
|
||||||
RNS.log("The selected firmware for this board is version "+selected_version)
|
RNS.log("The selected firmware for this board is version "+selected_version)
|
||||||
|
|
||||||
else:
|
else:
|
||||||
@ -1084,32 +1089,32 @@ def ensure_firmware_file(fw_filename):
|
|||||||
|
|
||||||
# if custom firmware url, use it
|
# if custom firmware url, use it
|
||||||
if fw_url != None:
|
if fw_url != None:
|
||||||
update_target_url = fw_url+"download/"+selected_version+"/"+fw_filename
|
update_target_url = "".join([fw_url, "download/", selected_version, "/", fw_filename])
|
||||||
RNS.log("Retrieving firmware from custom url "+update_target_url)
|
RNS.log("Retrieving firmware from custom url "+update_target_url)
|
||||||
else:
|
else:
|
||||||
update_target_url = firmware_update_url+selected_version+"/"+fw_filename
|
update_target_url = "".join([firmware_update_url, selected_version, "/", fw_filename])
|
||||||
|
|
||||||
try:
|
try:
|
||||||
if not os.path.isdir(UPD_DIR+"/"+selected_version):
|
if not os.path.isdir(UPD_DIR+"/"+selected_version):
|
||||||
os.makedirs(UPD_DIR+"/"+selected_version)
|
os.makedirs(UPD_DIR+"/"+selected_version)
|
||||||
|
|
||||||
if not os.path.isfile(UPD_DIR+"/"+selected_version+"/"+fw_filename):
|
if not os.path.isfile("".join([UPD_DIR, "/", selected_version, "/", fw_filename])):
|
||||||
RNS.log("Firmware "+UPD_DIR+"/"+selected_version+"/"+fw_filename+" not found.")
|
RNS.log("".join(["Firmware ", UPD_DIR, "/", selected_version, "/", fw_filename, " not found."]))
|
||||||
RNS.log("Downloading missing firmware file: "+fw_filename+" for version "+selected_version)
|
RNS.log("".join(["Downloading missing firmware file: ", fw_filename, " for version ", selected_version]))
|
||||||
urlretrieve(update_target_url, UPD_DIR+"/"+selected_version+"/"+fw_filename)
|
urlretrieve(update_target_url, "".join([UPD_DIR, "/", selected_version, "/", fw_filename]))
|
||||||
RNS.log("Firmware file downloaded")
|
RNS.log("Firmware file downloaded")
|
||||||
else:
|
else:
|
||||||
RNS.log("Using existing firmware file: "+fw_filename+" for version "+selected_version)
|
RNS.log("".join(["Using existing firmware file: ", fw_filename, " for version ", selected_version]))
|
||||||
|
|
||||||
try:
|
try:
|
||||||
if selected_hash == None:
|
if selected_hash == None:
|
||||||
try:
|
try:
|
||||||
file = open(UPD_DIR+"/"+selected_version+"/"+fw_filename+".version", "rb")
|
file = open("".join([UPD_DIR, "/", selected_version, "/", fw_filename, ".version"]), "rb")
|
||||||
release_info = file.read().decode("utf-8").strip()
|
release_info = file.read().decode("utf-8").strip()
|
||||||
selected_hash = release_info.split()[1]
|
selected_hash = release_info.split()[1]
|
||||||
except Exception as e:
|
except Exception as e:
|
||||||
RNS.log("Could not read locally cached release information.")
|
RNS.log("Could not read locally cached release information.")
|
||||||
RNS.log("Ensure "+UPD_DIR+"/"+selected_version+"/"+fw_filename+".version exists and has the correct format and hash.")
|
RNS.log("".join(["Ensure ", UPD_DIR, "/", selected_version, "/", fw_filename, ".version exists and has the correct format and hash."]))
|
||||||
RNS.log("You can clear the cache with the --clear-cache option and try again.")
|
RNS.log("You can clear the cache with the --clear-cache option and try again.")
|
||||||
|
|
||||||
if selected_hash == None:
|
if selected_hash == None:
|
||||||
@ -1117,7 +1122,8 @@ def ensure_firmware_file(fw_filename):
|
|||||||
exit(97)
|
exit(97)
|
||||||
|
|
||||||
RNS.log("Verifying firmware integrity...")
|
RNS.log("Verifying firmware integrity...")
|
||||||
fw_file = open(UPD_DIR+"/"+selected_version+"/"+fw_filename, "rb")
|
fw_file = open("".join([UPD_DIR, "/", selected_version, "/", fw_filename]), "rb")
|
||||||
|
# TODO: Remove unused variable
|
||||||
expected_hash = bytes.fromhex(selected_hash)
|
expected_hash = bytes.fromhex(selected_hash)
|
||||||
file_hash = hashlib.sha256(fw_file.read()).hexdigest()
|
file_hash = hashlib.sha256(fw_file.read()).hexdigest()
|
||||||
if file_hash == selected_hash:
|
if file_hash == selected_hash:
|
||||||
@ -1230,11 +1236,11 @@ def main():
|
|||||||
|
|
||||||
parser.add_argument("-f", "--flash", action="store_true", help="Flash firmware and bootstrap EEPROM")
|
parser.add_argument("-f", "--flash", action="store_true", help="Flash firmware and bootstrap EEPROM")
|
||||||
parser.add_argument("-r", "--rom", action="store_true", help="Bootstrap EEPROM without flashing firmware")
|
parser.add_argument("-r", "--rom", action="store_true", help="Bootstrap EEPROM without flashing firmware")
|
||||||
parser.add_argument("-k", "--key", action="store_true", help="Generate a new signing key and exit") #
|
parser.add_argument("-k", "--key", action="store_true", help="Generate a new signing key and exit") #
|
||||||
parser.add_argument("-S", "--sign", action="store_true", help="Display public part of signing key")
|
parser.add_argument("-S", "--sign", action="store_true", help="Display public part of signing key")
|
||||||
parser.add_argument("-H", "--firmware-hash", action="store", help="Display installed firmware hash")
|
parser.add_argument("-H", "--firmware-hash", action="store", help="Display installed firmware hash")
|
||||||
parser.add_argument("--platform", action="store", metavar="platform", type=str, default=None, help="Platform specification for device bootstrap")
|
parser.add_argument("--platform", action="store", metavar="platform", type=str, default=None, help="Platform specification for device bootstrap")
|
||||||
parser.add_argument("--product", action="store", metavar="product", type=str, default=None, help="Product specification for device bootstrap") #
|
parser.add_argument("--product", action="store", metavar="product", type=str, default=None, help="Product specification for device bootstrap") #
|
||||||
parser.add_argument("--model", action="store", metavar="model", type=str, default=None, help="Model code for device bootstrap")
|
parser.add_argument("--model", action="store", metavar="model", type=str, default=None, help="Model code for device bootstrap")
|
||||||
parser.add_argument("--hwrev", action="store", metavar="revision", type=int, default=None, help="Hardware revision for device bootstrap")
|
parser.add_argument("--hwrev", action="store", metavar="revision", type=int, default=None, help="Hardware revision for device bootstrap")
|
||||||
|
|
||||||
@ -1263,7 +1269,7 @@ def main():
|
|||||||
|
|
||||||
if args.fw_version != None:
|
if args.fw_version != None:
|
||||||
selected_version = args.fw_version
|
selected_version = args.fw_version
|
||||||
try:
|
try:
|
||||||
check_float = float(selected_version)
|
check_float = float(selected_version)
|
||||||
except ValueError:
|
except ValueError:
|
||||||
RNS.log("Selected version \""+selected_version+"\" does not appear to be a number.")
|
RNS.log("Selected version \""+selected_version+"\" does not appear to be a number.")
|
||||||
@ -1277,7 +1283,7 @@ def main():
|
|||||||
|
|
||||||
if args.nocheck:
|
if args.nocheck:
|
||||||
upd_nocheck = True
|
upd_nocheck = True
|
||||||
|
|
||||||
if args.public or args.key or args.flash or args.rom or args.autoinstall or args.trust_key:
|
if args.public or args.key or args.flash or args.rom or args.autoinstall or args.trust_key:
|
||||||
from cryptography.hazmat.primitives import hashes
|
from cryptography.hazmat.primitives import hashes
|
||||||
from cryptography.hazmat.backends import default_backend
|
from cryptography.hazmat.backends import default_backend
|
||||||
@ -1296,7 +1302,7 @@ def main():
|
|||||||
public_key = load_der_public_key(public_bytes, backend=default_backend())
|
public_key = load_der_public_key(public_bytes, backend=default_backend())
|
||||||
key_hash = hashlib.sha256(public_bytes).hexdigest()
|
key_hash = hashlib.sha256(public_bytes).hexdigest()
|
||||||
RNS.log("Trusting key: "+str(key_hash))
|
RNS.log("Trusting key: "+str(key_hash))
|
||||||
f = open(TK_DIR+"/"+str(key_hash)+".pubkey", "wb")
|
f = open("".join([TK_DIR, "/", str(key_hash), ".pubkey"]), "wb")
|
||||||
f.write(public_bytes)
|
f.write(public_bytes)
|
||||||
f.close()
|
f.close()
|
||||||
|
|
||||||
@ -1328,12 +1334,12 @@ def main():
|
|||||||
ports = list_ports.comports()
|
ports = list_ports.comports()
|
||||||
portlist = []
|
portlist = []
|
||||||
for port in ports:
|
for port in ports:
|
||||||
portlist.insert(0, port)
|
portlist.insert(0, port)
|
||||||
|
|
||||||
pi = 1
|
pi = 1
|
||||||
print("Detected serial ports:")
|
print("Detected serial ports:")
|
||||||
for port in portlist:
|
for port in portlist:
|
||||||
print(" ["+str(pi)+"] "+str(port.device)+" ("+str(port.product)+", "+str(port.serial_number)+")")
|
print("".join([" [", str(pi), "] ", str(port.device), " (", str(port.product), ", ", str(port.serial_number), ")"]))
|
||||||
pi += 1
|
pi += 1
|
||||||
|
|
||||||
print("\nEnter the number of the serial port your device is connected to:\n? ", end="")
|
print("\nEnter the number of the serial port your device is connected to:\n? ", end="")
|
||||||
@ -1355,7 +1361,7 @@ def main():
|
|||||||
port_product = selected_port.product
|
port_product = selected_port.product
|
||||||
port_serialno = selected_port.serial_number
|
port_serialno = selected_port.serial_number
|
||||||
|
|
||||||
print("\nOk, using device on "+str(port_path)+" ("+str(port_product)+", "+str(port_serialno)+")")
|
print("".join(["\nOk, using device on ", str(port_path), " (", str(port_product), ", ", str(port_serialno), ")"]))
|
||||||
|
|
||||||
else:
|
else:
|
||||||
ports = list_ports.comports()
|
ports = list_ports.comports()
|
||||||
@ -1423,11 +1429,11 @@ def main():
|
|||||||
hash_f.close()
|
hash_f.close()
|
||||||
|
|
||||||
extraction_parts = [
|
extraction_parts = [
|
||||||
("bootloader", "python \""+CNF_DIR+"/recovery_esptool.py\" --chip esp32 --port "+port_path+" --baud "+args.baud_flash+" --before default_reset --after hard_reset read_flash 0x1000 0x4650 \""+EXT_DIR+"/extracted_rnode_firmware.bootloader\""),
|
("bootloader", "".join(["python \"", CNF_DIR, "/recovery_esptool.py\" --chip esp32 --port ", port_path, " --baud ", args.baud_flash, " --before default_reset --after hard_reset read_flash 0x1000 0x4650 \"", EXT_DIR, "/extracted_rnode_firmware.bootloader\""])),
|
||||||
("partition table", "python \""+CNF_DIR+"/recovery_esptool.py\" --chip esp32 --port "+port_path+" --baud "+args.baud_flash+" --before default_reset --after hard_reset read_flash 0x8000 0xC00 \""+EXT_DIR+"/extracted_rnode_firmware.partitions\""),
|
("partition table", "".join(["python \"", CNF_DIR, "/recovery_esptool.py\" --chip esp32 --port ", port_path, " --baud ", args.baud_flash, " --before default_reset --after hard_reset read_flash 0x8000 0xC00 \"", EXT_DIR, "/extracted_rnode_firmware.partitions\""])),
|
||||||
("app boot", "python \""+CNF_DIR+"/recovery_esptool.py\" --chip esp32 --port "+port_path+" --baud "+args.baud_flash+" --before default_reset --after hard_reset read_flash 0xe000 0x2000 \""+EXT_DIR+"/extracted_rnode_firmware.boot_app0\""),
|
("app boot", "".join(["python \"", CNF_DIR, "/recovery_esptool.py\" --chip esp32 --port ", port_path, " --baud ", args.baud_flash, " --before default_reset --after hard_reset read_flash 0xe000 0x2000 \"", EXT_DIR, "/extracted_rnode_firmware.boot_app0\""])),
|
||||||
("application image", "python \""+CNF_DIR+"/recovery_esptool.py\" --chip esp32 --port "+port_path+" --baud "+args.baud_flash+" --before default_reset --after hard_reset read_flash 0x10000 0x200000 \""+EXT_DIR+"/extracted_rnode_firmware.bin\""),
|
("application image", "".join(["python \"", CNF_DIR, "/recovery_esptool.py\" --chip esp32 --port ", port_path, " --baud ", args.baud_flash, " --before default_reset --after hard_reset read_flash 0x10000 0x200000 \"", EXT_DIR, "/extracted_rnode_firmware.bin\""])),
|
||||||
("console image", "python \""+CNF_DIR+"/recovery_esptool.py\" --chip esp32 --port "+port_path+" --baud "+args.baud_flash+" --before default_reset --after hard_reset read_flash 0x210000 0x1F0000 \""+EXT_DIR+"/extracted_console_image.bin\""),
|
("console image", "".join(["python \"", CNF_DIR, "/recovery_esptool.py\" --chip esp32 --port ", port_path, " --baud ", args.baud_flash, " --before default_reset --after hard_reset read_flash 0x210000 0x1F0000 \"", EXT_DIR, "/extracted_console_image.bin\""])),
|
||||||
]
|
]
|
||||||
import subprocess, shlex
|
import subprocess, shlex
|
||||||
for part, command in extraction_parts:
|
for part, command in extraction_parts:
|
||||||
@ -1460,12 +1466,12 @@ def main():
|
|||||||
ports = list_ports.comports()
|
ports = list_ports.comports()
|
||||||
portlist = []
|
portlist = []
|
||||||
for port in ports:
|
for port in ports:
|
||||||
portlist.insert(0, port)
|
portlist.insert(0, port)
|
||||||
|
|
||||||
pi = 1
|
pi = 1
|
||||||
print("Detected serial ports:")
|
print("Detected serial ports:")
|
||||||
for port in portlist:
|
for port in portlist:
|
||||||
print(" ["+str(pi)+"] "+str(port.device)+" ("+str(port.product)+", "+str(port.serial_number)+")")
|
print("".join([" [", str(pi), "] ", str(port.device), " (", str(port.product), ", ", str(port.serial_number), ")"]))
|
||||||
pi += 1
|
pi += 1
|
||||||
|
|
||||||
print("\nEnter the number of the serial port your device is connected to:\n? ", end="")
|
print("\nEnter the number of the serial port your device is connected to:\n? ", end="")
|
||||||
@ -1488,7 +1494,7 @@ def main():
|
|||||||
port_serialno = selected_port.serial_number
|
port_serialno = selected_port.serial_number
|
||||||
|
|
||||||
clear()
|
clear()
|
||||||
print("\nOk, using device on "+str(port_path)+" ("+str(port_product)+", "+str(port_serialno)+")")
|
print("".join(["\nOk, using device on ", str(port_path), " (", str(port_product), ", ", str(port_serialno), ")"]))
|
||||||
|
|
||||||
else:
|
else:
|
||||||
ports = list_ports.comports()
|
ports = list_ports.comports()
|
||||||
@ -1541,7 +1547,7 @@ def main():
|
|||||||
print("correct firmware and provision it.")
|
print("correct firmware and provision it.")
|
||||||
else:
|
else:
|
||||||
print("\nIt looks like this is a fresh device with no RNode firmware.")
|
print("\nIt looks like this is a fresh device with no RNode firmware.")
|
||||||
|
|
||||||
print("")
|
print("")
|
||||||
print("What kind of device is this?\n")
|
print("What kind of device is this?\n")
|
||||||
print("[1] A specific kind of RNode")
|
print("[1] A specific kind of RNode")
|
||||||
@ -1981,7 +1987,7 @@ def main():
|
|||||||
fw_filename = "rnode_firmware.hex"
|
fw_filename = "rnode_firmware.hex"
|
||||||
elif selected_mcu == ROM.MCU_2560:
|
elif selected_mcu == ROM.MCU_2560:
|
||||||
fw_filename = "rnode_firmware_m2560.hex"
|
fw_filename = "rnode_firmware_m2560.hex"
|
||||||
|
|
||||||
elif selected_platform == ROM.PLATFORM_ESP32:
|
elif selected_platform == ROM.PLATFORM_ESP32:
|
||||||
fw_filename = None
|
fw_filename = None
|
||||||
print("\nWhat kind of ESP32 board is this?\n")
|
print("\nWhat kind of ESP32 board is this?\n")
|
||||||
@ -2094,7 +2100,7 @@ def main():
|
|||||||
|
|
||||||
except Exception as e:
|
except Exception as e:
|
||||||
RNS.log("Could not load device signing key")
|
RNS.log("Could not load device signing key")
|
||||||
|
|
||||||
|
|
||||||
exit()
|
exit()
|
||||||
|
|
||||||
@ -2177,7 +2183,7 @@ def main():
|
|||||||
if platform == "unzip":
|
if platform == "unzip":
|
||||||
flasher = "unzip"
|
flasher = "unzip"
|
||||||
if which(flasher) is not None:
|
if which(flasher) is not None:
|
||||||
return [flasher, "-o", UPD_DIR+"/"+selected_version+"/"+fw_filename, "-d", UPD_DIR+"/"+selected_version]
|
return [flasher, "-o", "".join([UPD_DIR, "/", selected_version, "/", fw_filename]), "-d", UPD_DIR+"/"+selected_version]
|
||||||
else:
|
else:
|
||||||
RNS.log("")
|
RNS.log("")
|
||||||
RNS.log("You do not currently have the \""+flasher+"\" program installed on your system.")
|
RNS.log("You do not currently have the \""+flasher+"\" program installed on your system.")
|
||||||
@ -2194,9 +2200,9 @@ def main():
|
|||||||
# avrdude -C/home/markqvist/.arduino15/packages/arduino/tools/avrdude/6.3.0-arduino17/etc/avrdude.conf -q -q -V -patmega2560 -cwiring -P/dev/ttyACM0 -b115200 -D -Uflash:w:/tmp/arduino-sketch-0E260F46C421A84A7CBAD48E859C8E64/RNode_Firmware.ino.hex:i
|
# avrdude -C/home/markqvist/.arduino15/packages/arduino/tools/avrdude/6.3.0-arduino17/etc/avrdude.conf -q -q -V -patmega2560 -cwiring -P/dev/ttyACM0 -b115200 -D -Uflash:w:/tmp/arduino-sketch-0E260F46C421A84A7CBAD48E859C8E64/RNode_Firmware.ino.hex:i
|
||||||
# avrdude -q -q -V -patmega2560 -cwiring -P/dev/ttyACM0 -b115200 -D -Uflash:w:/tmp/arduino-sketch-0E260F46C421A84A7CBAD48E859C8E64/RNode_Firmware.ino.hex:i
|
# avrdude -q -q -V -patmega2560 -cwiring -P/dev/ttyACM0 -b115200 -D -Uflash:w:/tmp/arduino-sketch-0E260F46C421A84A7CBAD48E859C8E64/RNode_Firmware.ino.hex:i
|
||||||
if fw_filename == "rnode_firmware.hex":
|
if fw_filename == "rnode_firmware.hex":
|
||||||
return [flasher, "-P", args.port, "-p", "m1284p", "-c", "arduino", "-b", "115200", "-U", "flash:w:"+UPD_DIR+"/"+selected_version+"/"+fw_filename+":i"]
|
return [flasher, "-P", args.port, "-p", "m1284p", "-c", "arduino", "-b", "115200", "-U", "".join(["flash:w:", UPD_DIR, "/", selected_version, "/", fw_filename, ":i"])]
|
||||||
elif fw_filename == "rnode_firmware_m2560.hex":
|
elif fw_filename == "rnode_firmware_m2560.hex":
|
||||||
return [flasher, "-P", args.port, "-p", "atmega2560", "-c", "wiring", "-D", "-b", "115200", "-U", "flash:w:"+UPD_DIR+"/"+selected_version+"/"+fw_filename]
|
return [flasher, "-P", args.port, "-p", "atmega2560", "-c", "wiring", "-D", "-b", "115200", "-U", "".join(["flash:w:", UPD_DIR, "/", selected_version, "/", fw_filename])]
|
||||||
else:
|
else:
|
||||||
RNS.log("")
|
RNS.log("")
|
||||||
RNS.log("You do not currently have the \""+flasher+"\" program installed on your system.")
|
RNS.log("You do not currently have the \""+flasher+"\" program installed on your system.")
|
||||||
@ -2224,6 +2230,7 @@ def main():
|
|||||||
os.chmod(flasher, stat.S_IRWXU | stat.S_IRGRP | stat.S_IXGRP)
|
os.chmod(flasher, stat.S_IRWXU | stat.S_IRGRP | stat.S_IXGRP)
|
||||||
|
|
||||||
if which(flasher) is not None:
|
if which(flasher) is not None:
|
||||||
|
# TODO: Simplify this returns with a list and add or remove arguments
|
||||||
if fw_filename == "rnode_firmware_tbeam.zip":
|
if fw_filename == "rnode_firmware_tbeam.zip":
|
||||||
if numeric_version >= 1.55:
|
if numeric_version >= 1.55:
|
||||||
return [
|
return [
|
||||||
@ -2237,11 +2244,11 @@ def main():
|
|||||||
"--flash_mode", "dio",
|
"--flash_mode", "dio",
|
||||||
"--flash_freq", "80m",
|
"--flash_freq", "80m",
|
||||||
"--flash_size", "4MB",
|
"--flash_size", "4MB",
|
||||||
"0xe000", UPD_DIR+"/"+selected_version+"/rnode_firmware_tbeam.boot_app0",
|
"0xe000", "".join([UPD_DIR, "/", selected_version, "/rnode_firmware_tbeam.boot_app0"]),
|
||||||
"0x1000", UPD_DIR+"/"+selected_version+"/rnode_firmware_tbeam.bootloader",
|
"0x1000", "".join([UPD_DIR, "/", selected_version, "/rnode_firmware_tbeam.bootloader"]),
|
||||||
"0x10000", UPD_DIR+"/"+selected_version+"/rnode_firmware_tbeam.bin",
|
"0x10000", "".join([UPD_DIR, "/", selected_version, "/rnode_firmware_tbeam.bin"]),
|
||||||
"0x210000",UPD_DIR+"/"+selected_version+"/console_image.bin",
|
"0x210000","".join([UPD_DIR, "/", selected_version, "/console_image.bin"]),
|
||||||
"0x8000", UPD_DIR+"/"+selected_version+"/rnode_firmware_tbeam.partitions",
|
"0x8000", "".join([UPD_DIR, "/", selected_version, "/rnode_firmware_tbeam.partitions"]),
|
||||||
]
|
]
|
||||||
else:
|
else:
|
||||||
return [
|
return [
|
||||||
@ -2672,7 +2679,7 @@ def main():
|
|||||||
wants_fw_provision = False
|
wants_fw_provision = False
|
||||||
if args.flash:
|
if args.flash:
|
||||||
from subprocess import call
|
from subprocess import call
|
||||||
|
|
||||||
if fw_filename == None:
|
if fw_filename == None:
|
||||||
fw_filename = "rnode_firmware.hex"
|
fw_filename = "rnode_firmware.hex"
|
||||||
|
|
||||||
@ -2703,9 +2710,9 @@ def main():
|
|||||||
RNS.log("Error while flashing")
|
RNS.log("Error while flashing")
|
||||||
RNS.log(str(e))
|
RNS.log(str(e))
|
||||||
exit(1)
|
exit(1)
|
||||||
|
|
||||||
else:
|
else:
|
||||||
fw_src = UPD_DIR+"/"+selected_version+"/"
|
fw_src = "".join([UPD_DIR, "/", selected_version, "/"])
|
||||||
if os.path.isfile(fw_src+fw_filename):
|
if os.path.isfile(fw_src+fw_filename):
|
||||||
try:
|
try:
|
||||||
if fw_filename.endswith(".zip"):
|
if fw_filename.endswith(".zip"):
|
||||||
@ -2862,7 +2869,7 @@ def main():
|
|||||||
update_full_path = EXT_DIR+"/extracted_rnode_firmware.version"
|
update_full_path = EXT_DIR+"/extracted_rnode_firmware.version"
|
||||||
else:
|
else:
|
||||||
update_full_path = UPD_DIR+"/"+selected_version+"/"+fw_filename
|
update_full_path = UPD_DIR+"/"+selected_version+"/"+fw_filename
|
||||||
if os.path.isfile(update_full_path):
|
if os.path.isfile(update_full_path):
|
||||||
try:
|
try:
|
||||||
args.info = False
|
args.info = False
|
||||||
RNS.log("Updating RNode firmware for device on "+args.port)
|
RNS.log("Updating RNode firmware for device on "+args.port)
|
||||||
@ -3017,13 +3024,13 @@ def main():
|
|||||||
|
|
||||||
RNS.log("")
|
RNS.log("")
|
||||||
RNS.log("Device info:")
|
RNS.log("Device info:")
|
||||||
RNS.log("\tProduct : "+products[rnode.product]+" "+models[rnode.model][3]+" ("+bytes([rnode.product]).hex()+":"+bytes([rnode.model]).hex()+board_string+")")
|
RNS.log("".join(["\tProduct : ", products[rnode.product], " ", models[rnode.model][3], " (", bytes([rnode.product]).hex(), ":", bytes([rnode.model]).hex(), board_string, ")"]))
|
||||||
RNS.log("\tDevice signature : "+sigstring)
|
RNS.log("\tDevice signature : "+sigstring)
|
||||||
RNS.log("\tFirmware version : "+rnode.version)
|
RNS.log("\tFirmware version : "+rnode.version)
|
||||||
RNS.log("\tHardware revision : "+str(int(rnode.hw_rev)))
|
RNS.log("\tHardware revision : "+str(int(rnode.hw_rev)))
|
||||||
RNS.log("\tSerial number : "+RNS.hexrep(rnode.serialno))
|
RNS.log("\tSerial number : "+RNS.hexrep(rnode.serialno))
|
||||||
RNS.log("\tModem chip : "+str(models[rnode.model][5]))
|
RNS.log("\tModem chip : "+str(models[rnode.model][5]))
|
||||||
RNS.log("\tFrequency range : "+str(rnode.min_freq/1e6)+" MHz - "+str(rnode.max_freq/1e6)+" MHz")
|
RNS.log("".join(["\tFrequency range : ", str(rnode.min_freq/1e6), " MHz - ", str(rnode.max_freq/1e6), " MHz"]))
|
||||||
RNS.log("\tMax TX power : "+str(rnode.max_output)+" dBm")
|
RNS.log("\tMax TX power : "+str(rnode.max_output)+" dBm")
|
||||||
RNS.log("\tManufactured : "+timestring)
|
RNS.log("\tManufactured : "+timestring)
|
||||||
|
|
||||||
@ -3040,7 +3047,7 @@ def main():
|
|||||||
RNS.log("\tDevice mode : TNC")
|
RNS.log("\tDevice mode : TNC")
|
||||||
RNS.log("\t Frequency : "+str((rnode.conf_frequency/1000000.0))+" MHz")
|
RNS.log("\t Frequency : "+str((rnode.conf_frequency/1000000.0))+" MHz")
|
||||||
RNS.log("\t Bandwidth : "+str(rnode.conf_bandwidth/1000.0)+" KHz")
|
RNS.log("\t Bandwidth : "+str(rnode.conf_bandwidth/1000.0)+" KHz")
|
||||||
RNS.log("\t TX power : "+str(rnode.conf_txpower)+" dBm ("+str(txp_mw)+" mW)")
|
RNS.log("".join(["\t TX power : ", str(rnode.conf_txpower), " dBm (", str(txp_mw), " mW)"]))
|
||||||
RNS.log("\t Spreading factor : "+str(rnode.conf_sf))
|
RNS.log("\t Spreading factor : "+str(rnode.conf_sf))
|
||||||
RNS.log("\t Coding rate : "+str(rnode.conf_cr))
|
RNS.log("\t Coding rate : "+str(rnode.conf_cr))
|
||||||
RNS.log("\t On-air bitrate : "+str(rnode.bitrate_kbps)+" kbps")
|
RNS.log("\t On-air bitrate : "+str(rnode.bitrate_kbps)+" kbps")
|
||||||
@ -3070,7 +3077,7 @@ def main():
|
|||||||
if args.autoinstall:
|
if args.autoinstall:
|
||||||
RNS.log("Clearing old EEPROM, this will take about 15 seconds...")
|
RNS.log("Clearing old EEPROM, this will take about 15 seconds...")
|
||||||
rnode.wipe_eeprom()
|
rnode.wipe_eeprom()
|
||||||
|
|
||||||
if rnode.platform == ROM.PLATFORM_ESP32:
|
if rnode.platform == ROM.PLATFORM_ESP32:
|
||||||
RNS.log("Waiting for ESP32 reset...")
|
RNS.log("Waiting for ESP32 reset...")
|
||||||
time.sleep(6)
|
time.sleep(6)
|
||||||
@ -3241,7 +3248,7 @@ def main():
|
|||||||
vf.close()
|
vf.close()
|
||||||
else:
|
else:
|
||||||
partition_filename = fw_filename.replace(".zip", ".bin")
|
partition_filename = fw_filename.replace(".zip", ".bin")
|
||||||
partition_hash = get_partition_hash(UPD_DIR+"/"+selected_version+"/"+partition_filename)
|
partition_hash = get_partition_hash("".join([UPD_DIR, "/", selected_version, "/", partition_filename]))
|
||||||
|
|
||||||
if partition_hash != None:
|
if partition_hash != None:
|
||||||
time.sleep(0.75)
|
time.sleep(0.75)
|
||||||
|
Loading…
Reference in New Issue
Block a user