From patchwork Wed Apr 12 18:49:31 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Patchwork-Submitter: Dmitrii Merkurev X-Patchwork-Id: 1768517 X-Patchwork-Delegate: rfried.dev@gmail.com Return-Path: X-Original-To: incoming@patchwork.ozlabs.org Delivered-To: patchwork-incoming@legolas.ozlabs.org Authentication-Results: legolas.ozlabs.org; spf=pass (sender SPF authorized) smtp.mailfrom=lists.denx.de (client-ip=85.214.62.61; helo=phobos.denx.de; envelope-from=u-boot-bounces@lists.denx.de; receiver=) Authentication-Results: legolas.ozlabs.org; dkim=pass (2048-bit key; unprotected) header.d=google.com header.i=@google.com header.a=rsa-sha256 header.s=20221208 header.b=p6YQjcrC; dkim-atps=neutral Received: from phobos.denx.de (phobos.denx.de [85.214.62.61]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature ECDSA (P-384)) (No client certificate requested) by legolas.ozlabs.org (Postfix) with ESMTPS id 4Py2jg1Mbcz1yZZ for ; Fri, 14 Apr 2023 00:57:11 +1000 (AEST) Received: from h2850616.stratoserver.net (localhost [IPv6:::1]) by phobos.denx.de (Postfix) with ESMTP id B22CB85C52; Thu, 13 Apr 2023 16:56:45 +0200 (CEST) Authentication-Results: phobos.denx.de; dmarc=pass (p=reject dis=none) header.from=google.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=google.com header.i=@google.com header.b="p6YQjcrC"; dkim-atps=neutral Received: by phobos.denx.de (Postfix, from userid 109) id 1CCAF83741; Wed, 12 Apr 2023 20:49:51 +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=-9.6 required=5.0 tests=BAYES_00,DKIMWL_WL_MED, DKIM_SIGNED,DKIM_VALID,DKIM_VALID_AU,DKIM_VALID_EF,SPF_HELO_NONE, SPF_PASS,USER_IN_DEF_DKIM_WL autolearn=ham autolearn_force=no version=3.4.2 Received: from mail-ej1-x64a.google.com (mail-ej1-x64a.google.com [IPv6:2a00:1450:4864:20::64a]) (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 BBED185FBB for ; Wed, 12 Apr 2023 20:49:47 +0200 (CEST) Authentication-Results: phobos.denx.de; dmarc=pass (p=reject dis=none) header.from=google.com Authentication-Results: phobos.denx.de; spf=pass smtp.mailfrom=3S_02ZAkKBkopuy03uzzAs00sxq.o0y6-n005xu454.pqz9.pq@flex--dimorinny.bounces.google.com Received: by mail-ej1-x64a.google.com with SMTP id vo2-20020a170907a80200b00949175b0b70so6381389ejc.9 for ; Wed, 12 Apr 2023 11:49:47 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=20221208; t=1681325387; x=1683917387; h=content-transfer-encoding:cc:to:from:subject:message-id:references :mime-version:in-reply-to:date:from:to:cc:subject:date:message-id :reply-to; bh=ROWg/pZbxbBKGoEuTpFW2PVq9vqk4qvwp90wYVI2bJs=; b=p6YQjcrC9kfDFKh4InalREwVDLtX13OGDI2mIer0IHywHUDdKZB82gIA6ZdKBUwQph ERzVg8AwW/1TyiPc2VjquBQ64sv2xD7TUnWfaLE+suc5UVG1uDWA+ChBTvcUUG8jI0cP D4722MLrQ5+svC/VNG6GJDt9SjCrfXvBMEGb8zr2mjVwWh5rZSZ2CE6pWxfo7qhi8WU3 kSpw5n4Bg1FlnHdbkf0enmleOZIYWkckGMbjcXbe4pfWYB2g9Lkk+Bsk9UfZ4byGbVSH FSLceXmuXQ0BlaYG8gJkVJkdg8PKAxrekD9LcB3vHjykOQXIY2zFAEQBEiQGbOllqT92 gAfQ== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20221208; t=1681325387; x=1683917387; h=content-transfer-encoding:cc:to:from:subject:message-id:references :mime-version:in-reply-to:date:x-gm-message-state:from:to:cc:subject :date:message-id:reply-to; bh=ROWg/pZbxbBKGoEuTpFW2PVq9vqk4qvwp90wYVI2bJs=; b=TwqyyW+ttuql+0o3/7GeFR2jq9F7l2nVgoAuwwdgzCW2Cpr5FHrhV8NSnJP1B9QUUh mSX5C2WYoFkTgcFeSCSisSpHFN2xiCe0PJYPTocAHa/YMo+BRGZ4jmlhIV/+KOwy6A7v UvjRZVk7q5ctZTs3Aeqke2s3fuPkMjX2DGi82sbJ4d+bzvCwq7ZngOjpXnYlxitaOxvk qT/Sd6quTQ+brt+r/6XroikRVt1SdBe3PBtkSrVXtpcSwPKvGqlpPdOKxBZ1g9yOyw1Q rJCtQacEn5q+PWoaq4nVMO+PRTmW9f9SQWzOMuFiJlXsaF6cInEDl+083oZTB6Emhbla y/dw== X-Gm-Message-State: AAQBX9cOj9mNz4Pj2ILrtGk2PKmXSL9C550RRH/KSrQlVwa81Ic2xqPx o46KrV9u/GH72kbGhwZ6yvoll5dj3lDE6rqqeSqWQmjjF0rs0VEjLiXzT8SC3nrKY38uqTUs03U Yhu/sFCllKS+kBSKtAQvrkeHdxvQq/lGem1U/J7/m+SzClHp1scDacu9MnxL/y7hcpwQ= X-Google-Smtp-Source: AKy350YhuCREbIsf2pJtFuIeCtGZkqqD0kC4GOtQqcN5q+2S90Zis3rwKSxlFewjgR/FDCiSac2wqOBQtFUoXMo= X-Received: from dimorinny0.lon.corp.google.com ([2a00:79e0:d:209:7766:76f9:f832:5b94]) (user=dimorinny job=sendgmr) by 2002:a17:906:f2ce:b0:94e:2d:e94f with SMTP id gz14-20020a170906f2ce00b0094e002de94fmr1840894ejb.8.1681325387269; Wed, 12 Apr 2023 11:49:47 -0700 (PDT) Date: Wed, 12 Apr 2023 19:49:31 +0100 In-Reply-To: <20230412184931.1422789-1-dimorinny@google.com> Mime-Version: 1.0 References: <20230412184931.1422789-1-dimorinny@google.com> X-Mailer: git-send-email 2.40.0.634.g4ca3ef3211-goog Message-ID: <20230412184931.1422789-3-dimorinny@google.com> Subject: [PATCH v2 3/3] net: share fastboot boot handle logic between transports From: Dmitrii Merkurev To: u-boot@lists.denx.de Cc: Dmitrii Merkurev , Ying-Chun Liu , Simon Glass , Ramon Fried X-Mailman-Approved-At: Thu, 13 Apr 2023 16:56:35 +0200 X-BeenThere: u-boot@lists.denx.de X-Mailman-Version: 2.1.39 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.103.8 at phobos.denx.de X-Virus-Status: Clean Introduce reboot, boot and continue commands support to TCP fastboot by moving existing UDP logic into the common module. Signed-off-by: Dmitrii Merkurev Cc: Ying-Chun Liu (PaulLiu) Cc: Simon Glass Сс: Joe Hershberger Сс: Ramon Fried Reviewed-by: Simon Glass Reviewed-by: Ramon Fried Reviewed-by: Simon Glass --- drivers/fastboot/fb_common.c | 32 ++++++++++++++++++++++++++++++++ include/fastboot.h | 9 +++++++++ net/fastboot_tcp.c | 5 ++++- net/fastboot_udp.c | 29 +---------------------------- 4 files changed, 46 insertions(+), 29 deletions(-) diff --git a/drivers/fastboot/fb_common.c b/drivers/fastboot/fb_common.c index dde3cda78f..621146bc6b 100644 --- a/drivers/fastboot/fb_common.c +++ b/drivers/fastboot/fb_common.c @@ -15,6 +15,7 @@ #include #include #include +#include /** * fastboot_buf_addr - base address of the fastboot download buffer @@ -155,6 +156,37 @@ void fastboot_boot(void) } } +/** + * fastboot_handle_boot() - Shared implementation of system reaction to + * fastboot commands + * + * Making desceisions about device boot state (stay in fastboot, reboot + * to bootloader, reboot to OS, etc). + */ +void fastboot_handle_boot(int command, bool success) +{ + if (!success) + return; + + switch (command) { + case FASTBOOT_COMMAND_BOOT: + fastboot_boot(); + net_set_state(NETLOOP_SUCCESS); + break; + + case FASTBOOT_COMMAND_CONTINUE: + net_set_state(NETLOOP_SUCCESS); + break; + + case FASTBOOT_COMMAND_REBOOT: + case FASTBOOT_COMMAND_REBOOT_BOOTLOADER: + case FASTBOOT_COMMAND_REBOOT_FASTBOOTD: + case FASTBOOT_COMMAND_REBOOT_RECOVERY: + do_reset(NULL, 0, 0, NULL); + break; + } +} + /** * fastboot_set_progress_callback() - set progress callback * diff --git a/include/fastboot.h b/include/fastboot.h index 07f4c8fa71..296451f89d 100644 --- a/include/fastboot.h +++ b/include/fastboot.h @@ -123,6 +123,15 @@ void fastboot_init(void *buf_addr, u32 buf_size); */ void fastboot_boot(void); +/** + * fastboot_handle_boot() - Shared implementation of system reaction to + * fastboot commands + * + * Making desceisions about device boot state (stay in fastboot, reboot + * to bootloader, reboot to OS, etc). + */ +void fastboot_handle_boot(int command, bool success); + /** * fastboot_handle_command() - Handle fastboot command * diff --git a/net/fastboot_tcp.c b/net/fastboot_tcp.c index b5613b6aa2..2eb52ea256 100644 --- a/net/fastboot_tcp.c +++ b/net/fastboot_tcp.c @@ -73,6 +73,7 @@ static void fastboot_tcp_handler_ipv4(uchar *pkt, u16 dport, u32 tcp_seq_num, u32 tcp_ack_num, u8 action, unsigned int len) { + int fastboot_command_id; u64 command_size; u8 tcp_fin = action & TCP_FIN; u8 tcp_push = action & TCP_PUSH; @@ -115,8 +116,10 @@ static void fastboot_tcp_handler_ipv4(uchar *pkt, u16 dport, break; } strlcpy(command, pkt, len + 1); - fastboot_handle_command(command, response); + fastboot_command_id = fastboot_handle_command(command, response); fastboot_tcp_send_message(response, strlen(response)); + fastboot_handle_boot(fastboot_command_id, + strncmp("OKAY", response, 4) == 0); } break; case FASTBOOT_DISCONNECTING: diff --git a/net/fastboot_udp.c b/net/fastboot_udp.c index 27e779d8e0..389a5b45f5 100644 --- a/net/fastboot_udp.c +++ b/net/fastboot_udp.c @@ -209,39 +209,12 @@ static void fastboot_send(struct fastboot_header header, char *fastboot_data, net_send_udp_packet(net_server_ethaddr, fastboot_remote_ip, fastboot_remote_port, fastboot_our_port, len); - /* Continue boot process after sending response */ - if (!strncmp("OKAY", response, 4)) { - switch (cmd) { - case FASTBOOT_COMMAND_BOOT: - boot_downloaded_image(); - break; - - case FASTBOOT_COMMAND_CONTINUE: - net_set_state(NETLOOP_SUCCESS); - break; - - case FASTBOOT_COMMAND_REBOOT: - case FASTBOOT_COMMAND_REBOOT_BOOTLOADER: - case FASTBOOT_COMMAND_REBOOT_FASTBOOTD: - case FASTBOOT_COMMAND_REBOOT_RECOVERY: - do_reset(NULL, 0, 0, NULL); - break; - } - } + fastboot_handle_boot(cmd, strncmp("OKAY", response, 4) == 0); if (!strncmp("OKAY", response, 4) || !strncmp("FAIL", response, 4)) cmd = -1; } -/** - * boot_downloaded_image() - Boots into downloaded image. - */ -static void boot_downloaded_image(void) -{ - fastboot_boot(); - net_set_state(NETLOOP_SUCCESS); -} - /** * fastboot_handler() - Incoming UDP packet handler. *