Zorya-NEO/src/zy-neo/builtins/init_managed/init.lua

47 lines
944 B
Lua
Raw Normal View History

2020-01-09 15:01:35 +11:00
local readfile=function(f,h)
local b=""
2020-03-07 01:16:42 +11:00
local d,r=f.read(h,math.huge)
2020-01-09 15:01:35 +11:00
if not d and r then error(r)end
b=d
while d do
2020-03-07 01:16:42 +11:00
local d,r=f.read(h,math.huge)
2020-01-09 15:01:35 +11:00
b=b..(d or "")
if(not d)then break end
end
2020-03-07 01:16:42 +11:00
f.close(h)
2020-01-09 15:01:35 +11:00
return b
end
local bfs = {}
local cfg = component.proxy(component.list("eeprom")()).getData()
local baddr = cfg:sub(1, 36)
2020-03-07 01:16:42 +11:00
local bootfs = component.proxy(baddr)
2020-03-10 13:42:47 +11:00
assert(bootfs.exists(".zy2/image.romfs"), "No boot image!")
local romfs_file = assert(bootfs.open(".zy2/image.romfs", "rb"))
2020-03-07 01:16:42 +11:00
local romfs_dev = romfs.read(function(a)
return bootfs.read(romfs_file, a)
end, function(a)
return bootfs.seek(romfs_file, "cur", a)
end, function()
return bootfs.close(romfs_file)
end)
2020-01-09 15:01:35 +11:00
function bfs.getfile(path)
2020-03-07 01:16:42 +11:00
return romfs_dev:fetch(path)
2020-01-09 15:01:35 +11:00
end
function bfs.exists(path)
2020-03-07 01:16:42 +11:00
return romfs_dev:exists(path)
2020-01-09 15:01:35 +11:00
end
2020-03-07 01:16:42 +11:00
function bfs.getcfg()
local h = assert(bootfs.open(".zy2/cfg.lua", "r"))
2020-03-10 13:42:47 +11:00
return readfile(bootfs, h)
2020-03-07 01:16:42 +11:00
end
2020-01-09 15:01:35 +11:00
bfs.addr = baddr