We romfs now bois

This commit is contained in:
Jane Roxanne 2020-03-09 21:42:47 -05:00
parent 90f1537fa4
commit a3f93518cc
10 changed files with 53 additions and 23 deletions

View File

@ -1,11 +1,16 @@
local function foxfs_getnodes(prox, sec) local function foxfs_getnodes(prox, sec)
[]
end end
local function foxfs_readnode(prox, sec) local function foxfs_readnode(prox, sec)
local dat = prox.readSector(sec)
local node = {pointers={}}
local size
node.size, node.namesize, node.mode, node.user, node.group, node.pointers[1], node.pointers[2], node.pointers[3], node.pointers[4], node.pointers[5], node.pointers[6], node.pointers[7], node.pointers[8], node.pointers[9], node.sip, node.dip, node.tip, size = string.unpack("<i3i1i2i2i2i3i3i3i3i3i3i3i3i3i3i3i3", sec)
node.name = dat:sub(size+1, size+node.namesize)
return node
end end
local function foxfs_update(prox, sec, data) local function foxfs_update(prox, sec, data)
end end

View File

@ -13,6 +13,7 @@ os.execute("mkdir -p pkg/bios")
status("Building EEPROM...") status("Building EEPROM...")
os.execute("luacomp src/loader.lua -O pkg/bios/managed.bios") os.execute("luacomp src/loader.lua -O pkg/bios/managed.bios")
os.execute("luacomp src/zy-neo/zinit.lua -O debug.lua")
if (os.execute("[[ $(stat --printf=%s pkg/bios/managed.bios) > 4096 ]]")) then if (os.execute("[[ $(stat --printf=%s pkg/bios/managed.bios) > 4096 ]]")) then
io.stderr:write("WARNING: BIOS is over 4KiB!\n") io.stderr:write("WARNING: BIOS is over 4KiB!\n")
end end

View File

@ -1,2 +1,2 @@
--#include "src/lzss.lua" --#include "src/lzss.lua"
return load(lzss_decompress($[[luacomp src/zy-neo/zinit.lua -mluamin 2>/dev/null | sed "s/\]\]/]\ ]/g" | lua5.3 utils/makezbios.lua ]]), "=bios.lua")(lzss_decompress) return assert(load(lzss_decompress($[[luacomp src/zy-neo/zinit.lua 2>/dev/null | sed "s/\]\]/]\ ]/g" | lua5.3 utils/makezbios.lua ]]), "=bios.lua"))(lzss_decompress)

View File

@ -1 +1,11 @@
local function lzss_decompress(a)local b,c,d,e,f,g,h,i=1,'',''while b<=#a do e=c.byte(a,b)b=b+1;for j=0,7 do h=c.sub;i=h(a,b,b)if e>>j&1<1 and b<#a then g=c.unpack('>I2',a,b)f=1+g>>4;i=h(d,f,f+g&15+2)b=b+1 end;b=b+1;c=c..i;d=h(d..i,-4^6)end end;return c end 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

View File

