connectcore-demo-example: fix firmware update from local web

Use the same command independently of the boot system.
Fix the way dual boot is detected to use 'dualboot' U-Boot variable.

Signed-off-by: Tatiana Leon <Tatiana.Leon@digi.com>
This commit is contained in:
Tatiana Leon 2022-11-23 17:43:16 +01:00
parent cab26c39e7
commit d9e0146e41
1 changed files with 11 additions and 15 deletions

View File

@ -513,19 +513,15 @@ class RequestHandler(http.server.SimpleHTTPRequestHandler):
path = json.loads(data.decode("utf-8")).get("file", None) path = json.loads(data.decode("utf-8")).get("file", None)
log.debug("Update firmware with file %s", path) log.debug("Update firmware with file %s", path)
if not is_dual_system() and not path.startswith(get_fw_store_path())\
if is_dual_system(): and shutil.disk_usage(get_fw_store_path())[2] >= os.path.getsize(path):
cmd = "firmware-update-dual.sh %s" % path # Move the package to /mnt/update to avoid permission problems
else: update_path = os.path.join(get_fw_store_path(), os.path.basename(path))
if not path.startswith(get_fw_store_path()): if os.path.exists(update_path):
# Move the package to /mnt/update os.remove(update_path)
update_path = os.path.join(get_fw_store_path(), os.path.basename(path)) shutil.move(path, update_path)
if os.path.exists(update_path): path = update_path
os.remove(update_path) cmd = "update-firmware %s" % path
shutil.move(path, update_path)
path = update_path
cmd = "update-firmware --reboot-timeout=1 %s" % path
log.debug("Update cmd: %s", cmd) log.debug("Update cmd: %s", cmd)
try: try:
@ -806,8 +802,8 @@ def is_dual_system():
Returns: Returns:
Boolean: True for dual systems, False otherwise. Boolean: True for dual systems, False otherwise.
""" """
res = exec_cmd("fdisk -l | grep recovery") res = exec_cmd("fw_printenv -n dualboot")
return res[0] != 0 return res[0] == 0 and res[1] == "yes"
def get_fw_store_path(): def get_fw_store_path():