From f617da0552c95202807c5e41c70bc78a3189378e Mon Sep 17 00:00:00 2001 From: Amaury Pouly Date: Sat, 13 Jul 2013 17:38:34 +0200 Subject: hwstub: enhance protocol with more functions Change-Id: I7944249c2f7ea3e180e7b79ee8ae402d1d0742d3 --- utils/hwstub/hwstub_protocol.h | 41 +++++++++++------- utils/hwstub/stub/stmp/target.c | 5 +++ utils/hwstub/tools/hwstub_shell.cpp | 86 ++++++++++++++----------------------- utils/hwstub/tools/init.lua | 9 +++- 4 files changed, 71 insertions(+), 70 deletions(-) (limited to 'utils') diff --git a/utils/hwstub/hwstub_protocol.h b/utils/hwstub/hwstub_protocol.h index 41be3957e8..f47ce3b5db 100644 --- a/utils/hwstub/hwstub_protocol.h +++ b/utils/hwstub/hwstub_protocol.h @@ -26,8 +26,8 @@ #define HWSTUB_PROTOCOL 0x1d #define HWSTUB_VERSION_MAJOR 2 -#define HWSTUB_VERSION_MINOR 9 -#define HWSTUB_VERSION_REV 2 +#define HWSTUB_VERSION_MINOR 11 +#define HWSTUB_VERSION_REV 1 #define HWSTUB_USB_VID 0xfee1 #define HWSTUB_USB_PID 0xdead @@ -46,17 +46,18 @@ #define HWSTUB_RW_MEM 2 /* optional */ #define HWSTUB_CALL 3 /* optional */ #define HWSTUB_JUMP 4 /* optional */ -#define HWSTUB_AES_OTP 5 /* optional */ +#define HWSTUB_STOP 5 /* optional */ /** * HWSTUB_GET_INFO: get some information about an aspect of the device. * The wIndex field of the SETUP specifies which information to get. */ /* list of possible information */ -#define HWSTUB_INFO_VERSION 0 -#define HWSTUB_INFO_LAYOUT 1 -#define HWSTUB_INFO_STMP 2 -#define HWSTUB_INFO_FEATURES 3 +#define HWSTUB_INFO_VERSION 0 /* mandatory */ +#define HWSTUB_INFO_LAYOUT 1 /* mandatory */ +#define HWSTUB_INFO_STMP 2 /* optional */ +#define HWSTUB_INFO_FEATURES 3 /* mandatory */ +#define HWSTUB_INFO_TARGET 4 /* mandatory */ struct usb_resp_info_version_t { @@ -89,14 +90,23 @@ struct usb_resp_info_stmp_t #define HWSTUB_FEATURE_LOG (1 << 0) #define HWSTUB_FEATURE_MEM (1 << 1) #define HWSTUB_FEATURE_CALL (1 << 2) -#define HWSTUB_FEATURE_JUMP (1 << 2) -#define HWSTUB_FEATURE_AES_OTP (1 << 3) +#define HWSTUB_FEATURE_JUMP (1 << 3) +#define HWSTUB_FEATURE_STOP (1 << 4) struct usb_resp_info_features_t { uint32_t feature_mask; }; +#define HWSTUB_TARGET_UNK ('U' | 'N' << 8 | 'K' << 16 | ' ' << 24) +#define HWSTUB_TARGET_STMP ('S' | 'T' << 8 | 'M' << 16 | 'P' << 24) + +struct usb_resp_info_target_t +{ + uint32_t id; + char name[60]; +}; + /** * HWSTUB_GET_LOG: only if has HWSTUB_FEATURE_LOG. * The log is returned as part of the control transfer. @@ -119,11 +129,12 @@ struct usb_resp_info_features_t * the transfer is either a read or a write. */ /** - * HWSTUB_AES_OTP: only if has HWSTUB_FEATURE_AES_OTP. - * The control transfer contains the data to be en/decrypted and the data - * is sent back on the interrupt endpoint. The first 16-bytes of the data - * are interpreted as the IV. The output format is the same. - * The wValue field contains the parameters of the process. */ -#define HWSTUB_AES_OTP_ENCRYPT (1 << 0) + * HWSTUB_STOP: only if has HWSTUB_FEATURE_STOP. + * Stop hwstub. Several methods can be employed (not all may be supported). + * The method is stored in wValue and interpreted as follows: + * - reboot: immediately reboot the device + * - off: wait for USB disconnection and power off */ +#define HWSTUB_STOP_REBOOT 0 +#define HWSTUB_STOP_OFF 1 #endif /* __HWSTUB_PROTOCOL__ */ diff --git a/utils/hwstub/stub/stmp/target.c b/utils/hwstub/stub/stmp/target.c index 60411f908e..11516e5492 100644 --- a/utils/hwstub/stub/stmp/target.c +++ b/utils/hwstub/stub/stmp/target.c @@ -196,6 +196,11 @@ int target_get_info(int info, void **buffer) *buffer = &g_stmp; return sizeof(g_stmp); } + else if(info == HWSTUB_INFO_TARGET) + { + *buffer = &g_target; + return sizeof(g_target); + } else return -1; } diff --git a/utils/hwstub/tools/hwstub_shell.cpp b/utils/hwstub/tools/hwstub_shell.cpp index 58147319e0..69e580f88e 100644 --- a/utils/hwstub/tools/hwstub_shell.cpp +++ b/utils/hwstub/tools/hwstub_shell.cpp @@ -41,6 +41,7 @@ struct hwstub_device_t g_hwdev; struct usb_resp_info_version_t g_hwdev_ver; struct usb_resp_info_layout_t g_hwdev_layout; struct usb_resp_info_features_t g_hwdev_features; +struct usb_resp_info_target_t g_hwdev_target; struct usb_resp_info_stmp_t g_hwdev_stmp; lua_State *g_lua; @@ -253,12 +254,22 @@ bool my_lua_import_hwstub() lua_setfield(g_lua, -2, "ocram"); lua_setfield(g_lua, -2, "layout"); - lua_newtable(g_lua); // stmp - lua_pushinteger(g_lua, g_hwdev_stmp.chipid); - lua_setfield(g_lua, -2, "chipid"); - lua_pushinteger(g_lua, g_hwdev_stmp.rev); - lua_setfield(g_lua, -2, "rev"); - lua_setfield(g_lua, -2, "stmp"); + lua_newtable(g_lua); // target + lua_pushstring(g_lua, g_hwdev_target.name); + lua_setfield(g_lua, -2, "name"); + lua_pushinteger(g_lua, g_hwdev_target.id); + lua_setfield(g_lua, -2, "id"); + lua_setfield(g_lua, -2, "target"); + + if(g_hwdev_target.id == HWSTUB_TARGET_STMP) + { + lua_newtable(g_lua); // stmp + lua_pushinteger(g_lua, g_hwdev_stmp.chipid); + lua_setfield(g_lua, -2, "chipid"); + lua_pushinteger(g_lua, g_hwdev_stmp.rev); + lua_setfield(g_lua, -2, "rev"); + lua_setfield(g_lua, -2, "stmp"); + } lua_newtable(g_lua); // features lua_pushboolean(g_lua, !!(g_hwdev_features.feature_mask & HWSTUB_FEATURE_LOG)); @@ -269,8 +280,6 @@ bool my_lua_import_hwstub() lua_setfield(g_lua, -2, "call"); lua_pushboolean(g_lua, !!(g_hwdev_features.feature_mask & HWSTUB_FEATURE_JUMP)); lua_setfield(g_lua, -2, "jump"); - lua_pushboolean(g_lua, !!(g_hwdev_features.feature_mask & HWSTUB_FEATURE_AES_OTP)); - lua_setfield(g_lua, -2, "aes_otp"); lua_setfield(g_lua, -2, "features"); lua_pushlightuserdata(g_lua, (void *)&hw_read8); @@ -751,14 +760,25 @@ int main(int argc, char **argv) goto Lerr; } - // get STMP specific information - ret = hwstub_get_info(&g_hwdev, HWSTUB_INFO_STMP, &g_hwdev_stmp, sizeof(g_hwdev_stmp)); - if(ret != sizeof(g_hwdev_stmp)) + // get target + ret = hwstub_get_info(&g_hwdev, HWSTUB_INFO_TARGET, &g_hwdev_target, sizeof(g_hwdev_target)); + if(ret != sizeof(g_hwdev_target)) { - printf("Cannot get stmp: %d\n", ret); + printf("Cannot get target: %d\n", ret); goto Lerr; } + // get STMP specific information + if(g_hwdev_target.id == HWSTUB_TARGET_STMP) + { + ret = hwstub_get_info(&g_hwdev, HWSTUB_INFO_STMP, &g_hwdev_stmp, sizeof(g_hwdev_stmp)); + if(ret != sizeof(g_hwdev_stmp)) + { + printf("Cannot get stmp: %d\n", ret); + goto Lerr; + } + } + // dump ROM if(!g_quiet) { @@ -776,48 +796,6 @@ int main(int argc, char **argv) fclose(f); } - // test DCP -#if 0 - if(!g_quiet) - { - struct - { - uint8_t iv[16]; - uint8_t data[16]; - } __attribute__((packed)) dcp_test; - - for(int i = 0; i < 16; i++) - dcp_test.iv[i] = rand(); - for(int i = 0; i < 16; i++) - dcp_test.data[i] = rand(); - printf("DCP\n"); - printf(" IN\n"); - printf(" IV:"); - for(int i = 0; i < 16; i++) - printf(" %02x", dcp_test.iv[i]); - printf("\n"); - printf(" IV:"); - for(int i = 0; i < 16; i++) - printf(" %02x", dcp_test.data[i]); - printf("\n"); - - if(!hwstub_aes_otp(&g_hwdev, &dcp_test, sizeof(dcp_test), HWSTUB_AES_OTP_ENCRYPT)) - { - printf(" OUT\n"); - printf(" IV:"); - for(int i = 0; i < 16; i++) - printf(" %02x", dcp_test.iv[i]); - printf("\n"); - printf(" IV:"); - for(int i = 0; i < 16; i++) - printf(" %02x", dcp_test.data[i]); - printf("\n"); - } - else - printf("DCP error!\n"); - } -#endif - /** Init lua */ // create lua state diff --git a/utils/hwstub/tools/init.lua b/utils/hwstub/tools/init.lua index 142c77e20a..97d393dab1 100644 --- a/utils/hwstub/tools/init.lua +++ b/utils/hwstub/tools/init.lua @@ -40,6 +40,7 @@ do h:add("It contains some information about the device and the following methods."); h:add("* read8/16/32(a) reads a 8/16/32-bit integer at address a"); h:add("* write8/16/32(a, v) writes the 8/16/32-bit integer v at address a"); + h:add("* print_log() prints the device log"); h = HELP:create_topic("HW"); h:add("This variable redirects to the current soc under hwstub.soc and should be changed by calling hwstub:soc:select only."); @@ -70,6 +71,13 @@ if not hwstub.options.quiet then print(" device") print(" version: " .. string.format("%d.%d.%d", hwstub.dev.version.major, hwstub.dev.version.minor, hwstub.dev.version.revision)) + print(" target") + local id_str = string.char(bit32.extract(hwstub.dev.target.id, 0, 8), + bit32.extract(hwstub.dev.target.id, 8, 8), + bit32.extract(hwstub.dev.target.id, 16, 8), + bit32.extract(hwstub.dev.target.id, 24, 8)) + print(" id: " .. string.format("%#x (%s)", hwstub.dev.target.id, id_str)) + print(" name: " .. hwstub.dev.target.name) print(" layout") print(" on-chip ram") print(" code: " .. string.format("%#x bytes @ %#x", @@ -83,7 +91,6 @@ if not hwstub.options.quiet then print(" mem: " .. tostring(hwstub.dev.features.mem)) print(" call: " .. tostring(hwstub.dev.features.call)) print(" jump: " .. tostring(hwstub.dev.features.jump)) - print(" aes_otp: " .. tostring(hwstub.dev.features.aes_otp)) end -- -- cgit v1.2.3