]> git.dujemihanovic.xyz Git - u-boot.git/commitdiff
fastboot: add oem console command support
authorIon Agorria <ion@agorria.com>
Fri, 5 Jan 2024 07:22:11 +0000 (09:22 +0200)
committerMattijs Korpershoek <mkorpershoek@baylibre.com>
Tue, 9 Jan 2024 13:58:33 +0000 (14:58 +0100)
"oem console" serves to read console record buffer.

Signed-off-by: Ion Agorria <ion@agorria.com>
Signed-off-by: Svyatoslav Ryhel <clamor95@gmail.com>
Reviewed-by: Mattijs Korpershoek <mkorpershoek@baylibre.com>
Link: https://lore.kernel.org/r/20240105072212.6615-7-clamor95@gmail.com
Signed-off-by: Mattijs Korpershoek <mkorpershoek@baylibre.com>
doc/android/fastboot.rst
drivers/fastboot/Kconfig
drivers/fastboot/fb_command.c
include/fastboot.h

index 1ad8a897c8536665ff4de3f26296d8f5167f2e28..05d8f777595f0fb88c70df5ae30a7feb83e216b4 100644 (file)
@@ -29,6 +29,7 @@ The following OEM commands are supported (if enabled):
   with <arg> = boot_ack boot_partition
 - ``oem bootbus``  - this executes ``mmc bootbus %x %s`` to configure eMMC
 - ``oem run`` - this executes an arbitrary U-Boot command
+- ``oem console`` - this dumps U-Boot console record buffer
 
 Support for both eMMC and NAND devices is included.
 
index 11fc0fe1c800a847ccaa8fc7c3830ffe079f5580..5e5855a76c2dcbc1c23420fd74253210c99f19bc 100644 (file)
@@ -242,6 +242,13 @@ 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"
+       depends on CONSOLE_RECORD
+       help
+         Add support for the "oem console" command to input and read console
+         record buffer.
+
 endif # FASTBOOT
 
 endmenu
index 6f621df074aee4047536cca088f8c9c2424c2feb..f95f4e4ae15e3cacfed3c8004d88d61ee35b83c1 100644 (file)
@@ -41,6 +41,7 @@ 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 run_ucmd(char *, char *);
 static void run_acmd(char *, char *);
 
@@ -108,6 +109,10 @@ 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_UCMD] = {
                .command = "UCmd",
                .dispatch = CONFIG_IS_ENABLED(FASTBOOT_UUU_SUPPORT, (run_ucmd), (NULL))
@@ -159,6 +164,23 @@ void fastboot_multiresponse(int cmd, char *response)
        case FASTBOOT_COMMAND_GETVAR:
                fastboot_getvar_all(response);
                break;
+       case FASTBOOT_COMMAND_OEM_CONSOLE:
+               if (CONFIG_IS_ENABLED(FASTBOOT_CMD_OEM_CONSOLE)) {
+                       char buf[FASTBOOT_RESPONSE_LEN] = { 0 };
+
+                       if (console_record_isempty()) {
+                               console_record_reset();
+                               fastboot_okay(NULL, response);
+                       } 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);
+                       }
+                       break;
+               }
        default:
                fastboot_fail("Unknown multiresponse command", response);
                break;
@@ -503,3 +525,20 @@ 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);
+
+       if (console_record_isempty())
+               fastboot_fail("Empty console", response);
+       else
+               fastboot_response(FASTBOOT_MULTIRESPONSE_START, response, NULL);
+}
index 59cbea61ecab553e459e54a776b086931c020faa..1e7920eb9133bec5d2dc73104f20e7f069c78a98 100644 (file)
@@ -47,6 +47,7 @@ enum {
        FASTBOOT_COMMAND_OEM_PARTCONF,
        FASTBOOT_COMMAND_OEM_BOOTBUS,
        FASTBOOT_COMMAND_OEM_RUN,
+       FASTBOOT_COMMAND_OEM_CONSOLE,
        FASTBOOT_COMMAND_ACMD,
        FASTBOOT_COMMAND_UCMD,
        FASTBOOT_COMMAND_COUNT