2626#include " absl/log/log.h"
2727#include " absl/strings/numbers.h"
2828
29+ #include " cuttlefish/common/libs/utils/contains.h"
2930#include " cuttlefish/common/libs/utils/json.h"
3031#include " cuttlefish/host/libs/config/config_constants.h"
3132#include " cuttlefish/host/libs/config/cuttlefish_config.h"
@@ -40,6 +41,42 @@ using vm_manager::QemuManager;
4041
4142namespace {
4243
44+ static constexpr std::string_view kLegacyBoardBootconfigKeysShared [] = {
45+ " androidboot.hardware" ,
46+ " androidboot.vendor.apex.com.google.emulated.camera.provider.hal" ,
47+ " kernel.vmw_vsock_virtio_transport_common.virtio_transport_max_vsock_pkt_"
48+ " buf_size" ,
49+ };
50+
51+ static constexpr std::string_view kLegacyBoardBootconfigKeysAuto [] = {
52+ " androidboot.cuttlefish_service_bluetooth_checker" ,
53+ " androidboot.hibernation_resume_device" ,
54+
55+ // Used by `sdv_ivi_cf` targets.
56+ " androidboot.sdv.rpc.interface" ,
57+ " androidboot.sdv.telemetry.enabled" ,
58+ };
59+
60+ static constexpr std::string_view kLegacyBoardBootconfigKeysMinidroid [] = {
61+ " androidboot.adb.enabled" ,
62+ " androidboot.init_rc" ,
63+ " androidboot.microdroid.debuggable" ,
64+ };
65+
66+ static constexpr std::string_view kLegacyBoardBootconfigKeysSdvCore [] = {
67+ " androidboot.adb.enabled" ,
68+ " androidboot.init_rc" ,
69+ " androidboot.microdroid.debuggable" ,
70+ " androidboot.sdv.health_monitor.agent_startup_timeout_sec" ,
71+ " androidboot.sdv.max_bundles_management_threads" ,
72+ " androidboot.sdv.oem_metadata_device" ,
73+ " androidboot.sdv.oem_slot_a_device" ,
74+ " androidboot.sdv.oem_slot_b_device" ,
75+ " androidboot.sdv.rpc.interface" ,
76+ " androidboot.sdv.telemetry.enabled" ,
77+ " androidboot.sdv.telemetry.enabled:" ,
78+ };
79+
4380template <typename T>
4481void AppendMapWithReplacement (T* destination, const T& source) {
4582 for (const auto & [k, v] : source) {
@@ -72,10 +109,47 @@ Result<std::unordered_map<std::string, std::string>> ConsoleBootconfig(
72109
73110} // namespace
74111
112+ // Bootconfing args should be added to the launcher and no longer via the build
113+ // system variable `BOARD_BOOTCONFIG`. Allow legacy keys for backward
114+ // compatibility.
115+ Result<void > ValidateBoardBootconfigKeys (
116+ const cuttlefish::DeviceType type,
117+ const std::map<std::string, std::string, std::less<void >> args) {
118+ std::vector<std::string> allowed_args (
119+ std::begin (kLegacyBoardBootconfigKeysShared ),
120+ std::end (kLegacyBoardBootconfigKeysShared ));
121+ if (type == cuttlefish::DeviceType::Auto) {
122+ allowed_args.insert (allowed_args.end (),
123+ std::begin (kLegacyBoardBootconfigKeysAuto ),
124+ std::end (kLegacyBoardBootconfigKeysAuto ));
125+ } else if (type == cuttlefish::DeviceType::Minidroid) {
126+ allowed_args.insert (allowed_args.end (),
127+ std::begin (kLegacyBoardBootconfigKeysMinidroid ),
128+ std::end (kLegacyBoardBootconfigKeysMinidroid ));
129+ } else if (type == cuttlefish::DeviceType::Unknown) {
130+ // Sdv core targets don't define device type yet.
131+ allowed_args.insert (allowed_args.end (),
132+ std::begin (kLegacyBoardBootconfigKeysSdvCore ),
133+ std::end (kLegacyBoardBootconfigKeysSdvCore ));
134+ }
135+
136+ for (auto iter = args.begin (); iter != args.end (); iter++) {
137+ CF_EXPECTF (Contains (allowed_args, iter->first ),
138+ " Error: detected new `BOARD_BOOTCONFIG` key: \" {}\" for device "
139+ " type: \" {}\" !!! Please "
140+ " add new bootconfig args to the `cvd` launcher." ,
141+ iter->first , static_cast <int >(type));
142+ }
143+
144+ return {};
145+ }
146+
75147Result<std::unordered_map<std::string, std::string>> BootconfigArgsFromConfig (
76148 const CuttlefishConfig& config,
77149 const CuttlefishConfig::InstanceSpecific& instance,
78150 const std::map<std::string, std::string, std::less<void >> builtin_bootconfig_args) {
151+ CF_EXPECT (ValidateBoardBootconfigKeys (instance.device_type (), builtin_bootconfig_args));
152+
79153 std::unordered_map<std::string, std::string> bootconfig_args;
80154
81155 AppendMapWithReplacement (&bootconfig_args,
0 commit comments