Commit 8cb9cd7e436a395ea772763c56788cb19e8c0b83
Committed by
Ji Luo
1 parent
a6ea228bd7
Exists in
smarc_8mq-imx_v2020.04_5.4.24_2.1.0
and in
1 other branch
MA-16457-2 support reboot-fastboot command in u-boot
Android implement the userspace fastboot in Android Recovery. Follow Google's spec, added below 2 fastboot command support: * fastboot getvar is-userspace * fastboot reboot fastboot TEST: fastboot commands. Change-Id: Ib6047413be0a45b3c00626cdb8594809eb8a2b6b Signed-off-by: Haoran.Wang <elven.wang@nxp.com> (cherry picked from commit 314bded076dfc3e544cc7094ce3f6c4c330be4dd)
Showing 7 changed files with 94 additions and 2 deletions Side-by-side Diff
drivers/fastboot/fb_fsl/bcb.h
... | ... | @@ -11,6 +11,7 @@ |
11 | 11 | #define FASTBOOT_BCB_CMD "bootonce-bootloader" |
12 | 12 | #ifdef CONFIG_ANDROID_RECOVERY |
13 | 13 | #define RECOVERY_BCB_CMD "boot-recovery" |
14 | +#define RECOVERY_FASTBOOT_ARG "recovery\n--fastboot" | |
14 | 15 | #endif |
15 | 16 | /* keep same as bootable/recovery/bootloader.h */ |
16 | 17 | struct bootloader_message { |
17 | 18 | |
... | ... | @@ -48,11 +49,19 @@ |
48 | 49 | (u32)(&(((struct bootloader_message_ab *)0)->slot_suffix[BOOTCTRL_IDX])) |
49 | 50 | #define MISC_COMMAND \ |
50 | 51 | (u32)(uintptr_t)(&(((struct bootloader_message *)0)->command[MISC_COMMAND_IDX])) |
52 | + | |
53 | +#ifdef CONFIG_ANDROID_RECOVERY | |
54 | +#define RECOVERY_OPTIONS\ | |
55 | + (u32)(uintptr_t)(&(((struct bootloader_message *)0)->recovery[0])) | |
56 | +#endif | |
51 | 57 | int bcb_rw_block(bool bread, char **ppblock, |
52 | 58 | uint *pblksize, char *pblock_write, uint offset, uint size); |
53 | 59 | |
54 | 60 | int bcb_write_command(char *bcb_command); |
55 | 61 | int bcb_read_command(char *command); |
56 | 62 | |
63 | +#ifdef CONFIG_ANDROID_RECOVERY | |
64 | +int bcb_write_recovery_opt(char *opts); | |
65 | +#endif | |
57 | 66 | #endif |
drivers/fastboot/fb_fsl/command.c
... | ... | @@ -59,4 +59,37 @@ |
59 | 59 | free(p_block); |
60 | 60 | return 0; |
61 | 61 | } |
62 | + | |
63 | +#ifdef CONFIG_ANDROID_RECOVERY | |
64 | +int bcb_write_recovery_opt(char *opts) | |
65 | +{ | |
66 | + int ret = 0; | |
67 | + char *p_block = NULL; | |
68 | + uint offset_in_block = 0; | |
69 | + uint blk_size = 0; | |
70 | + | |
71 | + if (opts == NULL) | |
72 | + return -1; | |
73 | + | |
74 | + | |
75 | + ret = bcb_rw_block(true, &p_block, &blk_size, NULL, RECOVERY_OPTIONS, 32); | |
76 | + if (ret) { | |
77 | + printf("write_bootctl, bcb_rw_block read failed\n"); | |
78 | + return -1; | |
79 | + } | |
80 | + | |
81 | + offset_in_block = RECOVERY_OPTIONS%blk_size; | |
82 | + memcpy(p_block + offset_in_block, opts, 32); | |
83 | + | |
84 | + ret = bcb_rw_block(false, NULL, NULL, p_block, RECOVERY_OPTIONS, 32); | |
85 | + if (ret) { | |
86 | + free(p_block); | |
87 | + printf("write_bootctl, bcb_rw_block write failed\n"); | |
88 | + return -1; | |
89 | + } | |
90 | + | |
91 | + free(p_block); | |
92 | + return 0; | |
93 | +} | |
94 | +#endif |
drivers/fastboot/fb_fsl/fb_fsl_command.c
... | ... | @@ -72,6 +72,20 @@ |
72 | 72 | #endif |
73 | 73 | } |
74 | 74 | |
75 | +#ifdef CONFIG_ANDROID_RECOVERY | |
76 | +/* Write the recovery options with fastboot bootloader commands */ | |
77 | +static void enable_recovery_fastboot(void) | |
78 | +{ | |
79 | +#ifdef CONFIG_BCB_SUPPORT | |
80 | + char msg[32] = {0}; | |
81 | + strncpy(msg, RECOVERY_BCB_CMD, 31); | |
82 | + bcb_write_command(msg); | |
83 | + strncpy(msg, RECOVERY_FASTBOOT_ARG, 31); | |
84 | + bcb_write_recovery_opt(msg); | |
85 | +#endif | |
86 | +} | |
87 | +#endif | |
88 | + | |
75 | 89 | /* Get the Boot mode from BCB cmd or Key pressed */ |
76 | 90 | static FbBootMode fastboot_get_bootmode(void) |
77 | 91 | { |
... | ... | @@ -176,6 +190,24 @@ |
176 | 190 | fastboot_okay(NULL, response); |
177 | 191 | } |
178 | 192 | |
193 | +#ifdef CONFIG_ANDROID_RECOVERY | |
194 | +/** | |
195 | + * reboot_fastboot() - Sets reboot fastboot flag. | |
196 | + * | |
197 | + * @cmd_parameter: Pointer to command parameter | |
198 | + * @response: Pointer to fastboot response buffer | |
199 | + */ | |
200 | +static void reboot_fastboot(char *cmd_parameter, char *response) | |
201 | +{ | |
202 | + enable_recovery_fastboot(); | |
203 | + | |
204 | + if (fastboot_set_reboot_flag()) | |
205 | + fastboot_fail("Cannot set reboot flag", response); | |
206 | + else | |
207 | + fastboot_okay(NULL, response); | |
208 | +} | |
209 | +#endif | |
210 | + | |
179 | 211 | static void upload(char *cmd_parameter, char *response) |
180 | 212 | { |
181 | 213 | if (!fastboot_bytes_received || fastboot_bytes_received > (EP_BUFFER_SIZE * 32)) { |
... | ... | @@ -929,6 +961,12 @@ |
929 | 961 | [FASTBOOT_COMMAND_STAGE] = { |
930 | 962 | .command = "stage", |
931 | 963 | .dispatch = download, |
964 | + }, | |
965 | +#endif | |
966 | +#ifdef CONFIG_ANDROID_RECOVERY | |
967 | + [FASTBOOT_COMMAND_RECOVERY_FASTBOOT] = { | |
968 | + .command = "reboot-fastboot", | |
969 | + .dispatch = reboot_fastboot, | |
932 | 970 | }, |
933 | 971 | #endif |
934 | 972 | }; |
drivers/fastboot/fb_fsl/fb_fsl_getvar.c
... | ... | @@ -48,9 +48,9 @@ |
48 | 48 | #endif |
49 | 49 | |
50 | 50 | #if defined(CONFIG_ANDROID_THINGS_SUPPORT) && defined(CONFIG_ARCH_IMX8M) |
51 | -#define FASTBOOT_COMMON_VAR_NUM 14 | |
51 | +#define FASTBOOT_COMMON_VAR_NUM 15 | |
52 | 52 | #else |
53 | -#define FASTBOOT_COMMON_VAR_NUM 13 | |
53 | +#define FASTBOOT_COMMON_VAR_NUM 14 | |
54 | 54 | #endif |
55 | 55 | |
56 | 56 | #define FASTBOOT_VAR_YES "yes" |
... | ... | @@ -71,6 +71,7 @@ |
71 | 71 | "battery-voltage", |
72 | 72 | "variant", |
73 | 73 | "battery-soc-ok", |
74 | + "is-userspace", | |
74 | 75 | #if defined(CONFIG_ANDROID_THINGS_SUPPORT) && defined(CONFIG_ARCH_IMX8M) |
75 | 76 | "baseboard_id" |
76 | 77 | #endif |
... | ... | @@ -213,6 +214,8 @@ |
213 | 214 | strncat(response, VARIANT_NAME, chars_left); |
214 | 215 | } else if (!strcmp_l1("off-mode-charge", cmd)) { |
215 | 216 | strncat(response, "1", chars_left); |
217 | + } else if (!strcmp_l1("is-userspace", cmd)) { | |
218 | + strncat(response, FASTBOOT_VAR_NO, chars_left); | |
216 | 219 | } else if (!strcmp_l1("downloadsize", cmd) || |
217 | 220 | !strcmp_l1("max-download-size", cmd)) { |
218 | 221 |
drivers/usb/gadget/f_fastboot.c
... | ... | @@ -631,6 +631,9 @@ |
631 | 631 | |
632 | 632 | case FASTBOOT_COMMAND_REBOOT: |
633 | 633 | case FASTBOOT_COMMAND_REBOOT_BOOTLOADER: |
634 | +#ifdef CONFIG_ANDROID_RECOVERY | |
635 | + case FASTBOOT_COMMAND_RECOVERY_FASTBOOT: | |
636 | +#endif | |
634 | 637 | fastboot_func->in_req->complete = compl_do_reset; |
635 | 638 | break; |
636 | 639 | #if CONFIG_IS_ENABLED(FASTBOOT_UUU_SUPPORT) |
include/fastboot.h
net/fastboot.c