diff options
Diffstat (limited to 'utils/hwstub/lib')
-rw-r--r-- | utils/hwstub/lib/Makefile | 17 | ||||
-rw-r--r-- | utils/hwstub/lib/hwemul_protocol.h | 1 | ||||
-rw-r--r-- | utils/hwstub/lib/hwstub.c (renamed from utils/hwstub/lib/hwemul.c) | 41 | ||||
-rw-r--r-- | utils/hwstub/lib/hwstub.h (renamed from utils/hwstub/lib/hwemul.h) | 39 | ||||
-rw-r--r-- | utils/hwstub/lib/hwstub_protocol.h | 1 |
5 files changed, 49 insertions, 50 deletions
diff --git a/utils/hwstub/lib/Makefile b/utils/hwstub/lib/Makefile index 7280fe8e38..7c455e4586 100644 --- a/utils/hwstub/lib/Makefile +++ b/utils/hwstub/lib/Makefile | |||
@@ -2,26 +2,19 @@ CC=gcc | |||
2 | AR=ar | 2 | AR=ar |
3 | CFLAGS=-W -Wall -O2 `pkg-config --cflags libusb-1.0` -std=c99 -g -fPIC | 3 | CFLAGS=-W -Wall -O2 `pkg-config --cflags libusb-1.0` -std=c99 -g -fPIC |
4 | LDFLAGS=`pkg-config --libs libusb-1.0` -fPIC | 4 | LDFLAGS=`pkg-config --libs libusb-1.0` -fPIC |
5 | LIB=libhwemul.a | 5 | LIB=libhwstub.a |
6 | REGTOOLS=../../regtools | 6 | SRC=$(wildcard *.c) |
7 | DESC=$(REGTOOLS)/desc | ||
8 | HWEMULGEN=$(REGTOOLS)/hwemulgen | ||
9 | HWEMULSOC_PREFIX=hwemul_soc | ||
10 | SRC=$(wildcard *.c) $(HWEMULSOC_PREFIX).c | ||
11 | OBJ=$(SRC:.c=.o) | 7 | OBJ=$(SRC:.c=.o) |
12 | 8 | ||
13 | all: $(LIB) $(EXEC) | 9 | all: $(LIB) |
14 | 10 | ||
15 | $(HWEMULSOC_PREFIX).c $(HWEMULSOC_PREFIX).h: | 11 | %.o: %.c |
16 | $(HWEMULGEN) $(DESC)/*.xml $(HWEMULSOC_PREFIX) | ||
17 | |||
18 | %.o: %.c $(HWEMULSOC_PREFIX).h | ||
19 | $(CC) $(CFLAGS) -c -o $@ $< | 12 | $(CC) $(CFLAGS) -c -o $@ $< |
20 | 13 | ||
21 | $(LIB): $(OBJ) | 14 | $(LIB): $(OBJ) |
22 | $(AR) rcs $@ $^ | 15 | $(AR) rcs $@ $^ |
23 | 16 | ||
24 | clean: | 17 | clean: |
25 | rm -rf $(OBJ) $(LIB) $(HWEMULSOC_PREFIX).c $(HWEMULSOC_PREFIX).h | 18 | rm -rf $(OBJ) $(LIB) |
26 | 19 | ||
27 | 20 | ||
diff --git a/utils/hwstub/lib/hwemul_protocol.h b/utils/hwstub/lib/hwemul_protocol.h deleted file mode 100644 index d3ffb6ce00..0000000000 --- a/utils/hwstub/lib/hwemul_protocol.h +++ /dev/null | |||
@@ -1 +0,0 @@ | |||
1 | #include "../hwemul_protocol.h" | ||
diff --git a/utils/hwstub/lib/hwemul.c b/utils/hwstub/lib/hwstub.c index 3e2e6de38a..92010e710b 100644 --- a/utils/hwstub/lib/hwemul.c +++ b/utils/hwstub/lib/hwstub.c | |||
@@ -18,15 +18,14 @@ | |||
18 | * KIND, either express or implied. | 18 | * KIND, either express or implied. |
19 | * | 19 | * |
20 | ****************************************************************************/ | 20 | ****************************************************************************/ |
21 | #include "hwemul.h" | 21 | #include "hwstub.h" |
22 | #include "hwemul_soc.h" | ||
23 | 22 | ||
24 | #ifndef MIN | 23 | #ifndef MIN |
25 | #define MIN(a,b) ((a) < (b) ? (a) : (b)) | 24 | #define MIN(a,b) ((a) < (b) ? (a) : (b)) |
26 | #endif | 25 | #endif |
27 | 26 | ||
28 | /* requires then ->handle field only */ | 27 | /* requires then ->handle field only */ |
29 | int hwemul_probe(struct hwemul_device_t *dev) | 28 | int hwstub_probe(struct hwstub_device_t *dev) |
30 | { | 29 | { |
31 | libusb_device *mydev = libusb_get_device(dev->handle); | 30 | libusb_device *mydev = libusb_get_device(dev->handle); |
32 | 31 | ||
@@ -44,9 +43,9 @@ int hwemul_probe(struct hwemul_device_t *dev) | |||
44 | const struct libusb_interface_descriptor *interface = | 43 | const struct libusb_interface_descriptor *interface = |
45 | &config->interface[intf].altsetting[0]; | 44 | &config->interface[intf].altsetting[0]; |
46 | if(interface->bNumEndpoints != 3 || | 45 | if(interface->bNumEndpoints != 3 || |
47 | interface->bInterfaceClass != HWEMUL_CLASS || | 46 | interface->bInterfaceClass != HWSTUB_CLASS || |
48 | interface->bInterfaceSubClass != HWEMUL_SUBCLASS || | 47 | interface->bInterfaceSubClass != HWSTUB_SUBCLASS || |
49 | interface->bInterfaceProtocol != HWEMUL_PROTOCOL) | 48 | interface->bInterfaceProtocol != HWSTUB_PROTOCOL) |
50 | continue; | 49 | continue; |
51 | dev->intf = intf; | 50 | dev->intf = intf; |
52 | dev->bulk_in = dev->bulk_out = dev->int_in = -1; | 51 | dev->bulk_in = dev->bulk_out = dev->int_in = -1; |
@@ -73,26 +72,26 @@ int hwemul_probe(struct hwemul_device_t *dev) | |||
73 | return libusb_claim_interface(dev->handle, intf); | 72 | return libusb_claim_interface(dev->handle, intf); |
74 | } | 73 | } |
75 | 74 | ||
76 | int hwemul_release(struct hwemul_device_t *dev) | 75 | int hwstub_release(struct hwstub_device_t *dev) |
77 | { | 76 | { |
78 | return libusb_release_interface(dev->handle, dev->intf); | 77 | return libusb_release_interface(dev->handle, dev->intf); |
79 | } | 78 | } |
80 | 79 | ||
81 | int hwemul_get_info(struct hwemul_device_t *dev, uint16_t idx, void *info, size_t sz) | 80 | int hwstub_get_info(struct hwstub_device_t *dev, uint16_t idx, void *info, size_t sz) |
82 | { | 81 | { |
83 | return libusb_control_transfer(dev->handle, | 82 | return libusb_control_transfer(dev->handle, |
84 | LIBUSB_REQUEST_TYPE_CLASS | LIBUSB_RECIPIENT_DEVICE | LIBUSB_ENDPOINT_IN, | 83 | LIBUSB_REQUEST_TYPE_CLASS | LIBUSB_RECIPIENT_DEVICE | LIBUSB_ENDPOINT_IN, |
85 | HWEMUL_GET_INFO, 0, idx, info, sz, 1000); | 84 | HWSTUB_GET_INFO, 0, idx, info, sz, 1000); |
86 | } | 85 | } |
87 | 86 | ||
88 | int hwemul_get_log(struct hwemul_device_t *dev, void *buf, size_t sz) | 87 | int hwstub_get_log(struct hwstub_device_t *dev, void *buf, size_t sz) |
89 | { | 88 | { |
90 | return libusb_control_transfer(dev->handle, | 89 | return libusb_control_transfer(dev->handle, |
91 | LIBUSB_REQUEST_TYPE_CLASS | LIBUSB_RECIPIENT_DEVICE | LIBUSB_ENDPOINT_IN, | 90 | LIBUSB_REQUEST_TYPE_CLASS | LIBUSB_RECIPIENT_DEVICE | LIBUSB_ENDPOINT_IN, |
92 | HWEMUL_GET_LOG, 0, 0, buf, sz, 1000); | 91 | HWSTUB_GET_LOG, 0, 0, buf, sz, 1000); |
93 | } | 92 | } |
94 | 93 | ||
95 | int hwemul_rw_mem(struct hwemul_device_t *dev, int read, uint32_t addr, void *buf, size_t sz) | 94 | int hwstub_rw_mem(struct hwstub_device_t *dev, int read, uint32_t addr, void *buf, size_t sz) |
96 | { | 95 | { |
97 | size_t tot_sz = 0; | 96 | size_t tot_sz = 0; |
98 | while(sz) | 97 | while(sz) |
@@ -101,7 +100,7 @@ int hwemul_rw_mem(struct hwemul_device_t *dev, int read, uint32_t addr, void *bu | |||
101 | int ret = libusb_control_transfer(dev->handle, | 100 | int ret = libusb_control_transfer(dev->handle, |
102 | LIBUSB_REQUEST_TYPE_CLASS | LIBUSB_RECIPIENT_DEVICE | | 101 | LIBUSB_REQUEST_TYPE_CLASS | LIBUSB_RECIPIENT_DEVICE | |
103 | (read ? LIBUSB_ENDPOINT_IN : LIBUSB_ENDPOINT_OUT), | 102 | (read ? LIBUSB_ENDPOINT_IN : LIBUSB_ENDPOINT_OUT), |
104 | HWEMUL_RW_MEM, addr & 0xffff, addr >> 16, buf, xfer, 1000); | 103 | HWSTUB_RW_MEM, addr & 0xffff, addr >> 16, buf, xfer, 1000); |
105 | if(ret != xfer) | 104 | if(ret != xfer) |
106 | return ret; | 105 | return ret; |
107 | sz -= xfer; | 106 | sz -= xfer; |
@@ -112,23 +111,23 @@ int hwemul_rw_mem(struct hwemul_device_t *dev, int read, uint32_t addr, void *bu | |||
112 | return tot_sz; | 111 | return tot_sz; |
113 | } | 112 | } |
114 | 113 | ||
115 | int hwemul_call(struct hwemul_device_t *dev, uint32_t addr) | 114 | int hwstub_call(struct hwstub_device_t *dev, uint32_t addr) |
116 | { | 115 | { |
117 | return libusb_control_transfer(dev->handle, | 116 | return libusb_control_transfer(dev->handle, |
118 | LIBUSB_REQUEST_TYPE_CLASS | LIBUSB_RECIPIENT_DEVICE | | 117 | LIBUSB_REQUEST_TYPE_CLASS | LIBUSB_RECIPIENT_DEVICE | |
119 | LIBUSB_ENDPOINT_OUT, HWEMUL_CALL, addr & 0xffff, addr >> 16, NULL, 0, | 118 | LIBUSB_ENDPOINT_OUT, HWSTUB_CALL, addr & 0xffff, addr >> 16, NULL, 0, |
120 | 1000); | 119 | 1000); |
121 | } | 120 | } |
122 | 121 | ||
123 | int hwemul_jump(struct hwemul_device_t *dev, uint32_t addr) | 122 | int hwstub_jump(struct hwstub_device_t *dev, uint32_t addr) |
124 | { | 123 | { |
125 | return libusb_control_transfer(dev->handle, | 124 | return libusb_control_transfer(dev->handle, |
126 | LIBUSB_REQUEST_TYPE_CLASS | LIBUSB_RECIPIENT_DEVICE | | 125 | LIBUSB_REQUEST_TYPE_CLASS | LIBUSB_RECIPIENT_DEVICE | |
127 | LIBUSB_ENDPOINT_OUT, HWEMUL_JUMP, addr & 0xffff, addr >> 16, NULL, 0, | 126 | LIBUSB_ENDPOINT_OUT, HWSTUB_JUMP, addr & 0xffff, addr >> 16, NULL, 0, |
128 | 1000); | 127 | 1000); |
129 | } | 128 | } |
130 | 129 | ||
131 | const char *hwemul_get_product_string(struct usb_resp_info_stmp_t *stmp) | 130 | const char *hwstub_get_product_string(struct usb_resp_info_stmp_t *stmp) |
132 | { | 131 | { |
133 | switch(stmp->chipid) | 132 | switch(stmp->chipid) |
134 | { | 133 | { |
@@ -139,7 +138,7 @@ const char *hwemul_get_product_string(struct usb_resp_info_stmp_t *stmp) | |||
139 | } | 138 | } |
140 | } | 139 | } |
141 | 140 | ||
142 | const char *hwemul_get_rev_string(struct usb_resp_info_stmp_t *stmp) | 141 | const char *hwstub_get_rev_string(struct usb_resp_info_stmp_t *stmp) |
143 | { | 142 | { |
144 | switch(stmp->chipid) | 143 | switch(stmp->chipid) |
145 | { | 144 | { |
@@ -159,11 +158,11 @@ const char *hwemul_get_rev_string(struct usb_resp_info_stmp_t *stmp) | |||
159 | } | 158 | } |
160 | } | 159 | } |
161 | 160 | ||
162 | int hwemul_aes_otp(struct hwemul_device_t *dev, void *buf, size_t sz, uint16_t param) | 161 | int hwstub_aes_otp(struct hwstub_device_t *dev, void *buf, size_t sz, uint16_t param) |
163 | { | 162 | { |
164 | int ret = libusb_control_transfer(dev->handle, | 163 | int ret = libusb_control_transfer(dev->handle, |
165 | LIBUSB_REQUEST_TYPE_CLASS | LIBUSB_RECIPIENT_DEVICE | | 164 | LIBUSB_REQUEST_TYPE_CLASS | LIBUSB_RECIPIENT_DEVICE | |
166 | LIBUSB_ENDPOINT_OUT, HWEMUL_AES_OTP, param, 0, buf, sz, | 165 | LIBUSB_ENDPOINT_OUT, HWSTUB_AES_OTP, param, 0, buf, sz, |
167 | 1000); | 166 | 1000); |
168 | if(ret <0 || (unsigned)ret != sz) | 167 | if(ret <0 || (unsigned)ret != sz) |
169 | return -1; | 168 | return -1; |
diff --git a/utils/hwstub/lib/hwemul.h b/utils/hwstub/lib/hwstub.h index 376ba65381..ed058dfa3b 100644 --- a/utils/hwstub/lib/hwemul.h +++ b/utils/hwstub/lib/hwstub.h | |||
@@ -18,12 +18,15 @@ | |||
18 | * KIND, either express or implied. | 18 | * KIND, either express or implied. |
19 | * | 19 | * |
20 | ****************************************************************************/ | 20 | ****************************************************************************/ |
21 | #ifndef __HWEMUL__ | 21 | #ifndef __HWSTUB__ |
22 | #define __HWEMUL__ | 22 | #define __HWSTUB__ |
23 | 23 | ||
24 | #include <libusb.h> | 24 | #include <libusb.h> |
25 | #include "hwemul_protocol.h" | 25 | #include "hwstub_protocol.h" |
26 | #include "hwemul_soc.h" | 26 | |
27 | #ifdef __cplusplus | ||
28 | extern "C" { | ||
29 | #endif | ||
27 | 30 | ||
28 | /** | 31 | /** |
29 | * | 32 | * |
@@ -31,7 +34,7 @@ | |||
31 | * | 34 | * |
32 | */ | 35 | */ |
33 | 36 | ||
34 | struct hwemul_device_t | 37 | struct hwstub_device_t |
35 | { | 38 | { |
36 | libusb_device_handle *handle; | 39 | libusb_device_handle *handle; |
37 | int intf; | 40 | int intf; |
@@ -41,23 +44,27 @@ struct hwemul_device_t | |||
41 | }; | 44 | }; |
42 | 45 | ||
43 | /* Requires then ->handle field only. Returns 0 on success */ | 46 | /* Requires then ->handle field only. Returns 0 on success */ |
44 | int hwemul_probe(struct hwemul_device_t *dev); | 47 | int hwstub_probe(struct hwstub_device_t *dev); |
45 | /* Returns 0 on success */ | 48 | /* Returns 0 on success */ |
46 | int hwemul_release(struct hwemul_device_t *dev); | 49 | int hwstub_release(struct hwstub_device_t *dev); |
47 | 50 | ||
48 | /* Returns number of bytes filled */ | 51 | /* Returns number of bytes filled */ |
49 | int hwemul_get_info(struct hwemul_device_t *dev, uint16_t idx, void *info, size_t sz); | 52 | int hwstub_get_info(struct hwstub_device_t *dev, uint16_t idx, void *info, size_t sz); |
50 | /* Returns number of bytes filled */ | 53 | /* Returns number of bytes filled */ |
51 | int hwemul_get_log(struct hwemul_device_t *dev, void *buf, size_t sz); | 54 | int hwstub_get_log(struct hwstub_device_t *dev, void *buf, size_t sz); |
52 | /* Returns number of bytes written/read or <0 on error */ | 55 | /* Returns number of bytes written/read or <0 on error */ |
53 | int hwemul_rw_mem(struct hwemul_device_t *dev, int read, uint32_t addr, void *buf, size_t sz); | 56 | int hwstub_rw_mem(struct hwstub_device_t *dev, int read, uint32_t addr, void *buf, size_t sz); |
54 | /* Returns <0 on error */ | 57 | /* Returns <0 on error */ |
55 | int hwemul_call(struct hwemul_device_t *dev, uint32_t addr); | 58 | int hwstub_call(struct hwstub_device_t *dev, uint32_t addr); |
56 | int hwemul_jump(struct hwemul_device_t *dev, uint32_t addr); | 59 | int hwstub_jump(struct hwstub_device_t *dev, uint32_t addr); |
57 | /* Returns <0 on error. The size must be a multiple of 16. */ | 60 | /* Returns <0 on error. The size must be a multiple of 16. */ |
58 | int hwemul_aes_otp(struct hwemul_device_t *dev, void *buf, size_t sz, uint16_t param); | 61 | int hwstub_aes_otp(struct hwstub_device_t *dev, void *buf, size_t sz, uint16_t param); |
62 | |||
63 | const char *hwstub_get_product_string(struct usb_resp_info_stmp_t *stmp); | ||
64 | const char *hwstub_get_rev_string(struct usb_resp_info_stmp_t *stmp); | ||
59 | 65 | ||
60 | const char *hwemul_get_product_string(struct usb_resp_info_stmp_t *stmp); | 66 | #ifdef __cplusplus |
61 | const char *hwemul_get_rev_string(struct usb_resp_info_stmp_t *stmp); | 67 | } // extern "C" |
68 | #endif | ||
62 | 69 | ||
63 | #endif /* __HWEMUL__ */ \ No newline at end of file | 70 | #endif /* __HWSTUB__ */ \ No newline at end of file |
diff --git a/utils/hwstub/lib/hwstub_protocol.h b/utils/hwstub/lib/hwstub_protocol.h new file mode 100644 index 0000000000..35510fa9b2 --- /dev/null +++ b/utils/hwstub/lib/hwstub_protocol.h | |||
@@ -0,0 +1 @@ | |||
#include "../hwstub_protocol.h" | |||