Merge tag 'tpm-030822' of https://source.denx.de/u-boot/custodians/u-boot-tpm
[platform/kernel/u-boot.git] / drivers / fastboot / fb_command.c
index 3c4acfe..bdfdf26 100644 (file)
@@ -36,9 +36,22 @@ static void flash(char *, char *);
 static void erase(char *, char *);
 #endif
 static void reboot_bootloader(char *, char *);
+static void reboot_fastbootd(char *, char *);
+static void reboot_recovery(char *, char *);
 #if CONFIG_IS_ENABLED(FASTBOOT_CMD_OEM_FORMAT)
 static void oem_format(char *, char *);
 #endif
+#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
+
+#if CONFIG_IS_ENABLED(FASTBOOT_UUU_SUPPORT)
+static void run_ucmd(char *, char *);
+static void run_acmd(char *, char *);
+#endif
 
 static const struct {
        const char *command;
@@ -78,6 +91,14 @@ static const struct {
                .command = "reboot-bootloader",
                .dispatch = reboot_bootloader
        },
+       [FASTBOOT_COMMAND_REBOOT_FASTBOOTD] =  {
+               .command = "reboot-fastboot",
+               .dispatch = reboot_fastbootd
+       },
+       [FASTBOOT_COMMAND_REBOOT_RECOVERY] =  {
+               .command = "reboot-recovery",
+               .dispatch = reboot_recovery
+       },
        [FASTBOOT_COMMAND_SET_ACTIVE] =  {
                .command = "set_active",
                .dispatch = okay
@@ -88,6 +109,28 @@ static const struct {
                .dispatch = oem_format,
        },
 #endif
+#if CONFIG_IS_ENABLED(FASTBOOT_CMD_OEM_PARTCONF)
+       [FASTBOOT_COMMAND_OEM_PARTCONF] = {
+               .command = "oem partconf",
+               .dispatch = oem_partconf,
+       },
+#endif
+#if CONFIG_IS_ENABLED(FASTBOOT_CMD_OEM_BOOTBUS)
+       [FASTBOOT_COMMAND_OEM_BOOTBUS] = {
+               .command = "oem bootbus",
+               .dispatch = oem_bootbus,
+       },
+#endif
+#if CONFIG_IS_ENABLED(FASTBOOT_UUU_SUPPORT)
+       [FASTBOOT_COMMAND_UCMD] = {
+               .command = "UCmd",
+               .dispatch = run_ucmd,
+       },
+       [FASTBOOT_COMMAND_ACMD] = {
+               .command = "ACmd",
+               .dispatch = run_acmd,
+       },
+#endif
 };
 
 /**
@@ -164,7 +207,7 @@ static void download(char *cmd_parameter, char *response)
                return;
        }
        fastboot_bytes_received = 0;
-       fastboot_bytes_expected = simple_strtoul(cmd_parameter, &tmp, 16);
+       fastboot_bytes_expected = hextoul(cmd_parameter, &tmp);
        if (fastboot_bytes_expected == 0) {
                fastboot_fail("Expected nonzero image size", response);
                return;
@@ -298,6 +341,59 @@ static void erase(char *cmd_parameter, char *response)
 }
 #endif
 
+#if CONFIG_IS_ENABLED(FASTBOOT_UUU_SUPPORT)
+/**
+ * run_ucmd() - Execute the UCmd command
+ *
+ * @cmd_parameter: Pointer to command parameter
+ * @response: Pointer to fastboot response buffer
+ */
+static void run_ucmd(char *cmd_parameter, char *response)
+{
+       if (!cmd_parameter) {
+               pr_err("missing slot suffix\n");
+               fastboot_fail("missing command", response);
+               return;
+       }
+
+       if (run_command(cmd_parameter, 0))
+               fastboot_fail("", response);
+       else
+               fastboot_okay(NULL, response);
+}
+
+static char g_a_cmd_buff[64];
+
+void fastboot_acmd_complete(void)
+{
+       run_command(g_a_cmd_buff, 0);
+}
+
+/**
+ * run_acmd() - Execute the ACmd command
+ *
+ * @cmd_parameter: Pointer to command parameter
+ * @response: Pointer to fastboot response buffer
+ */
+static void run_acmd(char *cmd_parameter, char *response)
+{
+       if (!cmd_parameter) {
+               pr_err("missing slot suffix\n");
+               fastboot_fail("missing command", response);
+               return;
+       }
+
+       if (strlen(cmd_parameter) > sizeof(g_a_cmd_buff)) {
+               pr_err("too long command\n");
+               fastboot_fail("too long command", response);
+               return;
+       }
+
+       strcpy(g_a_cmd_buff, cmd_parameter);
+       fastboot_okay(NULL, response);
+}
+#endif
+
 /**
  * reboot_bootloader() - Sets reboot bootloader flag.
  *
@@ -306,12 +402,40 @@ static void erase(char *cmd_parameter, char *response)
  */
 static void reboot_bootloader(char *cmd_parameter, char *response)
 {
-       if (fastboot_set_reboot_flag())
+       if (fastboot_set_reboot_flag(FASTBOOT_REBOOT_REASON_BOOTLOADER))
                fastboot_fail("Cannot set reboot flag", response);
        else
                fastboot_okay(NULL, response);
 }
 
+/**
+ * reboot_fastbootd() - Sets reboot fastboot flag.
+ *
+ * @cmd_parameter: Pointer to command parameter
+ * @response: Pointer to fastboot response buffer
+ */
+static void reboot_fastbootd(char *cmd_parameter, char *response)
+{
+       if (fastboot_set_reboot_flag(FASTBOOT_REBOOT_REASON_FASTBOOTD))
+               fastboot_fail("Cannot set fastboot flag", response);
+       else
+               fastboot_okay(NULL, response);
+}
+
+/**
+ * reboot_recovery() - Sets reboot recovery flag.
+ *
+ * @cmd_parameter: Pointer to command parameter
+ * @response: Pointer to fastboot response buffer
+ */
+static void reboot_recovery(char *cmd_parameter, char *response)
+{
+       if (fastboot_set_reboot_flag(FASTBOOT_REBOOT_REASON_RECOVERY))
+               fastboot_fail("Cannot set recovery flag", response);
+       else
+               fastboot_okay(NULL, response);
+}
+
 #if CONFIG_IS_ENABLED(FASTBOOT_CMD_OEM_FORMAT)
 /**
  * oem_format() - Execute the OEM format command
@@ -335,3 +459,57 @@ static void oem_format(char *cmd_parameter, char *response)
        }
 }
 #endif
+
+#if CONFIG_IS_ENABLED(FASTBOOT_CMD_OEM_PARTCONF)
+/**
+ * oem_partconf() - Execute the OEM partconf command
+ *
+ * @cmd_parameter: Pointer to command parameter
+ * @response: Pointer to fastboot response buffer
+ */
+static void oem_partconf(char *cmd_parameter, char *response)
+{
+       char cmdbuf[32];
+
+       if (!cmd_parameter) {
+               fastboot_fail("Expected command parameter", response);
+               return;
+       }
+
+       /* execute 'mmc partconfg' command with cmd_parameter arguments*/
+       snprintf(cmdbuf, sizeof(cmdbuf), "mmc partconf %x %s 0",
+                CONFIG_FASTBOOT_FLASH_MMC_DEV, cmd_parameter);
+       printf("Execute: %s\n", cmdbuf);
+       if (run_command(cmdbuf, 0))
+               fastboot_fail("Cannot set oem partconf", response);
+       else
+               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