blob: c4a7702bb3d7999bdc442194a85ad0c64b912ea7 [file] [log] [blame]
Alex Kiernaned6a41442018-05-29 15:30:41 +00001// SPDX-License-Identifier: GPL-2.0+
2/*
3 * (C) Copyright 2008 - 2009
4 * Windriver, <www.windriver.com>
5 * Tom Rix <Tom.Rix@windriver.com>
6 *
7 * Copyright 2011 Sebastian Andrzej Siewior <bigeasy@linutronix.de>
8 *
9 * Copyright 2014 Linaro, Ltd.
10 * Rob Herring <robh@kernel.org>
11 */
12
13#include <common.h>
14#include <fastboot.h>
15
16/**
17 * fastboot_response() - Writes a response of the form "$tag$reason".
18 *
19 * @tag: The first part of the response
20 * @response: Pointer to fastboot response buffer
21 * @format: printf style format string
22 */
23void fastboot_response(const char *tag, char *response,
24 const char *format, ...)
25{
26 va_list args;
27
28 strlcpy(response, tag, FASTBOOT_RESPONSE_LEN);
29 if (format) {
30 va_start(args, format);
31 vsnprintf(response + strlen(response),
32 FASTBOOT_RESPONSE_LEN - strlen(response) - 1,
33 format, args);
34 va_end(args);
35 }
36}
37
38/**
39 * fastboot_fail() - Write a FAIL response of the form "FAIL$reason".
40 *
41 * @reason: Pointer to returned reason string
42 * @response: Pointer to fastboot response buffer
43 */
44void fastboot_fail(const char *reason, char *response)
45{
46 fastboot_response("FAIL", response, "%s", reason);
47}
48
49/**
50 * fastboot_okay() - Write an OKAY response of the form "OKAY$reason".
51 *
52 * @reason: Pointer to returned reason string, or NULL to send a bare "OKAY"
53 * @response: Pointer to fastboot response buffer
54 */
55void fastboot_okay(const char *reason, char *response)
56{
57 if (reason)
58 fastboot_response("OKAY", response, "%s", reason);
59 else
60 fastboot_response("OKAY", response, NULL);
61}