Move the descriptor checks up from dfu_init() into the

FLIP protocol implementation.



git-svn-id: svn://svn.savannah.nongnu.org/avrdude/trunk/avrdude@1266 81a1dc3b-b13d-400b-aceb-764788c761c2
This commit is contained in:
joerg_wunsch 2014-01-16 08:11:19 +00:00
parent bd260fe2a4
commit 3dc4496761
4 changed files with 102 additions and 43 deletions

View File

@ -1,3 +1,10 @@
2014-01-16 Joerg Wunsch <j.gnu@uriah.heep.sax.de>
* dfu.c (dfu_init): Move the descriptor checks up into the
FLIP protocol implementation.
* flip2.c (flip2_initialize): (Dito.)
* flip1.c (flip1_initialize): (Dito.)
2014-01-16 Joerg Wunsch <j.gnu@uriah.heep.sax.de> 2014-01-16 Joerg Wunsch <j.gnu@uriah.heep.sax.de>
* flip2.c: Rename from flip.c * flip2.c: Rename from flip.c

42
dfu.c
View File

@ -236,48 +236,6 @@ int dfu_init(struct dfu_dev *dfu, unsigned short vid, unsigned short pid)
memcpy(&dfu->endp_desc, found->config->interface->altsetting->endpoint, memcpy(&dfu->endp_desc, found->config->interface->altsetting->endpoint,
sizeof(dfu->endp_desc)); sizeof(dfu->endp_desc));
/* Check if descriptor values are what we expect. */
if (dfu->dev_desc.idVendor != vid)
fprintf( stderr, "%s: Warning: USB idVendor = 0x%04X (expected 0x%04X)\n",
progname, dfu->dev_desc.idVendor, vid);
if (pid != 0 && dfu->dev_desc.idProduct != pid)
fprintf( stderr, "%s: Warning: USB idProduct = 0x%04X (expected 0x%04X)\n",
progname, dfu->dev_desc.idProduct, pid);
if (dfu->dev_desc.bNumConfigurations != 1)
fprintf( stderr, "%s: Warning: USB bNumConfigurations = %d (expected 1)\n",
progname, (int) dfu->dev_desc.bNumConfigurations);
if (dfu->conf_desc.bNumInterfaces != 1)
fprintf( stderr, "%s: Warning: USB bNumInterfaces = %d (expected 1)\n",
progname, (int) dfu->conf_desc.bNumInterfaces);
if (dfu->dev_desc.bDeviceClass != 0)
fprintf( stderr, "%s: Warning: USB bDeviceClass = %d (expected 0)\n",
progname, (int) dfu->dev_desc.bDeviceClass);
if (dfu->dev_desc.bDeviceSubClass != 0)
fprintf( stderr, "%s: Warning: USB bDeviceSubClass = %d (expected 0)\n",
progname, (int) dfu->dev_desc.bDeviceSubClass);
if (dfu->dev_desc.bDeviceProtocol != 0)
fprintf( stderr, "%s: Warning: USB bDeviceProtocol = %d (expected 0)\n",
progname, (int) dfu->dev_desc.bDeviceProtocol);
if (dfu->intf_desc.bInterfaceClass != 0xFF)
fprintf( stderr, "%s: Warning: USB bInterfaceClass = %d (expected 255)\n",
progname, (int) dfu->intf_desc.bInterfaceClass);
if (dfu->intf_desc.bInterfaceSubClass != 0)
fprintf( stderr, "%s: Warning: USB bInterfaceSubClass = %d (expected 0)\n",
progname, (int) dfu->intf_desc.bInterfaceSubClass);
if (dfu->intf_desc.bInterfaceProtocol != 0)
fprintf( stderr, "%s: Warning: USB bInterfaceSubClass = %d (expected 0)\n",
progname, (int) dfu->intf_desc.bInterfaceProtocol);
/* Get strings. */ /* Get strings. */
dfu->manf_str = get_usb_string(dfu->dev_handle, dfu->manf_str = get_usb_string(dfu->dev_handle,

51
flip1.c
View File

@ -162,6 +162,7 @@ int flip1_initialize(PROGRAMMER* pgm, AVRPART *part)
{ {
unsigned short vid, pid; unsigned short vid, pid;
int result; int result;
struct dfu_dev *dfu = FLIP1(pgm)->dfu;
/* A note about return values. Negative return values from this function are /* A note about return values. Negative return values from this function are
* interpreted as failure by main(), from where this function is called. * interpreted as failure by main(), from where this function is called.
@ -199,6 +200,56 @@ int flip1_initialize(PROGRAMMER* pgm, AVRPART *part)
if (result != 0) if (result != 0)
goto flip1_initialize_fail; goto flip1_initialize_fail;
/* Check if descriptor values are what we expect. */
if (dfu->dev_desc.idVendor != vid)
fprintf( stderr, "%s: Warning: USB idVendor = 0x%04X (expected 0x%04X)\n",
progname, dfu->dev_desc.idVendor, vid);
if (pid != 0 && dfu->dev_desc.idProduct != pid)
fprintf( stderr, "%s: Warning: USB idProduct = 0x%04X (expected 0x%04X)\n",
progname, dfu->dev_desc.idProduct, pid);
if (dfu->dev_desc.bNumConfigurations != 1)
fprintf( stderr, "%s: Warning: USB bNumConfigurations = %d (expected 1)\n",
progname, (int) dfu->dev_desc.bNumConfigurations);
if (dfu->conf_desc.bNumInterfaces != 1)
fprintf( stderr, "%s: Warning: USB bNumInterfaces = %d (expected 1)\n",
progname, (int) dfu->conf_desc.bNumInterfaces);
if (dfu->dev_desc.bDeviceClass != 254)
fprintf( stderr, "%s: Warning: USB bDeviceClass = %d (expected 254)\n",
progname, (int) dfu->dev_desc.bDeviceClass);
if (dfu->dev_desc.bDeviceSubClass != 1)
fprintf( stderr, "%s: Warning: USB bDeviceSubClass = %d (expected 1)\n",
progname, (int) dfu->dev_desc.bDeviceSubClass);
if (dfu->dev_desc.bDeviceProtocol != 0)
fprintf( stderr, "%s: Warning: USB bDeviceProtocol = %d (expected 0)\n",
progname, (int) dfu->dev_desc.bDeviceProtocol);
/*
* doc7618 claims an interface class of FEh and a subclas 01h.
* However, as of today (2014-01-16), all values in the interface
* descriptor (except of bLength and bDescriptorType) are actually
* 0. So rather don't check these.
*/
if (0) {
if (dfu->intf_desc.bInterfaceClass != 254)
fprintf( stderr, "%s: Warning: USB bInterfaceClass = %d (expected 254)\n",
progname, (int) dfu->intf_desc.bInterfaceClass);
if (dfu->intf_desc.bInterfaceSubClass != 1)
fprintf( stderr, "%s: Warning: USB bInterfaceSubClass = %d (expected 1)\n",
progname, (int) dfu->intf_desc.bInterfaceSubClass);
if (dfu->intf_desc.bInterfaceProtocol != 0)
fprintf( stderr, "%s: Warning: USB bInterfaceSubClass = %d (expected 0)\n",
progname, (int) dfu->intf_desc.bInterfaceProtocol);
}
#if 0 #if 0
result = flip1_read_memory(FLIP1(pgm)->dfu, result = flip1_read_memory(FLIP1(pgm)->dfu,
FLIP1_MEM_UNIT_SIGNATURE, 0, FLIP1(pgm)->part_sig, 4); FLIP1_MEM_UNIT_SIGNATURE, 0, FLIP1(pgm)->part_sig, 4);

45
flip2.c
View File

@ -210,6 +210,7 @@ int flip2_initialize(PROGRAMMER* pgm, AVRPART *part)
{ {
unsigned short vid, pid; unsigned short vid, pid;
int result; int result;
struct dfu_dev *dfu = FLIP2(pgm)->dfu;
/* A note about return values. Negative return values from this function are /* A note about return values. Negative return values from this function are
* interpreted as failure by main(), from where this function is called. * interpreted as failure by main(), from where this function is called.
@ -242,11 +243,53 @@ int flip2_initialize(PROGRAMMER* pgm, AVRPART *part)
return -1; return -1;
} }
result = dfu_init(FLIP2(pgm)->dfu, vid, pid); result = dfu_init(dfu, vid, pid);
if (result != 0) if (result != 0)
goto flip2_initialize_fail; goto flip2_initialize_fail;
/* Check if descriptor values are what we expect. */
if (dfu->dev_desc.idVendor != vid)
fprintf( stderr, "%s: Warning: USB idVendor = 0x%04X (expected 0x%04X)\n",
progname, dfu->dev_desc.idVendor, vid);
if (pid != 0 && dfu->dev_desc.idProduct != pid)
fprintf( stderr, "%s: Warning: USB idProduct = 0x%04X (expected 0x%04X)\n",
progname, dfu->dev_desc.idProduct, pid);
if (dfu->dev_desc.bNumConfigurations != 1)
fprintf( stderr, "%s: Warning: USB bNumConfigurations = %d (expected 1)\n",
progname, (int) dfu->dev_desc.bNumConfigurations);
if (dfu->conf_desc.bNumInterfaces != 1)
fprintf( stderr, "%s: Warning: USB bNumInterfaces = %d (expected 1)\n",
progname, (int) dfu->conf_desc.bNumInterfaces);
if (dfu->dev_desc.bDeviceClass != 0)
fprintf( stderr, "%s: Warning: USB bDeviceClass = %d (expected 0)\n",
progname, (int) dfu->dev_desc.bDeviceClass);
if (dfu->dev_desc.bDeviceSubClass != 0)
fprintf( stderr, "%s: Warning: USB bDeviceSubClass = %d (expected 0)\n",
progname, (int) dfu->dev_desc.bDeviceSubClass);
if (dfu->dev_desc.bDeviceProtocol != 0)
fprintf( stderr, "%s: Warning: USB bDeviceProtocol = %d (expected 0)\n",
progname, (int) dfu->dev_desc.bDeviceProtocol);
if (dfu->intf_desc.bInterfaceClass != 0xFF)
fprintf( stderr, "%s: Warning: USB bInterfaceClass = %d (expected 255)\n",
progname, (int) dfu->intf_desc.bInterfaceClass);
if (dfu->intf_desc.bInterfaceSubClass != 0)
fprintf( stderr, "%s: Warning: USB bInterfaceSubClass = %d (expected 0)\n",
progname, (int) dfu->intf_desc.bInterfaceSubClass);
if (dfu->intf_desc.bInterfaceProtocol != 0)
fprintf( stderr, "%s: Warning: USB bInterfaceSubClass = %d (expected 0)\n",
progname, (int) dfu->intf_desc.bInterfaceProtocol);
result = flip2_read_memory(FLIP2(pgm)->dfu, result = flip2_read_memory(FLIP2(pgm)->dfu,
FLIP2_MEM_UNIT_SIGNATURE, 0, FLIP2(pgm)->part_sig, 4); FLIP2_MEM_UNIT_SIGNATURE, 0, FLIP2(pgm)->part_sig, 4);