Skip to contentSkip to conversation

usb: gadget: fastboot: detach usb just before rebooting

PATCH Superseded Dario Binacchi 2 participants 9 messages Jan 4, 2023 – Jan 10, 2023 USB

v2 of 3 Superseded Latest is v3 →

lore
Share & tools
lore
#0 lore raw

PATCH v2 1/1 usb: gadget: fastboot: detach usb just before rebooting

The patch fixes the following error when updating a BSH SMM S2 board:
3:72>Start Cmd:FB[-t 8000]: ucmd nand write ${loadaddr} nanddtb ${filesize} 3:72>Okay (0.023s)
3:72>Start Cmd:FB: reboot
3:72>Fail Bulk(R):LIBUSB_ERROR_IO(0s)

The "fastboot reboot" command detaches the USB when it still needs to be used. So let's detach the USB just before the reset.

CC Mattijs Korpershoek <[email protected]>
Fixes 5f7e01e9d5d800 ("usb: gadget: fastboot: detach usb on reboot commands")

---

Changes in v2:
- Add 'Suggested-by' tag.

 drivers/usb/gadget/f_fastboot.c | 12 ++++++------
 1 file changed, 6 insertions(+), 6 deletions(-)
drivers/usb/gadget/f_fastboot.c +6 -6
index 07b1681c8a9a..0b3fae564d0a 100644
@@ -419,11 +419,6 @@ static int fastboot_tx_write_str(const char *buffer)
 	return fastboot_tx_write(buffer, strlen(buffer));
 }
 
-static void compl_do_reset(struct usb_ep *ep, struct usb_request *req)
-{
-	do_reset(NULL, 0, 0, NULL);
-}
-
 static unsigned int rx_bytes_expected(struct usb_ep *ep)
 {
 	int rx_remain = fastboot_data_remaining();
@@ -495,6 +490,12 @@ static void do_bootm_on_complete(struct usb_ep *ep, struct usb_request *req)
 	do_exit_on_complete(ep, req);
 }
 
+static void compl_do_reset(struct usb_ep *ep, struct usb_request *req)
+{
+	do_exit_on_complete(ep, req);
+	do_reset(NULL, 0, 0, NULL);
+}
+
 #if CONFIG_IS_ENABLED(FASTBOOT_UUU_SUPPORT)
 static void do_acmd_complete(struct usb_ep *ep, struct usb_request *req)
 {
@@ -544,7 +545,6 @@ static void rx_handler_command(struct usb_ep *ep, struct usb_request *req)
 		case FASTBOOT_COMMAND_REBOOT_FASTBOOTD:
 		case FASTBOOT_COMMAND_REBOOT_RECOVERY:
 			fastboot_func->in_req->complete = compl_do_reset;
-			g_dnl_trigger_detach();
 			break;
 #if CONFIG_IS_ENABLED(FASTBOOT_UUU_SUPPORT)
 		case FASTBOOT_COMMAND_ACMD:
Signature · 1 line
2.32.0
#1 lore raw
Quoted 6 lines · Dario Binacchi

The patch fixes the following error when updating a BSH SMM S2 board:
3:72>Start Cmd:FB[-t 8000]: ucmd nand write ${loadaddr} nanddtb ${filesize} 3:72>Okay (0.023s)
3:72>Start Cmd:FB: reboot
3:72>Fail Bulk(R):LIBUSB_ERROR_IO(0s)

Quoted 7 lines

The "fastboot reboot" command detaches the USB when it still needs to be used. So let's detach the USB just before the reset.

CC Mattijs Korpershoek <[email protected]>
Fixes 5f7e01e9d5d800 ("usb: gadget: fastboot: detach usb on reboot commands")

Hi Dario,

Thank you for your patch and for reporting the problem.

Unfortunately, applying it seems to break the problem I tried to solve with 5f7e01e9d5d800 ("usb: gadget: fastboot: detach usb on reboot commands")

Does reverting 5f7e01e9d5d800 also solves your issue?

I'll spend some time on this.

Quoted 48 lines

---

Changes in v2:
- Add 'Suggested-by' tag.

 drivers/usb/gadget/f_fastboot.c | 12 ++++++------
 1 file changed, 6 insertions(+), 6 deletions(-)
drivers/usb/gadget/f_fastboot.c +6 -6
index 07b1681c8a9a..0b3fae564d0a 100644
@@ -419,11 +419,6 @@ static int fastboot_tx_write_str(const char *buffer)
 	return fastboot_tx_write(buffer, strlen(buffer));
 }
 
-static void compl_do_reset(struct usb_ep *ep, struct usb_request *req)
-{
-	do_reset(NULL, 0, 0, NULL);
-}
-
 static unsigned int rx_bytes_expected(struct usb_ep *ep)
 {
 	int rx_remain = fastboot_data_remaining();
@@ -495,6 +490,12 @@ static void do_bootm_on_complete(struct usb_ep *ep, struct usb_request *req)
 	do_exit_on_complete(ep, req);
 }
 
