summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--utils/hwstub/hwstub_protocol.h41
-rw-r--r--utils/hwstub/stub/stmp/target.c5
-rw-r--r--utils/hwstub/tools/hwstub_shell.cpp86
-rw-r--r--utils/hwstub/tools/init.lua9
4 files changed, 71 insertions, 70 deletions
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 @@
26#define HWSTUB_PROTOCOL 0x1d 26#define HWSTUB_PROTOCOL 0x1d
27 27
28#define HWSTUB_VERSION_MAJOR 2 28#define HWSTUB_VERSION_MAJOR 2
29#define HWSTUB_VERSION_MINOR 9 29#define HWSTUB_VERSION_MINOR 11
30#define HWSTUB_VERSION_REV 2 30#define HWSTUB_VERSION_REV 1
31 31
32#define HWSTUB_USB_VID 0xfee1 32#define HWSTUB_USB_VID 0xfee1
33#define HWSTUB_USB_PID 0xdead 33#define HWSTUB_USB_PID 0xdead
@@ -46,17 +46,18 @@
46#define HWSTUB_RW_MEM 2 /* optional */ 46#define HWSTUB_RW_MEM 2 /* optional */
47#define HWSTUB_CALL 3 /* optional */ 47#define HWSTUB_CALL 3 /* optional */
48#define HWSTUB_JUMP 4 /* optional */ 48#define HWSTUB_JUMP 4 /* optional */
49#define HWSTUB_AES_OTP 5 /* optional */ 49#define HWSTUB_STOP 5 /* optional */
50 50
51/** 51/**
52 * HWSTUB_GET_INFO: get some information about an aspect of the device. 52 * HWSTUB_GET_INFO: get some information about an aspect of the device.
53 * The wIndex field of the SETUP specifies which information to get. */ 53 * The wIndex field of the SETUP specifies which information to get. */
54 54
55/* list of possible information */ 55/* list of possible information */
56#define HWSTUB_INFO_VERSION 0 56#define HWSTUB_INFO_VERSION 0 /* mandatory */
57#define HWSTUB_INFO_LAYOUT 1 57#define HWSTUB_INFO_LAYOUT 1 /* mandatory */
58#define HWSTUB_INFO_STMP 2 58#define HWSTUB_INFO_STMP 2 /* optional */
59#define HWSTUB_INFO_FEATURES 3 59#define HWSTUB_INFO_FEATURES 3 /* mandatory */
60#define HWSTUB_INFO_TARGET 4 /* mandatory */
60 61
61struct usb_resp_info_version_t 62struct usb_resp_info_version_t
62{ 63{
@@ -89,14 +90,23 @@ struct usb_resp_info_stmp_t
89#define HWSTUB_FEATURE_LOG (1 << 0) 90#define HWSTUB_FEATURE_LOG (1 << 0)
90#define HWSTUB_FEATURE_MEM (1 << 1) 91#define HWSTUB_FEATURE_MEM (1 << 1)
91#define HWSTUB_FEATURE_CALL (1 << 2) 92#define HWSTUB_FEATURE_CALL (1 << 2)
92#define HWSTUB_FEATURE_JUMP (1 << 2) 93#define HWSTUB_FEATURE_JUMP (1 << 3)
93#define HWSTUB_FEATURE_AES_OTP (1 << 3) 94#define HWSTUB_FEATURE_STOP (1 << 4)
94 95
95struct usb_resp_info_features_t 96struct usb_resp_info_features_t
96{ 97{
97 uint32_t feature_mask; 98 uint32_t feature_mask;
98}; 99};
99 100
101#define HWSTUB_TARGET_UNK ('U' | 'N' << 8 | 'K' << 16 | ' ' << 24)
102#define HWSTUB_TARGET_STMP ('S' | 'T' << 8 | 'M' << 16 | 'P' << 24)
103
104struct usb_resp_info_target_t
105{
106 uint32_t id;
107 char name[60];
108};
109
100/** 110/**
101 * HWSTUB_GET_LOG: only if has HWSTUB_FEATURE_LOG. 111 * HWSTUB_GET_LOG: only if has HWSTUB_FEATURE_LOG.
102 * The log is returned as part of the control transfer. 112 * The log is returned as part of the control transfer.
@@ -119,11 +129,12 @@ struct usb_resp_info_features_t
119 * the transfer is either a read or a write. */ 129 * the transfer is either a read or a write. */
120 130
121/** 131/**
122 * HWSTUB_AES_OTP: only if has HWSTUB_FEATURE_AES_OTP. 132 * HWSTUB_STOP: only if has HWSTUB_FEATURE_STOP.
123 * The control transfer contains the data to be en/decrypted and the data 133 * Stop hwstub. Several methods can be employed (not all may be supported).
124 * is sent back on the interrupt endpoint. The first 16-bytes of the data 134 * The method is stored in wValue and interpreted as follows:
125 * are interpreted as the IV. The output format is the same. 135 * - reboot: immediately reboot the device
126 * The wValue field contains the parameters of the process. */ 136 * - off: wait for USB disconnection and power off */
127#define HWSTUB_AES_OTP_ENCRYPT (1 << 0) 137#define HWSTUB_STOP_REBOOT 0
138#define HWSTUB_STOP_OFF 1
128 139
129#endif /* __HWSTUB_PROTOCOL__ */ 140#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)
196 *buffer = &g_stmp; 196 *buffer = &g_stmp;
197 return sizeof(g_stmp); 197 return sizeof(g_stmp);
198 } 198 }
199 else if(info == HWSTUB_INFO_TARGET)
200 {
201 *buffer = &g_target;
202 return sizeof(g_target);
203 }
199 else 204 else
200 return -1; 205 return -1;
201} 206}
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;
41struct usb_resp_info_version_t g_hwdev_ver; 41struct usb_resp_info_version_t g_hwdev_ver;
42struct usb_resp_info_layout_t g_hwdev_layout; 42struct usb_resp_info_layout_t g_hwdev_layout;
43struct usb_resp_info_features_t g_hwdev_features; 43struct usb_resp_info_features_t g_hwdev_features;
44struct usb_resp_info_target_t g_hwdev_target;
44struct usb_resp_info_stmp_t g_hwdev_stmp; 45struct usb_resp_info_stmp_t g_hwdev_stmp;
45lua_State *g_lua; 46lua_State *g_lua;
46 47
@@ -253,12 +254,22 @@ bool my_lua_import_hwstub()
253 lua_setfield(g_lua, -2, "ocram"); 254 lua_setfield(g_lua, -2, "ocram");
254 lua_setfield(g_lua, -2, "layout"); 255 lua_setfield(g_lua, -2, "layout");
255 256
256 lua_newtable(g_lua); // stmp 257 lua_newtable(g_lua); // target
257 lua_pushinteger(g_lua, g_hwdev_stmp.chipid); 258 lua_pushstring(g_lua, g_hwdev_target.name);
258 lua_setfield(g_lua, -2, "chipid"); 259 lua_setfield(g_lua, -2, "name");
259 lua_pushinteger(g_lua, g_hwdev_stmp.rev); 260 lua_pushinteger(g_lua, g_hwdev_target.id);
260 lua_setfield(g_lua, -2, "rev"); 261 lua_setfield(g_lua, -2, "id");
261 lua_setfield(g_lua, -2, "stmp"); 262 lua_setfield(g_lua, -2, "target");
263
264 if(g_hwdev_target.id == HWSTUB_TARGET_STMP)
265 {
266 lua_newtable(g_lua); // stmp
267 lua_pushinteger(g_lua, g_hwdev_stmp.chipid);
268 lua_setfield(g_lua, -2, "chipid");
269 lua_pushinteger(g_lua, g_hwdev_stmp.rev);
270 lua_setfield(g_lua, -2, "rev");
271 lua_setfield(g_lua, -2, "stmp");
272 }
262 273
263 lua_newtable(g_lua); // features 274 lua_newtable(g_lua); // features
264 lua_pushboolean(g_lua, !!(g_hwdev_features.feature_mask & HWSTUB_FEATURE_LOG)); 275 lua_pushboolean(g_lua, !!(g_hwdev_features.feature_mask & HWSTUB_FEATURE_LOG));
@@ -269,8 +280,6 @@ bool my_lua_import_hwstub()
269 lua_setfield(g_lua, -2, "call"); 280 lua_setfield(g_lua, -2, "call");
270 lua_pushboolean(g_lua, !!(g_hwdev_features.feature_mask & HWSTUB_FEATURE_JUMP)); 281 lua_pushboolean(g_lua, !!(g_hwdev_features.feature_mask & HWSTUB_FEATURE_JUMP));
271 lua_setfield(g_lua, -2, "jump"); 282 lua_setfield(g_lua, -2, "jump");
272 lua_pushboolean(g_lua, !!(g_hwdev_features.feature_mask & HWSTUB_FEATURE_AES_OTP));
273 lua_setfield(g_lua, -2, "aes_otp");
274 lua_setfield(g_lua, -2, "features"); 283 lua_setfield(g_lua, -2, "features");
275 284
276 lua_pushlightuserdata(g_lua, (void *)&hw_read8); 285 lua_pushlightuserdata(g_lua, (void *)&hw_read8);
@@ -751,14 +760,25 @@ int main(int argc, char **argv)
751 goto Lerr; 760 goto Lerr;
752 } 761 }
753 762
754 // get STMP specific information 763 // get target
755 ret = hwstub_get_info(&g_hwdev, HWSTUB_INFO_STMP, &g_hwdev_stmp, sizeof(g_hwdev_stmp)); 764 ret = hwstub_get_info(&g_hwdev, HWSTUB_INFO_TARGET, &g_hwdev_target, sizeof(g_hwdev_target));
756 if(ret != sizeof(g_hwdev_stmp)) 765 if(ret != sizeof(g_hwdev_target))
757 { 766 {
758 printf("Cannot get stmp: %d\n", ret); 767 printf("Cannot get target: %d\n", ret);
759 goto Lerr; 768 goto Lerr;
760 } 769 }
761 770
771 // get STMP specific information
772 if(g_hwdev_target.id == HWSTUB_TARGET_STMP)
773 {
774 ret = hwstub_get_info(&g_hwdev, HWSTUB_INFO_STMP, &g_hwdev_stmp, sizeof(g_hwdev_stmp));
775 if(ret != sizeof(g_hwdev_stmp))
776 {
777 printf("Cannot get stmp: %d\n", ret);
778 goto Lerr;
779 }
780 }
781
762 // dump ROM 782 // dump ROM
763 if(!g_quiet) 783 if(!g_quiet)
764 { 784 {
@@ -776,48 +796,6 @@ int main(int argc, char **argv)
776 fclose(f); 796 fclose(f);
777 } 797 }
778 798
779 // test DCP
780#if 0
781 if(!g_quiet)
782 {
783 struct
784 {
785 uint8_t iv[16];
786 uint8_t data[16];
787 } __attribute__((packed)) dcp_test;
788
789 for(int i = 0; i < 16; i++)
790 dcp_test.iv[i] = rand();
791 for(int i = 0; i < 16; i++)
792 dcp_test.data[i] = rand();
793 printf("DCP\n");
794 printf(" IN\n");
795 printf(" IV:");
796 for(int i = 0; i < 16; i++)
797 printf(" %02x", dcp_test.iv[i]);
798 printf("\n");
799 printf(" IV:");
800 for(int i = 0; i < 16; i++)
801 printf(" %02x", dcp_test.data[i]);
802 printf("\n");
803
804 if(!hwstub_aes_otp(&g_hwdev, &dcp_test, sizeof(dcp_test), HWSTUB_AES_OTP_ENCRYPT))
805 {
806 printf(" OUT\n");
807 printf(" IV:");
808 for(int i = 0; i < 16; i++)
809 printf(" %02x", dcp_test.iv[i]);
810 printf("\n");
811 printf(" IV:");
812 for(int i = 0; i < 16; i++)
813 printf(" %02x", dcp_test.data[i]);
814 printf("\n");
815 }
816 else
817 printf("DCP error!\n");
818 }
819#endif
820
821 /** Init lua */ 799 /** Init lua */
822 800
823 // create lua state 801 // 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
40 h:add("It contains some information about the device and the following methods."); 40 h:add("It contains some information about the device and the following methods.");
41 h:add("* read8/16/32(a) reads a 8/16/32-bit integer at address a"); 41 h:add("* read8/16/32(a) reads a 8/16/32-bit integer at address a");
42 h:add("* write8/16/32(a, v) writes the 8/16/32-bit integer v at address a"); 42 h:add("* write8/16/32(a, v) writes the 8/16/32-bit integer v at address a");
43 h:add("* print_log() prints the device log");
43 44
44 h = HELP:create_topic("HW"); 45 h = HELP:create_topic("HW");
45 h:add("This variable redirects to the current soc under hwstub.soc and should be changed by calling hwstub:soc:select only."); 46 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
70 print(" device") 71 print(" device")
71 print(" version: " .. string.format("%d.%d.%d", hwstub.dev.version.major, 72 print(" version: " .. string.format("%d.%d.%d", hwstub.dev.version.major,
72 hwstub.dev.version.minor, hwstub.dev.version.revision)) 73 hwstub.dev.version.minor, hwstub.dev.version.revision))
74 print(" target")
75 local id_str = string.char(bit32.extract(hwstub.dev.target.id, 0, 8),
76 bit32.extract(hwstub.dev.target.id, 8, 8),
77 bit32.extract(hwstub.dev.target.id, 16, 8),
78 bit32.extract(hwstub.dev.target.id, 24, 8))
79 print(" id: " .. string.format("%#x (%s)", hwstub.dev.target.id, id_str))
80 print(" name: " .. hwstub.dev.target.name)
73 print(" layout") 81 print(" layout")
74 print(" on-chip ram") 82 print(" on-chip ram")
75 print(" code: " .. string.format("%#x bytes @ %#x", 83 print(" code: " .. string.format("%#x bytes @ %#x",
@@ -83,7 +91,6 @@ if not hwstub.options.quiet then
83 print(" mem: " .. tostring(hwstub.dev.features.mem)) 91 print(" mem: " .. tostring(hwstub.dev.features.mem))
84 print(" call: " .. tostring(hwstub.dev.features.call)) 92 print(" call: " .. tostring(hwstub.dev.features.call))
85 print(" jump: " .. tostring(hwstub.dev.features.jump)) 93 print(" jump: " .. tostring(hwstub.dev.features.jump))
86 print(" aes_otp: " .. tostring(hwstub.dev.features.aes_otp))
87end 94end
88 95
89-- 96--