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#ifndef _FASTBOOT_H_ 13#define _FASTBOOT_H_ 14 15#define FASTBOOT_VERSION "0.4" 16 17/* 18 * Signals u-boot fastboot code to send multiple responses by 19 * calling response generating function repeatedly until a OKAY/FAIL 20 * is generated as final response. 21 * 22 * This status code is only used internally to signal, must NOT 23 * be sent to host. 24 */ 25#define FASTBOOT_MULTIRESPONSE_START ("MORE") 26 27/* The 64 defined bytes plus \0 */ 28#define FASTBOOT_COMMAND_LEN (64 + 1) 29#define FASTBOOT_RESPONSE_LEN (64 + 1) 30 31/** 32 * All known commands to fastboot 33 */ 34enum { 35 FASTBOOT_COMMAND_GETVAR = 0, 36 FASTBOOT_COMMAND_DOWNLOAD, 37 FASTBOOT_COMMAND_FLASH, 38 FASTBOOT_COMMAND_ERASE, 39 FASTBOOT_COMMAND_BOOT, 40 FASTBOOT_COMMAND_CONTINUE, 41 FASTBOOT_COMMAND_REBOOT, 42 FASTBOOT_COMMAND_REBOOT_BOOTLOADER, 43 FASTBOOT_COMMAND_REBOOT_FASTBOOTD, 44 FASTBOOT_COMMAND_REBOOT_RECOVERY, 45 FASTBOOT_COMMAND_SET_ACTIVE, 46 FASTBOOT_COMMAND_OEM_FORMAT, 47 FASTBOOT_COMMAND_OEM_PARTCONF, 48 FASTBOOT_COMMAND_OEM_BOOTBUS, 49 FASTBOOT_COMMAND_OEM_RUN, 50 FASTBOOT_COMMAND_OEM_CONSOLE, 51 FASTBOOT_COMMAND_OEM_BOARD, 52 FASTBOOT_COMMAND_ACMD, 53 FASTBOOT_COMMAND_UCMD, 54 FASTBOOT_COMMAND_COUNT 55}; 56 57/** 58 * Reboot reasons 59 */ 60enum fastboot_reboot_reason { 61 FASTBOOT_REBOOT_REASON_BOOTLOADER, 62 FASTBOOT_REBOOT_REASON_FASTBOOTD, 63 FASTBOOT_REBOOT_REASON_RECOVERY, 64 FASTBOOT_REBOOT_REASONS_COUNT 65}; 66 67/** 68 * fastboot_response() - Writes a response of the form "$tag$reason". 69 * 70 * @tag: The first part of the response 71 * @response: Pointer to fastboot response buffer 72 * @format: printf style format string 73 */ 74void fastboot_response(const char *tag, char *response, 75 const char *format, ...) 76 __attribute__ ((format (__printf__, 3, 4))); 77 78/** 79 * fastboot_fail() - Write a FAIL response of the form "FAIL$reason". 80 * 81 * @reason: Pointer to returned reason string 82 * @response: Pointer to fastboot response buffer 83 */ 84void fastboot_fail(const char *reason, char *response); 85 86/** 87 * fastboot_okay() - Write an OKAY response of the form "OKAY$reason". 88 * 89 * @reason: Pointer to returned reason string, or NULL to send a bare "OKAY" 90 * @response: Pointer to fastboot response buffer 91 */ 92void fastboot_okay(const char *reason, char *response); 93 94/** 95 * fastboot_set_reboot_flag() - Set flag to indicate reboot-bootloader 96 * 97 * Set flag which indicates that we should reboot into the bootloader 98 * following the reboot that fastboot executes after this function. 99 * 100 * This function should be overridden in your board file with one 101 * which sets whatever flag your board specific Android bootloader flow 102 * requires in order to re-enter the bootloader. 103 */ 104int fastboot_set_reboot_flag(enum fastboot_reboot_reason reason); 105 106/** 107 * fastboot_set_progress_callback() - set progress callback 108 * 109 * @progress: Pointer to progress callback 110 * 111 * Set a callback which is invoked periodically during long running operations 112 * (flash and erase). This can be used (for example) by the UDP transport to 113 * send INFO responses to keep the client alive whilst those commands are 114 * executing. 115 */ 116void fastboot_set_progress_callback(void (*progress)(const char *msg)); 117 118/* 119 * fastboot_init() - initialise new fastboot protocol session 120 * 121 * @buf_addr: Pointer to download buffer, or NULL for default 122 * @buf_size: Size of download buffer, or zero for default 123 */ 124void fastboot_init(void *buf_addr, u32 buf_size); 125 126/** 127 * fastboot_boot() - Execute fastboot boot command 128 * 129 * If ${fastboot_bootcmd} is set, run that command to execute the boot 130 * process, if that returns, then exit the fastboot server and return 131 * control to the caller. 132 * 133 * Otherwise execute "bootm <fastboot_buf_addr>", if that fails, reset 134 * the board. 135 */ 136void fastboot_boot(void); 137 138/** 139 * fastboot_handle_boot() - Shared implementation of system reaction to 140 * fastboot commands 141 * 142 * Making desceisions about device boot state (stay in fastboot, reboot 143 * to bootloader, reboot to OS, etc). 144 */ 145void fastboot_handle_boot(int command, bool success); 146 147/** 148 * fastboot_handle_command() - Handle fastboot command 149 * 150 * @cmd_string: Pointer to command string 151 * @response: Pointer to fastboot response buffer 152 * 153 * Return: Executed command, or -1 if not recognized 154 */ 155int fastboot_handle_command(char *cmd_string, char *response); 156 157/** 158 * fastboot_data_remaining() - return bytes remaining in current transfer 159 * 160 * Return: Number of bytes left in the current download 161 */ 162u32 fastboot_data_remaining(void); 163 164/** 165 * fastboot_data_download() - Copy image data to fastboot_buf_addr. 166 * 167 * @fastboot_data: Pointer to received fastboot data 168 * @fastboot_data_len: Length of received fastboot data 169 * @response: Pointer to fastboot response buffer 170 * 171 * Copies image data from fastboot_data to fastboot_buf_addr. Writes to 172 * response. fastboot_bytes_received is updated to indicate the number 173 * of bytes that have been transferred. 174 */ 175void fastboot_data_download(const void *fastboot_data, 176 unsigned int fastboot_data_len, char *response); 177 178/** 179 * fastboot_data_complete() - Mark current transfer complete 180 * 181 * @response: Pointer to fastboot response buffer 182 * 183 * Set image_size and ${filesize} to the total size of the downloaded image. 184 */ 185void fastboot_data_complete(char *response); 186 187/** 188 * fastboot_handle_multiresponse() - Called for each response to send 189 * 190 * @cmd: Command id that requested multiresponse 191 * @response: Pointer to fastboot response buffer 192 */ 193void fastboot_multiresponse(int cmd, char *response); 194 195void fastboot_acmd_complete(void); 196#endif /* _FASTBOOT_H_ */ 197