[PATCH 4/4] fastboot: add command to select the eMMC boot configuration

Patrick Delaunay
2020-09-09T13:22:39Z

Add command oem bootbus which executes the command
``mmc bootbus <id> <arg>`` on the current fastboot mmc device
( = CONFIG_FASTBOOT_FLASH_MMC_DEV) to set the eMMC boot
configuration on first update, with
<arg> = boot_bus_width reset_boot_bus_width boot_mode

$> fastboot oem bootbus:<boot_bus_width> <reset_boot_bus_width> <boot_mode>

Signed-off-by: Patrick Delaunay <patrick.delaunay@st.com>
---

doc/android/fastboot.rst | 1 +
drivers/fastboot/Kconfig | 7 +++++++
drivers/fastboot/fb_command.c | 36 +++++++++++++++++++++++++++++++++++
include/fastboot.h | 3 +++
4 files changed, 47 insertions(+)

diff --git a/doc/android/fastboot.rst b/doc/android/fastboot.rst
index 7d69372753..6aa725fcd8 100644
--- a/doc/android/fastboot.rst
+++ b/doc/android/fastboot.rst
@@ -25,6 +25,7 @@ The following OEM commands are supported (if enabled):
- ``oem format`` - this executes ``gpt write mmc %x $partitions``
- ``oem partconf`` - this executes ``mmc partconf %x <arg> 0`` to configure eMMC
with <arg> = boot_ack boot_partition
+- ``oem bootbus`` - this executes ``mmc bootbus %x %s`` to configure eMMC

Support for both eMMC and NAND devices is included.

diff --git a/drivers/fastboot/Kconfig b/drivers/fastboot/Kconfig
index 1bcc8d4ab9..a17e488714 100644
--- a/drivers/fastboot/Kconfig
+++ b/drivers/fastboot/Kconfig
@@ -196,6 +196,13 @@ config FASTBOOT_CMD_OEM_PARTCONF
Add support for the "oem partconf" command from a client. This set
the mmc boot-partition for the selecting eMMC device.

+config FASTBOOT_CMD_OEM_BOOTBUS
+ bool "Enable the 'oem bootbus' command"
+ depends on FASTBOOT_FLASH_MMC && SUPPORT_EMMC_BOOT
+ help
+ Add support for the "oem bootbus" command from a client. This set
+ the mmc boot configuration for the selecting eMMC device.
+
endif # FASTBOOT

endmenu
diff --git a/drivers/fastboot/fb_command.c b/drivers/fastboot/fb_command.c
index e42c018348..00efd477db 100644
--- a/drivers/fastboot/fb_command.c
+++ b/drivers/fastboot/fb_command.c
@@ -43,6 +43,9 @@ static void oem_format(char *, char *);
#if CONFIG_IS_ENABLED(FASTBOOT_CMD_OEM_PARTCONF)
static void oem_partconf(char *, char *);
#endif
+#if CONFIG_IS_ENABLED(FASTBOOT_CMD_OEM_BOOTBUS)
+static void oem_bootbus(char *, char *);
+#endif

static const struct {
const char *command;
@@ -98,6 +101,12 @@ static const struct {
.dispatch = oem_partconf,
},
#endif
+#if CONFIG_IS_ENABLED(FASTBOOT_CMD_OEM_BOOTBUS)
+ [FASTBOOT_COMMAND_OEM_BOOTBUS] = {
+ .command = "oem bootbus",
+ .dispatch = oem_bootbus,
+ },
+#endif
};

/**
@@ -372,3 +381,30 @@ static void oem_partconf(char *cmd_parameter, char *response)
fastboot_okay(NULL, response);
}
#endif
+
+#if CONFIG_IS_ENABLED(FASTBOOT_CMD_OEM_BOOTBUS)
+/**
+ * oem_bootbus() - Execute the OEM bootbus command
+ *
+ * @cmd_parameter: Pointer to command parameter
+ * @response: Pointer to fastboot response buffer
+ */
+static void oem_bootbus(char *cmd_parameter, char *response)
+{
+ char cmdbuf[32];
+
+ if (!cmd_parameter) {
+ fastboot_fail("Expected command parameter", response);
+ return;
+ }
+
+ /* execute 'mmc bootbus' command with cmd_parameter arguments*/
+ snprintf(cmdbuf, sizeof(cmdbuf), "mmc bootbus %x %s",
+ CONFIG_FASTBOOT_FLASH_MMC_DEV, cmd_parameter);
+ printf("Execute: %s\n", cmdbuf);
+ if (run_command(cmdbuf, 0))
+ fastboot_fail("Cannot set oem bootbus", response);
+ else
+ fastboot_okay(NULL, response);
+}
+#endif
diff --git a/include/fastboot.h b/include/fastboot.h
index 3e68852e9a..966ffc6d94 100644
--- a/include/fastboot.h
+++ b/include/fastboot.h
@@ -39,6 +39,9 @@ enum {
#if CONFIG_IS_ENABLED(FASTBOOT_CMD_OEM_PARTCONF)
FASTBOOT_COMMAND_OEM_PARTCONF,
#endif
+#if CONFIG_IS_ENABLED(FASTBOOT_CMD_OEM_BOOTBUS)
+ FASTBOOT_COMMAND_OEM_BOOTBUS,
+#endif

FASTBOOT_COMMAND_COUNT
};
--
2.17.1