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