Replace write_fb_response with fastboot_okay/fail/response. Also allow
fastboot_okay to take NULL when we have no message to send.

Signed-off-by: Alex Kiernan <alex.kier...@gmail.com>
---

Changes in v2: None

 drivers/fastboot/fb_common.c    |  5 ++-
 drivers/fastboot/fb_mmc.c       | 10 ++---
 drivers/fastboot/fb_nand.c      |  4 +-
 drivers/fastboot/image-sparse.c |  2 +-
 net/fastboot.c                  | 95 +++++++++++++++--------------------------
 5 files changed, 47 insertions(+), 69 deletions(-)

diff --git a/drivers/fastboot/fb_common.c b/drivers/fastboot/fb_common.c
index 7367fbb..f0bf53d 100644
--- a/drivers/fastboot/fb_common.c
+++ b/drivers/fastboot/fb_common.c
@@ -45,7 +45,10 @@ void fastboot_fail(const char *reason, char *response)
 
 void fastboot_okay(const char *reason, char *response)
 {
-       fastboot_response("OKAY", response, "%s", reason);
+       if (reason)
+               fastboot_response("OKAY", response, "%s", reason);
+       else
+               fastboot_response("OKAY", response, NULL);
 }
 
 void timed_send_info(ulong *start, const char *msg)
diff --git a/drivers/fastboot/fb_mmc.c b/drivers/fastboot/fb_mmc.c
index 304bda1..416f309 100644
--- a/drivers/fastboot/fb_mmc.c
+++ b/drivers/fastboot/fb_mmc.c
@@ -128,7 +128,7 @@ static void write_raw_image(struct blk_desc *dev_desc, 
disk_partition_t *info,
 
        printf("........ wrote " LBAFU " bytes to '%s'\n", blkcnt * info->blksz,
               part_name);
-       fastboot_okay("", response);
+       fastboot_okay(NULL, response);
 }
 
 #ifdef CONFIG_ANDROID_BOOT_IMAGE
@@ -288,7 +288,7 @@ static int fb_mmc_update_zimage(struct blk_desc *dev_desc,
        }
 
        puts("........ zImage was updated in boot partition\n");
-       fastboot_okay("", response);
+       fastboot_okay(NULL, response);
        return 0;
 }
 #endif
@@ -323,7 +323,7 @@ void fb_mmc_flash_write(const char *cmd, void 
*download_buffer,
                        return;
                }
                printf("........ success\n");
-               fastboot_okay("", response);
+               fastboot_okay(NULL, response);
                return;
        }
 #endif
@@ -344,7 +344,7 @@ void fb_mmc_flash_write(const char *cmd, void 
*download_buffer,
                        return;
                }
                printf("........ success\n");
-               fastboot_okay("", response);
+               fastboot_okay(NULL, response);
                return;
        }
 #endif
@@ -436,5 +436,5 @@ void fb_mmc_erase(const char *cmd, char *response)
 
        printf("........ erased " LBAFU " bytes from '%s'\n",
               blks_size * info.blksz, cmd);
-       fastboot_okay("", response);
+       fastboot_okay(NULL, response);
 }
diff --git a/drivers/fastboot/fb_nand.c b/drivers/fastboot/fb_nand.c
index 3a0b101..de869a0 100644
--- a/drivers/fastboot/fb_nand.c
+++ b/drivers/fastboot/fb_nand.c
@@ -199,7 +199,7 @@ void fb_nand_flash_write(const char *cmd, void 
*download_buffer,
                return;
        }
 
-       fastboot_okay("", response);
+       fastboot_okay(NULL, response);
 }
 
 void fb_nand_erase(const char *cmd, char *response)
@@ -226,5 +226,5 @@ void fb_nand_erase(const char *cmd, char *response)
                return;
        }
 
-       fastboot_okay("", response);
+       fastboot_okay(NULL, response);
 }
diff --git a/drivers/fastboot/image-sparse.c b/drivers/fastboot/image-sparse.c
index 616c2bd..ecdb3d3 100644
--- a/drivers/fastboot/image-sparse.c
+++ b/drivers/fastboot/image-sparse.c
@@ -257,7 +257,7 @@ void write_sparse_image(
        if (total_blocks != sparse_header->total_blks)
                fastboot_fail("sparse image write failure", response);
        else
-               fastboot_okay("", response);
+               fastboot_okay(NULL, response);
 
        return;
 }
diff --git a/net/fastboot.c b/net/fastboot.c
index 87c12e5..960e7f1 100644
--- a/net/fastboot.c
+++ b/net/fastboot.c
@@ -67,7 +67,6 @@ static void fb_continue(char *);
 static void fb_reboot(char *);
 static void boot_downloaded_image(void);
 static void cleanup_command_data(void);
