blob: 88fcfa5025d6e6810ea9feb634ea733a18c29943 [file] [log] [blame]
Tao Bao7197ee02015-12-05 21:21:27 -08001/*
2 * Copyright (C) 2015 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 */
16
17/*
Tao Bao1cc03512018-04-18 17:10:49 -070018 * update_verifier verifies the integrity of the partitions after an A/B OTA update. It gets invoked
19 * by init, and will only perform the verification if it's the first boot post an A/B OTA update
20 * (https://source.android.com/devices/tech/ota/ab/#after_reboot).
Tao Bao7197ee02015-12-05 21:21:27 -080021 *
Tao Bao1cc03512018-04-18 17:10:49 -070022 * update_verifier relies on device-mapper-verity (dm-verity) to capture any corruption on the
23 * partitions being verified (https://source.android.com/security/verifiedboot). The verification
24 * will be skipped, if dm-verity is not enabled on the device.
25 *
26 * Upon detecting verification failures, the device will be rebooted, although the trigger of the
27 * reboot depends on the dm-verity mode.
Tianjie Xu3958a952017-03-01 15:31:25 -080028 * enforcing mode: dm-verity reboots the device
29 * eio mode: dm-verity fails the read and update_verifier reboots the device
30 * other mode: not supported and update_verifier reboots the device
31 *
Tao Bao1cc03512018-04-18 17:10:49 -070032 * All these reboots prevent the device from booting into a known corrupt state. If the device
33 * continuously fails to boot into the new slot, the bootloader should mark the slot as unbootable
34 * and trigger a fallback to the old slot.
Tao Bao7197ee02015-12-05 21:21:27 -080035 *
Tao Bao1cc03512018-04-18 17:10:49 -070036 * The current slot will be marked as having booted successfully if the verifier reaches the end
37 * after the verification.
Tao Bao7197ee02015-12-05 21:21:27 -080038 */
39
Tao Bao83b07802017-04-26 14:30:56 -070040#include "update_verifier/update_verifier.h"
41
Tianjie Xub0ac8722017-01-18 18:41:53 -080042#include <dirent.h>
Tianjie Xud007cf22016-02-29 16:08:06 -080043#include <errno.h>
44#include <fcntl.h>
Tao Baoc89c3942019-03-13 15:30:13 -070045#include <stdint.h>
Tianjie Xud007cf22016-02-29 16:08:06 -080046#include <stdio.h>
Tao Baoc89c3942019-03-13 15:30:13 -070047#include <stdlib.h>
Tao Bao7197ee02015-12-05 21:21:27 -080048#include <string.h>
Tianjie Xu3958a952017-03-01 15:31:25 -080049#include <unistd.h>
Tao Bao7197ee02015-12-05 21:21:27 -080050
Tianjie Xu8fa8f0b2017-04-27 11:47:35 -070051#include <algorithm>
Wei Wang5226f472017-08-02 10:27:31 -070052#include <future>
Tao Baoc89c3942019-03-13 15:30:13 -070053#include <thread>
Tianjie Xud007cf22016-02-29 16:08:06 -080054
Akilesh Kailashdc1f6da2022-03-23 18:53:52 +000055#include <android-base/chrono_utils.h>
Tianjie Xud007cf22016-02-29 16:08:06 -080056#include <android-base/file.h>
Tianjie Xu7b0ad9c2016-08-05 18:00:04 -070057#include <android-base/logging.h>
Tianjie Xud007cf22016-02-29 16:08:06 -080058#include <android-base/parseint.h>
Tao Bao4f8d2172017-01-13 15:36:32 -080059#include <android-base/properties.h>
Tianjie Xud007cf22016-02-29 16:08:06 -080060#include <android-base/strings.h>
61#include <android-base/unique_fd.h>
Connor O'Brienad43d2d2016-11-21 12:47:33 -080062#include <android/hardware/boot/1.0/IBootControl.h>
Tao Baoc89c3942019-03-13 15:30:13 -070063#include <android/os/IVold.h>
Daniel Rosenberg15f22bd2019-01-22 19:57:28 -080064#include <binder/BinderService.h>
65#include <binder/Status.h>
Tianjie Xu3958a952017-03-01 15:31:25 -080066#include <cutils/android_reboot.h>
Connor O'Brienad43d2d2016-11-21 12:47:33 -080067
Tianjie Xu4d9e62d2018-05-11 10:41:44 -070068#include "care_map.pb.h"
Tao Bao160514b2017-11-04 00:08:08 -070069
Connor O'Brienad43d2d2016-11-21 12:47:33 -080070using android::sp;
71using android::hardware::boot::V1_0::IBootControl;
72using android::hardware::boot::V1_0::BoolResult;
73using android::hardware::boot::V1_0::CommandResult;
Tao Bao7197ee02015-12-05 21:21:27 -080074
xunchangaaa61032019-03-13 14:21:48 -070075// TODO(xunchang) remove the prefix and use a default path instead.
Tianjie Xu9eed65e2018-09-14 12:52:02 -070076constexpr const char* kDefaultCareMapPrefix = "/data/ota_package/care_map";
77
Tianjie Xub0ac8722017-01-18 18:41:53 -080078// Find directories in format of "/sys/block/dm-X".
79static int dm_name_filter(const dirent* de) {
80 if (android::base::StartsWith(de->d_name, "dm-")) {
81 return 1;
82 }
83 return 0;
84}
85
Tianjie Xu9eed65e2018-09-14 12:52:02 -070086UpdateVerifier::UpdateVerifier()
87 : care_map_prefix_(kDefaultCareMapPrefix),
88 property_reader_([](const std::string& id) { return android::base::GetProperty(id, ""); }) {}
89
Tianjie Xu446b64b2018-09-19 15:45:28 -070090// Iterate the content of "/sys/block/dm-X/dm/name" and find all the dm-wrapped block devices.
91// We will later read all the ("cared") blocks from "/dev/block/dm-X" to ensure the target
92// partition's integrity.
93std::map<std::string, std::string> UpdateVerifier::FindDmPartitions() {
Tao Bao83b07802017-04-26 14:30:56 -070094 static constexpr auto DM_PATH_PREFIX = "/sys/block/";
Tianjie Xub0ac8722017-01-18 18:41:53 -080095 dirent** namelist;
96 int n = scandir(DM_PATH_PREFIX, &namelist, dm_name_filter, alphasort);
97 if (n == -1) {
98 PLOG(ERROR) << "Failed to scan dir " << DM_PATH_PREFIX;
Tianjie Xu446b64b2018-09-19 15:45:28 -070099 return {};
Tianjie Xub0ac8722017-01-18 18:41:53 -0800100 }
101 if (n == 0) {
Tianjie Xu446b64b2018-09-19 15:45:28 -0700102 LOG(ERROR) << "No dm block device found.";
103 return {};
Tianjie Xub0ac8722017-01-18 18:41:53 -0800104 }
105
Tao Bao83b07802017-04-26 14:30:56 -0700106 static constexpr auto DM_PATH_SUFFIX = "/dm/name";
107 static constexpr auto DEV_PATH = "/dev/block/";
Tianjie Xu446b64b2018-09-19 15:45:28 -0700108 std::map<std::string, std::string> dm_block_devices;
Tianjie Xub0ac8722017-01-18 18:41:53 -0800109 while (n--) {
110 std::string path = DM_PATH_PREFIX + std::string(namelist[n]->d_name) + DM_PATH_SUFFIX;
111 std::string content;
112 if (!android::base::ReadFileToString(path, &content)) {
113 PLOG(WARNING) << "Failed to read " << path;
David Zeuthen8ed97382017-05-08 13:41:28 -0400114 } else {
115 std::string dm_block_name = android::base::Trim(content);
David Zeuthen8ed97382017-05-08 13:41:28 -0400116 // AVB is using 'vroot' for the root block device but we're expecting 'system'.
117 if (dm_block_name == "vroot") {
118 dm_block_name = "system";
David Andersonc52663c2019-04-01 14:37:33 -0700119 } else if (android::base::EndsWith(dm_block_name, "-verity")) {
120 auto npos = dm_block_name.rfind("-verity");
121 dm_block_name = dm_block_name.substr(0, npos);
122 } else if (!android::base::GetProperty("ro.boot.avb_version", "").empty()) {
123 // Verified Boot 1.0 doesn't add a -verity suffix. On AVB 2 devices,
124 // if DAP is enabled, then a -verity suffix must be used to
125 // differentiate between dm-linear and dm-verity devices. If we get
126 // here, we're AVB 2 and looking at a non-verity partition.
127 continue;
Tianjie Xub0ac8722017-01-18 18:41:53 -0800128 }
Tianjie Xu446b64b2018-09-19 15:45:28 -0700129
130 dm_block_devices.emplace(dm_block_name, DEV_PATH + std::string(namelist[n]->d_name));
Tianjie Xub0ac8722017-01-18 18:41:53 -0800131 }
132 free(namelist[n]);
133 }
134 free(namelist);
135
Tianjie Xu446b64b2018-09-19 15:45:28 -0700136 return dm_block_devices;
137}
Tao Bao4f8d2172017-01-13 15:36:32 -0800138
Tianjie Xu446b64b2018-09-19 15:45:28 -0700139bool UpdateVerifier::ReadBlocks(const std::string partition_name,
140 const std::string& dm_block_device, const RangeSet& ranges) {
Tao Bao160514b2017-11-04 00:08:08 -0700141 // RangeSet::Split() splits the ranges into multiple groups with same number of blocks (except for
142 // the last group).
143 size_t thread_num = std::thread::hardware_concurrency() ?: 4;
144 std::vector<RangeSet> groups = ranges.Split(thread_num);
Tao Bao4f8d2172017-01-13 15:36:32 -0800145
Wei Wang5226f472017-08-02 10:27:31 -0700146 std::vector<std::future<bool>> threads;
Tao Bao160514b2017-11-04 00:08:08 -0700147 for (const auto& group : groups) {
Tianjie Xu446b64b2018-09-19 15:45:28 -0700148 auto thread_func = [&group, &dm_block_device, &partition_name]() {
Wei Wang5226f472017-08-02 10:27:31 -0700149 android::base::unique_fd fd(TEMP_FAILURE_RETRY(open(dm_block_device.c_str(), O_RDONLY)));
150 if (fd.get() == -1) {
Tianjie Xu446b64b2018-09-19 15:45:28 -0700151 PLOG(ERROR) << "Error reading " << dm_block_device << " for partition " << partition_name;
Tianjie Xu8fa8f0b2017-04-27 11:47:35 -0700152 return false;
153 }
Wei Wang5226f472017-08-02 10:27:31 -0700154
Tao Bao160514b2017-11-04 00:08:08 -0700155 static constexpr size_t kBlockSize = 4096;
156 std::vector<uint8_t> buf(1024 * kBlockSize);
Wei Wang5226f472017-08-02 10:27:31 -0700157
Tao Bao160514b2017-11-04 00:08:08 -0700158 size_t block_count = 0;
Tianjie Xu446b64b2018-09-19 15:45:28 -0700159 for (const auto& [range_start, range_end] : group) {
Wei Wang5226f472017-08-02 10:27:31 -0700160 if (lseek64(fd.get(), static_cast<off64_t>(range_start) * kBlockSize, SEEK_SET) == -1) {
161 PLOG(ERROR) << "lseek to " << range_start << " failed";
162 return false;
163 }
164
165 size_t remain = (range_end - range_start) * kBlockSize;
166 while (remain > 0) {
167 size_t to_read = std::min(remain, 1024 * kBlockSize);
168 if (!android::base::ReadFully(fd.get(), buf.data(), to_read)) {
169 PLOG(ERROR) << "Failed to read blocks " << range_start << " to " << range_end;
170 return false;
171 }
172 remain -= to_read;
173 }
Tao Bao160514b2017-11-04 00:08:08 -0700174 block_count += (range_end - range_start);
Wei Wang5226f472017-08-02 10:27:31 -0700175 }
Tao Bao160514b2017-11-04 00:08:08 -0700176 LOG(INFO) << "Finished reading " << block_count << " blocks on " << dm_block_device;
Wei Wang5226f472017-08-02 10:27:31 -0700177 return true;
178 };
179
180 threads.emplace_back(std::async(std::launch::async, thread_func));
Tao Bao4f8d2172017-01-13 15:36:32 -0800181 }
Tianjie Xud007cf22016-02-29 16:08:06 -0800182
Wei Wang5226f472017-08-02 10:27:31 -0700183 bool ret = true;
184 for (auto& t : threads) {
185 ret = t.get() && ret;
186 }
187 LOG(INFO) << "Finished reading blocks on " << dm_block_device << " with " << thread_num
188 << " threads.";
189 return ret;
Tianjie Xud007cf22016-02-29 16:08:06 -0800190}
191
Akilesh Kailashdc1f6da2022-03-23 18:53:52 +0000192bool UpdateVerifier::CheckVerificationStatus() {
193 auto client =
194 android::snapshot::SnapuserdClient::Connect(android::snapshot::kSnapuserdSocket, 5s);
195 if (!client) {
196 LOG(ERROR) << "Unable to connect to snapuserd";
197 return false;
198 }
199
200 return client->QueryUpdateVerification();
201}
202
Tianjie Xu446b64b2018-09-19 15:45:28 -0700203bool UpdateVerifier::VerifyPartitions() {
Akilesh Kailashdc1f6da2022-03-23 18:53:52 +0000204 const bool userspace_snapshots =
205 android::base::GetBoolProperty("ro.virtual_ab.userspace.snapshots.enabled", false);
206
207 if (userspace_snapshots && CheckVerificationStatus()) {
208 LOG(INFO) << "Partitions verified by snapuserd daemon";
209 return true;
210 }
211
212 LOG(INFO) << "Partitions not verified by snapuserd daemon";
213
Tianjie Xu446b64b2018-09-19 15:45:28 -0700214 auto dm_block_devices = FindDmPartitions();
215 if (dm_block_devices.empty()) {
216 LOG(ERROR) << "No dm-enabled block device is found.";
Tao Bao5a1dee02017-07-21 15:15:31 -0700217 return false;
218 }
219
Tianjie Xu446b64b2018-09-19 15:45:28 -0700220 for (const auto& [partition_name, ranges] : partition_map_) {
221 if (dm_block_devices.find(partition_name) == dm_block_devices.end()) {
222 LOG(ERROR) << "Failed to find dm block device for " << partition_name;
223 return false;
Tao Bao5a1dee02017-07-21 15:15:31 -0700224 }
Tianjie Xu446b64b2018-09-19 15:45:28 -0700225
226 if (!ReadBlocks(partition_name, dm_block_devices.at(partition_name), ranges)) {
Tao Bao5a1dee02017-07-21 15:15:31 -0700227 return false;
228 }
229 }
230
231 return true;
Tianjie Xud007cf22016-02-29 16:08:06 -0800232}
233
Tianjie Xu9eed65e2018-09-14 12:52:02 -0700234bool UpdateVerifier::ParseCareMap() {
Tianjie Xu446b64b2018-09-19 15:45:28 -0700235 partition_map_.clear();
236
Tianjie Xu9eed65e2018-09-14 12:52:02 -0700237 std::string care_map_name = care_map_prefix_ + ".pb";
238 if (access(care_map_name.c_str(), R_OK) == -1) {
xunchangaaa61032019-03-13 14:21:48 -0700239 LOG(ERROR) << care_map_name << " doesn't exist";
240 return false;
Tianjie Xu446b64b2018-09-19 15:45:28 -0700241 }
242
Tianjie Xu4d9e62d2018-05-11 10:41:44 -0700243 android::base::unique_fd care_map_fd(TEMP_FAILURE_RETRY(open(care_map_name.c_str(), O_RDONLY)));
244 // If the device is flashed before the current boot, it may not have care_map.txt in
245 // /data/ota_package. To allow the device to continue booting in this situation, we should
246 // print a warning and skip the block verification.
247 if (care_map_fd.get() == -1) {
248 PLOG(WARNING) << "Failed to open " << care_map_name;
Tianjie Xu446b64b2018-09-19 15:45:28 -0700249 return false;
Tianjie Xu4d9e62d2018-05-11 10:41:44 -0700250 }
251
252 std::string file_content;
253 if (!android::base::ReadFdToString(care_map_fd.get(), &file_content)) {
Tianjie Xu446b64b2018-09-19 15:45:28 -0700254 PLOG(WARNING) << "Failed to read " << care_map_name;
Tianjie Xu4d9e62d2018-05-11 10:41:44 -0700255 return false;
256 }
257
258 if (file_content.empty()) {
Tianjie Xu446b64b2018-09-19 15:45:28 -0700259 LOG(WARNING) << "Unexpected empty care map";
Tianjie Xu4d9e62d2018-05-11 10:41:44 -0700260 return false;
261 }
262
Tianjie Xu446b64b2018-09-19 15:45:28 -0700263 recovery_update_verifier::CareMap care_map;
Tianjie Xu4d9e62d2018-05-11 10:41:44 -0700264 if (!care_map.ParseFromString(file_content)) {
Tianjie Xu446b64b2018-09-19 15:45:28 -0700265 LOG(WARNING) << "Failed to parse " << care_map_name << " in protobuf format.";
266 return false;
Tianjie Xu4d9e62d2018-05-11 10:41:44 -0700267 }
268
269 for (const auto& partition : care_map.partitions()) {
270 if (partition.name().empty()) {
Tianjie Xu446b64b2018-09-19 15:45:28 -0700271 LOG(WARNING) << "Unexpected empty partition name.";
Tianjie Xu4d9e62d2018-05-11 10:41:44 -0700272 return false;
273 }
274 if (partition.ranges().empty()) {
Tianjie Xu446b64b2018-09-19 15:45:28 -0700275 LOG(WARNING) << "Unexpected block ranges for partition " << partition.name();
Tianjie Xu4d9e62d2018-05-11 10:41:44 -0700276 return false;
277 }
Tianjie Xu446b64b2018-09-19 15:45:28 -0700278 RangeSet ranges = RangeSet::Parse(partition.ranges());
279 if (!ranges) {
280 LOG(WARNING) << "Error parsing RangeSet string " << partition.ranges();
Tianjie Xu4d9e62d2018-05-11 10:41:44 -0700281 return false;
282 }
Tianjie Xu446b64b2018-09-19 15:45:28 -0700283
Tianjie Xu9eed65e2018-09-14 12:52:02 -0700284 // Continues to check other partitions if there is a fingerprint mismatch.
285 if (partition.id().empty() || partition.id() == "unknown") {
286 LOG(WARNING) << "Skip reading partition " << partition.name()
287 << ": property_id is not provided to get fingerprint.";
288 continue;
289 }
290
291 std::string fingerprint = property_reader_(partition.id());
292 if (fingerprint != partition.fingerprint()) {
293 LOG(WARNING) << "Skip reading partition " << partition.name() << ": fingerprint "
294 << fingerprint << " doesn't match the expected value "
295 << partition.fingerprint();
296 continue;
297 }
298
Tianjie Xu446b64b2018-09-19 15:45:28 -0700299 partition_map_.emplace(partition.name(), ranges);
300 }
301
302 if (partition_map_.empty()) {
303 LOG(WARNING) << "No partition to verify";
304 return false;
Tianjie Xu4d9e62d2018-05-11 10:41:44 -0700305 }
306
307 return true;
308}
309
Tianjie Xu9eed65e2018-09-14 12:52:02 -0700310void UpdateVerifier::set_care_map_prefix(const std::string& prefix) {
311 care_map_prefix_ = prefix;
312}
313
314void UpdateVerifier::set_property_reader(
315 const std::function<std::string(const std::string&)>& property_reader) {
316 property_reader_ = property_reader;
317}
318
Tianjie Xu3958a952017-03-01 15:31:25 -0800319static int reboot_device() {
320 if (android_reboot(ANDROID_RB_RESTART2, 0, nullptr) == -1) {
321 LOG(ERROR) << "Failed to reboot.";
322 return -1;
323 }
324 while (true) pause();
325}
326
Tao Bao83b07802017-04-26 14:30:56 -0700327int update_verifier(int argc, char** argv) {
Tao Bao7197ee02015-12-05 21:21:27 -0800328 for (int i = 1; i < argc; i++) {
Tianjie Xu7b0ad9c2016-08-05 18:00:04 -0700329 LOG(INFO) << "Started with arg " << i << ": " << argv[i];
Tao Bao7197ee02015-12-05 21:21:27 -0800330 }
331
Chris Phoenix0157c782017-01-20 11:34:00 -0800332 sp<IBootControl> module = IBootControl::getService();
Connor O'Brienad43d2d2016-11-21 12:47:33 -0800333 if (module == nullptr) {
Tianjie Xu7b0ad9c2016-08-05 18:00:04 -0700334 LOG(ERROR) << "Error getting bootctrl module.";
Tianjie Xu3958a952017-03-01 15:31:25 -0800335 return reboot_device();
Tao Bao7197ee02015-12-05 21:21:27 -0800336 }
337
Connor O'Brienad43d2d2016-11-21 12:47:33 -0800338 uint32_t current_slot = module->getCurrentSlot();
339 BoolResult is_successful = module->isSlotMarkedSuccessful(current_slot);
340 LOG(INFO) << "Booting slot " << current_slot << ": isSlotMarkedSuccessful="
341 << static_cast<int32_t>(is_successful);
Tao Bao7197ee02015-12-05 21:21:27 -0800342
Connor O'Brienad43d2d2016-11-21 12:47:33 -0800343 if (is_successful == BoolResult::FALSE) {
Tao Bao7197ee02015-12-05 21:21:27 -0800344 // The current slot has not booted successfully.
Tao Baodb57f0d2017-03-10 14:21:25 -0800345
David Zeuthen1a0929c2017-08-07 18:47:27 -0400346 bool skip_verification = false;
Tao Bao4f8d2172017-01-13 15:36:32 -0800347 std::string verity_mode = android::base::GetProperty("ro.boot.veritymode", "");
348 if (verity_mode.empty()) {
Tao Bao1cc03512018-04-18 17:10:49 -0700349 // Skip the verification if ro.boot.veritymode property is not set. This could be a result
350 // that device doesn't support dm-verity, or has disabled that.
351 LOG(WARNING) << "dm-verity not enabled; marking without verification.";
David Zeuthen1a0929c2017-08-07 18:47:27 -0400352 skip_verification = true;
Tao Bao4f8d2172017-01-13 15:36:32 -0800353 } else if (android::base::EqualsIgnoreCase(verity_mode, "eio")) {
Tianjie Xu3958a952017-03-01 15:31:25 -0800354 // We shouldn't see verity in EIO mode if the current slot hasn't booted successfully before.
355 // Continue the verification until we fail to read some blocks.
356 LOG(WARNING) << "Found dm-verity in EIO mode.";
David Zeuthen1a0929c2017-08-07 18:47:27 -0400357 } else if (android::base::EqualsIgnoreCase(verity_mode, "disabled")) {
358 LOG(WARNING) << "dm-verity in disabled mode; marking without verification.";
359 skip_verification = true;
Tao Bao4f8d2172017-01-13 15:36:32 -0800360 } else if (verity_mode != "enforcing") {
Tao Bao1cc03512018-04-18 17:10:49 -0700361 LOG(ERROR) << "Unexpected dm-verity mode: " << verity_mode << ", expecting enforcing.";
Tianjie Xu3958a952017-03-01 15:31:25 -0800362 return reboot_device();
363 }
364
David Zeuthen1a0929c2017-08-07 18:47:27 -0400365 if (!skip_verification) {
Tianjie Xu446b64b2018-09-19 15:45:28 -0700366 UpdateVerifier verifier;
367 if (!verifier.ParseCareMap()) {
368 LOG(WARNING) << "Failed to parse the care map file, skipping verification";
369 } else if (!verifier.VerifyPartitions()) {
David Zeuthen1a0929c2017-08-07 18:47:27 -0400370 LOG(ERROR) << "Failed to verify all blocks in care map file.";
371 return reboot_device();
372 }
Tianjie Xud007cf22016-02-29 16:08:06 -0800373 }
Tao Bao7197ee02015-12-05 21:21:27 -0800374
Daniel Rosenberg15f22bd2019-01-22 19:57:28 -0800375 bool supports_checkpoint = false;
376 auto sm = android::defaultServiceManager();
377 android::sp<android::IBinder> binder = sm->getService(android::String16("vold"));
378 if (binder) {
379 auto vold = android::interface_cast<android::os::IVold>(binder);
380 android::binder::Status status = vold->supportsCheckpoint(&supports_checkpoint);
381 if (!status.isOk()) {
382 LOG(ERROR) << "Failed to check if checkpoints supported. Continuing";
383 }
384 } else {
385 LOG(ERROR) << "Failed to obtain vold Binder. Continuing";
Tao Bao7197ee02015-12-05 21:21:27 -0800386 }
Daniel Rosenberg15f22bd2019-01-22 19:57:28 -0800387
388 if (!supports_checkpoint) {
389 CommandResult cr;
390 module->markBootSuccessful([&cr](CommandResult result) { cr = result; });
391 if (!cr.success) {
392 LOG(ERROR) << "Error marking booted successfully: " << cr.errMsg;
393 return reboot_device();
394 }
395 LOG(INFO) << "Marked slot " << current_slot << " as booted successfully.";
Tianjie Xu88bf6d22019-11-14 15:07:25 -0800396 // Clears the warm reset flag for next reboot.
397 if (!android::base::SetProperty("ota.warm_reset", "0")) {
398 LOG(WARNING) << "Failed to reset the warm reset flag";
399 }
Daniel Rosenberg15f22bd2019-01-22 19:57:28 -0800400 } else {
401 LOG(INFO) << "Deferred marking slot " << current_slot << " as booted successfully.";
402 }
Tao Bao7197ee02015-12-05 21:21:27 -0800403 }
404
Tianjie Xu7b0ad9c2016-08-05 18:00:04 -0700405 LOG(INFO) << "Leaving update_verifier.";
Tao Bao7197ee02015-12-05 21:21:27 -0800406 return 0;
407}