1 // 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 */ 23 void 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 */ 44 void 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 */ 55 void 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 } 62 63 /** 64 * fastboot_set_reboot_flag() - Set flag to indicate reboot-bootloader 65 * 66 * Set flag which indicates that we should reboot into the bootloader 67 * following the reboot that fastboot executes after this function. 68 * 69 * This function should be overridden in your board file with one 70 * which sets whatever flag your board specific Android bootloader flow 71 * requires in order to re-enter the bootloader. 72 */ 73 int __weak fastboot_set_reboot_flag(void) 74 { 75 return -ENOSYS; 76 } 77