+static void compl_do_reset(struct usb_ep *ep, struct usb_request *req)
+{
+	do_exit_on_complete(ep, req);
+	do_reset(NULL, 0, 0, NULL);
+}
+
 #if CONFIG_IS_ENABLED(FASTBOOT_UUU_SUPPORT)
 static void do_acmd_complete(struct usb_ep *ep, struct usb_request *req)
 {
@@ -544,7 +545,6 @@ static void rx_handler_command(struct usb_ep *ep, struct usb_request *req)
 		case FASTBOOT_COMMAND_REBOOT_FASTBOOTD:
 		case FASTBOOT_COMMAND_REBOOT_RECOVERY:
 			fastboot_func->in_req->complete = compl_do_reset;
-			g_dnl_trigger_detach();
 			break;
 #if CONFIG_IS_ENABLED(FASTBOOT_UUU_SUPPORT)
 		case FASTBOOT_COMMAND_ACMD:
Signature · 1 line
2.32.0
#2 lore raw

Hi Mattijs,

Quoted 17 lines · Mattijs Korpershoek
Quoted 6 lines · Dario Binacchi

The patch fixes the following error when updating a BSH SMM S2 board:
3:72>Start Cmd:FB[-t 8000]: ucmd nand write ${loadaddr} nanddtb ${filesize} 3:72>Okay (0.023s)
3:72>Start Cmd:FB: reboot
3:72>Fail Bulk(R):LIBUSB_ERROR_IO(0s)

Quoted 7 lines

The "fastboot reboot" command detaches the USB when it still needs to be used. So let's detach the USB just before the reset.

CC Mattijs Korpershoek <[email protected]>
Fixes 5f7e01e9d5d800 ("usb: gadget: fastboot: detach usb on reboot commands")
Quoted 8 lines

Hi Dario,

Thank you for your patch and for reporting the problem.

Unfortunately, applying it seems to break the problem I tried to solve with 5f7e01e9d5d800 ("usb: gadget: fastboot: detach usb on reboot commands")

Does reverting 5f7e01e9d5d800 also solves your issue?

Yes

Quoted 2 lines

I'll spend some time on this.

Ok, thanks. So we can test on our hardware.
Regards Dario

Quoted 49 lines
Quoted 49 lines

---

Changes in v2:
- Add 'Suggested-by' tag.

 drivers/usb/gadget/f_fastboot.c | 12 ++++++------
 1 file changed, 6 insertions(+), 6 deletions(-)
drivers/usb/gadget/f_fastboot.c +6 -7
index 07b1681c8a9a..0b3fae564d0a 100644
@@ -419,11 +419,6 @@ static int fastboot_tx_write_str(const char *buffer)
      return fastboot_tx_write(buffer, strlen(buffer));
 }
 
-static void compl_do_reset(struct usb_ep *ep, struct usb_request *req)
-{
-     do_reset(NULL, 0, 0, NULL);
-}
-
 static unsigned int rx_bytes_expected(struct usb_ep *ep)
 {
      int rx_remain = fastboot_data_remaining();
@@ -495,6 +490,12 @@ static void do_bootm_on_complete(struct usb_ep *ep, struct usb_request *req)
      do_exit_on_complete(ep, req);
 }
 
+static void compl_do_reset(struct usb_ep *ep, struct usb_request *req)
+{
+     do_exit_on_complete(ep, req);
+     do_reset(NULL, 0, 0, NULL);
+}
+
 #if CONFIG_IS_ENABLED(FASTBOOT_UUU_SUPPORT)
 static void do_acmd_complete(struct usb_ep *ep, struct usb_request *req)
 {
@@ -544,7 +545,6 @@ static void rx_handler_command(struct usb_ep *ep, struct usb_request *req)
              case FASTBOOT_COMMAND_REBOOT_FASTBOOTD:
              case FASTBOOT_COMMAND_REBOOT_RECOVERY:
                      fastboot_func->in_req->complete = compl_do_reset;
-                     g_dnl_trigger_detach();
                      break;
 #if CONFIG_IS_ENABLED(FASTBOOT_UUU_SUPPORT)
              case FASTBOOT_COMMAND_ACMD:
--

2.32.0

Signature · 17 lines
Dario Binacchi

Senior Embedded Linux Developer

[email protected]

__________________________________


Amarula Solutions SRL

Via Le Canevare 30, 31100 Treviso, Veneto, IT

T. +39 042 243 5310
[email protected]

www.amarulasolutions.com
#3 lore raw
Quoted 28 lines · Dario Binacchi

Hi Mattijs,

Quoted 24 lines · Mattijs Korpershoek
Quoted 6 lines · Dario Binacchi

The patch fixes the following error when updating a BSH SMM S2 board:
3:72>Start Cmd:FB[-t 8000]: ucmd nand write ${loadaddr} nanddtb ${filesize} 3:72>Okay (0.023s)
3:72>Start Cmd:FB: reboot
3:72>Fail Bulk(R):LIBUSB_ERROR_IO(0s)

Quoted 7 lines

The "fastboot reboot" command detaches the USB when it still needs to be used. So let's detach the USB just before the reset.

CC Mattijs Korpershoek <[email protected]>
Fixes 5f7e01e9d5d800 ("usb: gadget: fastboot: detach usb on reboot commands")

Hi Dario,

Thank you for your patch and for reporting the problem.

Unfortunately, applying it seems to break the problem I tried to solve with 5f7e01e9d5d800 ("usb: gadget: fastboot: detach usb on reboot commands")

Quoted 8 lines
Quoted 1 line

Does reverting 5f7e01e9d5d800 also solves your issue?

Yes

Quoted 2 lines

I'll spend some time on this.

Ok, thanks. So we can test on our hardware.

So historically, I wanted to make this a "arch specific fix, as discussed in
https://lore.kernel.org/u-boot/[email protected]/

To me, the problem with calling g_dnl_trigger_detach() in the fastboot_func->in_req->complete() handler is that it's called too late.

In fact, the main fastboot loop is as following:

    while (1) {
            if (g_dnl_detach())
                    break;
            if (ctrlc())
                    break;
            schedule();
            usb_gadget_handle_interrupts(controller_index);
     }
      ret = CMD_RET_SUCCESS;
  exit:
      usb_gadget_release(controller_index);
      g_dnl_unregister();
      g_dnl_clear_detach();
      return ret;

usb_gadget_handle_interrupts, will at some point, call complete() which will call compl_do_reset(). But in compl_do_reset(), we already reset the board
(without going through the exit: section from cmd/fastboot.c)

For the BSH SMM S2 board, since it's being updated with uuu,
I assume that the host PC also triggers a call of acmd_complete() afterwards?

Can you try the following diff as well, on top of your change? (for testing purposes)

drivers/usb/gadget/f_fastboot.c +1 -1
@@ -492,7 +492,7 @@ static void do_bootm_on_complete(struct usb_ep *ep, struct usb_request *req)
 
 static void compl_do_reset(struct usb_ep *ep, struct usb_request *req)
 {
-       do_exit_on_complete(ep, req);
+       usb_gadget_release(0);
        do_reset(NULL, 0, 0, NULL);
 }
 

I suspect this will also break your flashing.

Quoted 73 lines

Regards Dario

Quoted 49 lines
Quoted 49 lines

---

Changes in v2:
- Add 'Suggested-by' tag.

 drivers/usb/gadget/f_fastboot.c | 12 ++++++------
 1 file changed, 6 insertions(+), 6 deletions(-)
drivers/usb/gadget/f_fastboot.c +6 -7
index 07b1681c8a9a..0b3fae564d0a 100644
@@ -419,11 +419,6 @@ static int fastboot_tx_write_str(const char *buffer)
      return fastboot_tx_write(buffer, strlen(buffer));
 }
 
