update_engine: New BootControlInterface class.
The new BootControlInterface class is a platform-independent
abstraction to control the bootloader. It provides methods for setting
what partition slots are available for booting and getting the
bootloader status about the available slots.
The Chrome OS specific implementation of the bootloader was moved to
the BootControlChromeOS which now depends on the vboot_host
implementation used in Chrome OS. Follow up CL will implement the
equivalent class for Brillo.
BUG=b:23010637
TEST=unittests; cros flash from the new image and rolled back from it.
Change-Id: I0a03aeeb8c21d8c99e1866b625e6e8c96628215b
diff --git a/update_manager/chromeos_policy.cc b/update_manager/chromeos_policy.cc
index 80ef63b..1c77318 100644
--- a/update_manager/chromeos_policy.cc
+++ b/update_manager/chromeos_policy.cc
@@ -187,10 +187,10 @@
// Do not perform any updates if booted from removable device. This decision
// is final.
- const bool* is_boot_device_removable_p = ec->GetValue(
- system_provider->var_is_boot_device_removable());
- if (is_boot_device_removable_p && *is_boot_device_removable_p) {
- LOG(INFO) << "Booted from removable device, disabling update checks.";
+ const unsigned int* num_slots_p = ec->GetValue(
+ system_provider->var_num_slots());
+ if (!num_slots_p || *num_slots_p < 2) {
+ LOG(INFO) << "Not enough slots for A/B updates, disabling update checks.";
result->updates_enabled = false;
return EvalStatus::kSucceeded;
}
diff --git a/update_manager/chromeos_policy_unittest.cc b/update_manager/chromeos_policy_unittest.cc
index 05a5e4b..e456e19 100644
--- a/update_manager/chromeos_policy_unittest.cc
+++ b/update_manager/chromeos_policy_unittest.cc
@@ -91,8 +91,7 @@
new bool(true));
fake_state_.system_provider()->var_is_oobe_complete()->reset(
new bool(true));
- fake_state_.system_provider()->var_is_boot_device_removable()->reset(
- new bool(false));
+ fake_state_.system_provider()->var_num_slots()->reset(new unsigned int(2));
// Connection is wifi, untethered.
fake_state_.shill_provider()->var_conn_type()->
@@ -421,8 +420,7 @@
// UpdateCheckAllowed should return false (kSucceeded) if the image booted
// from a removable device.
- fake_state_.system_provider()->var_is_boot_device_removable()->reset(
- new bool(true));
+ fake_state_.system_provider()->var_num_slots()->reset(new unsigned int(1));
UpdateCheckParams result;
ExpectPolicyStatus(EvalStatus::kSucceeded,
diff --git a/update_manager/fake_system_provider.h b/update_manager/fake_system_provider.h
index 5124231..6036198 100644
--- a/update_manager/fake_system_provider.h
+++ b/update_manager/fake_system_provider.h
@@ -39,8 +39,8 @@
return &var_is_oobe_complete_;
}
- FakeVariable<bool>* var_is_boot_device_removable() override {
- return &var_is_boot_device_removable_;
+ FakeVariable<unsigned int>* var_num_slots() override {
+ return &var_num_slots_;
}
private:
@@ -50,9 +50,7 @@
"is_official_build", kVariableModeConst};
FakeVariable<bool> var_is_oobe_complete_{ // NOLINT(whitespace/braces)
"is_oobe_complete", kVariableModePoll};
- FakeVariable<bool>
- var_is_boot_device_removable_{ // NOLINT(whitespace/braces)
- "is_boot_device_removable", kVariableModePoll};
+ FakeVariable<unsigned int> var_num_slots_{"num_slots", kVariableModePoll};
DISALLOW_COPY_AND_ASSIGN(FakeSystemProvider);
};
diff --git a/update_manager/real_system_provider.cc b/update_manager/real_system_provider.cc
index abb920e..d0d788d 100644
--- a/update_manager/real_system_provider.cc
+++ b/update_manager/real_system_provider.cc
@@ -51,9 +51,9 @@
base::Bind(&chromeos_update_engine::HardwareInterface::IsOOBEComplete,
base::Unretained(hardware_), nullptr)));
- var_is_boot_device_removable_.reset(
- new ConstCopyVariable<bool>("is_boot_device_removable",
- hardware_->IsBootDeviceRemovable()));
+ var_num_slots_.reset(
+ new ConstCopyVariable<unsigned int>(
+ "num_slots", boot_control_->GetNumSlots()));
return true;
}
diff --git a/update_manager/real_system_provider.h b/update_manager/real_system_provider.h
index 3fc2d8d..a46a698 100644
--- a/update_manager/real_system_provider.h
+++ b/update_manager/real_system_provider.h
@@ -20,6 +20,7 @@
#include <memory>
#include <string>
+#include "update_engine/boot_control_interface.h"
#include "update_engine/hardware_interface.h"
#include "update_engine/update_manager/system_provider.h"
@@ -29,8 +30,9 @@
class RealSystemProvider : public SystemProvider {
public:
explicit RealSystemProvider(
- chromeos_update_engine::HardwareInterface* hardware)
- : hardware_(hardware) {}
+ chromeos_update_engine::HardwareInterface* hardware,
+ chromeos_update_engine::BootControlInterface* boot_control)
+ : hardware_(hardware), boot_control_(boot_control) {}
// Initializes the provider and returns whether it succeeded.
bool Init();
@@ -47,17 +49,18 @@
return var_is_oobe_complete_.get();
}
- Variable<bool>* var_is_boot_device_removable() override {
- return var_is_boot_device_removable_.get();
+ Variable<unsigned int>* var_num_slots() override {
+ return var_num_slots_.get();
}
private:
std::unique_ptr<Variable<bool>> var_is_normal_boot_mode_;
std::unique_ptr<Variable<bool>> var_is_official_build_;
std::unique_ptr<Variable<bool>> var_is_oobe_complete_;
- std::unique_ptr<Variable<bool>> var_is_boot_device_removable_;
+ std::unique_ptr<Variable<unsigned int>> var_num_slots_;
chromeos_update_engine::HardwareInterface* hardware_;
+ chromeos_update_engine::BootControlInterface* boot_control_;
DISALLOW_COPY_AND_ASSIGN(RealSystemProvider);
};
diff --git a/update_manager/real_system_provider_unittest.cc b/update_manager/real_system_provider_unittest.cc
index e28cc5c..35e9be1 100644
--- a/update_manager/real_system_provider_unittest.cc
+++ b/update_manager/real_system_provider_unittest.cc
@@ -21,6 +21,7 @@
#include <base/time/time.h>
#include <gtest/gtest.h>
+#include "update_engine/fake_boot_control.h"
#include "update_engine/fake_hardware.h"
#include "update_engine/update_manager/umtest_utils.h"
@@ -31,11 +32,13 @@
class UmRealSystemProviderTest : public ::testing::Test {
protected:
void SetUp() override {
- provider_.reset(new RealSystemProvider(&fake_hardware_));
+ provider_.reset(
+ new RealSystemProvider(&fake_hardware_, &fake_boot_control_));
EXPECT_TRUE(provider_->Init());
}
chromeos_update_engine::FakeHardware fake_hardware_;
+ chromeos_update_engine::FakeBootControl fake_boot_control_;
unique_ptr<RealSystemProvider> provider_;
};
diff --git a/update_manager/state_factory.cc b/update_manager/state_factory.cc
index 9bd028a..f90bd6e 100644
--- a/update_manager/state_factory.cc
+++ b/update_manager/state_factory.cc
@@ -48,7 +48,8 @@
unique_ptr<RealShillProvider> shill_provider(
new RealShillProvider(shill_proxy, clock));
unique_ptr<RealSystemProvider> system_provider(
- new RealSystemProvider(system_state->hardware()));
+ new RealSystemProvider(system_state->hardware(),
+ system_state->boot_control()));
unique_ptr<RealTimeProvider> time_provider(new RealTimeProvider(clock));
unique_ptr<RealUpdaterProvider> updater_provider(
new RealUpdaterProvider(system_state));
diff --git a/update_manager/system_provider.h b/update_manager/system_provider.h
index 5edec18..00fb9af 100644
--- a/update_manager/system_provider.h
+++ b/update_manager/system_provider.h
@@ -39,8 +39,8 @@
// Returns a variable that tells whether OOBE was completed.
virtual Variable<bool>* var_is_oobe_complete() = 0;
- // Returns a variable that tells the boot device is removable (USB stick etc).
- virtual Variable<bool>* var_is_boot_device_removable() = 0;
+ // Returns a variable that tells the number of slots in the system.
+ virtual Variable<unsigned int>* var_num_slots() = 0;
protected:
SystemProvider() {}