blob: b9ab7f3033a574bbe39f8b6a94e4d8f2e23a048d [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
Xindong Xud9441422024-01-18 10:20:45 +080015#ifdef CONFIG_AMLOGIC_MODIFY
16#include <amlogic/android_vab.h>
17#include <version.h>
18#endif
19
Alex Kiernan1a28d382018-05-29 15:30:47 +000020#define FASTBOOT_VERSION "0.4"
21
Maxime Ripard3c8f98f2015-10-15 14:34:13 +020022/* The 64 defined bytes plus \0 */
Alex Kiernanf73a7df2018-05-29 15:30:53 +000023#define FASTBOOT_COMMAND_LEN (64 + 1)
Maxime Ripard3c8f98f2015-10-15 14:34:13 +020024#define FASTBOOT_RESPONSE_LEN (64 + 1)
25
Xindong Xud9441422024-01-18 10:20:45 +080026#ifdef CONFIG_AMLOGIC_MODIFY
27extern int busy_flag;
28extern u32 kMaxFetchSizeDefault;
29#endif
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,
Xindong Xud9441422024-01-18 10:20:45 +080036#ifdef CONFIG_FASTBOOT_WRITING_CMD
Alex Kiernanf73a7df2018-05-29 15:30:53 +000037 FASTBOOT_COMMAND_DOWNLOAD,
Xindong Xud9441422024-01-18 10:20:45 +080038#ifdef CONFIG_AMLOGIC_MODIFY
39#if !CONFIG_IS_ENABLED(NO_FASTBOOT_FLASHING)
40 FASTBOOT_COMMAND_FLASHING,
41#endif
42 FASTBOOT_COMMAND_FETCH,
Xindong Xub3cf2a82024-12-25 10:23:47 +080043 FASTBOOT_COMMAND_OEM,
Xindong Xud9441422024-01-18 10:20:45 +080044#endif
Alex Kiernanf73a7df2018-05-29 15:30:53 +000045#if CONFIG_IS_ENABLED(FASTBOOT_FLASH)
46 FASTBOOT_COMMAND_FLASH,
47 FASTBOOT_COMMAND_ERASE,
48#endif
Xindong Xud9441422024-01-18 10:20:45 +080049#endif
Alex Kiernanf73a7df2018-05-29 15:30:53 +000050 FASTBOOT_COMMAND_BOOT,
51 FASTBOOT_COMMAND_CONTINUE,
Alex Kiernanf73a7df2018-05-29 15:30:53 +000052 FASTBOOT_COMMAND_REBOOT_BOOTLOADER,
Roman Kovalivskyi2b2a7712020-07-28 23:35:33 +030053 FASTBOOT_COMMAND_REBOOT_FASTBOOTD,
54 FASTBOOT_COMMAND_REBOOT_RECOVERY,
Xindong Xud9441422024-01-18 10:20:45 +080055 FASTBOOT_COMMAND_REBOOT,
56#ifdef CONFIG_FASTBOOT_WRITING_CMD
Alex Kiernanf73a7df2018-05-29 15:30:53 +000057 FASTBOOT_COMMAND_SET_ACTIVE,
Alex Kiernan3845b902018-05-29 15:30:54 +000058#if CONFIG_IS_ENABLED(FASTBOOT_CMD_OEM_FORMAT)
59 FASTBOOT_COMMAND_OEM_FORMAT,
60#endif
Patrick Delaunayb2f6b972021-01-27 14:46:48 +010061#if CONFIG_IS_ENABLED(FASTBOOT_CMD_OEM_PARTCONF)
62 FASTBOOT_COMMAND_OEM_PARTCONF,
63#endif
Patrick Delaunay0c0394b2021-01-27 14:46:49 +010064#if CONFIG_IS_ENABLED(FASTBOOT_CMD_OEM_BOOTBUS)
65 FASTBOOT_COMMAND_OEM_BOOTBUS,
66#endif
Xindong Xud9441422024-01-18 10:20:45 +080067#endif
Heiko Schocherbc820d52021-02-10 09:29:03 +010068#if CONFIG_IS_ENABLED(FASTBOOT_UUU_SUPPORT)
69 FASTBOOT_COMMAND_ACMD,
70 FASTBOOT_COMMAND_UCMD,
71#endif
Alex Kiernanf73a7df2018-05-29 15:30:53 +000072
73 FASTBOOT_COMMAND_COUNT
74};
75
76/**
Roman Kovalivskyi851737a2020-07-28 23:35:32 +030077 * Reboot reasons
78 */
79enum fastboot_reboot_reason {
80 FASTBOOT_REBOOT_REASON_BOOTLOADER,
Roman Kovalivskyi2b2a7712020-07-28 23:35:33 +030081 FASTBOOT_REBOOT_REASON_FASTBOOTD,
82 FASTBOOT_REBOOT_REASON_RECOVERY,
Roman Kovalivskyi851737a2020-07-28 23:35:32 +030083 FASTBOOT_REBOOT_REASONS_COUNT
84};
85
Xindong Xud9441422024-01-18 10:20:45 +080086#ifdef CONFIG_AMLOGIC_MODIFY
87struct fastboot_read {
88 unsigned int totalBytes;
89 unsigned int transferredBytes; //transferredBytes <= totalBytes
90 unsigned int dataCheckAlg;
91 void *priv;//now for backup req->buf
92 void *buf;
93};
94
95extern struct fastboot_read fastboot_readInfo;
96#endif
97
Roman Kovalivskyi851737a2020-07-28 23:35:32 +030098/**
Alex Kiernand2df2ab2018-05-29 15:30:41 +000099 * fastboot_response() - Writes a response of the form "$tag$reason".
100 *
101 * @tag: The first part of the response
102 * @response: Pointer to fastboot response buffer
103 * @format: printf style format string
104 */
105void fastboot_response(const char *tag, char *response,
106 const char *format, ...)
107 __attribute__ ((format (__printf__, 3, 4)));
108
109/**
110 * fastboot_fail() - Write a FAIL response of the form "FAIL$reason".
111 *
112 * @reason: Pointer to returned reason string
113 * @response: Pointer to fastboot response buffer
114 */
Alex Kiernanc4ded032018-05-29 15:30:40 +0000115void fastboot_fail(const char *reason, char *response);
Alex Kiernand2df2ab2018-05-29 15:30:41 +0000116
117/**
118 * fastboot_okay() - Write an OKAY response of the form "OKAY$reason".
119 *
120 * @reason: Pointer to returned reason string, or NULL to send a bare "OKAY"
121 * @response: Pointer to fastboot response buffer
122 */
Alex Kiernanc4ded032018-05-29 15:30:40 +0000123void fastboot_okay(const char *reason, char *response);
Alex Kiernanf73a7df2018-05-29 15:30:53 +0000124
Xindong Xud9441422024-01-18 10:20:45 +0800125#ifdef CONFIG_AMLOGIC_MODIFY
126/**
127 * fastboot_busy() - Write a INFO response of the form "INFO$reason".
128 *
129 * @reason: Pointer to returned reason string
130 * @response: Pointer to fastboot response buffer
131 */
132void fastboot_busy(const char *reason, char *response);
133
134/**
135 *check lock state
136 *return 1 if locked
137 *return 0 if unlocked
138 */
139int check_lock(void);
140#endif
141
Alex Kiernanf73a7df2018-05-29 15:30:53 +0000142/**
143 * fastboot_set_reboot_flag() - Set flag to indicate reboot-bootloader
144 *
145 * Set flag which indicates that we should reboot into the bootloader
146 * following the reboot that fastboot executes after this function.
147 *
148 * This function should be overridden in your board file with one
149 * which sets whatever flag your board specific Android bootloader flow
150 * requires in order to re-enter the bootloader.
151 */
Roman Kovalivskyi851737a2020-07-28 23:35:32 +0300152int fastboot_set_reboot_flag(enum fastboot_reboot_reason reason);
Alex Kiernanf73a7df2018-05-29 15:30:53 +0000153
154/**
155 * fastboot_set_progress_callback() - set progress callback
156 *
157 * @progress: Pointer to progress callback
158 *
159 * Set a callback which is invoked periodically during long running operations
160 * (flash and erase). This can be used (for example) by the UDP transport to
161 * send INFO responses to keep the client alive whilst those commands are
162 * executing.
163 */
164void fastboot_set_progress_callback(void (*progress)(const char *msg));
165
166/*
167 * fastboot_init() - initialise new fastboot protocol session
168 *
169 * @buf_addr: Pointer to download buffer, or NULL for default
170 * @buf_size: Size of download buffer, or zero for default
171 */
172void fastboot_init(void *buf_addr, u32 buf_size);
173
174/**
175 * fastboot_boot() - Execute fastboot boot command
176 *
177 * If ${fastboot_bootcmd} is set, run that command to execute the boot
178 * process, if that returns, then exit the fastboot server and return
179 * control to the caller.
180 *
181 * Otherwise execute "bootm <fastboot_buf_addr>", if that fails, reset
182 * the board.
183 */
184void fastboot_boot(void);
185
186/**
187 * fastboot_handle_command() - Handle fastboot command
188 *
189 * @cmd_string: Pointer to command string
190 * @response: Pointer to fastboot response buffer
191 *
192 * Return: Executed command, or -1 if not recognized
193 */
194int fastboot_handle_command(char *cmd_string, char *response);
195
196/**
197 * fastboot_data_remaining() - return bytes remaining in current transfer
198 *
199 * Return: Number of bytes left in the current download
200 */
201u32 fastboot_data_remaining(void);
202
203/**
204 * fastboot_data_download() - Copy image data to fastboot_buf_addr.
205 *
206 * @fastboot_data: Pointer to received fastboot data
207 * @fastboot_data_len: Length of received fastboot data
208 * @response: Pointer to fastboot response buffer
209 *
210 * Copies image data from fastboot_data to fastboot_buf_addr. Writes to
211 * response. fastboot_bytes_received is updated to indicate the number
212 * of bytes that have been transferred.
213 */
214void fastboot_data_download(const void *fastboot_data,
215 unsigned int fastboot_data_len, char *response);
216
217/**
218 * fastboot_data_complete() - Mark current transfer complete
219 *
220 * @response: Pointer to fastboot response buffer
221 *
222 * Set image_size and ${filesize} to the total size of the downloaded image.
223 */
224void fastboot_data_complete(char *response);
225
Heiko Schocherbc820d52021-02-10 09:29:03 +0100226#if CONFIG_IS_ENABLED(FASTBOOT_UUU_SUPPORT)
227void fastboot_acmd_complete(void);
228#endif
Maxime Ripard3c8f98f2015-10-15 14:34:13 +0200229#endif /* _FASTBOOT_H_ */