-static void compl_do_reset(struct usb_ep *ep, struct usb_request *req)
-{
-     do_reset(NULL, 0, 0, NULL);
-}
-
 static unsigned int rx_bytes_expected(struct usb_ep *ep)
 {
      int rx_remain = fastboot_data_remaining();
@@ -495,6 +490,12 @@ static void do_bootm_on_complete(struct usb_ep *ep, struct usb_request *req)
      do_exit_on_complete(ep, req);
 }
 
+static void compl_do_reset(struct usb_ep *ep, struct usb_request *req)
+{
+     do_exit_on_complete(ep, req);
+     do_reset(NULL, 0, 0, NULL);
+}
+
 #if CONFIG_IS_ENABLED(FASTBOOT_UUU_SUPPORT)
 static void do_acmd_complete(struct usb_ep *ep, struct usb_request *req)
 {
@@ -544,7 +545,6 @@ static void rx_handler_command(struct usb_ep *ep, struct usb_request *req)
              case FASTBOOT_COMMAND_REBOOT_FASTBOOTD:
              case FASTBOOT_COMMAND_REBOOT_RECOVERY:
                      fastboot_func->in_req->complete = compl_do_reset;
-                     g_dnl_trigger_detach();
                      break;
 #if CONFIG_IS_ENABLED(FASTBOOT_UUU_SUPPORT)
              case FASTBOOT_COMMAND_ACMD:
--

2.32.0

Signature · 17 lines
Dario Binacchi

Senior Embedded Linux Developer

[email protected]

__________________________________


Amarula Solutions SRL

Via Le Canevare 30, 31100 Treviso, Veneto, IT

T. +39 042 243 5310
[email protected]

www.amarulasolutions.com
#4 lore raw

Hi Mattijs,

Quoted 86 lines · Mattijs Korpershoek
Quoted 28 lines · Dario Binacchi

Hi Mattijs,

Quoted 24 lines · Mattijs Korpershoek
Quoted 6 lines · Dario Binacchi

The patch fixes the following error when updating a BSH SMM S2 board:
3:72>Start Cmd:FB[-t 8000]: ucmd nand write ${loadaddr} nanddtb ${filesize} 3:72>Okay (0.023s)
3:72>Start Cmd:FB: reboot
3:72>Fail Bulk(R):LIBUSB_ERROR_IO(0s)

Quoted 7 lines

The "fastboot reboot" command detaches the USB when it still needs to be used. So let's detach the USB just before the reset.

CC Mattijs Korpershoek <[email protected]>
Fixes 5f7e01e9d5d800 ("usb: gadget: fastboot: detach usb on reboot commands")

Hi Dario,

Thank you for your patch and for reporting the problem.

Unfortunately, applying it seems to break the problem I tried to solve with 5f7e01e9d5d800 ("usb: gadget: fastboot: detach usb on reboot commands")

Quoted 8 lines
Quoted 1 line

Does reverting 5f7e01e9d5d800 also solves your issue?

Yes

Quoted 2 lines

I'll spend some time on this.

Ok, thanks. So we can test on our hardware.

So historically, I wanted to make this a "arch specific fix, as discussed in
https://lore.kernel.org/u-boot/[email protected]/

To me, the problem with calling g_dnl_trigger_detach() in the fastboot_func->in_req->complete() handler is that it's called too late.

In fact, the main fastboot loop is as following:

    while (1) {
            if (g_dnl_detach())
                    break;
            if (ctrlc())
                    break;
            schedule();
            usb_gadget_handle_interrupts(controller_index);
     }
      ret = CMD_RET_SUCCESS;
  exit:
      usb_gadget_release(controller_index);
      g_dnl_unregister();
      g_dnl_clear_detach();
      return ret;

usb_gadget_handle_interrupts, will at some point, call complete() which will call compl_do_reset(). But in compl_do_reset(), we already reset the board
(without going through the exit: section from cmd/fastboot.c)

For the BSH SMM S2 board, since it's being updated with uuu,
I assume that the host PC also triggers a call of acmd_complete() afterwards?

Can you try the following diff as well, on top of your change? (for testing purposes)

drivers/usb/gadget/f_fastboot.c +1 -1
@@ -492,7 +492,7 @@ static void do_bootm_on_complete(struct usb_ep *ep, struct usb_request *req)
 
 static void compl_do_reset(struct usb_ep *ep, struct usb_request *req)
 {
-       do_exit_on_complete(ep, req);
+       usb_gadget_release(0);
        do_reset(NULL, 0, 0, NULL);
 }
 
Quoted 1 line

I suspect this will also break your flashing.

No, I am able to flash and reset the board.
This change works.

Quoted 74 lines
Quoted 74 lines

Regards Dario

Quoted 41 lines
Quoted 41 lines

---

Changes in v2:
- Add 'Suggested-by' tag.

 drivers/usb/gadget/f_fastboot.c | 12 ++++++------
 1 file changed, 6 insertions(+), 6 deletions(-)
drivers/usb/gadget/f_fastboot.c +6 -5
index 07b1681c8a9a..0b3fae564d0a 100644
@@ -419,11 +419,6 @@ static int fastboot_tx_write_str(const char *buffer)
      return fastboot_tx_write(buffer, strlen(buffer));
 }
 
