blob: 2cdbac50ac4a0ce501753e95c1918ffa5d11158d [file] [log] [blame]
Alex Kiernand5aa57c2018-05-29 15:30:53 +00001// SPDX-License-Identifier: BSD-2-Clause
2/*
3 * Copyright (C) 2016 The Android Open Source Project
4 */
5
Simon Glassadaaa482019-11-14 12:57:43 -07006#include <command.h>
Ion Agorria1c387032024-01-05 09:22:06 +02007#include <console.h>
Simon Glass313112a2019-08-01 09:46:46 -06008#include <env.h>
Alex Kiernand5aa57c2018-05-29 15:30:53 +00009#include <fastboot.h>
10#include <fastboot-internal.h>
11#include <fb_mmc.h>
12#include <fb_nand.h>
13#include <part.h>
14#include <stdlib.h>
Tom Rinidec7ea02024-05-20 13:35:03 -060015#include <vsprintf.h>
Simon Glassbdd5f812023-09-14 18:21:46 -060016#include <linux/printk.h>
Alex Kiernand5aa57c2018-05-29 15:30:53 +000017
18/**
19 * image_size - final fastboot image size
20 */
21static u32 image_size;
22
23/**
24 * fastboot_bytes_received - number of bytes received in the current download
25 */
26static u32 fastboot_bytes_received;
27
28/**
29 * fastboot_bytes_expected - number of bytes expected in the current download
30 */
31static u32 fastboot_bytes_expected;
32
33static void okay(char *, char *);
34static void getvar(char *, char *);
35static void download(char *, char *);
Alex Kiernand5aa57c2018-05-29 15:30:53 +000036static void flash(char *, char *);
37static void erase(char *, char *);
Alex Kiernand5aa57c2018-05-29 15:30:53 +000038static void reboot_bootloader(char *, char *);
Roman Kovalivskyib30b97b2020-07-28 23:35:33 +030039static void reboot_fastbootd(char *, char *);
40static void reboot_recovery(char *, char *);
Alex Kiernanc86cde92018-05-29 15:30:54 +000041static void oem_format(char *, char *);
Patrick Delaunay61687702021-01-27 14:46:48 +010042static void oem_partconf(char *, char *);
Patrick Delaunay67af29a2021-01-27 14:46:49 +010043static void oem_bootbus(char *, char *);
Ion Agorriae64262d2024-01-05 09:22:11 +020044static void oem_console(char *, char *);
Alexey Romanova0ae7902024-04-18 13:01:29 +030045static void oem_board(char *, char *);
Heiko Schocher3a994482021-02-10 09:29:03 +010046static void run_ucmd(char *, char *);
47static void run_acmd(char *, char *);
Heiko Schocher3a994482021-02-10 09:29:03 +010048
Alex Kiernand5aa57c2018-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 Kiernand5aa57c2018-05-29 15:30:53 +000061 [FASTBOOT_COMMAND_FLASH] = {
62 .command = "flash",
Patrick Delaunayf82f9e42022-12-15 10:15:50 +010063 .dispatch = CONFIG_IS_ENABLED(FASTBOOT_FLASH, (flash), (NULL))
Alex Kiernand5aa57c2018-05-29 15:30:53 +000064 },
65 [FASTBOOT_COMMAND_ERASE] = {
66 .command = "erase",
Patrick Delaunayf82f9e42022-12-15 10:15:50 +010067 .dispatch = CONFIG_IS_ENABLED(FASTBOOT_FLASH, (erase), (NULL))
Alex Kiernand5aa57c2018-05-29 15:30:53 +000068 },
Alex Kiernand5aa57c2018-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 Kovalivskyib30b97b2020-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 Kiernand5aa57c2018-05-29 15:30:53 +000093 [FASTBOOT_COMMAND_SET_ACTIVE] = {
94 .command = "set_active",
95 .dispatch = okay
96 },
Alex Kiernanc86cde92018-05-29 15:30:54 +000097 [FASTBOOT_COMMAND_OEM_FORMAT] = {
98 .command = "oem format",
Patrick Delaunayf82f9e42022-12-15 10:15:50 +010099 .dispatch = CONFIG_IS_ENABLED(FASTBOOT_CMD_OEM_FORMAT, (oem_format), (NULL))
Alex Kiernanc86cde92018-05-29 15:30:54 +0000100 },
Patrick Delaunay61687702021-01-27 14:46:48 +0100101 [FASTBOOT_COMMAND_OEM_PARTCONF] = {
102 .command = "oem partconf",
Patrick Delaunayf82f9e42022-12-15 10:15:50 +0100103 .dispatch = CONFIG_IS_ENABLED(FASTBOOT_CMD_OEM_PARTCONF, (oem_partconf), (NULL))
Patrick Delaunay61687702021-01-27 14:46:48 +0100104 },
Patrick Delaunay67af29a2021-01-27 14:46:49 +0100105 [FASTBOOT_COMMAND_OEM_BOOTBUS] = {
106 .command = "oem bootbus",
Patrick Delaunayf82f9e42022-12-15 10:15:50 +0100107 .dispatch = CONFIG_IS_ENABLED(FASTBOOT_CMD_OEM_BOOTBUS, (oem_bootbus), (NULL))
Patrick Delaunay67af29a2021-01-27 14:46:49 +0100108 },
Sean Anderson421bec02022-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 Agorriae64262d2024-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 },
Alexey Romanova0ae7902024-04-18 13:01:29 +0300117 [FASTBOOT_COMMAND_OEM_BOARD] = {
118 .command = "oem board",
119 .dispatch = CONFIG_IS_ENABLED(FASTBOOT_OEM_BOARD, (oem_board), (NULL))
120 },
Heiko Schocher3a994482021-02-10 09:29:03 +0100121 [FASTBOOT_COMMAND_UCMD] = {
122 .command = "UCmd",
Patrick Delaunayf82f9e42022-12-15 10:15:50 +0100123 .dispatch = CONFIG_IS_ENABLED(FASTBOOT_UUU_SUPPORT, (run_ucmd), (NULL))
Heiko Schocher3a994482021-02-10 09:29:03 +0100124 },
125 [FASTBOOT_COMMAND_ACMD] = {
126 .command = "ACmd",
Patrick Delaunayf82f9e42022-12-15 10:15:50 +0100127 .dispatch = CONFIG_IS_ENABLED(FASTBOOT_UUU_SUPPORT, (run_acmd), (NULL))
Heiko Schocher3a994482021-02-10 09:29:03 +0100128 },
Alex Kiernand5aa57c2018-05-29 15:30:53 +0000129};
130
131/**
132 * fastboot_handle_command - Handle fastboot command
133 *
134 * @cmd_string: Pointer to command string
135 * @response: Pointer to fastboot response buffer
136 *
137 * Return: Executed command, or -1 if not recognized
138 */
139int fastboot_handle_command(char *cmd_string, char *response)
140{
141 int i;
142 char *cmd_parameter;
143
144 cmd_parameter = cmd_string;
145 strsep(&cmd_parameter, ":");
146
147 for (i = 0; i < FASTBOOT_COMMAND_COUNT; i++) {
148 if (!strcmp(commands[i].command, cmd_string)) {
149 if (commands[i].dispatch) {
150 commands[i].dispatch(cmd_parameter,
151 response);
152 return i;
153 } else {
Patrick Delaunayf82f9e42022-12-15 10:15:50 +0100154 pr_err("command %s not supported.\n", cmd_string);
155 fastboot_fail("Unsupported command", response);
156 return -1;
Alex Kiernand5aa57c2018-05-29 15:30:53 +0000157 }
158 }
159 }
160
161 pr_err("command %s not recognized.\n", cmd_string);
162 fastboot_fail("unrecognized command", response);
163 return -1;
164}
165
Ion Agorria1c387032024-01-05 09:22:06 +0200166void fastboot_multiresponse(int cmd, char *response)
167{
168 switch (cmd) {
Ion Agorria99fc6452024-01-05 09:22:07 +0200169 case FASTBOOT_COMMAND_GETVAR:
170 fastboot_getvar_all(response);
171 break;
Ion Agorriae64262d2024-01-05 09:22:11 +0200172 case FASTBOOT_COMMAND_OEM_CONSOLE:
173 if (CONFIG_IS_ENABLED(FASTBOOT_CMD_OEM_CONSOLE)) {
174 char buf[FASTBOOT_RESPONSE_LEN] = { 0 };
175
176 if (console_record_isempty()) {
177 console_record_reset();
178 fastboot_okay(NULL, response);
179 } else {
180 int ret = console_record_readline(buf, sizeof(buf) - 5);
181
182 if (ret < 0)
183 fastboot_fail("Error reading console", response);
184 else
185 fastboot_response("INFO", response, "%s", buf);
186 }
187 break;
188 }
Andre Przywara1e465ae2025-03-27 15:33:01 +0000189 fallthrough;
Ion Agorria1c387032024-01-05 09:22:06 +0200190 default:
191 fastboot_fail("Unknown multiresponse command", response);
192 break;
193 }
194}
195
Alex Kiernand5aa57c2018-05-29 15:30:53 +0000196/**
197 * okay() - Send bare OKAY response
198 *
199 * @cmd_parameter: Pointer to command parameter
200 * @response: Pointer to fastboot response buffer
201 *
202 * Send a bare OKAY fastboot response. This is used where the command is
203 * valid, but all the work is done after the response has been sent (e.g.
204 * boot, reboot etc.)
205 */
206static void okay(char *cmd_parameter, char *response)
207{
208 fastboot_okay(NULL, response);
209}
210
211/**
212 * getvar() - Read a config/version variable
213 *
214 * @cmd_parameter: Pointer to command parameter
215 * @response: Pointer to fastboot response buffer
216 */
217static void getvar(char *cmd_parameter, char *response)
218{
219 fastboot_getvar(cmd_parameter, response);
220}
221
222/**
223 * fastboot_download() - Start a download transfer from the client
224 *
225 * @cmd_parameter: Pointer to command parameter
226 * @response: Pointer to fastboot response buffer
227 */
228static void download(char *cmd_parameter, char *response)
229{
230 char *tmp;
231
232 if (!cmd_parameter) {
233 fastboot_fail("Expected command parameter", response);
234 return;
235 }
236 fastboot_bytes_received = 0;
Simon Glass3ff49ec2021-07-24 09:03:29 -0600237 fastboot_bytes_expected = hextoul(cmd_parameter, &tmp);
Alex Kiernand5aa57c2018-05-29 15:30:53 +0000238 if (fastboot_bytes_expected == 0) {
239 fastboot_fail("Expected nonzero image size", response);
240 return;
241 }
242 /*
243 * Nothing to download yet. Response is of the form:
244 * [DATA|FAIL]$cmd_parameter
245 *
246 * where cmd_parameter is an 8 digit hexadecimal number
247 */
248 if (fastboot_bytes_expected > fastboot_buf_size) {
249 fastboot_fail(cmd_parameter, response);
250 } else {
251 printf("Starting download of %d bytes\n",
252 fastboot_bytes_expected);
253 fastboot_response("DATA", response, "%s", cmd_parameter);
254 }
255}
256
257/**
258 * fastboot_data_remaining() - return bytes remaining in current transfer
259 *
260 * Return: Number of bytes left in the current download
261 */
262u32 fastboot_data_remaining(void)
263{
264 return fastboot_bytes_expected - fastboot_bytes_received;
265}
266
267/**
268 * fastboot_data_download() - Copy image data to fastboot_buf_addr.
269 *
270 * @fastboot_data: Pointer to received fastboot data
271 * @fastboot_data_len: Length of received fastboot data
272 * @response: Pointer to fastboot response buffer
273 *
274 * Copies image data from fastboot_data to fastboot_buf_addr. Writes to
275 * response. fastboot_bytes_received is updated to indicate the number
276 * of bytes that have been transferred.
277 *
278 * On completion sets image_size and ${filesize} to the total size of the
279 * downloaded image.
280 */
281void fastboot_data_download(const void *fastboot_data,
282 unsigned int fastboot_data_len,
283 char *response)
284{
285#define BYTES_PER_DOT 0x20000
286 u32 pre_dot_num, now_dot_num;
287
288 if (fastboot_data_len == 0 ||
289 (fastboot_bytes_received + fastboot_data_len) >
290 fastboot_bytes_expected) {
291 fastboot_fail("Received invalid data length",
292 response);
293 return;
294 }
295 /* Download data to fastboot_buf_addr */
Tom Rini793921e2024-04-18 08:29:35 -0600296 memcpy(fastboot_buf_addr + fastboot_bytes_received,
Alex Kiernand5aa57c2018-05-29 15:30:53 +0000297 fastboot_data, fastboot_data_len);
298
299 pre_dot_num = fastboot_bytes_received / BYTES_PER_DOT;
300 fastboot_bytes_received += fastboot_data_len;
301 now_dot_num = fastboot_bytes_received / BYTES_PER_DOT;
302
303 if (pre_dot_num != now_dot_num) {
304 putc('.');
305 if (!(now_dot_num % 74))
306 putc('\n');
307 }
308 *response = '\0';
309}
310
311/**
312 * fastboot_data_complete() - Mark current transfer complete
313 *
314 * @response: Pointer to fastboot response buffer
315 *
316 * Set image_size and ${filesize} to the total size of the downloaded image.
317 */
318void fastboot_data_complete(char *response)
319{
320 /* Download complete. Respond with "OKAY" */
321 fastboot_okay(NULL, response);
322 printf("\ndownloading of %d bytes finished\n", fastboot_bytes_received);
323 image_size = fastboot_bytes_received;
324 env_set_hex("filesize", image_size);
325 fastboot_bytes_expected = 0;
326 fastboot_bytes_received = 0;
327}
328
Alex Kiernand5aa57c2018-05-29 15:30:53 +0000329/**
330 * flash() - write the downloaded image to the indicated partition.
331 *
332 * @cmd_parameter: Pointer to partition name
333 * @response: Pointer to fastboot response buffer
334 *
335 * Writes the previously downloaded image to the partition indicated by
336 * cmd_parameter. Writes to response.
337 */
Patrick Delaunayf82f9e42022-12-15 10:15:50 +0100338static void __maybe_unused flash(char *cmd_parameter, char *response)
Alex Kiernand5aa57c2018-05-29 15:30:53 +0000339{
Simon Glass091a0712023-02-05 17:54:12 -0700340 if (IS_ENABLED(CONFIG_FASTBOOT_FLASH_MMC))
Tom Rini793921e2024-04-18 08:29:35 -0600341 fastboot_mmc_flash_write(cmd_parameter, fastboot_buf_addr,
342 image_size, response);
Patrick Delaunayf82f9e42022-12-15 10:15:50 +0100343
Simon Glass067995932023-02-05 17:54:13 -0700344 if (IS_ENABLED(CONFIG_FASTBOOT_FLASH_NAND))
Tom Rini793921e2024-04-18 08:29:35 -0600345 fastboot_nand_flash_write(cmd_parameter, fastboot_buf_addr,
346 image_size, response);
Alex Kiernand5aa57c2018-05-29 15:30:53 +0000347}
348
349/**
350 * erase() - erase the indicated partition.
351 *
352 * @cmd_parameter: Pointer to partition name
353 * @response: Pointer to fastboot response buffer
354 *
355 * Erases the partition indicated by cmd_parameter (clear to 0x00s). Writes
356 * to response.
357 */
Patrick Delaunayf82f9e42022-12-15 10:15:50 +0100358static void __maybe_unused erase(char *cmd_parameter, char *response)
Alex Kiernand5aa57c2018-05-29 15:30:53 +0000359{
Simon Glass091a0712023-02-05 17:54:12 -0700360 if (IS_ENABLED(CONFIG_FASTBOOT_FLASH_MMC))
Patrick Delaunayf82f9e42022-12-15 10:15:50 +0100361 fastboot_mmc_erase(cmd_parameter, response);
362
Simon Glass067995932023-02-05 17:54:13 -0700363 if (IS_ENABLED(CONFIG_FASTBOOT_FLASH_NAND))
Patrick Delaunayf82f9e42022-12-15 10:15:50 +0100364 fastboot_nand_erase(cmd_parameter, response);
Alex Kiernand5aa57c2018-05-29 15:30:53 +0000365}
Alex Kiernand5aa57c2018-05-29 15:30:53 +0000366
Heiko Schocher3a994482021-02-10 09:29:03 +0100367/**
368 * run_ucmd() - Execute the UCmd command
369 *
370 * @cmd_parameter: Pointer to command parameter
371 * @response: Pointer to fastboot response buffer
372 */
Patrick Delaunayf82f9e42022-12-15 10:15:50 +0100373static void __maybe_unused run_ucmd(char *cmd_parameter, char *response)
Heiko Schocher3a994482021-02-10 09:29:03 +0100374{
375 if (!cmd_parameter) {
376 pr_err("missing slot suffix\n");
377 fastboot_fail("missing command", response);
378 return;
379 }
380
381 if (run_command(cmd_parameter, 0))
382 fastboot_fail("", response);
383 else
384 fastboot_okay(NULL, response);
385}
386
387static char g_a_cmd_buff[64];
388
389void fastboot_acmd_complete(void)
390{
391 run_command(g_a_cmd_buff, 0);
392}
393
394/**
395 * run_acmd() - Execute the ACmd command
396 *
397 * @cmd_parameter: Pointer to command parameter
398 * @response: Pointer to fastboot response buffer
399 */
Patrick Delaunayf82f9e42022-12-15 10:15:50 +0100400static void __maybe_unused run_acmd(char *cmd_parameter, char *response)
Heiko Schocher3a994482021-02-10 09:29:03 +0100401{
402 if (!cmd_parameter) {
403 pr_err("missing slot suffix\n");
404 fastboot_fail("missing command", response);
405 return;
406 }
407
408 if (strlen(cmd_parameter) > sizeof(g_a_cmd_buff)) {
409 pr_err("too long command\n");
410 fastboot_fail("too long command", response);
411 return;
412 }
413
414 strcpy(g_a_cmd_buff, cmd_parameter);
415 fastboot_okay(NULL, response);
416}
Heiko Schocher3a994482021-02-10 09:29:03 +0100417
Alex Kiernand5aa57c2018-05-29 15:30:53 +0000418/**
419 * reboot_bootloader() - Sets reboot bootloader flag.
420 *
421 * @cmd_parameter: Pointer to command parameter
422 * @response: Pointer to fastboot response buffer
423 */
424static void reboot_bootloader(char *cmd_parameter, char *response)
425{
Roman Kovalivskyi1bb13422020-07-28 23:35:32 +0300426 if (fastboot_set_reboot_flag(FASTBOOT_REBOOT_REASON_BOOTLOADER))
Alex Kiernand5aa57c2018-05-29 15:30:53 +0000427 fastboot_fail("Cannot set reboot flag", response);
428 else
429 fastboot_okay(NULL, response);
430}
Alex Kiernanc86cde92018-05-29 15:30:54 +0000431
Roman Kovalivskyib30b97b2020-07-28 23:35:33 +0300432/**
433 * reboot_fastbootd() - Sets reboot fastboot flag.
434 *
435 * @cmd_parameter: Pointer to command parameter
436 * @response: Pointer to fastboot response buffer
437 */
438static void reboot_fastbootd(char *cmd_parameter, char *response)
439{
440 if (fastboot_set_reboot_flag(FASTBOOT_REBOOT_REASON_FASTBOOTD))
441 fastboot_fail("Cannot set fastboot flag", response);
442 else
443 fastboot_okay(NULL, response);
444}
445
446/**
447 * reboot_recovery() - Sets reboot recovery flag.
448 *
449 * @cmd_parameter: Pointer to command parameter
450 * @response: Pointer to fastboot response buffer
451 */
452static void reboot_recovery(char *cmd_parameter, char *response)
453{
454 if (fastboot_set_reboot_flag(FASTBOOT_REBOOT_REASON_RECOVERY))
455 fastboot_fail("Cannot set recovery flag", response);
456 else
457 fastboot_okay(NULL, response);
458}
459
Alex Kiernanc86cde92018-05-29 15:30:54 +0000460/**
461 * oem_format() - Execute the OEM format command
462 *
463 * @cmd_parameter: Pointer to command parameter
464 * @response: Pointer to fastboot response buffer
465 */
Patrick Delaunayf82f9e42022-12-15 10:15:50 +0100466static void __maybe_unused oem_format(char *cmd_parameter, char *response)
Alex Kiernanc86cde92018-05-29 15:30:54 +0000467{
468 char cmdbuf[32];
Patrick Delaunayf82f9e42022-12-15 10:15:50 +0100469 const int mmc_dev = config_opt_enabled(CONFIG_FASTBOOT_FLASH_MMC,
470 CONFIG_FASTBOOT_FLASH_MMC_DEV, -1);
Alex Kiernanc86cde92018-05-29 15:30:54 +0000471
472 if (!env_get("partitions")) {
473 fastboot_fail("partitions not set", response);
474 } else {
Patrick Delaunayf82f9e42022-12-15 10:15:50 +0100475 sprintf(cmdbuf, "gpt write mmc %x $partitions", mmc_dev);
Alex Kiernanc86cde92018-05-29 15:30:54 +0000476 if (run_command(cmdbuf, 0))
477 fastboot_fail("", response);
478 else
479 fastboot_okay(NULL, response);
480 }
481}
Patrick Delaunay61687702021-01-27 14:46:48 +0100482
Patrick Delaunay61687702021-01-27 14:46:48 +0100483/**
484 * oem_partconf() - Execute the OEM partconf command
485 *
486 * @cmd_parameter: Pointer to command parameter
487 * @response: Pointer to fastboot response buffer
488 */
Patrick Delaunayf82f9e42022-12-15 10:15:50 +0100489static void __maybe_unused oem_partconf(char *cmd_parameter, char *response)
Patrick Delaunay61687702021-01-27 14:46:48 +0100490{
491 char cmdbuf[32];
Patrick Delaunayf82f9e42022-12-15 10:15:50 +0100492 const int mmc_dev = config_opt_enabled(CONFIG_FASTBOOT_FLASH_MMC,
493 CONFIG_FASTBOOT_FLASH_MMC_DEV, -1);
Patrick Delaunay61687702021-01-27 14:46:48 +0100494
495 if (!cmd_parameter) {
496 fastboot_fail("Expected command parameter", response);
497 return;
498 }
499
500 /* execute 'mmc partconfg' command with cmd_parameter arguments*/
Patrick Delaunayf82f9e42022-12-15 10:15:50 +0100501 snprintf(cmdbuf, sizeof(cmdbuf), "mmc partconf %x %s 0", mmc_dev, cmd_parameter);
Patrick Delaunay61687702021-01-27 14:46:48 +0100502 printf("Execute: %s\n", cmdbuf);
503 if (run_command(cmdbuf, 0))
504 fastboot_fail("Cannot set oem partconf", response);
505 else
506 fastboot_okay(NULL, response);
507}
Patrick Delaunay67af29a2021-01-27 14:46:49 +0100508
Patrick Delaunay67af29a2021-01-27 14:46:49 +0100509/**
510 * oem_bootbus() - Execute the OEM bootbus command
511 *
512 * @cmd_parameter: Pointer to command parameter
513 * @response: Pointer to fastboot response buffer
514 */
Patrick Delaunayf82f9e42022-12-15 10:15:50 +0100515static void __maybe_unused oem_bootbus(char *cmd_parameter, char *response)
Patrick Delaunay67af29a2021-01-27 14:46:49 +0100516{
517 char cmdbuf[32];
Patrick Delaunayf82f9e42022-12-15 10:15:50 +0100518 const int mmc_dev = config_opt_enabled(CONFIG_FASTBOOT_FLASH_MMC,
519 CONFIG_FASTBOOT_FLASH_MMC_DEV, -1);
Patrick Delaunay67af29a2021-01-27 14:46:49 +0100520
521 if (!cmd_parameter) {
522 fastboot_fail("Expected command parameter", response);
523 return;
524 }
525
526 /* execute 'mmc bootbus' command with cmd_parameter arguments*/
Patrick Delaunayf82f9e42022-12-15 10:15:50 +0100527 snprintf(cmdbuf, sizeof(cmdbuf), "mmc bootbus %x %s", mmc_dev, cmd_parameter);
Patrick Delaunay67af29a2021-01-27 14:46:49 +0100528 printf("Execute: %s\n", cmdbuf);
529 if (run_command(cmdbuf, 0))
530 fastboot_fail("Cannot set oem bootbus", response);
531 else
532 fastboot_okay(NULL, response);
533}
Ion Agorriae64262d2024-01-05 09:22:11 +0200534
535/**
536 * oem_console() - Execute the OEM console command
537 *
538 * @cmd_parameter: Pointer to command parameter
539 * @response: Pointer to fastboot response buffer
540 */
541static void __maybe_unused oem_console(char *cmd_parameter, char *response)
542{
543 if (cmd_parameter)
544 console_in_puts(cmd_parameter);
545
546 if (console_record_isempty())
547 fastboot_fail("Empty console", response);
548 else
549 fastboot_response(FASTBOOT_MULTIRESPONSE_START, response, NULL);
550}
Alexey Romanova0ae7902024-04-18 13:01:29 +0300551
552/**
553 * fastboot_oem_board() - Execute the OEM board command. This is default
554 * weak implementation, which may be overwritten in board/ files.
555 *
556 * @cmd_parameter: Pointer to command parameter
557 * @data: Pointer to fastboot input buffer
558 * @size: Size of the fastboot input buffer
559 * @response: Pointer to fastboot response buffer
560 */
561void __weak fastboot_oem_board(char *cmd_parameter, void *data, u32 size, char *response)
562{
563 fastboot_fail("oem board function not defined", response);
564}
565
566/**
567 * oem_board() - Execute the OEM board command
568 *
569 * @cmd_parameter: Pointer to command parameter
570 * @response: Pointer to fastboot response buffer
571 */
572static void __maybe_unused oem_board(char *cmd_parameter, char *response)
573{
574 fastboot_oem_board(cmd_parameter, (void *)fastboot_buf_addr, image_size, response);
575}