blob: be70cec7f18622a074fbddd7eb722c5c2fd9682e [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/*
18 * This program verifies the integrity of the partitions after an A/B OTA
19 * update. It gets invoked by init, and will only perform the verification if
20 * it's the first boot post an A/B OTA update.
21 *
22 * It relies on dm-verity to capture any corruption on the partitions being
23 * verified. dm-verity must be in enforcing mode, so that it will reboot the
24 * device on dm-verity failures. When that happens, the bootloader should
25 * mark the slot as unbootable and stops trying. We should never see a device
Tao Bao612161e2015-12-09 14:41:40 -080026 * started in dm-verity logging mode but with isSlotMarkedSuccessful equals to
27 * 0.
Tao Bao7197ee02015-12-05 21:21:27 -080028 *
29 * The current slot will be marked as having booted successfully if the
30 * verifier reaches the end after the verification.
31 *
32 * TODO: The actual verification part will be added later after we have the
33 * A/B OTA package format in place.
34 */
35
Tao Bao7197ee02015-12-05 21:21:27 -080036#include <string.h>
37
38#include <hardware/boot_control.h>
39
40#define LOG_TAG "update_verifier"
Tao Bao740e01e2015-12-07 17:04:58 -080041#include <log/log.h>
Tao Bao7197ee02015-12-05 21:21:27 -080042
43int main(int argc, char** argv) {
Tao Bao7197ee02015-12-05 21:21:27 -080044 for (int i = 1; i < argc; i++) {
Tao Bao740e01e2015-12-07 17:04:58 -080045 SLOGI("Started with arg %d: %s\n", i, argv[i]);
Tao Bao7197ee02015-12-05 21:21:27 -080046 }
47
48 const hw_module_t* hw_module;
49 if (hw_get_module("bootctrl", &hw_module) != 0) {
Tao Bao740e01e2015-12-07 17:04:58 -080050 SLOGE("Error getting bootctrl module.\n");
Tao Bao7197ee02015-12-05 21:21:27 -080051 return -1;
52 }
53
54 boot_control_module_t* module = reinterpret_cast<boot_control_module_t*>(
55 const_cast<hw_module_t*>(hw_module));
56 module->init(module);
57
58 unsigned current_slot = module->getCurrentSlot(module);
Tao Bao612161e2015-12-09 14:41:40 -080059 int is_successful= module->isSlotMarkedSuccessful(module, current_slot);
60 SLOGI("Booting slot %u: isSlotMarkedSuccessful=%d\n", current_slot, is_successful);
Tao Bao7197ee02015-12-05 21:21:27 -080061
Tao Bao612161e2015-12-09 14:41:40 -080062 if (is_successful == 0) {
Tao Bao7197ee02015-12-05 21:21:27 -080063 // The current slot has not booted successfully.
64
65 // TODO: Add the actual verification after we have the A/B OTA package
66 // format in place.
67
68 // TODO: Assert the dm-verity mode. Bootloader should never boot a newly
Tao Bao612161e2015-12-09 14:41:40 -080069 // flashed slot (isSlotMarkedSuccessful == 0) with dm-verity logging mode.
Tao Bao7197ee02015-12-05 21:21:27 -080070
71 int ret = module->markBootSuccessful(module);
72 if (ret != 0) {
Tao Bao740e01e2015-12-07 17:04:58 -080073 SLOGE("Error marking booted successfully: %s\n", strerror(-ret));
Tao Bao7197ee02015-12-05 21:21:27 -080074 return -1;
75 }
Tao Bao740e01e2015-12-07 17:04:58 -080076 SLOGI("Marked slot %u as booted successfully.\n", current_slot);
Tao Bao7197ee02015-12-05 21:21:27 -080077 }
78
Tao Bao740e01e2015-12-07 17:04:58 -080079 SLOGI("Leaving update_verifier.\n");
Tao Bao7197ee02015-12-05 21:21:27 -080080 return 0;
81}