Commit graph

110 commits

Author SHA1 Message Date
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
Hongguang Chen
7516ebe63b fastbootd: Support TCP protocol.
The current fastbootd only supports USB protocol. But some Android TV
devices are built without USB port. The fastbootd cannot be used on
those ATV devices due to it.
This change adds TCP protocol for such devices and fastbootd.protocol
property is added to control which protocol to use.

BUG: 152544169
BUG: 155198345
Test: manual test.
Change-Id: Idc391e677eb6a1880036419ba5f6c4160e8dbcbc
Merged-In: Idc391e677eb6a1880036419ba5f6c4160e8dbcbc
2020-05-19 19:11:25 +00:00
Treehugger Robot
4222040bd5 Merge "fastbootd: Support TCP protocol." 2020-05-18 17:05:43 +00:00
TreeHugger Robot
56c1c590ac Merge "fastbootd: copy AVB footer on boot image to end of block device" into rvc-dev 2020-05-18 04:37:37 +00:00
Steve Muckle
bd98e25439 fastbootd: copy AVB footer on boot image to end of block device
If the flashed boot image is smaller than the block device, the AVB
footer will not be at the end of the partition. Although images are
normally created to match the partition size the GKI boot.img must work
on all devices, and the size of the boot partition will vary.

Copy the AVB footer to the end of the partition before flashing, if it
is not there already.

Bug: 156036850
Change-Id: I11f0c7d32d1b6c74edd4f84f815d175605280cb8
Merged-In: I11f0c7d32d1b6c74edd4f84f815d175605280cb8
2020-05-17 17:01:25 -07:00
Hongguang Chen
1e239289d5 fastbootd: Support TCP protocol.
The current fastbootd only supports USB protocol. But some Android TV
devices are built without USB port. The fastbootd cannot be used on
those ATV devices due to it.
This change adds TCP protocol for such devices and fastbootd.protocol
property is added to control which protocol to use.

BUG: 152544169
Test: manual test.
Change-Id: Idc391e677eb6a1880036419ba5f6c4160e8dbcbc
2020-05-13 01:25:58 +00:00
Steve Muckle
a9b3443e53 fastbootd: copy AVB footer on boot image to end of block device
If the flashed boot image is smaller than the block device, the AVB
footer will not be at the end of the partition. Although images are
normally created to match the partition size the GKI boot.img must work
on all devices, and the size of the boot partition will vary.

Copy the AVB footer to the end of the partition before flashing, if it
is not there already.

Bug: 156036850
Change-Id: I11f0c7d32d1b6c74edd4f84f815d175605280cb8
2020-05-12 16:21:41 -07:00
David Anderson
f2f5edd9d5 fastboot: Fix snapshot-update merge behavior.
When merging in recovery, the "imminent data wipe" code was used, which
made the assumption the /metadata and /data state would be zapped. This
caused future OTAs to error because the old snapshots were detected.

This CL allows OTAs to proceed even if unexpected snapshots are present.
It also forces the state to "MergeCompleted" after a merge in recovery,
so that the next normal boot can perform cleanup.

Bug: 155339165
Test: fastboot snapshot-update merge, then take another OTA
      vts_libsnapshot_test
Change-Id: Ief6dea3ba76323044e61307272dda320a4494aea
Merged-In: Ief6dea3ba76323044e61307272dda320a4494aea
2020-05-04 15:53:06 -07:00
David Anderson
5a0177d945 fastboot: Fix snapshot-update merge behavior.
When merging in recovery, the "imminent data wipe" code was used, which
made the assumption the /metadata and /data state would be zapped. This
caused future OTAs to error because the old snapshots were detected.

This CL allows OTAs to proceed even if unexpected snapshots are present.
It also forces the state to "MergeCompleted" after a merge in recovery,
so that the next normal boot can perform cleanup.

Bug: 155339165
Test: fastboot snapshot-update merge, then take another OTA
      vts_libsnapshot_test
Change-Id: Ief6dea3ba76323044e61307272dda320a4494aea
2020-05-02 16:02:07 -07:00
TreeHugger Robot
3db222694d Merge changes from topic "minadbd_static_libadbd" into rvc-dev
* changes:
  Statically link libadbd into minadbd.
  adb: temporarily kill adb_benchmark.
  Move adbd's legacy USB implementation to fastboot.
