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