Skip to contentSkip to conversation

usb, g_dnl: generalize DFU detach functions

PATCH New Rob Herring 3 participants 6 messages Dec 10, 2014 – Dec 11, 2014 USB

lore
Share & tools
lore
#0 lore raw

PATCH 1/2 usb, g_dnl: generalize DFU detach functions

From: Rob Herring <[email protected]>

In order to add detach functions for fastboot, make the DFU detach related functions common so they can be shared.

---
 common/cmd_dfu.c           |  6 +++---
 drivers/dfu/dfu.c          | 16 ----------------
 drivers/usb/gadget/f_dfu.c |  2 +-
 drivers/usb/gadget/g_dnl.c | 17 +++++++++++++++++
 include/dfu.h              |  3 ---
 include/g_dnl.h            |  4 ++++
 6 files changed, 25 insertions(+), 23 deletions(-)
common/cmd_dfu.c +3 -3
index 9e020b4..e975abe 100644
@@ -38,10 +38,10 @@ static int do_dfu(cmd_tbl_t *cmdtp, int flag, int argc, char * const argv[])
 
 	int controller_index = simple_strtoul(usb_controller, NULL, 0);
 	board_usb_init(controller_index, USB_INIT_DEVICE);
-	dfu_clear_detach();
+	g_dnl_clear_detach();
 	g_dnl_register("usb_dnl_dfu");
 	while (1) {
-		if (dfu_detach()) {
+		if (g_dnl_detach()) {
 			/*
 			 * Check if USB bus reset is performed after detach,
 			 * which indicates that -R switch has been passed to
@@ -74,7 +74,7 @@ done:
 	if (dfu_reset)
 		run_command("reset", 0);
 
-	dfu_clear_detach();
+	g_dnl_clear_detach();
 
 	return ret;
 }
drivers/dfu/dfu.c +0 -16
index c0aba6e..a3e3ec5 100644
@@ -17,7 +17,6 @@
 #include <linux/list.h>
 #include <linux/compiler.h>
 
-static bool dfu_detach_request;
 static LIST_HEAD(dfu_list);
 static int dfu_alt_num;
 static int alt_num_cnt;
@@ -39,21 +38,6 @@ __weak bool dfu_usb_get_reset(void)
 	return true;
 }
 
-bool dfu_detach(void)
-{
-	return dfu_detach_request;
-}
-
-void dfu_trigger_detach(void)
-{
-	dfu_detach_request = true;
-}
-
-void dfu_clear_detach(void)
-{
-	dfu_detach_request = false;
-}
-
 static int dfu_find_alt_num(const char *s)
 {
 	int i = 0;
drivers/usb/gadget/f_dfu.c +1 -1
index 16fc9dd..ead71eb 100644
@@ -366,7 +366,7 @@ static int state_dfu_idle(struct f_dfu *f_dfu,
 		to_runtime_mode(f_dfu);
 		f_dfu->dfu_state = DFU_STATE_appIDLE;
 
-		dfu_trigger_detach();
+		g_dnl_trigger_detach();
 		break;
 	default:
 		f_dfu->dfu_state = DFU_STATE_dfuERROR;
drivers/usb/gadget/g_dnl.c +17 -0
index 25611ac..ee52a29 100644
@@ -163,6 +163,23 @@ __weak int g_dnl_board_usb_cable_connected(void)
 	return -EOPNOTSUPP;
 }
 
+static bool g_dnl_detach_request;
+
+bool g_dnl_detach(void)
+{
+	return g_dnl_detach_request;
+}
+
+void g_dnl_trigger_detach(void)
+{
+	g_dnl_detach_request = true;
+}
+
+void g_dnl_clear_detach(void)
+{
+	g_dnl_detach_request = false;
+}
+
 static int g_dnl_get_bcd_device_number(struct usb_composite_dev *cdev)
 {
 	struct usb_gadget *gadget = cdev->gadget;
include/dfu.h +0 -3
index f1a71c7..c27856c 100644
@@ -150,9 +150,6 @@ struct dfu_entity *dfu_get_entity(int alt);
 char *dfu_extract_token(char** e, int *n);
 void dfu_trigger_reset(void);
 int dfu_get_alt(char *name);
-bool dfu_detach(void);
-void dfu_trigger_detach(void);
-void dfu_clear_detach(void);
 int dfu_init_env_entities(char *interface, char *devstr);
 unsigned char *dfu_get_buf(struct dfu_entity *dfu);
 unsigned char *dfu_free_buf(void);
include/g_dnl.h +4 -0
index 1b1b35e..4eeb5e4 100644
@@ -39,4 +39,8 @@ int g_dnl_register(const char *s);
 void g_dnl_unregister(void);
 void g_dnl_set_serialnumber(char *);
 
+bool g_dnl_detach(void);
+void g_dnl_trigger_detach(void);
+void g_dnl_clear_detach(void);
+
 #endif /* __G_DOWNLOAD_H_ */
Signature · 1 line
2.1.0
#1 lore raw

PATCH 2/2 fastboot: add support for continue command

From: Rob Herring <[email protected]>

The fastboot continue command is defined to exit fastboot and continue autoboot. This commit implements the continue command and the exiting of fastboot only. Subsequent u-boot commands can be processed after exiting fastboot. Autoboot should implement a boot script such as "fastboot; mmc read <...>; bootm" to fully implement the fastboot continue function.

---
 common/cmd_fastboot.c           |  4 ++++
 drivers/usb/gadget/f_fastboot.c | 14 ++++++++++++++
 2 files changed, 18 insertions(+)
common/cmd_fastboot.c +4 -0
index 909616d..b72f4f3 100644
@@ -15,17 +15,21 @@ static int do_fastboot(cmd_tbl_t *cmdtp, int flag, int argc, char *const argv[])
 {
 	int ret;
 
+	g_dnl_clear_detach();
 	ret = g_dnl_register("usb_dnl_fastboot");
 	if (ret)
 		return ret;
 
 	while (1) {
+		if (g_dnl_detach())
+			break;
 		if (ctrlc())
 			break;
 		usb_gadget_handle_interrupts();
 	}
 
 	g_dnl_unregister();
+	g_dnl_clear_detach();
 	return CMD_RET_SUCCESS;
 }
 
drivers/usb/gadget/f_fastboot.c +14 -0
index 71b62e5..310175a 100644
@@ -480,6 +480,17 @@ static void cb_boot(struct usb_ep *ep, struct usb_request *req)
 	fastboot_tx_write_str("OKAY");
 }
 
+static void do_exit_on_complete(struct usb_ep *ep, struct usb_request *req)
+{
+	g_dnl_trigger_detach();
+}
+
+static void cb_continue(struct usb_ep *ep, struct usb_request *req)
+{
+	fastboot_func->in_req->complete = do_exit_on_complete;
+	fastboot_tx_write_str("OKAY");
+}
+
 #ifdef CONFIG_FASTBOOT_FLASH
 static void cb_flash(struct usb_ep *ep, struct usb_request *req)
 {
@@ -520,6 +531,9 @@ static const struct cmd_dispatch_info cmd_dispatch_info[] = {
 	}, {
 		.cmd = "boot",
 		.cb = cb_boot,
+	}, {
+		.cmd = "continue",
+		.cb = cb_continue,
 	},
 #ifdef CONFIG_FASTBOOT_FLASH
 	{
Signature · 1 line
2.1.0
#2 lore raw

PATCH 2/2 fastboot: add support for continue command

Quoted 9 lines · Rob Herring

From: Rob Herring <[email protected]>

The fastboot continue command is defined to exit fastboot and continue autoboot. This commit implements the continue command and the exiting of fastboot only. Subsequent u-boot commands can be processed after exiting fastboot. Autoboot should implement a boot script such as "fastboot; mmc read <...>; bootm" to fully implement the fastboot continue function.

Hi!

Again, CC Lukasz . As for the boot script implementation, I believe this should be documented in some README file, possibly in doc/README.android-fastboot . What do you think?

Best regards,
Marek Vasut

#3 lore raw

PATCH 2/2 fastboot: add support for continue command

In reply to Rob Herring

Hi Rob,

Quoted 64 lines

From: Rob Herring <[email protected]>

The fastboot continue command is defined to exit fastboot and continue autoboot. This commit implements the continue command and the exiting of fastboot only. Subsequent u-boot commands can be processed after exiting fastboot. Autoboot should implement a boot script such as "fastboot; mmc read <...>; bootm" to fully implement the fastboot continue function.

---
 common/cmd_fastboot.c           |  4 ++++
 drivers/usb/gadget/f_fastboot.c | 14 ++++++++++++++
 2 files changed, 18 insertions(+)
common/cmd_fastboot.c +4 -0
index 909616d..b72f4f3 100644
@@ -15,17 +15,21 @@ static int do_fastboot(cmd_tbl_t *cmdtp, int
 flag, int argc, char *const argv[]) {
 	int ret;
 
+	g_dnl_clear_detach();
 	ret = g_dnl_register("usb_dnl_fastboot");
 	if (ret)
 		return ret;
 
 	while (1) {
+		if (g_dnl_detach())
+			break;
 		if (ctrlc())
 			break;
 		usb_gadget_handle_interrupts();
 	}
 
 	g_dnl_unregister();
+	g_dnl_clear_detach();
 	return CMD_RET_SUCCESS;
 }
 
(quoted diff) +0 -0

b/drivers/usb/gadget/f_fastboot.c index 71b62e5..310175a 100644

drivers/usb/gadget/f_fastboot.c +10 -0
@@ -480,6 +480,17 @@ static void cb_boot(struct usb_ep *ep, struct
 usb_request *req) fastboot_tx_write_str("OKAY");
 }
 
+static void do_exit_on_complete(struct usb_ep *ep, struct
 usb_request *req) +{
+	g_dnl_trigger_detach();
+}
+
+static void cb_continue(struct usb_ep *ep, struct usb_request *req)
+{
+	fastboot_func->in_req->complete = do_exit_on_complete;
+	fastboot_tx_write_str("OKAY");
+}
+
 #ifdef CONFIG_FASTBOOT_FLASH
 static void cb_flash(struct usb_ep *ep, struct usb_request *req)
 {

drivers/usb/gadget/f_fastboot.c static const struct cmd_dispatch_info · line 539

Quoted 9 lines
drivers/usb/gadget/f_fastboot.c +3 -0
@@ -520,6 +531,9 @@ static const struct cmd_dispatch_info
 cmd_dispatch_info[] = { }, {
 		.cmd = "boot",
 		.cb = cb_boot,
+	}, {
+		.cmd = "continue",
+		.cb = cb_continue,
 	},
 #ifdef CONFIG_FASTBOOT_FLASH
 	{

(Test HW: Trats2 board)

I will add this patch to u-boot-dfu tree.

Signature · 5 lines
Best regards,

Lukasz Majewski

Samsung R&D Institute Poland (SRPOL) | Linux Platform Group
#4 lore raw

PATCH 1/2 usb, g_dnl: generalize DFU detach functions

In reply to Rob Herring
Quoted 6 lines · Rob Herring

From: Rob Herring <[email protected]>

In order to add detach functions for fastboot, make the DFU detach related functions common so they can be shared.

Thanks, the patch looks good! I'm CCing Lukasz, who is maintaining the Gadget infrastructure, so he can take a look and possibly pick them.

Best regards,
Marek Vasut

#5 lore raw

PATCH 1/2 usb, g_dnl: generalize DFU detach functions

In reply to Rob Herring

Hi Rob,

Quoted 136 lines

From: Rob Herring <[email protected]>

In order to add detach functions for fastboot, make the DFU detach related functions common so they can be shared.

---
 common/cmd_dfu.c           |  6 +++---
 drivers/dfu/dfu.c          | 16 ----------------
 drivers/usb/gadget/f_dfu.c |  2 +-
 drivers/usb/gadget/g_dnl.c | 17 +++++++++++++++++
 include/dfu.h              |  3 ---
 include/g_dnl.h            |  4 ++++
 6 files changed, 25 insertions(+), 23 deletions(-)
common/cmd_dfu.c +2 -2
index 9e020b4..e975abe 100644
@@ -38,10 +38,10 @@ static int do_dfu(cmd_tbl_t *cmdtp, int flag, int
 argc, char * const argv[]) 
 	int controller_index = simple_strtoul(usb_controller, NULL,
 0); board_usb_init(controller_index, USB_INIT_DEVICE);
-	dfu_clear_detach();
+	g_dnl_clear_detach();
 	g_dnl_register("usb_dnl_dfu");
 	while (1) {
-		if (dfu_detach()) {
+		if (g_dnl_detach()) {
 			/*
 			 * Check if USB bus reset is performed after
 detach,

* which indicates that -R switch has been
passed to @@ -74,7 +74,7 @@ done:

common/cmd_dfu.c +1 -1
 	if (dfu_reset)
 		run_command("reset", 0);
 
-	dfu_clear_detach();
+	g_dnl_clear_detach();
 
 	return ret;
 }
drivers/dfu/dfu.c +0 -16
index c0aba6e..a3e3ec5 100644
@@ -17,7 +17,6 @@
 #include <linux/list.h>
 #include <linux/compiler.h>
 
-static bool dfu_detach_request;
 static LIST_HEAD(dfu_list);
 static int dfu_alt_num;
 static int alt_num_cnt;
@@ -39,21 +38,6 @@ __weak bool dfu_usb_get_reset(void)
 	return true;
 }
 
-bool dfu_detach(void)
-{
-	return dfu_detach_request;
-}
-
-void dfu_trigger_detach(void)
-{
-	dfu_detach_request = true;
-}
-
-void dfu_clear_detach(void)
-{
-	dfu_detach_request = false;
-}
-
 static int dfu_find_alt_num(const char *s)
 {
 	int i = 0;
drivers/usb/gadget/f_dfu.c +1 -1
index 16fc9dd..ead71eb 100644
@@ -366,7 +366,7 @@ static int state_dfu_idle(struct f_dfu *f_dfu,
 		to_runtime_mode(f_dfu);
 		f_dfu->dfu_state = DFU_STATE_appIDLE;
 
-		dfu_trigger_detach();
+		g_dnl_trigger_detach();
 		break;
 	default:
 		f_dfu->dfu_state = DFU_STATE_dfuERROR;
drivers/usb/gadget/g_dnl.c +17 -0
index 25611ac..ee52a29 100644
@@ -163,6 +163,23 @@ __weak int g_dnl_board_usb_cable_connected(void)
 	return -EOPNOTSUPP;
 }
 
+static bool g_dnl_detach_request;
+
+bool g_dnl_detach(void)
+{
+	return g_dnl_detach_request;
+}
+
+void g_dnl_trigger_detach(void)
+{
+	g_dnl_detach_request = true;
+}
+
+void g_dnl_clear_detach(void)
+{
+	g_dnl_detach_request = false;
+}
+
 static int g_dnl_get_bcd_device_number(struct usb_composite_dev
 *cdev) {
 	struct usb_gadget *gadget = cdev->gadget;
include/dfu.h +0 -3
index f1a71c7..c27856c 100644
@@ -150,9 +150,6 @@ struct dfu_entity *dfu_get_entity(int alt);
 char *dfu_extract_token(char** e, int *n);
 void dfu_trigger_reset(void);
 int dfu_get_alt(char *name);
-bool dfu_detach(void);
-void dfu_trigger_detach(void);
-void dfu_clear_detach(void);
 int dfu_init_env_entities(char *interface, char *devstr);
 unsigned char *dfu_get_buf(struct dfu_entity *dfu);
 unsigned char *dfu_free_buf(void);
include/g_dnl.h +0 -0
index 1b1b35e..4eeb5e4 100644

include/g_dnl.h int g_dnl_register(const char *s); · line 46

Quoted 8 lines
include/g_dnl.h +4 -0
@@ -39,4 +39,8 @@ int g_dnl_register(const char *s);
 void g_dnl_unregister(void);
 void g_dnl_set_serialnumber(char *);
 
+bool g_dnl_detach(void);
+void g_dnl_trigger_detach(void);
+void g_dnl_clear_detach(void);
+
 #endif /* __G_DOWNLOAD_H_ */

(Test HW: Trats2 board)

I will add this patch to u-boot-dfu tree.

Signature · 5 lines
Best regards,

Lukasz Majewski

Samsung R&D Institute Poland (SRPOL) | Linux Platform Group