summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorAaron Wisner2018-08-01 12:57:20 -0500
committerAaron Wisner2018-08-02 17:47:38 -0500
commitc771ae0fd432f33d6916c72bf9f7824edfffbd38 (patch)
treec2dcd5b9d7e26153383ed62db58fce81621480a2
parent081b710b2ee7f726f1bef282333c397006b6b37f (diff)
downloadplatform-system-core-c771ae0fd432f33d6916c72bf9f7824edfffbd38.tar.gz
platform-system-core-c771ae0fd432f33d6916c72bf9f7824edfffbd38.tar.xz
platform-system-core-c771ae0fd432f33d6916c72bf9f7824edfffbd38.zip
Minor fixes to fastboot_driver
- Make RCString() static - Add clearer error message for 0 length upload error - Fix regex hex matching for partition-size - Move ZLP packet checking to SparseWriteCallback() Test: build fastboot on glinux Change-Id: I51a040e07b9698a41f64b35a9e2baa8d575527a9
-rw-r--r--fastboot/fastboot_driver.cpp17
-rw-r--r--fastboot/fastboot_driver.h2
2 files changed, 12 insertions, 7 deletions
diff --git a/fastboot/fastboot_driver.cpp b/fastboot/fastboot_driver.cpp
index aabc620d4..55ca65d3f 100644
--- a/fastboot/fastboot_driver.cpp
+++ b/fastboot/fastboot_driver.cpp
@@ -134,7 +134,7 @@ RetCode FastBootDriver::Partitions(std::vector<std::tuple<std::string, uint32_t>
134 return ret; 134 return ret;
135 } 135 }
136 136
137 std::regex reg("partition-size[[:s:]]*:[[:s:]]*([[:w:]]+)[[:s:]]*:[[:s:]]*0x([[:d:]]+)"); 137 std::regex reg("partition-size[[:s:]]*:[[:s:]]*([[:w:]]+)[[:s:]]*:[[:s:]]*0x([[:xdigit:]]+)");
138 std::smatch sm; 138 std::smatch sm;
139 139
140 for (auto& s : all) { 140 for (auto& s : all) {
@@ -264,11 +264,16 @@ RetCode FastBootDriver::Upload(const std::string& outfile, std::string* response
264 std::vector<std::string>* info) { 264 std::vector<std::string>* info) {
265 RetCode ret; 265 RetCode ret;
266 int dsize; 266 int dsize;
267 if ((ret = RawCommand(Commands::UPLOAD, response, info, &dsize)) || dsize == 0) { 267 if ((ret = RawCommand(Commands::UPLOAD, response, info, &dsize))) {
268 error_ = "Upload request failed"; 268 error_ = "Upload request failed: " + error_;
269 return ret; 269 return ret;
270 } 270 }
271 271
272 if (!dsize) {
273 error_ = "Upload request failed, device reports 0 bytes available";
274 return BAD_DEV_RESP;
275 }
276
272 std::vector<char> data; 277 std::vector<char> data;
273 data.resize(dsize); 278 data.resize(dsize);
274 279
@@ -462,10 +467,10 @@ RetCode FastBootDriver::SendBuffer(const std::vector<char>& buf) {
462} 467}
463 468
464RetCode FastBootDriver::SendBuffer(const void* buf, size_t size) { 469RetCode FastBootDriver::SendBuffer(const void* buf, size_t size) {
470 // ioctl on 0-length buffer causes freezing
465 if (!size) { 471 if (!size) {
466 return SUCCESS; 472 return BAD_ARG;
467 } 473 }
468
469 // Write the buffer 474 // Write the buffer
470 ssize_t tmp = transport->Write(buf, size); 475 ssize_t tmp = transport->Write(buf, size);
471 476
@@ -521,7 +526,7 @@ int FastBootDriver::SparseWriteCallback(std::vector<char>& tpbuf, const char* da
521 // Now we need to send a multiple of chunk size 526 // Now we need to send a multiple of chunk size
522 size_t nchunks = (len - total) / TRANSPORT_CHUNK_SIZE; 527 size_t nchunks = (len - total) / TRANSPORT_CHUNK_SIZE;
523 size_t nbytes = TRANSPORT_CHUNK_SIZE * nchunks; 528 size_t nbytes = TRANSPORT_CHUNK_SIZE * nchunks;
524 if (SendBuffer(data + total, nbytes)) { 529 if (nbytes && SendBuffer(data + total, nbytes)) { // Don't send a ZLP
525 error_ = ErrnoStr("Send failed in SparseWriteCallback()"); 530 error_ = ErrnoStr("Send failed in SparseWriteCallback()");
526 return -1; 531 return -1;
527 } 532 }
diff --git a/fastboot/fastboot_driver.h b/fastboot/fastboot_driver.h
index 9fdd31700..e8711cba2 100644
--- a/fastboot/fastboot_driver.h
+++ b/fastboot/fastboot_driver.h
@@ -103,7 +103,7 @@ class FastBootDriver {
103 103
104 /* HELPERS */ 104 /* HELPERS */
105 void SetInfoCallback(std::function<void(std::string&)> info); 105 void SetInfoCallback(std::function<void(std::string&)> info);
106 const std::string RCString(RetCode rc); 106 static const std::string RCString(RetCode rc);
107 std::string Error(); 107 std::string Error();
108 RetCode WaitForDisconnect(); 108 RetCode WaitForDisconnect();
109 109