From patchwork Mon Jan 11 10:19:19 2021 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Heiko Schocher X-Patchwork-Id: 1424488 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=none (p=none dis=none) header.from=denx.de Authentication-Results: ozlabs.org; dkim=pass (2048-bit key; unprotected) header.d=denx.de header.i=@denx.de header.a=rsa-sha256 header.s=phobos-20191101 header.b=I/chhGap; 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 4DDqTJ1DpZz9sWt for ; Mon, 11 Jan 2021 21:19:52 +1100 (AEDT) Received: from h2850616.stratoserver.net (localhost [IPv6:::1]) by phobos.denx.de (Postfix) with ESMTP id 4EF76828DE; Mon, 11 Jan 2021 11:19:37 +0100 (CET) Authentication-Results: phobos.denx.de; dmarc=none (p=none dis=none) header.from=denx.de Authentication-Results: phobos.denx.de; spf=pass smtp.mailfrom=u-boot-bounces@lists.denx.de DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=denx.de; s=phobos-20191101; t=1610360377; bh=3UbXK3gVgK9maDw/oFQSgK7qaZvFJNUYfF9uonIURfs=; h=From:To:Cc:Subject:Date:List-Id:List-Unsubscribe:List-Archive: List-Post:List-Help:List-Subscribe:From; b=I/chhGapu/jzgISHDhlc/aCB9DBUeN8ty4pdsQGjEhm8v5+jR3j3SvVz+cEfKxQoc PJnFAyCfUwHOyarscr+hUoyGEyYpaul39Pp37Ze/Ejm4k4fuvT7EIEyiLVXJBsHpdS m9cYva9G20Ft+B0CKlGXJciwM9WW4okQoZ0u/OF0ZAXJcgf5b1oHu+9kPgLqDhJg42 pWlQmPKTieXWD4N8iALlJ6Fmwht58GCDSR1ofk+qgVajTQrXfjukZ9tbvrV/hYvbxl OHHzCcjiBnVN7hVNL4znLYxPSxxL2Rgf2TtJ5ikz9qeB3xIP+xVb2WmrdZ8fp3DCL3 FWQvljifYlBfQ== Received: by phobos.denx.de (Postfix, from userid 109) id 20692828ED; Mon, 11 Jan 2021 11:19:36 +0100 (CET) X-Spam-Checker-Version: SpamAssassin 3.4.2 (2018-09-13) on phobos.denx.de X-Spam-Level: X-Spam-Status: No, score=-2.6 required=5.0 tests=BAYES_00,RCVD_IN_DNSWL_LOW, RCVD_IN_MSPIKE_H3,RCVD_IN_MSPIKE_WL,SPF_HELO_NONE autolearn=ham autolearn_force=no version=3.4.2 Received: from mail-out.m-online.net (mail-out.m-online.net [212.18.0.10]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by phobos.denx.de (Postfix) with ESMTPS id 3DCBB828DB for ; Mon, 11 Jan 2021 11:19:32 +0100 (CET) Authentication-Results: phobos.denx.de; dmarc=none (p=none dis=none) header.from=denx.de Authentication-Results: phobos.denx.de; spf=none smtp.mailfrom=hs@denx.de Received: from frontend01.mail.m-online.net (unknown [192.168.8.182]) by mail-out.m-online.net (Postfix) with ESMTP id 4DDqSh0Lwnz1rvBT; Mon, 11 Jan 2021 11:19:32 +0100 (CET) Received: from localhost (dynscan1.mnet-online.de [192.168.6.70]) by mail.m-online.net (Postfix) with ESMTP id 4DDqSh07Cvz1qql0; Mon, 11 Jan 2021 11:19:31 +0100 (CET) Received: from mail.mnet-online.de ([192.168.8.182]) by localhost (dynscan1.mail.m-online.net [192.168.6.70]) (amavisd-new, port 10024) with ESMTP id lbr-hw8W41AJ; Mon, 11 Jan 2021 11:19:29 +0100 (CET) X-Auth-Info: ZqfOQIQyMmagSTddy4C4LE00BJz98TGwyvRWCiJIlOI= Received: from mail-internal.denx.de (p578adb1c.dip0.t-ipconnect.de [87.138.219.28]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by mail.mnet-online.de (Postfix) with ESMTPSA; Mon, 11 Jan 2021 11:19:29 +0100 (CET) Received: from pollux.denx.de (pollux [192.168.1.1]) by mail-internal.denx.de (Postfix) with ESMTP id B12B0182FE0; Mon, 11 Jan 2021 11:19:24 +0100 (CET) Received: by pollux.denx.de (Postfix, from userid 515) id 8F3A51A9864; Mon, 11 Jan 2021 11:19:24 +0100 (CET) From: Heiko Schocher To: u-boot@lists.denx.de Cc: Heiko Schocher , Filip Brozovic , Lokesh Vutla , Lukasz Majewski , Marek Vasut , Roman Kovalivskyi , Roman Stratiienko , Sam Protsenko , Simon Glass , mingming lee Subject: [PATCH] fastboot: add UUU command UCmd and ACmd support Date: Mon, 11 Jan 2021 11:19:19 +0100 Message-Id: <20210111101919.228555-1-hs@denx.de> X-Mailer: git-send-email 2.25.4 MIME-Version: 1.0 X-BeenThere: u-boot@lists.denx.de X-Mailman-Version: 2.1.34 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.3 at phobos.denx.de X-Virus-Status: Clean add support for the UUU commands ACmd and UCmd. Enable them through the Kconfig option CONFIG_FASTBOOT_UUU_SUPPORT base was commit in NXP kernel 9b149c2a2882: ("MLK-18591-3 android: Add FSL android fastboot support") and ported it to current mainline. Tested this patch on imx6ul based board. Signed-off-by: Heiko Schocher Reviewed-by: Simon Glass --- azure build: https://dev.azure.com/hs0298/hs/_build/results?buildId=57&view=results version uuu tool used for tests: commit 3870fb781b35: ("fastboot: default to logical-block-size 4096") doc/android/fastboot-protocol.rst | 5 +++ doc/android/fastboot.rst | 2 + drivers/fastboot/Kconfig | 7 ++++ drivers/fastboot/fb_command.c | 62 +++++++++++++++++++++++++++++++ drivers/usb/gadget/f_fastboot.c | 17 +++++++++ include/fastboot.h | 7 ++++ 6 files changed, 100 insertions(+) diff --git a/doc/android/fastboot-protocol.rst b/doc/android/fastboot-protocol.rst index e723659e49c..e8cbd7f24ea 100644 --- a/doc/android/fastboot-protocol.rst +++ b/doc/android/fastboot-protocol.rst @@ -144,6 +144,11 @@ Command Reference "powerdown" Power off the device. + "ucmd" execute any bootloader command and wait until it + finishs. + + "acmd" execute any bootloader command, do not wait. + Client Variables ---------------- diff --git a/doc/android/fastboot.rst b/doc/android/fastboot.rst index 2877c3cbaaa..b58d1b5b31a 100644 --- a/doc/android/fastboot.rst +++ b/doc/android/fastboot.rst @@ -19,6 +19,8 @@ The current implementation supports the following standard commands: - ``reboot`` - ``reboot-bootloader`` - ``set_active`` (only a stub implementation which always succeeds) +- ``ucmd`` (if enabled) +- ``acmd`` (if enabled) The following OEM commands are supported (if enabled): diff --git a/drivers/fastboot/Kconfig b/drivers/fastboot/Kconfig index 4352ba67a71..b1f8cd74a15 100644 --- a/drivers/fastboot/Kconfig +++ b/drivers/fastboot/Kconfig @@ -72,6 +72,13 @@ config FASTBOOT_FLASH the downloaded image to a non-volatile storage device. Define this to enable the "fastboot flash" command. +config FASTBOOT_UUU_SUPPORT + bool "Enable FASTBOOT i.MX UUU special command" + default y if ARCH_MX7 || ARCH_MX6 || ARCH_IMX8 || ARCH_IMX8M || ARCH_MX7ULP + select FSL_FASTBOOT + help + The fastboot protocol includes "UCmd" command and "ACmd" command + choice prompt "Flash provider for FASTBOOT" depends on FASTBOOT_FLASH diff --git a/drivers/fastboot/fb_command.c b/drivers/fastboot/fb_command.c index d3c578672dc..31a47e46386 100644 --- a/drivers/fastboot/fb_command.c +++ b/drivers/fastboot/fb_command.c @@ -43,6 +43,11 @@ static void reboot_recovery(char *, char *); static void oem_format(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; void (*dispatch)(char *cmd_parameter, char *response); @@ -99,6 +104,16 @@ static const struct { .dispatch = oem_format, }, #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 }; /** @@ -309,6 +324,53 @@ 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; + } + + strcpy(g_a_cmd_buff, cmd_parameter); + fastboot_okay(NULL, response); +} +#endif + /** * reboot_bootloader() - Sets reboot bootloader flag. * diff --git a/drivers/usb/gadget/f_fastboot.c b/drivers/usb/gadget/f_fastboot.c index d1d087e12b2..bf52d2505f4 100644 --- a/drivers/usb/gadget/f_fastboot.c +++ b/drivers/usb/gadget/f_fastboot.c @@ -419,6 +419,18 @@ static void do_bootm_on_complete(struct usb_ep *ep, struct usb_request *req) do_exit_on_complete(ep, req); } +#if CONFIG_IS_ENABLED(FASTBOOT_UUU_SUPPORT) +static void do_acmd_complete(struct usb_ep *ep, struct usb_request *req) +{ + /* When usb dequeue complete will be called + * Need status value before call run_command. + * otherwise, host can't get last message. + */ + if (req->status == 0) + fastboot_acmd_complete(); +} +#endif + static void rx_handler_command(struct usb_ep *ep, struct usb_request *req) { char *cmdbuf = req->buf; @@ -457,6 +469,11 @@ static void rx_handler_command(struct usb_ep *ep, struct usb_request *req) case FASTBOOT_COMMAND_REBOOT_RECOVERY: fastboot_func->in_req->complete = compl_do_reset; break; +#if CONFIG_IS_ENABLED(FASTBOOT_UUU_SUPPORT) + case FASTBOOT_COMMAND_ACMD: + fastboot_func->in_req->complete = do_acmd_complete; + break; +#endif } } diff --git a/include/fastboot.h b/include/fastboot.h index 8e9ee80907d..ef8cd842bb3 100644 --- a/include/fastboot.h +++ b/include/fastboot.h @@ -38,6 +38,10 @@ enum { #if CONFIG_IS_ENABLED(FASTBOOT_CMD_OEM_FORMAT) FASTBOOT_COMMAND_OEM_FORMAT, #endif +#if CONFIG_IS_ENABLED(FASTBOOT_UUU_SUPPORT) + FASTBOOT_COMMAND_ACMD, + FASTBOOT_COMMAND_UCMD, +#endif FASTBOOT_COMMAND_COUNT }; @@ -172,4 +176,7 @@ void fastboot_data_download(const void *fastboot_data, */ void fastboot_data_complete(char *response); +#if CONFIG_IS_ENABLED(FASTBOOT_UUU_SUPPORT) +void fastboot_acmd_complete(void); +#endif #endif /* _FASTBOOT_H_ */