Commit graph

1075 commits

Author SHA1 Message Date
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
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
Daniel Zheng
750fe6a37b Adding include to functional
adding include to functional since we use it in this file. Some users
are reporting build issues due to missing this include

Test: m fastboot
Change-Id: I9ba11bdaf7dcedf5f9ebfb6fa50013be50738f48
2023-07-28 11:00:16 -07:00
Daniel Zheng
cbda2c038b Adding flag to flash only static partitions
adding in --exclude-dynamic-partitions to flash only bootloader
partitions and skip the rest. Super optimization will be turned off as
well when this flag is enabled

Test: fastboot flashall --exclude-dynamic-partitions

Change-Id: I4b9d70b7f6179bf079991bf3a20aade64cfe9935
2023-07-24 13:54:49 -07:00
Daniel Zheng
f161ee2771 Merge "Adding documentation" into main 2023-07-19 00:20:59 +00:00
Daniel Zheng
658182b8e7 Adding documentation
adding --help documentation to fastboot for --disable-super-optimization
and --disable-fastboot-info

Test: fastboot -h
Change-Id: Ia8993b3894d302a63cc97796d66e0af3fb004eef
2023-07-18 15:36:26 -07:00
Treehugger Robot
1c77579a06 Merge "Look for radio.img and bootloader.img in ANDROID_PRODUCT_OUT" into main 2023-07-17 21:51:01 +00:00
Paul Lawrence
556c46bfb9 Look for radio.img and bootloader.img in ANDROID_PRODUCT_OUT
Test: fastboot flash bootloader and fastboot flash radio both work
Change-Id: I79674469c0df3dd592e5fcf840fef0dcc3f11d33
2023-07-17 14:05:21 -07:00
Daniel Zheng
6acfe9bcd0 Turning on fastboot-info
turning on fastboot-info by default again

Test: fastboot flashall
Change-Id: I6b8bb0d145af37d437419a5e6cee70158ed553ae
2023-07-11 12:53:30 -07:00
Daniel Zheng
63dfeaae7a Adding flag to disable fastboot_info
Adding flag to override fastboot_info for a quick fix in case
fastboot_info format is wrong

Test: fastboot flashall
Change-Id: I1f41646f14d747ce7ac7636ca9ced7279e13f7b0
2023-07-11 12:53:30 -07:00
Daniel Zheng
eabfe272c3 Fastboot-info testing
adding test to compare task list formed from fastboot-info vs list
formed from image list. To test, we need to set sparse_limit in flashing
plan and turn off update-super-optimization. The list of partitions to
be flashed by parsing fastboot-info should be a superset of the
partitions flashed by the hardcoded list. Changing is_retrofit_device()
to also take in a fastboot driver so we can pass in a mock

Test: fastboot_test
Bug: 194686221
Change-Id: Ib860c24c85779de1fbaa6bec8778e1f5ebb9475a
2023-07-11 12:53:29 -07:00
Daniel Zheng
59589d47db Asserting flashing plan is used in do_flash
Adding check to ensure flashing plan is used in do_flash. FlashingPlan
should never be null

Test: fastboot flashall -w
Change-Id: I8e69326c59b31c7b54d6d2e04c8ce5c0f12693a7
2023-07-11 12:44:13 -07:00
Daniel Zheng
a0d2401d23 Mocking get_uint_var()
Changing implementation to have mock fastboot driver return a the
sparse_limit rather than modifying the variable inside of flashing plan

Test: fastboot_test
Change-Id: I850ccd5bd09b6a8479ccc8cf7bf1d227abb87e3a
2023-07-11 12:44:13 -07:00
Daniel Zheng
c97eeed5e4 Adding parsing for fastboot-info
Adding back the parsing for fastboot info

Test: m fastboot, fastboot flashall
Change-Id: I0075266bad5d45dcb99dbf91aa431008ca336216
2023-07-05 13:17:39 -07:00
Daniel Zheng
3e04857a59 Changing name of flash super layout
OptimizedFlashSuper makes more sense and is more consistent with
should-optimize-super

Test: m fastboot
Change-Id: I6ceb31144dce591e0a53faec68b932112d9cd360
2023-06-27 10:19:58 -07:00
Daniel Zheng
ba07ef5732 Change HardcodedFlash to add flashtasks
Changing Hardcoded FLash to add flash tasks, also modifying do_flash to
download signature data if a source is provided

Test: fastboot flashall
Change-Id: Ic33bc4076f269d0d48146a3de457a72eedd5e6df
2023-06-22 09:52:08 -07:00
Daniel Zheng
5769b268bf use FlashingPlan sparse_limit for testing
Have get_sparse_limit() return FlashingPlan's sparse limit if set. Used
for testing to compare task lists

