blob: b8782bfa7fa95047ab8c8920693580a75d85ba64 [file] [log] [blame]
Alex Kiernanf73a7df2018-05-29 15:30:53 +00001// SPDX-License-Identifier: BSD-2-Clause
2/*
3 * Copyright (C) 2016 The Android Open Source Project
4 */
5
6#include <common.h>
Simon Glass288b29e2019-11-14 12:57:43 -07007#include <command.h>
Ion Agorria85fcd692024-01-05 09:22:06 +02008#include <console.h>
Simon Glassc7694dd2019-08-01 09:46:46 -06009#include <env.h>
Alex Kiernanf73a7df2018-05-29 15:30:53 +000010#include <fastboot.h>
11#include <fastboot-internal.h>
12#include <fb_mmc.h>
13#include <fb_nand.h>
Simon Glass637425b2023-12-14 21:19:04 -070014#include <mapmem.h>
Alex Kiernanf73a7df2018-05-29 15:30:53 +000015#include <part.h>
16#include <stdlib.h>
Simon Glass1e94b462023-09-14 18:21:46 -060017#include <linux/printk.h>
Alex Kiernanf73a7df2018-05-29 15:30:53 +000018
19/**
20 * image_size - final fastboot image size
21 */
22static u32 image_size;
23
24/**
25 * fastboot_bytes_received - number of bytes received in the current download
26 */
27static u32 fastboot_bytes_received;
28
29/**
30 * fastboot_bytes_expected - number of bytes expected in the current download
31 */
32static u32 fastboot_bytes_expected;
33
34static void okay(char *, char *);
35static void getvar(char *, char *);
36static void download(char *, char *);
Alex Kiernanf73a7df2018-05-29 15:30:53 +000037static void flash(char *, char *);
38static void erase(char *, char *);
Alex Kiernanf73a7df2018-05-29 15:30:53 +000039static void reboot_bootloader(char *, char *);
Roman Kovalivskyi2b2a7712020-07-28 23:35:33 +030040static void reboot_fastbootd(char *, char *);
41static void reboot_recovery(char *, char *);
Alex Kiernan3845b902018-05-29 15:30:54 +000042static void oem_format(char *, char *);
Patrick Delaunayb2f6b972021-01-27 14:46:48 +010043static void oem_partconf(char *, char *);
Patrick Delaunay0c0394b2021-01-27 14:46:49 +010044static void oem_bootbus(char *, char *);
Ion Agorria16f79dd2024-01-05 09:22:11 +020045static void oem_console(char *, char *);
Heiko Schocherbc820d52021-02-10 09:29:03 +010046static void run_ucmd(char *, char *);
47static void run_acmd(char *, char *);
Heiko Schocherbc820d52021-02-10 09:29:03 +010048
Alex Kiernanf73a7df2018-05-29 15:30:53 +000049static 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 Kiernanf73a7df2018-05-29 15:30:53 +000061 [FASTBOOT_COMMAND_FLASH] = {
62 .command = "flash",
Patrick Delaunayd0379902022-12-15 10:15:50 +010063 .dispatch = CONFIG_IS_ENABLED(FASTBOOT_FLASH, (flash), (NULL))
Alex Kiernanf73a7df2018-05-29 15:30:53 +000064 },
65 [FASTBOOT_COMMAND_ERASE] = {
66 .command = "erase",
Patrick Delaunayd0379902022-12-15 10:15:50 +010067 .dispatch = CONFIG_IS_ENABLED(FASTBOOT_FLASH, (erase), (NULL))
Alex Kiernanf73a7df2018-05-29 15:30:53 +000068 },
Alex Kiernanf73a7df2018-05-29 15:30:53 +000069 [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 Kovalivskyi2b2a7712020-07-28 23:35:33 +030085 [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 Kiernanf73a7df2018-05-29 15:30:53 +000093 [FASTBOOT_COMMAND_SET_ACTIVE] = {
94 .command = "set_active",
95 .dispatch = okay
96 },
Alex Kiernan3845b902018-05-29 15:30:54 +000097 [FASTBOOT_COMMAND_OEM_FORMAT] = {
98 .command = "oem format",
Patrick Delaunayd0379902022-12-15 10:15:50 +010099 .dispatch = CONFIG_IS_ENABLED(FASTBOOT_CMD_OEM_FORMAT, (oem_format), (NULL))
Alex Kiernan3845b902018-05-29 15:30:54 +0000100 },
Patrick Delaunayb2f6b972021-01-27 14:46:48 +0100101 [FASTBOOT_COMMAND_OEM_PARTCONF] = {
102 .command = "oem partconf",
Patrick Delaunayd0379902022-12-15 10:15:50 +0100103 .dispatch = CONFIG_IS_ENABLED(FASTBOOT_CMD_OEM_PARTCONF, (oem_partconf), (NULL))
Patrick Delaunayb2f6b972021-01-27 14:46:48 +0100104 },
Patrick Delaunay0c0394b2021-01-27 14:46:49 +0100105 [FASTBOOT_COMMAND_OEM_BOOTBUS] = {
106 .command = "oem bootbus",
Patrick Delaunayd0379902022-12-15 10:15:50 +0100107 .dispatch = CONFIG_IS_ENABLED(FASTBOOT_CMD_OEM_BOOTBUS, (oem_bootbus), (NULL))
Patrick Delaunay0c0394b2021-01-27 14:46:49 +0100108 },
Sean Andersonf3d914c2022-12-16 13:20:16 -0500109 [FASTBOOT_COMMAND_OEM_RUN] = {
110 .command = "oem run",
111 .dispatch = CONFIG_IS_ENABLED(FASTBOOT_OEM_RUN, (run_ucmd), (NULL))
112 },
Ion Agorria16f79dd2024-01-05 09:22:11 +0200113 [FASTBOOT_COMMAND_OEM_CONSOLE] = {
114 .command = "oem console",
115 .dispatch = CONFIG_IS_ENABLED(FASTBOOT_CMD_OEM_CONSOLE, (oem_console), (NULL))
116 },
Heiko Schocherbc820d52021-02-10 09:29:03 +0100117 [FASTBOOT_COMMAND_UCMD] = {
118 .command = "UCmd",
Patrick Delaunayd0379902022-12-15 10:15:50 +0100119 .dispatch = CONFIG_IS_ENABLED(FASTBOOT_UUU_SUPPORT, (run_ucmd), (NULL))
Heiko Schocherbc820d52021-02-10 09:29:03 +0100120 },
121 [FASTBOOT_COMMAND_ACMD] = {
122 .command = "ACmd",
Patrick Delaunayd0379902022-12-15 10:15:50 +0100123 .dispatch = CONFIG_IS_ENABLED(FASTBOOT_UUU_SUPPORT, (run_acmd), (NULL))
Heiko Schocherbc820d52021-02-10 09:29:03 +0100124 },
Alex Kiernanf73a7df2018-05-29 15:30:53 +0000125};
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 */
135int 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 Delaunayd0379902022-12-15 10:15:50 +0100150 pr_err("command %s not supported.\n", cmd_string);
151 fastboot_fail("Unsupported command", response);
152 return -1;
Alex Kiernanf73a7df2018-05-29 15:30:53 +0000153 }
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 Agorria85fcd692024-01-05 09:22:06 +0200162void fastboot_multiresponse(int cmd, char *response)
163{
164 switch (cmd) {
Ion Agorria475aa9a2024-01-05 09:22:07 +0200165 case FASTBOOT_COMMAND_GETVAR:
166 fastboot_getvar_all(response);
167 break;
Ion Agorria16f79dd2024-01-05 09:22:11 +0200168 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 Agorria85fcd692024-01-05 09:22:06 +0200185 default:
186 fastboot_fail("Unknown multiresponse command", response);
187 break;
188 }
189}
190
Alex Kiernanf73a7df2018-05-29 15:30:53 +0000191/**
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 */
201static 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 */
212static 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 */
223static 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 Glass7e5f4602021-07-24 09:03:29 -0600232 fastboot_bytes_expected = hextoul(cmd_parameter, &tmp);
Alex Kiernanf73a7df2018-05-29 15:30:53 +0000233 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 */
257u32 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 */
276void 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 Glass637425b2023-12-14 21:19:04 -0700282 void *buf;
Alex Kiernanf73a7df2018-05-29 15:30:53 +0000283
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 Glass637425b2023-12-14 21:19:04 -0700292 buf = map_sysmem(fastboot_buf_addr, 0);
293 memcpy(buf + fastboot_bytes_received,
Alex Kiernanf73a7df2018-05-29 15:30:53 +0000294 fastboot_data, fastboot_data_len);
Simon Glass637425b2023-12-14 21:19:04 -0700295 unmap_sysmem(buf);
Alex Kiernanf73a7df2018-05-29 15:30:53 +0000296
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 */
316void 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 Kiernanf73a7df2018-05-29 15:30:53 +0000327/**
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 Delaunayd0379902022-12-15 10:15:50 +0100336static void __maybe_unused flash(char *cmd_parameter, char *response)
Alex Kiernanf73a7df2018-05-29 15:30:53 +0000337{
Simon Glass637425b2023-12-14 21:19:04 -0700338 void *buf = map_sysmem(fastboot_buf_addr, 0);
339
Simon Glass7cb10e52023-02-05 17:54:12 -0700340 if (IS_ENABLED(CONFIG_FASTBOOT_FLASH_MMC))
Simon Glass637425b2023-12-14 21:19:04 -0700341 fastboot_mmc_flash_write(cmd_parameter, buf, image_size,
342 response);
Patrick Delaunayd0379902022-12-15 10:15:50 +0100343
Simon Glassc6228ed2023-02-05 17:54:13 -0700344 if (IS_ENABLED(CONFIG_FASTBOOT_FLASH_NAND))
Simon Glass637425b2023-12-14 21:19:04 -0700345 fastboot_nand_flash_write(cmd_parameter, buf, image_size,
346 response);
347 unmap_sysmem(buf);
Alex Kiernanf73a7df2018-05-29 15:30:53 +0000348}
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 Delaunayd0379902022-12-15 10:15:50 +0100359static void __maybe_unused erase(char *cmd_parameter, char *response)
Alex Kiernanf73a7df2018-05-29 15:30:53 +0000360{
Simon Glass7cb10e52023-02-05 17:54:12 -0700361 if (IS_ENABLED(CONFIG_FASTBOOT_FLASH_MMC))
Patrick Delaunayd0379902022-12-15 10:15:50 +0100362 fastboot_mmc_erase(cmd_parameter, response);
Alex Kiernanf73a7df2018-05-29 15:30:53 +0000363
Simon Glassc6228ed2023-02-05 17:54:13 -0700364 if (IS_ENABLED(CONFIG_FASTBOOT_FLASH_NAND))
Patrick Delaunayd0379902022-12-15 10:15:50 +0100365 fastboot_nand_erase(cmd_parameter, response);
366}
367
Heiko Schocherbc820d52021-02-10 09:29:03 +0100368/**
369 * run_ucmd() - Execute the UCmd command
370 *
371 * @cmd_parameter: Pointer to command parameter
372 * @response: Pointer to fastboot response buffer
373 */
Patrick Delaunayd0379902022-12-15 10:15:50 +0100374static void __maybe_unused run_ucmd(char *cmd_parameter, char *response)
Heiko Schocherbc820d52021-02-10 09:29:03 +0100375{
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
388static char g_a_cmd_buff[64];
389
390void 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 Delaunayd0379902022-12-15 10:15:50 +0100401static void __maybe_unused run_acmd(char *cmd_parameter, char *response)
Heiko Schocherbc820d52021-02-10 09:29:03 +0100402{
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 Schocherbc820d52021-02-10 09:29:03 +0100418
Alex Kiernanf73a7df2018-05-29 15:30:53 +0000419/**
420 * reboot_bootloader() - Sets reboot bootloader flag.
421 *
422 * @cmd_parameter: Pointer to command parameter
423 * @response: Pointer to fastboot response buffer
424 */
425static void reboot_bootloader(char *cmd_parameter, char *response)
426{
Roman Kovalivskyi851737a2020-07-28 23:35:32 +0300427 if (fastboot_set_reboot_flag(FASTBOOT_REBOOT_REASON_BOOTLOADER))
Alex Kiernanf73a7df2018-05-29 15:30:53 +0000428 fastboot_fail("Cannot set reboot flag", response);
429 else
430 fastboot_okay(NULL, response);
431}
Alex Kiernan3845b902018-05-29 15:30:54 +0000432
Roman Kovalivskyi2b2a7712020-07-28 23:35:33 +0300433/**
434 * reboot_fastbootd() - Sets reboot fastboot flag.
435 *
436 * @cmd_parameter: Pointer to command parameter
437 * @response: Pointer to fastboot response buffer
438 */
439static 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 */
453static 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 Kiernan3845b902018-05-29 15:30:54 +0000461/**
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 Delaunayd0379902022-12-15 10:15:50 +0100467static void __maybe_unused oem_format(char *cmd_parameter, char *response)
Alex Kiernan3845b902018-05-29 15:30:54 +0000468{
469 char cmdbuf[32];
Patrick Delaunayd0379902022-12-15 10:15:50 +0100470 const int mmc_dev = config_opt_enabled(CONFIG_FASTBOOT_FLASH_MMC,
471 CONFIG_FASTBOOT_FLASH_MMC_DEV, -1);
Alex Kiernan3845b902018-05-29 15:30:54 +0000472
473 if (!env_get("partitions")) {
474 fastboot_fail("partitions not set", response);
475 } else {
Patrick Delaunayd0379902022-12-15 10:15:50 +0100476 sprintf(cmdbuf, "gpt write mmc %x $partitions", mmc_dev);
Alex Kiernan3845b902018-05-29 15:30:54 +0000477 if (run_command(cmdbuf, 0))
478 fastboot_fail("", response);
479 else
480 fastboot_okay(NULL, response);
481 }
482}
Patrick Delaunayb2f6b972021-01-27 14:46:48 +0100483
Patrick Delaunayb2f6b972021-01-27 14:46:48 +0100484/**
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 Delaunayd0379902022-12-15 10:15:50 +0100490static void __maybe_unused oem_partconf(char *cmd_parameter, char *response)
Patrick Delaunayb2f6b972021-01-27 14:46:48 +0100491{
492 char cmdbuf[32];
Patrick Delaunayd0379902022-12-15 10:15:50 +0100493 const int mmc_dev = config_opt_enabled(CONFIG_FASTBOOT_FLASH_MMC,
494 CONFIG_FASTBOOT_FLASH_MMC_DEV, -1);
Patrick Delaunayb2f6b972021-01-27 14:46:48 +0100495
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 Delaunayd0379902022-12-15 10:15:50 +0100502 snprintf(cmdbuf, sizeof(cmdbuf), "mmc partconf %x %s 0", mmc_dev, cmd_parameter);
Patrick Delaunayb2f6b972021-01-27 14:46:48 +0100503 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 Delaunay0c0394b2021-01-27 14:46:49 +0100509
Patrick Delaunay0c0394b2021-01-27 14:46:49 +0100510/**
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 Delaunayd0379902022-12-15 10:15:50 +0100516static void __maybe_unused oem_bootbus(char *cmd_parameter, char *response)
Patrick Delaunay0c0394b2021-01-27 14:46:49 +0100517{
518 char cmdbuf[32];
Patrick Delaunayd0379902022-12-15 10:15:50 +0100519 const int mmc_dev = config_opt_enabled(CONFIG_FASTBOOT_FLASH_MMC,
520 CONFIG_FASTBOOT_FLASH_MMC_DEV, -1);
Patrick Delaunay0c0394b2021-01-27 14:46:49 +0100521
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 Delaunayd0379902022-12-15 10:15:50 +0100528 snprintf(cmdbuf, sizeof(cmdbuf), "mmc bootbus %x %s", mmc_dev, cmd_parameter);
Patrick Delaunay0c0394b2021-01-27 14:46:49 +0100529 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 Agorria16f79dd2024-01-05 09:22:11 +0200535
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 */
542static 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}