ota升级分区即差分升级又整分区升级(android11)
fota差分增量升级
·
问题:系统在采用差分升级时,因业务要求,需要一部分分区需要差分升级,另一部分特定分区需要整包升级
分析:正常情况下,当使用./build/make/tools/releasetools/ota_from_target_files.py -i old.zip new.zip cfb.zip命令制作差分包时,所有分区均采用了差分升级。所以要想达到上述业务要求,需修改编译脚本,本次提供2种方式进行修改,均可。
第一种:
修改代码路径:aosp/system/update_engine/payload_generator/delta_diff_utils.cc
bool ReadExtentsToDiff(const string& old_part,
const string& new_part,
const vector<Extent>& old_extents,
const vector<Extent>& new_extents,
const vector<puffin::BitExtent>& old_deflates,
const vector<puffin::BitExtent>& new_deflates,
const PayloadVersion& version,
brillo::Blob* out_data,
InstallOperation* out_op) {
InstallOperation operation;
// We read blocks from old_extents and write blocks to new_extents.
uint64_t blocks_to_read = utils::BlocksInExtents(old_extents);
uint64_t blocks_to_write = utils::BlocksInExtents(new_extents);
// Disable bsdiff, and puffdiff when the data is too big.
bool bsdiff_allowed =
version.OperationAllowed(InstallOperation::SOURCE_BSDIFF) ||
version.OperationAllowed(InstallOperation::BSDIFF);
//此处主要是判断当前遍历的分区bsdiff大小是否大于200mb,若是大于,则不采用差分diff增量升级,从做差分包效率性能考虑
if (bsdiff_allowed &&
blocks_to_read * kBlockSize > kMaxBsdiffDestinationSize) {
LOG(INFO) << "bsdiff blacklisted, data too big: "
<< blocks_to_read * kBlockSize << " bytes";
bsdiff_allowed = false;
}
//此处主要是判断当前遍历的分区puffdif大小是否大于100mb,若是大于,则不采用差分puffdiff增量升,
bool puffdiff_allowed = version.OperationAllowed(InstallOperation::PUFFDIFF);
if (puffdiff_allowed &&
blocks_to_read * kBlockSize > kMaxPuffdiffDestinationSize) {
LOG(INFO) << "puffdiff blacklisted, data too big: "
<< blocks_to_read * kBlockSize << " bytes";
puffdiff_allowed = false;
}
/*****修改处******* 将特定分区时,两个Boolean值全部修改为false,跳过差分增量升级/
if(new_part.find("修改的分区名例如 system") != string::npos ){
bsdiff_allowed = false;
puffdiff_allowed = false;
}
// Make copies of the extents so we can modify them.
vector<Extent> src_extents = old_extents;
vector<Extent> dst_extents = new_extents;
第二种:
代码路径:aosp/system/update_engine/payload_generator/delta_diff_generator.cc
bool GenerateUpdatePayloadFile(const PayloadGenerationConfig& config,
const string& output_path,
const string& private_key_path,
uint64_t* metadata_size) {
if (!config.version.Validate()) {
LOG(ERROR) << "Unsupported major.minor version: " << config.version.major
<< "." << config.version.minor;
return false;
}
// Create empty payload file object.
PayloadFile payload;
TEST_AND_RETURN_FALSE(payload.Init(config));
const string kTempFileTemplate("CrAU_temp_data.XXXXXX");
string temp_file_path;
int data_file_fd;
TEST_AND_RETURN_FALSE(
utils::MakeTempFile(kTempFileTemplate, &temp_file_path, &data_file_fd));
ScopedPathUnlinker temp_file_unlinker(temp_file_path);
TEST_AND_RETURN_FALSE(data_file_fd >= 0);
{
off_t data_file_size = 0;
ScopedFdCloser data_file_fd_closer(&data_file_fd);
BlobFileWriter blob_file(data_file_fd, &data_file_size);
if (config.is_delta) {
TEST_AND_RETURN_FALSE(config.source.partitions.size() ==
config.target.partitions.size());
}
PartitionConfig empty_part("");
for (size_t i = 0; i < config.target.partitions.size(); i++) {
const PartitionConfig& old_part =
config.is_delta ? config.source.partitions[i] : empty_part;
const PartitionConfig& new_part = config.target.partitions[i];
LOG(INFO) << "Partition name: " << new_part.name;
LOG(INFO) << "Partition size: " << new_part.size;
LOG(INFO) << "Block count: " << new_part.size / config.block_size;
// Select payload generation strategy based on the config.
unique_ptr<OperationsGenerator> strategy;
if (!old_part.path.empty()) {
// Delta update.
/*******修改处******遍历特定分区时,直接采用FullUpdateGenerator()整分区升级方法****/
if(new_part.name.find("修改的分区名例如 system") != string::npos ){
strategy.reset(new FullUpdateGenerator());
}else if (config.version.minor == kInPlaceMinorPayloadVersion) {
LOG(INFO) << "Using generator InplaceGenerator().";
strategy.reset(new InplaceGenerator());
} else {
LOG(INFO) << "Using generator ABGenerator().";
strategy.reset(new ABGenerator());
}
} else {
LOG(INFO) << "Using generator FullUpdateGenerator().";
strategy.reset(new FullUpdateGenerator());
}
vector<AnnotatedOperation> aops;
// Generate the operations using the strategy we selected above.
TEST_AND_RETURN_FALSE(strategy->GenerateOperations(
config, old_part, new_part, &blob_file, &aops));
// Filter the no-operations. OperationsGenerators should not output this
// kind of operations normally, but this is an extra step to fix that if
// happened.
diff_utils::FilterNoopOperations(&aops);
TEST_AND_RETURN_FALSE(payload.AddPartition(old_part, new_part, aops));
}
}
LOG(INFO) << "Writing payload file...";
// Write payload file to disk.
TEST_AND_RETURN_FALSE(payload.WritePayload(
output_path, temp_file_path, private_key_path, metadata_size));
LOG(INFO) << "All done. Successfully created delta file with "
<< "metadata size = " << *metadata_size;
return true;
}
按照上述两种方式 代码修改后,单编make delta_generator,然后重新执行 差分命令,即可。
更多推荐
所有评论(0)