added PixICE, the network bootloader firmware

This commit is contained in:
Izaya 2017-07-13 18:05:44 +10:00
parent 43f00e7669
commit 7518483d25
3 changed files with 117 additions and 49 deletions

View File

@ -1,49 +0,0 @@
for k,v in ipairs(tM) do v.open(9671) end
s("nbsrv",function() print(pcall(function()
print("[netboot] loading data")
local f,tnbd=io.open("boot:/nbsrv.csv"),{}
setmetatable(tnbd,{__index=function(t,k)
return rawget(t,k) or {}
end})
if f then
local c=f:read("*a")
f:close()
for l in c:gmatch("[^\n]+") do
local c,i = 1,""
for d in l:gmatch("[^,]+") do
if c == 1 then
i=d
tnbd[i]={}
else
tnbd[i][#tnbd[i]+1]=d
end
c=c+1
end
end
end
local d,d2="",""
local f=io.open("boot:/nbstart.lua")
if f then
d=f:read("*a")
f:close()
end
local f=io.open("boot:/nbend.lua")
if f then
d2=f:read("*a")
f:close()
end
while true do
if ev[1] == "modem_message" and ev[4] == 9671 then
print("[netboot] request from "..ev[3])
for k,v in ipairs(tnbd[ev[3]]) do
d=d..v.."\n"
end
d=d..d2
for i = 1, d:len(), 2048 do
component.invoke(ev[2],"send",ev[3],9671,d:sub(i,i+2047))
end
component.invoke(ev[2],"send",ev[3],9671,".")
end
C.yield()
end
end)) end)

59
modules/net/pxesrv.lua Normal file
View File

@ -0,0 +1,59 @@
function pxesrv(i,P,LF) -- port, image, log file
_G.pxcl = {}
local P,i,LF = P or 9671,i or "boot:/pxeimage.lua",LF or "boot:/pxetab.csv"
for k,v in ipairs(tM) do v.open(P) end
print("[netboot] loading data")
f=io.open(i)
if f then d=f:read("*a") f:close()
else error("image not found")
end
print("[netboot] server starting, port "..TS(P)..", image file "..i)
print("[netboot] loading existing data")
local f=io.open(LF)
C.yield()
if f then
local c = f:read("*a")
f:close()
for m,C,h,p in c:gmatch("(.-),(.-),(.-),(.-)\n") do
print(m.." = {"..C..", "..h..", "..p.."}")
pxcl[m]={C,h,p}
end
end
s("pxesrv",function() print(pcall(function()
while true do
if ev[1] == "modem_message" and ev[4] == P then
print("[netboot] request from "..ev[3]:sub(1,8)..":"..TS(ev[6]):sub(1,8))
if type(pxcl[ev[3]]) ~= "table" then
pxcl[ev[3]]={ev[6],ev[6]:sub(1,8),"pass"}
else
pxcl[ev[3]]={ev[6],pxcl[ev[3]][2] or ev[6]:sub(1,8),pxcl[ev[3]][3] or "pass"}
end
fd=d:gsub("HOSTNAME",pxcl[ev[3]][2])
fd=fd:gsub("PASSWORD",pxcl[ev[3]][3])
local la,fr = ev[2],ev[3]
print(fd:len())
for i = 1, fd:len(), 2048 do
component.invoke(la,"send",fr,P,fd:sub(i,i+2047))
C.yield()
end
component.invoke(la,"send",fr,P,".")
end
C.yield()
end
end)) end)
s("pxesrv logger",function() print(pcall(function()
while true do
for i = 1, 100 do
C.yield()
end
f=fopen(LF,"w")
if f then
for k,v in pairs(pxcl) do
fwrite(f,k..","..v[1]..","..v[2]..","..v[3].."\n")
end
fclose(f)
C.yield()
end
end
end)) end)
end

58
util/pixice.lua Normal file
View File

@ -0,0 +1,58 @@
--base/loadlin.lua
if pcall(require,"computer") then
print("OpenOS detected.")
print(os.getenv("_"))
local computer = require "computer"
local process = require "process"
os.execute("cp "..os.getenv("_").." /tmp/init.lua")
computer.setBootAddress(computer.tmpAddress())
computer.shutdown(true)
end
-- actual code starts here
s=""
computer.getBootAddress = computer.tmpAddress
do
local addr=nil
local OCPS,OCSD,OCI=computer.pullSignal,computer.shutdown,component.invoke
function computer.pullSignal(...)
local tA={...}
local eV={OCPS(...)}
if eV[1] == "modem_message" and eV[3] == addr and eV[4] == 9671 then
if eV[6] == "reboot" then
OCSD(true)
end
return
end
return table.unpack(eV)
end
function computer.shutdown()
OCSD(true)
end
function component.invoke(...)
tA={...}
if tA[2] == "stop" then return end
return OCI(...)
end
local m=component.proxy(component.list("modem")())
m.open(9671)
if addr then
m.send(addr,9671,computer.address())
while true do
local ev={computer.pullSignal()}
if ev[1] == "modem_message" and ev[3] == addr and ev[4] == 9671 then
if ev[6] == "." then break end
s=s..ev[6]
end
end
else
m.broadcast(9671,computer.address())
while true do
local ev={computer.pullSignal()}
if ev[1] == "modem_message" and ev[4] == 9671 then
if ev[6] == "." then break end
s=s..ev[6]
end
end
end
end
load(s)()