blob: d8cb64261cdcd7082ab6d2437118c939a6c28675 [file] [log] [blame]
Sam Protsenko586a1bf2020-01-24 17:53:44 +02001.. SPDX-License-Identifier: GPL-2.0+
2
Sebastian Siewior3aab70a2014-05-05 15:08:10 -05003Android Fastboot
Alex Kiernan277b1332018-05-29 15:30:56 +00004================
Sebastian Siewior3aab70a2014-05-05 15:08:10 -05005
6Overview
Sam Protsenko586a1bf2020-01-24 17:53:44 +02007--------
Sebastian Siewior3aab70a2014-05-05 15:08:10 -05008
Sam Protsenko586a1bf2020-01-24 17:53:44 +02009The protocol that is used over USB and UDP is described in [1]_.
Alex Kiernan277b1332018-05-29 15:30:56 +000010
11The 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
23The following OEM commands are supported (if enabled):
24
Sam Protsenko586a1bf2020-01-24 17:53:44 +020025- ``oem format`` - this executes ``gpt write mmc %x $partitions``
Patrick Delaunayb2f6b972021-01-27 14:46:48 +010026- ``oem partconf`` - this executes ``mmc partconf %x <arg> 0`` to configure eMMC
27 with <arg> = boot_ack boot_partition
Alex Kiernan277b1332018-05-29 15:30:56 +000028
29Support for both eMMC and NAND devices is included.
Sebastian Siewior3aab70a2014-05-05 15:08:10 -050030
31Client installation
Sam Protsenko586a1bf2020-01-24 17:53:44 +020032-------------------
Sebastian Siewior3aab70a2014-05-05 15:08:10 -050033
Alex Kiernan277b1332018-05-29 15:30:56 +000034The counterpart to this is the fastboot client which can be found in
35Android's ``platform/system/core`` repository in the fastboot
36folder. It runs on Windows, Linux and OSX. The fastboot client is
Sam Protsenko586a1bf2020-01-24 17:53:44 +020037part of the Android SDK Platform-Tools and can be downloaded from [2]_.
Sebastian Siewior3aab70a2014-05-05 15:08:10 -050038
39Board specific
Sam Protsenko586a1bf2020-01-24 17:53:44 +020040--------------
Alex Kiernan277b1332018-05-29 15:30:56 +000041
42USB configuration
Sam Protsenko586a1bf2020-01-24 17:53:44 +020043^^^^^^^^^^^^^^^^^
Alex Kiernan277b1332018-05-29 15:30:56 +000044
Sebastian Siewior3aab70a2014-05-05 15:08:10 -050045The fastboot gadget relies on the USB download gadget, so the following
46options must be configured:
47
Alex Kiernan277b1332018-05-29 15:30:56 +000048::
Sebastian Siewior3aab70a2014-05-05 15:08:10 -050049
Alex Kiernan277b1332018-05-29 15:30:56 +000050 CONFIG_USB_GADGET_DOWNLOAD
51 CONFIG_USB_GADGET_VENDOR_NUM
52 CONFIG_USB_GADGET_PRODUCT_NUM
53 CONFIG_USB_GADGET_MANUFACTURER
Barnes, Clifton A183cbff2014-07-22 11:23:56 -040054
Alex Kiernan277b1332018-05-29 15:30:56 +000055NOTE: The ``CONFIG_USB_GADGET_VENDOR_NUM`` must be one of the numbers
56supported by the fastboot client. The list of vendor IDs supported can
57be found in the fastboot client source code.
Sebastian Siewior3aab70a2014-05-05 15:08:10 -050058
Alex Kiernan277b1332018-05-29 15:30:56 +000059General configuration
Sam Protsenko586a1bf2020-01-24 17:53:44 +020060^^^^^^^^^^^^^^^^^^^^^
Alex Kiernan277b1332018-05-29 15:30:56 +000061
62The fastboot protocol requires a large memory buffer for
63downloads. This buffer should be as large as possible for a
64platform. The location of the buffer and size are set with
65``CONFIG_FASTBOOT_BUF_ADDR`` and ``CONFIG_FASTBOOT_BUF_SIZE``. These
66may be overridden on the fastboot command line using ``-l`` and
67``-s``.
68
69Fastboot environment variables
Sam Protsenko586a1bf2020-01-24 17:53:44 +020070------------------------------
Alex Kiernan277b1332018-05-29 15:30:56 +000071
72Partition aliases
Sam Protsenko586a1bf2020-01-24 17:53:44 +020073^^^^^^^^^^^^^^^^^
Sebastian Siewior3aab70a2014-05-05 15:08:10 -050074
Michael Scott8a418022015-03-11 10:02:31 -070075Fastboot partition aliases can also be defined for devices where GPT
Sam Protsenko586a1bf2020-01-24 17:53:44 +020076limitations prevent user-friendly partition names such as ``boot``, ``system``
77and ``cache``. Or, where the actual partition name doesn't match a standard
Alex Kiernan277b1332018-05-29 15:30:56 +000078partition name used commonly with fastboot.
79
80The current implementation checks aliases when accessing partitions by
81name (flash_write and erase functions). To define a partition alias
Sam Protsenko586a1bf2020-01-24 17:53:44 +020082add an environment variable similar to::
Alex Kiernan277b1332018-05-29 15:30:56 +000083
Sam Protsenko586a1bf2020-01-24 17:53:44 +020084 fastboot_partition_alias_<alias partition name>=<actual partition name>
Alex Kiernan277b1332018-05-29 15:30:56 +000085
Sam Protsenko586a1bf2020-01-24 17:53:44 +020086for example::
Alex Kiernan277b1332018-05-29 15:30:56 +000087
Sam Protsenko586a1bf2020-01-24 17:53:44 +020088 fastboot_partition_alias_boot=LNX
Alex Kiernan277b1332018-05-29 15:30:56 +000089
Filip Brozovica17c0cb2020-06-29 13:14:37 +020090Raw partition descriptors
91^^^^^^^^^^^^^^^^^^^^^^^^^
92
93In cases where no partition table is present, a raw partition descriptor can be
94defined, specifying the offset, size, and optionally the MMC hardware partition
95number for a given partition name.
96
97This is useful when using fastboot to flash files (e.g. SPL or U-Boot) to a
98specific offset in the eMMC boot partition, without having to update the entire
99boot partition.
100
101To define a raw partition descriptor, add an environment variable similar to::
102
103 fastboot_raw_partition_<raw partition name>=<offset> <size> [mmcpart <num>]
104
105for example::
106
107 fastboot_raw_partition_boot=0x100 0x1f00 mmcpart 1
108
Alex Kiernan277b1332018-05-29 15:30:56 +0000109Variable overrides
Sam Protsenko586a1bf2020-01-24 17:53:44 +0200110^^^^^^^^^^^^^^^^^^
Alex Kiernan277b1332018-05-29 15:30:56 +0000111
112Variables retrived through ``getvar`` can be overridden by defining
113environment variables of the form ``fastboot.<variable>``. These are
114looked up first so can be used to override values which would
115otherwise be returned. Using this mechanism you can also return types
116for NAND filesystems, as the fully parameterised variable is looked
Sam Protsenko586a1bf2020-01-24 17:53:44 +0200117up, e.g.::
Alex Kiernan277b1332018-05-29 15:30:56 +0000118
Sam Protsenko586a1bf2020-01-24 17:53:44 +0200119 fastboot.partition-type:boot=jffs2
Alex Kiernan277b1332018-05-29 15:30:56 +0000120
121Boot command
Sam Protsenko586a1bf2020-01-24 17:53:44 +0200122^^^^^^^^^^^^
Alex Kiernan277b1332018-05-29 15:30:56 +0000123
Sam Protsenko586a1bf2020-01-24 17:53:44 +0200124When executing the fastboot ``boot`` command, if ``fastboot_bootcmd`` is set
125then that will be executed in place of ``bootm <CONFIG_FASTBOOT_BUF_ADDR>``.
Michael Scott8a418022015-03-11 10:02:31 -0700126
Petr Kulhavyb6dd69a2016-09-09 10:27:16 +0200127Partition Names
Sam Protsenko586a1bf2020-01-24 17:53:44 +0200128---------------
Alex Kiernan277b1332018-05-29 15:30:56 +0000129
130The Fastboot implementation in U-Boot allows to write images into disk
131partitions. Target partitions are referred on the host computer by
132their names.
Petr Kulhavyb6dd69a2016-09-09 10:27:16 +0200133
134For GPT/EFI the respective partition name is used.
135
136For MBR the partitions are referred by generic names according to the
Sam Protsenko586a1bf2020-01-24 17:53:44 +0200137following schema::
Petr Kulhavyb6dd69a2016-09-09 10:27:16 +0200138
Sam Protsenko586a1bf2020-01-24 17:53:44 +0200139 <device type><device index letter><partition index>
Petr Kulhavyb6dd69a2016-09-09 10:27:16 +0200140
Sam Protsenko586a1bf2020-01-24 17:53:44 +0200141Example: ``hda3``, ``sdb1``, ``usbda1``.
Petr Kulhavyb6dd69a2016-09-09 10:27:16 +0200142
143The device type is as follows:
144
Alex Kiernan277b1332018-05-29 15:30:56 +0000145 * IDE, ATAPI and SATA disks: ``hd``
146 * SCSI disks: ``sd``
147 * USB media: ``usbd``
148 * MMC and SD cards: ``mmcsd``
149 * Disk on chip: ``docd``
150 * other: ``xx``
Petr Kulhavyb6dd69a2016-09-09 10:27:16 +0200151
Alex Kiernan277b1332018-05-29 15:30:56 +0000152The device index starts from ``a`` and refers to the interface (e.g. USB
Petr Kulhavyb6dd69a2016-09-09 10:27:16 +0200153controller, SD/MMC controller) or disk index. The partition index starts
Alex Kiernan277b1332018-05-29 15:30:56 +0000154from ``1`` and describes the partition number on the particular device.
Petr Kulhavyb6dd69a2016-09-09 10:27:16 +0200155
156Writing Partition Table
Sam Protsenko586a1bf2020-01-24 17:53:44 +0200157-----------------------
Alex Kiernan277b1332018-05-29 15:30:56 +0000158
Petr Kulhavyb6dd69a2016-09-09 10:27:16 +0200159Fastboot also allows to write the partition table to the media. This can be
160done by writing the respective partition table image to a special target
161"gpt" or "mbr". These names can be customized by defining the following
162configuration options:
163
Alex Kiernan277b1332018-05-29 15:30:56 +0000164::
165
166 CONFIG_FASTBOOT_GPT_NAME
167 CONFIG_FASTBOOT_MBR_NAME
Petr Kulhavyb6dd69a2016-09-09 10:27:16 +0200168
Sebastian Siewior3aab70a2014-05-05 15:08:10 -0500169In Action
Sam Protsenko586a1bf2020-01-24 17:53:44 +0200170---------
Alex Kiernan277b1332018-05-29 15:30:56 +0000171
Sam Protsenko586a1bf2020-01-24 17:53:44 +0200172Enter into fastboot by executing the fastboot command in U-Boot for either USB::
Alex Kiernan277b1332018-05-29 15:30:56 +0000173
174 => fastboot usb 0
175
Sam Protsenko586a1bf2020-01-24 17:53:44 +0200176or UDP::
Alex Kiernan277b1332018-05-29 15:30:56 +0000177
178 => fastboot udp
179 link up on port 0, speed 100, full duplex
180 Using ethernet@4a100000 device
181 Listening for fastboot command on 192.168.0.102
Sebastian Siewior3aab70a2014-05-05 15:08:10 -0500182
Sam Protsenko586a1bf2020-01-24 17:53:44 +0200183On the client side you can fetch the bootloader version for instance::
Alex Kiernan277b1332018-05-29 15:30:56 +0000184
Sam Protsenko29a81142019-07-03 19:34:07 +0300185 $ fastboot getvar version-bootloader
186 version-bootloader: U-Boot 2019.07-rc4-00240-g00c9f2a2ec
187 Finished. Total time: 0.005s
Sebastian Siewior3aab70a2014-05-05 15:08:10 -0500188
Sam Protsenko586a1bf2020-01-24 17:53:44 +0200189or initiate a reboot::
Alex Kiernan277b1332018-05-29 15:30:56 +0000190
191 $ fastboot reboot
Sebastian Siewior3aab70a2014-05-05 15:08:10 -0500192
193and once the client comes back, the board should reset.
194
195You can also specify a kernel image to boot. You have to either specify
Alex Kiernan277b1332018-05-29 15:30:56 +0000196the an image in Android format *or* pass a binary kernel and let the
Sebastian Siewior3aab70a2014-05-05 15:08:10 -0500197fastboot client wrap the Android suite around it. On OMAP for instance you
Sam Protsenko586a1bf2020-01-24 17:53:44 +0200198take zImage kernel and pass it to the fastboot client::
Sebastian Siewior3aab70a2014-05-05 15:08:10 -0500199
Alex Kiernan277b1332018-05-29 15:30:56 +0000200 $ fastboot -b 0x80000000 -c "console=ttyO2 earlyprintk root=/dev/ram0 mem=128M" boot zImage
201 creating boot image...
202 creating boot image - 1847296 bytes
203 downloading 'boot.img'...
204 OKAY [ 2.766s]
205 booting...
206 OKAY [ -0.000s]
207 finished. total time: 2.766s
208
Sam Protsenko586a1bf2020-01-24 17:53:44 +0200209and on the U-Boot side you should see::
Alex Kiernan277b1332018-05-29 15:30:56 +0000210
211 Starting download of 1847296 bytes
212 ........................................................
213 downloading of 1847296 bytes finished
214 Booting kernel..
215 ## Booting Android Image at 0x81000000 ...
216 Kernel load addr 0x80008000 size 1801 KiB
217 Kernel command line: console=ttyO2 earlyprintk root=/dev/ram0 mem=128M
218 Loading Kernel Image ... OK
219 OK
220
221 Starting kernel ...
Sam Protsenko586a1bf2020-01-24 17:53:44 +0200222
223References
224----------
225
226.. [1] :doc:`fastboot-protocol`
227.. [2] https://developer.android.com/studio/releases/platform-tools