Commit graph

56 commits

Author SHA1 Message Date
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
Chris Fries
0ea946c007 fastboot: Support larger transfers during flash
Adding methods to queue and download flashable images by fd instead of
by pointer, so that we can deal with sending large (up to 4GB) files
on windows and linux.  This gets past limitations on linux to read
more than 2GB from a file at a time, as well as memory limitations
on win32, in order to download up to 4GB in a single transfer.

Test: fastboot -w
Test: "flash-all" from nexus factory images site (incl. fastboot -w update)
Test: fastboot flash with large and small image, large and small max-download-size
Test: Sanity check flashing on win32, darwin, linux.
Test: Sanity check 3GB image download (with 3GB max-download-size)
      on win32, darwin, linux.

Bug: 36810152
Change-Id: I528d739d344eb080d59d721dadf3b3b34d4b375e
2017-04-17 09:22:49 -05:00
Chris Fries
6a99971096 fastboot: Cap max size sent to libsparse
This is required for large (>INT_MAX) sparse limit reported by
the target.

Also, patch up return chains of "int" that need to deal with sizes
bigger than 2GB as well as return negative error codes.

Test: -S works with large max-download-size
Test: Flash 3GB system.img with max-download-size 2.5GB

Bug: 36810152
Change-Id: I562a50eabd706bd5b97c71a1aef07c1ffd1a2e5c
2017-04-14 15:44:20 -05:00
Elliott Hughes
82ff315bb0 Add android::base::GetExecutablePath, switch adb and fastboot over.
We'd long had two copies of this stuff, so rather than rewrite both
Linux versions to use android::base::Readlink, let's kill the duplication
too...

Bug: http://b/30988271
Change-Id: I4de58a94a22a4b1faf969a6fc70ca1560a4d5121
2016-09-01 09:24:24 -07:00
Elliott Hughes
2810d00dd9 Use more std::string in fastboot.
Change-Id: Ic8c77eac1e0088627ab650050d9c97c5749e5c39
2016-04-29 08:30:13 -07:00
Josh Gao
9da9ac5b2a fastboot: show progress when sending sparse images.
Bug: http://b/25443220
Change-Id: Ica0c88aea2a0661f39ff1415ebba464c037651da
2016-01-19 14:50:18 -08:00
David Pursell
0b15663830 fastboot: create Transport object (take 2).
(Second upload of this CL; original upload had the wrong version of
usb_windows.cpp that caused a compilation error. Fixed error and
re-tested.)

This CL creates a Transport object to provide a generic interface for
various transports. Specifically this is designed to be able to add UDP
support to fastboot in an upcoming CL without changing the main program
logic.

Also includes some minor code style fixes and replaces malloc/free
in the USB implementation files with smart pointers and std::string.

Bug: http://b/22029765
Change-Id: I1175bbce08690fbd15f51e68166be9b3e9973ea0
2015-11-16 09:31:07 -08:00
David Pursell
c0504e1873 Revert "fastboot: create Transport object."
This broke some stuff, will look into it Monday.

This reverts commit 6f233a7799.

Change-Id: I155bc85d21fda3b0ba1e5e17839059797fb15509
2015-11-14 00:15:57 +00:00
David Pursell
6f233a7799 fastboot: create Transport object.
This CL creates a Transport object to provide a generic interface for
various transports. Specifically this is designed to be able to add UDP
support to fastboot in an upcoming CL without changing the main program
logic.

Also includes some minor code style fixes and replaces malloc/free
in the USB implementation files with smart pointers and std::string.

Bug: http://b/22029765
Change-Id: I68641af0da7d13db4647f5e20a18d04d67f0b327
2015-11-13 11:08:17 -08:00
Daniel Rosenberg
b7bd4ae529 Fastboot changes to support A/B partitioning
Introduce support for -slot option for specifying slots,
and set_active, for changing the current slot.
Change-Id: Ib3b2a75491c0d0413534dd0c1d7bcb52555bba66
2015-11-05 18:07:46 -08:00
Elliott Hughes
8ab9a32323 Clarify and fix the intent of the partition-type checking code.
Change-Id: I202dab4ee91208b632bc2086d1e5c387a4c29edd
2015-11-02 14:05:57 -08:00
Elliott Hughes
2fd45a9cea fastboot shouldn't erase non-existent cache partitions.
Check that the cache partition exists before trying to erase it.

Also clean up some of the C string handling and int booleans.

Bug: http://b/25375777
Change-Id: I1880e542b729f2026ab3a2943d4bee9d659b1eeb
2015-10-30 14:15:22 -07:00
Elliott Hughes
fc79767fc2 Use 64-bit file sizes in fastboot.
Bug: 20110580
Change-Id: I5d3718103ff581ff3b5241c8b0e52b585b4f37e5
2015-08-25 19:11:52 -07:00
Narayan Kamath
f6e9ffbc73 Fix file descriptor leak when opening invalid archives.
Also add -Wunreachable-code to the set of compiler flags, otherwise
noreturn becomes considerably less useful.

