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