-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathKernelUpgrade.lua
More file actions
99 lines (71 loc) · 2.1 KB
/
KernelUpgrade.lua
File metadata and controls
99 lines (71 loc) · 2.1 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
--[[
Subclass of SetupFirmareUpgrade.UpgradeUBI to only update the kernel volume
--]]
local assert, error, pairs, pcall, tonumber, type, string = assert, error, pairs, pcall, tonumber, type, string
local oo = require("loop.simple")
local io = require("io")
local Framework = require("jive.ui.Framework")
local Task = require("jive.ui.Task")
local UpgradeUBI = require("applets.SetupFirmwareUpgrade.UpgradeUBI")
local debug = require("jive.utils.debug")
local jnt = jnt
local appletManager = appletManager
module(..., oo.class)
oo.class(_M, UpgradeUBI)
function start(self, url, md5, callback)
self._url = url
self._md5 = md5
self._callback = callback
self:parseMtd()
return Task:pcall(_upgrade, self)
end
function _upgrade(self)
self._callback(false, "UPDATE_DOWNLOAD", "")
-- parse the board revision
local t, err = self:parseCpuInfo()
if not t then
log:warn("parseCpuInfo failed")
return nil, err
end
-- remove any failed upgrades
self:rmvol("kernel_upg")
-- wait for udev
self:udevtrigger()
-- write new volume contents
self:download()
self._callback(false, "UPDATE_VERIFY")
-- check the correct ubi volumes exist
local oldvol = self:parseUbi()
assert(oldvol.kernel_upg)
-- verify new volumes
self:parseMtd()
self.verifyBytes = 0
self.verifySize = self._size["kernel_upg"]
-- verify md5 in zip with one passed by caller and validate volume
local checksum = {}
for md5, file in string.gmatch(self._checksum, "(%x+)%s+([^%s]+)") do
checksum[file] = md5
end
assert(self._md5 == checksum[self._file["kernel_upg"]])
self:checksum("kernel_upg")
-- remove old image
self:rmvol("kernel_bak")
-- automically rename volumes
self:renamevol({
["kernel"] = "kernel_bak",
["kernel_upg"] = "kernel",
})
-- check the volume rename worked
local newvol = self:parseUbi()
assert(newvol.kernel)
assert(newvol.kernel ~= oldvol.kernel)
-- reboot
self._callback(true, "UPDATE_REBOOT")
-- two second delay
local t = Framework:getTicks()
while (t + 2000) > Framework:getTicks() do
Task:yield(true)
end
appletManager:callService("reboot")
return true
end