Added autoinstall and updating from extracted RNode Firmwares to rnodeconf

This commit is contained in:
Mark Qvist 2023-01-14 14:51:44 +01:00
parent eed7698ed3
commit 2a1ec6592c

View File

@ -867,6 +867,38 @@ selected_hash = None
firmware_version_url = "https://unsigned.io/firmware/latest/?v="+program_version+"&variant=" firmware_version_url = "https://unsigned.io/firmware/latest/?v="+program_version+"&variant="
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
if fw_filename == "extracted_rnode_firmware.zip":
vfpath = EXT_DIR+"/extracted_rnode_firmware.version"
if os.path.isfile(vfpath):
required_files = [
"extracted_console_image.bin",
"extracted_rnode_firmware.bin",
"extracted_rnode_firmware.boot_app0",
"extracted_rnode_firmware.bootloader",
"extracted_rnode_firmware.partitions",
]
parts_missing = False
for rf in required_files:
if not os.path.isfile(EXT_DIR+"/"+rf):
parts_missing = True
if parts_missing:
RNS.log("One or more required firmware files are missing from the extracted RNode")
RNS.log("Firmware archive. Installation cannot continue. Please try extracting the")
RNS.log("firmware again with the --extract-firmware option.")
exit(184)
vf = open(vfpath, "rb")
release_info = vf.read().decode("utf-8").strip()
selected_version = release_info.split()[0]
selected_hash = release_info.split()[1]
RNS.log("Using existing firmware file: "+fw_filename+" for version "+selected_version)
else:
RNS.log("No extracted firmware is available, cannot continue.")
RNS.log("Extract a firmware from an existing RNode first, using the --extract-firmware option.")
exit(183)
else:
try: try:
if selected_version == None: if selected_version == None:
if not upd_nocheck: if not upd_nocheck:
@ -1114,7 +1146,6 @@ def main():
port_product = selected_port.product port_product = selected_port.product
port_serialno = selected_port.serial_number port_serialno = selected_port.serial_number
clear()
print("\nOk, using device on "+str(port_path)+" ("+str(port_product)+", "+str(port_serialno)+")") print("\nOk, using device on "+str(port_path)+" ("+str(port_product)+", "+str(port_serialno)+")")
else: else:
@ -1457,6 +1488,7 @@ def main():
print("\nWhat model is this RNode?\n") print("\nWhat model is this RNode?\n")
print("[1] Handheld v2.x RNode, 410 - 525 MHz") print("[1] Handheld v2.x RNode, 410 - 525 MHz")
print("[2] Handheld v2.x RNode, 820 - 1020 MHz") print("[2] Handheld v2.x RNode, 820 - 1020 MHz")
print("")
print("[3] Original v1.x RNode, 410 - 525 MHz") print("[3] Original v1.x RNode, 410 - 525 MHz")
print("[4] Original v1.x RNode, 820 - 1020 MHz") print("[4] Original v1.x RNode, 820 - 1020 MHz")
# print("[5] Prototype v2 RNode, 410 - 525 MHz") # print("[5] Prototype v2 RNode, 410 - 525 MHz")
@ -1618,6 +1650,9 @@ def main():
print("") print("")
exit() exit()
if args.use_extracted:
fw_filename = "extracted_rnode_firmware.zip"
clear() clear()
print("") print("")
print("------------------------------------------------------------------------------") print("------------------------------------------------------------------------------")
@ -2104,6 +2139,24 @@ def main():
"0x10000", UPD_DIR+"/"+selected_version+"/rnode_firmware_ng21.bin", "0x10000", UPD_DIR+"/"+selected_version+"/rnode_firmware_ng21.bin",
"0x8000", UPD_DIR+"/"+selected_version+"/rnode_firmware_ng21.partitions", "0x8000", UPD_DIR+"/"+selected_version+"/rnode_firmware_ng21.partitions",
] ]
elif fw_filename == "extracted_rnode_firmware.zip":
return [
flasher,
"--chip", "esp32",
"--port", args.port,
"--baud", "921600",
"--before", "default_reset",
"--after", "hard_reset",
"write_flash", "-z",
"--flash_mode", "dio",
"--flash_freq", "80m",
"--flash_size", "4MB",
"0x1000", EXT_DIR+"/extracted_rnode_firmware.bootloader",
"0xe000", EXT_DIR+"/extracted_rnode_firmware.boot_app0",
"0x8000", EXT_DIR+"/extracted_rnode_firmware.partitions",
"0x10000", EXT_DIR+"/extracted_rnode_firmware.bin",
"0x210000",EXT_DIR+"/extracted_console_image.bin",
]
else: else:
RNS.log("No flasher available for this board, cannot install firmware.") RNS.log("No flasher available for this board, cannot install firmware.")
else: else:
@ -2132,6 +2185,28 @@ def main():
RNS.log("Missing parameters, cannot continue") RNS.log("Missing parameters, cannot continue")
exit(68) exit(68)
if fw_filename == "extracted_rnode_firmware.zip":
try:
RNS.log("Flashing RNode firmware to device on "+args.port)
from subprocess import call
rc = get_flasher_call(args.platform, fw_filename)
flash_status = call(rc)
if flash_status == 0:
RNS.log("Done flashing")
args.rom = True
if args.platform == ROM.PLATFORM_ESP32:
wants_fw_provision = True
RNS.log("Waiting for ESP32 reset...")
time.sleep(7)
else:
exit()
except Exception as e:
RNS.log("Error while flashing")
RNS.log(str(e))
exit(1)
else:
fw_src = UPD_DIR+"/"+selected_version+"/" fw_src = UPD_DIR+"/"+selected_version+"/"
if os.path.isfile(fw_src+fw_filename): if os.path.isfile(fw_src+fw_filename):
try: try:
@ -2202,6 +2277,9 @@ def main():
if rnode.provisioned: if rnode.provisioned:
if rnode.model != ROM.MODEL_FF: if rnode.model != ROM.MODEL_FF:
fw_filename = models[rnode.model][4] fw_filename = models[rnode.model][4]
else:
if args.use_extracted:
fw_filename = "extracted_rnode_firmware.zip"
else: else:
if rnode.platform == ROM.PLATFORM_AVR: if rnode.platform == ROM.PLATFORM_AVR:
if rnode.mcu == ROM.MCU_1284P: if rnode.mcu == ROM.MCU_1284P:
@ -2224,6 +2302,9 @@ def main():
RNS.log("Device not provisioned. Cannot update device firmware.") RNS.log("Device not provisioned. Cannot update device firmware.")
exit(1) exit(1)
if args.use_extracted:
fw_filename = "extracted_rnode_firmware.zip"
from subprocess import call from subprocess import call
try: try:
@ -2257,7 +2338,7 @@ def main():
if not fw_file_ensured and selected_version != None: if not fw_file_ensured and selected_version != None:
ensure_firmware_file(fw_filename) ensure_firmware_file(fw_filename)
if fw_filename.endswith(".zip"): if fw_filename.endswith(".zip") and not fw_filename == "extracted_rnode_firmware.zip":
RNS.log("Extracting firmware...") RNS.log("Extracting firmware...")
unzip_status = call(get_flasher_call("unzip", fw_filename)) unzip_status = call(get_flasher_call("unzip", fw_filename))
if unzip_status == 0: if unzip_status == 0:
@ -2271,10 +2352,20 @@ def main():
RNS.log("The contained exception was: "+str(e)) RNS.log("The contained exception was: "+str(e))
exit() exit()
if os.path.isfile(UPD_DIR+"/"+selected_version+"/"+fw_filename): if fw_filename == "extracted_rnode_firmware.zip":
update_full_path = EXT_DIR+"/extracted_rnode_firmware.version"
else:
update_full_path = UPD_DIR+"/"+selected_version+"/"+fw_filename
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)
if fw_filename == "extracted_rnode_firmware.zip":
vf = open(update_full_path, "rb")
release_info = vf.read().decode("utf-8").strip()
partition_hash = bytes.fromhex(release_info.split()[1])
vf.close()
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(UPD_DIR+"/"+selected_version+"/"+partition_filename)
if partition_hash != None: if partition_hash != None:
@ -2582,8 +2673,18 @@ def main():
RNS.log("EEPROM written! Validating...") RNS.log("EEPROM written! Validating...")
if wants_fw_provision: if wants_fw_provision:
partition_hash = None
if fw_filename == "extracted_rnode_firmware.zip":
update_full_path = EXT_DIR+"/extracted_rnode_firmware.version"
vf = open(update_full_path, "rb")
release_info = vf.read().decode("utf-8").strip()
partition_hash = bytes.fromhex(release_info.split()[1])
vf.close()
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(UPD_DIR+"/"+selected_version+"/"+partition_filename)
if partition_hash != None: if partition_hash != None:
rnode.set_firmware_hash(partition_hash) rnode.set_firmware_hash(partition_hash)