blob: 80dd8255aa2dd64b82c17030d4fc467d76d754d0 [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,
Roman Kovalivskyi2b2a7712020-07-28 23:35:33 +030035 FASTBOOT_COMMAND_REBOOT_FASTBOOTD,
36 FASTBOOT_COMMAND_REBOOT_RECOVERY,
Alex Kiernanf73a7df2018-05-29 15:30:53 +000037 FASTBOOT_COMMAND_SET_ACTIVE,
Alex Kiernan3845b902018-05-29 15:30:54 +000038#if CONFIG_IS_ENABLED(FASTBOOT_CMD_OEM_FORMAT)
39 FASTBOOT_COMMAND_OEM_FORMAT,
40#endif
Patrick Delaunayb2f6b972021-01-27 14:46:48 +010041#if CONFIG_IS_ENABLED(FASTBOOT_CMD_OEM_PARTCONF)
42 FASTBOOT_COMMAND_OEM_PARTCONF,
43#endif
Alex Kiernanf73a7df2018-05-29 15:30:53 +000044
45 FASTBOOT_COMMAND_COUNT
46};
47
48/**
Roman Kovalivskyi851737a2020-07-28 23:35:32 +030049 * Reboot reasons
50 */
51enum fastboot_reboot_reason {
52 FASTBOOT_REBOOT_REASON_BOOTLOADER,
Roman Kovalivskyi2b2a7712020-07-28 23:35:33 +030053 FASTBOOT_REBOOT_REASON_FASTBOOTD,
54 FASTBOOT_REBOOT_REASON_RECOVERY,
Roman Kovalivskyi851737a2020-07-28 23:35:32 +030055 FASTBOOT_REBOOT_REASONS_COUNT
56};
57
58/**
Alex Kiernand2df2ab2018-05-29 15:30:41 +000059 * fastboot_response() - Writes a response of the form "$tag$reason".
60 *
61 * @tag: The first part of the response
62 * @response: Pointer to fastboot response buffer
63 * @format: printf style format string
64 */
65void fastboot_response(const char *tag, char *response,
66 const char *format, ...)
67 __attribute__ ((format (__printf__, 3, 4)));
68
69/**
70 * fastboot_fail() - Write a FAIL response of the form "FAIL$reason".
71 *
72 * @reason: Pointer to returned reason string
73 * @response: Pointer to fastboot response buffer
74 */
Alex Kiernanc4ded032018-05-29 15:30:40 +000075void fastboot_fail(const char *reason, char *response);
Alex Kiernand2df2ab2018-05-29 15:30:41 +000076
77/**
78 * fastboot_okay() - Write an OKAY response of the form "OKAY$reason".
79 *
80 * @reason: Pointer to returned reason string, or NULL to send a bare "OKAY"
81 * @response: Pointer to fastboot response buffer
82 */
Alex Kiernanc4ded032018-05-29 15:30:40 +000083void fastboot_okay(const char *reason, char *response);
Alex Kiernanf73a7df2018-05-29 15:30:53 +000084
85/**
86 * fastboot_set_reboot_flag() - Set flag to indicate reboot-bootloader
87 *
88 * Set flag which indicates that we should reboot into the bootloader
89 * following the reboot that fastboot executes after this function.
90 *
91 * This function should be overridden in your board file with one
92 * which sets whatever flag your board specific Android bootloader flow
93 * requires in order to re-enter the bootloader.
94 */
Roman Kovalivskyi851737a2020-07-28 23:35:32 +030095int fastboot_set_reboot_flag(enum fastboot_reboot_reason reason);
Alex Kiernanf73a7df2018-05-29 15:30:53 +000096
97/**
98 * fastboot_set_progress_callback() - set progress callback
99 *
100 * @progress: Pointer to progress callback
101 *
102 * Set a callback which is invoked periodically during long running operations
103 * (flash and erase). This can be used (for example) by the UDP transport to
104 * send INFO responses to keep the client alive whilst those commands are
105 * executing.
106 */
107void fastboot_set_progress_callback(void (*progress)(const char *msg));
108
109/*
110 * fastboot_init() - initialise new fastboot protocol session
111 *
112 * @buf_addr: Pointer to download buffer, or NULL for default
113 * @buf_size: Size of download buffer, or zero for default
114 */
115void fastboot_init(void *buf_addr, u32 buf_size);
116
117/**
118 * fastboot_boot() - Execute fastboot boot command
119 *
120 * If ${fastboot_bootcmd} is set, run that command to execute the boot
121 * process, if that returns, then exit the fastboot server and return
122 * control to the caller.
123 *
124 * Otherwise execute "bootm <fastboot_buf_addr>", if that fails, reset
125 * the board.
126 */
127void fastboot_boot(void);
128
129/**
130 * fastboot_handle_command() - Handle fastboot command
131 *
132 * @cmd_string: Pointer to command string
133 * @response: Pointer to fastboot response buffer
134 *
135 * Return: Executed command, or -1 if not recognized
136 */
137int fastboot_handle_command(char *cmd_string, char *response);
138
139/**
140 * fastboot_data_remaining() - return bytes remaining in current transfer
141 *
142 * Return: Number of bytes left in the current download
143 */
144u32 fastboot_data_remaining(void);
145
146/**
147 * fastboot_data_download() - Copy image data to fastboot_buf_addr.
148 *
149 * @fastboot_data: Pointer to received fastboot data
150 * @fastboot_data_len: Length of received fastboot data
151 * @response: Pointer to fastboot response buffer
152 *
153 * Copies image data from fastboot_data to fastboot_buf_addr. Writes to
154 * response. fastboot_bytes_received is updated to indicate the number
155 * of bytes that have been transferred.
156 */
157void fastboot_data_download(const void *fastboot_data,
158 unsigned int fastboot_data_len, char *response);
159
160/**
161 * fastboot_data_complete() - Mark current transfer complete
162 *
163 * @response: Pointer to fastboot response buffer
164 *
165 * Set image_size and ${filesize} to the total size of the downloaded image.
166 */
167void fastboot_data_complete(char *response);
168
Maxime Ripard3c8f98f2015-10-15 14:34:13 +0200169#endif /* _FASTBOOT_H_ */