summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorRyan Harkin <ryan.harkin@linaro.org>2018-03-08 15:15:28 +0000
committerRyan Harkin <ryan.harkin@linaro.org>2018-03-08 16:40:55 +0000
commit5c17566eae9a84786f14460c00cdbaf58f73b0ba (patch)
tree24c8ff99e82734350382c71d382eaf0437250bd7
parent66a25788a9979fc732db65ff4c5b71833fc3bb39 (diff)
sunxi: usb: Set USB device descriptor iSerial based on serial#
Copied from "warp7: usb: Set USB device descriptor iSerial based on serial#" by Bryan O'Donoghue <bryan.odonoghue@linaro.org>. Previous patches add routines to manipulate an OTP fuse to store and retrieve data that we will use to stuff the iSerial field of the standard USB device descriptor. The OTP variable is made available by the environment serial# variable. This patch takes the iseral# environment variable and stuffs the USB device descriptor iSerial field by way of an over-ridden weak symbol g_dnl_bind_fixup(). With this change in place any gadget device UMS, Ethernet etc, will provide a unique iSerial string, which you can see if you run lsusb -v as root. Example: Bus 001 Device 053: ID 1f3a:1010 Onda (unverified) Device Descriptor: bLength 18 bDescriptorType 1 bcdUSB 2.00 bDeviceClass 0 (Defined at Interface level) bDeviceSubClass 0 bDeviceProtocol 0 bMaxPacketSize0 64 idVendor 0x1f3a Onda (unverified) idProduct 0x1010 bcdDevice 2.15 iManufacturer 1 iProduct 2 USB download gadget iSerial 3 bananapi-m2-zero-02004620022f73fe bNumConfigurations 1 Where the iSerial string is the board name concatenated with the SID0 and SID3 words. Signed-off-by: Ryan Harkin <ryan.harkin@linaro.org>
-rw-r--r--board/sunxi/board.c21
1 files changed, 18 insertions, 3 deletions
diff --git a/board/sunxi/board.c b/board/sunxi/board.c
index 800f412b38..58c656f31b 100644
--- a/board/sunxi/board.c
+++ b/board/sunxi/board.c
@@ -16,7 +16,6 @@
#include <axp_pmic.h>
#include <asm/arch/clock.h>
#include <asm/arch/cpu.h>
-#include <asm/arch/display.h>
#include <asm/arch/dram.h>
#include <asm/arch/gpio.h>
#include <asm/arch/mmc.h>
@@ -34,6 +33,7 @@
#include <net.h>
#include <sy8106a.h>
#include <asm/setup.h>
+#include <g_dnl.h>
#if defined CONFIG_VIDEO_LCD_PANEL_I2C && !(defined CONFIG_SPL_BUILD)
/* So that we can use pin names in Kconfig and sunxi_name_to_gpio() */
@@ -655,7 +655,7 @@ static void parse_spl_header(const uint32_t spl_addr)
*/
static void setup_environment(const void *fdt)
{
- char serial_string[17] = { 0 };
+ char serial_string[34] = { 0 };
unsigned int sid[4];
uint8_t mac_addr[6];
char ethaddr[16];
@@ -710,7 +710,7 @@ static void setup_environment(const void *fdt)
if (!getenv("serial#")) {
snprintf(serial_string, sizeof(serial_string),
- "%08x%08x", sid[0], sid[3]);
+ "bananapi-m2-zero-%08x%08x", sid[0], sid[3]);
setenv("serial#", serial_string);
}
@@ -787,3 +787,18 @@ int board_fit_config_name_match(const char *name)
}
}
#endif
+
+#ifdef CONFIG_USB_GADGET
+
+/* Over-ride weak symbol to set device descriptor iSerial field */
+int g_dnl_bind_fixup(struct usb_device_descriptor *dev, const char *name)
+{
+ char *str = getenv("serial#");
+
+ if (str)
+ g_dnl_set_serialnumber(str);
+
+ return 0;
+}
+
+#endif /* ifdef CONFIG_USB_GADGET */