Skip to content

Create a type to represent metadata.img creation #1282

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
wants to merge 3 commits into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
7 changes: 5 additions & 2 deletions base/cvd/cuttlefish/host/commands/assemble_cvd/BUILD.bazel
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,8 @@ cc_binary(
"//cuttlefish/common/libs/utils:flag_parser",
"//cuttlefish/common/libs/utils:in_sandbox",
"//cuttlefish/common/libs/utils:tee_logging",
"//cuttlefish/host/commands/assemble_cvd/disk:metadata_image",
"//cuttlefish/host/commands/assemble_cvd/disk:misc_image",
"//cuttlefish/host/commands/assemble_cvd:clean",
"//cuttlefish/host/commands/assemble_cvd:disk_flags",
"//cuttlefish/host/commands/assemble_cvd:display",
Expand All @@ -43,12 +45,12 @@ cc_binary(
"//cuttlefish/host/commands/assemble_cvd:flags_defaults",
"//cuttlefish/host/commands/assemble_cvd:touchpad",
"//cuttlefish/host/libs/command_util",
"//cuttlefish/host/libs/config/adb",
"//cuttlefish/host/libs/config/fastboot",
"//cuttlefish/host/libs/config:ap_boot_flow",
"//cuttlefish/host/libs/config:config_flag",
"//cuttlefish/host/libs/config:custom_actions",
"//cuttlefish/host/libs/config:fetcher_config",
"//cuttlefish/host/libs/config/adb",
"//cuttlefish/host/libs/config/fastboot",
"//cuttlefish/host/libs/feature:inject",
"//libbase",
"@gflags",
Expand Down Expand Up @@ -204,6 +206,7 @@ cc_library(
"//cuttlefish/host/commands/assemble_cvd/disk:initialize_instance_composite_disk",
"//cuttlefish/host/commands/assemble_cvd/disk:kernel_ramdisk_repacker",
"//cuttlefish/host/commands/assemble_cvd/disk:metadata_image",
"//cuttlefish/host/commands/assemble_cvd/disk:misc_image",
"//cuttlefish/host/commands/assemble_cvd/disk:os_composite_disk",
"//cuttlefish/host/commands/assemble_cvd/disk:pflash",
"//cuttlefish/host/commands/assemble_cvd/disk:pstore",
Expand Down
53 changes: 28 additions & 25 deletions base/cvd/cuttlefish/host/commands/assemble_cvd/assemble_cvd.cc
Original file line number Diff line number Diff line change
Expand Up @@ -22,29 +22,31 @@
#include <android-base/strings.h>
#include <gflags/gflags.h>

#include "common/libs/fs/shared_buf.h"
#include "common/libs/fs/shared_fd.h"
#include "common/libs/utils/contains.h"
#include "common/libs/utils/environment.h"
#include "common/libs/utils/files.h"
#include "common/libs/utils/flag_parser.h"
#include "common/libs/utils/in_sandbox.h"
#include "common/libs/utils/known_paths.h"
#include "common/libs/utils/tee_logging.h"
#include "cuttlefish/common/libs/fs/shared_buf.h"
#include "cuttlefish/common/libs/fs/shared_fd.h"
#include "cuttlefish/common/libs/utils/contains.h"
#include "cuttlefish/common/libs/utils/environment.h"
#include "cuttlefish/common/libs/utils/files.h"
#include "cuttlefish/common/libs/utils/flag_parser.h"
#include "cuttlefish/common/libs/utils/in_sandbox.h"
#include "cuttlefish/common/libs/utils/known_paths.h"
#include "cuttlefish/common/libs/utils/tee_logging.h"
#include "cuttlefish/host/commands/assemble_cvd/clean.h"
#include "cuttlefish/host/commands/assemble_cvd/disk/metadata_image.h"
#include "cuttlefish/host/commands/assemble_cvd/disk/misc_image.h"
#include "cuttlefish/host/commands/assemble_cvd/disk_flags.h"
#include "cuttlefish/host/commands/assemble_cvd/display.h"
#include "cuttlefish/host/commands/assemble_cvd/flag_feature.h"
#include "cuttlefish/host/commands/assemble_cvd/flags.h"
#include "cuttlefish/host/commands/assemble_cvd/flags_defaults.h"
#include "cuttlefish/host/commands/assemble_cvd/touchpad.h"
#include "cuttlefish/host/libs/command_util/snapshot_utils.h"
#include "cuttlefish/host/libs/config/adb/adb.h"
#include "cuttlefish/host/libs/config/config_flag.h"
#include "host/commands/assemble_cvd/clean.h"
#include "host/commands/assemble_cvd/disk_flags.h"
#include "host/commands/assemble_cvd/display.h"
#include "host/commands/assemble_cvd/flag_feature.h"
#include "host/commands/assemble_cvd/flags.h"
#include "host/commands/assemble_cvd/flags_defaults.h"
#include "host/commands/assemble_cvd/touchpad.h"
#include "host/libs/command_util/snapshot_utils.h"
#include "host/libs/config/adb/adb.h"
#include "host/libs/config/custom_actions.h"
#include "host/libs/config/fastboot/fastboot.h"
#include "host/libs/config/fetcher_config.h"
#include "host/libs/feature/inject.h"
#include "cuttlefish/host/libs/config/custom_actions.h"
#include "cuttlefish/host/libs/config/fastboot/fastboot.h"
#include "cuttlefish/host/libs/config/fetcher_config.h"
#include "cuttlefish/host/libs/feature/inject.h"

using cuttlefish::StringFromEnv;

Expand Down Expand Up @@ -266,7 +268,7 @@ Result<std::set<std::string>> PreservingOnResume(
preserving.insert("pflash.img");
preserving.insert("uboot_env.img");
preserving.insert("factory_reset_protected.img");
preserving.insert("misc.img");
preserving.insert(MiscImage::Name());
preserving.insert("vmmtruststore.img");
preserving.insert(MetadataImage::Name());
preserving.insert("persistent_vbmeta.img");
Expand Down Expand Up @@ -370,9 +372,10 @@ Result<const CuttlefishConfig*> InitFilesystemAndCreateConfig(
// then don't preserve any files and delete everything.
for (const auto& instance : config.Instances()) {
Result<MetadataImage> metadata = MetadataImage::Reuse(instance);
if (metadata.ok()) {
Result<MiscImage> misc = MiscImage::Reuse(instance);
if (metadata.ok() && misc.ok()) {
DiskBuilder os_builder =
OsCompositeDiskBuilder(config, instance, *metadata);
OsCompositeDiskBuilder(config, instance, *metadata, *misc);
creating_os_disk |= CF_EXPECT(os_builder.WillRebuildCompositeDisk());
} else {
creating_os_disk = true;
Expand Down
25 changes: 25 additions & 0 deletions base/cvd/cuttlefish/host/commands/assemble_cvd/disk/BUILD.bazel
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,7 @@ cc_library(
deps = [
"//cuttlefish/common/libs/utils:files",
"//cuttlefish/host/commands/assemble_cvd/disk:metadata_image",
"//cuttlefish/host/commands/assemble_cvd/disk:misc_image",
"//cuttlefish/host/libs/config:cuttlefish_config",
"//cuttlefish/host/libs/image_aggregator",
"//libbase",
Expand All @@ -56,6 +57,7 @@ cc_library(
"//cuttlefish/common/libs/utils:files",
"//cuttlefish/host/commands/assemble_cvd/disk:android_composite_disk_config",
"//cuttlefish/host/commands/assemble_cvd/disk:metadata_image",
"//cuttlefish/host/commands/assemble_cvd/disk:misc_image",
"//cuttlefish/host/libs/config:cuttlefish_config",
"//cuttlefish/host/libs/image_aggregator",
],
Expand Down Expand Up @@ -358,6 +360,28 @@ clang_tidy_test(
tags = ["clang_tidy", "clang-tidy"],
)

cc_library(
name = "misc_image",
srcs = ["misc_image.cc"],
hdrs = ["misc_image.h"],
copts = COPTS,
strip_include_prefix = "//cuttlefish",
deps = [
"//cuttlefish/common/libs/utils:files",
"//cuttlefish/common/libs/utils:result",
"//cuttlefish/host/libs/config:cuttlefish_config",
"//cuttlefish/host/libs/config:data_image",
"//cuttlefish/host/libs/image_aggregator",
"//libbase",
],
)

clang_tidy_test(
name = "misc_image_clang_tidy",
srcs = [":misc_image"],
tags = ["clang_tidy", "clang-tidy"],
)

cc_library(
name = "os_composite_disk",
srcs = ["os_composite_disk.cc"],
Expand All @@ -371,6 +395,7 @@ cc_library(
"//cuttlefish/host/commands/assemble_cvd/disk:fuchsia_composite_disk",
"//cuttlefish/host/commands/assemble_cvd/disk:linux_composite_disk",
"//cuttlefish/host/commands/assemble_cvd/disk:metadata_image",
"//cuttlefish/host/commands/assemble_cvd/disk:misc_image",
"//cuttlefish/host/libs/config:boot_flow",
"//cuttlefish/host/libs/config:cuttlefish_config",
"//cuttlefish/host/libs/image_aggregator",
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -24,20 +24,18 @@

#include "cuttlefish/common/libs/utils/files.h"
#include "cuttlefish/host/commands/assemble_cvd/disk/metadata_image.h"
#include "cuttlefish/host/commands/assemble_cvd/disk/misc_image.h"
#include "cuttlefish/host/libs/config/cuttlefish_config.h"
#include "cuttlefish/host/libs/image_aggregator/image_aggregator.h"

namespace cuttlefish {

std::vector<ImagePartition> AndroidCompositeDiskConfig(
const CuttlefishConfig::InstanceSpecific& instance,
const MetadataImage& metadata_image) {
const MetadataImage& metadata_image, const MiscImage& misc_image) {
std::vector<ImagePartition> partitions;

partitions.push_back(ImagePartition{
.label = "misc",
.image_file_path = AbsolutePath(instance.misc_image()),
});
partitions.push_back(misc_image.Partition());
partitions.push_back(ImagePartition{
.label = "boot_a",
.image_file_path = AbsolutePath(instance.new_boot_image()),
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -18,12 +18,14 @@
#include <vector>

#include "cuttlefish/host/commands/assemble_cvd/disk/metadata_image.h"
#include "cuttlefish/host/commands/assemble_cvd/disk/misc_image.h"
#include "cuttlefish/host/libs/config/cuttlefish_config.h"
#include "cuttlefish/host/libs/image_aggregator/image_aggregator.h"

namespace cuttlefish {

std::vector<ImagePartition> AndroidCompositeDiskConfig(
const CuttlefishConfig::InstanceSpecific& instance, const MetadataImage&);
const CuttlefishConfig::InstanceSpecific& instance, const MetadataImage&,
const MiscImage&);

} // namespace cuttlefish
Original file line number Diff line number Diff line change
Expand Up @@ -21,16 +21,17 @@
#include "cuttlefish/common/libs/utils/files.h"
#include "cuttlefish/host/commands/assemble_cvd/disk/android_composite_disk_config.h"
#include "cuttlefish/host/commands/assemble_cvd/disk/metadata_image.h"
#include "cuttlefish/host/commands/assemble_cvd/disk/misc_image.h"
#include "cuttlefish/host/libs/config/cuttlefish_config.h"
#include "cuttlefish/host/libs/image_aggregator/image_aggregator.h"

namespace cuttlefish {

std::vector<ImagePartition> AndroidEfiLoaderCompositeDiskConfig(
const CuttlefishConfig::InstanceSpecific& instance,
const MetadataImage& metadata) {
const MetadataImage& metadata, const MiscImage& misc) {
std::vector<ImagePartition> partitions =
AndroidCompositeDiskConfig(instance, metadata);
AndroidCompositeDiskConfig(instance, metadata, misc);
// Cuttlefish uboot EFI bootflow by default looks at the first partition
// for EFI application. Thus we put "android_esp" at the beginning.
partitions.insert(
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -19,12 +19,14 @@
#include <vector>

#include "cuttlefish/host/commands/assemble_cvd/disk/metadata_image.h"
#include "cuttlefish/host/commands/assemble_cvd/disk/misc_image.h"
#include "cuttlefish/host/libs/config/cuttlefish_config.h"
#include "cuttlefish/host/libs/image_aggregator/image_aggregator.h"

namespace cuttlefish {

std::vector<ImagePartition> AndroidEfiLoaderCompositeDiskConfig(
const CuttlefishConfig::InstanceSpecific& instance, const MetadataImage&);
const CuttlefishConfig::InstanceSpecific& instance, const MetadataImage&,
const MiscImage&);

} // namespace cuttlefish
60 changes: 60 additions & 0 deletions base/cvd/cuttlefish/host/commands/assemble_cvd/disk/misc_image.cc
Original file line number Diff line number Diff line change
@@ -0,0 +1,60 @@
/*
* Copyright (C) 2025 The Android Open Source Project
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/

#include "cuttlefish/host/commands/assemble_cvd/disk/misc_image.h"

#include <android-base/logging.h>

#include "cuttlefish/common/libs/utils/files.h"
#include "cuttlefish/common/libs/utils/result.h"
#include "cuttlefish/host/libs/config/cuttlefish_config.h"
#include "cuttlefish/host/libs/config/data_image.h"
#include "cuttlefish/host/libs/image_aggregator/image_aggregator.h"

namespace cuttlefish {

Result<MiscImage> MiscImage::Reuse(
const CuttlefishConfig::InstanceSpecific& instance) {
std::string path = instance.PerInstancePath(Name());
CF_EXPECT(FileHasContent(path));

LOG(DEBUG) << "misc partition image already exists";

return MiscImage(path);
}

Result<MiscImage> MiscImage::ReuseOrCreate(
const CuttlefishConfig::InstanceSpecific& instance) {
std::string path = instance.PerInstancePath(Name());

LOG(DEBUG) << "misc partition image: creating empty at '" << path << "'";
CF_EXPECT(CreateBlankImage(path, 1 /* mb */, "none"),
"Failed to create misc image");
return MiscImage(path);
}

MiscImage::MiscImage(std::string path) : path_(std::move(path)) {}

std::string MiscImage::Name() { return "misc.img"; }

ImagePartition MiscImage::Partition() const {
return ImagePartition{
.label = "misc",
.image_file_path = path_,
};
}

} // namespace cuttlefish
41 changes: 41 additions & 0 deletions base/cvd/cuttlefish/host/commands/assemble_cvd/disk/misc_image.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,41 @@
/*
* Copyright (C) 2025 The Android Open Source Project
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/

#pragma once

#include "cuttlefish/common/libs/utils/result.h"
#include "cuttlefish/host/libs/config/cuttlefish_config.h"
#include "cuttlefish/host/libs/image_aggregator/image_aggregator.h"

namespace cuttlefish {

class MiscImage {
public:
static Result<MiscImage> Reuse(const CuttlefishConfig::InstanceSpecific&);
static Result<MiscImage> ReuseOrCreate(
const CuttlefishConfig::InstanceSpecific&);

static std::string Name();

ImagePartition Partition() const;

private:
MiscImage(std::string);

std::string path_;
};

} // namespace cuttlefish
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,7 @@
#include "cuttlefish/host/commands/assemble_cvd/disk/fuchsia_composite_disk.h"
#include "cuttlefish/host/commands/assemble_cvd/disk/linux_composite_disk.h"
#include "cuttlefish/host/commands/assemble_cvd/disk/metadata_image.h"
#include "cuttlefish/host/commands/assemble_cvd/disk/misc_image.h"
#include "cuttlefish/host/libs/config/boot_flow.h"
#include "cuttlefish/host/libs/config/cuttlefish_config.h"
#include "cuttlefish/host/libs/image_aggregator/image_aggregator.h"
Expand All @@ -32,12 +33,12 @@ namespace cuttlefish {

std::vector<ImagePartition> GetOsCompositeDiskConfig(
const CuttlefishConfig::InstanceSpecific& instance,
const MetadataImage& metadata) {
const MetadataImage& metadata, const MiscImage& misc) {
switch (instance.boot_flow()) {
case BootFlow::Android:
return AndroidCompositeDiskConfig(instance, metadata);
return AndroidCompositeDiskConfig(instance, metadata, misc);
case BootFlow::AndroidEfiLoader:
return AndroidEfiLoaderCompositeDiskConfig(instance, metadata);
return AndroidEfiLoaderCompositeDiskConfig(instance, metadata, misc);
case BootFlow::ChromeOs:
return ChromeOsCompositeDiskConfig(instance);
case BootFlow::ChromeOsDisk:
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -19,12 +19,14 @@
#include <vector>

#include "cuttlefish/host/commands/assemble_cvd/disk/metadata_image.h"
#include "cuttlefish/host/commands/assemble_cvd/disk/misc_image.h"
#include "cuttlefish/host/libs/config/cuttlefish_config.h"
#include "cuttlefish/host/libs/image_aggregator/image_aggregator.h"

namespace cuttlefish {

std::vector<ImagePartition> GetOsCompositeDiskConfig(
const CuttlefishConfig::InstanceSpecific& instance, const MetadataImage&);
const CuttlefishConfig::InstanceSpecific& instance, const MetadataImage&,
const MiscImage&);

} // namespace cuttlefish
Loading
Loading