Commit graph

151 commits

Author SHA1 Message Date
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
Harry Pan
06949876be Merge "Add new fastbootd battery-soc variable" into main 2023-10-11 00:28:28 +00: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
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
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
Sandeep Dhavale
63928c310e Fastboot: Use AServiceManager_waitForService instead of AServiceManager_getService
AServiceManager_getService waits unncessarily waits for 5 seconds if
service is not available. Use isDeclared() and waitForService() instead.

Bug: 261759425
Test: build and flash
Change-Id: I20a5f422ca0c26c6e9e183e6636b30a2f19e76d3
Signed-off-by: Sandeep Dhavale <dhavale@google.com>
2022-12-10 05:29:26 +00:00
Yi-Yo Chiang
38b68c6a0e fastbootd: Add getvar is-force-debuggable
Export ro.force.debuggable property so that the user can check image
compatibility prior to running fastboot flash.
For example, if is-force-debuggable is yes, then the "system" and
"vendor" build fingerprint must match.

Bug: 191649082
Test: fastboot getvar is-force-debuggable
Change-Id: I772d98253f58ba208d5803e18b589ff693deebd0
2022-11-22 17:32:21 +08:00
Sandeep Dhavale
2534d485d8 Fastbootd: Use Fastboot AIDL with the help of fastbootshim for legacy fastboot HAL
Bug: 205760652
Test: build & flash & reboot fastboot
Change-Id: I79617a396f536258655bdc28006ac2d0a7ab1912
Signed-off-by: Sandeep Dhavale <dhavale@google.com>
2022-11-09 00:38:34 +00:00
Florian Mayer
4c3c526e54 [MTE] Reset MTE state for userdata wipe in fastbootd
Test: $ adb shell su root [...]/mtectrl memtag,memtag-kernel default
      $ adb shell 'su root dd bs=1 skip=32832 if=/dev/block/bootdevice/by-name/misc count=15 | xxd'
      00000000: 015a fefe 5a05 [...]
      $ adb reboot fastboot
      $ fastboot -w
      $ fastboot reboot
      $ adb shell 'su root dd bs=1 skip=32832 if=/dev/block/bootdevice/by-name/misc count=15 | xxd'
      00000000: 0000 0000 0000 [...]

Bug: 245596152
Change-Id: I5e2d4584776ab1685bdf37124e32dcb827eaf05a
2022-10-03 11:01:36 -07:00
Nicolas Gagnon
e21b7a552d Port ADB's new handling of the USB packet ClearFeature(HALT) to Fastboot.
This patch addresses Fastboot/Fastbootd connection issues seen on ARM Mac devices.

Original ADB patch: https://android-review.googlesource.com/c/platform/packages/modules/adb/+/1699250/

Bug: 238779161
Test: 'fastboot update <path_to_update_archive>.zip' now works on ARM Mac.

Signed-off-by: Nicolas Gagnon <nicolasgagnon@google.com>
Change-Id: Id67904d91abc8b66ef1a00962e1fd57c97df98a7
2022-09-14 21:11:30 +00:00
Kelvin Zhang
682e5b530a Add io_uring support to fastboot
Test: th
Bug: 31712568

Change-Id: If18bd4eb53ffe851c31d7dc61906921da111114f
2022-08-11 18:58:43 -07:00
Kelvin Zhang
6befe78c3c Convert fastboot/libsnapshot to new BootControl client
Thew new client will use AIDL if available, and fallback to HIDL
otherwise.

Test: th
Bug: 227536004
Change-Id: I9af21037a76a4a6db00144f5b2774ea23f3a5cc2
2022-07-08 10:57:53 -07:00
David Anderson
ebc8fe19f8 fastboot: Add a command to get current kernel logs.
This adds "fastboot getvar dmesg", usable only in userspace fastboot,
and only on unlocked devices. This is to debug flashing failures when
serial log access is not available.

