summaryrefslogtreecommitdiffstats
path: root/utils/hwstub/stub
diff options
context:
space:
mode:
authorAmaury Pouly <amaury.pouly@gmail.com>2014-02-04 00:10:41 +0100
committerAmaury Pouly <amaury.pouly@gmail.com>2014-02-10 23:14:24 +0100
commitc17d30f20466861a244c603665c580feb7758abf (patch)
treec5044f599f89d89de0b1419bd40e92211f8c8b8a /utils/hwstub/stub
parent6d64111b3c2f772cfc3539bb13851f78d4b55870 (diff)
downloadrockbox-c17d30f20466861a244c603665c580feb7758abf.tar.gz
rockbox-c17d30f20466861a244c603665c580feb7758abf.tar.bz2
rockbox-c17d30f20466861a244c603665c580feb7758abf.zip
utils/hwstub: completely rework the protocol, drop unused features
The protocol has evolved a lot during the 2.x.y lifetime, bringing more features which later got unused. This commit removes all the unused stuff and simplifies everything: - drop the feature mask: everything is mandatory or stalled on error - remove the info request and put all static information in standard USB descriptors which are part of the configuration descriptor (and can be retrieved using the standard GetDescriptor request). - remove the USB interface, we had only one anyway - remove all endpoint descriptors - remove the exit/atexit stuff, it never worked as intended anyway - update the hwstub library and make it able to handle any device - update the tools (mostly renaming and removing of code) Change-Id: I1872bba7f4177fc3891180e8f944aab88f5bde31
Diffstat (limited to 'utils/hwstub/stub')
-rw-r--r--utils/hwstub/stub/main.c241
-rw-r--r--utils/hwstub/stub/rk27xx/target.c59
-rw-r--r--utils/hwstub/stub/stmp/target.c132
-rw-r--r--utils/hwstub/stub/target.h13
4 files changed, 124 insertions, 321 deletions
diff --git a/utils/hwstub/stub/main.c b/utils/hwstub/stub/main.c
index 0923bf85ce..37590e88f8 100644
--- a/utils/hwstub/stub/main.c
+++ b/utils/hwstub/stub/main.c
@@ -51,16 +51,16 @@ static struct usb_device_descriptor __attribute__((aligned(2)))
.bLength = sizeof(struct usb_device_descriptor),
.bDescriptorType = USB_DT_DEVICE,
.bcdUSB = 0x0200,
- .bDeviceClass = USB_CLASS_PER_INTERFACE,
- .bDeviceSubClass = 0,
- .bDeviceProtocol = 0,
+ .bDeviceClass = HWSTUB_CLASS,
+ .bDeviceSubClass = HWSTUB_SUBCLASS,
+ .bDeviceProtocol = HWSTUB_PROTOCOL,
.bMaxPacketSize0 = 64,
.idVendor = HWSTUB_USB_VID,
.idProduct = HWSTUB_USB_PID,
.bcdDevice = HWSTUB_VERSION_MAJOR << 8 | HWSTUB_VERSION_MINOR,
.iManufacturer = 1,
.iProduct = 2,
- .iSerialNumber = 3,
+ .iSerialNumber = 0,
.bNumConfigurations = 1
};
@@ -72,40 +72,13 @@ static struct usb_config_descriptor __attribute__((aligned(2)))
.bLength = sizeof(struct usb_config_descriptor),
.bDescriptorType = USB_DT_CONFIG,
.wTotalLength = 0, /* will be filled in later */
- .bNumInterfaces = 1,
+ .bNumInterfaces = 0,
.bConfigurationValue = 1,
.iConfiguration = 0,
.bmAttributes = USB_CONFIG_ATT_ONE | USB_CONFIG_ATT_SELFPOWER,
.bMaxPower = (USB_MAX_CURRENT + 1) / 2, /* In 2mA units */
};
-/* main interface */
-static struct usb_interface_descriptor __attribute__((aligned(2)))
- interface_descriptor =
-{
- .bLength = sizeof(struct usb_interface_descriptor),
- .bDescriptorType = USB_DT_INTERFACE,
- .bInterfaceNumber = 0,
- .bAlternateSetting = 0,
- .bNumEndpoints = 3,
- .bInterfaceClass = HWSTUB_CLASS,
- .bInterfaceSubClass = HWSTUB_SUBCLASS,
- .bInterfaceProtocol = HWSTUB_PROTOCOL,
- .iInterface = 4
-};
-
-
-static struct usb_endpoint_descriptor __attribute__((aligned(2)))
- endpoint_descriptor =
-{
- .bLength = sizeof(struct usb_endpoint_descriptor),
- .bDescriptorType = USB_DT_ENDPOINT,
- .bEndpointAddress = 0,
- .bmAttributes = USB_ENDPOINT_XFER_BULK,
- .wMaxPacketSize = 0,
- .bInterval = 0
-};
-
static const struct usb_string_descriptor __attribute__((aligned(2)))
usb_string_iManufacturer =
{
@@ -117,42 +90,38 @@ static const struct usb_string_descriptor __attribute__((aligned(2)))
static const struct usb_string_descriptor __attribute__((aligned(2)))
usb_string_iProduct =
{
- 52,
+ 44,
USB_DT_STRING,
{'R', 'o', 'c', 'k', 'b', 'o', 'x', ' ',
'h', 'a', 'r', 'd', 'w', 'a', 'r', 'e', ' ',
- 'e', 'm', 'u', 'l', 'a', 't', 'e', 'r'}
+ 's', 't', 'u', 'b'}
};
-static struct usb_string_descriptor __attribute__((aligned(2)))
- usb_string_iSerial =
+/* this is stringid #0: languages supported */
+static const struct usb_string_descriptor __attribute__((aligned(2)))
+ lang_descriptor =
{
- 84,
+ 4,
USB_DT_STRING,
- {'0', '0', '0', '0', '0', '0', '0', '0', '0', '0', '0',
- '0', '0', '0', '0', '0', '0', '0', '0', '0', '0', '0',
- '0', '0', '0', '0', '0', '0', '0', '0', '0', '0', '0',
- '0', '0', '0', '0', '0', '0', '0', '0'}
+ {0x0409} /* LANGID US English */
};
-static struct usb_string_descriptor __attribute__((aligned(2)))
- usb_string_iInterface =
+static struct hwstub_version_desc_t __attribute__((aligned(2)))
+ version_descriptor =
{
- 28,
- USB_DT_STRING,
- {'A', 'c', 'i', 'd', ' ',
- '0' + (HWSTUB_VERSION_MAJOR >> 4), '0' + (HWSTUB_VERSION_MAJOR & 0xf), '.',
- '0' + (HWSTUB_VERSION_MINOR >> 4), '0' + (HWSTUB_VERSION_MINOR & 0xf), '.',
- '0' + (HWSTUB_VERSION_REV >> 4), '0' + (HWSTUB_VERSION_REV & 0xf) }
+ sizeof(struct hwstub_version_desc_t),
+ HWSTUB_DT_VERSION,
+ HWSTUB_VERSION_MAJOR,
+ HWSTUB_VERSION_MINOR,
+ HWSTUB_VERSION_REV
};
-/* this is stringid #0: languages supported */
-static const struct usb_string_descriptor __attribute__((aligned(2)))
- lang_descriptor =
+static struct hwstub_layout_desc_t __attribute__((aligned(2)))
+ layout_descriptor =
{
- 4,
- USB_DT_STRING,
- {0x0409} /* LANGID US English */
+ sizeof(struct hwstub_layout_desc_t),
+ HWSTUB_DT_LAYOUT,
+ 0, 0, 0, 0, 0, 0
};
#define USB_NUM_STRINGS 5
@@ -162,26 +131,25 @@ static const struct usb_string_descriptor* const usb_strings[USB_NUM_STRINGS] =
&lang_descriptor,
&usb_string_iManufacturer,
&usb_string_iProduct,
- &usb_string_iSerial,
- &usb_string_iInterface
};
uint8_t *usb_buffer = oc_bufferstart;
uint32_t usb_buffer_size = 0;
-#define EP_BULK 1
-#define EP_INT 2
-
-static void set_config(void)
+static void fill_layout_info(void)
{
- usb_drv_configure_endpoint(EP_BULK, USB_ENDPOINT_XFER_BULK);
- usb_drv_configure_endpoint(EP_INT, USB_ENDPOINT_XFER_INT);
+ layout_descriptor.dCodeStart = (uint32_t)oc_codestart;
+ layout_descriptor.dCodeSize = oc_codesize;
+ layout_descriptor.dStackStart = (uint32_t)oc_stackstart;
+ layout_descriptor.dStackSize = oc_stacksize;
+ layout_descriptor.dBufferStart = (uint32_t)oc_bufferstart;
+ layout_descriptor.dBufferSize = oc_buffersize;
}
static void handle_std_dev_desc(struct usb_ctrlrequest *req)
{
int size;
- const void* ptr = NULL;
+ void* ptr = NULL;
unsigned index = req->wValue & 0xff;
switch(req->wValue >> 8)
@@ -208,32 +176,22 @@ static void handle_std_dev_desc(struct usb_ctrlrequest *req)
}
size = sizeof(struct usb_config_descriptor);
- /* interface */
- memcpy(usb_buffer + size, (void *)&interface_descriptor,
- sizeof(interface_descriptor));
- size += sizeof(interface_descriptor);
- /* endpoint 1: bulk out */
- endpoint_descriptor.bEndpointAddress = EP_BULK | USB_DIR_OUT;
- endpoint_descriptor.bmAttributes = USB_ENDPOINT_XFER_BULK;
- endpoint_descriptor.wMaxPacketSize = 512;
- memcpy(usb_buffer + size, (void *)&endpoint_descriptor,
- sizeof(endpoint_descriptor));
- size += sizeof(endpoint_descriptor);
- /* endpoint 2: bulk in */
- endpoint_descriptor.bEndpointAddress = EP_BULK | USB_DIR_IN;
- endpoint_descriptor.bmAttributes = USB_ENDPOINT_XFER_BULK;
- endpoint_descriptor.wMaxPacketSize = 512;
- memcpy(usb_buffer + size, (void *)&endpoint_descriptor,
- sizeof(endpoint_descriptor));
- size += sizeof(endpoint_descriptor);
- /* endpoint 3: int in */
- endpoint_descriptor.bEndpointAddress = EP_INT | USB_DIR_IN;
- endpoint_descriptor.bmAttributes = USB_ENDPOINT_XFER_INT;
- endpoint_descriptor.wMaxPacketSize = 1024;
- memcpy(usb_buffer + size, (void *)&endpoint_descriptor,
- sizeof(endpoint_descriptor));
- size += sizeof(endpoint_descriptor);
-
+ /* hwstub version */
+ memcpy(usb_buffer + size, (void *)&version_descriptor,
+ sizeof(version_descriptor));
+ size += sizeof(version_descriptor);
+ /* hwstub layout */
+ fill_layout_info();
+ memcpy(usb_buffer + size, (void *)&layout_descriptor,
+ sizeof(layout_descriptor));
+ size += sizeof(layout_descriptor);
+ /* hwstub target */
+ fill_layout_info();
+ memcpy(usb_buffer + size, (void *)&target_descriptor,
+ sizeof(target_descriptor));
+ size += sizeof(target_descriptor);
+ /* target specific descriptors */
+ target_get_config_desc(usb_buffer + size, &size);
/* fix config descriptor */
config_descriptor.bNumInterfaces = 1;
config_descriptor.wTotalLength = size;
@@ -246,12 +204,27 @@ static void handle_std_dev_desc(struct usb_ctrlrequest *req)
if(index < USB_NUM_STRINGS)
{
size = usb_strings[index]->bLength;
- ptr = usb_strings[index];
+ ptr = (void *)usb_strings[index];
}
else
usb_drv_stall(EP_CONTROL, true, true);
break;
+ case HWSTUB_DT_VERSION:
+ ptr = &version_descriptor;
+ size = sizeof(version_descriptor);
+ break;
+ case HWSTUB_DT_LAYOUT:
+ ptr = &layout_descriptor;
+ size = sizeof(layout_descriptor);
+ break;
+ case HWSTUB_DT_TARGET:
+ ptr = &target_descriptor;
+ size = sizeof(target_descriptor);
+ break;
default:
+ target_get_desc(req->wValue >> 8, &ptr);
+ if(ptr != 0)
+ size = ((struct usb_descriptor_header *)ptr)->bLength;
break;
}
@@ -280,7 +253,6 @@ static void handle_std_dev_req(struct usb_ctrlrequest *req)
break;
case USB_REQ_SET_CONFIGURATION:
usb_drv_send(EP_CONTROL, NULL, 0);
- set_config();
break;
case USB_REQ_GET_DESCRIPTOR:
handle_std_dev_desc(req);
@@ -311,67 +283,6 @@ static void handle_std_req(struct usb_ctrlrequest *req)
}
}
-struct usb_resp_info_version_t g_version =
-{
- .major = HWSTUB_VERSION_MAJOR,
- .minor = HWSTUB_VERSION_MINOR,
- .revision = HWSTUB_VERSION_REV
-};
-
-struct usb_resp_info_layout_t g_layout;
-
-struct usb_resp_info_features_t g_features =
-{
- .feature_mask = HWSTUB_FEATURE_LOG | HWSTUB_FEATURE_MEM |
- HWSTUB_FEATURE_CALL | HWSTUB_FEATURE_JUMP
-};
-
-static void fill_layout_info(void)
-{
- g_layout.oc_code_start = (uint32_t)oc_codestart;
- g_layout.oc_code_size = oc_codesize;
- g_layout.oc_stack_start = (uint32_t)oc_stackstart;
- g_layout.oc_stack_size = oc_stacksize;
- g_layout.oc_buffer_start = (uint32_t)oc_bufferstart;
- g_layout.oc_buffer_size = oc_buffersize;
-}
-
-static void handle_get_info(struct usb_ctrlrequest *req)
-{
- void *ptr = NULL;
- int size = 0;
- switch(req->wIndex)
- {
- case HWSTUB_INFO_VERSION:
- ptr = &g_version;
- size = sizeof(g_version);
- break;
- case HWSTUB_INFO_LAYOUT:
- fill_layout_info();
- ptr = &g_layout;
- size = sizeof(g_layout);
- break;
- case HWSTUB_INFO_FEATURES:
- ptr = &g_features;
- size = sizeof(g_features);
- break;
- default:
- size = target_get_info(req->wIndex, &ptr);
- if(size < 0)
- usb_drv_stall(EP_CONTROL, true, true);
- }
-
- if(ptr)
- {
- int length = MIN(size, req->wLength);
-
- if(ptr != usb_buffer)
- memcpy(usb_buffer, ptr, length);
- usb_drv_send(EP_CONTROL, usb_buffer, length);
- usb_drv_recv(EP_CONTROL, NULL, 0);
- }
-}
-
static void handle_get_log(struct usb_ctrlrequest *req)
{
enable_logf(false);
@@ -421,28 +332,10 @@ static void handle_call_jump(struct usb_ctrlrequest *req)
}
}
-static void handle_atexit(struct usb_ctrlrequest *req)
-{
- if(target_atexit(req->wIndex) < 0)
- usb_drv_stall(EP_CONTROL, true, true);
- else
- usb_drv_send(EP_CONTROL, NULL, 0);
-}
-
-static void handle_exit(struct usb_ctrlrequest *req)
-{
- (void)req;
- usb_drv_send(EP_CONTROL, NULL, 0);
- g_exit = true;
-}
-
static void handle_class_dev_req(struct usb_ctrlrequest *req)
{
switch(req->bRequest)
{
- case HWSTUB_GET_INFO:
- handle_get_info(req);
- break;
case HWSTUB_GET_LOG:
handle_get_log(req);
break;
@@ -453,11 +346,6 @@ static void handle_class_dev_req(struct usb_ctrlrequest *req)
case HWSTUB_JUMP:
handle_call_jump(req);
break;
- case HWSTUB_ATEXIT:
- handle_atexit(req);
- break;
- case HWSTUB_EXIT:
- handle_exit(req);
break;
default:
usb_drv_stall(EP_CONTROL, true, true);
@@ -510,5 +398,4 @@ void main(uint32_t arg)
}
}
usb_drv_exit();
- target_exit();
}
diff --git a/utils/hwstub/stub/rk27xx/target.c b/utils/hwstub/stub/rk27xx/target.c
index f9efccaef0..ff2e952909 100644
--- a/utils/hwstub/stub/rk27xx/target.c
+++ b/utils/hwstub/stub/rk27xx/target.c
@@ -33,7 +33,6 @@ enum rk27xx_family_t
};
static enum rk27xx_family_t g_rk27xx_family = UNKNOWN;
-static int g_atexit = HWSTUB_ATEXIT_OFF;
static void _enable_irq(void)
{
@@ -43,23 +42,6 @@ static void _enable_irq(void)
);
}
-static void power_off(void)
-{
- GPIO_PCCON &= ~(1<<0);
- while(1);
-}
-
-static void rk27xx_reset(void)
-{
- /* use Watchdog to reset */
- SCU_CLKCFG &= ~CLKCFG_WDT;
- WDTLR = 1;
- WDTCON = (1<<4) | (1<<3);
-
- /* Wait for reboot to kick in */
- while(1);
-}
-
/* us may be at most 2^31/200 (~10 seconds) for 200MHz max cpu freq */
void target_udelay(int us)
{
@@ -132,41 +114,22 @@ void target_init(void)
}
}
-static struct usb_resp_info_target_t g_target =
+struct hwstub_target_desc_t __attribute__((aligned(2))) target_descriptor =
{
- .id = HWSTUB_TARGET_RK27,
- .name = "Rockchip RK27XX"
+ sizeof(struct hwstub_target_desc_t),
+ HWSTUB_DT_TARGET,
+ HWSTUB_TARGET_RK27,
+ "Rockchip RK27XX"
};
-int target_get_info(int info, void **buffer)
+void target_get_desc(int desc, void **buffer)
{
- if(info == HWSTUB_INFO_TARGET)
- {
- *buffer = &g_target;
- return sizeof(g_target);
- }
- else
- return -1;
+ (void) desc;
+ *buffer = NULL;
}
-int target_atexit(int method)
+void target_get_config_desc(void *buffer, int *size)
{
- g_atexit = method;
- return 0;
-}
-
-void target_exit(void)
-{
- switch(g_atexit)
- {
- case HWSTUB_ATEXIT_OFF:
- power_off();
- // fallthrough in case of return
- case HWSTUB_ATEXIT_REBOOT:
- rk27xx_reset();
- // fallthrough in case of return
- case HWSTUB_ATEXIT_NOP:
- default:
- return;
- }
+ (void) buffer;
+ (void) size;
}
diff --git a/utils/hwstub/stub/stmp/target.c b/utils/hwstub/stub/stmp/target.c
index 98f65da625..8d48707088 100644
--- a/utils/hwstub/stub/stmp/target.c
+++ b/utils/hwstub/stub/stmp/target.c
@@ -22,6 +22,7 @@
#include "target.h"
#include "system.h"
#include "logf.h"
+#include "memory.h"
#define __REG_SET(reg) (*((volatile uint32_t *)(&reg + 1)))
#define __REG_CLR(reg) (*((volatile uint32_t *)(&reg + 2)))
@@ -50,34 +51,6 @@ enum stmp_family_t
};
static enum stmp_family_t g_stmp_family = UNKNOWN;
-static int g_atexit = HWSTUB_ATEXIT_OFF;
-
-/**
- *
- * Power
- *
- */
-
-#define HW_POWER_BASE 0x80044000
-
-void power_off(void)
-{
- switch(g_stmp_family)
- {
- case STMP3600:
- *(volatile uint32_t *)(HW_POWER_BASE + 0xc0) = 0x3e770014;
- break;
- case STMP3700:
- case STMP3770:
- *(volatile uint32_t *)(HW_POWER_BASE + 0xe0) = 0x3e770001;
- break;
- case STMP3780:
- *(volatile uint32_t *)(HW_POWER_BASE + 0x100) = 0x3e770001;
- break;
- default:
- break;
- }
-}
/**
*
@@ -114,25 +87,6 @@ void power_off(void)
#define HW_CLKCTRL_UTMICLKCTRL__UTMI_CLK30M_GATE (1 << 30)
#define HW_CLKCTRL_UTMICLKCTRL__UTMI_CLK120M_GATE (1 << 31)
-void clkctrl_reset(void)
-{
- switch(g_stmp_family)
- {
- case STMP3600:
- *(volatile uint32_t *)(HW_POWER_BASE + 0xc0) = 0x3e770002;
- break;
- case STMP3700:
- case STMP3770:
- *(volatile uint32_t *)(HW_CLKCTRL_BASE + 0xf0) = 0x1;
- break;
- case STMP3780:
- *(volatile uint32_t *)(HW_CLKCTRL_BASE + 0x120) = 0x1;
- break;
- default:
- break;
- }
-}
-
/**
*
* Digctl
@@ -143,11 +97,18 @@ void clkctrl_reset(void)
#define HW_DIGCTL_BASE 0x8001C000
#define HW_DIGCTL_CTRL (*(volatile uint32_t *)(HW_DIGCTL_BASE + 0))
#define HW_DIGCTL_CTRL__USB_CLKGATE (1 << 2)
+#define HW_DIGCTL_CTRL__PACKAGE_SENSE_ENABLE_STMP3600 (1 << 0)
+
+#define HW_DIGCTL_STATUS (*(volatile uint32_t *)(HW_DIGCTL_BASE + 0x10))
+#define HW_DIGCTL_STATUS__PACKAGE_TYPE_BP 1
+#define HW_DIGCTL_STATUS__PACKAGE_TYPE_BM (7 << 1)
+#define HW_DIGCTL_STATUS__PACKAGE_TYPE_STMP3600_BP 1
+#define HW_DIGCTL_STATUS__PACKAGE_TYPE_STMP3600_BM (1 << 1)
/* STMP3700+ */
#define HW_DIGCTL_MICROSECONDS (*(volatile uint32_t *)(HW_DIGCTL_BASE + 0xC0))
/* STMP3600 */
-#define HW_DIGCTL_MICROSECONDS2 (*(volatile uint32_t *)(HW_DIGCTL_BASE + 0xB0))
+#define HW_DIGCTL_MICROSECONDS_STMP3600 (*(volatile uint32_t *)(HW_DIGCTL_BASE + 0xB0))
#define HW_DIGCTL_CHIPID (*(volatile uint32_t *)(HW_DIGCTL_BASE + 0x310))
#define HW_DIGCTL_CHIPID__PRODUCT_CODE_BP 16
@@ -177,8 +138,25 @@ void clkctrl_reset(void)
#define HW_RTC_CTRL (*(volatile uint32_t *)(HW_RTC_BASE + 0))
#define HW_RTC_CTRL__WATCHDOGEN (1 << 4)
+struct hwstub_target_desc_t __attribute__((aligned(2))) target_descriptor =
+{
+ sizeof(struct hwstub_target_desc_t),
+ HWSTUB_DT_TARGET,
+ HWSTUB_TARGET_STMP,
+ "STMP3600 / STMP3700 / STMP3780 (i.MX233)"
+};
+
+static struct hwstub_stmp_desc_t __attribute__((aligned(2))) stmp_descriptor =
+{
+ sizeof(struct hwstub_stmp_desc_t),
+ HWSTUB_DT_STMP,
+ 0, 0, 0
+};
+
void target_init(void)
{
+ stmp_descriptor.wChipID = __XTRACT(HW_DIGCTL_CHIPID, PRODUCT_CODE);
+ stmp_descriptor.bRevision = __XTRACT(HW_DIGCTL_CHIPID, REVISION);
/* detect family */
uint16_t product_code = __XTRACT(HW_DIGCTL_CHIPID, PRODUCT_CODE);
if(product_code >= 0x3600 && product_code < 0x3700)
@@ -208,6 +186,7 @@ void target_init(void)
if(g_stmp_family == STMP3600)
{
+ stmp_descriptor.bPackage = __XTRACT(HW_DIGCTL_STATUS, PACKAGE_TYPE);
/* CPU clock is always derived from PLL, if we switch to PLL, cpu will
* run at 480 MHz unprepared ! That's bad so prepare to run at slow sleed
* (1.2MHz) for a safe transition */
@@ -230,7 +209,13 @@ void target_init(void)
__REG_CLR(HW_CLKCTRL_UTMICLKCTRL) = HW_CLKCTRL_UTMICLKCTRL__UTMI_CLK30M_GATE;
}
else
+ {
+ __REG_SET(HW_DIGCTL_CTRL) = HW_DIGCTL_CTRL__PACKAGE_SENSE_ENABLE_STMP3600;
+ stmp_descriptor.bPackage = __XTRACT(HW_DIGCTL_STATUS, PACKAGE_TYPE_STMP3600);
+ __REG_CLR(HW_DIGCTL_CTRL) = HW_DIGCTL_CTRL__PACKAGE_SENSE_ENABLE_STMP3600;
+
__REG_SET(HW_CLKCTRL_PLLCTRL0) = HW_CLKCTRL_PLLCTRL0__POWER;
+ }
/* enable USB PHY PLL */
__REG_SET(HW_CLKCTRL_PLLCTRL0) = HW_CLKCTRL_PLLCTRL0__EN_USB_CLKS;
/* power up USB PHY */
@@ -240,57 +225,24 @@ void target_init(void)
__REG_CLR(HW_DIGCTL_CTRL) = HW_DIGCTL_CTRL__USB_CLKGATE;
}
-static struct usb_resp_info_stmp_t g_stmp;
-static struct usb_resp_info_target_t g_target =
-{
- .id = HWSTUB_TARGET_STMP,
- .name = "STMP3600 / STMP3700 / STMP3780 (i.MX233)"
-};
-
-int target_get_info(int info, void **buffer)
+void target_get_desc(int desc, void **buffer)
{
- if(info == HWSTUB_INFO_STMP)
- {
- g_stmp.chipid = __XTRACT(HW_DIGCTL_CHIPID, PRODUCT_CODE);
- g_stmp.rev = __XTRACT(HW_DIGCTL_CHIPID, REVISION);
- g_stmp.is_supported = g_stmp_family != 0;
- *buffer = &g_stmp;
- return sizeof(g_stmp);
- }
- else if(info == HWSTUB_INFO_TARGET)
- {
- *buffer = &g_target;
- return sizeof(g_target);
- }
+ if(desc == HWSTUB_DT_STMP)
+ *buffer = &stmp_descriptor;
else
- return -1;
+ *buffer = NULL;
}
-int target_atexit(int method)
+void target_get_config_desc(void *buffer, int *size)
{
- g_atexit = method;
- return 0;
-}
-
-void target_exit(void)
-{
- switch(g_atexit)
- {
- case HWSTUB_ATEXIT_OFF:
- power_off();
- // fallthrough in case of return
- case HWSTUB_ATEXIT_REBOOT:
- clkctrl_reset();
- // fallthrough in case of return
- case HWSTUB_ATEXIT_NOP:
- default:
- return;
- }
+ memcpy(buffer, &stmp_descriptor, sizeof(stmp_descriptor));
+ *size += sizeof(stmp_descriptor);
}
void target_udelay(int us)
{
- volatile uint32_t *reg = g_stmp_family == STMP3600 ? &HW_DIGCTL_MICROSECONDS2 : &HW_DIGCTL_MICROSECONDS;
+ volatile uint32_t *reg = g_stmp_family == STMP3600 ?
+ &HW_DIGCTL_MICROSECONDS_STMP3600 : &HW_DIGCTL_MICROSECONDS;
uint32_t cur = *reg;
uint32_t end = cur + us;
if(cur < end)
diff --git a/utils/hwstub/stub/target.h b/utils/hwstub/stub/target.h
index 43151e9a34..cb17401a9c 100644
--- a/utils/hwstub/stub/target.h
+++ b/utils/hwstub/stub/target.h
@@ -25,15 +25,16 @@
/* do target specific init */
void target_init(void);
-/* exit, performing the atexit action (default is target specific) */
-void target_exit(void);
-/* get information, return actual size or -1 if error */
-int target_get_info(int info, void **buffer);
-/* set atexit action or return -1 on error */
-int target_atexit(int action);
+/* get descriptor, set buffer to NULL on error */
+void target_get_desc(int desc, void **buffer);
+/* pack all descriptors for config desc */
+void target_get_config_desc(void *buffer, int *size);
/* Wait a very short time (us<=1000) */
void target_udelay(int us);
/* Wait for a short time (ms <= 1000) */
void target_mdelay(int ms);
+/* mandatory for all targets */
+extern struct hwstub_target_desc_t target_descriptor;
+
#endif /* __TARGET_H__ */