Commit graph

1101 commits

Author SHA1 Message Date
Treehugger Robot
73c6f08f5e Merge "Wait for disconnect when rebooting to userspace FB" into main 2024-04-13 04:35:47 +00:00
Akshata Kadam
fb6957c645 Updated 'cc' field of fuzz_config in Android.bp file
corrected cc field in fuzz_config

Bug: 306435930
Test: Build fastboot_fuzzer

Change-Id: I487838914e515619a4acb68331b9c9c7b2030173
2024-04-10 11:39:05 +05:30
Chris Sarbora
7199051aaf Wait for disconnect when rebooting to userspace FB
Wait for the device to disconnect when rebooting to userspace fastboot.
This is a particular problem for USB-over-IP devices, which must tunnel
the USB commands over a relatively-slow network and thus will not
disconnect as quickly as local ones.

Only currently effective for Linux hosts, since LinuxUsbTransport is the
only transport that implements WaitForDisconnect().

Test Plan:
provision with a usbip-attached device, see flash succeed

Change-Id: Ia8903dfa6e40755377870fbeaef9162934f992a0
2024-03-25 14:53:10 -05:00
Treehugger Robot
c0e1b607d3 Merge "fastboot: Increase maximum usbfs bulk size for writes to 256KiB" into main 2024-02-15 03:47:49 +00:00
Peter Collingbourne
ab8cc2f7f3 fastboot: Increase maximum usbfs bulk size for writes to 256KiB
With a device capable of saturating the bus at SuperSpeed+,
the next bottleneck is the fixed (size-independent) overhead of
the usbfs ioctl() system calls, which includes entering/exiting
the kernel, allocating/deallocating a contiguous buffer for DMA,
configuring/deconfiguring the IOMMU and issuing the DMA to the HC. In
order to saturate the bus from the host software perspective, we must
reach the schedule() call in reap_as() before the next interrupt from
the HC indicating the completion of the URB.

In my experimental setup, with an SS+ capable host and device
and 16 KiB URBs, we reach the schedule() call in 25us, but the
URB is serviced in an estimated 16us, so we lose roughly a third
of the bandwidth. Increasing the URB size to 64KiB there are
65us between interrupts and 55us until schedule(). This means
we usually reach schedule() in time but not always, so we lose a
bit of bandwidth. Increasing it again to 128KiB and we have 128us
between interrupts and 65us until schedule(), so we're now comfortably
saturating the bus. In order to account for differences between hosts,
this CL uses a doubled maximum of 256KiB.

With larger allocation sizes we now risk contiguous allocation
failures, so I implemented a fallback where we try smaller sizes if
a larger one fails.

With this CL download speeds on my hosts are now around 980 MB/s over
SS+ and 440 MB/s over SS.

Bug: 325128548
Change-Id: Ie5ad480c73f2f71a50ce7f75ffb4aaa93ded2f0b
2024-02-14 16:09:47 -08:00
Treehugger Robot
2d686d7b71 Merge "fastboot: Use clock_gettime(CLOCK_MONOTONIC) in now()" into main 2024-02-08 16:09:44 +00:00
Peter Collingbourne
cc1bf34ba6 fastboot: Use clock_gettime(CLOCK_MONOTONIC) in now()
If the system time changes during the execution of fastboot we might
see some strange output such as:

Sending sparse 'super' 4/20 (254972 KB)            OKAY [-516.263s]

Fix it by changing now() to use clock_gettime(CLOCK_MONOTONIC).
I confirmed that all callers of now() are using it for relative time
and not time since the epoch.

Change-Id: Ic3e9442c2ab21dfb076bfed88915085a183754b0
2024-02-07 16:55:49 -08:00
Matt Schulte
28f4807dd3 fastboot: Remove '\n' from interface name on linux
If the device provides an interface string, we should remove the newline
from the read file that is added from by the linux kernel.

Bug: 324320178
Test: Ran the same command with my local changes vs not

```
bash$ ./fastboot devices -l
5f42ad5ad259c90cf14ea222791b6aaa fastboot usb:7-3

bash$ fastboot devices -l
5f42ad5ad259c90cf14ea222791b6aaa fastboot
 usb:7-3
```

