common: fastboot: support oem format command
authorChanho Park <chanho61.park@samsung.com>
Wed, 5 Aug 2015 03:27:31 +0000 (12:27 +0900)
committerChanho Park <chanho61.park@samsung.com>
Wed, 5 Aug 2015 03:27:31 +0000 (12:27 +0900)
This patch implements fastboot's oem format command. The default
partition format is gpt and dos partition will be supported later.

The "fastboot oem format" executes "gpt write mmc $partitions" command.
Thus, you should define the "$partitions" environment variable. After
creating gpt partition, the board will be rebooted automatically and
enter fastboot again.

Change-Id: Ia05194d150e3ccd7ea3ee68f2d67cbc6b5414d09
Signed-off-by: Chanho Park <chanho61.park@samsung.com>
common/cmd_fastboot.c

index 186c0d8629e84de8b56d8af6e0f7da4924e47680..d370c8e08fdb8b1a0898a37176fe4669e6275a8f 100644 (file)
@@ -1372,10 +1372,42 @@ static int process_cmd_flash(const char *cmdbuf, char *response)
        return 0;
 }
 
+static int process_cmd_format(const char *cmdbuf, char *response)
+{
+       char run_cmd[32];
+       int status = -1;
+       char *part_type = getenv("part_type");
+       if (!part_type)
+               part_type = "gpt";
+
+       if (!strcmp(part_type, "gpt")) {
+               sprintf(run_cmd, "gpt write mmc 0 $partitions");
+               status = run_command(run_cmd, 0);
+       }
+       return status;
+}
+
 static int process_cmd_oem(const char *cmdbuf, char *response)
 {
-       sprintf(response, "INFOunknown OEM command");
-       fastboot_tx_status(response, strlen(response), FASTBOOT_TX_ASYNC);
+       if (!strcmp("format", cmdbuf + 4)) {
+               if (process_cmd_format(cmdbuf, response) == -1) {
+                       sprintf(response, "FAILpartition format");
+                       fastboot_tx_status(response, strlen(response),
+                                          FASTBOOT_TX_ASYNC);
+                       return -1;
+               } else {
+                       sprintf(response, "OKAY");
+                       fastboot_tx_status(response, strlen(response),
+                                       FASTBOOT_TX_SYNC);
+#ifdef CONFIG_FASTBOOT_AUTO_REBOOT
+                       do_reset_fastboot();
+#endif
+               }
+       } else {
+               sprintf(response, "INFOunknown OEM command");
+               fastboot_tx_status(response, strlen(response),
+                                  FASTBOOT_TX_ASYNC);
+       }
 
        sprintf(response, "OKAY");
        fastboot_tx_status(response, strlen(response), FASTBOOT_TX_ASYNC);