Commit graph

1099 commits

Author SHA1 Message Date
Daniel Zheng
233a5a162d Merge "Added forward declaration for compilation" 2023-04-19 21:13:35 +00:00
Daniel Zheng
7d67d569f3 Merge "Pointed FlashingPlan to Interface" 2023-04-19 21:13:25 +00:00
Daniel Zheng
3ac1e55e1e Merge "Adding fastboot_driver interface + mock" 2023-04-19 21:12:59 +00:00
Daniel Zheng
39b1de953f Merge "Moving FlashallTool Definition" 2023-04-19 21:12:37 +00:00
Daniel Zheng
b7d14facd2 Merge "Changing flashall to parse fastboot-info.txt" 2023-04-19 21:12:29 +00: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
76aa257850 Adding Test for Parsing Flash Task
Test: fastboot_test
Bug: 194686221
Change-Id: Ie15b2d0423366fb9d1debb9be52de3b6d3a891af
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
37673f0bf5 Merge "Fixing circular dependency" 2023-04-19 00:16:13 +00:00
Daniel Zheng
729c159744 Merge "Moving logging include" 2023-04-18 16:26:01 +00:00
Daniel Zheng
0897526557 Fixing circular dependency
Test: tested compilation
Change-Id: Iae25cade1efb2372e5fc219fa69cbb2381b4e05c
2023-04-17 11:34:00 -07:00
Daniel Zheng
7627b54910 Moving logging include
Header file shouldn't have include of logging

Test: tested compilation
Change-Id: I02cccb66b6ee5811e5d4f2b9b72508fee640e828
2023-04-17 09:42:39 -07:00
Daniel Zheng
0a785083bb Merge "Cleaning up main code" 2023-04-13 20:44:31 +00:00
Daniel Zheng
83800601f6 Merge "Adding const to task constructors" 2023-04-10 19:44:31 +00:00
Daniel Zheng
23631b9be7 Merge "Cleaned up slot logic" 2023-04-10 18:02:05 +00:00
Daniel Zheng
dddb5fa80b Merge "Correcting Reboot Task Functionality" 2023-04-10 17:46:03 +00:00
Daniel Zheng
e6dbd4f194 Adding const to task constructors
Adding const decorator to class constructor to ensure Flashing Plan
isn't modified during task construction

Bug: 194686221
Test: tested Flashall on raven
Change-Id: I99b71b2b756beaf871a31a1a035545d754d128e8
2023-04-10 09:53:08 -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
Treehugger Robot
b2fdbef489 Merge "Revert "Cleaned up some slot logic"" 2023-04-03 21:49:25 +00: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
b16aba889a Merge "Cleaned up some slot logic" 2023-03-30 21:49:15 +00:00
Daniel Zheng
719caca725 Merge "Added some error logs to wipe" 2023-03-30 21:30:11 +00:00
Daniel Zheng
76c9343339 Cleaning up main code
cleaning up main() code in fastboot.cpp to run off one task vector. The
eventual goal is to just have all functionality run off this vector.

Test: tested commands on raven
Bug: 194686221
Change-Id: I98d0ba33091eff31ff1bc338766c3689ffb54746
2023-03-30 18:35:14 +00:00
Daniel Zheng
1418fb8ce0 Correcting Reboot Task Functionality
Modifying fastboot-info.txt to directly call reboot fastboot instead of
reboot userspace -> so no longer need "userspace" in reboot task. Also
moving skip_reboot check to task since in old code we can have
skip_reboot be true and still reboot to bootloader, fastboot, or
recovery

Test: tested reboot commands on Raven
Change-Id: I98ba51747bf7229a88ba737540c81d20b42e5981
2023-03-30 18:35:14 +00:00
Daniel Zheng
4aa47338f2 Merge "Added check to copy AVB footer" 2023-03-30 18:24:31 +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
6f213b2c79 Added some error logs to wipe
Changed so if we call wipe on a partition that doesn't exist we'll get
some helpful error messages.

Test: tested wipe test
Bug: 194686221
Change-Id: I19dc0396a7a98d0b2be7859edbffeb8acdc9850a
2023-03-30 18:19:04 +00:00
Daniel Zheng
e33e8a8685 Added check to copy AVB footer
is_logical shouldn't work in bootloader for some devices, so we also need to check
using should_flash_in_userspace to see if partition is dynamic