Change-Id: Ida3316fdba8e35f0c66784f83455a4d82e90ba1c
2024-02-07 16:24:26 -08:00
Peter Collingbourne
8635c016db fastboot: Use asynchronous operations to send data
The fastboot command currently uses USBDEVFS_BULK to transfer data
(including image data) to the target. On the kernel side it looks
like this:

1. Allocate a contiguous memory region and copy the user data into
   the memory region (which may involve accessing storage).
2. Instruct the driver to start a DMA operation.
3. Wait for the DMA to finish.

This is suboptimal because it misses out on a pipelining
opportunity. We could be doing 3 for the current operation in parallel
with 1 for the next operation, so that the next DMA is ready to go
as soon as the current DMA finishes.

The kernel supports asynchronous operations on usbdevfs file
descriptors (USBDEVFS_SUBMITURB and USBDEVFS_REAPURB), so we can
implement this like so:

1. Submit URB 0
2. Submit URB 1
3. Wait for URB 0
4. Submit URB 2
5. Wait for URB 1
and so on.

That is what this CL implements. On my machine it increases transfer
speed from 125 MB/s to 160 MB/s using a USB 3.0 connection to the
target (Pixel 8).

Bug: 324107907
Change-Id: I20db7ea14af85db48f6494091c8279ef7a21033d
2024-02-06 13:10:27 -08:00
Chun-Wei Wang
9c48951d91 Add help text for fastboot gsi status
Bug: 298533290
Test: fastboot -h
Change-Id: Icf91a980059aaa8e74e41af4036778fbbfbf1bd2
2024-01-02 15:29:21 +08:00
David Anderson
adb91b0e59 remount: Detect when flashall has happened in the bootloader.
This adds a new metadata header flag to the super partition. This flag
is set when "adb remount" is used, and is implicitly cleared when
flashing.

If there is a scratch partition present on /data, we require that the
flag be set in order to proceed using overlays. If not set, scratch is
not mapped in first-stage init, and scratch images are removed later
during startup.

Bug: 297923468
Test: adb remount -R, touch file in out/, sync, flashall
Change-Id: I9cc411a1632101b5fc043193b38db8ffb9c20e7f
2023-12-14 16:00:27 -08:00
David Anderson
99a33df544 Merge changes from topic "health-v3" into main
* changes:
  fastboot: Add getvar commands to query battery part info.
  Update fastbootd to use Health AIDL HAL V3.
  Update healthd to use Health AIDL HAL V3.
  Update storaged to use Health AIDL HAL V3.
2023-12-12 04:00:47 +00:00
Treehugger Robot
dcf3542d43 Merge "fastboot: fix network connected device status" into main 2023-12-11 23:41:21 +00:00
David Anderson
2cb36706f4 fastboot: Add getvar commands to query battery part info.
This adds two commands to test the new v3 Health HAL, to query the
battery serial number (unlocked devices only) and part status.

Bug: 309792384
Test: adb reboot fastboot
      fastboot getvar battery-part-status
      fastboot getvar battery-serial-number
Change-Id: Ie0a14eda06483d047544833124c327fb88ba43a2
2023-12-11 11:59:23 -08:00
David Anderson
9305c988b3 Update fastbootd to use Health AIDL HAL V3.
Bug: 309792384
Test: m
Change-Id: I660228c89cf18b46ea6c8165a4a74d20c0a2ac41
2023-12-11 11:59:23 -08:00
Dmitrii Merkurev
e20438f83b fastboot: fix network connected device status
Bug: 303236495
Change-Id: Iceac3509531af1af65b455b1a3d5f5ab9029fda6
Signed-off-by: Dmitrii Merkurev <dimorinny@google.com>
2023-12-09 01:55:20 +00:00
Yi Kong
90f6cb4b2c Fix -Wunused-variable compiler warning
Test: presubmit
Change-Id: Ia6d0a735c94c7be39994fb9c8ae4d3b65d6f4301
2023-12-06 14:07:36 +09:00
Yi Kong
b8bbc43489 Fix -Wunused-variable compiler warning
Test: presubmit
Change-Id: I63b1625decd3dcdb9f405c8825203e04810c282c
2023-12-05 18:36:00 +09:00
William Hester
bdf0b1bb83 Create integration test for fastboot CLI
We rely on parsing the `fastboot devices` output in device labs, and a
format change previously broke us. This test will ensure that the output
is exactly what we expect.