-static void write_fb_response(const char *, const char *, char *);
 
 void fastboot_send_info(const char *msg)
 {
@@ -89,7 +88,7 @@ void fastboot_send_info(const char *msg)
        memcpy(packet, &fb_response_header, sizeof(fb_response_header));
        packet += sizeof(fb_response_header);
        /* Write response */
-       write_fb_response("INFO", msg, response);
+       fastboot_response("INFO", response, "%s", msg);
        memcpy(packet, response, strlen(response));
        packet += strlen(response);
 
@@ -178,18 +177,17 @@ static void fastboot_send(struct fastboot_header 
fb_header, char *fastboot_data,
                        fb_erase(response);
 #endif
                } else if (!strcmp("boot", cmd_string)) {
-                       write_fb_response("OKAY", "", response);
+                       fastboot_okay(NULL, response);
                } else if (!strcmp("continue", cmd_string)) {
                        fb_continue(response);
                } else if (!strncmp("reboot", cmd_string, 6)) {
                        fb_reboot(response);
                } else if (!strcmp("set_active", cmd_string)) {
                        /* A/B not implemented, for now do nothing */
-                       write_fb_response("OKAY", "", response);
+                       fastboot_okay(NULL, response);
                } else {
                        pr_err("command %s not implemented.\n", cmd_string);
-                       write_fb_response("FAIL", "unrecognized command",
-                                         response);
+                       fastboot_fail("unrecognized command", response);
                }
                /* Sent some INFO packets, need to update sequence number in
                 * header
@@ -242,74 +240,67 @@ static void fastboot_send(struct fastboot_header 
fb_header, char *fastboot_data,
 static void fb_getvar(char *response)
 {
        if (!cmd_parameter) {
-               write_fb_response("FAIL", "missing var", response);
+               fastboot_fail("missing var", response);
        } else if (!strcmp("version", cmd_parameter)) {
-               write_fb_response("OKAY", FASTBOOT_VERSION, response);
+               fastboot_okay(FASTBOOT_VERSION, response);
        } else if (!strcmp("bootloader-version", cmd_parameter) ||
                   !strcmp("version-bootloader", cmd_parameter)) {
-               write_fb_response("OKAY", U_BOOT_VERSION, response);
+               fastboot_okay(U_BOOT_VERSION, response);
        } else if (!strcmp("downloadsize", cmd_parameter) ||
                   !strcmp("max-download-size", cmd_parameter)) {
-               char buf_size_str[12];
-
-               sprintf(buf_size_str, "0x%08x", CONFIG_FASTBOOT_BUF_SIZE);
-               write_fb_response("OKAY", buf_size_str, response);
+               fastboot_response("OKAY", response,
+                                 "0x%08x", CONFIG_FASTBOOT_BUF_SIZE);
        } else if (!strcmp("serialno", cmd_parameter)) {
                const char *tmp = env_get("serial#");
 
                if (tmp)
-                       write_fb_response("OKAY", tmp, response);
+                       fastboot_okay(tmp, response);
                else
-                       write_fb_response("FAIL", "Value not set", response);
+                       fastboot_fail("Value not set", response);
        } else if (!strcmp("version-baseband", cmd_parameter)) {
-               write_fb_response("OKAY", "N/A", response);
+               fastboot_okay("N/A", response);
        } else if (!strcmp("product", cmd_parameter)) {
                const char *board = env_get("board");
 
                if (board)
-                       write_fb_response("OKAY", board, response);
+                       fastboot_okay(board, response);
                else
-                       write_fb_response("FAIL", "Board not set", response);
+                       fastboot_fail("Board not set", response);
        } else if (!strcmp("current-slot", cmd_parameter)) {
                /* A/B not implemented, for now always return _a */
-               write_fb_response("OKAY", "_a", response);
+               fastboot_okay("_a", response);
        } else if (!strcmp("slot-suffixes", cmd_parameter)) {
-               write_fb_response("OKAY", "_a,_b", response);
+               fastboot_okay("_a,_b", response);
        } else if (!strncmp("has-slot", cmd_parameter, 8)) {
                char *part_name = cmd_parameter;
 
                cmd_parameter = strsep(&part_name, ":");
                if (!strcmp(part_name, "boot") || !strcmp(part_name, "system"))
-                       write_fb_response("OKAY", "yes", response);
+                       fastboot_okay("yes", response);
                else
-                       write_fb_response("OKAY", "no", response);
+                       fastboot_okay("no", response);
        } else if (!strncmp("partition-type", cmd_parameter, 14) ||
                   !strncmp("partition-size", cmd_parameter, 14)) {
                disk_partition_t part_info;
                struct blk_desc *dev_desc;
                char *part_name = cmd_parameter;
-               char part_size_str[20];
 
                cmd_parameter = strsep(&part_name, ":");
                dev_desc = blk_get_dev("mmc", 0);
                if (!dev_desc) {
-                       write_fb_response("FAIL", "block device not found",
-                                         response);
+                       fastboot_fail("block device not found", response);
                } else if (part_get_info_by_name(dev_desc, part_name,
                                                 &part_info) < 0) {
-                       write_fb_response("FAIL", "partition not found",
-                                         response);
+                       fastboot_fail("partition not found", response);
                } else if (!strncmp("partition-type", cmd_parameter, 14)) {
-                       write_fb_response("OKAY", (char *)part_info.type,
-                                         response);
+                       fastboot_okay((char *)part_info.type, response);
                } else if (!strncmp("partition-size", cmd_parameter, 14)) {
-                       sprintf(part_size_str, "0x%016x", (int)part_info.size);
-                       write_fb_response("OKAY", part_size_str, response);
+                       fastboot_response("OKAY", response,
+                                         "0x%016x", (int)part_info.size);
                }
        } else {
                printf("WARNING: unknown variable: %s\n", cmd_parameter);
-               write_fb_response("FAIL", "Variable not implemented",
-                                 response);
+               fastboot_fail("Variable not implemented", response);
        }
 }
 
