Commit graph

309 commits

Author SHA1 Message Date
Greg Kaiser
dc9b62ba74 fastboot: Don't leak file in error case
This is probably not very significant in this standalone tool,
but makes it easier for us to find leaks in our other system
code via static analysis.

(cherry-pick of 407a2195391685627e6be947491041ae3c8cbe61.)

Change-Id: I4e14cadc1e53bac0848e0e0c7f531f920e43cb0a
2016-08-12 08:57:22 -07:00
Treehugger Robot
4efbce14b5 Merge "Fix clang-tidy performance warnings in syste/core." 2016-08-01 20:13:54 +00:00
Chih-Hung Hsieh
8f7b9e3d39 Fix clang-tidy performance warnings in syste/core.
* Use const reference type for parameters to avoid unnecessary copy.
* Suppress warning of not using faster overloaded string find function.

Bug: 30407689
Bug: 30411878
Change-Id: I6cfdbbd50cf5e8f3db6e5263076d3a17a9a791ee
Test: build with WITH_TIDY=1
Merged-In: Ie79dbe21899867bc62031f8618bb1322b8071525
2016-08-01 11:55:42 -07:00
Chih-Hung Hsieh
034c475931 Fix google-explicit-constructor warnings in system/core.
* Declare explicit conversion constructors.
* Add NOLINT for implicit conversion constructors.
* Fix also some misaligned indendations.

Bug: 28341362
Change-Id: Idf911f35923b408d92285cc1a053f382ba08c63e
Test: build with clang-tidy
2016-07-26 11:26:01 -07:00
Elliott Hughes
749ae2d32f Remove unnecessary ARRAY_SIZE macros.
Use the canonical one instead.

Change-Id: Id80f19455f37fd2a29d9ec4191c1a0af80c5c0e7
2016-06-28 14:48:45 -07:00
Chih-Hung Hsieh
cdb2ca5d9f Fix misc-macro-parentheses warnings in system/core.
Add parentheses around macro arguments used beside operators.
Bug: 28705665

Change-Id: I9226f319e283be640eddc31687f75b51a8ef0ac6
2016-06-22 14:33:13 -07:00
Elliott Hughes
53ec495b40 Report errno more often in fastboot.
Change-Id: I4b4b47c584a146b38876a379f26ceb20d071c643
2016-05-11 12:39:27 -07:00
Chih-hung Hsieh
7bdd6a8b5a Merge "Fix google-explicit-constructor warnings." 2016-04-30 05:10:05 +00:00
Chih-Hung Hsieh
1c563d96f0 Fix google-explicit-constructor warnings.
Bug: 28341362
Change-Id: I4504e98a8db31e0edcbe63c23f9af43eb13e9d86
2016-04-29 15:44:04 -07:00
Elliott Hughes
2810d00dd9 Use more std::string in fastboot.
Change-Id: Ic8c77eac1e0088627ab650050d9c97c5749e5c39
2016-04-29 08:30:13 -07:00
Raja M
79bf64dc66 GCC compiler warning fix for sprintf into snprintf
To fix GCC WARNINGS while building.
or
To support error free -D_FORTIFY_SOURCE=2 strict mode compilation.
2016-04-24 09:44:04 +05:30
Alex Deymo
f62d0cd943 fastboot: Minor fix to help text.
Help text had some missing end of line markers.

Bug: None
TEST=make out/host/linux-x86/bin/fastboot; fastboot

Change-Id: Iaa9e4e0a2d70c7d427f5e99e72fe1c2e2c26ee92
2016-03-24 19:51:05 -07:00
Ying Wang
71edfc8b9a Also archive adb.exe/fastboot.exe when building win_sdk.
On linux we archive both Linux and Windows binaries.

Bug: 27315911
Change-Id: I17d25cd1ea611a9c917f1e78b47f21a8959eea20
2016-02-29 19:27:06 -08:00
James Hawkins
588a2cad7f system/core: Cleanup direct calls to opendir by containing in a
std::unique_ptr.

