Add an overload function in boot control
It's used to support partial update. The overload function takes
additional info whether the partition is included in payload. And
it also outputs if the partition is a dynamic partition.
Bug: 157778739
Test: unit tests pass
Change-Id: I0741d44c223fb7c187fe208564371acd6d868c65
diff --git a/boot_control_android.cc b/boot_control_android.cc
index ec2ca0f..dee5fa8 100644
--- a/boot_control_android.cc
+++ b/boot_control_android.cc
@@ -82,12 +82,24 @@
return module_->getCurrentSlot();
}
+bool BootControlAndroid::GetPartitionDevice(const std::string& partition_name,
+ BootControlInterface::Slot slot,
+ bool not_in_payload,
+ std::string* device,
+ bool* is_dynamic) const {
+ return dynamic_control_->GetPartitionDevice(partition_name,
+ slot,
+ GetCurrentSlot(),
+ not_in_payload,
+ device,
+ is_dynamic);
+}
bool BootControlAndroid::GetPartitionDevice(const string& partition_name,
- Slot slot,
+ BootControlInterface::Slot slot,
string* device) const {
- return dynamic_control_->GetPartitionDevice(
- partition_name, slot, GetCurrentSlot(), device);
+ return GetPartitionDevice(
+ partition_name, slot, false /* not_in_payload */, device, nullptr);
}
bool BootControlAndroid::IsSlotBootable(Slot slot) const {
diff --git a/boot_control_android.h b/boot_control_android.h
index 0b042e3..5009dbd 100644
--- a/boot_control_android.h
+++ b/boot_control_android.h
@@ -46,6 +46,11 @@
BootControlInterface::Slot GetCurrentSlot() const override;
bool GetPartitionDevice(const std::string& partition_name,
BootControlInterface::Slot slot,
+ bool not_in_payload,
+ std::string* device,
+ bool* is_dynamic) const override;
+ bool GetPartitionDevice(const std::string& partition_name,
+ BootControlInterface::Slot slot,
std::string* device) const override;
bool IsSlotBootable(BootControlInterface::Slot slot) const override;
bool MarkSlotUnbootable(BootControlInterface::Slot slot) override;
diff --git a/boot_control_chromeos.cc b/boot_control_chromeos.cc
index 0f47169..da84e99 100644
--- a/boot_control_chromeos.cc
+++ b/boot_control_chromeos.cc
@@ -148,9 +148,11 @@
return current_slot_;
}
-bool BootControlChromeOS::GetPartitionDevice(const string& partition_name,
- unsigned int slot,
- string* device) const {
+bool BootControlChromeOS::GetPartitionDevice(const std::string& partition_name,
+ BootControlInterface::Slot slot,
+ bool not_in_payload,
+ std::string* device,
+ bool* is_dynamic) const {
// Partition name prefixed with |kPartitionNamePrefixDlc| is a DLC module.
if (base::StartsWith(partition_name,
kPartitionNamePrefixDlc,
@@ -180,9 +182,18 @@
return false;
*device = part_device;
+ if (is_dynamic) {
+ *is_dynamic = false;
+ }
return true;
}
+bool BootControlChromeOS::GetPartitionDevice(const string& partition_name,
+ BootControlInterface::Slot slot,
+ string* device) const {
+ return GetPartitionDevice(partition_name, slot, false, device, nullptr);
+}
+
bool BootControlChromeOS::IsSlotBootable(Slot slot) const {
int partition_num = GetPartitionNumber(kChromeOSPartitionNameKernel, slot);
if (partition_num < 0)
diff --git a/boot_control_chromeos.h b/boot_control_chromeos.h
index 0209052..6edc148 100644
--- a/boot_control_chromeos.h
+++ b/boot_control_chromeos.h
@@ -47,6 +47,11 @@
BootControlInterface::Slot GetCurrentSlot() const override;
bool GetPartitionDevice(const std::string& partition_name,
BootControlInterface::Slot slot,
+ bool not_in_payload,
+ std::string* device,
+ bool* is_dynamic) const override;
+ bool GetPartitionDevice(const std::string& partition_name,
+ BootControlInterface::Slot slot,
std::string* device) const override;
bool IsSlotBootable(BootControlInterface::Slot slot) const override;
bool MarkSlotUnbootable(BootControlInterface::Slot slot) override;
diff --git a/common/boot_control_interface.h b/common/boot_control_interface.h
index 3906e2f..c93de5c 100644
--- a/common/boot_control_interface.h
+++ b/common/boot_control_interface.h
@@ -59,8 +59,18 @@
// every slot. In order to access the dynamic partitions in the target slot,
// GetDynamicPartitionControl()->PreparePartitionsForUpdate() must be called
// (with |update| == true for the first time for a payload, and |false| for
- // for the rest of the times) prior to calling this function. On success,
- // returns true and stores the block device in |device|.
+ // for the rest of the times) prior to calling this function.
+ // The handling may be different based on whether the partition is included
+ // in the update payload. On success, returns true; and stores the block
+ // device in |device|, if the partition is dynamic in |is_dynamic|.
+ virtual bool GetPartitionDevice(const std::string& partition_name,
+ Slot slot,
+ bool not_in_payload,
+ std::string* device,
+ bool* is_dynamic) const = 0;
+
+ // Overload of the above function. We assume the partition is always included
+ // in the payload.
virtual bool GetPartitionDevice(const std::string& partition_name,
Slot slot,
std::string* device) const = 0;
diff --git a/common/boot_control_stub.cc b/common/boot_control_stub.cc
index 2eb9211..907f670 100644
--- a/common/boot_control_stub.cc
+++ b/common/boot_control_stub.cc
@@ -35,6 +35,15 @@
return 0;
}
+bool BootControlStub::GetPartitionDevice(const std::string& partition_name,
+ BootControlInterface::Slot slot,
+ bool not_in_payload,
+ std::string* device,
+ bool* is_dynamic) const {
+ LOG(ERROR) << __FUNCTION__ << " should never be called.";
+ return false;
+}
+
bool BootControlStub::GetPartitionDevice(const string& partition_name,
Slot slot,
string* device) const {
diff --git a/common/boot_control_stub.h b/common/boot_control_stub.h
index cc16190..a1bdb96 100644
--- a/common/boot_control_stub.h
+++ b/common/boot_control_stub.h
@@ -41,6 +41,11 @@
unsigned int GetNumSlots() const override;
BootControlInterface::Slot GetCurrentSlot() const override;
bool GetPartitionDevice(const std::string& partition_name,
+ Slot slot,
+ bool not_in_payload,
+ std::string* device,
+ bool* is_dynamic) const override;
+ bool GetPartitionDevice(const std::string& partition_name,
BootControlInterface::Slot slot,
std::string* device) const override;
bool IsSlotBootable(BootControlInterface::Slot slot) const override;
diff --git a/common/fake_boot_control.h b/common/fake_boot_control.h
index bd9d9ca..adbacd6 100644
--- a/common/fake_boot_control.h
+++ b/common/fake_boot_control.h
@@ -48,7 +48,9 @@
bool GetPartitionDevice(const std::string& partition_name,
BootControlInterface::Slot slot,
- std::string* device) const override {
+ bool not_in_payload,
+ std::string* device,
+ bool* is_dynamic) const override {
if (slot >= num_slots_)
return false;
auto part_it = devices_[slot].find(partition_name);
@@ -58,6 +60,12 @@
return true;
}
+ bool GetPartitionDevice(const std::string& partition_name,
+ BootControlInterface::Slot slot,
+ std::string* device) const override {
+ return GetPartitionDevice(partition_name, slot, false, device, nullptr);
+ }
+
bool IsSlotBootable(BootControlInterface::Slot slot) const override {
return slot < num_slots_ && is_bootable_[slot];
}
diff --git a/dynamic_partition_control_android.cc b/dynamic_partition_control_android.cc
index a9c2bb3..829e3eb 100644
--- a/dynamic_partition_control_android.cc
+++ b/dynamic_partition_control_android.cc
@@ -886,22 +886,35 @@
const std::string& partition_name,
uint32_t slot,
uint32_t current_slot,
- std::string* device) {
+ bool not_in_payload,
+ std::string* device,
+ bool* is_dynamic) {
const auto& partition_name_suffix =
partition_name + SlotSuffixForSlotNumber(slot);
std::string device_dir_str;
TEST_AND_RETURN_FALSE(GetDeviceDir(&device_dir_str));
base::FilePath device_dir(device_dir_str);
+ if (is_dynamic) {
+ *is_dynamic = false;
+ }
+
// When looking up target partition devices, treat them as static if the
// current payload doesn't encode them as dynamic partitions. This may happen
// when applying a retrofit update on top of a dynamic-partitions-enabled
// build.
if (GetDynamicPartitionsFeatureFlag().IsEnabled() &&
(slot == current_slot || is_target_dynamic_)) {
- switch (GetDynamicPartitionDevice(
- device_dir, partition_name_suffix, slot, current_slot, device)) {
+ switch (GetDynamicPartitionDevice(device_dir,
+ partition_name_suffix,
+ slot,
+ current_slot,
+ not_in_payload,
+ device)) {
case DynamicPartitionDeviceStatus::SUCCESS:
+ if (is_dynamic) {
+ *is_dynamic = true;
+ }
return true;
case DynamicPartitionDeviceStatus::TRY_STATIC:
break;
@@ -920,6 +933,15 @@
return true;
}
+bool DynamicPartitionControlAndroid::GetPartitionDevice(
+ const std::string& partition_name,
+ uint32_t slot,
+ uint32_t current_slot,
+ std::string* device) {
+ return GetPartitionDevice(
+ partition_name, slot, current_slot, false, device, nullptr);
+}
+
bool DynamicPartitionControlAndroid::IsSuperBlockDevice(
const base::FilePath& device_dir,
uint32_t current_slot,
@@ -936,6 +958,7 @@
const std::string& partition_name_suffix,
uint32_t slot,
uint32_t current_slot,
+ bool not_in_payload,
std::string* device) {
std::string super_device =
device_dir.Append(GetSuperPartitionName(slot)).value();
@@ -975,7 +998,7 @@
}
}
- bool force_writable = slot != current_slot;
+ bool force_writable = (slot != current_slot) && !not_in_payload;
if (MapPartitionOnDeviceMapper(
super_device, partition_name_suffix, slot, force_writable, device)) {
return DynamicPartitionDeviceStatus::SUCCESS;
diff --git a/dynamic_partition_control_android.h b/dynamic_partition_control_android.h
index 18a05fb..e3bedbc 100644
--- a/dynamic_partition_control_android.h
+++ b/dynamic_partition_control_android.h
@@ -61,6 +61,13 @@
bool GetPartitionDevice(const std::string& partition_name,
uint32_t slot,
uint32_t current_slot,
+ bool not_in_payload,
+ std::string* device,
+ bool* is_dynamic);
+
+ bool GetPartitionDevice(const std::string& partition_name,
+ uint32_t slot,
+ uint32_t current_slot,
std::string* device);
protected:
@@ -222,6 +229,7 @@
const std::string& partition_name_suffix,
uint32_t slot,
uint32_t current_slot,
+ bool not_in_payload,
std::string* device);
// Return true if |partition_name_suffix| is a block device of