bug: https://code.google.com/p/android/issues/detail?id=171099
Change-Id: I9a95d45633c731c7046d4e4a39844d9cebfd1718
(cherrypick of 241bcf05e0e394bbf2681f359f52646dd6c707f6.)
2015-06-03 12:16:43 -07:00
Elliott Hughes
253c18d2fb Prepare for switching to libziparchive.
Bug: 19765860
Change-Id: I58249d28fbc4975428d0dcac5107d1994c35676c
2015-03-18 22:47:54 -07:00
Alexander Levitskiy
8d7ddb35d5 Revert "System: Fastboot: warning fixit, misc bugs and cleanup."
This reverts commit 782111b3bc.

Change-Id: Ib66400dfaeef7f01e6461a57b9f09be08de2f1fe
2014-05-07 23:31:59 +00:00
Sasha Levitskiy
782111b3bc System: Fastboot: warning fixit, misc bugs and cleanup.
Change-Id: Ib8517a852977962de3f05c879ba7dce89bcef644
Signed-off-by: Sasha Levitskiy <sanek@google.com>
2014-05-07 11:43:12 -07:00
JP Abgrall
7e85974fc2 fastboot: support for overriding format fs-type and size
This changes allows overriding the fs-type and size that
are normally returned by the booloader.

This is in preparation for supporting other FSes.

Change-Id: I8d141a0d4d14df9fe84d3b131484e9696fcd8870
Signed-off-by: JP Abgrall <jpa@google.com>
2014-05-06 15:14:15 -07:00
Dmitry Grinberg
e6f3e9bd26 fastboot: allow format on devices with small buffers
Formatting large partitions on devices with small transfer buffers did
not work before since format used a strange path through the code to
send data. It now uses the normal path. Also cleaned up a bit. FS
code now lives in a separate file and the custom path for format is
gone.

Change-Id: If4e01cabc2e250b7c02ca7ce8c268e51d49e1529
2014-05-06 12:28:37 -07:00
Mark Wachsler
157b00171a Wait for device to disappear after reboot-bootloader.
(Linux only for now) With fastboot reading serial numbers from sysfs, it had
become possible for a fastboot command issued immediately after rebooting
the bootloader to fail, because sysfs still thought the device was online.
To prevent this, after reboot-bootloader we wait for the device to disconnect.

Also made usb_read and usb_write fail immediately if the descriptor has been
closed; this prevents an incorrect error message ("Bad file descriptor")
when errors from fb_getvar are ignored (e.g., by fb_format_supported).

Also removed unused fd param from filter_usb_device, and simplified logic
in usb_write by using do/while instead of a special case for len == 0.

Change-Id: I799b857eab411fd8ad25f5777fc61c685152ea86
2013-10-17 20:06:32 +00:00
Ken Sumrall
5ee5d389d6 Update fastboot to wipe ext4 partitions before flashing
To prevent false error reports from e2fsck, update fastboot to erase
a partition identified as being ext4 partition before flashing an image
to it.

bug: 7259359

Change-Id: I85e9963aa8247b4b33fdd57f994cdb3ee72b670f
2012-10-02 19:10:51 -07:00
Colin Cross
9a70e5c338 resolved conflicts for merge of 4d72d881 to master
Change-Id: Ic092d27d3fc2bcc4db8a375bbcb5b86c111bf062
2012-07-17 23:35:49 -07:00
Colin Cross
f838788e6a fastboot: add support for auto-resparsing large files
Add support to fastboot for automatically using libsparse to break large
files, whether they are in sparse or normal format, into multiple sparse
files that can each fit into the target's memory.  Allows flashing
images that are larger than the size of the available memory on the
target.

By default, any file over 512MB will be sparsed into 512MB chunks.  The
limit can be modified with the -m argument, or sparsing can be forced
with -S or avoided with -N.  If -m is not specified, the target can
override the default by implementing getvar:max-download-size

Change-Id: I6c59381c3d24475c4f2587ea877200b96971cbd7
2012-07-09 22:17:58 -07:00
Colin Cross
80f2d036a9 fastboot: add fb_getvar
Add an fb_getvar helper that can be used to get values from the
target.

Change-Id: I0da088fcbc8d40076c7bf5ef6e5bbd97fae61471
2012-07-09 22:16:57 -07:00
JP Abgrall
3447b11d3e am 177a74ac: am c1f88106: Merge "fastboot: Change -w to format after the erase of userdata & cache" into jb-dev
* commit '177a74aced971b89c319fb61ee12da0ca40f0c12':
  fastboot: Change -w to format after the erase of userdata & cache
2012-05-14 08:35:13 -07:00
JP Abgrall
30ae5806e9 fastboot: Change -w to format after the erase of userdata & cache
If the bootloader doesn't support formatting of those partitions
(either because it doesn't support the getvar commands needed or
the partition type is not supported), the errors are printed but
doesn't halt processing of subsequent commands.

