summaryrefslogtreecommitdiffstats
path: root/fastboot
diff options
context:
space:
mode:
Diffstat (limited to 'fastboot')
-rw-r--r--fastboot/device/usb_client.cpp2
-rw-r--r--fastboot/fastboot.cpp6
-rw-r--r--fastboot/fuzzy_fastboot/fixtures.cpp15
-rw-r--r--fastboot/fuzzy_fastboot/fixtures.h3
-rw-r--r--fastboot/fuzzy_fastboot/main.cpp55
5 files changed, 59 insertions, 22 deletions
diff --git a/fastboot/device/usb_client.cpp b/fastboot/device/usb_client.cpp
index 5921df958..101429134 100644
--- a/fastboot/device/usb_client.cpp
+++ b/fastboot/device/usb_client.cpp
@@ -33,7 +33,7 @@ constexpr int kMaxPacketSizeHs = 512;
constexpr int kMaxPacketsizeSs = 1024;
constexpr size_t kFbFfsNumBufs = 16;
-constexpr size_t kFbFfsBufSize = 32768;
+constexpr size_t kFbFfsBufSize = 16384;
constexpr const char* kUsbFfsFastbootEp0 = "/dev/usb-ffs/fastboot/ep0";
constexpr const char* kUsbFfsFastbootOut = "/dev/usb-ffs/fastboot/ep1";
diff --git a/fastboot/fastboot.cpp b/fastboot/fastboot.cpp
index 827db9671..c8caa67f4 100644
--- a/fastboot/fastboot.cpp
+++ b/fastboot/fastboot.cpp
@@ -1177,6 +1177,10 @@ static void reboot_to_userspace_fastboot() {
if (!is_userspace_fastboot()) {
die("Failed to boot into userspace fastboot; one or more components might be unbootable.");
}
+
+ // Reset target_sparse_limit after reboot to userspace fastboot. Max
+ // download sizes may differ in bootloader and fastbootd.
+ target_sparse_limit = -1;
}
class ImageSource {
@@ -1407,7 +1411,7 @@ bool LocalImageSource::ReadFile(const std::string& name, std::vector<char>* out)
int LocalImageSource::OpenFile(const std::string& name) const {
auto path = find_item_given_name(name);
- return open(path.c_str(), O_RDONLY);
+ return open(path.c_str(), O_RDONLY | O_BINARY);
}
static void do_flashall(const std::string& slot_override, bool skip_secondary, bool wipe) {
diff --git a/fastboot/fuzzy_fastboot/fixtures.cpp b/fastboot/fuzzy_fastboot/fixtures.cpp
index c23da01a2..bc13a8c4e 100644
--- a/fastboot/fuzzy_fastboot/fixtures.cpp
+++ b/fastboot/fuzzy_fastboot/fixtures.cpp
@@ -59,7 +59,7 @@ using namespace std::literals::chrono_literals;
namespace fastboot {
-int FastBootTest::MatchFastboot(usb_ifc_info* info, const char* local_serial) {
+int FastBootTest::MatchFastboot(usb_ifc_info* info, const std::string& local_serial) {
if (info->ifc_class != 0xff || info->ifc_subclass != 0x42 || info->ifc_protocol != 0x03) {
return -1;
}
@@ -68,8 +68,8 @@ int FastBootTest::MatchFastboot(usb_ifc_info* info, const char* local_serial) {
// require matching serial number or device path if requested
// at the command line with the -s option.
- if (local_serial && (strcmp(local_serial, info->serial_number) != 0 &&
- strcmp(local_serial, info->device_path) != 0))
+ if (!local_serial.empty() && local_serial != info->serial_number &&
+ local_serial != info->device_path)
return -1;
return 0;
}
@@ -113,7 +113,9 @@ void FastBootTest::SetUp() {
ASSERT_TRUE(UsbStillAvailible()); // The device disconnected
}
- const auto matcher = [](usb_ifc_info* info) -> int { return MatchFastboot(info, nullptr); };
+ const auto matcher = [](usb_ifc_info* info) -> int {
+ return MatchFastboot(info, device_serial);
+ };
for (int i = 0; i < MAX_USB_TRIES && !transport; i++) {
std::unique_ptr<UsbTransport> usb(usb_open(matcher, USB_TIMEOUT));
if (usb)
@@ -172,7 +174,9 @@ void FastBootTest::ReconnectFastbootDevice() {
;
printf("WAITING FOR DEVICE\n");
// Need to wait for device
- const auto matcher = [](usb_ifc_info* info) -> int { return MatchFastboot(info, nullptr); };
+ const auto matcher = [](usb_ifc_info* info) -> int {
+ return MatchFastboot(info, device_serial);
+ };
while (!transport) {
std::unique_ptr<UsbTransport> usb(usb_open(matcher, USB_TIMEOUT));
if (usb) {
@@ -238,6 +242,7 @@ std::string FastBootTest::device_path = "";
std::string FastBootTest::cb_scratch = "";
std::string FastBootTest::initial_slot = "";
int FastBootTest::serial_port = 0;
+std::string FastBootTest::device_serial = "";
template <bool UNLOCKED>
void ModeTest<UNLOCKED>::SetUp() {
diff --git a/fastboot/fuzzy_fastboot/fixtures.h b/fastboot/fuzzy_fastboot/fixtures.h
index 7c8d54d27..c71c89766 100644
--- a/fastboot/fuzzy_fastboot/fixtures.h
+++ b/fastboot/fuzzy_fastboot/fixtures.h
@@ -43,9 +43,10 @@ constexpr char USB_PORT_GONE[] =
class FastBootTest : public testing::Test {
public:
static int serial_port;
+ static std::string device_serial;
static constexpr int MAX_USB_TRIES = 10;
- static int MatchFastboot(usb_ifc_info* info, const char* local_serial = nullptr);
+ static int MatchFastboot(usb_ifc_info* info, const std::string& local_serial = "");
bool UsbStillAvailible();
bool UserSpaceFastboot();
void ReconnectFastbootDevice();
diff --git a/fastboot/fuzzy_fastboot/main.cpp b/fastboot/fuzzy_fastboot/main.cpp
index 7ffc7d57c..a1d69d272 100644
--- a/fastboot/fuzzy_fastboot/main.cpp
+++ b/fastboot/fuzzy_fastboot/main.cpp
@@ -162,7 +162,7 @@ const auto not_allowed = [](char c) -> int {
// Test that USB even works
TEST(USBFunctionality, USBConnect) {
const auto matcher = [](usb_ifc_info* info) -> int {
- return FastBootTest::MatchFastboot(info, nullptr);
+ return FastBootTest::MatchFastboot(info, fastboot::FastBootTest::device_serial);
};
Transport* transport = nullptr;
for (int i = 0; i < FastBootTest::MAX_USB_TRIES && !transport; i++) {
@@ -201,18 +201,28 @@ TEST_F(LogicalPartitionCompliance, GetVarIsLogical) {
ASSERT_TRUE(UserSpaceFastboot());
std::string has_slot;
EXPECT_EQ(fb->GetVar("has-slot:system", &has_slot), SUCCESS) << "getvar has-slot:system failed";
- std::string is_logical_cmd;
+ std::string is_logical_cmd_system = "is-logical:system";
+ std::string is_logical_cmd_vendor = "is-logical:vendor";
+ std::string is_logical_cmd_boot = "is-logical:boot";
if (has_slot == "yes") {
std::string current_slot;
- EXPECT_EQ(fb->GetVar("current-slot", &current_slot), SUCCESS)
+ ASSERT_EQ(fb->GetVar("current-slot", &current_slot), SUCCESS)
<< "getvar current-slot failed";
- is_logical_cmd = "is-logical:system_" + current_slot;
- } else {
- is_logical_cmd = "is-logical:system";
+ std::string slot_suffix = "_" + current_slot;
+ is_logical_cmd_system += slot_suffix;
+ is_logical_cmd_vendor += slot_suffix;
+ is_logical_cmd_boot += slot_suffix;
}
std::string is_logical;
- EXPECT_EQ(fb->GetVar(is_logical_cmd, &is_logical), SUCCESS) << "getvar is-logical failed";
- ASSERT_EQ(is_logical, "yes");
+ EXPECT_EQ(fb->GetVar(is_logical_cmd_system, &is_logical), SUCCESS)
+ << "system must be a logical partition";
+ EXPECT_EQ(is_logical, "yes");
+ EXPECT_EQ(fb->GetVar(is_logical_cmd_vendor, &is_logical), SUCCESS)
+ << "vendor must be a logical partition";
+ EXPECT_EQ(is_logical, "yes");
+ EXPECT_EQ(fb->GetVar(is_logical_cmd_boot, &is_logical), SUCCESS)
+ << "boot must not be logical partition";
+ EXPECT_EQ(is_logical, "no");
}
TEST_F(LogicalPartitionCompliance, FastbootRebootTest) {
@@ -234,16 +244,29 @@ TEST_F(LogicalPartitionCompliance, FastbootRebootTest) {
// Testing creation/resize/delete of logical partitions
TEST_F(LogicalPartitionCompliance, CreateResizeDeleteLP) {
ASSERT_TRUE(UserSpaceFastboot());
+ std::string test_partition_name = "test_partition";
+ std::string slot_count;
+ // Add suffix to test_partition_name if device is slotted.
+ EXPECT_EQ(fb->GetVar("slot-count", &slot_count), SUCCESS) << "getvar slot-count failed";
+ int32_t num_slots = strtol(slot_count.c_str(), nullptr, 10);
+ if (num_slots > 0) {
+ std::string current_slot;
+ EXPECT_EQ(fb->GetVar("current-slot", &current_slot), SUCCESS)
+ << "getvar current-slot failed";
+ std::string slot_suffix = "_" + current_slot;
+ test_partition_name += slot_suffix;
+ }
+
GTEST_LOG_(INFO) << "Testing 'fastboot create-logical-partition' command";
- EXPECT_EQ(fb->CreatePartition("test_partition_a", "0"), SUCCESS)
+ EXPECT_EQ(fb->CreatePartition(test_partition_name, "0"), SUCCESS)
<< "create-logical-partition failed";
GTEST_LOG_(INFO) << "Testing 'fastboot resize-logical-partition' command";
- EXPECT_EQ(fb->ResizePartition("test_partition_a", "4096"), SUCCESS)
+ EXPECT_EQ(fb->ResizePartition(test_partition_name, "4096"), SUCCESS)
<< "resize-logical-partition failed";
std::vector<char> buf(4096);
GTEST_LOG_(INFO) << "Flashing a logical partition..";
- EXPECT_EQ(fb->FlashPartition("test_partition_a", buf), SUCCESS)
+ EXPECT_EQ(fb->FlashPartition(test_partition_name, buf), SUCCESS)
<< "flash logical -partition failed";
GTEST_LOG_(INFO) << "Rebooting to bootloader mode";
// Reboot to bootloader mode and attempt to flash the logical partitions
@@ -252,7 +275,7 @@ TEST_F(LogicalPartitionCompliance, CreateResizeDeleteLP) {
ReconnectFastbootDevice();
ASSERT_FALSE(UserSpaceFastboot());
GTEST_LOG_(INFO) << "Attempt to flash a logical partition..";
- EXPECT_EQ(fb->FlashPartition("test_partition", buf), DEVICE_FAIL)
+ EXPECT_EQ(fb->FlashPartition(test_partition_name, buf), DEVICE_FAIL)
<< "flash logical partition must fail in bootloader";
GTEST_LOG_(INFO) << "Rebooting back to fastbootd mode";
fb->RebootTo("fastboot");
@@ -260,7 +283,7 @@ TEST_F(LogicalPartitionCompliance, CreateResizeDeleteLP) {
ReconnectFastbootDevice();
ASSERT_TRUE(UserSpaceFastboot());
GTEST_LOG_(INFO) << "Testing 'fastboot delete-logical-partition' command";
- EXPECT_EQ(fb->DeletePartition("test_partition_a"), SUCCESS)
+ EXPECT_EQ(fb->DeletePartition(test_partition_name), SUCCESS)
<< "delete logical-partition failed";
}
@@ -1728,10 +1751,14 @@ int main(int argc, char** argv) {
fastboot::GenerateXmlTests(fastboot::config);
}
+ if (args.find("serial") != args.end()) {
+ fastboot::FastBootTest::device_serial = args.at("serial");
+ }
+
setbuf(stdout, NULL); // no buffering
printf("<Waiting for Device>\n");
const auto matcher = [](usb_ifc_info* info) -> int {
- return fastboot::FastBootTest::MatchFastboot(info, nullptr);
+ return fastboot::FastBootTest::MatchFastboot(info, fastboot::FastBootTest::device_serial);
};
Transport* transport = nullptr;
while (!transport) {