blob: 870fc4514503c197bdea4ab46bed5e47a1364ccc [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>
Simon Glassc7694dd2019-08-01 09:46:46 -06008#include <env.h>
Alex Kiernanf73a7df2018-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>
Xindong Xud9441422024-01-18 10:20:45 +080015#ifdef CONFIG_AMLOGIC_MODIFY
16#include <amlogic/emmc_partitions.h>
17#include <amlogic/storage.h>
18#include <amlogic/aml_efuse.h>
19#include <amlogic/aml_mmc.h>
20
21#include <android_image.h>
22#include <image.h>
23#include <amlogic/store_wrapper.h>
24#include <malloc.h>
25#include <amlogic/image_check.h>
26#include <fs.h>
Xindong Xuac88caf2024-10-28 17:10:12 +080027#include <version.h>
Xindong Xud9441422024-01-18 10:20:45 +080028#if defined(CONFIG_AML_ANTIROLLBACK) || defined(CONFIG_AML_AVB2_ANTIROLLBACK)
29#include <amlogic/anti-rollback.h>
30#endif
31#endif
Alex Kiernanf73a7df2018-05-29 15:30:53 +000032
33/**
34 * image_size - final fastboot image size
35 */
36static u32 image_size;
37
38/**
39 * fastboot_bytes_received - number of bytes received in the current download
40 */
41static u32 fastboot_bytes_received;
42
43/**
44 * fastboot_bytes_expected - number of bytes expected in the current download
45 */
46static u32 fastboot_bytes_expected;
47
Xindong Xud9441422024-01-18 10:20:45 +080048#ifdef CONFIG_AMLOGIC_MODIFY
49int busy_flag;
50#endif
51
Alex Kiernanf73a7df2018-05-29 15:30:53 +000052static void okay(char *, char *);
53static void getvar(char *, char *);
Xindong Xud9441422024-01-18 10:20:45 +080054
55#ifdef CONFIG_FASTBOOT_WRITING_CMD
Alex Kiernanf73a7df2018-05-29 15:30:53 +000056static void download(char *, char *);
57#if CONFIG_IS_ENABLED(FASTBOOT_FLASH)
58static void flash(char *, char *);
59static void erase(char *, char *);
60#endif
Xindong Xud9441422024-01-18 10:20:45 +080061#endif
Alex Kiernanf73a7df2018-05-29 15:30:53 +000062static void reboot_bootloader(char *, char *);
Roman Kovalivskyi2b2a7712020-07-28 23:35:33 +030063static void reboot_fastbootd(char *, char *);
64static void reboot_recovery(char *, char *);
Xindong Xud9441422024-01-18 10:20:45 +080065#ifdef CONFIG_FASTBOOT_WRITING_CMD
66#ifdef CONFIG_AMLOGIC_MODIFY
67static void fetch(char *, char *);
Xindong Xub3cf2a82024-12-25 10:23:47 +080068static void oem_cmd(char *, char *);
Xindong Xud9441422024-01-18 10:20:45 +080069#if !CONFIG_IS_ENABLED(NO_FASTBOOT_FLASHING)
70static void flashing(char *, char *);
71#endif
72#endif
Alex Kiernan3845b902018-05-29 15:30:54 +000073#if CONFIG_IS_ENABLED(FASTBOOT_CMD_OEM_FORMAT)
74static void oem_format(char *, char *);
75#endif
Patrick Delaunayb2f6b972021-01-27 14:46:48 +010076#if CONFIG_IS_ENABLED(FASTBOOT_CMD_OEM_PARTCONF)
77static void oem_partconf(char *, char *);
78#endif
Patrick Delaunay0c0394b2021-01-27 14:46:49 +010079#if CONFIG_IS_ENABLED(FASTBOOT_CMD_OEM_BOOTBUS)
80static void oem_bootbus(char *, char *);
81#endif
Xindong Xud9441422024-01-18 10:20:45 +080082static void set_active_cmd(char *, char *);
83#endif
84
85#ifdef CONFIG_AMLOGIC_MODIFY
86extern int is_partition_logical(char* partition_name);
87#endif
Alex Kiernanf73a7df2018-05-29 15:30:53 +000088
Heiko Schocherbc820d52021-02-10 09:29:03 +010089#if CONFIG_IS_ENABLED(FASTBOOT_UUU_SUPPORT)
90static void run_ucmd(char *, char *);
91static void run_acmd(char *, char *);
92#endif
93
Alex Kiernanf73a7df2018-05-29 15:30:53 +000094static const struct {
95 const char *command;
96 void (*dispatch)(char *cmd_parameter, char *response);
97} commands[FASTBOOT_COMMAND_COUNT] = {
98 [FASTBOOT_COMMAND_GETVAR] = {
99 .command = "getvar",
100 .dispatch = getvar
101 },
Xindong Xud9441422024-01-18 10:20:45 +0800102#ifdef CONFIG_FASTBOOT_WRITING_CMD
Alex Kiernanf73a7df2018-05-29 15:30:53 +0000103 [FASTBOOT_COMMAND_DOWNLOAD] = {
104 .command = "download",
105 .dispatch = download
106 },
Xindong Xud9441422024-01-18 10:20:45 +0800107#ifdef CONFIG_AMLOGIC_MODIFY
108#if !CONFIG_IS_ENABLED(NO_FASTBOOT_FLASHING)
109 [FASTBOOT_COMMAND_FLASHING] = {
110 .command = "flashing",
111 .dispatch = flashing
112 },
113#endif
114 [FASTBOOT_COMMAND_FETCH] = {
115 .command = "fetch",
116 .dispatch = fetch
117 },
Xindong Xub3cf2a82024-12-25 10:23:47 +0800118 [FASTBOOT_COMMAND_OEM] = {
119 .command = "oem",
120 .dispatch = oem_cmd,
121 },
Xindong Xud9441422024-01-18 10:20:45 +0800122#endif
Alex Kiernanf73a7df2018-05-29 15:30:53 +0000123#if CONFIG_IS_ENABLED(FASTBOOT_FLASH)
124 [FASTBOOT_COMMAND_FLASH] = {
125 .command = "flash",
126 .dispatch = flash
127 },
128 [FASTBOOT_COMMAND_ERASE] = {
129 .command = "erase",
130 .dispatch = erase
131 },
132#endif
133 [FASTBOOT_COMMAND_BOOT] = {
134 .command = "boot",
135 .dispatch = okay
136 },
Xindong Xud9441422024-01-18 10:20:45 +0800137#endif
Alex Kiernanf73a7df2018-05-29 15:30:53 +0000138 [FASTBOOT_COMMAND_CONTINUE] = {
139 .command = "continue",
140 .dispatch = okay
141 },
Alex Kiernanf73a7df2018-05-29 15:30:53 +0000142 [FASTBOOT_COMMAND_REBOOT_BOOTLOADER] = {
143 .command = "reboot-bootloader",
144 .dispatch = reboot_bootloader
145 },
Roman Kovalivskyi2b2a7712020-07-28 23:35:33 +0300146 [FASTBOOT_COMMAND_REBOOT_FASTBOOTD] = {
147 .command = "reboot-fastboot",
148 .dispatch = reboot_fastbootd
149 },
150 [FASTBOOT_COMMAND_REBOOT_RECOVERY] = {
151 .command = "reboot-recovery",
152 .dispatch = reboot_recovery
153 },
Xindong Xud9441422024-01-18 10:20:45 +0800154 [FASTBOOT_COMMAND_REBOOT] = {
155 .command = "reboot",
156 .dispatch = okay
157 },
158#ifdef CONFIG_FASTBOOT_WRITING_CMD
Alex Kiernanf73a7df2018-05-29 15:30:53 +0000159 [FASTBOOT_COMMAND_SET_ACTIVE] = {
160 .command = "set_active",
Xindong Xud9441422024-01-18 10:20:45 +0800161#ifdef CONFIG_AMLOGIC_MODIFY
162 .dispatch = set_active_cmd
163#else
Alex Kiernanf73a7df2018-05-29 15:30:53 +0000164 .dispatch = okay
Xindong Xud9441422024-01-18 10:20:45 +0800165#endif
Alex Kiernanf73a7df2018-05-29 15:30:53 +0000166 },
Alex Kiernan3845b902018-05-29 15:30:54 +0000167#if CONFIG_IS_ENABLED(FASTBOOT_CMD_OEM_FORMAT)
168 [FASTBOOT_COMMAND_OEM_FORMAT] = {
169 .command = "oem format",
170 .dispatch = oem_format,
171 },
172#endif
Patrick Delaunayb2f6b972021-01-27 14:46:48 +0100173#if CONFIG_IS_ENABLED(FASTBOOT_CMD_OEM_PARTCONF)
174 [FASTBOOT_COMMAND_OEM_PARTCONF] = {
175 .command = "oem partconf",
176 .dispatch = oem_partconf,
177 },
178#endif
Patrick Delaunay0c0394b2021-01-27 14:46:49 +0100179#if CONFIG_IS_ENABLED(FASTBOOT_CMD_OEM_BOOTBUS)
180 [FASTBOOT_COMMAND_OEM_BOOTBUS] = {
181 .command = "oem bootbus",
182 .dispatch = oem_bootbus,
183 },
184#endif
Xindong Xud9441422024-01-18 10:20:45 +0800185#endif
Heiko Schocherbc820d52021-02-10 09:29:03 +0100186#if CONFIG_IS_ENABLED(FASTBOOT_UUU_SUPPORT)
187 [FASTBOOT_COMMAND_UCMD] = {
188 .command = "UCmd",
189 .dispatch = run_ucmd,
190 },
191 [FASTBOOT_COMMAND_ACMD] = {
192 .command = "ACmd",
193 .dispatch = run_acmd,
194 },
195#endif
Alex Kiernanf73a7df2018-05-29 15:30:53 +0000196};
197
Xindong Xud9441422024-01-18 10:20:45 +0800198#ifdef CONFIG_AMLOGIC_MODIFY
199struct fastboot_read fastboot_readInfo;
200
201static int strcmp_l1(const char *s1, const char *s2)
202{
203 if (!s1 || !s2)
204 return -1;
205 return strncmp(s1, s2, strlen(s1));
206}
207#endif
208
Alex Kiernanf73a7df2018-05-29 15:30:53 +0000209/**
210 * fastboot_handle_command - Handle fastboot command
211 *
212 * @cmd_string: Pointer to command string
213 * @response: Pointer to fastboot response buffer
214 *
215 * Return: Executed command, or -1 if not recognized
216 */
217int fastboot_handle_command(char *cmd_string, char *response)
218{
219 int i;
220 char *cmd_parameter;
221
222 cmd_parameter = cmd_string;
223 strsep(&cmd_parameter, ":");
224
225 for (i = 0; i < FASTBOOT_COMMAND_COUNT; i++) {
Xindong Xud9441422024-01-18 10:20:45 +0800226#ifdef CONFIG_AMLOGIC_MODIFY
227 if (!strcmp_l1(commands[i].command, cmd_string)) {
228 if (commands[i].dispatch) {
229 if (cmd_parameter) {
230 commands[i].dispatch(cmd_parameter,
231 response);
232 } else {
233 commands[i].dispatch(cmd_string,
234 response);
235 }
236 return i;
237 } else {
238 break;
239 }
240 }
241#else
Alex Kiernanf73a7df2018-05-29 15:30:53 +0000242 if (!strcmp(commands[i].command, cmd_string)) {
243 if (commands[i].dispatch) {
244 commands[i].dispatch(cmd_parameter,
245 response);
246 return i;
247 } else {
248 break;
249 }
250 }
Xindong Xud9441422024-01-18 10:20:45 +0800251#endif
Alex Kiernanf73a7df2018-05-29 15:30:53 +0000252 }
253
254 pr_err("command %s not recognized.\n", cmd_string);
255 fastboot_fail("unrecognized command", response);
256 return -1;
257}
258
259/**
260 * okay() - Send bare OKAY response
261 *
262 * @cmd_parameter: Pointer to command parameter
263 * @response: Pointer to fastboot response buffer
264 *
265 * Send a bare OKAY fastboot response. This is used where the command is
266 * valid, but all the work is done after the response has been sent (e.g.
267 * boot, reboot etc.)
268 */
269static void okay(char *cmd_parameter, char *response)
270{
271 fastboot_okay(NULL, response);
272}
273
Xindong Xud9441422024-01-18 10:20:45 +0800274#ifdef CONFIG_AMLOGIC_MODIFY
275void dump_lock_info(LockData_t info)
276{
277#if 0
278 printf("info.version_major = %d\n", info.version_major);
279 printf("info.version_minor = %d\n", info.version_minor);
280 printf("info.unlock_ability = %d\n", info.unlock_ability);
281 printf("info.lock_state = %d\n", info.lock_state);
282 printf("info.lock_critical_state = %d\n", info.lock_critical_state);
283 printf("info.lock_bootloader = %d\n", info.lock_bootloader);
284#endif
285}
286
287static const char* getvar_list[] = {
288 "version-baseband", "version-bootloader", "version", "hw-revision", "max-download-size",
289 "serialno", "product", "off-mode-charge", "variant", "battery-soc-ok",
290 "battery-voltage", "partition-type:boot", "partition-size:boot",
291 "partition-type:system", "partition-size:system", "partition-type:vendor", "partition-size:vendor",
292 "partition-type:odm", "partition-size:odm", "partition-type:data", "partition-size:data",
293 "erase-block-size", "logical-block-size", "secure", "unlocked",
294};
295
296static const char* getvar_list_dynamic[] = {
297 "hw-revision", "battery-voltage", "is-userspace", "is-logical:data",
298 "is-logical:metadata", "is-logical:misc", "is-logical:super", "is-logical:boot",
299 "is-logical:system", "is-logical:vendor", "is-logical:product", "is-logical:odm",
300 "slot-count", "max-download-size", "serialno", "product", "unlocked",
301 "secure", "super-partition-name", "version-baseband", "version-bootloader",
302 "partition-size:boot", "partition-size:metadata", "partition-size:misc",
303 "partition-size:super", "partition-size:data", "version",
304};
305
306static const char* getvar_list_dynamic_ab[] = {
307 "hw-revision", "battery-voltage", "is-userspace", "is-logical:data",
308 "is-logical:misc", "is-logical:super",
309 "is-logical:boot_a", "is-logical:boot_b", "is-logical:system_a", "is-logical:system_b",
310 "is-logical:vendor_a", "is-logical:vendor_b", "is-logical:product_a", "is-logical:product_b",
311 "is-logical:odm_a", "is-logical:odm_b",
312 "slot-count", "max-download-size", "serialno", "product", "unlocked", "has-slot:data",
313 "has-slot:metadata", "has-slot:misc", "has-slot:super", "has-slot:boot",
314 "has-slot:system", "has-slot:vendor", "has-slot:product", "has-slot:odm", "current-slot",
315 "secure", "super-partition-name", "version-baseband", "version-bootloader",
316 "partition-size:super",
317 "partition-size:boot_a", "partition-size:boot_b", "partition-size:misc",
318 "partition-size:data", "version",
319};
320
321
322static const char* getvar_list_ab[] = {
323 "version-baseband", "version-bootloader", "version", "hw-revision", "max-download-size",
324 "serialno", "product", "off-mode-charge", "variant", "battery-soc-ok",
325 "battery-voltage", "partition-type:boot_a", "partition-size:boot_a",
326 "partition-type:system_a", "partition-size:system_a", "partition-type:vendor_a", "partition-size:vendor_a",
327 "partition-type:odm_a", "partition-size:odm_a", "partition-type:data", "partition-size:data",
328 "erase-block-size", "logical-block-size", "secure", "unlocked",
329 "slot-count", "slot-suffixes","current-slot", "has-slot:bootloader", "has-slot:boot",
330 "has-slot:system", "has-slot:vendor", "has-slot:odm", "has-slot:vbmeta",
331 "has-slot:metadata", "has-slot:product", "has-slot:dtbo",
332 "slot-successful:a", "slot-unbootable:a", "slot-retry-count:a",
333 "slot-successful:b", "slot-unbootable:b", "slot-retry-count:b",
334};
335#endif
336
Alex Kiernanf73a7df2018-05-29 15:30:53 +0000337/**
338 * getvar() - Read a config/version variable
339 *
340 * @cmd_parameter: Pointer to command parameter
341 * @response: Pointer to fastboot response buffer
342 */
343static void getvar(char *cmd_parameter, char *response)
344{
Xindong Xud9441422024-01-18 10:20:45 +0800345#ifdef CONFIG_AMLOGIC_MODIFY
346 run_command("get_valid_slot", 0);
347 if (!strncmp(cmd_parameter, "all", 3)) {
348 static int cmdIndex = 0;
349 int getvar_num = 0;
350 char* cmd=cmd_parameter;
351
352 busy_flag = 1;
353
354 if (dynamic_partition && has_boot_slot == 1 && strlen(getvar_list_dynamic_ab[cmdIndex]) < 64) {
355 strncpy(cmd, getvar_list_dynamic_ab[cmdIndex], 64);
356 getvar_num = (sizeof(getvar_list_dynamic_ab) / sizeof(getvar_list_dynamic_ab[0]));
357 } else if (has_boot_slot == 1 && strlen(getvar_list_ab[cmdIndex]) < 64) {
358 strncpy(cmd, getvar_list_ab[cmdIndex], 64);
359 getvar_num = (sizeof(getvar_list_ab) / sizeof(getvar_list_ab[0]));
360 } else if (dynamic_partition && strlen(getvar_list_dynamic[cmdIndex]) < 64) {
361 strncpy(cmd, getvar_list_dynamic[cmdIndex], 64);//only support no-arg cmd
362 getvar_num = (sizeof(getvar_list_dynamic) / sizeof(getvar_list_dynamic[0]));
363 } else if (strlen(getvar_list[cmdIndex]) < 64) {
364 strncpy(cmd, getvar_list[cmdIndex], 64);//only support no-arg cmd
365 getvar_num = (sizeof(getvar_list) / sizeof(getvar_list[0]));
366 }
367 //printf("getvar_num: %d\n", getvar_num);
368 //printf("all cmd:%s\n", cmd);
369 if ( ++cmdIndex >= getvar_num) {
370 cmdIndex = 0;
371 busy_flag = 0;
372 fastboot_okay(NULL, response);
373 } else {
374 fastboot_getvar(cmd, response);
375 }
376
377 }else {
378#endif
379 fastboot_getvar(cmd_parameter, response);
380#ifdef CONFIG_AMLOGIC_MODIFY
381 }
382#endif
Alex Kiernanf73a7df2018-05-29 15:30:53 +0000383}
384
385/**
386 * fastboot_download() - Start a download transfer from the client
387 *
388 * @cmd_parameter: Pointer to command parameter
389 * @response: Pointer to fastboot response buffer
390 */
Xindong Xud9441422024-01-18 10:20:45 +0800391#ifdef CONFIG_FASTBOOT_WRITING_CMD
Alex Kiernanf73a7df2018-05-29 15:30:53 +0000392static void download(char *cmd_parameter, char *response)
393{
394 char *tmp;
395
Xindong Xud9441422024-01-18 10:20:45 +0800396#ifdef CONFIG_AMLOGIC_MODIFY
397 if (check_lock() == 1) {
398 printf("device is locked, can not run this cmd.Please flashing unlock & flashing unlock_critical\n");
399 fastboot_fail("locked device", response);
400 return;
401 }
402#endif
403
Alex Kiernanf73a7df2018-05-29 15:30:53 +0000404 if (!cmd_parameter) {
405 fastboot_fail("Expected command parameter", response);
406 return;
407 }
408 fastboot_bytes_received = 0;
Simon Glass7e5f4602021-07-24 09:03:29 -0600409 fastboot_bytes_expected = hextoul(cmd_parameter, &tmp);
Alex Kiernanf73a7df2018-05-29 15:30:53 +0000410 if (fastboot_bytes_expected == 0) {
411 fastboot_fail("Expected nonzero image size", response);
412 return;
413 }
414 /*
415 * Nothing to download yet. Response is of the form:
416 * [DATA|FAIL]$cmd_parameter
417 *
418 * where cmd_parameter is an 8 digit hexadecimal number
419 */
420 if (fastboot_bytes_expected > fastboot_buf_size) {
Xindong Xud9441422024-01-18 10:20:45 +0800421#ifdef CONFIG_AMLOGIC_MODIFY
422 char str[128] = {0};
423
424 printf("fastboot_bytes_expected %d > fastboot_buf_size %d\n",
425 fastboot_bytes_expected, fastboot_buf_size);
426 sprintf(str, "data too large, please add -S %dM",
427 (fastboot_buf_size / 1024 / 1024));
428 fastboot_fail(str, response);
429#else
Alex Kiernanf73a7df2018-05-29 15:30:53 +0000430 fastboot_fail(cmd_parameter, response);
Xindong Xud9441422024-01-18 10:20:45 +0800431#endif
Alex Kiernanf73a7df2018-05-29 15:30:53 +0000432 } else {
433 printf("Starting download of %d bytes\n",
434 fastboot_bytes_expected);
435 fastboot_response("DATA", response, "%s", cmd_parameter);
436 }
437}
Xindong Xud9441422024-01-18 10:20:45 +0800438#endif
Alex Kiernanf73a7df2018-05-29 15:30:53 +0000439/**
440 * fastboot_data_remaining() - return bytes remaining in current transfer
441 *
442 * Return: Number of bytes left in the current download
443 */
444u32 fastboot_data_remaining(void)
445{
446 return fastboot_bytes_expected - fastboot_bytes_received;
447}
448
449/**
450 * fastboot_data_download() - Copy image data to fastboot_buf_addr.
451 *
452 * @fastboot_data: Pointer to received fastboot data
453 * @fastboot_data_len: Length of received fastboot data
454 * @response: Pointer to fastboot response buffer
455 *
456 * Copies image data from fastboot_data to fastboot_buf_addr. Writes to
457 * response. fastboot_bytes_received is updated to indicate the number
458 * of bytes that have been transferred.
459 *
460 * On completion sets image_size and ${filesize} to the total size of the
461 * downloaded image.
462 */
463void fastboot_data_download(const void *fastboot_data,
464 unsigned int fastboot_data_len,
465 char *response)
466{
467#define BYTES_PER_DOT 0x20000
468 u32 pre_dot_num, now_dot_num;
469
470 if (fastboot_data_len == 0 ||
471 (fastboot_bytes_received + fastboot_data_len) >
472 fastboot_bytes_expected) {
473 fastboot_fail("Received invalid data length",
474 response);
475 return;
476 }
477 /* Download data to fastboot_buf_addr */
478 memcpy(fastboot_buf_addr + fastboot_bytes_received,
479 fastboot_data, fastboot_data_len);
480
481 pre_dot_num = fastboot_bytes_received / BYTES_PER_DOT;
482 fastboot_bytes_received += fastboot_data_len;
483 now_dot_num = fastboot_bytes_received / BYTES_PER_DOT;
484
485 if (pre_dot_num != now_dot_num) {
486 putc('.');
487 if (!(now_dot_num % 74))
488 putc('\n');
489 }
490 *response = '\0';
491}
492
493/**
494 * fastboot_data_complete() - Mark current transfer complete
495 *
496 * @response: Pointer to fastboot response buffer
497 *
498 * Set image_size and ${filesize} to the total size of the downloaded image.
499 */
500void fastboot_data_complete(char *response)
501{
502 /* Download complete. Respond with "OKAY" */
503 fastboot_okay(NULL, response);
504 printf("\ndownloading of %d bytes finished\n", fastboot_bytes_received);
505 image_size = fastboot_bytes_received;
506 env_set_hex("filesize", image_size);
507 fastboot_bytes_expected = 0;
508 fastboot_bytes_received = 0;
509}
510
Xindong Xud9441422024-01-18 10:20:45 +0800511#ifdef CONFIG_FASTBOOT_WRITING_CMD
Alex Kiernanf73a7df2018-05-29 15:30:53 +0000512#if CONFIG_IS_ENABLED(FASTBOOT_FLASH)
Xindong Xud9441422024-01-18 10:20:45 +0800513
514#ifdef CONFIG_AMLOGIC_MODIFY
515static void write_dts_reserve(void)
516{
517 int ret;
518 void *addr = NULL;
519 char *mem_addr;
520
521 if (run_command("imgread dtb ${boot_part} ${dtb_mem_addr}", 0)) {
522 printf("Fail in load dtb\n");
523 } else {
524 mem_addr = env_get("dtb_mem_addr");
525
526 if (mem_addr) {
527 addr = (void *)simple_strtoul(mem_addr, NULL, 16);
528 ret = dtb_write(addr);
529 if (ret)
530 printf("write dtb error\n");
531 else
532 printf("write dtb ok\n");
533 }
534 }
535}
536
Xindong Xu0afe60a2024-05-21 16:15:13 +0800537static int clear_misc_partition(void)
538{
539 char *partition = "misc";
540 char *buffer = NULL;
541 u64 rc = 0;
542
543 rc = store_part_size(partition);
544 buffer = (char *)malloc(rc - AVB_CUSTOM_KEY_LEN_MAX);
545 if (!buffer) {
546 printf("malloc error\n");
547 return -1;
548 }
549 memset(buffer, 0, rc - AVB_CUSTOM_KEY_LEN_MAX);
550
551 store_write((const char *)partition, 0, rc - AVB_CUSTOM_KEY_LEN_MAX,
552 (unsigned char *)buffer);
553
554 free(buffer);
555
556 return 0;
557}
558
Xindong Xu22e8daf2024-03-12 18:08:41 +0800559static void set_fastboot_flag(int flag)
Xindong Xud9441422024-01-18 10:20:45 +0800560{
561 env_set("default_env", "1");
Xindong Xu22e8daf2024-03-12 18:08:41 +0800562 if (flag == 1)
563 env_set("fastboot_step", "1");
Xindong Xud9441422024-01-18 10:20:45 +0800564#if CONFIG_IS_ENABLED(AML_UPDATE_ENV)
565 run_command("update_env_part -p default_env;", 0);
Xindong Xu22e8daf2024-03-12 18:08:41 +0800566 if (flag == 1)
567 run_command("update_env_part -p fastboot_step;", 0);
Xindong Xud9441422024-01-18 10:20:45 +0800568#else
569 run_command("defenv_reserve;", 0);
570 run_command("setenv default_env 1;", 0);
Xindong Xu22e8daf2024-03-12 18:08:41 +0800571 if (flag == 1)
572 run_command("setenv fastboot_step 1;", 0);
Xindong Xud9441422024-01-18 10:20:45 +0800573 run_command("saveenv;", 0);
574#endif//#if CONFIG_IS_ENABLED(AML_UPDATE_ENV)
575}
576#endif
577
Alex Kiernanf73a7df2018-05-29 15:30:53 +0000578/**
579 * flash() - write the downloaded image to the indicated partition.
580 *
581 * @cmd_parameter: Pointer to partition name
582 * @response: Pointer to fastboot response buffer
583 *
584 * Writes the previously downloaded image to the partition indicated by
585 * cmd_parameter. Writes to response.
586 */
587static void flash(char *cmd_parameter, char *response)
588{
Xindong Xud9441422024-01-18 10:20:45 +0800589#ifdef CONFIG_AMLOGIC_MODIFY
590 char name[32] = {0};
591 u64 rc = 0;
592 int gpt_flag = -1;
593 int ret = -1;
594
595 if (check_lock() == 1) {
596 printf("device is locked, can not run this cmd.Please flashing unlock & flashing unlock_critical\n");
597 fastboot_fail("locked device", response);
598 return;
599 }
600
601 printf("cmd_parameter: %s\n", cmd_parameter);
602
603#ifdef CONFIG_FASTBOOT_FLASH_MMC_DEV
604 struct mmc *mmc = find_mmc_device(CONFIG_FASTBOOT_FLASH_MMC_DEV);
605 if (mmc && strcmp(cmd_parameter, "bootloader") == 0) {
606 printf("try to read gpt data from bootloader.img\n");
607 struct blk_desc *dev_desc;
608 int erase_flag = 0;
Xindong Xu22e8daf2024-03-12 18:08:41 +0800609 char *bootloaderindex;
610 char *slot_name = NULL;
611 char partname[32] = {0};
Xindong Xud9441422024-01-18 10:20:45 +0800612
yihui wu7935bce2024-12-17 01:17:08 +0800613#ifdef CONFIG_MESON_S7D
Dongjin Kimddfb7182025-02-24 16:50:49 +0900614#ifdef CONFIG_AML_V3_FACTORY_BURN
Zhigang Yua69e3f92024-06-18 03:13:38 +0000615 ret = update_boot_hdr_4_s7d_reva(fastboot_buf_addr, image_size, 0);
616 if (ret) {
617 printf("Failed to write s7d reva boot0\n");
618 fastboot_fail("Failed to write s7d reva boot0", response);
619 return;
620 }
Dongjin Kimddfb7182025-02-24 16:50:49 +0900621#endif
yihui wu7935bce2024-12-17 01:17:08 +0800622#endif//#ifdef CONFIG_MESON_S7D
Zhigang Yua69e3f92024-06-18 03:13:38 +0000623
Xindong Xu22e8daf2024-03-12 18:08:41 +0800624 slot_name = env_get("active_slot");
625 if (slot_name && (strcmp(slot_name, "_a") == 0))
626 strcpy((char *)partname, "bootloader_a");
627 else if (slot_name && (strcmp(slot_name, "_b") == 0))
628 strcpy((char *)partname, "bootloader_b");
629 else
630 strcpy((char *)partname, "bootloader_up");
631
632 rc = store_part_size(partname);
Xindong Xud9441422024-01-18 10:20:45 +0800633 if (rc != -1) {
Xindong Xu22e8daf2024-03-12 18:08:41 +0800634 fastboot_mmc_erase(partname, response);
635 fastboot_mmc_flash_write(partname, fastboot_buf_addr, image_size,
Xindong Xud9441422024-01-18 10:20:45 +0800636 response);
637 }
638
639 /* the max size of bootloader.img is 4M, we reserve 128k for gpt.bin
640 * so we put gpt.bin at offset 0x3DFE00
641 * 0 ~ 512 bootloader secure boot, we don't care it here.
642 * 512 ~ 0x3DFDFF original bootloader.img and 0
643 * 0x3DFE00 ~ end gpt.bin
644 */
645
646 dev_desc = blk_get_dev("mmc", CONFIG_FASTBOOT_FLASH_MMC_DEV);
647 if (!dev_desc || dev_desc->type == DEV_TYPE_UNKNOWN) {
648 printf("invalid mmc device\n");
649 fastboot_fail("invalid mmc device", response);
650 return;
651 }
652
653 if (is_valid_gpt_buf(dev_desc, fastboot_buf_addr + 0x3DFE00)) {
654 printf("printf normal bootloader.img, no gpt partition table\n");
655 } else {
656 printf("find gpt partition table, update it\n"
657 "and write bootloader to boot0/boot1\n");
658
659 erase_flag = check_gpt_part(dev_desc, fastboot_buf_addr + 0x3DFE00);
660
661 if (erase_flag == 1) {
662 printf("partition changes, erase emmc\n");
663 //run_command("store erase.chip 0;", 0);
Dongjin Kimddfb7182025-02-24 16:50:49 +0900664#ifdef CONFIG_AML_V3_FACTORY_BURN
Xindong Xud9441422024-01-18 10:20:45 +0800665 if (usb_burn_erase_data(0x3)) {
666 printf("partition erase failed!\n");
667 return;
668 }
Dongjin Kimddfb7182025-02-24 16:50:49 +0900669#endif
Xindong Xud9441422024-01-18 10:20:45 +0800670 }
671
672 if (write_mbr_and_gpt_partitions(dev_desc, fastboot_buf_addr + 0x3DFE00)) {
673 printf("%s: writing GPT partitions failed\n", __func__);
674 fastboot_fail("writing GPT partitions failed", response);
675 return;
676 }
677
678 if (mmc_device_init(mmc) != 0) {
679 printf(" update gpt partition table fail\n");
680 fastboot_fail("fastboot update gpt partition fail", response);
681 return;
682 }
683 printf("%s: writing GPT partitions ok\n", __func__);
684
685 char *mem_addr;
686 void *addr = NULL;
687 int ret;
688
689 mem_addr = env_get("dtb_mem_addr");
690
691 if (mem_addr && erase_flag == 1) {
692 printf("partition changes, erase emmc\n");
693 //run_command("store erase.chip 0;", 0);
Dongjin Kimddfb7182025-02-24 16:50:49 +0900694#ifdef CONFIG_AML_V3_FACTORY_BURN
Xindong Xud9441422024-01-18 10:20:45 +0800695 if (usb_burn_erase_data(0x3)) {
696 printf("partition erase failed!\n");
697 return;
698 }
Dongjin Kimddfb7182025-02-24 16:50:49 +0900699#endif
Xindong Xud9441422024-01-18 10:20:45 +0800700 printf("write _aml_dtb\n");
701 addr = (void *)simple_strtoul(mem_addr, NULL, 16);
702 ret = dtb_write(addr);
703 if (ret)
704 printf("write _aml_dtb error\n");
705 else
706 printf("write _aml_dtb ok\n");
707 }
708 }
709
Xindong Xu0afe60a2024-05-21 16:15:13 +0800710 ret = clear_misc_partition();
711 if (ret) {
712 printf("clear misc partition error\n");
713 fastboot_fail("clear misc partition fail", response);
714 return;
715 }
716
Xindong Xud9441422024-01-18 10:20:45 +0800717 gpt_flag = aml_gpt_valid(mmc);
718 if (gpt_flag == 0)
719 ret = 0;
720
721#if defined(CONFIG_EFUSE_OBJ_API) && defined(CONFIG_CMD_EFUSE)
722 run_command("efuse_obj get FEAT_DISABLE_EMMC_USER", 0);
723
724 if (*efuse_field.data == 1) {
725 wrnP("efuse_field.data == 1\n");
726 ret = 0;
727 env_set("nocs_mode", "true");
728 } else {
729 wrnP("efuse_field.data != 1\n");
730 env_set("nocs_mode", "false");
731 }
732#endif//#ifdef CONFIG_EFUSE_OBJ_API
733
Xindong Xu22e8daf2024-03-12 18:08:41 +0800734 bootloaderindex = env_get("forUpgrade_bootloaderIndex");
735
736 if (ret == 0) {
737 printf("gpt/nocs mode\n");
Alex Kiernanf73a7df2018-05-29 15:30:53 +0000738#if CONFIG_IS_ENABLED(FASTBOOT_FLASH_MMC)
Xindong Xu22e8daf2024-03-12 18:08:41 +0800739 fastboot_mmc_flash_write("bootloader-boot1", fastboot_buf_addr, image_size,
740 response);
741 if (strcmp(bootloaderindex, "1") != 0) {
742 printf("boot from boot1, means boot0 is error, rewrite it\n");
743 fastboot_mmc_flash_write("bootloader-boot0",
744 fastboot_buf_addr, image_size, response);
745 run_command("mmc dev 1 0;", 0);
746 set_fastboot_flag(0);
747 } else {
748 printf("need to set fastboot_step\n");
749 run_command("mmc dev 1 0;", 0);
750 set_fastboot_flag(1);
751 }
Xindong Xud9441422024-01-18 10:20:45 +0800752#endif
Xindong Xu22e8daf2024-03-12 18:08:41 +0800753 return;
754 } else {
755 printf("normal mode\n");
756#if CONFIG_IS_ENABLED(FASTBOOT_FLASH_MMC)
757 fastboot_mmc_flash_write("bootloader-boot0", fastboot_buf_addr, image_size,
758 response);
759 fastboot_mmc_flash_write("bootloader-boot1", fastboot_buf_addr, image_size,
760 response);
761 if (strcmp(bootloaderindex, "0") != 0) {
762 printf("boot from boot0, rewrite user bootloader is error\n");
763 fastboot_mmc_flash_write("bootloader",
764 fastboot_buf_addr, image_size, response);
765 run_command("mmc dev 1 0;", 0);
766 set_fastboot_flag(0);
767 } else {
768 run_command("mmc dev 1 0;", 0);
769 set_fastboot_flag(1);
770 }
771#endif
772 return;
773 }
Xindong Xud9441422024-01-18 10:20:45 +0800774 }
775#endif
776
777 if (strcmp(cmd_parameter, "avb_custom_key") == 0) {
778 char* buffer = NULL;
779 char *partition = "misc";
780 AvbKey_t key;
781 printf("avb_custom_key image_size: %d\n", image_size);
782
783 if (image_size > AVB_CUSTOM_KEY_LEN_MAX - sizeof(AvbKey_t)) {
784 printf("key size is too large\n");
785 fastboot_fail("size error", response);
786 return;
787 }
788
789 memcpy(key.magic_name, "AVBK", 4);
790 key.size = image_size;
791 rc = store_part_size(partition);
792
793 buffer = (char *)malloc(AVB_CUSTOM_KEY_LEN_MAX);
794 if (!buffer) {
795 printf("malloc error\n");
796 fastboot_fail("malloc error", response);
797 return;
798 }
799 memset(buffer, 0, AVB_CUSTOM_KEY_LEN_MAX);
800 memcpy(buffer, &key, sizeof(AvbKey_t));
801 memcpy(buffer + sizeof(AvbKey_t), fastboot_buf_addr, image_size);
802
803 store_write((const char *)partition, rc - AVB_CUSTOM_KEY_LEN_MAX,
804 AVB_CUSTOM_KEY_LEN_MAX, (unsigned char *)buffer);
805
806 fastboot_okay(NULL, response);
807 free(buffer);
808 return;
809 }
810
811 if (strcmp(cmd_parameter, "userdata") == 0 || strcmp(cmd_parameter, "data") == 0) {
812 fastboot_okay(NULL, response);
813 return;
814 } else if (strcmp(cmd_parameter, "dts") == 0) {
815 strcpy(name, "dtb");
Zhigang Yua69e3f92024-06-18 03:13:38 +0000816 } else if (!strcmp(cmd_parameter, "bootloader-boot0") ||
817 !strcmp(cmd_parameter, "bootloader-boot1")) {
yihui wu7935bce2024-12-17 01:17:08 +0800818#ifdef CONFIG_MESON_S7D
Dongjin Kimddfb7182025-02-24 16:50:49 +0900819#ifdef CONFIG_AML_V3_FACTORY_BURN
Zhigang Yua69e3f92024-06-18 03:13:38 +0000820 ret = update_boot_hdr_4_s7d_reva(fastboot_buf_addr, image_size, 0);
821 if (ret) {
822 printf("Failed to write s7d reva boot0\n");
823 fastboot_fail("Failed to write s7d reva boot0-1", response);
824 return;
825 }
Dongjin Kimddfb7182025-02-24 16:50:49 +0900826#endif
yihui wu7935bce2024-12-17 01:17:08 +0800827#endif//#ifdef CONFIG_MESON_S7D
hao.qi278cfd32024-06-28 16:09:50 +0800828 strlcpy(name, cmd_parameter, 31);
Xindong Xud9441422024-01-18 10:20:45 +0800829 } else {
hao.qi278cfd32024-06-28 16:09:50 +0800830 strlcpy(name, cmd_parameter, 31);
Xindong Xud9441422024-01-18 10:20:45 +0800831 }
832 strcat(name, "\0");
833
834#ifdef CONFIG_BOOTLOADER_CONTROL_BLOCK
835 if (dynamic_partition) {
836 if (is_partition_logical(name) == 0) {
837 printf("logic partition, can not write here.......\n");
838 fastboot_fail("logic partition", response);
839 return;
840 }
841 }
842#endif
843
844#if CONFIG_IS_ENABLED(FASTBOOT_FLASH_MMC)
845 fastboot_mmc_flash_write(name, fastboot_buf_addr, image_size,
Alex Kiernanf73a7df2018-05-29 15:30:53 +0000846 response);
847#endif
848#if CONFIG_IS_ENABLED(FASTBOOT_FLASH_NAND)
Xindong Xud9441422024-01-18 10:20:45 +0800849 fastboot_nand_flash_write(name, fastboot_buf_addr, image_size,
Alex Kiernanf73a7df2018-05-29 15:30:53 +0000850 response);
851#endif
Xindong Xud9441422024-01-18 10:20:45 +0800852
853 if (strcmp(name, "bootloader") == 0) {
854 env_set("default_env", "1");
855#if CONFIG_IS_ENABLED(AML_UPDATE_ENV)
856 run_command("update_env_part -p default_env;", 0);
857#else
858 run_command("defenv_reserve;saveenv;", 0);
859#endif// #if CONFIG_IS_ENABLED(AML_UPDATE_ENV)
860 }
861
862 if (strcmp(name, "bootloader-boot0") == 0 ||
863 strcmp(name, "bootloader-boot1") == 0) {
864 printf("try to switch back to user\n");
865 run_command("mmc dev 1 0;", 0);
866 }
867
868#ifdef CONFIG_FASTBOOT_FLASH_MMC_DEV
869 if (mmc && aml_gpt_valid(mmc) == 0) {
870 if (vendor_boot_partition) {
871 if (strcmp_l1("vendor_boot", name) == 0) {
872 printf("gpt mode, write dts to reserve\n");
873 write_dts_reserve();
874 }
875 } else {
876 if (strcmp_l1("boot", name) == 0) {
877 printf("gpt mode, write dts to reserve\n");
878 write_dts_reserve();
879 }
880 }
881 }
882#endif
883
884#endif
Alex Kiernanf73a7df2018-05-29 15:30:53 +0000885}
886
887/**
888 * erase() - erase the indicated partition.
889 *
890 * @cmd_parameter: Pointer to partition name
891 * @response: Pointer to fastboot response buffer
892 *
893 * Erases the partition indicated by cmd_parameter (clear to 0x00s). Writes
894 * to response.
895 */
896static void erase(char *cmd_parameter, char *response)
897{
Xindong Xud9441422024-01-18 10:20:45 +0800898#ifdef CONFIG_AMLOGIC_MODIFY
899 char name[32] = {0};
900 u64 rc = 0;
901
902 if (check_lock() == 1) {
903 printf("device is locked, can not run this cmd.Please flashing unlock & flashing unlock_critical\n");
904 fastboot_fail("locked device", response);
905 return;
906 }
907
908 printf("cmd_parameter: %s\n", cmd_parameter);
909
910#ifdef CONFIG_FASTBOOT_FLASH_MMC_DEV
911 struct mmc *mmc = find_mmc_device(CONFIG_FASTBOOT_FLASH_MMC_DEV);
912 if ((mmc != NULL) && strcmp(cmd_parameter, "bootloader") == 0 && (aml_gpt_valid(mmc) == 0)) {
913 printf("we write gpt partition table to bootloader now\n");
914 printf("plese write bootloader to bootloader-boot0/bootloader-boot1\n");
915 fastboot_okay("gpt mode, skip", response);
916 return;
917 }
918#endif
919
920 if (strcmp(cmd_parameter, "avb_custom_key") == 0) {
921 char* buffer = NULL;
922 char *partition = "misc";
923
924 rc = store_part_size(partition);
925 buffer = (char *)malloc(AVB_CUSTOM_KEY_LEN_MAX);
926 if (!buffer) {
927 printf("malloc error\n");
928 fastboot_fail("malloc error", response);
929 return;
930 }
931 memset(buffer, 0, AVB_CUSTOM_KEY_LEN_MAX);
932
933 store_write((const char *)partition, rc - AVB_CUSTOM_KEY_LEN_MAX,
934 AVB_CUSTOM_KEY_LEN_MAX, (unsigned char *)buffer);
935
936 fastboot_okay(NULL, response);
937 free(buffer);
938 return;
939 }
940
941 if (strcmp(cmd_parameter, "env") == 0) {
942 char *fastboot_step = env_get("fastboot_step");
943
944 if (fastboot_step && strcmp(fastboot_step, "0")) {
945 printf("fastboot_step: %s, run defenv_reserv\n", fastboot_step);
946 run_command("defenv_reserv; setenv upgrade_step 2; saveenv;", 0);
947 run_command("run bcb_cmd", 0);
948 fastboot_okay(NULL, response);
949 return;
950 }
951 }
952
953 if (strcmp(cmd_parameter, "misc") == 0) {
954 char* buffer = NULL;
955 char *partition = "misc";
956
957 rc = store_part_size(partition);
958 buffer = (char *)malloc(rc - AVB_CUSTOM_KEY_LEN_MAX);
959 if (!buffer) {
960 printf("malloc error\n");
961 fastboot_fail("malloc error", response);
962 return;
963 }
964 memset(buffer, 0, rc - AVB_CUSTOM_KEY_LEN_MAX);
965
966 store_write((const char *)partition, 0, rc - AVB_CUSTOM_KEY_LEN_MAX,
967 (unsigned char *)buffer);
968
969 fastboot_okay(NULL, response);
970 free(buffer);
971 return;
972 }
973
974 if (strcmp(cmd_parameter, "userdata") == 0 || strcmp(cmd_parameter, "data") == 0) {
975 rc = store_part_size("userdata");
976 if (-1 == rc)
977 strcpy(name, "data");
978 else
979 strcpy(name, "userdata");
980 } else if (strcmp(cmd_parameter, "dts") == 0) {
981 strcpy(name, "dtb");
982 } else {
983 strncpy(name, cmd_parameter, 31);
984 }
985 strcat(name, "\0");
986
987#ifdef CONFIG_BOOTLOADER_CONTROL_BLOCK
988 if (dynamic_partition) {
989 if (is_partition_logical(name) == 0) {
990 printf("logic partition, can not erase here.......\n");
991 fastboot_fail("logic partition", response);
992 return;
993 }
994 }
995#endif
996
Alex Kiernanf73a7df2018-05-29 15:30:53 +0000997#if CONFIG_IS_ENABLED(FASTBOOT_FLASH_MMC)
Xindong Xud9441422024-01-18 10:20:45 +0800998 fastboot_mmc_erase(name, response);
Alex Kiernanf73a7df2018-05-29 15:30:53 +0000999#endif
1000#if CONFIG_IS_ENABLED(FASTBOOT_FLASH_NAND)
Xindong Xud9441422024-01-18 10:20:45 +08001001 fastboot_nand_erase(name, response);
1002#endif
1003
Alex Kiernanf73a7df2018-05-29 15:30:53 +00001004#endif
1005}
1006#endif
Xindong Xud9441422024-01-18 10:20:45 +08001007#endif
1008
1009#ifdef CONFIG_FASTBOOT_WRITING_CMD
1010
1011#ifdef CONFIG_AMLOGIC_MODIFY
1012static u64 my_ato11(const char *str)
1013{
1014 u64 result = 0;
1015 int len, i;
1016
1017 len = strlen(str);
1018 for (i = 0; i < len; i++) {
1019 if (*str >= '0' && *str <= '9')
1020 result = result * 16 + (*str - '0');
1021 else if (*str >= 'A' && *str <= 'F')
1022 result = result * 16 + (*str - 'A') + 10;
1023 else if (*str >= 'a' && *str <= 'f')
1024 result = result * 16 + (*str - 'a') + 10;
1025 str++;
1026 }
1027
1028 return result;
1029}
1030
1031static void fetch(char *cmd_parameter, char *response)
1032{
1033 int len;
1034 int i = 0;
1035 char *cmd;
1036 char name[32] = {0};
1037 u64 offset = 0;
1038 u64 read_size = 0;
1039 size_t size = 0;
1040
1041 if (check_lock() == 1) {
1042 printf("device is locked, can not run this cmd\n");
1043 fastboot_fail("locked device", response);
1044 return;
1045 }
1046
1047 cmd = cmd_parameter;
1048 len = strlen(cmd_parameter);
1049 while (strsep(&cmd, ":"))
1050 i++;
1051
1052 for (cmd = cmd_parameter, i = 0; cmd < (cmd_parameter + len); i++) {
1053 /* Skip to next assignment */
1054 if (i == 0) {
1055 strncpy(name, cmd, 31);
1056 strcat(name, "\0");
1057 } else if (i == 1) {
1058 offset = my_ato11(cmd);
1059 } else if (i == 2) {
1060 read_size = my_ato11(cmd);
1061 }
1062
1063 for (cmd += strlen(cmd); cmd < (cmd_parameter + len) && !*cmd;)
1064 cmd++;
1065 }
1066
1067 printf("name: %s\n", name);
1068 if (strncmp("vendor_boot", name, strlen("vendor_boot")) != 0) {
1069 printf("We can only %s vendor_boot\n", __func__);
1070 fastboot_fail("Fetch is only allowed on vendor_boot", response);
1071 return;
1072 }
1073
1074#if CONFIG_IS_ENABLED(FASTBOOT_FLASH_MMC)
1075 struct blk_desc *dev_desc;
1076 disk_partition_t part_info;
1077 int r;
1078
1079 r = fastboot_mmc_get_part_info(name, &dev_desc, &part_info,
1080 response);
1081 if (r >= 0)
1082 size = part_info.size * 512;
1083#endif
1084#if CONFIG_IS_ENABLED(FASTBOOT_FLASH_NAND)
1085 struct part_info *part_info;
1086 int r;
1087
1088 r = fastboot_nand_get_part_info(name, &part_info, response);
1089 if (r >= 0)
1090 size = part_info->size * 512;
1091#endif
1092
1093 if (offset > size) {
1094 printf("Invalid offset: 0x%llx, partition size is 0x%lx\n",
1095 offset, size);
1096 fastboot_fail("Invalid offset", response);
1097 return;
1098 }
1099
1100 if (read_size == 0 || read_size > size - offset ||
1101 read_size > kMaxFetchSizeDefault) {
1102 printf("Invalid read size: 0x%llx, partition size is 0x%lx\n",
1103 offset, size);
1104 fastboot_fail("Invalid read size", response);
1105 return;
1106 }
1107
1108 printf("Start read %s partition datas!\n", name);
1109 void *buffer;
1110 char str[128] = {0};
1111
1112 buffer = (void *)CONFIG_FASTBOOT_BUF_ADDR;
1113 sprintf(str, "DATA%12llx", read_size);
1114 printf("str: %s, len: %ld\n", str, strlen(str));
1115 memcpy(buffer, str, strlen(str));
1116
1117 if (store_read((const char *)name, offset, read_size,
1118 (unsigned char *)buffer + strlen(str)) < 0) {
1119 printf("failed to store read %s.\n", name);
1120 fastboot_fail("read partition data error", response);
1121 return;
1122 }
1123
1124 fastboot_readInfo.transferredBytes = 0;
1125 fastboot_readInfo.totalBytes = read_size + strlen(str);
1126 fastboot_response("DATA", response, "%12llx", read_size);
1127}
1128
Xindong Xub3cf2a82024-12-25 10:23:47 +08001129static void oem_cmd(char *cmd_parameter, char *response)
1130{
1131 char *cmd;
1132 int i = 0, len = 0, j = 0;
1133 char cmd_str[FASTBOOT_RESPONSE_LEN];
1134
1135 printf("oem cmd_parameter: %s\n", cmd_parameter);
1136
1137 if (IS_FEAT_BOOT_VERIFY()) {
1138 printf("device is secure mode, can not run this cmd.\n");
1139 fastboot_fail("secure boot device", response);
1140 return;
1141 }
1142
1143 if (check_lock() == 1) {
1144 printf("device is locked, can not run this cmd.Please flashing unlock & flashing unlock_critical\n");
1145 fastboot_fail("locked device", response);
1146 return;
1147 }
1148
1149 cmd = cmd_parameter;
1150 strsep(&cmd, " ");
1151 printf("To run cmd[%s]\n", cmd);
1152
1153 len = strlen(cmd);
1154 for (i = 0; i < len; i++) {
1155 if (cmd[i] != '\'')
1156 cmd_str[j++] = cmd[i];
1157 }
1158 cmd_str[j] = '\0';
1159 printf("cmd_str2: %s\n", cmd_str);
1160
1161 run_command(cmd_str, 0);
1162
1163 fastboot_okay(NULL, response);
1164}
1165
Xindong Xud9441422024-01-18 10:20:45 +08001166static void set_active_cmd(char *cmd_parameter, char *response)
1167{
1168 char *cmd;
1169 int ret = 0;
1170 char str[128];
1171
1172 printf("cmd cb_set_active is %s\n", cmd_parameter);
1173 cmd = cmd_parameter;
1174
1175 if (check_lock() == 1) {
1176 printf("device is locked, can not run this cmd.Please flashing unlock & flashing unlock_critical\n");
1177 fastboot_fail("locked device", response);
1178 return;
1179 }
1180
1181 sprintf(str, "set_active_slot %s", cmd);
1182 printf("command: %s\n", str);
1183 ret = run_command(str, 0);
1184 printf("ret = %d\n", ret);
1185 if (ret == 0)
1186 fastboot_okay(NULL, response);
1187 else
1188 fastboot_fail("set slot error", response);
1189}
1190
1191#if !CONFIG_IS_ENABLED(NO_FASTBOOT_FLASHING)
Xindong Xub3cf2a82024-12-25 10:23:47 +08001192#ifdef CONFIG_AVB2
Xindong Xud9441422024-01-18 10:20:45 +08001193static void try_unlock_dev(u64 rc)
1194{
1195#if defined(CONFIG_AML_ANTIROLLBACK) || defined(CONFIG_AML_AVB2_ANTIROLLBACK)
1196 if (is_avb_arb_available()) {
1197 if (avb_unlock()) {
1198 if (-1 == rc) {
1199 printf("unlocking device. Erasing data partition!\n");
1200 run_command("store erase data 0 0", 0);
1201 } else {
1202 printf("unlocking device. Erasing userdata partition!\n");
1203 run_command("store erase userdata 0 0", 0);
1204 }
1205 printf("unlocking device. Erasing metadata partition!\n");
1206 run_command("store erase metadata 0 0", 0);
1207 } else {
1208 printf("unlock failed!\n");
1209 }
1210
1211 return;
1212 }
1213#endif
1214 if (-1 == rc) {
1215 printf("unlocking device. Erasing data partition!\n");
1216 run_command("store erase data 0 0", 0);
1217 } else {
1218 printf("unlocking device. Erasing userdata partition!\n");
1219 run_command("store erase userdata 0 0", 0);
1220 }
1221 printf("unlocking device. Erasing metadata partition!\n");
1222 run_command("store erase metadata 0 0", 0);
1223}
1224
1225static void try_lock_dev(u64 rc)
1226{
1227#if defined(CONFIG_AML_ANTIROLLBACK) || defined(CONFIG_AML_AVB2_ANTIROLLBACK)
1228 if (is_avb_arb_available()) {
1229 if (avb_lock()) {
1230 if (-1 == rc) {
1231 printf("locking device. Erasing data partition!\n");
1232 run_command("store erase data 0 0", 0);
1233 } else {
1234 printf("locking device. Erasing userdata partition!\n");
1235 run_command("store erase userdata 0 0", 0);
1236 }
1237 printf("locking device. Erasing metadata partition!\n");
1238 run_command("store erase metadata 0 0", 0);
1239 } else {
1240 printf("lock failed!\n");
1241 }
1242
1243 return;
1244 }
1245#endif
1246 if (-1 == rc) {
1247 printf("locking device. Erasing data partition!\n");
1248 run_command("store erase data 0 0", 0);
1249 } else {
1250 printf("locking device. Erasing userdata partition!\n");
1251 run_command("store erase userdata 0 0", 0);
1252 }
1253 printf("locking device. Erasing metadata partition!\n");
1254 run_command("store erase metadata 0 0", 0);
1255}
Xindong Xub3cf2a82024-12-25 10:23:47 +08001256#endif
Xindong Xud9441422024-01-18 10:20:45 +08001257
1258/**
1259 * flashing() - lock/unlock.
1260 *
1261 * @cmd_parameter: Pointer to partition name
1262 * @response: Pointer to fastboot response buffer
1263 *
1264 * Writes the previously downloaded image to the partition indicated by
1265 * cmd_parameter. Writes to response.
1266 */
1267static void flashing(char *cmd_parameter, char *response)
1268{
1269 char *cmd;
1270 char* lock_s;
1271 LockData_t info = {0};
1272 char lock_d[LOCK_DATA_SIZE];
1273 u64 rc;
1274 int debug_flag = 0;
1275
Xindong Xu2e748322024-11-22 09:24:46 +08001276#ifndef CONFIG_REFERENCE
Xindong Xud9441422024-01-18 10:20:45 +08001277 if (IS_FEAT_BOOT_VERIFY()) {
1278 printf("device is secure mode, can not run this cmd.\n");
1279 fastboot_fail("secure boot device", response);
1280 return;
1281 }
Xindong Xu2e748322024-11-22 09:24:46 +08001282#endif
Xindong Xud9441422024-01-18 10:20:45 +08001283
1284 lock_s = env_get("lock");
1285 if (!lock_s) {
1286 printf("lock state is NULL \n");
1287 memcpy(lock_d, "10101000", 8);
1288 lock_s = "10101000";
1289 env_set("lock", "10101000");
1290#if CONFIG_IS_ENABLED(AML_UPDATE_ENV)
1291 run_command("update_env_part -p lock;", 0);
1292#else
1293 run_command("defenv_reserv; saveenv;", 0);
1294#endif//#if CONFIG_IS_ENABLED(AML_UPDATE_ENV)
1295 } else {
1296 printf("lock state: %s\n", lock_s);
1297 if (strlen(lock_s) > 15)
1298 strncpy(lock_d, lock_s, 15);
1299 else
1300 strncpy(lock_d, lock_s, strlen(lock_s));
1301 }
1302
1303 info.version_major = (int)(lock_d[0] - '0');
1304 info.version_minor = (int)(lock_d[1] - '0');
1305 info.unlock_ability = (int)(lock_d[2] - '0');
1306 info.lock_state = (int)(lock_d[4] - '0');
1307 info.lock_critical_state = (int)(lock_d[5] - '0');
1308 info.lock_bootloader = (int)(lock_d[6] - '0');
1309 dump_lock_info(info);
1310
1311 printf("cb_flashing cmd_parameter: %s\n", cmd_parameter);
1312 cmd = cmd_parameter;
1313 strsep(&cmd, " ");
1314 printf("cb_flashing: %s\n", cmd);
1315 if (!cmd) {
1316 printf("missing variable\n");
1317 fastboot_fail("missing var", response);
1318 return;
1319 }
1320
1321 boot_img_hdr_t *hdr_addr = NULL;
1322 const int preloadsz = 0x1000 * 2;//4k not enough for signed
1323 unsigned char *pbuffpreload = 0;
1324 char partname[32] = {0};
1325 char *slot_name;
1326 char cmdline[4096];
1327 char *result = NULL;
1328
1329 slot_name = env_get("slot-suffixes");
1330 if (slot_name && (strcmp(slot_name, "0") == 0))
1331 strcpy((char *)partname, "boot_a");
1332 else if (slot_name && (strcmp(slot_name, "1") == 0))
1333 strcpy((char *)partname, "boot_b");
1334 else
1335 strcpy((char *)partname, "boot");
1336
1337 pbuffpreload = malloc(preloadsz);
1338 if (!pbuffpreload) {
1339 printf("Fail to allocate memory!\n");
1340 goto next;
1341 }
1342
1343 hdr_addr = (boot_img_hdr_t *)pbuffpreload;
1344
1345 printf("read from part: %s\n", partname);
1346 rc = store_logic_read(partname, 0, preloadsz, pbuffpreload);
1347 if (rc) {
1348 printf("Fail to read 0x%xB from part[%s] at offset 0\n",
1349 preloadsz, partname);
1350 free(pbuffpreload);
1351 pbuffpreload = 0;
1352 goto next;
1353 }
1354
1355 if (is_android_r_image((void *)hdr_addr)) {
1356 char partname_r[32] = {0};
1357 const int preloadsz_r = 0x1000 * 2;//4k not enough for signed
1358 unsigned char *pbuffpreload_r = 0;
1359 int ret_r = __LINE__;
1360
1361 if (slot_name && (strcmp(slot_name, "0") == 0))
1362 strcpy((char *)partname_r, "vendor_boot_a");
1363 else if (slot_name && (strcmp(slot_name, "1") == 0))
1364 strcpy((char *)partname_r, "vendor_boot_b");
1365 else
1366 strcpy((char *)partname_r, "vendor_boot");
1367
1368 pbuffpreload_r = malloc(preloadsz_r);
1369
1370 if (!pbuffpreload_r) {
1371 printf("Fail to allocate memory for %s!\n",
1372 partname_r);
1373 goto next;
1374 }
1375
1376 printf("read from part: %s\n", partname_r);
1377 ret_r = store_logic_read(partname_r, 0,
1378 preloadsz_r, pbuffpreload_r);
1379 if (ret_r) {
1380 printf("Fail to read 0x%xB from part[%s] at offset 0\n",
1381 preloadsz_r, partname_r);
1382 free(pbuffpreload_r);
1383 pbuffpreload_r = 0;
1384 goto next;
1385 }
1386
1387 p_vendor_boot_img_hdr_t vb_hdr = (p_vendor_boot_img_hdr_t)pbuffpreload_r;
1388
1389 if (*vb_hdr->cmdline) {
1390 printf("Kernel command line: %s\n", vb_hdr->cmdline);
1391 sprintf(cmdline, "%s", vb_hdr->cmdline);
1392 }
1393 free(pbuffpreload_r);
1394 pbuffpreload_r = 0;
1395 } else {
1396 if (*hdr_addr->cmdline) {
1397 printf("Kernel command line: %s\n", hdr_addr->cmdline);
1398 sprintf(cmdline, "%s", hdr_addr->cmdline);
1399 }
1400 }
1401
1402 free(pbuffpreload);
1403 pbuffpreload = 0;
1404
1405 result = strtok(cmdline, " ");
1406 while (result) {
1407 printf("result: %s\n", result);
1408 if (strcmp(result, "buildvariant=userdebug") == 0 ||
1409 strcmp(result, "buildvariant=eng") == 0)
1410 debug_flag = 1;
1411 result = strtok(NULL, " ");
1412 }
1413
1414 if (info.unlock_ability == 0 && debug_flag == 1) {
1415 printf("userdebug mode can ignore\n");
1416 info.unlock_ability = 1;
1417 }
1418
1419next:
1420 rc = store_part_size("userdata");
1421
1422 if (!strcmp_l1("unlock_critical", cmd)) {
1423 info.lock_critical_state = 0;
1424 fastboot_okay(NULL, response);
1425 } else if (!strcmp_l1("lock_critical", cmd)) {
1426 info.lock_critical_state = 1;
1427 fastboot_okay(NULL, response);
1428 } else if (!strcmp_l1("get_unlock_ability", cmd)) {
1429 char str[32];
1430 static bool is_unlock_ability_sent = false;
1431 if (is_unlock_ability_sent) {
1432 is_unlock_ability_sent = false;
1433 fastboot_okay(NULL, response);
1434 busy_flag = 0;
1435 } else {
1436 sprintf(str, "get_unlock_ability: %d",
1437 info.unlock_ability);
1438 fastboot_response("INFO", response, "%s", str);
1439 is_unlock_ability_sent = true;
1440 busy_flag = 1;
1441 }
1442 return;
1443 } else if (!strcmp_l1("get_unlock_bootloader_nonce", cmd)) {
1444 char str_num[8];
1445 sprintf(str_num, "%d", info.lock_critical_state);
1446 fastboot_response("OKAY", response, "%s", str_num);
1447 } else if (!strcmp_l1("lock_bootloader", cmd)) {
1448 info.lock_bootloader = 1;
1449 } else if (!strcmp_l1("unlock", cmd)) {
hao.qi40c37a02024-07-15 13:40:47 +08001450#if defined(CONFIG_AML_ANTIROLLBACK) || defined(CONFIG_AML_AVB2_ANTIROLLBACK)
hao.qi0696a542024-09-12 14:58:03 +08001451 u32 rpmb_lock_state = 0;
1452 bool ret = get_avb_lock_state(&rpmb_lock_state);
hao.qi40c37a02024-07-15 13:40:47 +08001453
hao.qi0696a542024-09-12 14:58:03 +08001454 if (info.lock_state == 1 || (ret && rpmb_lock_state == 1)) {
hao.qi40c37a02024-07-15 13:40:47 +08001455#else
hao.qi0696a542024-09-12 14:58:03 +08001456 if (info.lock_state == 1) {
hao.qi40c37a02024-07-15 13:40:47 +08001457#endif
Xindong Xuac88caf2024-10-28 17:10:12 +08001458#ifdef CONFIG_AVB2
1459 try_unlock_dev(rc);
1460#endif
Xindong Xud9441422024-01-18 10:20:45 +08001461 }
hao.qi0696a542024-09-12 14:58:03 +08001462 info.lock_state = 0;
1463 info.lock_critical_state = 0;
1464 env_set("lock_state", "green");
1465 fastboot_okay(NULL, response);
Xindong Xud9441422024-01-18 10:20:45 +08001466 } else if (!strcmp_l1("lock", cmd)) {
hao.qi40c37a02024-07-15 13:40:47 +08001467#if defined(CONFIG_AML_ANTIROLLBACK) || defined(CONFIG_AML_AVB2_ANTIROLLBACK)
1468 u32 rpmb_lock_state = 0;
1469 bool ret = get_avb_lock_state(&rpmb_lock_state);
1470
1471 if (info.lock_state == 0 || (ret && rpmb_lock_state == 0)) {
1472#else
Xindong Xud9441422024-01-18 10:20:45 +08001473 if (info.lock_state == 0) {
hao.qi40c37a02024-07-15 13:40:47 +08001474#endif
Xindong Xuac88caf2024-10-28 17:10:12 +08001475#ifdef CONFIG_AVB2
1476 try_lock_dev(rc);
1477#endif
Xindong Xud9441422024-01-18 10:20:45 +08001478 }
1479 info.lock_state = 1;
1480 env_set("lock_state", "orange");
1481 fastboot_okay(NULL, response);
1482 } else {
1483 printf("unknown variable: %s\n", cmd);
1484 fastboot_response("FAIL", response, "%s", "Variable not implemented");
1485 }
1486
1487 sprintf(lock_d, "%d%d%d0%d%d%d0", info.version_major, info.version_minor,
1488 info.unlock_ability, info.lock_state, info.lock_critical_state,
1489 info.lock_bootloader);
1490 printf("lock_d state: %s\n", lock_d);
1491 env_set("lock", lock_d);
1492#if CONFIG_IS_ENABLED(AML_UPDATE_ENV)
1493 run_command("update_env_part -p lock;", 0);
1494#else
1495 run_command("defenv_reserv; saveenv;", 0);
1496#endif//#if CONFIG_IS_ENABLED(AML_UPDATE_ENV)
1497 return;
1498}
1499#endif// #if !CONFIG_IS_ENABLED(NO_FASTBOOT_FLASHING)
1500#endif
1501#endif
Alex Kiernanf73a7df2018-05-29 15:30:53 +00001502
Heiko Schocherbc820d52021-02-10 09:29:03 +01001503#if CONFIG_IS_ENABLED(FASTBOOT_UUU_SUPPORT)
1504/**
1505 * run_ucmd() - Execute the UCmd command
1506 *
1507 * @cmd_parameter: Pointer to command parameter
1508 * @response: Pointer to fastboot response buffer
1509 */
1510static void run_ucmd(char *cmd_parameter, char *response)
1511{
1512 if (!cmd_parameter) {
1513 pr_err("missing slot suffix\n");
1514 fastboot_fail("missing command", response);
1515 return;
1516 }
1517
1518 if (run_command(cmd_parameter, 0))
1519 fastboot_fail("", response);
1520 else
1521 fastboot_okay(NULL, response);
1522}
1523
1524static char g_a_cmd_buff[64];
1525
1526void fastboot_acmd_complete(void)
1527{
1528 run_command(g_a_cmd_buff, 0);
1529}
1530
1531/**
1532 * run_acmd() - Execute the ACmd command
1533 *
1534 * @cmd_parameter: Pointer to command parameter
1535 * @response: Pointer to fastboot response buffer
1536 */
1537static void run_acmd(char *cmd_parameter, char *response)
1538{
1539 if (!cmd_parameter) {
1540 pr_err("missing slot suffix\n");
1541 fastboot_fail("missing command", response);
1542 return;
1543 }
1544
1545 if (strlen(cmd_parameter) > sizeof(g_a_cmd_buff)) {
1546 pr_err("too long command\n");
1547 fastboot_fail("too long command", response);
1548 return;
1549 }
1550
1551 strcpy(g_a_cmd_buff, cmd_parameter);
1552 fastboot_okay(NULL, response);
1553}
1554#endif
1555
Alex Kiernanf73a7df2018-05-29 15:30:53 +00001556/**
1557 * reboot_bootloader() - Sets reboot bootloader flag.
1558 *
1559 * @cmd_parameter: Pointer to command parameter
1560 * @response: Pointer to fastboot response buffer
1561 */
1562static void reboot_bootloader(char *cmd_parameter, char *response)
1563{
Xindong Xud9441422024-01-18 10:20:45 +08001564#ifndef CONFIG_AMLOGIC_MODIFY
Roman Kovalivskyi851737a2020-07-28 23:35:32 +03001565 if (fastboot_set_reboot_flag(FASTBOOT_REBOOT_REASON_BOOTLOADER))
Alex Kiernanf73a7df2018-05-29 15:30:53 +00001566 fastboot_fail("Cannot set reboot flag", response);
1567 else
Xindong Xud9441422024-01-18 10:20:45 +08001568#endif
Alex Kiernanf73a7df2018-05-29 15:30:53 +00001569 fastboot_okay(NULL, response);
1570}
Alex Kiernan3845b902018-05-29 15:30:54 +00001571
Roman Kovalivskyi2b2a7712020-07-28 23:35:33 +03001572/**
1573 * reboot_fastbootd() - Sets reboot fastboot flag.
1574 *
1575 * @cmd_parameter: Pointer to command parameter
1576 * @response: Pointer to fastboot response buffer
1577 */
1578static void reboot_fastbootd(char *cmd_parameter, char *response)
1579{
Xindong Xud9441422024-01-18 10:20:45 +08001580#ifndef CONFIG_AMLOGIC_MODIFY
Roman Kovalivskyi2b2a7712020-07-28 23:35:33 +03001581 if (fastboot_set_reboot_flag(FASTBOOT_REBOOT_REASON_FASTBOOTD))
Xindong Xud9441422024-01-18 10:20:45 +08001582 fastboot_fail("Cannot set reboot flag", response);
Roman Kovalivskyi2b2a7712020-07-28 23:35:33 +03001583 else
Xindong Xud9441422024-01-18 10:20:45 +08001584#endif
Roman Kovalivskyi2b2a7712020-07-28 23:35:33 +03001585 fastboot_okay(NULL, response);
1586}
1587
1588/**
1589 * reboot_recovery() - Sets reboot recovery flag.
1590 *
1591 * @cmd_parameter: Pointer to command parameter
1592 * @response: Pointer to fastboot response buffer
1593 */
1594static void reboot_recovery(char *cmd_parameter, char *response)
1595{
Xindong Xud9441422024-01-18 10:20:45 +08001596#ifndef CONFIG_AMLOGIC_MODIFY
Roman Kovalivskyi2b2a7712020-07-28 23:35:33 +03001597 if (fastboot_set_reboot_flag(FASTBOOT_REBOOT_REASON_RECOVERY))
Xindong Xud9441422024-01-18 10:20:45 +08001598 fastboot_fail("Cannot set reboot flag", response);
Roman Kovalivskyi2b2a7712020-07-28 23:35:33 +03001599 else
Xindong Xud9441422024-01-18 10:20:45 +08001600#endif
Roman Kovalivskyi2b2a7712020-07-28 23:35:33 +03001601 fastboot_okay(NULL, response);
1602}
1603
Xindong Xud9441422024-01-18 10:20:45 +08001604#ifdef CONFIG_FASTBOOT_WRITING_CMD
Alex Kiernan3845b902018-05-29 15:30:54 +00001605#if CONFIG_IS_ENABLED(FASTBOOT_CMD_OEM_FORMAT)
1606/**
1607 * oem_format() - Execute the OEM format command
1608 *
1609 * @cmd_parameter: Pointer to command parameter
1610 * @response: Pointer to fastboot response buffer
1611 */
1612static void oem_format(char *cmd_parameter, char *response)
1613{
1614 char cmdbuf[32];
1615
Xindong Xud9441422024-01-18 10:20:45 +08001616#ifdef CONFIG_AMLOGIC_MODIFY
Xindong Xu2e748322024-11-22 09:24:46 +08001617#ifndef CONFIG_REFERENCE
Xindong Xud9441422024-01-18 10:20:45 +08001618 if (IS_FEAT_BOOT_VERIFY()) {
1619 printf("device is secure mode, can not run this cmd.\n");
1620 fastboot_fail("secure boot device", response);
1621 return;
1622 }
Xindong Xu2e748322024-11-22 09:24:46 +08001623#endif
Xindong Xud9441422024-01-18 10:20:45 +08001624
1625 if (check_lock() == 1) {
1626 printf("device is locked, can not run this cmd.Please flashing unlock & flashing unlock_critical\n");
1627 fastboot_fail("locked device", response);
1628 return;
1629 }
1630#endif
1631
Alex Kiernan3845b902018-05-29 15:30:54 +00001632 if (!env_get("partitions")) {
1633 fastboot_fail("partitions not set", response);
1634 } else {
1635 sprintf(cmdbuf, "gpt write mmc %x $partitions",
1636 CONFIG_FASTBOOT_FLASH_MMC_DEV);
1637 if (run_command(cmdbuf, 0))
1638 fastboot_fail("", response);
1639 else
1640 fastboot_okay(NULL, response);
1641 }
1642}
1643#endif
Patrick Delaunayb2f6b972021-01-27 14:46:48 +01001644
1645#if CONFIG_IS_ENABLED(FASTBOOT_CMD_OEM_PARTCONF)
1646/**
1647 * oem_partconf() - Execute the OEM partconf command
1648 *
1649 * @cmd_parameter: Pointer to command parameter
1650 * @response: Pointer to fastboot response buffer
1651 */
1652static void oem_partconf(char *cmd_parameter, char *response)
1653{
1654 char cmdbuf[32];
1655
1656 if (!cmd_parameter) {
1657 fastboot_fail("Expected command parameter", response);
1658 return;
1659 }
1660
1661 /* execute 'mmc partconfg' command with cmd_parameter arguments*/
1662 snprintf(cmdbuf, sizeof(cmdbuf), "mmc partconf %x %s 0",
1663 CONFIG_FASTBOOT_FLASH_MMC_DEV, cmd_parameter);
1664 printf("Execute: %s\n", cmdbuf);
1665 if (run_command(cmdbuf, 0))
1666 fastboot_fail("Cannot set oem partconf", response);
1667 else
1668 fastboot_okay(NULL, response);
1669}
1670#endif
Patrick Delaunay0c0394b2021-01-27 14:46:49 +01001671
1672#if CONFIG_IS_ENABLED(FASTBOOT_CMD_OEM_BOOTBUS)
1673/**
1674 * oem_bootbus() - Execute the OEM bootbus command
1675 *
1676 * @cmd_parameter: Pointer to command parameter
1677 * @response: Pointer to fastboot response buffer
1678 */
1679static void oem_bootbus(char *cmd_parameter, char *response)
1680{
1681 char cmdbuf[32];
1682
1683 if (!cmd_parameter) {
1684 fastboot_fail("Expected command parameter", response);
1685 return;
1686 }
1687
1688 /* execute 'mmc bootbus' command with cmd_parameter arguments*/
1689 snprintf(cmdbuf, sizeof(cmdbuf), "mmc bootbus %x %s",
1690 CONFIG_FASTBOOT_FLASH_MMC_DEV, cmd_parameter);
1691 printf("Execute: %s\n", cmdbuf);
1692 if (run_command(cmdbuf, 0))
1693 fastboot_fail("Cannot set oem bootbus", response);
1694 else
1695 fastboot_okay(NULL, response);
1696}
1697#endif
Xindong Xud9441422024-01-18 10:20:45 +08001698#endif