Test: tested to flash {partition} on raven and checked to see avb
footers are not copied from dynamic partitions

Change-Id: Iabb3ea535fa80b26cf1c08040beb3d4ea5e8c2ae
2023-03-30 18:19:04 +00:00
Ayushi Khopkar
33ff88f9c3 Updated fuzz_config in Android.bp file
Added new fields in fuzz_config like - hotlists,
description, vector, service_privilege, users, fuzzed_code_usage, etc.

Bug: 271384401
Test: Build fastboot_fuzzer

Change-Id: I7799ffcb7f11202711b19cf40e8c05e050d3b519
2023-03-23 16:06:24 +05:30
David Anderson
ecdbbbda82 Merge changes Ie68aed2f,Ic40696b3
* changes:
  fastboot: Handle libsparse failures better.
  libsparse: Fix allocation failures on 32-bit systems.
2023-03-22 00:02:13 +00:00
David Anderson
74c7807af1 fastboot: Handle libsparse failures better.
sparse_file_len is not actually infallible; on Windows it's pretty easy
to make it fail by embedding large files in the stream. fastboot didn't
handle this anywhere, leading to bad sparse images when libsparse
runs out of address space.

Bug: 273933042
Bug: 268872725
Test: fastboot flashall on Windows
Change-Id: Ie68aed2f1970e820350d9f97aa89a6c0242229b8
2023-03-20 15:55:57 -07:00
Daniel Zheng
0bf3b71fbb Updating Flashall to work off tasks
Test: testing fastboot flashall on raven
Bug: 194686221
Change-Id: I82ac2392686775b57c3d98ea003ab30b48f1ab0f
2023-03-20 20:21:31 +00:00
Daniel Zheng
85c0f3e567 Updated location of initialization
Test: tested flashall on raven
Bug: 194686221
Change-Id: Ie0dd7acd65833a938623e374e2b21e6bd6079d08
2023-03-20 20:21:31 +00:00
Daniel Zheng
f1ddba9dfd Updating FlashTask to require img-name
Test: tested flash {partition} on pixel
Bug: 194686221
Change-Id: I8018e48f68606ec9c559d06973154d79e7c0634a
2023-03-20 20:20:43 +00:00
Daniel Zheng
980985af6e Removed hardcoded check to copy AVB Footer
Test: tested flashall on raven
Bug: 194686221
Change-Id: Iaca03bde51fcd6b2886dc8ba84da4f67174a9c3f
2023-03-20 16:24:40 +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
43987c948b Fixed parameter styling and minor error in tasks
Test: tested compilation
Change-Id: Ieb949243da1284dec3bad2caa895a59465858adc
2023-03-08 23:07:51 +00:00
Daniel Zheng
aa70f4c748 Added support for Delete Task
Test: tested delete-logical-partition {partition} and flashall on Raven

Change-Id: I04f07c8132159deda42434b9178e8c98d5ab768b
Bug: 194686221
2023-03-08 23:07:51 +00:00
Daniel Zheng
9f7bf7eff3 Added support for Resize Task
Test: tested flashall on raven
Bug: 194686221
Change-Id: I60586756b2d5f99848a664def8204c0bd47d7e67
2023-03-08 23:07:50 +00:00
Daniel Zheng
6bb8baa929 Added support for Update Super Task
Test: tested flashall on raven
Bug: 194686221
Change-Id: Ifc99af77f9235bf56a549f53e7d43575686fb42b
2023-03-08 23:07:50 +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
78a0f7f1b2 Merge "Changed FlashTask and RebootTask to take in FlashingPlan" 2023-03-03 07:43:03 +00:00
Daniel Zheng
f8da682c84 Merge "Added Flashing Plan" 2023-03-03 07:42:55 +00:00
Daniel Zheng
bc01da5c0d Changed FlashTask and RebootTask to take in FlashingPlan
Test: tested flash {partition} on raven and reboot {target} on raven
Change-Id: I26f4723474c3a142b086c1ac361578f8487ec3b9
Bug: 194686221
2023-03-03 06:49:34 +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
Dmitrii Merkurev
95c90c6588 fastboot: Fix fastboot_vendor_boot_img_utils_test mac os compilation
Use more universal lseek instead of lseek64

