blob: 05d8f777595f0fb88c70df5ae30a7feb83e216b4 [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)
Heiko Schocher3a994482021-02-10 09:29:03 +010022- ``ucmd`` (if enabled)
23- ``acmd`` (if enabled)
Alex Kiernana59e9132018-05-29 15:30:56 +000024
25The following OEM commands are supported (if enabled):
26
Sam Protsenkocd43fa12020-01-24 17:53:44 +020027- ``oem format`` - this executes ``gpt write mmc %x $partitions``
Patrick Delaunay61687702021-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 Delaunay67af29a2021-01-27 14:46:49 +010030- ``oem bootbus`` - this executes ``mmc bootbus %x %s`` to configure eMMC
Sean Anderson421bec02022-12-16 13:20:16 -050031- ``oem run`` - this executes an arbitrary U-Boot command
Ion Agorriae64262d2024-01-05 09:22:11 +020032- ``oem console`` - this dumps U-Boot console record buffer
Alex Kiernana59e9132018-05-29 15:30:56 +000033
34Support for both eMMC and NAND devices is included.
Sebastian Siewior9d4471e2014-05-05 15:08:10 -050035
36Client installation
Sam Protsenkocd43fa12020-01-24 17:53:44 +020037-------------------
Sebastian Siewior9d4471e2014-05-05 15:08:10 -050038
Alex Kiernana59e9132018-05-29 15:30:56 +000039The counterpart to this is the fastboot client which can be found in
40Android's ``platform/system/core`` repository in the fastboot
41folder. It runs on Windows, Linux and OSX. The fastboot client is
Sam Protsenkocd43fa12020-01-24 17:53:44 +020042part of the Android SDK Platform-Tools and can be downloaded from [2]_.
Sebastian Siewior9d4471e2014-05-05 15:08:10 -050043
44Board specific
Sam Protsenkocd43fa12020-01-24 17:53:44 +020045--------------
Alex Kiernana59e9132018-05-29 15:30:56 +000046
47USB configuration
Sam Protsenkocd43fa12020-01-24 17:53:44 +020048^^^^^^^^^^^^^^^^^
Alex Kiernana59e9132018-05-29 15:30:56 +000049
Sebastian Siewior9d4471e2014-05-05 15:08:10 -050050The fastboot gadget relies on the USB download gadget, so the following
51options must be configured:
52
Alex Kiernana59e9132018-05-29 15:30:56 +000053::
54
55 CONFIG_USB_GADGET_DOWNLOAD
56 CONFIG_USB_GADGET_VENDOR_NUM
57 CONFIG_USB_GADGET_PRODUCT_NUM
58 CONFIG_USB_GADGET_MANUFACTURER
59
60NOTE: The ``CONFIG_USB_GADGET_VENDOR_NUM`` must be one of the numbers
61supported by the fastboot client. The list of vendor IDs supported can
62be found in the fastboot client source code.
Sebastian Siewior9d4471e2014-05-05 15:08:10 -050063
Alex Kiernana59e9132018-05-29 15:30:56 +000064General configuration
Sam Protsenkocd43fa12020-01-24 17:53:44 +020065^^^^^^^^^^^^^^^^^^^^^
Barnes, Clifton A1f9f3212014-07-22 11:23:56 -040066
Alex Kiernana59e9132018-05-29 15:30:56 +000067The fastboot protocol requires a large memory buffer for
68downloads. This buffer should be as large as possible for a
69platform. The location of the buffer and size are set with
70``CONFIG_FASTBOOT_BUF_ADDR`` and ``CONFIG_FASTBOOT_BUF_SIZE``. These
71may be overridden on the fastboot command line using ``-l`` and
72``-s``.
Sebastian Siewior9d4471e2014-05-05 15:08:10 -050073
Alex Kiernana59e9132018-05-29 15:30:56 +000074Fastboot environment variables
Sam Protsenkocd43fa12020-01-24 17:53:44 +020075------------------------------
Alex Kiernana59e9132018-05-29 15:30:56 +000076
77Partition aliases
Sam Protsenkocd43fa12020-01-24 17:53:44 +020078^^^^^^^^^^^^^^^^^
Sebastian Siewior9d4471e2014-05-05 15:08:10 -050079
Michael Scottced33492015-03-11 10:02:31 -070080Fastboot partition aliases can also be defined for devices where GPT
Sam Protsenkocd43fa12020-01-24 17:53:44 +020081limitations prevent user-friendly partition names such as ``boot``, ``system``
82and ``cache``. Or, where the actual partition name doesn't match a standard
Alex Kiernana59e9132018-05-29 15:30:56 +000083partition name used commonly with fastboot.
84
85The current implementation checks aliases when accessing partitions by
86name (flash_write and erase functions). To define a partition alias
Sam Protsenkocd43fa12020-01-24 17:53:44 +020087add an environment variable similar to::
Alex Kiernana59e9132018-05-29 15:30:56 +000088
Sam Protsenkocd43fa12020-01-24 17:53:44 +020089 fastboot_partition_alias_<alias partition name>=<actual partition name>
Alex Kiernana59e9132018-05-29 15:30:56 +000090
Sam Protsenkocd43fa12020-01-24 17:53:44 +020091for example::
Alex Kiernana59e9132018-05-29 15:30:56 +000092
Sam Protsenkocd43fa12020-01-24 17:53:44 +020093 fastboot_partition_alias_boot=LNX
Alex Kiernana59e9132018-05-29 15:30:56 +000094
Filip Brozovic859e6a82020-06-29 13:14:37 +020095Raw partition descriptors
96^^^^^^^^^^^^^^^^^^^^^^^^^
97
98In cases where no partition table is present, a raw partition descriptor can be
99defined, specifying the offset, size, and optionally the MMC hardware partition
100number for a given partition name.
101
102This is useful when using fastboot to flash files (e.g. SPL or U-Boot) to a
103specific offset in the eMMC boot partition, without having to update the entire
104boot partition.
105
106To define a raw partition descriptor, add an environment variable similar to::
107
108 fastboot_raw_partition_<raw partition name>=<offset> <size> [mmcpart <num>]
109
110for example::
111
112 fastboot_raw_partition_boot=0x100 0x1f00 mmcpart 1
113
Alex Kiernana59e9132018-05-29 15:30:56 +0000114Variable overrides
Sam Protsenkocd43fa12020-01-24 17:53:44 +0200115^^^^^^^^^^^^^^^^^^
Alex Kiernana59e9132018-05-29 15:30:56 +0000116
117Variables retrived through ``getvar`` can be overridden by defining
118environment variables of the form ``fastboot.<variable>``. These are
119looked up first so can be used to override values which would
120otherwise be returned. Using this mechanism you can also return types
121for NAND filesystems, as the fully parameterised variable is looked
Sam Protsenkocd43fa12020-01-24 17:53:44 +0200122up, e.g.::
Alex Kiernana59e9132018-05-29 15:30:56 +0000123
Sam Protsenkocd43fa12020-01-24 17:53:44 +0200124 fastboot.partition-type:boot=jffs2
Alex Kiernana59e9132018-05-29 15:30:56 +0000125
126Boot command
Sam Protsenkocd43fa12020-01-24 17:53:44 +0200127^^^^^^^^^^^^
Alex Kiernana59e9132018-05-29 15:30:56 +0000128
Sam Protsenkocd43fa12020-01-24 17:53:44 +0200129When executing the fastboot ``boot`` command, if ``fastboot_bootcmd`` is set
130then that will be executed in place of ``bootm <CONFIG_FASTBOOT_BUF_ADDR>``.
Michael Scottced33492015-03-11 10:02:31 -0700131
Petr Kulhavy9f174c92016-09-09 10:27:16 +0200132Partition Names
Sam Protsenkocd43fa12020-01-24 17:53:44 +0200133---------------
Alex Kiernana59e9132018-05-29 15:30:56 +0000134
135The Fastboot implementation in U-Boot allows to write images into disk
136partitions. Target partitions are referred on the host computer by
137their names.
Petr Kulhavy9f174c92016-09-09 10:27:16 +0200138
139For GPT/EFI the respective partition name is used.
140
141For MBR the partitions are referred by generic names according to the
Sam Protsenkocd43fa12020-01-24 17:53:44 +0200142following schema::
Petr Kulhavy9f174c92016-09-09 10:27:16 +0200143
Sam Protsenkocd43fa12020-01-24 17:53:44 +0200144 <device type><device index letter><partition index>
Petr Kulhavy9f174c92016-09-09 10:27:16 +0200145
Sam Protsenkocd43fa12020-01-24 17:53:44 +0200146Example: ``hda3``, ``sdb1``, ``usbda1``.
Petr Kulhavy9f174c92016-09-09 10:27:16 +0200147
148The device type is as follows:
149
Alex Kiernana59e9132018-05-29 15:30:56 +0000150 * IDE, ATAPI and SATA disks: ``hd``
151 * SCSI disks: ``sd``
152 * USB media: ``usbd``
153 * MMC and SD cards: ``mmcsd``
154 * Disk on chip: ``docd``
155 * other: ``xx``
Petr Kulhavy9f174c92016-09-09 10:27:16 +0200156
Alex Kiernana59e9132018-05-29 15:30:56 +0000157The device index starts from ``a`` and refers to the interface (e.g. USB
Petr Kulhavy9f174c92016-09-09 10:27:16 +0200158controller, SD/MMC controller) or disk index. The partition index starts
Alex Kiernana59e9132018-05-29 15:30:56 +0000159from ``1`` and describes the partition number on the particular device.
Petr Kulhavy9f174c92016-09-09 10:27:16 +0200160
Sean Anderson21e84762021-02-05 09:39:02 -0500161Alternatively, partition types may be specified using :ref:`U-Boot's partition
162syntax <partitions>`. This allows specifying partitions like ``0.1``,
163``0#boot``, or ``:3``. The interface is always ``mmc``.
164
Petr Kulhavy9f174c92016-09-09 10:27:16 +0200165Writing Partition Table
Sam Protsenkocd43fa12020-01-24 17:53:44 +0200166-----------------------
Alex Kiernana59e9132018-05-29 15:30:56 +0000167
Petr Kulhavy9f174c92016-09-09 10:27:16 +0200168Fastboot also allows to write the partition table to the media. This can be
169done by writing the respective partition table image to a special target
170"gpt" or "mbr". These names can be customized by defining the following
171configuration options:
172
Alex Kiernana59e9132018-05-29 15:30:56 +0000173::
174
175 CONFIG_FASTBOOT_GPT_NAME
176 CONFIG_FASTBOOT_MBR_NAME
Petr Kulhavy9f174c92016-09-09 10:27:16 +0200177
Sebastian Siewior9d4471e2014-05-05 15:08:10 -0500178In Action
Sam Protsenkocd43fa12020-01-24 17:53:44 +0200179---------
Alex Kiernana59e9132018-05-29 15:30:56 +0000180
Sam Protsenkocd43fa12020-01-24 17:53:44 +0200181Enter into fastboot by executing the fastboot command in U-Boot for either USB::
Alex Kiernana59e9132018-05-29 15:30:56 +0000182
183 => fastboot usb 0
184
Sam Protsenkocd43fa12020-01-24 17:53:44 +0200185or UDP::
Alex Kiernana59e9132018-05-29 15:30:56 +0000186
187 => fastboot udp
188 link up on port 0, speed 100, full duplex
189 Using ethernet@4a100000 device
190 Listening for fastboot command on 192.168.0.102
Sebastian Siewior9d4471e2014-05-05 15:08:10 -0500191
Sam Protsenkocd43fa12020-01-24 17:53:44 +0200192On the client side you can fetch the bootloader version for instance::
Alex Kiernana59e9132018-05-29 15:30:56 +0000193
Sam Protsenkoac21e742019-07-03 19:34:07 +0300194 $ fastboot getvar version-bootloader
195 version-bootloader: U-Boot 2019.07-rc4-00240-g00c9f2a2ec
196 Finished. Total time: 0.005s
Sebastian Siewior9d4471e2014-05-05 15:08:10 -0500197
Sam Protsenkocd43fa12020-01-24 17:53:44 +0200198or initiate a reboot::
Alex Kiernana59e9132018-05-29 15:30:56 +0000199
200 $ fastboot reboot
Sebastian Siewior9d4471e2014-05-05 15:08:10 -0500201
202and once the client comes back, the board should reset.
203
204You can also specify a kernel image to boot. You have to either specify
Alex Kiernana59e9132018-05-29 15:30:56 +0000205the an image in Android format *or* pass a binary kernel and let the
Sebastian Siewior9d4471e2014-05-05 15:08:10 -0500206fastboot client wrap the Android suite around it. On OMAP for instance you
Sam Protsenkocd43fa12020-01-24 17:53:44 +0200207take zImage kernel and pass it to the fastboot client::
Alex Kiernana59e9132018-05-29 15:30:56 +0000208
209 $ fastboot -b 0x80000000 -c "console=ttyO2 earlyprintk root=/dev/ram0 mem=128M" boot zImage
210 creating boot image...
211 creating boot image - 1847296 bytes
212 downloading 'boot.img'...
213 OKAY [ 2.766s]
214 booting...
215 OKAY [ -0.000s]
216 finished. total time: 2.766s
217
Sam Protsenkocd43fa12020-01-24 17:53:44 +0200218and on the U-Boot side you should see::
Alex Kiernana59e9132018-05-29 15:30:56 +0000219
220 Starting download of 1847296 bytes
221 ........................................................
222 downloading of 1847296 bytes finished
223 Booting kernel..
224 ## Booting Android Image at 0x81000000 ...
225 Kernel load addr 0x80008000 size 1801 KiB
226 Kernel command line: console=ttyO2 earlyprintk root=/dev/ram0 mem=128M
227 Loading Kernel Image ... OK
228 OK
Sebastian Siewior9d4471e2014-05-05 15:08:10 -0500229
Alex Kiernana59e9132018-05-29 15:30:56 +0000230 Starting kernel ...
Sam Protsenkocd43fa12020-01-24 17:53:44 +0200231
Sean Anderson421bec02022-12-16 13:20:16 -0500232Running Shell Commands
233^^^^^^^^^^^^^^^^^^^^^^
234
235Normally, arbitrary U-Boot command execution is not enabled. This is so
236fastboot can be used to update systems using verified boot. However, such
237functionality can be useful for production or when verified boot is not in use.
238Enable ``CONFIG_FASTBOOT_OEM_RUN`` to use this functionality. This will enable
239``oem run`` command, which can be used with the fastboot client. For example,
240to print "Hello at 115200 baud" (or whatever ``CONFIG_BAUDRATE`` is), run::
241
242 $ fastboot oem run:'echo Hello at $baudrate baud'
243
244You can run any command you would normally run on the U-Boot command line,
245including multiple commands (using e.g. ``;`` or ``&&``) and control structures
246(``if``, ``while``, etc.). The exit code of ``fastboot`` will reflect the exit
247code of the command you ran.
248
Sam Protsenkocd43fa12020-01-24 17:53:44 +0200249References
250----------
251
252.. [1] :doc:`fastboot-protocol`
253.. [2] https://developer.android.com/studio/releases/platform-tools