From 0e7f55624a869aced49643a8de80809d96c36733 Mon Sep 17 00:00:00 2001 From: Jane Roxanne Date: Sun, 29 Mar 2020 11:52:53 -0500 Subject: [PATCH] Because someone complained about boot speed. --- mods/menu_classic/init.lua | 46 ++++++++------ src/zy-neo/builtins/init_initramfs/init.lua | 67 +++++++++++++++++++++ utils/mkselfextract.lua | 3 +- utils/selfextract.lua | 3 +- 4 files changed, 97 insertions(+), 22 deletions(-) create mode 100644 src/zy-neo/builtins/init_initramfs/init.lua diff --git a/mods/menu_classic/init.lua b/mods/menu_classic/init.lua index b98affa..3b16c15 100644 --- a/mods/menu_classic/init.lua +++ b/mods/menu_classic/init.lua @@ -37,25 +37,6 @@ function menu.draw() local sel = 1 local function redraw() local w, h = gpu.getViewport() - local cls = function()gpu.fill(1,1,w,h," ")end - gpu.setBackground(bg) - gpu.setForeground(fg) - cls() - --Draw some things - local namestr = _BIOS .. " " .. string.format("%.1f.%d %s", _ZVER, _ZPAT, _ZGIT) - gpu.set((w/2)-(#namestr/2), 1, namestr) - gpu.set(1, 2, border_chars[1]) - gpu.set(2, 2, border_chars[2]:rep(w-2)) - gpu.set(w, 2, border_chars[3]) - for i=1, h-6 do - gpu.set(1, i+2, border_chars[4]) - gpu.set(w, i+2, border_chars[4]) - end - gpu.set(1, h-3, border_chars[5]) - gpu.set(2, h-3, border_chars[2]:rep(w-2)) - gpu.set(w, h-3, border_chars[6]) - gpu.set(1, h-1, "Use ↑ and ↓ keys to select which entry is highlighted.") - gpu.set(1, h, "Use ENTER to boot the selected entry.") gpu.setBackground(bg) gpu.setForeground(fg) gpu.fill(1, h-2, w, 1, " ") @@ -84,7 +65,30 @@ function menu.draw() gpu.set(2, i+2, short) end end - redraw() + local function full_redraw() + local w, h = gpu.getViewport() + local cls = function()gpu.fill(1,1,w,h," ")end + gpu.setBackground(bg) + gpu.setForeground(fg) + cls() + --Draw some things + local namestr = _BIOS .. " " .. string.format("%.1f.%d %s", _ZVER, _ZPAT, _ZGIT) + gpu.set((w/2)-(#namestr/2), 1, namestr) + gpu.set(1, 2, border_chars[1]) + gpu.set(2, 2, border_chars[2]:rep(w-2)) + gpu.set(w, 2, border_chars[3]) + for i=1, h-6 do + gpu.set(1, i+2, border_chars[4]) + gpu.set(w, i+2, border_chars[4]) + end + gpu.set(1, h-3, border_chars[5]) + gpu.set(2, h-3, border_chars[2]:rep(w-2)) + gpu.set(w, h-3, border_chars[6]) + gpu.set(1, h-1, "Use ↑ and ↓ keys to select which entry is highlighted.") + gpu.set(1, h, "Use ENTER to boot the selected entry.") + redraw() + end + full_redraw() sel = 1 while true do local sig, _, key, code = computer.pullSignal(0.01) @@ -110,10 +114,12 @@ function menu.draw() gpu.setBackground(0) gpu.setForeground(0xFFFFFF) entries[sel][2]() + full_redraw() end end if (((computer.uptime()-stime) >= timeout) and autosel) then entries[sel][2]() + full_redraw() end redraw() end diff --git a/src/zy-neo/builtins/init_initramfs/init.lua b/src/zy-neo/builtins/init_initramfs/init.lua new file mode 100644 index 0000000..f80fdc4 --- /dev/null +++ b/src/zy-neo/builtins/init_initramfs/init.lua @@ -0,0 +1,67 @@ +_ZLOADER = "initramfs" +local readfile=function(f,h) + local b="" + local d,r=f.read(h,math.huge) + if not d and r then error(r)end + b=d + while d do + local d,r=f.read(h,math.huge) + b=b..(d or "") + if(not d)then break end + end + f.close(h) + return b +end + +local bfs = {} + +local cfg = component.proxy(component.list("eeprom")()).getData() + +local baddr = cfg:sub(1, 36) +local bootfs = component.proxy(baddr) + +assert(bootfs.exists(".zy2/image.tsar"), "No boot image!") + +local romfs_file = assert(bootfs.open(".zy2/image.tsar", "rb")) +local rfs = readfile(bootfs, romfs_file) + +--[[local romfs_dev = tsar.read(function(a) + local c = "" + local d + while a > 0 do + d = bootfs.read(romfs_file, a) + a = a - #d + c = c .. d + end + return c +end, function(a) + return bootfs.seek(romfs_file, "cur", a) +end, function() + return bootfs.close(romfs_file) +end)]] +local h = 1 +local romfs_dev = tsar.read(function(a) + local d = rfs:sub(h, h+a-1) + h = h+a + return d +end, function(a) + h = h + a + return h +end, function() + rfs = nil +end) + +function bfs.getfile(path) + return romfs_dev:fetch(path) +end + +function bfs.exists(path) + return romfs_dev:exists(path) +end + +function bfs.getcfg() + local h = assert(bootfs.open(".zy2/cfg.lua", "r")) + return readfile(bootfs, h) +end + +bfs.addr = baddr \ No newline at end of file diff --git a/utils/mkselfextract.lua b/utils/mkselfextract.lua index 0b4d1c8..3d6a14b 100644 --- a/utils/mkselfextract.lua +++ b/utils/mkselfextract.lua @@ -78,7 +78,8 @@ end local tmp = os.tmpname() local h = io.popen("luacomp ../utils/selfextract.lua -O"..tmp, "w") -h:write(mkstr(lzss_compress(f))) +--h:write(mkstr(lzss_compress(f))) +h:write(mkstr(f)) h:close() local f = io.open(tmp, "rb") io.stdout:write(f:read("*a")) diff --git a/utils/selfextract.lua b/utils/selfextract.lua index 0a60787..05cf3c2 100644 --- a/utils/selfextract.lua +++ b/utils/selfextract.lua @@ -42,7 +42,8 @@ function lzss_decompress(input) return table.concat(output) end --print("Decompressing CPIO...") -local code = lzss_decompress(@[{io.stdin:read("*a")}]) +--local code = lzss_decompress(@--[{io.stdin:read("*a")}]) +local code = @[{io.stdin:read("*a")}] local dat = code local tbl = {}