blob: 1e7920eb9133bec5d2dc73104f20e7f069c78a98 [file] [log] [blame]
Tom Rini83d290c2018-05-06 17:58:06 -04001/* SPDX-License-Identifier: GPL-2.0+ */
Maxime Ripard3c8f98f2015-10-15 14:34:13 +02002/*
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>
Maxime Ripard3c8f98f2015-10-15 14:34:13 +020011 */
12#ifndef _FASTBOOT_H_
13#define _FASTBOOT_H_
14
Alex Kiernan1a28d382018-05-29 15:30:47 +000015#define FASTBOOT_VERSION "0.4"
16
Ion Agorria85fcd692024-01-05 09:22:06 +020017/*
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
Maxime Ripard3c8f98f2015-10-15 14:34:13 +020027/* The 64 defined bytes plus \0 */
Alex Kiernanf73a7df2018-05-29 15:30:53 +000028#define FASTBOOT_COMMAND_LEN (64 + 1)
Maxime Ripard3c8f98f2015-10-15 14:34:13 +020029#define FASTBOOT_RESPONSE_LEN (64 + 1)
30
Alex Kiernand2df2ab2018-05-29 15:30:41 +000031/**
Alex Kiernanf73a7df2018-05-29 15:30:53 +000032 * All known commands to fastboot
33 */
34enum {
35 FASTBOOT_COMMAND_GETVAR = 0,
36 FASTBOOT_COMMAND_DOWNLOAD,
Alex Kiernanf73a7df2018-05-29 15:30:53 +000037 FASTBOOT_COMMAND_FLASH,
38 FASTBOOT_COMMAND_ERASE,
Alex Kiernanf73a7df2018-05-29 15:30:53 +000039 FASTBOOT_COMMAND_BOOT,
40 FASTBOOT_COMMAND_CONTINUE,
41 FASTBOOT_COMMAND_REBOOT,
42 FASTBOOT_COMMAND_REBOOT_BOOTLOADER,
Roman Kovalivskyi2b2a7712020-07-28 23:35:33 +030043 FASTBOOT_COMMAND_REBOOT_FASTBOOTD,
44 FASTBOOT_COMMAND_REBOOT_RECOVERY,
Alex Kiernanf73a7df2018-05-29 15:30:53 +000045 FASTBOOT_COMMAND_SET_ACTIVE,
Alex Kiernan3845b902018-05-29 15:30:54 +000046 FASTBOOT_COMMAND_OEM_FORMAT,
Patrick Delaunayb2f6b972021-01-27 14:46:48 +010047 FASTBOOT_COMMAND_OEM_PARTCONF,
Patrick Delaunay0c0394b2021-01-27 14:46:49 +010048 FASTBOOT_COMMAND_OEM_BOOTBUS,
Sean Andersonf3d914c2022-12-16 13:20:16 -050049 FASTBOOT_COMMAND_OEM_RUN,
Ion Agorria16f79dd2024-01-05 09:22:11 +020050 FASTBOOT_COMMAND_OEM_CONSOLE,
Heiko Schocherbc820d52021-02-10 09:29:03 +010051 FASTBOOT_COMMAND_ACMD,
52 FASTBOOT_COMMAND_UCMD,
Alex Kiernanf73a7df2018-05-29 15:30:53 +000053 FASTBOOT_COMMAND_COUNT
54};
55
56/**
Roman Kovalivskyi851737a2020-07-28 23:35:32 +030057 * Reboot reasons
58 */
59enum fastboot_reboot_reason {
60 FASTBOOT_REBOOT_REASON_BOOTLOADER,
Roman Kovalivskyi2b2a7712020-07-28 23:35:33 +030061 FASTBOOT_REBOOT_REASON_FASTBOOTD,
62 FASTBOOT_REBOOT_REASON_RECOVERY,
Roman Kovalivskyi851737a2020-07-28 23:35:32 +030063 FASTBOOT_REBOOT_REASONS_COUNT
64};
65
66/**
Alex Kiernand2df2ab2018-05-29 15:30:41 +000067 * fastboot_response() - Writes a response of the form "$tag$reason".
68 *
69 * @tag: The first part of the response
70 * @response: Pointer to fastboot response buffer
71 * @format: printf style format string
72 */
73void fastboot_response(const char *tag, char *response,
74 const char *format, ...)
75 __attribute__ ((format (__printf__, 3, 4)));
76
77/**
78 * fastboot_fail() - Write a FAIL response of the form "FAIL$reason".
79 *
80 * @reason: Pointer to returned reason string
81 * @response: Pointer to fastboot response buffer
82 */
Alex Kiernanc4ded032018-05-29 15:30:40 +000083void fastboot_fail(const char *reason, char *response);
Alex Kiernand2df2ab2018-05-29 15:30:41 +000084
85/**
86 * fastboot_okay() - Write an OKAY response of the form "OKAY$reason".
87 *
88 * @reason: Pointer to returned reason string, or NULL to send a bare "OKAY"
89 * @response: Pointer to fastboot response buffer
90 */
Alex Kiernanc4ded032018-05-29 15:30:40 +000091void fastboot_okay(const char *reason, char *response);
Alex Kiernanf73a7df2018-05-29 15:30:53 +000092
93/**
94 * fastboot_set_reboot_flag() - Set flag to indicate reboot-bootloader
95 *
96 * Set flag which indicates that we should reboot into the bootloader
97 * following the reboot that fastboot executes after this function.
98 *
99 * This function should be overridden in your board file with one
100 * which sets whatever flag your board specific Android bootloader flow
101 * requires in order to re-enter the bootloader.
102 */
Roman Kovalivskyi851737a2020-07-28 23:35:32 +0300103int fastboot_set_reboot_flag(enum fastboot_reboot_reason reason);
Alex Kiernanf73a7df2018-05-29 15:30:53 +0000104
105/**
106 * fastboot_set_progress_callback() - set progress callback
107 *
108 * @progress: Pointer to progress callback
109 *
110 * Set a callback which is invoked periodically during long running operations
111 * (flash and erase). This can be used (for example) by the UDP transport to
112 * send INFO responses to keep the client alive whilst those commands are
113 * executing.
114 */
115void fastboot_set_progress_callback(void (*progress)(const char *msg));
116
117/*
118 * fastboot_init() - initialise new fastboot protocol session
119 *
120 * @buf_addr: Pointer to download buffer, or NULL for default
121 * @buf_size: Size of download buffer, or zero for default
122 */
123void fastboot_init(void *buf_addr, u32 buf_size);
124
125/**
126 * fastboot_boot() - Execute fastboot boot command
127 *
128 * If ${fastboot_bootcmd} is set, run that command to execute the boot
129 * process, if that returns, then exit the fastboot server and return
130 * control to the caller.
131 *
132 * Otherwise execute "bootm <fastboot_buf_addr>", if that fails, reset
133 * the board.
134 */
135void fastboot_boot(void);
136
137/**
Dmitrii Merkurevc8acbbb2023-04-12 19:49:31 +0100138 * fastboot_handle_boot() - Shared implementation of system reaction to
139 * fastboot commands
140 *
141 * Making desceisions about device boot state (stay in fastboot, reboot
142 * to bootloader, reboot to OS, etc).
143 */
144void fastboot_handle_boot(int command, bool success);
145
146/**
Alex Kiernanf73a7df2018-05-29 15:30:53 +0000147 * fastboot_handle_command() - Handle fastboot command
148 *
149 * @cmd_string: Pointer to command string
150 * @response: Pointer to fastboot response buffer
151 *
152 * Return: Executed command, or -1 if not recognized
153 */
154int fastboot_handle_command(char *cmd_string, char *response);
155
156/**
157 * fastboot_data_remaining() - return bytes remaining in current transfer
158 *
159 * Return: Number of bytes left in the current download
160 */
161u32 fastboot_data_remaining(void);
162
163/**
164 * fastboot_data_download() - Copy image data to fastboot_buf_addr.
165 *
166 * @fastboot_data: Pointer to received fastboot data
167 * @fastboot_data_len: Length of received fastboot data
168 * @response: Pointer to fastboot response buffer
169 *
170 * Copies image data from fastboot_data to fastboot_buf_addr. Writes to
171 * response. fastboot_bytes_received is updated to indicate the number
172 * of bytes that have been transferred.
173 */
174void fastboot_data_download(const void *fastboot_data,
175 unsigned int fastboot_data_len, char *response);
176
177/**
178 * fastboot_data_complete() - Mark current transfer complete
179 *
180 * @response: Pointer to fastboot response buffer
181 *
182 * Set image_size and ${filesize} to the total size of the downloaded image.
183 */
184void fastboot_data_complete(char *response);
185
Ion Agorria85fcd692024-01-05 09:22:06 +0200186/**
187 * fastboot_handle_multiresponse() - Called for each response to send
188 *
189 * @cmd: Command id that requested multiresponse
190 * @response: Pointer to fastboot response buffer
191 */
192void fastboot_multiresponse(int cmd, char *response);
193
Heiko Schocherbc820d52021-02-10 09:29:03 +0100194void fastboot_acmd_complete(void);
Maxime Ripard3c8f98f2015-10-15 14:34:13 +0200195#endif /* _FASTBOOT_H_ */