Commit graph

592 commits

Author SHA1 Message Date
Tom Cherry
4aa60b382c fastboot: clean up CheckRequirements
CheckRequirements() had various issues that are cleaned up here,

1) Move from C string parsing to C++
2) Moved from C data structures to C++, including fixing memory leaks.
3) Removed the 'cur_product' global and the 'query_save' function that
   stores it
4) Actually writing tests for the parsing function for
android-info.txt
5) Check that a variable needs to be checked for a given product before
   trying to read it.  Previously, fastboot would fail if a variable
   isn't recognized on a device, even if the check should be ignored.

A lot of flexibility is allowed for the input strings, to keep
backwards compatibility with the previous parsers.

Test: fastboot works, unit tests

Change-Id: Idc3bba8b8fe829d8eefe5f6c495e63a9441c0b60
2018-09-21 12:50:39 -07:00
Tom Cherry
dfd85df11a Use vector<char> instead of char* and malloc() for images
And fix the associated memory leaks in the process.

Test: fastboot works
Change-Id: I6e41f351ca6cebf79282d30b1eca1506496e0c21
2018-09-20 16:48:36 -07:00
David Anderson
1109c92bea fastboot: Add vbmeta_mainline to the partition list.
Bug: 115939310
Test: fastboot flash vbmeta_mainline works
      fastboot flashall includes vbmeta_mainline

Change-Id: I081660cd8437ac66cab750b270f5019230050285
2018-09-17 17:34:22 -07:00
Treehugger Robot
e9997f8152 Merge "Integrate with fastboot HAL to get partition type" 2018-09-08 02:47:41 +00:00
Hridya Valsaraju
bf9f8d1a64 Integrate with fastboot HAL to get partition type
Bug: 79480454
Bug: 78793464

Test: fastboot getvar partition-type:userdata

Change-Id: Ib096ee8061568b8503f3a3f2dbb7e19a932162c4
2018-09-07 12:22:00 -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
Greg Kaiser
1fd4b364fc Merge changes I891f64fb,I6182d84e
* changes:
  logcat: Fix buffer size
  UsbTransportSniffer: Defensively use 'final'
2018-09-06 17:11:13 +00:00
Tom Cherry
04ccbfd62c Merge "fastboot: remove command queue" 2018-09-06 16:07:18 +00:00
Greg Kaiser
33b07ba96c UsbTransportSniffer: Defensively use 'final'
UsbTransportSniffer invokes the virtual method Close() within
its destructor.  This usage is fine right now, but if a future
class inherited from UsbTransportSniffer and overrode the Close()
method, then this destructor would not act as expected.

To protect against this, we declare Close() 'final' in
UsbTransportSniffer, and add a comment.

Test: Treehugger
Change-Id: I6182d84e7caf67cb06f37c22c6203ad6d6e57f34
2018-09-06 06:18:01 -07:00
Treehugger Robot
8c0a3e0a7d Merge "fastbootd: Implement getvar hw-revision." 2018-09-06 00:55:32 +00:00
Treehugger Robot
950ec1a001 Merge "fastbootd: Perform CRC check when flashing sparse images." 2018-09-05 22:12:32 +00:00
Treehugger Robot
6e66d36c24 Merge "fastbootd: Fix getvar max-download-size formatting." 2018-09-05 22:11:40 +00:00
Treehugger Robot
61b6c5cdfe Merge "Remove request for read access to partitions." 2018-09-05 21:45:24 +00:00
Tom Cherry
11f12099cc fastboot: remove command queue
There is little advantage and increasingly much disadvantage to
queueing up fastboot commands before executing them.  This change
removes the queue in the most simple way possible to enable further
clean up.

Test: fastboot works
Change-Id: I9abab05df07ed167dbe6a42e1eb9eab8f8d4f157
2018-09-05 14:28:47 -07:00
David Anderson
c091c176cb fastbootd: Implement getvar hw-revision.
Bug: 78793464
Test: fastboot getvar hw-revision works
      fuzzy_fastboot Conformance.GetVarRevision passes