Test: atest fastboot_vendor_boot_img_utils_test
Test: mm on mac os
Bug: 271152365
Change-Id: I4d094dd2c24e4ffec8ea7fe2f3b355122fd8cd19
Signed-off-by: Dmitrii Merkurev <dimorinny@google.com>
2023-03-01 15:49:56 +00:00
Treehugger Robot
396b107a41 Merge "fastboot: Fix IPv6 connect and -s host parsing" 2023-02-28 22:46:02 +00:00
Dmitrii Merkurev
4785554ca1 fastboot: Fix IPv6 connect and -s host parsing
During fastboot connect / disconnect introduction, we
completely broke the IPv6 support (it was considering
all IPv6 addresses as a USB serial).

Makeing sure this problem isn't reproducible anymore
alongside with fixing EXCPECT causing process crash
and improve network serial error detection.

Bug: 271152365
Change-Id: Ic52aa5fff1948a64ac3d2672f3cf4d2b022e5cea
Signed-off-by: Dmitrii Merkurev <dimorinny@google.com>
2023-02-28 21:02:48 +00:00
Daniel Zheng
71b3b43495 Added support for reboot task
Test: tested on raven device
Change-Id: I4935d720f567e70da95ea8da37f3404b80b313c8
Bug: 194686221

Changed reboot {target} to work off tasks. reboot-{target} commands are
also supported.

Test: tested reboot on raven device
Change-Id: I05aed269d121a5d651c1ab1180a1b4878ae213fd

Modified load_buf to be able to find images in $OUT directory

Test: tested flash {partition} and flash {partition} {img_name} on raven
device

Change-Id: I3879792d11ad15bc910670853d2a7fe200fcc66f
2023-02-23 00:15:08 +00:00
Dmitrii Merkurev
45380e4ace Merge "fastboot: Use copy constructor to copy fastboot match callback" 2023-02-15 19:05:55 +00:00
Dmitrii Merkurev
96ea7b9ccf Merge "fastboot: Follow fastboot pattern to show network-connected device status" 2023-02-15 19:05:34 +00:00
Dmitrii Merkurev
c48cd9f6c0 fastboot: Follow fastboot pattern to show network-connected device status
Bug: 269348113
Test: checked output
Change-Id: Ie6c48d36bd67fcb060ad3f4a35185fd9cc59ff81
Signed-off-by: Dmitrii Merkurev <dimorinny@google.com>
2023-02-15 15:34:58 +00:00
Dmitrii Merkurev
b5b8276db1 fastboot: Use copy constructor to copy fastboot match callback
Test: fastboot -s 15171FDF6000CV getvar all on OSX
Bug: 269348113
Change-Id: I968626c95ee19ea348bac48cac308e3c817e0d55
Signed-off-by: Dmitrii Merkurev <dimorinny@google.com>
2023-02-15 15:21:22 +00:00
Treehugger Robot
368a908334 Merge "Fastboot: Add new TEXT message to protocol to handle long lines." 2023-02-15 11:49:24 +00:00
Raphael Herouart
99097cc020 Fastboot: Add new TEXT message to protocol to handle long lines.
Trusty Benchmarks need to be evaluated in ABL which is much more
controlled than linux. However fastboot prints evry atomic message from
trusty/abl on its own line starting with "(bootloader)"

Bug: 263454481
Test: - "fastboot oem trusty runtest trusty.hwrng.bench"
Change-Id: I99847a8cc54457c8ec809e219736325dce0ac891
2023-02-14 19:58:42 +00:00
David Anderson
2d6c30da7f Merge "fastboot: Add a mock transport and some driver tests." 2023-02-14 16:05:44 +00:00
David Anderson
e6d8dd3e15 fastboot: Add a mock transport and some driver tests.
Bug: N/A
Test: fastboot_test
Change-Id: I08d8dfedcc7e9dad9ce418e0f3aaf5ac69a3a2a2
2023-02-13 18:59:48 -08:00
David Anderson
6c5b6a8705 Merge "fastboot: Add a test for super_flash_helper." 2023-02-14 02:12:52 +00:00
David Anderson
ada871875e fastboot: Add a test for super_flash_helper.
This test checks that the sparsing logic matches a canonical sample
output.