Test: fastboot_test
Change-Id: I7ac1eb4dc83a53b3d7aa59aa668a780b4b550664
2023-06-22 09:52:06 -07:00
Daniel Zheng
d62002cf06 Add flag to disable super optimization
Adding flag to turn off the super optimization. Makes for easier testing
as dynamic partitions flash tasks won't be replaced by one flash super
layout task

Test: fastboot flashall --disable-super-optimization
Bug: 194686221
Change-Id: I9142490ecfe587725872e4b734486d3db1728aa7
2023-06-22 09:49:09 -07:00
Daniel Zheng
59c22c33a0 Removing local image lookup from load_buf
The initial logic for adding this in was incorrect. This changed had
allowed us to do fastboot flash dts dt.img on command line. But really
we should enforce that we pass in the path to the image. This change was
added so the command line tool with resemble fastboot-info format which
will support flash dts dt.img (situation where image name and partition
name don't match).

Test: fastboot flash {partition}, fastboot flashall
Bug: 194686221
Change-Id: I62f170e14860d865453ab52793e346fe4066c6d4
2023-06-22 09:49:09 -07:00
Daniel Zheng
7f8fff0360 Moving source class declaration
Moving zipImageSource and localImageSource to header file to be used for
testing purposes

Test: m fastboot
Bug: 194686221
Change-Id: I689e73eb0102d3b2cdd0c4fc232b2b60b9022c47
2023-06-21 14:23:56 -07:00
Roy Luo
d1d5f5ab69 fastboot: remove retries on invalid IO iterator in OSX
When IOServiceGetMatchingServices returns an invalid
iterator, IOIteratorReset doesn't help. Break the loop
to prevent being stuck in the reset loop forever.
This should be fine as the open_device() call in the
upper layer is already doing retries.

Bug: 286495045
Test: fastboot update
Change-Id: Ia58fa9285640be34aa22cd77e4f58cc9092679a4
2023-06-20 21:44:53 +00:00
Treehugger Robot
18c531984c Merge "Removing duplicate CollectImages()" 2023-06-13 23:18:50 +00:00
Daniel Zheng
3dc7fcc0b6 Removing duplicate CollectImages()
images are being flashed twice, because of an additional collectImages.
This is resulting in a ~50% increase in flashing time

Test: fastboot flashall -w
Change-Id: I6c271e1e1456cd789f37ebd67cefd221cabc6e7a
2023-06-13 14:57:25 -07:00
David Anderson
1347d3407e Merge "fastboot: Include header for ostream_iterator and istream_iterator" 2023-06-12 22:26:44 +00:00
Treehugger Robot
929a665f02 Merge "fastboot: Introduce FASTBOOT_DEVICE alias for ANDROID_SERIAL environment variable" 2023-06-12 22:01:54 +00:00
Biswapriyo Nath
816480b56e fastboot: Include header for ostream_iterator and istream_iterator
This fixes the following compiler errors with gcc

storage.cpp:45:20: error: 'ostream_iterator' is not a member of 'std'
storage.cpp:50:10: error: 'istream_iterator' is not a member of 'std'

Change-Id: I570e332d100bb18e445644a9d57dc14d80f104b5
2023-06-13 00:28:24 +05:30
Biswapriyo Nath
214f37c249 fastboot: Add header that declares std::function
This fixes the following compiler error with gcc
fastboot_driver.h:51:10: error: ‘function’ in namespace ‘std’ does not name a template type

Change-Id: I3a4d9b48bfdc2c76e443e2efe1761ec9503c6dc5
2023-06-10 20:08:29 +05:30
John Stultz
9d2fb9ca3c fastboot: Introduce FASTBOOT_DEVICE alias for ANDROID_SERIAL environment variable
The ANDROID_SERIAL env is useful for managing multiple
directly connected devices at one time.

Unfortunately for network connected devices, its harder to use.

This is because both adb and fastboot use the same ANDROID_SERIAL
environment value to identify the device to use, and while that
one value works for directly connected devices, when using
network connected devices, the fastboot and adb port numbers may
differ for the same device.

So if I set: `ANDROID_SERIAL="tcp:127.0.0.1:44403"`
fastboot will work, but when I type `adb shell`, I'll get:
 adb: device 'tcp:127.0.0.1:44403' not found

As `adb devices` outputs:
List of devices attached
localhost:36697 device

To resolve this, we need separate environment variables,
so introduce a FASTBOOT_DEVICE variable for fastboot.

If FASTBOOT_DEVICE is set, it will use that, and if not
it will fall back to the ANDROID_SERIAL if it is set.

Using an explicit -s argument will still override both.

Change-Id: Icd7db6f29e51ed2decd219e35537f6ed98d698b8
Signed-off-by: John Stultz <jstultz@google.com>
2023-06-09 22:54:09 +00:00