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