Implement eeprom component

This commit is contained in:
Łukasz Magiera 2016-01-06 21:32:53 +01:00
parent e6f07e6cb6
commit 7d5a223f85
6 changed files with 159 additions and 9 deletions

View File

@ -3,6 +3,8 @@
extern char lua_boot[]; extern char lua_boot[];
extern char lua_component[]; extern char lua_component[];
extern char lua_computer[]; extern char lua_computer[];
extern char lua_eepromDefault[];
extern char lua_eeprom[];
extern char lua_init[]; extern char lua_init[];
extern char lua_sandbox[]; extern char lua_sandbox[];
extern char lua_textgpu[]; extern char lua_textgpu[];

View File

@ -11,6 +11,8 @@ void setup_modules(lua_State *L) {
pushstuple(L, "boot", lua_boot); pushstuple(L, "boot", lua_boot);
pushstuple(L, "component", lua_component); pushstuple(L, "component", lua_component);
pushstuple(L, "computer", lua_computer); pushstuple(L, "computer", lua_computer);
pushstuple(L, "eeprom", lua_eeprom);
pushstuple(L, "eepromDefault", lua_eepromDefault);
pushstuple(L, "sandbox", lua_sandbox); pushstuple(L, "sandbox", lua_sandbox);
pushstuple(L, "textgpu", lua_textgpu); pushstuple(L, "textgpu", lua_textgpu);
pushstuple(L, "color", lua_util_color); pushstuple(L, "color", lua_util_color);

View File

@ -1,15 +1,29 @@
local boot = {} local boot = {}
function boot.boot() function boot.boot()
local gpu = modules.component.api.proxy(modules.component.api.list("gpu", true)()) local gpu = modules.component.api.proxy(modules.component.api.list("gpu", true)())
local w, h = gpu.getResolution() local w, h = gpu.getResolution()
print("r= " .. tostring(w) .. " " .. tostring(h)) print("r= " .. tostring(w) .. " " .. tostring(h))
gpu.fill(0, 0, w, h, " ") gpu.fill(0, 0, w, h, " ")
gpu.set(10, 5, "HHHHHHHHHHHHH") gpu.set(10, 5, "HHHHHHHHHHHHH")
print("LuPI L2 INIT") gpu.set(11, 11, "VVVVVVVVVVVVVVVVV", true)
print("FIXME: boot stub") print("LuPI L2 INIT")
native.sleep(1000000) print("FIXME: boot stub")
error("Unable to boot") native.sleep(1000000)
local code = modules.component.api.invoke(modules.component.api.list("eeprom", true)(), "get")
if not code then
print("No bootcode")
error("No bootcode")
end
---PASS SANDBOX!!!!!!
local f, reason = load(code, "=BIOS")
if not f then
print(reason)
else
f()
print("System quit, Panic")
end
end end
return boot return boot

68
src/lua/core/eeprom.lua Normal file
View File

@ -0,0 +1,68 @@
local eeprom = {}
local default = moduleCode["eepromDefault"]
local size = 4092
local dataSize = 256
function eeprom.register()
local component = {}
function component.get()
local h = io.open("usereeprom.lua", "r")
if h then
local data = h:read("*a")
h:close()
return data
else
return default
end
end
function component.set(data)
checkArg(1, data, "string")
data = data:sub(1, size)
local h = io.open("usereeprom.lua", "w")
if not h then
error("Critical: Cannot open EERPOM file")
end
h:write(data)
h:close()
end
function component.getLabel()
return "LUA BIOS"
end
function component.setLabel()
return nil, "Cannot set label"
end
function component.getSize()
return size
end
function component.getData()
local h = io.open("usereepromdata.lua", "r")
if h then
local data = h:read("*a")
h:close()
return data
else
return default
end
end
function component.setData(data)
checkArg(1, data, "string")
data = data:sub(1, dataSize)
local h = io.open("usereepromdata.lua", "w")
if not h then
error("Critical: Cannot open EERPOM file")
end
h:write(data)
h:close()
end
--FIXME: Implement
function component.getChecksum()
error("Method stub")
end
function component.makeReadonly()
return false, "Method stub"
end
modules.component.api.register(nil, "eeprom", component)
end
return eeprom

View File

@ -0,0 +1,61 @@
local component_invoke = component.invoke
function boot_invoke(address, method, ...)
local result = table.pack(pcall(component_invoke, address, method, ...))
if not result[1] then
return nil, result[2]
else
return table.unpack(result, 2, result.n)
end
end
-- backwards compatibility, may remove later
local eeprom = component.list("eeprom")()
computer.getBootAddress = function()
return boot_invoke(eeprom, "getData")
end
computer.setBootAddress = function(address)
return boot_invoke(eeprom, "setData", address)
end
do
local screen = component.list("screen")()
local gpu = component.list("gpu")()
if gpu and screen then
boot_invoke(gpu, "bind", screen)
end
end
local function tryLoadFrom(address)
local handle, reason = boot_invoke(address, "open", "/init.lua")
if not handle then
return nil, reason
end
local buffer = ""
repeat
local data, reason = boot_invoke(address, "read", handle, math.huge)
if not data and reason then
return nil, reason
end
buffer = buffer .. (data or "")
until not data
boot_invoke(address, "close", handle)
return load(buffer, "=init")
end
local init, reason
if computer.getBootAddress() then
init, reason = tryLoadFrom(computer.getBootAddress())
end
if not init then
computer.setBootAddress()
for address in component.list("filesystem") do
init, reason = tryLoadFrom(address)
if init then
computer.setBootAddress(address)
break
end
end
end
if not init then
error("no bootable medium found" .. (reason and (": " .. tostring(reason)) or ""), 0)
end
computer.beep(1000, 0.2)
init()

View File

@ -41,6 +41,7 @@ loadModule("color")
loadModule("component") loadModule("component")
loadModule("computer") loadModule("computer")
loadModule("eeprom")
loadModule("textgpu") loadModule("textgpu")
loadModule("sandbox") loadModule("sandbox")
@ -50,5 +51,7 @@ loadModule("boot")
modules.component.prepare() modules.component.prepare()
modules.computer.prepare() modules.computer.prepare()
modules.eeprom.register()
modules.textgpu.start() modules.textgpu.start()
modules.boot.boot() modules.boot.boot()