diff mbox series

[U-Boot,v5,16/16] fastboot: Add support for 'oem format' command

Message ID 1526572769-5906-17-git-send-email-alex.kiernan@gmail.com
State Superseded
Delegated to: Joe Hershberger
Headers show
Series Add fastboot UDP support | expand

Commit Message

Alex Kiernan May 17, 2018, 3:59 p.m. UTC
Introduce 'oem format' which matches the USB implementation, guard this
with CONFIG_FASTBOOT_CMD_OEM_FORMAT so that you can configure it out.

Signed-off-by: Alex Kiernan <alex.kiernan@gmail.com>
---

Changes in v5:
- new

Changes in v4: None
Changes in v3: None
Changes in v2: None

 drivers/fastboot/Kconfig      |  8 ++++++++
 drivers/fastboot/fb_command.c | 33 +++++++++++++++++++++++++++++++++
 include/fastboot.h            |  3 +++
 3 files changed, 44 insertions(+)
diff mbox series

Patch

diff --git a/drivers/fastboot/Kconfig b/drivers/fastboot/Kconfig
index 4c0a5b0..b3186b0 100644
--- a/drivers/fastboot/Kconfig
+++ b/drivers/fastboot/Kconfig
@@ -132,6 +132,14 @@  config FASTBOOT_MBR_NAME
 	  specified on the "fastboot flash" command line matches the value
 	  defined here. The default target name for updating MBR is "mbr".
 
+config FASTBOOT_CMD_OEM_FORMAT
+	bool "Enable the 'oem format' command"
+	depends on FASTBOOT_FLASH_MMC && CMD_GPT
+	help
+	  Add support for the "oem format" command from a client. This
+	  relies on the env variable partitions to contain the list of
+	  partitions as required by the gpt command.
+
 endif # FASTBOOT
 
 endmenu
diff --git a/drivers/fastboot/fb_command.c b/drivers/fastboot/fb_command.c
index 4db0165..0b8c3b9 100644
--- a/drivers/fastboot/fb_command.c
+++ b/drivers/fastboot/fb_command.c
@@ -34,6 +34,9 @@  static void flash(char *, char *);
 static void erase(char *, char *);
 #endif
 static void reboot_bootloader(char *, char *);
+#if CONFIG_IS_ENABLED(FASTBOOT_CMD_OEM_FORMAT)
+static void oem_format(char *, char *);
+#endif
 
 static const struct {
 	const char *command;
@@ -77,6 +80,12 @@  static const struct {
 		.command = "set_active",
 		.dispatch = okay
 	},
+#if CONFIG_IS_ENABLED(FASTBOOT_CMD_OEM_FORMAT)
+	[FASTBOOT_COMMAND_OEM_FORMAT] = {
+		.command = "oem format",
+		.dispatch = oem_format,
+	},
+#endif
 };
 
 /**
@@ -293,3 +302,27 @@  static void reboot_bootloader(char *cmd_parameter, char *response)
 	else
 		fastboot_okay(NULL, response);
 }
+
+#if CONFIG_IS_ENABLED(FASTBOOT_CMD_OEM_FORMAT)
+/**
+ * oem_format() - Execute the OEM format command
+ *
+ * @cmd_parameter: Pointer to command parameter
+ * @response: Pointer to fastboot response buffer
+ */
+static void oem_format(char *cmd_parameter, char *response)
+{
+	char cmdbuf[32];
+
+	if (!env_get("partitions")) {
+		fastboot_fail("partitions not set", response);
+	} else {
+		sprintf(cmdbuf, "gpt write mmc %x $partitions",
+			CONFIG_FASTBOOT_FLASH_MMC_DEV);
+		if (run_command(cmdbuf, 0))
+			fastboot_fail("", response);
+		else
+			fastboot_okay(NULL, response);
+	}
+}
+#endif
diff --git a/include/fastboot.h b/include/fastboot.h
index d7de385..3384c1a 100644
--- a/include/fastboot.h
+++ b/include/fastboot.h
@@ -33,6 +33,9 @@  enum {
 	FASTBOOT_COMMAND_REBOOT,
 	FASTBOOT_COMMAND_REBOOT_BOOTLOADER,
 	FASTBOOT_COMMAND_SET_ACTIVE,
+#if CONFIG_IS_ENABLED(FASTBOOT_CMD_OEM_FORMAT)
+	FASTBOOT_COMMAND_OEM_FORMAT,
+#endif
 
 	FASTBOOT_COMMAND_COUNT
 };