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