Alex Deymo | 4243291 | 2013-07-12 20:21:15 -0700 | [diff] [blame] | 1 | // Copyright (c) 2013 The Chromium OS Authors. All rights reserved. |
| 2 | // Use of this source code is governed by a BSD-style license that can be |
| 3 | // found in the LICENSE file. |
| 4 | |
Gilad Arnold | cf175a0 | 2014-07-10 16:48:47 -0700 | [diff] [blame] | 5 | #ifndef UPDATE_ENGINE_HARDWARE_INTERFACE_H_ |
| 6 | #define UPDATE_ENGINE_HARDWARE_INTERFACE_H_ |
Alex Deymo | 4243291 | 2013-07-12 20:21:15 -0700 | [diff] [blame] | 7 | |
| 8 | #include <string> |
Alex Vakulenko | 59e253e | 2014-02-24 10:40:21 -0800 | [diff] [blame] | 9 | #include <vector> |
Alex Deymo | 4243291 | 2013-07-12 20:21:15 -0700 | [diff] [blame] | 10 | |
Alex Deymo | bccbc38 | 2014-04-03 13:38:55 -0700 | [diff] [blame] | 11 | #include <base/time/time.h> |
| 12 | |
Alex Deymo | 4243291 | 2013-07-12 20:21:15 -0700 | [diff] [blame] | 13 | namespace chromeos_update_engine { |
| 14 | |
| 15 | // The hardware interface allows access to the following parts of the system, |
| 16 | // closely related to the hardware: |
| 17 | // * crossystem exposed properties: firmware, hwid, etc. |
| 18 | // * Physical disk: partition booted from and partition name conversions. |
| 19 | // These stateless functions are tied together in this interface to facilitate |
| 20 | // unit testing. |
| 21 | class HardwareInterface { |
| 22 | public: |
Alex Deymo | 610277e | 2014-11-11 21:18:11 -0800 | [diff] [blame] | 23 | virtual ~HardwareInterface() {} |
| 24 | |
Don Garrett | 83692e4 | 2013-11-08 10:11:30 -0800 | [diff] [blame] | 25 | // Returns the currently booted kernel partition. "/dev/sda2", for example. |
Alex Vakulenko | d0fdfb3 | 2014-02-21 15:26:26 -0800 | [diff] [blame] | 26 | virtual std::string BootKernelDevice() const = 0; |
Don Garrett | 83692e4 | 2013-11-08 10:11:30 -0800 | [diff] [blame] | 27 | |
| 28 | // Returns the currently booted rootfs partition. "/dev/sda3", for example. |
Alex Vakulenko | d0fdfb3 | 2014-02-21 15:26:26 -0800 | [diff] [blame] | 29 | virtual std::string BootDevice() const = 0; |
Alex Deymo | 4243291 | 2013-07-12 20:21:15 -0700 | [diff] [blame] | 30 | |
Alex Deymo | 5708ecd | 2014-04-29 19:44:50 -0700 | [diff] [blame] | 31 | // Return whether the BootDevice() is a removable device. |
| 32 | virtual bool IsBootDeviceRemovable() const = 0; |
| 33 | |
Alex Vakulenko | 59e253e | 2014-02-24 10:40:21 -0800 | [diff] [blame] | 34 | // Returns a list of all kernel partitions available (whether bootable or not) |
Alex Vakulenko | d0fdfb3 | 2014-02-21 15:26:26 -0800 | [diff] [blame] | 35 | virtual std::vector<std::string> GetKernelDevices() const = 0; |
Alex Vakulenko | 59e253e | 2014-02-24 10:40:21 -0800 | [diff] [blame] | 36 | |
Don Garrett | 83692e4 | 2013-11-08 10:11:30 -0800 | [diff] [blame] | 37 | // Is the specified kernel partition currently bootable, based on GPT flags? |
| 38 | // Returns success. |
| 39 | virtual bool IsKernelBootable(const std::string& kernel_device, |
Alex Vakulenko | d0fdfb3 | 2014-02-21 15:26:26 -0800 | [diff] [blame] | 40 | bool* bootable) const = 0; |
Don Garrett | 83692e4 | 2013-11-08 10:11:30 -0800 | [diff] [blame] | 41 | |
| 42 | // Mark the specified kernel partition unbootable in GPT flags. We mark |
| 43 | // the other kernel as bootable inside postinst, not inside the UE. |
| 44 | // Returns success. |
| 45 | virtual bool MarkKernelUnbootable(const std::string& kernel_device) = 0; |
| 46 | |
J. Richard Barnette | 056b0ab | 2013-10-29 15:24:56 -0700 | [diff] [blame] | 47 | // Returns true if this is an official Chrome OS build, false otherwise. |
Alex Vakulenko | d0fdfb3 | 2014-02-21 15:26:26 -0800 | [diff] [blame] | 48 | virtual bool IsOfficialBuild() const = 0; |
J. Richard Barnette | 056b0ab | 2013-10-29 15:24:56 -0700 | [diff] [blame] | 49 | |
| 50 | // Returns true if the boot mode is normal or if it's unable to |
| 51 | // determine the boot mode. Returns false if the boot mode is |
| 52 | // developer. |
Alex Vakulenko | d0fdfb3 | 2014-02-21 15:26:26 -0800 | [diff] [blame] | 53 | virtual bool IsNormalBootMode() const = 0; |
J. Richard Barnette | 522d36f | 2013-10-28 17:22:12 -0700 | [diff] [blame] | 54 | |
Alex Deymo | bccbc38 | 2014-04-03 13:38:55 -0700 | [diff] [blame] | 55 | // Returns true if the OOBE process has been completed and EULA accepted, |
| 56 | // False otherwise. If True is returned, and |out_time_of_oobe| isn't null, |
| 57 | // the time-stamp of when OOBE happened is stored at |out_time_of_oobe|. |
| 58 | virtual bool IsOOBEComplete(base::Time* out_time_of_oobe) const = 0; |
| 59 | |
J. Richard Barnette | 522d36f | 2013-10-28 17:22:12 -0700 | [diff] [blame] | 60 | // Returns the HWID or an empty string on error. |
Alex Vakulenko | d0fdfb3 | 2014-02-21 15:26:26 -0800 | [diff] [blame] | 61 | virtual std::string GetHardwareClass() const = 0; |
J. Richard Barnette | 522d36f | 2013-10-28 17:22:12 -0700 | [diff] [blame] | 62 | |
| 63 | // Returns the firmware version or an empty string if the system is |
| 64 | // not running chrome os firmware. |
Alex Vakulenko | d0fdfb3 | 2014-02-21 15:26:26 -0800 | [diff] [blame] | 65 | virtual std::string GetFirmwareVersion() const = 0; |
J. Richard Barnette | 522d36f | 2013-10-28 17:22:12 -0700 | [diff] [blame] | 66 | |
| 67 | // Returns the ec version or an empty string if the system is not |
| 68 | // running a custom chrome os ec. |
Alex Vakulenko | d0fdfb3 | 2014-02-21 15:26:26 -0800 | [diff] [blame] | 69 | virtual std::string GetECVersion() const = 0; |
Alex Deymo | 4243291 | 2013-07-12 20:21:15 -0700 | [diff] [blame] | 70 | |
Alex Deymo | ebbe7ef | 2014-10-30 13:02:49 -0700 | [diff] [blame] | 71 | // Returns the powerwash_count from the stateful. If the file is not found |
| 72 | // or is invalid, returns -1. Brand new machines out of the factory or after |
| 73 | // recovery don't have this value set. |
| 74 | virtual int GetPowerwashCount() const = 0; |
Alex Deymo | 4243291 | 2013-07-12 20:21:15 -0700 | [diff] [blame] | 75 | }; |
| 76 | |
| 77 | } // namespace chromeos_update_engine |
| 78 | |
Gilad Arnold | cf175a0 | 2014-07-10 16:48:47 -0700 | [diff] [blame] | 79 | #endif // UPDATE_ENGINE_HARDWARE_INTERFACE_H_ |