Scott Anderson | 9bfecb0 | 2012-12-06 09:34:34 -0800 | [diff] [blame] | 1 | |
| 2 | FastBoot Version 0.4 |
| 3 | ---------------------- |
| 4 | |
| 5 | The fastboot protocol is a mechanism for communicating with bootloaders |
David Pursell | 2ec418a | 2016-01-20 08:32:08 -0800 | [diff] [blame^] | 6 | over USB or ethernet. It is designed to be very straightforward to implement, |
| 7 | to allow it to be used across a wide range of devices and from hosts running |
Scott Anderson | 9bfecb0 | 2012-12-06 09:34:34 -0800 | [diff] [blame] | 8 | Linux, Windows, or OSX. |
| 9 | |
| 10 | |
| 11 | Basic Requirements |
| 12 | ------------------ |
| 13 | |
David Pursell | 2ec418a | 2016-01-20 08:32:08 -0800 | [diff] [blame^] | 14 | * USB |
| 15 | * Two bulk endpoints (in, out) are required |
| 16 | * Max packet size must be 64 bytes for full-speed, 512 bytes for |
| 17 | high-speed and 1024 bytes for Super Speed USB. |
| 18 | * The protocol is entirely host-driven and synchronous (unlike the |
| 19 | multi-channel, bi-directional, asynchronous ADB protocol) |
| 20 | |
| 21 | * TCP |
| 22 | * Device must be reachable via IP. |
| 23 | * Device will act as the TCP server, fastboot will be the client. |
| 24 | * Fastboot data is wrapped in a simple protocol; see below for details. |
Scott Anderson | 9bfecb0 | 2012-12-06 09:34:34 -0800 | [diff] [blame] | 25 | |
| 26 | |
| 27 | Transport and Framing |
| 28 | --------------------- |
| 29 | |
| 30 | 1. Host sends a command, which is an ascii string in a single |
| 31 | packet no greater than 64 bytes. |
| 32 | |
| 33 | 2. Client response with a single packet no greater than 64 bytes. |
| 34 | The first four bytes of the response are "OKAY", "FAIL", "DATA", |
| 35 | or "INFO". Additional bytes may contain an (ascii) informative |
| 36 | message. |
| 37 | |
| 38 | a. INFO -> the remaining 60 bytes are an informative message |
| 39 | (providing progress or diagnostic messages). They should |
| 40 | be displayed and then step #2 repeats |
| 41 | |
| 42 | b. FAIL -> the requested command failed. The remaining 60 bytes |
| 43 | of the response (if present) provide a textual failure message |
| 44 | to present to the user. Stop. |
| 45 | |
| 46 | c. OKAY -> the requested command completed successfully. Go to #5 |
| 47 | |
| 48 | d. DATA -> the requested command is ready for the data phase. |
| 49 | A DATA response packet will be 12 bytes long, in the form of |
Elliott Hughes | fc79767 | 2015-04-07 20:12:50 -0700 | [diff] [blame] | 50 | DATA00000000 where the 8 digit hexadecimal number represents |
Scott Anderson | 9bfecb0 | 2012-12-06 09:34:34 -0800 | [diff] [blame] | 51 | the total data size to transfer. |
| 52 | |
| 53 | 3. Data phase. Depending on the command, the host or client will |
| 54 | send the indicated amount of data. Short packets are always |
| 55 | acceptable and zero-length packets are ignored. This phase continues |
| 56 | until the client has sent or received the number of bytes indicated |
| 57 | in the "DATA" response above. |
| 58 | |
| 59 | 4. Client responds with a single packet no greater than 64 bytes. |
| 60 | The first four bytes of the response are "OKAY", "FAIL", or "INFO". |
| 61 | Similar to #2: |
| 62 | |
| 63 | a. INFO -> display the remaining 60 bytes and return to #4 |
| 64 | |
| 65 | b. FAIL -> display the remaining 60 bytes (if present) as a failure |
| 66 | reason and consider the command failed. Stop. |
| 67 | |
| 68 | c. OKAY -> success. Go to #5 |
| 69 | |
| 70 | 5. Success. Stop. |
| 71 | |
| 72 | |
| 73 | Example Session |
| 74 | --------------- |
| 75 | |
| 76 | Host: "getvar:version" request version variable |
| 77 | |
| 78 | Client: "OKAY0.4" return version "0.4" |
| 79 | |
| 80 | Host: "getvar:nonexistant" request some undefined variable |
| 81 | |
| 82 | Client: "OKAY" return value "" |
| 83 | |
| 84 | Host: "download:00001234" request to send 0x1234 bytes of data |
| 85 | |
| 86 | Client: "DATA00001234" ready to accept data |
| 87 | |
| 88 | Host: < 0x1234 bytes > send data |
| 89 | |
| 90 | Client: "OKAY" success |
| 91 | |
| 92 | Host: "flash:bootloader" request to flash the data to the bootloader |
| 93 | |
| 94 | Client: "INFOerasing flash" indicate status / progress |
| 95 | "INFOwriting flash" |
| 96 | "OKAY" indicate success |
| 97 | |
| 98 | Host: "powerdown" send a command |
| 99 | |
| 100 | Client: "FAILunknown command" indicate failure |
| 101 | |
| 102 | |
| 103 | Command Reference |
| 104 | ----------------- |
| 105 | |
| 106 | * Command parameters are indicated by printf-style escape sequences. |
| 107 | |
| 108 | * Commands are ascii strings and sent without the quotes (which are |
| 109 | for illustration only here) and without a trailing 0 byte. |
| 110 | |
| 111 | * Commands that begin with a lowercase letter are reserved for this |
| 112 | specification. OEM-specific commands should not begin with a |
| 113 | lowercase letter, to prevent incompatibilities with future specs. |
| 114 | |
| 115 | "getvar:%s" Read a config/version variable from the bootloader. |
| 116 | The variable contents will be returned after the |
| 117 | OKAY response. |
| 118 | |
| 119 | "download:%08x" Write data to memory which will be later used |
| 120 | by "boot", "ramdisk", "flash", etc. The client |
| 121 | will reply with "DATA%08x" if it has enough |
| 122 | space in RAM or "FAIL" if not. The size of |
| 123 | the download is remembered. |
| 124 | |
| 125 | "verify:%08x" Send a digital signature to verify the downloaded |
| 126 | data. Required if the bootloader is "secure" |
| 127 | otherwise "flash" and "boot" will be ignored. |
| 128 | |
| 129 | "flash:%s" Write the previously downloaded image to the |
| 130 | named partition (if possible). |
| 131 | |
| 132 | "erase:%s" Erase the indicated partition (clear to 0xFFs) |
| 133 | |
| 134 | "boot" The previously downloaded data is a boot.img |
| 135 | and should be booted according to the normal |
| 136 | procedure for a boot.img |
| 137 | |
| 138 | "continue" Continue booting as normal (if possible) |
| 139 | |
| 140 | "reboot" Reboot the device. |
| 141 | |
| 142 | "reboot-bootloader" Reboot back into the bootloader. |
| 143 | Useful for upgrade processes that require upgrading |
| 144 | the bootloader and then upgrading other partitions |
| 145 | using the new bootloader. |
| 146 | |
| 147 | "powerdown" Power off the device. |
| 148 | |
| 149 | |
| 150 | |
| 151 | Client Variables |
| 152 | ---------------- |
| 153 | |
| 154 | The "getvar:%s" command is used to read client variables which |
| 155 | represent various information about the device and the software |
| 156 | on it. |
| 157 | |
| 158 | The various currently defined names are: |
| 159 | |
| 160 | version Version of FastBoot protocol supported. |
| 161 | It should be "0.3" for this document. |
| 162 | |
| 163 | version-bootloader Version string for the Bootloader. |
| 164 | |
| 165 | version-baseband Version string of the Baseband Software |
| 166 | |
| 167 | product Name of the product |
| 168 | |
| 169 | serialno Product serial number |
| 170 | |
| 171 | secure If the value is "yes", this is a secure |
| 172 | bootloader requiring a signature before |
| 173 | it will install or boot images. |
| 174 | |
| 175 | Names starting with a lowercase character are reserved by this |
| 176 | specification. OEM-specific names should not start with lowercase |
| 177 | characters. |
| 178 | |
| 179 | |
David Pursell | 2ec418a | 2016-01-20 08:32:08 -0800 | [diff] [blame^] | 180 | TCP Protocol v1 |
| 181 | --------------- |
| 182 | |
| 183 | The TCP protocol is designed to be a simple way to use the fastboot protocol |
| 184 | over ethernet if USB is not available. |
| 185 | |
| 186 | The device will open a TCP server on port 5554 and wait for a fastboot client |
| 187 | to connect. |
| 188 | |
| 189 | -- Handshake -- |
| 190 | Upon connecting, both sides will send a 4-byte handshake message to ensure they |
| 191 | are speaking the same protocol. This consists of the ASCII characters "FB" |
| 192 | followed by a 2-digit base-10 ASCII version number. For example, the version 1 |
| 193 | handshake message will be [FB01]. |
| 194 | |
| 195 | If either side detects a malformed handshake, it should disconnect. |
| 196 | |
| 197 | The protocol version to use must be the minimum of the versions sent by each |
| 198 | side; if either side cannot speak this protocol version, it should disconnect. |
| 199 | |
| 200 | -- Fastboot Data -- |
| 201 | Once the handshake is complete, fastboot data will be sent as follows: |
| 202 | |
| 203 | [data_size][data] |
| 204 | |
| 205 | Where data_size is an unsigned 8-byte big-endian binary value, and data is the |
| 206 | fastboot packet. The 8-byte length is intended to provide future-proofing even |
| 207 | though currently fastboot packets have a 4-byte maximum length. |
| 208 | |
| 209 | -- Example -- |
| 210 | In this example the fastboot host queries the device for two variables, |
| 211 | "version" and "none". |
| 212 | |
| 213 | Host <connect to the device on port 5555> |
| 214 | Host FB01 |
| 215 | Device FB01 |
| 216 | Host [0x00][0x00][0x00][0x00][0x00][0x00][0x00][0x0E]getvar:version |
| 217 | Device [0x00][0x00][0x00][0x00][0x00][0x00][0x00][0x07]OKAY0.4 |
| 218 | Host [0x00][0x00][0x00][0x00][0x00][0x00][0x00][0x0B]getvar:none |
| 219 | Device [0x00][0x00][0x00][0x00][0x00][0x00][0x00][0x04]OKAY |
| 220 | Host <disconnect> |