summaryrefslogtreecommitdiff
path: root/utils/hwstub/tools/lua/hwlib.lua
diff options
context:
space:
mode:
Diffstat (limited to 'utils/hwstub/tools/lua/hwlib.lua')
-rw-r--r--utils/hwstub/tools/lua/hwlib.lua27
1 files changed, 27 insertions, 0 deletions
diff --git a/utils/hwstub/tools/lua/hwlib.lua b/utils/hwstub/tools/lua/hwlib.lua
new file mode 100644
index 0000000000..5bbd1e2668
--- /dev/null
+++ b/utils/hwstub/tools/lua/hwlib.lua
@@ -0,0 +1,27 @@
1HWLIB = {}
2
3local h = HELP:create_topic("HWLIB")
4h:add("This table contains helper functions for use inside hwstub_shell")
5
6local hh = h:create_topic("load_blob")
7hh:add("load_blob(filename, address) -- this function loads raw binary blob from the file filename")
8hh:add(" at specified address in memory. No cache coherency is")
9hh:add(" guaranteed")
10
11hh = h:create_topic("printf")
12hh:add("printf(s,...) -- this function is simple wrapper around string.format to emulate")
13hh:add(" C printf() function")
14
15function HWLIB.load_blob(filename, address)
16 local f = assert(io.open(filename, "rb"))
17 local bytes = f:read("*all")
18 for b in string.gmatch(bytes, ".") do
19 DEV.write8(address, string.byte(b))
20 address = address + 1
21 end
22 io.close(f)
23end
24
25function HWLIB.printf(s,...)
26 return io.write(s:format(...))
27end