-static void compl_do_reset(struct usb_ep *ep, struct usb_request *req)
-{
-     do_reset(NULL, 0, 0, NULL);
-}
-
 static unsigned int rx_bytes_expected(struct usb_ep *ep)
 {
      int rx_remain = fastboot_data_remaining();
@@ -495,6 +490,12 @@ static void do_bootm_on_complete(struct usb_ep *ep, struct usb_request *req)
      do_exit_on_complete(ep, req);
 }
 
+static void compl_do_reset(struct usb_ep *ep, struct usb_request *req)
+{
+     do_exit_on_complete(ep, req);
+     do_reset(NULL, 0, 0, NULL);
+}
+
 #if CONFIG_IS_ENABLED(FASTBOOT_UUU_SUPPORT)
 static void do_acmd_complete(struct usb_ep *ep, struct usb_request *req)
 {
@@ -544,7 +545,6 @@ static void rx_handler_command(struct usb_ep *ep, struct usb_request *req)
              case FASTBOOT_COMMAND_REBOOT_FASTBOOTD:
Quoted 8 lines
Quoted 8 lines
drivers/usb/gadget/f_fastboot.c +0 -2
              case FASTBOOT_COMMAND_REBOOT_RECOVERY:
                      fastboot_func->in_req->complete = compl_do_reset;
-                     g_dnl_trigger_detach();
                      break;
 #if CONFIG_IS_ENABLED(FASTBOOT_UUU_SUPPORT)
              case FASTBOOT_COMMAND_ACMD:
--

2.32.0

--

Dario Binacchi

Senior Embedded Linux Developer

[email protected]

__________________________________

Amarula Solutions SRL

Via Le Canevare 30, 31100 Treviso, Veneto, IT

T. +39 042 243 5310
[email protected]

www.amarulasolutions.com

Signature · 17 lines
Dario Binacchi

Senior Embedded Linux Developer

[email protected]

__________________________________


Amarula Solutions SRL

Via Le Canevare 30, 31100 Treviso, Veneto, IT

T. +39 042 243 5310
[email protected]

www.amarulasolutions.com
#5 lore raw
Quoted 90 lines · Dario Binacchi

Hi Mattijs,

Quoted 86 lines · Mattijs Korpershoek
Quoted 28 lines · Dario Binacchi

Hi Mattijs,

Quoted 24 lines · Mattijs Korpershoek
Quoted 6 lines · Dario Binacchi

The patch fixes the following error when updating a BSH SMM S2 board:
3:72>Start Cmd:FB[-t 8000]: ucmd nand write ${loadaddr} nanddtb ${filesize} 3:72>Okay (0.023s)
3:72>Start Cmd:FB: reboot
3:72>Fail Bulk(R):LIBUSB_ERROR_IO(0s)

Quoted 7 lines

The "fastboot reboot" command detaches the USB when it still needs to be used. So let's detach the USB just before the reset.

CC Mattijs Korpershoek <[email protected]>
Fixes 5f7e01e9d5d800 ("usb: gadget: fastboot: detach usb on reboot commands")

Hi Dario,

Thank you for your patch and for reporting the problem.

Unfortunately, applying it seems to break the problem I tried to solve with 5f7e01e9d5d800 ("usb: gadget: fastboot: detach usb on reboot commands")

Quoted 8 lines
Quoted 1 line

Does reverting 5f7e01e9d5d800 also solves your issue?

Yes

Quoted 2 lines

I'll spend some time on this.

Ok, thanks. So we can test on our hardware.

So historically, I wanted to make this a "arch specific fix, as discussed in
https://lore.kernel.org/u-boot/[email protected]/

To me, the problem with calling g_dnl_trigger_detach() in the fastboot_func->in_req->complete() handler is that it's called too late.

In fact, the main fastboot loop is as following:

    while (1) {
            if (g_dnl_detach())
                    break;
            if (ctrlc())
                    break;
            schedule();
            usb_gadget_handle_interrupts(controller_index);
     }
      ret = CMD_RET_SUCCESS;
  exit:
      usb_gadget_release(controller_index);
      g_dnl_unregister();
      g_dnl_clear_detach();
      return ret;

usb_gadget_handle_interrupts, will at some point, call complete() which will call compl_do_reset(). But in compl_do_reset(), we already reset the board
(without going through the exit: section from cmd/fastboot.c)

For the BSH SMM S2 board, since it's being updated with uuu,
I assume that the host PC also triggers a call of acmd_complete() afterwards?

Can you try the following diff as well, on top of your change? (for testing purposes)

drivers/usb/gadget/f_fastboot.c +1 -1
@@ -492,7 +492,7 @@ static void do_bootm_on_complete(struct usb_ep *ep, struct usb_request *req)
 
 static void compl_do_reset(struct usb_ep *ep, struct usb_request *req)
 {
-       do_exit_on_complete(ep, req);
+       usb_gadget_release(0);
        do_reset(NULL, 0, 0, NULL);
 }
 
Quoted 4 lines
Quoted 1 line

I suspect this will also break your flashing.

No, I am able to flash and reset the board.
This change works.

Huh. Ok. I will do some more debugging on my end. Thank you for your patience.

Quoted 97 lines
Quoted 75 lines
Quoted 75 lines

Regards Dario

Quoted 41 lines
Quoted 41 lines

---

Changes in v2:
- Add 'Suggested-by' tag.

 drivers/usb/gadget/f_fastboot.c | 12 ++++++------
 1 file changed, 6 insertions(+), 6 deletions(-)
drivers/usb/gadget/f_fastboot.c +6 -5
index 07b1681c8a9a..0b3fae564d0a 100644
@@ -419,11 +419,6 @@ static int fastboot_tx_write_str(const char *buffer)
      return fastboot_tx_write(buffer, strlen(buffer));
 }
 
-static void compl_do_reset(struct usb_ep *ep, struct usb_request *req)
-{
-     do_reset(NULL, 0, 0, NULL);
-}
-
 static unsigned int rx_bytes_expected(struct usb_ep *ep)
 {
      int rx_remain = fastboot_data_remaining();
@@ -495,6 +490,12 @@ static void do_bootm_on_complete(struct usb_ep *ep, struct usb_request *req)
      do_exit_on_complete(ep, req);
 }
 
