summaryrefslogtreecommitdiffstats
path: root/utils/hwstub/lib
diff options
context:
space:
mode:
authorAmaury Pouly <amaury.pouly@gmail.com>2013-06-13 02:02:53 +0200
committerAmaury Pouly <amaury.pouly@gmail.com>2013-06-13 02:25:15 +0200
commitc5357940ab0108b4102442d07825c44d5be0d22f (patch)
treeddfdd9744b1f0ac037fed1c802329cb4542f376b /utils/hwstub/lib
parent934e1e15af6f2b7bcfdd9dbe8a3a6393ffe5a4a1 (diff)
downloadrockbox-c5357940ab0108b4102442d07825c44d5be0d22f.tar.gz
rockbox-c5357940ab0108b4102442d07825c44d5be0d22f.tar.bz2
rockbox-c5357940ab0108b4102442d07825c44d5be0d22f.zip
hwstub: major improvement in the stub and the tools
Fix the stub in many way to correctly detect the STMP family and act upon that. Drop some unused commands and bump version. Rewrite the tool to allows scripting in lua and load the register description from an XML file using the regtools. Introduce a new tool to load and run code using the hwstub (either binary format or Rockbox additive scramble format). Also switch to an optimise version of the memcpy/move/set functions to correctly handle alignement issue (like writing a full word/half-word when possible for registers which is crucial) Change-Id: Id1d5cfe0b1b47e8b43900d32c5cd6eafae6414f6
Diffstat (limited to 'utils/hwstub/lib')
-rw-r--r--utils/hwstub/lib/Makefile17
-rw-r--r--utils/hwstub/lib/hwemul_protocol.h1
-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.h1
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
AR=ar
CFLAGS=-W -Wall -O2 `pkg-config --cflags libusb-1.0` -std=c99 -g -fPIC
LDFLAGS=`pkg-config --libs libusb-1.0` -fPIC
-LIB=libhwemul.a
-REGTOOLS=../../regtools
-DESC=$(REGTOOLS)/desc
-HWEMULGEN=$(REGTOOLS)/hwemulgen
-HWEMULSOC_PREFIX=hwemul_soc
-SRC=$(wildcard *.c) $(HWEMULSOC_PREFIX).c
+LIB=libhwstub.a
+SRC=$(wildcard *.c)
OBJ=$(SRC:.c=.o)
-all: $(LIB) $(EXEC)
+all: $(LIB)
-$(HWEMULSOC_PREFIX).c $(HWEMULSOC_PREFIX).h:
- $(HWEMULGEN) $(DESC)/*.xml $(HWEMULSOC_PREFIX)
-
-%.o: %.c $(HWEMULSOC_PREFIX).h
+%.o: %.c
$(CC) $(CFLAGS) -c -o $@ $<
$(LIB): $(OBJ)
$(AR) rcs $@ $^
clean:
- rm -rf $(OBJ) $(LIB) $(HWEMULSOC_PREFIX).c $(HWEMULSOC_PREFIX).h
+ rm -rf $(OBJ) $(LIB)
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 @@
-#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 @@
* KIND, either express or implied.
*
****************************************************************************/
-#include "hwemul.h"
-#include "hwemul_soc.h"
+#include "hwstub.h"
#ifndef MIN
#define MIN(a,b) ((a) < (b) ? (a) : (b))
#endif
/* requires then ->handle field only */
-int hwemul_probe(struct hwemul_device_t *dev)
+int hwstub_probe(struct hwstub_device_t *dev)
{
libusb_device *mydev = libusb_get_device(dev->handle);
@@ -44,9 +43,9 @@ int hwemul_probe(struct hwemul_device_t *dev)
const struct libusb_interface_descriptor *interface =
&config->interface[intf].altsetting[0];
if(interface->bNumEndpoints != 3 ||
- interface->bInterfaceClass != HWEMUL_CLASS ||
- interface->bInterfaceSubClass != HWEMUL_SUBCLASS ||
- interface->bInterfaceProtocol != HWEMUL_PROTOCOL)
+ interface->bInterfaceClass != HWSTUB_CLASS ||
+ interface->bInterfaceSubClass != HWSTUB_SUBCLASS ||
+ interface->bInterfaceProtocol != HWSTUB_PROTOCOL)
continue;
dev->intf = intf;
dev->bulk_in = dev->bulk_out = dev->int_in = -1;
@@ -73,26 +72,26 @@ int hwemul_probe(struct hwemul_device_t *dev)
return libusb_claim_interface(dev->handle, intf);
}
-int hwemul_release(struct hwemul_device_t *dev)
+int hwstub_release(struct hwstub_device_t *dev)
{
return libusb_release_interface(dev->handle, dev->intf);
}
-int hwemul_get_info(struct hwemul_device_t *dev, uint16_t idx, void *info, size_t sz)
+int hwstub_get_info(struct hwstub_device_t *dev, uint16_t idx, void *info, size_t sz)
{
return libusb_control_transfer(dev->handle,
LIBUSB_REQUEST_TYPE_CLASS | LIBUSB_RECIPIENT_DEVICE | LIBUSB_ENDPOINT_IN,
- HWEMUL_GET_INFO, 0, idx, info, sz, 1000);
+ HWSTUB_GET_INFO, 0, idx, info, sz, 1000);
}
-int hwemul_get_log(struct hwemul_device_t *dev, void *buf, size_t sz)
+int hwstub_get_log(struct hwstub_device_t *dev, void *buf, size_t sz)
{
return libusb_control_transfer(dev->handle,
LIBUSB_REQUEST_TYPE_CLASS | LIBUSB_RECIPIENT_DEVICE | LIBUSB_ENDPOINT_IN,
- HWEMUL_GET_LOG, 0, 0, buf, sz, 1000);
+ HWSTUB_GET_LOG, 0, 0, buf, sz, 1000);
}
-int hwemul_rw_mem(struct hwemul_device_t *dev, int read, uint32_t addr, void *buf, size_t sz)
+int hwstub_rw_mem(struct hwstub_device_t *dev, int read, uint32_t addr, void *buf, size_t sz)
{
size_t tot_sz = 0;
while(sz)
@@ -101,7 +100,7 @@ int hwemul_rw_mem(struct hwemul_device_t *dev, int read, uint32_t addr, void *bu
int ret = libusb_control_transfer(dev->handle,
LIBUSB_REQUEST_TYPE_CLASS | LIBUSB_RECIPIENT_DEVICE |
(read ? LIBUSB_ENDPOINT_IN : LIBUSB_ENDPOINT_OUT),
- HWEMUL_RW_MEM, addr & 0xffff, addr >> 16, buf, xfer, 1000);
+ HWSTUB_RW_MEM, addr & 0xffff, addr >> 16, buf, xfer, 1000);
if(ret != xfer)
return ret;
sz -= xfer;
@@ -112,23 +111,23 @@ int hwemul_rw_mem(struct hwemul_device_t *dev, int read, uint32_t addr, void *bu
return tot_sz;
}
-int hwemul_call(struct hwemul_device_t *dev, uint32_t addr)
+int hwstub_call(struct hwstub_device_t *dev, uint32_t addr)
{
return libusb_control_transfer(dev->handle,
LIBUSB_REQUEST_TYPE_CLASS | LIBUSB_RECIPIENT_DEVICE |
- LIBUSB_ENDPOINT_OUT, HWEMUL_CALL, addr & 0xffff, addr >> 16, NULL, 0,
+ LIBUSB_ENDPOINT_OUT, HWSTUB_CALL, addr & 0xffff, addr >> 16, NULL, 0,
1000);
}
-int hwemul_jump(struct hwemul_device_t *dev, uint32_t addr)
+int hwstub_jump(struct hwstub_device_t *dev, uint32_t addr)
{
return libusb_control_transfer(dev->handle,
LIBUSB_REQUEST_TYPE_CLASS | LIBUSB_RECIPIENT_DEVICE |
- LIBUSB_ENDPOINT_OUT, HWEMUL_JUMP, addr & 0xffff, addr >> 16, NULL, 0,
+ LIBUSB_ENDPOINT_OUT, HWSTUB_JUMP, addr & 0xffff, addr >> 16, NULL, 0,
1000);
}
-const char *hwemul_get_product_string(struct usb_resp_info_stmp_t *stmp)
+const char *hwstub_get_product_string(struct usb_resp_info_stmp_t *stmp)
{
switch(stmp->chipid)
{
@@ -139,7 +138,7 @@ const char *hwemul_get_product_string(struct usb_resp_info_stmp_t *stmp)
}
}
-const char *hwemul_get_rev_string(struct usb_resp_info_stmp_t *stmp)
+const char *hwstub_get_rev_string(struct usb_resp_info_stmp_t *stmp)
{
switch(stmp->chipid)
{
@@ -159,11 +158,11 @@ const char *hwemul_get_rev_string(struct usb_resp_info_stmp_t *stmp)
}
}
-int hwemul_aes_otp(struct hwemul_device_t *dev, void *buf, size_t sz, uint16_t param)
+int hwstub_aes_otp(struct hwstub_device_t *dev, void *buf, size_t sz, uint16_t param)
{
int ret = libusb_control_transfer(dev->handle,
LIBUSB_REQUEST_TYPE_CLASS | LIBUSB_RECIPIENT_DEVICE |
- LIBUSB_ENDPOINT_OUT, HWEMUL_AES_OTP, param, 0, buf, sz,
+ LIBUSB_ENDPOINT_OUT, HWSTUB_AES_OTP, param, 0, buf, sz,
1000);
if(ret <0 || (unsigned)ret != sz)
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 @@
* KIND, either express or implied.
*
****************************************************************************/
-#ifndef __HWEMUL__
-#define __HWEMUL__
+#ifndef __HWSTUB__
+#define __HWSTUB__
#include <libusb.h>
-#include "hwemul_protocol.h"
-#include "hwemul_soc.h"
+#include "hwstub_protocol.h"
+
+#ifdef __cplusplus
+extern "C" {
+#endif
/**
*
@@ -31,7 +34,7 @@
*
*/
-struct hwemul_device_t
+struct hwstub_device_t
{
libusb_device_handle *handle;
int intf;
@@ -41,23 +44,27 @@ struct hwemul_device_t
};
/* Requires then ->handle field only. Returns 0 on success */
-int hwemul_probe(struct hwemul_device_t *dev);
+int hwstub_probe(struct hwstub_device_t *dev);
/* Returns 0 on success */
-int hwemul_release(struct hwemul_device_t *dev);
+int hwstub_release(struct hwstub_device_t *dev);
/* Returns number of bytes filled */
-int hwemul_get_info(struct hwemul_device_t *dev, uint16_t idx, void *info, size_t sz);
+int hwstub_get_info(struct hwstub_device_t *dev, uint16_t idx, void *info, size_t sz);
/* Returns number of bytes filled */
-int hwemul_get_log(struct hwemul_device_t *dev, void *buf, size_t sz);
+int hwstub_get_log(struct hwstub_device_t *dev, void *buf, size_t sz);
/* Returns number of bytes written/read or <0 on error */
-int hwemul_rw_mem(struct hwemul_device_t *dev, int read, uint32_t addr, void *buf, size_t sz);
+int hwstub_rw_mem(struct hwstub_device_t *dev, int read, uint32_t addr, void *buf, size_t sz);
/* Returns <0 on error */
-int hwemul_call(struct hwemul_device_t *dev, uint32_t addr);
-int hwemul_jump(struct hwemul_device_t *dev, uint32_t addr);
+int hwstub_call(struct hwstub_device_t *dev, uint32_t addr);
+int hwstub_jump(struct hwstub_device_t *dev, uint32_t addr);
/* Returns <0 on error. The size must be a multiple of 16. */
-int hwemul_aes_otp(struct hwemul_device_t *dev, void *buf, size_t sz, uint16_t param);
+int hwstub_aes_otp(struct hwstub_device_t *dev, void *buf, size_t sz, uint16_t param);
+
+const char *hwstub_get_product_string(struct usb_resp_info_stmp_t *stmp);
+const char *hwstub_get_rev_string(struct usb_resp_info_stmp_t *stmp);
-const char *hwemul_get_product_string(struct usb_resp_info_stmp_t *stmp);
-const char *hwemul_get_rev_string(struct usb_resp_info_stmp_t *stmp);
+#ifdef __cplusplus
+} // extern "C"
+#endif
-#endif /* __HWEMUL__ */ \ No newline at end of file
+#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"