Skip to content

Commit 39f26db

Browse files
JianyuWang0623xiaoxiang781216
authored andcommitted
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 <[email protected]>
1 parent c9813ce commit 39f26db

File tree

1 file changed

+44
-0
lines changed

1 file changed

+44
-0
lines changed

system/fastboot/fastboot.c

Lines changed: 44 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -23,6 +23,7 @@
2323
****************************************************************************/
2424

2525
#include <nuttx/config.h>
26+
#include <nuttx/memoryregion.h>
2627
#include <nuttx/mtd/mtd.h>
2728
#include <nuttx/version.h>
2829

@@ -154,6 +155,8 @@ struct fastboot_cmd_s
154155
FAR const char *arg);
155156
};
156157

158+
typedef void (*memdump_print_t)(FAR void *, FAR char *);
159+
157160
/****************************************************************************
158161
* Private Function Prototypes
159162
****************************************************************************/
@@ -209,6 +212,13 @@ static const struct fastboot_cmd_s g_oem_cmd[] =
209212
#endif
210213
};
211214

215+
#ifdef CONFIG_BOARD_MEMORY_RANGE
216+
static const struct memory_region_s g_memory_region[] =
217+
{
218+
CONFIG_BOARD_MEMORY_RANGE
219+
};
220+
#endif
221+
212222
/****************************************************************************
213223
* Private Functions
214224
****************************************************************************/
@@ -648,6 +658,37 @@ static int fastboot_memdump_upload(FAR struct fastboot_ctx_s *context)
648658
context->upload_param.size);
649659
}
650660

661+
static void fastboot_memdump_region(memdump_print_t memprint, FAR void *priv)
662+
{
663+
#ifdef CONFIG_BOARD_MEMORY_RANGE
664+
char response[FASTBOOT_MSG_LEN - 4];
665+
size_t index;
666+
667+
for (index = 0; index < nitems(g_memory_region); index++)
668+
{
669+
snprintf(response, sizeof(response),
670+
"fastboot oem memdump 0x%" PRIxPTR " 0x%" PRIxPTR "\n",
671+
g_memory_region[index].start,
672+
g_memory_region[index].end - g_memory_region[index].start);
673+
memprint(priv, response);
674+
snprintf(response, sizeof(response),
675+
"fastboot get_staged 0x%" PRIxPTR ".bin\n",
676+
g_memory_region[index].start);
677+
memprint(priv, response);
678+
}
679+
#endif
680+
}
681+
682+
static void fastboot_memdump_syslog(FAR void *priv, FAR char *response)
683+
{
684+
fb_err(" %s", response);
685+
}
686+
687+
static void fastboot_memdump_response(FAR void *priv, FAR char *response)
688+
{
689+
fastboot_ack((FAR struct fastboot_ctx_s *)priv, "TEXT", response);
690+
}
691+
651692
/* Usage(host):
652693
* fastboot oem memdump <addr> <size>
653694
*
@@ -664,6 +705,7 @@ static void fastboot_memdump(FAR struct fastboot_ctx_s *context,
664705
&context->upload_param.u.mem.addr,
665706
&context->upload_param.size) != 2)
666707
{
708+
fastboot_memdump_region(fastboot_memdump_response, context);
667709
fastboot_fail(context, "Invalid argument");
668710
return;
669711
}
@@ -1042,6 +1084,8 @@ int main(int argc, FAR char **argv)
10421084
if (strcmp(argv[1], "-h") == 0)
10431085
{
10441086
fb_err("Usage: fastbootd [wait_ms]\n");
1087+
fb_err("\nmemdump: \n");
1088+
fastboot_memdump_region(fastboot_memdump_syslog, NULL);
10451089
return 0;
10461090
}
10471091

0 commit comments

Comments
 (0)