diff options
author | Amaury Pouly <amaury.pouly@gmail.com> | 2014-02-04 00:10:41 +0100 |
---|---|---|
committer | Amaury Pouly <amaury.pouly@gmail.com> | 2014-02-10 23:14:24 +0100 |
commit | c17d30f20466861a244c603665c580feb7758abf (patch) | |
tree | c5044f599f89d89de0b1419bd40e92211f8c8b8a /utils/hwstub/tools | |
parent | 6d64111b3c2f772cfc3539bb13851f78d4b55870 (diff) | |
download | rockbox-c17d30f20466861a244c603665c580feb7758abf.tar.gz rockbox-c17d30f20466861a244c603665c580feb7758abf.zip |
utils/hwstub: completely rework the protocol, drop unused features
The protocol has evolved a lot during the 2.x.y lifetime, bringing more
features which later got unused. This commit removes all the unused stuff
and simplifies everything:
- drop the feature mask: everything is mandatory or stalled on error
- remove the info request and put all static information in standard USB
descriptors which are part of the configuration descriptor (and can be
retrieved using the standard GetDescriptor request).
- remove the USB interface, we had only one anyway
- remove all endpoint descriptors
- remove the exit/atexit stuff, it never worked as intended anyway
- update the hwstub library and make it able to handle any device
- update the tools (mostly renaming and removing of code)
Change-Id: I1872bba7f4177fc3891180e8f944aab88f5bde31
Diffstat (limited to 'utils/hwstub/tools')
-rw-r--r-- | utils/hwstub/tools/hwstub_load.cpp | 61 | ||||
-rw-r--r-- | utils/hwstub/tools/hwstub_shell.cpp | 142 | ||||
-rw-r--r-- | utils/hwstub/tools/init.lua | 18 |
3 files changed, 71 insertions, 150 deletions
diff --git a/utils/hwstub/tools/hwstub_load.cpp b/utils/hwstub/tools/hwstub_load.cpp index 58c8ac726f..8782c158d7 100644 --- a/utils/hwstub/tools/hwstub_load.cpp +++ b/utils/hwstub/tools/hwstub_load.cpp | |||
@@ -121,7 +121,7 @@ void usage(void) | |||
121 | int main(int argc, char **argv) | 121 | int main(int argc, char **argv) |
122 | { | 122 | { |
123 | bool quiet = false; | 123 | bool quiet = false; |
124 | struct hwstub_device_t hwdev; | 124 | struct hwstub_device_t *hwdev; |
125 | enum image_type_t type = IT_DETECT; | 125 | enum image_type_t type = IT_DETECT; |
126 | 126 | ||
127 | // parse command line | 127 | // parse command line |
@@ -244,73 +244,52 @@ int main(int argc, char **argv) | |||
244 | libusb_get_bus_number(mydev), | 244 | libusb_get_bus_number(mydev), |
245 | libusb_get_device_address(mydev)); | 245 | libusb_get_device_address(mydev)); |
246 | } | 246 | } |
247 | hwdev.handle = handle; | 247 | hwdev = hwstub_open(handle); |
248 | if(hwstub_probe(&hwdev)) | 248 | if(hwdev == NULL) |
249 | { | 249 | { |
250 | fprintf(stderr, "Cannot probe device!\n"); | 250 | fprintf(stderr, "Cannot probe device!\n"); |
251 | return 1; | 251 | return 1; |
252 | } | 252 | } |
253 | 253 | ||
254 | // get hwstub information | 254 | // get hwstub information |
255 | struct usb_resp_info_version_t hwdev_ver; | 255 | struct hwstub_version_desc_t hwdev_ver; |
256 | int ret = hwstub_get_info(&hwdev, HWSTUB_INFO_VERSION, &hwdev_ver, sizeof(hwdev_ver)); | 256 | int ret = hwstub_get_desc(hwdev, HWSTUB_DT_VERSION, &hwdev_ver, sizeof(hwdev_ver)); |
257 | if(ret != sizeof(hwdev_ver)) | 257 | if(ret != sizeof(hwdev_ver)) |
258 | { | 258 | { |
259 | fprintf(stderr, "Cannot get version!\n"); | 259 | fprintf(stderr, "Cannot get version!\n"); |
260 | goto Lerr; | 260 | goto Lerr; |
261 | } | 261 | } |
262 | if(hwdev_ver.major != HWSTUB_VERSION_MAJOR || hwdev_ver.minor < HWSTUB_VERSION_MINOR) | 262 | if(hwdev_ver.bMajor != HWSTUB_VERSION_MAJOR || hwdev_ver.bMinor < HWSTUB_VERSION_MINOR) |
263 | { | 263 | { |
264 | printf("Warning: this tool is possibly incompatible with your device:\n"); | 264 | printf("Warning: this tool is possibly incompatible with your device:\n"); |
265 | printf("Device version: %d.%d.%d\n", hwdev_ver.major, hwdev_ver.minor, hwdev_ver.revision); | 265 | printf("Device version: %d.%d.%d\n", hwdev_ver.bMajor, hwdev_ver.bMinor, hwdev_ver.bRevision); |
266 | printf("Host version: %d.%d.%d\n", HWSTUB_VERSION_MAJOR, HWSTUB_VERSION_MINOR, HWSTUB_VERSION_REV); | 266 | printf("Host version: %d.%d.%d\n", HWSTUB_VERSION_MAJOR, HWSTUB_VERSION_MINOR, HWSTUB_VERSION_REV); |
267 | } | 267 | } |
268 | 268 | ||
269 | // get features | 269 | ret = hwstub_rw_mem(hwdev, 0, addr, buffer, size); |
270 | struct usb_resp_info_features_t hwdev_features; | ||
271 | ret = hwstub_get_info(&hwdev, HWSTUB_INFO_FEATURES, &hwdev_features, sizeof(hwdev_features)); | ||
272 | if(ret != sizeof(hwdev_features)) | ||
273 | { | ||
274 | fprintf(stderr, "Cannot get features: %d\n", ret); | ||
275 | goto Lerr; | ||
276 | } | ||
277 | if(!(hwdev_features.feature_mask & HWSTUB_RW_MEM)) | ||
278 | { | ||
279 | fprintf(stderr, "Device doesn't support R/W commands\n"); | ||
280 | goto Lerr; | ||
281 | } | ||
282 | if(!(hwdev_features.feature_mask & HWSTUB_JUMP)) | ||
283 | { | ||
284 | fprintf(stderr, "Device doesn't support jump commands\n"); | ||
285 | goto Lerr; | ||
286 | } | ||
287 | ret = hwstub_rw_mem(&hwdev, 0, addr, buffer, size); | ||
288 | if(ret != (int)size) | 270 | if(ret != (int)size) |
289 | { | 271 | { |
290 | fprintf(stderr, "Image write failed\n"); | 272 | fprintf(stderr, "Image write failed\n"); |
291 | goto Lerr; | 273 | goto Lerr; |
292 | } | 274 | } |
293 | hwstub_jump(&hwdev, addr); | 275 | hwstub_jump(hwdev, addr); |
294 | 276 | ||
295 | hwstub_release(&hwdev); | 277 | hwstub_release(hwdev); |
296 | return 0; | 278 | return 0; |
297 | 279 | ||
298 | Lerr: | 280 | Lerr: |
299 | // display log if handled | 281 | // display log if handled |
300 | if(hwdev_features.feature_mask & HWSTUB_FEATURE_LOG) | 282 | fprintf(stderr, "Device log:\n"); |
283 | do | ||
301 | { | 284 | { |
302 | fprintf(stderr, "Device log:\n"); | 285 | char buffer[128]; |
303 | do | 286 | int length = hwstub_get_log(hwdev, buffer, sizeof(buffer) - 1); |
304 | { | 287 | if(length <= 0) |
305 | char buffer[128]; | 288 | break; |
306 | int length = hwstub_get_log(&hwdev, buffer, sizeof(buffer) - 1); | 289 | buffer[length] = 0; |
307 | if(length <= 0) | 290 | fprintf(stderr, "%s", buffer); |
308 | break; | 291 | }while(1); |
309 | buffer[length] = 0; | 292 | hwstub_release(hwdev); |
310 | fprintf(stderr, "%s", buffer); | ||
311 | }while(1); | ||
312 | } | ||
313 | hwstub_release(&hwdev); | ||
314 | return 1; | 293 | return 1; |
315 | } | 294 | } |
316 | 295 | ||
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 | } |
diff --git a/utils/hwstub/tools/init.lua b/utils/hwstub/tools/init.lua index 4c62de007f..3c60abf806 100644 --- a/utils/hwstub/tools/init.lua +++ b/utils/hwstub/tools/init.lua | |||
@@ -79,18 +79,12 @@ if not hwstub.options.quiet then | |||
79 | print(" id: " .. string.format("%#x (%s)", hwstub.dev.target.id, id_str)) | 79 | print(" id: " .. string.format("%#x (%s)", hwstub.dev.target.id, id_str)) |
80 | print(" name: " .. hwstub.dev.target.name) | 80 | print(" name: " .. hwstub.dev.target.name) |
81 | print(" layout") | 81 | print(" layout") |
82 | print(" on-chip ram") | 82 | print(" code: " .. string.format("%#x bytes @ %#x", |
83 | print(" code: " .. string.format("%#x bytes @ %#x", | 83 | hwstub.dev.layout.code.size, hwstub.dev.layout.code.start)) |
84 | hwstub.dev.layout.ocram.code.size, hwstub.dev.layout.ocram.code.start)) | 84 | print(" stack: " .. string.format("%#x bytes @ %#x", |
85 | print(" stack: " .. string.format("%#x bytes @ %#x", | 85 | hwstub.dev.layout.stack.size, hwstub.dev.layout.stack.start)) |
86 | hwstub.dev.layout.ocram.stack.size, hwstub.dev.layout.ocram.stack.start)) | 86 | print(" buffer: " .. string.format("%#x bytes @ %#x", |
87 | print(" buffer: " .. string.format("%#x bytes @ %#x", | 87 | hwstub.dev.layout.buffer.size, hwstub.dev.layout.buffer.start)) |
88 | hwstub.dev.layout.ocram.buffer.size, hwstub.dev.layout.ocram.buffer.start)) | ||
89 | print(" features"); | ||
90 | print(" log: " .. tostring(hwstub.dev.features.log)) | ||
91 | print(" mem: " .. tostring(hwstub.dev.features.mem)) | ||
92 | print(" call: " .. tostring(hwstub.dev.features.call)) | ||
93 | print(" jump: " .. tostring(hwstub.dev.features.jump)) | ||
94 | end | 88 | end |
95 | 89 | ||
96 | -- | 90 | -- |