diff options
author | David Anderson <dvander@google.com> | 2018-11-06 22:59:17 +0000 |
---|---|---|
committer | Gerrit Code Review <noreply-gerritcodereview@google.com> | 2018-11-06 22:59:17 +0000 |
commit | a97d6e36d5e3902d52d258ec0ec76d21c481ffed (patch) | |
tree | 0ff2f29625be6841ec585552dd1753ce9df97327 | |
parent | 7d87981f79f90db5ba4a55b3c35affabcda6dddb (diff) | |
parent | 90fe0a43abaa0d395b8884a690c0d3661282b044 (diff) | |
download | system_core-a97d6e36d5e3902d52d258ec0ec76d21c481ffed.tar.gz system_core-a97d6e36d5e3902d52d258ec0ec76d21c481ffed.tar.bz2 system_core-a97d6e36d5e3902d52d258ec0ec76d21c481ffed.zip |
Merge "fastboot: Query the name of the super partition."
-rw-r--r-- | fastboot/constants.h | 1 | ||||
-rw-r--r-- | fastboot/device/commands.cpp | 3 | ||||
-rw-r--r-- | fastboot/device/variables.cpp | 10 | ||||
-rw-r--r-- | fastboot/device/variables.h | 2 | ||||
-rw-r--r-- | fastboot/fastboot.cpp | 32 | ||||
-rw-r--r-- | fs_mgr/liblp/utility.cpp | 8 | ||||
-rw-r--r-- | fs_mgr/liblp/utility_test.cpp | 6 |
7 files changed, 30 insertions, 32 deletions
diff --git a/fastboot/constants.h b/fastboot/constants.h index 705da333b..81f0560e7 100644 --- a/fastboot/constants.h +++ b/fastboot/constants.h @@ -64,3 +64,4 @@ #define FB_VAR_OFF_MODE_CHARGE_STATE "off-mode-charge" #define FB_VAR_BATTERY_VOLTAGE "battery-voltage" #define FB_VAR_BATTERY_SOC_OK "battery-soc-ok" +#define FB_VAR_SUPER_PARTITION_NAME "super-partition-name" diff --git a/fastboot/device/commands.cpp b/fastboot/device/commands.cpp index 11c838aae..08744ec02 100644 --- a/fastboot/device/commands.cpp +++ b/fastboot/device/commands.cpp @@ -99,7 +99,8 @@ bool GetVarHandler(FastbootDevice* device, const std::vector<std::string>& args) {FB_VAR_OFF_MODE_CHARGE_STATE, {GetOffModeChargeState, nullptr}}, {FB_VAR_BATTERY_VOLTAGE, {GetBatteryVoltage, nullptr}}, {FB_VAR_BATTERY_SOC_OK, {GetBatterySoCOk, nullptr}}, - {FB_VAR_HW_REVISION, {GetHardwareRevision, nullptr}}}; + {FB_VAR_HW_REVISION, {GetHardwareRevision, nullptr}}, + {FB_VAR_SUPER_PARTITION_NAME, {GetSuperPartitionName, nullptr}}}; if (args.size() < 2) { return device->WriteFail("Missing argument"); diff --git a/fastboot/device/variables.cpp b/fastboot/device/variables.cpp index cbd2856dc..601af3446 100644 --- a/fastboot/device/variables.cpp +++ b/fastboot/device/variables.cpp @@ -24,7 +24,9 @@ #include <android-base/stringprintf.h> #include <android-base/strings.h> #include <ext4_utils/ext4_utils.h> +#include <fs_mgr.h> #include <healthhalutils/HealthHalUtils.h> +#include <liblp/liblp.h> #include "fastboot_device.h" #include "flashing.h" @@ -35,6 +37,7 @@ using ::android::hardware::boot::V1_0::Slot; using ::android::hardware::fastboot::V1_0::FileSystemType; using ::android::hardware::fastboot::V1_0::Result; using ::android::hardware::fastboot::V1_0::Status; +using namespace android::fs_mgr; constexpr char kFastbootProtocolVersion[] = "0.4"; @@ -417,3 +420,10 @@ bool GetHardwareRevision(FastbootDevice* /* device */, const std::vector<std::st *message = android::base::GetProperty("ro.revision", ""); return true; } + +bool GetSuperPartitionName(FastbootDevice* device, const std::vector<std::string>& /* args */, + std::string* message) { + uint32_t slot_number = SlotNumberForSlotSuffix(device->GetCurrentSlot()); + *message = fs_mgr_get_super_partition_name(slot_number); + return true; +} diff --git a/fastboot/device/variables.h b/fastboot/device/variables.h index 59b71e836..015a4c55a 100644 --- a/fastboot/device/variables.h +++ b/fastboot/device/variables.h @@ -59,6 +59,8 @@ bool GetBatteryVoltage(FastbootDevice* device, const std::vector<std::string>& a std::string* message); bool GetBatterySoCOk(FastbootDevice* device, const std::vector<std::string>& args, std::string* message); +bool GetSuperPartitionName(FastbootDevice* device, const std::vector<std::string>& args, + std::string* message); // Helpers for getvar all. std::vector<std::vector<std::string>> GetAllPartitionArgsWithSlot(FastbootDevice* device); diff --git a/fastboot/fastboot.cpp b/fastboot/fastboot.cpp index e358bec68..625e047b6 100644 --- a/fastboot/fastboot.cpp +++ b/fastboot/fastboot.cpp @@ -1129,25 +1129,6 @@ static bool is_userspace_fastboot() { return fb->GetVar("is-userspace", &value) == fastboot::SUCCESS && value == "yes"; } -static bool if_partition_exists(const std::string& partition, const std::string& slot) { - std::string has_slot; - std::string partition_name = partition; - - if (fb->GetVar("has-slot:" + partition, &has_slot) == fastboot::SUCCESS && has_slot == "yes") { - if (slot == "") { - std::string current_slot = get_current_slot(); - if (current_slot == "") { - die("Failed to identify current slot"); - } - partition_name += "_" + current_slot; - } else { - partition_name += "_" + slot; - } - } - std::string partition_size; - return fb->GetVar("partition-size:" + partition_name, &partition_size) == fastboot::SUCCESS; -} - static void reboot_to_userspace_fastboot() { fb->RebootTo("fastboot"); @@ -1307,10 +1288,6 @@ void FlashAllTool::FlashImage(const Image& image, const std::string& slot, fastb } void FlashAllTool::UpdateSuperPartition() { - if (!if_partition_exists("super", "")) { - return; - } - int fd = source_.OpenFile("super_empty.img"); if (fd < 0) { return; @@ -1321,9 +1298,14 @@ void FlashAllTool::UpdateSuperPartition() { if (!is_userspace_fastboot()) { die("Failed to boot into userspace; one or more components might be unbootable."); } - fb->Download("super", fd, get_file_size(fd)); - std::string command = "update-super:super"; + std::string super_name; + if (fb->GetVar("super-partition-name", &super_name) != fastboot::RetCode::SUCCESS) { + super_name = "super"; + } + fb->Download(super_name, fd, get_file_size(fd)); + + std::string command = "update-super:" + super_name; if (wipe_) { command += ":wipe"; } diff --git a/fs_mgr/liblp/utility.cpp b/fs_mgr/liblp/utility.cpp index 2bf9a7d30..cce90a308 100644 --- a/fs_mgr/liblp/utility.cpp +++ b/fs_mgr/liblp/utility.cpp @@ -97,15 +97,15 @@ void SHA256(const void* data, size_t length, uint8_t out[32]) { } uint32_t SlotNumberForSlotSuffix(const std::string& suffix) { - if (suffix.empty()) { + if (suffix.empty() || suffix == "a" || suffix == "_a") { return 0; - } - if (suffix.size() != 2 || suffix[0] != '_' || suffix[1] < 'a') { + } else if (suffix == "b" || suffix == "_b") { + return 1; + } else { LERROR << __PRETTY_FUNCTION__ << "slot '" << suffix << "' does not have a recognized format."; return 0; } - return suffix[1] - 'a'; } uint64_t GetTotalSuperPartitionSize(const LpMetadata& metadata) { diff --git a/fs_mgr/liblp/utility_test.cpp b/fs_mgr/liblp/utility_test.cpp index f1f958ce5..0fa4590ee 100644 --- a/fs_mgr/liblp/utility_test.cpp +++ b/fs_mgr/liblp/utility_test.cpp @@ -24,10 +24,12 @@ using namespace android::fs_mgr; TEST(liblp, SlotNumberForSlotSuffix) { EXPECT_EQ(SlotNumberForSlotSuffix(""), 0); + EXPECT_EQ(SlotNumberForSlotSuffix("a"), 0); EXPECT_EQ(SlotNumberForSlotSuffix("_a"), 0); + EXPECT_EQ(SlotNumberForSlotSuffix("b"), 1); EXPECT_EQ(SlotNumberForSlotSuffix("_b"), 1); - EXPECT_EQ(SlotNumberForSlotSuffix("_c"), 2); - EXPECT_EQ(SlotNumberForSlotSuffix("_d"), 3); + EXPECT_EQ(SlotNumberForSlotSuffix("_c"), 0); + EXPECT_EQ(SlotNumberForSlotSuffix("_d"), 0); } TEST(liblp, GetMetadataOffset) { |