From patchwork Wed May 27 08:50:07 2020 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Roman Kovalivskyi X-Patchwork-Id: 1298805 X-Patchwork-Delegate: lukma@denx.de Return-Path: X-Original-To: incoming@patchwork.ozlabs.org Delivered-To: patchwork-incoming@bilbo.ozlabs.org Authentication-Results: ozlabs.org; spf=pass (sender SPF authorized) smtp.mailfrom=lists.denx.de (client-ip=2a01:238:438b:c500:173d:9f52:ddab:ee01; helo=phobos.denx.de; envelope-from=u-boot-bounces@lists.denx.de; receiver=) Authentication-Results: ozlabs.org; dmarc=pass (p=reject dis=none) header.from=globallogic.com Authentication-Results: ozlabs.org; dkim=pass (2048-bit key; unprotected) header.d=globallogic.com header.i=@globallogic.com header.a=rsa-sha256 header.s=google header.b=hSAXf38R; dkim-atps=neutral Received: from phobos.denx.de (phobos.denx.de [IPv6:2a01:238:438b:c500:173d:9f52:ddab:ee01]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature RSA-PSS (4096 bits) server-digest SHA256) (No client certificate requested) by ozlabs.org (Postfix) with ESMTPS id 49X7Wk0X8Qz9sSW for ; Wed, 27 May 2020 21:14:26 +1000 (AEST) Received: from h2850616.stratoserver.net (localhost [IPv6:::1]) by phobos.denx.de (Postfix) with ESMTP id 75E7B815F1; Wed, 27 May 2020 13:14:08 +0200 (CEST) Authentication-Results: phobos.denx.de; dmarc=pass (p=reject dis=none) header.from=globallogic.com Authentication-Results: phobos.denx.de; spf=pass smtp.mailfrom=u-boot-bounces@lists.denx.de Authentication-Results: phobos.denx.de; dkim=pass (2048-bit key; unprotected) header.d=globallogic.com header.i=@globallogic.com header.b="hSAXf38R"; dkim-atps=neutral Received: by phobos.denx.de (Postfix, from userid 109) id EB6D2812EA; Wed, 27 May 2020 10:50:23 +0200 (CEST) X-Spam-Checker-Version: SpamAssassin 3.4.2 (2018-09-13) on phobos.denx.de X-Spam-Level: X-Spam-Status: No, score=-2.0 required=5.0 tests=BAYES_00,DKIM_SIGNED, DKIM_VALID,DKIM_VALID_AU,SPF_HELO_NONE,URIBL_BLOCKED autolearn=ham autolearn_force=no version=3.4.2 Received: from mail-lj1-x241.google.com (mail-lj1-x241.google.com [IPv6:2a00:1450:4864:20::241]) (using TLSv1.3 with cipher TLS_AES_128_GCM_SHA256 (128/128 bits)) (No client certificate requested) by phobos.denx.de (Postfix) with ESMTPS id B6D9480929 for ; Wed, 27 May 2020 10:50:19 +0200 (CEST) Authentication-Results: phobos.denx.de; dmarc=pass (p=reject dis=none) header.from=globallogic.com Authentication-Results: phobos.denx.de; spf=pass smtp.mailfrom=roman.kovalivskyi@globallogic.com Received: by mail-lj1-x241.google.com with SMTP id k5so27886242lji.11 for ; Wed, 27 May 2020 01:50:19 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=globallogic.com; s=google; h=from:to:cc:subject:date:message-id:in-reply-to:references :in-reply-to:references; bh=Z1wbRXLpv7jpATDg52Bh2kKH/DgFr9kP/voiKmY+y8M=; b=hSAXf38RAuBcYyrGa33NXNjCPM1u6hfs8mh7avq4DxIS6Tk4fLR8tNFXaWC6nplWNt IKgaR97IyPNesgY+kLqbJpJxbuKPrO+ZhPZQkRtP9yo/mBPQ4zWc3vev3ZxdQyx6GMxm +N+hk6t+aG9SL2rXxo9Y6m/8/8jnFsT1vcI71tMuOJ6ggiVqLQpMcmXE08mlEDkgQdnY u6nvNL6KDcUF1yN0gyv9Yzi7VRdmNTQo2k4+qec3YmMy+qw3g9UrxXrvO9eqbXzDoiaS rtk/w/AF+davgo0wCh2T4vm7KrH3sSnzUfnlxCX4OlfqwHzKE6zCT1X5dhGyeibY1+Su YCVw== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:from:to:cc:subject:date:message-id:in-reply-to :references:in-reply-to:references; bh=Z1wbRXLpv7jpATDg52Bh2kKH/DgFr9kP/voiKmY+y8M=; b=kL4QxtGLWFrTyiUUwEys7ScQ1vpP4JKjy98bwHGYm69kUWjQeNEeYtzU/wqvVw7Hq2 88mmyteMZYQfSWHmaSkbJCsrfIoK8JPrqwat9pRzHGMx/sCqAkSEgpquMmvHaCTs/DpO UdzSMaSUTt7SwHPrwv+yKlG/WR5hi/2cyMNrDgebYzzXhKbxo0nZy1hZj0H/J/bso2+c pEZu3NtM0d7N0xEETgOUV1SXHlnG30fdrUtsXZKrYF/Nc2faB1KFy7G5fWdLHTVyYDB7 kc6yvBIJL4rRyidAHu+qcPDzMjdL8PP5Y1Z0ey6uiym9MDezlGjho7soL78ZMMCm028b TRZw== X-Gm-Message-State: AOAM530RJ0AVnenahe4h/roAJOSZE9n0iOsPCH1FYcLVPT9X3uRIF/HO QaD5jeFkrdRIYAC3qwP57j9O/9HUibM= X-Google-Smtp-Source: ABdhPJyS0gU8Rj54Da8BM2wb7qUZcbS04PZKnCbB2Sppul5XrJ14M66IKIxTWHbte30w0d6WJXpO6A== X-Received: by 2002:a2e:a37b:: with SMTP id i27mr2694308ljn.467.1590569418832; Wed, 27 May 2020 01:50:18 -0700 (PDT) Received: from localhost.localdomain ([159.224.5.60]) by smtp.googlemail.com with ESMTPSA id y28sm559955ljn.4.2020.05.27.01.50.17 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Wed, 27 May 2020 01:50:18 -0700 (PDT) From: Roman Kovalivskyi To: u-boot@lists.denx.de Cc: Roman Stratiienko , Joe Hershberger , Roman Kovalivskyi , Simon Glass , Marek Vasut , Lukasz Majewski , Eugeniu Rosca Subject: [PATCH 1/1] fastboot: add support for 'reboot fastboot' command Date: Wed, 27 May 2020 11:50:07 +0300 Message-Id: <85bb97d3704b4579963f9200a0ddd4dbae7b84ab.1590539734.git.roman.kovalivskyi@globallogic.com> X-Mailer: git-send-email 2.17.1 In-Reply-To: References: In-Reply-To: References: X-Mailman-Approved-At: Wed, 27 May 2020 13:14:05 +0200 X-BeenThere: u-boot@lists.denx.de X-Mailman-Version: 2.1.30rc1 Precedence: list List-Id: U-Boot discussion List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: u-boot-bounces@lists.denx.de Sender: "U-Boot" X-Virus-Scanned: clamav-milter 0.102.2 at phobos.denx.de X-Virus-Status: Clean From: Roman Stratiienko Android 10 adds support for dynamic partitions and in order to support them userspace fastboot must be used[1]. New tool fastbootd is included into recovery image. Userspace fastboot works from recovery and is launched if: 1) - Dynamic partitioning is enabled 2) - Boot control block has 'boot-fastboot' value into command field The bootloader is expected to load and boot into the recovery image upon seeing boot-fastboot in the BCB command. Recovery then parses the BCB message and switches to fastbootd mode[2]. Please note that boot script is expected to handle 'boot-fastboot' command in BCB and load into recovery mode. Bootloader must support 'reboot fastboot' command which should reboot device into userspace fastboot to accomodate those changes[3]. [1] - https://source.android.com/devices/bootloader/fastbootd [2] - https://source.android.com/devices/bootloader/fastbootd#unified_fastboot_and_recovery [3] - https://source.android.com/devices/bootloader/fastbootd#modifications_to_the_bootloader Signed-off-by: Roman Kovalivskyi Signed-off-by: Roman Stratiienko Change-Id: I9d2bdc9a6f6f31ea98572fe155e1cc8341e9af76 --- drivers/fastboot/fb_command.c | 42 +++++++++++++++++++++++++++++++++ drivers/fastboot/fb_common.c | 31 ++++++++++++++++++++++++ drivers/usb/gadget/f_fastboot.c | 2 ++ include/fastboot.h | 9 +++++++ 4 files changed, 84 insertions(+) diff --git a/drivers/fastboot/fb_command.c b/drivers/fastboot/fb_command.c index 49f6a61c3745..3616133b880e 100644 --- a/drivers/fastboot/fb_command.c +++ b/drivers/fastboot/fb_command.c @@ -37,6 +37,8 @@ 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 @@ -79,6 +81,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 @@ -307,12 +317,44 @@ static void erase(char *cmd_parameter, char *response) */ static void reboot_bootloader(char *cmd_parameter, char *response) { +#if CONFIG_IS_ENABLED(CMD_BCB) + if (fastboot_set_flag("bootonce-bootloader")) +#else if (fastboot_set_reboot_flag()) +#endif 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_flag("boot-fastboot")) + 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_flag("boot-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 diff --git a/drivers/fastboot/fb_common.c b/drivers/fastboot/fb_common.c index c3735a44af74..b6401640ad06 100644 --- a/drivers/fastboot/fb_common.c +++ b/drivers/fastboot/fb_common.c @@ -93,6 +93,37 @@ int __weak fastboot_set_reboot_flag(void) return -ENOSYS; } +/** + * fastboot_set_flag() - Set flag to indicate reboot-recovery + * + * Set flag which indicates that we should reboot into the recovery + * following the reboot that fastboot executes after this function. + */ +int fastboot_set_flag(const char *command) +{ +#if CONFIG_IS_ENABLED(CMD_BCB) + char cmd[32]; + + snprintf(cmd, sizeof(cmd), "bcb load %d misc", + CONFIG_FASTBOOT_FLASH_MMC_DEV); + + if (run_command(cmd, 0)) + return -ENODEV; + + snprintf(cmd, sizeof(cmd), "bcb set command %s", command); + + if (run_command(cmd, 0)) + return -ENOEXEC; + + if (run_command("bcb store", 0)) + return -EIO; + + return 0; +#else + return -ENOSYS; +#endif +} + /** * fastboot_get_progress_callback() - Return progress callback * diff --git a/drivers/usb/gadget/f_fastboot.c b/drivers/usb/gadget/f_fastboot.c index 384c0f6f6e27..30f7a52087fc 100644 --- a/drivers/usb/gadget/f_fastboot.c +++ b/drivers/usb/gadget/f_fastboot.c @@ -455,6 +455,8 @@ static void rx_handler_command(struct usb_ep *ep, struct usb_request *req) case FASTBOOT_COMMAND_REBOOT: case FASTBOOT_COMMAND_REBOOT_BOOTLOADER: + case FASTBOOT_COMMAND_REBOOT_FASTBOOTD: + case FASTBOOT_COMMAND_REBOOT_RECOVERY: fastboot_func->in_req->complete = compl_do_reset; break; } diff --git a/include/fastboot.h b/include/fastboot.h index 1933b1d98e3b..8fd2a9e49d0f 100644 --- a/include/fastboot.h +++ b/include/fastboot.h @@ -32,6 +32,8 @@ enum { FASTBOOT_COMMAND_CONTINUE, FASTBOOT_COMMAND_REBOOT, FASTBOOT_COMMAND_REBOOT_BOOTLOADER, + FASTBOOT_COMMAND_REBOOT_FASTBOOTD, + FASTBOOT_COMMAND_REBOOT_RECOVERY, FASTBOOT_COMMAND_SET_ACTIVE, #if CONFIG_IS_ENABLED(FASTBOOT_CMD_OEM_FORMAT) FASTBOOT_COMMAND_OEM_FORMAT, @@ -79,6 +81,13 @@ void fastboot_okay(const char *reason, char *response); */ int fastboot_set_reboot_flag(void); +/** + * fastboot_set_flag() - Set flag to indicate reboot-fastboot + * + * Set flag which indicates that system should reboot into specified mode. + */ +int fastboot_set_flag(const char *command); + /** * fastboot_set_progress_callback() - set progress callback *