+static void compl_do_reset(struct usb_ep *ep, struct usb_request *req)
+{
+     do_exit_on_complete(ep, req);
+     do_reset(NULL, 0, 0, NULL);
+}
+
 #if CONFIG_IS_ENABLED(FASTBOOT_UUU_SUPPORT)
 static void do_acmd_complete(struct usb_ep *ep, struct usb_request *req)
 {
@@ -544,7 +545,6 @@ static void rx_handler_command(struct usb_ep *ep, struct usb_request *req)
              case FASTBOOT_COMMAND_REBOOT_FASTBOOTD:
Quoted 8 lines
Quoted 8 lines
drivers/usb/gadget/f_fastboot.c +0 -2
              case FASTBOOT_COMMAND_REBOOT_RECOVERY:
                      fastboot_func->in_req->complete = compl_do_reset;
-                     g_dnl_trigger_detach();
                      break;
 #if CONFIG_IS_ENABLED(FASTBOOT_UUU_SUPPORT)
              case FASTBOOT_COMMAND_ACMD:
--

2.32.0

--

Dario Binacchi

Senior Embedded Linux Developer

[email protected]

__________________________________

Amarula Solutions SRL

Via Le Canevare 30, 31100 Treviso, Veneto, IT

T. +39 042 243 5310
[email protected]

www.amarulasolutions.com

Signature · 17 lines
Dario Binacchi

Senior Embedded Linux Developer

[email protected]

__________________________________


Amarula Solutions SRL

Via Le Canevare 30, 31100 Treviso, Veneto, IT

T. +39 042 243 5310
[email protected]

www.amarulasolutions.com
#6 lore raw
In reply to Dario Binacchi
Quoted 90 lines · Dario Binacchi

Hi Mattijs,

Quoted 86 lines · Mattijs Korpershoek
Quoted 28 lines · Dario Binacchi

Hi Mattijs,

Quoted 24 lines · Mattijs Korpershoek
Quoted 6 lines · Dario Binacchi

The patch fixes the following error when updating a BSH SMM S2 board:
3:72>Start Cmd:FB[-t 8000]: ucmd nand write ${loadaddr} nanddtb ${filesize} 3:72>Okay (0.023s)
3:72>Start Cmd:FB: reboot
3:72>Fail Bulk(R):LIBUSB_ERROR_IO(0s)

Quoted 7 lines

The "fastboot reboot" command detaches the USB when it still needs to be used. So let's detach the USB just before the reset.

CC Mattijs Korpershoek <[email protected]>
Fixes 5f7e01e9d5d800 ("usb: gadget: fastboot: detach usb on reboot commands")

Hi Dario,

Thank you for your patch and for reporting the problem.

Unfortunately, applying it seems to break the problem I tried to solve with 5f7e01e9d5d800 ("usb: gadget: fastboot: detach usb on reboot commands")

Quoted 8 lines
Quoted 1 line

Does reverting 5f7e01e9d5d800 also solves your issue?

Yes

Quoted 2 lines

I'll spend some time on this.

Ok, thanks. So we can test on our hardware.

So historically, I wanted to make this a "arch specific fix, as discussed in
https://lore.kernel.org/u-boot/[email protected]/

To me, the problem with calling g_dnl_trigger_detach() in the fastboot_func->in_req->complete() handler is that it's called too late.

In fact, the main fastboot loop is as following:

    while (1) {
            if (g_dnl_detach())
                    break;
            if (ctrlc())
                    break;
            schedule();
            usb_gadget_handle_interrupts(controller_index);
     }
      ret = CMD_RET_SUCCESS;
  exit:
      usb_gadget_release(controller_index);
      g_dnl_unregister();
      g_dnl_clear_detach();
      return ret;

usb_gadget_handle_interrupts, will at some point, call complete() which will call compl_do_reset(). But in compl_do_reset(), we already reset the board
(without going through the exit: section from cmd/fastboot.c)

For the BSH SMM S2 board, since it's being updated with uuu,
I assume that the host PC also triggers a call of acmd_complete() afterwards?

Can you try the following diff as well, on top of your change? (for testing purposes)

drivers/usb/gadget/f_fastboot.c +1 -1
@@ -492,7 +492,7 @@ static void do_bootm_on_complete(struct usb_ep *ep, struct usb_request *req)
 
 static void compl_do_reset(struct usb_ep *ep, struct usb_request *req)
 {
-       do_exit_on_complete(ep, req);
+       usb_gadget_release(0);
        do_reset(NULL, 0, 0, NULL);
 }
 
Quoted 4 lines
Quoted 1 line

I suspect this will also break your flashing.

No, I am able to flash and reset the board.
This change works.

With some additional testing on my end, I can see that the final message (sending OKAY to the host) done on fastboot_func->in_ep is not done on my end. I think I am lucky that my controller driver (dwc2_udc_otg) delivers the message to my host anyways and calls done() even when messages are aborted.

I think I have something that might be better.

Dario, could you do another test for me, please?
1. Revert 5f7e01e9d5d800 ("usb: gadget: fastboot: detach usb on reboot commands")

2. Apply the following diff:

drivers/usb/gadget/f_fastboot.c +1 -0
index d0e92c7a071f..f4311328a2da 100644
@@ -421,6 +421,7 @@ static int fastboot_tx_write_str(const char *buffer)
 
 static void compl_do_reset(struct usb_ep *ep, struct usb_request *req)
 {
+       g_dnl_unregister();
        do_reset(NULL, 0, 0, NULL);
 }
 

The call to g_dnl_unregister() will end up calling g_dnl_unbind() which calls usb_gadget_disconnect()
where each controller can implement a soft disconnect (which I can do for dwc2_udc_otg)

Quoted 97 lines
Quoted 75 lines
Quoted 75 lines

Regards Dario

Quoted 41 lines
Quoted 41 lines

---

Changes in v2:
- Add 'Suggested-by' tag.

 drivers/usb/gadget/f_fastboot.c | 12 ++++++------
 1 file changed, 6 insertions(+), 6 deletions(-)
drivers/usb/gadget/f_fastboot.c +6 -5
index 07b1681c8a9a..0b3fae564d0a 100644
@@ -419,11 +419,6 @@ static int fastboot_tx_write_str(const char *buffer)
      return fastboot_tx_write(buffer, strlen(buffer));
 }
 
