Skip to content
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
Original file line number Diff line number Diff line change
Expand Up @@ -666,7 +666,7 @@ Result<int> AssembleCvdMain(int argc, char** argv) {
SuperImageFlag::FromGlobalGflags(system_image_dir);

VendorBootImageFlag vendor_boot_image =
VendorBootImageFlag::FromGlobalGflags(system_image_dir);
CF_EXPECT(VendorBootImageFlag::FromGlobalGflags(system_image_dir));

fruit::Injector<> injector(FlagsComponent, &system_image_dir);

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -335,7 +335,9 @@ cf_cc_library(
hdrs = ["vendor_boot_image.h"],
deps = [
"//cuttlefish/host/commands/assemble_cvd:flags_defaults",
"//cuttlefish/host/commands/assemble_cvd/flags:from_gflags",
"//cuttlefish/host/commands/assemble_cvd/flags:system_image_dir",
"//cuttlefish/result",
"@abseil-cpp//absl/strings",
"@gflags",
],
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -24,31 +24,62 @@
#include "absl/strings/str_split.h"
#include "gflags/gflags.h"

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

DEFINE_string(use_vendor_boot_debug,
CF_DEFAULTS_USE_VENDOR_BOOT_DEBUG ? "true" : "false",
"Use vendor_boot-debug.img in the system_image_dir instead of "
"vendor_boot.img. Has no effect if -vendor_boot_image is set.");

DEFINE_string(
vendor_boot_image, CF_DEFAULTS_VENDOR_BOOT_IMAGE,
"Location of cuttlefish vendor boot image. If empty it is assumed to "
"be vendor_boot.img in the directory specified by -system_image_dir.");
"Location of cuttlefish vendor boot image. If empty, the image is "
"selected from the directory specified by -system_image-dir based on "
"the value of -use_vendor_boot_debug.");

namespace cuttlefish {

VendorBootImageFlag VendorBootImageFlag::FromGlobalGflags(
Result<VendorBootImageFlag> VendorBootImageFlag::FromGlobalGflags(
const SystemImageDirFlag& system_image_dir) {
gflags::CommandLineFlagInfo flag_info =
gflags::CommandLineFlagInfo vendor_boot_image_flag_info =
gflags::GetCommandLineFlagInfoOrDie("vendor_boot_image");
gflags::CommandLineFlagInfo use_vendor_boot_debug_flag_info =
gflags::GetCommandLineFlagInfoOrDie("use_vendor_boot_debug");

FromGflags<bool> use_vendor_boot_debug_flag = CF_EXPECT(
BoolFromGlobalGflags(use_vendor_boot_debug_flag_info, "vendor_boot_image",
CF_DEFAULTS_USE_VENDOR_BOOT_DEBUG));

std::vector<std::string> vendor_boot_images =
flag_info.is_default ? std::vector<std::string>{}
: absl::StrSplit(FLAGS_vendor_boot_image, ',');
vendor_boot_image_flag_info.is_default
? std::vector<std::string>{}
: absl::StrSplit(FLAGS_vendor_boot_image, ',');

return VendorBootImageFlag(system_image_dir, vendor_boot_images);
return VendorBootImageFlag(system_image_dir, vendor_boot_images,
use_vendor_boot_debug_flag.values);
}

std::string VendorBootImageFlag::VendorBootImageForIndex(size_t index) const {
if (vendor_boot_images_.empty()) {
return system_image_dir_.ForIndex(index) + "/vendor_boot.img";
std::string dir = system_image_dir_.ForIndex(index);
bool use_vendor_boot_debug = false;

if (index < use_vendor_boot_debugs_.size()) {
use_vendor_boot_debug = use_vendor_boot_debugs_[index];
} else if (!use_vendor_boot_debugs_.empty()) {
use_vendor_boot_debug = use_vendor_boot_debugs_[0];
}

if (use_vendor_boot_debug) {
dir += "/vendor_boot-debug.img";
} else {
dir += "/vendor_boot.img";
}

return dir;
} else if (index < vendor_boot_images_.size()) {
return vendor_boot_images_[index];
} else {
Expand All @@ -62,8 +93,10 @@ bool VendorBootImageFlag::IsDefault() const {

VendorBootImageFlag::VendorBootImageFlag(
const SystemImageDirFlag& system_image_dir,
std::vector<std::string> vendor_boot_images)
std::vector<std::string> vendor_boot_images,
std::vector<bool> use_vendor_boot_debugs)
: system_image_dir_(system_image_dir),
vendor_boot_images_(std::move(vendor_boot_images)) {}
vendor_boot_images_(std::move(vendor_boot_images)),
use_vendor_boot_debugs_(std::move(use_vendor_boot_debugs)) {}

} // namespace cuttlefish
Original file line number Diff line number Diff line change
Expand Up @@ -21,23 +21,27 @@
#include <vector>

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

namespace cuttlefish {

/* Vendor boot image flag, `--vendor_boot_image` */
class VendorBootImageFlag {
public:
static VendorBootImageFlag FromGlobalGflags(const SystemImageDirFlag&);
static Result<VendorBootImageFlag> FromGlobalGflags(
const SystemImageDirFlag&);

std::string VendorBootImageForIndex(size_t index) const;

bool IsDefault() const;

private:
VendorBootImageFlag(const SystemImageDirFlag&, std::vector<std::string>);
VendorBootImageFlag(const SystemImageDirFlag&, std::vector<std::string>,
std::vector<bool>);

const SystemImageDirFlag& system_image_dir_;
std::vector<std::string> vendor_boot_images_;
std::vector<bool> use_vendor_boot_debugs_;
};

} // namespace cuttlefish
Original file line number Diff line number Diff line change
Expand Up @@ -131,6 +131,7 @@
#define CF_DEFAULTS_VBMETA_SYSTEM_IMAGE CF_DEFAULTS_DYNAMIC_STRING
#define CF_DEFAULTS_VBMETA_VENDOR_DLKM_IMAGE CF_DEFAULTS_DYNAMIC_STRING
#define CF_DEFAULTS_VBMETA_SYSTEM_DLKM_IMAGE CF_DEFAULTS_DYNAMIC_STRING
#define CF_DEFAULTS_USE_VENDOR_BOOT_DEBUG false
#define CF_DEFAULTS_VENDOR_BOOT_IMAGE CF_DEFAULTS_DYNAMIC_STRING
#define CF_DEFAULTS_DEFAULT_VVMTRUSTSTORE_FILE_NAME CF_DEFAULTS_DYNAMIC_STRING
#define CF_DEFAULTS_VVMTRUSTSTORE_PATH CF_DEFAULTS_DYNAMIC_STRING
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -137,6 +137,14 @@ static bool DownloadTargetFilesZip(const Instance& instance) {
}
}

static bool UseVendorBootDebug(const Instance& instance) {
if (instance.boot().has_use_vendor_boot_debug()) {
return instance.boot().use_vendor_boot_debug();
} else {
return kDefaultUseVendorBootDebug;
}
}

} // namespace

Result<std::vector<std::string>> ParseFetchCvdConfigs(
Expand Down Expand Up @@ -211,6 +219,8 @@ Result<std::vector<std::string>> ParseFetchCvdConfigs(
DownloadImgZip));
result.emplace_back(GenerateInstanceFlag(
"download_target_files_zip", fetch_instances, DownloadTargetFilesZip));
result.emplace_back(GenerateInstanceFlag(
"download_vendor_boot_debug", fetch_instances, UseVendorBootDebug));

return result;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -133,6 +133,83 @@ TEST(BootFlagsParserTest, ParseTwoInstancesBootAnimationFlagFullJson) {
<< "enable_bootanimation flag is missing or wrongly formatted";
}

TEST(BootFlagsParserTest, ParseTwoInstancesUseVendorBootDebugFlagPartialJson) {
const char* test_string = R""""(
{
"instances" :
[
{
"vm": {
"crosvm":{
}
},
"boot": {
}
},
{
"vm": {
"crosvm":{
}
},
"boot": {
"use_vendor_boot_debug": true
}
}
]
}
)"""";

Json::Value json_configs;
std::string json_text(test_string);

EXPECT_TRUE(ParseJsonString(json_text, json_configs))
<< "Invalid Json string";
auto serialized_data = LaunchCvdParserTester(json_configs);
ASSERT_THAT(serialized_data, IsOk());
EXPECT_TRUE(
FindConfig(*serialized_data, R"(--use_vendor_boot_debug=false,true)"))
<< "use_vendor_boot_debug flag is missing or wrongly formatted";
}

TEST(BootFlagsParserTest, ParseTwoInstancesUseVendorBootDebugFlagFullJson) {
const char* test_string = R""""(
{
"instances" :
[
{
"vm": {
"crosvm":{
}
},
"boot": {
"use_vendor_boot_debug": true
}
},
{
"vm": {
"crosvm":{
}
},
"boot": {
"use_vendor_boot_debug": true
}
}
]
}
)"""";

Json::Value json_configs;
std::string json_text(test_string);

EXPECT_TRUE(ParseJsonString(json_text, json_configs))
<< "Invalid Json string";
auto serialized_data = LaunchCvdParserTester(json_configs);
ASSERT_THAT(serialized_data, IsOk());
EXPECT_TRUE(
FindConfig(*serialized_data, R"(--use_vendor_boot_debug=true,true)"))
<< "use_vendor_boot_debug flag is missing or wrongly formatted";
}

TEST(BootFlagsParserTest, ParseTwoInstancesSerialNumberFlagEmptyJson) {
const char* test_string = R""""(
{
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -47,12 +47,19 @@ static Result<std::string> BootCfgArgs(const Instance& instance) {
return encoded;
}

static bool UseVendorBootDebug(const Instance& instance) {
const auto& boot = instance.boot();
return boot.has_use_vendor_boot_debug() ? boot.use_vendor_boot_debug()
: CF_DEFAULTS_USE_VENDOR_BOOT_DEBUG;
}

Result<std::vector<std::string>> GenerateBootFlags(
const EnvironmentSpecification& cfg) {
return std::vector<std::string>{
GenerateInstanceFlag("enable_bootanimation", cfg, EnableBootAnimation),
CF_EXPECT(
ResultInstanceFlag("extra_bootconfig_args_base64", cfg, BootCfgArgs)),
GenerateInstanceFlag("use_vendor_boot_debug", cfg, UseVendorBootDebug),
};
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -107,6 +107,7 @@ message Boot {
optional string build = 4;
optional Build bootloader = 5;
optional Build android_efi_loader = 6;
optional bool use_vendor_boot_debug = 7;
}

message Build {
Expand Down
4 changes: 4 additions & 0 deletions base/cvd/cuttlefish/host/commands/cvd/fetch/download_flags.cc
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,10 @@ DownloadFlags DownloadFlags::Create(const VectorFlags& flags, const int index) {
.value_or(kDefaultDownloadTargetFilesZip),
.dynamic_super_image = GetOptional(flags.dynamic_super_image, index)
.value_or(kDefaultDynamicSuperImageFragments),
.download_vendor_boot_debug =
GetOptional(flags.download_vendor_boot_debug, index)
.value_or(kDefaultUseVendorBootDebug),

};
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,7 @@ struct DownloadFlags {
bool download_img_zip;
bool download_target_files_zip;
bool dynamic_super_image;
bool download_vendor_boot_debug;
};

} // namespace cuttlefish
22 changes: 19 additions & 3 deletions base/cvd/cuttlefish/host/commands/cvd/fetch/fetch_cvd.cc
Original file line number Diff line number Diff line change
Expand Up @@ -192,6 +192,12 @@ Result<std::string> SaveConfig(FetcherConfig& config,
return fetcher_path;
}

Result<void> DownloadVendorBootDebug(FetchBuildContext& context) {
FetchArtifact vendor_boot_debug = context.Artifact("vendor_boot-debug.img");
CF_EXPECT(vendor_boot_debug.Download());
return {};
}

Result<void> FetchDefaultTarget(FetchBuildContext& context,
bool keep_downloaded_archives,
const DownloadFlags& flags,
Expand Down Expand Up @@ -253,6 +259,10 @@ Result<void> FetchDefaultTarget(FetchBuildContext& context,
}
}
}

if (flags.download_vendor_boot_debug) {
CF_EXPECT(DownloadVendorBootDebug(context));
}
return {};
}

Expand Down Expand Up @@ -314,7 +324,8 @@ Result<void> FetchKernelTarget(FetchBuildContext context) {
}

Result<void> FetchBootTarget(FetchBuildContext& context,
bool keep_downloaded_archives) {
bool keep_downloaded_archives,
bool download_vendor_boot_debug) {
const std::optional<std::string> filepath = context.GetFilepath();
const std::string to_download =
filepath.has_value() ? *filepath : context.GetBuildZipName("img");
Expand All @@ -323,7 +334,11 @@ Result<void> FetchBootTarget(FetchBuildContext& context,

if (!filepath.has_value()) {
CF_EXPECT(artifact.ExtractOne("boot.img"));
CF_EXPECT(artifact.ExtractOne("vendor_boot.img"));
if (download_vendor_boot_debug) {
CF_EXPECT(DownloadVendorBootDebug(context));
} else {
CF_EXPECT(artifact.ExtractOne("vendor_boot.img"));
}
if (!keep_downloaded_archives) {
CF_EXPECT(artifact.DeleteLocalFile());
}
Expand Down Expand Up @@ -422,7 +437,8 @@ Result<void> FetchTarget(FetchContext& fetch_context,
}

if (std::optional<FetchBuildContext> context = fetch_context.BootBuild()) {
CF_EXPECT(FetchBootTarget(*context, keep_downloaded_archives));
CF_EXPECT(FetchBootTarget(*context, keep_downloaded_archives,
flags.download_vendor_boot_debug));
}

if (std::optional<FetchBuildContext> ctx = fetch_context.BootloaderBuild()) {
Expand Down
4 changes: 4 additions & 0 deletions base/cvd/cuttlefish/host/commands/cvd/fetch/vector_flags.cc
Original file line number Diff line number Diff line change
Expand Up @@ -76,6 +76,10 @@ std::vector<Flag> VectorFlags::Flags() {
GflagsCompatFlag("dynamic_super_image", this->dynamic_super_image,
kDefaultDynamicSuperImageFragments)
.Help("Fetch the super image members as independent files."));
flags.emplace_back(GflagsCompatFlag("download_vendor_boot_debug",
this->download_vendor_boot_debug,
kDefaultUseVendorBootDebug)
.Help("Fetch vendor_boot-debug.img."));

return flags;
}
Expand Down
2 changes: 2 additions & 0 deletions base/cvd/cuttlefish/host/commands/cvd/fetch/vector_flags.h
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,7 @@ inline constexpr bool kDefaultDownloadImgZip = true;
inline constexpr bool kDefaultDownloadTargetFilesZip = false;
// TODO: schuffelen - Enable this by default.
inline constexpr bool kDefaultDynamicSuperImageFragments = false;
inline constexpr bool kDefaultUseVendorBootDebug = false;

struct VectorFlags {
std::vector<Flag> Flags();
Expand All @@ -49,6 +50,7 @@ struct VectorFlags {
std::vector<bool> download_target_files_zip;
std::vector<std::string> boot_artifact;
std::vector<bool> dynamic_super_image;
std::vector<bool> download_vendor_boot_debug;
};

} // namespace cuttlefish
Loading