Skip to content

Commit

Permalink
f_mu: fixes #1125 by checking that safe upgrade is ready
Browse files Browse the repository at this point in the history
  • Loading branch information
javierbrk committed Sep 13, 2024
1 parent a03cc22 commit 32b40a1
Show file tree
Hide file tree
Showing 3 changed files with 30 additions and 5 deletions.
25 changes: 20 additions & 5 deletions packages/lime-mesh-upgrade/files/usr/lib/lua/lime-mesh-upgrade.lua
Original file line number Diff line number Diff line change
Expand Up @@ -39,8 +39,8 @@ local mesh_upgrade = {
CONFIRMATION_TIME_OUT = "confirmation_timeout",
-- ABORTED = "aborted",
FW_FILE_NOT_FOUND = "firmware_file_not_found",
INVALID_FW_FILE = "invalid_firmware_file"

INVALID_FW_FILE = "invalid_firmware_file",
SAFE_UPGRADE_NOT_BOOTSTRAPED= "safe upgrade not working"
},
fw_path = "",
su_confirm_timeout = 600,
Expand Down Expand Up @@ -179,6 +179,18 @@ function mesh_upgrade.check_eupgrade_download_failed()
return download_status
end


function mesh_upgrade.check_safeupgrade_is_working()
local result = os.execute("safe-upgrade bootstrap")
local exit_code = result and (result / 256) or result
if exit_code == 121 then
-- this means that safeupgrade has been bootrsaped and is ready to work
return true
end
mesh_upgrade.report_error(mesh_upgrade.errors.SAFE_UPGRADE_NOT_BOOTSTRAPED)
return false
end

function mesh_upgrade.start_firmware_upgrade_transaction()
-- todo(kon): do all needed checks also with the main node state etc..
-- Expose eupgrade folder to uhttp (this is the best place to do it since
Expand Down Expand Up @@ -478,14 +490,16 @@ end

-- ! Read status from UCI
function mesh_upgrade.get_node_status()
mesh_upgrade.check_safeupgrade_is_working()
local uci = config.get_uci_cursor()
local upgrade_data = {}
upgrade_data.candidate_fw = uci:get('mesh-upgrade', 'main', 'candidate_fw')
upgrade_data.repo_url = uci:get('mesh-upgrade', 'main', 'repo_url')
upgrade_data.eupgradestate = mesh_upgrade.check_eupgrade_download_failed()
upgrade_data.upgrade_state = mesh_upgrade.state()
local safe_upgrade_confirm_remaining = tonumber(utils.unsafe_shell("safe-upgrade confirm-remaining"))
if (upgrade_data.upgrade_state == mesh_upgrade.upgrade_states.UPGRADE_SCHEDULED) then
if (tonumber(utils.unsafe_shell("safe-upgrade confirm-remaining")) > 1) then
if (safe_upgrade_confirm_remaining and safe_upgrade_confirm_remaining > 1) then
mesh_upgrade.change_state(mesh_upgrade.upgrade_states.CONFIRMATION_PENDING)
elseif utils.file_exists(mesh_upgrade.get_fw_path()) == false then
mesh_upgrade.report_error(mesh_upgrade.errors.FW_FILE_NOT_FOUND)
Expand All @@ -510,15 +524,16 @@ function mesh_upgrade.get_node_status()
(utils.uptime_s() - mesh_upgrade.safeupgrade_start_mark) > 0 and
mesh_upgrade.su_start_time_out -
(utils.uptime_s() - mesh_upgrade.safeupgrade_start_mark) or -1)
upgrade_data.confirm_remining = tonumber(utils.unsafe_shell("safe-upgrade confirm-remaining"))
upgrade_data.confirm_remining = safe_upgrade_confirm_remaining
return upgrade_data
end

function mesh_upgrade.start_safe_upgrade(su_start_delay, su_confirm_timeout)
mesh_upgrade.su_start_time_out = su_start_delay or mesh_upgrade.su_start_time_out
mesh_upgrade.su_confirm_timeout = su_confirm_timeout or mesh_upgrade.su_confirm_timeout

if mesh_upgrade.state() == mesh_upgrade.upgrade_states.READY_FOR_UPGRADE then
if mesh_upgrade.state() == mesh_upgrade.upgrade_states.READY_FOR_UPGRADE and
mesh_upgrade.check_safeupgrade_is_working() then
if utils.file_exists(mesh_upgrade.get_fw_path()) then

-- veryfy the image before starting
Expand Down
6 changes: 6 additions & 0 deletions packages/lime-mesh-upgrade/tests/test_lime-mesh-upgrade.lua
Original file line number Diff line number Diff line change
Expand Up @@ -57,6 +57,8 @@ stub(utils, 'unsafe_shell', function(command)

end)



local utils = require "lime.utils"
local lime_mesh_upgrade = {}
local test_utils = require "tests.utils"
Expand Down Expand Up @@ -470,6 +472,10 @@ describe('LiMe mesh upgrade', function()
end)
lime_mesh_upgrade = require 'lime-mesh-upgrade'

stub(lime_mesh_upgrade, 'check_safeupgrade_is_working', function(command)
return true
end)

uci = test_utils.setup_test_uci()
uci:set('mesh-upgrade', 'main', "mesh-upgrade")
uci:set('mesh-upgrade', 'main', "upgrade_state", "DEFAULT")
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,10 @@ describe('general rpc testing', function()
return boardname
end)
lime_mesh_upgrade = require 'lime-mesh-upgrade'
stub(lime_mesh_upgrade, 'check_safeupgrade_is_working', function(command)
return true
end)


snapshot = assert:snapshot()
uci:set('mesh-upgrade', 'main', "mesh-upgrade")
Expand Down

0 comments on commit 32b40a1

Please sign in to comment.