Donate to e Foundation | Murena handsets with /e/OS | Own a part of Murena! Learn more

Commit 45180122 authored by Bowgo Tsai's avatar Bowgo Tsai
Browse files

Set libavb version into system property for Treble OTA

Set ro.boot.avb_version to "AVB_VERSION_MAJOR.AVB_VERSION_MINOR".
During Treble OTA match, the major version must be the same as that in
the avb metadata on disk, while the minor version can be equal or
greater to that in the avb metadata on disk.

See how avb versioning work on the following link:

  https://android-review.googlesource.com/#/c/342757/

Also renames AvbHashtreeDisabled() -> hashtree_disabled().

Bug: 35322304
Test: Early mount with AVB, checks [ro.boot.avb_version]: [1.0] exists.
Test: Not enable AVB, checks [ro.boot.avb_version] doesn't exists.

Change-Id: I5aaf476ca53c4fe817779518ba14b68ebcfdc6d6
Merged-In: I5aaf476ca53c4fe817779518ba14b68ebcfdc6d6
(cherry picked from commit 1a898c25)
parent 43b72b58
Loading
Loading
Loading
Loading
+4 −0
Original line number Diff line number Diff line
@@ -493,6 +493,10 @@ FsManagerAvbUniquePtr FsManagerAvbHandle::Open(const std::string& device_file_by
        return nullptr;
    }

    // Sets the MAJOR.MINOR for init to set it into "ro.boot.avb_version".
    avb_handle->avb_version_ =
        android::base::StringPrintf("%d.%d", AVB_VERSION_MAJOR, AVB_VERSION_MINOR);

    // Verifies vbmeta images against the digest passed from bootloader.
    if (!avb_verifier->VerifyVbmetaImages(*avb_handle->avb_slot_data_)) {
        LERROR << "VerifyVbmetaImages failed";
+3 −1
Original line number Diff line number Diff line
@@ -72,7 +72,8 @@ class FsManagerAvbHandle {
    // Otherwise, returns false.
    bool SetUpAvb(fstab_rec* fstab_entry, bool wait_for_verity_dev);

    bool AvbHashtreeDisabled() { return status_ == kFsManagerAvbHandleHashtreeDisabled; }
    bool hashtree_disabled() const { return status_ == kFsManagerAvbHandleHashtreeDisabled; }
    const std::string& avb_version() const { return avb_version_; }

    FsManagerAvbHandle(const FsManagerAvbHandle&) = delete;             // no copy
    FsManagerAvbHandle& operator=(const FsManagerAvbHandle&) = delete;  // no assignment
@@ -92,6 +93,7 @@ class FsManagerAvbHandle {
  private:
    AvbSlotVerifyData* avb_slot_data_;
    FsManagerAvbHandleStatus status_;
    std::string avb_version_;
};

#endif /* __CORE_FS_MGR_AVB_H */
+5 −2
Original line number Diff line number Diff line
@@ -1034,10 +1034,11 @@ static bool vboot_2_0_mount_partitions(const std::vector<fstab_rec*>& fstab_recs
        return false;
    }

    setenv("INIT_AVB_VERSION", avb_handle->avb_version().c_str(), 1);
    for (auto rec : fstab_recs) {
        bool need_create_dm_device = false;
        if (fs_mgr_is_avb(rec)) {
            if (avb_handle->AvbHashtreeDisabled()) {
            if (avb_handle->hashtree_disabled()) {
                LOG(INFO) << "avb hashtree disabled for '" << rec->mount_point << "'";
            } else if (avb_handle->SetUpAvb(rec, false /* wait_for_verity_dev */)) {
                need_create_dm_device = true;
@@ -1384,12 +1385,14 @@ int main(int argc, char** argv) {
    property_set("ro.boottime.init.selinux", getenv("INIT_SELINUX_TOOK"));

    // Set libavb version for Framework-only OTA match in Treble build.
    property_set("ro.boot.init.avb_version", std::to_string(AVB_MAJOR_VERSION).c_str());
    const char* avb_version = getenv("INIT_AVB_VERSION");
    if (avb_version) property_set("ro.boot.avb_version", avb_version);

    // Clean up our environment.
    unsetenv("INIT_SECOND_STAGE");
    unsetenv("INIT_STARTED_AT");
    unsetenv("INIT_SELINUX_TOOK");
    unsetenv("INIT_AVB_VERSION");

    // Now set up SELinux for second stage.
    selinux_initialize(false);