Tom Rini | 83d290c | 2018-05-06 17:58:06 -0400 | [diff] [blame] | 1 | /* SPDX-License-Identifier: GPL-2.0+ */ |
Maxime Ripard | 3c8f98f | 2015-10-15 14:34:13 +0200 | [diff] [blame] | 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> |
Maxime Ripard | 3c8f98f | 2015-10-15 14:34:13 +0200 | [diff] [blame] | 11 | */ |
| 12 | #ifndef _FASTBOOT_H_ |
| 13 | #define _FASTBOOT_H_ |
| 14 | |
Xindong Xu | d944142 | 2024-01-18 10:20:45 +0800 | [diff] [blame] | 15 | #ifdef CONFIG_AMLOGIC_MODIFY |
| 16 | #include <amlogic/android_vab.h> |
| 17 | #include <version.h> |
| 18 | #endif |
| 19 | |
Alex Kiernan | 1a28d38 | 2018-05-29 15:30:47 +0000 | [diff] [blame] | 20 | #define FASTBOOT_VERSION "0.4" |
| 21 | |
Maxime Ripard | 3c8f98f | 2015-10-15 14:34:13 +0200 | [diff] [blame] | 22 | /* The 64 defined bytes plus \0 */ |
Alex Kiernan | f73a7df | 2018-05-29 15:30:53 +0000 | [diff] [blame] | 23 | #define FASTBOOT_COMMAND_LEN (64 + 1) |
Maxime Ripard | 3c8f98f | 2015-10-15 14:34:13 +0200 | [diff] [blame] | 24 | #define FASTBOOT_RESPONSE_LEN (64 + 1) |
| 25 | |
Xindong Xu | d944142 | 2024-01-18 10:20:45 +0800 | [diff] [blame] | 26 | #ifdef CONFIG_AMLOGIC_MODIFY |
| 27 | extern int busy_flag; |
| 28 | extern u32 kMaxFetchSizeDefault; |
| 29 | #endif |
| 30 | |
Alex Kiernan | d2df2ab | 2018-05-29 15:30:41 +0000 | [diff] [blame] | 31 | /** |
Alex Kiernan | f73a7df | 2018-05-29 15:30:53 +0000 | [diff] [blame] | 32 | * All known commands to fastboot |
| 33 | */ |
| 34 | enum { |
| 35 | FASTBOOT_COMMAND_GETVAR = 0, |
Xindong Xu | d944142 | 2024-01-18 10:20:45 +0800 | [diff] [blame] | 36 | #ifdef CONFIG_FASTBOOT_WRITING_CMD |
Alex Kiernan | f73a7df | 2018-05-29 15:30:53 +0000 | [diff] [blame] | 37 | FASTBOOT_COMMAND_DOWNLOAD, |
Xindong Xu | d944142 | 2024-01-18 10:20:45 +0800 | [diff] [blame] | 38 | #ifdef CONFIG_AMLOGIC_MODIFY |
| 39 | #if !CONFIG_IS_ENABLED(NO_FASTBOOT_FLASHING) |
| 40 | FASTBOOT_COMMAND_FLASHING, |
| 41 | #endif |
| 42 | FASTBOOT_COMMAND_FETCH, |
Xindong Xu | b3cf2a8 | 2024-12-25 10:23:47 +0800 | [diff] [blame] | 43 | FASTBOOT_COMMAND_OEM, |
Xindong Xu | d944142 | 2024-01-18 10:20:45 +0800 | [diff] [blame] | 44 | #endif |
Alex Kiernan | f73a7df | 2018-05-29 15:30:53 +0000 | [diff] [blame] | 45 | #if CONFIG_IS_ENABLED(FASTBOOT_FLASH) |
| 46 | FASTBOOT_COMMAND_FLASH, |
| 47 | FASTBOOT_COMMAND_ERASE, |
| 48 | #endif |
Xindong Xu | d944142 | 2024-01-18 10:20:45 +0800 | [diff] [blame] | 49 | #endif |
Alex Kiernan | f73a7df | 2018-05-29 15:30:53 +0000 | [diff] [blame] | 50 | FASTBOOT_COMMAND_BOOT, |
| 51 | FASTBOOT_COMMAND_CONTINUE, |
Alex Kiernan | f73a7df | 2018-05-29 15:30:53 +0000 | [diff] [blame] | 52 | FASTBOOT_COMMAND_REBOOT_BOOTLOADER, |
Roman Kovalivskyi | 2b2a771 | 2020-07-28 23:35:33 +0300 | [diff] [blame] | 53 | FASTBOOT_COMMAND_REBOOT_FASTBOOTD, |
| 54 | FASTBOOT_COMMAND_REBOOT_RECOVERY, |
Xindong Xu | d944142 | 2024-01-18 10:20:45 +0800 | [diff] [blame] | 55 | FASTBOOT_COMMAND_REBOOT, |
| 56 | #ifdef CONFIG_FASTBOOT_WRITING_CMD |
Alex Kiernan | f73a7df | 2018-05-29 15:30:53 +0000 | [diff] [blame] | 57 | FASTBOOT_COMMAND_SET_ACTIVE, |
Alex Kiernan | 3845b90 | 2018-05-29 15:30:54 +0000 | [diff] [blame] | 58 | #if CONFIG_IS_ENABLED(FASTBOOT_CMD_OEM_FORMAT) |
| 59 | FASTBOOT_COMMAND_OEM_FORMAT, |
| 60 | #endif |
Patrick Delaunay | b2f6b97 | 2021-01-27 14:46:48 +0100 | [diff] [blame] | 61 | #if CONFIG_IS_ENABLED(FASTBOOT_CMD_OEM_PARTCONF) |
| 62 | FASTBOOT_COMMAND_OEM_PARTCONF, |
| 63 | #endif |
Patrick Delaunay | 0c0394b | 2021-01-27 14:46:49 +0100 | [diff] [blame] | 64 | #if CONFIG_IS_ENABLED(FASTBOOT_CMD_OEM_BOOTBUS) |
| 65 | FASTBOOT_COMMAND_OEM_BOOTBUS, |
| 66 | #endif |
Xindong Xu | d944142 | 2024-01-18 10:20:45 +0800 | [diff] [blame] | 67 | #endif |
Heiko Schocher | bc820d5 | 2021-02-10 09:29:03 +0100 | [diff] [blame] | 68 | #if CONFIG_IS_ENABLED(FASTBOOT_UUU_SUPPORT) |
| 69 | FASTBOOT_COMMAND_ACMD, |
| 70 | FASTBOOT_COMMAND_UCMD, |
| 71 | #endif |
Alex Kiernan | f73a7df | 2018-05-29 15:30:53 +0000 | [diff] [blame] | 72 | |
| 73 | FASTBOOT_COMMAND_COUNT |
| 74 | }; |
| 75 | |
| 76 | /** |
Roman Kovalivskyi | 851737a | 2020-07-28 23:35:32 +0300 | [diff] [blame] | 77 | * Reboot reasons |
| 78 | */ |
| 79 | enum fastboot_reboot_reason { |
| 80 | FASTBOOT_REBOOT_REASON_BOOTLOADER, |
Roman Kovalivskyi | 2b2a771 | 2020-07-28 23:35:33 +0300 | [diff] [blame] | 81 | FASTBOOT_REBOOT_REASON_FASTBOOTD, |
| 82 | FASTBOOT_REBOOT_REASON_RECOVERY, |
Roman Kovalivskyi | 851737a | 2020-07-28 23:35:32 +0300 | [diff] [blame] | 83 | FASTBOOT_REBOOT_REASONS_COUNT |
| 84 | }; |
| 85 | |
Xindong Xu | d944142 | 2024-01-18 10:20:45 +0800 | [diff] [blame] | 86 | #ifdef CONFIG_AMLOGIC_MODIFY |
| 87 | struct fastboot_read { |
| 88 | unsigned int totalBytes; |
| 89 | unsigned int transferredBytes; //transferredBytes <= totalBytes |
| 90 | unsigned int dataCheckAlg; |
| 91 | void *priv;//now for backup req->buf |
| 92 | void *buf; |
| 93 | }; |
| 94 | |
| 95 | extern struct fastboot_read fastboot_readInfo; |
| 96 | #endif |
| 97 | |
Roman Kovalivskyi | 851737a | 2020-07-28 23:35:32 +0300 | [diff] [blame] | 98 | /** |
Alex Kiernan | d2df2ab | 2018-05-29 15:30:41 +0000 | [diff] [blame] | 99 | * fastboot_response() - Writes a response of the form "$tag$reason". |
| 100 | * |
| 101 | * @tag: The first part of the response |
| 102 | * @response: Pointer to fastboot response buffer |
| 103 | * @format: printf style format string |
| 104 | */ |
| 105 | void fastboot_response(const char *tag, char *response, |
| 106 | const char *format, ...) |
| 107 | __attribute__ ((format (__printf__, 3, 4))); |
| 108 | |
| 109 | /** |
| 110 | * fastboot_fail() - Write a FAIL response of the form "FAIL$reason". |
| 111 | * |
| 112 | * @reason: Pointer to returned reason string |
| 113 | * @response: Pointer to fastboot response buffer |
| 114 | */ |
Alex Kiernan | c4ded03 | 2018-05-29 15:30:40 +0000 | [diff] [blame] | 115 | void fastboot_fail(const char *reason, char *response); |
Alex Kiernan | d2df2ab | 2018-05-29 15:30:41 +0000 | [diff] [blame] | 116 | |
| 117 | /** |
| 118 | * fastboot_okay() - Write an OKAY response of the form "OKAY$reason". |
| 119 | * |
| 120 | * @reason: Pointer to returned reason string, or NULL to send a bare "OKAY" |
| 121 | * @response: Pointer to fastboot response buffer |
| 122 | */ |
Alex Kiernan | c4ded03 | 2018-05-29 15:30:40 +0000 | [diff] [blame] | 123 | void fastboot_okay(const char *reason, char *response); |
Alex Kiernan | f73a7df | 2018-05-29 15:30:53 +0000 | [diff] [blame] | 124 | |
Xindong Xu | d944142 | 2024-01-18 10:20:45 +0800 | [diff] [blame] | 125 | #ifdef CONFIG_AMLOGIC_MODIFY |
| 126 | /** |
| 127 | * fastboot_busy() - Write a INFO response of the form "INFO$reason". |
| 128 | * |
| 129 | * @reason: Pointer to returned reason string |
| 130 | * @response: Pointer to fastboot response buffer |
| 131 | */ |
| 132 | void fastboot_busy(const char *reason, char *response); |
| 133 | |
| 134 | /** |
| 135 | *check lock state |
| 136 | *return 1 if locked |
| 137 | *return 0 if unlocked |
| 138 | */ |
| 139 | int check_lock(void); |
| 140 | #endif |
| 141 | |
Alex Kiernan | f73a7df | 2018-05-29 15:30:53 +0000 | [diff] [blame] | 142 | /** |
| 143 | * fastboot_set_reboot_flag() - Set flag to indicate reboot-bootloader |
| 144 | * |
| 145 | * Set flag which indicates that we should reboot into the bootloader |
| 146 | * following the reboot that fastboot executes after this function. |
| 147 | * |
| 148 | * This function should be overridden in your board file with one |
| 149 | * which sets whatever flag your board specific Android bootloader flow |
| 150 | * requires in order to re-enter the bootloader. |
| 151 | */ |
Roman Kovalivskyi | 851737a | 2020-07-28 23:35:32 +0300 | [diff] [blame] | 152 | int fastboot_set_reboot_flag(enum fastboot_reboot_reason reason); |
Alex Kiernan | f73a7df | 2018-05-29 15:30:53 +0000 | [diff] [blame] | 153 | |
| 154 | /** |
| 155 | * fastboot_set_progress_callback() - set progress callback |
| 156 | * |
| 157 | * @progress: Pointer to progress callback |
| 158 | * |
| 159 | * Set a callback which is invoked periodically during long running operations |
| 160 | * (flash and erase). This can be used (for example) by the UDP transport to |
| 161 | * send INFO responses to keep the client alive whilst those commands are |
| 162 | * executing. |
| 163 | */ |
| 164 | void fastboot_set_progress_callback(void (*progress)(const char *msg)); |
| 165 | |
| 166 | /* |
| 167 | * fastboot_init() - initialise new fastboot protocol session |
| 168 | * |
| 169 | * @buf_addr: Pointer to download buffer, or NULL for default |
| 170 | * @buf_size: Size of download buffer, or zero for default |
| 171 | */ |
| 172 | void fastboot_init(void *buf_addr, u32 buf_size); |
| 173 | |
| 174 | /** |
| 175 | * fastboot_boot() - Execute fastboot boot command |
| 176 | * |
| 177 | * If ${fastboot_bootcmd} is set, run that command to execute the boot |
| 178 | * process, if that returns, then exit the fastboot server and return |
| 179 | * control to the caller. |
| 180 | * |
| 181 | * Otherwise execute "bootm <fastboot_buf_addr>", if that fails, reset |
| 182 | * the board. |
| 183 | */ |
| 184 | void fastboot_boot(void); |
| 185 | |
| 186 | /** |
| 187 | * fastboot_handle_command() - Handle fastboot command |
| 188 | * |
| 189 | * @cmd_string: Pointer to command string |
| 190 | * @response: Pointer to fastboot response buffer |
| 191 | * |
| 192 | * Return: Executed command, or -1 if not recognized |
| 193 | */ |
| 194 | int fastboot_handle_command(char *cmd_string, char *response); |
| 195 | |
| 196 | /** |
| 197 | * fastboot_data_remaining() - return bytes remaining in current transfer |
| 198 | * |
| 199 | * Return: Number of bytes left in the current download |
| 200 | */ |
| 201 | u32 fastboot_data_remaining(void); |
| 202 | |
| 203 | /** |
| 204 | * fastboot_data_download() - Copy image data to fastboot_buf_addr. |
| 205 | * |
| 206 | * @fastboot_data: Pointer to received fastboot data |
| 207 | * @fastboot_data_len: Length of received fastboot data |
| 208 | * @response: Pointer to fastboot response buffer |
| 209 | * |
| 210 | * Copies image data from fastboot_data to fastboot_buf_addr. Writes to |
| 211 | * response. fastboot_bytes_received is updated to indicate the number |
| 212 | * of bytes that have been transferred. |
| 213 | */ |
| 214 | void fastboot_data_download(const void *fastboot_data, |
| 215 | unsigned int fastboot_data_len, char *response); |
| 216 | |
| 217 | /** |
| 218 | * fastboot_data_complete() - Mark current transfer complete |
| 219 | * |
| 220 | * @response: Pointer to fastboot response buffer |
| 221 | * |
| 222 | * Set image_size and ${filesize} to the total size of the downloaded image. |
| 223 | */ |
| 224 | void fastboot_data_complete(char *response); |
| 225 | |
Heiko Schocher | bc820d5 | 2021-02-10 09:29:03 +0100 | [diff] [blame] | 226 | #if CONFIG_IS_ENABLED(FASTBOOT_UUU_SUPPORT) |
| 227 | void fastboot_acmd_complete(void); |
| 228 | #endif |
Maxime Ripard | 3c8f98f | 2015-10-15 14:34:13 +0200 | [diff] [blame] | 229 | #endif /* _FASTBOOT_H_ */ |