Bug: 26643633
Change-Id: Ia3491fdbff086558da694ae949cf08e4c89d0307
2016-02-18 14:52:46 -08:00
David Pursell
aad72a533f fastboot: fix TCP protocol version check.
Currently the TCP handshake fails if the device TCP protocol version
doesn't match the host exactly, but the protocol is supposed to allow
for forwards compatibility by accepting any protocol version >= itself.
That way the other side can potentially lower its protocol to match and
keep going.

This CL fixes the protocol version check and adds corresponding unit
tests.

Bug: http://b/27220700
Change-Id: Ib17f0a55eb910105a27609bc94bf76a30442e92e
2016-02-17 10:00:09 -08:00
David Pursell
4601c978ca fastboot: add UDP protocol.
Implements a UDP protocol for fastboot, documented in
fastboot_protocol.txt.

This version of the protocol does not include multi-packet windowing,
which will likely be needed to achieve reasonable speeds over WiFi.
Since we don't have any WiFi use cases yet, we'd like to get this in
now and update the protocol later if it becomes necessary.

Usage:
  fastboot -s udp:<hostname>[:port] <command>

Bug: http://b/26154914
Change-Id: Ia5bbae6bcd6405671f594d7120b3994746d234d3
2016-02-10 10:21:30 -08:00
David Pursell
c742a7f174 fastboot: add Socket timeout detection.
UDP fastboot will require re-transmission in the case of datagrams
getting lost. This CL adds Socket functionality to easily distinguish
between a normal timeout and a socket failure.

I also found some Windows docs that indicate sockets may become
invalid after a call to recv() times out. This has never occurred in
my testing, but to be safe this switches the timeout implementation
to use select() instead of SO_RCVTIMEO.

Bug: http://b/26154914
Change-Id: Id7b598f8aea5df1a3676d24702b489042d5f9e3a
2016-02-05 13:22:06 -08:00
Elliott Hughes
d505cd8db2 Fix the version number in the fastboot documentation.
Bug: https://code.google.com/p/android/issues/detail?id=65414
Change-Id: Ia52101f7c8d59e79583fd9658e001648ff545c66
2016-02-03 14:30:01 -08:00
David Pursell
2ec418a4c9 fastboot: add TCP protocol.
This CL implements a TCP protocol for use with fastboot. Protocol
description is given in fastboot_protocol.txt, some examples of
expected behavior can also be found in tcp_test.cpp.

Usage is:
  fastboot -s tcp:<hostname>[:port] <command>

Bug: http://b/26558551
Change-Id: If53a514a534489c617db32c4fea8819949121282
2016-02-03 13:57:45 -08:00
David Pursell
2c094f7983 fastboot: fix SocketMock send failures.
Fixes SocketMock::ExpectSendFailure() to allow unit testing of errors
during send, and adds tests for ExpectSendFailure() and
AddReceiveFailure().

Also adds missing tests to make sure ReceiveAll() continues to read
until failure or all bytes have been read.

Bug: http://b/26157893
Change-Id: I67e7d6de8e8ec4a3b62a6b7d7217f7530862edf7
2016-02-03 10:43:01 -08:00
David Pursell
b34e4a06ee libcutils/fastboot: improve multi-buffer write.
Fixes libcutils multi-buffer write interface to be more friendly and
hooks into it from the fastboot Socket class.

Bug: http://b/26558551
Change-Id: Ibb3a8428fc379755602de52722c1260f9e345bc0
2016-02-03 10:01:38 -08:00
David Pursell
c3a466960f fastboot: socket testing improvements.
(This code was originally part of a huge fastboot CL but has been split
out to try to make the CLs a little more manageable).

More prep for fastboot TCP and UDP implementations. This CL adds a
SocketMock class that makes it easy to mock out network behavior so we
can unit test the TCP and UDP protocols.

Also uses the new libcutils socket_get_local_port() to avoid hardcoding
a server port in unit tests.

Bug: http://b/26157893.
Change-Id: I1ba10f31e98d7349313fc15f240383d63378a8db
2016-02-02 11:29:10 -08:00
David Pursell
572bce2908 fastboot: use cutils socket functions.
Now that cutils has cross-platform socket functionality, we can
restructure fastboot to remove platform-dependent networking code.