2020-04-01 04:18:37 +00:00
Josh Gao
2783122071 Move adbd's legacy USB implementation to fastboot.
This code path is effectively dead in adbd, and fastboot's dependency on
libadbd makes it hard to refactor adbd's dependencies.

Bug: http://b/150317254
Test: built and flashed aosp_walleye-eng
Change-Id: I5118136d32fdcbbd011559ed0a4a71e1dc7bf064
Merged-In: I5118136d32fdcbbd011559ed0a4a71e1dc7bf064
(cherry picked from commit 0871824de6)
2020-03-31 16:05:36 -07:00
David Anderson
083df2945e fastbootd: Unmount /cache before flashing.
Bug: 150112538
Test: fastboot flash cache on non-A/B device
Change-Id: I8a86bc4d12e4b3be020bbe47e02262a5aaa913a7
Merged-In: I8a86bc4d12e4b3be020bbe47e02262a5aaa913a7
2020-03-31 13:23:00 -07:00
Tom Cherry
e4a6ed8534 fastbootd: sync() after flashing partitions or updating super
There is a chance that devices are failing to reboot in the lab due to
sync() taking explicitly long during reboot.  Let's add the sync()'s
here to ensure they get accounted for in the flashing process.

A side benefit is it's likely safer to sync immediately after
flashing than to hope init does it during reboot.

Bug: 150863651
Test: flash local devices successfully
Change-Id: I4c4b0114f3cde8af4b8b2cb283ec21f869ef9f6f
2020-03-31 10:54:58 -07:00
Josh Gao
0871824de6 Move adbd's legacy USB implementation to fastboot.
This code path is effectively dead in adbd, and fastboot's dependency on
libadbd makes it hard to refactor adbd's dependencies.

Bug: http://b/150317254
Test: built and flashed aosp_walleye-eng
Change-Id: I5118136d32fdcbbd011559ed0a4a71e1dc7bf064
2020-03-30 16:43:06 -07:00
David Anderson
2ffc31b090 fastbootd: Unmount /cache before flashing.
Bug: 150112538
Test: fastboot flash cache on non-A/B device
Change-Id: I8a86bc4d12e4b3be020bbe47e02262a5aaa913a7
2020-03-25 21:00:13 -07:00
Hridya Valsaraju
6c889bb9cb fastbootd: use FastbootDevice::GetCurrentSlot to get current slot suffix
Using FastbootDevice::GetCurrentSlot to get the current slot suffix
instead of reading the same from the device's boot control HAL
is required to account for the prior set_active commands issued via
fastbootd in the same boot.

Test: fuzzy_fastboot
--gtest_filter=Conformance.Slots:Conformance.SetActive --gtest_repeat=10
Bug: 146589281

Change-Id: I2edb0f024d93c2483659623423ef5c69c717c7af
Merged-In: I2edb0f024d93c2483659623423ef5c69c717c7af
2020-03-03 17:38:19 +00:00
Hridya Valsaraju
45719a8f07 fastbootd: use FastbootDevice::GetCurrentSlot to get current slot suffix
Using FastbootDevice::GetCurrentSlot to get the current slot suffix
instead of reading the same from the device's boot control HAL
is required to account for the prior set_active commands issued via
fastbootd in the same boot.

Test: fuzzy_fastboot
--gtest_filter=Conformance.Slots:Conformance.SetActive --gtest_repeat=10
Bug: 146589281

Change-Id: I2edb0f024d93c2483659623423ef5c69c717c7af
2020-03-02 13:14:11 -08:00
Bowgo Tsai
99f9a38a8b fastbootd: exporting more properties
Exporting more properties that can be useful for image compatibility
check, prior to run fastboot flash.

Bug: 74445765
Bug: 144473561
Test: fastboot getvar <new variable>
Change-Id: I2ddfa2c1e9e719e05a3a64b9ca1d608957aebf11
2020-01-22 23:29:07 +08:00
steven_fann
fde5e27602 Allow fuzzy_fastboot test devices over internet
Bug: 144667236
Test: fuzzy_fastboot --serial=192.168.1.104:5555 --gtest_filter=*Logical*

Change-Id: I02e62f706d0a3a19a9b7b56788abe05759d2d63d
2020-01-21 15:40:52 +00:00
David Anderson
23243497fd fastboot: Mount /metadata before overlayfs teardown.
fs_mgr_overlayfs needs access to /metadata to tell whether or not the
scratch partition exists on /data.

