diff options
Diffstat (limited to 'utils/hwstub/tools/init.lua')
-rw-r--r-- | utils/hwstub/tools/init.lua | 104 |
1 files changed, 104 insertions, 0 deletions
diff --git a/utils/hwstub/tools/init.lua b/utils/hwstub/tools/init.lua new file mode 100644 index 0000000000..142c77e20a --- /dev/null +++ b/utils/hwstub/tools/init.lua | |||
@@ -0,0 +1,104 @@ | |||
1 | -- init code for hwstub_tools | ||
2 | |||
3 | -- | ||
4 | -- HELP | ||
5 | -- | ||
6 | HELP = hwstub.help | ||
7 | |||
8 | function HELP:create_topic(name) | ||
9 | self[name] = { create_topic = HELP.create_topic, add = HELP.add, get_topic = HELP.get_topic } | ||
10 | return self[name] | ||
11 | end | ||
12 | |||
13 | function HELP:get_topic(name) | ||
14 | return self[name] | ||
15 | end | ||
16 | |||
17 | function HELP:add(text) | ||
18 | table.insert(self, text) | ||
19 | end | ||
20 | |||
21 | do | ||
22 | local h = HELP:create_topic("hwstub") | ||
23 | h:add("This tool uses a number of well-defined namespaces (tables) to organise its features.") | ||
24 | h:add("The hwstub table contains a number of information and functions related to the tool itself.") | ||
25 | h:add("Of particular interest are") | ||
26 | h:add("* hwstub.host which holds host specific information.") | ||
27 | h:add("* hwstub.dev which holds device specific information. See DEV") | ||
28 | h:add("* hwstub.help (aka HELP) which holds the help. See HELP."); | ||
29 | h:add("* hwstub.soc which holds soc specific information. See HW"); | ||
30 | |||
31 | h = HELP:create_topic("HELP"); | ||
32 | h:add("This variable redirects to hwstub.help and provides access to the help system."); | ||
33 | h:add("You can enhance the help using the following methods on any topic (including HELP itself)."); | ||
34 | h:add("* t:create_topic(s) to create a new subtopic named s under topic t"); | ||
35 | h:add("* t:add(s) to add a help line to topic t"); | ||
36 | h:add("* t:get_topic(s) to get the subtopic s under topic t"); | ||
37 | |||
38 | h = HELP:create_topic("DEV"); | ||
39 | h:add("This variable redirects to hwstub.dev and provides direct access to the device."); | ||
40 | h:add("It contains some information about the device and the following methods."); | ||
41 | h:add("* read8/16/32(a) reads a 8/16/32-bit integer at address a"); | ||
42 | h:add("* write8/16/32(a, v) writes the 8/16/32-bit integer v at address a"); | ||
43 | |||
44 | h = HELP:create_topic("HW"); | ||
45 | h:add("This variable redirects to the current soc under hwstub.soc and should be changed by calling hwstub:soc:select only."); | ||
46 | h:add("The complete register tree can be found under HW in a well organise fashion."); | ||
47 | h:add("* HW.dev points to device dev"); | ||
48 | h:add("* HW.dev[i] points to device devi if there are several copies of the device at different addresses."); | ||
49 | h:add("* HW.dev.reg points to the register reg under dev"); | ||
50 | h:add("* HW.dev.reg[i] points to the register regi if there are several copies."); | ||
51 | h:add("* HW.dev.reg.f points to the field f under register reg."); | ||
52 | h:add("* HW.dev.reg.f.v gives the value of named value v of field f."); | ||
53 | h:add("* All registers can be read using HW.dev.reg.read() and written using HW.dev.reg.write(v)."); | ||
54 | h:add("* Register with a SCT variant also implement HW.dev.reg.set/clr/tog(v)."); | ||
55 | h:add("* All register field can be read using HW.dev.reg.f.read() and written using HW.dev.reg.f.write(v)."); | ||
56 | h:add("* Field writes can either give a integer or a named value to write(v)."); | ||
57 | h:add("* Register with a SCT variant also implement HW.dev.reg.f.set/clr/tog(v) with the same properties."); | ||
58 | h:add("* All devices, registers and fields also have descriptions available such as addresses."); | ||
59 | end | ||
60 | |||
61 | -- | ||
62 | -- INFO | ||
63 | -- | ||
64 | |||
65 | if not hwstub.options.quiet then | ||
66 | print("information") | ||
67 | print(" hwstub") | ||
68 | print(" version: " .. string.format("%d.%d.%d", hwstub.host.version.major, | ||
69 | hwstub.host.version.minor, hwstub.host.version.revision)) | ||
70 | print(" device") | ||
71 | print(" version: " .. string.format("%d.%d.%d", hwstub.dev.version.major, | ||
72 | hwstub.dev.version.minor, hwstub.dev.version.revision)) | ||
73 | print(" layout") | ||
74 | print(" on-chip ram") | ||
75 | print(" code: " .. string.format("%#x bytes @ %#x", | ||
76 | hwstub.dev.layout.ocram.code.size, hwstub.dev.layout.ocram.code.start)) | ||
77 | print(" stack: " .. string.format("%#x bytes @ %#x", | ||
78 | hwstub.dev.layout.ocram.stack.size, hwstub.dev.layout.ocram.stack.start)) | ||
79 | print(" buffer: " .. string.format("%#x bytes @ %#x", | ||
80 | hwstub.dev.layout.ocram.buffer.size, hwstub.dev.layout.ocram.buffer.start)) | ||
81 | print(" features"); | ||
82 | print(" log: " .. tostring(hwstub.dev.features.log)) | ||
83 | print(" mem: " .. tostring(hwstub.dev.features.mem)) | ||
84 | print(" call: " .. tostring(hwstub.dev.features.call)) | ||
85 | print(" jump: " .. tostring(hwstub.dev.features.jump)) | ||
86 | print(" aes_otp: " .. tostring(hwstub.dev.features.aes_otp)) | ||
87 | end | ||
88 | |||
89 | -- | ||
90 | -- SOC | ||
91 | -- | ||
92 | function hwstub.soc:select(soc) | ||
93 | if self[soc] == nil then return false end | ||
94 | print("Selecting soc " .. soc .. ". Redirecting HW to hwstub.soc." .. soc) | ||
95 | HW = self[soc] | ||
96 | return true | ||
97 | end | ||
98 | |||
99 | -- | ||
100 | -- DEV | ||
101 | -- | ||
102 | DEV = hwstub.dev | ||
103 | |||
104 | require "lua/load" | ||