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> |
Simon Glass | 313112a | 2019-08-01 09:46:46 -0600 | [diff] [blame] | 8 | #include <env.h> |
Alex Kiernan | d5aa57c | 2018-05-29 15:30:53 +0000 | [diff] [blame] | 9 | #include <fastboot.h> |
| 10 | #include <fastboot-internal.h> |
| 11 | #include <fb_mmc.h> |
| 12 | #include <fb_nand.h> |
Simon Glass | ae4eb81 | 2023-12-14 21:19:04 -0700 | [diff] [blame] | 13 | #include <mapmem.h> |
Alex Kiernan | d5aa57c | 2018-05-29 15:30:53 +0000 | [diff] [blame] | 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 | |
| 156 | /** |
| 157 | * okay() - Send bare OKAY response |
| 158 | * |
| 159 | * @cmd_parameter: Pointer to command parameter |
| 160 | * @response: Pointer to fastboot response buffer |
| 161 | * |
| 162 | * Send a bare OKAY fastboot response. This is used where the command is |
| 163 | * valid, but all the work is done after the response has been sent (e.g. |
| 164 | * boot, reboot etc.) |
| 165 | */ |
| 166 | static void okay(char *cmd_parameter, char *response) |
| 167 | { |
| 168 | fastboot_okay(NULL, response); |
| 169 | } |
| 170 | |
| 171 | /** |
| 172 | * getvar() - Read a config/version variable |
| 173 | * |
| 174 | * @cmd_parameter: Pointer to command parameter |
| 175 | * @response: Pointer to fastboot response buffer |
| 176 | */ |
| 177 | static void getvar(char *cmd_parameter, char *response) |
| 178 | { |
| 179 | fastboot_getvar(cmd_parameter, response); |
| 180 | } |
| 181 | |
| 182 | /** |
| 183 | * fastboot_download() - Start a download transfer from the client |
| 184 | * |
| 185 | * @cmd_parameter: Pointer to command parameter |
| 186 | * @response: Pointer to fastboot response buffer |
| 187 | */ |
| 188 | static void download(char *cmd_parameter, char *response) |
| 189 | { |
| 190 | char *tmp; |
| 191 | |
| 192 | if (!cmd_parameter) { |
| 193 | fastboot_fail("Expected command parameter", response); |
| 194 | return; |
| 195 | } |
| 196 | fastboot_bytes_received = 0; |
Simon Glass | 3ff49ec | 2021-07-24 09:03:29 -0600 | [diff] [blame] | 197 | fastboot_bytes_expected = hextoul(cmd_parameter, &tmp); |
Alex Kiernan | d5aa57c | 2018-05-29 15:30:53 +0000 | [diff] [blame] | 198 | if (fastboot_bytes_expected == 0) { |
| 199 | fastboot_fail("Expected nonzero image size", response); |
| 200 | return; |
| 201 | } |
| 202 | /* |
| 203 | * Nothing to download yet. Response is of the form: |
| 204 | * [DATA|FAIL]$cmd_parameter |
| 205 | * |
| 206 | * where cmd_parameter is an 8 digit hexadecimal number |
| 207 | */ |
| 208 | if (fastboot_bytes_expected > fastboot_buf_size) { |
| 209 | fastboot_fail(cmd_parameter, response); |
| 210 | } else { |
| 211 | printf("Starting download of %d bytes\n", |
| 212 | fastboot_bytes_expected); |
| 213 | fastboot_response("DATA", response, "%s", cmd_parameter); |
| 214 | } |
| 215 | } |
| 216 | |
| 217 | /** |
| 218 | * fastboot_data_remaining() - return bytes remaining in current transfer |
| 219 | * |
| 220 | * Return: Number of bytes left in the current download |
| 221 | */ |
| 222 | u32 fastboot_data_remaining(void) |
| 223 | { |
| 224 | return fastboot_bytes_expected - fastboot_bytes_received; |
| 225 | } |
| 226 | |
| 227 | /** |
| 228 | * fastboot_data_download() - Copy image data to fastboot_buf_addr. |
| 229 | * |
| 230 | * @fastboot_data: Pointer to received fastboot data |
| 231 | * @fastboot_data_len: Length of received fastboot data |
| 232 | * @response: Pointer to fastboot response buffer |
| 233 | * |
| 234 | * Copies image data from fastboot_data to fastboot_buf_addr. Writes to |
| 235 | * response. fastboot_bytes_received is updated to indicate the number |
| 236 | * of bytes that have been transferred. |
| 237 | * |
| 238 | * On completion sets image_size and ${filesize} to the total size of the |
| 239 | * downloaded image. |
| 240 | */ |
| 241 | void fastboot_data_download(const void *fastboot_data, |
| 242 | unsigned int fastboot_data_len, |
| 243 | char *response) |
| 244 | { |
| 245 | #define BYTES_PER_DOT 0x20000 |
| 246 | u32 pre_dot_num, now_dot_num; |
Simon Glass | ae4eb81 | 2023-12-14 21:19:04 -0700 | [diff] [blame] | 247 | void *buf; |
Alex Kiernan | d5aa57c | 2018-05-29 15:30:53 +0000 | [diff] [blame] | 248 | |
| 249 | if (fastboot_data_len == 0 || |
| 250 | (fastboot_bytes_received + fastboot_data_len) > |
| 251 | fastboot_bytes_expected) { |
| 252 | fastboot_fail("Received invalid data length", |
| 253 | response); |
| 254 | return; |
| 255 | } |
| 256 | /* Download data to fastboot_buf_addr */ |
Simon Glass | ae4eb81 | 2023-12-14 21:19:04 -0700 | [diff] [blame] | 257 | buf = map_sysmem(fastboot_buf_addr, 0); |
| 258 | memcpy(buf + fastboot_bytes_received, |
Alex Kiernan | d5aa57c | 2018-05-29 15:30:53 +0000 | [diff] [blame] | 259 | fastboot_data, fastboot_data_len); |
Simon Glass | ae4eb81 | 2023-12-14 21:19:04 -0700 | [diff] [blame] | 260 | unmap_sysmem(buf); |
Alex Kiernan | d5aa57c | 2018-05-29 15:30:53 +0000 | [diff] [blame] | 261 | |
| 262 | pre_dot_num = fastboot_bytes_received / BYTES_PER_DOT; |
| 263 | fastboot_bytes_received += fastboot_data_len; |
| 264 | now_dot_num = fastboot_bytes_received / BYTES_PER_DOT; |
| 265 | |
| 266 | if (pre_dot_num != now_dot_num) { |
| 267 | putc('.'); |
| 268 | if (!(now_dot_num % 74)) |
| 269 | putc('\n'); |
| 270 | } |
| 271 | *response = '\0'; |
| 272 | } |
| 273 | |
| 274 | /** |
| 275 | * fastboot_data_complete() - Mark current transfer complete |
| 276 | * |
| 277 | * @response: Pointer to fastboot response buffer |
| 278 | * |
| 279 | * Set image_size and ${filesize} to the total size of the downloaded image. |
| 280 | */ |
| 281 | void fastboot_data_complete(char *response) |
| 282 | { |
| 283 | /* Download complete. Respond with "OKAY" */ |
| 284 | fastboot_okay(NULL, response); |
| 285 | printf("\ndownloading of %d bytes finished\n", fastboot_bytes_received); |
| 286 | image_size = fastboot_bytes_received; |
| 287 | env_set_hex("filesize", image_size); |
| 288 | fastboot_bytes_expected = 0; |
| 289 | fastboot_bytes_received = 0; |
| 290 | } |
| 291 | |
Alex Kiernan | d5aa57c | 2018-05-29 15:30:53 +0000 | [diff] [blame] | 292 | /** |
| 293 | * flash() - write the downloaded image to the indicated partition. |
| 294 | * |
| 295 | * @cmd_parameter: Pointer to partition name |
| 296 | * @response: Pointer to fastboot response buffer |
| 297 | * |
| 298 | * Writes the previously downloaded image to the partition indicated by |
| 299 | * cmd_parameter. Writes to response. |
| 300 | */ |
Patrick Delaunay | f82f9e4 | 2022-12-15 10:15:50 +0100 | [diff] [blame] | 301 | static void __maybe_unused flash(char *cmd_parameter, char *response) |
Alex Kiernan | d5aa57c | 2018-05-29 15:30:53 +0000 | [diff] [blame] | 302 | { |
Simon Glass | ae4eb81 | 2023-12-14 21:19:04 -0700 | [diff] [blame] | 303 | void *buf = map_sysmem(fastboot_buf_addr, 0); |
| 304 | |
Simon Glass | 091a071 | 2023-02-05 17:54:12 -0700 | [diff] [blame] | 305 | if (IS_ENABLED(CONFIG_FASTBOOT_FLASH_MMC)) |
Simon Glass | ae4eb81 | 2023-12-14 21:19:04 -0700 | [diff] [blame] | 306 | fastboot_mmc_flash_write(cmd_parameter, buf, image_size, |
| 307 | response); |
Patrick Delaunay | f82f9e4 | 2022-12-15 10:15:50 +0100 | [diff] [blame] | 308 | |
Simon Glass | 06799593 | 2023-02-05 17:54:13 -0700 | [diff] [blame] | 309 | if (IS_ENABLED(CONFIG_FASTBOOT_FLASH_NAND)) |
Simon Glass | ae4eb81 | 2023-12-14 21:19:04 -0700 | [diff] [blame] | 310 | fastboot_nand_flash_write(cmd_parameter, buf, image_size, |
| 311 | response); |
| 312 | unmap_sysmem(buf); |
Alex Kiernan | d5aa57c | 2018-05-29 15:30:53 +0000 | [diff] [blame] | 313 | } |
| 314 | |
| 315 | /** |
| 316 | * erase() - erase the indicated partition. |
| 317 | * |
| 318 | * @cmd_parameter: Pointer to partition name |
| 319 | * @response: Pointer to fastboot response buffer |
| 320 | * |
| 321 | * Erases the partition indicated by cmd_parameter (clear to 0x00s). Writes |
| 322 | * to response. |
| 323 | */ |
Patrick Delaunay | f82f9e4 | 2022-12-15 10:15:50 +0100 | [diff] [blame] | 324 | static void __maybe_unused erase(char *cmd_parameter, char *response) |
Alex Kiernan | d5aa57c | 2018-05-29 15:30:53 +0000 | [diff] [blame] | 325 | { |
Simon Glass | 091a071 | 2023-02-05 17:54:12 -0700 | [diff] [blame] | 326 | if (IS_ENABLED(CONFIG_FASTBOOT_FLASH_MMC)) |
Patrick Delaunay | f82f9e4 | 2022-12-15 10:15:50 +0100 | [diff] [blame] | 327 | fastboot_mmc_erase(cmd_parameter, response); |
| 328 | |
Simon Glass | 06799593 | 2023-02-05 17:54:13 -0700 | [diff] [blame] | 329 | if (IS_ENABLED(CONFIG_FASTBOOT_FLASH_NAND)) |
Patrick Delaunay | f82f9e4 | 2022-12-15 10:15:50 +0100 | [diff] [blame] | 330 | fastboot_nand_erase(cmd_parameter, response); |
Alex Kiernan | d5aa57c | 2018-05-29 15:30:53 +0000 | [diff] [blame] | 331 | } |
Alex Kiernan | d5aa57c | 2018-05-29 15:30:53 +0000 | [diff] [blame] | 332 | |
Heiko Schocher | 3a99448 | 2021-02-10 09:29:03 +0100 | [diff] [blame] | 333 | /** |
| 334 | * run_ucmd() - Execute the UCmd command |
| 335 | * |
| 336 | * @cmd_parameter: Pointer to command parameter |
| 337 | * @response: Pointer to fastboot response buffer |
| 338 | */ |
Patrick Delaunay | f82f9e4 | 2022-12-15 10:15:50 +0100 | [diff] [blame] | 339 | static void __maybe_unused run_ucmd(char *cmd_parameter, char *response) |
Heiko Schocher | 3a99448 | 2021-02-10 09:29:03 +0100 | [diff] [blame] | 340 | { |
| 341 | if (!cmd_parameter) { |
| 342 | pr_err("missing slot suffix\n"); |
| 343 | fastboot_fail("missing command", response); |
| 344 | return; |
| 345 | } |
| 346 | |
| 347 | if (run_command(cmd_parameter, 0)) |
| 348 | fastboot_fail("", response); |
| 349 | else |
| 350 | fastboot_okay(NULL, response); |
| 351 | } |
| 352 | |
| 353 | static char g_a_cmd_buff[64]; |
| 354 | |
| 355 | void fastboot_acmd_complete(void) |
| 356 | { |
| 357 | run_command(g_a_cmd_buff, 0); |
| 358 | } |
| 359 | |
| 360 | /** |
| 361 | * run_acmd() - Execute the ACmd command |
| 362 | * |
| 363 | * @cmd_parameter: Pointer to command parameter |
| 364 | * @response: Pointer to fastboot response buffer |
| 365 | */ |
Patrick Delaunay | f82f9e4 | 2022-12-15 10:15:50 +0100 | [diff] [blame] | 366 | static void __maybe_unused run_acmd(char *cmd_parameter, char *response) |
Heiko Schocher | 3a99448 | 2021-02-10 09:29:03 +0100 | [diff] [blame] | 367 | { |
| 368 | if (!cmd_parameter) { |
| 369 | pr_err("missing slot suffix\n"); |
| 370 | fastboot_fail("missing command", response); |
| 371 | return; |
| 372 | } |
| 373 | |
| 374 | if (strlen(cmd_parameter) > sizeof(g_a_cmd_buff)) { |
| 375 | pr_err("too long command\n"); |
| 376 | fastboot_fail("too long command", response); |
| 377 | return; |
| 378 | } |
| 379 | |
| 380 | strcpy(g_a_cmd_buff, cmd_parameter); |
| 381 | fastboot_okay(NULL, response); |
| 382 | } |
Heiko Schocher | 3a99448 | 2021-02-10 09:29:03 +0100 | [diff] [blame] | 383 | |
Alex Kiernan | d5aa57c | 2018-05-29 15:30:53 +0000 | [diff] [blame] | 384 | /** |
| 385 | * reboot_bootloader() - Sets reboot bootloader flag. |
| 386 | * |
| 387 | * @cmd_parameter: Pointer to command parameter |
| 388 | * @response: Pointer to fastboot response buffer |
| 389 | */ |
| 390 | static void reboot_bootloader(char *cmd_parameter, char *response) |
| 391 | { |
Roman Kovalivskyi | 1bb1342 | 2020-07-28 23:35:32 +0300 | [diff] [blame] | 392 | if (fastboot_set_reboot_flag(FASTBOOT_REBOOT_REASON_BOOTLOADER)) |
Alex Kiernan | d5aa57c | 2018-05-29 15:30:53 +0000 | [diff] [blame] | 393 | fastboot_fail("Cannot set reboot flag", response); |
| 394 | else |
| 395 | fastboot_okay(NULL, response); |
| 396 | } |
Alex Kiernan | c86cde9 | 2018-05-29 15:30:54 +0000 | [diff] [blame] | 397 | |
Roman Kovalivskyi | b30b97b | 2020-07-28 23:35:33 +0300 | [diff] [blame] | 398 | /** |
| 399 | * reboot_fastbootd() - Sets reboot fastboot flag. |
| 400 | * |
| 401 | * @cmd_parameter: Pointer to command parameter |
| 402 | * @response: Pointer to fastboot response buffer |
| 403 | */ |
| 404 | static void reboot_fastbootd(char *cmd_parameter, char *response) |
| 405 | { |
| 406 | if (fastboot_set_reboot_flag(FASTBOOT_REBOOT_REASON_FASTBOOTD)) |
| 407 | fastboot_fail("Cannot set fastboot flag", response); |
| 408 | else |
| 409 | fastboot_okay(NULL, response); |
| 410 | } |
| 411 | |
| 412 | /** |
| 413 | * reboot_recovery() - Sets reboot recovery flag. |
| 414 | * |
| 415 | * @cmd_parameter: Pointer to command parameter |
| 416 | * @response: Pointer to fastboot response buffer |
| 417 | */ |
| 418 | static void reboot_recovery(char *cmd_parameter, char *response) |
| 419 | { |
| 420 | if (fastboot_set_reboot_flag(FASTBOOT_REBOOT_REASON_RECOVERY)) |
| 421 | fastboot_fail("Cannot set recovery flag", response); |
| 422 | else |
| 423 | fastboot_okay(NULL, response); |
| 424 | } |
| 425 | |
Alex Kiernan | c86cde9 | 2018-05-29 15:30:54 +0000 | [diff] [blame] | 426 | /** |
| 427 | * oem_format() - Execute the OEM format command |
| 428 | * |
| 429 | * @cmd_parameter: Pointer to command parameter |
| 430 | * @response: Pointer to fastboot response buffer |
| 431 | */ |
Patrick Delaunay | f82f9e4 | 2022-12-15 10:15:50 +0100 | [diff] [blame] | 432 | static void __maybe_unused oem_format(char *cmd_parameter, char *response) |
Alex Kiernan | c86cde9 | 2018-05-29 15:30:54 +0000 | [diff] [blame] | 433 | { |
| 434 | char cmdbuf[32]; |
Patrick Delaunay | f82f9e4 | 2022-12-15 10:15:50 +0100 | [diff] [blame] | 435 | const int mmc_dev = config_opt_enabled(CONFIG_FASTBOOT_FLASH_MMC, |
| 436 | CONFIG_FASTBOOT_FLASH_MMC_DEV, -1); |
Alex Kiernan | c86cde9 | 2018-05-29 15:30:54 +0000 | [diff] [blame] | 437 | |
| 438 | if (!env_get("partitions")) { |
| 439 | fastboot_fail("partitions not set", response); |
| 440 | } else { |
Patrick Delaunay | f82f9e4 | 2022-12-15 10:15:50 +0100 | [diff] [blame] | 441 | sprintf(cmdbuf, "gpt write mmc %x $partitions", mmc_dev); |
Alex Kiernan | c86cde9 | 2018-05-29 15:30:54 +0000 | [diff] [blame] | 442 | if (run_command(cmdbuf, 0)) |
| 443 | fastboot_fail("", response); |
| 444 | else |
| 445 | fastboot_okay(NULL, response); |
| 446 | } |
| 447 | } |
Patrick Delaunay | 6168770 | 2021-01-27 14:46:48 +0100 | [diff] [blame] | 448 | |
Patrick Delaunay | 6168770 | 2021-01-27 14:46:48 +0100 | [diff] [blame] | 449 | /** |
| 450 | * oem_partconf() - Execute the OEM partconf command |
| 451 | * |
| 452 | * @cmd_parameter: Pointer to command parameter |
| 453 | * @response: Pointer to fastboot response buffer |
| 454 | */ |
Patrick Delaunay | f82f9e4 | 2022-12-15 10:15:50 +0100 | [diff] [blame] | 455 | static void __maybe_unused oem_partconf(char *cmd_parameter, char *response) |
Patrick Delaunay | 6168770 | 2021-01-27 14:46:48 +0100 | [diff] [blame] | 456 | { |
| 457 | char cmdbuf[32]; |
Patrick Delaunay | f82f9e4 | 2022-12-15 10:15:50 +0100 | [diff] [blame] | 458 | const int mmc_dev = config_opt_enabled(CONFIG_FASTBOOT_FLASH_MMC, |
| 459 | CONFIG_FASTBOOT_FLASH_MMC_DEV, -1); |
Patrick Delaunay | 6168770 | 2021-01-27 14:46:48 +0100 | [diff] [blame] | 460 | |
| 461 | if (!cmd_parameter) { |
| 462 | fastboot_fail("Expected command parameter", response); |
| 463 | return; |
| 464 | } |
| 465 | |
| 466 | /* execute 'mmc partconfg' command with cmd_parameter arguments*/ |
Patrick Delaunay | f82f9e4 | 2022-12-15 10:15:50 +0100 | [diff] [blame] | 467 | 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] | 468 | printf("Execute: %s\n", cmdbuf); |
| 469 | if (run_command(cmdbuf, 0)) |
| 470 | fastboot_fail("Cannot set oem partconf", response); |
| 471 | else |
| 472 | fastboot_okay(NULL, response); |
| 473 | } |
Patrick Delaunay | 67af29a | 2021-01-27 14:46:49 +0100 | [diff] [blame] | 474 | |
Patrick Delaunay | 67af29a | 2021-01-27 14:46:49 +0100 | [diff] [blame] | 475 | /** |
| 476 | * oem_bootbus() - Execute the OEM bootbus command |
| 477 | * |
| 478 | * @cmd_parameter: Pointer to command parameter |
| 479 | * @response: Pointer to fastboot response buffer |
| 480 | */ |
Patrick Delaunay | f82f9e4 | 2022-12-15 10:15:50 +0100 | [diff] [blame] | 481 | static void __maybe_unused oem_bootbus(char *cmd_parameter, char *response) |
Patrick Delaunay | 67af29a | 2021-01-27 14:46:49 +0100 | [diff] [blame] | 482 | { |
| 483 | char cmdbuf[32]; |
Patrick Delaunay | f82f9e4 | 2022-12-15 10:15:50 +0100 | [diff] [blame] | 484 | const int mmc_dev = config_opt_enabled(CONFIG_FASTBOOT_FLASH_MMC, |
| 485 | CONFIG_FASTBOOT_FLASH_MMC_DEV, -1); |
Patrick Delaunay | 67af29a | 2021-01-27 14:46:49 +0100 | [diff] [blame] | 486 | |
| 487 | if (!cmd_parameter) { |
| 488 | fastboot_fail("Expected command parameter", response); |
| 489 | return; |
| 490 | } |
| 491 | |
| 492 | /* execute 'mmc bootbus' command with cmd_parameter arguments*/ |
Patrick Delaunay | f82f9e4 | 2022-12-15 10:15:50 +0100 | [diff] [blame] | 493 | snprintf(cmdbuf, sizeof(cmdbuf), "mmc bootbus %x %s", mmc_dev, cmd_parameter); |
Patrick Delaunay | 67af29a | 2021-01-27 14:46:49 +0100 | [diff] [blame] | 494 | printf("Execute: %s\n", cmdbuf); |
| 495 | if (run_command(cmdbuf, 0)) |
| 496 | fastboot_fail("Cannot set oem bootbus", response); |
| 497 | else |
| 498 | fastboot_okay(NULL, response); |
| 499 | } |