Commit graph

92 commits

Author SHA1 Message Date
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
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
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
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
720007ba43 Merge "Adding flag to flash only static partitions" into main 2023-08-09 18:09:00 +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
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
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
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
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
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
Daniel Zheng
997ce15d5e Update add resizetasks to work in update
Old should_flash_in_userspace doesn't work if $ANDROID_PRODUCT_OUT is
not set. Also adding in a check to see if resizetasks were added
correctly

Test: fastboot update update.zip without $ANDROID_PRODUCT_OUT and
removing the flashsuperlayout code.
Bug: 283330320

Change-Id: Ib72f6a1cf07745daf70fffae3d1a6b8352e3f79c
2023-05-30 09:24:46 -07:00
Daniel Zheng
791a83bb45 Chang flash task to take in source
Old changes didn't actually take into account sources. fastboot update
{update.zip} should read fastboot-info from the update package. It was
instead flashing local images + reading local fastboot-info.txt

Test: m fastboot, fastboot update, fastboot flashall
Bug: 283330320

Change-Id: I9587a7735ddfbfb661153eb12ebc3caa7c32f141
2023-05-25 13:29:16 -07:00
Daniel Zheng
630f29e0db Updating fastboot-info version check
Updating version to just be a single number.  Reason for updating is
to keep format the same as Flashstation's

Test: fastboot_test
Bug: 194686221
Change-Id: I21ab0747e620d3f6d05c5170c3e55707eed0288a
2023-05-01 14:04:12 -07:00
Daniel Zheng
68b84df994 Added test for version check
Test: fastboot_test
Bug: 194686221
Change-Id: I886c0a91be3b4f4bf7f2b8c76704aa30a352ee5b
2023-04-19 12:30:38 -07:00
Daniel Zheng
efca333730 Added forward declaration for compilation
Test: tested compilation
Change-Id: I7165e323574ef8f3f90d1540c4a2b6a991803b40
2023-04-19 12:30:38 -07:00
Daniel Zheng
bf09c61d95 Pointed FlashingPlan to Interface
Using interface for testing purposes

Bug: 194686221
Test: tested compilation
Change-Id: Ia9465c1f5673c249cdbc08a1a2432e8a603bd9cc
2023-04-19 12:30:38 -07:00
Daniel Zheng
c9e869bd9e Adding fastboot_driver interface + mock
Adding mock fastboot_driver to be used for testing

Test: tested fastboot_test
Bug: 194686221
Change-Id: I6948310d44b75c0f389cbfd194747649aaccb0b8
2023-04-19 12:30:38 -07:00
Daniel Zheng
65eb246aa2 Moving FlashallTool Definition
moved flashalltool definition to header file

Test: flashall on raven
Bug: 194686221
Change-Id: I5f726492ee5b3ae42755214e3de0269257b62ba8
2023-04-19 12:30:38 -07:00
Daniel Zheng
29a211c194 Changing flashall to parse fastboot-info.txt
Test: tested on Raven
Change-Id: I9f26bf6025a0a6318f84be929091f4e82bd87556
2023-04-19 12:30:37 -07:00
Daniel Zheng
1e6456b011 Cleaned up slot logic
Updating old clean up slot logic change. Some devices don't know current
slot so we can't always just call get_current_slot()

Test: tested flashall on raven
Change-Id: Id655f1c1ee0b1ff09331f0d91d77412836d0af8d
2023-04-10 09:35:48 -07:00
Kelvin Zhang
2a4a45f3e4 Revert "Cleaned up some slot logic"
This reverts commit bd85a18d0b.

Reason for revert: b/276759363

Change-Id: I3ba08cf4abeeb7769569512d50e7ff135438cf20
2023-04-03 20:44:05 +00:00
Daniel Zheng
bd85a18d0b Cleaned up some slot logic
Doesn't look like we actually need current_slot, since we can always
just call function get_current_slot

Test: tested flashall on raven
Change-Id: Icba64bc9fdd08f36d44965e32558a73d0beab0e1
2023-03-30 18:21:28 +00:00
Daniel Zheng
403657d998 Changing FlashTask to take in apply_vbmeta
Test: tested on Raven
Change-Id: I709842d87aa4ad6a7772e4f441886d127c3028a7
2023-03-13 18:28:14 +00:00
Daniel Zheng
15e7783263 Added support for Wipe Task
Test: tested wipe on Raven
Bug: 194686221
Change-Id: I582800a279cbe8a3e733a1e75447e5b5142d4120
2023-03-13 17:37:31 +00:00
Daniel Zheng
47d70a5559 Added support for FlashSuperLayoutTask
Test: testing flashall code with this change
Bug: 194686221
Change-Id: Ibb96980402db51b48c9a296338f29195f68c65bf
2023-03-08 23:07:48 +00:00
Dmitrii Merkurev
48b39ba01e Merge "fastboot: Introduce ParseNetworkSerial unit tests" 2023-03-03 18:52:33 +00:00
Daniel Zheng
7df2ab9c87 Added Flashing Plan
Fastboot has a lot of flags that are used by many different functions
including the Flashall Class and newly added FlashSuperTask. Passing all
of these flags as paramaters is cumbersome, so adding a Flashing Plan
that contains these flags simplifies the code.

