blob: 7611f07038eac218297ebd90121391eac8c4e03e [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)
Heiko Schocherbc820d52021-02-10 09:29:03 +010022- ``ucmd`` (if enabled)
23- ``acmd`` (if enabled)
Alex Kiernan277b1332018-05-29 15:30:56 +000024
25The following OEM commands are supported (if enabled):
26
Sam Protsenko586a1bf2020-01-24 17:53:44 +020027- ``oem format`` - this executes ``gpt write mmc %x $partitions``
Patrick Delaunayb2f6b972021-01-27 14:46:48 +010028- ``oem partconf`` - this executes ``mmc partconf %x <arg> 0`` to configure eMMC
29 with <arg> = boot_ack boot_partition
Patrick Delaunay0c0394b2021-01-27 14:46:49 +010030- ``oem bootbus`` - this executes ``mmc bootbus %x %s`` to configure eMMC
Alex Kiernan277b1332018-05-29 15:30:56 +000031
32Support for both eMMC and NAND devices is included.
Sebastian Siewior3aab70a2014-05-05 15:08:10 -050033
34Client installation
Sam Protsenko586a1bf2020-01-24 17:53:44 +020035-------------------
Sebastian Siewior3aab70a2014-05-05 15:08:10 -050036
Alex Kiernan277b1332018-05-29 15:30:56 +000037The counterpart to this is the fastboot client which can be found in
38Android's ``platform/system/core`` repository in the fastboot
39folder. It runs on Windows, Linux and OSX. The fastboot client is
Sam Protsenko586a1bf2020-01-24 17:53:44 +020040part of the Android SDK Platform-Tools and can be downloaded from [2]_.
Sebastian Siewior3aab70a2014-05-05 15:08:10 -050041
42Board specific
Sam Protsenko586a1bf2020-01-24 17:53:44 +020043--------------
Alex Kiernan277b1332018-05-29 15:30:56 +000044
45USB configuration
Sam Protsenko586a1bf2020-01-24 17:53:44 +020046^^^^^^^^^^^^^^^^^
Alex Kiernan277b1332018-05-29 15:30:56 +000047
Sebastian Siewior3aab70a2014-05-05 15:08:10 -050048The fastboot gadget relies on the USB download gadget, so the following
49options must be configured:
50
Alex Kiernan277b1332018-05-29 15:30:56 +000051::
Sebastian Siewior3aab70a2014-05-05 15:08:10 -050052
Alex Kiernan277b1332018-05-29 15:30:56 +000053 CONFIG_USB_GADGET_DOWNLOAD
54 CONFIG_USB_GADGET_VENDOR_NUM
55 CONFIG_USB_GADGET_PRODUCT_NUM
56 CONFIG_USB_GADGET_MANUFACTURER
Barnes, Clifton A183cbff2014-07-22 11:23:56 -040057
Alex Kiernan277b1332018-05-29 15:30:56 +000058NOTE: The ``CONFIG_USB_GADGET_VENDOR_NUM`` must be one of the numbers
59supported by the fastboot client. The list of vendor IDs supported can
60be found in the fastboot client source code.
Sebastian Siewior3aab70a2014-05-05 15:08:10 -050061
Alex Kiernan277b1332018-05-29 15:30:56 +000062General configuration
Sam Protsenko586a1bf2020-01-24 17:53:44 +020063^^^^^^^^^^^^^^^^^^^^^
Alex Kiernan277b1332018-05-29 15:30:56 +000064
65The fastboot protocol requires a large memory buffer for
66downloads. This buffer should be as large as possible for a
67platform. The location of the buffer and size are set with
68``CONFIG_FASTBOOT_BUF_ADDR`` and ``CONFIG_FASTBOOT_BUF_SIZE``. These
69may be overridden on the fastboot command line using ``-l`` and
70``-s``.
71
72Fastboot environment variables
Sam Protsenko586a1bf2020-01-24 17:53:44 +020073------------------------------
Alex Kiernan277b1332018-05-29 15:30:56 +000074
75Partition aliases
Sam Protsenko586a1bf2020-01-24 17:53:44 +020076^^^^^^^^^^^^^^^^^
Sebastian Siewior3aab70a2014-05-05 15:08:10 -050077
Michael Scott8a418022015-03-11 10:02:31 -070078Fastboot partition aliases can also be defined for devices where GPT
Sam Protsenko586a1bf2020-01-24 17:53:44 +020079limitations prevent user-friendly partition names such as ``boot``, ``system``
80and ``cache``. Or, where the actual partition name doesn't match a standard
Alex Kiernan277b1332018-05-29 15:30:56 +000081partition name used commonly with fastboot.
82
83The current implementation checks aliases when accessing partitions by
84name (flash_write and erase functions). To define a partition alias
Sam Protsenko586a1bf2020-01-24 17:53:44 +020085add an environment variable similar to::
Alex Kiernan277b1332018-05-29 15:30:56 +000086
Sam Protsenko586a1bf2020-01-24 17:53:44 +020087 fastboot_partition_alias_<alias partition name>=<actual partition name>
Alex Kiernan277b1332018-05-29 15:30:56 +000088
Sam Protsenko586a1bf2020-01-24 17:53:44 +020089for example::
Alex Kiernan277b1332018-05-29 15:30:56 +000090
Sam Protsenko586a1bf2020-01-24 17:53:44 +020091 fastboot_partition_alias_boot=LNX
Alex Kiernan277b1332018-05-29 15:30:56 +000092
Filip Brozovica17c0cb2020-06-29 13:14:37 +020093Raw partition descriptors
94^^^^^^^^^^^^^^^^^^^^^^^^^
95
96In cases where no partition table is present, a raw partition descriptor can be
97defined, specifying the offset, size, and optionally the MMC hardware partition
98number for a given partition name.
99
100This is useful when using fastboot to flash files (e.g. SPL or U-Boot) to a
101specific offset in the eMMC boot partition, without having to update the entire
102boot partition.
103
104To define a raw partition descriptor, add an environment variable similar to::
105
106 fastboot_raw_partition_<raw partition name>=<offset> <size> [mmcpart <num>]
107
108for example::
109
110 fastboot_raw_partition_boot=0x100 0x1f00 mmcpart 1
111
Alex Kiernan277b1332018-05-29 15:30:56 +0000112Variable overrides
Sam Protsenko586a1bf2020-01-24 17:53:44 +0200113^^^^^^^^^^^^^^^^^^
Alex Kiernan277b1332018-05-29 15:30:56 +0000114
115Variables retrived through ``getvar`` can be overridden by defining
116environment variables of the form ``fastboot.<variable>``. These are
117looked up first so can be used to override values which would
118otherwise be returned. Using this mechanism you can also return types
119for NAND filesystems, as the fully parameterised variable is looked
Sam Protsenko586a1bf2020-01-24 17:53:44 +0200120up, e.g.::
Alex Kiernan277b1332018-05-29 15:30:56 +0000121
Sam Protsenko586a1bf2020-01-24 17:53:44 +0200122 fastboot.partition-type:boot=jffs2
Alex Kiernan277b1332018-05-29 15:30:56 +0000123
124Boot command
Sam Protsenko586a1bf2020-01-24 17:53:44 +0200125^^^^^^^^^^^^
Alex Kiernan277b1332018-05-29 15:30:56 +0000126
Sam Protsenko586a1bf2020-01-24 17:53:44 +0200127When executing the fastboot ``boot`` command, if ``fastboot_bootcmd`` is set
128then that will be executed in place of ``bootm <CONFIG_FASTBOOT_BUF_ADDR>``.
Michael Scott8a418022015-03-11 10:02:31 -0700129
Petr Kulhavyb6dd69a2016-09-09 10:27:16 +0200130Partition Names
Sam Protsenko586a1bf2020-01-24 17:53:44 +0200131---------------
Alex Kiernan277b1332018-05-29 15:30:56 +0000132
133The Fastboot implementation in U-Boot allows to write images into disk
134partitions. Target partitions are referred on the host computer by
135their names.
Petr Kulhavyb6dd69a2016-09-09 10:27:16 +0200136
137For GPT/EFI the respective partition name is used.
138
139For MBR the partitions are referred by generic names according to the
Sam Protsenko586a1bf2020-01-24 17:53:44 +0200140following schema::
Petr Kulhavyb6dd69a2016-09-09 10:27:16 +0200141
Sam Protsenko586a1bf2020-01-24 17:53:44 +0200142 <device type><device index letter><partition index>
Petr Kulhavyb6dd69a2016-09-09 10:27:16 +0200143
Sam Protsenko586a1bf2020-01-24 17:53:44 +0200144Example: ``hda3``, ``sdb1``, ``usbda1``.
Petr Kulhavyb6dd69a2016-09-09 10:27:16 +0200145
146The device type is as follows:
147
Alex Kiernan277b1332018-05-29 15:30:56 +0000148 * IDE, ATAPI and SATA disks: ``hd``
149 * SCSI disks: ``sd``
150 * USB media: ``usbd``
151 * MMC and SD cards: ``mmcsd``
152 * Disk on chip: ``docd``
153 * other: ``xx``
Petr Kulhavyb6dd69a2016-09-09 10:27:16 +0200154
Alex Kiernan277b1332018-05-29 15:30:56 +0000155The device index starts from ``a`` and refers to the interface (e.g. USB
Petr Kulhavyb6dd69a2016-09-09 10:27:16 +0200156controller, SD/MMC controller) or disk index. The partition index starts
Alex Kiernan277b1332018-05-29 15:30:56 +0000157from ``1`` and describes the partition number on the particular device.
Petr Kulhavyb6dd69a2016-09-09 10:27:16 +0200158
Sean Anderson403c2e42021-02-05 09:39:02 -0500159Alternatively, partition types may be specified using :ref:`U-Boot's partition
160syntax <partitions>`. This allows specifying partitions like ``0.1``,
161``0#boot``, or ``:3``. The interface is always ``mmc``.
162
Petr Kulhavyb6dd69a2016-09-09 10:27:16 +0200163Writing Partition Table
Sam Protsenko586a1bf2020-01-24 17:53:44 +0200164-----------------------
Alex Kiernan277b1332018-05-29 15:30:56 +0000165
Petr Kulhavyb6dd69a2016-09-09 10:27:16 +0200166Fastboot also allows to write the partition table to the media. This can be
167done by writing the respective partition table image to a special target
168"gpt" or "mbr". These names can be customized by defining the following
169configuration options:
170
Alex Kiernan277b1332018-05-29 15:30:56 +0000171::
172
173 CONFIG_FASTBOOT_GPT_NAME
174 CONFIG_FASTBOOT_MBR_NAME
Petr Kulhavyb6dd69a2016-09-09 10:27:16 +0200175
Sebastian Siewior3aab70a2014-05-05 15:08:10 -0500176In Action
Sam Protsenko586a1bf2020-01-24 17:53:44 +0200177---------
Alex Kiernan277b1332018-05-29 15:30:56 +0000178
Sam Protsenko586a1bf2020-01-24 17:53:44 +0200179Enter into fastboot by executing the fastboot command in U-Boot for either USB::
Alex Kiernan277b1332018-05-29 15:30:56 +0000180
181 => fastboot usb 0
182
Sam Protsenko586a1bf2020-01-24 17:53:44 +0200183or UDP::
Alex Kiernan277b1332018-05-29 15:30:56 +0000184
185 => fastboot udp
186 link up on port 0, speed 100, full duplex
187 Using ethernet@4a100000 device
188 Listening for fastboot command on 192.168.0.102
Sebastian Siewior3aab70a2014-05-05 15:08:10 -0500189
Sam Protsenko586a1bf2020-01-24 17:53:44 +0200190On the client side you can fetch the bootloader version for instance::
Alex Kiernan277b1332018-05-29 15:30:56 +0000191
Sam Protsenko29a81142019-07-03 19:34:07 +0300192 $ fastboot getvar version-bootloader
193 version-bootloader: U-Boot 2019.07-rc4-00240-g00c9f2a2ec
194 Finished. Total time: 0.005s
Sebastian Siewior3aab70a2014-05-05 15:08:10 -0500195
Sam Protsenko586a1bf2020-01-24 17:53:44 +0200196or initiate a reboot::
Alex Kiernan277b1332018-05-29 15:30:56 +0000197
198 $ fastboot reboot
Sebastian Siewior3aab70a2014-05-05 15:08:10 -0500199
200and once the client comes back, the board should reset.
201
202You can also specify a kernel image to boot. You have to either specify
Alex Kiernan277b1332018-05-29 15:30:56 +0000203the an image in Android format *or* pass a binary kernel and let the
Sebastian Siewior3aab70a2014-05-05 15:08:10 -0500204fastboot client wrap the Android suite around it. On OMAP for instance you
Sam Protsenko586a1bf2020-01-24 17:53:44 +0200205take zImage kernel and pass it to the fastboot client::
Sebastian Siewior3aab70a2014-05-05 15:08:10 -0500206
Alex Kiernan277b1332018-05-29 15:30:56 +0000207 $ fastboot -b 0x80000000 -c "console=ttyO2 earlyprintk root=/dev/ram0 mem=128M" boot zImage
208 creating boot image...
209 creating boot image - 1847296 bytes
210 downloading 'boot.img'...
211 OKAY [ 2.766s]
212 booting...
213 OKAY [ -0.000s]
214 finished. total time: 2.766s
215
Sam Protsenko586a1bf2020-01-24 17:53:44 +0200216and on the U-Boot side you should see::
Alex Kiernan277b1332018-05-29 15:30:56 +0000217
218 Starting download of 1847296 bytes
219 ........................................................
220 downloading of 1847296 bytes finished
221 Booting kernel..
222 ## Booting Android Image at 0x81000000 ...
223 Kernel load addr 0x80008000 size 1801 KiB
224 Kernel command line: console=ttyO2 earlyprintk root=/dev/ram0 mem=128M
225 Loading Kernel Image ... OK
226 OK
227
228 Starting kernel ...
Sam Protsenko586a1bf2020-01-24 17:53:44 +0200229
230References
231----------
232
233.. [1] :doc:`fastboot-protocol`
234.. [2] https://developer.android.com/studio/releases/platform-tools