Change-Id: I5a3e9893d61e18567f2f818ef06cad8e862d637f
2018-09-05 12:52:15 -07:00
David Anderson
56843eec45 fastbootd: Perform CRC check when flashing sparse images.
Bug: 78793464
Test: fuzzy_fastboot Conformance.SparseCRCCheck passes
Change-Id: I717fbec42599a43bafafa1f73837e115a9f9109a
2018-09-05 12:52:15 -07:00
David Anderson
28b81cdc91 fastbootd: Fix getvar max-download-size formatting.
Bug: 78793464
Test: fuzzy_fastboot Conformance.GetVarDownloadSize passes
Change-Id: I8f33cb01e5b2ba66eab91b2481322d7fae593cf0
2018-09-05 12:52:14 -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
4758967bf9 fastbootd: Fix partition size testing issues.
Partition sizes must be reported with an "0x" prefix for fuzzy_fastboot.
Also, with dynamic partitions, the size of a partition can be 0.

Bug: 78793464
Test: fuzzy_fastboot Conformance.PartitionInfo does not error on
      partition sizes when using fastbootd

Change-Id: I4148440bd9ed420878940829618cbf8cee85bf6a
2018-09-04 16:25:06 -07:00
David Anderson
6c30f6e3d2 fuzzy_fastboot: Use uint64_t for partition sizes.
Bug: N/A
Test: fuzzy_fastboot Conformance.PartitionInfo passes
Change-Id: I27182585a1522d22dd3ddfe83ce22e06dd7fc762
2018-09-04 15:58:28 -07:00
David Anderson
03de645aac fastbootd: Fix transport ownership.
This change moves Transport ownership back out of FastBootDriver.
Callers of set_transport must ensure that the previous transport is
destroyed. In addition, deleting a transport now ensures that it is
closed.

Bug: 78793464
Test: fastboot, fuzzy_fastboot works
Change-Id: I8f9ed2f7d5b09fd0820b2677d087a027378f26db
2018-09-04 15:01:12 -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
1fb3fd7242 fastbootd: Refactor for getvar all.
It is easier to implement getvar all if we can invoke each variable
handler and collect their results. This change reverts the handlers to
return their messages as an outparam, rather than going through
FastbootDevice.

Bug: 78793464
Test: fastboot getvar works
Change-Id: I8544251ce517526b26435526756359ce220520cc
2018-08-31 17:03:50 -07:00
Dan Willemsen
822465a930 Fix the mac fastboot build
The Carbon framework isn't on the list of libraries that Soong allows
linking against, so this broke the Mac build. This compiles just fine
without Carbon though, and I don't see any references to Carbon in the
code.

Test: mma
Change-Id: I83044d244f7cec778c8b8b6132249c0f016c10fc
2018-08-30 18:26:11 -07:00
Dan Willemsen
4d8929773b Merge "Convert fastboot to Soong" 2018-08-30 23:36:54 +00:00
Treehugger Robot
c47c508dcd Merge "fastboot: Use a single codepath for flashall and update." 2018-08-30 20:12:16 +00:00
Dan Willemsen
ab971b5e7e Convert fastboot to Soong
Also fix adb's version number to match.

See build/soong/README.md for more information.

Test: cd system/core/fastboot; mma
Test: fastboot --version
Test: adb --version
Test: out/host/linux-x86/nativetest/fastboot_test/fastboot_test
Test: out/host/linux-x86/nativetest64/fastboot_test/fastboot_test
Change-Id: I65ea39af9183c602e84f3bc0e4a0d066a30fc464
2018-08-30 11:28:18 -07:00
David Anderson
cf444f3633 fastboot: Use a single codepath for flashall and update.
This patch extracts the common logic out of the flashall and update
command implementations. There is now a FlashAllTool helper class, and
an ImageSource class for commands to specify how to find built images.

With these paths merged, the update command now supports logical
partitions.

Bug: 78793464
Test: flashall works with or without a super partition
      update works with or without a super partition

Change-Id: I63a8690bbc4da6ea98a07eb2c07166ddd993a7b7
2018-08-29 15:58:34 -07:00
Tom Cherry
e51dadb8a7 fastboot: remove 'verify'
This isn't sent by the fastboot client.
This isn't in our bootloader requirement document.
Neither my hikey nor sailfish respond to this.