This CL adds socket_set_receive_timeout() to libcutils and combines the
fastboot socket code into a single implementation. It also adds TCP
functionality to fastboot sockets, but nothing uses it yet except for
the unit tests. A future CL will add the TCP protocol which will use
this TCP socket implementation.

Bug: http://b/26558551

Change-Id: If613fb348f9332b31fa2c88d67fb1e839923768a
2016-01-21 09:53:11 -08:00
David Pursell
1906de1e0f Merge "libcutils: share Windows networking code." 2016-01-21 16:40:00 +00: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
Josh Gao
cb73db7cd8 fastboot: add .clang-format.
Change-Id: Iacad00adfa3948118543d680651814b3c8c42858
2016-01-19 14:49:45 -08:00
David Pursell
0eb8e1b706 libcutils: share Windows networking code.
This CL moves Windows networking code from fastboot to libcutils so
that it can be shared with other host programs such as adb.

Not all libcutils networking functions have been implemented for
Windows, just those necessary for fastboot. In the next CL I will do
the same for adb, adding any additional required functions.

Unit tests have also been added to test the functions using a loopback
connection.

Bug: http://b/26236380.
Change-Id: Ibc51a67030fe69a04c23512eefa9d19b055c7c12
2016-01-15 15:57:35 -08:00
Daniel Rosenberg
c1743ba0d4 fastboot: Add "--slot other"
This allows you to flash to a slot other than the current one
without needing to enter the name of the slots.

Change-Id: I6bf8c29817be0a29b1abb005f1e72056cee126df
2016-01-06 19:42:01 +00:00
Daniel Rosenberg
15174d9bc7 fastboot: correct set_active behavior
Removed automatic reboot attached to set_active,
and fixed documentation error.

Change-Id: Idbb1639dc80870c17a6622dc78a7d78c88e268ab
2016-01-05 19:35:54 -08:00
David Pursell
815c7beae7 fastboot: implement UDP networking interface.
This CL creates a UdpSocket class that provides a simple unified
interface to send and receive UDP packets for all platforms. Nothing
uses this interface yet except for tests.

The eventual goal is to implement a UDP protocol for fastboot, but it
makes the code much simpler and more modular if we handle the low-level
networking here independently of our custom fastboot protocol.

Some of the Windows code is similar to adb. I'd like to create a
library to hold the common functionality, but it is going to be a
little delicate to separate out the features unique to adb (e.g. the
custom file descriptor system), and I don't want to risk breaking
something in adb before the holiday break, so I'm hoping to get this in
for now and merge them early next year.

Tests are included in this CL to exercise this functionality using a
loopback connection.

Bug: http://b/26154763.
Tests: `fastboot_test` loopback tests on Linux, Mac, and Windows 7.
Change-Id: I81d1b7ace8d864246b99f6c80b8e29f64b8aa375
2015-12-16 16:16:08 -08:00
Elliott Hughes
1b708d368f Share the new adb USB diagnostic code with fastboot.
Bug: http://b/26134129
Change-Id: Ieaf0651c7b3f8a028760982091ec63a21a5484ba
2015-12-14 10:50:21 -08:00
Elliott Hughes
44b6aefeeb Remove fastboot/genkey.sh.
Some unknown cruft from the pre-cupcake era.

Change-Id: I8964892419cda9781d1506aa7006c51dc00ca33d
2015-12-11 17:57:53 -08:00
Daniel Rosenberg
98a8257313 Merge "fastboot: Re-add set_active as a command." 2015-12-10 00:54:01 +00:00
Daniel Rosenberg
9b432054dc fastboot: Re-add set_active as a command.
It turns out that adding a -- allows suffixes
starting with - to work fine, and there are
edge cases where calling set_active twice in
a command is useful, so the command version
has been re-added.

