is_retrofit_device to work in bootloader
Changing is_retrofit_device() to work in bootloader. Previously flashall
flow was to boot into fastbootd and then make a call to get
"super-image-name", however this does not work in bootloader. Since all
tasks are generated ahead of time, this old check will now fail and we
will fail to add the correct delete tasks in collectTasks(). This change
does make it so that is_retrofit check only works during fastboot
flashall + fastboot update (since this function is only used here,
nothing is currently affected).
To determine if a device is retrofit, it must satisfy two conditions -> Has
dynamic partitions && does not contain a super partition. The check for
if source has super_empty.img is sufficient for determining if a device
has dynamic partitions and if any single partition has
LP_PARTITION_ATTR_SLOT_SUFFIXED it is determined to be retrofit
Test: logs from fastboot update on sargo device confirms this check
returns true. Fastboot update on sargo
Bug: 300287332
Change-Id: Iadf5c56de51993a79307c60e45d6cc4988436f23
diff --git a/fastboot/fastboot.cpp b/fastboot/fastboot.cpp
index 080ad42..63f7843 100644
--- a/fastboot/fastboot.cpp
+++ b/fastboot/fastboot.cpp
@@ -1413,12 +1413,19 @@
}
}
-bool is_retrofit_device(fastboot::IFastBootDriver* fb) {
- std::string value;
- if (fb->GetVar("super-partition-name", &value) != fastboot::SUCCESS) {
+bool is_retrofit_device(const ImageSource* source) {
+ // Does this device use dynamic partitions at all?
+ std::vector<char> contents;
+ if (!source->ReadFile("super_empty.img", &contents)) {
return false;
}
- return android::base::StartsWith(value, "system_");
+ auto metadata = android::fs_mgr::ReadFromImageBlob(contents.data(), contents.size());
+ for (const auto& partition : metadata->partitions) {
+ if (partition.attributes & LP_PARTITION_ATTR_SLOT_SUFFIXED) {
+ return true;
+ }
+ }
+ return false;
}
// Fetch a partition from the device to a given fd. This is a wrapper over FetchToFd to fetch
@@ -1876,7 +1883,7 @@
// On these devices, secondary slots must be flashed as physical
// partitions (otherwise they would not mount on first boot). To enforce
// this, we delete any logical partitions for the "other" slot.
- if (is_retrofit_device(fp_->fb)) {
+ if (is_retrofit_device(fp_->source)) {
std::string partition_name = image->part_name + "_" + slot;
if (image->IsSecondary() && should_flash_in_userspace(partition_name)) {
tasks.emplace_back(std::make_unique<DeleteTask>(fp_, partition_name));