52 lines
1.2 KiB
Lua
52 lines
1.2 KiB
Lua
local function lzss_decompress(a)local b,c,d,e,j,i,h,g=1,'',''while b<=#a do
|
|
e=c.byte(a,b)b=b+1
|
|
for k=0,7 do h=c.sub
|
|
g=h(a,b,b)if e>>k&1<1 and b<#a then
|
|
i=c.unpack('>I2',a,b)j=1+(i>>4)g=h(d,j,j+(i&15)+2)b=b+1
|
|
end
|
|
b=b+1
|
|
c=c..g
|
|
d=h(d..g,-4^6)end
|
|
end
|
|
return c end
|
|
local function boot_velx(addr, path)
|
|
local fs = component.proxy(addr)
|
|
local h = fs.open(path)
|
|
local magic, fver, comp, lver, osid, psize = string.unpack("<c5BBBBxxxxI3xxxxxxxxxx", fs.read(h, 13))
|
|
if (magic ~= "\27VelX" or fver ~= 1 or osid ~= 127) then
|
|
return
|
|
end
|
|
local rdat = psize
|
|
local dat = ""
|
|
local buf = ""
|
|
repeat
|
|
buf = fs.read(h, rdat)
|
|
if (buf) then
|
|
dat = dat .. buf
|
|
end
|
|
rdat = psize - #dat
|
|
until rdat == 0 or not buf or buf == ""
|
|
if (comp == 1) then
|
|
buf = lzss_decompress(buf)
|
|
end
|
|
assert(load(buf, "="..path))()
|
|
end
|
|
|
|
local eeprom = component.proxy(component.list("eeprom")())
|
|
local config = eeprom.getData()
|
|
local addr, path = config:match("^(.+);(.+)$")
|
|
if not addr then
|
|
addr = config
|
|
path = "boot.velx"
|
|
else
|
|
return boot_velx(addr, path)
|
|
end
|
|
|
|
if not component.invoke(addr, "exists", path) then
|
|
for d in component.list("filesystem") do
|
|
if (component.invoke(d, "exists", "boot.velx")) then
|
|
eeprom.setData(d..";boot.velx")
|
|
boot_velx(d, "boot.velx")
|
|
end
|
|
end
|
|
end |