xref: /openbmc/u-boot/include/fastboot.h (revision 3ba98ed8)
1 /* SPDX-License-Identifier: GPL-2.0+ */
2 /*
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>
11  */
12 #ifndef _FASTBOOT_H_
13 #define _FASTBOOT_H_
14 
15 #define FASTBOOT_VERSION	"0.4"
16 
17 /* The 64 defined bytes plus \0 */
18 #define FASTBOOT_COMMAND_LEN	(64 + 1)
19 #define FASTBOOT_RESPONSE_LEN	(64 + 1)
20 
21 /**
22  * All known commands to fastboot
23  */
24 enum {
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,
36 #if CONFIG_IS_ENABLED(FASTBOOT_CMD_OEM_FORMAT)
37 	FASTBOOT_COMMAND_OEM_FORMAT,
38 #endif
39 
40 	FASTBOOT_COMMAND_COUNT
41 };
42 
43 /**
44  * fastboot_response() - Writes a response of the form "$tag$reason".
45  *
46  * @tag: The first part of the response
47  * @response: Pointer to fastboot response buffer
48  * @format: printf style format string
49  */
50 void fastboot_response(const char *tag, char *response,
51 		       const char *format, ...)
52 	__attribute__ ((format (__printf__, 3, 4)));
53 
54 /**
55  * fastboot_fail() - Write a FAIL response of the form "FAIL$reason".
56  *
57  * @reason: Pointer to returned reason string
58  * @response: Pointer to fastboot response buffer
59  */
60 void fastboot_fail(const char *reason, char *response);
61 
62 /**
63  * fastboot_okay() - Write an OKAY response of the form "OKAY$reason".
64  *
65  * @reason: Pointer to returned reason string, or NULL to send a bare "OKAY"
66  * @response: Pointer to fastboot response buffer
67  */
68 void fastboot_okay(const char *reason, char *response);
69 
70 /**
71  * fastboot_set_reboot_flag() - Set flag to indicate reboot-bootloader
72  *
73  * Set flag which indicates that we should reboot into the bootloader
74  * following the reboot that fastboot executes after this function.
75  *
76  * This function should be overridden in your board file with one
77  * which sets whatever flag your board specific Android bootloader flow
78  * requires in order to re-enter the bootloader.
79  */
80 int fastboot_set_reboot_flag(void);
81 
82 /**
83  * fastboot_set_progress_callback() - set progress callback
84  *
85  * @progress: Pointer to progress callback
86  *
87  * Set a callback which is invoked periodically during long running operations
88  * (flash and erase). This can be used (for example) by the UDP transport to
89  * send INFO responses to keep the client alive whilst those commands are
90  * executing.
91  */
92 void fastboot_set_progress_callback(void (*progress)(const char *msg));
93 
94 /*
95  * fastboot_init() - initialise new fastboot protocol session
96  *
97  * @buf_addr: Pointer to download buffer, or NULL for default
98  * @buf_size: Size of download buffer, or zero for default
99  */
100 void fastboot_init(void *buf_addr, u32 buf_size);
101 
102 /**
103  * fastboot_boot() - Execute fastboot boot command
104  *
105  * If ${fastboot_bootcmd} is set, run that command to execute the boot
106  * process, if that returns, then exit the fastboot server and return
107  * control to the caller.
108  *
109  * Otherwise execute "bootm <fastboot_buf_addr>", if that fails, reset
110  * the board.
111  */
112 void fastboot_boot(void);
113 
114 /**
115  * fastboot_handle_command() - Handle fastboot command
116  *
117  * @cmd_string: Pointer to command string
118  * @response: Pointer to fastboot response buffer
119  *
120  * Return: Executed command, or -1 if not recognized
121  */
122 int fastboot_handle_command(char *cmd_string, char *response);
123 
124 /**
125  * fastboot_data_remaining() - return bytes remaining in current transfer
126  *
127  * Return: Number of bytes left in the current download
128  */
129 u32 fastboot_data_remaining(void);
130 
131 /**
132  * fastboot_data_download() - Copy image data to fastboot_buf_addr.
133  *
134  * @fastboot_data: Pointer to received fastboot data
135  * @fastboot_data_len: Length of received fastboot data
136  * @response: Pointer to fastboot response buffer
137  *
138  * Copies image data from fastboot_data to fastboot_buf_addr. Writes to
139  * response. fastboot_bytes_received is updated to indicate the number
140  * of bytes that have been transferred.
141  */
142 void fastboot_data_download(const void *fastboot_data,
143 			    unsigned int fastboot_data_len, char *response);
144 
145 /**
146  * fastboot_data_complete() - Mark current transfer complete
147  *
148  * @response: Pointer to fastboot response buffer
149  *
150  * Set image_size and ${filesize} to the total size of the downloaded image.
151  */
152 void fastboot_data_complete(char *response);
153 
154 #endif /* _FASTBOOT_H_ */
155