diff options
author | Alex Kiernan <alex.kiernan@gmail.com> | 2018-05-29 15:30:41 +0000 |
---|---|---|
committer | Marek Vasut <marex@denx.de> | 2018-05-30 11:59:21 +0200 |
commit | d2df2abbcd4b88539605f8329edd244e6474d7a0 (patch) | |
tree | 572a2ecdd83b6f84715ad5033e60dd95f6373b4d /drivers/fastboot | |
parent | c4ded03ef608be37db105200010d2f3f88195bd6 (diff) |
fastboot: Extract fastboot_okay/fail to fb_common.c
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>
Diffstat (limited to 'drivers/fastboot')
-rw-r--r-- | drivers/fastboot/Makefile | 2 | ||||
-rw-r--r-- | drivers/fastboot/fb_common.c | 61 |
2 files changed, 63 insertions, 0 deletions
diff --git a/drivers/fastboot/Makefile b/drivers/fastboot/Makefile index 651fbf0935a..b38dcff2026 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 00000000000..c4a7702bb3d --- /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); +} |