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

59 lines
1.1 KiB
Lua
Raw Normal View History

2020-03-20 07:50:37 +11:00
_ZLOADER = "managed"
2020-06-06 10:45:08 +10:00
--[[local readfile=function(f,h)
2020-01-09 15:01:35 +11:00
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
2020-06-06 10:45:08 +10:00
end]]
2020-01-09 15:01:35 +11:00
local bfs = {}
2020-06-06 10:45:08 +10:00
local cfg = cproxy(clist("eeprom")()).getData()
2020-01-09 15:01:35 +11:00
local baddr = cfg:sub(1, 36)
2020-06-06 10:45:08 +10:00
local bootfs = cproxy(baddr)
2020-03-07 01:16:42 +11:00
2020-03-19 08:02:05 +11:00
assert(bootfs.exists(".zy2/image.tsar"), "No boot image!")
2020-03-10 13:42:47 +11:00
2020-03-19 08:02:05 +11:00
local romfs_file = assert(bootfs.open(".zy2/image.tsar", "rb"))
2020-03-07 01:16:42 +11:00
2020-03-20 07:50:37 +11:00
local romfs_dev = tsar.read(function(a)
2020-03-12 09:19:08 +11:00
local c = ""
local d
while a > 0 do
d = bootfs.read(romfs_file, a)
a = a - #d
c = c .. d
end
return c
2020-03-07 01:16:42 +11:00
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-06-06 10:45:08 +10:00
function bfs.getstream(path)
return romfs_dev:stream(path)
end
2020-03-07 01:16:42 +11:00
function bfs.getcfg()
local h = assert(bootfs.open(".zy2/cfg.lua", "r"))
2020-06-06 10:45:08 +10:00
return utils.readfile(bootfs, h)
2020-03-07 01:16:42 +11:00
end
2020-01-09 15:01:35 +11:00
bfs.addr = baddr