From patchwork Thu Jun 4 07:55:49 2020 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Roman Kovalivskyi X-Patchwork-Id: 241625 List-Id: U-Boot discussion From: roman.kovalivskyi at globallogic.com (Roman Kovalivskyi) Date: Thu, 4 Jun 2020 10:55:49 +0300 Subject: [PATCH v2 2/2] fastboot: add default fastboot_set_reboot_flag implementation In-Reply-To: References: Message-ID: Default implementation of fastboot_set_reboot_flag function that depends on "bcb" commands could be used in general case if there are no need to make any platform-specific implementation, otherwise it could be disabled via Kconfig option FASTBOOT_USE_BCB_SET_REBOOT_FLAG. Please note that FASTBOOT_USE_BCB_SET_REBOOT_FLAG is mutually exclusive with some platforms which already have their own implementation of this function. Signed-off-by: Roman Kovalivskyi --- drivers/fastboot/Kconfig | 9 +++++++++ drivers/fastboot/fb_common.c | 36 ++++++++++++++++++++++++++++++++++++ 2 files changed, 45 insertions(+) diff --git a/drivers/fastboot/Kconfig b/drivers/fastboot/Kconfig index d4436dfc9173..bcb43bc5d556 100644 --- a/drivers/fastboot/Kconfig +++ b/drivers/fastboot/Kconfig @@ -165,6 +165,15 @@ config FASTBOOT_CMD_OEM_FORMAT relies on the env variable partitions to contain the list of partitions as required by the gpt command. +config FASTBOOT_USE_BCB_SET_REBOOT_FLAG + bool "Enable default fastboot_set_reboot_flag implementation" + depends on CMD_BCB && !ARCH_MESON && !ARCH_ROCKCHIP && !TARGET_KC1 && \ + !TARGET_SNIPER && !TARGET_AM57XX_EVM && !TARGET_DRA7XX_EVM + default 1 + help + Add default implementation of fastboot_set_reboot_flag that uses + "bcb" commands. + endif # FASTBOOT endmenu diff --git a/drivers/fastboot/fb_common.c b/drivers/fastboot/fb_common.c index 012a6288c187..77fe22e88f3d 100644 --- a/drivers/fastboot/fb_common.c +++ b/drivers/fastboot/fb_common.c @@ -88,6 +88,41 @@ void fastboot_okay(const char *reason, char *response) * which sets whatever flag your board specific Android bootloader flow * requires in order to re-enter the bootloader. */ +#if CONFIG_IS_ENABLED(FASTBOOT_USE_BCB_SET_REBOOT_FLAG) +int fastboot_set_reboot_flag(int reason) +{ + char cmd[32]; + + snprintf(cmd, sizeof(cmd), "bcb load %d misc", + CONFIG_FASTBOOT_FLASH_MMC_DEV); + + if (run_command(cmd, 0)) + return -ENODEV; + + switch (reason) { + case FASTBOOT_REBOOT_BOOTLOADER: + snprintf(cmd, sizeof(cmd), + "bcb set command bootonce-bootloader"); + break; + case FASTBOOT_REBOOT_FASTBOOTD: + snprintf(cmd, sizeof(cmd), "bcb set command boot-fastboot"); + break; + case FASTBOOT_REBOOT_RECOVERY: + snprintf(cmd, sizeof(cmd), "bcb set command boot-recovery"); + break; + default: + return -EINVAL; + } + + if (run_command(cmd, 0)) + return -ENOEXEC; + + if (run_command("bcb store", 0)) + return -EIO; + + return 0; +} +#else int __weak fastboot_set_reboot_flag(int reason) { if (reason != FASTBOOT_REBOOT_BOOTLOADER) @@ -95,6 +130,7 @@ int __weak fastboot_set_reboot_flag(int reason) return -ENOSYS; } +#endif /** * fastboot_get_progress_callback() - Return progress callback