Bug: 230269532
Test: fastboot getvar dmesg
Change-Id: Ic57881e362efe3f0687f41ab986d30b3a59dc4e4
2022-06-21 19:32:19 -07:00
David Anderson
954ff922ea fastbootd: Add better logging for flashing failures.
Bug: 233980876
Test: builds, fastboot flashall
Change-Id: Icc81ac4d9a4ca76f7eb757df5524d95f488fcd8c
2022-06-01 22:46:35 -07:00
Michael Bestas
bcf7680614
fastboot: Print OemCmdHandler return message on success
This allows OEM commands to print messages in fastboot output.

Test: run fastboot oem getprop ro.boot.rf_version
      and observe property value being printed in console

Change-Id: Id9bd5a107861a790cd02dc87057600de5bb94d42
2022-05-16 19:42:28 +03:00
Konstantin Vyshetsky
04a4a10ee1 Merge changes from topic "fastbootd-reset-fd"
* changes:
  fastbootd: reset file descriptor on unaligned writes
  fastbootd: add support to reset fd by handle
  fastbootd: pass handle in place of fd
2022-03-28 20:13:25 +00:00
Konstantin Vyshetsky
57b23d25eb fastbootd: reset file descriptor on unaligned writes
Writes on file descriptors opened with O_DIRECT will fail if the buffer
is not page aligned. This CL will reset the file descriptor without the
O_DIRECT flag for such instances.

Bug: 225108941
Signed-off-by: Konstantin Vyshetsky <vkon@google.com>
Change-Id: I841c84f5d2c0b9435b394c48b1bfcc2d51d771bb
2022-03-28 10:57:03 -07:00
Konstantin Vyshetsky
1cee2ed239 fastbootd: add support to reset fd by handle
There are cases where the flags the file descriptor was opened with need
to be modified. This CL adds functionality to reset the file descriptor
held by a PartitionHandle, reopening with new flags and repositioning
file offset to previous.

Bug: 225108941
Signed-off-by: Konstantin Vyshetsky <vkon@google.com>
Change-Id: I9adb0e7696bc6af74e14dd61a6cb0ef10b4c98c8
2022-03-28 10:57:03 -07:00
Konstantin Vyshetsky
b3e1829421 fastbootd: pass handle in place of fd
There are cases such as non 4KB aligned buffers which break writes on
file descriptors opened with O_DIRECT. Flashing functions need more
control over the file descriptor, which is not achievable easily by
having only a file descriptor passed. This CL modifies the logic to pass
the PartitionHandle in place of the file descriptor during flashing.

Bug: 225108941
Signed-off-by: Konstantin Vyshetsky <vkon@google.com>
Change-Id: I049d0ffb183c9de1267b7e442488c8ba5002186a
2022-03-21 11:35:42 -07:00
LuK1337
9dd073ebfa fastboot: Fallback to "raw" partition type if fastboot hal isn't present
Fastboot format fails to wipe any partition that doesn't at least return
"raw" partition type. Also both android.hardware.fastboot@1.0-impl.pixel
and android.hardware.fastboot@1.1-impl-mock return FileSystemType::RAW
so I assume this is fine.

Change-Id: I5707bddb1ba32edb6359858853d7b1afbf138b9f
2022-03-02 14:28:33 +01:00
David Anderson
982c3410c7 fastbootd: Remove all scratch partitions on update-super.
This ensures that the dynamic "scratch" partition is removed when doing
a flashall operation.

If "scratch" is on /data, disable the partition. Add IsImageDisabled to
ImageManager so EnsureScratchMapped can skip mapping it. Also, fix
"scratch" not getting unmapped if on /data.

Bug: 205987817
Test: adb remount
      adb sync
      adb reboot fastboot
      fastboot flashall --skip-reboot # no errors
Test: adb-remount-test.sh
Change-Id: I4b9702e1dac15fb663635506fb50a8274e1e10d1
2022-02-17 04:16:53 +00:00
Keith Mok
a3b72067de Add checking for sparse file format
Sparse file can come from an untrusted source.
Need more checking to ensure that it is not a malformed
file and would not cause any OOB read access.

Update fuzz test for decoding also.

Test: adb reboot fastboot
      fuzzy_fastboot --gtest_filter=Fuzz.Sparse*
      fuzzy_fastboot --gtest_filter=Conformance.Sparse*
      sparse_fuzzer
