]> git.sur5r.net Git - u-boot/commitdiff
fastboot: Extract fastboot_okay/fail to fb_common.c
authorAlex Kiernan <alex.kiernan@gmail.com>
Tue, 29 May 2018 15:30:41 +0000 (15:30 +0000)
committerMarek Vasut <marex@denx.de>
Wed, 30 May 2018 09:59:21 +0000 (11:59 +0200)
Add drivers/fastboot/fb_common.c, where fastboot_okay/fail are implemented
so we can call them from a non-USB implementation.

Introduce fastboot_response which takes varargs parameters so we can
use it to generate formatted response strings. Refactor fastboot_okay/fail
to use it.

Signed-off-by: Alex Kiernan <alex.kiernan@gmail.com>
Reviewed-by: Joe Hershberger <joe.hershberger@ni.com>
drivers/Makefile
drivers/fastboot/Makefile
drivers/fastboot/fb_common.c [new file with mode: 0644]
drivers/usb/gadget/f_fastboot.c
include/fastboot.h

index a79ff2e6b0065953d8a307a605793fbee6271512..d29a6e467b6c5d121d3b73152b7d3314e2af898a 100644 (file)
@@ -71,9 +71,7 @@ obj-y += block/
 obj-$(CONFIG_BOOTCOUNT_LIMIT) += bootcount/
 obj-$(CONFIG_CPU) += cpu/
 obj-y += crypto/
-ifneq ($(CONFIG_FASTBOOT_FLASH_MMC_DEV)$(CONFIG_FASTBOOT_FLASH_NAND_DEV),)
-obj-y += fastboot/
-endif
+obj-$(CONFIG_FASTBOOT) += fastboot/
 obj-y += firmware/
 obj-$(CONFIG_FPGA) += fpga/
 obj-y += misc/
index 651fbf0935a94645df82b4808023576b78f5a65a..b38dcff202602f7d70c4453b6c79bac8c786fd06 100644 (file)
@@ -1,5 +1,7 @@
 # SPDX-License-Identifier:      GPL-2.0+
 
+obj-y += fb_common.o
+
 ifdef CONFIG_FASTBOOT_FLASH_MMC_DEV
 obj-y += fb_mmc.o
 endif
diff --git a/drivers/fastboot/fb_common.c b/drivers/fastboot/fb_common.c
new file mode 100644 (file)
index 0000000..c4a7702
--- /dev/null
@@ -0,0 +1,61 @@
+// SPDX-License-Identifier: GPL-2.0+
+/*
+ * (C) Copyright 2008 - 2009
+ * Windriver, <www.windriver.com>
+ * Tom Rix <Tom.Rix@windriver.com>
+ *
+ * Copyright 2011 Sebastian Andrzej Siewior <bigeasy@linutronix.de>
+ *
+ * Copyright 2014 Linaro, Ltd.
+ * Rob Herring <robh@kernel.org>
+ */
+
+#include <common.h>
+#include <fastboot.h>
+
+/**
+ * fastboot_response() - Writes a response of the form "$tag$reason".
+ *
+ * @tag: The first part of the response
+ * @response: Pointer to fastboot response buffer
+ * @format: printf style format string
+ */
+void fastboot_response(const char *tag, char *response,
+                      const char *format, ...)
+{
+       va_list args;
+
+       strlcpy(response, tag, FASTBOOT_RESPONSE_LEN);
+       if (format) {
+               va_start(args, format);
+               vsnprintf(response + strlen(response),
+                         FASTBOOT_RESPONSE_LEN - strlen(response) - 1,
+                         format, args);
+               va_end(args);
+       }
+}
+
+/**
+ * fastboot_fail() - Write a FAIL response of the form "FAIL$reason".
+ *
+ * @reason: Pointer to returned reason string
+ * @response: Pointer to fastboot response buffer
+ */
+void fastboot_fail(const char *reason, char *response)
+{
+       fastboot_response("FAIL", response, "%s", reason);
+}
+
+/**
+ * fastboot_okay() - Write an OKAY response of the form "OKAY$reason".
+ *
+ * @reason: Pointer to returned reason string, or NULL to send a bare "OKAY"
+ * @response: Pointer to fastboot response buffer
+ */
+void fastboot_okay(const char *reason, char *response)
+{
+       if (reason)
+               fastboot_response("OKAY", response, "%s", reason);
+       else
+               fastboot_response("OKAY", response, NULL);
+}
index bb60612647dddb2934d69e2597083f8b3d993a7a..2e6e1615bfc7079224f0bea09821110fd29796eb 100644 (file)
@@ -149,19 +149,6 @@ static struct usb_gadget_strings *fastboot_strings[] = {
 static void rx_handler_command(struct usb_ep *ep, struct usb_request *req);
 static int strcmp_l1(const char *s1, const char *s2);
 
-
-void fastboot_fail(const char *reason, char *response)
-{
-       strncpy(response, "FAIL\0", 5);
-       strncat(response, reason, FASTBOOT_RESPONSE_LEN - 4 - 1);
-}
-
-void fastboot_okay(const char *reason, char *response)
-{
-       strncpy(response, "OKAY\0", 5);
-       strncat(response, reason, FASTBOOT_RESPONSE_LEN - 4 - 1);
-}
-
 static void fastboot_complete(struct usb_ep *ep, struct usb_request *req)
 {
        int status = req->status;
index ed52daeb1b8df1c4f14fd9a90f0b451207b81551..6cd44d2ab9240b06c6241abd5ab453804686500f 100644 (file)
 /* The 64 defined bytes plus \0 */
 #define FASTBOOT_RESPONSE_LEN  (64 + 1)
 
+/**
+ * fastboot_response() - Writes a response of the form "$tag$reason".
+ *
+ * @tag: The first part of the response
+ * @response: Pointer to fastboot response buffer
+ * @format: printf style format string
+ */
+void fastboot_response(const char *tag, char *response,
+                      const char *format, ...)
+       __attribute__ ((format (__printf__, 3, 4)));
+
+/**
+ * fastboot_fail() - Write a FAIL response of the form "FAIL$reason".
+ *
+ * @reason: Pointer to returned reason string
+ * @response: Pointer to fastboot response buffer
+ */
 void fastboot_fail(const char *reason, char *response);
+
+/**
+ * fastboot_okay() - Write an OKAY response of the form "OKAY$reason".
+ *
+ * @reason: Pointer to returned reason string, or NULL to send a bare "OKAY"
+ * @response: Pointer to fastboot response buffer
+ */
 void fastboot_okay(const char *reason, char *response);
 
 #endif /* _FASTBOOT_H_ */