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/tools/hwstub_shell.cpp | 86 ++++++++++++++----------------------- utils/hwstub/tools/init.lua | 9 +++- 2 files changed, 40 insertions(+), 55 deletions(-) (limited to 'utils/hwstub/tools') 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