Alex Deymo | aea4c1c | 2015-08-19 20:24:43 -0700 | [diff] [blame] | 1 | // |
| 2 | // Copyright (C) 2013 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 | // |
Alex Deymo | 4243291 | 2013-07-12 20:21:15 -0700 | [diff] [blame] | 16 | |
Alex Deymo | 1b03f9f | 2015-12-09 00:38:36 -0800 | [diff] [blame] | 17 | #include "update_engine/hardware_chromeos.h" |
Alex Deymo | 4243291 | 2013-07-12 20:21:15 -0700 | [diff] [blame] | 18 | |
Zentaro Kavanagh | baacb98 | 2018-02-20 17:48:39 -0800 | [diff] [blame] | 19 | #include <utility> |
| 20 | |
Alex Deymo | 46a9aae | 2016-05-04 20:20:11 -0700 | [diff] [blame] | 21 | #include <base/files/file_path.h> |
Ben Chan | 06c76a4 | 2014-09-05 08:21:06 -0700 | [diff] [blame] | 22 | #include <base/files/file_util.h> |
Alex Deymo | 4243291 | 2013-07-12 20:21:15 -0700 | [diff] [blame] | 23 | #include <base/logging.h> |
Alex Deymo | ebbe7ef | 2014-10-30 13:02:49 -0700 | [diff] [blame] | 24 | #include <base/strings/string_number_conversions.h> |
Alex Vakulenko | 75039d7 | 2014-03-25 12:36:28 -0700 | [diff] [blame] | 25 | #include <base/strings/string_util.h> |
Alex Deymo | 46a9aae | 2016-05-04 20:20:11 -0700 | [diff] [blame] | 26 | #include <brillo/key_value_store.h> |
Sen Jiang | e67bb5b | 2016-06-20 15:53:56 -0700 | [diff] [blame] | 27 | #include <debugd/dbus-constants.h> |
J. Richard Barnette | c7dd853 | 2013-10-29 16:30:46 -0700 | [diff] [blame] | 28 | #include <vboot/crossystem.h> |
Alex Deymo | 4243291 | 2013-07-12 20:21:15 -0700 | [diff] [blame] | 29 | |
Don Garrett | 83692e4 | 2013-11-08 10:11:30 -0800 | [diff] [blame] | 30 | extern "C" { |
| 31 | #include "vboot/vboot_host.h" |
| 32 | } |
| 33 | |
Alex Deymo | 46a9aae | 2016-05-04 20:20:11 -0700 | [diff] [blame] | 34 | #include "update_engine/common/constants.h" |
Alex Deymo | 39910dc | 2015-11-09 17:04:30 -0800 | [diff] [blame] | 35 | #include "update_engine/common/hardware.h" |
| 36 | #include "update_engine/common/hwid_override.h" |
Sen Jiang | 9c12346 | 2015-11-19 13:16:23 -0800 | [diff] [blame] | 37 | #include "update_engine/common/platform_constants.h" |
Alex Deymo | 39910dc | 2015-11-09 17:04:30 -0800 | [diff] [blame] | 38 | #include "update_engine/common/subprocess.h" |
| 39 | #include "update_engine/common/utils.h" |
Sen Jiang | e67bb5b | 2016-06-20 15:53:56 -0700 | [diff] [blame] | 40 | #include "update_engine/dbus_connection.h" |
J. Richard Barnette | 522d36f | 2013-10-28 17:22:12 -0700 | [diff] [blame] | 41 | |
Alex Deymo | 4243291 | 2013-07-12 20:21:15 -0700 | [diff] [blame] | 42 | using std::string; |
J. Richard Barnette | 522d36f | 2013-10-28 17:22:12 -0700 | [diff] [blame] | 43 | using std::vector; |
Alex Deymo | 4243291 | 2013-07-12 20:21:15 -0700 | [diff] [blame] | 44 | |
Alex Deymo | bccbc38 | 2014-04-03 13:38:55 -0700 | [diff] [blame] | 45 | namespace { |
| 46 | |
Alex Deymo | dd132f3 | 2015-09-14 19:12:07 -0700 | [diff] [blame] | 47 | const char kOOBECompletedMarker[] = "/home/chronos/.oobe_completed"; |
| 48 | |
| 49 | // The stateful directory used by update_engine to store powerwash-safe files. |
Andrew | 5b00207 | 2020-06-25 07:41:40 -0700 | [diff] [blame] | 50 | // The files stored here must be added to the powerwash script allowlist. |
Alex Deymo | dd132f3 | 2015-09-14 19:12:07 -0700 | [diff] [blame] | 51 | const char kPowerwashSafeDirectory[] = |
| 52 | "/mnt/stateful_partition/unencrypted/preserve"; |
Alex Deymo | bccbc38 | 2014-04-03 13:38:55 -0700 | [diff] [blame] | 53 | |
Alex Deymo | ebbe7ef | 2014-10-30 13:02:49 -0700 | [diff] [blame] | 54 | // The powerwash_count marker file contains the number of times the device was |
| 55 | // powerwashed. This value is incremented by the clobber-state script when |
| 56 | // a powerwash is performed. |
Alex Deymo | dd132f3 | 2015-09-14 19:12:07 -0700 | [diff] [blame] | 57 | const char kPowerwashCountMarker[] = "powerwash_count"; |
| 58 | |
Alex Deymo | fb905d9 | 2016-06-03 19:26:58 -0700 | [diff] [blame] | 59 | // The name of the marker file used to trigger powerwash when post-install |
| 60 | // completes successfully so that the device is powerwashed on next reboot. |
| 61 | const char kPowerwashMarkerFile[] = |
| 62 | "/mnt/stateful_partition/factory_install_reset"; |
| 63 | |
Zentaro Kavanagh | 28def4f | 2019-01-15 17:15:01 -0800 | [diff] [blame] | 64 | // The name of the marker file used to trigger a save of rollback data |
| 65 | // during the next shutdown. |
| 66 | const char kRollbackSaveMarkerFile[] = |
| 67 | "/mnt/stateful_partition/.save_rollback_data"; |
| 68 | |
Zentaro Kavanagh | 0418de3 | 2019-01-15 10:29:35 -0800 | [diff] [blame] | 69 | // The contents of the powerwash marker file for the non-rollback case. |
Alex Deymo | fb905d9 | 2016-06-03 19:26:58 -0700 | [diff] [blame] | 70 | const char kPowerwashCommand[] = "safe fast keepimg reason=update_engine\n"; |
| 71 | |
Zentaro Kavanagh | 0418de3 | 2019-01-15 10:29:35 -0800 | [diff] [blame] | 72 | // The contents of the powerwas marker file for the rollback case. |
| 73 | const char kRollbackPowerwashCommand[] = |
| 74 | "safe fast keepimg rollback reason=update_engine\n"; |
| 75 | |
Alex Deymo | 46a9aae | 2016-05-04 20:20:11 -0700 | [diff] [blame] | 76 | // UpdateManager config path. |
| 77 | const char* kConfigFilePath = "/etc/update_manager.conf"; |
| 78 | |
| 79 | // UpdateManager config options: |
| 80 | const char* kConfigOptsIsOOBEEnabled = "is_oobe_enabled"; |
| 81 | |
Amin Hassani | 1677e81 | 2017-06-21 13:36:36 -0700 | [diff] [blame] | 82 | const char* kActivePingKey = "first_active_omaha_ping_sent"; |
| 83 | |
Matt Ziegelbaum | aa8e1a4 | 2019-05-09 21:41:58 -0400 | [diff] [blame] | 84 | const char* kOemRequisitionKey = "oem_device_requisition"; |
| 85 | |
| 86 | // Gets a string value from the vpd for a given key using the `vpd_get_value` |
| 87 | // shell command. Returns true on success. |
| 88 | int GetVpdValue(string key, string* result) { |
| 89 | int exit_code = 0; |
Amin Hassani | 3a4caa1 | 2019-11-06 11:12:28 -0800 | [diff] [blame] | 90 | string value, error; |
Matt Ziegelbaum | aa8e1a4 | 2019-05-09 21:41:58 -0400 | [diff] [blame] | 91 | vector<string> cmd = {"vpd_get_value", key}; |
| 92 | if (!chromeos_update_engine::Subprocess::SynchronousExec( |
Amin Hassani | 3a4caa1 | 2019-11-06 11:12:28 -0800 | [diff] [blame] | 93 | cmd, &exit_code, &value, &error) || |
Matt Ziegelbaum | aa8e1a4 | 2019-05-09 21:41:58 -0400 | [diff] [blame] | 94 | exit_code) { |
| 95 | LOG(ERROR) << "Failed to get vpd key for " << value |
Amin Hassani | 3a4caa1 | 2019-11-06 11:12:28 -0800 | [diff] [blame] | 96 | << " with exit code: " << exit_code << " and error: " << error; |
Matt Ziegelbaum | aa8e1a4 | 2019-05-09 21:41:58 -0400 | [diff] [blame] | 97 | return false; |
Amin Hassani | 3a4caa1 | 2019-11-06 11:12:28 -0800 | [diff] [blame] | 98 | } else if (!error.empty()) { |
| 99 | LOG(INFO) << "vpd_get_value succeeded but with following errors: " << error; |
Matt Ziegelbaum | aa8e1a4 | 2019-05-09 21:41:58 -0400 | [diff] [blame] | 100 | } |
| 101 | |
| 102 | base::TrimWhitespaceASCII(value, base::TRIM_ALL, &value); |
| 103 | *result = value; |
| 104 | return true; |
| 105 | } |
| 106 | |
Alex Deymo | bccbc38 | 2014-04-03 13:38:55 -0700 | [diff] [blame] | 107 | } // namespace |
| 108 | |
Alex Deymo | 4243291 | 2013-07-12 20:21:15 -0700 | [diff] [blame] | 109 | namespace chromeos_update_engine { |
| 110 | |
Alex Deymo | 40d86b2 | 2015-09-03 22:27:10 -0700 | [diff] [blame] | 111 | namespace hardware { |
| 112 | |
| 113 | // Factory defined in hardware.h. |
| 114 | std::unique_ptr<HardwareInterface> CreateHardware() { |
Alex Deymo | 46a9aae | 2016-05-04 20:20:11 -0700 | [diff] [blame] | 115 | std::unique_ptr<HardwareChromeOS> hardware(new HardwareChromeOS()); |
| 116 | hardware->Init(); |
| 117 | return std::move(hardware); |
Alex Deymo | 40d86b2 | 2015-09-03 22:27:10 -0700 | [diff] [blame] | 118 | } |
| 119 | |
| 120 | } // namespace hardware |
| 121 | |
Alex Deymo | 46a9aae | 2016-05-04 20:20:11 -0700 | [diff] [blame] | 122 | void HardwareChromeOS::Init() { |
| 123 | LoadConfig("" /* root_prefix */, IsNormalBootMode()); |
Sen Jiang | e67bb5b | 2016-06-20 15:53:56 -0700 | [diff] [blame] | 124 | debugd_proxy_.reset( |
| 125 | new org::chromium::debugdProxy(DBusConnection::Get()->GetDBus())); |
Alex Deymo | 46a9aae | 2016-05-04 20:20:11 -0700 | [diff] [blame] | 126 | } |
| 127 | |
Alex Deymo | 40d86b2 | 2015-09-03 22:27:10 -0700 | [diff] [blame] | 128 | bool HardwareChromeOS::IsOfficialBuild() const { |
J. Richard Barnette | c7dd853 | 2013-10-29 16:30:46 -0700 | [diff] [blame] | 129 | return VbGetSystemPropertyInt("debug_build") == 0; |
J. Richard Barnette | 056b0ab | 2013-10-29 15:24:56 -0700 | [diff] [blame] | 130 | } |
| 131 | |
Alex Deymo | 40d86b2 | 2015-09-03 22:27:10 -0700 | [diff] [blame] | 132 | bool HardwareChromeOS::IsNormalBootMode() const { |
J. Richard Barnette | c7dd853 | 2013-10-29 16:30:46 -0700 | [diff] [blame] | 133 | bool dev_mode = VbGetSystemPropertyInt("devsw_boot") != 0; |
J. Richard Barnette | 056b0ab | 2013-10-29 15:24:56 -0700 | [diff] [blame] | 134 | return !dev_mode; |
| 135 | } |
| 136 | |
Sen Jiang | e67bb5b | 2016-06-20 15:53:56 -0700 | [diff] [blame] | 137 | bool HardwareChromeOS::AreDevFeaturesEnabled() const { |
| 138 | // Even though the debugd tools are also gated on devmode, checking here can |
| 139 | // save us a D-Bus call so it's worth doing explicitly. |
| 140 | if (IsNormalBootMode()) |
| 141 | return false; |
| 142 | |
| 143 | int32_t dev_features = debugd::DEV_FEATURES_DISABLED; |
| 144 | brillo::ErrorPtr error; |
| 145 | // Some boards may not include debugd so it's expected that this may fail, |
| 146 | // in which case we treat it as disabled. |
| 147 | if (debugd_proxy_ && debugd_proxy_->QueryDevFeatures(&dev_features, &error) && |
| 148 | !(dev_features & debugd::DEV_FEATURES_DISABLED)) { |
| 149 | LOG(INFO) << "Debugd dev tools enabled."; |
| 150 | return true; |
| 151 | } |
| 152 | return false; |
| 153 | } |
| 154 | |
Alex Deymo | 46a9aae | 2016-05-04 20:20:11 -0700 | [diff] [blame] | 155 | bool HardwareChromeOS::IsOOBEEnabled() const { |
| 156 | return is_oobe_enabled_; |
| 157 | } |
| 158 | |
Alex Deymo | 40d86b2 | 2015-09-03 22:27:10 -0700 | [diff] [blame] | 159 | bool HardwareChromeOS::IsOOBEComplete(base::Time* out_time_of_oobe) const { |
Alex Deymo | 46a9aae | 2016-05-04 20:20:11 -0700 | [diff] [blame] | 160 | if (!is_oobe_enabled_) { |
| 161 | LOG(WARNING) << "OOBE is not enabled but IsOOBEComplete() was called"; |
| 162 | } |
Alex Deymo | bccbc38 | 2014-04-03 13:38:55 -0700 | [diff] [blame] | 163 | struct stat statbuf; |
| 164 | if (stat(kOOBECompletedMarker, &statbuf) != 0) { |
| 165 | if (errno != ENOENT) { |
Amin Hassani | 7cc8bb0 | 2019-01-14 16:29:47 -0800 | [diff] [blame] | 166 | PLOG(ERROR) << "Error getting information about " << kOOBECompletedMarker; |
Alex Deymo | bccbc38 | 2014-04-03 13:38:55 -0700 | [diff] [blame] | 167 | } |
| 168 | return false; |
| 169 | } |
| 170 | |
| 171 | if (out_time_of_oobe != nullptr) |
| 172 | *out_time_of_oobe = base::Time::FromTimeT(statbuf.st_mtime); |
| 173 | return true; |
| 174 | } |
| 175 | |
J. Richard Barnette | 522d36f | 2013-10-28 17:22:12 -0700 | [diff] [blame] | 176 | static string ReadValueFromCrosSystem(const string& key) { |
J. Richard Barnette | c7dd853 | 2013-10-29 16:30:46 -0700 | [diff] [blame] | 177 | char value_buffer[VB_MAX_STRING_PROPERTY]; |
J. Richard Barnette | 522d36f | 2013-10-28 17:22:12 -0700 | [diff] [blame] | 178 | |
Amin Hassani | 7cc8bb0 | 2019-01-14 16:29:47 -0800 | [diff] [blame] | 179 | const char* rv = VbGetSystemPropertyString( |
| 180 | key.c_str(), value_buffer, sizeof(value_buffer)); |
Alex Vakulenko | 88b591f | 2014-08-28 16:48:57 -0700 | [diff] [blame] | 181 | if (rv != nullptr) { |
J. Richard Barnette | c7dd853 | 2013-10-29 16:30:46 -0700 | [diff] [blame] | 182 | string return_value(value_buffer); |
Ben Chan | 736fcb5 | 2014-05-21 18:28:22 -0700 | [diff] [blame] | 183 | base::TrimWhitespaceASCII(return_value, base::TRIM_ALL, &return_value); |
J. Richard Barnette | 522d36f | 2013-10-28 17:22:12 -0700 | [diff] [blame] | 184 | return return_value; |
| 185 | } |
J. Richard Barnette | c7dd853 | 2013-10-29 16:30:46 -0700 | [diff] [blame] | 186 | |
| 187 | LOG(ERROR) << "Unable to read crossystem key " << key; |
J. Richard Barnette | 522d36f | 2013-10-28 17:22:12 -0700 | [diff] [blame] | 188 | return ""; |
| 189 | } |
| 190 | |
Alex Deymo | 40d86b2 | 2015-09-03 22:27:10 -0700 | [diff] [blame] | 191 | string HardwareChromeOS::GetHardwareClass() const { |
Chris Masone | f8d037f | 2014-02-19 01:53:00 +0000 | [diff] [blame] | 192 | if (USE_HWID_OVERRIDE) { |
| 193 | return HwidOverride::Read(base::FilePath("/")); |
| 194 | } |
J. Richard Barnette | 522d36f | 2013-10-28 17:22:12 -0700 | [diff] [blame] | 195 | return ReadValueFromCrosSystem("hwid"); |
| 196 | } |
| 197 | |
Alex Deymo | 40d86b2 | 2015-09-03 22:27:10 -0700 | [diff] [blame] | 198 | string HardwareChromeOS::GetFirmwareVersion() const { |
J. Richard Barnette | 522d36f | 2013-10-28 17:22:12 -0700 | [diff] [blame] | 199 | return ReadValueFromCrosSystem("fwid"); |
| 200 | } |
| 201 | |
Alex Deymo | 40d86b2 | 2015-09-03 22:27:10 -0700 | [diff] [blame] | 202 | string HardwareChromeOS::GetECVersion() const { |
Amin Hassani | 3a4caa1 | 2019-11-06 11:12:28 -0800 | [diff] [blame] | 203 | string input_line, error; |
J. Richard Barnette | 522d36f | 2013-10-28 17:22:12 -0700 | [diff] [blame] | 204 | int exit_code = 0; |
Alex Vakulenko | d0fdfb3 | 2014-02-21 15:26:26 -0800 | [diff] [blame] | 205 | vector<string> cmd = {"/usr/sbin/mosys", "-k", "ec", "info"}; |
J. Richard Barnette | 522d36f | 2013-10-28 17:22:12 -0700 | [diff] [blame] | 206 | |
Amin Hassani | 3a4caa1 | 2019-11-06 11:12:28 -0800 | [diff] [blame] | 207 | if (!Subprocess::SynchronousExec(cmd, &exit_code, &input_line, &error) || |
| 208 | exit_code != 0) { |
| 209 | LOG(ERROR) << "Unable to read EC info from mosys with exit code: " |
| 210 | << exit_code << " and error: " << error; |
J. Richard Barnette | 522d36f | 2013-10-28 17:22:12 -0700 | [diff] [blame] | 211 | return ""; |
| 212 | } |
| 213 | |
| 214 | return utils::ParseECVersion(input_line); |
| 215 | } |
| 216 | |
Matt Ziegelbaum | aa8e1a4 | 2019-05-09 21:41:58 -0400 | [diff] [blame] | 217 | string HardwareChromeOS::GetDeviceRequisition() const { |
| 218 | string requisition; |
| 219 | return GetVpdValue(kOemRequisitionKey, &requisition) ? requisition : ""; |
| 220 | } |
| 221 | |
Zentaro Kavanagh | baacb98 | 2018-02-20 17:48:39 -0800 | [diff] [blame] | 222 | int HardwareChromeOS::GetMinKernelKeyVersion() const { |
| 223 | return VbGetSystemPropertyInt("tpm_kernver"); |
| 224 | } |
| 225 | |
Zentaro Kavanagh | 8f6f243 | 2018-05-16 13:48:12 -0700 | [diff] [blame] | 226 | int HardwareChromeOS::GetMaxFirmwareKeyRollforward() const { |
| 227 | return VbGetSystemPropertyInt("firmware_max_rollforward"); |
| 228 | } |
| 229 | |
| 230 | bool HardwareChromeOS::SetMaxFirmwareKeyRollforward( |
| 231 | int firmware_max_rollforward) { |
| 232 | // Not all devices have this field yet. So first try to read |
| 233 | // it and if there is an error just fail. |
| 234 | if (GetMaxFirmwareKeyRollforward() == -1) |
| 235 | return false; |
| 236 | |
| 237 | return VbSetSystemPropertyInt("firmware_max_rollforward", |
| 238 | firmware_max_rollforward) == 0; |
| 239 | } |
| 240 | |
Marton Hunyady | 99ced78 | 2018-05-08 12:59:50 +0200 | [diff] [blame] | 241 | int HardwareChromeOS::GetMinFirmwareKeyVersion() const { |
| 242 | return VbGetSystemPropertyInt("tpm_fwver"); |
| 243 | } |
| 244 | |
Zentaro Kavanagh | 5d95615 | 2018-05-15 09:40:33 -0700 | [diff] [blame] | 245 | bool HardwareChromeOS::SetMaxKernelKeyRollforward(int kernel_max_rollforward) { |
| 246 | return VbSetSystemPropertyInt("kernel_max_rollforward", |
| 247 | kernel_max_rollforward) == 0; |
Zentaro Kavanagh | baacb98 | 2018-02-20 17:48:39 -0800 | [diff] [blame] | 248 | } |
| 249 | |
Alex Deymo | 40d86b2 | 2015-09-03 22:27:10 -0700 | [diff] [blame] | 250 | int HardwareChromeOS::GetPowerwashCount() const { |
Alex Deymo | ebbe7ef | 2014-10-30 13:02:49 -0700 | [diff] [blame] | 251 | int powerwash_count; |
Amin Hassani | 7cc8bb0 | 2019-01-14 16:29:47 -0800 | [diff] [blame] | 252 | base::FilePath marker_path = |
| 253 | base::FilePath(kPowerwashSafeDirectory).Append(kPowerwashCountMarker); |
Alex Deymo | ebbe7ef | 2014-10-30 13:02:49 -0700 | [diff] [blame] | 254 | string contents; |
Alex Deymo | dd132f3 | 2015-09-14 19:12:07 -0700 | [diff] [blame] | 255 | if (!utils::ReadFile(marker_path.value(), &contents)) |
Alex Deymo | ebbe7ef | 2014-10-30 13:02:49 -0700 | [diff] [blame] | 256 | return -1; |
| 257 | base::TrimWhitespaceASCII(contents, base::TRIM_TRAILING, &contents); |
| 258 | if (!base::StringToInt(contents, &powerwash_count)) |
| 259 | return -1; |
| 260 | return powerwash_count; |
| 261 | } |
| 262 | |
Zentaro Kavanagh | 28def4f | 2019-01-15 17:15:01 -0800 | [diff] [blame] | 263 | bool HardwareChromeOS::SchedulePowerwash(bool save_rollback_data) { |
| 264 | if (save_rollback_data) { |
| 265 | if (!utils::WriteFile(kRollbackSaveMarkerFile, nullptr, 0)) { |
| 266 | PLOG(ERROR) << "Error in creating rollback save marker file: " |
| 267 | << kRollbackSaveMarkerFile << ". Rollback will not" |
| 268 | << " preserve any data."; |
| 269 | } else { |
| 270 | LOG(INFO) << "Rollback data save has been scheduled on next shutdown."; |
| 271 | } |
| 272 | } |
| 273 | |
Zentaro Kavanagh | 0418de3 | 2019-01-15 10:29:35 -0800 | [diff] [blame] | 274 | const char* powerwash_command = |
Zentaro Kavanagh | 28def4f | 2019-01-15 17:15:01 -0800 | [diff] [blame] | 275 | save_rollback_data ? kRollbackPowerwashCommand : kPowerwashCommand; |
Alex Deymo | fb905d9 | 2016-06-03 19:26:58 -0700 | [diff] [blame] | 276 | bool result = utils::WriteFile( |
Zentaro Kavanagh | 0418de3 | 2019-01-15 10:29:35 -0800 | [diff] [blame] | 277 | kPowerwashMarkerFile, powerwash_command, strlen(powerwash_command)); |
Alex Deymo | fb905d9 | 2016-06-03 19:26:58 -0700 | [diff] [blame] | 278 | if (result) { |
Alex Deymo | caa4672 | 2016-06-09 12:08:29 -0700 | [diff] [blame] | 279 | LOG(INFO) << "Created " << kPowerwashMarkerFile |
Zentaro Kavanagh | 28def4f | 2019-01-15 17:15:01 -0800 | [diff] [blame] | 280 | << " to powerwash on next reboot (" |
| 281 | << "save_rollback_data=" << save_rollback_data << ")"; |
Alex Deymo | fb905d9 | 2016-06-03 19:26:58 -0700 | [diff] [blame] | 282 | } else { |
Alex Deymo | caa4672 | 2016-06-09 12:08:29 -0700 | [diff] [blame] | 283 | PLOG(ERROR) << "Error in creating powerwash marker file: " |
| 284 | << kPowerwashMarkerFile; |
Alex Deymo | fb905d9 | 2016-06-03 19:26:58 -0700 | [diff] [blame] | 285 | } |
| 286 | |
| 287 | return result; |
| 288 | } |
| 289 | |
| 290 | bool HardwareChromeOS::CancelPowerwash() { |
| 291 | bool result = base::DeleteFile(base::FilePath(kPowerwashMarkerFile), false); |
| 292 | |
| 293 | if (result) { |
| 294 | LOG(INFO) << "Successfully deleted the powerwash marker file : " |
Alex Deymo | caa4672 | 2016-06-09 12:08:29 -0700 | [diff] [blame] | 295 | << kPowerwashMarkerFile; |
Alex Deymo | fb905d9 | 2016-06-03 19:26:58 -0700 | [diff] [blame] | 296 | } else { |
| 297 | PLOG(ERROR) << "Could not delete the powerwash marker file : " |
Alex Deymo | caa4672 | 2016-06-09 12:08:29 -0700 | [diff] [blame] | 298 | << kPowerwashMarkerFile; |
Alex Deymo | fb905d9 | 2016-06-03 19:26:58 -0700 | [diff] [blame] | 299 | } |
| 300 | |
Zentaro Kavanagh | 28def4f | 2019-01-15 17:15:01 -0800 | [diff] [blame] | 301 | // Delete the rollback save marker file if it existed. |
| 302 | if (!base::DeleteFile(base::FilePath(kRollbackSaveMarkerFile), false)) { |
| 303 | PLOG(ERROR) << "Could not remove rollback save marker"; |
| 304 | } |
| 305 | |
Alex Deymo | fb905d9 | 2016-06-03 19:26:58 -0700 | [diff] [blame] | 306 | return result; |
| 307 | } |
| 308 | |
Alex Deymo | dd132f3 | 2015-09-14 19:12:07 -0700 | [diff] [blame] | 309 | bool HardwareChromeOS::GetNonVolatileDirectory(base::FilePath* path) const { |
Sen Jiang | 9c12346 | 2015-11-19 13:16:23 -0800 | [diff] [blame] | 310 | *path = base::FilePath(constants::kNonVolatileDirectory); |
Alex Deymo | dd132f3 | 2015-09-14 19:12:07 -0700 | [diff] [blame] | 311 | return true; |
| 312 | } |
| 313 | |
| 314 | bool HardwareChromeOS::GetPowerwashSafeDirectory(base::FilePath* path) const { |
| 315 | *path = base::FilePath(kPowerwashSafeDirectory); |
| 316 | return true; |
| 317 | } |
| 318 | |
Sen Jiang | 5011df6 | 2017-06-28 17:13:19 -0700 | [diff] [blame] | 319 | int64_t HardwareChromeOS::GetBuildTimestamp() const { |
| 320 | // TODO(senj): implement this in Chrome OS. |
| 321 | return 0; |
| 322 | } |
| 323 | |
Alex Deymo | 46a9aae | 2016-05-04 20:20:11 -0700 | [diff] [blame] | 324 | void HardwareChromeOS::LoadConfig(const string& root_prefix, bool normal_mode) { |
| 325 | brillo::KeyValueStore store; |
| 326 | |
| 327 | if (normal_mode) { |
| 328 | store.Load(base::FilePath(root_prefix + kConfigFilePath)); |
| 329 | } else { |
| 330 | if (store.Load(base::FilePath(root_prefix + kStatefulPartition + |
| 331 | kConfigFilePath))) { |
| 332 | LOG(INFO) << "UpdateManager Config loaded from stateful partition."; |
| 333 | } else { |
| 334 | store.Load(base::FilePath(root_prefix + kConfigFilePath)); |
| 335 | } |
| 336 | } |
| 337 | |
| 338 | if (!store.GetBoolean(kConfigOptsIsOOBEEnabled, &is_oobe_enabled_)) |
| 339 | is_oobe_enabled_ = true; // Default value. |
| 340 | } |
| 341 | |
Amin Hassani | 1677e81 | 2017-06-21 13:36:36 -0700 | [diff] [blame] | 342 | bool HardwareChromeOS::GetFirstActiveOmahaPingSent() const { |
Amin Hassani | 1677e81 | 2017-06-21 13:36:36 -0700 | [diff] [blame] | 343 | string active_ping_str; |
Matt Ziegelbaum | aa8e1a4 | 2019-05-09 21:41:58 -0400 | [diff] [blame] | 344 | if (!GetVpdValue(kActivePingKey, &active_ping_str)) { |
Amin Hassani | 1677e81 | 2017-06-21 13:36:36 -0700 | [diff] [blame] | 345 | return false; |
| 346 | } |
| 347 | |
Amin Hassani | 1677e81 | 2017-06-21 13:36:36 -0700 | [diff] [blame] | 348 | int active_ping; |
| 349 | if (active_ping_str.empty() || |
| 350 | !base::StringToInt(active_ping_str, &active_ping)) { |
| 351 | LOG(INFO) << "Failed to parse active_ping value: " << active_ping_str; |
| 352 | return false; |
| 353 | } |
| 354 | return static_cast<bool>(active_ping); |
| 355 | } |
| 356 | |
Amin Hassani | 80f4d4c | 2018-05-16 13:34:00 -0700 | [diff] [blame] | 357 | bool HardwareChromeOS::SetFirstActiveOmahaPingSent() { |
Amin Hassani | 1677e81 | 2017-06-21 13:36:36 -0700 | [diff] [blame] | 358 | int exit_code = 0; |
Amin Hassani | 3a4caa1 | 2019-11-06 11:12:28 -0800 | [diff] [blame] | 359 | string output, error; |
Amin Hassani | 1677e81 | 2017-06-21 13:36:36 -0700 | [diff] [blame] | 360 | vector<string> vpd_set_cmd = { |
Amin Hassani | 7cc8bb0 | 2019-01-14 16:29:47 -0800 | [diff] [blame] | 361 | "vpd", "-i", "RW_VPD", "-s", string(kActivePingKey) + "=1"}; |
Amin Hassani | 3a4caa1 | 2019-11-06 11:12:28 -0800 | [diff] [blame] | 362 | if (!Subprocess::SynchronousExec(vpd_set_cmd, &exit_code, &output, &error) || |
Amin Hassani | 1677e81 | 2017-06-21 13:36:36 -0700 | [diff] [blame] | 363 | exit_code) { |
| 364 | LOG(ERROR) << "Failed to set vpd key for " << kActivePingKey |
Amin Hassani | 3a4caa1 | 2019-11-06 11:12:28 -0800 | [diff] [blame] | 365 | << " with exit code: " << exit_code << " with output: " << output |
| 366 | << " and error: " << error; |
Amin Hassani | 80f4d4c | 2018-05-16 13:34:00 -0700 | [diff] [blame] | 367 | return false; |
Amin Hassani | 3a4caa1 | 2019-11-06 11:12:28 -0800 | [diff] [blame] | 368 | } else if (!error.empty()) { |
| 369 | LOG(INFO) << "vpd succeeded but with error logs: " << error; |
Amin Hassani | 1677e81 | 2017-06-21 13:36:36 -0700 | [diff] [blame] | 370 | } |
| 371 | |
Amin Hassani | 7cc8bb0 | 2019-01-14 16:29:47 -0800 | [diff] [blame] | 372 | vector<string> vpd_dump_cmd = {"dump_vpd_log", "--force"}; |
Amin Hassani | 3a4caa1 | 2019-11-06 11:12:28 -0800 | [diff] [blame] | 373 | if (!Subprocess::SynchronousExec(vpd_dump_cmd, &exit_code, &output, &error) || |
Amin Hassani | 1677e81 | 2017-06-21 13:36:36 -0700 | [diff] [blame] | 374 | exit_code) { |
Amin Hassani | 7cc8bb0 | 2019-01-14 16:29:47 -0800 | [diff] [blame] | 375 | LOG(ERROR) << "Failed to cache " << kActivePingKey << " using dump_vpd_log" |
Amin Hassani | 3a4caa1 | 2019-11-06 11:12:28 -0800 | [diff] [blame] | 376 | << " with exit code: " << exit_code << " with output: " << output |
| 377 | << " and error: " << error; |
Amin Hassani | 80f4d4c | 2018-05-16 13:34:00 -0700 | [diff] [blame] | 378 | return false; |
Amin Hassani | 3a4caa1 | 2019-11-06 11:12:28 -0800 | [diff] [blame] | 379 | } else if (!error.empty()) { |
| 380 | LOG(INFO) << "dump_vpd_log succeeded but with error logs: " << error; |
Amin Hassani | 1677e81 | 2017-06-21 13:36:36 -0700 | [diff] [blame] | 381 | } |
Amin Hassani | 80f4d4c | 2018-05-16 13:34:00 -0700 | [diff] [blame] | 382 | return true; |
Amin Hassani | 1677e81 | 2017-06-21 13:36:36 -0700 | [diff] [blame] | 383 | } |
| 384 | |
Tianjie Xu | d6aa91f | 2019-11-14 11:55:10 -0800 | [diff] [blame] | 385 | void HardwareChromeOS::SetWarmReset(bool warm_reset) {} |
| 386 | |
Kelvin Zhang | d719103 | 2020-08-11 10:48:16 -0400 | [diff] [blame] | 387 | std::string HardwareChromeOS::GetVersionForLogging( |
| 388 | const std::string& partition_name) const { |
| 389 | // TODO(zhangkelvin) Implement per-partition timestamp for Chrome OS. |
| 390 | return ""; |
| 391 | } |
| 392 | bool HardwareChromeOS::IsPartitionUpdateValid( |
| 393 | const std::string& partition_name, const std::string& new_version) const { |
| 394 | // TODO(zhangkelvin) Implement per-partition timestamp for Chrome OS. |
| 395 | return true; |
| 396 | } |
| 397 | |
Alex Deymo | 4243291 | 2013-07-12 20:21:15 -0700 | [diff] [blame] | 398 | } // namespace chromeos_update_engine |