Test: fastboot still works
Change-Id: I11ff0aed818d98f3427ed427605d99b3c76ccb06
2018-08-29 15:29:20 -07:00
Tom Cherry
566751444d fastboot: remove 'powerdown'
This isn't sent by the fastboot client.
This isn't in our bootloader requirement document.
Neither my hikey nor sailfish respond to this.
The README.md literally uses this as an example for 'unknown command'

Test: fastboot still works.
Change-Id: Ia442a41de517dae078dd7e73c951aadb97646c73
2018-08-29 14:10:47 -07:00
David Anderson
0debda098f fastboot: Clean up the image array a bit.
This makes the following changes to the images array:
 * The "optional_if_no_partition" flag is removed, as it was a temporary
   workaround for super.img.
 * The "flashall" flag is removed.
 * The "needed_for_fastbootd" flag is now an ImageType enum.

Bug: N/A
Test: fastboot builds, flashall works
Change-Id: Id000ea20cf83639cec2c9ae94f28c799b34606f1
2018-08-28 15:17:48 -07:00
David Anderson
95d4093b49 fastboot: Flash boot partitions before rebooting to fastbootd.
Userspace fastboot is required when flashing logical partitions. If for
some reason userspace fastboot is broken, the user may be stuck with
bootloader fastboot. To address this scenario, we now flash "boot",
"vbmeta", "recovery", "dtbo", and "dts" before booting into userspace
fastboot, using whatever fastboot is currently active.

Bug: 78793464
Test: fastboot flashall with device in bootloader fastboot
Change-Id: I773707bbbe9235c560416c70976e32fd8e52a5a3
2018-08-28 12:54:01 -07:00
David Anderson
1d887434da fastboot: Automatically reboot to userspace fastboot.
In order to flash logical partitions, "flashall" must be run against
userspace fastboot. When the bootloader supports the "reboot-fastboot"
command, we now attempt to automatically reboot into userspace fastboot.

We do this by closing the transport, sleeping for one second, and then
polling for a new connection until one is available. FastBootDriver is
then assigned the new transport.

Bug: 78793464
Test: fastboot flashall on device with logical partitions, while booted
      into bootloader fastboot

Change-Id: I6949871b93ab5e352784cabe0963c6ecfc0af36d
2018-08-28 09:07:40 -07:00
Mark Salyzyn
8fb0fb86a7 fastboot: allow automatic detection of super location
Add "super" to the table of known images so that automatic file
resolution can occur.  Add a flag to indicate if the image should
be flashed with flashall and set it to false for the new "super"
image, all else true.

Test: 'fastboot flash super' works.
      'fastboot flashall' does not flash super
Bug: 78793464
Change-Id: I5b85536b1d4890264531af357aba84a061d6df44
2018-08-24 15:24:41 -07:00
Treehugger Robot
07c2c9a58d Merge "Added support to fuzzy_fastboot for more sparse tests" 2018-08-24 17:54:24 +00:00
Aaron Wisner
ab2645514d Added support to fuzzy_fastboot for more sparse tests
Test: Pixel 2
Change-Id: Ibd491336ace4f346c3900a61bca30ac3023e4f21
2018-08-24 16:22:54 +00:00
Aaron Wisner
a5ad20aecc Fix mac build breakage due to missing usb_osx.cpp in
Android.cpp file for libfastboot2

https://android-review.googlesource.com/c/platform/system/core/+/722153

Test: Build on osx
Change-Id: I6151e37581ac332e4d5cfb5e40feb3ea0e3093df
2018-08-24 10:53:04 -05:00
Treehugger Robot
5d3edb1422 Merge changes from topic "fastbootd-flashall"
* changes:
  fastbootd: Support flashall with logical partitions.
  fastboot: Use _WIN32 instead of WIN32.
2018-08-23 18:55:42 +00:00
David Anderson
32e376f848 fastbootd: Support flashall with logical partitions.
Currently, fastboot flashall will try to flash every partition in the
image list. For devices with logical partitions, this will cause those
partitions to be flashed twice (once via super.img, and again for each
individual image). Additionally, super.img is needed to synchronize the
logical partition list, but it is only generated with "make dist",
making it inconvenient for most workflows.

