blob: 296451f89d44dc25ac8ecdb8a3446681f93e14f0 [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
Maxime Ripard3c8f98f2015-10-15 14:34:13 +020017/* The 64 defined bytes plus \0 */
Alex Kiernanf73a7df2018-05-29 15:30:53 +000018#define FASTBOOT_COMMAND_LEN (64 + 1)
Maxime Ripard3c8f98f2015-10-15 14:34:13 +020019#define FASTBOOT_RESPONSE_LEN (64 + 1)
20
Alex Kiernand2df2ab2018-05-29 15:30:41 +000021/**
Alex Kiernanf73a7df2018-05-29 15:30:53 +000022 * All known commands to fastboot
23 */
24enum {
25 FASTBOOT_COMMAND_GETVAR = 0,
26 FASTBOOT_COMMAND_DOWNLOAD,
Alex Kiernanf73a7df2018-05-29 15:30:53 +000027 FASTBOOT_COMMAND_FLASH,
28 FASTBOOT_COMMAND_ERASE,
Alex Kiernanf73a7df2018-05-29 15:30:53 +000029 FASTBOOT_COMMAND_BOOT,
30 FASTBOOT_COMMAND_CONTINUE,
31 FASTBOOT_COMMAND_REBOOT,
32 FASTBOOT_COMMAND_REBOOT_BOOTLOADER,
Roman Kovalivskyi2b2a7712020-07-28 23:35:33 +030033 FASTBOOT_COMMAND_REBOOT_FASTBOOTD,
34 FASTBOOT_COMMAND_REBOOT_RECOVERY,
Alex Kiernanf73a7df2018-05-29 15:30:53 +000035 FASTBOOT_COMMAND_SET_ACTIVE,
Alex Kiernan3845b902018-05-29 15:30:54 +000036 FASTBOOT_COMMAND_OEM_FORMAT,
Patrick Delaunayb2f6b972021-01-27 14:46:48 +010037 FASTBOOT_COMMAND_OEM_PARTCONF,
Patrick Delaunay0c0394b2021-01-27 14:46:49 +010038 FASTBOOT_COMMAND_OEM_BOOTBUS,
Sean Andersonf3d914c2022-12-16 13:20:16 -050039 FASTBOOT_COMMAND_OEM_RUN,
Heiko Schocherbc820d52021-02-10 09:29:03 +010040 FASTBOOT_COMMAND_ACMD,
41 FASTBOOT_COMMAND_UCMD,
Alex Kiernanf73a7df2018-05-29 15:30:53 +000042 FASTBOOT_COMMAND_COUNT
43};
44
45/**
Roman Kovalivskyi851737a2020-07-28 23:35:32 +030046 * Reboot reasons
47 */
48enum fastboot_reboot_reason {
49 FASTBOOT_REBOOT_REASON_BOOTLOADER,
Roman Kovalivskyi2b2a7712020-07-28 23:35:33 +030050 FASTBOOT_REBOOT_REASON_FASTBOOTD,
51 FASTBOOT_REBOOT_REASON_RECOVERY,
Roman Kovalivskyi851737a2020-07-28 23:35:32 +030052 FASTBOOT_REBOOT_REASONS_COUNT
53};
54
55/**
Alex Kiernand2df2ab2018-05-29 15:30:41 +000056 * fastboot_response() - Writes a response of the form "$tag$reason".
57 *
58 * @tag: The first part of the response
59 * @response: Pointer to fastboot response buffer
60 * @format: printf style format string
61 */
62void fastboot_response(const char *tag, char *response,
63 const char *format, ...)
64 __attribute__ ((format (__printf__, 3, 4)));
65
66/**
67 * fastboot_fail() - Write a FAIL response of the form "FAIL$reason".
68 *
69 * @reason: Pointer to returned reason string
70 * @response: Pointer to fastboot response buffer
71 */
Alex Kiernanc4ded032018-05-29 15:30:40 +000072void fastboot_fail(const char *reason, char *response);
Alex Kiernand2df2ab2018-05-29 15:30:41 +000073
74/**
75 * fastboot_okay() - Write an OKAY response of the form "OKAY$reason".
76 *
77 * @reason: Pointer to returned reason string, or NULL to send a bare "OKAY"
78 * @response: Pointer to fastboot response buffer
79 */
Alex Kiernanc4ded032018-05-29 15:30:40 +000080void fastboot_okay(const char *reason, char *response);
Alex Kiernanf73a7df2018-05-29 15:30:53 +000081
82/**
83 * fastboot_set_reboot_flag() - Set flag to indicate reboot-bootloader
84 *
85 * Set flag which indicates that we should reboot into the bootloader
86 * following the reboot that fastboot executes after this function.
87 *
88 * This function should be overridden in your board file with one
89 * which sets whatever flag your board specific Android bootloader flow
90 * requires in order to re-enter the bootloader.
91 */
Roman Kovalivskyi851737a2020-07-28 23:35:32 +030092int fastboot_set_reboot_flag(enum fastboot_reboot_reason reason);
Alex Kiernanf73a7df2018-05-29 15:30:53 +000093
94/**
95 * fastboot_set_progress_callback() - set progress callback
96 *
97 * @progress: Pointer to progress callback
98 *
99 * Set a callback which is invoked periodically during long running operations
100 * (flash and erase). This can be used (for example) by the UDP transport to
101 * send INFO responses to keep the client alive whilst those commands are
102 * executing.
103 */
104void fastboot_set_progress_callback(void (*progress)(const char *msg));
105
106/*
107 * fastboot_init() - initialise new fastboot protocol session
108 *
109 * @buf_addr: Pointer to download buffer, or NULL for default
110 * @buf_size: Size of download buffer, or zero for default
111 */
112void fastboot_init(void *buf_addr, u32 buf_size);
113
114/**
115 * fastboot_boot() - Execute fastboot boot command
116 *
117 * If ${fastboot_bootcmd} is set, run that command to execute the boot
118 * process, if that returns, then exit the fastboot server and return
119 * control to the caller.
120 *
121 * Otherwise execute "bootm <fastboot_buf_addr>", if that fails, reset
122 * the board.
123 */
124void fastboot_boot(void);
125
126/**
Dmitrii Merkurevc8acbbb2023-04-12 19:49:31 +0100127 * fastboot_handle_boot() - Shared implementation of system reaction to
128 * fastboot commands
129 *
130 * Making desceisions about device boot state (stay in fastboot, reboot
131 * to bootloader, reboot to OS, etc).
132 */
133void fastboot_handle_boot(int command, bool success);
134
135/**
Alex Kiernanf73a7df2018-05-29 15:30:53 +0000136 * fastboot_handle_command() - Handle fastboot command
137 *
138 * @cmd_string: Pointer to command string
139 * @response: Pointer to fastboot response buffer
140 *
141 * Return: Executed command, or -1 if not recognized
142 */
143int fastboot_handle_command(char *cmd_string, char *response);
144
145/**
146 * fastboot_data_remaining() - return bytes remaining in current transfer
147 *
148 * Return: Number of bytes left in the current download
149 */
150u32 fastboot_data_remaining(void);
151
152/**
153 * fastboot_data_download() - Copy image data to fastboot_buf_addr.
154 *
155 * @fastboot_data: Pointer to received fastboot data
156 * @fastboot_data_len: Length of received fastboot data
157 * @response: Pointer to fastboot response buffer
158 *
159 * Copies image data from fastboot_data to fastboot_buf_addr. Writes to
160 * response. fastboot_bytes_received is updated to indicate the number
161 * of bytes that have been transferred.
162 */
163void fastboot_data_download(const void *fastboot_data,
164 unsigned int fastboot_data_len, char *response);
165
166/**
167 * fastboot_data_complete() - Mark current transfer complete
168 *
169 * @response: Pointer to fastboot response buffer
170 *
171 * Set image_size and ${filesize} to the total size of the downloaded image.
172 */
173void fastboot_data_complete(char *response);
174
Heiko Schocherbc820d52021-02-10 09:29:03 +0100175void fastboot_acmd_complete(void);
Maxime Ripard3c8f98f2015-10-15 14:34:13 +0200176#endif /* _FASTBOOT_H_ */