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