Sam Protsenko | cd43fa1 | 2020-01-24 17:53:44 +0200 | [diff] [blame] | 1 | .. SPDX-License-Identifier: GPL-2.0+ |
| 2 | |
Sebastian Siewior | 9d4471e | 2014-05-05 15:08:10 -0500 | [diff] [blame] | 3 | Android Fastboot |
Alex Kiernan | a59e913 | 2018-05-29 15:30:56 +0000 | [diff] [blame] | 4 | ================ |
Sebastian Siewior | 9d4471e | 2014-05-05 15:08:10 -0500 | [diff] [blame] | 5 | |
| 6 | Overview |
Sam Protsenko | cd43fa1 | 2020-01-24 17:53:44 +0200 | [diff] [blame] | 7 | -------- |
Sebastian Siewior | 9d4471e | 2014-05-05 15:08:10 -0500 | [diff] [blame] | 8 | |
Sam Protsenko | cd43fa1 | 2020-01-24 17:53:44 +0200 | [diff] [blame] | 9 | The protocol that is used over USB and UDP is described in [1]_. |
Alex Kiernan | a59e913 | 2018-05-29 15:30:56 +0000 | [diff] [blame] | 10 | |
| 11 | The current implementation supports the following standard commands: |
| 12 | |
| 13 | - ``boot`` |
| 14 | - ``continue`` |
| 15 | - ``download`` |
| 16 | - ``erase`` (if enabled) |
| 17 | - ``flash`` (if enabled) |
| 18 | - ``getvar`` |
| 19 | - ``reboot`` |
| 20 | - ``reboot-bootloader`` |
| 21 | - ``set_active`` (only a stub implementation which always succeeds) |
Heiko Schocher | 3a99448 | 2021-02-10 09:29:03 +0100 | [diff] [blame] | 22 | - ``ucmd`` (if enabled) |
| 23 | - ``acmd`` (if enabled) |
Alex Kiernan | a59e913 | 2018-05-29 15:30:56 +0000 | [diff] [blame] | 24 | |
| 25 | The following OEM commands are supported (if enabled): |
| 26 | |
Sam Protsenko | cd43fa1 | 2020-01-24 17:53:44 +0200 | [diff] [blame] | 27 | - ``oem format`` - this executes ``gpt write mmc %x $partitions`` |
Patrick Delaunay | 6168770 | 2021-01-27 14:46:48 +0100 | [diff] [blame] | 28 | - ``oem partconf`` - this executes ``mmc partconf %x <arg> 0`` to configure eMMC |
| 29 | with <arg> = boot_ack boot_partition |
Patrick Delaunay | 67af29a | 2021-01-27 14:46:49 +0100 | [diff] [blame] | 30 | - ``oem bootbus`` - this executes ``mmc bootbus %x %s`` to configure eMMC |
Sean Anderson | 421bec0 | 2022-12-16 13:20:16 -0500 | [diff] [blame] | 31 | - ``oem run`` - this executes an arbitrary U-Boot command |
Ion Agorria | e64262d | 2024-01-05 09:22:11 +0200 | [diff] [blame] | 32 | - ``oem console`` - this dumps U-Boot console record buffer |
Alexey Romanov | a0ae790 | 2024-04-18 13:01:29 +0300 | [diff] [blame] | 33 | - ``oem board`` - this executes a custom board function which is defined by the vendor |
Alex Kiernan | a59e913 | 2018-05-29 15:30:56 +0000 | [diff] [blame] | 34 | |
| 35 | Support for both eMMC and NAND devices is included. |
Sebastian Siewior | 9d4471e | 2014-05-05 15:08:10 -0500 | [diff] [blame] | 36 | |
| 37 | Client installation |
Sam Protsenko | cd43fa1 | 2020-01-24 17:53:44 +0200 | [diff] [blame] | 38 | ------------------- |
Sebastian Siewior | 9d4471e | 2014-05-05 15:08:10 -0500 | [diff] [blame] | 39 | |
Alex Kiernan | a59e913 | 2018-05-29 15:30:56 +0000 | [diff] [blame] | 40 | The counterpart to this is the fastboot client which can be found in |
| 41 | Android's ``platform/system/core`` repository in the fastboot |
| 42 | folder. It runs on Windows, Linux and OSX. The fastboot client is |
Sam Protsenko | cd43fa1 | 2020-01-24 17:53:44 +0200 | [diff] [blame] | 43 | part of the Android SDK Platform-Tools and can be downloaded from [2]_. |
Sebastian Siewior | 9d4471e | 2014-05-05 15:08:10 -0500 | [diff] [blame] | 44 | |
| 45 | Board specific |
Sam Protsenko | cd43fa1 | 2020-01-24 17:53:44 +0200 | [diff] [blame] | 46 | -------------- |
Alex Kiernan | a59e913 | 2018-05-29 15:30:56 +0000 | [diff] [blame] | 47 | |
| 48 | USB configuration |
Sam Protsenko | cd43fa1 | 2020-01-24 17:53:44 +0200 | [diff] [blame] | 49 | ^^^^^^^^^^^^^^^^^ |
Alex Kiernan | a59e913 | 2018-05-29 15:30:56 +0000 | [diff] [blame] | 50 | |
Sebastian Siewior | 9d4471e | 2014-05-05 15:08:10 -0500 | [diff] [blame] | 51 | The fastboot gadget relies on the USB download gadget, so the following |
| 52 | options must be configured: |
| 53 | |
Alex Kiernan | a59e913 | 2018-05-29 15:30:56 +0000 | [diff] [blame] | 54 | :: |
| 55 | |
| 56 | CONFIG_USB_GADGET_DOWNLOAD |
| 57 | CONFIG_USB_GADGET_VENDOR_NUM |
| 58 | CONFIG_USB_GADGET_PRODUCT_NUM |
| 59 | CONFIG_USB_GADGET_MANUFACTURER |
| 60 | |
| 61 | NOTE: The ``CONFIG_USB_GADGET_VENDOR_NUM`` must be one of the numbers |
| 62 | supported by the fastboot client. The list of vendor IDs supported can |
| 63 | be found in the fastboot client source code. |
Sebastian Siewior | 9d4471e | 2014-05-05 15:08:10 -0500 | [diff] [blame] | 64 | |
Alex Kiernan | a59e913 | 2018-05-29 15:30:56 +0000 | [diff] [blame] | 65 | General configuration |
Sam Protsenko | cd43fa1 | 2020-01-24 17:53:44 +0200 | [diff] [blame] | 66 | ^^^^^^^^^^^^^^^^^^^^^ |
Barnes, Clifton A | 1f9f321 | 2014-07-22 11:23:56 -0400 | [diff] [blame] | 67 | |
Alex Kiernan | a59e913 | 2018-05-29 15:30:56 +0000 | [diff] [blame] | 68 | The fastboot protocol requires a large memory buffer for |
| 69 | downloads. This buffer should be as large as possible for a |
| 70 | platform. The location of the buffer and size are set with |
| 71 | ``CONFIG_FASTBOOT_BUF_ADDR`` and ``CONFIG_FASTBOOT_BUF_SIZE``. These |
| 72 | may be overridden on the fastboot command line using ``-l`` and |
| 73 | ``-s``. |
Sebastian Siewior | 9d4471e | 2014-05-05 15:08:10 -0500 | [diff] [blame] | 74 | |
Alex Kiernan | a59e913 | 2018-05-29 15:30:56 +0000 | [diff] [blame] | 75 | Fastboot environment variables |
Sam Protsenko | cd43fa1 | 2020-01-24 17:53:44 +0200 | [diff] [blame] | 76 | ------------------------------ |
Alex Kiernan | a59e913 | 2018-05-29 15:30:56 +0000 | [diff] [blame] | 77 | |
| 78 | Partition aliases |
Sam Protsenko | cd43fa1 | 2020-01-24 17:53:44 +0200 | [diff] [blame] | 79 | ^^^^^^^^^^^^^^^^^ |
Sebastian Siewior | 9d4471e | 2014-05-05 15:08:10 -0500 | [diff] [blame] | 80 | |
Michael Scott | ced3349 | 2015-03-11 10:02:31 -0700 | [diff] [blame] | 81 | Fastboot partition aliases can also be defined for devices where GPT |
Sam Protsenko | cd43fa1 | 2020-01-24 17:53:44 +0200 | [diff] [blame] | 82 | limitations prevent user-friendly partition names such as ``boot``, ``system`` |
| 83 | and ``cache``. Or, where the actual partition name doesn't match a standard |
Alex Kiernan | a59e913 | 2018-05-29 15:30:56 +0000 | [diff] [blame] | 84 | partition name used commonly with fastboot. |
| 85 | |
| 86 | The current implementation checks aliases when accessing partitions by |
| 87 | name (flash_write and erase functions). To define a partition alias |
Sam Protsenko | cd43fa1 | 2020-01-24 17:53:44 +0200 | [diff] [blame] | 88 | add an environment variable similar to:: |
Alex Kiernan | a59e913 | 2018-05-29 15:30:56 +0000 | [diff] [blame] | 89 | |
Sam Protsenko | cd43fa1 | 2020-01-24 17:53:44 +0200 | [diff] [blame] | 90 | fastboot_partition_alias_<alias partition name>=<actual partition name> |
Alex Kiernan | a59e913 | 2018-05-29 15:30:56 +0000 | [diff] [blame] | 91 | |
Sam Protsenko | cd43fa1 | 2020-01-24 17:53:44 +0200 | [diff] [blame] | 92 | for example:: |
Alex Kiernan | a59e913 | 2018-05-29 15:30:56 +0000 | [diff] [blame] | 93 | |
Sam Protsenko | cd43fa1 | 2020-01-24 17:53:44 +0200 | [diff] [blame] | 94 | fastboot_partition_alias_boot=LNX |
Alex Kiernan | a59e913 | 2018-05-29 15:30:56 +0000 | [diff] [blame] | 95 | |
Filip Brozovic | 859e6a8 | 2020-06-29 13:14:37 +0200 | [diff] [blame] | 96 | Raw partition descriptors |
| 97 | ^^^^^^^^^^^^^^^^^^^^^^^^^ |
| 98 | |
| 99 | In cases where no partition table is present, a raw partition descriptor can be |
| 100 | defined, specifying the offset, size, and optionally the MMC hardware partition |
| 101 | number for a given partition name. |
| 102 | |
| 103 | This is useful when using fastboot to flash files (e.g. SPL or U-Boot) to a |
| 104 | specific offset in the eMMC boot partition, without having to update the entire |
| 105 | boot partition. |
| 106 | |
| 107 | To define a raw partition descriptor, add an environment variable similar to:: |
| 108 | |
| 109 | fastboot_raw_partition_<raw partition name>=<offset> <size> [mmcpart <num>] |
| 110 | |
| 111 | for example:: |
| 112 | |
| 113 | fastboot_raw_partition_boot=0x100 0x1f00 mmcpart 1 |
| 114 | |
Alex Kiernan | a59e913 | 2018-05-29 15:30:56 +0000 | [diff] [blame] | 115 | Variable overrides |
Sam Protsenko | cd43fa1 | 2020-01-24 17:53:44 +0200 | [diff] [blame] | 116 | ^^^^^^^^^^^^^^^^^^ |
Alex Kiernan | a59e913 | 2018-05-29 15:30:56 +0000 | [diff] [blame] | 117 | |
| 118 | Variables retrived through ``getvar`` can be overridden by defining |
| 119 | environment variables of the form ``fastboot.<variable>``. These are |
| 120 | looked up first so can be used to override values which would |
| 121 | otherwise be returned. Using this mechanism you can also return types |
| 122 | for NAND filesystems, as the fully parameterised variable is looked |
Sam Protsenko | cd43fa1 | 2020-01-24 17:53:44 +0200 | [diff] [blame] | 123 | up, e.g.:: |
Alex Kiernan | a59e913 | 2018-05-29 15:30:56 +0000 | [diff] [blame] | 124 | |
Sam Protsenko | cd43fa1 | 2020-01-24 17:53:44 +0200 | [diff] [blame] | 125 | fastboot.partition-type:boot=jffs2 |
Alex Kiernan | a59e913 | 2018-05-29 15:30:56 +0000 | [diff] [blame] | 126 | |
| 127 | Boot command |
Sam Protsenko | cd43fa1 | 2020-01-24 17:53:44 +0200 | [diff] [blame] | 128 | ^^^^^^^^^^^^ |
Alex Kiernan | a59e913 | 2018-05-29 15:30:56 +0000 | [diff] [blame] | 129 | |
Sam Protsenko | cd43fa1 | 2020-01-24 17:53:44 +0200 | [diff] [blame] | 130 | When executing the fastboot ``boot`` command, if ``fastboot_bootcmd`` is set |
| 131 | then that will be executed in place of ``bootm <CONFIG_FASTBOOT_BUF_ADDR>``. |
Michael Scott | ced3349 | 2015-03-11 10:02:31 -0700 | [diff] [blame] | 132 | |
Petr Kulhavy | 9f174c9 | 2016-09-09 10:27:16 +0200 | [diff] [blame] | 133 | Partition Names |
Sam Protsenko | cd43fa1 | 2020-01-24 17:53:44 +0200 | [diff] [blame] | 134 | --------------- |
Alex Kiernan | a59e913 | 2018-05-29 15:30:56 +0000 | [diff] [blame] | 135 | |
| 136 | The Fastboot implementation in U-Boot allows to write images into disk |
| 137 | partitions. Target partitions are referred on the host computer by |
| 138 | their names. |
Petr Kulhavy | 9f174c9 | 2016-09-09 10:27:16 +0200 | [diff] [blame] | 139 | |
| 140 | For GPT/EFI the respective partition name is used. |
| 141 | |
| 142 | For MBR the partitions are referred by generic names according to the |
Sam Protsenko | cd43fa1 | 2020-01-24 17:53:44 +0200 | [diff] [blame] | 143 | following schema:: |
Petr Kulhavy | 9f174c9 | 2016-09-09 10:27:16 +0200 | [diff] [blame] | 144 | |
Sam Protsenko | cd43fa1 | 2020-01-24 17:53:44 +0200 | [diff] [blame] | 145 | <device type><device index letter><partition index> |
Petr Kulhavy | 9f174c9 | 2016-09-09 10:27:16 +0200 | [diff] [blame] | 146 | |
Sam Protsenko | cd43fa1 | 2020-01-24 17:53:44 +0200 | [diff] [blame] | 147 | Example: ``hda3``, ``sdb1``, ``usbda1``. |
Petr Kulhavy | 9f174c9 | 2016-09-09 10:27:16 +0200 | [diff] [blame] | 148 | |
| 149 | The device type is as follows: |
| 150 | |
Alex Kiernan | a59e913 | 2018-05-29 15:30:56 +0000 | [diff] [blame] | 151 | * IDE, ATAPI and SATA disks: ``hd`` |
| 152 | * SCSI disks: ``sd`` |
| 153 | * USB media: ``usbd`` |
| 154 | * MMC and SD cards: ``mmcsd`` |
| 155 | * Disk on chip: ``docd`` |
| 156 | * other: ``xx`` |
Petr Kulhavy | 9f174c9 | 2016-09-09 10:27:16 +0200 | [diff] [blame] | 157 | |
Alex Kiernan | a59e913 | 2018-05-29 15:30:56 +0000 | [diff] [blame] | 158 | The device index starts from ``a`` and refers to the interface (e.g. USB |
Petr Kulhavy | 9f174c9 | 2016-09-09 10:27:16 +0200 | [diff] [blame] | 159 | controller, SD/MMC controller) or disk index. The partition index starts |
Alex Kiernan | a59e913 | 2018-05-29 15:30:56 +0000 | [diff] [blame] | 160 | from ``1`` and describes the partition number on the particular device. |
Petr Kulhavy | 9f174c9 | 2016-09-09 10:27:16 +0200 | [diff] [blame] | 161 | |
Sean Anderson | 21e8476 | 2021-02-05 09:39:02 -0500 | [diff] [blame] | 162 | Alternatively, partition types may be specified using :ref:`U-Boot's partition |
| 163 | syntax <partitions>`. This allows specifying partitions like ``0.1``, |
| 164 | ``0#boot``, or ``:3``. The interface is always ``mmc``. |
| 165 | |
Petr Kulhavy | 9f174c9 | 2016-09-09 10:27:16 +0200 | [diff] [blame] | 166 | Writing Partition Table |
Sam Protsenko | cd43fa1 | 2020-01-24 17:53:44 +0200 | [diff] [blame] | 167 | ----------------------- |
Alex Kiernan | a59e913 | 2018-05-29 15:30:56 +0000 | [diff] [blame] | 168 | |
Petr Kulhavy | 9f174c9 | 2016-09-09 10:27:16 +0200 | [diff] [blame] | 169 | Fastboot also allows to write the partition table to the media. This can be |
| 170 | done by writing the respective partition table image to a special target |
| 171 | "gpt" or "mbr". These names can be customized by defining the following |
| 172 | configuration options: |
| 173 | |
Alex Kiernan | a59e913 | 2018-05-29 15:30:56 +0000 | [diff] [blame] | 174 | :: |
| 175 | |
| 176 | CONFIG_FASTBOOT_GPT_NAME |
| 177 | CONFIG_FASTBOOT_MBR_NAME |
Petr Kulhavy | 9f174c9 | 2016-09-09 10:27:16 +0200 | [diff] [blame] | 178 | |
Sebastian Siewior | 9d4471e | 2014-05-05 15:08:10 -0500 | [diff] [blame] | 179 | In Action |
Sam Protsenko | cd43fa1 | 2020-01-24 17:53:44 +0200 | [diff] [blame] | 180 | --------- |
Alex Kiernan | a59e913 | 2018-05-29 15:30:56 +0000 | [diff] [blame] | 181 | |
Sam Protsenko | cd43fa1 | 2020-01-24 17:53:44 +0200 | [diff] [blame] | 182 | Enter into fastboot by executing the fastboot command in U-Boot for either USB:: |
Alex Kiernan | a59e913 | 2018-05-29 15:30:56 +0000 | [diff] [blame] | 183 | |
| 184 | => fastboot usb 0 |
| 185 | |
Sam Protsenko | cd43fa1 | 2020-01-24 17:53:44 +0200 | [diff] [blame] | 186 | or UDP:: |
Alex Kiernan | a59e913 | 2018-05-29 15:30:56 +0000 | [diff] [blame] | 187 | |
| 188 | => fastboot udp |
| 189 | link up on port 0, speed 100, full duplex |
| 190 | Using ethernet@4a100000 device |
| 191 | Listening for fastboot command on 192.168.0.102 |
Sebastian Siewior | 9d4471e | 2014-05-05 15:08:10 -0500 | [diff] [blame] | 192 | |
Sam Protsenko | cd43fa1 | 2020-01-24 17:53:44 +0200 | [diff] [blame] | 193 | On the client side you can fetch the bootloader version for instance:: |
Alex Kiernan | a59e913 | 2018-05-29 15:30:56 +0000 | [diff] [blame] | 194 | |
Sam Protsenko | ac21e74 | 2019-07-03 19:34:07 +0300 | [diff] [blame] | 195 | $ fastboot getvar version-bootloader |
| 196 | version-bootloader: U-Boot 2019.07-rc4-00240-g00c9f2a2ec |
| 197 | Finished. Total time: 0.005s |
Sebastian Siewior | 9d4471e | 2014-05-05 15:08:10 -0500 | [diff] [blame] | 198 | |
Sam Protsenko | cd43fa1 | 2020-01-24 17:53:44 +0200 | [diff] [blame] | 199 | or initiate a reboot:: |
Alex Kiernan | a59e913 | 2018-05-29 15:30:56 +0000 | [diff] [blame] | 200 | |
| 201 | $ fastboot reboot |
Sebastian Siewior | 9d4471e | 2014-05-05 15:08:10 -0500 | [diff] [blame] | 202 | |
| 203 | and once the client comes back, the board should reset. |
| 204 | |
| 205 | You can also specify a kernel image to boot. You have to either specify |
Alex Kiernan | a59e913 | 2018-05-29 15:30:56 +0000 | [diff] [blame] | 206 | the an image in Android format *or* pass a binary kernel and let the |
Sebastian Siewior | 9d4471e | 2014-05-05 15:08:10 -0500 | [diff] [blame] | 207 | fastboot client wrap the Android suite around it. On OMAP for instance you |
Sam Protsenko | cd43fa1 | 2020-01-24 17:53:44 +0200 | [diff] [blame] | 208 | take zImage kernel and pass it to the fastboot client:: |
Alex Kiernan | a59e913 | 2018-05-29 15:30:56 +0000 | [diff] [blame] | 209 | |
| 210 | $ fastboot -b 0x80000000 -c "console=ttyO2 earlyprintk root=/dev/ram0 mem=128M" boot zImage |
| 211 | creating boot image... |
| 212 | creating boot image - 1847296 bytes |
| 213 | downloading 'boot.img'... |
| 214 | OKAY [ 2.766s] |
| 215 | booting... |
| 216 | OKAY [ -0.000s] |
| 217 | finished. total time: 2.766s |
| 218 | |
Sam Protsenko | cd43fa1 | 2020-01-24 17:53:44 +0200 | [diff] [blame] | 219 | and on the U-Boot side you should see:: |
Alex Kiernan | a59e913 | 2018-05-29 15:30:56 +0000 | [diff] [blame] | 220 | |
| 221 | Starting download of 1847296 bytes |
| 222 | ........................................................ |
| 223 | downloading of 1847296 bytes finished |
| 224 | Booting kernel.. |
| 225 | ## Booting Android Image at 0x81000000 ... |
| 226 | Kernel load addr 0x80008000 size 1801 KiB |
| 227 | Kernel command line: console=ttyO2 earlyprintk root=/dev/ram0 mem=128M |
| 228 | Loading Kernel Image ... OK |
| 229 | OK |
Sebastian Siewior | 9d4471e | 2014-05-05 15:08:10 -0500 | [diff] [blame] | 230 | |
Alex Kiernan | a59e913 | 2018-05-29 15:30:56 +0000 | [diff] [blame] | 231 | Starting kernel ... |
Sam Protsenko | cd43fa1 | 2020-01-24 17:53:44 +0200 | [diff] [blame] | 232 | |
Sean Anderson | 421bec0 | 2022-12-16 13:20:16 -0500 | [diff] [blame] | 233 | Running Shell Commands |
| 234 | ^^^^^^^^^^^^^^^^^^^^^^ |
| 235 | |
| 236 | Normally, arbitrary U-Boot command execution is not enabled. This is so |
| 237 | fastboot can be used to update systems using verified boot. However, such |
| 238 | functionality can be useful for production or when verified boot is not in use. |
| 239 | Enable ``CONFIG_FASTBOOT_OEM_RUN`` to use this functionality. This will enable |
| 240 | ``oem run`` command, which can be used with the fastboot client. For example, |
| 241 | to print "Hello at 115200 baud" (or whatever ``CONFIG_BAUDRATE`` is), run:: |
| 242 | |
| 243 | $ fastboot oem run:'echo Hello at $baudrate baud' |
| 244 | |
| 245 | You can run any command you would normally run on the U-Boot command line, |
| 246 | including multiple commands (using e.g. ``;`` or ``&&``) and control structures |
| 247 | (``if``, ``while``, etc.). The exit code of ``fastboot`` will reflect the exit |
| 248 | code of the command you ran. |
| 249 | |
Alexey Romanov | a0ae790 | 2024-04-18 13:01:29 +0300 | [diff] [blame] | 250 | Running Custom Vendor Code |
| 251 | ^^^^^^^^^^^^^^^^^^^^^^^^^^ |
| 252 | |
| 253 | U-Boot allows you to execute custom fastboot logic, which can be defined |
| 254 | in board/ files. It can still be used for production devices with verified |
| 255 | boot, because the vendor defines logic at compile time by implementing |
| 256 | fastboot_oem_board() function. The attacker will not be able to execute |
| 257 | custom commands / code. For example, this can be useful for custom flashing |
| 258 | or erasing protocols:: |
| 259 | |
| 260 | $ fastboot stage bootloader.img |
| 261 | $ fastboot oem board:write_bootloader |
| 262 | |
| 263 | In this case, ``cmd_parameter`` argument of the function ``fastboot_oem_board()`` |
| 264 | will contain string "write_bootloader" and ``data`` argument is a pointer to |
| 265 | fastboot input buffer, which contains the contents of bootloader.img file. |
| 266 | |
Sam Protsenko | cd43fa1 | 2020-01-24 17:53:44 +0200 | [diff] [blame] | 267 | References |
| 268 | ---------- |
| 269 | |
| 270 | .. [1] :doc:`fastboot-protocol` |
| 271 | .. [2] https://developer.android.com/studio/releases/platform-tools |