Skip to content
Merged
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
Original file line number Diff line number Diff line change
Expand Up @@ -36,8 +36,8 @@ class PhysicalPartitionsImpl : public AndroidBuild {
std::string Name() const override { return "PhysicalPartitions"; }

PrettyStruct Pretty() override {
return PrettyStruct(Name())
.Member("PhysicalPartitions()", PhysicalPartitions());
return PrettyStruct(Name()).Member("PhysicalPartitions()",
PhysicalPartitions());
}

Result<std::set<std::string, std::less<void>>> PhysicalPartitions() override {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -62,7 +62,9 @@ Result<std::vector<LpMetadataExtent>> PartitionExtents(
const android::fs_mgr::LpMetadata& metadata, std::string_view name) {
for (const LpMetadataPartition& partition : metadata.partitions) {
std::string partition_name = android::fs_mgr::GetPartitionName(partition);
if (name != WithoutSlotSuffix(partition_name)) {
bool exact_match = name == partition_name;
bool without_suffix_match = name == WithoutSlotSuffix(partition_name);
if (!(exact_match || without_suffix_match)) {
continue;
}
std::vector<LpMetadataExtent> extents;
Expand Down Expand Up @@ -145,7 +147,7 @@ class SuperImageAsBuildImpl : public AndroidBuild {
std::string extract_path = absl::StrCat(extract_dir_, "/", name, ".img");
unlink(extract_path.c_str()); // Ignore errors
SharedFD extract_fd =
SharedFD::Open(extract_path, O_RDWR | O_CREAT | O_EXCL);
SharedFD::Open(extract_path, O_RDWR | O_CREAT | O_EXCL, 0644);
CF_EXPECTF(extract_fd->IsOpen(), "Failed to open '{}': ", extract_path,
extract_fd->StrError());

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -25,9 +25,11 @@ cf_cc_library(
"//cuttlefish/common/libs/utils:files",
"//cuttlefish/host/commands/assemble_cvd/android_build",
"//cuttlefish/host/commands/assemble_cvd/disk:image_file",
"//cuttlefish/host/commands/assemble_cvd/flags:build_super_image",
"//cuttlefish/host/commands/assemble_cvd/flags:system_image_dir",
"//cuttlefish/host/libs/config:cuttlefish_config",
"//cuttlefish/host/libs/image_aggregator",
"//cuttlefish/host/libs/image_aggregator:super_builder",
"//cuttlefish/result",
"//libbase",
"@abseil-cpp//absl/strings",
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -30,9 +30,11 @@

#include "cuttlefish/common/libs/utils/files.h"
#include "cuttlefish/host/commands/assemble_cvd/android_build/android_build.h"
#include "cuttlefish/host/commands/assemble_cvd/flags/build_super_image.h"
#include "cuttlefish/host/commands/assemble_cvd/flags/system_image_dir.h"
#include "cuttlefish/host/libs/config/cuttlefish_config.h"
#include "cuttlefish/host/libs/image_aggregator/image_aggregator.h"
#include "cuttlefish/host/libs/image_aggregator/super_builder.h"
#include "cuttlefish/result/result.h"

namespace cuttlefish {
Expand Down Expand Up @@ -96,7 +98,6 @@ Result<std::vector<ImagePartition>> AndroidCompositeDiskConfig(
{std::string(kPartitions.init_boot), instance.init_boot_image()},
{std::string(kPartitions.metadata), ""},
{std::string(kPartitions.misc), ""},
{std::string(kPartitions.super), instance.new_super_image()},
{std::string(kPartitions.userdata), instance.new_data_image()},
{std::string(kPartitions.vbmeta), instance.new_vbmeta_image()},
{std::string(kPartitions.vbmeta_system), instance.vbmeta_system_image()},
Expand All @@ -106,6 +107,7 @@ Result<std::vector<ImagePartition>> AndroidCompositeDiskConfig(
instance.new_vbmeta_vendor_dlkm_image()},
{std::string(kPartitions.vendor_boot), instance.new_vendor_boot_image()},
{std::string(kPartitions.vvmtruststore), instance.vvmtruststore_path()},
{std::string(kPartitions.super), instance.new_super_image()},
};

for (std::string partition : CF_EXPECT(android_build.PhysicalPartitions())) {
Expand All @@ -128,9 +130,36 @@ Result<std::vector<ImagePartition>> AndroidCompositeDiskConfig(
CF_EXPECTF(!!inserted, "Duplicate images for '{}'", image_file->Name());
}

const BuildSuperImageFlag build_super_image =
CF_EXPECT(BuildSuperImageFlag::FromGlobalGflags());

for (const auto& [partition, path] : primary_paths) {
std::string path_used;
if (auto it = dynamic_paths.find(partition); it != dynamic_paths.end()) {
if (partition == "super" && build_super_image.ForIndex(instance.index())) {
CompositeSuperImageBuilder super_builder;

const std::string super_from_build =
CF_EXPECT(android_build.ImageFile("super"));
super_builder.BlockDeviceSize(FileSize(super_from_build));

const std::set<std::string, std::less<void>> system_partitions =
CF_EXPECT(android_build.SystemPartitions());
const std::set<std::string, std::less<void>> vendor_partitions =
CF_EXPECT(android_build.VendorPartitions());
for (const std::string& logical :
CF_EXPECT(android_build.LogicalPartitions())) {
const std::string path = CF_EXPECT(android_build.ImageFile(logical));
if (system_partitions.count(logical)) {
super_builder.SystemPartition(logical, path);
} else {
super_builder.VendorPartition(logical, path);
}
}
// TODO: b/480197663: system_other should be written as system_b
path_used = CF_EXPECT(super_builder.WriteToDirectory(
instance.instance_dir(), "super_composite.img", "super_header.img"));
} else if (auto it = dynamic_paths.find(partition);
it != dynamic_paths.end()) {
path_used = it->second;
} else if (FileExists(path)) {
path_used = path;
Expand Down
14 changes: 14 additions & 0 deletions base/cvd/cuttlefish/host/commands/assemble_cvd/flags/BUILD.bazel
Original file line number Diff line number Diff line change
Expand Up @@ -83,6 +83,20 @@ cf_cc_library(
],
)

cf_cc_library(
name = "build_super_image",
srcs = ["build_super_image.cc"],
hdrs = ["build_super_image.h"],
deps = [
"//cuttlefish/host/commands/assemble_cvd:flags_defaults",
"//cuttlefish/host/commands/assemble_cvd/flags:flag_base",
"//cuttlefish/host/commands/assemble_cvd/flags:from_gflags",
"//cuttlefish/result",
"//libbase",
"@gflags",
],
)

cf_cc_library(
name = "cpus",
srcs = ["cpus.cc"],
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,49 @@
/*
* 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/flags/build_super_image.h"

#include <utility>
#include <vector>

#include <gflags/gflags.h>

#include "cuttlefish/host/commands/assemble_cvd/flags/flag_base.h"
#include "cuttlefish/host/commands/assemble_cvd/flags/from_gflags.h"
#include "cuttlefish/result/result.h"

DEFINE_string(
experimental_build_super_image, "false",
"Build the super image at runtime. This is probably not what you want.");

namespace cuttlefish {
namespace {

constexpr char kFlagName[] = "experimental_build_super_image";

} // namespace

Result<BuildSuperImageFlag> BuildSuperImageFlag::FromGlobalGflags() {
const auto flag_info = gflags::GetCommandLineFlagInfoOrDie(kFlagName);
std::vector<bool> flag_values =
CF_EXPECT(BoolFromGlobalGflags(flag_info, kFlagName));
return BuildSuperImageFlag(std::move(flag_values));
}

BuildSuperImageFlag::BuildSuperImageFlag(std::vector<bool> flag_values)
: FlagBase<bool>(std::move(flag_values)) {}

} // namespace cuttlefish
Original file line number Diff line number Diff line change
@@ -0,0 +1,35 @@
/*
* Copyright (C) 2026 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 <vector>

#include "cuttlefish/host/commands/assemble_cvd/flags/flag_base.h"
#include "cuttlefish/result/result.h"

namespace cuttlefish {

class BuildSuperImageFlag : public FlagBase<bool> {
public:
static Result<BuildSuperImageFlag> FromGlobalGflags();
~BuildSuperImageFlag() override = default;

private:
BuildSuperImageFlag(std::vector<bool>);
};

} // namespace cuttlefish
1 change: 1 addition & 0 deletions base/cvd/cuttlefish/host/commands/start/main.cc
Original file line number Diff line number Diff line change
Expand Up @@ -154,6 +154,7 @@ const std::unordered_set<std::string>& BoolFlags() {
"enable_sandbox",
"enable_usb",
"enable_virtiofs",
"experimental_build_super_image",
"fail_fast",
"guest_enforce_security",
"kgdb",
Expand Down
21 changes: 21 additions & 0 deletions base/cvd/cuttlefish/host/libs/image_aggregator/BUILD.bazel
Original file line number Diff line number Diff line change
Expand Up @@ -133,6 +133,27 @@ cf_cc_library(
],
)

cf_cc_library(
name = "super_builder",
srcs = ["super_builder.cc"],
hdrs = ["super_builder.h"],
deps = [
"//cuttlefish/common/libs/fs",
"//cuttlefish/host/libs/config:log_string_to_dir",
"//cuttlefish/host/libs/image_aggregator:cdisk_spec_cc_proto",
"//cuttlefish/host/libs/image_aggregator:composite_disk",
"//cuttlefish/host/libs/image_aggregator:disk_image",
"//cuttlefish/host/libs/image_aggregator:image_from_file",
"//cuttlefish/pretty:unique_ptr",
"//cuttlefish/pretty/liblp",
"//cuttlefish/result",
"@abseil-cpp//absl/log",
"@abseil-cpp//absl/strings",
"@android_system_core//:liblp",
"@boringssl//:crypto",
],
)

cf_cc_library(
name = "qcow2",
srcs = ["qcow2.cc"],
Expand Down
Loading
Loading