Skip to content

Commit

Permalink
fastboot: add oem console and oem cmd
Browse files Browse the repository at this point in the history
  • Loading branch information
IonAgorria authored and clamor-s committed Oct 3, 2023
1 parent 384663f commit 53c4b82
Show file tree
Hide file tree
Showing 3 changed files with 106 additions and 0 deletions.
14 changes: 14 additions & 0 deletions drivers/fastboot/Kconfig
Original file line number Diff line number Diff line change
Expand Up @@ -241,6 +241,20 @@ config FASTBOOT_OEM_RUN
this feature if you are using verified boot, as it will allow an
attacker to bypass any restrictions you have in place.

config FASTBOOT_CMD_OEM_CONSOLE
bool "Enable the 'oem console' command"
help
Add support for the "oem console" command to input and read console
record buffer.

config FASTBOOT_CMD_OEM_CMD
bool "Enable the 'oem cmd' command"
help
Add support for the "oem cmd" command to run a command and read
console record buffer if is enabled. Be aware that you provide full
access to any U-Boot command, including working with memory and may
open a huge backdoor when enabling this option.

endif # FASTBOOT

endmenu
90 changes: 90 additions & 0 deletions drivers/fastboot/fb_command.c
Original file line number Diff line number Diff line change
Expand Up @@ -41,6 +41,8 @@ static void reboot_recovery(char *, char *);
static void oem_format(char *, char *);
static void oem_partconf(char *, char *);
static void oem_bootbus(char *, char *);
static void oem_console(char *, char *);
static void oem_cmd(char *, char *);
static void run_ucmd(char *, char *);
static void run_acmd(char *, char *);

Expand Down Expand Up @@ -108,6 +110,14 @@ static const struct {
.command = "oem run",
.dispatch = CONFIG_IS_ENABLED(FASTBOOT_OEM_RUN, (run_ucmd), (NULL))
},
[FASTBOOT_COMMAND_OEM_CONSOLE] = {
.command = "oem console",
.dispatch = CONFIG_IS_ENABLED(FASTBOOT_CMD_OEM_CONSOLE, (oem_console), (NULL))
},
[FASTBOOT_COMMAND_OEM_CMD] = {
.command = "oem cmd",
.dispatch = CONFIG_IS_ENABLED(FASTBOOT_CMD_OEM_CMD, (oem_cmd), (NULL)),
},
[FASTBOOT_COMMAND_UCMD] = {
.command = "UCmd",
.dispatch = CONFIG_IS_ENABLED(FASTBOOT_UUU_SUPPORT, (run_ucmd), (NULL))
Expand Down Expand Up @@ -159,6 +169,33 @@ void fastboot_multiresponse(int cmd, char *response)
case FASTBOOT_COMMAND_GETVAR:
fastboot_getvar_all(response);
break;
#if CONFIG_IS_ENABLED(FASTBOOT_CMD_OEM_CONSOLE) || CONFIG_IS_ENABLED(FASTBOOT_CMD_OEM_CMD)
case FASTBOOT_COMMAND_OEM_CONSOLE:
case FASTBOOT_COMMAND_OEM_CMD:
{
#ifdef CONFIG_CONSOLE_RECORD
char buf[FASTBOOT_RESPONSE_LEN] = { 0 };
if (console_record_isempty()) {
//Flush the console records to empty buffer
console_record_reset();
//We are done here
fastboot_okay(NULL, response);
break;
} else {
int ret = console_record_readline(buf, sizeof(buf) - 5);
if (ret < 0) {
fastboot_fail("Error reading console", response);
} else {
fastboot_response("INFO", response, "%s", buf);
}
}
#else
//Shouldn't reach here anyway
fastboot_okay(NULL, response);
#endif
break;
}
#endif
default:
fastboot_fail("Unknown multiresponse command", response);
break;
Expand Down Expand Up @@ -503,3 +540,56 @@ static void __maybe_unused oem_bootbus(char *cmd_parameter, char *response)
else
fastboot_okay(NULL, response);
}

/**
* oem_console() - Execute the OEM console command
*
* @cmd_parameter: Pointer to command parameter
* @response: Pointer to fastboot response buffer
*/
static void __maybe_unused oem_console(char *cmd_parameter, char *response)
{
if (cmd_parameter) {
console_in_puts(cmd_parameter);
}

#ifdef CONFIG_CONSOLE_RECORD
if (console_record_isempty()) {
fastboot_fail("Empty console", response);
} else {
fastboot_response("MORE", response, NULL);
}
#else
fastboot_okay(NULL, response);
#endif
}

/**
* oem_cmd() - Execute the OEM cmd command
*
* @cmd_parameter: Pointer to command parameter
* @response: Pointer to fastboot response buffer
*/
static void __maybe_unused oem_cmd(char *cmd_parameter, char *response)
{
if (!cmd_parameter) {
fastboot_fail("No command was provided", response);
return;
}

if (run_command(cmd_parameter, 0)) {
fastboot_fail("Error running command", response);
return;
}

//Return console if recording or just OK
#ifdef CONFIG_CONSOLE_RECORD
if (console_record_isempty()) {
fastboot_okay(NULL, response);
} else {
fastboot_response("MORE", response, NULL);
}
#else
fastboot_okay(NULL, response);
#endif
}
2 changes: 2 additions & 0 deletions include/fastboot.h
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,8 @@ enum {
FASTBOOT_COMMAND_OEM_PARTCONF,
FASTBOOT_COMMAND_OEM_BOOTBUS,
FASTBOOT_COMMAND_OEM_RUN,
FASTBOOT_COMMAND_OEM_CONSOLE,
FASTBOOT_COMMAND_OEM_CMD,
FASTBOOT_COMMAND_ACMD,
FASTBOOT_COMMAND_UCMD,
FASTBOOT_COMMAND_COUNT
Expand Down

0 comments on commit 53c4b82

Please sign in to comment.