Tom Rini | 83d290c | 2018-05-06 17:58:06 -0400 | [diff] [blame] | 1 | /* SPDX-License-Identifier: GPL-2.0+ */ |
Maxime Ripard | 3c8f98f | 2015-10-15 14:34:13 +0200 | [diff] [blame] | 2 | /* |
| 3 | * (C) Copyright 2008 - 2009 |
| 4 | * Windriver, <www.windriver.com> |
| 5 | * Tom Rix <Tom.Rix@windriver.com> |
| 6 | * |
| 7 | * Copyright 2011 Sebastian Andrzej Siewior <bigeasy@linutronix.de> |
| 8 | * |
| 9 | * Copyright 2014 Linaro, Ltd. |
| 10 | * Rob Herring <robh@kernel.org> |
Maxime Ripard | 3c8f98f | 2015-10-15 14:34:13 +0200 | [diff] [blame] | 11 | */ |
| 12 | #ifndef _FASTBOOT_H_ |
| 13 | #define _FASTBOOT_H_ |
| 14 | |
Alex Kiernan | 1a28d38 | 2018-05-29 15:30:47 +0000 | [diff] [blame] | 15 | #define FASTBOOT_VERSION "0.4" |
| 16 | |
Maxime Ripard | 3c8f98f | 2015-10-15 14:34:13 +0200 | [diff] [blame] | 17 | /* The 64 defined bytes plus \0 */ |
Alex Kiernan | f73a7df | 2018-05-29 15:30:53 +0000 | [diff] [blame] | 18 | #define FASTBOOT_COMMAND_LEN (64 + 1) |
Maxime Ripard | 3c8f98f | 2015-10-15 14:34:13 +0200 | [diff] [blame] | 19 | #define FASTBOOT_RESPONSE_LEN (64 + 1) |
| 20 | |
Alex Kiernan | d2df2ab | 2018-05-29 15:30:41 +0000 | [diff] [blame] | 21 | /** |
Alex Kiernan | f73a7df | 2018-05-29 15:30:53 +0000 | [diff] [blame] | 22 | * All known commands to fastboot |
| 23 | */ |
| 24 | enum { |
| 25 | FASTBOOT_COMMAND_GETVAR = 0, |
| 26 | FASTBOOT_COMMAND_DOWNLOAD, |
| 27 | #if CONFIG_IS_ENABLED(FASTBOOT_FLASH) |
| 28 | FASTBOOT_COMMAND_FLASH, |
| 29 | FASTBOOT_COMMAND_ERASE, |
| 30 | #endif |
| 31 | FASTBOOT_COMMAND_BOOT, |
| 32 | FASTBOOT_COMMAND_CONTINUE, |
| 33 | FASTBOOT_COMMAND_REBOOT, |
| 34 | FASTBOOT_COMMAND_REBOOT_BOOTLOADER, |
Roman Kovalivskyi | 2b2a771 | 2020-07-28 23:35:33 +0300 | [diff] [blame] | 35 | FASTBOOT_COMMAND_REBOOT_FASTBOOTD, |
| 36 | FASTBOOT_COMMAND_REBOOT_RECOVERY, |
Alex Kiernan | f73a7df | 2018-05-29 15:30:53 +0000 | [diff] [blame] | 37 | FASTBOOT_COMMAND_SET_ACTIVE, |
Alex Kiernan | 3845b90 | 2018-05-29 15:30:54 +0000 | [diff] [blame] | 38 | #if CONFIG_IS_ENABLED(FASTBOOT_CMD_OEM_FORMAT) |
| 39 | FASTBOOT_COMMAND_OEM_FORMAT, |
| 40 | #endif |
Patrick Delaunay | b2f6b97 | 2021-01-27 14:46:48 +0100 | [diff] [blame] | 41 | #if CONFIG_IS_ENABLED(FASTBOOT_CMD_OEM_PARTCONF) |
| 42 | FASTBOOT_COMMAND_OEM_PARTCONF, |
| 43 | #endif |
Patrick Delaunay | 0c0394b | 2021-01-27 14:46:49 +0100 | [diff] [blame] | 44 | #if CONFIG_IS_ENABLED(FASTBOOT_CMD_OEM_BOOTBUS) |
| 45 | FASTBOOT_COMMAND_OEM_BOOTBUS, |
| 46 | #endif |
Alex Kiernan | f73a7df | 2018-05-29 15:30:53 +0000 | [diff] [blame] | 47 | |
| 48 | FASTBOOT_COMMAND_COUNT |
| 49 | }; |
| 50 | |
| 51 | /** |
Roman Kovalivskyi | 851737a | 2020-07-28 23:35:32 +0300 | [diff] [blame] | 52 | * Reboot reasons |
| 53 | */ |
| 54 | enum fastboot_reboot_reason { |
| 55 | FASTBOOT_REBOOT_REASON_BOOTLOADER, |
Roman Kovalivskyi | 2b2a771 | 2020-07-28 23:35:33 +0300 | [diff] [blame] | 56 | FASTBOOT_REBOOT_REASON_FASTBOOTD, |
| 57 | FASTBOOT_REBOOT_REASON_RECOVERY, |
Roman Kovalivskyi | 851737a | 2020-07-28 23:35:32 +0300 | [diff] [blame] | 58 | FASTBOOT_REBOOT_REASONS_COUNT |
| 59 | }; |
| 60 | |
| 61 | /** |
Alex Kiernan | d2df2ab | 2018-05-29 15:30:41 +0000 | [diff] [blame] | 62 | * fastboot_response() - Writes a response of the form "$tag$reason". |
| 63 | * |
| 64 | * @tag: The first part of the response |
| 65 | * @response: Pointer to fastboot response buffer |
| 66 | * @format: printf style format string |
| 67 | */ |
| 68 | void fastboot_response(const char *tag, char *response, |
| 69 | const char *format, ...) |
| 70 | __attribute__ ((format (__printf__, 3, 4))); |
| 71 | |
| 72 | /** |
| 73 | * fastboot_fail() - Write a FAIL response of the form "FAIL$reason". |
| 74 | * |
| 75 | * @reason: Pointer to returned reason string |
| 76 | * @response: Pointer to fastboot response buffer |
| 77 | */ |
Alex Kiernan | c4ded03 | 2018-05-29 15:30:40 +0000 | [diff] [blame] | 78 | void fastboot_fail(const char *reason, char *response); |
Alex Kiernan | d2df2ab | 2018-05-29 15:30:41 +0000 | [diff] [blame] | 79 | |
| 80 | /** |
| 81 | * fastboot_okay() - Write an OKAY response of the form "OKAY$reason". |
| 82 | * |
| 83 | * @reason: Pointer to returned reason string, or NULL to send a bare "OKAY" |
| 84 | * @response: Pointer to fastboot response buffer |
| 85 | */ |
Alex Kiernan | c4ded03 | 2018-05-29 15:30:40 +0000 | [diff] [blame] | 86 | void fastboot_okay(const char *reason, char *response); |
Alex Kiernan | f73a7df | 2018-05-29 15:30:53 +0000 | [diff] [blame] | 87 | |
| 88 | /** |
| 89 | * fastboot_set_reboot_flag() - Set flag to indicate reboot-bootloader |
| 90 | * |
| 91 | * Set flag which indicates that we should reboot into the bootloader |
| 92 | * following the reboot that fastboot executes after this function. |
| 93 | * |
| 94 | * This function should be overridden in your board file with one |
| 95 | * which sets whatever flag your board specific Android bootloader flow |
| 96 | * requires in order to re-enter the bootloader. |
| 97 | */ |
Roman Kovalivskyi | 851737a | 2020-07-28 23:35:32 +0300 | [diff] [blame] | 98 | int fastboot_set_reboot_flag(enum fastboot_reboot_reason reason); |
Alex Kiernan | f73a7df | 2018-05-29 15:30:53 +0000 | [diff] [blame] | 99 | |
| 100 | /** |
| 101 | * fastboot_set_progress_callback() - set progress callback |
| 102 | * |
| 103 | * @progress: Pointer to progress callback |
| 104 | * |
| 105 | * Set a callback which is invoked periodically during long running operations |
| 106 | * (flash and erase). This can be used (for example) by the UDP transport to |
| 107 | * send INFO responses to keep the client alive whilst those commands are |
| 108 | * executing. |
| 109 | */ |
| 110 | void fastboot_set_progress_callback(void (*progress)(const char *msg)); |
| 111 | |
| 112 | /* |
| 113 | * fastboot_init() - initialise new fastboot protocol session |
| 114 | * |
| 115 | * @buf_addr: Pointer to download buffer, or NULL for default |
| 116 | * @buf_size: Size of download buffer, or zero for default |
| 117 | */ |
| 118 | void fastboot_init(void *buf_addr, u32 buf_size); |
| 119 | |
| 120 | /** |
| 121 | * fastboot_boot() - Execute fastboot boot command |
| 122 | * |
| 123 | * If ${fastboot_bootcmd} is set, run that command to execute the boot |
| 124 | * process, if that returns, then exit the fastboot server and return |
| 125 | * control to the caller. |
| 126 | * |
| 127 | * Otherwise execute "bootm <fastboot_buf_addr>", if that fails, reset |
| 128 | * the board. |
| 129 | */ |
| 130 | void fastboot_boot(void); |
| 131 | |
| 132 | /** |
| 133 | * fastboot_handle_command() - Handle fastboot command |
| 134 | * |
| 135 | * @cmd_string: Pointer to command string |
| 136 | * @response: Pointer to fastboot response buffer |
| 137 | * |
| 138 | * Return: Executed command, or -1 if not recognized |
| 139 | */ |
| 140 | int fastboot_handle_command(char *cmd_string, char *response); |
| 141 | |
| 142 | /** |
| 143 | * fastboot_data_remaining() - return bytes remaining in current transfer |
| 144 | * |
| 145 | * Return: Number of bytes left in the current download |
| 146 | */ |
| 147 | u32 fastboot_data_remaining(void); |
| 148 | |
| 149 | /** |
| 150 | * fastboot_data_download() - Copy image data to fastboot_buf_addr. |
| 151 | * |
| 152 | * @fastboot_data: Pointer to received fastboot data |
| 153 | * @fastboot_data_len: Length of received fastboot data |
| 154 | * @response: Pointer to fastboot response buffer |
| 155 | * |
| 156 | * Copies image data from fastboot_data to fastboot_buf_addr. Writes to |
| 157 | * response. fastboot_bytes_received is updated to indicate the number |
| 158 | * of bytes that have been transferred. |
| 159 | */ |
| 160 | void fastboot_data_download(const void *fastboot_data, |
| 161 | unsigned int fastboot_data_len, char *response); |
| 162 | |
| 163 | /** |
| 164 | * fastboot_data_complete() - Mark current transfer complete |
| 165 | * |
| 166 | * @response: Pointer to fastboot response buffer |
| 167 | * |
| 168 | * Set image_size and ${filesize} to the total size of the downloaded image. |
| 169 | */ |
| 170 | void fastboot_data_complete(char *response); |
| 171 | |
Maxime Ripard | 3c8f98f | 2015-10-15 14:34:13 +0200 | [diff] [blame] | 172 | #endif /* _FASTBOOT_H_ */ |