1
0
Fork 0
forked from len0rd/rockbox

hwstub: enhance protocol with more functions

Change-Id: I7944249c2f7ea3e180e7b79ee8ae402d1d0742d3
This commit is contained in:
Amaury Pouly 2013-07-13 17:38:34 +02:00
parent 140783ef66
commit f617da0552
4 changed files with 71 additions and 70 deletions

View file

@ -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