This is an automated email from the ASF dual-hosted git repository.

xiaoxiang pushed a commit to branch master
in repository https://gitbox.apache.org/repos/asf/nuttx-apps.git


The following commit(s) were added to refs/heads/master by this push:
     new 7375f6574 system/fastboot: move usbdev init after help
7375f6574 is described below

commit 7375f6574e7c0c2a143c349194a9e2c36985d79d
Author: wangjianyu3 <[email protected]>
AuthorDate: Sun Jun 15 01:00:22 2025 +0800

    system/fastboot: move usbdev init after help
    
    Move initialization of usbdev to after help().
    
    This patch fix that even users just run `fastbootd -h`,
    the usbdev will also be (re)initialized,
    and if the daemon is running the status will be broken.
    
    Signed-off-by: wangjianyu3 <[email protected]>
---
 system/fastboot/fastboot.c | 34 +++++++++++++++++++++++-----------
 1 file changed, 23 insertions(+), 11 deletions(-)

diff --git a/system/fastboot/fastboot.c b/system/fastboot/fastboot.c
index df250290d..734561798 100644
--- a/system/fastboot/fastboot.c
+++ b/system/fastboot/fastboot.c
@@ -1035,16 +1035,8 @@ static int fastboot_open_usb(int index, int flags)
   return -errno;
 }
 
-/****************************************************************************
- * Public Functions
- ****************************************************************************/
-
-int main(int argc, FAR char **argv)
+static int fastboot_usbdev_initialize(void)
 {
-  struct fastboot_ctx_s context;
-  FAR void *buffer = NULL;
-  int ret = OK;
-
 #ifdef CONFIG_SYSTEM_FASTBOOTD_USB_BOARDCTL
   struct boardioc_usbdev_ctrl_s ctrl;
 #  ifdef CONFIG_USBDEV_COMPOSITE
@@ -1053,6 +1045,7 @@ int main(int argc, FAR char **argv)
     uint8_t dev = BOARDIOC_USBDEV_FASTBOOT;
 #  endif
   FAR void *handle;
+  int ret;
 
   ctrl.usbdev   = dev;
   ctrl.action   = BOARDIOC_USBDEV_INITIALIZE;
@@ -1063,7 +1056,7 @@ int main(int argc, FAR char **argv)
   ret = boardctl(BOARDIOC_USBDEV_CONTROL, (uintptr_t)&ctrl);
   if (ret < 0)
     {
-      fb_err("boardctl(BOARDIOC_USBDEV_CONTROL) failed: %d\n", ret);
+      fb_err("boardctl(BOARDIOC_USBDEV_INITIALIZE) failed: %d\n", ret);
       return ret;
     }
 
@@ -1076,11 +1069,24 @@ int main(int argc, FAR char **argv)
   ret = boardctl(BOARDIOC_USBDEV_CONTROL, (uintptr_t)&ctrl);
   if (ret < 0)
     {
-      fb_err("boardctl(BOARDIOC_USBDEV_CONTROL) failed: %d\n", ret);
+      fb_err("boardctl(BOARDIOC_USBDEV_CONNECT) failed: %d\n", ret);
       return ret;
     }
 #endif /* SYSTEM_FASTBOOTD_USB_BOARDCTL */
 
+  return 0;
+}
+
+/****************************************************************************
+ * Public Functions
+ ****************************************************************************/
+
+int main(int argc, FAR char **argv)
+{
+  struct fastboot_ctx_s context;
+  FAR void *buffer = NULL;
+  int ret = OK;
+
   if (argc > 1)
     {
       if (strcmp(argv[1], "-h") == 0)
@@ -1098,6 +1104,12 @@ int main(int argc, FAR char **argv)
       context.wait_ms = 0;
     }
 
+  ret = fastboot_usbdev_initialize();
+  if (ret < 0)
+    {
+      return ret;
+    }
+
   buffer = malloc(CONFIG_SYSTEM_FASTBOOTD_DOWNLOAD_MAX);
   if (buffer == NULL)
     {

Reply via email to