Bug: 134949511
Test: adb remount, fastboot flash system
Change-Id: I3a09aae495d691e9c1a1e25a8fb3514e355ecd05
2019-12-30 13:42:57 -08:00
David Anderson
bf55a76fd9 Merge "fastbootd: Disallow certain operations during snapshot updates." 2019-11-19 00:49:44 +00:00
Bowgo Tsai
33da5c9493 fastbootd: exporting CPU ABI info
CPU ABI info, e.g., arm64-v8a, can be useful to determine image
compatibility, prior to flash. Adding this info in fastbootd.

Bug: 74445765
Test: fastboot getvar cpu-abi # arm64-v8a
Change-Id: Ied494b646c551320295956b7890c0102fdb88382
2019-11-13 17:22:22 +08:00
David Anderson
220ddb1f0f fastbootd: Disallow certain operations during snapshot updates.
When a snapshot is applied or is merging, requests to erase or flash
userdata, metadata, or misc must be protected. In addition, the
set_active command must be restricted when a merge is in progress.

In addition, introduce a "snapshot-update merge" command for assisting
with erase requests when a merge is in progress. As in recovery, this
will force a merge to complete.

Bug: 139154945
Test: apply update
      fastboot erase userdata
      fastboot erase metadata
      fastboot erase misc
      fastboot set_active

Change-Id: I152446464335c62c39ffb4cc6366be9de19eac30
2019-11-10 23:07:13 -08:00
David Anderson
c399ccb345 Merge "fastboot: Implement helper commands for Virtual A/B." 2019-10-31 01:11:49 +00:00
David Anderson
ab8f466107 fastboot: Implement helper commands for Virtual A/B.
This introduces two new commands to the fastboot protocol:

  - getvar snapshot-update-status - Return "none", "snapshotted", or
    "merging" depending on the current status set by the boot control
    HAL.
  - snapshot-update [cancel] - Cancel any pending snapshot-based updates
    via the boot control HAL. After this, the HAL should return
    MergeStatus::CANCELLED and "update-merge-status" should be "none".
    If no argument is specified, the snapshot-update-status is returned
    via an INFO response.

Bootloaders are expected to implement this in a manner consistent with
the boot control HAL.

Fastboot-based tooling should expect wipes of userdata to fail when
update-merge-status returns "merging". Thus, the force flag now cancel
any pending snapshots.

Bug: 139154945
Test: fastboot getvar snapshot-update-status
      fastboot snapshot-update cancel
      fastboot snapshot-update

Change-Id: Idc423fe7656b212e929e64eb0e6b85b453e0e8dc
2019-10-31 01:11:16 +00:00
David Anderson
376f04e047 Merge "avoid data overflow in low memory device" 2019-10-23 23:15:06 +00:00
JeiFeng Lee
ba117304ab avoid data overflow in low memory device
Bug: 142294642
Test: fastboot flash system system.img
Change-Id: Iec50817aaca5d31c194f0fdf409503829d14ca06
2019-10-23 13:20:41 +08:00
Yifan Hong
0e13bbade3 fastbootd: skip COW group
Skip importing COW group because they are dynamically
created by OTA clients and will never show up in built
images.
Test: flash

Change-Id: I44e7693cfb4c15e64455b56212a02f9abde88d61
2019-09-11 18:32:57 -07:00
David Anderson
ad970fc055 fastbootd: Cancel snapshots when modifying partitions.
When flashing or resizing partitions, remove the
LP_PARTITION_ATTR_UPDATED flag. This will cause first-stage init to skip
any snapshots for that partition, and the backing storage (if any)
will later be reclaimed.

Bug: 139155473
Test: manual test
Change-Id: I3b185f68dfecb5a93636af0b5ae289ead1363fd0
2019-08-27 14:03:44 -07:00
David Anderson
15aa9540df liblp: CreateLogicalPartition with a given mapped name
Introduce a parameter struct to eliminate parameter explosion, and refactor
existing callers to use the new helper.

Test: manual test
Bug: 135752105
Change-Id: I0c5ebe4e084ad7503c2ac6c65886a71505d50d00
2019-08-13 13:41:36 -07:00
David Anderson
470fe2b5f0 fs_mgr: Remove the timeout parameter to DestroyLogicalPartition.
This is no longer needed as CreateLogicalPartition() ensures the
obtained path will not race with device deletion.

