require ("swupdate")
function flash_ext_lua(image)
local part_erase_cmd, part_write_cmd, err
part_erase_cmd = string.format("flash_erase %s 0 0", image.device)
part_write_cmd = string.format("nandwrite -p %s /tmp/%s", image.device, image.filename)
swupdate.info("handler: '%s' image: '%s' device: '%s'", image.type, image.filename, image.device)
swupdate.info("cmd erase: '%s'", part_erase_cmd)
swupdate.info("cmd write: '%s'", part_write_cmd)
err = os.execute(part_erase_cmd)
if not err then
swupdate.error(string.format("Error: %s return %s!", part_erase_cmd, tostring(err)))
return 1
end
err = os.execute(part_write_cmd)
if not err then
swupdate.error(string.format("Error: %s return %s!", part_write_cmd, tostring(err)))
return 1
end
os.execute("sync")
return 0
end
swupdate.register_handler("flash_ext", flash_ext_lua, swupdate.HANDLER_MASK.IMAGE_HANDLER)