-static void compl_do_reset(struct usb_ep *ep, struct usb_request *req)
-{
-     do_reset(NULL, 0, 0, NULL);
-}
-
 static unsigned int rx_bytes_expected(struct usb_ep *ep)
 {
      int rx_remain = fastboot_data_remaining();
@@ -495,6 +490,12 @@ static void do_bootm_on_complete(struct usb_ep *ep, struct usb_request *req)
      do_exit_on_complete(ep, req);
 }
 
+static void compl_do_reset(struct usb_ep *ep, struct usb_request *req)
+{
+     do_exit_on_complete(ep, req);
+     do_reset(NULL, 0, 0, NULL);
+}
+
 #if CONFIG_IS_ENABLED(FASTBOOT_UUU_SUPPORT)
 static void do_acmd_complete(struct usb_ep *ep, struct usb_request *req)
 {
@@ -544,7 +545,6 @@ static void rx_handler_command(struct usb_ep *ep, struct usb_request *req)
              case FASTBOOT_COMMAND_REBOOT_FASTBOOTD:
Quoted 8 lines
Quoted 8 lines
drivers/usb/gadget/f_fastboot.c +0 -2
              case FASTBOOT_COMMAND_REBOOT_RECOVERY:
                      fastboot_func->in_req->complete = compl_do_reset;
-                     g_dnl_trigger_detach();
                      break;
 #if CONFIG_IS_ENABLED(FASTBOOT_UUU_SUPPORT)
              case FASTBOOT_COMMAND_ACMD:
--

2.32.0

--

Dario Binacchi

Senior Embedded Linux Developer

[email protected]

__________________________________

Amarula Solutions SRL

Via Le Canevare 30, 31100 Treviso, Veneto, IT

T. +39 042 243 5310
[email protected]

www.amarulasolutions.com

Signature · 17 lines
Dario Binacchi

Senior Embedded Linux Developer

[email protected]

__________________________________


Amarula Solutions SRL

Via Le Canevare 30, 31100 Treviso, Veneto, IT

T. +39 042 243 5310
[email protected]

www.amarulasolutions.com
#7 lore raw

Hi Mattijs,

Quoted 116 lines · Mattijs Korpershoek
Quoted 90 lines · Dario Binacchi

Hi Mattijs,

Quoted 86 lines · Mattijs Korpershoek
Quoted 28 lines · Dario Binacchi

Hi Mattijs,

Quoted 24 lines · Mattijs Korpershoek
Quoted 6 lines · Dario Binacchi

The patch fixes the following error when updating a BSH SMM S2 board:
3:72>Start Cmd:FB[-t 8000]: ucmd nand write ${loadaddr} nanddtb ${filesize} 3:72>Okay (0.023s)
3:72>Start Cmd:FB: reboot
3:72>Fail Bulk(R):LIBUSB_ERROR_IO(0s)

Quoted 7 lines

The "fastboot reboot" command detaches the USB when it still needs to be used. So let's detach the USB just before the reset.

CC Mattijs Korpershoek <[email protected]>
Fixes 5f7e01e9d5d800 ("usb: gadget: fastboot: detach usb on reboot commands")

Hi Dario,

Thank you for your patch and for reporting the problem.

Unfortunately, applying it seems to break the problem I tried to solve with 5f7e01e9d5d800 ("usb: gadget: fastboot: detach usb on reboot commands")

Quoted 8 lines
Quoted 1 line

Does reverting 5f7e01e9d5d800 also solves your issue?

Yes

Quoted 2 lines

I'll spend some time on this.

Ok, thanks. So we can test on our hardware.

So historically, I wanted to make this a "arch specific fix, as discussed in
https://lore.kernel.org/u-boot/[email protected]/

To me, the problem with calling g_dnl_trigger_detach() in the fastboot_func->in_req->complete() handler is that it's called too late.

In fact, the main fastboot loop is as following:

    while (1) {
            if (g_dnl_detach())
                    break;
            if (ctrlc())
                    break;
            schedule();
            usb_gadget_handle_interrupts(controller_index);
     }
      ret = CMD_RET_SUCCESS;
  exit:
      usb_gadget_release(controller_index);
      g_dnl_unregister();
      g_dnl_clear_detach();
      return ret;

usb_gadget_handle_interrupts, will at some point, call complete() which will call compl_do_reset(). But in compl_do_reset(), we already reset the board
(without going through the exit: section from cmd/fastboot.c)

For the BSH SMM S2 board, since it's being updated with uuu,
I assume that the host PC also triggers a call of acmd_complete() afterwards?

Can you try the following diff as well, on top of your change? (for testing purposes)

drivers/usb/gadget/f_fastboot.c +1 -1
@@ -492,7 +492,7 @@ static void do_bootm_on_complete(struct usb_ep *ep, struct usb_request *req)
 
 static void compl_do_reset(struct usb_ep *ep, struct usb_request *req)
 {
-       do_exit_on_complete(ep, req);
+       usb_gadget_release(0);
        do_reset(NULL, 0, 0, NULL);
 }
 
Quoted 4 lines
Quoted 1 line

I suspect this will also break your flashing.

No, I am able to flash and reset the board.
This change works.

With some additional testing on my end, I can see that the final message (sending OKAY to the host) done on fastboot_func->in_ep is not done on my end. I think I am lucky that my controller driver (dwc2_udc_otg) delivers the message to my host anyways and calls done() even when messages are aborted.

I think I have something that might be better.

Dario, could you do another test for me, please?
1. Revert 5f7e01e9d5d800 ("usb: gadget: fastboot: detach usb on reboot commands")

2. Apply the following diff:

drivers/usb/gadget/f_fastboot.c +0 -0
index d0e92c7a071f..f4311328a2da 100644

drivers/usb/gadget/f_fastboot.c static int fastboot_tx_write_str(const char *buffer) · line 427

Quoted 7 lines
drivers/usb/gadget/f_fastboot.c +1 -0
@@ -421,6 +421,7 @@ static int fastboot_tx_write_str(const char *buffer)
 
 static void compl_do_reset(struct usb_ep *ep, struct usb_request *req)
 {
+       g_dnl_unregister();
        do_reset(NULL, 0, 0, NULL);
 }
 

I applied your diff and it runs.
I changed my patch with your suggestion.
I'll submit v3.
The patch can be applied without reverting 5f7e01e9d5d800. Can you re-test and apply your tested-by tag?
I added the Co-developed-by tag too.
Do you think it is correct to proceed like this?

Thanks and regards,
Dario

Quoted 102 lines

The call to g_dnl_unregister() will end up calling g_dnl_unbind() which calls usb_gadget_disconnect()
where each controller can implement a soft disconnect (which I can do for dwc2_udc_otg)

Quoted 97 lines
Quoted 67 lines
Quoted 67 lines

Regards Dario

Quoted 41 lines
Quoted 41 lines

---

Changes in v2:
- Add 'Suggested-by' tag.

 drivers/usb/gadget/f_fastboot.c | 12 ++++++------
 1 file changed, 6 insertions(+), 6 deletions(-)
drivers/usb/gadget/f_fastboot.c +6 -5
index 07b1681c8a9a..0b3fae564d0a 100644
@@ -419,11 +419,6 @@ static int fastboot_tx_write_str(const char *buffer)
      return fastboot_tx_write(buffer, strlen(buffer));
 }
 
