Skip to content

Commit c9158a8

Browse files
JianyuWang0623xiaoxiang781216
authored andcommitted
system/fastboot: Add support for fastboot oem shell
To support executing custom commands. Usage fastboot oem shell <command> Tests # Configuration "esp32s3-devkit:fastboot" with `SYSTEM_FASTBOOTD_SHELL` enabled $ fastboot --version fastboot version 35.0.2-12147458 $ fastboot oem shell ls /FILE_NOT_EXISTS FAILED (remote: 'error detected 0xff00 4') fastboot: error: Command failed $ fastboot oem shell ps PID GROUP PRI POLICY TYPE NPX STATE EVENT SIGMASK STACK COMMAND 0 0 0 FIFO Kthread - Ready 0000000000000000 0003056 Idle_Task 1 0 224 RR Kthread - Waiting Semaphore 0000000000000000 0001976 hpwork 0x3fc8bd50 0x3fc8bd80 2 2 100 RR Task - Waiting Semaphore 0000000000000000 0004048 nsh_main 3 3 100 RR Task - Ready 0000000000000000 0001992 fastbootd 4 4 100 RR Task - Running 0000000000000000 0001992 popen -c ps OKAY [ 0.010s] Finished. Total time: 0.010s Signed-off-by: wangjianyu3 <[email protected]>
1 parent 064bfb3 commit c9158a8

File tree

2 files changed

+50
-1
lines changed

2 files changed

+50
-1
lines changed

system/fastboot/Kconfig

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -31,4 +31,14 @@ config FASTBOOTD_USB_BOARDCTL
3131
---help---
3232
Connect usbdev before running fastboot daemon.
3333

34+
config SYSTEM_FASTBOOTD_SHELL
35+
bool "Execute custom commands"
36+
default n
37+
depends on SCHED_CHILD_STATUS
38+
depends on SYSTEM_POPEN
39+
---help---
40+
Enable to support executing custom commands.
41+
e.g. fastboot oem shell ps
42+
e.g. fastboot oem shell "mkrd -m 10 -s 512 640"
43+
3444
endif # SYSTEM_FASTBOOTD

system/fastboot/fastboot.c

Lines changed: 40 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -44,6 +44,7 @@
4444
#include <sys/statfs.h>
4545
#include <sys/types.h>
4646
#include <sys/poll.h>
47+
#include <sys/wait.h>
4748

4849
/****************************************************************************
4950
* Pre-processor Definitions
@@ -178,6 +179,10 @@ static void fastboot_memdump(FAR struct fastboot_ctx_s *context,
178179
FAR const char *arg);
179180
static void fastboot_filedump(FAR struct fastboot_ctx_s *context,
180181
FAR const char *arg);
182+
#ifdef CONFIG_SYSTEM_FASTBOOTD_SHELL
183+
static void fastboot_shell(FAR struct fastboot_ctx_s *context,
184+
FAR const char *arg);
185+
#endif
181186

182187
/****************************************************************************
183188
* Private Data
@@ -198,7 +203,10 @@ static const struct fastboot_cmd_s g_fast_cmd[] =
198203
static const struct fastboot_cmd_s g_oem_cmd[] =
199204
{
200205
{ "filedump", fastboot_filedump },
201-
{ "memdump", fastboot_memdump }
206+
{ "memdump", fastboot_memdump },
207+
#ifdef CONFIG_SYSTEM_FASTBOOTD_SHELL
208+
{ "shell", fastboot_shell },
209+
#endif
202210
};
203211

204212
/****************************************************************************
@@ -774,6 +782,37 @@ static void fastboot_filedump(FAR struct fastboot_ctx_s *context,
774782
fastboot_okay(context, "");
775783
}
776784

785+
#ifdef CONFIG_SYSTEM_FASTBOOTD_SHELL
786+
static void fastboot_shell(FAR struct fastboot_ctx_s *context,
787+
FAR const char *arg)
788+
{
789+
char response[FASTBOOT_MSG_LEN - 4];
790+
FILE *fp;
791+
int ret;
792+
793+
fp = popen(arg, "r");
794+
if (fp == NULL)
795+
{
796+
fastboot_fail(context, "popen() fails %d", errno);
797+
return;
798+
}
799+
800+
while (fgets(response, sizeof(response), fp))
801+
{
802+
fastboot_ack(context, "TEXT", response);
803+
}
804+
805+
ret = pclose(fp);
806+
if (WIFEXITED(ret) && WEXITSTATUS(ret) == 0)
807+
{
808+
fastboot_okay(context, "");
809+
return;
810+
}
811+
812+
fastboot_fail(context, "error detected 0x%x %d", ret, errno);
813+
}
814+
#endif
815+
777816
static void fastboot_upload(FAR struct fastboot_ctx_s *context,
778817
FAR const char *arg)
779818
{

0 commit comments

Comments
 (0)