Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from phobos.denx.de (phobos.denx.de [85.214.62.61]) (using TLSv1.2 with cipher ECDHE-RSA-AES128-GCM-SHA256 (128/128 bits)) (No client certificate requested) by smtp.lore.kernel.org (Postfix) with ESMTPS id 6464DC761A6 for ; Tue, 28 Mar 2023 21:08:53 +0000 (UTC) Received: from h2850616.stratoserver.net (localhost [IPv6:::1]) by phobos.denx.de (Postfix) with ESMTP id C0BD485D13; Tue, 28 Mar 2023 23:07:48 +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="TW9TaMCs"; dkim-atps=neutral Received: by phobos.denx.de (Postfix, from userid 109) id 80F0185CB1; Tue, 28 Mar 2023 22:31:29 +0200 (CEST) Received: from mail-ed1-x549.google.com (mail-ed1-x549.google.com [IPv6:2a00:1450:4864:20::549]) (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 EE32285AEC for ; Tue, 28 Mar 2023 22:31:26 +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=3nk4jZAkKBu8UZdfiZeepXffXcV.Tfdl-SffkcZjkj.UVeo.UV@flex--dimorinny.bounces.google.com Received: by mail-ed1-x549.google.com with SMTP id k30-20020a50ce5e000000b00500544ebfb1so18942586edj.7 for ; Tue, 28 Mar 2023 13:31:26 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=20210112; t=1680035486; 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=2WmJTWCbq3ieawJtUzB7RlhmLPLN6bJGDHW8BhYG4fM=; b=TW9TaMCsWKgK4wTOw0mZiEFasn+NqKmoAhsWHBaBDLuiOYLyFJ7B/PpjpqLhpZ2Yv0 M6H5IRoNfCHVB0+0uqAWACenNRgA/nH0L25BRVPYl0a8Ru8/FuWlZN3jikJ/LklIrLUd oWsNIuZ6uzoy0wBTEyHylgWhntHQ7Jz+hDl8maHuljLzW6TLI91jslT0++ODOvuc6B+9 uhteUki4e2RHSx0ztHaXh3cGxu32jSFpfIrotjDKSVVVX8Epg+Vrf42cTlfZhQCJCUGW xzCt9PNXIF99bJtRIdFfRynPQx5kcEiJv0xC+7Xg8Hnz1yE8AsjO5+95T6aRsn/6fsiC vEBg== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; t=1680035486; 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=2WmJTWCbq3ieawJtUzB7RlhmLPLN6bJGDHW8BhYG4fM=; b=F//thN9GGv/mUQvhCePmyH5GAIQk1w2/OyilZkCo6WFHrfOebcYbXv1XqtX4AhuRTL UFNR/f3seAY0dS7rMxKpnpTkBonM1MU3dqCr7I6vMBB9D1HBjOTiGZHt6PnWCXVB9pg0 1FLM00ozH6d6JgFJfkm37O0FPus3s9Hp0NMnnstCWKqRoEMzqhxPsltEZ3urIpZee455 B7V8JiPNF4MiN9MRtUruPtelgerHzZQ86Opazbr0g4UrvgTvYyY7a3b4xH3v3Tl4SzAx cw4JaJpq6Tsnm8drsLSrIYTdhLkprEeICjuEe7X8johBmBTXRiCgN8fIxV96KplnVEls PL3Q== X-Gm-Message-State: AAQBX9dJVLVZf1IdbOvsak5k5T+NKakShAcdZ0zNGf3bACLRlDH9tDM/ HfNojUGmUPkmsT7alLNPNe2PR0bo5awEZXJ8Z4rQXFhYTLfR72CnzzzDsfGB+/zuIc1PV3WmLbP GGFh8j9AiFM1ORRv6HZla59kqf1qNTzgIgxr52tYmn4esxDfM/fLp4tUm4z6SJAI96uU= X-Google-Smtp-Source: AKy350ZXk1e8B8WIAx8cXPSBqdBiJyqTf5+6cjgHD0dqpwSaXs4xe4VEzv1ekkj7PejbN100HpPzI6STdRq4vUM= X-Received: from dimorinny0.lon.corp.google.com ([2a00:79e0:d:209:dec6:15cf:125b:436b]) (user=dimorinny job=sendgmr) by 2002:a50:cd0b:0:b0:4fc:a484:c6ed with SMTP id z11-20020a50cd0b000000b004fca484c6edmr8319400edi.2.1680035486587; Tue, 28 Mar 2023 13:31:26 -0700 (PDT) Date: Tue, 28 Mar 2023 21:31:11 +0100 In-Reply-To: <20230328203111.1032378-1-dimorinny@google.com> Mime-Version: 1.0 References: <20230328203111.1032378-1-dimorinny@google.com> X-Mailer: git-send-email 2.40.0.348.gf938b09366-goog Message-ID: <20230328203111.1032378-3-dimorinny@google.com> Subject: [PATCH 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 Content-Type: text/plain; charset="UTF-8" Content-Transfer-Encoding: quoted-printable X-Mailman-Approved-At: Tue, 28 Mar 2023 23:07:15 +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. Cc: Ying-Chun Liu (PaulLiu) Cc: Simon Glass =D0=A1=D1=81: Joe Hershberger =D0=A1=D1=81: Ramon Fried Signed-off-by: Dmitrii Merkurev --- 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 =20 /** * fastboot_buf_addr - base address of the fastboot download buffer @@ -155,6 +156,37 @@ void fastboot_boot(void) } } =20 +/** + * 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); =20 +/** + * 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 b4bbd815c8..f3f087db81 100644 --- a/net/fastboot_tcp.c +++ b/net/fastboot_tcp.c @@ -73,6 +73,7 @@ static void fastboot_tcp_handler_ipv4(uchar *pkt, u16 dpo= rt, u32 tcp_seq_num, u32 tcp_ack_num, u8 action, unsigned int len) { + int fastboot_command_id; u64 command_size; u8 tcp_fin =3D action & TCP_FIN; u8 tcp_push =3D 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 =3D fastboot_handle_command(command, response); fastboot_tcp_send_message(response, strlen(response)); + fastboot_handle_boot(fastboot_command_id, + strncmp("OKAY", response, 4) =3D=3D 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 head= er, char *fastboot_data, net_send_udp_packet(net_server_ethaddr, fastboot_remote_ip, fastboot_remote_port, fastboot_our_port, len); =20 - /* 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) =3D=3D 0); =20 if (!strncmp("OKAY", response, 4) || !strncmp("FAIL", response, 4)) cmd =3D -1; } =20 -/** - * 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. * --=20 2.40.0.348.gf938b09366-goog