Change-Id: I528c258bf23ade61db530eb27586c1a1721896bc
2015-12-07 13:42:48 -08:00
Elliott Hughes
4f71319df0 Track rename of base/ to android-base/.
Change-Id: Idf9444fece4aa89c93e15640de59a91f6e758ccf
2015-12-04 22:00:26 -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
44c58471e4 Merge "Revert "fastboot: create Transport object."" 2015-11-14 00:18:43 +00: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
f131772a79 Merge "fastboot: create Transport object." 2015-11-13 22:49:08 +00:00
Daniel Rosenberg
996ecd8b7d Fix fastboot to not add '-' before suffix
Change-Id: I9351b385412151498f47ab46a2620f21b9ac38b8
2015-11-13 12:56:19 -08: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
8336a96c9c Merge changes I8fb6b513,I6dd16245,I0c2753e2
* changes:
  Update fastboot help command with long options
  Changed set_active to be a flag
  Fix fastboot variable name
2015-11-12 23:22:00 +00:00
Elliott Hughes
a2db2618ec Cope with angler's whitespace-padded partition size reporting.
Before:

  $ fastboot -w
  wiping userdata...
  Couldn't parse partition size '0x        0x66257ee00'.
  wiping cache...
  Couldn't parse partition size '0x        0x6400000'.
  erasing 'userdata'...

Bug: http://b/25653580
Change-Id: I301b8410689c1e52681796c240a149d270360edf
2015-11-12 07:28:39 -08:00
Daniel Rosenberg
7aa38bc54c Update fastboot help command with long options
Change-Id: I8fb6b5139f81893b324202d4c68f29393213ee6f
2015-11-11 20:27:56 -08:00
Daniel Rosenberg
0d08856416 Changed set_active to be a flag
set_active must be able to accept flag like arguments

Change-Id: I6dd162453835d2d64fd8d877f2a7b98e8dd8a907
2015-11-11 20:27:50 -08:00
Daniel Rosenberg
a797479bd5 Fix fastboot variable name
Change-Id: I0c2753e2b79d715f227ee314c071ce68d91779b3
2015-11-11 20:27:43 -08:00
Elliott Hughes
c1fd492ac5 Revert "Revert "adb/base: fix adb push of Unicode filenames on Win32""
This reverts commit cc8cd59456.

With the dependency on libcutils (for gettid for non-bionic) removed,
this no longer breaks the build.

Change-Id: I645bd6876e2502ddc1535b69af1e645c0df9d178
2015-11-11 18:23:00 -08:00
Elliott Hughes
cc8cd59456 Revert "adb/base: fix adb push of Unicode filenames on Win32"
This reverts commit ac9514a452.

The new gettid dependency caused other breakage.

Change-Id: I74a75e40c30a45beb275f9dd38eb5c7beac15fbd
2015-11-11 18:01:12 +00:00
Spencer Low
ac9514a452 adb/base: fix adb push of Unicode filenames on Win32
ae5a6c06cd made adb push use
android::base::ReadFileToString() for small files, but that API did not
support UTF-8 filenames on Windows, until this fix which does the
following:

- Add android::base::{WideToUTF8,UTF8ToWide}() which are only available
  on Windows. The signatures are based on Chromium's APIs of the same
  name.

- Add the namespace android::base::utf8 which has versions of APIs that
  take UTF-8 strings. To use this, make sure your code is in a namespace
  and then do "using namespace android::base::utf8;". On Windows, this will
  make calls to open() call android::base::utf8::open(), and on other
  platforms, it will just call the regular ::open().

- Make ReadFileToString() and WriteStringToFile() use utf8::open() and
  utf8::unlink().

- Adapt unittests from Chromium.

- fastboot needs to link with libcutils because it links with libbase
  which depends on libcutils for gettid() for logging.

Change-Id: I1aeac40ff358331d7a1ff457ce894bfb17863904
Signed-off-by: Spencer Low <CompareAndSwap@gmail.com>
2015-11-10 15:48:54 -08:00
Daniel Rosenberg
f8e70a3a60 Merge "Fastboot changes to support A/B partitioning" 2015-11-06 03:43:49 +00:00