Merge tag 'android-11.0.0_r16' into android-10.0

Android 11.0.0 release 16 - twrp bringup patch
This commit is contained in:
bigbiff
2020-12-02 19:44:56 -05:00
250 changed files with 31359 additions and 4187 deletions

View File

@@ -50,7 +50,7 @@
using namespace std::string_literals;
static bool GenerateTarget(const Partition& target, const FileContents& source_file,
const Value& patch, const Value* bonus_data);
const Value& patch, const Value* bonus_data, bool backup_source);
bool LoadFileContents(const std::string& filename, FileContents* file) {
// No longer allow loading contents from eMMC partitions.
@@ -262,7 +262,7 @@ int ShowLicenses() {
}
bool PatchPartition(const Partition& target, const Partition& source, const Value& patch,
const Value* bonus) {
const Value* bonus, bool backup_source) {
LOG(INFO) << "Patching " << target.name;
// We try to load and check against the target hash first.
@@ -275,8 +275,8 @@ bool PatchPartition(const Partition& target, const Partition& source, const Valu
}
FileContents source_file;
if (ReadPartitionToBuffer(source, &source_file, true)) {
return GenerateTarget(target, source_file, patch, bonus);
if (ReadPartitionToBuffer(source, &source_file, backup_source)) {
return GenerateTarget(target, source_file, patch, bonus, backup_source);
}
LOG(ERROR) << "Failed to find any match";
@@ -322,7 +322,7 @@ bool FlashPartition(const Partition& partition, const std::string& source_filena
}
static bool GenerateTarget(const Partition& target, const FileContents& source_file,
const Value& patch, const Value* bonus_data) {
const Value& patch, const Value* bonus_data, bool backup_source) {
uint8_t expected_sha1[SHA_DIGEST_LENGTH];
if (ParseSha1(target.hash, expected_sha1) != 0) {
LOG(ERROR) << "Failed to parse target hash \"" << target.hash << "\"";
@@ -347,11 +347,11 @@ static bool GenerateTarget(const Partition& target, const FileContents& source_f
}
// We write the original source to cache, in case the partition write is interrupted.
if (!CheckAndFreeSpaceOnCache(source_file.data.size())) {
if (backup_source && !CheckAndFreeSpaceOnCache(source_file.data.size())) {
LOG(ERROR) << "Not enough free space on /cache";
return false;
}
if (!SaveFileContents(Paths::Get().cache_temp_source(), &source_file)) {
if (backup_source && !SaveFileContents(Paths::Get().cache_temp_source(), &source_file)) {
LOG(ERROR) << "Failed to back up source file";
return false;
}
@@ -405,6 +405,42 @@ static bool GenerateTarget(const Partition& target, const FileContents& source_f
LOG(INFO) << " now " << short_sha1(expected_sha1);
// Write back the temp file to the partition.
if (!WriteBufferToPartition(patched, target)) {
LOG(ERROR) << "Failed to write patched data to " << target.name;
return false;
}
// Delete the backup copy of the source.
if (backup_source) {
unlink(Paths::Get().cache_temp_source().c_str());
}
// Success!
return true;
}
bool CheckPartition(const Partition& partition) {
FileContents target_file;
return ReadPartitionToBuffer(partition, &target_file, false);
}
Partition Partition::Parse(const std::string& input_str, std::string* err) {
std::vector<std::string> pieces = android::base::Split(input_str, ":");
if (pieces.size() != 4 || pieces[0] != "EMMC") {
*err = "Invalid number of tokens or non-eMMC target";
return {};
}
size_t size;
if (!android::base::ParseUint(pieces[2], &size) || size == 0) {
*err = "Failed to parse \"" + pieces[2] + "\" as byte count";
return {};
}
return Partition(pieces[1], size, pieces[3]);
}
std::string Partition::ToString() const {
if (*this) {
return "EMMC:"s + name + ":" + std::to_string(size) + ":" + hash;
}