Bug: 212705418
Change-Id: I7622df307bb00e59faaba8bb2c67cb474cffed8e
2022-01-14 00:37:48 +00:00
Devin Moore
12e5f038a9 Merge changes Ib5a63a7b,If00f581a
* changes:
  fastboot: copy AVB footer from init_boot.img to end of partition
  fastboot: Support flashing init_boot.img into init_boot partition
2022-01-07 16:24:13 +00:00
Devin Moore
1af1202fbd fastboot: copy AVB footer from init_boot.img to end of partition
Similar to GKI boot.img, init_boot.img is released as a specific size
and should be able to be flashed into partitions that have different
sizes. So the AVB footer is moved from the end of the init_boot.img to
the end of the partition in the case that the partition is larger than
the image.

Bug: 203698939
Test: m
Change-Id: Ib5a63a7bf1b4be4eba4941972750f12e3edb3a17
2022-01-06 22:33:19 +00:00
Keith Mok
3724bbcbe9 Fix userspace fastboot with fuzzy test
Add more checking for fastboot to detect malformed
requests.
Such as checking no control characters in the command
send from host.
Make sure the download command length is eight bytes.
And report FAIL if download length is zero.

Test: adb reboot fastboot
      fuzzy_fastboot --gtest_filter=Fuzz.DownloadInvalid1
      fuzzy_fastboot --gtest_filter=Fuzz.DownloadInvalid2
      fuzzy_fastboot --gtest_filter=Fuzz.DownloadInvalid7
      fuzzy_fastboot --gtest_filter=Fuzz.DownloadInvalid8
Bug: 212628476
Change-Id: I750174205377395b5328923fb00462d078f3310d
2022-01-04 19:24:23 +00:00
Yifan Hong
4cb88dc811 fastboot: use health AIDL HAL
Bug: 208543110
Test: fastboot getvar
Change-Id: Ib83e7ccd53e49367f7af218ffafb7c0a57a514f6
2021-12-06 23:18:32 -08:00
Konstantin Vyshetsky
d5f3da8dc5 fastbootd: use O_DIRECT for write partition
Direct writes for partition flashing significantly increase performance.
Use O_DIRECT flag when opening partition for flashing. Additionally use
a 4096b aligned buffer which is required for O_DIRECT.
Switch from using 8MB write buffer to 1MB write buffer, as the extra
allocation has no performance impact.

Test: flash locally and reach home screen
Bug: 205151372
Signed-off-by: Konstantin Vyshetsky <vkon@google.com>
Change-Id: I060f438cf698d0fda1e59e35338bb5dc1cd05b51
2021-11-04 13:24:33 -07:00
Konstantin Vyshetsky
81cc119eff fastbootd: allow passage of flags to open partition
Allow caller to pass additional flags when opening a partition. Obsolete
usage of boolean read, and make previous callers use O_RDONLY instead.
Explicitly OR (O_EXCL | O_CLOEXEC | O_BINARY) to keep existing design
working as is.

Test: flash locally and reach home screen
Bug: 205151372
Signed-off-by: Konstantin Vyshetsky <vkon@google.com>
Change-Id: I48fbca459a17fcf0b0926ab339585e3bd8e31e35
2021-11-04 12:05:48 -07:00
David Anderson
1f670ef7a8 fastbootd: Delete all VAB partitions during "flashall".
With VAB we encourage a smaller super partition, so make sure we delete
"other" slot partitions during flashing. Otherwise, we may not have
enough space in super.

Bug: 195930130
Test: set_active, flashall, ensure other slot is deleted
Change-Id: Ic6a4f60e8f4c7abb8af7b38228753ad8ed85eedf
2021-08-09 12:36:13 -07:00
David Anderson
7723c72cab Merge "Unable to mount filesystem in fastbootd mode on the user build." 2021-04-13 23:45:01 +00:00
joker.yang
09090946a8 Unable to mount filesystem in fastbootd mode on the user build.
for GSI XTS self-test, we need to mount filesystem(/metadata) in fastbootd mode. so we add a qualification since there is no overlayfs on user build anyway.