Test: atest --host fastboot_integration_test

Change-Id: I7606e7b3e4a1edfe487ff14bb06cbd3c0a3aa777
2023-10-26 16:51:33 -07:00
David Anderson
0bc02bfe71 fastboot: Fix flashing failure when a sparse image has an avb footer.
Trying to move the AVB footer on a sparse file will corrupt the sparse
format. Rather than implement this properly, for now, have the
copy_avb_footer() function gracefully fail by skipping the operation.

Bug: 304574023
Test: fastboot flash sparse image with avb footer
Change-Id: Ia6f0711789a04897ec266ad604a3d243c7184082
2023-10-20 11:20:53 -07:00
Bradley Furman
c6941de738 Merge "Update the fastboot command size from 64 to 4096 to cover the changes from https://android-review.git.corp.google.com/c/platform/system/core/+/2214970" into main 2023-10-13 18:28:17 +00:00
Harry Pan
06949876be Merge "Add new fastbootd battery-soc variable" into main 2023-10-11 00:28:28 +00:00
Daniel Zheng
3e9b88d504 Removing is_retrofit code path
This code path was never invoked. is_logical will return false on
secondary partitions in retrofit devices, so nothing actually is ever
deleted. If we manage to call the delete, the device side code will
fail with "cannot open the super partition"

Test: fastboot flashall on sargo device
Change-Id: I20b430c5c30bf992506190ea4e00b0b69c7b1005
2023-10-05 12:37:57 -07:00
Arun Sharma
1a3456f0bc FastbootDevice::boot1_1 null pointer dereference
FastbootDevice::boot1_1 attempts to dereference a null pointer when the
boot_control_hal_ is not set. It needs a guard statement to prevent
that.

Test: Manually tested on device without BootControl.
Bug: 301682120
Change-Id: Id86bcb915c8e2857bda26f64738dd5b643048e98
2023-10-05 16:35:24 +00:00
Harry Pan
7fa8dd655a Add new fastbootd battery-soc variable
Introduce new battery-soc variable to read battery
SSOC, this benefits manufacturing to better track
the SSOC after FSI image flashing in the userspace
fastbootd using the same approach as Android space,
otherwise it is difficult to implement the entire
battery SW stack from Android to fastboot bootloader
and generate the same test experience monotonically.

Bug: 303561559
Test: fastboot getvar battery-soc # in fastbootd
Change-Id: Ia3f68e314263d7dd4d4c45a908a0a49db6e761f9
Signed-off-by: Harry Pan <gspj@google.com>
2023-10-05 12:08:02 +00:00
Christopher Ferris
9dabc9ef32 Change source to be a unique_ptr.
The current code keeps a pointer to a local variable which doesn't
work too well. Change this to a unique_ptr and allocate the source
object that will be used instead.

Test: All unit tests pass.
Test: fastboot -w flashall on a mokey which crashed without this change.
Change-Id: Ief5437374181e514928c45dd540b42898901a137
2023-10-02 17:02:51 -07:00
Bradley Furman
5eea7e384b Update the fastboot command size from 64 to 4096 to cover the changes from https://android-review.git.corp.google.com/c/platform/system/core/+/2214970
BUG=182864081

Change-Id: I6766647e53d777fd61df6e40cfefb45c7b138c77
2023-09-29 21:18:23 +00:00
Daniel Zheng
7a8f82acbd should_flash_in_userspace signature change
We should change should_flash_in_userspace to work without
$ANDROID_PRODUCT_OUT being set and fall back on $OUT directory when
source isn't specified

This also fixes the flashing issue of flashing retrofit devices without
$ANDROID_PRODUCT_OUT set. If we
call fastboot update on a retrofit device, copy_avb_footer will resize
buf->sz of secondary partitions to the partition size, causing us to
send the unsparsed payload to the device -> "Invalid Size" issue.

