summaryrefslogtreecommitdiffstats
path: root/update_verifier/update_verifier.cpp
diff options
context:
space:
mode:
authorTao Bao <tbao@google.com>2015-12-06 06:21:27 +0100
committerTao Bao <tbao@google.com>2015-12-08 20:24:11 +0100
commit7197ee0e39bebea3a1bbe5d980f4dbf1cfe58136 (patch)
tree950da26b6e000666b9a77bab67bbe41d90929468 /update_verifier/update_verifier.cpp
parentMerge "updater: Replace strtok() with android::base::Split()." (diff)
downloadandroid_bootable_recovery-7197ee0e39bebea3a1bbe5d980f4dbf1cfe58136.tar
android_bootable_recovery-7197ee0e39bebea3a1bbe5d980f4dbf1cfe58136.tar.gz
android_bootable_recovery-7197ee0e39bebea3a1bbe5d980f4dbf1cfe58136.tar.bz2
android_bootable_recovery-7197ee0e39bebea3a1bbe5d980f4dbf1cfe58136.tar.lz
android_bootable_recovery-7197ee0e39bebea3a1bbe5d980f4dbf1cfe58136.tar.xz
android_bootable_recovery-7197ee0e39bebea3a1bbe5d980f4dbf1cfe58136.tar.zst
android_bootable_recovery-7197ee0e39bebea3a1bbe5d980f4dbf1cfe58136.zip
Diffstat (limited to 'update_verifier/update_verifier.cpp')
-rw-r--r--update_verifier/update_verifier.cpp84
1 files changed, 84 insertions, 0 deletions
diff --git a/update_verifier/update_verifier.cpp b/update_verifier/update_verifier.cpp
new file mode 100644
index 000000000..9ba792b86
--- /dev/null
+++ b/update_verifier/update_verifier.cpp
@@ -0,0 +1,84 @@
+/*
+ * Copyright (C) 2015 The Android Open Source Project
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+/*
+ * This program verifies the integrity of the partitions after an A/B OTA
+ * update. It gets invoked by init, and will only perform the verification if
+ * it's the first boot post an A/B OTA update.
+ *
+ * It relies on dm-verity to capture any corruption on the partitions being
+ * verified. dm-verity must be in enforcing mode, so that it will reboot the
+ * device on dm-verity failures. When that happens, the bootloader should
+ * mark the slot as unbootable and stops trying. We should never see a device
+ * started in dm-verity logging mode but with isSlotBootable equals to 0.
+ *
+ * The current slot will be marked as having booted successfully if the
+ * verifier reaches the end after the verification.
+ *
+ * TODO: The actual verification part will be added later after we have the
+ * A/B OTA package format in place.
+ */
+
+#include <cutils/klog.h>
+#include <string.h>
+
+#include <hardware/boot_control.h>
+
+#define LOG_TAG "update_verifier"
+#define INFO(x...) KLOG_INFO(LOG_TAG, x)
+#define ERROR(x...) KLOG_ERROR(LOG_TAG, x)
+
+int main(int argc, char** argv) {
+ klog_init();
+ klog_set_level(6);
+ for (int i = 1; i < argc; i++) {
+ INFO("Started with arg %d: %s\n", i, argv[i]);
+ }
+
+ const hw_module_t* hw_module;
+ if (hw_get_module("bootctrl", &hw_module) != 0) {
+ ERROR("Error getting bootctrl module.\n");
+ return -1;
+ }
+
+ boot_control_module_t* module = reinterpret_cast<boot_control_module_t*>(
+ const_cast<hw_module_t*>(hw_module));
+ module->init(module);
+
+ unsigned current_slot = module->getCurrentSlot(module);
+ int bootable = module->isSlotBootable(module, current_slot);
+ INFO("Booting slot %u: isSlotBootable=%d\n", current_slot, bootable);
+
+ if (bootable == 0) {
+ // The current slot has not booted successfully.
+
+ // TODO: Add the actual verification after we have the A/B OTA package
+ // format in place.
+
+ // TODO: Assert the dm-verity mode. Bootloader should never boot a newly
+ // flashed slot (isSlotBootable == 0) with dm-verity logging mode.
+
+ int ret = module->markBootSuccessful(module);
+ if (ret != 0) {
+ ERROR("Error marking booted successfully: %s\n", strerror(-ret));
+ return -1;
+ }
+ INFO("Marked slot %u as booted successfully.\n", current_slot);
+ }
+
+ INFO("Leaving update_verifier.\n");
+ return 0;
+}