-static void compl_do_reset(struct usb_ep *ep, struct usb_request *req)
-{
-     do_reset(NULL, 0, 0, NULL);
-}
-
 static unsigned int rx_bytes_expected(struct usb_ep *ep)
 {
      int rx_remain = fastboot_data_remaining();
@@ -495,6 +490,12 @@ static void do_bootm_on_complete(struct usb_ep *ep, struct usb_request *req)
      do_exit_on_complete(ep, req);
 }
 
+static void compl_do_reset(struct usb_ep *ep, struct usb_request *req)
+{
+     do_exit_on_complete(ep, req);
+     do_reset(NULL, 0, 0, NULL);
+}
+
 #if CONFIG_IS_ENABLED(FASTBOOT_UUU_SUPPORT)
 static void do_acmd_complete(struct usb_ep *ep, struct usb_request *req)
 {
@@ -544,7 +545,6 @@ static void rx_handler_command(struct usb_ep *ep, struct usb_request *req)
              case FASTBOOT_COMMAND_REBOOT_FASTBOOTD:
Quoted 8 lines
Quoted 8 lines
drivers/usb/gadget/f_fastboot.c +0 -2
              case FASTBOOT_COMMAND_REBOOT_RECOVERY:
                      fastboot_func->in_req->complete = compl_do_reset;
-                     g_dnl_trigger_detach();
                      break;
 #if CONFIG_IS_ENABLED(FASTBOOT_UUU_SUPPORT)
              case FASTBOOT_COMMAND_ACMD:
--

2.32.0

--

Dario Binacchi

Senior Embedded Linux Developer

[email protected]

__________________________________

Quoted 8 lines
Quoted 8 lines

Amarula Solutions SRL

Via Le Canevare 30, 31100 Treviso, Veneto, IT

T. +39 042 243 5310
[email protected]

www.amarulasolutions.com

--

Dario Binacchi

Senior Embedded Linux Developer

[email protected]

__________________________________

Amarula Solutions SRL

Via Le Canevare 30, 31100 Treviso, Veneto, IT

T. +39 042 243 5310
[email protected]

www.amarulasolutions.com

Signature · 17 lines
Dario Binacchi

Senior Embedded Linux Developer

[email protected]

__________________________________


Amarula Solutions SRL

Via Le Canevare 30, 31100 Treviso, Veneto, IT

T. +39 042 243 5310
[email protected]

www.amarulasolutions.com
#8 lore raw

Hi Dario,

Quoted 121 lines · Dario Binacchi

Hi Mattijs,

Quoted 117 lines · Mattijs Korpershoek
Quoted 90 lines · Dario Binacchi

Hi Mattijs,

Quoted 86 lines · Mattijs Korpershoek
Quoted 28 lines · Dario Binacchi

Hi Mattijs,

Quoted 24 lines · Mattijs Korpershoek
Quoted 6 lines · Dario Binacchi

The patch fixes the following error when updating a BSH SMM S2 board:
3:72>Start Cmd:FB[-t 8000]: ucmd nand write ${loadaddr} nanddtb ${filesize} 3:72>Okay (0.023s)
3:72>Start Cmd:FB: reboot
3:72>Fail Bulk(R):LIBUSB_ERROR_IO(0s)

Quoted 7 lines

The "fastboot reboot" command detaches the USB when it still needs to be used. So let's detach the USB just before the reset.

CC Mattijs Korpershoek <[email protected]>
Fixes 5f7e01e9d5d800 ("usb: gadget: fastboot: detach usb on reboot commands")

Hi Dario,

Thank you for your patch and for reporting the problem.

Unfortunately, applying it seems to break the problem I tried to solve with 5f7e01e9d5d800 ("usb: gadget: fastboot: detach usb on reboot commands")

Quoted 8 lines
Quoted 1 line

Does reverting 5f7e01e9d5d800 also solves your issue?

Yes

Quoted 2 lines

I'll spend some time on this.

Ok, thanks. So we can test on our hardware.

So historically, I wanted to make this a "arch specific fix, as discussed in
https://lore.kernel.org/u-boot/[email protected]/

To me, the problem with calling g_dnl_trigger_detach() in the fastboot_func->in_req->complete() handler is that it's called too late.

In fact, the main fastboot loop is as following:

    while (1) {
            if (g_dnl_detach())
                    break;
            if (ctrlc())
                    break;
            schedule();
            usb_gadget_handle_interrupts(controller_index);
     }
      ret = CMD_RET_SUCCESS;
  exit:
      usb_gadget_release(controller_index);
      g_dnl_unregister();
      g_dnl_clear_detach();
      return ret;

usb_gadget_handle_interrupts, will at some point, call complete() which will call compl_do_reset(). But in compl_do_reset(), we already reset the board
(without going through the exit: section from cmd/fastboot.c)

For the BSH SMM S2 board, since it's being updated with uuu,
I assume that the host PC also triggers a call of acmd_complete() afterwards?

Can you try the following diff as well, on top of your change? (for testing purposes)

drivers/usb/gadget/f_fastboot.c +1 -1
@@ -492,7 +492,7 @@ static void do_bootm_on_complete(struct usb_ep *ep, struct usb_request *req)
 
 static void compl_do_reset(struct usb_ep *ep, struct usb_request *req)
 {
-       do_exit_on_complete(ep, req);
+       usb_gadget_release(0);
        do_reset(NULL, 0, 0, NULL);
 }
 
Quoted 4 lines
Quoted 1 line

I suspect this will also break your flashing.

No, I am able to flash and reset the board.
This change works.

With some additional testing on my end, I can see that the final message (sending OKAY to the host) done on fastboot_func->in_ep is not done on my end. I think I am lucky that my controller driver (dwc2_udc_otg) delivers the message to my host anyways and calls done() even when messages are aborted.

I think I have something that might be better.

Dario, could you do another test for me, please?
1. Revert 5f7e01e9d5d800 ("usb: gadget: fastboot: detach usb on reboot commands")

2. Apply the following diff:

drivers/usb/gadget/f_fastboot.c +0 -0
index d0e92c7a071f..f4311328a2da 100644
@@ -421,6 +421,7 @@ static int fastboot_tx_write_str(const char *buffer)
 
Quoted 13 lines

drivers/usb/gadget/f_fastboot.c static int fastboot_tx_write_str(const char *buffer) · line 427

Quoted 6 lines
drivers/usb/gadget/f_fastboot.c +1 -0
 static void compl_do_reset(struct usb_ep *ep, struct usb_request *req)
 {
+       g_dnl_unregister();
        do_reset(NULL, 0, 0, NULL);
 }
 

I applied your diff and it runs.
I changed my patch with your suggestion.
I'll submit v3.
The patch can be applied without reverting 5f7e01e9d5d800. Can you re-test and apply your tested-by tag?
I added the Co-developed-by tag too.
Do you think it is correct to proceed like this?

Yes it's ok to proceed like this.

Quoted 128 lines

Thanks and regards,
Dario

Quoted 102 lines

The call to g_dnl_unregister() will end up calling g_dnl_unbind() which calls usb_gadget_disconnect()
where each controller can implement a soft disconnect (which I can do for dwc2_udc_otg)

Quoted 97 lines
Quoted 67 lines
Quoted 67 lines

Regards Dario

Quoted 41 lines
Quoted 41 lines

---

Changes in v2:
- Add 'Suggested-by' tag.

 drivers/usb/gadget/f_fastboot.c | 12 ++++++------
 1 file changed, 6 insertions(+), 6 deletions(-)
drivers/usb/gadget/f_fastboot.c +6 -5
index 07b1681c8a9a..0b3fae564d0a 100644
@@ -419,11 +419,6 @@ static int fastboot_tx_write_str(const char *buffer)
      return fastboot_tx_write(buffer, strlen(buffer));
 }
 
