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