From c8acbbbf0847744ff2ad98e9d8d4e11d5e37eda2 Mon Sep 17 00:00:00 2001 From: Dmitrii Merkurev Date: Wed, 12 Apr 2023 19:49:31 +0100 Subject: net: share fastboot boot handle logic between transports MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit 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 --- net/fastboot_tcp.c | 5 ++++- net/fastboot_udp.c | 31 +------------------------------ 2 files changed, 5 insertions(+), 31 deletions(-) (limited to 'net') diff --git a/net/fastboot_tcp.c b/net/fastboot_tcp.c index b5613b6..2eb52ea 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 27e779d..d706928 100644 --- a/net/fastboot_udp.c +++ b/net/fastboot_udp.c @@ -40,8 +40,6 @@ static int fastboot_remote_port; /* The UDP port at our end */ static int fastboot_our_port; -static void boot_downloaded_image(void); - /** * fastboot_udp_send_info() - Send an INFO packet during long commands. * @@ -209,40 +207,13 @@ 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. * * @packet: Pointer to incoming UDP packet -- cgit v1.1