You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@nuttx.apache.org by xi...@apache.org on 2024/09/11 15:20:59 UTC

(nuttx-apps) 04/17: system/fastboot: erase - add driver independent

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

commit 6b53e1fae95cd122e266174feaea76fca3d177ed
Author: wangjianyu3 <wa...@xiaomi.com>
AuthorDate: Fri Dec 15 15:35:34 2023 +0800

    system/fastboot: erase - add driver independent
    
    Signed-off-by: wangjianyu3 <wa...@xiaomi.com>
---
 system/fastboot/fastboot.c | 32 ++++++++++++++++++++++++++++++--
 1 file changed, 30 insertions(+), 2 deletions(-)

diff --git a/system/fastboot/fastboot.c b/system/fastboot/fastboot.c
index c703a34bb..f216e07a5 100644
--- a/system/fastboot/fastboot.c
+++ b/system/fastboot/fastboot.c
@@ -33,10 +33,12 @@
 #include <stdint.h>
 #include <stdio.h>
 #include <string.h>
+#include <unistd.h>
 
 #include <sys/boardctl.h>
 #include <sys/ioctl.h>
 #include <sys/param.h>
+#include <sys/stat.h>
 #include <sys/statfs.h>
 #include <sys/types.h>
 
@@ -305,7 +307,7 @@ static int fastboot_flash_erase(int fd)
       printf("Erase device failed\n");
     }
 
-  return ret;
+  return ret < 0 ? -errno : ret;
 }
 
 static int
@@ -422,6 +424,7 @@ static void fastboot_erase(FAR struct fastboot_ctx_s *context,
                            FAR const char *arg)
 {
   char blkdev[PATH_MAX];
+  int ret;
   int fd;
 
   snprintf(blkdev, PATH_MAX, FASTBOOT_BLKDEV, arg);
@@ -434,7 +437,32 @@ static void fastboot_erase(FAR struct fastboot_ctx_s *context,
       return;
     }
 
-  if (fastboot_flash_erase(fd) < 0)
+  ret = fastboot_flash_erase(fd);
+  if (ret == -ENOTTY)
+    {
+      struct stat sb;
+
+      ret = fstat(fd, &sb);
+      if (ret >= 0)
+        {
+          memset(context->download_buffer, 0xff, context->download_max);
+
+          while (sb.st_size > 0)
+            {
+              size_t len = MIN(sb.st_size, context->download_max);
+
+              ret = fastboot_write(fd, context->download_buffer, len);
+              if (ret < 0)
+                {
+                  break;
+                }
+
+              sb.st_size -= len;
+            }
+        }
+    }
+
+  if (ret < 0)
     {
       fastboot_fail(context, "Flash erase failure");
     }