bug: 181097763
Change-Id: Ie36bd2f5b3981e6774dc4a2123c33180cddb99d1
2021-03-30 01:21:52 +00:00
Oleg Matcovschi
d0a16c20fc fastboot: derive device locked state from Android property
We shall rely on Android property instead of parsing kernel
command line directly: parameters could be originated from
kernel command line or bootconfig.

Bug: 183237066
Bug: 183719613
Signed-off-by: Oleg Matcovschi <omatcovschi@google.com>
Change-Id: Ia70d286646a83a95967ca4293168a6550ffff7f0
2021-03-25 14:45:54 -07:00
Yifan Hong
07e947fc5d fastboot device: Disallow implicit conversion from unique_fd to int.
Do not use the implicit cast from unique_fd to int so
that it is clearer to the reader what the ownership model
is.

Test: pass
Change-Id: I66563eb2bd06f6a712a5afd4c6009f9b25a55de6
2021-03-22 19:30:59 -07:00
Yifan Hong
bcd2770207 fastboot driver: add fetch command in driver
The `fastboot fetch` command is a wrapper around
the fetch protocol. It:

- getvar max-fetch-size
- get the size of the partition
- read the data by chunks, chunk size = max-fetch-size.

The name of the partition is passed directly to the device
(with the usual has-slot magic for flashing etc.) If we support
fetching partitions other than vendor_boot in the future, no change
in the driver is needed.

Bug: 173654501
Test: manual

Change-Id: Ie576eea668234df236b096a372e65c5e91c1e48c
2021-03-17 15:38:06 -07:00
Yifan Hong
a5cee93b5a fastbootd: add O_CLOEXEC/O_BINARY for OpenPartition
O_CLOEXEC ensures fastbootd does not leak fds to the parent
process (recovery).

O_BINARY has no effect in Linux, but it is explicit that
the file (partition) to read is a binary file.

Test: pass
Bug: 173654501

Change-Id: Idba922965ce666af1b7ee460ec7449fabd511c35
2021-03-17 15:38:06 -07:00
Yifan Hong
c4073d3e13 fastbootd: add read arg to OpenPartition
Allow it to read partitions.

Bug: 173654501
Test: pass

Change-Id: I115e84734dd258243ca3f4f1b373b06adcaa4080
2021-03-17 15:38:06 -07:00
Yifan Hong
a4eb4753ac fastbootd: Add fetch command on device
Test: manual
Test: see follow up CL on fuzzy_fastboot
Bug: 173654501

Change-Id: I912d60d6dca0082734f2b84adc6a647c881bb5a1
2021-03-17 15:38:06 -07:00
Yifan Hong
b299cb7217 fastbootd: Add getvar max-fetch-size.
Test: run it
Test: see follow up CL on fuzzy_fastboot

Bug: 173654501

Change-Id: I5ed110c5569d83cbe791d04b4abea3a2af2765a9
2021-03-17 15:38:06 -07:00
Treehugger Robot
fce8e0f4a4 Merge "fastbootd: Fix USB transport data is repeated every 256K" 2021-03-06 05:50:50 +00:00
Yifan Hong
5f23388c7a fastbootd: Fix USB transport data is repeated every 256K
When Write() is called on data > 256K, the written data
repeats every 256K because of the buggy line in this change.

Test: fastboot fetch vendor_boot.img
Fixes: 180654366

Change-Id: I33b129de27000d3f32f284469998daf540d4f856
2021-03-05 19:45:00 -08:00
David Anderson
565577f926 Add support for compressed snapshot merges in fastboot.
SnapshotManager::New() is now preferred in recovery. Previously we used
NewForFirstStageMount(), which is technically incorrect as that enables
code paths specifically for first-stage init.

We also explicitly label the snapuserd context, since rootfs in recovery
has unlabelled files.

Finally, we add a timeout to internal calls to
CreateSnapshotsAndLogicalPartitions. Without this, WaitForDevice() calls
will terminate immediately, which breaks VABC given the more complex
device stacking that is created.

