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