fastboot.rst 7.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252
  1. .. SPDX-License-Identifier: GPL-2.0+
  2. Android Fastboot
  3. ================
  4. Overview
  5. --------
  6. The protocol that is used over USB and UDP is described in [1]_.
  7. The current implementation supports the following standard commands:
  8. - ``boot``
  9. - ``continue``
  10. - ``download``
  11. - ``erase`` (if enabled)
  12. - ``flash`` (if enabled)
  13. - ``getvar``
  14. - ``reboot``
  15. - ``reboot-bootloader``
  16. - ``set_active`` (only a stub implementation which always succeeds)
  17. - ``ucmd`` (if enabled)
  18. - ``acmd`` (if enabled)
  19. The following OEM commands are supported (if enabled):
  20. - ``oem format`` - this executes ``gpt write mmc %x $partitions``
  21. - ``oem partconf`` - this executes ``mmc partconf %x <arg> 0`` to configure eMMC
  22. with <arg> = boot_ack boot_partition
  23. - ``oem bootbus`` - this executes ``mmc bootbus %x %s`` to configure eMMC
  24. - ``oem run`` - this executes an arbitrary U-Boot command
  25. Support for both eMMC and NAND devices is included.
  26. Client installation
  27. -------------------
  28. The counterpart to this is the fastboot client which can be found in
  29. Android's ``platform/system/core`` repository in the fastboot
  30. folder. It runs on Windows, Linux and OSX. The fastboot client is
  31. part of the Android SDK Platform-Tools and can be downloaded from [2]_.
  32. Board specific
  33. --------------
  34. USB configuration
  35. ^^^^^^^^^^^^^^^^^
  36. The fastboot gadget relies on the USB download gadget, so the following
  37. options must be configured:
  38. ::
  39. CONFIG_USB_GADGET_DOWNLOAD
  40. CONFIG_USB_GADGET_VENDOR_NUM
  41. CONFIG_USB_GADGET_PRODUCT_NUM
  42. CONFIG_USB_GADGET_MANUFACTURER
  43. NOTE: The ``CONFIG_USB_GADGET_VENDOR_NUM`` must be one of the numbers
  44. supported by the fastboot client. The list of vendor IDs supported can
  45. be found in the fastboot client source code.
  46. General configuration
  47. ^^^^^^^^^^^^^^^^^^^^^
  48. The fastboot protocol requires a large memory buffer for
  49. downloads. This buffer should be as large as possible for a
  50. platform. The location of the buffer and size are set with
  51. ``CONFIG_FASTBOOT_BUF_ADDR`` and ``CONFIG_FASTBOOT_BUF_SIZE``. These
  52. may be overridden on the fastboot command line using ``-l`` and
  53. ``-s``.
  54. Fastboot environment variables
  55. ------------------------------
  56. Partition aliases
  57. ^^^^^^^^^^^^^^^^^
  58. Fastboot partition aliases can also be defined for devices where GPT
  59. limitations prevent user-friendly partition names such as ``boot``, ``system``
  60. and ``cache``. Or, where the actual partition name doesn't match a standard
  61. partition name used commonly with fastboot.
  62. The current implementation checks aliases when accessing partitions by
  63. name (flash_write and erase functions). To define a partition alias
  64. add an environment variable similar to::
  65. fastboot_partition_alias_<alias partition name>=<actual partition name>
  66. for example::
  67. fastboot_partition_alias_boot=LNX
  68. Raw partition descriptors
  69. ^^^^^^^^^^^^^^^^^^^^^^^^^
  70. In cases where no partition table is present, a raw partition descriptor can be
  71. defined, specifying the offset, size, and optionally the MMC hardware partition
  72. number for a given partition name.
  73. This is useful when using fastboot to flash files (e.g. SPL or U-Boot) to a
  74. specific offset in the eMMC boot partition, without having to update the entire
  75. boot partition.
  76. To define a raw partition descriptor, add an environment variable similar to::
  77. fastboot_raw_partition_<raw partition name>=<offset> <size> [mmcpart <num>]
  78. for example::
  79. fastboot_raw_partition_boot=0x100 0x1f00 mmcpart 1
  80. Variable overrides
  81. ^^^^^^^^^^^^^^^^^^
  82. Variables retrived through ``getvar`` can be overridden by defining
  83. environment variables of the form ``fastboot.<variable>``. These are
  84. looked up first so can be used to override values which would
  85. otherwise be returned. Using this mechanism you can also return types
  86. for NAND filesystems, as the fully parameterised variable is looked
  87. up, e.g.::
  88. fastboot.partition-type:boot=jffs2
  89. Boot command
  90. ^^^^^^^^^^^^
  91. When executing the fastboot ``boot`` command, if ``fastboot_bootcmd`` is set
  92. then that will be executed in place of ``bootm <CONFIG_FASTBOOT_BUF_ADDR>``.
  93. Partition Names
  94. ---------------
  95. The Fastboot implementation in U-Boot allows to write images into disk
  96. partitions. Target partitions are referred on the host computer by
  97. their names.
  98. For GPT/EFI the respective partition name is used.
  99. For MBR the partitions are referred by generic names according to the
  100. following schema::
  101. <device type><device index letter><partition index>
  102. Example: ``hda3``, ``sdb1``, ``usbda1``.
  103. The device type is as follows:
  104. * IDE, ATAPI and SATA disks: ``hd``
  105. * SCSI disks: ``sd``
  106. * USB media: ``usbd``
  107. * MMC and SD cards: ``mmcsd``
  108. * Disk on chip: ``docd``
  109. * other: ``xx``
  110. The device index starts from ``a`` and refers to the interface (e.g. USB
  111. controller, SD/MMC controller) or disk index. The partition index starts
  112. from ``1`` and describes the partition number on the particular device.
  113. Alternatively, partition types may be specified using :ref:`U-Boot's partition
  114. syntax <partitions>`. This allows specifying partitions like ``0.1``,
  115. ``0#boot``, or ``:3``. The interface is always ``mmc``.
  116. Writing Partition Table
  117. -----------------------
  118. Fastboot also allows to write the partition table to the media. This can be
  119. done by writing the respective partition table image to a special target
  120. "gpt" or "mbr". These names can be customized by defining the following
  121. configuration options:
  122. ::
  123. CONFIG_FASTBOOT_GPT_NAME
  124. CONFIG_FASTBOOT_MBR_NAME
  125. In Action
  126. ---------
  127. Enter into fastboot by executing the fastboot command in U-Boot for either USB::
  128. => fastboot usb 0
  129. or UDP::
  130. => fastboot udp
  131. link up on port 0, speed 100, full duplex
  132. Using ethernet@4a100000 device
  133. Listening for fastboot command on 192.168.0.102
  134. On the client side you can fetch the bootloader version for instance::
  135. $ fastboot getvar version-bootloader
  136. version-bootloader: U-Boot 2019.07-rc4-00240-g00c9f2a2ec
  137. Finished. Total time: 0.005s
  138. or initiate a reboot::
  139. $ fastboot reboot
  140. and once the client comes back, the board should reset.
  141. You can also specify a kernel image to boot. You have to either specify
  142. the an image in Android format *or* pass a binary kernel and let the
  143. fastboot client wrap the Android suite around it. On OMAP for instance you
  144. take zImage kernel and pass it to the fastboot client::
  145. $ fastboot -b 0x80000000 -c "console=ttyO2 earlyprintk root=/dev/ram0 mem=128M" boot zImage
  146. creating boot image...
  147. creating boot image - 1847296 bytes
  148. downloading 'boot.img'...
  149. OKAY [ 2.766s]
  150. booting...
  151. OKAY [ -0.000s]
  152. finished. total time: 2.766s
  153. and on the U-Boot side you should see::
  154. Starting download of 1847296 bytes
  155. ........................................................
  156. downloading of 1847296 bytes finished
  157. Booting kernel..
  158. ## Booting Android Image at 0x81000000 ...
  159. Kernel load addr 0x80008000 size 1801 KiB
  160. Kernel command line: console=ttyO2 earlyprintk root=/dev/ram0 mem=128M
  161. Loading Kernel Image ... OK
  162. OK
  163. Starting kernel ...
  164. Running Shell Commands
  165. ^^^^^^^^^^^^^^^^^^^^^^
  166. Normally, arbitrary U-Boot command execution is not enabled. This is so
  167. fastboot can be used to update systems using verified boot. However, such
  168. functionality can be useful for production or when verified boot is not in use.
  169. Enable ``CONFIG_FASTBOOT_OEM_RUN`` to use this functionality. This will enable
  170. ``oem run`` command, which can be used with the fastboot client. For example,
  171. to print "Hello at 115200 baud" (or whatever ``CONFIG_BAUDRATE`` is), run::
  172. $ fastboot oem run:'echo Hello at $baudrate baud'
  173. You can run any command you would normally run on the U-Boot command line,
  174. including multiple commands (using e.g. ``;`` or ``&&``) and control structures
  175. (``if``, ``while``, etc.). The exit code of ``fastboot`` will reflect the exit
  176. code of the command you ran.
  177. References
  178. ----------
  179. .. [1] :doc:`fastboot-protocol`
  180. .. [2] https://developer.android.com/studio/releases/platform-tools