From e85a5f856e7819eff2c4ba8da9490a03f5edd346 Mon Sep 17 00:00:00 2001 From: "Haoran.Wang" Date: Wed, 26 Feb 2020 08:45:13 +0800 Subject: [PATCH] MA-16457-2 support reboot-fastboot command in u-boot Android implement the userspace fastboot in Android Recovery. Follow Google's spec, added below 2 fastboot command support: * fastboot getvar is-userspace * fastboot reboot fastboot TEST: fastboot commands. Change-Id: Ib6047413be0a45b3c00626cdb8594809eb8a2b6b Signed-off-by: Haoran.Wang (cherry picked from commit 314bded076dfc3e544cc7094ce3f6c4c330be4dd) (cherry picked from commit 89e63a8f1b20dfe5633f4d854aeb6d712b3ccaa4) --- drivers/fastboot/fb_fsl/bcb.h | 9 ++++++ drivers/fastboot/fb_fsl/command.c | 33 ++++++++++++++++++++ drivers/fastboot/fb_fsl/fb_fsl_command.c | 38 ++++++++++++++++++++++++ drivers/fastboot/fb_fsl/fb_fsl_getvar.c | 7 +++-- drivers/usb/gadget/f_fastboot.c | 3 ++ include/fastboot.h | 3 ++ net/fastboot.c | 3 ++ 7 files changed, 94 insertions(+), 2 deletions(-) diff --git a/drivers/fastboot/fb_fsl/bcb.h b/drivers/fastboot/fb_fsl/bcb.h index af01c19201..2aca18eb9b 100644 --- a/drivers/fastboot/fb_fsl/bcb.h +++ b/drivers/fastboot/fb_fsl/bcb.h @@ -11,6 +11,7 @@ #define FASTBOOT_BCB_CMD "bootonce-bootloader" #ifdef CONFIG_ANDROID_RECOVERY #define RECOVERY_BCB_CMD "boot-recovery" +#define RECOVERY_FASTBOOT_ARG "recovery\n--fastboot" #endif /* keep same as bootable/recovery/bootloader.h */ struct bootloader_message { @@ -48,10 +49,18 @@ struct bootloader_message_ab { (u32)(&(((struct bootloader_message_ab *)0)->slot_suffix[BOOTCTRL_IDX])) #define MISC_COMMAND \ (u32)(uintptr_t)(&(((struct bootloader_message *)0)->command[MISC_COMMAND_IDX])) + +#ifdef CONFIG_ANDROID_RECOVERY +#define RECOVERY_OPTIONS\ + (u32)(uintptr_t)(&(((struct bootloader_message *)0)->recovery[0])) +#endif int bcb_rw_block(bool bread, char **ppblock, uint *pblksize, char *pblock_write, uint offset, uint size); int bcb_write_command(char *bcb_command); int bcb_read_command(char *command); +#ifdef CONFIG_ANDROID_RECOVERY +int bcb_write_recovery_opt(char *opts); +#endif #endif diff --git a/drivers/fastboot/fb_fsl/command.c b/drivers/fastboot/fb_fsl/command.c index 349a014ead..d3fb9f03df 100644 --- a/drivers/fastboot/fb_fsl/command.c +++ b/drivers/fastboot/fb_fsl/command.c @@ -59,3 +59,36 @@ int bcb_write_command(char *bcb_command) free(p_block); return 0; } + +#ifdef CONFIG_ANDROID_RECOVERY +int bcb_write_recovery_opt(char *opts) +{ + int ret = 0; + char *p_block = NULL; + uint offset_in_block = 0; + uint blk_size = 0; + + if (opts == NULL) + return -1; + + + ret = bcb_rw_block(true, &p_block, &blk_size, NULL, RECOVERY_OPTIONS, 32); + if (ret) { + printf("write_bootctl, bcb_rw_block read failed\n"); + return -1; + } + + offset_in_block = RECOVERY_OPTIONS%blk_size; + memcpy(p_block + offset_in_block, opts, 32); + + ret = bcb_rw_block(false, NULL, NULL, p_block, RECOVERY_OPTIONS, 32); + if (ret) { + free(p_block); + printf("write_bootctl, bcb_rw_block write failed\n"); + return -1; + } + + free(p_block); + return 0; +} +#endif diff --git a/drivers/fastboot/fb_fsl/fb_fsl_command.c b/drivers/fastboot/fb_fsl/fb_fsl_command.c index 771f624b4d..679757a0a6 100644 --- a/drivers/fastboot/fb_fsl/fb_fsl_command.c +++ b/drivers/fastboot/fb_fsl/fb_fsl_command.c @@ -72,6 +72,20 @@ static void enable_fastboot_command(void) #endif } +#ifdef CONFIG_ANDROID_RECOVERY +/* Write the recovery options with fastboot bootloader commands */ +static void enable_recovery_fastboot(void) +{ +#ifdef CONFIG_BCB_SUPPORT + char msg[32] = {0}; + strncpy(msg, RECOVERY_BCB_CMD, 31); + bcb_write_command(msg); + strncpy(msg, RECOVERY_FASTBOOT_ARG, 31); + bcb_write_recovery_opt(msg); +#endif +} +#endif + /* Get the Boot mode from BCB cmd or Key pressed */ static FbBootMode fastboot_get_bootmode(void) { @@ -176,6 +190,24 @@ static void reboot_bootloader(char *cmd_parameter, char *response) fastboot_okay(NULL, response); } +#ifdef CONFIG_ANDROID_RECOVERY +/** + * reboot_fastboot() - Sets reboot fastboot flag. + * + * @cmd_parameter: Pointer to command parameter + * @response: Pointer to fastboot response buffer + */ +static void reboot_fastboot(char *cmd_parameter, char *response) +{ + enable_recovery_fastboot(); + + if (fastboot_set_reboot_flag(FASTBOOT_REBOOT_REASON_FASTBOOTD)) + fastboot_fail("Cannot set reboot flag", response); + else + fastboot_okay(NULL, response); +} +#endif + static void upload(char *cmd_parameter, char *response) { if (!fastboot_bytes_received || fastboot_bytes_received > (EP_BUFFER_SIZE * 32)) { @@ -938,6 +970,12 @@ static const struct { .dispatch = download, }, #endif +#ifdef CONFIG_ANDROID_RECOVERY + [FASTBOOT_COMMAND_RECOVERY_FASTBOOT] = { + .command = "reboot-fastboot", + .dispatch = reboot_fastboot, + }, +#endif }; /** diff --git a/drivers/fastboot/fb_fsl/fb_fsl_getvar.c b/drivers/fastboot/fb_fsl/fb_fsl_getvar.c index c11b253e55..f4808f5fe7 100644 --- a/drivers/fastboot/fb_fsl/fb_fsl_getvar.c +++ b/drivers/fastboot/fb_fsl/fb_fsl_getvar.c @@ -48,9 +48,9 @@ #endif #if defined(CONFIG_ANDROID_THINGS_SUPPORT) && defined(CONFIG_ARCH_IMX8M) -#define FASTBOOT_COMMON_VAR_NUM 14 +#define FASTBOOT_COMMON_VAR_NUM 15 #else -#define FASTBOOT_COMMON_VAR_NUM 13 +#define FASTBOOT_COMMON_VAR_NUM 14 #endif #define FASTBOOT_VAR_YES "yes" @@ -71,6 +71,7 @@ char *fastboot_common_var[FASTBOOT_COMMON_VAR_NUM] = { "battery-voltage", "variant", "battery-soc-ok", + "is-userspace", #if defined(CONFIG_ANDROID_THINGS_SUPPORT) && defined(CONFIG_ARCH_IMX8M) "baseboard_id" #endif @@ -213,6 +214,8 @@ static int get_single_var(char *cmd, char *response) strncat(response, VARIANT_NAME, chars_left); } else if (!strcmp_l1("off-mode-charge", cmd)) { strncat(response, "1", chars_left); + } else if (!strcmp_l1("is-userspace", cmd)) { + strncat(response, FASTBOOT_VAR_NO, chars_left); } else if (!strcmp_l1("downloadsize", cmd) || !strcmp_l1("max-download-size", cmd)) { diff --git a/drivers/usb/gadget/f_fastboot.c b/drivers/usb/gadget/f_fastboot.c index cfd1f0b564..346573aff8 100644 --- a/drivers/usb/gadget/f_fastboot.c +++ b/drivers/usb/gadget/f_fastboot.c @@ -636,6 +636,9 @@ static void rx_handler_command(struct usb_ep *ep, struct usb_request *req) case FASTBOOT_COMMAND_REBOOT_BOOTLOADER: case FASTBOOT_COMMAND_REBOOT_FASTBOOTD: case FASTBOOT_COMMAND_REBOOT_RECOVERY: +#ifdef CONFIG_ANDROID_RECOVERY + case FASTBOOT_COMMAND_RECOVERY_FASTBOOT: +#endif fastboot_func->in_req->complete = compl_do_reset; break; #if CONFIG_IS_ENABLED(FASTBOOT_UUU_SUPPORT) diff --git a/include/fastboot.h b/include/fastboot.h index 5671cbab07..d2fce5b27f 100644 --- a/include/fastboot.h +++ b/include/fastboot.h @@ -61,6 +61,9 @@ enum { #ifdef CONFIG_AVB_ATX FASTBOOT_COMMAND_STAGE, #endif +#endif +#ifdef CONFIG_ANDROID_RECOVERY + FASTBOOT_COMMAND_RECOVERY_FASTBOOT, #endif FASTBOOT_COMMAND_COUNT }; diff --git a/net/fastboot.c b/net/fastboot.c index 7e7a601b9f..7284efe211 100644 --- a/net/fastboot.c +++ b/net/fastboot.c @@ -229,6 +229,9 @@ static void fastboot_send(struct fastboot_header header, char *fastboot_data, case FASTBOOT_COMMAND_REBOOT_BOOTLOADER: case FASTBOOT_COMMAND_REBOOT_FASTBOOTD: case FASTBOOT_COMMAND_REBOOT_RECOVERY: +#ifdef CONFIG_ANDROID_RECOVERY + case FASTBOOT_COMMAND_RECOVERY_FASTBOOT: +#endif do_reset(NULL, 0, 0, NULL); break; } -- 2.17.1