Mark the new kernel invalid when starting an update.
Before we overwrite the new kernel, mark it as unbootable by setting the GPT
flags "successful" and "tries" to 0. This is good, but not critical as a
general behavior because it prevents the firmware from even trying a kernel
we think will be bad.
It's more useful, because it gives us a definitive way to know if the other
kernel is expected to be valid for purposes of things like rollback. There
will be a future CL to use it for preventing rollback to a known invalid
installation.
Also adds a MockHardware implementation backed by the FakeHardware
implementation, and switches MockSystemState to use it.
BUG=chromium:280816
TEST=Manual watching of flags, and multiple updates.
CQ-DEPEND=CL:176177
Change-Id: Idb083279cd1438a555c5165c69b25c351207e382
Reviewed-on: https://chromium-review.googlesource.com/176169
Reviewed-by: Don Garrett <dgarrett@chromium.org>
Tested-by: Don Garrett <dgarrett@chromium.org>
Reviewed-by: David Zeuthen <zeuthen@chromium.org>
Commit-Queue: Don Garrett <dgarrett@chromium.org>
diff --git a/fake_hardware.h b/fake_hardware.h
index 4351e2c..97ab8dd 100644
--- a/fake_hardware.h
+++ b/fake_hardware.h
@@ -5,6 +5,8 @@
#ifndef CHROMEOS_PLATFORM_UPDATE_ENGINE_FAKE_HARDWARE_H__
#define CHROMEOS_PLATFORM_UPDATE_ENGINE_FAKE_HARDWARE_H__
+#include <map>
+
#include "update_engine/hardware_interface.h"
namespace chromeos_update_engine {
@@ -13,7 +15,8 @@
class FakeHardware : public HardwareInterface {
public:
FakeHardware()
- : boot_device_("/dev/sdz5"),
+ : kernel_device_("/dev/sdz4"),
+ boot_device_("/dev/sdz5"),
is_official_build_(true),
is_normal_boot_mode_(true),
hardware_class_("Fake HWID BLAH-1234"),
@@ -21,7 +24,18 @@
ec_version_("Fake EC v1.0a") {}
// HardwareInterface methods.
+ virtual const std::string BootKernelDevice() { return kernel_device_; }
virtual const std::string BootDevice() { return boot_device_; }
+ virtual bool IsKernelBootable(const std::string& kernel_device,
+ bool* bootable)
+ { std::map<std::string, bool>::const_iterator i =
+ is_bootable_.find(kernel_device);
+ *bootable = (i != is_bootable_.end()) ? i->second : true;
+ return true; }
+
+ virtual bool MarkKernelUnbootable(const std::string& kernel_device)
+ { is_bootable_[kernel_device] = false; return true;}
+
virtual bool IsOfficialBuild() { return is_official_build_; }
virtual bool IsNormalBootMode() { return is_normal_boot_mode_; }
virtual std::string GetHardwareClass() { return hardware_class_; }
@@ -54,7 +68,9 @@
}
private:
+ std::string kernel_device_;
std::string boot_device_;
+ std::map<std::string, bool> is_bootable_;
bool is_official_build_;
bool is_normal_boot_mode_;
std::string hardware_class_;