@@ -328,14 +319,12 @@ static void fb_download(char *fastboot_data, unsigned int 
fastboot_data_len,
 
        if (bytes_expected == 0) {
                if (!cmd_parameter) {
-                       write_fb_response("FAIL", "Expected command parameter",
-                                         response);
+                       fastboot_fail("Expected command parameter", response);
                        return;
                }
                bytes_expected = simple_strtoul(cmd_parameter, &tmp, 16);
                if (bytes_expected == 0) {
-                       write_fb_response("FAIL", "Expected nonzero image size",
-                                         response);
+                       fastboot_fail("Expected nonzero image size", response);
                        return;
                }
        }
@@ -346,22 +335,22 @@ static void fb_download(char *fastboot_data, unsigned int 
fastboot_data_len,
                 * where cmd_parameter is an 8 digit hexadecimal number
                 */
                if (bytes_expected > CONFIG_FASTBOOT_BUF_SIZE)
-                       write_fb_response("FAIL", cmd_parameter, response);
+                       fastboot_fail(cmd_parameter, response);
                else
-                       write_fb_response("DATA", cmd_parameter, response);
+                       fastboot_response("DATA", response, "%s",
+                                         cmd_parameter);
        } else if (fastboot_data_len == 0 &&
                   (bytes_received >= bytes_expected)) {
                /* Download complete. Respond with "OKAY" */
-               write_fb_response("OKAY", "", response);
+               fastboot_okay(NULL, response);
                image_size = bytes_received;
                bytes_expected = 0;
                bytes_received = 0;
        } else {
                if (fastboot_data_len == 0 ||
                    (bytes_received + fastboot_data_len) > bytes_expected) {
-                       write_fb_response("FAIL",
-                                         "Received invalid data length",
-                                         response);
+                       fastboot_fail("Received invalid data length",
+                                     response);
                        return;
                }
                /* Download data to CONFIG_FASTBOOT_BUF_ADDR */
@@ -408,9 +397,9 @@ static void fb_continue(char *response)
 
        bootcmd = env_get("bootcmd");
        if (bootcmd)
-               write_fb_response("OKAY", "", response);
+               fastboot_okay(NULL, response);
        else
-               write_fb_response("FAIL", "bootcmd not set", response);
+               fastboot_fail("bootcmd not set", response);
 }
 
 /**
@@ -420,7 +409,7 @@ static void fb_continue(char *response)
  */
 static void fb_reboot(char *response)
 {
-       write_fb_response("OKAY", "", response);
+       fastboot_okay(NULL, response);
        if (!strcmp("reboot-bootloader", cmd_string))
                strcpy((char *)CONFIG_FASTBOOT_BUF_ADDR, "reboot-bootloader");
 }
@@ -447,20 +436,6 @@ static void boot_downloaded_image(void)
 }
 
 /**
- * Writes a response to response buffer of the form "$tag$reason".
- *
- * @param tag         The first part of the response
- * @param reason      The second part of the response
- * @param repsonse    Pointer to fastboot response buffer
- */
-static void write_fb_response(const char *tag, const char *reason,
-                             char *response)
-{
-       strncpy(response, tag, strlen(tag));
-       strncat(response, reason, FASTBOOT_RESPONSE_LEN - strlen(tag) - 1);
-}
-
-/**
  * Frees any resources allocated during current fastboot command.
  */
 static void cleanup_command_data(void)
-- 
2.7.4

_______________________________________________
U-Boot mailing list
U-Boot@lists.denx.de
https://lists.denx.de/listinfo/u-boot

Reply via email to