[U-Boot] [PATCH v1 3/5] usb, g_dnl: make iSerialNumber board configurable
Heiko Schocher
hs at denx.de
Tue Oct 22 12:25:43 CEST 2013
add the possibility to set the iSerialNumber board specific.
Therefore the CONFIG_G_DNL_SERIAL_STRING is introduced, which
defines the maximum length of the iSerialNumber string.
The new function g_dnl_set_serialnumber() must called from
g_dnl_bind_fixup(), to setup the iSerialNumber string.
Signed-off-by: Heiko Schocher <hs at denx.de>
Cc: Marek Vasut <marek.vasut at gmail.com>
Cc: Lukasz Majewski <l.majewski at samsung.com>
Cc: Kyungmin Park <kyungmin.park at samsung.com>
---
drivers/usb/gadget/g_dnl.c | 28 ++++++++++++++++++++++++++++
include/g_dnl.h | 3 +++
2 files changed, 31 insertions(+)
diff --git a/drivers/usb/gadget/g_dnl.c b/drivers/usb/gadget/g_dnl.c
index 40868c0..5f09d66 100644
--- a/drivers/usb/gadget/g_dnl.c
+++ b/drivers/usb/gadget/g_dnl.c
@@ -39,8 +39,21 @@
static const char shortname[] = "usb_dnl_";
static const char product[] = "USB download gadget";
+#if defined(CONFIG_G_DNL_SERIAL_STRING)
+#define STRING_SERIAL 3
+static char g_dnl_serial[CONFIG_G_DNL_SERIAL_STRING + 1];
+#endif
static const char manufacturer[] = CONFIG_G_DNL_MANUFACTURER;
+#if defined(CONFIG_G_DNL_SERIAL_STRING)
+void g_dnl_set_serialnumber(char *s)
+{
+ memset(g_dnl_serial, 0, CONFIG_G_DNL_SERIAL_STRING + 1);
+ if (strlen(s) <= CONFIG_G_DNL_SERIAL_STRING)
+ strncpy(g_dnl_serial, s, strlen(s));
+}
+#endif
+
static struct usb_device_descriptor device_desc = {
.bLength = sizeof device_desc,
.bDescriptorType = USB_DT_DEVICE,
@@ -52,6 +65,9 @@ static struct usb_device_descriptor device_desc = {
.idVendor = __constant_cpu_to_le16(CONFIG_G_DNL_VENDOR_NUM),
.idProduct = __constant_cpu_to_le16(CONFIG_G_DNL_PRODUCT_NUM),
.iProduct = STRING_PRODUCT,
+#if defined(CONFIG_G_DNL_SERIAL_STRING)
+ .iSerialNumber = STRING_SERIAL,
+#endif
.bNumConfigurations = 1,
};
@@ -62,6 +78,9 @@ static struct usb_device_descriptor device_desc = {
static struct usb_string g_dnl_string_defs[] = {
{.s = manufacturer},
{.s = product},
+#if defined(CONFIG_G_DNL_SERIAL_STRING)
+ {.s = g_dnl_serial},
+#endif
{ } /* end of list */
};
@@ -145,6 +164,15 @@ static int g_dnl_bind(struct usb_composite_dev *cdev)
g_dnl_string_defs[1].id = id;
device_desc.iProduct = id;
+#if defined(CONFIG_G_DNL_SERIAL_STRING)
+ id = usb_string_id(cdev);
+ if (id < 0)
+ return id;
+
+ g_dnl_string_defs[2].id = id;
+ device_desc.iSerialNumber = id;
+#endif
+
g_dnl_bind_fixup(&device_desc);
ret = g_dnl_config_register(cdev);
if (ret)
diff --git a/include/g_dnl.h b/include/g_dnl.h
index 2b2f11a..a539a34 100644
--- a/include/g_dnl.h
+++ b/include/g_dnl.h
@@ -13,6 +13,9 @@
int g_dnl_bind_fixup(struct usb_device_descriptor *);
int g_dnl_register(const char *s);
void g_dnl_unregister(void);
+#if defined(CONFIG_G_DNL_SERIAL_STRING)
+void g_dnl_set_serialnumber(char *);
+#endif
/* USB initialization declaration - board specific */
void board_usb_init(void);
--
1.8.3.1
More information about the U-Boot
mailing list