blob: 1248640dc7975c6341c9672aa53035cfb5f2750b [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,
27#if CONFIG_IS_ENABLED(FASTBOOT_FLASH)
28 FASTBOOT_COMMAND_FLASH,
29 FASTBOOT_COMMAND_ERASE,
30#endif
31 FASTBOOT_COMMAND_BOOT,
32 FASTBOOT_COMMAND_CONTINUE,
33 FASTBOOT_COMMAND_REBOOT,
34 FASTBOOT_COMMAND_REBOOT_BOOTLOADER,
35 FASTBOOT_COMMAND_SET_ACTIVE,
Alex Kiernan3845b902018-05-29 15:30:54 +000036#if CONFIG_IS_ENABLED(FASTBOOT_CMD_OEM_FORMAT)
37 FASTBOOT_COMMAND_OEM_FORMAT,
38#endif
Ye Li9b149c22019-05-14 22:49:31 -070039#if CONFIG_IS_ENABLED(FASTBOOT_UUU_SUPPORT)
40 FASTBOOT_COMMAND_ACMD,
41 FASTBOOT_COMMAND_UCMD,
42#endif
43#ifdef CONFIG_FSL_FASTBOOT
44 FASTBOOT_COMMAND_UPLOAD,
45 FASTBOOT_COMMAND_GETSTAGED,
46#ifdef CONFIG_FASTBOOT_LOCK
47 FASTBOOT_COMMAND_FLASHING,
48 FASTBOOT_COMMAND_OEM,
49#endif
50#ifdef CONFIG_AVB_SUPPORT
51 FASTBOOT_COMMAND_SETACTIVE,
52#endif
53#ifdef CONFIG_AVB_ATX
54 FASTBOOT_COMMAND_STAGE,
55#endif
56#endif
Alex Kiernanf73a7df2018-05-29 15:30:53 +000057 FASTBOOT_COMMAND_COUNT
58};
59
60/**
Alex Kiernand2df2ab2018-05-29 15:30:41 +000061 * fastboot_response() - Writes a response of the form "$tag$reason".
62 *
63 * @tag: The first part of the response
64 * @response: Pointer to fastboot response buffer
65 * @format: printf style format string
66 */
67void fastboot_response(const char *tag, char *response,
68 const char *format, ...)
69 __attribute__ ((format (__printf__, 3, 4)));
70
71/**
72 * fastboot_fail() - Write a FAIL response of the form "FAIL$reason".
73 *
74 * @reason: Pointer to returned reason string
75 * @response: Pointer to fastboot response buffer
76 */
Alex Kiernanc4ded032018-05-29 15:30:40 +000077void fastboot_fail(const char *reason, char *response);
Alex Kiernand2df2ab2018-05-29 15:30:41 +000078
79/**
80 * fastboot_okay() - Write an OKAY response of the form "OKAY$reason".
81 *
82 * @reason: Pointer to returned reason string, or NULL to send a bare "OKAY"
83 * @response: Pointer to fastboot response buffer
84 */
Alex Kiernanc4ded032018-05-29 15:30:40 +000085void fastboot_okay(const char *reason, char *response);
Alex Kiernanf73a7df2018-05-29 15:30:53 +000086
87/**
88 * fastboot_set_reboot_flag() - Set flag to indicate reboot-bootloader
89 *
90 * Set flag which indicates that we should reboot into the bootloader
91 * following the reboot that fastboot executes after this function.
92 *
93 * This function should be overridden in your board file with one
94 * which sets whatever flag your board specific Android bootloader flow
95 * requires in order to re-enter the bootloader.
96 */
Alex Kiernan8a65bd62018-05-29 15:30:46 +000097int fastboot_set_reboot_flag(void);
Alex Kiernanf73a7df2018-05-29 15:30:53 +000098
99/**
100 * fastboot_set_progress_callback() - set progress callback
101 *
102 * @progress: Pointer to progress callback
103 *
104 * Set a callback which is invoked periodically during long running operations
105 * (flash and erase). This can be used (for example) by the UDP transport to
106 * send INFO responses to keep the client alive whilst those commands are
107 * executing.
108 */
109void fastboot_set_progress_callback(void (*progress)(const char *msg));
110
111/*
112 * fastboot_init() - initialise new fastboot protocol session
113 *
114 * @buf_addr: Pointer to download buffer, or NULL for default
115 * @buf_size: Size of download buffer, or zero for default
116 */
117void fastboot_init(void *buf_addr, u32 buf_size);
118
119/**
120 * fastboot_boot() - Execute fastboot boot command
121 *
122 * If ${fastboot_bootcmd} is set, run that command to execute the boot
123 * process, if that returns, then exit the fastboot server and return
124 * control to the caller.
125 *
126 * Otherwise execute "bootm <fastboot_buf_addr>", if that fails, reset
127 * the board.
128 */
129void fastboot_boot(void);
130
131/**
132 * fastboot_handle_command() - Handle fastboot command
133 *
134 * @cmd_string: Pointer to command string
135 * @response: Pointer to fastboot response buffer
136 *
137 * Return: Executed command, or -1 if not recognized
138 */
139int fastboot_handle_command(char *cmd_string, char *response);
140
141/**
142 * fastboot_data_remaining() - return bytes remaining in current transfer
143 *
144 * Return: Number of bytes left in the current download
145 */
146u32 fastboot_data_remaining(void);
147
148/**
149 * fastboot_data_download() - Copy image data to fastboot_buf_addr.
150 *
151 * @fastboot_data: Pointer to received fastboot data
152 * @fastboot_data_len: Length of received fastboot data
153 * @response: Pointer to fastboot response buffer
154 *
155 * Copies image data from fastboot_data to fastboot_buf_addr. Writes to
156 * response. fastboot_bytes_received is updated to indicate the number
157 * of bytes that have been transferred.
158 */
159void fastboot_data_download(const void *fastboot_data,
160 unsigned int fastboot_data_len, char *response);
161
162/**
163 * fastboot_data_complete() - Mark current transfer complete
164 *
165 * @response: Pointer to fastboot response buffer
166 *
167 * Set image_size and ${filesize} to the total size of the downloaded image.
168 */
169void fastboot_data_complete(char *response);
170
Ye Li9b149c22019-05-14 22:49:31 -0700171#if CONFIG_IS_ENABLED(FASTBOOT_UUU_SUPPORT)
172void fastboot_acmd_complete(void);
173#endif
174
175int fastboot_tx_write_more(const char *buffer);
176
177int fastboot_tx_write(const char *buffer, unsigned int buffer_size);
178
Maxime Ripard3c8f98f2015-10-15 14:34:13 +0200179#endif /* _FASTBOOT_H_ */