Change in osmo-ccid-firmware[master]: Add DFU runtime descriptor

This is merely a historical archive of years 2008-2021, before the migration to mailman3.

A maintained and still updated list archive can be found at https://lists.osmocom.org/hyperkitty/list/gerrit-log@lists.osmocom.org/.

laforge gerrit-no-reply at lists.osmocom.org
Mon Feb 10 10:25:44 UTC 2020


laforge has submitted this change. ( https://gerrit.osmocom.org/c/osmo-ccid-firmware/+/17033 )

Change subject: Add DFU runtime descriptor
......................................................................

Add DFU runtime descriptor

Change-Id: I031c2353248873735698c845f591537779eee995
---
A sysmoOCTSIM/dfu_descriptors.h
M sysmoOCTSIM/usb_descriptors.c
M sysmoOCTSIM/usb_descriptors.h
A sysmoOCTSIM/usb_dfu.h
4 files changed, 133 insertions(+), 4 deletions(-)

Approvals:
  laforge: Looks good to me, approved
  Jenkins Builder: Verified



diff --git a/sysmoOCTSIM/dfu_descriptors.h b/sysmoOCTSIM/dfu_descriptors.h
new file mode 100644
index 0000000..8cbaf23
--- /dev/null
+++ b/sysmoOCTSIM/dfu_descriptors.h
@@ -0,0 +1,44 @@
+#ifndef _USB_DEV_DFU_H
+#define _USB_DEV_DFU_H
+
+#include <stdint.h>
+
+#include "usb_protocol.h"
+#include "usb_dfu.h"
+
+/* USB DFU functional descriptor */
+#define DFU_FUNC_DESC  {						\
+	.bLength		= USB_DT_DFU_SIZE,			\
+	.bDescriptorType	= USB_DT_DFU,				\
+	.bmAttributes		= USB_DFU_CAN_UPLOAD | USB_DFU_CAN_DOWNLOAD, \
+	.wDetachTimeOut		= 5000,					\
+	.wTransferSize		= FLASH_PAGE_SIZE,			\
+	.bcdDFUVersion		= 0x0100,				\
+}
+
+/* Number of DFU interface during runtime mode */
+#define DFURT_NUM_IF		1
+
+/* to be used by the runtime as part of its USB descriptor structure
+ * declaration */
+#define DFURT_IF_DESCRIPTOR_STRUCT		\
+	struct usb_iface_desc		dfu_rt;		\
+	struct usb_dfu_func_descriptor	func_dfu;
+
+/* to be used by the runtime as part of its USB Dsecriptor structure
+ * definition */
+#define DFURT_IF_DESCRIPTOR(dfuIF, dfuSTR)					\
+	.dfu_rt = {								\
+		.bLength 		= sizeof(struct usb_iface_desc),	\
+		.bDescriptorType	= USB_DT_INTERFACE,			\
+		.bInterfaceNumber	= dfuIF,				\
+		.bAlternateSetting	= 0,					\
+		.bNumEndpoints		= 0,					\
+		.bInterfaceClass	= 0xFE,					\
+		.bInterfaceSubClass	= 0x01,					\
+		.bInterfaceProtocol	= 0x01,					\
+		.iInterface		= dfuSTR,				\
+	},									\
+	.func_dfu = DFU_FUNC_DESC						\
+
+#endif
diff --git a/sysmoOCTSIM/usb_descriptors.c b/sysmoOCTSIM/usb_descriptors.c
index 2b41390..00d2007 100644
--- a/sysmoOCTSIM/usb_descriptors.c
+++ b/sysmoOCTSIM/usb_descriptors.c
@@ -47,8 +47,10 @@
 		.bDescriptorType = USB_DT_CONFIG,
 		.wTotalLength = sizeof(usb_fs_descs.cfg) +
 				sizeof(usb_fs_descs.cdc) +
-				sizeof(usb_fs_descs.ccid),
-		.bNumInterfaces = 3,
+				sizeof(usb_fs_descs.ccid) +
+				sizeof(usb_fs_descs.dfu_rt) +
+				sizeof(usb_fs_descs.func_dfu),
+		.bNumInterfaces = 4,
 		.bConfigurationValue = CONF_USB_CDCD_ACM_BCONFIGVAL,
 		.iConfiguration = STR_DESC_CONFIG,
 		.bmAttributes = CONF_USB_CDCD_ACM_BMATTRI,
@@ -206,7 +208,7 @@
 			},
 		},
 	},
-	//DFURT_IF_DESCRIPTOR,
+	DFURT_IF_DESCRIPTOR(3, STR_DESC_INTF_DFURT),
 	.str = {
 #if 0
 		CDCD_ACM_STR_DESCES
@@ -219,6 +221,7 @@
 		22,  3, 'd',0, 'e',0, 'b',0, 'u',0, 'g',0, ' ',0, 'U',0, 'A',0, 'R',0, 'T',0,
 		10,  3, 'C',0, 'C',0, 'I',0, 'D',0,
 		12,  3, 'F',0, 'I',0, 'X',0, 'M',0, 'E',0,
+		28,  3, 'D',0, 'F',0, 'U',0, ' ',0, '(',0, 'R',0, 'u',0, 'n',0, 't',0, 'i',0, 'm',0, 'e',0 ,')',0,
 #endif
 	}
 };
diff --git a/sysmoOCTSIM/usb_descriptors.h b/sysmoOCTSIM/usb_descriptors.h
index df072c2..ea47d07 100644
--- a/sysmoOCTSIM/usb_descriptors.h
+++ b/sysmoOCTSIM/usb_descriptors.h
@@ -20,6 +20,7 @@
 #define USB_DESCRIPTORS_H_
 
 #include "ccid_device.h"