This is because secondary partitions are considered physical partitions
on retrofit devices && should_flash_in_userspace wouldn't work if
$ANDROID_PRODUCT_OUT is set, so our first return clause in
copy_avb_footer doesn't catch this edge case causing us to resize the
buf-> sz incorrectly.

Did some testing, and also observed a case where flashing is able to
succeed despite $ANDROID_PRODUCT_OUT not being set before, so there
might still be some other edge case that we are still missing.

Test: fastboot update on sargo without $ANDROID_PRODUCT_OUT

Change-Id: I0e4781d96709b712f7d71657ec0d16d99b90214d
2023-09-26 16:55:06 -07:00
Daniel Zheng
5cbcdfae4e is_retrofit_device to work in bootloader
Changing is_retrofit_device() to work in bootloader. Previously flashall
flow was to boot into fastbootd and then  make a call to get
"super-image-name", however this does not work in bootloader. Since all
tasks are generated ahead of time, this old check will now fail and we
will fail to add the correct delete tasks in collectTasks(). This change
does make it so that is_retrofit check only works during fastboot
flashall + fastboot update (since this function is only used here,
nothing is currently affected).

To determine if a device is retrofit, it must satisfy two conditions -> Has
dynamic partitions && does not contain a super partition. The check for
if source has super_empty.img is sufficient for determining if a device
has dynamic partitions and if any single partition has
LP_PARTITION_ATTR_SLOT_SUFFIXED it is determined to be retrofit

Test: logs from fastboot update on sargo device confirms this check
returns true. Fastboot update on sargo
Bug: 300287332

Change-Id: Iadf5c56de51993a79307c60e45d6cc4988436f23
2023-09-22 13:22:57 -07:00
Daniel Zheng
8aba6d022c Removing headers + using string
Removing some unused headers and swapping out std::string_literal to
strings

Test: fastboot flashall
Change-Id: I343272f4a678398a0446660a639c525e42e25891
2023-09-19 17:01:23 -07:00
Daniel Zheng
2e6aee5316 Removing double delete from flashall
From aosp/2475604 the functionality of deleting retrofit partitions
wasn't added back correctly. aosp/837186 adds this logic in. We should
only have one delete that exists if the image is secondary and is
dynamic.

Unfortunately don't have a retrofit device to test on, but from an eye
test this logic seems to match the old functionality and should be
working

Test: m fastboot
Change-Id: I5481893ab1638541d21813efe1c4aab5219e1dcd
2023-09-19 16:17:52 -07:00
Daniel Zheng
1b547892f6 Merge "Adding test for IsDynamicPartition" into main 2023-09-11 21:06:32 +00:00
Daniel Zheng
a3b232c30c Merge "documenting optimized flash super" into main 2023-09-11 21:06:02 +00:00
Chun-Wei Wang
66b68dde92 Merge "Disallow fastboot to modify locked DSU" into main 2023-09-08 02:59:32 +00:00
Daniel Zheng
7d8ac7f122 Merge "Adding testing for optimized flash super" into main 2023-09-07 16:12:30 +00:00
Chun-Wei Wang
e72b3ad204 Disallow fastboot to modify locked DSU
This enhances the security requirement by only allowing
the owner app to change a locked DSU.

Bug: 277691885
Bug: 296985785
Test: 1. ensure device is OEM locked
      2. adb shell am start-activity \
         -n com.android.dynsystem/com.android.dynsystem.VerificationActivity \
         -a android.os.image.action.START_INSTALL \
         --el KEY_USERDATA_SIZE 2147483648 \
	 --es KEY_DSU_SLOT foo.lock
      3. adb reboot fastboot
      4. `fastboot gsi disable|wipe` should be blocked

Change-Id: I1a0cb8a074412468d16043ddf4101fbb76490115
2023-09-07 15:18:23 +08:00
Chun-Wei Wang
62051237a2 Merge "Add a fastboot command to show GSI status" into main 2023-09-05 22:18:40 +00:00
Chun-Wei Wang
671a2a551a Add a fastboot command to show GSI status
The command will be used by RMA tool to skip
device wiping when it is already in GSI mode.

This change also makes it easier to add more
gsi commands in the future without needing to
update the host side tool (fastboot).

Bug: 298130522
Bug: 298138572
Test: 1. reboot into fastboot mode
      2. fastboot gsi status
