diff options
Diffstat (limited to 'utils/hwstub/tools/lua')
-rw-r--r-- | utils/hwstub/tools/lua/hwlib.lua | 27 | ||||
-rw-r--r-- | utils/hwstub/tools/lua/load.lua | 1 |
2 files changed, 28 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 @@ | |||
1 | HWLIB = {} | ||
2 | |||
3 | local h = HELP:create_topic("HWLIB") | ||
4 | h:add("This table contains helper functions for use inside hwstub_shell") | ||
5 | |||
6 | local hh = h:create_topic("load_blob") | ||
7 | hh:add("load_blob(filename, address) -- this function loads raw binary blob from the file filename") | ||
8 | hh:add(" at specified address in memory. No cache coherency is") | ||
9 | hh:add(" guaranteed") | ||
10 | |||
11 | hh = h:create_topic("printf") | ||
12 | hh:add("printf(s,...) -- this function is simple wrapper around string.format to emulate") | ||
13 | hh:add(" C printf() function") | ||
14 | |||
15 | function 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) | ||
23 | end | ||
24 | |||
25 | function HWLIB.printf(s,...) | ||
26 | return io.write(s:format(...)) | ||
27 | end | ||
diff --git a/utils/hwstub/tools/lua/load.lua b/utils/hwstub/tools/lua/load.lua index 86f01f7f0c..f636360c4c 100644 --- a/utils/hwstub/tools/lua/load.lua +++ b/utils/hwstub/tools/lua/load.lua | |||
@@ -10,4 +10,5 @@ elseif hwstub.dev.target.id == hwstub.dev.target.ATJ then | |||
10 | require "atj" | 10 | require "atj" |
11 | end | 11 | end |
12 | 12 | ||
13 | require "hwlib" | ||
13 | require "dumper" | 14 | require "dumper" |