public inbox for u-boot@lists.denx.de
 help / color / mirror / Atom feed
From: Alex Kiernan <alex.kiernan@gmail.com>
To: u-boot@lists.denx.de
Subject: [U-Boot] [PATCH v7 03/18] fastboot: Extract fastboot_okay/fail to fb_common.c
Date: Thu, 24 May 2018 13:28:58 +0000	[thread overview]
Message-ID: <20180524132913.11575-4-alex.kiernan@gmail.com> (raw)
In-Reply-To: <20180524132913.11575-1-alex.kiernan@gmail.com>

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

Changes in v7: None
Changes in v6: None
Changes in v5:
- fix docbook formatting

Changes in v4:
- add docbook comments

Changes in v3:
- Merge subsequent patch for formatting response strings into this one
- allow NULL to fastboot_okay() when there's no message to send

Changes in v2: None

 drivers/Makefile                |  4 +--
 drivers/fastboot/Makefile       |  2 ++
 drivers/fastboot/fb_common.c    | 61 +++++++++++++++++++++++++++++++++
 drivers/usb/gadget/f_fastboot.c | 13 -------
 include/fastboot.h              | 24 +++++++++++++
 5 files changed, 88 insertions(+), 16 deletions(-)
 create mode 100644 drivers/fastboot/fb_common.c

diff --git a/drivers/Makefile b/drivers/Makefile
index a79ff2e6b0..d29a6e467b 100644
--- a/drivers/Makefile
+++ b/drivers/Makefile
@@ -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/
diff --git a/drivers/fastboot/Makefile b/drivers/fastboot/Makefile
index 651fbf0935..b38dcff202 100644
--- a/drivers/fastboot/Makefile
+++ b/drivers/fastboot/Makefile
@@ -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
index 0000000000..c4a7702bb3
--- /dev/null
+++ b/drivers/fastboot/fb_common.c
@@ -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);
+}
diff --git a/drivers/usb/gadget/f_fastboot.c b/drivers/usb/gadget/f_fastboot.c
index bb60612647..2e6e1615bf 100644
--- a/drivers/usb/gadget/f_fastboot.c
+++ b/drivers/usb/gadget/f_fastboot.c
@@ -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;
diff --git a/include/fastboot.h b/include/fastboot.h
index ed52daeb1b..6cd44d2ab9 100644
--- a/include/fastboot.h
+++ b/include/fastboot.h
@@ -15,7 +15,31 @@
 /* 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_ */
-- 
2.17.0

  parent reply	other threads:[~2018-05-24 13:28 UTC|newest]

Thread overview: 25+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2018-05-24 13:28 [U-Boot] [PATCH v7 00/18] Add fastboot UDP support Alex Kiernan
2018-05-24 13:28 ` [U-Boot] [PATCH v7 01/18] fastboot: Move fastboot to drivers/fastboot Alex Kiernan
2018-05-24 13:28 ` [U-Boot] [PATCH v7 02/18] fastboot: Refactor fastboot_okay/fail to take response Alex Kiernan
2018-05-24 13:28 ` Alex Kiernan [this message]
2018-05-24 13:28 ` [U-Boot] [PATCH v7 04/18] fastboot: Correct dependencies in FASTBOOT_FLASH Alex Kiernan
2018-05-24 13:29 ` [U-Boot] [PATCH v7 05/18] fastboot: Add missing newlines Alex Kiernan
2018-05-24 13:29 ` [U-Boot] [PATCH v7 06/18] fastboot: Remove FIXME for CONFIG_FASTBOOT_...NAME Alex Kiernan
2018-05-24 13:29 ` [U-Boot] [PATCH v7 07/18] fastboot: Fix parameter types in _fb_nand_write Alex Kiernan
2018-05-24 13:29 ` [U-Boot] [PATCH v7 08/18] fastboot: Rename fb_set_reboot_flag to fastboot_set_reboot_flag Alex Kiernan
2018-05-24 13:29 ` [U-Boot] [PATCH v7 09/18] fastboot: Extract common definitions from USB fastboot Alex Kiernan
2018-05-24 13:29 ` [U-Boot] [PATCH v7 10/18] fastboot: Rename public fb_ functions to fastboot_ Alex Kiernan
2018-05-24 13:29 ` [U-Boot] [PATCH v7 11/18] ti: fastboot: Move weak overrides to board files Alex Kiernan
2018-05-24 13:29 ` [U-Boot] [PATCH v7 12/18] fs: Add fs_get_type_name to return current filesystem name Alex Kiernan
2018-05-24 13:29 ` [U-Boot] [PATCH v7 13/18] fastboot: Migrate FASTBOOT_FLASH_NAND_TRIMFFS to Kconfig Alex Kiernan
2018-05-24 13:29 ` [U-Boot] [PATCH v7 14/18] mmc: Separate "mmc swrite" from fastboot Alex Kiernan
2018-05-25  2:41   ` Simon Glass
2018-05-25 10:02     ` Alex Kiernan
2018-05-24 13:29 ` [U-Boot] [PATCH v7 15/18] net: fastboot: Merge AOSP UDP fastboot Alex Kiernan
2018-05-24 13:29 ` [U-Boot] [PATCH v7 16/18] fastboot: Add support for 'oem format' command Alex Kiernan
2018-05-24 13:29 ` [U-Boot] [PATCH v7 17/18] usb: fastboot: Convert USB f_fastboot to shared fastboot Alex Kiernan
2018-05-25  2:41   ` Simon Glass
2018-05-24 13:29 ` [U-Boot] [PATCH v7 18/18] fastboot: Update fastboot documentation Alex Kiernan
2018-05-25  2:41   ` Simon Glass
2018-05-28  7:39 ` [U-Boot] [PATCH v7 00/18] Add fastboot UDP support Lukasz Majewski
2018-05-29 11:24   ` Alex Kiernan

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=20180524132913.11575-4-alex.kiernan@gmail.com \
    --to=alex.kiernan@gmail.com \
    --cc=u-boot@lists.denx.de \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox