xref: /aosp_15_r20/bootable/libbootloader/gbl/docs/gbl_fastboot.md (revision 5225e6b173e52d2efc6bcf950c27374fd72adabc)
1*5225e6b1SAndroid Build Coastguard Worker# Fastboot in GBL
2*5225e6b1SAndroid Build Coastguard Worker
3*5225e6b1SAndroid Build Coastguard WorkerThis document describes Fastboot in the [GBL UEFI bootloader](../efi/BUILD).
4*5225e6b1SAndroid Build Coastguard Worker
5*5225e6b1SAndroid Build Coastguard Worker## Transport
6*5225e6b1SAndroid Build Coastguard Worker
7*5225e6b1SAndroid Build Coastguard WorkerThe GBL UEFI bootloader supports both Fastboot over TCP and USB. To enable
8*5225e6b1SAndroid Build Coastguard WorkerFastboot over TCP, the UEFI loader needs to implement the
9*5225e6b1SAndroid Build Coastguard Worker`EFI_SIMPLE_NETWORK_PROTOCOL` protocol. To enable Fastboot over USB, the
10*5225e6b1SAndroid Build Coastguard Worker[GBL_EFI_FASTBOOT_USB_PROTOCOL](./GBL_EFI_FASTBOOT_USB_PROTOCOL.md) protocol is
11*5225e6b1SAndroid Build Coastguard Workerneeded. GBL automatically establishes the corresponding transport channel if
12*5225e6b1SAndroid Build Coastguard Workerthe needed protocol is available.
13*5225e6b1SAndroid Build Coastguard Worker
14*5225e6b1SAndroid Build Coastguard Worker## The Partition Argument
15*5225e6b1SAndroid Build Coastguard Worker
16*5225e6b1SAndroid Build Coastguard WorkerFastboot commands such as `fastboot flash`, `fastboot fetch` and
17*5225e6b1SAndroid Build Coastguard Worker`fastboot getvar partition-size` operate on partitions and requires a partition
18*5225e6b1SAndroid Build Coastguard Workername argument. See this [doc](./partitions.md) for how GBL defines and handles
19*5225e6b1SAndroid Build Coastguard Workerpartitions on storage devices. GBL fastboot additionaly supports accessing sub
20*5225e6b1SAndroid Build Coastguard Workerranges of partitions and disambiguating betweeen same name partitions on
21*5225e6b1SAndroid Build Coastguard Workermultiple storage devices (i.e. in the presence of external or removable boot
22*5225e6b1SAndroid Build Coastguard Workerstorage). The following summarizes the supported syntaxes for partition name
23*5225e6b1SAndroid Build Coastguard Workerargument in fastboot.
24*5225e6b1SAndroid Build Coastguard Worker
25*5225e6b1SAndroid Build Coastguard Worker* Partition
26*5225e6b1SAndroid Build Coastguard Worker  ```sh
27*5225e6b1SAndroid Build Coastguard Worker  <part>[/<storage_id>]
28*5225e6b1SAndroid Build Coastguard Worker  <part>/[<storage_id>][/<offset>]
29*5225e6b1SAndroid Build Coastguard Worker  <part>/[<storage_id>]/[<offset>][/<size>]
30*5225e6b1SAndroid Build Coastguard Worker  ```
31*5225e6b1SAndroid Build Coastguard Worker
32*5225e6b1SAndroid Build Coastguard Worker  This specifies range `[offset, offset+size)` in partition `part` on the
33*5225e6b1SAndroid Build Coastguard Worker  storage device with ID `storage_id`. `storage_id` is a hex string and
34*5225e6b1SAndroid Build Coastguard Worker  represents a unique integer ID assigned to each storage device detected
35*5225e6b1SAndroid Build Coastguard Worker  by GBL. The integer ID is for disambiguation purpose in case multiple storage
36*5225e6b1SAndroid Build Coastguard Worker  devices have same name partitions.  If `storage_id` is not given, GBL will
37*5225e6b1SAndroid Build Coastguard Worker  check if a default storage ID is set via
38*5225e6b1SAndroid Build Coastguard Worker  `fastboot oem gbl-set-default-block <storage_id>` and use the default ID if
39*5225e6b1SAndroid Build Coastguard Worker  set. If the default ID is not set, GBL will check that `part` can match to a
40*5225e6b1SAndroid Build Coastguard Worker  unique parition. Otherwise, it will be rejected. The default ID can be unset
41*5225e6b1SAndroid Build Coastguard Worker  via `fastboot oem gbl-unset-default-block`. `offset` and `size` must be a
42*5225e6b1SAndroid Build Coastguard Worker  64bit integer hex string. `offset` defaults to 0 if not given. `size`
43*5225e6b1SAndroid Build Coastguard Worker  defaults to the rest of the partition after `offset` if not given.
44*5225e6b1SAndroid Build Coastguard Worker
45*5225e6b1SAndroid Build Coastguard Worker  Examples:
46*5225e6b1SAndroid Build Coastguard Worker  * `fastboot flash boot_a` -- If there is only one storage or a default
47*5225e6b1SAndroid Build Coastguard Worker    storage ID is set via `fastboot oem gbl-set-default-block <default ID>`,
48*5225e6b1SAndroid Build Coastguard Worker    flashes in the entire range of the storage. If not, checks that `boot_a`
49*5225e6b1SAndroid Build Coastguard Worker    can match to a unique partition among all storage devices and flashes to
50*5225e6b1SAndroid Build Coastguard Worker    it.
51*5225e6b1SAndroid Build Coastguard Worker  * `fastboot flash boot_a/0x0` or `boot_a/0` -- Flashes in the entire range of
52*5225e6b1SAndroid Build Coastguard Worker    partition "boot_a" on storage device 0.
53*5225e6b1SAndroid Build Coastguard Worker  * `fastboot flash boot_a/0/200` -- Flashes only in range `[512, end)` of
54*5225e6b1SAndroid Build Coastguard Worker    partition "boot_a" on storage device 0.
55*5225e6b1SAndroid Build Coastguard Worker  * `fastboot flash boot_a/0/200/200` -- Flashes only in range `[512, 1024)` of
56*5225e6b1SAndroid Build Coastguard Worker    partition "boot_a" on storage device 0.
57*5225e6b1SAndroid Build Coastguard Worker  * `fastboot flash boot_a///` -- Same as `"fastboot flash boot_a"`.
58*5225e6b1SAndroid Build Coastguard Worker  * `fastboot flash boot_a//200/200` -- Same as `"fastboot flash boot_a///"`,
59*5225e6b1SAndroid Build Coastguard Worker    except that it only flashes in range `[512, 1024)`
60*5225e6b1SAndroid Build Coastguard Worker
61*5225e6b1SAndroid Build Coastguard Worker* Raw storage devices by ID
62*5225e6b1SAndroid Build Coastguard Worker  ```
63*5225e6b1SAndroid Build Coastguard Worker  /[<storage_id>]
64*5225e6b1SAndroid Build Coastguard Worker  /[<storage_id>][/<offset>]
65*5225e6b1SAndroid Build Coastguard Worker  /[<storage_id>][/<offset>][/<size>]
66*5225e6b1SAndroid Build Coastguard Worker  ```
67*5225e6b1SAndroid Build Coastguard Worker
68*5225e6b1SAndroid Build Coastguard Worker  This is similar to the case of partition except that `part` is an empty
69*5225e6b1SAndroid Build Coastguard Worker  string. It specifies range`[offset, offset+size)` of the raw data on the
70*5225e6b1SAndroid Build Coastguard Worker  storage device with ID `storage_id`.  If `storage_id` is not given, GBL will
71*5225e6b1SAndroid Build Coastguard Worker  check if a default storage ID is set via
72*5225e6b1SAndroid Build Coastguard Worker  `fastboot oem gbl-set-default-block <storage_id>` and use the default ID if
73*5225e6b1SAndroid Build Coastguard Worker  set. Otherwise it is rejected. `offset` defaults to 0 if not given. `size`
74*5225e6b1SAndroid Build Coastguard Worker  defaults to the rest of the block after `offset` if not given. This semantic
75*5225e6b1SAndroid Build Coastguard Worker  applies to all storage devcies that can detected by GBL, whether or not it is
76*5225e6b1SAndroid Build Coastguard Worker  a raw storage partition or GPT device.
77*5225e6b1SAndroid Build Coastguard Worker
78*5225e6b1SAndroid Build Coastguard Worker  Examples:
79*5225e6b1SAndroid Build Coastguard Worker  * `fastboot flash /` -- If there is only one storage or a default storage ID
80*5225e6b1SAndroid Build Coastguard Worker    is set via `fastboot oem gbl-set-default-block <default ID>`, flashes in
81*5225e6b1SAndroid Build Coastguard Worker    the entire range of the storage.
82*5225e6b1SAndroid Build Coastguard Worker  * `fastboot flash /0x0` or `/0` -- Flashes in the entire range of storage
83*5225e6b1SAndroid Build Coastguard Worker    device 0.
84*5225e6b1SAndroid Build Coastguard Worker  * `fastboot flash /0/200` -- Flashes only in range `[512, end)` of storage
85*5225e6b1SAndroid Build Coastguard Worker    device 0.
86*5225e6b1SAndroid Build Coastguard Worker  * `fastboot flash /0/200/200` -- Flashes only in range `[512, 1024)` of
87*5225e6b1SAndroid Build Coastguard Worker    storage device 0.
88*5225e6b1SAndroid Build Coastguard Worker  * `fastboot flash ///` -- Same as `"fastboot flash /"`.
89*5225e6b1SAndroid Build Coastguard Worker  * `fastboot flash //200/200` -- Same as `"fastboot flash ///"`, except that
90*5225e6b1SAndroid Build Coastguard Worker    it only flashes in range `[512, 1024)`
91*5225e6b1SAndroid Build Coastguard Worker
92*5225e6b1SAndroid Build Coastguard WorkerNote: AOSP fastboot client tool introduces a special flash command syntax
93*5225e6b1SAndroid Build Coastguard Worker`fastboot flash vendor_boot_a:<part_size>` for performing vendor ramdisk
94*5225e6b1SAndroid Build Coastguard Workerrepacking and flashing. This however, does not work with GBL's `'/'` syntax
95*5225e6b1SAndroid Build Coastguard Workerdiscussed above, i.e. `fastboot flash vendor_boot_a/0:<part_size>` will not
96*5225e6b1SAndroid Build Coastguard Workertrigger the repack and flash flow for the vendor_boot_a partition on storage 0
97*5225e6b1SAndroid Build Coastguard Workeras might be expected. Instead, in this case, user should run
98*5225e6b1SAndroid Build Coastguard Worker`fastboot oem gbl-set-default-block 0` to set the default block to 0 first and
99*5225e6b1SAndroid Build Coastguard Workerthen use `fastboot flash vendor_boot_a:<part size>` normally.
100*5225e6b1SAndroid Build Coastguard Worker
101*5225e6b1SAndroid Build Coastguard Worker### Updating GPT Partition Table
102*5225e6b1SAndroid Build Coastguard Worker
103*5225e6b1SAndroid Build Coastguard WorkerGBL supports the following syntaxes for updating GPT partition table on a
104*5225e6b1SAndroid Build Coastguard Workerstorage device:
105*5225e6b1SAndroid Build Coastguard Worker
106*5225e6b1SAndroid Build Coastguard Worker```
107*5225e6b1SAndroid Build Coastguard Workerfastboot flash gpt <path to MBR+primary GPT blob file>
108*5225e6b1SAndroid Build Coastguard Workerfastboot flash gpt/<storage_id> <path to MBR+primary GPT blob file>
109*5225e6b1SAndroid Build Coastguard Workerfastboot flash gpt/[<storage_id>][/resize] <path to MBR+primary GPT blob file>
110*5225e6b1SAndroid Build Coastguard Worker```
111*5225e6b1SAndroid Build Coastguard Worker
112*5225e6b1SAndroid Build Coastguard WorkerUser must provide an image file that contains a MBR block and the primary GPT
113*5225e6b1SAndroid Build Coastguard Workerheader and entries. The above command will verify the given GPT and update it
114*5225e6b1SAndroid Build Coastguard Workerto the specified storage device. If the `resize` option is given, GBL will
115*5225e6b1SAndroid Build Coastguard Workeradjust the ending block of the last partition entry to cover the rest of the
116*5225e6b1SAndroid Build Coastguard Workerstorage. This is useful for sharing one single GPT blob file for different
117*5225e6b1SAndroid Build Coastguard Workerdevices with varying size of storage.
118*5225e6b1SAndroid Build Coastguard Worker
119*5225e6b1SAndroid Build Coastguard WorkerExamples:
120*5225e6b1SAndroid Build Coastguard Worker  * `fastboot flash gpt` -- If there is only one storage or a default storage
121*5225e6b1SAndroid Build Coastguard Worker    ID is set via `fastboot oem gbl-set-default-block <default ID>`, updates
122*5225e6b1SAndroid Build Coastguard Worker    the GPT of that storage.
123*5225e6b1SAndroid Build Coastguard Worker  * `fastboot flash gpt//resize` -- Same as `fastboot flash gpt` but also
124*5225e6b1SAndroid Build Coastguard Worker    performs resizing.
125*5225e6b1SAndroid Build Coastguard Worker  * `fastboot flash gpt/0` -- Update GPT to storage device 0.
126*5225e6b1SAndroid Build Coastguard Worker  * `fastboot flash gpt/0/resize` -- Same as `fastboot flash gpt/0` but also
127*5225e6b1SAndroid Build Coastguard Worker    performs resizing.
128*5225e6b1SAndroid Build Coastguard Worker
129*5225e6b1SAndroid Build Coastguard WorkerTo erase existing GPT partition table on a storage device, use:
130*5225e6b1SAndroid Build Coastguard Worker
131*5225e6b1SAndroid Build Coastguard Worker```
132*5225e6b1SAndroid Build Coastguard Workerfastboot erase gpt
133*5225e6b1SAndroid Build Coastguard Workerfastboot erase gpt/<storage_id>
134*5225e6b1SAndroid Build Coastguard Worker```
135*5225e6b1SAndroid Build Coastguard Worker
136*5225e6b1SAndroid Build Coastguard WorkerNote: The above only erases GPT partition table. Partition content remains
137*5225e6b1SAndroid Build Coastguard Workerunchanged.
138*5225e6b1SAndroid Build Coastguard Worker
139*5225e6b1SAndroid Build Coastguard WorkerExamples:
140*5225e6b1SAndroid Build Coastguard Worker  * `fastboot erase gpt` -- If there is only one storage or a default storage
141*5225e6b1SAndroid Build Coastguard Worker    ID is set via `fastboot oem gbl-set-default-block <default ID>`, erase
142*5225e6b1SAndroid Build Coastguard Worker    the GPT of that storage.
143*5225e6b1SAndroid Build Coastguard Worker  * `fastboot flash gpt/0` -- Erase GPT to storage device 0.
144*5225e6b1SAndroid Build Coastguard Worker
145*5225e6b1SAndroid Build Coastguard Worker## Non-blocking `fastboot flash`.
146*5225e6b1SAndroid Build Coastguard Worker
147*5225e6b1SAndroid Build Coastguard WorkerIf the UEFI firmware supports `EFI_BLOCK_IO2_PROTOCOL` for the storage devices,
148*5225e6b1SAndroid Build Coastguard WorkerGBL Fastboot provides an option to make `fastboot flash` non-blocking.
149*5225e6b1SAndroid Build Coastguard WorkerSpecifically, after the image is downloaded, GBL Fastboot will launch a
150*5225e6b1SAndroid Build Coastguard Workerseparate task in the background for writing the image to the device, while
151*5225e6b1SAndroid Build Coastguard Workeritself will continue to listen for the next Fastboot command from the host,
152*5225e6b1SAndroid Build Coastguard Workerincluding a new `fastboot flash` command. This provides some paralellism
153*5225e6b1SAndroid Build Coastguard Workerbetween downloading and flashing when the host is flashing multiple images.
154*5225e6b1SAndroid Build Coastguard WorkerExample:
155*5225e6b1SAndroid Build Coastguard Worker
156*5225e6b1SAndroid Build Coastguard Worker```
157*5225e6b1SAndroid Build Coastguard Workerfastboot oem gbl-enable-async-task
158*5225e6b1SAndroid Build Coastguard Workerfastboot flash boot_a <image>
159*5225e6b1SAndroid Build Coastguard Workerfastboot flash boot_b <image>
160*5225e6b1SAndroid Build Coastguard Workerfastboot flash vendor_boot_a <image>
161*5225e6b1SAndroid Build Coastguard Worker...
162*5225e6b1SAndroid Build Coastguard Workerfastboot oem gbl-sync-blocks
163*5225e6b1SAndroid Build Coastguard Workerfastboot oem gbl-disable-async-task
164*5225e6b1SAndroid Build Coastguard Worker```
165*5225e6b1SAndroid Build Coastguard Worker
166*5225e6b1SAndroid Build Coastguard WorkerIf a storage device is busy processing a previous flash when a new image is
167*5225e6b1SAndroid Build Coastguard Workerdownloaded and ready to be flashed, it will be blocked until the previous flash
168*5225e6b1SAndroid Build Coastguard Workeris completed. Different storage devices are independent to each other.
169*5225e6b1SAndroid Build Coastguard Worker
170*5225e6b1SAndroid Build Coastguard WorkerBecause IO is now non-blocking, the return status of a `fastboot flash` does
171*5225e6b1SAndroid Build Coastguard Workernot necessarily represents the status of the IO. If a storage device encounters
172*5225e6b1SAndroid Build Coastguard Workererrors while processing a non-blocking IO, all subsequent flash requests will
173*5225e6b1SAndroid Build Coastguard Workerbe rejected and the host should reboot the device.
174*5225e6b1SAndroid Build Coastguard Worker`fastboot oem gbl-sync-blocks` can be used to wait until all currently pending
175*5225e6b1SAndroid Build Coastguard Workerflash are completed. The command returns error if any previous or current flash
176*5225e6b1SAndroid Build Coastguard Workerencounters errors.
177