Test: tested Flashall and update img.zip on raven
Change-Id: I9c842f25389a20b852d55f684e1b86040af1d86a
Bug: 194686221
2023-03-03 06:49:32 +00:00
Dmitrii Merkurev
cdbfa7a3e8 fastboot: Introduce ParseNetworkSerial unit tests
Introduced positive and negative unit tests to cover
ParseNetworkSerial logic. Alongside with that move
result related stuff to the separate header.

Test: atest fastboot_test
Test: manually checked basic functionality works fine
Bug: 271155012
Change-Id: Icac6053c11b5a36daa64555209555826ea28cc61
Signed-off-by: Dmitrii Merkurev <dimorinny@google.com>
2023-03-02 00:03:49 +00:00
Daniel Zheng
0d30718d9c Added support for flash task
Added Flash Task

Test: tested on raven
Change-Id: I4a6c22f795440afeba18497745dddf8d5c570f65
Bug: 194686221

changed flash {partition_name} to work with tasks

Test: tested flash {partition_name} on raven
Change-Id: I1fa45b949ad8e5017026dd542dfe1389279a9e64
Bug: 194686221
2023-02-13 23:27:41 +00:00
Daniel Zheng
1a01a1cda1 Created new Task.h file to contain task classes.
Test: tested Reboot {target} + Flash {partition} on raven device
Bug: 194686221
Change-Id: I0d80230d682f80af12cca9705df0172651bf4461
2023-02-06 23:58:13 +00:00
Jaegeuk Kim
638d05e84e fastboot: add casefold/projid/compress options
fastboot -w --fs-options=casefold
fastboot -w --fs-options=casefold,projid
fastboot format:f2fs --fs-options=casefold
fastboot format:f2fs --fs-options=casefold,projid
fastboot format:f2fs --fs-options=casefold,projid,compress

Bug: 172514669
Bug: 160198145
Signed-off-by: Jaegeuk Kim <jaegeuk@google.com>
Change-Id: If3fad004fdd25dd754432ce98934b4ae6c8a8706
2020-11-09 10:04:30 -08:00
Tom Cherry
9027af0d40 fastboot: remove engine.cpp/engine.h
Replace the remnants of engine.cpp with better functionality in
FastBootDriver.  Particularly, add prolog() and epilog()
callbacks to FastBootDriver for printing actions and their result to
the console.  Then clean up the rest of fastboot.cpp to directly use
FastBootDriver.

Test: fastboot works
Change-Id: I0ff01d6a10f75e9dc1c82b46c6e9bb3bc4c68638
2018-09-25 14:32:56 -07:00
Aaron Wisner
db511207ed Refactor libfastboot
This change creates a nice and clean API for issuing
fastboot commands without using the fastboot tool itself.

Test: fastboot tool itself (now using libfastboot2)
on sailfish, walleye, and other devices.
Test: flash bootloader bootloader.img
Test: flash radio radio.img
Test: -w update img.zip
Test: Manually getvar and reboot commands.

Bug: 111126621
Change-Id: I0022536b204ce0c5ad8329367fd522fa3c57877d
2018-07-19 15:16:47 -05:00
Jerry Zhang
769a9c1d11 fastboot: Refactor string constants to constants.h
This allows them to be shared between host and device
implementations.

Test: fastboot works
Bug: 78793464
Change-Id: I79271687850ade2a904fd03d6a97dad1a9ab8e1c
2018-07-16 14:18:41 -07:00
Elliott Hughes
d8a4c60276 Simplify __attribute__((__printf__)) use.
We don't need this now everyone's using clang...

Bug: http://b/69933068
Test: ran tests
Change-Id: I88f0cf03981ade47e210387fd6f3a2706dfeb9b8
2018-06-26 13:07:21 -07:00
Pirama Arumuga Nainar
a2df1ef441 Do not customize __format__ for Windows/MinGW to gnu_printf
Bug: http://b/69933090
Bug: http://b/69933068

MinGW uses gnu_printf to force C99 printf analysis with GCC, but clang
does not support gnu_printf.  So just use the default that's used for
other platforms.  This also mirrors upstream commit
015e637b4b/.

Test: m native-host-cross with Clang.
Change-Id: I3deb266d70e25296c4ae1d58637afbabc3d949c1
2018-06-25 11:52:54 -07:00
Elliott Hughes
6ebec932d6 Add fastboot_test.cpp and test --os-version/--os-patch-level parsing.
Also switch all remaining headers over to #pragma once, and actually
use FB_COMMAND_SZ.