Bug: N/A
Test: fastboot_test
Change-Id: Ic7bad08a79e4223f8352db2397b741c2179e76bb
2023-02-13 15:47:10 -08: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
Treehugger Robot
77f4cb4db0 Merge "fastboot: Introduce connect / disconnect for network-connected devices" 2023-02-13 20:25:12 +00:00
Dmitrii Merkurev
0ee285aa68 fastboot: Introduce connect / disconnect for network-connected devices
Use introduced FileLock and network-connected devices storage entities
to introduce fastboot connect / disconnect commands

Test: everything works like discussed here go/fastboot-connect-disconnect on windows/linux
Bug: 267507450
Bug: 267506875
Change-Id: I2d6495ad567a3ddadd471a89b82d78c8c36a3d52
Signed-off-by: Dmitrii Merkurev <dimorinny@google.com>
2023-02-11 00:02:22 +00:00
Dmitrii Merkurev
4dd1ac9282 Merge "fastboot: Introduce network-connected devices storage" 2023-02-10 20:27:15 +00:00
Sandeep Dhavale
ee065fe080 Merge "Fastboot: Use AServiceManager_waitForService instead of AServiceManager_getService" 2023-02-10 04:12:06 +00:00
David Anderson
d45181f1c2 Merge "fastboot: Add fastboot_test to TEST_MAPPING." 2023-02-09 21:33:26 +00:00
Dmitrii Merkurev
91297172eb fastboot: Introduce network-connected devices storage
Bug: 267507577
Bug: 267505625
Test: tested file lock api works on linux/windows
Test: tested storage api works on linux/windows
Change-Id: I33dda819370900310ae7fc63cbf6b00ba22ad4e8
Signed-off-by: Dmitrii Merkurev <dimorinny@google.com>
2023-02-09 16:28:17 +00:00
David Anderson
86e869a566 fastboot: Add fastboot_test to TEST_MAPPING.
Bug: N/A
Test: fastboot_test on host
Change-Id: I1947b371ba6117e6eed811d1d6e1ed4019e0a0e9
2023-02-08 15:03:51 -08:00
Daniel Zheng
166efb16c7 Merge "Created new Task.h file to contain task classes." 2023-02-07 21:03:20 +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
John Stultz
3f061f9813 fastboot: Fix missing endian header in fastboot_driver.h to avoid header confusion
So fastboot_driver.h includes <android-base/logging.h>, but that
file has a dependency on <android-base/endian.h>. So if
fastboot_driver.h gets included somewhere before
<android-base/endian.h>, it results in *very* opaque error
message:

system/core/fastboot/fastboot.cpp:1490:9: error: expected unqualified-id
        LOG(VERBOSE) << "Cannot optimize flashing super on non-AB device";
        ^
system/libbase/include/android-base/logging.h:221:23: note: expanded from macro 'LOG'
                      ^
