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