diff mbox series

[3/3] net: share fastboot boot handle logic between transports

Message ID 20230328203111.1032378-3-dimorinny@google.com
State Superseded
Delegated to: Ramon Fried
Headers show
Series [1/3] net: support being a TCP server to unblock TCP fastboot | expand

Commit Message

Dmitrii Merkurev March 28, 2023, 8:31 p.m. UTC
Introduce reboot, boot and continue commands support to
TCP fastboot by moving existing UDP logic into the common module.

Cc: Ying-Chun Liu (PaulLiu) <paul.liu@linaro.org>
Cc: Simon Glass <sjg@chromium.org>
Сс: Joe Hershberger <joe.hershberger@ni.com>
Сс: Ramon Fried <rfried.dev@gmail.com>
Signed-off-by: Dmitrii Merkurev <dimorinny@google.com>
---

 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(-)

Comments

Simon Glass April 1, 2023, 6:32 a.m. UTC | #1
On Wed, 29 Mar 2023 at 09:31, Dmitrii Merkurev <dimorinny@google.com> wrote:
>
> Introduce reboot, boot and continue commands support to
> TCP fastboot by moving existing UDP logic into the common module.
>
> Cc: Ying-Chun Liu (PaulLiu) <paul.liu@linaro.org>
> Cc: Simon Glass <sjg@chromium.org>
> Сс: Joe Hershberger <joe.hershberger@ni.com>
> Сс: Ramon Fried <rfried.dev@gmail.com>
> Signed-off-by: Dmitrii Merkurev <dimorinny@google.com>
> ---
>
>  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(-)

Reviewed-by: Simon Glass <sjg@chromium.org>
Ramon Fried April 1, 2023, 6:55 p.m. UTC | #2
On Sat, Apr 1, 2023 at 9:36 AM Simon Glass <sjg@chromium.org> wrote:
>
> On Wed, 29 Mar 2023 at 09:31, Dmitrii Merkurev <dimorinny@google.com> wrote:
> >
> > Introduce reboot, boot and continue commands support to
> > TCP fastboot by moving existing UDP logic into the common module.
> >
> > Cc: Ying-Chun Liu (PaulLiu) <paul.liu@linaro.org>
> > Cc: Simon Glass <sjg@chromium.org>
> > Сс: Joe Hershberger <joe.hershberger@ni.com>
> > Сс: Ramon Fried <rfried.dev@gmail.com>
> > Signed-off-by: Dmitrii Merkurev <dimorinny@google.com>
> > ---
> >
> >  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(-)
>
> Reviewed-by: Simon Glass <sjg@chromium.org>
Reviewed-by: Ramon Fried <rfried.dev@gmail.com>
diff mbox series

Patch

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 <command.h>
 #include <env.h>
 #include <fastboot.h>
+#include <net.h>
 
 /**
  * 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 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 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.
  *