system/libbase/include/android-base/logging.h:227:4: note: expanded from macro 'LOGGING_PREAMBLE'
  (WOULD_LOG(severity) &&                                                                  \
   ^
system/libbase/include/android-base/logging.h:202:40: note: expanded from macro 'WOULD_LOG'
  (UNLIKELY(::android::base::ShouldLog(SEVERITY_LAMBDA(severity), _LOG_TAG_INTERNAL)) || \
                                       ^
system/libbase/include/android-base/logging.h:174:26: note: expanded from macro 'SEVERITY_LAMBDA'
  using ::android::base::ERROR;               \
                         ^
prebuilts/gcc/linux-x86/host/x86_64-w64-mingw32-4.8/x86_64-w64-mingw32/include/wingdi.h:75:15: note: expanded from macro 'ERROR'
              ^

This patch includes <android-base/endian.h> before
<android-base/logging.h> to avoid this issue.

Reported-by: Daniel Zheng <zhengdaniel@google.com>
Signed-off-by: John Stultz <jstultz@google.com>
Change-Id: I8752f2cdbef5b13901f0f4e8adfe60a21db785b6
2023-02-04 04:06:48 +00:00
David Anderson
667b1efadd fastboot: Avoid reboots to userspace when using flashall/update.
Reboots to fastbootd (userspace fastboot) take a long time, particularly
due to the orange AVB screen and the likelihood of devices having uart
enabled. For "flashall", there is rarely a need to actually go into
userspace, because all of super is getting thrown away. We can just
flash super in the bootloader.

In the past we didn't do this because computing super.img is expensive -
both in terms of time (due to reading dependent images) and in terms of
space (it's easily over 5GB).

But we don't actually need to fully compute super.img. We can build a
sparse_file containing the metadata/headers, with additional references
to each image file containing partition data. Liblp provides the API to
do that, and here, we simply need to translate the layout to libsparse.

On Pixel, this reduces flashall time by around 35-50 seconds, or around
20% of total time, depending on whether uart is in use.

There are some caveats, in which case we'll fall back to normal
fastbootd. This does not work on non-A/B devices, on retrofit dynamic
partition devices (Pixel 3), and in some other edge-casey scenarios. If
it fails, -v will add logging information about why.

Bue: 266982466
Test: fastboot flashall on Pixel 5+
Change-Id: Ie040da597d739faa7f834202184cec8f8e412076
2023-02-01 11:28:18 -08:00
David Anderson
aa87dc5a0d fastboot: Move some helpers into util.h/.cpp.
Bug: 266982466
Test: builds
Change-Id: Ib744d763e11d8a7f7e3f417b331defff61fe4559
2023-02-01 11:28:16 -08:00
David Anderson
a67fc32a8a fastboot: Allow using LOG().
The die() and verbose() macros are not really standard for AOSP. To
allow a gradual transition off them, call InitLogging on startup. This
will also allow seeing liblp logs when -v is passed.

Bug: 266982466
Test: builds
Change-Id: I74278bb5f698edb0dc81477a575b130b0bd11cdf
2023-02-01 11:09:29 -08:00
David Anderson
a1c983e800 fastboot: Use RAII for sparse_file objects.
Bug: 266982466
Test: fastboot flash
Change-Id: I3d240d6ecc8a37d968ffdef9d50e349e787e8d3e
2023-02-01 11:09:28 -08:00
Jack Wu
0635794d2d fastboot: Update health AIDL HAL to V2
Bug: 251425963
Test: Build
Change-Id: I538ebee69ebe69a1ad1fa934bb7440ef12fc2cc2
Signed-off-by: Jack Wu <wjack@google.com>
2023-01-21 15:21:00 +08:00
Isaac J. Manjarres
acb49528a7 fastboot: Copy AVB footer from recovery.img to the end of the partition
Copy the AVB footer of the recovery.img to the end of the recovery
partition, so that it can be found when loading a recovery image
from a partition that is larger than the image.

Bug: 261673286
Test: m and flashing recovery image and bootloader can now detect
AVB footer.
Change-Id: Ib93da33c72f3a96eb8d9bcedaab5ef0c3a4d418d
Signed-off-by: Isaac J. Manjarres <isaacmanjarres@google.com>
2023-01-12 14:33:56 -08:00
Shaju Mathew
dce1371666 Zero-length packet send bug resolution for fastboot.
Bug: 208675141

Test: Treehugger, cursory test of fastbootd against macOS Monterey running fastboot.

Change-Id: Id2ac1be428470385c866d505f860e50bd9132e2e
Signed-off-by: Shaju Mathew <shaju@google.com>
2023-01-11 19:32:01 +00: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
Daniel Zheng
14000f19a9 Merge "Updating fastboot to modern c++ standards" 2022-12-08 17:23:08 +00:00
Chih-Hung Hsieh
c76bc32d95 Fix "Attempt to delete released memory" warning.
EXPECT_NONFATAL_FAILURE(statement, ...) expands to
  do {
    ... statement ...
  } while (::testing::internal::AlwaysFalse());

Clang analyzer cannot see into AlwaysFalse(),
and gives a false warning assuming that the
do loop can be done twice.

Use a unique_ptr::reset to call delete,
because reset can be called multiple times..

Bug: 259999410
Test: make tidy-system-core-fastboot_subset
Change-Id: Ie536f76635dd55f4e47b80eed6498fd1193b88ee
2022-12-02 12:38:41 -08:00
Daniel Zheng
65452d036e Updating fastboot to modern c++ standards
Test: tested fastboot on raven device
Change-Id: I0c1fa4cd09378282edf5df54ae26d747e6d4f3eb
2022-11-30 03:36:46 +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
Treehugger Robot
460f70bb52 Merge "Adding target (sdk-repo-platform-tools) that is used by gmac(sdk_mac) build." 2022-10-07 04:13:51 +00:00
Shaju Mathew
6c27f235cf Adding target (sdk-repo-platform-tools) that is used by gmac(sdk_mac) build.
Bug: 249370316
Test: N/A (coastguard)

Signed-off-by: Shaju Mathew <shaju@google.com>
Change-Id: I641d4f8dc60652c7e8eaebafd905090d3c0324f2
2022-10-06 22:37:09 +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
Treehugger Robot
a67092a7b8 Merge "Updates the FB_COMMAND_SIZE from 64 to the linux max value of 4096 and updates the relevant unit tests." 2022-09-15 08:48:52 +00: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
Bradley Furman
7518e8ba7e Updates the FB_COMMAND_SIZE from 64 to the linux max value of 4096 and
updates the relevant unit tests.

BUG=182864081

Test: Update the size check to the existing unit tests

Change-Id: I66b08884a5228e164c22c575a6f6c82a236fece2
2022-09-13 20:58:06 +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
Thiébaud Weksteen
3c1f230971 Remove e2fsdroid and sload_f2fs dep from fastboot
In commit 5d72d6c, an unused code path for e2fsdroid and sload_f2fs was
removed from fastboot. Remove them from the build dependency list.

Bug: 237960487
Test: m fastboot
Change-Id: Ibee72a86eeb43fcde3a032094bfc1c19de09bc03
2022-08-11 15:36:17 +10:00
Thiébaud Weksteen
5d72d6ce20 Remove unused execution paths when formatting
fastboot uses the internal functions generate_ext4_image and
generate_f2fs_image when called via the `format` subcommand. An option
for populating the newly created fs with an initial directory exists,
but it is not exposed to the command line interface (initial_dir is
always ""). Remove the unused codepaths for this preloading.

Test: atest --host fastboot_test
Bug: 237960487
Change-Id: I7acfe6352cf26b5cbe0e5553b288c3798e96a893
2022-07-21 14:50:05 +10:00
Kelvin Zhang
1fcdce21d6 Add zhangkelvin@ as owner of fastboot
Working on replacing aio w/ liburing in fastboot recently

Change-Id: I8076e2e53dc8d620faf9bff7f37ba2d2538460d6
2022-07-12 11:05:33 -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
Kelvin Zhang
5cb1b0295e Add lz4 support for VABC
Add lz4 support in CowWriter/CowReader. Lz4 should offer faster
read/write performance but slightly larger COW sizes.

Download time: Reduced from 1264s to 825s (~35% faster)
Filesystem verification time: from 69s to 59s (~15% faster)
COW Size: 2.59GB to 3.21GB, (~25% regression)
Merge time: 37046ms to 27690ms (~25% faster)
Boot time: LZ4 is 2.7% faster

Overall, LZ4 offers faster read/write performance at the cost of 25%
space regression.

Test: th
Bug: 228478555
Change-Id: Ie521852fb3c9ff8a12e55b764c1eb1838f7b2181
2022-06-29 13:10:55 -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
Keith Mok
1e490f032e fastboot: vendor boot img util OOB
If vendor image size is less than what the header claims,
there is OOB access.
And it did not check page size equal to zero also.

Bug: 234208198
Test: fastboot_fuzzer
Change-Id: Iec08acf9bb354db4c4cd25e3a0c581974fee7eed
2022-06-07 16:14:43 +00: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
Trevor Radcliffe
b0fa575e1f Merge "set isolated: false on fuzzy_fastboot" 2022-05-06 17:11:17 +00:00
Alix Espino
d3918d8d1e Merge "Moved contents of clang_cflags into cflags" 2022-05-03 17:12:37 +00:00
Trevor Radcliffe
1adca2b8e9 set isolated: false on fuzzy_fastboot
fuzzy_fastboot causes vts to fail when it has isolated set to true
so manually set it to false to avoid this.

Bug: 178498003
Test: Ran tests that failed presubmit
Change-Id: I871854c26e07ac6ad94feb14703b705a3054c176
2022-04-28 19:30:42 +00:00
Lucas Wei
a85c719661 Merge "fastboot: Add vendor_kernel_boot" 2022-04-25 18:31:36 +00:00
Alix
9640339389 Moved contents of clang_cflags into cflags
Test: Treehugger
Bug: 226636335
Change-Id: I30294801423e6d39ab1d8ed3804c15a6ff0e90e5
2022-04-21 03:41:26 +00:00
Lucas Wei
f0fb5dde89 fastboot: Add vendor_kernel_boot
Bug: 214409109
Signed-off-by: Lucas Wei <lucaswei@google.com>
Change-Id: I8b0baa887e5e2309a1cb4a602fe8f6ca9e22526b
2022-04-02 01:04:23 +08: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
Bob Badour
c9605e6ae1 Add LOCAL_LICENSE_KINDS to system/core
Added SPDX-license-identifier-Apache-2.0 to:
  fastboot/fuzzer/Android.bp
  fs_mgr/fuzz/Android.bp

Bug: 68860345
Bug: 151177513
Bug: 151953481

Test: m all

Change-Id: I3bb21e1af846d175a345c2a3a632dc47ecdd62de
2022-02-10 11:12:20 -08:00
Paweł Grabas
ff9cfac08e Allow disabling AVB on special vbmeta partitions
The vbmeta partition might have additional prefix
(e.g., guest_vbmeta_a) on some virtual machine
environment. Allowing rewriting the disable-verity/
disable-verification bits in the vbmeta image upon
flash under such use case.

Bug: https://partnerissuetracker.corp.google.com/u/1/issues/181791553
Test: manual tests with different names of vbmeta partition
Change-Id: Iacadaf587fce1e1e7fef946f56bbfc7f4e8233d8
2022-02-08 22:40:06 +00:00
Keith Mok
d59e883ee5 Merge "fuzzy_fastboot: Add malformed download command test" 2022-01-19 19:31:49 +00:00
Hridya Valsaraju
ddb215da38 Merge "Add a LICENSE file for fastboot" 2022-01-19 19:05:27 +00:00
Keith Mok
7e87807d16 fuzzy_fastboot: Add malformed download command test
Add a malformed download command test.
And add a sparse file test with very large block size

Bug: 215236564
Test: bootloader fastboot
Change-Id: I1072ba189ac15b2e1eb8f13ffd754f93c967e2d5
2022-01-19 00:02:51 +00:00
Hridya Valsaraju
99373794b3 Add a LICENSE file for fastboot
The BSD license used by some of the files in the project was lacking a
license_text file.

Bug: 191508821
Test: m fastboot
Change-Id: I3bdfdea3de69ceaa28528b72a09d02d2a9535e85
2022-01-18 14:03:16 -08: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
Treehugger Robot
0b5bfdce7d Merge "fastboot: make init_boot.img optional" 2022-01-11 03:54:31 +00:00
Devin Moore
60bd33ffd5 fastboot: make init_boot.img optional
Older devices don't build this image because they don't have a partition
for it.

Bug: N/A
Test: m
Change-Id: I56b58c1bc137ce25e426aa4ec6d2303fa7d77ccc
2022-01-11 02:02:59 +00:00
Treehugger Robot
afd4ccd70b Merge "Remove win_sdk" 2022-01-10 20:18:16 +00:00
Cole Faust
eea1dadba8 Remove win_sdk
win_sdk is deprecated, if given on the command line
sdk will be build instead.

Bug: 212724080
Test: Presubmits
Change-Id: Ia92b879fe08f0a1d9ebefc90e369adf1d4aa4112
2022-01-07 14:55:54 -08:00
Devin Moore
cb5098f547 fastboot: make copy_boot_avb_footer more generic
The funciton is now used for init_boot and boot partitions, so the name
and the error messages should be more generic.

Bug: 203698939
Test: m
Change-Id: I168fdcb08accb11b2c9cfc402168744274f59665
2022-01-07 18:03:33 +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
Hridya Valsaraju
8fb1aa982b fastboot: Add elsk@ to OWNERS file
Also, remove hridya@ from the OWNERS file

Test: N/A
Bug: N/A
Change-Id: I1d5a03ebf9e2e93f555474a6a654e16879b8e96a
2022-01-06 15:29:17 -08: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
Devin Moore
dd1eb8733d fastboot: Support flashing init_boot.img into init_boot partition
init_boot_a and init_boot_b partitions are used in A/B devices.

Bug: 203698939
Test: m

Change-Id: If00f581ab7ae340d78d7d55eebafd92ac15d2bc1
2022-01-06 22:32:28 +00:00
Keith Mok
e3f4b84468 Merge changes I75017420,I3612e131
* changes:
  Fix userspace fastboot with fuzzy test
  Fix fuzzy test on too large command
2022-01-05 23:50:12 +00:00
Keith Mok
ba31ce8655 Merge "Fix typo in fuzzy_fastboot README" 2022-01-05 18:43:16 +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
Keith Mok
921ad28a30 Fix fuzzy test on too large command
Device might return I/O error instead of FAIL message
if command send to device is too large.
Since maximum command size in fastboto protocol is 64 bytes.
The device might only try to read 64 bytes for the bulk transfer,
sending data more than that might result in USB I/O error.

Do proper handler for that in fuzzy_fastboot and reset the USB
if I/O error encounter during the Comman.dTooLarge test

Test: adb reboot fastboot
      fuzzy_fastboot --gtest_filter=Fuzz.CommandTooLarge
      fuzzy_fastboot --gtest_filter=Fuzz.BadCommandTooLarge
Bug: 212628476
Change-Id: I3612e131de02435ee3ed7d18f2b2d20b50ae6c3f
2022-01-04 19:24:05 +00:00
Treehugger Robot
5785297922 Merge "fastboot: Add system_dlkm flashing support" 2022-01-04 00:28:41 +00:00
Keith Mok
66f6e63731 Fix typo in fuzzy_fastboot README
The fuzzy_fastboot does not output error
with invalid command line argument.

Fix typo in README for running with gtest_filter

Bug: 212628476
Test: N/A
Change-Id: I4a67a84807b59db50f063f1b9cf60dc964c1df20
2021-12-30 20:33:05 +00:00
Ramji Jiyani
b3ddb534c3 fastboot: Add system_dlkm flashing support
Bug: 200082547
Test: TreeHugger
Signed-off-by: Ramji Jiyani <ramjiyani@google.com>
Change-Id: I35e081bbe8674c102324d22d440dcc38493ec25b
2021-12-29 21:00:25 +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
Colin Cross
8a87bdf80d Use HOST_OUT_EXECUTABLES instead of SOONG_HOST_OUT_EXECUTABLES
Soong is installing binaries directly to HOST_OUT_EXECUTABLES instead
of SOONG_HOST_OUT_EXECUTABLES, dist from the HOST_OUT_EXECUTABLES
location.

Bug: 204136549
Test: m checkbuild
Change-Id: Iee7ae8d1ed478aa2a0344fc9f54ad2c146841cb0
2021-10-25 22:41:07 -07:00
Ayushi Khopkar
ce5c033e2b Added fastboot_fuzzer
Test: ./fastboot_fuzzer
Bug: 189053436

Change-Id: Idf9be2f86238eb2c7090402adc54bbb9c0b43582
2021-10-14 00:32:38 +00:00
David Anderson
b72fa73ace Merge "fastboot: Support casefolding in ext4 partitions." 2021-08-27 01:18:06 +00:00
Colin Cross
fb66f3d13f Merge "Include sys/select.h for fd_set" 2021-08-17 18:56:16 +00:00
Yi-Yo Chiang
b33cfbfc4b Merge "fastboot/README.md: Update response packet max size to 256" 2021-08-17 14:15:36 +00:00
Colin Cross
cbca269d75 Include sys/select.h for fd_set
socket.cpp fails to compile on musl with a missing definition of
fd_set.  Include sys/select.h for the definition.

Bug: 190084016
Test: m USE_HOST_MUSL=true fastboot
Change-Id: I095a56381a85981f42444f4c39ae8e7786d8640f
2021-08-16 17:20:19 -07:00