Changing FlashTask to take in apply_vbmeta
Test: tested on Raven Change-Id: I709842d87aa4ad6a7772e4f441886d127c3028a7
This commit is contained in:
parent
15e7783263
commit
403657d998
|
@ -1159,6 +1159,12 @@ static bool has_vbmeta_partition() {
|
||||||
fb->GetVar("partition-type:vbmeta_b", &partition_type) == fastboot::SUCCESS;
|
fb->GetVar("partition-type:vbmeta_b", &partition_type) == fastboot::SUCCESS;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
static bool is_vbmeta_partition(const std::string& partition) {
|
||||||
|
return android::base::EndsWith(partition, "vbmeta") ||
|
||||||
|
android::base::EndsWith(partition, "vbmeta_a") ||
|
||||||
|
android::base::EndsWith(partition, "vbmeta_b");
|
||||||
|
}
|
||||||
|
|
||||||
// Note: this only works in userspace fastboot. In the bootloader, use
|
// Note: this only works in userspace fastboot. In the bootloader, use
|
||||||
// should_flash_in_userspace().
|
// should_flash_in_userspace().
|
||||||
bool is_logical(const std::string& partition) {
|
bool is_logical(const std::string& partition) {
|
||||||
|
@ -1251,7 +1257,8 @@ void flash_partition_files(const std::string& partition, const std::vector<Spars
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
static void flash_buf(const std::string& partition, struct fastboot_buffer* buf) {
|
static void flash_buf(const std::string& partition, struct fastboot_buffer* buf,
|
||||||
|
const bool apply_vbmeta) {
|
||||||
if (partition == "boot" || partition == "boot_a" || partition == "boot_b" ||
|
if (partition == "boot" || partition == "boot_a" || partition == "boot_b" ||
|
||||||
partition == "init_boot" || partition == "init_boot_a" || partition == "init_boot_b" ||
|
partition == "init_boot" || partition == "init_boot_a" || partition == "init_boot_b" ||
|
||||||
partition == "recovery" || partition == "recovery_a" || partition == "recovery_b") {
|
partition == "recovery" || partition == "recovery_a" || partition == "recovery_b") {
|
||||||
|
@ -1262,9 +1269,7 @@ static void flash_buf(const std::string& partition, struct fastboot_buffer* buf)
|
||||||
if (g_disable_verity || g_disable_verification) {
|
if (g_disable_verity || g_disable_verification) {
|
||||||
// The vbmeta partition might have additional prefix if running in virtual machine
|
// The vbmeta partition might have additional prefix if running in virtual machine
|
||||||
// e.g., guest_vbmeta_a.
|
// e.g., guest_vbmeta_a.
|
||||||
if (android::base::EndsWith(partition, "vbmeta") ||
|
if (apply_vbmeta) {
|
||||||
android::base::EndsWith(partition, "vbmeta_a") ||
|
|
||||||
android::base::EndsWith(partition, "vbmeta_b")) {
|
|
||||||
rewrite_vbmeta_buffer(buf, false /* vbmeta_in_boot */);
|
rewrite_vbmeta_buffer(buf, false /* vbmeta_in_boot */);
|
||||||
} else if (!has_vbmeta_partition() &&
|
} else if (!has_vbmeta_partition() &&
|
||||||
(partition == "boot" || partition == "boot_a" || partition == "boot_b")) {
|
(partition == "boot" || partition == "boot_a" || partition == "boot_b")) {
|
||||||
|
@ -1499,7 +1504,7 @@ static std::string repack_ramdisk(const char* pname, struct fastboot_buffer* buf
|
||||||
return partition;
|
return partition;
|
||||||
}
|
}
|
||||||
|
|
||||||
void do_flash(const char* pname, const char* fname) {
|
void do_flash(const char* pname, const char* fname, const bool apply_vbmeta) {
|
||||||
verbose("Do flash %s %s", pname, fname);
|
verbose("Do flash %s %s", pname, fname);
|
||||||
struct fastboot_buffer buf;
|
struct fastboot_buffer buf;
|
||||||
|
|
||||||
|
@ -1510,7 +1515,7 @@ void do_flash(const char* pname, const char* fname) {
|
||||||
fb->ResizePartition(pname, std::to_string(buf.image_size));
|
fb->ResizePartition(pname, std::to_string(buf.image_size));
|
||||||
}
|
}
|
||||||
std::string flash_pname = repack_ramdisk(pname, &buf);
|
std::string flash_pname = repack_ramdisk(pname, &buf);
|
||||||
flash_buf(flash_pname, &buf);
|
flash_buf(flash_pname, &buf, apply_vbmeta);
|
||||||
}
|
}
|
||||||
|
|
||||||
// Sets slot_override as the active slot. If slot_override is blank,
|
// Sets slot_override as the active slot. If slot_override is blank,
|
||||||
|
@ -1729,7 +1734,8 @@ void FlashAllTool::FlashImage(const Image& image, const std::string& slot, fastb
|
||||||
if (is_logical(partition_name)) {
|
if (is_logical(partition_name)) {
|
||||||
fb->ResizePartition(partition_name, std::to_string(buf->image_size));
|
fb->ResizePartition(partition_name, std::to_string(buf->image_size));
|
||||||
}
|
}
|
||||||
flash_buf(partition_name.c_str(), buf);
|
|
||||||
|
flash_buf(partition_name.c_str(), buf, is_vbmeta_partition(partition_name));
|
||||||
};
|
};
|
||||||
do_for_partitions(image.part_name, slot, flash, false);
|
do_for_partitions(image.part_name, slot, flash, false);
|
||||||
}
|
}
|
||||||
|
@ -1904,7 +1910,7 @@ void fb_perform_format(const std::string& partition, int skip_if_not_supported,
|
||||||
if (!load_buf_fd(std::move(fd), &buf)) {
|
if (!load_buf_fd(std::move(fd), &buf)) {
|
||||||
die("Cannot read image: %s", strerror(errno));
|
die("Cannot read image: %s", strerror(errno));
|
||||||
}
|
}
|
||||||
flash_buf(partition, &buf);
|
flash_buf(partition, &buf, is_vbmeta_partition(partition));
|
||||||
return;
|
return;
|
||||||
|
|
||||||
failed:
|
failed:
|
||||||
|
@ -1974,7 +1980,7 @@ static bool wipe_super(const android::fs_mgr::LpMetadata& metadata, const std::s
|
||||||
|
|
||||||
auto image_path = temp_dir.path + "/"s + image_name;
|
auto image_path = temp_dir.path + "/"s + image_name;
|
||||||
auto flash = [&](const std::string& partition_name) {
|
auto flash = [&](const std::string& partition_name) {
|
||||||
do_flash(partition_name.c_str(), image_path.c_str());
|
do_flash(partition_name.c_str(), image_path.c_str(), false);
|
||||||
};
|
};
|
||||||
do_for_partitions(partition, slot, flash, force_slot);
|
do_for_partitions(partition, slot, flash, force_slot);
|
||||||
|
|
||||||
|
@ -2295,7 +2301,8 @@ int FastBootTool::Main(int argc, char* argv[]) {
|
||||||
fname = find_item(pname);
|
fname = find_item(pname);
|
||||||
}
|
}
|
||||||
if (fname.empty()) die("cannot determine image filename for '%s'", pname.c_str());
|
if (fname.empty()) die("cannot determine image filename for '%s'", pname.c_str());
|
||||||
FlashTask task(slot_override, pname, fname);
|
|
||||||
|
FlashTask task(slot_override, pname, fname, is_vbmeta_partition(pname));
|
||||||
task.Run();
|
task.Run();
|
||||||
} else if (command == "flash:raw") {
|
} else if (command == "flash:raw") {
|
||||||
std::string partition = next_arg(&args);
|
std::string partition = next_arg(&args);
|
||||||
|
|
|
@ -88,7 +88,7 @@ struct FlashingPlan {
|
||||||
|
|
||||||
bool should_flash_in_userspace(const std::string& partition_name);
|
bool should_flash_in_userspace(const std::string& partition_name);
|
||||||
bool is_userspace_fastboot();
|
bool is_userspace_fastboot();
|
||||||
void do_flash(const char* pname, const char* fname);
|
void do_flash(const char* pname, const char* fname, const bool apply_vbmeta);
|
||||||
void do_for_partitions(const std::string& part, const std::string& slot,
|
void do_for_partitions(const std::string& part, const std::string& slot,
|
||||||
const std::function<void(const std::string&)>& func, bool force_slot);
|
const std::function<void(const std::string&)>& func, bool force_slot);
|
||||||
std::string find_item(const std::string& item);
|
std::string find_item(const std::string& item);
|
||||||
|
|
|
@ -21,12 +21,13 @@
|
||||||
|
|
||||||
using namespace std::string_literals;
|
using namespace std::string_literals;
|
||||||
|
|
||||||
FlashTask::FlashTask(const std::string& slot, const std::string& pname)
|
FlashTask::FlashTask(const std::string& slot, const std::string& pname, const bool apply_vbmeta)
|
||||||
: pname_(pname), fname_(find_item(pname)), slot_(slot) {
|
: pname_(pname), fname_(find_item(pname)), slot_(slot), apply_vbmeta_(apply_vbmeta) {
|
||||||
if (fname_.empty()) die("cannot determine image filename for '%s'", pname_.c_str());
|
if (fname_.empty()) die("cannot determine image filename for '%s'", pname_.c_str());
|
||||||
}
|
}
|
||||||
FlashTask::FlashTask(const std::string& _slot, const std::string& _pname, const std::string& _fname)
|
FlashTask::FlashTask(const std::string& _slot, const std::string& _pname, const std::string& _fname,
|
||||||
: pname_(_pname), fname_(_fname), slot_(_slot) {}
|
const bool apply_vbmeta)
|
||||||
|
: pname_(_pname), fname_(_fname), slot_(_slot), apply_vbmeta_(apply_vbmeta) {}
|
||||||
|
|
||||||
void FlashTask::Run() {
|
void FlashTask::Run() {
|
||||||
auto flash = [&](const std::string& partition) {
|
auto flash = [&](const std::string& partition) {
|
||||||
|
@ -39,7 +40,7 @@ void FlashTask::Run() {
|
||||||
"And try again. If you are intentionally trying to "
|
"And try again. If you are intentionally trying to "
|
||||||
"overwrite a fixed partition, use --force.");
|
"overwrite a fixed partition, use --force.");
|
||||||
}
|
}
|
||||||
do_flash(partition.c_str(), fname_.c_str());
|
do_flash(partition.c_str(), fname_.c_str(), apply_vbmeta_);
|
||||||
};
|
};
|
||||||
do_for_partitions(pname_, slot_, flash, true);
|
do_for_partitions(pname_, slot_, flash, true);
|
||||||
}
|
}
|
||||||
|
|
|
@ -32,8 +32,9 @@ class Task {
|
||||||
|
|
||||||
class FlashTask : public Task {
|
class FlashTask : public Task {
|
||||||
public:
|
public:
|
||||||
FlashTask(const std::string& slot, const std::string& pname);
|
FlashTask(const std::string& slot, const std::string& pname, const bool apply_vbmeta);
|
||||||
FlashTask(const std::string& slot, const std::string& pname, const std::string& fname);
|
FlashTask(const std::string& slot, const std::string& pname, const std::string& fname,
|
||||||
|
const bool apply_vbmeta);
|
||||||
|
|
||||||
void Run() override;
|
void Run() override;
|
||||||
|
|
||||||
|
@ -41,6 +42,7 @@ class FlashTask : public Task {
|
||||||
const std::string pname_;
|
const std::string pname_;
|
||||||
const std::string fname_;
|
const std::string fname_;
|
||||||
const std::string slot_;
|
const std::string slot_;
|
||||||
|
const bool apply_vbmeta_;
|
||||||
};
|
};
|
||||||
|
|
||||||
class RebootTask : public Task {
|
class RebootTask : public Task {
|
||||||
|
|
Loading…
Reference in New Issue