+#include "dfu_descriptors.h"
 
 #define CCID_NUM_CLK_SUPPORTED 4
 
@@ -34,6 +35,7 @@
 	STR_DESC_INTF_ACM_DATA,
 	STR_DESC_INTF_CCID,
 	STR_DESC_SERIAL,
+	STR_DESC_INTF_DFURT,
 };
 
 /* a struct of structs representing the concatenated collection of USB descriptors */
@@ -63,7 +65,8 @@
 		struct usb_ccid_class_descriptor class;
 		struct usb_ep_desc ep[3];
 	} ccid;
-	uint8_t str[148];
+	DFURT_IF_DESCRIPTOR_STRUCT
+	uint8_t str[176];
 } __attribute__((packed));
 
 #endif /* USB_DESCRIPTORS_H_ */
diff --git a/sysmoOCTSIM/usb_dfu.h b/sysmoOCTSIM/usb_dfu.h
new file mode 100644
index 0000000..b447c7c
--- /dev/null
+++ b/sysmoOCTSIM/usb_dfu.h
@@ -0,0 +1,79 @@
+#ifndef _USB_DFU_H
+#define _USB_DFU_H
+/* USB Device Firmware Update Implementation for OpenPCD
+ * (C) 2006 by Harald Welte <hwelte at hmw-consulting.de>
+ *
+ * Protocol definitions for USB DFU
+ *
+ * This ought to be compliant to the USB DFU Spec 1.0 as available from
+ * http://www.usb.org/developers/devclass_docs/usbdfu10.pdf
+ *
+ */
+
+#include <stdint.h>
+
+#define USB_DT_DFU			0x21
+
+struct usb_dfu_func_descriptor {
+	uint8_t		bLength;
+	uint8_t		bDescriptorType;
+	uint8_t		bmAttributes;
+#define USB_DFU_CAN_DOWNLOAD	(1 << 0)
+#define USB_DFU_CAN_UPLOAD	(1 << 1)
+#define USB_DFU_MANIFEST_TOL	(1 << 2)
+#define USB_DFU_WILL_DETACH	(1 << 3)
+	uint16_t		wDetachTimeOut;
+	uint16_t		wTransferSize;
+	uint16_t		bcdDFUVersion;
+} __attribute__ ((packed));
+
+#define USB_DT_DFU_SIZE			9
+
+/* DFU class-specific requests (Section 3, DFU Rev 1.1) */
+#define USB_REQ_DFU_DETACH	0x00
+#define USB_REQ_DFU_DNLOAD	0x01
+#define USB_REQ_DFU_UPLOAD	0x02
+#define USB_REQ_DFU_GETSTATUS	0x03
+#define USB_REQ_DFU_CLRSTATUS	0x04
+#define USB_REQ_DFU_GETSTATE	0x05
+#define USB_REQ_DFU_ABORT	0x06
+
+struct dfu_status {
+	uint8_t bStatus;
+	uint8_t bwPollTimeout[3];
+	uint8_t bState;
+	uint8_t iString;
+} __attribute__((packed));
+
+#define DFU_STATUS_OK			0x00
+#define DFU_STATUS_errTARGET		0x01
+#define DFU_STATUS_errFILE		0x02
+#define DFU_STATUS_errWRITE		0x03
+#define DFU_STATUS_errERASE		0x04
+#define DFU_STATUS_errCHECK_ERASED	0x05
+#define DFU_STATUS_errPROG		0x06
+#define DFU_STATUS_errVERIFY		0x07
+#define DFU_STATUS_errADDRESS		0x08
+#define DFU_STATUS_errNOTDONE		0x09
+#define DFU_STATUS_errFIRMWARE		0x0a
+#define DFU_STATUS_errVENDOR		0x0b
+#define DFU_STATUS_errUSBR		0x0c
+#define DFU_STATUS_errPOR		0x0d
+#define DFU_STATUS_errUNKNOWN		0x0e
+#define DFU_STATUS_errSTALLEDPKT	0x0f
+
+enum dfu_state {
+	DFU_STATE_appIDLE		= 0,
+	DFU_STATE_appDETACH		= 1,
+	DFU_STATE_dfuIDLE		= 2,
+	DFU_STATE_dfuDNLOAD_SYNC	= 3,
+	DFU_STATE_dfuDNBUSY		= 4,
+	DFU_STATE_dfuDNLOAD_IDLE	= 5,
+	DFU_STATE_dfuMANIFEST_SYNC	= 6,
+	DFU_STATE_dfuMANIFEST		= 7,
+	DFU_STATE_dfuMANIFEST_WAIT_RST	= 8,
+	DFU_STATE_dfuUPLOAD_IDLE	= 9,
+	DFU_STATE_dfuERROR		= 10,
+};
+
+#endif /* _USB_DFU_H */

-- 
To view, visit https://gerrit.osmocom.org/c/osmo-ccid-firmware/+/17033
To unsubscribe, or for help writing mail filters, visit https://gerrit.osmocom.org/settings

Gerrit-Project: osmo-ccid-firmware
Gerrit-Branch: master
Gerrit-Change-Id: I031c2353248873735698c845f591537779eee995
Gerrit-Change-Number: 17033
Gerrit-PatchSet: 4
Gerrit-Owner: Hoernchen <ewild at sysmocom.de>
Gerrit-Reviewer: Jenkins Builder
Gerrit-Reviewer: laforge <laforge at osmocom.org>
Gerrit-MessageType: merged
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.osmocom.org/pipermail/gerrit-log/attachments/20200210/6b1fe1c4/attachment.htm>


More information about the gerrit-log mailing list