This patch removes automatic flashing of super.img. Instead, devices
with a super partition must now generate a "super_empty.img"
describing the super geometry and logical partition layout. Before
flashing any other partitions, this image is used to ensure the device
has created all necessary logical partitions.

Additionally, before flashing (but after updating super), all logical
partitions that will be flashed are resized to 0. This ensures that
logical partitions will receive more optimal space allocation.

Finally, during flashing of individual images, logical partitions are
resized to the image size, since they do not have hardcoded sizes in the
build.

Bug: 78793464
Test: fastboot flashall can flash vendor, product, product_services
      without a make dist/super.img.

Change-Id: I18c2291e0d0cb10de729c5646b75ac84dde8c871
2018-08-23 10:43:46 -07:00
David Anderson
c3ade7f48a fastboot: Use _WIN32 instead of WIN32.
Bug: N/A
Test: fastboot.exe builds
Change-Id: I316611f581c80ec813b953a7e6074293399ab7d7
2018-08-23 10:42:59 -07:00
Treehugger Robot
e41cb2e767 Merge "fastbootd: Add an update-super command to sync the super partition." 2018-08-23 00:54:26 +00:00
Treehugger Robot
9dc6f90cb8 Merge "adbd: use unique_fd for the usb file descriptors." 2018-08-23 00:45:03 +00:00
Treehugger Robot
e37c5ca4dd Merge "Create fuzzy-fastboot pen tester" 2018-08-23 00:42:54 +00:00
Josh Gao
860cc5ae39 adbd: use unique_fd for the usb file descriptors.
Test: adb shell
Change-Id: I8b5e31377bbda9b02e522e3a4b75ac908197912f
2018-08-22 15:33:08 -07:00
David Anderson
38b3c7a122 fastbootd: Add an update-super command to sync the super partition.
This change introduces an "update-super" command to the fastboot
protocol. Unlike the "flash" command, which copies raw or sparse data to
a partition, the "update-super" command requires the data to be a super
image generated by lpmake.

If the super partition is not yet formatted (or is corrupt), then it
will be formatted using the given image. Otherwise, "update-super" will
preserve the existing partition layout, and only ensure that logical
partition entries exist for all the new partitions in the given image.
All new partitions added this way will have a zero size, and it is the
host's responsibility to size them as needed afterwards with the
"resize-logical-partition" command.

In addition, the "update-super" command supports a "wipe" argument,
which will force the super partition to be reformatted with the given
image, overwriting any existing partition tables.

Bug: 78793464
Test: fastboot flashall with a super partition
Change-Id: If37d839a03e396e11b6c08a9c32984106613d1dc
2018-08-22 15:05:03 -07:00
Chris Fries
1572771495 Merge "Add support to fastboot_driver for sending sparse images with CRC check" 2018-08-22 18:39:16 +00:00
Aaron Wisner
00737b3939 Create fuzzy-fastboot pen tester
Test: Run on Sailfish, Walleye, and other devices
Bug: http://b/111126621
Change-Id: I309af79411d0a16d11874a048ce0db024770d7b2
2018-08-22 11:30:29 -05:00
Aaron Wisner
9812b58fc4 Add support to fastboot_driver for sending sparse images with CRC check
The default argument will prevent anything from breaking

Test: Build on glinux
Change-Id: Ib427ab210476db1ec1c69c0a3238d0653e98b79a
2018-08-22 11:02:47 -05:00
Dario Freni
ab5583b585 s/product-services/product_services/g
Attempting to reduce the number of different spellings we have for
"product services" partition in the codebase.

Bug: 112431447
Test: m
Change-Id: I1a87d7e040a8b1f91f973ac7d90d6360b5b54f71
Merged-In: I1a87d7e040a8b1f91f973ac7d90d6360b5b54f71
2018-08-20 17:46:42 +00:00
David Anderson
79ab0e3e98 fastbootd: Complete the implementation of getvar has-slot.
Bug: 78793464
Test: fastboot getvar has-slot:super returns "no"
Change-Id: I80f171df062c008718b810bbe12070834d4aa3fb
2018-08-14 16:24:07 -07:00