Alex Kiernan | f73a7df | 2018-05-29 15:30:53 +0000 | [diff] [blame] | 1 | // SPDX-License-Identifier: BSD-2-Clause |
| 2 | /* |
| 3 | * Copyright (C) 2016 The Android Open Source Project |
| 4 | */ |
| 5 | |
| 6 | #include <common.h> |
Simon Glass | 288b29e | 2019-11-14 12:57:43 -0700 | [diff] [blame] | 7 | #include <command.h> |
Ion Agorria | 85fcd69 | 2024-01-05 09:22:06 +0200 | [diff] [blame] | 8 | #include <console.h> |
Simon Glass | c7694dd | 2019-08-01 09:46:46 -0600 | [diff] [blame] | 9 | #include <env.h> |
Alex Kiernan | f73a7df | 2018-05-29 15:30:53 +0000 | [diff] [blame] | 10 | #include <fastboot.h> |
| 11 | #include <fastboot-internal.h> |
| 12 | #include <fb_mmc.h> |
| 13 | #include <fb_nand.h> |
Simon Glass | 637425b | 2023-12-14 21:19:04 -0700 | [diff] [blame] | 14 | #include <mapmem.h> |
Alex Kiernan | f73a7df | 2018-05-29 15:30:53 +0000 | [diff] [blame] | 15 | #include <part.h> |
| 16 | #include <stdlib.h> |
Simon Glass | 1e94b46 | 2023-09-14 18:21:46 -0600 | [diff] [blame] | 17 | #include <linux/printk.h> |
Alex Kiernan | f73a7df | 2018-05-29 15:30:53 +0000 | [diff] [blame] | 18 | |
| 19 | /** |
| 20 | * image_size - final fastboot image size |
| 21 | */ |
| 22 | static u32 image_size; |
| 23 | |
| 24 | /** |
| 25 | * fastboot_bytes_received - number of bytes received in the current download |
| 26 | */ |
| 27 | static u32 fastboot_bytes_received; |
| 28 | |
| 29 | /** |
| 30 | * fastboot_bytes_expected - number of bytes expected in the current download |
| 31 | */ |
| 32 | static u32 fastboot_bytes_expected; |
| 33 | |
| 34 | static void okay(char *, char *); |
| 35 | static void getvar(char *, char *); |
| 36 | static void download(char *, char *); |
Alex Kiernan | f73a7df | 2018-05-29 15:30:53 +0000 | [diff] [blame] | 37 | static void flash(char *, char *); |
| 38 | static void erase(char *, char *); |
Alex Kiernan | f73a7df | 2018-05-29 15:30:53 +0000 | [diff] [blame] | 39 | static void reboot_bootloader(char *, char *); |
Roman Kovalivskyi | 2b2a771 | 2020-07-28 23:35:33 +0300 | [diff] [blame] | 40 | static void reboot_fastbootd(char *, char *); |
| 41 | static void reboot_recovery(char *, char *); |
Alex Kiernan | 3845b90 | 2018-05-29 15:30:54 +0000 | [diff] [blame] | 42 | static void oem_format(char *, char *); |
Patrick Delaunay | b2f6b97 | 2021-01-27 14:46:48 +0100 | [diff] [blame] | 43 | static void oem_partconf(char *, char *); |
Patrick Delaunay | 0c0394b | 2021-01-27 14:46:49 +0100 | [diff] [blame] | 44 | static void oem_bootbus(char *, char *); |
Ion Agorria | 16f79dd | 2024-01-05 09:22:11 +0200 | [diff] [blame] | 45 | static void oem_console(char *, char *); |
Heiko Schocher | bc820d5 | 2021-02-10 09:29:03 +0100 | [diff] [blame] | 46 | static void run_ucmd(char *, char *); |
| 47 | static void run_acmd(char *, char *); |
Heiko Schocher | bc820d5 | 2021-02-10 09:29:03 +0100 | [diff] [blame] | 48 | |
Alex Kiernan | f73a7df | 2018-05-29 15:30:53 +0000 | [diff] [blame] | 49 | static const struct { |
| 50 | const char *command; |
| 51 | void (*dispatch)(char *cmd_parameter, char *response); |
| 52 | } commands[FASTBOOT_COMMAND_COUNT] = { |
| 53 | [FASTBOOT_COMMAND_GETVAR] = { |
| 54 | .command = "getvar", |
| 55 | .dispatch = getvar |
| 56 | }, |
| 57 | [FASTBOOT_COMMAND_DOWNLOAD] = { |
| 58 | .command = "download", |
| 59 | .dispatch = download |
| 60 | }, |
Alex Kiernan | f73a7df | 2018-05-29 15:30:53 +0000 | [diff] [blame] | 61 | [FASTBOOT_COMMAND_FLASH] = { |
| 62 | .command = "flash", |
Patrick Delaunay | d037990 | 2022-12-15 10:15:50 +0100 | [diff] [blame] | 63 | .dispatch = CONFIG_IS_ENABLED(FASTBOOT_FLASH, (flash), (NULL)) |
Alex Kiernan | f73a7df | 2018-05-29 15:30:53 +0000 | [diff] [blame] | 64 | }, |
| 65 | [FASTBOOT_COMMAND_ERASE] = { |
| 66 | .command = "erase", |
Patrick Delaunay | d037990 | 2022-12-15 10:15:50 +0100 | [diff] [blame] | 67 | .dispatch = CONFIG_IS_ENABLED(FASTBOOT_FLASH, (erase), (NULL)) |
Alex Kiernan | f73a7df | 2018-05-29 15:30:53 +0000 | [diff] [blame] | 68 | }, |
Alex Kiernan | f73a7df | 2018-05-29 15:30:53 +0000 | [diff] [blame] | 69 | [FASTBOOT_COMMAND_BOOT] = { |
| 70 | .command = "boot", |
| 71 | .dispatch = okay |
| 72 | }, |
| 73 | [FASTBOOT_COMMAND_CONTINUE] = { |
| 74 | .command = "continue", |
| 75 | .dispatch = okay |
| 76 | }, |
| 77 | [FASTBOOT_COMMAND_REBOOT] = { |
| 78 | .command = "reboot", |
| 79 | .dispatch = okay |
| 80 | }, |
| 81 | [FASTBOOT_COMMAND_REBOOT_BOOTLOADER] = { |
| 82 | .command = "reboot-bootloader", |
| 83 | .dispatch = reboot_bootloader |
| 84 | }, |
Roman Kovalivskyi | 2b2a771 | 2020-07-28 23:35:33 +0300 | [diff] [blame] | 85 | [FASTBOOT_COMMAND_REBOOT_FASTBOOTD] = { |
| 86 | .command = "reboot-fastboot", |
| 87 | .dispatch = reboot_fastbootd |
| 88 | }, |
| 89 | [FASTBOOT_COMMAND_REBOOT_RECOVERY] = { |
| 90 | .command = "reboot-recovery", |
| 91 | .dispatch = reboot_recovery |
| 92 | }, |
Alex Kiernan | f73a7df | 2018-05-29 15:30:53 +0000 | [diff] [blame] | 93 | [FASTBOOT_COMMAND_SET_ACTIVE] = { |
| 94 | .command = "set_active", |
| 95 | .dispatch = okay |
| 96 | }, |
Alex Kiernan | 3845b90 | 2018-05-29 15:30:54 +0000 | [diff] [blame] | 97 | [FASTBOOT_COMMAND_OEM_FORMAT] = { |
| 98 | .command = "oem format", |
Patrick Delaunay | d037990 | 2022-12-15 10:15:50 +0100 | [diff] [blame] | 99 | .dispatch = CONFIG_IS_ENABLED(FASTBOOT_CMD_OEM_FORMAT, (oem_format), (NULL)) |
Alex Kiernan | 3845b90 | 2018-05-29 15:30:54 +0000 | [diff] [blame] | 100 | }, |
Patrick Delaunay | b2f6b97 | 2021-01-27 14:46:48 +0100 | [diff] [blame] | 101 | [FASTBOOT_COMMAND_OEM_PARTCONF] = { |
| 102 | .command = "oem partconf", |
Patrick Delaunay | d037990 | 2022-12-15 10:15:50 +0100 | [diff] [blame] | 103 | .dispatch = CONFIG_IS_ENABLED(FASTBOOT_CMD_OEM_PARTCONF, (oem_partconf), (NULL)) |
Patrick Delaunay | b2f6b97 | 2021-01-27 14:46:48 +0100 | [diff] [blame] | 104 | }, |
Patrick Delaunay | 0c0394b | 2021-01-27 14:46:49 +0100 | [diff] [blame] | 105 | [FASTBOOT_COMMAND_OEM_BOOTBUS] = { |
| 106 | .command = "oem bootbus", |
Patrick Delaunay | d037990 | 2022-12-15 10:15:50 +0100 | [diff] [blame] | 107 | .dispatch = CONFIG_IS_ENABLED(FASTBOOT_CMD_OEM_BOOTBUS, (oem_bootbus), (NULL)) |
Patrick Delaunay | 0c0394b | 2021-01-27 14:46:49 +0100 | [diff] [blame] | 108 | }, |
Sean Anderson | f3d914c | 2022-12-16 13:20:16 -0500 | [diff] [blame] | 109 | [FASTBOOT_COMMAND_OEM_RUN] = { |
| 110 | .command = "oem run", |
| 111 | .dispatch = CONFIG_IS_ENABLED(FASTBOOT_OEM_RUN, (run_ucmd), (NULL)) |
| 112 | }, |
Ion Agorria | 16f79dd | 2024-01-05 09:22:11 +0200 | [diff] [blame] | 113 | [FASTBOOT_COMMAND_OEM_CONSOLE] = { |
| 114 | .command = "oem console", |
| 115 | .dispatch = CONFIG_IS_ENABLED(FASTBOOT_CMD_OEM_CONSOLE, (oem_console), (NULL)) |
| 116 | }, |
Heiko Schocher | bc820d5 | 2021-02-10 09:29:03 +0100 | [diff] [blame] | 117 | [FASTBOOT_COMMAND_UCMD] = { |
| 118 | .command = "UCmd", |
Patrick Delaunay | d037990 | 2022-12-15 10:15:50 +0100 | [diff] [blame] | 119 | .dispatch = CONFIG_IS_ENABLED(FASTBOOT_UUU_SUPPORT, (run_ucmd), (NULL)) |
Heiko Schocher | bc820d5 | 2021-02-10 09:29:03 +0100 | [diff] [blame] | 120 | }, |
| 121 | [FASTBOOT_COMMAND_ACMD] = { |
| 122 | .command = "ACmd", |
Patrick Delaunay | d037990 | 2022-12-15 10:15:50 +0100 | [diff] [blame] | 123 | .dispatch = CONFIG_IS_ENABLED(FASTBOOT_UUU_SUPPORT, (run_acmd), (NULL)) |
Heiko Schocher | bc820d5 | 2021-02-10 09:29:03 +0100 | [diff] [blame] | 124 | }, |
Alex Kiernan | f73a7df | 2018-05-29 15:30:53 +0000 | [diff] [blame] | 125 | }; |
| 126 | |
| 127 | /** |
| 128 | * fastboot_handle_command - Handle fastboot command |
| 129 | * |
| 130 | * @cmd_string: Pointer to command string |
| 131 | * @response: Pointer to fastboot response buffer |
| 132 | * |
| 133 | * Return: Executed command, or -1 if not recognized |
| 134 | */ |
| 135 | int fastboot_handle_command(char *cmd_string, char *response) |
| 136 | { |
| 137 | int i; |
| 138 | char *cmd_parameter; |
| 139 | |
| 140 | cmd_parameter = cmd_string; |
| 141 | strsep(&cmd_parameter, ":"); |
| 142 | |
| 143 | for (i = 0; i < FASTBOOT_COMMAND_COUNT; i++) { |
| 144 | if (!strcmp(commands[i].command, cmd_string)) { |
| 145 | if (commands[i].dispatch) { |
| 146 | commands[i].dispatch(cmd_parameter, |
| 147 | response); |
| 148 | return i; |
| 149 | } else { |
Patrick Delaunay | d037990 | 2022-12-15 10:15:50 +0100 | [diff] [blame] | 150 | pr_err("command %s not supported.\n", cmd_string); |
| 151 | fastboot_fail("Unsupported command", response); |
| 152 | return -1; |
Alex Kiernan | f73a7df | 2018-05-29 15:30:53 +0000 | [diff] [blame] | 153 | } |
| 154 | } |
| 155 | } |
| 156 | |
| 157 | pr_err("command %s not recognized.\n", cmd_string); |
| 158 | fastboot_fail("unrecognized command", response); |
| 159 | return -1; |
| 160 | } |
| 161 | |
Ion Agorria | 85fcd69 | 2024-01-05 09:22:06 +0200 | [diff] [blame] | 162 | void fastboot_multiresponse(int cmd, char *response) |
| 163 | { |
| 164 | switch (cmd) { |
Ion Agorria | 475aa9a | 2024-01-05 09:22:07 +0200 | [diff] [blame] | 165 | case FASTBOOT_COMMAND_GETVAR: |
| 166 | fastboot_getvar_all(response); |
| 167 | break; |
Ion Agorria | 16f79dd | 2024-01-05 09:22:11 +0200 | [diff] [blame] | 168 | case FASTBOOT_COMMAND_OEM_CONSOLE: |
| 169 | if (CONFIG_IS_ENABLED(FASTBOOT_CMD_OEM_CONSOLE)) { |
| 170 | char buf[FASTBOOT_RESPONSE_LEN] = { 0 }; |
| 171 | |
| 172 | if (console_record_isempty()) { |
| 173 | console_record_reset(); |
| 174 | fastboot_okay(NULL, response); |
| 175 | } else { |
| 176 | int ret = console_record_readline(buf, sizeof(buf) - 5); |
| 177 | |
| 178 | if (ret < 0) |
| 179 | fastboot_fail("Error reading console", response); |
| 180 | else |
| 181 | fastboot_response("INFO", response, "%s", buf); |
| 182 | } |
| 183 | break; |
| 184 | } |
Ion Agorria | 85fcd69 | 2024-01-05 09:22:06 +0200 | [diff] [blame] | 185 | default: |
| 186 | fastboot_fail("Unknown multiresponse command", response); |
| 187 | break; |
| 188 | } |
| 189 | } |
| 190 | |
Alex Kiernan | f73a7df | 2018-05-29 15:30:53 +0000 | [diff] [blame] | 191 | /** |
| 192 | * okay() - Send bare OKAY response |
| 193 | * |
| 194 | * @cmd_parameter: Pointer to command parameter |
| 195 | * @response: Pointer to fastboot response buffer |
| 196 | * |
| 197 | * Send a bare OKAY fastboot response. This is used where the command is |
| 198 | * valid, but all the work is done after the response has been sent (e.g. |
| 199 | * boot, reboot etc.) |
| 200 | */ |
| 201 | static void okay(char *cmd_parameter, char *response) |
| 202 | { |
| 203 | fastboot_okay(NULL, response); |
| 204 | } |
| 205 | |
| 206 | /** |
| 207 | * getvar() - Read a config/version variable |
| 208 | * |
| 209 | * @cmd_parameter: Pointer to command parameter |
| 210 | * @response: Pointer to fastboot response buffer |
| 211 | */ |
| 212 | static void getvar(char *cmd_parameter, char *response) |
| 213 | { |
| 214 | fastboot_getvar(cmd_parameter, response); |
| 215 | } |
| 216 | |
| 217 | /** |
| 218 | * fastboot_download() - Start a download transfer from the client |
| 219 | * |
| 220 | * @cmd_parameter: Pointer to command parameter |
| 221 | * @response: Pointer to fastboot response buffer |
| 222 | */ |
| 223 | static void download(char *cmd_parameter, char *response) |
| 224 | { |
| 225 | char *tmp; |
| 226 | |
| 227 | if (!cmd_parameter) { |
| 228 | fastboot_fail("Expected command parameter", response); |
| 229 | return; |
| 230 | } |
| 231 | fastboot_bytes_received = 0; |
Simon Glass | 7e5f460 | 2021-07-24 09:03:29 -0600 | [diff] [blame] | 232 | fastboot_bytes_expected = hextoul(cmd_parameter, &tmp); |
Alex Kiernan | f73a7df | 2018-05-29 15:30:53 +0000 | [diff] [blame] | 233 | if (fastboot_bytes_expected == 0) { |
| 234 | fastboot_fail("Expected nonzero image size", response); |
| 235 | return; |
| 236 | } |
| 237 | /* |
| 238 | * Nothing to download yet. Response is of the form: |
| 239 | * [DATA|FAIL]$cmd_parameter |
| 240 | * |
| 241 | * where cmd_parameter is an 8 digit hexadecimal number |
| 242 | */ |
| 243 | if (fastboot_bytes_expected > fastboot_buf_size) { |
| 244 | fastboot_fail(cmd_parameter, response); |
| 245 | } else { |
| 246 | printf("Starting download of %d bytes\n", |
| 247 | fastboot_bytes_expected); |
| 248 | fastboot_response("DATA", response, "%s", cmd_parameter); |
| 249 | } |
| 250 | } |
| 251 | |
| 252 | /** |
| 253 | * fastboot_data_remaining() - return bytes remaining in current transfer |
| 254 | * |
| 255 | * Return: Number of bytes left in the current download |
| 256 | */ |
| 257 | u32 fastboot_data_remaining(void) |
| 258 | { |
| 259 | return fastboot_bytes_expected - fastboot_bytes_received; |
| 260 | } |
| 261 | |
| 262 | /** |
| 263 | * fastboot_data_download() - Copy image data to fastboot_buf_addr. |
| 264 | * |
| 265 | * @fastboot_data: Pointer to received fastboot data |
| 266 | * @fastboot_data_len: Length of received fastboot data |
| 267 | * @response: Pointer to fastboot response buffer |
| 268 | * |
| 269 | * Copies image data from fastboot_data to fastboot_buf_addr. Writes to |
| 270 | * response. fastboot_bytes_received is updated to indicate the number |
| 271 | * of bytes that have been transferred. |
| 272 | * |
| 273 | * On completion sets image_size and ${filesize} to the total size of the |
| 274 | * downloaded image. |
| 275 | */ |
| 276 | void fastboot_data_download(const void *fastboot_data, |
| 277 | unsigned int fastboot_data_len, |
| 278 | char *response) |
| 279 | { |
| 280 | #define BYTES_PER_DOT 0x20000 |
| 281 | u32 pre_dot_num, now_dot_num; |
Simon Glass | 637425b | 2023-12-14 21:19:04 -0700 | [diff] [blame] | 282 | void *buf; |
Alex Kiernan | f73a7df | 2018-05-29 15:30:53 +0000 | [diff] [blame] | 283 | |
| 284 | if (fastboot_data_len == 0 || |
| 285 | (fastboot_bytes_received + fastboot_data_len) > |
| 286 | fastboot_bytes_expected) { |
| 287 | fastboot_fail("Received invalid data length", |
| 288 | response); |
| 289 | return; |
| 290 | } |
| 291 | /* Download data to fastboot_buf_addr */ |
Simon Glass | 637425b | 2023-12-14 21:19:04 -0700 | [diff] [blame] | 292 | buf = map_sysmem(fastboot_buf_addr, 0); |
| 293 | memcpy(buf + fastboot_bytes_received, |
Alex Kiernan | f73a7df | 2018-05-29 15:30:53 +0000 | [diff] [blame] | 294 | fastboot_data, fastboot_data_len); |
Simon Glass | 637425b | 2023-12-14 21:19:04 -0700 | [diff] [blame] | 295 | unmap_sysmem(buf); |
Alex Kiernan | f73a7df | 2018-05-29 15:30:53 +0000 | [diff] [blame] | 296 | |
| 297 | pre_dot_num = fastboot_bytes_received / BYTES_PER_DOT; |
| 298 | fastboot_bytes_received += fastboot_data_len; |
| 299 | now_dot_num = fastboot_bytes_received / BYTES_PER_DOT; |
| 300 | |
| 301 | if (pre_dot_num != now_dot_num) { |
| 302 | putc('.'); |
| 303 | if (!(now_dot_num % 74)) |
| 304 | putc('\n'); |
| 305 | } |
| 306 | *response = '\0'; |
| 307 | } |
| 308 | |
| 309 | /** |
| 310 | * fastboot_data_complete() - Mark current transfer complete |
| 311 | * |
| 312 | * @response: Pointer to fastboot response buffer |
| 313 | * |
| 314 | * Set image_size and ${filesize} to the total size of the downloaded image. |
| 315 | */ |
| 316 | void fastboot_data_complete(char *response) |
| 317 | { |
| 318 | /* Download complete. Respond with "OKAY" */ |
| 319 | fastboot_okay(NULL, response); |
| 320 | printf("\ndownloading of %d bytes finished\n", fastboot_bytes_received); |
| 321 | image_size = fastboot_bytes_received; |
| 322 | env_set_hex("filesize", image_size); |
| 323 | fastboot_bytes_expected = 0; |
| 324 | fastboot_bytes_received = 0; |
| 325 | } |
| 326 | |
Alex Kiernan | f73a7df | 2018-05-29 15:30:53 +0000 | [diff] [blame] | 327 | /** |
| 328 | * flash() - write the downloaded image to the indicated partition. |
| 329 | * |
| 330 | * @cmd_parameter: Pointer to partition name |
| 331 | * @response: Pointer to fastboot response buffer |
| 332 | * |
| 333 | * Writes the previously downloaded image to the partition indicated by |
| 334 | * cmd_parameter. Writes to response. |
| 335 | */ |
Patrick Delaunay | d037990 | 2022-12-15 10:15:50 +0100 | [diff] [blame] | 336 | static void __maybe_unused flash(char *cmd_parameter, char *response) |
Alex Kiernan | f73a7df | 2018-05-29 15:30:53 +0000 | [diff] [blame] | 337 | { |
Simon Glass | 637425b | 2023-12-14 21:19:04 -0700 | [diff] [blame] | 338 | void *buf = map_sysmem(fastboot_buf_addr, 0); |
| 339 | |
Simon Glass | 7cb10e5 | 2023-02-05 17:54:12 -0700 | [diff] [blame] | 340 | if (IS_ENABLED(CONFIG_FASTBOOT_FLASH_MMC)) |
Simon Glass | 637425b | 2023-12-14 21:19:04 -0700 | [diff] [blame] | 341 | fastboot_mmc_flash_write(cmd_parameter, buf, image_size, |
| 342 | response); |
Patrick Delaunay | d037990 | 2022-12-15 10:15:50 +0100 | [diff] [blame] | 343 | |
Simon Glass | c6228ed | 2023-02-05 17:54:13 -0700 | [diff] [blame] | 344 | if (IS_ENABLED(CONFIG_FASTBOOT_FLASH_NAND)) |
Simon Glass | 637425b | 2023-12-14 21:19:04 -0700 | [diff] [blame] | 345 | fastboot_nand_flash_write(cmd_parameter, buf, image_size, |
| 346 | response); |
| 347 | unmap_sysmem(buf); |
Alex Kiernan | f73a7df | 2018-05-29 15:30:53 +0000 | [diff] [blame] | 348 | } |
| 349 | |
| 350 | /** |
| 351 | * erase() - erase the indicated partition. |
| 352 | * |
| 353 | * @cmd_parameter: Pointer to partition name |
| 354 | * @response: Pointer to fastboot response buffer |
| 355 | * |
| 356 | * Erases the partition indicated by cmd_parameter (clear to 0x00s). Writes |
| 357 | * to response. |
| 358 | */ |
Patrick Delaunay | d037990 | 2022-12-15 10:15:50 +0100 | [diff] [blame] | 359 | static void __maybe_unused erase(char *cmd_parameter, char *response) |
Alex Kiernan | f73a7df | 2018-05-29 15:30:53 +0000 | [diff] [blame] | 360 | { |
Simon Glass | 7cb10e5 | 2023-02-05 17:54:12 -0700 | [diff] [blame] | 361 | if (IS_ENABLED(CONFIG_FASTBOOT_FLASH_MMC)) |
Patrick Delaunay | d037990 | 2022-12-15 10:15:50 +0100 | [diff] [blame] | 362 | fastboot_mmc_erase(cmd_parameter, response); |
Alex Kiernan | f73a7df | 2018-05-29 15:30:53 +0000 | [diff] [blame] | 363 | |
Simon Glass | c6228ed | 2023-02-05 17:54:13 -0700 | [diff] [blame] | 364 | if (IS_ENABLED(CONFIG_FASTBOOT_FLASH_NAND)) |
Patrick Delaunay | d037990 | 2022-12-15 10:15:50 +0100 | [diff] [blame] | 365 | fastboot_nand_erase(cmd_parameter, response); |
| 366 | } |
| 367 | |
Heiko Schocher | bc820d5 | 2021-02-10 09:29:03 +0100 | [diff] [blame] | 368 | /** |
| 369 | * run_ucmd() - Execute the UCmd command |
| 370 | * |
| 371 | * @cmd_parameter: Pointer to command parameter |
| 372 | * @response: Pointer to fastboot response buffer |
| 373 | */ |
Patrick Delaunay | d037990 | 2022-12-15 10:15:50 +0100 | [diff] [blame] | 374 | static void __maybe_unused run_ucmd(char *cmd_parameter, char *response) |
Heiko Schocher | bc820d5 | 2021-02-10 09:29:03 +0100 | [diff] [blame] | 375 | { |
| 376 | if (!cmd_parameter) { |
| 377 | pr_err("missing slot suffix\n"); |
| 378 | fastboot_fail("missing command", response); |
| 379 | return; |
| 380 | } |
| 381 | |
| 382 | if (run_command(cmd_parameter, 0)) |
| 383 | fastboot_fail("", response); |
| 384 | else |
| 385 | fastboot_okay(NULL, response); |
| 386 | } |
| 387 | |
| 388 | static char g_a_cmd_buff[64]; |
| 389 | |
| 390 | void fastboot_acmd_complete(void) |
| 391 | { |
| 392 | run_command(g_a_cmd_buff, 0); |
| 393 | } |
| 394 | |
| 395 | /** |
| 396 | * run_acmd() - Execute the ACmd command |
| 397 | * |
| 398 | * @cmd_parameter: Pointer to command parameter |
| 399 | * @response: Pointer to fastboot response buffer |
| 400 | */ |
Patrick Delaunay | d037990 | 2022-12-15 10:15:50 +0100 | [diff] [blame] | 401 | static void __maybe_unused run_acmd(char *cmd_parameter, char *response) |
Heiko Schocher | bc820d5 | 2021-02-10 09:29:03 +0100 | [diff] [blame] | 402 | { |
| 403 | if (!cmd_parameter) { |
| 404 | pr_err("missing slot suffix\n"); |
| 405 | fastboot_fail("missing command", response); |
| 406 | return; |
| 407 | } |
| 408 | |
| 409 | if (strlen(cmd_parameter) > sizeof(g_a_cmd_buff)) { |
| 410 | pr_err("too long command\n"); |
| 411 | fastboot_fail("too long command", response); |
| 412 | return; |
| 413 | } |
| 414 | |
| 415 | strcpy(g_a_cmd_buff, cmd_parameter); |
| 416 | fastboot_okay(NULL, response); |
| 417 | } |
Heiko Schocher | bc820d5 | 2021-02-10 09:29:03 +0100 | [diff] [blame] | 418 | |
Alex Kiernan | f73a7df | 2018-05-29 15:30:53 +0000 | [diff] [blame] | 419 | /** |
| 420 | * reboot_bootloader() - Sets reboot bootloader flag. |
| 421 | * |
| 422 | * @cmd_parameter: Pointer to command parameter |
| 423 | * @response: Pointer to fastboot response buffer |
| 424 | */ |
| 425 | static void reboot_bootloader(char *cmd_parameter, char *response) |
| 426 | { |
Roman Kovalivskyi | 851737a | 2020-07-28 23:35:32 +0300 | [diff] [blame] | 427 | if (fastboot_set_reboot_flag(FASTBOOT_REBOOT_REASON_BOOTLOADER)) |
Alex Kiernan | f73a7df | 2018-05-29 15:30:53 +0000 | [diff] [blame] | 428 | fastboot_fail("Cannot set reboot flag", response); |
| 429 | else |
| 430 | fastboot_okay(NULL, response); |
| 431 | } |
Alex Kiernan | 3845b90 | 2018-05-29 15:30:54 +0000 | [diff] [blame] | 432 | |
Roman Kovalivskyi | 2b2a771 | 2020-07-28 23:35:33 +0300 | [diff] [blame] | 433 | /** |
| 434 | * reboot_fastbootd() - Sets reboot fastboot flag. |
| 435 | * |
| 436 | * @cmd_parameter: Pointer to command parameter |
| 437 | * @response: Pointer to fastboot response buffer |
| 438 | */ |
| 439 | static void reboot_fastbootd(char *cmd_parameter, char *response) |
| 440 | { |
| 441 | if (fastboot_set_reboot_flag(FASTBOOT_REBOOT_REASON_FASTBOOTD)) |
| 442 | fastboot_fail("Cannot set fastboot flag", response); |
| 443 | else |
| 444 | fastboot_okay(NULL, response); |
| 445 | } |
| 446 | |
| 447 | /** |
| 448 | * reboot_recovery() - Sets reboot recovery flag. |
| 449 | * |
| 450 | * @cmd_parameter: Pointer to command parameter |
| 451 | * @response: Pointer to fastboot response buffer |
| 452 | */ |
| 453 | static void reboot_recovery(char *cmd_parameter, char *response) |
| 454 | { |
| 455 | if (fastboot_set_reboot_flag(FASTBOOT_REBOOT_REASON_RECOVERY)) |
| 456 | fastboot_fail("Cannot set recovery flag", response); |
| 457 | else |
| 458 | fastboot_okay(NULL, response); |
| 459 | } |
| 460 | |
Alex Kiernan | 3845b90 | 2018-05-29 15:30:54 +0000 | [diff] [blame] | 461 | /** |
| 462 | * oem_format() - Execute the OEM format command |
| 463 | * |
| 464 | * @cmd_parameter: Pointer to command parameter |
| 465 | * @response: Pointer to fastboot response buffer |
| 466 | */ |
Patrick Delaunay | d037990 | 2022-12-15 10:15:50 +0100 | [diff] [blame] | 467 | static void __maybe_unused oem_format(char *cmd_parameter, char *response) |
Alex Kiernan | 3845b90 | 2018-05-29 15:30:54 +0000 | [diff] [blame] | 468 | { |
| 469 | char cmdbuf[32]; |
Patrick Delaunay | d037990 | 2022-12-15 10:15:50 +0100 | [diff] [blame] | 470 | const int mmc_dev = config_opt_enabled(CONFIG_FASTBOOT_FLASH_MMC, |
| 471 | CONFIG_FASTBOOT_FLASH_MMC_DEV, -1); |
Alex Kiernan | 3845b90 | 2018-05-29 15:30:54 +0000 | [diff] [blame] | 472 | |
| 473 | if (!env_get("partitions")) { |
| 474 | fastboot_fail("partitions not set", response); |
| 475 | } else { |
Patrick Delaunay | d037990 | 2022-12-15 10:15:50 +0100 | [diff] [blame] | 476 | sprintf(cmdbuf, "gpt write mmc %x $partitions", mmc_dev); |
Alex Kiernan | 3845b90 | 2018-05-29 15:30:54 +0000 | [diff] [blame] | 477 | if (run_command(cmdbuf, 0)) |
| 478 | fastboot_fail("", response); |
| 479 | else |
| 480 | fastboot_okay(NULL, response); |
| 481 | } |
| 482 | } |
Patrick Delaunay | b2f6b97 | 2021-01-27 14:46:48 +0100 | [diff] [blame] | 483 | |
Patrick Delaunay | b2f6b97 | 2021-01-27 14:46:48 +0100 | [diff] [blame] | 484 | /** |
| 485 | * oem_partconf() - Execute the OEM partconf command |
| 486 | * |
| 487 | * @cmd_parameter: Pointer to command parameter |
| 488 | * @response: Pointer to fastboot response buffer |
| 489 | */ |
Patrick Delaunay | d037990 | 2022-12-15 10:15:50 +0100 | [diff] [blame] | 490 | static void __maybe_unused oem_partconf(char *cmd_parameter, char *response) |
Patrick Delaunay | b2f6b97 | 2021-01-27 14:46:48 +0100 | [diff] [blame] | 491 | { |
| 492 | char cmdbuf[32]; |
Patrick Delaunay | d037990 | 2022-12-15 10:15:50 +0100 | [diff] [blame] | 493 | const int mmc_dev = config_opt_enabled(CONFIG_FASTBOOT_FLASH_MMC, |
| 494 | CONFIG_FASTBOOT_FLASH_MMC_DEV, -1); |
Patrick Delaunay | b2f6b97 | 2021-01-27 14:46:48 +0100 | [diff] [blame] | 495 | |
| 496 | if (!cmd_parameter) { |
| 497 | fastboot_fail("Expected command parameter", response); |
| 498 | return; |
| 499 | } |
| 500 | |
| 501 | /* execute 'mmc partconfg' command with cmd_parameter arguments*/ |
Patrick Delaunay | d037990 | 2022-12-15 10:15:50 +0100 | [diff] [blame] | 502 | snprintf(cmdbuf, sizeof(cmdbuf), "mmc partconf %x %s 0", mmc_dev, cmd_parameter); |
Patrick Delaunay | b2f6b97 | 2021-01-27 14:46:48 +0100 | [diff] [blame] | 503 | printf("Execute: %s\n", cmdbuf); |
| 504 | if (run_command(cmdbuf, 0)) |
| 505 | fastboot_fail("Cannot set oem partconf", response); |
| 506 | else |
| 507 | fastboot_okay(NULL, response); |
| 508 | } |
Patrick Delaunay | 0c0394b | 2021-01-27 14:46:49 +0100 | [diff] [blame] | 509 | |
Patrick Delaunay | 0c0394b | 2021-01-27 14:46:49 +0100 | [diff] [blame] | 510 | /** |
| 511 | * oem_bootbus() - Execute the OEM bootbus command |
| 512 | * |
| 513 | * @cmd_parameter: Pointer to command parameter |
| 514 | * @response: Pointer to fastboot response buffer |
| 515 | */ |
Patrick Delaunay | d037990 | 2022-12-15 10:15:50 +0100 | [diff] [blame] | 516 | static void __maybe_unused oem_bootbus(char *cmd_parameter, char *response) |
Patrick Delaunay | 0c0394b | 2021-01-27 14:46:49 +0100 | [diff] [blame] | 517 | { |
| 518 | char cmdbuf[32]; |
Patrick Delaunay | d037990 | 2022-12-15 10:15:50 +0100 | [diff] [blame] | 519 | const int mmc_dev = config_opt_enabled(CONFIG_FASTBOOT_FLASH_MMC, |
| 520 | CONFIG_FASTBOOT_FLASH_MMC_DEV, -1); |
Patrick Delaunay | 0c0394b | 2021-01-27 14:46:49 +0100 | [diff] [blame] | 521 | |
| 522 | if (!cmd_parameter) { |
| 523 | fastboot_fail("Expected command parameter", response); |
| 524 | return; |
| 525 | } |
| 526 | |
| 527 | /* execute 'mmc bootbus' command with cmd_parameter arguments*/ |
Patrick Delaunay | d037990 | 2022-12-15 10:15:50 +0100 | [diff] [blame] | 528 | snprintf(cmdbuf, sizeof(cmdbuf), "mmc bootbus %x %s", mmc_dev, cmd_parameter); |
Patrick Delaunay | 0c0394b | 2021-01-27 14:46:49 +0100 | [diff] [blame] | 529 | printf("Execute: %s\n", cmdbuf); |
| 530 | if (run_command(cmdbuf, 0)) |
| 531 | fastboot_fail("Cannot set oem bootbus", response); |
| 532 | else |
| 533 | fastboot_okay(NULL, response); |
| 534 | } |
Ion Agorria | 16f79dd | 2024-01-05 09:22:11 +0200 | [diff] [blame] | 535 | |
| 536 | /** |
| 537 | * oem_console() - Execute the OEM console command |
| 538 | * |
| 539 | * @cmd_parameter: Pointer to command parameter |
| 540 | * @response: Pointer to fastboot response buffer |
| 541 | */ |
| 542 | static void __maybe_unused oem_console(char *cmd_parameter, char *response) |
| 543 | { |
| 544 | if (cmd_parameter) |
| 545 | console_in_puts(cmd_parameter); |
| 546 | |
| 547 | if (console_record_isempty()) |
| 548 | fastboot_fail("Empty console", response); |
| 549 | else |
| 550 | fastboot_response(FASTBOOT_MULTIRESPONSE_START, response, NULL); |
| 551 | } |