diff options
Diffstat (limited to 'utils/hwstub/tools/hwstub_shell.cpp')
-rw-r--r-- | utils/hwstub/tools/hwstub_shell.cpp | 142 |
1 files changed, 45 insertions, 97 deletions
diff --git a/utils/hwstub/tools/hwstub_shell.cpp b/utils/hwstub/tools/hwstub_shell.cpp index 2a3fc177ed..61cb617509 100644 --- a/utils/hwstub/tools/hwstub_shell.cpp +++ b/utils/hwstub/tools/hwstub_shell.cpp | |||
@@ -39,12 +39,11 @@ | |||
39 | */ | 39 | */ |
40 | bool g_quiet = false; | 40 | bool g_quiet = false; |
41 | bool g_exit = false; | 41 | bool g_exit = false; |
42 | struct hwstub_device_t g_hwdev; | 42 | struct hwstub_device_t *g_hwdev; |
43 | struct usb_resp_info_version_t g_hwdev_ver; | 43 | struct hwstub_version_desc_t g_hwdev_ver; |
44 | struct usb_resp_info_layout_t g_hwdev_layout; | 44 | struct hwstub_layout_desc_t g_hwdev_layout; |
45 | struct usb_resp_info_features_t g_hwdev_features; | 45 | struct hwstub_target_desc_t g_hwdev_target; |
46 | struct usb_resp_info_target_t g_hwdev_target; | 46 | struct hwstub_stmp_desc_t g_hwdev_stmp; |
47 | struct usb_resp_info_stmp_t g_hwdev_stmp; | ||
48 | lua_State *g_lua; | 47 | lua_State *g_lua; |
49 | 48 | ||
50 | /** | 49 | /** |
@@ -144,7 +143,7 @@ typedef void (*hw_writen_fn_t)(lua_State *state, soc_addr_t addr, soc_word_t val | |||
144 | soc_word_t hw_read8(lua_State *state, soc_addr_t addr) | 143 | soc_word_t hw_read8(lua_State *state, soc_addr_t addr) |
145 | { | 144 | { |
146 | uint8_t u; | 145 | uint8_t u; |
147 | if(hwstub_rw_mem(&g_hwdev, 1, addr, &u, sizeof(u)) != sizeof(u)) | 146 | if(hwstub_rw_mem(g_hwdev, 1, addr, &u, sizeof(u)) != sizeof(u)) |
148 | luaL_error(state, "fail to read8 @ %p", addr); | 147 | luaL_error(state, "fail to read8 @ %p", addr); |
149 | return u; | 148 | return u; |
150 | } | 149 | } |
@@ -152,7 +151,7 @@ soc_word_t hw_read8(lua_State *state, soc_addr_t addr) | |||
152 | soc_word_t hw_read16(lua_State *state, soc_addr_t addr) | 151 | soc_word_t hw_read16(lua_State *state, soc_addr_t addr) |
153 | { | 152 | { |
154 | uint16_t u; | 153 | uint16_t u; |
155 | if(hwstub_rw_mem(&g_hwdev, 1, addr, &u, sizeof(u)) != sizeof(u)) | 154 | if(hwstub_rw_mem(g_hwdev, 1, addr, &u, sizeof(u)) != sizeof(u)) |
156 | luaL_error(state, "fail to read16 @ %p", addr); | 155 | luaL_error(state, "fail to read16 @ %p", addr); |
157 | return u; | 156 | return u; |
158 | } | 157 | } |
@@ -160,7 +159,7 @@ soc_word_t hw_read16(lua_State *state, soc_addr_t addr) | |||
160 | soc_word_t hw_read32(lua_State *state, soc_addr_t addr) | 159 | soc_word_t hw_read32(lua_State *state, soc_addr_t addr) |
161 | { | 160 | { |
162 | uint32_t u; | 161 | uint32_t u; |
163 | if(hwstub_rw_mem(&g_hwdev, 1, addr, &u, sizeof(u)) != sizeof(u)) | 162 | if(hwstub_rw_mem(g_hwdev, 1, addr, &u, sizeof(u)) != sizeof(u)) |
164 | luaL_error(state, "fail to read32 @ %p", addr); | 163 | luaL_error(state, "fail to read32 @ %p", addr); |
165 | return u; | 164 | return u; |
166 | } | 165 | } |
@@ -168,21 +167,21 @@ soc_word_t hw_read32(lua_State *state, soc_addr_t addr) | |||
168 | void hw_write8(lua_State *state, soc_addr_t addr, soc_word_t val) | 167 | void hw_write8(lua_State *state, soc_addr_t addr, soc_word_t val) |
169 | { | 168 | { |
170 | uint8_t u = val; | 169 | uint8_t u = val; |
171 | if(hwstub_rw_mem(&g_hwdev, 0, addr, &u, sizeof(u)) != sizeof(u)) | 170 | if(hwstub_rw_mem(g_hwdev, 0, addr, &u, sizeof(u)) != sizeof(u)) |
172 | luaL_error(state, "fail to write8 @ %p", addr); | 171 | luaL_error(state, "fail to write8 @ %p", addr); |
173 | } | 172 | } |
174 | 173 | ||
175 | void hw_write16(lua_State *state, soc_addr_t addr, soc_word_t val) | 174 | void hw_write16(lua_State *state, soc_addr_t addr, soc_word_t val) |
176 | { | 175 | { |
177 | uint16_t u = val; | 176 | uint16_t u = val; |
178 | if(hwstub_rw_mem(&g_hwdev, 0, addr, &u, sizeof(u)) != sizeof(u)) | 177 | if(hwstub_rw_mem(g_hwdev, 0, addr, &u, sizeof(u)) != sizeof(u)) |
179 | luaL_error(state, "fail to write16 @ %p", addr); | 178 | luaL_error(state, "fail to write16 @ %p", addr); |
180 | } | 179 | } |
181 | 180 | ||
182 | void hw_write32(lua_State *state, soc_addr_t addr, soc_word_t val) | 181 | void hw_write32(lua_State *state, soc_addr_t addr, soc_word_t val) |
183 | { | 182 | { |
184 | uint32_t u = val; | 183 | uint32_t u = val; |
185 | if(hwstub_rw_mem(&g_hwdev, 0, addr, &u, sizeof(u)) != sizeof(u)) | 184 | if(hwstub_rw_mem(g_hwdev, 0, addr, &u, sizeof(u)) != sizeof(u)) |
186 | luaL_error(state, "fail to write32 @ %p", addr); | 185 | luaL_error(state, "fail to write32 @ %p", addr); |
187 | } | 186 | } |
188 | 187 | ||
@@ -208,34 +207,7 @@ int my_lua_writen(lua_State *state) | |||
208 | 207 | ||
209 | int my_lua_printlog(lua_State *state) | 208 | int my_lua_printlog(lua_State *state) |
210 | { | 209 | { |
211 | print_log(&g_hwdev); | 210 | print_log(g_hwdev); |
212 | return 0; | ||
213 | } | ||
214 | |||
215 | int my_lua_atexit(lua_State *state) | ||
216 | { | ||
217 | int n = lua_gettop(state); | ||
218 | if(n != 1) | ||
219 | luaL_error(state, "atexit takes one argument"); | ||
220 | const char *arg = luaL_checkstring(state, 1); | ||
221 | int ret = -1; | ||
222 | if(strcmp(arg, "nop") == 0) | ||
223 | ret = hwstub_atexit(&g_hwdev, HWSTUB_ATEXIT_NOP); | ||
224 | else if(strcmp(arg, "reboot") == 0) | ||
225 | ret = hwstub_atexit(&g_hwdev, HWSTUB_ATEXIT_REBOOT); | ||
226 | else if(strcmp(arg, "off") == 0) | ||
227 | ret = hwstub_atexit(&g_hwdev, HWSTUB_ATEXIT_OFF); | ||
228 | else | ||
229 | luaL_error(state, "unknown atexit method '%s'", arg); | ||
230 | if(ret < 0) | ||
231 | luaL_error(state, "fail to set atexit method"); | ||
232 | return 0; | ||
233 | } | ||
234 | |||
235 | int my_lua_exit(lua_State *state) | ||
236 | { | ||
237 | if(hwstub_exit(&g_hwdev) < 0) | ||
238 | luaL_error(state, "fail to exit hwstub"); | ||
239 | return 0; | 211 | return 0; |
240 | } | 212 | } |
241 | 213 | ||
@@ -268,69 +240,60 @@ bool my_lua_import_hwstub() | |||
268 | 240 | ||
269 | lua_newtable(g_lua); // dev | 241 | lua_newtable(g_lua); // dev |
270 | lua_newtable(g_lua); // version | 242 | lua_newtable(g_lua); // version |
271 | lua_pushinteger(g_lua, g_hwdev_ver.major); | 243 | lua_pushinteger(g_lua, g_hwdev_ver.bMajor); |
272 | lua_setfield(g_lua, -2, "major"); | 244 | lua_setfield(g_lua, -2, "major"); |
273 | lua_pushinteger(g_lua, g_hwdev_ver.minor); | 245 | lua_pushinteger(g_lua, g_hwdev_ver.bMinor); |
274 | lua_setfield(g_lua, -2, "minor"); | 246 | lua_setfield(g_lua, -2, "minor"); |
275 | lua_pushinteger(g_lua, g_hwdev_ver.revision); | 247 | lua_pushinteger(g_lua, g_hwdev_ver.bRevision); |
276 | lua_setfield(g_lua, -2, "revision"); | 248 | lua_setfield(g_lua, -2, "revision"); |
277 | lua_setfield(g_lua, -2, "version"); | 249 | lua_setfield(g_lua, -2, "version"); |
278 | 250 | ||
279 | lua_newtable(g_lua); // layout | 251 | lua_newtable(g_lua); // layout |
280 | lua_newtable(g_lua); // ocram | ||
281 | lua_newtable(g_lua); // code | 252 | lua_newtable(g_lua); // code |
282 | lua_pushinteger(g_lua, g_hwdev_layout.oc_code_start); | 253 | lua_pushinteger(g_lua, g_hwdev_layout.dCodeStart); |
283 | lua_setfield(g_lua, -2, "start"); | 254 | lua_setfield(g_lua, -2, "start"); |
284 | lua_pushinteger(g_lua, g_hwdev_layout.oc_code_size); | 255 | lua_pushinteger(g_lua, g_hwdev_layout.dCodeSize); |
285 | lua_setfield(g_lua, -2, "size"); | 256 | lua_setfield(g_lua, -2, "size"); |
286 | lua_setfield(g_lua, -2, "code"); | 257 | lua_setfield(g_lua, -2, "code"); |
287 | lua_newtable(g_lua); // stack | 258 | lua_newtable(g_lua); // stack |
288 | lua_pushinteger(g_lua, g_hwdev_layout.oc_stack_start); | 259 | lua_pushinteger(g_lua, g_hwdev_layout.dStackStart); |
289 | lua_setfield(g_lua, -2, "start"); | 260 | lua_setfield(g_lua, -2, "start"); |
290 | lua_pushinteger(g_lua, g_hwdev_layout.oc_stack_size); | 261 | lua_pushinteger(g_lua, g_hwdev_layout.dStackSize); |
291 | lua_setfield(g_lua, -2, "size"); | 262 | lua_setfield(g_lua, -2, "size"); |
292 | lua_setfield(g_lua, -2, "stack"); | 263 | lua_setfield(g_lua, -2, "stack"); |
293 | lua_newtable(g_lua); // buffer | 264 | lua_newtable(g_lua); // buffer |
294 | lua_pushinteger(g_lua, g_hwdev_layout.oc_buffer_start); | 265 | lua_pushinteger(g_lua, g_hwdev_layout.dBufferStart); |
295 | lua_setfield(g_lua, -2, "start"); | 266 | lua_setfield(g_lua, -2, "start"); |
296 | lua_pushinteger(g_lua, g_hwdev_layout.oc_buffer_size); | 267 | lua_pushinteger(g_lua, g_hwdev_layout.dBufferSize); |
297 | lua_setfield(g_lua, -2, "size"); | 268 | lua_setfield(g_lua, -2, "size"); |
298 | lua_setfield(g_lua, -2, "buffer"); | 269 | lua_setfield(g_lua, -2, "buffer"); |
299 | lua_setfield(g_lua, -2, "ocram"); | ||
300 | lua_setfield(g_lua, -2, "layout"); | 270 | lua_setfield(g_lua, -2, "layout"); |
301 | 271 | ||
302 | lua_newtable(g_lua); // target | 272 | lua_newtable(g_lua); // target |
303 | lua_pushstring(g_lua, g_hwdev_target.name); | 273 | lua_pushstring(g_lua, g_hwdev_target.bName); |
304 | lua_setfield(g_lua, -2, "name"); | 274 | lua_setfield(g_lua, -2, "name"); |
305 | lua_pushinteger(g_lua, g_hwdev_target.id); | 275 | lua_pushinteger(g_lua, g_hwdev_target.dID); |
306 | lua_setfield(g_lua, -2, "id"); | 276 | lua_setfield(g_lua, -2, "id"); |
307 | lua_pushinteger(g_lua, HWSTUB_TARGET_UNK); | 277 | lua_pushinteger(g_lua, HWSTUB_TARGET_UNK); |
308 | lua_setfield(g_lua, -2, "UNK"); | 278 | lua_setfield(g_lua, -2, "UNK"); |
309 | lua_pushinteger(g_lua, HWSTUB_TARGET_STMP); | 279 | lua_pushinteger(g_lua, HWSTUB_TARGET_STMP); |
310 | lua_setfield(g_lua, -2, "STMP"); | 280 | lua_setfield(g_lua, -2, "STMP"); |
281 | lua_pushinteger(g_lua, HWSTUB_TARGET_RK27); | ||
282 | lua_setfield(g_lua, -2, "RK27"); | ||
311 | lua_setfield(g_lua, -2, "target"); | 283 | lua_setfield(g_lua, -2, "target"); |
312 | 284 | ||
313 | if(g_hwdev_target.id == HWSTUB_TARGET_STMP) | 285 | if(g_hwdev_target.dID == HWSTUB_TARGET_STMP) |
314 | { | 286 | { |
315 | lua_newtable(g_lua); // stmp | 287 | lua_newtable(g_lua); // stmp |
316 | lua_pushinteger(g_lua, g_hwdev_stmp.chipid); | 288 | lua_pushinteger(g_lua, g_hwdev_stmp.wChipID); |
317 | lua_setfield(g_lua, -2, "chipid"); | 289 | lua_setfield(g_lua, -2, "chipid"); |
318 | lua_pushinteger(g_lua, g_hwdev_stmp.rev); | 290 | lua_pushinteger(g_lua, g_hwdev_stmp.bRevision); |
319 | lua_setfield(g_lua, -2, "rev"); | 291 | lua_setfield(g_lua, -2, "rev"); |
292 | lua_pushinteger(g_lua, g_hwdev_stmp.bPackage); | ||
293 | lua_setfield(g_lua, -2, "package"); | ||
320 | lua_setfield(g_lua, -2, "stmp"); | 294 | lua_setfield(g_lua, -2, "stmp"); |
321 | } | 295 | } |
322 | 296 | ||
323 | lua_newtable(g_lua); // features | ||
324 | lua_pushboolean(g_lua, !!(g_hwdev_features.feature_mask & HWSTUB_FEATURE_LOG)); | ||
325 | lua_setfield(g_lua, -2, "log"); | ||
326 | lua_pushboolean(g_lua, !!(g_hwdev_features.feature_mask & HWSTUB_FEATURE_MEM)); | ||
327 | lua_setfield(g_lua, -2, "mem"); | ||
328 | lua_pushboolean(g_lua, !!(g_hwdev_features.feature_mask & HWSTUB_FEATURE_CALL)); | ||
329 | lua_setfield(g_lua, -2, "call"); | ||
330 | lua_pushboolean(g_lua, !!(g_hwdev_features.feature_mask & HWSTUB_FEATURE_JUMP)); | ||
331 | lua_setfield(g_lua, -2, "jump"); | ||
332 | lua_setfield(g_lua, -2, "features"); | ||
333 | |||
334 | lua_pushlightuserdata(g_lua, (void *)&hw_read8); | 297 | lua_pushlightuserdata(g_lua, (void *)&hw_read8); |
335 | lua_pushcclosure(g_lua, my_lua_readn, 1); | 298 | lua_pushcclosure(g_lua, my_lua_readn, 1); |
336 | lua_setfield(g_lua, -2, "read8"); | 299 | lua_setfield(g_lua, -2, "read8"); |
@@ -352,10 +315,6 @@ bool my_lua_import_hwstub() | |||
352 | lua_setfield(g_lua, -2, "write32"); | 315 | lua_setfield(g_lua, -2, "write32"); |
353 | lua_pushcclosure(g_lua, my_lua_printlog, 0); | 316 | lua_pushcclosure(g_lua, my_lua_printlog, 0); |
354 | lua_setfield(g_lua, -2, "print_log"); | 317 | lua_setfield(g_lua, -2, "print_log"); |
355 | lua_pushcclosure(g_lua, my_lua_atexit, 0); | ||
356 | lua_setfield(g_lua, -2, "atexit"); | ||
357 | lua_pushcclosure(g_lua, my_lua_exit, 0); | ||
358 | lua_setfield(g_lua, -2, "exit"); | ||
359 | 318 | ||
360 | lua_setfield(g_lua, -2, "dev"); | 319 | lua_setfield(g_lua, -2, "dev"); |
361 | 320 | ||
@@ -404,7 +363,7 @@ bool my_lua_import_hwstub() | |||
404 | 363 | ||
405 | if(lua_gettop(g_lua) != oldtop) | 364 | if(lua_gettop(g_lua) != oldtop) |
406 | { | 365 | { |
407 | printf("internal error: unbalanced my_lua_import_soc"); | 366 | printf("internal error: unbalanced my_lua_import_soc\n"); |
408 | return false; | 367 | return false; |
409 | } | 368 | } |
410 | return true; | 369 | return true; |
@@ -785,45 +744,37 @@ int main(int argc, char **argv) | |||
785 | libusb_get_bus_number(mydev), | 744 | libusb_get_bus_number(mydev), |
786 | libusb_get_device_address(mydev)); | 745 | libusb_get_device_address(mydev)); |
787 | } | 746 | } |
788 | g_hwdev.handle = handle; | 747 | g_hwdev = hwstub_open(handle); |
789 | if(hwstub_probe(&g_hwdev)) | 748 | if(g_hwdev == NULL) |
790 | { | 749 | { |
791 | printf("Cannot probe device!\n"); | 750 | printf("Cannot open device!\n"); |
792 | return 1; | 751 | return 1; |
793 | } | 752 | } |
794 | 753 | ||
795 | // get hwstub information | 754 | // get hwstub information |
796 | int ret = hwstub_get_info(&g_hwdev, HWSTUB_INFO_VERSION, &g_hwdev_ver, sizeof(g_hwdev_ver)); | 755 | int ret = hwstub_get_desc(g_hwdev, HWSTUB_DT_VERSION, &g_hwdev_ver, sizeof(g_hwdev_ver)); |
797 | if(ret != sizeof(g_hwdev_ver)) | 756 | if(ret != sizeof(g_hwdev_ver)) |
798 | { | 757 | { |
799 | printf("Cannot get version!\n"); | 758 | printf("Cannot get version!\n"); |
800 | goto Lerr; | 759 | goto Lerr; |
801 | } | 760 | } |
802 | if(g_hwdev_ver.major != HWSTUB_VERSION_MAJOR || g_hwdev_ver.minor < HWSTUB_VERSION_MINOR) | 761 | if(g_hwdev_ver.bMajor != HWSTUB_VERSION_MAJOR || g_hwdev_ver.bMinor < HWSTUB_VERSION_MINOR) |
803 | { | 762 | { |
804 | printf("Warning: this tool is possibly incompatible with your device:\n"); | 763 | printf("Warning: this tool is possibly incompatible with your device:\n"); |
805 | printf("Device version: %d.%d.%d\n", g_hwdev_ver.major, g_hwdev_ver.minor, g_hwdev_ver.revision); | 764 | printf("Device version: %d.%d.%d\n", g_hwdev_ver.bMajor, g_hwdev_ver.bMinor, g_hwdev_ver.bRevision); |
806 | printf("Host version: %d.%d.%d\n", HWSTUB_VERSION_MAJOR, HWSTUB_VERSION_MINOR, HWSTUB_VERSION_REV); | 765 | printf("Host version: %d.%d.%d\n", HWSTUB_VERSION_MAJOR, HWSTUB_VERSION_MINOR, HWSTUB_VERSION_REV); |
807 | } | 766 | } |
808 | 767 | ||
809 | // get memory layout information | 768 | // get memory layout information |
810 | ret = hwstub_get_info(&g_hwdev, HWSTUB_INFO_LAYOUT, &g_hwdev_layout, sizeof(g_hwdev_layout)); | 769 | ret = hwstub_get_desc(g_hwdev, HWSTUB_DT_LAYOUT, &g_hwdev_layout, sizeof(g_hwdev_layout)); |
811 | if(ret != sizeof(g_hwdev_layout)) | 770 | if(ret != sizeof(g_hwdev_layout)) |
812 | { | 771 | { |
813 | printf("Cannot get layout: %d\n", ret); | 772 | printf("Cannot get layout: %d\n", ret); |
814 | goto Lerr; | 773 | goto Lerr; |
815 | } | 774 | } |
816 | 775 | ||
817 | // get features | ||
818 | ret = hwstub_get_info(&g_hwdev, HWSTUB_INFO_FEATURES, &g_hwdev_features, sizeof(g_hwdev_features)); | ||
819 | if(ret != sizeof(g_hwdev_features)) | ||
820 | { | ||
821 | printf("Cannot get features: %d\n", ret); | ||
822 | goto Lerr; | ||
823 | } | ||
824 | |||
825 | // get target | 776 | // get target |
826 | ret = hwstub_get_info(&g_hwdev, HWSTUB_INFO_TARGET, &g_hwdev_target, sizeof(g_hwdev_target)); | 777 | ret = hwstub_get_desc(g_hwdev, HWSTUB_DT_TARGET, &g_hwdev_target, sizeof(g_hwdev_target)); |
827 | if(ret != sizeof(g_hwdev_target)) | 778 | if(ret != sizeof(g_hwdev_target)) |
828 | { | 779 | { |
829 | printf("Cannot get target: %d\n", ret); | 780 | printf("Cannot get target: %d\n", ret); |
@@ -831,9 +782,9 @@ int main(int argc, char **argv) | |||
831 | } | 782 | } |
832 | 783 | ||
833 | // get STMP specific information | 784 | // get STMP specific information |
834 | if(g_hwdev_target.id == HWSTUB_TARGET_STMP) | 785 | if(g_hwdev_target.dID == HWSTUB_TARGET_STMP) |
835 | { | 786 | { |
836 | ret = hwstub_get_info(&g_hwdev, HWSTUB_INFO_STMP, &g_hwdev_stmp, sizeof(g_hwdev_stmp)); | 787 | ret = hwstub_get_desc(g_hwdev, HWSTUB_DT_STMP, &g_hwdev_stmp, sizeof(g_hwdev_stmp)); |
837 | if(ret != sizeof(g_hwdev_stmp)) | 788 | if(ret != sizeof(g_hwdev_stmp)) |
838 | { | 789 | { |
839 | printf("Cannot get stmp: %d\n", ret); | 790 | printf("Cannot get stmp: %d\n", ret); |
@@ -884,12 +835,9 @@ int main(int argc, char **argv) | |||
884 | 835 | ||
885 | Lerr: | 836 | Lerr: |
886 | // display log if handled | 837 | // display log if handled |
887 | if(g_hwdev_features.feature_mask & HWSTUB_FEATURE_LOG) | 838 | if(!g_quiet) |
888 | { | 839 | printf("Device log:\n"); |
889 | if(!g_quiet) | 840 | print_log(g_hwdev); |
890 | printf("Device log:\n"); | 841 | hwstub_release(g_hwdev); |
891 | print_log(&g_hwdev); | ||
892 | } | ||
893 | hwstub_release(&g_hwdev); | ||
894 | return 1; | 842 | return 1; |
895 | } | 843 | } |