diff mbox series

[U-Boot,RFC,v1,2/5] dfu: Extract fastboot_okay/fail to fb_common.c

Message ID 1524562627-5794-3-git-send-email-alex.kiernan@gmail.com
State Superseded
Delegated to: Lukasz Majewski
Headers show
Series Add fastboot UDP support | expand

Commit Message

Alex Kiernan April 24, 2018, 9:37 a.m. UTC
Added common/fb_common.c, where fastboot_okay/fail are implemented
so we can call them from a non-USB implementation.

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

 common/Makefile                 |  4 ++++
 common/fb_common.c              | 26 ++++++++++++++++++++++++++
 drivers/usb/gadget/f_fastboot.c | 13 -------------
 3 files changed, 30 insertions(+), 13 deletions(-)
 create mode 100644 common/fb_common.c

Comments

Lukasz Majewski April 25, 2018, 7:32 a.m. UTC | #1
Hi Alex,

> Added common/fb_common.c, where fastboot_okay/fail are implemented
> so we can call them from a non-USB implementation.
> 
> Signed-off-by: Alex Kiernan <alex.kiernan@gmail.com>
> ---
> 
>  common/Makefile                 |  4 ++++
>  common/fb_common.c              | 26 ++++++++++++++++++++++++++
>  drivers/usb/gadget/f_fastboot.c | 13 -------------
>  3 files changed, 30 insertions(+), 13 deletions(-)
>  create mode 100644 common/fb_common.c
> 
> diff --git a/common/Makefile b/common/Makefile
> index 7011dad..8177341 100644
> --- a/common/Makefile
> +++ b/common/Makefile
> @@ -124,6 +124,10 @@ endif
>  endif
>  endif
>  
> +ifneq ($(or
> $(CONFIG_USB_FUNCTION_FASTBOOT),$(CONFIG_UDP_FUNCTION_FASTBOOT)),)
> +obj-y += fb_common.o +endif
> +
>  ifdef CONFIG_CMD_EEPROM_LAYOUT
>  obj-y += eeprom/eeprom_field.o eeprom/eeprom_layout.o
>  endif
> diff --git a/common/fb_common.c b/common/fb_common.c
> new file mode 100644
> index 0000000..53cffe3
> --- /dev/null
> +++ b/common/fb_common.c
> @@ -0,0 +1,26 @@
> +// 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>
> +
> +void fastboot_fail(const char *reason, char *response)
> +{
> +	strncpy(response, "FAIL\0", 5);
> +	strncat(response, reason, FASTBOOT_RESPONSE_LEN - 4 - 1);
				  ^^^^^^^ This looks a bit
				  "hand-crafted". I suppose that it is
				  to prevent not adding "reason" when
				  response is large ?
> +}
> +
> +void fastboot_okay(const char *reason, char *response)
> +{
> +	strncpy(response, "OKAY\0", 5);
> +	strncat(response, reason, FASTBOOT_RESPONSE_LEN - 4 - 1);
> +}
> diff --git a/drivers/usb/gadget/f_fastboot.c
> b/drivers/usb/gadget/f_fastboot.c index 6ae1d97..fda4505 100644
> --- a/drivers/usb/gadget/f_fastboot.c
> +++ b/drivers/usb/gadget/f_fastboot.c
> @@ -150,19 +150,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;




Best regards,

Lukasz Majewski

--

DENX Software Engineering GmbH,      Managing Director: Wolfgang Denk
HRB 165235 Munich, Office: Kirchenstr.5, D-82194 Groebenzell, Germany
Phone: (+49)-8142-66989-10 Fax: (+49)-8142-66989-80 Email: wd@denx.de
Alex Kiernan April 25, 2018, 8:15 a.m. UTC | #2
On Wed, Apr 25, 2018 at 8:32 AM, Lukasz Majewski <lukma@denx.de> wrote:
> Hi Alex,
>
>> Added common/fb_common.c, where fastboot_okay/fail are implemented
>> so we can call them from a non-USB implementation.
>>
>> Signed-off-by: Alex Kiernan <alex.kiernan@gmail.com>
>> ---
>>
>>  common/Makefile                 |  4 ++++
>>  common/fb_common.c              | 26 ++++++++++++++++++++++++++
>>  drivers/usb/gadget/f_fastboot.c | 13 -------------
>>  3 files changed, 30 insertions(+), 13 deletions(-)
>>  create mode 100644 common/fb_common.c
>>
>> diff --git a/common/Makefile b/common/Makefile
>> index 7011dad..8177341 100644
>> --- a/common/Makefile
>> +++ b/common/Makefile
>> @@ -124,6 +124,10 @@ endif
>>  endif
>>  endif
>>
>> +ifneq ($(or
>> $(CONFIG_USB_FUNCTION_FASTBOOT),$(CONFIG_UDP_FUNCTION_FASTBOOT)),)
>> +obj-y += fb_common.o +endif
>> +
>>  ifdef CONFIG_CMD_EEPROM_LAYOUT
>>  obj-y += eeprom/eeprom_field.o eeprom/eeprom_layout.o
>>  endif
>> diff --git a/common/fb_common.c b/common/fb_common.c
>> new file mode 100644
>> index 0000000..53cffe3
>> --- /dev/null
>> +++ b/common/fb_common.c
>> @@ -0,0 +1,26 @@
>> +// 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>
>> +
>> +void fastboot_fail(const char *reason, char *response)
>> +{
>> +     strncpy(response, "FAIL\0", 5);
>> +     strncat(response, reason, FASTBOOT_RESPONSE_LEN - 4 - 1);
>                                   ^^^^^^^ This looks a bit
>                                   "hand-crafted". I suppose that it is
>                                   to prevent not adding "reason" when
>                                   response is large ?

It is a bit, isn't it. Obviously it was a simple cut & paste refactor,
but I can't think of any reason not to turn it into an snprintf.
diff mbox series

Patch

diff --git a/common/Makefile b/common/Makefile
index 7011dad..8177341 100644
--- a/common/Makefile
+++ b/common/Makefile
@@ -124,6 +124,10 @@  endif
 endif
 endif
 
+ifneq ($(or $(CONFIG_USB_FUNCTION_FASTBOOT),$(CONFIG_UDP_FUNCTION_FASTBOOT)),)
+obj-y += fb_common.o
+endif
+
 ifdef CONFIG_CMD_EEPROM_LAYOUT
 obj-y += eeprom/eeprom_field.o eeprom/eeprom_layout.o
 endif
diff --git a/common/fb_common.c b/common/fb_common.c
new file mode 100644
index 0000000..53cffe3
--- /dev/null
+++ b/common/fb_common.c
@@ -0,0 +1,26 @@ 
+// 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>
+
+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);
+}
diff --git a/drivers/usb/gadget/f_fastboot.c b/drivers/usb/gadget/f_fastboot.c
index 6ae1d97..fda4505 100644
--- a/drivers/usb/gadget/f_fastboot.c
+++ b/drivers/usb/gadget/f_fastboot.c
@@ -150,19 +150,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;