blob: 16b11399b30837c60e961d2a5bd2f8652ef96ed0 [file] [log] [blame]
Sam Protsenkocd43fa12020-01-24 17:53:44 +02001.. SPDX-License-Identifier: GPL-2.0+
2
Sebastian Siewior9d4471e2014-05-05 15:08:10 -05003Android Fastboot
Alex Kiernana59e9132018-05-29 15:30:56 +00004================
Sebastian Siewior9d4471e2014-05-05 15:08:10 -05005
6Overview
Sam Protsenkocd43fa12020-01-24 17:53:44 +02007--------
Sebastian Siewior9d4471e2014-05-05 15:08:10 -05008
Sam Protsenkocd43fa12020-01-24 17:53:44 +02009The protocol that is used over USB and UDP is described in [1]_.
Alex Kiernana59e9132018-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 Protsenkocd43fa12020-01-24 17:53:44 +020025- ``oem format`` - this executes ``gpt write mmc %x $partitions``
Patrick Delaunay61687702021-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
Patrick Delaunay67af29a2021-01-27 14:46:49 +010028- ``oem bootbus`` - this executes ``mmc bootbus %x %s`` to configure eMMC
Alex Kiernana59e9132018-05-29 15:30:56 +000029
30Support for both eMMC and NAND devices is included.
Sebastian Siewior9d4471e2014-05-05 15:08:10 -050031
32Client installation
Sam Protsenkocd43fa12020-01-24 17:53:44 +020033-------------------
Sebastian Siewior9d4471e2014-05-05 15:08:10 -050034
Alex Kiernana59e9132018-05-29 15:30:56 +000035The counterpart to this is the fastboot client which can be found in
36Android's ``platform/system/core`` repository in the fastboot
37folder. It runs on Windows, Linux and OSX. The fastboot client is
Sam Protsenkocd43fa12020-01-24 17:53:44 +020038part of the Android SDK Platform-Tools and can be downloaded from [2]_.
Sebastian Siewior9d4471e2014-05-05 15:08:10 -050039
40Board specific
Sam Protsenkocd43fa12020-01-24 17:53:44 +020041--------------
Alex Kiernana59e9132018-05-29 15:30:56 +000042
43USB configuration
Sam Protsenkocd43fa12020-01-24 17:53:44 +020044^^^^^^^^^^^^^^^^^
Alex Kiernana59e9132018-05-29 15:30:56 +000045
Sebastian Siewior9d4471e2014-05-05 15:08:10 -050046The fastboot gadget relies on the USB download gadget, so the following
47options must be configured:
48
Alex Kiernana59e9132018-05-29 15:30:56 +000049::
50
51 CONFIG_USB_GADGET_DOWNLOAD
52 CONFIG_USB_GADGET_VENDOR_NUM
53 CONFIG_USB_GADGET_PRODUCT_NUM
54 CONFIG_USB_GADGET_MANUFACTURER
55
56NOTE: The ``CONFIG_USB_GADGET_VENDOR_NUM`` must be one of the numbers
57supported by the fastboot client. The list of vendor IDs supported can
58be found in the fastboot client source code.
Sebastian Siewior9d4471e2014-05-05 15:08:10 -050059
Alex Kiernana59e9132018-05-29 15:30:56 +000060General configuration
Sam Protsenkocd43fa12020-01-24 17:53:44 +020061^^^^^^^^^^^^^^^^^^^^^
Barnes, Clifton A1f9f3212014-07-22 11:23:56 -040062
Alex Kiernana59e9132018-05-29 15:30:56 +000063The fastboot protocol requires a large memory buffer for
64downloads. This buffer should be as large as possible for a
65platform. The location of the buffer and size are set with
66``CONFIG_FASTBOOT_BUF_ADDR`` and ``CONFIG_FASTBOOT_BUF_SIZE``. These
67may be overridden on the fastboot command line using ``-l`` and
68``-s``.
Sebastian Siewior9d4471e2014-05-05 15:08:10 -050069
Alex Kiernana59e9132018-05-29 15:30:56 +000070Fastboot environment variables
Sam Protsenkocd43fa12020-01-24 17:53:44 +020071------------------------------
Alex Kiernana59e9132018-05-29 15:30:56 +000072
73Partition aliases
Sam Protsenkocd43fa12020-01-24 17:53:44 +020074^^^^^^^^^^^^^^^^^
Sebastian Siewior9d4471e2014-05-05 15:08:10 -050075
Michael Scottced33492015-03-11 10:02:31 -070076Fastboot partition aliases can also be defined for devices where GPT
Sam Protsenkocd43fa12020-01-24 17:53:44 +020077limitations prevent user-friendly partition names such as ``boot``, ``system``
78and ``cache``. Or, where the actual partition name doesn't match a standard
Alex Kiernana59e9132018-05-29 15:30:56 +000079partition name used commonly with fastboot.
80
81The current implementation checks aliases when accessing partitions by
82name (flash_write and erase functions). To define a partition alias
Sam Protsenkocd43fa12020-01-24 17:53:44 +020083add an environment variable similar to::
Alex Kiernana59e9132018-05-29 15:30:56 +000084
Sam Protsenkocd43fa12020-01-24 17:53:44 +020085 fastboot_partition_alias_<alias partition name>=<actual partition name>
Alex Kiernana59e9132018-05-29 15:30:56 +000086
Sam Protsenkocd43fa12020-01-24 17:53:44 +020087for example::
Alex Kiernana59e9132018-05-29 15:30:56 +000088
Sam Protsenkocd43fa12020-01-24 17:53:44 +020089 fastboot_partition_alias_boot=LNX
Alex Kiernana59e9132018-05-29 15:30:56 +000090
Filip Brozovic859e6a82020-06-29 13:14:37 +020091Raw partition descriptors
92^^^^^^^^^^^^^^^^^^^^^^^^^
93
94In cases where no partition table is present, a raw partition descriptor can be
95defined, specifying the offset, size, and optionally the MMC hardware partition
96number for a given partition name.
97
98This is useful when using fastboot to flash files (e.g. SPL or U-Boot) to a
99specific offset in the eMMC boot partition, without having to update the entire
100boot partition.
101
102To define a raw partition descriptor, add an environment variable similar to::
103
104 fastboot_raw_partition_<raw partition name>=<offset> <size> [mmcpart <num>]
105
106for example::
107
108 fastboot_raw_partition_boot=0x100 0x1f00 mmcpart 1
109
Alex Kiernana59e9132018-05-29 15:30:56 +0000110Variable overrides
Sam Protsenkocd43fa12020-01-24 17:53:44 +0200111^^^^^^^^^^^^^^^^^^
Alex Kiernana59e9132018-05-29 15:30:56 +0000112
113Variables retrived through ``getvar`` can be overridden by defining
114environment variables of the form ``fastboot.<variable>``. These are
115looked up first so can be used to override values which would
116otherwise be returned. Using this mechanism you can also return types
117for NAND filesystems, as the fully parameterised variable is looked
Sam Protsenkocd43fa12020-01-24 17:53:44 +0200118up, e.g.::
Alex Kiernana59e9132018-05-29 15:30:56 +0000119
Sam Protsenkocd43fa12020-01-24 17:53:44 +0200120 fastboot.partition-type:boot=jffs2
Alex Kiernana59e9132018-05-29 15:30:56 +0000121
122Boot command
Sam Protsenkocd43fa12020-01-24 17:53:44 +0200123^^^^^^^^^^^^
Alex Kiernana59e9132018-05-29 15:30:56 +0000124
Sam Protsenkocd43fa12020-01-24 17:53:44 +0200125When executing the fastboot ``boot`` command, if ``fastboot_bootcmd`` is set
126then that will be executed in place of ``bootm <CONFIG_FASTBOOT_BUF_ADDR>``.
Michael Scottced33492015-03-11 10:02:31 -0700127
Petr Kulhavy9f174c92016-09-09 10:27:16 +0200128Partition Names
Sam Protsenkocd43fa12020-01-24 17:53:44 +0200129---------------
Alex Kiernana59e9132018-05-29 15:30:56 +0000130
131The Fastboot implementation in U-Boot allows to write images into disk
132partitions. Target partitions are referred on the host computer by
133their names.
Petr Kulhavy9f174c92016-09-09 10:27:16 +0200134
135For GPT/EFI the respective partition name is used.
136
137For MBR the partitions are referred by generic names according to the
Sam Protsenkocd43fa12020-01-24 17:53:44 +0200138following schema::
Petr Kulhavy9f174c92016-09-09 10:27:16 +0200139
Sam Protsenkocd43fa12020-01-24 17:53:44 +0200140 <device type><device index letter><partition index>
Petr Kulhavy9f174c92016-09-09 10:27:16 +0200141
Sam Protsenkocd43fa12020-01-24 17:53:44 +0200142Example: ``hda3``, ``sdb1``, ``usbda1``.
Petr Kulhavy9f174c92016-09-09 10:27:16 +0200143
144The device type is as follows:
145
Alex Kiernana59e9132018-05-29 15:30:56 +0000146 * IDE, ATAPI and SATA disks: ``hd``
147 * SCSI disks: ``sd``
148 * USB media: ``usbd``
149 * MMC and SD cards: ``mmcsd``
150 * Disk on chip: ``docd``
151 * other: ``xx``
Petr Kulhavy9f174c92016-09-09 10:27:16 +0200152
Alex Kiernana59e9132018-05-29 15:30:56 +0000153The device index starts from ``a`` and refers to the interface (e.g. USB
Petr Kulhavy9f174c92016-09-09 10:27:16 +0200154controller, SD/MMC controller) or disk index. The partition index starts
Alex Kiernana59e9132018-05-29 15:30:56 +0000155from ``1`` and describes the partition number on the particular device.
Petr Kulhavy9f174c92016-09-09 10:27:16 +0200156
157Writing Partition Table
Sam Protsenkocd43fa12020-01-24 17:53:44 +0200158-----------------------
Alex Kiernana59e9132018-05-29 15:30:56 +0000159
Petr Kulhavy9f174c92016-09-09 10:27:16 +0200160Fastboot also allows to write the partition table to the media. This can be
161done by writing the respective partition table image to a special target
162"gpt" or "mbr". These names can be customized by defining the following
163configuration options:
164
Alex Kiernana59e9132018-05-29 15:30:56 +0000165::
166
167 CONFIG_FASTBOOT_GPT_NAME
168 CONFIG_FASTBOOT_MBR_NAME
Petr Kulhavy9f174c92016-09-09 10:27:16 +0200169
Sebastian Siewior9d4471e2014-05-05 15:08:10 -0500170In Action
Sam Protsenkocd43fa12020-01-24 17:53:44 +0200171---------
Alex Kiernana59e9132018-05-29 15:30:56 +0000172
Sam Protsenkocd43fa12020-01-24 17:53:44 +0200173Enter into fastboot by executing the fastboot command in U-Boot for either USB::
Alex Kiernana59e9132018-05-29 15:30:56 +0000174
175 => fastboot usb 0
176
Sam Protsenkocd43fa12020-01-24 17:53:44 +0200177or UDP::
Alex Kiernana59e9132018-05-29 15:30:56 +0000178
179 => fastboot udp
180 link up on port 0, speed 100, full duplex
181 Using ethernet@4a100000 device
182 Listening for fastboot command on 192.168.0.102
Sebastian Siewior9d4471e2014-05-05 15:08:10 -0500183
Sam Protsenkocd43fa12020-01-24 17:53:44 +0200184On the client side you can fetch the bootloader version for instance::
Alex Kiernana59e9132018-05-29 15:30:56 +0000185
Sam Protsenkoac21e742019-07-03 19:34:07 +0300186 $ fastboot getvar version-bootloader
187 version-bootloader: U-Boot 2019.07-rc4-00240-g00c9f2a2ec
188 Finished. Total time: 0.005s
Sebastian Siewior9d4471e2014-05-05 15:08:10 -0500189
Sam Protsenkocd43fa12020-01-24 17:53:44 +0200190or initiate a reboot::
Alex Kiernana59e9132018-05-29 15:30:56 +0000191
192 $ fastboot reboot
Sebastian Siewior9d4471e2014-05-05 15:08:10 -0500193
194and once the client comes back, the board should reset.
195
196You can also specify a kernel image to boot. You have to either specify
Alex Kiernana59e9132018-05-29 15:30:56 +0000197the an image in Android format *or* pass a binary kernel and let the
Sebastian Siewior9d4471e2014-05-05 15:08:10 -0500198fastboot client wrap the Android suite around it. On OMAP for instance you
Sam Protsenkocd43fa12020-01-24 17:53:44 +0200199take zImage kernel and pass it to the fastboot client::
Alex Kiernana59e9132018-05-29 15:30:56 +0000200
201 $ fastboot -b 0x80000000 -c "console=ttyO2 earlyprintk root=/dev/ram0 mem=128M" boot zImage
202 creating boot image...
203 creating boot image - 1847296 bytes
204 downloading 'boot.img'...
205 OKAY [ 2.766s]
206 booting...
207 OKAY [ -0.000s]
208 finished. total time: 2.766s
209
Sam Protsenkocd43fa12020-01-24 17:53:44 +0200210and on the U-Boot side you should see::
Alex Kiernana59e9132018-05-29 15:30:56 +0000211
212 Starting download of 1847296 bytes
213 ........................................................
214 downloading of 1847296 bytes finished
215 Booting kernel..
216 ## Booting Android Image at 0x81000000 ...
217 Kernel load addr 0x80008000 size 1801 KiB
218 Kernel command line: console=ttyO2 earlyprintk root=/dev/ram0 mem=128M
219 Loading Kernel Image ... OK
220 OK
Sebastian Siewior9d4471e2014-05-05 15:08:10 -0500221
Alex Kiernana59e9132018-05-29 15:30:56 +0000222 Starting kernel ...
Sam Protsenkocd43fa12020-01-24 17:53:44 +0200223
224References
225----------
226
227.. [1] :doc:`fastboot-protocol`
228.. [2] https://developer.android.com/studio/releases/platform-tools