Change-Id: I816ac2e5e7593846fcb4fd39c793a8dbdd996f6f
Signed-off-by: Mike J. Chen <mjchen@google.com>
2012-05-07 20:25:24 -07:00
Scott Anderson
a61bcad58b resolved conflicts for merge of 13081c69 to master
Change-Id: I631e466fc53e9b0f4a39f24f959b4ae9b626bdda
2012-05-01 18:34:22 -07:00
Scott Anderson
13081c6915 fastboot: Add ability to specify device path
For manufacturing and testing, there is a need to talk to
whatever device is connected to a given port on the host.  This
change modifies fastboot's "-s" option to take either a serial
number or a device path.  The device paths of the connected
devices can be listed using "fastboot -l devices" whose output
will resemble:

    016B75D60A00600D	usb:2-5	fastboot
    AD3C12020173	usb:1-4.3	fastboot

The second column lists the device paths.  If the -l option is
not given, the output from "fastboot devices" will be the same as
it used to be (i.e. the paths will not be printed).

Finally, note that the format of the device paths are platform
dependent.  The example above is from Linux.  On OS-X, the paths
will be "usb:" followed by hex digits.  For Windows, the device
paths will be printed as "????????????" and the -s option will
not be able to select a device until someone implements the
underlying functionality in usb_windows.c.

Change-Id: I1f01b8f47acd32edb0ac18db107316a2c923bbde
Signed-off-by: Scott Anderson <saa@android.com>
2012-04-19 11:59:09 -07:00
Anatol Pomazau
5ae3f93f3b Remove trailing whitespaces
Change-Id: I6f83333a6ee0fbc562a12bb9555c43a44c98768e
2012-02-28 07:21:08 -08:00
Anatol Pomazau
c8ba5366da Implement 'fastboot format' command
Some filesystems (e.g. ext4) require flushing an initial
fs image, right after erasing it the partition is unusable.

Doing erase,flush emptyfs is a little bit scaring so we have a
separate command that performs it as atomic step:

 - get size of partition
 - create an empty filesystem image
 - erase the partition
 - flush empty fs to the partition

This command applicable only for ext4 filesystem and checks the
partition type before formatting it.

Change-Id: I8529bc3485739487f0d91312f7c0ab1a6e5d8b44
2012-02-17 16:29:58 -08:00
Mike J. Chen
714052ba4d DO NOT MERGE
fastboot: Change -w to format after the erase of userdata & cache

If the bootloader doesn't support formatting of those partitions
(either because it doesn't support the getvar commands needed or
the partition type is not supported), the errors are printed but
doesn't halt processing of subsequent commands.

Change-Id: I816ac2e5e7593846fcb4fd39c793a8dbdd996f6f
Signed-off-by: Mike J. Chen <mjchen@google.com>
2012-02-16 09:32:42 -08:00
Mike Lockwood
ca2074b78d Revert "Implement 'fastboot format' command"
until Windows support is done

This reverts commit 452e11885a.
2012-02-13 09:57:19 -08:00
Anatol Pomazau
452e11885a Implement 'fastboot format' command
Some filesystems (e.g. ext4) require flushing an initial
fs image, right after erasing it the partition is unusable.

Doing erase,flush emptyfs is a little bit scaring so we have a
separate command that performs it as atomic step:

 - get size of partition
 - create an empty filesystem image
 - erase the partition
 - flush empty fs to the partition

This command applicable only for ext4 filesystem and checks the
partition type before formatting it.

Change-Id: Ifa42deaa66c3cb96ff786a73c3fadad92658f395
2012-02-11 11:02:40 -08:00
Anatol Pomazau
6f53225ef9 Revert "Implement 'fastboot format' command"
This reverts commit 230d160a71
2012-02-03 18:20:02 -08:00
Anatol Pomazau
230d160a71 Implement 'fastboot format' command
Some filesystems (e.g. ext4) require flushing an initial
fs image, right after erasing it the partition is unusable.

Doing erase,flush emptyfs is a little bit scaring so we have a
separate command that performs it as atomic step:

 - get size of partition
 - create an empty filesystem image
 - erase the partition
 - flush empty fs to the partition

This command applicable only for ext4 filesystem and checks the
partition type before formatting it.

Change-Id: I8529bc1dc64237f1f0d91312f7c0ab1a6e5d8b44
2012-02-03 16:07:18 -08:00
Anatol Pomazau
21311f87c6 Revert "Implement 'fastboot format' command"
This reverts commit 049dff53ef
2012-02-03 10:57:46 -08:00
Anatol Pomazau
65cf84f3ff Implement 'fastboot format' command
Some filesystems (e.g. ext4) require flushing an initial
fs image, right after erasing it the partition is unusable.

Doing erase,flush emptyfs is a little bit scaring so we have a
separate command that performs it as atomic step:

 - get size of partition
 - create an empty filesystem image
 - erase the partition
 - flush empty fs to the partition

This command applicable only for ext4 filesystem and checks the
partition type before formatting it.

Change-Id: I8529bc1dc64698f1f0d91312f7c0ab1a6e5d8b44
2012-02-03 10:29:56 -08:00