Bug: http://b/77340848
Test: ran tests
Change-Id: I27107d054c206e66c39208099e36a55df604e08f
2018-04-10 14:24:02 -07:00
Elliott Hughes
11ff345979 Minimal changes to build fastboot as a library.
Bug: http://b/77809061
Test: builds
Change-Id: I0c388334d643a0a2abf0c03a29f336dc3af2f83f
2018-04-09 20:40:45 -07:00
Elliott Hughes
855cdf82f5 Improve fastboot verbose output.
Move some verbose messages so they're only output with -v.

Remove some misleading verbose messages altogether (such as "wiping
userdata...").

Properly log all the commands sent and responses received. Example:

  $ fastboot -v flashall
  ...
  Sending sparse 'system' 2/2 (443712 KB)
  fastboot: verbose: sending command "download:1b1500d0"
  fastboot: verbose: received DATA 1b1500d0
  fastboot: verbose: sending data (1024 bytes)
  fastboot: verbose: sending data (165596160 bytes)
  fastboot: verbose: sending data (1024 bytes)
  fastboot: verbose: sending data (267762688 bytes)
  fastboot: verbose: sending data (1024 bytes)
  fastboot: verbose: sending data (20978688 bytes)
  fastboot: verbose: sending data (1024 bytes)
  fastboot: verbose: sending data (7168 bytes)
  fastboot: verbose: sending data (1024 bytes)
  fastboot: verbose: sending data (3072 bytes)
  fastboot: verbose: sending data (1024 bytes)
  fastboot: verbose: sending data (3072 bytes)
  fastboot: verbose: sending data (1024 bytes)
  fastboot: verbose: sending data (3072 bytes)
  fastboot: verbose: sending data (208 bytes)
  fastboot: verbose: received OKAY
  OKAY [ 13.871s]
  Writing sparse 'system' 2/2
  fastboot: verbose: sending command "flash:system"
  fastboot: verbose: received OKAY
  OKAY [  3.228s]
  Rebooting
  fastboot: verbose: sending command "reboot"
  fastboot: verbose: received OKAY

  Finished. Total time: 36.939s

Bug: http://b/30953083
Bug: http://b/74444116
Test: `fastboot -v flashall`
Change-Id: I2cca198daa062fd1fb732218343263803b111e38
2018-04-02 14:28:18 -07:00
Elliott Hughes
5620d224b6 Add "require partition-exists=" support.
The Pixel 2 system images release was a bit of a disaster because anyone
using an old version of fastboot would blindly flash too few partitions,
potentially bricking their device. This change lets us add a line to
the android-info.txt file for a device with a new partition.

Also error out sooner in such cases by checking the requirements
immediately, rather than optimistically unpacking everything first.

Switch Action over to C++ to fix memory issues.

Bug: http://b/77158188 (partition checking)
Bug: http://b/74444116 (error out sooner)
Test: manual testing with a modified android-info.txt
Change-Id: I58b426cad410107e368f35f5725216d07281dd97
2018-03-28 12:43:53 -07:00
Elliott Hughes
3d7fa22164 Add __attribute__((__format__)) to fastboot's die().
Also make the <android-base/stringprintf.h> macro less likely to collide.

Bug: N/A
Test: builds
Change-Id: I868a0a0002c9c53c1ec0670153df2af5f48fd969
2018-01-09 11:18:10 -08:00
Elliott Hughes
d6365a7052 Make fastboot command-line parsing a bit more like adb.
Only show all the help if asked to, and have a few more descriptive
syntax errors.

Also show the help on stdout rather than stderr.

Bug: N/A
Test: manually ran "fastboot flash"/"fastboot update"/"fastboot flashall"
Change-Id: I59abd60e58a56fe7e44da5116a702087c36e14ce
2017-05-09 08:16:23 -07:00
Jocelyn Bohr
91fefadc2e fastboot: Add 'get_staged' command
(cherry-picked from internal nyc-iot-dev to AOSP)

New user-level command usage:

 * fastboot get_staged <outfile>
   Reads staged data from the last command handled by the device. If the
   last command did not result in staged data, this command will fail.

This enables data staged by OEM commands to be transferred from device
to host. get_staged wraps new device command "upload". Fastboot
clients are not required to support "upload", so get_staged won't
work on all devices.

Bug: 36002804
Test: Implemented "upload" in fastboot on imx6ul. Verified that uploading
      ~100K data from the device works.
Change-Id: I5b1a1ce023f362062505ee62746ea8ab6f36bfbf
(cherry-picked from commit 83a875de994bf48f0faa2a8a23ceb0b8f52b6b04)
2017-04-27 16:47:51 -07:00
Jocelyn Bohr
98cc283168 fastboot: Add 'stage' command
(cherry-picked from internal nyc-iot-dev to AOSP)

New user-level command usage:

 * fastboot stage <infile>
   Sends the contents of <infile> to the device to stage for use in the
   next command.

This enables OEM commands to use data downloaded from host to device.

Bug: 35811075
Test: Manual test on imx6ul
Change-Id: I483a18f9f4205d3289ee524656b9d741b16e9fe6
(cherry-picked from commit 001c75c6c0fe6a70a1db2a65253ab3c43ec17d46)
2017-04-26 11:08:41 -07:00