Bug: 135771280
Test: device builds, flashes
Change-Id: I821290aa08fede99d5c51cd68681c351a1ea97bc
2019-07-11 15:39:53 -07:00
David Anderson
2747532f96 fastbootd: Don't include all of the fs_mgr namespace in commands.cpp.
Bug: N/A
Test: m fastbootd
Change-Id: Iea67a27a2d3637df5dfd55982bda1465b7ef7de8
2019-06-11 14:05:02 -07:00
David Anderson
196d2ba7b9 liblp: Add helpers for finding partitions and partition sizes.
These tend to get manually, so let's promote to actual helpers.

Bug: 134536978
Test: liblp_test gtest
Change-Id: Ifb79c8d6f247cc3f9635bf6adfd1c99907340002
2019-06-07 11:09:28 -07:00
chihhao.chen
8c544b6fd8 Fix non-aio USB read issue for fastbootd
non-aio USB read function was stuck in a loop waiting for more data
because data length parameter is always set 64 for fastbootd commands.
It should be a normal case to get less data than expected
since lengths of these commands are usually less than 64.
Add logic to check this and one more parameter to distinguish
fastbootd from general adbd case.

Bug: 133189029
Test: try various fastbootd commands
Change-Id: I6690324840d78f3f1e04235040301520329976db
Merged-In: I6690324840d78f3f1e04235040301520329976db
2019-05-29 23:10:50 +00:00
Hridya Valsaraju
d747dba9c0 fastbootd: reduce USB buffer size to 16K
Some USB controllers can only support transfers upto 16K.

Bug: 133208811
Test: fastboot flashall
Change-Id: Ic025bdd8e7a6cf2634fc24524fd189e0cc9efbb5
2019-05-21 13:08:52 -07:00
Hridya Valsaraju
8efadf70e1 Handle failed usb/reads and writes correctly
Currently if the device is unplugged from host,
there is a lot of log spamming since fastbootd
does not not recognize that the device has been
disconnected and keeps trying to read/write to the
device.

2856 printk messages dropped ** [  169.941904] c7    579 fastbootd: aio: got error event on
read total bufs 1: No such devie
** 2960 printk messages dropped ** [  169.953328] c7    579 fastbootd: Fastboot command:
** 2074 printk messages dropped ** [  169.961355] c7    579 fastbootd: aio: got error event
on read total bufs 1: No such devie

Bug: 121333158
Test: unplug device and check for log spam multiple times

Change-Id: I1d4c6f48f34e313c5ebce23d62a4fe6a6373f94f
2019-04-15 10:36:42 -07:00
David Anderson
3d782d57cc fastboot: Fix "fastboot gsi".
This command erroneously reports that no GSI is installed, because
/metadata is not mounted in recovery. To address this, temporarily mount
/metadata when the gsi command is invoked.

Bug: 122556707
Test: fastboot gsi disable
      fastboot gsi wipe

Change-Id: Ib21971b49b46fd580b902ff75f01cfb96192afc0
2019-01-29 13:20:36 -08:00
Tom Cherry
b688d917cd Remove the rest of users of the old style fstab
And deprecate one more old style function that is not used after this
change.

Test: boot, disable and enable verity
Change-Id: Id509f479850120352b4ea4dc3b6c40f6e8e2e53e
2019-01-28 12:34:33 -08:00
David Anderson
1d504e3342 fastbootd: Add command to remove GSI installs
Note: this only removes the bootable marker, since we're unable to
remove the userdata files within recovery.

Bug: 121210348
Test: fastboot gsi wipe
      fastboot gsi disable
Change-Id: I64fe848c787d426ae9d18a1557a9d6b340bfc2cf
2019-01-17 18:33:14 +00:00
David Anderson
a48f86b88e fastbootd: Better error message when boot_devices is missing.
Bug: 121333158
Test: N/A
Change-Id: Ifac7ae382d9e57864f6a3915987300eb91355293
2018-12-20 16:56:06 -08:00
Treehugger Robot
8fd4435d53 Merge "fastbootd: Only flash slots listed by the boot control HAL." 2018-12-18 03:56:48 +00:00
David Anderson
4d307b0975 fastbootd: Only flash slots listed by the boot control HAL.
Bug: N/A
Test: flash when metadata slot count is >2
Change-Id: I67481be0de162cab5da8d32c2e318489427f1932
Merged-In: I67481be0de162cab5da8d32c2e318489427f1932
(cherry picked from commit 8568dcb057)
2018-12-18 02:12:22 +00:00