Commit graph

19 commits

Author SHA1 Message Date
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
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
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
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
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
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
David Anderson
d25f1c3775 fastbootd: Support two super partitions for retrofit devices.
Retrofit devices will have two super partitions, spanning the A and B
slots separately. By design an OTA will never cause "A" or "B"
partitions to be assigned to the wrong super. However, the same is not
true of fastbootd, where it is possible to flash the inactive slot. We
do not want, for example, logical "system_a" flashing to super_b.

When interacting with partitions, fastbootd now extracts the slot suffix
from a GetSuperSlotSuffix() helper. On retrofit devices, if the partition
name has a slot, that slot will override FastbootDevice::GetCurrentSlot.
This forces partitions in the inactive slot to be assigned to the correct
super.

There are two consequences of this. First, partitions with no slot
suffix will default to the current slot. That means it is possible to
wind up with two "scratch" partitions, if "adb remount" is used on both
the "A" and "B" slots. However, only the active slot's "scratch" will be
visible to the user (either through adb or fastboot).

Second, if one slot does not have dynamic partitions, flashing will
default to fixed partitions. For example, if the A slot is logical and B
is not, flashing "system_a" will be logical and "system_b" will be
fixed. This works no matter which slot is active. We do not try to
upgrade the inactive slot to dynamic partitions.

Bug: 116802789
Test: fastboot set_active a
      fastboot flashall # dynamic partitions
      fastboot getvar is-logical:system_a # true
      fastboot getvar is-logical:system_b # false
      fastboot set_active b
      fastboot flashall --skip-secondary
      fastboot getvar is-logical:system_a # true
      fastboot getvar is-logical:system_b # true
      Booting both slots works.

Change-Id: Ib3c91944aaee1a96b2f5ad69c90e215bd6c5a2e8
2018-11-20 13:47:01 -08:00
Hridya Valsaraju
bb12c5e45b Check return status of ReadFileToString() in GetDeviceLockStatus()
Return lock status of true if unable to read kernel command line.

Test: fastboot getvar unlocked
Bug: 117275849
Change-Id: Id6c00c769bcdcdf87fcc9e88902713a8eff3e320
2018-10-08 19:21:12 +00:00
Hridya Valsaraju
99f3772cb2 Validate partition name when searching for physical partitions.
Bug: 117274137
Test: fastboot getvar has-slot:../by-name/system
Change-Id: Ibc74a12f836a30bdf1fd7f6b2a1e941de2430c70
2018-10-08 11:59:07 -07:00
David Anderson
5cbd2e43ee Don't hardcode the super partition name.
If a device has logical partitions but does not use a partition called
"super", we will need this to be configurable. Note that the "slot"
argument is currently unused, but will be necessary for update_engine if
there are A and B super partitions.

Bug: 116608795
Test: super partition works
Change-Id: Ieb548a158faeb423f3561230f26d582325efbc6b
2018-10-01 14:13:22 -07:00
Hridya Valsaraju
dca328d55c Support 'fastboot getvar unlocked' command.
Test: fastboot getvar unlocked.
Bug: 78793464

Change-Id: Ie59c6db90a503e9a6e9ac1c416e4ee5deac60479
2018-09-25 16:25:46 -07:00
David Anderson
c8ac4e7644 fastbootd: Wait for /dev/block paths when opening logical partitions.
Note that in addition to waiting for the path to appear, we must also
wait for it to be unlinked. Otherwise, we could accidentally access an
older device when opening and closing the same partition twice in a row.

Bug: 114198005
Test: fastboot flashall works
Change-Id: Iddffc34e1ac8aa066c28e7b1a92b09b6dfd7945c
2018-09-06 17:38:06 -07:00
Hridya Valsaraju
3ffed21262 Remove request for read access to partitions.
It is not needed for flash or erase.

Bug: 113648914
Test: fastboot flashall
Change-Id: I34ba57ac809934556569e3b38ab594969860882a
2018-09-05 12:11:13 -07:00
David Anderson
0f6266305e fastbootd: Implement getvar all.
This implements getvar all by invoking each callback and writing an INFO
status for each result. For commands that take arguments, the variable
handler can specify a function that returns all possible arguments.
Currently this only applies to partition variables.

Bug: 78793464
Test: fastboot getvar all works
Change-Id: I1cf84e06bf67614b6f56171c0ee6ca5d7ac383c9
2018-08-31 18:39:28 -07:00
David Anderson
88ef0b1f25 fastbootd: Add support for flashing logical partitions.
When flashing logical partitions, we read the "super" partition metadata
corresponding to the current slot. We then temporarily create a
device-mapper device for that partition, and immediately destroy the
device after all operations are complete. We do not mount partitions
ahead of time, or keep them mounted, because a fastboot operation may
change the layout of the logical partition table (or change which slot
is current).

Bug: 78793464
Test: fastboot flash a logical partition under "super"
Change-Id: Id2a61d3592decabeebfd283c4fd6e6cbe576a18c
2018-08-09 11:15:23 -07:00
David Anderson
12211d163e fastbootd: Enable erase and flash commands for physical partitions.
Bug: 78793464
Test: adb reboot fastboot && fastboot flashall

Change-Id: Ibe802c36f6efe20111a2315616ef34d3a027950f
2018-08-09 09:58:37 -07:00
Hridya Valsaraju
31d2c26409 fastbootd: Implement the getvar command.
This implements basic "fastboot getvar" support, including commands supported
by IBootControl.

Bug: 78793464
Test: fastboot getvar <fastboot variable>

Change-Id: Iee1a7b3f43dea46f80dcdf73c45034e2ffe4727d
2018-08-08 11:41:53 -07:00