new sysupgrade fixes part 2
This commit is contained in:
parent
5067e2d185
commit
8f5d0d6ff5
3 changed files with 50 additions and 15 deletions
|
@ -20,7 +20,7 @@ local util = require "luci.util"
|
|||
local ltn12 = require "luci.ltn12"
|
||||
local posix = require "posix"
|
||||
|
||||
local type, assert, error = type, assert, error
|
||||
local type, assert, error, ipairs = type, assert, error, ipairs
|
||||
|
||||
module "luci.sys.mtdow"
|
||||
|
||||
|
@ -63,7 +63,8 @@ CFEWriter.blocks = {
|
|||
image = {
|
||||
magic = {"4844", "5735"},
|
||||
device = "linux",
|
||||
write = WRITE_IMAGE
|
||||
write = WRITE_IMAGE,
|
||||
system = true
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -72,7 +73,8 @@ CommonWriter = util.class(Writer)
|
|||
CommonWriter.blocks = {
|
||||
image = {
|
||||
device = "linux",
|
||||
write = WRITE_COMBINED
|
||||
write = WRITE_COMBINED,
|
||||
system = true
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -85,7 +87,8 @@ RedWriter.blocks = {
|
|||
},
|
||||
rootfs = {
|
||||
device = "rootfs",
|
||||
write = WRITE_COMBINED
|
||||
write = WRITE_COMBINED,
|
||||
system = true
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -117,10 +120,11 @@ end
|
|||
|
||||
|
||||
|
||||
Writer.MTD = "/sbin/mtd"
|
||||
Writer.SAFEMTD = "/tmp/mtd"
|
||||
Writer.COPY = {"/sbin/mtd"}
|
||||
Writer.MTD = "/tmp/mtd"
|
||||
Writer.IMAGEFIFO = "/tmp/mtdimage.fifo"
|
||||
|
||||
|
||||
function Writer.write_block(self, name, imagestream, appendfile)
|
||||
assert(self.blocks[name], ERROR_NOTFOUND)
|
||||
local block = self.blocks[name]
|
||||
|
@ -132,6 +136,8 @@ function Writer.write_block(self, name, imagestream, appendfile)
|
|||
end
|
||||
assert(imagestream, ERROR_INVMAGIC)
|
||||
|
||||
self:_prepare_env()
|
||||
|
||||
if appendfile then
|
||||
if block.write == WRITE_COMBINED then
|
||||
return (self:_write_combined(device, imagestream, appendfile) == 0)
|
||||
|
@ -145,6 +151,21 @@ function Writer.write_block(self, name, imagestream, appendfile)
|
|||
end
|
||||
end
|
||||
|
||||
function Writer._prepare_env(self)
|
||||
if self._prepared then
|
||||
return
|
||||
end
|
||||
|
||||
for k, app in ipairs(self.COPY) do
|
||||
local target = "/tmp/"..fs.basename(app)
|
||||
fs.unlink(target)
|
||||
fs.copy(app, target)
|
||||
fs.chmod(target, "rwx------")
|
||||
end
|
||||
|
||||
self._prepared = true
|
||||
end
|
||||
|
||||
function Writer._check_magic(self, imagestream, magic)
|
||||
magic = type(magic) == "table" and magic or {magic}
|
||||
|
||||
|
|
|
@ -188,6 +188,8 @@ function action_upgrade()
|
|||
local uploads = {}
|
||||
local flash = {}
|
||||
|
||||
writer.COPY[#writer.COPY + 1] = "/sbin/reboot"
|
||||
|
||||
local ret
|
||||
local filepat = "/tmp/mtdblock.%s"
|
||||
local kfile = "/tmp/mtdappend.tgz"
|
||||
|
@ -195,8 +197,7 @@ function action_upgrade()
|
|||
local keep_avail = false
|
||||
if blocks then
|
||||
for k, block in pairs(blocks) do
|
||||
if block.write == mtdow.WRITE_COMBINED
|
||||
or block.write == mtdow.WRITE_EMULATED then
|
||||
if block.write ~= mtdow.WRITE_IMAGE then
|
||||
keep_avail = true
|
||||
end
|
||||
end
|
||||
|
@ -242,10 +243,18 @@ function action_upgrade()
|
|||
end
|
||||
|
||||
for name, file in pairs(uploads) do
|
||||
flash[name] = function()
|
||||
local e = {name=name, func=function()
|
||||
local imgstream = ltn12.source.file(io.open(file))
|
||||
local kf = blocks[name].write ~= mtdow.WRITE_IMAGE
|
||||
and keepcfg and _kfile()
|
||||
return pcall(writer.write_block, writer,
|
||||
name, imgstream, keepcfg and _kfile())
|
||||
name, imgstream, kf)
|
||||
end}
|
||||
|
||||
if blocks[name].system then
|
||||
flash[#flash+1] = e
|
||||
else
|
||||
table.insert(flash, 1, e)
|
||||
end
|
||||
end
|
||||
|
||||
|
@ -256,8 +265,8 @@ function action_upgrade()
|
|||
if reboot.exec then
|
||||
local pid = posix.fork()
|
||||
if pid == 0 then
|
||||
os.execute("sleep 1")
|
||||
posix.execp("reboot")
|
||||
posix.sleep(1)
|
||||
posix.exec("/tmp/reboot")
|
||||
end
|
||||
end
|
||||
end
|
||||
|
|
|
@ -38,17 +38,22 @@ $Id$
|
|||
<p><%:a_s_flash_received%></p>
|
||||
|
||||
<% reboot.exec = false
|
||||
for name, func in pairs(flash) do %>
|
||||
for i, entry in ipairs(flash) do
|
||||
local name, func = entry.name, entry.func %>
|
||||
<%:a_s_flash_inprogress%> <%=name%>...
|
||||
<%=string.rep(" ", 2048)%>
|
||||
<%=string.rep(" ", 32*1024)%>
|
||||
<%
|
||||
local stat, code = func()
|
||||
reboot.exec = reboot.exec or stat
|
||||
if stat and code then %>
|
||||
<%:a_s_flash_flashed%><br />
|
||||
<%:ok%><br />
|
||||
<% else %>
|
||||
<%:a_s_flash_flasherr%>! (<%:code%> <%=code%>)<br />
|
||||
<% end %>
|
||||
<% if reboot.exec then %>
|
||||
<br />
|
||||
<div><%:a_s_flash_flashed%></div>
|
||||
<% end %>
|
||||
<% end %>
|
||||
<% else %>
|
||||
<div class="error"><%:a_s_flash_notimplemented%></div>
|
||||
|
|
Loading…
Reference in a new issue