Commit graph

12 commits

Author SHA1 Message Date
Peter Collingbourne
cc1bf34ba6 fastboot: Use clock_gettime(CLOCK_MONOTONIC) in now()
If the system time changes during the execution of fastboot we might
see some strange output such as:

Sending sparse 'super' 4/20 (254972 KB)            OKAY [-516.263s]

Fix it by changing now() to use clock_gettime(CLOCK_MONOTONIC).
I confirmed that all callers of now() are using it for relative time
and not time since the epoch.

Change-Id: Ic3e9442c2ab21dfb076bfed88915085a183754b0
2024-02-07 16:55:49 -08: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
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
7c84b9fea2 fastboot: add a wipe-super command.
Usage: fastboot wipe-super [super_empty.img]

This command will read the given super_empty.img (using the default one
in ANDROID_PRODUCT_OUT if not specified), and flash by generating a
temporary super.img with no partition data. This command will even work
on retrofit devices.

This command is intended to be used either during device bringup or with
scripts that will manually flash individual dynamic partitions, in place
of using "fastboot flashall".

Bug: 136282057
Test: fastboot wipe-super on retrofit and non-retrofit device
Change-Id: Icab368a63ff36fcce9ac9304eb3966dd38bd78c4
2019-06-28 21:09:03 +00: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
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
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
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
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
f238d8751b Modernize fastboot output format.
After:

  --------------------------------------------
  Bootloader Version...: 0.5
  Baseband Version.....: 0.5
  Serial Number........: serialv1.0
  --------------------------------------------
  Checking product                                   OKAY [  0.032s]
  Sending 'boot' (9962 KB)                           OKAY [  0.350s]
  Writing 'boot'                                     OKAY [  0.143s]
  Sending 'dts' (14 KB)                              OKAY [  0.068s]
  Writing 'dts'                                      OKAY [  0.048s]
  Sending sparse 'system' 1/2 (460796 KB)            OKAY [ 14.383s]
  Writing sparse 'system' 1/2                        OKAY [  4.138s]
  Sending sparse 'system' 2/2 (443712 KB)            OKAY [ 13.871s]
  Writing sparse 'system' 2/2                        OKAY [  3.246s]
  Rebooting
  Finished. Total time: 36.962s

For a failure:

  extracting android-info.txt (0 MB) to RAM...
  --------------------------------------------
  Bootloader Version...: 0.5
  Baseband Version.....: 0.5
  Serial Number........: serialv1.0
  --------------------------------------------
  Checking product                                   FAILED

  Device product is 'hikey960'.
  Update requires 'marlin' or 'sailfish'.

  fastboot: error: requirements not met!

This change also adds a -v/--verbose flag, but doesn't make much use of
it yet (http://b/30953083 will need it).

Bug: N/A
Test: manual
Change-Id: I7d19f5775859ffad5f3be5707b37dcb6e180917f
2018-04-02 11:01:48 -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
b3748de33f Move fastboot to C++.
Minimal conversion.

Change-Id: I32cbf125be481a8757720d10fa303c38a7fd5e38
2015-06-23 20:56:01 -07:00
Renamed from fastboot/util.c (Browse further)