1 /* SPDX-License-Identifier: GPL-2.0+ */
3 * (C) Copyright 2008 - 2009
4 * Windriver, <www.windriver.com>
5 * Tom Rix <Tom.Rix@windriver.com>
7 * Copyright 2011 Sebastian Andrzej Siewior <bigeasy@linutronix.de>
9 * Copyright 2014 Linaro, Ltd.
10 * Rob Herring <robh@kernel.org>
15 #define FASTBOOT_VERSION "0.4"
17 /* The 64 defined bytes plus \0 */
18 #define FASTBOOT_COMMAND_LEN (64 + 1)
19 #define FASTBOOT_RESPONSE_LEN (64 + 1)
22 * All known commands to fastboot
25 FASTBOOT_COMMAND_GETVAR = 0,
26 FASTBOOT_COMMAND_DOWNLOAD,
27 #if CONFIG_IS_ENABLED(FASTBOOT_FLASH)
28 FASTBOOT_COMMAND_FLASH,
29 FASTBOOT_COMMAND_ERASE,
31 FASTBOOT_COMMAND_BOOT,
32 FASTBOOT_COMMAND_CONTINUE,
33 FASTBOOT_COMMAND_REBOOT,
34 FASTBOOT_COMMAND_REBOOT_BOOTLOADER,
35 FASTBOOT_COMMAND_SET_ACTIVE,
36 #if CONFIG_IS_ENABLED(FASTBOOT_CMD_OEM_FORMAT)
37 FASTBOOT_COMMAND_OEM_FORMAT,
40 FASTBOOT_COMMAND_COUNT
46 enum fastboot_reboot_reason {
47 FASTBOOT_REBOOT_REASON_BOOTLOADER,
48 FASTBOOT_REBOOT_REASONS_COUNT
52 * fastboot_response() - Writes a response of the form "$tag$reason".
54 * @tag: The first part of the response
55 * @response: Pointer to fastboot response buffer
56 * @format: printf style format string
58 void fastboot_response(const char *tag, char *response,
59 const char *format, ...)
60 __attribute__ ((format (__printf__, 3, 4)));
63 * fastboot_fail() - Write a FAIL response of the form "FAIL$reason".
65 * @reason: Pointer to returned reason string
66 * @response: Pointer to fastboot response buffer
68 void fastboot_fail(const char *reason, char *response);
71 * fastboot_okay() - Write an OKAY response of the form "OKAY$reason".
73 * @reason: Pointer to returned reason string, or NULL to send a bare "OKAY"
74 * @response: Pointer to fastboot response buffer
76 void fastboot_okay(const char *reason, char *response);
79 * fastboot_set_reboot_flag() - Set flag to indicate reboot-bootloader
81 * Set flag which indicates that we should reboot into the bootloader
82 * following the reboot that fastboot executes after this function.
84 * This function should be overridden in your board file with one
85 * which sets whatever flag your board specific Android bootloader flow
86 * requires in order to re-enter the bootloader.
88 int fastboot_set_reboot_flag(enum fastboot_reboot_reason reason);
91 * fastboot_set_progress_callback() - set progress callback
93 * @progress: Pointer to progress callback
95 * Set a callback which is invoked periodically during long running operations
96 * (flash and erase). This can be used (for example) by the UDP transport to
97 * send INFO responses to keep the client alive whilst those commands are
100 void fastboot_set_progress_callback(void (*progress)(const char *msg));
103 * fastboot_init() - initialise new fastboot protocol session
105 * @buf_addr: Pointer to download buffer, or NULL for default
106 * @buf_size: Size of download buffer, or zero for default
108 void fastboot_init(void *buf_addr, u32 buf_size);
111 * fastboot_boot() - Execute fastboot boot command
113 * If ${fastboot_bootcmd} is set, run that command to execute the boot
114 * process, if that returns, then exit the fastboot server and return
115 * control to the caller.
117 * Otherwise execute "bootm <fastboot_buf_addr>", if that fails, reset
120 void fastboot_boot(void);
123 * fastboot_handle_command() - Handle fastboot command
125 * @cmd_string: Pointer to command string
126 * @response: Pointer to fastboot response buffer
128 * Return: Executed command, or -1 if not recognized
130 int fastboot_handle_command(char *cmd_string, char *response);
133 * fastboot_data_remaining() - return bytes remaining in current transfer
135 * Return: Number of bytes left in the current download
137 u32 fastboot_data_remaining(void);
140 * fastboot_data_download() - Copy image data to fastboot_buf_addr.
142 * @fastboot_data: Pointer to received fastboot data
143 * @fastboot_data_len: Length of received fastboot data
144 * @response: Pointer to fastboot response buffer
146 * Copies image data from fastboot_data to fastboot_buf_addr. Writes to
147 * response. fastboot_bytes_received is updated to indicate the number
148 * of bytes that have been transferred.
150 void fastboot_data_download(const void *fastboot_data,
151 unsigned int fastboot_data_len, char *response);
154 * fastboot_data_complete() - Mark current transfer complete
156 * @response: Pointer to fastboot response buffer
158 * Set image_size and ${filesize} to the total size of the downloaded image.
160 void fastboot_data_complete(char *response);
162 #endif /* _FASTBOOT_H_ */