Skip to content

Commit e8d4a29

Browse files
committed
Add an AndroidEfiLoaderFlag type.
This removes the last flag default set by SetDefaultFlagsForQemu, and removes an ordering dependency that SetDefaultFlagsForVmm must be called before accessing `FLAGS_android_efi_loader`. Bug: b/436657168 Test: Run from cvd fetch --android_efi_loader_build=aosp_uefi-gbl-mainline/gbl_efi_dist_and_test
1 parent 24ce4c3 commit e8d4a29

9 files changed

Lines changed: 165 additions & 68 deletions

File tree

base/cvd/cuttlefish/host/commands/assemble_cvd/BUILD.bazel

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -193,6 +193,7 @@ cf_cc_library(
193193
"//cuttlefish/common/libs/utils:result",
194194
"//cuttlefish/host/commands/assemble_cvd:assemble_cvd_flags",
195195
"//cuttlefish/host/commands/assemble_cvd:super_image_mixer",
196+
"//cuttlefish/host/commands/assemble_cvd/flags:android_efi_loader",
196197
"//cuttlefish/host/commands/assemble_cvd/flags:boot_image",
197198
"//cuttlefish/host/commands/assemble_cvd/flags:bootloader",
198199
"//cuttlefish/host/commands/assemble_cvd/flags:initramfs_path",
@@ -258,6 +259,7 @@ cf_cc_library(
258259
"//cuttlefish/host/commands/assemble_cvd:guest_config",
259260
"//cuttlefish/host/commands/assemble_cvd:network_flags",
260261
"//cuttlefish/host/commands/assemble_cvd:touchpad",
262+
"//cuttlefish/host/commands/assemble_cvd/flags:android_efi_loader",
261263
"//cuttlefish/host/commands/assemble_cvd/flags:boot_image",
262264
"//cuttlefish/host/commands/assemble_cvd/flags:bootloader",
263265
"//cuttlefish/host/commands/assemble_cvd/flags:display_proto",

base/cvd/cuttlefish/host/commands/assemble_cvd/assemble_cvd_flags.cpp

Lines changed: 0 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -517,9 +517,6 @@ DEFINE_string(
517517
system_target_zip, CF_DEFAULTS_SYSTEM_TARGET_ZIP,
518518
"Location of system target zip file.");
519519

520-
DEFINE_string(android_efi_loader, CF_DEFAULTS_ANDROID_EFI_LOADER,
521-
"Location of android EFI loader for android efi load flow.");
522-
523520
DEFINE_string(linux_kernel_path, CF_DEFAULTS_LINUX_KERNEL_PATH,
524521
"Location of linux kernel for cuttlefish otheros flow.");
525522
DEFINE_string(linux_initramfs_path, CF_DEFAULTS_LINUX_INITRAMFS_PATH,

base/cvd/cuttlefish/host/commands/assemble_cvd/assemble_cvd_flags.h

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -234,8 +234,6 @@ DECLARE_string(vvmtruststore_path);
234234
DECLARE_string(default_target_zip);
235235
DECLARE_string(system_target_zip);
236236

237-
DECLARE_string(android_efi_loader);
238-
239237
DECLARE_string(linux_kernel_path);
240238
DECLARE_string(linux_initramfs_path);
241239
DECLARE_string(linux_root_image);

base/cvd/cuttlefish/host/commands/assemble_cvd/disk_image_flags_vectorization.cc

Lines changed: 4 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -26,6 +26,7 @@
2626

2727
#include "cuttlefish/common/libs/utils/result.h"
2828
#include "cuttlefish/host/commands/assemble_cvd/assemble_cvd_flags.h"
29+
#include "cuttlefish/host/commands/assemble_cvd/flags/android_efi_loader.h"
2930
#include "cuttlefish/host/commands/assemble_cvd/flags/boot_image.h"
3031
#include "cuttlefish/host/commands/assemble_cvd/flags/bootloader.h"
3132
#include "cuttlefish/host/commands/assemble_cvd/flags/initramfs_path.h"
@@ -41,6 +42,7 @@ namespace cuttlefish {
4142

4243
Result<void> DiskImageFlagsVectorization(
4344
CuttlefishConfig& config, const FetcherConfig& fetcher_config,
45+
const AndroidEfiLoaderFlag& android_efi_loader,
4446
const BootImageFlag& boot_image, const BootloaderFlag& bootloader,
4547
const InitramfsPathFlag& initramfs_path, const KernelPathFlag& kernel_path,
4648
const SystemImageDirFlag& system_image_dir) {
@@ -63,9 +65,6 @@ Result<void> DiskImageFlagsVectorization(
6365
std::vector<std::string> system_target_zip_vec =
6466
android::base::Split(FLAGS_system_target_zip, ",");
6567

66-
std::vector<std::string> android_efi_loader =
67-
android::base::Split(FLAGS_android_efi_loader, ",");
68-
6968
std::vector<std::string> chromeos_disk =
7069
android::base::Split(FLAGS_chromeos_disk, ",");
7170
std::vector<std::string> chromeos_kernel_path =
@@ -149,11 +148,8 @@ Result<void> DiskImageFlagsVectorization(
149148
cur_super_image = super_image[instance_index];
150149
}
151150
instance.set_super_image(cur_super_image);
152-
if (instance_index >= android_efi_loader.size()) {
153-
instance.set_android_efi_loader(android_efi_loader[0]);
154-
} else {
155-
instance.set_android_efi_loader(android_efi_loader[instance_index]);
156-
}
151+
instance.set_android_efi_loader(
152+
android_efi_loader.AndroidEfiLoaderForInstance(instance_index));
157153
if (instance_index >= chromeos_disk.size()) {
158154
instance.set_chromeos_disk(chromeos_disk[0]);
159155
} else {

base/cvd/cuttlefish/host/commands/assemble_cvd/disk_image_flags_vectorization.h

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,7 @@
1717
#pragma once
1818

1919
#include "cuttlefish/common/libs/utils/result.h"
20+
#include "cuttlefish/host/commands/assemble_cvd/flags/android_efi_loader.h"
2021
#include "cuttlefish/host/commands/assemble_cvd/flags/boot_image.h"
2122
#include "cuttlefish/host/commands/assemble_cvd/flags/bootloader.h"
2223
#include "cuttlefish/host/commands/assemble_cvd/flags/initramfs_path.h"
@@ -29,7 +30,7 @@ namespace cuttlefish {
2930

3031
Result<void> DiskImageFlagsVectorization(
3132
CuttlefishConfig& config, const FetcherConfig& fetcher_config,
32-
const BootImageFlag&, const BootloaderFlag&, const InitramfsPathFlag&,
33-
const KernelPathFlag&, const SystemImageDirFlag&);
33+
const AndroidEfiLoaderFlag&, const BootImageFlag&, const BootloaderFlag&,
34+
const InitramfsPathFlag&, const KernelPathFlag&, const SystemImageDirFlag&);
3435

3536
} // namespace cuttlefish

base/cvd/cuttlefish/host/commands/assemble_cvd/flags.cc

Lines changed: 7 additions & 53 deletions
Original file line numberDiff line numberDiff line change
@@ -49,6 +49,7 @@
4949
#include "cuttlefish/host/commands/assemble_cvd/assemble_cvd_flags.h"
5050
#include "cuttlefish/host/commands/assemble_cvd/disk_image_flags_vectorization.h"
5151
#include "cuttlefish/host/commands/assemble_cvd/display.h"
52+
#include "cuttlefish/host/commands/assemble_cvd/flags/android_efi_loader.h"
5253
#include "cuttlefish/host/commands/assemble_cvd/flags/boot_image.h"
5354
#include "cuttlefish/host/commands/assemble_cvd/flags/bootloader.h"
5455
#include "cuttlefish/host/commands/assemble_cvd/flags/display_proto.h"
@@ -1326,49 +1327,19 @@ Result<CuttlefishConfig> InitializeCuttlefishConfiguration(
13261327
calculated_gpu_mode_vec),
13271328
"The set of flags is incompatible with snapshot");
13281329

1330+
AndroidEfiLoaderFlag efi_loader =
1331+
AndroidEfiLoaderFlag::FromGlobalGflags(system_image_dir, vm_manager_flag);
1332+
13291333
BootloaderFlag bootloader = CF_EXPECT(BootloaderFlag::FromGlobalGflags(
13301334
guest_configs, system_image_dir, vm_manager_flag));
13311335

1332-
CF_EXPECT(DiskImageFlagsVectorization(tmp_config_obj, fetcher_config,
1333-
boot_image, bootloader, initramfs_path,
1334-
kernel_path, system_image_dir));
1336+
CF_EXPECT(DiskImageFlagsVectorization(
1337+
tmp_config_obj, fetcher_config, efi_loader, boot_image, bootloader,
1338+
initramfs_path, kernel_path, system_image_dir));
13351339

13361340
return tmp_config_obj;
13371341
}
13381342

1339-
Result<void> SetDefaultFlagsForQemu(
1340-
const SystemImageDirFlag& system_image_dir,
1341-
const std::vector<GuestConfig>& guest_configs,
1342-
std::map<std::string, std::string>& name_to_default_value) {
1343-
auto instance_nums =
1344-
CF_EXPECT(InstanceNumsCalculator().FromGlobalGflags().Calculate());
1345-
int32_t instances_size = instance_nums.size();
1346-
std::vector<std::string> gpu_mode_vec =
1347-
CF_EXPECT(GET_FLAG_STR_VALUE(gpu_mode));
1348-
std::string default_android_efi_loader = "";
1349-
1350-
for (int instance_index = 0; instance_index < instance_nums.size();
1351-
instance_index++) {
1352-
std::string curr_android_efi_loader =
1353-
system_image_dir.ForIndex(instance_index) + "/android_efi_loader.efi";
1354-
1355-
if (instance_index > 0) {
1356-
default_android_efi_loader += ",";
1357-
}
1358-
1359-
// EFI loader isn't presented in the output folder by default and can be
1360-
// only fetched by --uefi_app_build in fetch_cvd, so pick it only in case
1361-
// it's presented.
1362-
if (FileExists(curr_android_efi_loader)) {
1363-
default_android_efi_loader += curr_android_efi_loader;
1364-
}
1365-
}
1366-
SetCommandLineOptionWithMode("android_efi_loader",
1367-
default_android_efi_loader.c_str(),
1368-
google::FlagSettingMode::SET_FLAGS_DEFAULT);
1369-
return {};
1370-
}
1371-
13721343
Result<void> SetDefaultFlagsForCrosvm(
13731344
const SystemImageDirFlag& system_image_dir,
13741345
const std::vector<GuestConfig>& guest_configs,
@@ -1382,29 +1353,14 @@ Result<void> SetDefaultFlagsForCrosvm(
13821353
EnsureDirectoryExists(kCrosvmVarEmptyDir).ok() &&
13831354
IsDirectoryEmpty(kCrosvmVarEmptyDir) && !IsRunningInContainer();
13841355

1385-
std::string default_android_efi_loader = "";
13861356
std::string default_enable_sandbox_str = "";
13871357
for (int instance_index = 0; instance_index < instance_nums.size();
13881358
instance_index++) {
1389-
std::string curr_android_efi_loader =
1390-
system_image_dir.ForIndex(instance_index) + "/android_efi_loader.efi";
1391-
13921359
if (instance_index > 0) {
1393-
default_android_efi_loader += ",";
13941360
default_enable_sandbox_str += ",";
13951361
}
1396-
1397-
// EFI loader isn't presented in the output folder by default and can be
1398-
// only fetched by --uefi_app_build in fetch_cvd, so pick it only in case
1399-
// it's presented.
1400-
if (FileExists(curr_android_efi_loader)) {
1401-
default_android_efi_loader += curr_android_efi_loader;
1402-
}
14031362
default_enable_sandbox_str += fmt::format("{}", default_enable_sandbox);
14041363
}
1405-
SetCommandLineOptionWithMode("android_efi_loader",
1406-
default_android_efi_loader.c_str(),
1407-
google::FlagSettingMode::SET_FLAGS_DEFAULT);
14081364
// This is the 1st place to set "enable_sandbox" flag value
14091365
SetCommandLineOptionWithMode("enable_sandbox",
14101366
default_enable_sandbox_str.c_str(),
@@ -1468,8 +1424,6 @@ Result<void> SetFlagDefaultsForVmm(
14681424

14691425
switch (vm_manager_flag.Mode()) {
14701426
case VmmMode::kQemu:
1471-
CF_EXPECT(SetDefaultFlagsForQemu(system_image_dir, guest_configs,
1472-
name_to_default_value));
14731427
break;
14741428
case VmmMode::kCrosvm:
14751429
CF_EXPECT(SetDefaultFlagsForCrosvm(system_image_dir, guest_configs,

base/cvd/cuttlefish/host/commands/assemble_cvd/flags/BUILD.bazel

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,21 @@ package(
1818
default_visibility = ["//:android_cuttlefish"],
1919
)
2020

21+
cf_cc_library(
22+
name = "android_efi_loader",
23+
srcs = ["android_efi_loader.cc"],
24+
hdrs = ["android_efi_loader.h"],
25+
deps = [
26+
"//cuttlefish/common/libs/utils:files",
27+
"//cuttlefish/host/commands/assemble_cvd:flags_defaults",
28+
"//cuttlefish/host/commands/assemble_cvd/flags:system_image_dir",
29+
"//cuttlefish/host/commands/assemble_cvd/flags:vm_manager",
30+
"//cuttlefish/host/libs/config:vmm_mode",
31+
"@abseil-cpp//absl/strings",
32+
"@gflags",
33+
],
34+
)
35+
2136
cf_cc_library(
2237
name = "boot_image",
2338
srcs = ["boot_image.cc"],
Lines changed: 89 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,89 @@
1+
/*
2+
* Copyright (C) 2019 The Android Open Source Project
3+
*
4+
* Licensed under the Apache License, Version 2.0 (the "License");
5+
* you may not use this file except in compliance with the License.
6+
* You may obtain a copy of the License at
7+
*
8+
* http://www.apache.org/licenses/LICENSE-2.0
9+
*
10+
* Unless required by applicable law or agreed to in writing, software
11+
* distributed under the License is distributed on an "AS IS" BASIS,
12+
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13+
* See the License for the specific language governing permissions and
14+
* limitations under the License.
15+
*/
16+
#include "cuttlefish/host/commands/assemble_cvd/flags/android_efi_loader.h"
17+
18+
#include <stddef.h>
19+
20+
#include <string>
21+
#include <utility>
22+
#include <vector>
23+
24+
#include <gflags/gflags.h>
25+
#include "absl/strings/str_split.h"
26+
27+
#include "cuttlefish/common/libs/utils/files.h"
28+
#include "cuttlefish/host/commands/assemble_cvd/flags/system_image_dir.h"
29+
#include "cuttlefish/host/commands/assemble_cvd/flags/vm_manager.h"
30+
#include "cuttlefish/host/commands/assemble_cvd/flags_defaults.h"
31+
#include "cuttlefish/host/libs/config/vmm_mode.h"
32+
33+
DEFINE_string(android_efi_loader, CF_DEFAULTS_ANDROID_EFI_LOADER,
34+
"Location of android EFI loader for android efi load flow.");
35+
36+
namespace cuttlefish {
37+
38+
/* `--android_efi_loader` flag */
39+
AndroidEfiLoaderFlag AndroidEfiLoaderFlag::FromGlobalGflags(
40+
const SystemImageDirFlag& system_image_dir, const VmManagerFlag& vmm) {
41+
bool enabled = false;
42+
switch (vmm.Mode()) {
43+
case VmmMode::kCrosvm:
44+
case VmmMode::kQemu:
45+
enabled = true;
46+
break;
47+
case VmmMode::kGem5:
48+
case VmmMode::kUnknown:
49+
enabled = false;
50+
break;
51+
}
52+
gflags::CommandLineFlagInfo flag_info =
53+
gflags::GetCommandLineFlagInfoOrDie("bootloader");
54+
if (flag_info.is_default) {
55+
return AndroidEfiLoaderFlag(system_image_dir, {}, enabled);
56+
}
57+
std::vector<std::string> loaders =
58+
absl::StrSplit(FLAGS_android_efi_loader, ",");
59+
return AndroidEfiLoaderFlag(system_image_dir, std::move(loaders), enabled);
60+
}
61+
62+
AndroidEfiLoaderFlag::AndroidEfiLoaderFlag(
63+
const SystemImageDirFlag& system_image_dir, std::vector<std::string> flag,
64+
bool enabled)
65+
: system_image_dir_(system_image_dir),
66+
flag_(std::move(flag)),
67+
enabled_(enabled) {}
68+
69+
std::string AndroidEfiLoaderFlag::AndroidEfiLoaderForInstance(
70+
size_t instance_index) const {
71+
if (instance_index < flag_.size()) {
72+
return flag_[instance_index];
73+
} else if (!flag_.empty()) {
74+
return flag_[0];
75+
} else if (!enabled_) {
76+
return "";
77+
}
78+
// EFI loader isn't present in the output folder by default and can be only
79+
// fetched by --android_efi_loader_build in fetch_cvd, so pick it only in case
80+
// it's present.
81+
std::string downloaded =
82+
system_image_dir_.ForIndex(instance_index) + "/android_efi_loader.efi";
83+
if (FileExists(downloaded)) {
84+
return downloaded;
85+
}
86+
return "";
87+
}
88+
89+
} // namespace cuttlefish
Lines changed: 45 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,45 @@
1+
/*
2+
* Copyright (C) 2019 The Android Open Source Project
3+
*
4+
* Licensed under the Apache License, Version 2.0 (the "License");
5+
* you may not use this file except in compliance with the License.
6+
* You may obtain a copy of the License at
7+
*
8+
* http://www.apache.org/licenses/LICENSE-2.0
9+
*
10+
* Unless required by applicable law or agreed to in writing, software
11+
* distributed under the License is distributed on an "AS IS" BASIS,
12+
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13+
* See the License for the specific language governing permissions and
14+
* limitations under the License.
15+
*/
16+
#pragma once
17+
18+
#include <stddef.h>
19+
20+
#include <string>
21+
#include <vector>
22+
23+
#include "cuttlefish/host/commands/assemble_cvd/flags/system_image_dir.h"
24+
#include "cuttlefish/host/commands/assemble_cvd/flags/vm_manager.h"
25+
26+
namespace cuttlefish {
27+
28+
/* `--android_efi_loader` flag */
29+
class AndroidEfiLoaderFlag {
30+
public:
31+
static AndroidEfiLoaderFlag FromGlobalGflags(const SystemImageDirFlag&,
32+
const VmManagerFlag&);
33+
34+
std::string AndroidEfiLoaderForInstance(size_t instance_index) const;
35+
36+
private:
37+
AndroidEfiLoaderFlag(const SystemImageDirFlag&, std::vector<std::string> flag,
38+
bool enabled);
39+
40+
const SystemImageDirFlag& system_image_dir_;
41+
std::vector<std::string> flag_;
42+
bool enabled_;
43+
};
44+
45+
} // namespace cuttlefish

0 commit comments

Comments
 (0)