blob: 2ca1b907a54d72770577ec0a70bb1d67ed14d708 [file] [log] [blame]
Tom Rini10e47792018-05-06 17:58:06 -04001/* SPDX-License-Identifier: GPL-2.0+ */
Maxime Ripard00e8eb72015-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 Ripard00e8eb72015-10-15 14:34:13 +020011 */
12#ifndef _FASTBOOT_H_
13#define _FASTBOOT_H_
14
Alex Kiernan1df98902018-05-29 15:30:47 +000015#define FASTBOOT_VERSION "0.4"
16
Ion Agorria1c387032024-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 Ripard00e8eb72015-10-15 14:34:13 +020027/* The 64 defined bytes plus \0 */
Alex Kiernand5aa57c2018-05-29 15:30:53 +000028#define FASTBOOT_COMMAND_LEN (64 + 1)
Maxime Ripard00e8eb72015-10-15 14:34:13 +020029#define FASTBOOT_RESPONSE_LEN (64 + 1)
30
Alex Kiernaned6a41442018-05-29 15:30:41 +000031/**
Alex Kiernand5aa57c2018-05-29 15:30:53 +000032 * All known commands to fastboot
33 */
34enum {
35 FASTBOOT_COMMAND_GETVAR = 0,
36 FASTBOOT_COMMAND_DOWNLOAD,
Alex Kiernand5aa57c2018-05-29 15:30:53 +000037 FASTBOOT_COMMAND_FLASH,
38 FASTBOOT_COMMAND_ERASE,
Alex Kiernand5aa57c2018-05-29 15:30:53 +000039 FASTBOOT_COMMAND_BOOT,
40 FASTBOOT_COMMAND_CONTINUE,
41 FASTBOOT_COMMAND_REBOOT,
42 FASTBOOT_COMMAND_REBOOT_BOOTLOADER,
Roman Kovalivskyib30b97b2020-07-28 23:35:33 +030043 FASTBOOT_COMMAND_REBOOT_FASTBOOTD,
44 FASTBOOT_COMMAND_REBOOT_RECOVERY,
Alex Kiernand5aa57c2018-05-29 15:30:53 +000045 FASTBOOT_COMMAND_SET_ACTIVE,
Alex Kiernanc86cde92018-05-29 15:30:54 +000046 FASTBOOT_COMMAND_OEM_FORMAT,
Patrick Delaunay61687702021-01-27 14:46:48 +010047 FASTBOOT_COMMAND_OEM_PARTCONF,
Patrick Delaunay67af29a2021-01-27 14:46:49 +010048 FASTBOOT_COMMAND_OEM_BOOTBUS,
Sean Anderson421bec02022-12-16 13:20:16 -050049 FASTBOOT_COMMAND_OEM_RUN,
Ion Agorriae64262d2024-01-05 09:22:11 +020050 FASTBOOT_COMMAND_OEM_CONSOLE,
Alexey Romanova0ae7902024-04-18 13:01:29 +030051 FASTBOOT_COMMAND_OEM_BOARD,
Heiko Schocher3a994482021-02-10 09:29:03 +010052 FASTBOOT_COMMAND_ACMD,
53 FASTBOOT_COMMAND_UCMD,
Alex Kiernand5aa57c2018-05-29 15:30:53 +000054 FASTBOOT_COMMAND_COUNT
55};
56
57/**
Roman Kovalivskyi1bb13422020-07-28 23:35:32 +030058 * Reboot reasons
59 */
60enum fastboot_reboot_reason {
61 FASTBOOT_REBOOT_REASON_BOOTLOADER,
Roman Kovalivskyib30b97b2020-07-28 23:35:33 +030062 FASTBOOT_REBOOT_REASON_FASTBOOTD,
63 FASTBOOT_REBOOT_REASON_RECOVERY,
Roman Kovalivskyi1bb13422020-07-28 23:35:32 +030064 FASTBOOT_REBOOT_REASONS_COUNT
65};
66
67/**
Alex Kiernaned6a41442018-05-29 15:30:41 +000068 * 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 */
Alex Kiernan27b69de2018-05-29 15:30:40 +000084void fastboot_fail(const char *reason, char *response);
Alex Kiernaned6a41442018-05-29 15:30:41 +000085
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 */
Alex Kiernan27b69de2018-05-29 15:30:40 +000092void fastboot_okay(const char *reason, char *response);
Alex Kiernand5aa57c2018-05-29 15:30:53 +000093
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 */
Roman Kovalivskyi1bb13422020-07-28 23:35:32 +0300104int fastboot_set_reboot_flag(enum fastboot_reboot_reason reason);
Alex Kiernand5aa57c2018-05-29 15:30:53 +0000105
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
Tom Rini793921e2024-04-18 08:29:35 -0600118/*
Alex Kiernand5aa57c2018-05-29 15:30:53 +0000119 * fastboot_init() - initialise new fastboot protocol session
120 *
Tom Rini793921e2024-04-18 08:29:35 -0600121 * @buf_addr: Pointer to download buffer, or NULL for default
Alex Kiernand5aa57c2018-05-29 15:30:53 +0000122 * @buf_size: Size of download buffer, or zero for default
123 */
Tom Rini793921e2024-04-18 08:29:35 -0600124void fastboot_init(void *buf_addr, u32 buf_size);
Alex Kiernand5aa57c2018-05-29 15:30:53 +0000125
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/**
Dmitrii Merkurev07882902023-04-12 19:49:31 +0100139 * 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/**
Alex Kiernand5aa57c2018-05-29 15:30:53 +0000148 * 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
Ion Agorria1c387032024-01-05 09:22:06 +0200187/**
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
Heiko Schocher3a994482021-02-10 09:29:03 +0100195void fastboot_acmd_complete(void);
Maxime Ripard00e8eb72015-10-15 14:34:13 +0200196#endif /* _FASTBOOT_H_ */