Bug: 168258606
Test: fastboot snapshot-update merge
Change-Id: I3a663b95c0b1eabaf14e6fde409c6902653c3c5e
2021-02-04 20:21:18 -08:00
Xin Li
4217e6d7bd Merge rvc-qpr-dev-plus-aosp-without-vendor@6881855
Bug: 172690556
Merged-In: I22cc7bb8ac579d0e03f92ec5a16e8c0f2c768051
Change-Id: Ide85f5a8acd02dead55dc87f9d6a80b3261027b4
2020-12-02 00:17:00 -08:00
Yo Chiang
66d0d96c89 Refactor fs_mgr_overlayfs_teardown()
Right now fs_mgr_overlayfs_teardown() does slightly different things
when called from the userspace or recovery. This is accomplished by many
runtime checks, runtime assumptions and conditional execution of code.

This makes the control flow of the function very hard to follow, and
assumptions becomes more fragile as the function becomes more complex.

This CL forks fs_mgr_overlayfs_teardown() and removes "recovery" bits
from it. A new entry point TeardownAllOverlayForMountPoint() is added
for recovery.

Recovery (fastbootd) should call TeardownAllOverlayForMountPoint() to
teardown overlays of all sources (cache dir, scratch device or DSU).
While fs_mgr_overlayfs_teardown() should only be called from the
userspace.

Also apply some linter suggestions.

Bug: 165925766
Test: adb-remount-test.sh
Change-Id: I7ff7e3409c910782e1ec207fcd02b967a9762bc1
2020-10-28 16:05:09 +08:00
David Anderson
f74c1a9556 fastbootd: Add more logging for when the USB transport fails.
Bug: 161542676
Test: fastboot flashall
Change-Id: Ief4e7452b72504c51c807dd38a07765ad65c96a4
2020-10-12 15:55:48 -07:00
josephjang
2906975399 fastboot: add new oem command for post wipe userdata
When Android userdata partition has been erased in fastbootd, call
oem specific API doOemSpecificErase() to wipe other userdata in
device.

If oem doesn't implement this specific API in fastboot_hal lib,
fastbootd will receive 'NOT_SUPPORTED' return status.

Bug: 169173873
Change-Id: I9b6a5a4aaed31d1168e633418b189f9bb6d34d01
2020-10-01 05:09:26 +00:00
TreeHugger Robot
6ec7e3a5c3 Merge "fastboot: add new oem command for post wipe userdata" into rvc-qpr-dev am: 46ef208603
Original change: https://googleplex-android-review.googlesource.com/c/platform/system/core/+/12626459

Change-Id: Ieae4b452be87163f15589bf8ae081e507ded8f2b
2020-09-25 17:03:43 +00:00
josephjang
ad90b45558 fastboot: add new oem command for post wipe userdata
When user input fastboot erase userdata, need a follow
up oem command to wipe other user data in device.
We support this new postwipedata command in
"fastboot erase userdata" only.

Bug: 150929955
Change-Id: I9b6a5a4aaed31d1168e633418b189f9bb6d34d01
Ignore-AOSP-First: I9b6a5a4aaed31d1168e633418b189f9bb6d34d01
2020-09-25 08:22:19 +00:00
David Anderson
e681cf01c8 Merge "fastboot: Allow fastboot to asynchronously differentiate between fastboot and fastbootd." 2020-05-29 04:47:35 +00:00
David Anderson
4e058cac0d fastboot: Allow fastboot to asynchronously differentiate between fastboot and fastbootd.
It's not possible to programmatically determine which fastboot mode a
device is in, without sending a getvar:is-userspace query. Unfortunately
this is not possible asynchronously, and may interrupt other queries
being processed.

This patch changes fastbootd's USB interface name to "fastbootd". Note
that tools use the protocol number/class and not this string, so it
should be safe to extend. When using "fastboot devices", the interface
name is now listed if set. Note that currently only the Linux version of
the fastboot tool is capable of reading the interface name.

Bug: 156966319
Test: fastboot devices on Linux
Change-Id: I57ccf2bec1dda573fe3ac628a646624b76f45905
2020-05-28 17:42:00 +00:00