[U-Boot] [RFC PATCH v2 14/20] fastboot: Avoid re-parsing cmd_string for boot/reboot

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


When picking up boot/reboot after we've sent our result packet, use
the previously parsed command rather than redoing the strcmp.

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

Changes in v2: None

 net/fastboot.c | 15 +++++++--------
 1 file changed, 7 insertions(+), 8 deletions(-)

diff --git a/net/fastboot.c b/net/fastboot.c
index edf78df..ad8c101 100644
--- a/net/fastboot.c
+++ b/net/fastboot.c
@@ -141,6 +141,7 @@ static void fastboot_send(struct fastboot_header fb_header, char *fastboot_data,
 	uchar *packet;
 	uchar *packet_base;
 	int len = 0;
+	int cmd = -1;
 	const char *error_msg = "An error occurred.";
 	short tmp;
 	struct fastboot_header fb_response_header = fb_header;
@@ -192,15 +193,13 @@ static void fastboot_send(struct fastboot_header fb_header, char *fastboot_data,
 			if (cmd_parameter)
 				cmd_parameter = strdup(cmd_parameter);
 		} else {
-			int i;
-
-			i = fastboot_lookup_command(cmd_string);
-			if (i >= 0) {
+			cmd = fastboot_lookup_command(cmd_string);
+			if (cmd >= 0) {
 				void (*fb_call)(char *cmd_parameter,
 						char *fastboot_data,
 						unsigned int fastboot_data_len,
 						char *response);
-				fb_call = fb_net_dispatch[i];
+				fb_call = fb_net_dispatch[cmd];
 				if (fb_call) {
 					fb_call(cmd_parameter, fastboot_data,
 						fastboot_data_len, response);
@@ -244,10 +243,10 @@ static void fastboot_send(struct fastboot_header fb_header, char *fastboot_data,
 
 	/* Continue boot process after sending response */
 	if (!strncmp("OKAY", response, 4)) {
-		if (!strcmp("boot", cmd_string)) {
+		if (cmd == FB_CMD_BOOT) {
 			boot_downloaded_image();
-		} else if (!strncmp("reboot", cmd_string, 6)) {
-			/* Matches reboot or reboot-bootloader */
+		} else if (cmd == FB_CMD_REBOOT ||
+			   cmd == FB_CMD_REBOOT_BOOTLOADER) {
 			do_reset(NULL, 0, 0, NULL);
 		}
 	}
-- 
2.7.4



More information about the U-Boot mailing list