-static void compl_do_reset(struct usb_ep *ep, struct usb_request *req)
-{
-     do_reset(NULL, 0, 0, NULL);
-}
-
 static unsigned int rx_bytes_expected(struct usb_ep *ep)
 {
      int rx_remain = fastboot_data_remaining();
@@ -495,6 +490,12 @@ static void do_bootm_on_complete(struct usb_ep *ep, struct usb_request *req)
      do_exit_on_complete(ep, req);
 }
 
+static void compl_do_reset(struct usb_ep *ep, struct usb_request *req)
+{
+     do_exit_on_complete(ep, req);
+     do_reset(NULL, 0, 0, NULL);
+}
+
 #if CONFIG_IS_ENABLED(FASTBOOT_UUU_SUPPORT)
 static void do_acmd_complete(struct usb_ep *ep, struct usb_request *req)
 {
@@ -544,7 +545,6 @@ static void rx_handler_command(struct usb_ep *ep, struct usb_request *req)
              case FASTBOOT_COMMAND_REBOOT_FASTBOOTD:
Quoted 8 lines
Quoted 8 lines
drivers/usb/gadget/f_fastboot.c +0 -2
              case FASTBOOT_COMMAND_REBOOT_RECOVERY:
                      fastboot_func->in_req->complete = compl_do_reset;
-                     g_dnl_trigger_detach();
                      break;
 #if CONFIG_IS_ENABLED(FASTBOOT_UUU_SUPPORT)
              case FASTBOOT_COMMAND_ACMD:
--

2.32.0

--

Dario Binacchi

Senior Embedded Linux Developer

[email protected]

__________________________________

Quoted 8 lines
Quoted 8 lines

Amarula Solutions SRL

Via Le Canevare 30, 31100 Treviso, Veneto, IT

T. +39 042 243 5310
[email protected]

www.amarulasolutions.com

--

Dario Binacchi

Senior Embedded Linux Developer

[email protected]

__________________________________

Amarula Solutions SRL

Via Le Canevare 30, 31100 Treviso, Veneto, IT

T. +39 042 243 5310
[email protected]

www.amarulasolutions.com

Signature · 17 lines
Dario Binacchi

Senior Embedded Linux Developer

[email protected]

__________________________________


Amarula Solutions SRL

Via Le Canevare 30, 31100 Treviso, Veneto, IT

T. +39 042 243 5310
[email protected]

www.amarulasolutions.com