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

Commit bc05312e authored by Bowgo Tsai's avatar Bowgo Tsai Committed by android-build-merger
Browse files

Merge "fs_mgr: move AVB related source into libfs_avb"

am: e43c146e

Change-Id: Iea5eaef97c12127bc8c814ab63fc099df6964bea
parents 7a6df083 e43c146e
Loading
Loading
Loading
Loading
+27 −2
Original line number Diff line number Diff line
@@ -42,8 +42,6 @@ cc_library {
        "fs_mgr.cpp",
        "fs_mgr_format.cpp",
        "fs_mgr_verity.cpp",
        "fs_mgr_avb.cpp",
        "fs_mgr_avb_ops.cpp",
        "fs_mgr_dm_linear.cpp",
        "fs_mgr_overlayfs.cpp",
        "fs_mgr_vendor_overlay.cpp",
@@ -61,10 +59,12 @@ cc_library {
    ],
    static_libs: [
        "libavb",
        "libfs_avb",
        "libfstab",
        "libdm",
    ],
    export_static_lib_headers: [
        "libfs_avb",
        "libfstab",
        "libdm",
    ],
@@ -104,3 +104,28 @@ cc_library_static {
    export_include_dirs: ["include_fstab"],
    header_libs: ["libbase_headers"],
}

cc_library_static {
    name: "libfs_avb",
    defaults: ["fs_mgr_defaults"],
    recovery_available: true,
    export_include_dirs: ["libfs_avb/include"],
    srcs: [
        "libfs_avb/avb_ops.cpp",
        "libfs_avb/fs_avb.cpp",
    ],
    static_libs: [
        "libavb",
        "libfstab",
        "libdm",
    ],
    export_static_lib_headers: [
        "libfstab",
    ],
    shared_libs: [
        "libcrypto",
    ],
    header_libs: [
        "libbase_headers",
    ],
}
+13 −9
Original line number Diff line number Diff line
@@ -34,6 +34,7 @@
#include <unistd.h>

#include <functional>
#include <map>
#include <memory>
#include <string>
#include <thread>
@@ -53,6 +54,7 @@
#include <ext4_utils/ext4_sb.h>
#include <ext4_utils/ext4_utils.h>
#include <ext4_utils/wipe.h>
#include <fs_avb/fs_avb.h>
#include <fs_mgr_overlayfs.h>
#include <libdm/dm.h>
#include <liblp/metadata_format.h>
@@ -62,7 +64,6 @@
#include <log/log_properties.h>
#include <logwrap/logwrap.h>

#include "fs_mgr_avb.h"
#include "fs_mgr_priv.h"

#define KEY_LOC_PROP   "ro.crypto.keyfile.userdata"
@@ -82,6 +83,9 @@

using android::dm::DeviceMapper;
using android::dm::DmDeviceState;
using android::fs_mgr::AvbHandle;
using android::fs_mgr::AvbHashtreeResult;
using android::fs_mgr::AvbUniquePtr;

// record fs stat
enum FsStatFlags {
@@ -973,7 +977,7 @@ int fs_mgr_mount_all(fstab* fstab, int mount_mode) {
    int mount_errno = 0;
    int attempted_idx = -1;
    CheckpointManager checkpoint_manager;
    FsManagerAvbUniquePtr avb_handle(nullptr);
    AvbUniquePtr avb_handle(nullptr);

    if (!fstab) {
        return FS_MGR_MNTALL_FAIL;
@@ -1031,14 +1035,14 @@ int fs_mgr_mount_all(fstab* fstab, int mount_mode) {

        if (fstab->recs[i].fs_mgr_flags & MF_AVB) {
            if (!avb_handle) {
                avb_handle = FsManagerAvbHandle::Open();
                avb_handle = AvbHandle::Open();
                if (!avb_handle) {
                    LERROR << "Failed to open FsManagerAvbHandle";
                    LERROR << "Failed to open AvbHandle";
                    return FS_MGR_MNTALL_FAIL;
                }
            }
            if (avb_handle->SetUpAvbHashtree(&fstab->recs[i], true /* wait_for_verity_dev */) ==
                SetUpAvbHashtreeResult::kFail) {
                AvbHashtreeResult::kFail) {
                LERROR << "Failed to set up AVB on partition: "
                       << fstab->recs[i].mount_point << ", skipping!";
                /* Skips mounting the device. */
@@ -1232,7 +1236,7 @@ static int fs_mgr_do_mount_helper(fstab* fstab, const char* n_name, char* n_blk_
    int first_mount_errno = 0;
    char* mount_point;
    CheckpointManager checkpoint_manager(needs_checkpoint);
    FsManagerAvbUniquePtr avb_handle(nullptr);
    AvbUniquePtr avb_handle(nullptr);

    if (!fstab) {
        return FS_MGR_DOMNT_FAILED;
@@ -1275,14 +1279,14 @@ static int fs_mgr_do_mount_helper(fstab* fstab, const char* n_name, char* n_blk_

        if (fstab->recs[i].fs_mgr_flags & MF_AVB) {
            if (!avb_handle) {
                avb_handle = FsManagerAvbHandle::Open();
                avb_handle = AvbHandle::Open();
                if (!avb_handle) {
                    LERROR << "Failed to open FsManagerAvbHandle";
                    LERROR << "Failed to open AvbHandle";
                    return FS_MGR_DOMNT_FAILED;
                }
            }
            if (avb_handle->SetUpAvbHashtree(&fstab->recs[i], true /* wait_for_verity_dev */) ==
                SetUpAvbHashtreeResult::kFail) {
                AvbHashtreeResult::kFail) {
                LERROR << "Failed to set up AVB on partition: "
                       << fstab->recs[i].mount_point << ", skipping!";
                /* Skips mounting the device. */
+1 −1
Original line number Diff line number Diff line
@@ -21,8 +21,8 @@
#include <string>

#include <android-base/logging.h>
#include <fs_mgr.h>

#include "fs_mgr.h"
#include "fs_mgr_priv_boot_config.h"

/* The CHECK() in logging.h will use program invocation name as the tag.
+12 −6
Original line number Diff line number Diff line
@@ -22,7 +22,7 @@
 * SOFTWARE.
 */

#include "fs_mgr_priv_avb_ops.h"
#include "avb_ops.h"

#include <errno.h>
#include <fcntl.h>
@@ -37,11 +37,13 @@
#include <libavb/libavb.h>
#include <utils/Compat.h>

#include "fs_mgr.h"
#include "fs_mgr_priv.h"

using namespace std::literals;

namespace android {
namespace fs_mgr {

static AvbIOResult read_from_partition(AvbOps* ops, const char* partition, int64_t offset,
                                       size_t num_bytes, void* buffer, size_t* out_num_read) {
    return FsManagerAvbOps::GetInstanceFromAvbOps(ops)->ReadFromPartition(
@@ -59,7 +61,8 @@ static AvbIOResult dummy_read_rollback_index(AvbOps* ops ATTRIBUTE_UNUSED,

static AvbIOResult dummy_validate_vbmeta_public_key(
        AvbOps* ops ATTRIBUTE_UNUSED, const uint8_t* public_key_data ATTRIBUTE_UNUSED,
    size_t public_key_length ATTRIBUTE_UNUSED, const uint8_t* public_key_metadata ATTRIBUTE_UNUSED,
        size_t public_key_length ATTRIBUTE_UNUSED,
        const uint8_t* public_key_metadata ATTRIBUTE_UNUSED,
        size_t public_key_metadata_length ATTRIBUTE_UNUSED, bool* out_is_trusted) {
    // vbmeta public key has been checked in bootloader phase.
    // In user-space, returns true to pass the check.
@@ -178,3 +181,6 @@ AvbSlotVerifyResult FsManagerAvbOps::AvbSlotVerify(const std::string& ab_suffix,
    return avb_slot_verify(&avb_ops_, requested_partitions, ab_suffix.c_str(), flags,
                           AVB_HASHTREE_ERROR_MODE_RESTART_AND_INVALIDATE, out_data);
}

}  // namespace fs_mgr
}  // namespace android
+7 −7
Original line number Diff line number Diff line
@@ -22,15 +22,14 @@
 * SOFTWARE.
 */

#ifndef __CORE_FS_MGR_PRIV_AVB_OPS_H
#define __CORE_FS_MGR_PRIV_AVB_OPS_H
#pragma once

#include <map>
#include <string>

#include <libavb/libavb.h>

#include "fs_mgr.h"
namespace android {
namespace fs_mgr {

// This class provides C++ bindings to interact with libavb, a small
// self-contained piece of code that's intended to be used in bootloaders.
@@ -42,7 +41,7 @@
//     read and verify the metadata and store it into the out_data parameter.
//     The caller MUST check the integrity of metadata against the
//     androidboot.vbmeta.{hash_alg, size, digest} values from /proc/cmdline.
//     e.g., see class FsManagerAvbVerifier for more details.
//     e.g., see class AvbVerifier for more details.
//
class FsManagerAvbOps {
  public:
@@ -60,6 +59,7 @@ class FsManagerAvbOps {

  private:
    AvbOps avb_ops_;
    std::map<std::string, std::string> by_name_symlink_map_;
};
#endif /* __CORE_FS_MGR_PRIV_AVB_OPS_H */

}  // namespace fs_mgr
}  // namespace android
Loading