Skip to contentSkip to conversation

usb: gadget: g_dnl: Sync internal SN variable with env

PATCH Superseded Sam Protsenko 1 participant 2 messages Sep 1, 2017 USB

v2 of 3 Superseded Latest is v3 →

lore
Share & tools
lore
#0 lore raw

PATCH v2 1/1 usb: gadget: g_dnl: Sync internal SN variable with env

Since commit 842778a09104 ("usb: gadget: g_dnl: only set iSerialNumber if we have a serial#") "fastboot devices" stopped to show correct device serial number for TI boards, showing this line instead:

    ????????????	fastboot

This is because serial# env variable could be set after g_dnl gadget was initialized (e.g. by using env_set() in the board file).

To fix this, let's update internal serial number variable (g_dnl_serial) when "serial#" env var is changed.

---
 drivers/usb/gadget/g_dnl.c | 24 ++++++++++++++++++++++++
 include/env_callback.h     |  1 +
 2 files changed, 25 insertions(+)
drivers/usb/gadget/g_dnl.c +24 -0
index 0491a0eea9..1a9f075485 100644
@@ -19,6 +19,8 @@
 #include <dfu.h>
 #include <thor.h>
 
+#include <env_callback.h>
+
 #include "gadget_chips.h"
 #include "composite.c"
 
@@ -202,6 +204,28 @@ static int g_dnl_get_bcd_device_number(struct usb_composite_dev *cdev)
 	return g_dnl_get_board_bcd_device_number(gcnum);
 }
 
+/**
+ * Update internal serial number variable when the "serial#" env var changes.
+ *
+ * Handle all cases, including when flags == H_PROGRAMMATIC.
+ */
+static int on_serialno(const char *name, const char *value, enum env_op op,
+		int flags)
+{
+	switch (op) {
+	case env_op_create:
+		/* Fall through */
+	case env_op_overwrite:
+		g_dnl_set_serialnumber((char *)value);
+		break;
+	default:
+		break;
+	}
+
+	return 0;
+}
+U_BOOT_ENV_CALLBACK(serialno, on_serialno);
+
 static int g_dnl_bind(struct usb_composite_dev *cdev)
 {
 	struct usb_gadget *gadget = cdev->gadget;
include/env_callback.h +1 -0
index 90b95b5e66..5c4a30c2de 100644
@@ -72,6 +72,7 @@
 	SILENT_CALLBACK \
 	SPLASHIMAGE_CALLBACK \
 	"stdin:console,stdout:console,stderr:console," \
+	"serial#:serialno," \
 	CONFIG_ENV_CALLBACK_LIST_STATIC
 
 struct env_clbk_tbl {
Signature · 1 line
2.14.1
#1 lore raw

PATCH v2 1/1 usb: gadget: g_dnl: Sync internal SN variable with env

Quoted 74 lines · Sam Protsenko

Since commit 842778a09104 ("usb: gadget: g_dnl: only set iSerialNumber if we have a serial#") "fastboot devices" stopped to show correct device serial number for TI boards, showing this line instead:

    ????????????        fastboot

This is because serial# env variable could be set after g_dnl gadget was initialized (e.g. by using env_set() in the board file).

To fix this, let's update internal serial number variable (g_dnl_serial) when "serial#" env var is changed.

---
 drivers/usb/gadget/g_dnl.c | 24 ++++++++++++++++++++++++
 include/env_callback.h     |  1 +
 2 files changed, 25 insertions(+)
drivers/usb/gadget/g_dnl.c +24 -0
index 0491a0eea9..1a9f075485 100644
@@ -19,6 +19,8 @@
 #include <dfu.h>
 #include <thor.h>
 
+#include <env_callback.h>
+
 #include "gadget_chips.h"
 #include "composite.c"
 
@@ -202,6 +204,28 @@ static int g_dnl_get_bcd_device_number(struct usb_composite_dev *cdev)
        return g_dnl_get_board_bcd_device_number(gcnum);
 }
 
+/**
+ * Update internal serial number variable when the "serial#" env var changes.
+ *
+ * Handle all cases, including when flags == H_PROGRAMMATIC.
+ */
+static int on_serialno(const char *name, const char *value, enum env_op op,
+               int flags)
+{
+       switch (op) {
+       case env_op_create:
+               /* Fall through */
+       case env_op_overwrite:
+               g_dnl_set_serialnumber((char *)value);
+               break;
+       default:
+               break;
+       }
+
+       return 0;
+}
+U_BOOT_ENV_CALLBACK(serialno, on_serialno);
+
 static int g_dnl_bind(struct usb_composite_dev *cdev)
 {
        struct usb_gadget *gadget = cdev->gadget;
include/env_callback.h +1 -1
index 90b95b5e66..5c4a30c2de 100644
@@ -72,6 +72,7 @@
        SILENT_CALLBACK \
        SPLASHIMAGE_CALLBACK \
        "stdin:console,stdout:console,stderr:console," \
+       "serial#:serialno," \
        CONFIG_ENV_CALLBACK_LIST_STATIC
 
 struct env_clbk_tbl {
--
Quoted 2 lines

2.14.1

Please ignore this patch. It doesn't handle the env_op_delete event. Will send v3 soon.