Skip to content

Commit

Permalink
system/fastboot: Add support for oem mkrd command
Browse files Browse the repository at this point in the history
To support creating RAM disk on device via fastboot on host side.

Usage

    fastboot oem mkrd <minor> <nsectors> <sectsize>

Test

    0. The "esp32s3-devkit:fastboot" configuration with `SYSTEM_FASTBOOTD_MKRD` enabled

        ./tools/configure.sh -l esp32s3-devkit:fastboot
	# Enable `SYSTEM_FASTBOOTD_MKRD`
	make menuconfig

    1. List "ram10" on device side

        nsh> ls /dev/ram10
        nsh: ls: stat failed: 2

    2. Create RAM disk "ram10" on host side

        $ fastboot -s 1234 oem mkrd 10 2 512
                                                           OKAY [  0.001s]
        Finished. Total time: 0.001s

    3. List "ram10" on device side, again

	nsh> ls -l /dev/ram10
	 brw-rw-rw-        1024 /dev/ram10

Signed-off-by: wangjianyu3 <[email protected]>
  • Loading branch information
JianyuWang0623 committed Feb 20, 2025
1 parent fb4c03f commit de83ff2
Show file tree
Hide file tree
Showing 2 changed files with 50 additions and 1 deletion.
7 changes: 7 additions & 0 deletions system/fastboot/Kconfig
Original file line number Diff line number Diff line change
Expand Up @@ -32,4 +32,11 @@ config SYSTEM_FASTBOOTD_USB_BOARDCTL
---help---
Connect usbdev before running fastboot daemon.

config SYSTEM_FASTBOOTD_MKRD
bool "Create RAM disk"
default n
depends on BOARDCTL_MKRD
---help---
fastboot oem mkrd <minor> <nsectors> <sectsize>

endif # SYSTEM_FASTBOOTD
44 changes: 43 additions & 1 deletion system/fastboot/fastboot.c
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,9 @@
#include <nuttx/config.h>
#include <nuttx/mtd/mtd.h>
#include <nuttx/version.h>
#ifdef CONFIG_SYSTEM_FASTBOOTD_MKRD
#include <nuttx/drivers/ramdisk.h>
#endif

#include <errno.h>
#include <fcntl.h>
Expand Down Expand Up @@ -180,6 +183,10 @@ static void fastboot_memdump(FAR struct fastboot_ctx_s *context,
FAR const char *arg);
static void fastboot_filedump(FAR struct fastboot_ctx_s *context,
FAR const char *arg);
#ifdef CONFIG_SYSTEM_FASTBOOTD_MKRD
static void fastboot_mkrd(FAR struct fastboot_ctx_s *context,
FAR const char *arg);
#endif

/****************************************************************************
* Private Data
Expand All @@ -200,7 +207,10 @@ static const struct fastboot_cmd_s g_fast_cmd[] =
static const struct fastboot_cmd_s g_oem_cmd[] =
{
{ "filedump", fastboot_filedump },
{ "memdump", fastboot_memdump }
{ "memdump", fastboot_memdump },
#ifdef CONFIG_SYSTEM_FASTBOOTD_MKRD
{ "mkrd", fastboot_mkrd },
#endif
};

/****************************************************************************
Expand Down Expand Up @@ -776,6 +786,38 @@ static void fastboot_filedump(FAR struct fastboot_ctx_s *context,
fastboot_okay(context, "");
}

#ifdef CONFIG_SYSTEM_FASTBOOTD_MKRD
static void fastboot_mkrd(FAR struct fastboot_ctx_s *context,
FAR const char *arg)
{
struct boardioc_mkrd_s desc;
int ret = -1;

if (arg != NULL)
{
ret = sscanf(arg, "%" SCNu8 " %" SCNu32 " %" SCNu16,
&desc.minor, &desc.nsectors, &desc.sectsize);
}

if (ret != 3)
{
fastboot_fail(context, "Usage: mkrd <minor> <nsectors> <sectsize>");
return;
}

desc.rdflags = RDFLAG_WRENABLED | RDFLAG_FUNLINK;

ret = boardctl(BOARDIOC_MKRD, (uintptr_t)&desc);
if (ret < 0)
{
fastboot_fail(context, "Create RAM disk failed %d", ret);
return;
}

fastboot_okay(context, "");
}
#endif

static void fastboot_upload(FAR struct fastboot_ctx_s *context,
FAR const char *arg)
{
Expand Down

0 comments on commit de83ff2

Please sign in to comment.