[U-Boot] [RFC PATCH v2 15/20] fastboot: Merge boot common across USB and UDP

Alex Kiernan alex.kiernan at gmail.com
Mon Apr 30 08:32:49 UTC 2018


Merge USB and UDP boot code. The USB implementation stays the same, but
UDP no longer passes an fdt. We introduce a new environment variable
'fastbootcmd' which if set overrides the hardcoded boot command, setting
this then allows the UDP implementation to remain the same. If after
running 'fastbootcmd' the board has not booted, control is returned
to U-Boot and the fastboot process ends.

Signed-off-by: Alex Kiernan <alex.kiernan at gmail.com>
---

Changes in v2: None

 drivers/fastboot/fb_common.c    | 27 +++++++++++++++++++++++++++
 drivers/usb/gadget/f_fastboot.c | 22 +++++++---------------
 include/fastboot.h              |  1 +
 net/fastboot.c                  | 16 ++--------------
 4 files changed, 37 insertions(+), 29 deletions(-)

diff --git a/drivers/fastboot/fb_common.c b/drivers/fastboot/fb_common.c
index 36ef669..73d8f94 100644
--- a/drivers/fastboot/fb_common.c
+++ b/drivers/fastboot/fb_common.c
@@ -107,3 +107,30 @@ int __weak fb_set_reboot_flag(void)
 {
 	return -1;
 }
+
+void fastboot_boot(void *addr)
+{
+	char *s;
+
+	s = env_get("fastbootcmd");
+	if (s) {
+		run_command(s, CMD_FLAG_ENV);
+	} else {
+		static char boot_addr_start[12];
+		static char *const bootm_args[] = {
+			"bootm", boot_addr_start, NULL
+		};
+
+		snprintf(boot_addr_start, sizeof(boot_addr_start) - 1,
+			 "0x%lx", (long)addr);
+		printf("Booting kernel at %s...\n\n\n", boot_addr_start);
+
+		do_bootm(NULL, 0, 2, bootm_args);
+
+		/* This only happens if image is somehow faulty so we start
+		 * over. We deliberately leave this policy to the invocation
+		 * of fastbootcmd if that's what's being run
+		 */
+		do_reset(NULL, 0, 0, NULL);
+	}
+}
diff --git a/drivers/usb/gadget/f_fastboot.c b/drivers/usb/gadget/f_fastboot.c
index 84515da..1dca4dd 100644
--- a/drivers/usb/gadget/f_fastboot.c
+++ b/drivers/usb/gadget/f_fastboot.c
@@ -480,18 +480,15 @@ static void cb_download(struct usb_ep *ep, struct usb_request *req)
 	fastboot_tx_write_str(response);
 }
 
-static void do_bootm_on_complete(struct usb_ep *ep, struct usb_request *req)
+static void do_exit_on_complete(struct usb_ep *ep, struct usb_request *req)
 {
-	char boot_addr_start[12];
-	char *bootm_args[] = { "bootm", boot_addr_start, NULL };
-
-	puts("Booting kernel..\n");
-
-	sprintf(boot_addr_start, "0x%lx", (long)CONFIG_FASTBOOT_BUF_ADDR);
-	do_bootm(NULL, 0, 2, bootm_args);
+	g_dnl_trigger_detach();
+}
 
-	/* This only happens if image is somehow faulty so we start over */
-	do_reset(NULL, 0, 0, NULL);
+static void do_bootm_on_complete(struct usb_ep *ep, struct usb_request *req)
+{
+	fastboot_boot((void *)CONFIG_FASTBOOT_BUF_ADDR);
+	do_exit_on_complete(ep, req);
 }
 
 static void cb_boot(struct usb_ep *ep, struct usb_request *req)
@@ -500,11 +497,6 @@ static void cb_boot(struct usb_ep *ep, struct usb_request *req)
 	fastboot_tx_write_str("OKAY");
 }
 
-static void do_exit_on_complete(struct usb_ep *ep, struct usb_request *req)
-{
-	g_dnl_trigger_detach();
-}
-
 static void cb_continue(struct usb_ep *ep, struct usb_request *req)
 {
 	fastboot_func->in_req->complete = do_exit_on_complete;
diff --git a/include/fastboot.h b/include/fastboot.h
index 9767065..64f9939 100644
--- a/include/fastboot.h
+++ b/include/fastboot.h
@@ -76,4 +76,5 @@ int strcmp_l1(const char *s1, const char *s2);
 
 int fastboot_lookup_command(const char *cmd_string);
 int fb_set_reboot_flag(void);
+void fastboot_boot(void *addr);
 #endif /* _FASTBOOT_H_ */
diff --git a/net/fastboot.c b/net/fastboot.c
index ad8c101..119011c 100644
--- a/net/fastboot.c
+++ b/net/fastboot.c
@@ -383,20 +383,8 @@ static void cb_reboot_bootloader(char *cmd_parameter, char *fastboot_data,
  */
 static void boot_downloaded_image(void)
 {
-	char kernel_addr[12];
-	char *fdt_addr = env_get("fdt_addr_r");
-	char *const bootm_args[] = {
-		"bootm", kernel_addr, "-", fdt_addr, NULL
-	};
-
-	sprintf(kernel_addr, "0x%lx", (long)CONFIG_FASTBOOT_BUF_ADDR);
-
-	printf("\nBooting kernel at %s with fdt at %s...\n\n\n",
-	       kernel_addr, fdt_addr);
-	do_bootm(NULL, 0, 4, bootm_args);
-
-	/* This only happens if image is faulty so we start over. */
-	do_reset(NULL, 0, 0, NULL);
+	fastboot_boot((void *)CONFIG_FASTBOOT_BUF_ADDR);
+	net_set_state(NETLOOP_SUCCESS);
 }
 
 /**
-- 
2.7.4



More information about the U-Boot mailing list