@ -19,7 +19,9 @@ local cfg = component.proxy(component.list("eeprom")()).getData()
local baddr = cfg:sub(1, 36) local baddr = cfg:sub(1, 36)
local bootfs = component.proxy(baddr) local bootfs = component.proxy(baddr)
local romfs_file = component.invoke(baddr, "open", ".zy2/bootimage.romfs") assert(bootfs.exists(".zy2/image.romfs"), "No boot image!")
local romfs_file = assert(bootfs.open(".zy2/image.romfs", "rb"))
local romfs_dev = romfs.read(function(a) local romfs_dev = romfs.read(function(a)
return bootfs.read(romfs_file, a) return bootfs.read(romfs_file, a)
@ -39,8 +41,7 @@ end
function bfs.getcfg() function bfs.getcfg()
local h = assert(bootfs.open(".zy2/cfg.lua", "r")) local h = assert(bootfs.open(".zy2/cfg.lua", "r"))
readfile(bootfs, h) return readfile(bootfs, h)
return
end end
bfs.addr = baddr bfs.addr = baddr

View File

@ -2,28 +2,38 @@ local romfs = {}
local arc = {} local arc = {}
local function readint(r, n) local function readint(r, n)
return string.unpack("<i"..n, r(n)) local str = assert(r(n), "Unexpected EOF!")
return string.unpack("<i"..n, str)
end end
function romfs.read(read, seek, close) function romfs.read(read, seek, close)
if read(7) ~= "romfs\1\0" then error("Invalid romfs") end local sig = read(7)
utils.debug_log("SIGNATURE", sig, #sig)
assert(sig, "Read error!")
if sig ~= "romfs\1\0" then error(string.format("Invalid romfs (%.14x != %.14x)", string.unpack("i7", sig), string.unpack("i7", "romfs\1\0"))) end
local tbl = {} local tbl = {}
local lname local lname
while lname ~= "TRAILER!!!" do while lname ~= "TRAILER!!!" do
local name = read(readint(read, 1)) local nz = read(1):byte()
local name = read(nz)
local fsize = readint(read, 2) local fsize = readint(read, 2)
local exec = read(1) local exec = read(1)
tbl[#tbl+1] = {name = name, size = size, exec = exec == "x", pos = seek(0)} tbl[#tbl+1] = {name = name, size = fsize, exec = exec == "x", pos = seek(0)}
utils.debug_log(name, fsize, exec)
seek(fsize) seek(fsize)
lname = name
end end
tbl[#tbl] = nil tbl[#tbl] = nil
utils.debug_log("ROMFS loaded!")
return setmetatable({tbl=tbl, read=read,seek=seek, close=close}, {__index=arc}) return setmetatable({tbl=tbl, read=read,seek=seek, close=close}, {__index=arc})
end end
function arc:fetch(path) function arc:fetch(path)
for i=1, #self.tbl do for i=1, #self.tbl do
if self.tbl[i].name == path then if self.tbl[i].name == path then
utils.debug_log("DEBUG", self.tbl[i].pos, self.tbl[i].size)
self.seek(self.tbl[i].pos-self.seek(0)) self.seek(self.tbl[i].pos-self.seek(0))
utils.debug_log("DEBUG2", self.seek(0))
return self.read(self.tbl[i].size) return self.read(self.tbl[i].size)
end end
end end

View File

@ -1,5 +1,3 @@
builtins.utils = function()
local utils = {} local utils = {}
function utils.debug_log(...) function utils.debug_log(...)
@ -59,5 +57,5 @@ function utils.deepcopy(src, dest)
end end
return dest return dest
end end
return utils utils.debug_log("Zorya NEO Started!")
end builtins.utils = function() return utils end

View File

@ -23,9 +23,11 @@ local function th_a(func)
end end
local function load_lua(src, ...) local function load_lua(src, ...)
if (src:sub(1, 4) == "\27ZLSS") then log(#src)
if (src:sub(1, 4) == "\27ZLS") then
src = lzss_decompress(src:sub(5)) src = lzss_decompress(src:sub(5))
end end
log("DECOMPRESS", src)
return load(src, ...) return load(src, ...)
end end
@ -89,6 +91,7 @@ th_a(function()
local zy = krequire("zorya") local zy = krequire("zorya")
zy.add_mod_search(function(mod) zy.add_mod_search(function(mod)
if (bfs.exists(".zy2/mods/"..mod..".zy2m")) then if (bfs.exists(".zy2/mods/"..mod..".zy2m")) then
utils.debug_log(mod, ".zy2m")
return load_lua(bfs.getfile(".zy2/mods/"..mod..".zy2m"), "=.zy2/mods/"..mod..".zy2m")() return load_lua(bfs.getfile(".zy2/mods/"..mod..".zy2m"), "=.zy2/mods/"..mod..".zy2m")()
elseif (bfs.exists(".zy2/mods/"..mod.."/init.zy2m")) then elseif (bfs.exists(".zy2/mods/"..mod.."/init.zy2m")) then
return load_lua(bfs.getfile(".zy2/mods/"..mod.."/init.zy2m"), "=.zy2/mods/"..mod.."/init.zy2m")() return load_lua(bfs.getfile(".zy2/mods/"..mod.."/init.zy2m"), "=.zy2/mods/"..mod.."/init.zy2m")()
@ -106,7 +109,7 @@ th_a(function()
return load_lua(bfs.getfile(".zy2/lib/"..mod.."/init.zy2l"), "=.zy2/lib/"..mod.."/init.zy2l") return load_lua(bfs.getfile(".zy2/lib/"..mod.."/init.zy2l"), "=.zy2/lib/"..mod.."/init.zy2l")
end end
end) end)
local zycfg = bfs.getfile(".zy2/cfg.lua") local zycfg = bfs.getcfg()
-- Config loaded, now we can do our shit. -- Config loaded, now we can do our shit.
local env = { local env = {
zorya = zy, zorya = zy,

View File

@ -118,9 +118,7 @@ end
local function mkstr(d) local function mkstr(d)
local dat = "\"" local dat = "\""
for i=1, #f do for i=1, #f do
if (d:byte(i) == 0) then if (d:sub(i,i) == "\\") then
dat = dat .. "\0"
elseif (d:sub(i,i) == "\\") then
dat = dat .. ("\\\\") dat = dat .. ("\\\\")
elseif (d:sub(i,i) == "\"") then elseif (d:sub(i,i) == "\"") then
dat = dat .. ("\\\"") dat = dat .. ("\\\"")
@ -128,6 +126,8 @@ local function mkstr(d)
dat = dat .. ("\\n") dat = dat .. ("\\n")
elseif (d:sub(i,i) == "\r") then elseif (d:sub(i,i) == "\r") then
dat = dat .. ("\\r") dat = dat .. ("\\r")
elseif (d:sub(i,i) == "\t") then
dat = dat .. ("\\t")
else else
dat = dat .. (d:sub(i,i)) dat = dat .. (d:sub(i,i))
end end

View File

@ -111,12 +111,12 @@ function writeFile(path, data)
--fs.close(hand) --fs.close(hand)
fs.write(romfs, string.char(#path)..path) fs.write(romfs, string.char(#path)..path)
local ext = path:sub(#path-2) local ext = path:sub(#path-2)
fs.write(romfs, string.pack("<i2", #data))
if (ext == "lua" or ext == "z2l" or ext == "z2y") then if (ext == "lua" or ext == "z2l" or ext == "z2y") then
fs.write(romfs, "x") fs.write(romfs, "x")
else else
fs.write(romfs, "-") fs.write(romfs, "-")
end end
fs.write(romfs, string.pack("<i2", #data))
fs.write(romfs, data) fs.write(romfs, data)
end end
@ -162,11 +162,13 @@ eeprom.setLabel("Zorya NEO BIOS v2.0")
setBar(100) setBar(100)
setStatus("Rebooting in 5 seconds...") setStatus("Rebooting in 5 seconds...")
if not fs.exists(".zy2/cfg.lua") then if not fs.exists(".zy2/cfg.lua") then
writeFile(fs, ".zy2/cfg.lua", string.format([[local menu = loadmod("menu_classic") local hand = fs.open(".zy2/cfg.lua", "w")
fs.write(hand, string.format([[local menu = loadmod("menu_classic")
menu.add("OpenOS on %s", function() menu.add("OpenOS on %s", function()
return loadmod("loader_openos")("%s") return loadmod("loader_openos")("%s")
end) end)
menu.draw()]], fsaddr:sub(1, 3), fsaddr)) menu.draw()]], fsaddr:sub(1, 3), fsaddr))
fs.close(hand)
end end
computer = computer or require("computer") computer = computer or require("computer")
local stime = computer.uptime() local stime = computer.uptime()