Change-Id: Ic81f89a93b854f9ec70aebe2d209bfd1f98e3645
2023-09-05 23:31:01 +08:00
Dmitrii Merkurev
f667b6d8ba Merge "fastboot: get rid of manual transport memory management" into main 2023-09-05 14:04:54 +00:00
Dmitrii Merkurev
0b627d92c4 fastboot: get rid of manual transport memory management
Existing code has transport memory leaks. Use smart pointers
for transport to get rid of those cases and manual memory
management

Test: atest fastboot_test
Test: manually checked transport isn't leaking anymore
Bug: 296629925
Change-Id: Ifdf162d5084f61ae5c1d2b56a897464af58100da
Signed-off-by: Dmitrii Merkurev <dimorinny@google.com>
2023-09-03 17:30:46 +01:00
Daniel Zheng
afe1163ade Adding test for IsDynamicPartition
Adding a test case for checking if flash task is a dynamic partition
flash task. This function is used since is-logical only works in
fastbootd, and should_flash_in_userspace() only works if
$ANDROID_PRODUCT_OUT is set. This function works with fastboot update
when called in bootloader without $OUT dir set

Test: fastboot_test
Change-Id: I65309f97e04fdfc449e61de5cd3a6feff18bc9ab
2023-08-30 12:59:29 -07:00
Daniel Zheng
2d4261ca43 documenting optimized flash super
Adding documentation on the explicit pattern match we are going to add
to optimizing flash super.

Test: na
Change-Id: I57c19fb2a85d74beea5b91e38f6f46fa47637117
2023-08-30 12:59:27 -07:00
Daniel Zheng
1fff690c18 Adding testing for optimized flash super
Adding test cases for correct formation of optimized flash super task.
We are adding an explicit pattern match for this task to be correctly
formed. Changing Optimized flash task to only remove the reboot to
userspace as a user might want to reboot back to bootloader after
flashing. We also need to change a couple functions to take a
IFastbootDriver to mock up the initialization path.

Test: fastboot_test
Bug: 297085098
Change-Id: Ic5c63bd4057ca6d64647134e5ce33fef12077fdb
2023-08-30 12:59:26 -07:00
Daniel Zheng
1ef66b70ff Fixing optimization logic
Adding a hard pattern check for optimized task formation. To keep
behavior consistent, we will remove the old initialization path and add
resize tasks after attempting optimization.

Test: fastboot_test
Bug: 297085098
Change-Id: Ie0e656af9be7abdd130290fe547ffbf385ce75d6
2023-08-30 09:39:30 -07:00
Daniel Zheng
2326e056bd Add documentation to README
adding documentation on how to use fastboot-info inside of fastboot
README

Test: na
Bug: 297084293
Change-Id: Ic2d17c92a776f1cae9ef80f6b615ddbc841afb74
2023-08-22 14:27:16 -07:00
Keith Mok
eb2165079a Merge "Adding force_flash functionality" into main 2023-08-09 20:45:24 +00:00
Daniel Zheng
720007ba43 Merge "Adding flag to flash only static partitions" into main 2023-08-09 18:09:00 +00:00
Daniel Zheng
376b70423d Adding force_flash functionality
aosp/2452605 might've accidentally omitted force flash functionality
from fastboot. Some users need to flash dynamic partitions from
bootloader, so we are readding this feature back into fastboot

Test: adb reboot bootloader, fastboot flash system --force

Change-Id: I37a51ebbe38b27ed428c38068d30c0febd7db09c
2023-08-09 10:54:14 -07:00
Alexander Koskovich
6367e8953a core: fastboot: Fix data not being wiped on do_update
* With platform-tools-34.0.4 if you try to wipe data
   as apart of the fastboot update command it will not
   work, will just reboot to userspace without running
   the wipe task.

Test: fastboot -w update image.zip, observe that data
      gets wiped. Also verified 'fastboot update image.zip'
      does *not* wipe data.
Change-Id: I57a2c64029fd4f78968324bdf60251e1e962b3fd
2023-08-05 00:39:10 -04:00
Daniel Zheng
b0f9c07590 Merge "Adding include to functional" into main 2023-07-28 20:00:44 +00:00