Support incremental OTA in ota_extractor
Test: Run ota_extractor on an incremental OTA
Bug: 228326856
Change-Id: I8adcbb923a5ad53f35d6eddb9b29afedbc46b041
diff --git a/payload_consumer/install_operation_executor.cc b/payload_consumer/install_operation_executor.cc
index 69ef9c1..cd6546f 100644
--- a/payload_consumer/install_operation_executor.cc
+++ b/payload_consumer/install_operation_executor.cc
@@ -255,6 +255,7 @@
operation, std::move(writer), source_fd, data, count);
default:
LOG(ERROR) << "Unexpected operation type when executing diff ops "
+ << operation.type() << " "
<< operation.Type_Name(operation.type());
return false;
}
diff --git a/payload_consumer/install_plan.cc b/payload_consumer/install_plan.cc
index db0af4e..91eb53b 100644
--- a/payload_consumer/install_plan.cc
+++ b/payload_consumer/install_plan.cc
@@ -187,6 +187,44 @@
postinstall_optional == that.postinstall_optional);
}
+bool InstallPlan::Partition::ParseVerityConfig(
+ const PartitionUpdate& partition) {
+ if (partition.has_hash_tree_extent()) {
+ Extent extent = partition.hash_tree_data_extent();
+ hash_tree_data_offset = extent.start_block() * block_size;
+ hash_tree_data_size = extent.num_blocks() * block_size;
+ extent = partition.hash_tree_extent();
+ hash_tree_offset = extent.start_block() * block_size;
+ hash_tree_size = extent.num_blocks() * block_size;
+ uint64_t hash_tree_data_end = hash_tree_data_offset + hash_tree_data_size;
+ if (hash_tree_offset < hash_tree_data_end) {
+ LOG(ERROR) << "Invalid hash tree extents, hash tree data ends at "
+ << hash_tree_data_end << ", but hash tree starts at "
+ << hash_tree_offset;
+ return false;
+ }
+ hash_tree_algorithm = partition.hash_tree_algorithm();
+ hash_tree_salt.assign(partition.hash_tree_salt().begin(),
+ partition.hash_tree_salt().end());
+ }
+ if (partition.has_fec_extent()) {
+ Extent extent = partition.fec_data_extent();
+ fec_data_offset = extent.start_block() * block_size;
+ fec_data_size = extent.num_blocks() * block_size;
+ extent = partition.fec_extent();
+ fec_offset = extent.start_block() * block_size;
+ fec_size = extent.num_blocks() * block_size;
+ uint64_t fec_data_end = fec_data_offset + fec_data_size;
+ if (fec_offset < fec_data_end) {
+ LOG(ERROR) << "Invalid fec extents, fec data ends at " << fec_data_end
+ << ", but fec starts at " << fec_offset;
+ return false;
+ }
+ fec_roots = partition.fec_roots();
+ }
+ return true;
+}
+
template <typename PartitinoUpdateArray>
bool InstallPlan::ParseManifestToInstallPlan(
const PartitinoUpdateArray& partitions,
@@ -226,42 +264,11 @@
install_part.target_hash.assign(info.hash().begin(), info.hash().end());
install_part.block_size = block_size;
- if (partition.has_hash_tree_extent()) {
- Extent extent = partition.hash_tree_data_extent();
- install_part.hash_tree_data_offset = extent.start_block() * block_size;
- install_part.hash_tree_data_size = extent.num_blocks() * block_size;
- extent = partition.hash_tree_extent();
- install_part.hash_tree_offset = extent.start_block() * block_size;
- install_part.hash_tree_size = extent.num_blocks() * block_size;
- uint64_t hash_tree_data_end =
- install_part.hash_tree_data_offset + install_part.hash_tree_data_size;
- if (install_part.hash_tree_offset < hash_tree_data_end) {
- LOG(ERROR) << "Invalid hash tree extents, hash tree data ends at "
- << hash_tree_data_end << ", but hash tree starts at "
- << install_part.hash_tree_offset;
- *error = ErrorCode::kDownloadNewPartitionInfoError;
- return false;
- }
- install_part.hash_tree_algorithm = partition.hash_tree_algorithm();
- install_part.hash_tree_salt.assign(partition.hash_tree_salt().begin(),
- partition.hash_tree_salt().end());
- }
- if (partition.has_fec_extent()) {
- Extent extent = partition.fec_data_extent();
- install_part.fec_data_offset = extent.start_block() * block_size;
- install_part.fec_data_size = extent.num_blocks() * block_size;
- extent = partition.fec_extent();
- install_part.fec_offset = extent.start_block() * block_size;
- install_part.fec_size = extent.num_blocks() * block_size;
- uint64_t fec_data_end =
- install_part.fec_data_offset + install_part.fec_data_size;
- if (install_part.fec_offset < fec_data_end) {
- LOG(ERROR) << "Invalid fec extents, fec data ends at " << fec_data_end
- << ", but fec starts at " << install_part.fec_offset;
- *error = ErrorCode::kDownloadNewPartitionInfoError;
- return false;
- }
- install_part.fec_roots = partition.fec_roots();
+ if (!install_part.ParseVerityConfig(partition)) {
+ *error = ErrorCode::kDownloadNewPartitionInfoError;
+ LOG(INFO) << "Failed to parse partition `" << partition.partition_name()
+ << "` verity configs";
+ return false;
}
install_plan->partitions.push_back(install_part);
diff --git a/payload_consumer/install_plan.h b/payload_consumer/install_plan.h
index 0278ea5..883aa60 100644
--- a/payload_consumer/install_plan.h
+++ b/payload_consumer/install_plan.h
@@ -156,6 +156,8 @@
uint64_t fec_offset{0};
uint64_t fec_size{0};
uint32_t fec_roots{0};
+
+ bool ParseVerityConfig(const PartitionUpdate&);
};
std::vector<Partition> partitions;
diff --git a/payload_consumer/verity_writer_android.cc b/payload_consumer/verity_writer_android.cc
index ffa2944..91efa3e 100644
--- a/payload_consumer/verity_writer_android.cc
+++ b/payload_consumer/verity_writer_android.cc
@@ -116,7 +116,8 @@
return false;
}
// All hash tree data blocks has been hashed, write hash tree to disk.
- LOG(INFO) << "Writing verity hash tree to " << partition_->target_path;
+ LOG(INFO) << "Writing verity hash tree to "
+ << partition_->readonly_target_path;
if (hash_tree_builder_) {
TEST_AND_RETURN_FALSE(hash_tree_builder_->BuildHashTree());
TEST_AND_RETURN_FALSE_ERRNO(
@@ -130,7 +131,7 @@
hash_tree_builder_.reset();
}
if (partition_->fec_size != 0) {
- LOG(INFO) << "Writing verity FEC to " << partition_->target_path;
+ LOG(INFO) << "Writing verity FEC to " << partition_->readonly_target_path;
TEST_AND_RETURN_FALSE(EncodeFEC(read_fd,
write_fd,
partition_->fec_data_offset,