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 4c605ac43 system/fastboot: dump all memory regions
4c605ac43 is described below

commit 4c605ac43f92c0cee74c277a1ce19c641cb90bda
Author: wangjianyu3 <wangjian...@xiaomi.com>
AuthorDate: Wed Jun 11 21:54:55 2025 +0800

    system/fastboot: dump all memory regions
    
    Add examples for oem memdump dumping all memory regions.
    
    Host side
    
      $ fastboot oem memdump
      fastboot oem memdump 0x20000 0x28000
      fastboot get_staged 0x20000.bin
      fastboot oem memdump 0x40000000 0xf590000
      fastboot get_staged 0x40000000.bin
      fastboot oem memdump 0x4ff30000 0xd0000
      fastboot get_staged 0x4ff30000.bin
      FAILED (remote: 'Invalid argument')
      fastboot: error: Command failed
    
    Device side
    
      nsh> fastbootd -h
      Usage: fastbootd [wait_ms]
    
      memdump:
          fastboot oem memdump 0x20000 0x28000
          fastboot get_staged 0x20000.bin
          fastboot oem memdump 0x40000000 0xf590000
          fastboot get_staged 0x40000000.bin
          fastboot oem memdump 0x4ff30000 0xd0000
          fastboot get_staged 0x4ff30000.bin
    
    Signed-off-by: wangjianyu3 <wangjian...@xiaomi.com>
---
 system/fastboot/fastboot.c | 44 ++++++++++++++++++++++++++++++++++++++++++++
 1 file changed, 44 insertions(+)

diff --git a/system/fastboot/fastboot.c b/system/fastboot/fastboot.c
index 4fa882eee..df250290d 100644
--- a/system/fastboot/fastboot.c
+++ b/system/fastboot/fastboot.c
@@ -25,6 +25,7 @@
  ****************************************************************************/
 
 #include <nuttx/config.h>
+#include <nuttx/memoryregion.h>
 #include <nuttx/mtd/mtd.h>
 #include <nuttx/version.h>
 
@@ -156,6 +157,8 @@ struct fastboot_cmd_s
                       FAR const char *arg);
 };
 
+typedef void (*memdump_print_t)(FAR void *, FAR char *);
+
 /****************************************************************************
  * Private Function Prototypes
  ****************************************************************************/
@@ -211,6 +214,13 @@ static const struct fastboot_cmd_s g_oem_cmd[] =
 #endif
 };
 
+#ifdef CONFIG_BOARD_MEMORY_RANGE
+static const struct memory_region_s g_memory_region[] =
+{
+  CONFIG_BOARD_MEMORY_RANGE
+};
+#endif
+
 /****************************************************************************
  * Private Functions
  ****************************************************************************/
@@ -650,6 +660,37 @@ static int fastboot_memdump_upload(FAR struct 
fastboot_ctx_s *context)
                         context->upload_param.size);
 }
 
+static void fastboot_memdump_region(memdump_print_t memprint, FAR void *priv)
+{
+#ifdef CONFIG_BOARD_MEMORY_RANGE
+  char response[FASTBOOT_MSG_LEN - 4];
+  size_t index;
+
+  for (index = 0; index < nitems(g_memory_region); index++)
+    {
+      snprintf(response, sizeof(response),
+               "fastboot oem memdump 0x%" PRIxPTR " 0x%" PRIxPTR "\n",
+               g_memory_region[index].start,
+               g_memory_region[index].end - g_memory_region[index].start);
+      memprint(priv, response);
+      snprintf(response, sizeof(response),
+               "fastboot get_staged 0x%" PRIxPTR ".bin\n",
+               g_memory_region[index].start);
+      memprint(priv, response);
+    }
+#endif
+}
+
+static void fastboot_memdump_syslog(FAR void *priv, FAR char *response)
+{
+  fb_err("    %s", response);
+}
+
+static void fastboot_memdump_response(FAR void *priv, FAR char *response)
+{
+  fastboot_ack((FAR struct fastboot_ctx_s *)priv, "TEXT", response);
+}
+
 /* Usage(host):
  *   fastboot oem memdump <addr> <size>
  *
@@ -666,6 +707,7 @@ static void fastboot_memdump(FAR struct fastboot_ctx_s 
*context,
              &context->upload_param.u.mem.addr,
              &context->upload_param.size) != 2)
     {
+      fastboot_memdump_region(fastboot_memdump_response, context);
       fastboot_fail(context, "Invalid argument");
       return;
     }
@@ -1044,6 +1086,8 @@ int main(int argc, FAR char **argv)
       if (strcmp(argv[1], "-h") == 0)
         {
           fb_err("Usage: fastbootd [wait_ms]\n");
+          fb_err("\nmemdump: \n");
+          fastboot_memdump_region(fastboot_memdump_syslog, NULL);
           return 0;
         }
 

Reply via email to