mirror of
https://github.com/Fishwaldo/u-boot.git
synced 2025-03-19 05:31:32 +00:00
Merge branch 'master' of git://git.denx.de/u-boot-usb
This commit is contained in:
commit
87fcdca6be
4 changed files with 40 additions and 38 deletions
|
@ -23,7 +23,6 @@
|
||||||
|
|
||||||
#include <linux/usb/ch9.h>
|
#include <linux/usb/ch9.h>
|
||||||
#include <linux/usb/gadget.h>
|
#include <linux/usb/gadget.h>
|
||||||
#include <asm/arch/sys_proto.h>
|
|
||||||
|
|
||||||
#include "core.h"
|
#include "core.h"
|
||||||
#include "gadget.h"
|
#include "gadget.h"
|
||||||
|
|
|
@ -159,7 +159,7 @@ static void dnload_request_complete(struct usb_ep *ep, struct usb_request *req)
|
||||||
int ret;
|
int ret;
|
||||||
|
|
||||||
ret = dfu_write(dfu_get_entity(f_dfu->altsetting), req->buf,
|
ret = dfu_write(dfu_get_entity(f_dfu->altsetting), req->buf,
|
||||||
req->length, f_dfu->blk_seq_num);
|
req->actual, f_dfu->blk_seq_num);
|
||||||
if (ret) {
|
if (ret) {
|
||||||
f_dfu->dfu_status = DFU_STATUS_errUNKNOWN;
|
f_dfu->dfu_status = DFU_STATUS_errUNKNOWN;
|
||||||
f_dfu->dfu_state = DFU_STATE_dfuERROR;
|
f_dfu->dfu_state = DFU_STATE_dfuERROR;
|
||||||
|
@ -178,7 +178,7 @@ static inline int dfu_get_manifest_timeout(struct dfu_entity *dfu)
|
||||||
DFU_MANIFEST_POLL_TIMEOUT;
|
DFU_MANIFEST_POLL_TIMEOUT;
|
||||||
}
|
}
|
||||||
|
|
||||||
static void handle_getstatus(struct usb_request *req)
|
static int handle_getstatus(struct usb_request *req)
|
||||||
{
|
{
|
||||||
struct dfu_status *dstat = (struct dfu_status *)req->buf;
|
struct dfu_status *dstat = (struct dfu_status *)req->buf;
|
||||||
struct f_dfu *f_dfu = req->context;
|
struct f_dfu *f_dfu = req->context;
|
||||||
|
@ -210,14 +210,16 @@ static void handle_getstatus(struct usb_request *req)
|
||||||
dstat->bStatus = f_dfu->dfu_status;
|
dstat->bStatus = f_dfu->dfu_status;
|
||||||
dstat->bState = f_dfu->dfu_state;
|
dstat->bState = f_dfu->dfu_state;
|
||||||
dstat->iString = 0;
|
dstat->iString = 0;
|
||||||
|
|
||||||
|
return sizeof(struct dfu_status);
|
||||||
}
|
}
|
||||||
|
|
||||||
static void handle_getstate(struct usb_request *req)
|
static int handle_getstate(struct usb_request *req)
|
||||||
{
|
{
|
||||||
struct f_dfu *f_dfu = req->context;
|
struct f_dfu *f_dfu = req->context;
|
||||||
|
|
||||||
((u8 *)req->buf)[0] = f_dfu->dfu_state;
|
((u8 *)req->buf)[0] = f_dfu->dfu_state;
|
||||||
req->actual = sizeof(u8);
|
return sizeof(u8);
|
||||||
}
|
}
|
||||||
|
|
||||||
static inline void to_dfu_mode(struct f_dfu *f_dfu)
|
static inline void to_dfu_mode(struct f_dfu *f_dfu)
|
||||||
|
@ -268,11 +270,10 @@ static int state_app_idle(struct f_dfu *f_dfu,
|
||||||
|
|
||||||
switch (ctrl->bRequest) {
|
switch (ctrl->bRequest) {
|
||||||
case USB_REQ_DFU_GETSTATUS:
|
case USB_REQ_DFU_GETSTATUS:
|
||||||
handle_getstatus(req);
|
value = handle_getstatus(req);
|
||||||
value = RET_STAT_LEN;
|
|
||||||
break;
|
break;
|
||||||
case USB_REQ_DFU_GETSTATE:
|
case USB_REQ_DFU_GETSTATE:
|
||||||
handle_getstate(req);
|
value = handle_getstate(req);
|
||||||
break;
|
break;
|
||||||
case USB_REQ_DFU_DETACH:
|
case USB_REQ_DFU_DETACH:
|
||||||
f_dfu->dfu_state = DFU_STATE_appDETACH;
|
f_dfu->dfu_state = DFU_STATE_appDETACH;
|
||||||
|
@ -296,11 +297,10 @@ static int state_app_detach(struct f_dfu *f_dfu,
|
||||||
|
|
||||||
switch (ctrl->bRequest) {
|
switch (ctrl->bRequest) {
|
||||||
case USB_REQ_DFU_GETSTATUS:
|
case USB_REQ_DFU_GETSTATUS:
|
||||||
handle_getstatus(req);
|
value = handle_getstatus(req);
|
||||||
value = RET_STAT_LEN;
|
|
||||||
break;
|
break;
|
||||||
case USB_REQ_DFU_GETSTATE:
|
case USB_REQ_DFU_GETSTATE:
|
||||||
handle_getstate(req);
|
value = handle_getstate(req);
|
||||||
break;
|
break;
|
||||||
default:
|
default:
|
||||||
f_dfu->dfu_state = DFU_STATE_appIDLE;
|
f_dfu->dfu_state = DFU_STATE_appIDLE;
|
||||||
|
@ -341,11 +341,10 @@ static int state_dfu_idle(struct f_dfu *f_dfu,
|
||||||
value = RET_ZLP;
|
value = RET_ZLP;
|
||||||
break;
|
break;
|
||||||
case USB_REQ_DFU_GETSTATUS:
|
case USB_REQ_DFU_GETSTATUS:
|
||||||
handle_getstatus(req);
|
value = handle_getstatus(req);
|
||||||
value = RET_STAT_LEN;
|
|
||||||
break;
|
break;
|
||||||
case USB_REQ_DFU_GETSTATE:
|
case USB_REQ_DFU_GETSTATE:
|
||||||
handle_getstate(req);
|
value = handle_getstate(req);
|
||||||
break;
|
break;
|
||||||
case USB_REQ_DFU_DETACH:
|
case USB_REQ_DFU_DETACH:
|
||||||
/*
|
/*
|
||||||
|
@ -381,11 +380,10 @@ static int state_dfu_dnload_sync(struct f_dfu *f_dfu,
|
||||||
|
|
||||||
switch (ctrl->bRequest) {
|
switch (ctrl->bRequest) {
|
||||||
case USB_REQ_DFU_GETSTATUS:
|
case USB_REQ_DFU_GETSTATUS:
|
||||||
handle_getstatus(req);
|
value = handle_getstatus(req);
|
||||||
value = RET_STAT_LEN;
|
|
||||||
break;
|
break;
|
||||||
case USB_REQ_DFU_GETSTATE:
|
case USB_REQ_DFU_GETSTATE:
|
||||||
handle_getstate(req);
|
value = handle_getstate(req);
|
||||||
break;
|
break;
|
||||||
default:
|
default:
|
||||||
f_dfu->dfu_state = DFU_STATE_dfuERROR;
|
f_dfu->dfu_state = DFU_STATE_dfuERROR;
|
||||||
|
@ -405,8 +403,7 @@ static int state_dfu_dnbusy(struct f_dfu *f_dfu,
|
||||||
|
|
||||||
switch (ctrl->bRequest) {
|
switch (ctrl->bRequest) {
|
||||||
case USB_REQ_DFU_GETSTATUS:
|
case USB_REQ_DFU_GETSTATUS:
|
||||||
handle_getstatus(req);
|
value = handle_getstatus(req);
|
||||||
value = RET_STAT_LEN;
|
|
||||||
break;
|
break;
|
||||||
default:
|
default:
|
||||||
f_dfu->dfu_state = DFU_STATE_dfuERROR;
|
f_dfu->dfu_state = DFU_STATE_dfuERROR;
|
||||||
|
@ -437,11 +434,10 @@ static int state_dfu_dnload_idle(struct f_dfu *f_dfu,
|
||||||
value = RET_ZLP;
|
value = RET_ZLP;
|
||||||
break;
|
break;
|
||||||
case USB_REQ_DFU_GETSTATUS:
|
case USB_REQ_DFU_GETSTATUS:
|
||||||
handle_getstatus(req);
|
value = handle_getstatus(req);
|
||||||
value = RET_STAT_LEN;
|
|
||||||
break;
|
break;
|
||||||
case USB_REQ_DFU_GETSTATE:
|
case USB_REQ_DFU_GETSTATE:
|
||||||
handle_getstate(req);
|
value = handle_getstate(req);
|
||||||
break;
|
break;
|
||||||
default:
|
default:
|
||||||
f_dfu->dfu_state = DFU_STATE_dfuERROR;
|
f_dfu->dfu_state = DFU_STATE_dfuERROR;
|
||||||
|
@ -463,13 +459,12 @@ static int state_dfu_manifest_sync(struct f_dfu *f_dfu,
|
||||||
case USB_REQ_DFU_GETSTATUS:
|
case USB_REQ_DFU_GETSTATUS:
|
||||||
/* We're MainfestationTolerant */
|
/* We're MainfestationTolerant */
|
||||||
f_dfu->dfu_state = DFU_STATE_dfuMANIFEST;
|
f_dfu->dfu_state = DFU_STATE_dfuMANIFEST;
|
||||||
handle_getstatus(req);
|
value = handle_getstatus(req);
|
||||||
f_dfu->blk_seq_num = 0;
|
f_dfu->blk_seq_num = 0;
|
||||||
value = RET_STAT_LEN;
|
|
||||||
req->complete = dnload_request_flush;
|
req->complete = dnload_request_flush;
|
||||||
break;
|
break;
|
||||||
case USB_REQ_DFU_GETSTATE:
|
case USB_REQ_DFU_GETSTATE:
|
||||||
handle_getstate(req);
|
value = handle_getstate(req);
|
||||||
break;
|
break;
|
||||||
default:
|
default:
|
||||||
f_dfu->dfu_state = DFU_STATE_dfuERROR;
|
f_dfu->dfu_state = DFU_STATE_dfuERROR;
|
||||||
|
@ -491,13 +486,12 @@ static int state_dfu_manifest(struct f_dfu *f_dfu,
|
||||||
case USB_REQ_DFU_GETSTATUS:
|
case USB_REQ_DFU_GETSTATUS:
|
||||||
/* We're MainfestationTolerant */
|
/* We're MainfestationTolerant */
|
||||||
f_dfu->dfu_state = DFU_STATE_dfuIDLE;
|
f_dfu->dfu_state = DFU_STATE_dfuIDLE;
|
||||||
handle_getstatus(req);
|
value = handle_getstatus(req);
|
||||||
f_dfu->blk_seq_num = 0;
|
f_dfu->blk_seq_num = 0;
|
||||||
value = RET_STAT_LEN;
|
|
||||||
puts("DOWNLOAD ... OK\nCtrl+C to exit ...\n");
|
puts("DOWNLOAD ... OK\nCtrl+C to exit ...\n");
|
||||||
break;
|
break;
|
||||||
case USB_REQ_DFU_GETSTATE:
|
case USB_REQ_DFU_GETSTATE:
|
||||||
handle_getstate(req);
|
value = handle_getstate(req);
|
||||||
break;
|
break;
|
||||||
default:
|
default:
|
||||||
f_dfu->dfu_state = DFU_STATE_dfuERROR;
|
f_dfu->dfu_state = DFU_STATE_dfuERROR;
|
||||||
|
@ -530,11 +524,10 @@ static int state_dfu_upload_idle(struct f_dfu *f_dfu,
|
||||||
value = RET_ZLP;
|
value = RET_ZLP;
|
||||||
break;
|
break;
|
||||||
case USB_REQ_DFU_GETSTATUS:
|
case USB_REQ_DFU_GETSTATUS:
|
||||||
handle_getstatus(req);
|
value = handle_getstatus(req);
|
||||||
value = RET_STAT_LEN;
|
|
||||||
break;
|
break;
|
||||||
case USB_REQ_DFU_GETSTATE:
|
case USB_REQ_DFU_GETSTATE:
|
||||||
handle_getstate(req);
|
value = handle_getstate(req);
|
||||||
break;
|
break;
|
||||||
default:
|
default:
|
||||||
f_dfu->dfu_state = DFU_STATE_dfuERROR;
|
f_dfu->dfu_state = DFU_STATE_dfuERROR;
|
||||||
|
@ -554,11 +547,10 @@ static int state_dfu_error(struct f_dfu *f_dfu,
|
||||||
|
|
||||||
switch (ctrl->bRequest) {
|
switch (ctrl->bRequest) {
|
||||||
case USB_REQ_DFU_GETSTATUS:
|
case USB_REQ_DFU_GETSTATUS:
|
||||||
handle_getstatus(req);
|
value = handle_getstatus(req);
|
||||||
value = RET_STAT_LEN;
|
|
||||||
break;
|
break;
|
||||||
case USB_REQ_DFU_GETSTATE:
|
case USB_REQ_DFU_GETSTATE:
|
||||||
handle_getstate(req);
|
value = handle_getstate(req);
|
||||||
break;
|
break;
|
||||||
case USB_REQ_DFU_CLRSTATUS:
|
case USB_REQ_DFU_CLRSTATUS:
|
||||||
f_dfu->dfu_state = DFU_STATE_dfuIDLE;
|
f_dfu->dfu_state = DFU_STATE_dfuIDLE;
|
||||||
|
@ -654,7 +646,7 @@ static int dfu_prepare_function(struct f_dfu *f_dfu, int n)
|
||||||
struct usb_interface_descriptor *d;
|
struct usb_interface_descriptor *d;
|
||||||
int i = 0;
|
int i = 0;
|
||||||
|
|
||||||
f_dfu->function = calloc(sizeof(struct usb_descriptor_header *), n + 1);
|
f_dfu->function = calloc(sizeof(struct usb_descriptor_header *), n + 2);
|
||||||
if (!f_dfu->function)
|
if (!f_dfu->function)
|
||||||
goto enomem;
|
goto enomem;
|
||||||
|
|
||||||
|
@ -673,6 +665,14 @@ static int dfu_prepare_function(struct f_dfu *f_dfu, int n)
|
||||||
|
|
||||||
f_dfu->function[i] = (struct usb_descriptor_header *)d;
|
f_dfu->function[i] = (struct usb_descriptor_header *)d;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/* add DFU Functional Descriptor */
|
||||||
|
f_dfu->function[i] = calloc(sizeof(dfu_func), 1);
|
||||||
|
if (!f_dfu->function[i])
|
||||||
|
goto enomem;
|
||||||
|
memcpy(f_dfu->function[i], &dfu_func, sizeof(dfu_func));
|
||||||
|
|
||||||
|
i++;
|
||||||
f_dfu->function[i] = NULL;
|
f_dfu->function[i] = NULL;
|
||||||
|
|
||||||
return 0;
|
return 0;
|
||||||
|
@ -691,6 +691,7 @@ static int dfu_bind(struct usb_configuration *c, struct usb_function *f)
|
||||||
{
|
{
|
||||||
struct usb_composite_dev *cdev = c->cdev;
|
struct usb_composite_dev *cdev = c->cdev;
|
||||||
struct f_dfu *f_dfu = func_to_dfu(f);
|
struct f_dfu *f_dfu = func_to_dfu(f);
|
||||||
|
const char *s;
|
||||||
int alt_num = dfu_get_alt_number();
|
int alt_num = dfu_get_alt_number();
|
||||||
int rv, id, i;
|
int rv, id, i;
|
||||||
|
|
||||||
|
@ -724,6 +725,10 @@ static int dfu_bind(struct usb_configuration *c, struct usb_function *f)
|
||||||
|
|
||||||
cdev->req->context = f_dfu;
|
cdev->req->context = f_dfu;
|
||||||
|
|
||||||
|
s = getenv("serial#");
|
||||||
|
if (s)
|
||||||
|
g_dnl_set_serialnumber((char *)s);
|
||||||
|
|
||||||
error:
|
error:
|
||||||
return rv;
|
return rv;
|
||||||
}
|
}
|
||||||
|
|
|
@ -51,7 +51,6 @@
|
||||||
|
|
||||||
#define RET_STALL -1
|
#define RET_STALL -1
|
||||||
#define RET_ZLP 0
|
#define RET_ZLP 0
|
||||||
#define RET_STAT_LEN 6
|
|
||||||
|
|
||||||
enum dfu_state {
|
enum dfu_state {
|
||||||
DFU_STATE_appIDLE = 0,
|
DFU_STATE_appIDLE = 0,
|
||||||
|
|
|
@ -49,8 +49,7 @@ static const char manufacturer[] = CONFIG_G_DNL_MANUFACTURER;
|
||||||
void g_dnl_set_serialnumber(char *s)
|
void g_dnl_set_serialnumber(char *s)
|
||||||
{
|
{
|
||||||
memset(g_dnl_serial, 0, MAX_STRING_SERIAL);
|
memset(g_dnl_serial, 0, MAX_STRING_SERIAL);
|
||||||
if (strlen(s) < MAX_STRING_SERIAL)
|
strncpy(g_dnl_serial, s, MAX_STRING_SERIAL - 1);
|
||||||
strncpy(g_dnl_serial, s, strlen(s));
|
|
||||||
}
|
}
|
||||||
|
|
||||||
static struct usb_device_descriptor device_desc = {
|
static struct usb_device_descriptor device_desc = {
|
||||||
|
|
Loading…
Add table
Reference in a new issue