Skip to content

Commit 1e1dc54

Browse files
committed
Create a type to represent the --vendor_boot_image flag
This removes one part of the ordering dependency between `ResolveInstanceFiles` and `DiskImageFlagsVectorization`. Bug: b/438587104
1 parent f3dfc9a commit 1e1dc54

File tree

13 files changed

+169
-45
lines changed

13 files changed

+169
-45
lines changed

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

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -44,6 +44,7 @@ cf_cc_binary(
4444
"//cuttlefish/host/commands/assemble_cvd/flags:kernel_path",
4545
"//cuttlefish/host/commands/assemble_cvd/flags:super_image",
4646
"//cuttlefish/host/commands/assemble_cvd/flags:system_image_dir",
47+
"//cuttlefish/host/commands/assemble_cvd/flags:vendor_boot_image",
4748
"//cuttlefish/host/commands/assemble_cvd/flags:vm_manager",
4849
"//cuttlefish/host/libs/command_util",
4950
"//cuttlefish/host/libs/config:ap_boot_flow",
@@ -201,6 +202,7 @@ cf_cc_library(
201202
"//cuttlefish/host/commands/assemble_cvd/flags:kernel_path",
202203
"//cuttlefish/host/commands/assemble_cvd/flags:super_image",
203204
"//cuttlefish/host/commands/assemble_cvd/flags:system_image_dir",
205+
"//cuttlefish/host/commands/assemble_cvd/flags:vendor_boot_image",
204206
"//cuttlefish/host/libs/config:cuttlefish_config",
205207
"//cuttlefish/host/libs/config:fetcher_config",
206208
"//cuttlefish/host/libs/config:instance_nums",
@@ -269,6 +271,7 @@ cf_cc_library(
269271
"//cuttlefish/host/commands/assemble_cvd/flags:mcu_config_path",
270272
"//cuttlefish/host/commands/assemble_cvd/flags:super_image",
271273
"//cuttlefish/host/commands/assemble_cvd/flags:system_image_dir",
274+
"//cuttlefish/host/commands/assemble_cvd/flags:vendor_boot_image",
272275
"//cuttlefish/host/commands/assemble_cvd/flags:vm_manager",
273276
"//cuttlefish/host/libs/config:ap_boot_flow",
274277
"//cuttlefish/host/libs/config:config_constants",
@@ -405,6 +408,7 @@ cf_cc_library(
405408
"//cuttlefish/host/commands/assemble_cvd/flags:kernel_path",
406409
"//cuttlefish/host/commands/assemble_cvd/flags:super_image",
407410
"//cuttlefish/host/commands/assemble_cvd/flags:system_image_dir",
411+
"//cuttlefish/host/commands/assemble_cvd/flags:vendor_boot_image",
408412
"//cuttlefish/host/libs/config:instance_nums",
409413
"//libbase",
410414
"@gflags",

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

Lines changed: 16 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -47,6 +47,7 @@
4747
#include "cuttlefish/host/commands/assemble_cvd/flags/kernel_path.h"
4848
#include "cuttlefish/host/commands/assemble_cvd/flags/super_image.h"
4949
#include "cuttlefish/host/commands/assemble_cvd/flags/system_image_dir.h"
50+
#include "cuttlefish/host/commands/assemble_cvd/flags/vendor_boot_image.h"
5051
#include "cuttlefish/host/commands/assemble_cvd/flags/vm_manager.h"
5152
#include "cuttlefish/host/commands/assemble_cvd/flags_defaults.h"
5253
#include "cuttlefish/host/commands/assemble_cvd/resolve_instance_files.h"
@@ -320,18 +321,19 @@ Result<const CuttlefishConfig*> InitFilesystemAndCreateConfig(
320321
const InitramfsPathFlag& initramfs_path, const KernelPathFlag& kernel_path,
321322
const SuperImageFlag& super_image,
322323
const SystemImageDirFlag& system_image_dir,
324+
const VendorBootImageFlag& vendor_boot_image,
323325
const VmManagerFlag& vm_manager_flag) {
324326
{
325327
// The config object is created here, but only exists in memory until the
326328
// SaveConfig line below. Don't launch cuttlefish subprocesses between these
327329
// two operations, as those will assume they can read the config object from
328330
// disk.
329-
auto config =
330-
CF_EXPECT(InitializeCuttlefishConfiguration(
331-
FLAGS_instance_dir, guest_configs, injector,
332-
fetcher_config, boot_image, initramfs_path, kernel_path,
333-
super_image, system_image_dir, vm_manager_flag),
334-
"cuttlefish configuration initialization failed");
331+
auto config = CF_EXPECT(
332+
InitializeCuttlefishConfiguration(
333+
FLAGS_instance_dir, guest_configs, injector, fetcher_config,
334+
boot_image, initramfs_path, kernel_path, super_image,
335+
system_image_dir, vendor_boot_image, vm_manager_flag),
336+
"cuttlefish configuration initialization failed");
335337

336338
const std::string snapshot_path = FLAGS_snapshot_path;
337339
if (!snapshot_path.empty()) {
@@ -626,6 +628,9 @@ Result<int> AssembleCvdMain(int argc, char** argv) {
626628
SuperImageFlag super_image =
627629
SuperImageFlag::FromGlobalGflags(system_image_dir);
628630

631+
VendorBootImageFlag vendor_boot_image =
632+
VendorBootImageFlag::FromGlobalGflags(system_image_dir);
633+
629634
fruit::Injector<> injector(FlagsComponent, &system_image_dir);
630635

631636
for (auto& late_injected : injector.getMultibindings<LateInjected>()) {
@@ -654,9 +659,10 @@ Result<int> AssembleCvdMain(int argc, char** argv) {
654659
// gflags either consumes all arguments that start with - or leaves all of
655660
// them in place, and either errors out on unknown flags or accepts any flags.
656661

657-
CF_EXPECT(ResolveInstanceFiles(boot_image, initramfs_path, kernel_path,
658-
super_image, system_image_dir),
659-
"Failed to resolve instance files");
662+
CF_EXPECT(
663+
ResolveInstanceFiles(boot_image, initramfs_path, kernel_path, super_image,
664+
system_image_dir, vendor_boot_image),
665+
"Failed to resolve instance files");
660666
// Depends on ResolveInstanceFiles to set flag globals
661667
std::vector<GuestConfig> guest_configs =
662668
CF_EXPECT(ReadGuestConfig(boot_image, kernel_path, system_image_dir));
@@ -671,7 +677,7 @@ Result<int> AssembleCvdMain(int argc, char** argv) {
671677
CF_EXPECT(InitFilesystemAndCreateConfig(
672678
std::move(fetcher_config), guest_configs, injector, log,
673679
boot_image, initramfs_path, kernel_path, super_image,
674-
system_image_dir, vm_manager_flag),
680+
system_image_dir, vendor_boot_image, vm_manager_flag),
675681
"Failed to create config");
676682

677683
std::cout << GetConfigFilePath(*config) << "\n";

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

Lines changed: 0 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -472,10 +472,6 @@ DEFINE_bool(resume, CF_DEFAULTS_RESUME,
472472
"in. This flag is ignored if the underlying partition "
473473
"images have been updated since the first launch."
474474
"If the device starts from a snapshot, this will be always true.");
475-
DEFINE_string(
476-
vendor_boot_image, CF_DEFAULTS_VENDOR_BOOT_IMAGE,
477-
"Location of cuttlefish vendor boot image. If empty it is assumed to "
478-
"be vendor_boot.img in the directory specified by -system_image_dir.");
479475
DEFINE_string(vbmeta_image, CF_DEFAULTS_VBMETA_IMAGE,
480476
"Location of cuttlefish vbmeta image. If empty it is assumed to "
481477
"be vbmeta.img in the directory specified by -system_image_dir.");

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

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -220,7 +220,6 @@ DECLARE_string(instance_dir);
220220
DECLARE_string(snapshot_path);
221221
DECLARE_bool(resume);
222222

223-
DECLARE_string(vendor_boot_image);
224223
DECLARE_string(vbmeta_image);
225224
DECLARE_string(vbmeta_system_image);
226225
DECLARE_string(vbmeta_vendor_dlkm_image);

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

Lines changed: 7 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -33,6 +33,7 @@
3333
#include "cuttlefish/host/commands/assemble_cvd/flags/kernel_path.h"
3434
#include "cuttlefish/host/commands/assemble_cvd/flags/super_image.h"
3535
#include "cuttlefish/host/commands/assemble_cvd/flags/system_image_dir.h"
36+
#include "cuttlefish/host/commands/assemble_cvd/flags/vendor_boot_image.h"
3637
#include "cuttlefish/host/commands/assemble_cvd/super_image_mixer.h"
3738
#include "cuttlefish/host/libs/config/cuttlefish_config.h"
3839
#include "cuttlefish/host/libs/config/fetcher_config.h"
@@ -47,9 +48,8 @@ Result<void> DiskImageFlagsVectorization(
4748
const BootImageFlag& boot_image, const BootloaderFlag& bootloader,
4849
const InitramfsPathFlag& initramfs_path, const KernelPathFlag& kernel_path,
4950
const SuperImageFlag& super_image,
50-
const SystemImageDirFlag& system_image_dir) {
51-
std::vector<std::string> vendor_boot_image =
52-
android::base::Split(FLAGS_vendor_boot_image, ",");
51+
const SystemImageDirFlag& system_image_dir,
52+
const VendorBootImageFlag& vendor_boot_image) {
5353
std::vector<std::string> vbmeta_image =
5454
android::base::Split(FLAGS_vbmeta_image, ",");
5555
std::vector<std::string> vbmeta_system_image =
@@ -93,7 +93,6 @@ Result<void> DiskImageFlagsVectorization(
9393
android::base::Split(FLAGS_blank_sdcard_image_mb, ",");
9494

9595
std::string cur_boot_image;
96-
std::string cur_vendor_boot_image;
9796
int value{};
9897
int instance_index = 0;
9998
auto instance_nums =
@@ -106,13 +105,10 @@ Result<void> DiskImageFlagsVectorization(
106105

107106
instance.set_init_boot_image(system_image_dir.ForIndex(instance_index) +
108107
"/init_boot.img");
109-
if (instance_index >= vendor_boot_image.size()) {
110-
cur_vendor_boot_image = vendor_boot_image[0];
111-
} else {
112-
cur_vendor_boot_image = vendor_boot_image[instance_index];
113-
}
114-
instance.set_vendor_boot_image(cur_vendor_boot_image);
115-
instance.set_new_vendor_boot_image(cur_vendor_boot_image);
108+
instance.set_vendor_boot_image(
109+
vendor_boot_image.VendorBootImageForIndex(instance_index));
110+
instance.set_new_vendor_boot_image(
111+
vendor_boot_image.VendorBootImageForIndex(instance_index));
116112

117113
if (instance_index >= vbmeta_image.size()) {
118114
instance.set_vbmeta_image(vbmeta_image[0]);

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

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -24,6 +24,7 @@
2424
#include "cuttlefish/host/commands/assemble_cvd/flags/kernel_path.h"
2525
#include "cuttlefish/host/commands/assemble_cvd/flags/super_image.h"
2626
#include "cuttlefish/host/commands/assemble_cvd/flags/system_image_dir.h"
27+
#include "cuttlefish/host/commands/assemble_cvd/flags/vendor_boot_image.h"
2728
#include "cuttlefish/host/libs/config/cuttlefish_config.h"
2829
#include "cuttlefish/host/libs/config/fetcher_config.h"
2930

@@ -33,6 +34,6 @@ Result<void> DiskImageFlagsVectorization(
3334
CuttlefishConfig& config, const FetcherConfig& fetcher_config,
3435
const AndroidEfiLoaderFlag&, const BootImageFlag&, const BootloaderFlag&,
3536
const InitramfsPathFlag&, const KernelPathFlag&, const SuperImageFlag&,
36-
const SystemImageDirFlag&);
37+
const SystemImageDirFlag&, const VendorBootImageFlag&);
3738

3839
} // namespace cuttlefish

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

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -56,6 +56,7 @@
5656
#include "cuttlefish/host/commands/assemble_cvd/flags/kernel_path.h"
5757
#include "cuttlefish/host/commands/assemble_cvd/flags/mcu_config_path.h"
5858
#include "cuttlefish/host/commands/assemble_cvd/flags/system_image_dir.h"
59+
#include "cuttlefish/host/commands/assemble_cvd/flags/vendor_boot_image.h"
5960
#include "cuttlefish/host/commands/assemble_cvd/flags/vm_manager.h"
6061
#include "cuttlefish/host/commands/assemble_cvd/graphics_flags.h"
6162
#include "cuttlefish/host/commands/assemble_cvd/guest_config.h"
@@ -368,6 +369,7 @@ Result<CuttlefishConfig> InitializeCuttlefishConfiguration(
368369
const BootImageFlag& boot_image, const InitramfsPathFlag& initramfs_path,
369370
const KernelPathFlag& kernel_path, const SuperImageFlag& super_image,
370371
const SystemImageDirFlag& system_image_dir,
372+
const VendorBootImageFlag& vendor_boot_image,
371373
const VmManagerFlag& vm_manager_flag) {
372374
CuttlefishConfig tmp_config_obj;
373375
// If a snapshot path is provided, do not read all flags to set up the config.
@@ -1328,7 +1330,8 @@ Result<CuttlefishConfig> InitializeCuttlefishConfiguration(
13281330

13291331
CF_EXPECT(DiskImageFlagsVectorization(
13301332
tmp_config_obj, fetcher_config, efi_loader, boot_image, bootloader,
1331-
initramfs_path, kernel_path, super_image, system_image_dir));
1333+
initramfs_path, kernel_path, super_image, system_image_dir,
1334+
vendor_boot_image));
13321335

13331336
return tmp_config_obj;
13341337
}

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

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -25,6 +25,7 @@
2525
#include "cuttlefish/host/commands/assemble_cvd/flags/kernel_path.h"
2626
#include "cuttlefish/host/commands/assemble_cvd/flags/super_image.h"
2727
#include "cuttlefish/host/commands/assemble_cvd/flags/system_image_dir.h"
28+
#include "cuttlefish/host/commands/assemble_cvd/flags/vendor_boot_image.h"
2829
#include "cuttlefish/host/commands/assemble_cvd/flags/vm_manager.h"
2930
#include "cuttlefish/host/commands/assemble_cvd/guest_config.h"
3031
#include "cuttlefish/host/libs/config/cuttlefish_config.h"
@@ -42,7 +43,8 @@ Result<CuttlefishConfig> InitializeCuttlefishConfiguration(
4243
fruit::Injector<>& injector, const FetcherConfig& fetcher_config,
4344
const BootImageFlag&, const InitramfsPathFlag&,
4445
const KernelPathFlag& kernel_path, const SuperImageFlag&,
45-
const SystemImageDirFlag&, const VmManagerFlag&);
46+
const SystemImageDirFlag&, const VendorBootImageFlag&,
47+
const VmManagerFlag&);
4648

4749
std::string GetConfigFilePath(const CuttlefishConfig& config);
4850

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

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -144,6 +144,18 @@ cf_cc_library(
144144
],
145145
)
146146

147+
cf_cc_library(
148+
name = "vendor_boot_image",
149+
srcs = ["vendor_boot_image.cc"],
150+
hdrs = ["vendor_boot_image.h"],
151+
deps = [
152+
"//cuttlefish/host/commands/assemble_cvd:flags_defaults",
153+
"//cuttlefish/host/commands/assemble_cvd/flags:system_image_dir",
154+
"//libbase",
155+
"@gflags",
156+
],
157+
)
158+
147159
cf_cc_library(
148160
name = "vm_manager",
149161
srcs = ["vm_manager.cc"],
Lines changed: 68 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,68 @@
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/vendor_boot_image.h"
17+
18+
#include <stddef.h>
19+
20+
#include <string>
21+
#include <vector>
22+
23+
#include <android-base/strings.h>
24+
#include <gflags/gflags.h>
25+
26+
#include "cuttlefish/host/commands/assemble_cvd/flags/system_image_dir.h"
27+
#include "cuttlefish/host/commands/assemble_cvd/flags_defaults.h"
28+
29+
DEFINE_string(
30+
vendor_boot_image, CF_DEFAULTS_VENDOR_BOOT_IMAGE,
31+
"Location of cuttlefish vendor boot image. If empty it is assumed to "
32+
"be vendor_boot.img in the directory specified by -system_image_dir.");
33+
34+
namespace cuttlefish {
35+
36+
VendorBootImageFlag VendorBootImageFlag::FromGlobalGflags(
37+
const SystemImageDirFlag& system_image_dir) {
38+
gflags::CommandLineFlagInfo flag_info =
39+
gflags::GetCommandLineFlagInfoOrDie("vendor_boot_image");
40+
41+
std::vector<std::string> vendor_boot_images =
42+
flag_info.is_default ? std::vector<std::string>{}
43+
: android::base::Split(FLAGS_vendor_boot_image, ",");
44+
45+
return VendorBootImageFlag(system_image_dir, vendor_boot_images);
46+
}
47+
48+
std::string VendorBootImageFlag::VendorBootImageForIndex(size_t index) const {
49+
if (vendor_boot_images_.empty()) {
50+
return system_image_dir_.ForIndex(index) + "/vendor_boot.img";
51+
} else if (index < vendor_boot_images_.size()) {
52+
return vendor_boot_images_[index];
53+
} else {
54+
return vendor_boot_images_[0];
55+
}
56+
}
57+
58+
bool VendorBootImageFlag::IsDefault() const {
59+
return vendor_boot_images_.empty();
60+
}
61+
62+
VendorBootImageFlag::VendorBootImageFlag(
63+
const SystemImageDirFlag& system_image_dir,
64+
std::vector<std::string> vendor_boot_images)
65+
: system_image_dir_(system_image_dir),
66+
vendor_boot_images_(std::move(vendor_boot_images)) {}
67+
68+
} // namespace cuttlefish

0 commit comments

Comments
 (0)