Merge changes from topic "tombstone_proto"
* changes:
libdebuggerd: add protobuf implementation.
tombstoned: support for protobuf fds.
tombstoned: make it easier to add more types of outputs.
tombstoned: switch from goto to RAII.
diff --git a/code_coverage/seccomp_policy/code_coverage.arm.policy b/code_coverage/seccomp_policy/code_coverage.arm.policy
index b80910f..3589379 100644
--- a/code_coverage/seccomp_policy/code_coverage.arm.policy
+++ b/code_coverage/seccomp_policy/code_coverage.arm.policy
@@ -1,4 +1,5 @@
close: 1
+fchmod: 1
mkdirat: 1
msync: 1
munmap: 1
diff --git a/code_coverage/seccomp_policy/code_coverage.arm64.policy b/code_coverage/seccomp_policy/code_coverage.arm64.policy
index 7040ea2..fdb4d1e 100644
--- a/code_coverage/seccomp_policy/code_coverage.arm64.policy
+++ b/code_coverage/seccomp_policy/code_coverage.arm64.policy
@@ -1,4 +1,5 @@
close: 1
+fchmod: 1
mkdirat: 1
msync: 1
munmap: 1
diff --git a/code_coverage/seccomp_policy/code_coverage.policy.def b/code_coverage/seccomp_policy/code_coverage.policy.def
index 599c4a4..b6a4c6d 100644
--- a/code_coverage/seccomp_policy/code_coverage.policy.def
+++ b/code_coverage/seccomp_policy/code_coverage.policy.def
@@ -13,6 +13,9 @@
// 2nd-Nth: uses mmap() to update in place
close: 1
+// fchmod allowed to set libprofile-clang-extras, which wraps `open` calls, to
+// set correct permission for coverage files.
+fchmod: 1
mkdirat: 1
msync: 1
munmap: 1
diff --git a/code_coverage/seccomp_policy/code_coverage.x86.policy b/code_coverage/seccomp_policy/code_coverage.x86.policy
index f8e0cc0..145d3a3 100644
--- a/code_coverage/seccomp_policy/code_coverage.x86.policy
+++ b/code_coverage/seccomp_policy/code_coverage.x86.policy
@@ -1,4 +1,5 @@
close: 1
+fchmod: 1
mkdirat: 1
msync: 1
munmap: 1
diff --git a/code_coverage/seccomp_policy/code_coverage.x86_64.policy b/code_coverage/seccomp_policy/code_coverage.x86_64.policy
index dcf2f9a..11c8075 100644
--- a/code_coverage/seccomp_policy/code_coverage.x86_64.policy
+++ b/code_coverage/seccomp_policy/code_coverage.x86_64.policy
@@ -1,4 +1,5 @@
close: 1
+fchmod: 1
mkdirat: 1
msync: 1
munmap: 1
diff --git a/debuggerd/crash_dump.cpp b/debuggerd/crash_dump.cpp
index f2ff6df..51afcc2 100644
--- a/debuggerd/crash_dump.cpp
+++ b/debuggerd/crash_dump.cpp
@@ -40,6 +40,7 @@
#include <android-base/stringprintf.h>
#include <android-base/strings.h>
#include <android-base/unique_fd.h>
+#include <bionic/macros.h>
#include <bionic/reserved_signals.h>
#include <cutils/sockets.h>
#include <log/log.h>
@@ -310,7 +311,9 @@
*siginfo = crash_info->data.s.siginfo;
if (signal_has_si_addr(siginfo)) {
process_info->has_fault_address = true;
- process_info->fault_address = reinterpret_cast<uintptr_t>(siginfo->si_addr);
+ process_info->maybe_tagged_fault_address = reinterpret_cast<uintptr_t>(siginfo->si_addr);
+ process_info->untagged_fault_address =
+ untag_address(reinterpret_cast<uintptr_t>(siginfo->si_addr));
}
regs->reset(unwindstack::Regs::CreateFromUcontext(unwindstack::Regs::CurrentArch(),
&crash_info->data.s.ucontext));
diff --git a/debuggerd/debuggerd_test.cpp b/debuggerd/debuggerd_test.cpp
index 2652b1c..b9d6606 100644
--- a/debuggerd/debuggerd_test.cpp
+++ b/debuggerd/debuggerd_test.cpp
@@ -16,6 +16,7 @@
#include <err.h>
#include <fcntl.h>
+#include <malloc.h>
#include <stdlib.h>
#include <sys/capability.h>
#include <sys/mman.h>
@@ -32,7 +33,6 @@
#include <android/fdsan.h>
#include <android/set_abort_message.h>
-#include <bionic/malloc.h>
#include <bionic/mte.h>
#include <bionic/reserved_signals.h>
@@ -385,8 +385,7 @@
#if defined(__aarch64__)
static void SetTagCheckingLevelSync() {
- HeapTaggingLevel heap_tagging_level = M_HEAP_TAGGING_LEVEL_SYNC;
- if (!android_mallopt(M_SET_HEAP_TAGGING_LEVEL, &heap_tagging_level, sizeof(heap_tagging_level))) {
+ if (mallopt(M_BIONIC_SET_HEAP_TAGGING_LEVEL, M_HEAP_TAGGING_LEVEL_SYNC) == 0) {
abort();
}
}
diff --git a/debuggerd/handler/debuggerd_handler.cpp b/debuggerd/handler/debuggerd_handler.cpp
index 735f692..ca809e4 100644
--- a/debuggerd/handler/debuggerd_handler.cpp
+++ b/debuggerd/handler/debuggerd_handler.cpp
@@ -53,7 +53,6 @@
#include <android-base/unique_fd.h>
#include <async_safe/log.h>
#include <bionic/reserved_signals.h>
-#include <cutils/properties.h>
#include <libdebuggerd/utility.h>
diff --git a/debuggerd/libdebuggerd/gwp_asan.cpp b/debuggerd/libdebuggerd/gwp_asan.cpp
index f271365..9750fc4 100644
--- a/debuggerd/libdebuggerd/gwp_asan.cpp
+++ b/debuggerd/libdebuggerd/gwp_asan.cpp
@@ -72,8 +72,8 @@
// Get the external crash address from the thread info.
crash_address_ = 0u;
- if (signal_has_si_addr(thread_info.siginfo)) {
- crash_address_ = reinterpret_cast<uintptr_t>(thread_info.siginfo->si_addr);
+ if (process_info.has_fault_address) {
+ crash_address_ = process_info.untagged_fault_address;
}
// Ensure the error belongs to GWP-ASan.
diff --git a/debuggerd/libdebuggerd/include/libdebuggerd/types.h b/debuggerd/libdebuggerd/include/libdebuggerd/types.h
index ec2913c..d5b0735 100644
--- a/debuggerd/libdebuggerd/include/libdebuggerd/types.h
+++ b/debuggerd/libdebuggerd/include/libdebuggerd/types.h
@@ -48,5 +48,6 @@
uintptr_t scudo_region_info = 0;
bool has_fault_address = false;
- uintptr_t fault_address = 0;
+ uintptr_t untagged_fault_address = 0;
+ uintptr_t maybe_tagged_fault_address = 0;
};
diff --git a/debuggerd/libdebuggerd/scudo.cpp b/debuggerd/libdebuggerd/scudo.cpp
index f8bfe07..141c3bd 100644
--- a/debuggerd/libdebuggerd/scudo.cpp
+++ b/debuggerd/libdebuggerd/scudo.cpp
@@ -44,7 +44,7 @@
auto region_info = AllocAndReadFully(process_memory, process_info.scudo_region_info,
__scudo_get_region_info_size());
- untagged_fault_addr_ = untag_address(process_info.fault_address);
+ untagged_fault_addr_ = process_info.untagged_fault_address;
uintptr_t fault_page = untagged_fault_addr_ & ~(PAGE_SIZE - 1);
uintptr_t memory_begin = fault_page - PAGE_SIZE * 16;
@@ -67,7 +67,7 @@
memory_tags[(i - memory_begin) / kTagGranuleSize] = process_memory->ReadTag(i);
}
- __scudo_get_error_info(&error_info_, process_info.fault_address, stack_depot.get(),
+ __scudo_get_error_info(&error_info_, process_info.maybe_tagged_fault_address, stack_depot.get(),
region_info.get(), memory.get(), memory_tags.get(), memory_begin,
memory_end - memory_begin);
}
diff --git a/debuggerd/libdebuggerd/tombstone.cpp b/debuggerd/libdebuggerd/tombstone.cpp
index 5faa258..822b74a 100644
--- a/debuggerd/libdebuggerd/tombstone.cpp
+++ b/debuggerd/libdebuggerd/tombstone.cpp
@@ -153,7 +153,9 @@
const ProcessInfo& process_info, unwindstack::Memory* process_memory) {
char addr_desc[64]; // ", fault addr 0x1234"
if (process_info.has_fault_address) {
- size_t addr = process_info.fault_address;
+ // SIGILL faults will never have tagged addresses, so okay to
+ // indiscriminately use the tagged address here.
+ size_t addr = process_info.maybe_tagged_fault_address;
if (thread_info.siginfo->si_signo == SIGILL) {
uint32_t instruction = {};
process_memory->Read(addr, &instruction, sizeof(instruction));
@@ -433,9 +435,8 @@
thread_info.registers.get());
if (maps != nullptr) {
uint64_t addr = 0;
- siginfo_t* si = thread_info.siginfo;
- if (signal_has_si_addr(si)) {
- addr = reinterpret_cast<uint64_t>(si->si_addr);
+ if (process_info.has_fault_address) {
+ addr = process_info.untagged_fault_address;
}
dump_all_maps(log, unwinder, addr);
}
diff --git a/debuggerd/tombstoned/intercept_manager.cpp b/debuggerd/tombstoned/intercept_manager.cpp
index 577f829..437639e 100644
--- a/debuggerd/tombstoned/intercept_manager.cpp
+++ b/debuggerd/tombstoned/intercept_manager.cpp
@@ -27,7 +27,6 @@
#include <android-base/cmsg.h>
#include <android-base/logging.h>
#include <android-base/unique_fd.h>
-#include <cutils/sockets.h>
#include "protocol.h"
#include "util.h"
diff --git a/debuggerd/util.cpp b/debuggerd/util.cpp
index 9d09210..f3bff8c 100644
--- a/debuggerd/util.cpp
+++ b/debuggerd/util.cpp
@@ -16,7 +16,6 @@
#include "util.h"
-#include <sys/socket.h>
#include <time.h>
#include <string>
@@ -25,7 +24,6 @@
#include <android-base/file.h>
#include <android-base/stringprintf.h>
#include <android-base/strings.h>
-#include <cutils/sockets.h>
#include "protocol.h"
std::string get_process_name(pid_t pid) {
diff --git a/deprecated-adf/OWNERS b/deprecated-adf/OWNERS
deleted file mode 100644
index 72b8b5a..0000000
--- a/deprecated-adf/OWNERS
+++ /dev/null
@@ -1,2 +0,0 @@
-ghackmann@google.com
-marissaw@google.com
diff --git a/deprecated-adf/libadf/Android.bp b/deprecated-adf/libadf/Android.bp
deleted file mode 100644
index 70f0a3b..0000000
--- a/deprecated-adf/libadf/Android.bp
+++ /dev/null
@@ -1,26 +0,0 @@
-// Copyright (C) 2013 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.
-
-cc_library {
- name: "libadf",
- recovery_available: true,
- vendor_available: true,
- vndk: {
- enabled: true,
- },
- srcs: ["adf.cpp"],
- cflags: ["-Werror"],
- local_include_dirs: ["include"],
- export_include_dirs: ["include"],
-}
diff --git a/deprecated-adf/libadf/adf.cpp b/deprecated-adf/libadf/adf.cpp
deleted file mode 100644
index fd9c208..0000000
--- a/deprecated-adf/libadf/adf.cpp
+++ /dev/null
@@ -1,746 +0,0 @@
-/*
- * Copyright (C) 2013 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.
- */
-
-#include <dirent.h>
-#include <errno.h>
-#include <fcntl.h>
-#include <malloc.h>
-#include <stdint.h>
-#include <stdio.h>
-#include <string.h>
-#include <unistd.h>
-
-#include <algorithm>
-#include <memory>
-#include <vector>
-
-#include <linux/limits.h>
-
-#include <sys/ioctl.h>
-
-#include <adf/adf.h>
-
-#define ADF_BASE_PATH "/dev/"
-
-static ssize_t adf_id_vector_to_array(const std::vector<adf_id_t> &in,
- adf_id_t **out)
-{
- auto size = sizeof(in[0]) * in.size();
- // We can't use new[] since the existing API says the caller should free()
- // the returned array
- auto ret = static_cast<adf_id_t *>(malloc(size));
- if (!ret)
- return -ENOMEM;
-
- std::copy(in.begin(), in.end(), ret);
- *out = ret;
- return in.size();
-}
-
-static ssize_t adf_find_nodes(const char *pattern, adf_id_t **ids_out)
-{
- struct dirent *dirent;
- std::unique_ptr<DIR, decltype(&closedir)>
- dir{opendir(ADF_BASE_PATH), closedir};
- if (!dir)
- return -errno;
-
- std::vector<adf_id_t> ids;
- errno = 0;
- while ((dirent = readdir(dir.get()))) {
- adf_id_t id;
- int matched = sscanf(dirent->d_name, pattern, &id);
-
- if (matched < 0)
- return -errno;
- else if (matched == 1)
- ids.push_back(id);
- }
- if (errno)
- return -errno;
-
- return adf_id_vector_to_array(ids, ids_out);
-}
-
-ssize_t adf_devices(adf_id_t **ids)
-{
- return adf_find_nodes("adf%u", ids);
-}
-
-int adf_device_open(adf_id_t id, int flags, struct adf_device *dev)
-{
- char filename[64];
-
- dev->id = id;
-
- snprintf(filename, sizeof(filename), ADF_BASE_PATH "adf%u", id);
- dev->fd = open(filename, flags);
- if (dev->fd < 0)
- return -errno;
-
- return 0;
-}
-
-void adf_device_close(struct adf_device *dev)
-{
- if (dev->fd >= 0)
- close(dev->fd);
-}
-
-int adf_get_device_data(struct adf_device *dev, struct adf_device_data *data)
-{
- int err;
- int ret = 0;
-
- memset(data, 0, sizeof(*data));
-
- err = ioctl(dev->fd, ADF_GET_DEVICE_DATA, data);
- if (err < 0)
- return -ENOMEM;
-
- if (data->n_attachments)
- data->attachments = new adf_attachment_config[data->n_attachments];
-
- if (data->n_allowed_attachments)
- data->allowed_attachments =
- new adf_attachment_config[data->n_allowed_attachments];
-
- if (data->custom_data_size)
- data->custom_data = new char[data->custom_data_size];
-
- err = ioctl(dev->fd, ADF_GET_DEVICE_DATA, data);
- if (err < 0) {
- ret = -errno;
- adf_free_device_data(data);
- }
- return ret;
-}
-
-void adf_free_device_data(struct adf_device_data *data)
-{
- delete [] data->attachments;
- data->attachments = nullptr;
- delete [] data->allowed_attachments;
- data->allowed_attachments = nullptr;
- delete [] static_cast<char *>(data->custom_data);
- data->custom_data = nullptr;
-}
-
-int adf_device_post(struct adf_device *dev,
- adf_id_t *interfaces, size_t n_interfaces,
- struct adf_buffer_config *bufs, size_t n_bufs,
- void *custom_data, size_t custom_data_size)
-{
- int err;
- struct adf_post_config data;
-
- memset(&data, 0, sizeof(data));
- data.interfaces = interfaces;
- data.n_interfaces = n_interfaces;
- data.bufs = bufs;
- data.n_bufs = n_bufs;
- data.custom_data = custom_data;
- data.custom_data_size = custom_data_size;
-
- err = ioctl(dev->fd, ADF_POST_CONFIG, &data);
- if (err < 0)
- return -errno;
-
- return (int)data.complete_fence;
-}
-
-int adf_device_post_v2(struct adf_device *dev,
- adf_id_t *interfaces, __u32 n_interfaces,
- struct adf_buffer_config *bufs, __u32 n_bufs,
- void *custom_data, __u64 custom_data_size,
- enum adf_complete_fence_type complete_fence_type,
- int *complete_fence)
-{
- int err;
- struct adf_post_config_v2 data;
-
- memset(&data, 0, sizeof(data));
- data.interfaces = (uintptr_t)interfaces;
- data.n_interfaces = n_interfaces;
- data.bufs = (uintptr_t)bufs;
- data.n_bufs = n_bufs;
- data.custom_data = (uintptr_t)custom_data;
- data.custom_data_size = custom_data_size;
- data.complete_fence_type = complete_fence_type;
-
- err = ioctl(dev->fd, ADF_POST_CONFIG_V2, &data);
- if (err < 0)
- return -errno;
-
- if (complete_fence)
- *complete_fence = data.complete_fence;
- else if (data.complete_fence >= 0)
- close(data.complete_fence);
-
- return 0;
-}
-
-static int adf_device_attachment(struct adf_device *dev,
- adf_id_t overlay_engine, adf_id_t interface, bool attach)
-{
- int err;
- struct adf_attachment_config data;
-
- memset(&data, 0, sizeof(data));
- data.overlay_engine = overlay_engine;
- data.interface = interface;
-
- err = ioctl(dev->fd, attach ? ADF_ATTACH : ADF_DETACH, &data);
- if (err < 0)
- return -errno;
-
- return 0;
-}
-
-int adf_device_attach(struct adf_device *dev, adf_id_t overlay_engine,
- adf_id_t interface)
-{
- return adf_device_attachment(dev, overlay_engine, interface, true);
-}
-
-int adf_device_detach(struct adf_device *dev, adf_id_t overlay_engine,
- adf_id_t interface)
-{
- return adf_device_attachment(dev, overlay_engine, interface, false);
-}
-
-ssize_t adf_interfaces(struct adf_device *dev, adf_id_t **interfaces)
-{
- char pattern[64];
-
- snprintf(pattern, sizeof(pattern), "adf-interface%u.%%u", dev->id);
- return adf_find_nodes(pattern, interfaces);
-}
-
-ssize_t adf_interfaces_for_overlay_engine(struct adf_device *dev,
- adf_id_t overlay_engine, adf_id_t **interfaces)
-{
- struct adf_device_data data;
- auto err = adf_get_device_data(dev, &data);
- if (err < 0)
- return err;
-
- std::vector<adf_id_t> ids;
- if (data.allowed_attachments != nullptr)
- for (size_t i = 0; i < data.n_allowed_attachments; i++)
- if (data.allowed_attachments[i].overlay_engine == overlay_engine)
- ids.push_back(data.allowed_attachments[i].interface);
-
- adf_free_device_data(&data);
- return adf_id_vector_to_array(ids, interfaces);
-}
-
-static ssize_t adf_interfaces_filter(struct adf_device *dev,
- adf_id_t *in, size_t n_in, adf_id_t **out,
- bool (*filter)(struct adf_interface_data *data, __u32 match),
- __u32 match)
-{
- std::vector<adf_id_t> ids;
- for (size_t i = 0; i < n_in; i++) {
- int fd = adf_interface_open(dev, in[i], O_RDONLY);
- if (fd < 0)
- return fd;
-
- struct adf_interface_data data;
- auto ret = adf_get_interface_data(fd, &data);
- close(fd);
- if (ret < 0)
- return ret;
-
- if (filter(&data, match))
- ids.push_back(in[i]);
- }
-
- return adf_id_vector_to_array(ids, out);
-}
-
-static bool adf_interface_type_filter(struct adf_interface_data *data,
- __u32 type)
-{
- return data->type == (enum adf_interface_type)type;
-}
-
-ssize_t adf_interfaces_filter_by_type(struct adf_device *dev,
- enum adf_interface_type type,
- adf_id_t *in, size_t n_in, adf_id_t **out)
-{
- return adf_interfaces_filter(dev, in, n_in, out, adf_interface_type_filter,
- type);
-}
-
-static bool adf_interface_flags_filter(struct adf_interface_data *data,
- __u32 flag)
-{
- return !!(data->flags & flag);
-}
-
-ssize_t adf_interfaces_filter_by_flag(struct adf_device *dev, __u32 flag,
- adf_id_t *in, size_t n_in, adf_id_t **out)
-{
- return adf_interfaces_filter(dev, in, n_in, out, adf_interface_flags_filter,
- flag);
-}
-
-int adf_interface_open(struct adf_device *dev, adf_id_t id, int flags)
-{
- char filename[64];
-
- snprintf(filename, sizeof(filename), ADF_BASE_PATH "adf-interface%u.%u",
- dev->id, id);
-
- int fd = open(filename, flags);
- if (fd < 0)
- return -errno;
- return fd;
-}
-
-int adf_get_interface_data(int fd, struct adf_interface_data *data)
-{
- int err;
- int ret = 0;
-
- memset(data, 0, sizeof(*data));
-
- err = ioctl(fd, ADF_GET_INTERFACE_DATA, data);
- if (err < 0)
- return -errno;
-
- if (data->n_available_modes)
- data->available_modes = new drm_mode_modeinfo[data->n_available_modes];
-
- if (data->custom_data_size)
- data->custom_data = new char[data->custom_data_size];
-
- err = ioctl(fd, ADF_GET_INTERFACE_DATA, data);
- if (err < 0) {
- ret = -errno;
- adf_free_interface_data(data);
- }
- return ret;
-}
-
-void adf_free_interface_data(struct adf_interface_data *data)
-{
- delete [] data->available_modes;
- delete [] static_cast<char *>(data->custom_data);
-}
-
-int adf_interface_blank(int fd, __u8 mode)
-{
- int err = ioctl(fd, ADF_BLANK, mode);
- if (err < 0)
- return -errno;
- return 0;
-}
-
-int adf_interface_set_mode(int fd, struct drm_mode_modeinfo *mode)
-{
- int err = ioctl(fd, ADF_SET_MODE, mode);
- if (err < 0)
- return -errno;
- return 0;
-}
-
-int adf_interface_simple_buffer_alloc(int fd, __u32 w, __u32 h,
- __u32 format, __u32 *offset, __u32 *pitch)
-{
- int err;
- struct adf_simple_buffer_alloc data;
-
- memset(&data, 0, sizeof(data));
- data.w = w;
- data.h = h;
- data.format = format;
-
- err = ioctl(fd, ADF_SIMPLE_BUFFER_ALLOC, &data);
- if (err < 0)
- return -errno;
-
- *offset = data.offset;
- *pitch = data.pitch;
- return (int)data.fd;
-}
-
-static void adf_interface_simple_post_config_buf(struct adf_buffer_config *buf,
- __u32 overlay_engine, __u32 w, __u32 h, __u32 format, int buf_fd,
- __u32 offset, __u32 pitch, int acquire_fence)
-{
- buf->overlay_engine = overlay_engine;
- buf->w = w;
- buf->h = h;
- buf->format = format;
- buf->fd[0] = buf_fd;
- buf->offset[0] = offset;
- buf->pitch[0] = pitch;
- buf->n_planes = 1;
- buf->acquire_fence = acquire_fence;
-}
-
-int adf_interface_simple_post(int fd, __u32 overlay_engine,
- __u32 w, __u32 h, __u32 format, int buf_fd, __u32 offset,
- __u32 pitch, int acquire_fence)
-{
- int ret;
- struct adf_simple_post_config data;
-
- memset(&data, 0, sizeof(data));
- adf_interface_simple_post_config_buf(&data.buf, overlay_engine, w, h, format,
- buf_fd, offset, pitch, acquire_fence);
- ret = ioctl(fd, ADF_SIMPLE_POST_CONFIG, &data);
- if (ret < 0)
- return -errno;
-
- return (int)data.complete_fence;
-}
-
-int adf_interface_simple_post_v2(int fd, adf_id_t overlay_engine,
- __u32 w, __u32 h, __u32 format, int buf_fd, __u32 offset,
- __u32 pitch, int acquire_fence,
- enum adf_complete_fence_type complete_fence_type,
- int *complete_fence)
-{
- int ret;
- struct adf_simple_post_config_v2 data;
-
- memset(&data, 0, sizeof(data));
- adf_interface_simple_post_config_buf(&data.buf, overlay_engine, w, h, format,
- buf_fd, offset, pitch, acquire_fence);
- data.complete_fence_type = complete_fence_type;
-
- ret = ioctl(fd, ADF_SIMPLE_POST_CONFIG_V2, &data);
- if (ret < 0)
- return -errno;
-
- if (complete_fence)
- *complete_fence = data.complete_fence;
- else if (data.complete_fence >= 0)
- close(data.complete_fence);
-
- return 0;
-}
-
-ssize_t adf_overlay_engines(struct adf_device *dev, adf_id_t **overlay_engines)
-{
- char pattern[64];
-
- snprintf(pattern, sizeof(pattern), "adf-overlay-engine%u.%%u", dev->id);
- return adf_find_nodes(pattern, overlay_engines);
-}
-
-ssize_t adf_overlay_engines_for_interface(struct adf_device *dev,
- adf_id_t interface, adf_id_t **overlay_engines)
-{
- struct adf_device_data data;
- auto err = adf_get_device_data(dev, &data);
- if (err < 0)
- return err;
-
- std::vector<adf_id_t> ids;
- if (data.allowed_attachments != nullptr)
- for (size_t i = 0; i < data.n_allowed_attachments; i++)
- if (data.allowed_attachments[i].interface == interface)
- ids.push_back(data.allowed_attachments[i].overlay_engine);
-
- return adf_id_vector_to_array(ids, overlay_engines);
-}
-
-static ssize_t adf_overlay_engines_filter(struct adf_device *dev,
- adf_id_t *in, size_t n_in, adf_id_t **out,
- bool (*filter)(struct adf_overlay_engine_data *data, void *cookie),
- void *cookie)
-{
- std::vector<adf_id_t> ids;
- size_t i;
- for (i = 0; i < n_in; i++) {
- int fd = adf_overlay_engine_open(dev, in[i], O_RDONLY);
- if (fd < 0)
- return fd;
-
- struct adf_overlay_engine_data data;
- auto ret = adf_get_overlay_engine_data(fd, &data);
- close(fd);
- if (ret < 0)
- return ret;
-
- if (filter(&data, cookie))
- ids.push_back(in[i]);
- }
-
- return adf_id_vector_to_array(ids, out);
-}
-
-struct format_filter_cookie {
- const __u32 *formats;
- size_t n_formats;
-};
-
-static bool adf_overlay_engine_format_filter(
- struct adf_overlay_engine_data *data, void *cookie)
-{
- auto c = static_cast<format_filter_cookie *>(cookie);
- size_t i;
- for (i = 0; i < data->n_supported_formats; i++) {
- size_t j;
- for (j = 0; j < c->n_formats; j++)
- if (data->supported_formats[i] == c->formats[j])
- return true;
- }
- return false;
-}
-
-ssize_t adf_overlay_engines_filter_by_format(struct adf_device *dev,
- const __u32 *formats, size_t n_formats, adf_id_t *in, size_t n_in,
- adf_id_t **out)
-{
- struct format_filter_cookie cookie = { formats, n_formats };
- return adf_overlay_engines_filter(dev, in, n_in, out,
- adf_overlay_engine_format_filter, &cookie);
-}
-
-int adf_overlay_engine_open(struct adf_device *dev, adf_id_t id, int flags)
-{
- char filename[64];
-
- snprintf(filename, sizeof(filename),
- ADF_BASE_PATH "adf-overlay-engine%u.%u", dev->id, id);
-
- int fd = open(filename, flags);
- if (fd < 0)
- return -errno;
- return fd;
-}
-
-int adf_get_overlay_engine_data(int fd, struct adf_overlay_engine_data *data)
-{
- int err;
- int ret = 0;
-
- memset(data, 0, sizeof(*data));
-
- err = ioctl(fd, ADF_GET_OVERLAY_ENGINE_DATA, data);
- if (err < 0)
- return -errno;
-
- if (data->n_supported_formats)
- data->supported_formats = new __u32[data->n_supported_formats];
-
- if (data->custom_data_size)
- data->custom_data = new char[data->custom_data_size];
-
- err = ioctl(fd, ADF_GET_OVERLAY_ENGINE_DATA, data);
- if (err < 0) {
- ret = -errno;
- adf_free_overlay_engine_data(data);
- }
- return ret;
-}
-
-void adf_free_overlay_engine_data(struct adf_overlay_engine_data *data)
-{
- delete [] data->supported_formats;
- data->supported_formats = nullptr;
- delete [] static_cast<char *>(data->custom_data);
- data->custom_data = nullptr;
-}
-
-bool adf_overlay_engine_supports_format(int fd, __u32 format)
-{
- struct adf_overlay_engine_data data;
- bool ret = false;
- size_t i;
-
- int err = adf_get_overlay_engine_data(fd, &data);
- if (err < 0)
- return false;
-
- if (data.supported_formats != nullptr) {
- for (i = 0; i < data.n_supported_formats; i++) {
- if (data.supported_formats[i] == format) {
- ret = true;
- break;
- }
- }
- }
-
- adf_free_overlay_engine_data(&data);
- return ret;
-}
-
-int adf_set_event(int fd, enum adf_event_type type, bool enabled)
-{
- struct adf_set_event data;
-
- data.type = type;
- data.enabled = enabled;
-
- int err = ioctl(fd, ADF_SET_EVENT, &data);
- if (err < 0)
- return -errno;
- return 0;
-}
-
-int adf_read_event(int fd, struct adf_event **event)
-{
- struct adf_event header;
- struct event_with_data {
- struct adf_event base;
- uint8_t data[0];
- };
- using unique_event = std::unique_ptr<event_with_data, decltype(&free)>;
- size_t data_size;
-
- int err = read(fd, &header, sizeof(header));
- if (err < 0)
- return -errno;
- if ((size_t)err < sizeof(header))
- return -EIO;
- if (header.length < sizeof(header))
- return -EIO;
-
- // Again, we can't use new[] since the existing API says the caller should
- // free() the returned event
- auto event_ptr = static_cast<event_with_data *>(malloc(header.length));
- unique_event event_ret{event_ptr, free};
- if (!event_ret)
- return -ENOMEM;
- data_size = header.length - sizeof(header);
-
- memcpy(event_ret.get(), &header, sizeof(header));
- ssize_t read_size = read(fd, &event_ret->data, data_size);
- if (read_size < 0)
- return -errno;
- if ((size_t)read_size < data_size)
- return -EIO;
-
- *event = &event_ret.release()->base;
- return 0;
-}
-
-void adf_format_str(__u32 format, char buf[ADF_FORMAT_STR_SIZE])
-{
- buf[0] = format & 0xFF;
- buf[1] = (format >> 8) & 0xFF;
- buf[2] = (format >> 16) & 0xFF;
- buf[3] = (format >> 24) & 0xFF;
- buf[4] = '\0';
-}
-
-static bool adf_find_simple_post_overlay_engine(struct adf_device *dev,
- const __u32 *formats, size_t n_formats,
- adf_id_t interface, adf_id_t *overlay_engine)
-{
- adf_id_t *engs = nullptr;
- ssize_t n_engs = adf_overlay_engines_for_interface(dev, interface, &engs);
-
- if (engs == nullptr)
- return false;
-
- adf_id_t *filtered_engs = nullptr;
- ssize_t n_filtered_engs = adf_overlay_engines_filter_by_format(dev,
- formats, n_formats, engs, n_engs, &filtered_engs);
- free(engs);
-
- if (filtered_engs == nullptr)
- return false;
-
- *overlay_engine = filtered_engs[0];
- free(filtered_engs);
- return true;
-}
-
-static const __u32 any_rgb_format[] = {
- DRM_FORMAT_C8,
- DRM_FORMAT_RGB332,
- DRM_FORMAT_BGR233,
- DRM_FORMAT_XRGB1555,
- DRM_FORMAT_XBGR1555,
- DRM_FORMAT_RGBX5551,
- DRM_FORMAT_BGRX5551,
- DRM_FORMAT_ARGB1555,
- DRM_FORMAT_ABGR1555,
- DRM_FORMAT_RGBA5551,
- DRM_FORMAT_BGRA5551,
- DRM_FORMAT_RGB565,
- DRM_FORMAT_BGR565,
- DRM_FORMAT_RGB888,
- DRM_FORMAT_BGR888,
- DRM_FORMAT_XRGB8888,
- DRM_FORMAT_XBGR8888,
- DRM_FORMAT_RGBX8888,
- DRM_FORMAT_BGRX8888,
- DRM_FORMAT_XRGB2101010,
- DRM_FORMAT_XBGR2101010,
- DRM_FORMAT_RGBX1010102,
- DRM_FORMAT_BGRX1010102,
- DRM_FORMAT_ARGB2101010,
- DRM_FORMAT_ABGR2101010,
- DRM_FORMAT_RGBA1010102,
- DRM_FORMAT_BGRA1010102,
- DRM_FORMAT_ARGB8888,
- DRM_FORMAT_ABGR8888,
- DRM_FORMAT_RGBA8888,
- DRM_FORMAT_BGRA8888,
-};
-
-int adf_find_simple_post_configuration(struct adf_device *dev,
- const __u32 *formats, size_t n_formats,
- adf_id_t *interface, adf_id_t *overlay_engine)
-{
- adf_id_t *intfs = NULL;
- ssize_t n_intfs = adf_interfaces(dev, &intfs);
-
- if (n_intfs < 0)
- return n_intfs;
- else if (!intfs)
- return -ENODEV;
-
- adf_id_t *primary_intfs = nullptr;
- ssize_t n_primary_intfs = adf_interfaces_filter_by_flag(dev,
- ADF_INTF_FLAG_PRIMARY, intfs, n_intfs, &primary_intfs);
- free(intfs);
-
- if (n_primary_intfs < 0)
- return n_primary_intfs;
- else if (!primary_intfs)
- return -ENODEV;
-
- if (!formats) {
- formats = any_rgb_format;
- n_formats = sizeof(any_rgb_format) / sizeof(any_rgb_format[0]);
- }
-
- bool found = false;
- ssize_t i = 0;
- for (i = 0; i < n_primary_intfs; i++) {
- found = adf_find_simple_post_overlay_engine(dev, formats, n_formats,
- primary_intfs[i], overlay_engine);
- if (found) {
- *interface = primary_intfs[i];
- break;
- }
- }
- free(primary_intfs);
-
- if (!found)
- return -ENODEV;
-
- return 0;
-}
diff --git a/deprecated-adf/libadf/include/adf/adf.h b/deprecated-adf/libadf/include/adf/adf.h
deleted file mode 100644
index e4c7b28..0000000
--- a/deprecated-adf/libadf/include/adf/adf.h
+++ /dev/null
@@ -1,295 +0,0 @@
-/*
- * Copyright (C) 2013 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.
- */
-
-#ifndef _LIBADF_ADF_H_
-#define _LIBADF_ADF_H_
-
-#include <stdint.h>
-#include <stdbool.h>
-#include <sys/cdefs.h>
-#include <sys/types.h>
-#include <video/adf.h>
-
-typedef __u32 adf_id_t;
-
-struct adf_device {
- adf_id_t id;
- int fd;
-};
-
-__BEGIN_DECLS
-
-/**
- * Enumerates all ADF devices.
- *
- * Returns the number of ADF devices, and sets ids to a list of device IDs.
- * The caller must free() the returned list of device IDs.
- *
- * On error, returns -errno.
- */
-ssize_t adf_devices(adf_id_t **ids);
-
-/**
- * Opens an ADF device.
- *
- * On error, returns -errno.
- */
-int adf_device_open(adf_id_t id, int flags, struct adf_device *dev);
-/**
- * Closes an ADF device.
- */
-void adf_device_close(struct adf_device *dev);
-/**
- * Reads the ADF device data.
- *
- * adf_get_device_data() allocates buffers inside data, which the caller
- * must free by calling adf_free_device_data(). On error, returns -errno.
- */
-int adf_get_device_data(struct adf_device *dev, struct adf_device_data *data);
-/**
- * Frees the device data returned by adf_get_device_data().
- */
-void adf_free_device_data(struct adf_device_data *data);
-
-/**
- * Atomically posts a new display configuration to the specified interfaces.
- *
- * Returns a sync fence fd that will fire when the configuration is removed
- * from the screen. On error, returns -errno.
- */
-int adf_device_post(struct adf_device *dev,
- adf_id_t *interfaces, size_t n_interfaces,
- struct adf_buffer_config *bufs, size_t n_bufs,
- void *custom_data, size_t custom_data_size);
-/**
- * Atomically posts a new display configuration to the specified interfaces.
- *
- * Compared to adf_device_post(), adf_device_post_v2():
- *
- * (*) allows the client to choose the kind of sync fence returned
- * (through complete_fence_type)
- *
- * (*) stores the returned sync fence fd in a provided buffer, so the client
- * can distinguish between a permission error (ret = -1) and a successful
- * call that returns no fence (*complete_fence = -1)
- *
- * On error, returns -errno.
- *
- * On devices without the corresponding kernel support, returns -ENOTTY.
- */
-int adf_device_post_v2(struct adf_device *dev,
- adf_id_t *interfaces, __u32 n_interfaces,
- struct adf_buffer_config *bufs, __u32 n_bufs,
- void *custom_data, __u64 custom_data_size,
- enum adf_complete_fence_type complete_fence_type,
- int *complete_fence);
-
-/**
- * Attaches the specified interface and overlay engine.
- */
-int adf_device_attach(struct adf_device *dev, adf_id_t overlay_engine,
- adf_id_t interface);
-/**
- * Detaches the specified interface and overlay engine.
- */
-int adf_device_detach(struct adf_device *dev, adf_id_t overlay_engine,
- adf_id_t interface);
-
-/**
- * Enumerates all interfaces belonging to an ADF device.
- *
- * The caller must free() the returned list of interface IDs.
- */
-ssize_t adf_interfaces(struct adf_device *dev, adf_id_t **interfaces);
-
-/**
- * Enumerates all interfaces which can be attached to the specified overlay
- * engine.
- *
- * The caller must free() the returned list of interface IDs.
- */
-ssize_t adf_interfaces_for_overlay_engine(struct adf_device *dev,
- adf_id_t overlay_engine, adf_id_t **interfaces);
-/**
- * Filters a list of interfaces by type.
- *
- * Returns the number of matching interfaces, and sets out to a list of matching
- * interface IDs. The caller must free() the returned list of interface IDs.
- *
- * On error, returns -errno.
- */
-ssize_t adf_interfaces_filter_by_type(struct adf_device *dev,
- enum adf_interface_type type,
- adf_id_t *in, size_t n_in, adf_id_t **out);
-/**
- * Filters a list of interfaces by flag.
- *
- * The caller must free() the returned list of interface IDs.
- */
-ssize_t adf_interfaces_filter_by_flag(struct adf_device *dev, __u32 flag,
- adf_id_t *in, size_t n_in, adf_id_t **out);
-
-/**
- * Opens an ADF interface.
- *
- * Returns a file descriptor. The caller must close() the fd when done.
- * On error, returns -errno.
- */
-int adf_interface_open(struct adf_device *dev, adf_id_t id, int flags);
-/**
- * Reads the interface data.
- *
- * adf_get_interface_data() allocates buffers inside data, which the caller
- * must free by calling adf_free_interface_data(). On error, returns -errno.
- */
-int adf_get_interface_data(int fd, struct adf_interface_data *data);
-/**
- * Frees the interface data returned by adf_get_interface_data().
- */
-void adf_free_interface_data(struct adf_interface_data *data);
-
-/**
- * Sets the interface's DPMS mode.
- */
-int adf_interface_blank(int fd, __u8 mode);
-/**
- * Sets the interface's display mode.
- */
-int adf_interface_set_mode(int fd, struct drm_mode_modeinfo *mode);
-/**
- * Allocates a single-plane RGB buffer of the specified size and format.
- *
- * Returns a dma-buf fd. On error, returns -errno.
- */
-int adf_interface_simple_buffer_alloc(int fd, __u32 w, __u32 h,
- __u32 format, __u32 *offset, __u32 *pitch);
-/**
- * Posts a single-plane RGB buffer to the display using the specified
- * overlay engine.
- *
- * Returns a sync fence fd that will fire when the buffer is removed
- * from the screen. On error, returns -errno.
- */
-int adf_interface_simple_post(int fd, adf_id_t overlay_engine,
- __u32 w, __u32 h, __u32 format, int buf_fd, __u32 offset,
- __u32 pitch, int acquire_fence);
-/**
- * Posts a single-plane RGB buffer to the display using the specified
- * overlay engine.
- *
- * Compared to adf_interface_simple_post(), adf_interface_simple_post_v2():
- *
- * (*) allows the client to choose the kind of sync fence returned
- * (through complete_fence_type)
- *
- * (*) stores the returned sync fence fd in a provided buffer, so the client
- * can distinguish between a permission error (ret = -1) and a successful
- * call that returns no fence (*complete_fence = -1)
- *
- * On error, returns -errno.
- *
- * On devices without the corresponding kernel support, returns -ENOTTY.
- */
-int adf_interface_simple_post_v2(int fd, adf_id_t overlay_engine,
- __u32 w, __u32 h, __u32 format, int buf_fd, __u32 offset,
- __u32 pitch, int acquire_fence,
- enum adf_complete_fence_type complete_fence_type,
- int *complete_fence);
-
-/**
- * Enumerates all overlay engines belonging to an ADF device.
- *
- * The caller must free() the returned list of overlay engine IDs.
- */
-ssize_t adf_overlay_engines(struct adf_device *dev, adf_id_t **overlay_engines);
-
-/**
- * Enumerates all overlay engines which can be attached to the specified
- * interface.
- *
- * The caller must free() the returned list of overlay engine IDs.
- */
-ssize_t adf_overlay_engines_for_interface(struct adf_device *dev,
- adf_id_t interface, adf_id_t **overlay_engines);
-/**
- * Filters a list of overlay engines by supported buffer format.
- *
- * Returns the overlay engines which support at least one of the specified
- * formats. The caller must free() the returned list of overlay engine IDs.
- */
-ssize_t adf_overlay_engines_filter_by_format(struct adf_device *dev,
- const __u32 *formats, size_t n_formats, adf_id_t *in, size_t n_in,
- adf_id_t **out);
-
-/**
- * Opens an ADF overlay engine.
- *
- * Returns a file descriptor. The caller must close() the fd when done.
- * On error, returns -errno.
- */
-int adf_overlay_engine_open(struct adf_device *dev, adf_id_t id, int flags);
-/**
- * Reads the overlay engine data.
- *
- * adf_get_overlay_engine_data() allocates buffers inside data, which the caller
- * must free by calling adf_free_overlay_engine_data(). On error, returns
- * -errno.
- */
-int adf_get_overlay_engine_data(int fd, struct adf_overlay_engine_data *data);
-/**
- * Frees the overlay engine data returned by adf_get_overlay_engine_data().
- */
-void adf_free_overlay_engine_data(struct adf_overlay_engine_data *data);
-
-/**
- * Returns whether the overlay engine supports the specified format.
- */
-bool adf_overlay_engine_supports_format(int fd, __u32 format);
-
-/**
- * Subscribes or unsubscribes from the specified hardware event.
- */
-int adf_set_event(int fd, enum adf_event_type type, bool enabled);
-/**
- * Reads one event from the fd, blocking if needed.
- *
- * The caller must free() the returned buffer. On error, returns -errno.
- */
-int adf_read_event(int fd, struct adf_event **event);
-
-#define ADF_FORMAT_STR_SIZE 5
-/**
- * Converts an ADF/DRM fourcc format to its string representation.
- */
-void adf_format_str(__u32 format, char buf[ADF_FORMAT_STR_SIZE]);
-
-/**
- * Finds an appropriate interface and overlay engine for a simple post.
- *
- * Specifically, finds the primary interface, and an overlay engine
- * that can be attached to the primary interface and supports one of the
- * specified formats. The caller may pass a NULL formats list, to indicate that
- * any RGB format is acceptable.
- *
- * On error, returns -errno.
- */
-int adf_find_simple_post_configuration(struct adf_device *dev,
- const __u32 *formats, size_t n_formats,
- adf_id_t *interface, adf_id_t *overlay_engine);
-
-__END_DECLS
-
-#endif /* _LIBADF_ADF_H_ */
diff --git a/deprecated-adf/libadf/include/video/adf.h b/deprecated-adf/libadf/include/video/adf.h
deleted file mode 100644
index 692a425..0000000
--- a/deprecated-adf/libadf/include/video/adf.h
+++ /dev/null
@@ -1,209 +0,0 @@
-/****************************************************************************
- ****************************************************************************
- ***
- *** This header was automatically generated from a Linux kernel header
- *** of the same name, to make information necessary for userspace to
- *** call into the kernel available to libc. It contains only constants,
- *** structures, and macros generated from the original header, and thus,
- *** contains no copyrightable information.
- ***
- *** To edit the content of this header, modify the corresponding
- *** source file (e.g. under external/kernel-headers/original/) then
- *** run bionic/libc/kernel/tools/update_all.py
- ***
- *** Any manual change here will be lost the next time this script will
- *** be run. You've been warned!
- ***
- ****************************************************************************
- ****************************************************************************/
-#ifndef _UAPI_VIDEO_ADF_H_
-#define _UAPI_VIDEO_ADF_H_
-#include <linux/ioctl.h>
-#include <linux/types.h>
-/* WARNING: DO NOT EDIT, AUTO-GENERATED CODE - SEE TOP FOR INSTRUCTIONS */
-#include <drm/drm_fourcc.h>
-#include <drm/drm_mode.h>
-#define ADF_NAME_LEN 32
-#define ADF_MAX_CUSTOM_DATA_SIZE 4096
-/* WARNING: DO NOT EDIT, AUTO-GENERATED CODE - SEE TOP FOR INSTRUCTIONS */
-enum adf_interface_type {
- ADF_INTF_DSI = 0,
- ADF_INTF_eDP = 1,
- ADF_INTF_DPI = 2,
-/* WARNING: DO NOT EDIT, AUTO-GENERATED CODE - SEE TOP FOR INSTRUCTIONS */
- ADF_INTF_VGA = 3,
- ADF_INTF_DVI = 4,
- ADF_INTF_HDMI = 5,
- ADF_INTF_MEMORY = 6,
-/* WARNING: DO NOT EDIT, AUTO-GENERATED CODE - SEE TOP FOR INSTRUCTIONS */
- ADF_INTF_TYPE_DEVICE_CUSTOM = 128,
- ADF_INTF_TYPE_MAX = (~(__u32) 0),
-};
-#define ADF_INTF_FLAG_PRIMARY (1 << 0)
-/* WARNING: DO NOT EDIT, AUTO-GENERATED CODE - SEE TOP FOR INSTRUCTIONS */
-#define ADF_INTF_FLAG_EXTERNAL (1 << 1)
-enum adf_event_type {
- ADF_EVENT_VSYNC = 0,
- ADF_EVENT_HOTPLUG = 1,
-/* WARNING: DO NOT EDIT, AUTO-GENERATED CODE - SEE TOP FOR INSTRUCTIONS */
- ADF_EVENT_DEVICE_CUSTOM = 128,
- ADF_EVENT_TYPE_MAX = 255,
-};
-enum adf_complete_fence_type {
-/* WARNING: DO NOT EDIT, AUTO-GENERATED CODE - SEE TOP FOR INSTRUCTIONS */
- ADF_COMPLETE_FENCE_NONE = 0,
- ADF_COMPLETE_FENCE_PRESENT = 1,
- ADF_COMPLETE_FENCE_RELEASE = 2,
-};
-/* WARNING: DO NOT EDIT, AUTO-GENERATED CODE - SEE TOP FOR INSTRUCTIONS */
-struct adf_set_event {
- __u8 type;
- __u8 enabled;
-};
-/* WARNING: DO NOT EDIT, AUTO-GENERATED CODE - SEE TOP FOR INSTRUCTIONS */
-struct adf_event {
- __u8 type;
- __u32 length;
-};
-/* WARNING: DO NOT EDIT, AUTO-GENERATED CODE - SEE TOP FOR INSTRUCTIONS */
-struct adf_vsync_event {
- struct adf_event base;
- __aligned_u64 timestamp;
-};
-/* WARNING: DO NOT EDIT, AUTO-GENERATED CODE - SEE TOP FOR INSTRUCTIONS */
-struct adf_hotplug_event {
- struct adf_event base;
- __u8 connected;
-};
-/* WARNING: DO NOT EDIT, AUTO-GENERATED CODE - SEE TOP FOR INSTRUCTIONS */
-#define ADF_MAX_PLANES 4
-struct adf_buffer_config {
- __u32 overlay_engine;
- __u32 w;
-/* WARNING: DO NOT EDIT, AUTO-GENERATED CODE - SEE TOP FOR INSTRUCTIONS */
- __u32 h;
- __u32 format;
- __s32 fd[ADF_MAX_PLANES];
- __u32 offset[ADF_MAX_PLANES];
-/* WARNING: DO NOT EDIT, AUTO-GENERATED CODE - SEE TOP FOR INSTRUCTIONS */
- __u32 pitch[ADF_MAX_PLANES];
- __u8 n_planes;
- __s32 acquire_fence;
-};
-/* WARNING: DO NOT EDIT, AUTO-GENERATED CODE - SEE TOP FOR INSTRUCTIONS */
-#define ADF_MAX_BUFFERS (4096 / sizeof(struct adf_buffer_config))
-struct adf_post_config {
- size_t n_interfaces;
- __u32 __user * interfaces;
-/* WARNING: DO NOT EDIT, AUTO-GENERATED CODE - SEE TOP FOR INSTRUCTIONS */
- size_t n_bufs;
- struct adf_buffer_config __user * bufs;
- size_t custom_data_size;
- void __user * custom_data;
-/* WARNING: DO NOT EDIT, AUTO-GENERATED CODE - SEE TOP FOR INSTRUCTIONS */
- __s32 complete_fence;
-};
-struct adf_post_config_v2 {
- __u32 n_interfaces;
-/* WARNING: DO NOT EDIT, AUTO-GENERATED CODE - SEE TOP FOR INSTRUCTIONS */
- __u64 interfaces;
- __u32 n_bufs;
- __u64 bufs;
- __u64 custom_data_size;
-/* WARNING: DO NOT EDIT, AUTO-GENERATED CODE - SEE TOP FOR INSTRUCTIONS */
- __u64 custom_data;
- __s32 complete_fence;
- __u8 complete_fence_type;
-};
-/* WARNING: DO NOT EDIT, AUTO-GENERATED CODE - SEE TOP FOR INSTRUCTIONS */
-#define ADF_MAX_INTERFACES (4096 / sizeof(__u32))
-struct adf_simple_buffer_alloc {
- __u16 w;
- __u16 h;
-/* WARNING: DO NOT EDIT, AUTO-GENERATED CODE - SEE TOP FOR INSTRUCTIONS */
- __u32 format;
- __s32 fd;
- __u32 offset;
- __u32 pitch;
-/* WARNING: DO NOT EDIT, AUTO-GENERATED CODE - SEE TOP FOR INSTRUCTIONS */
-};
-struct adf_simple_post_config {
- struct adf_buffer_config buf;
- __s32 complete_fence;
-/* WARNING: DO NOT EDIT, AUTO-GENERATED CODE - SEE TOP FOR INSTRUCTIONS */
-};
-struct adf_simple_post_config_v2 {
- struct adf_buffer_config buf;
- __s32 complete_fence;
-/* WARNING: DO NOT EDIT, AUTO-GENERATED CODE - SEE TOP FOR INSTRUCTIONS */
- __u8 complete_fence_type;
-};
-struct adf_attachment_config {
- __u32 overlay_engine;
-/* WARNING: DO NOT EDIT, AUTO-GENERATED CODE - SEE TOP FOR INSTRUCTIONS */
- __u32 interface;
-};
-struct adf_device_data {
- char name[ADF_NAME_LEN];
-/* WARNING: DO NOT EDIT, AUTO-GENERATED CODE - SEE TOP FOR INSTRUCTIONS */
- size_t n_attachments;
- struct adf_attachment_config __user * attachments;
- size_t n_allowed_attachments;
- struct adf_attachment_config __user * allowed_attachments;
-/* WARNING: DO NOT EDIT, AUTO-GENERATED CODE - SEE TOP FOR INSTRUCTIONS */
- size_t custom_data_size;
- void __user * custom_data;
-};
-#define ADF_MAX_ATTACHMENTS (4096 / sizeof(struct adf_attachment_config))
-/* WARNING: DO NOT EDIT, AUTO-GENERATED CODE - SEE TOP FOR INSTRUCTIONS */
-struct adf_interface_data {
- char name[ADF_NAME_LEN];
- __u32 type;
- __u32 id;
-/* WARNING: DO NOT EDIT, AUTO-GENERATED CODE - SEE TOP FOR INSTRUCTIONS */
- __u32 flags;
- __u8 dpms_state;
- __u8 hotplug_detect;
- __u16 width_mm;
-/* WARNING: DO NOT EDIT, AUTO-GENERATED CODE - SEE TOP FOR INSTRUCTIONS */
- __u16 height_mm;
- struct drm_mode_modeinfo current_mode;
- size_t n_available_modes;
- struct drm_mode_modeinfo __user * available_modes;
-/* WARNING: DO NOT EDIT, AUTO-GENERATED CODE - SEE TOP FOR INSTRUCTIONS */
- size_t custom_data_size;
- void __user * custom_data;
-};
-#define ADF_MAX_MODES (4096 / sizeof(struct drm_mode_modeinfo))
-/* WARNING: DO NOT EDIT, AUTO-GENERATED CODE - SEE TOP FOR INSTRUCTIONS */
-struct adf_overlay_engine_data {
- char name[ADF_NAME_LEN];
- size_t n_supported_formats;
- __u32 __user * supported_formats;
-/* WARNING: DO NOT EDIT, AUTO-GENERATED CODE - SEE TOP FOR INSTRUCTIONS */
- size_t custom_data_size;
- void __user * custom_data;
-};
-#define ADF_MAX_SUPPORTED_FORMATS (4096 / sizeof(__u32))
-/* WARNING: DO NOT EDIT, AUTO-GENERATED CODE - SEE TOP FOR INSTRUCTIONS */
-#define ADF_IOCTL_TYPE 'D'
-#define ADF_IOCTL_NR_CUSTOM 128
-#define ADF_SET_EVENT _IOW(ADF_IOCTL_TYPE, 0, struct adf_set_event)
-#define ADF_BLANK _IOW(ADF_IOCTL_TYPE, 1, __u8)
-/* WARNING: DO NOT EDIT, AUTO-GENERATED CODE - SEE TOP FOR INSTRUCTIONS */
-#define ADF_POST_CONFIG _IOW(ADF_IOCTL_TYPE, 2, struct adf_post_config)
-#define ADF_SET_MODE _IOW(ADF_IOCTL_TYPE, 3, struct drm_mode_modeinfo)
-#define ADF_GET_DEVICE_DATA _IOR(ADF_IOCTL_TYPE, 4, struct adf_device_data)
-#define ADF_GET_INTERFACE_DATA _IOR(ADF_IOCTL_TYPE, 5, struct adf_interface_data)
-/* WARNING: DO NOT EDIT, AUTO-GENERATED CODE - SEE TOP FOR INSTRUCTIONS */
-#define ADF_GET_OVERLAY_ENGINE_DATA _IOR(ADF_IOCTL_TYPE, 6, struct adf_overlay_engine_data)
-#define ADF_SIMPLE_POST_CONFIG _IOW(ADF_IOCTL_TYPE, 7, struct adf_simple_post_config)
-#define ADF_SIMPLE_BUFFER_ALLOC _IOW(ADF_IOCTL_TYPE, 8, struct adf_simple_buffer_alloc)
-#define ADF_ATTACH _IOW(ADF_IOCTL_TYPE, 9, struct adf_attachment_config)
-/* WARNING: DO NOT EDIT, AUTO-GENERATED CODE - SEE TOP FOR INSTRUCTIONS */
-#define ADF_DETACH _IOW(ADF_IOCTL_TYPE, 10, struct adf_attachment_config)
-#define ADF_POST_CONFIG_V2 _IOW(ADF_IOCTL_TYPE, 11, struct adf_post_config_v2)
-#define ADF_SIMPLE_POST_CONFIG_V2 _IOW(ADF_IOCTL_TYPE, 12, struct adf_simple_post_config_v2)
-#endif
-/* WARNING: DO NOT EDIT, AUTO-GENERATED CODE - SEE TOP FOR INSTRUCTIONS */
-
diff --git a/deprecated-adf/libadf/original-kernel-headers/video/adf.h b/deprecated-adf/libadf/original-kernel-headers/video/adf.h
deleted file mode 100644
index 8293c1d..0000000
--- a/deprecated-adf/libadf/original-kernel-headers/video/adf.h
+++ /dev/null
@@ -1,386 +0,0 @@
-/*
- * Copyright (C) 2013 Google, Inc.
- *
- * This software is licensed under the terms of the GNU General Public
- * License version 2, as published by the Free Software Foundation, and
- * may be copied, distributed, and modified under those terms.
- *
- * This program is distributed in the hope that it will be useful,
- * but WITHOUT ANY WARRANTY; without even the implied warranty of
- * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
- * GNU General Public License for more details.
- *
- */
-
-#ifndef _UAPI_VIDEO_ADF_H_
-#define _UAPI_VIDEO_ADF_H_
-
-#include <linux/ioctl.h>
-#include <linux/types.h>
-
-#include <drm/drm_fourcc.h>
-#include <drm/drm_mode.h>
-
-#define ADF_NAME_LEN 32
-#define ADF_MAX_CUSTOM_DATA_SIZE 4096
-
-enum adf_interface_type {
- ADF_INTF_DSI = 0,
- ADF_INTF_eDP = 1,
- ADF_INTF_DPI = 2,
- ADF_INTF_VGA = 3,
- ADF_INTF_DVI = 4,
- ADF_INTF_HDMI = 5,
- ADF_INTF_MEMORY = 6,
- ADF_INTF_TYPE_DEVICE_CUSTOM = 128,
- ADF_INTF_TYPE_MAX = (~(__u32)0),
-};
-
-#define ADF_INTF_FLAG_PRIMARY (1 << 0)
-#define ADF_INTF_FLAG_EXTERNAL (1 << 1)
-
-enum adf_event_type {
- ADF_EVENT_VSYNC = 0,
- ADF_EVENT_HOTPLUG = 1,
- ADF_EVENT_DEVICE_CUSTOM = 128,
- ADF_EVENT_TYPE_MAX = 255,
-};
-
-enum adf_complete_fence_type {
- /* no fence */
- ADF_COMPLETE_FENCE_NONE = 0,
- /* fence fires when the configuration appears on the screen */
- ADF_COMPLETE_FENCE_PRESENT = 1,
- /* fence fires when the configuration leaves the screen */
- ADF_COMPLETE_FENCE_RELEASE = 2,
-};
-
-/**
- * struct adf_set_event - start or stop subscribing to ADF events
- *
- * @type: the type of event to (un)subscribe
- * @enabled: subscribe or unsubscribe
- *
- * After subscribing to an event, userspace may poll() the ADF object's fd
- * to wait for events or read() to consume the event's data.
- *
- * ADF reserves event types 0 to %ADF_EVENT_DEVICE_CUSTOM-1 for its own events.
- * Devices may use event types %ADF_EVENT_DEVICE_CUSTOM to %ADF_EVENT_TYPE_MAX-1
- * for driver-private events.
- */
-struct adf_set_event {
- __u8 type;
- __u8 enabled;
-};
-
-/**
- * struct adf_event - common header for ADF event data
- *
- * @type: event type
- * @length: total size of event data, header inclusive
- */
-struct adf_event {
- __u8 type;
- __u32 length;
-};
-
-/**
- * struct adf_vsync_event - ADF vsync event
- *
- * @base: event header (see &struct adf_event)
- * @timestamp: time of vsync event, in nanoseconds
- */
-struct adf_vsync_event {
- struct adf_event base;
- __aligned_u64 timestamp;
-};
-
-/**
- * struct adf_vsync_event - ADF display hotplug event
- *
- * @base: event header (see &struct adf_event)
- * @connected: whether a display is now connected to the interface
- */
-struct adf_hotplug_event {
- struct adf_event base;
- __u8 connected;
-};
-
-#define ADF_MAX_PLANES 4
-/**
- * struct adf_buffer_config - description of buffer displayed by adf_post_config
- *
- * @overlay_engine: id of the target overlay engine
- * @w: width of display region in pixels
- * @h: height of display region in pixels
- * @format: DRM-style fourcc, see drm_fourcc.h for standard formats
- * @fd: dma_buf fd for each plane
- * @offset: location of first pixel to scan out, in bytes
- * @pitch: stride (i.e. length of a scanline including padding) in bytes
- * @n_planes: number of planes in buffer
- * @acquire_fence: sync_fence fd which will clear when the buffer is
- * ready for display, or <0 if the buffer is already ready
- */
-struct adf_buffer_config {
- __u32 overlay_engine;
-
- __u32 w;
- __u32 h;
- __u32 format;
-
- __s32 fd[ADF_MAX_PLANES];
- __u32 offset[ADF_MAX_PLANES];
- __u32 pitch[ADF_MAX_PLANES];
- __u8 n_planes;
-
- __s32 acquire_fence;
-};
-#define ADF_MAX_BUFFERS (4096 / sizeof(struct adf_buffer_config))
-
-/**
- * struct adf_post_config - request to flip to a new set of buffers
- *
- * This request is equivalent to &struct adf_post_config_v2 with
- * @complete_fence_type = %ADF_COMPLETE_FENCE_RELEASE.
- *
- * @n_interfaces: number of interfaces targeted by the flip (input)
- * @interfaces: ids of interfaces targeted by the flip (input)
- * @n_bufs: number of buffers displayed (input)
- * @bufs: description of buffers displayed (input)
- * @custom_data_size: size of driver-private data (input)
- * @custom_data: driver-private data (input)
- * @complete_fence: sync_fence fd which will clear when this
- * configuration has left the screen (output)
- */
-struct adf_post_config {
- size_t n_interfaces;
- __u32 __user *interfaces;
-
- size_t n_bufs;
- struct adf_buffer_config __user *bufs;
-
- size_t custom_data_size;
- void __user *custom_data;
-
- __s32 complete_fence;
-};
-
-/**
- * struct adf_post_config_v2 - request to flip to a new set of buffers
- *
- * @n_interfaces: number of interfaces targeted by the flip (input)
- * @interfaces: ids of interfaces targeted by the flip (input)
- * @n_bufs: number of buffers displayed (input)
- * @bufs: description of buffers displayed (input)
- * @custom_data_size: size of driver-private data (input)
- * @custom_data: driver-private data (input)
- * @complete_fence_type: one of &enum adf_complete_fence_type describing what
- * fence to return (input)
- * @complete_fence: sync_fence fd which will fire at the time
- * requested by @complete_fence_type (output)
- */
-struct adf_post_config_v2 {
- __u32 n_interfaces;
- __u64 interfaces; /* __u32 * packed into __u64 */
-
- __u32 n_bufs;
- __u64 bufs; /* struct adf_buffer_config * packed into __u64 */
-
- __u64 custom_data_size;
- __u64 custom_data; /* void * packed into __u64 */
-
- __s32 complete_fence;
- __u8 complete_fence_type;
-};
-#define ADF_MAX_INTERFACES (4096 / sizeof(__u32))
-
-/**
- * struct adf_simple_buffer_allocate - request to allocate a "simple" buffer
- *
- * @w: width of buffer in pixels (input)
- * @h: height of buffer in pixels (input)
- * @format: DRM-style fourcc (input)
- *
- * @fd: dma_buf fd (output)
- * @offset: location of first pixel, in bytes (output)
- * @pitch: length of a scanline including padding, in bytes (output)
- *
- * Simple buffers are analogous to DRM's "dumb" buffers. They have a single
- * plane of linear RGB data which can be allocated and scanned out without
- * any driver-private ioctls or data.
- *
- * @format must be a standard RGB format defined in drm_fourcc.h.
- *
- * ADF clients must NOT assume that an interface can scan out a simple buffer
- * allocated by a different ADF interface, even if the two interfaces belong to
- * the same ADF device.
- */
-struct adf_simple_buffer_alloc {
- __u16 w;
- __u16 h;
- __u32 format;
-
- __s32 fd;
- __u32 offset;
- __u32 pitch;
-};
-
-/**
- * struct adf_simple_post_config - request to flip to a single buffer without
- * driver-private data
- *
- * This request is equivalent to &struct adf_simple_post_config_v2 with
- * @complete_fence_type = %ADF_COMPLETE_FENCE_RELEASE.
- *
- * @buf: description of buffer displayed (input)
- * @complete_fence: sync_fence fd which will clear when this buffer has left the
- * screen (output)
- */
-struct adf_simple_post_config {
- struct adf_buffer_config buf;
- __s32 complete_fence;
-};
-
-/**
- * struct adf_simple_post_config_v2 - request to flip to a single buffer without
- * driver-private data
- *
- * @buf: description of buffer displayed (input)
- * @complete_fence_type: one of &enum adf_complete_fence_type describing what
- * fence to return (input)
- * @complete_fence: sync_fence fd which will fire at the time
- * requested by @complete_fence_type (output)
- */
-struct adf_simple_post_config_v2 {
- struct adf_buffer_config buf;
- __s32 complete_fence;
- __u8 complete_fence_type;
-};
-
-/**
- * struct adf_attachment_config - description of attachment between an overlay
- * engine and an interface
- *
- * @overlay_engine: id of the overlay engine
- * @interface: id of the interface
- */
-struct adf_attachment_config {
- __u32 overlay_engine;
- __u32 interface;
-};
-
-/**
- * struct adf_device_data - describes a display device
- *
- * @name: display device's name
- * @n_attachments: the number of current attachments
- * @attachments: list of current attachments
- * @n_allowed_attachments: the number of allowed attachments
- * @allowed_attachments: list of allowed attachments
- * @custom_data_size: size of driver-private data
- * @custom_data: driver-private data
- */
-struct adf_device_data {
- char name[ADF_NAME_LEN];
-
- size_t n_attachments;
- struct adf_attachment_config __user *attachments;
-
- size_t n_allowed_attachments;
- struct adf_attachment_config __user *allowed_attachments;
-
- size_t custom_data_size;
- void __user *custom_data;
-};
-#define ADF_MAX_ATTACHMENTS (4096 / sizeof(struct adf_attachment_config))
-
-/**
- * struct adf_device_data - describes a display interface
- *
- * @name: display interface's name
- * @type: interface type (see enum @adf_interface_type)
- * @id: which interface of type @type;
- * e.g. interface DSI.1 -> @type=@ADF_INTF_TYPE_DSI, @id=1
- * @flags: informational flags (bitmask of %ADF_INTF_FLAG_* values)
- * @dpms_state: DPMS state (one of @DRM_MODE_DPMS_* defined in drm_mode.h)
- * @hotplug_detect: whether a display is plugged in
- * @width_mm: screen width in millimeters, or 0 if unknown
- * @height_mm: screen height in millimeters, or 0 if unknown
- * @current_mode: current display mode
- * @n_available_modes: the number of hardware display modes
- * @available_modes: list of hardware display modes
- * @custom_data_size: size of driver-private data
- * @custom_data: driver-private data
- */
-struct adf_interface_data {
- char name[ADF_NAME_LEN];
-
- __u32 type;
- __u32 id;
- /* e.g. type=ADF_INTF_TYPE_DSI, id=1 => DSI.1 */
- __u32 flags;
-
- __u8 dpms_state;
- __u8 hotplug_detect;
- __u16 width_mm;
- __u16 height_mm;
-
- struct drm_mode_modeinfo current_mode;
- size_t n_available_modes;
- struct drm_mode_modeinfo __user *available_modes;
-
- size_t custom_data_size;
- void __user *custom_data;
-};
-#define ADF_MAX_MODES (4096 / sizeof(struct drm_mode_modeinfo))
-
-/**
- * struct adf_overlay_engine_data - describes an overlay engine
- *
- * @name: overlay engine's name
- * @n_supported_formats: number of supported formats
- * @supported_formats: list of supported formats
- * @custom_data_size: size of driver-private data
- * @custom_data: driver-private data
- */
-struct adf_overlay_engine_data {
- char name[ADF_NAME_LEN];
-
- size_t n_supported_formats;
- __u32 __user *supported_formats;
-
- size_t custom_data_size;
- void __user *custom_data;
-};
-#define ADF_MAX_SUPPORTED_FORMATS (4096 / sizeof(__u32))
-
-#define ADF_IOCTL_TYPE 'D'
-#define ADF_IOCTL_NR_CUSTOM 128
-
-#define ADF_SET_EVENT _IOW(ADF_IOCTL_TYPE, 0, struct adf_set_event)
-#define ADF_BLANK _IOW(ADF_IOCTL_TYPE, 1, __u8)
-#define ADF_POST_CONFIG _IOW(ADF_IOCTL_TYPE, 2, struct adf_post_config)
-#define ADF_SET_MODE _IOW(ADF_IOCTL_TYPE, 3, \
- struct drm_mode_modeinfo)
-#define ADF_GET_DEVICE_DATA _IOR(ADF_IOCTL_TYPE, 4, struct adf_device_data)
-#define ADF_GET_INTERFACE_DATA _IOR(ADF_IOCTL_TYPE, 5, \
- struct adf_interface_data)
-#define ADF_GET_OVERLAY_ENGINE_DATA \
- _IOR(ADF_IOCTL_TYPE, 6, \
- struct adf_overlay_engine_data)
-#define ADF_SIMPLE_POST_CONFIG _IOW(ADF_IOCTL_TYPE, 7, \
- struct adf_simple_post_config)
-#define ADF_SIMPLE_BUFFER_ALLOC _IOW(ADF_IOCTL_TYPE, 8, \
- struct adf_simple_buffer_alloc)
-#define ADF_ATTACH _IOW(ADF_IOCTL_TYPE, 9, \
- struct adf_attachment_config)
-#define ADF_DETACH _IOW(ADF_IOCTL_TYPE, 10, \
- struct adf_attachment_config)
-
-#define ADF_POST_CONFIG_V2 _IOW(ADF_IOCTL_TYPE, 11, \
- struct adf_post_config_v2)
-#define ADF_SIMPLE_POST_CONFIG_V2 \
- _IOW(ADF_IOCTL_TYPE, 12, \
- struct adf_simple_post_config_v2)
-
-#endif /* _UAPI_VIDEO_ADF_H_ */
diff --git a/deprecated-adf/libadf/tests/adf_test.cpp b/deprecated-adf/libadf/tests/adf_test.cpp
deleted file mode 100644
index 82a91f4..0000000
--- a/deprecated-adf/libadf/tests/adf_test.cpp
+++ /dev/null
@@ -1,403 +0,0 @@
-/*
- * Copyright (C) 2013 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.
- */
-
-#include <errno.h>
-#include <fcntl.h>
-
-#include <adf/adf.h>
-#include <gtest/gtest.h>
-#include <sys/mman.h>
-#include <sync/sync.h>
-
-class AdfTest : public testing::Test {
-public:
- AdfTest() : intf_id(0), intf(-1), eng_id(0), eng(-1) { }
-
- virtual void SetUp() {
- int err = adf_device_open(dev_id, O_RDWR, &dev);
- ASSERT_GE(err, 0) << "opening ADF device " << dev_id <<
- " failed: " << strerror(-err);
-
- err = adf_find_simple_post_configuration(&dev, fmt8888, n_fmt8888,
- &intf_id, &eng_id);
- ASSERT_GE(err, 0) << "finding ADF configuration failed: " <<
- strerror(-err);
-
- intf = adf_interface_open(&dev, intf_id, O_RDWR);
- ASSERT_GE(intf, 0) << "opening ADF interface " << dev_id << "." <<
- intf_id << " failed: " << strerror(-intf);
-
- eng = adf_overlay_engine_open(&dev, eng_id, O_RDWR);
- ASSERT_GE(eng, 0) << "opening ADF overlay engine " << dev_id << "." <<
- eng_id << " failed: " << strerror(-eng);
- }
-
- virtual void TearDown() {
- if (eng >= 0)
- close(eng);
- if (intf >= 0)
- close(intf);
- adf_device_close(&dev);
- }
-
- void get8888Format(uint32_t &fmt, char fmt_str[ADF_FORMAT_STR_SIZE]) {
- adf_overlay_engine_data data;
- int err = adf_get_overlay_engine_data(eng, &data);
- ASSERT_GE(err, 0) << "getting ADF overlay engine data failed: " <<
- strerror(-err);
-
- for (size_t i = 0; i < data.n_supported_formats; i++) {
- for (size_t j = 0; j < n_fmt8888; j++) {
- if (data.supported_formats[i] == fmt8888[j]) {
- fmt = data.supported_formats[i];
- adf_format_str(fmt, fmt_str);
- adf_free_overlay_engine_data(&data);
- return;
- }
- }
- }
-
- adf_free_overlay_engine_data(&data);
- FAIL(); /* this should never happen */
- }
-
- /* various helpers to call ADF and die on failure */
-
- void getInterfaceData(adf_interface_data &data) {
- int err = adf_get_interface_data(intf, &data);
- ASSERT_GE(err, 0) << "getting ADF interface data failed: " <<
- strerror(-err);
- }
-
- void getCurrentMode(uint32_t &w, uint32_t &h) {
- adf_interface_data data;
- ASSERT_NO_FATAL_FAILURE(getInterfaceData(data));
- w = data.current_mode.hdisplay;
- h = data.current_mode.vdisplay;
- adf_free_interface_data(&data);
- }
-
- void blank(uint8_t mode) {
- int err = adf_interface_blank(intf, mode);
- ASSERT_FALSE(err < 0 && err != -EBUSY) <<
- "unblanking interface failed: " << strerror(-err);
- }
-
- void attach() {
- int err = adf_device_attach(&dev, eng_id, intf_id);
- ASSERT_FALSE(err < 0 && err != -EALREADY) <<
- "attaching overlay engine " << eng_id << " to interface " <<
- intf_id << " failed: " << strerror(-err);
- }
-
- void detach() {
- int err = adf_device_detach(&dev, eng_id, intf_id);
- ASSERT_FALSE(err < 0 && err != -EINVAL) <<
- "detaching overlay engine " << eng_id << " from interface " <<
- intf_id << " failed: " << strerror(-err);
- }
-
- void readVsyncTimestamp(uint64_t ×tamp) {
- adf_event *event;
- int err = adf_read_event(intf, &event);
- ASSERT_GE(err, 0) << "reading ADF event failed: " << strerror(-err);
-
- ASSERT_EQ(ADF_EVENT_VSYNC, event->type);
- ASSERT_EQ(sizeof(adf_vsync_event), event->length);
-
- adf_vsync_event *vsync_event =
- reinterpret_cast<adf_vsync_event *>(event);
- timestamp = vsync_event->timestamp;
- free(event);
- }
-
- void drawCheckerboard(uint32_t &w, uint32_t &h, uint32_t &format,
- char format_str[ADF_FORMAT_STR_SIZE], int &buf_fd, uint32_t &offset,
- uint32_t &pitch) {
- ASSERT_NO_FATAL_FAILURE(getCurrentMode(w, h));
- ASSERT_NO_FATAL_FAILURE(get8888Format(format, format_str));
-
- buf_fd = adf_interface_simple_buffer_alloc(intf, w, h, format, &offset,
- &pitch);
- ASSERT_GE(buf_fd, 0) << "allocating " << w << "x" << h << " " <<
- format_str << " buffer failed: " << strerror(-buf_fd);
- EXPECT_GE(pitch, w * 4);
-
- void *mapped = mmap(NULL, pitch * h, PROT_WRITE, MAP_SHARED, buf_fd,
- offset);
- ASSERT_NE(mapped, MAP_FAILED) << "mapping " << w << "x" << h << " " <<
- format_str << " buffer failed: " << strerror(-errno);
-
- uint8_t *buf8 = static_cast<uint8_t *>(mapped);
- for (uint32_t y = 0; y < h / 2; y++) {
- uint32_t *scanline = reinterpret_cast<uint32_t *>(buf8 + y * pitch);
- for (uint32_t x = 0; x < w / 2; x++)
- scanline[x] = 0xFF0000FF;
- for (uint32_t x = w / 2; x < w; x++)
- scanline[x] = 0xFF00FFFF;
- }
- for (uint32_t y = h / 2; y < h; y++) {
- uint32_t *scanline = reinterpret_cast<uint32_t *>(buf8 + y * pitch);
- for (uint32_t x = 0; x < w / 2; x++)
- scanline[x] = 0xFFFF00FF;
- for (uint32_t x = w / 2; x < w; x++)
- scanline[x] = 0xFFFFFFFF;
- }
-
- munmap(mapped, pitch * h);
- }
-
-protected:
- adf_device dev;
- adf_id_t intf_id;
- int intf;
- adf_id_t eng_id;
- int eng;
-
-private:
- const static adf_id_t dev_id;
- const static __u32 fmt8888[];
- const static size_t n_fmt8888;
-};
-
-const adf_id_t AdfTest::dev_id = 0;
-
-const __u32 AdfTest::fmt8888[] = {
- DRM_FORMAT_XRGB8888,
- DRM_FORMAT_XBGR8888,
- DRM_FORMAT_RGBX8888,
- DRM_FORMAT_BGRX8888,
- DRM_FORMAT_ARGB8888,
- DRM_FORMAT_ABGR8888,
- DRM_FORMAT_RGBA8888,
- DRM_FORMAT_BGRA8888
-};
-const size_t AdfTest::n_fmt8888 = sizeof(fmt8888) / sizeof(fmt8888[0]);
-
-TEST(adf, devices) {
- adf_id_t *devs = nullptr;
- ssize_t n_devs = adf_devices(&devs);
- free(devs);
-
- ASSERT_GE(n_devs, 0) << "enumerating ADF devices failed: " <<
- strerror(-n_devs);
- ASSERT_TRUE(devs != NULL);
-}
-
-TEST_F(AdfTest, device_data) {
- adf_device_data data;
- int err = adf_get_device_data(&dev, &data);
- ASSERT_GE(err, 0) << "getting ADF device data failed: " << strerror(-err);
-
- EXPECT_LT(data.n_attachments, ADF_MAX_ATTACHMENTS);
- EXPECT_GT(data.n_allowed_attachments, 0U);
- EXPECT_LT(data.n_allowed_attachments, ADF_MAX_ATTACHMENTS);
- EXPECT_LT(data.custom_data_size, (size_t)ADF_MAX_CUSTOM_DATA_SIZE);
- adf_free_device_data(&data);
-}
-
-TEST_F(AdfTest, interface_data) {
- adf_interface_data data;
- ASSERT_NO_FATAL_FAILURE(getInterfaceData(data));
-
- EXPECT_LT(data.type, ADF_INTF_TYPE_MAX);
- EXPECT_LE(data.dpms_state, DRM_MODE_DPMS_OFF);
- EXPECT_EQ(1, data.hotplug_detect);
- EXPECT_GT(data.n_available_modes, 0U);
- EXPECT_LT(data.custom_data_size, (size_t)ADF_MAX_CUSTOM_DATA_SIZE);
- adf_free_interface_data(&data);
-}
-
-TEST_F(AdfTest, overlay_engine_data) {
- adf_overlay_engine_data data;
- int err = adf_get_overlay_engine_data(eng, &data);
- ASSERT_GE(err, 0) << "getting ADF overlay engine failed: " <<
- strerror(-err);
-
- EXPECT_GT(data.n_supported_formats, 0U);
- EXPECT_LT(data.n_supported_formats, ADF_MAX_SUPPORTED_FORMATS);
- EXPECT_LT(data.custom_data_size, (size_t)ADF_MAX_CUSTOM_DATA_SIZE);
- adf_free_overlay_engine_data(&data);
-}
-
-TEST_F(AdfTest, blank) {
- int err = adf_interface_blank(intf, (uint8_t)-1);
- EXPECT_EQ(-EINVAL, err) << "setting bogus DPMS mode should have failed";
-
- err = adf_interface_blank(eng, DRM_MODE_DPMS_OFF);
- EXPECT_EQ(-EINVAL, err) << "blanking overlay engine should have failed";
-
- ASSERT_NO_FATAL_FAILURE(blank(DRM_MODE_DPMS_OFF));
- err = adf_interface_blank(intf, DRM_MODE_DPMS_OFF);
- EXPECT_EQ(-EBUSY, err) << "blanking interface twice should have failed";
-
- ASSERT_NO_FATAL_FAILURE(blank(DRM_MODE_DPMS_ON));
- err = adf_interface_blank(intf, DRM_MODE_DPMS_ON);
- EXPECT_EQ(-EBUSY, err) << "unblanking interface twice should have failed";
-
- adf_interface_data data;
- ASSERT_NO_FATAL_FAILURE(getInterfaceData(data));
- EXPECT_EQ(DRM_MODE_DPMS_ON, data.dpms_state);
- adf_free_interface_data(&data);
-}
-
-TEST_F(AdfTest, event) {
- int err = adf_set_event(intf, ADF_EVENT_TYPE_MAX, true);
- EXPECT_EQ(-EINVAL, err) << "enabling bogus ADF event should have failed";
-
- err = adf_set_event(intf, ADF_EVENT_TYPE_MAX, false);
- EXPECT_EQ(-EINVAL, err) << "disabling bogus ADF event should have failed";
-
- err = adf_set_event(intf, ADF_EVENT_VSYNC, true);
- ASSERT_GE(err, 0) << "enabling vsync event failed: " << strerror(-err);
-
- err = adf_set_event(intf, ADF_EVENT_VSYNC, true);
- EXPECT_EQ(-EALREADY, err) <<
- "enabling vsync event twice should have failed";
-
- ASSERT_NO_FATAL_FAILURE(blank(DRM_MODE_DPMS_ON));
-
- uint64_t timestamp1, timestamp2;
- ASSERT_NO_FATAL_FAILURE(readVsyncTimestamp(timestamp1));
- ASSERT_NO_FATAL_FAILURE(readVsyncTimestamp(timestamp2));
- EXPECT_GT(timestamp2, timestamp1);
-
- err = adf_set_event(intf, ADF_EVENT_VSYNC, false);
- EXPECT_GE(err, 0) << "disabling vsync event failed: " << strerror(-err);
-
- err = adf_set_event(intf, ADF_EVENT_VSYNC, false);
- EXPECT_EQ(-EALREADY, err) <<
- "disabling vsync event twice should have failed";
-}
-
-TEST_F(AdfTest, attach) {
- ASSERT_NO_FATAL_FAILURE(attach());
- int err = adf_device_attach(&dev, eng_id, intf_id);
- EXPECT_EQ(-EALREADY, err) << "attaching overlay engine " << eng_id <<
- " to interface " << intf_id << " twice should have failed";
-
- ASSERT_NO_FATAL_FAILURE(detach());
- err = adf_device_detach(&dev, eng_id, intf_id);
- EXPECT_EQ(-EINVAL, err) << "detaching overlay engine " << eng_id <<
- " from interface " << intf_id << " twice should have failed";
-
- err = adf_device_attach(&dev, eng_id, ADF_MAX_INTERFACES);
- EXPECT_EQ(-EINVAL, err) << "attaching overlay engine " << eng_id <<
- " to bogus interface should have failed";
-
- err = adf_device_detach(&dev, eng_id, ADF_MAX_INTERFACES);
- EXPECT_EQ(-EINVAL, err) << "detaching overlay engine " << eng_id <<
- " from bogus interface should have failed";
-}
-
-TEST_F(AdfTest, simple_buffer_alloc) {
- uint32_t w = 0, h = 0;
- ASSERT_NO_FATAL_FAILURE(getCurrentMode(w, h));
-
- uint32_t format;
- char format_str[ADF_FORMAT_STR_SIZE];
- ASSERT_NO_FATAL_FAILURE(get8888Format(format, format_str));
-
- uint32_t offset;
- uint32_t pitch;
- int buf_fd = adf_interface_simple_buffer_alloc(intf, w, h, format, &offset,
- &pitch);
- EXPECT_GE(buf_fd, 0) << "allocating " << w << "x" << h << " " <<
- format_str << " buffer failed: " << strerror(-buf_fd);
- EXPECT_GE(pitch, w * 4);
- close(buf_fd);
-
- buf_fd = adf_interface_simple_buffer_alloc(intf, w, h, 0xDEADBEEF, &offset,
- &pitch);
- /* n.b.: ADF only allows simple buffers with built-in RGB formats,
- so this should fail even if a driver supports custom format 0xDEADBEEF */
- EXPECT_EQ(-EINVAL, buf_fd) <<
- "allocating buffer with bogus format should have failed";
-}
-
-TEST_F(AdfTest, simple_buffer) {
- int buf_fd;
- uint32_t w, h, format, offset, pitch;
- char format_str[ADF_FORMAT_STR_SIZE];
- ASSERT_NO_FATAL_FAILURE(drawCheckerboard(w, h, format, format_str,
- buf_fd, offset, pitch));
-
- ASSERT_NO_FATAL_FAILURE(attach());
- ASSERT_NO_FATAL_FAILURE(blank(DRM_MODE_DPMS_ON));
-
- int release_fence = adf_interface_simple_post(intf, eng_id, w, h, format,
- buf_fd, offset, pitch, -1);
- close(buf_fd);
- ASSERT_GE(release_fence, 0) << "posting " << w << "x" << h << " " <<
- format_str << " buffer failed: " << strerror(-release_fence);
- close(release_fence);
-}
-
-TEST_F(AdfTest, simple_buffer_v2) {
- int buf_fd;
- uint32_t w, h, format, offset, pitch;
- char format_str[ADF_FORMAT_STR_SIZE];
- ASSERT_NO_FATAL_FAILURE(drawCheckerboard(w, h, format, format_str,
- buf_fd, offset, pitch));
-
- ASSERT_NO_FATAL_FAILURE(attach());
- ASSERT_NO_FATAL_FAILURE(blank(DRM_MODE_DPMS_ON));
-
- int config_1_release;
- int err = adf_interface_simple_post_v2(intf, eng_id, w, h,
- format, buf_fd, offset, pitch, -1, ADF_COMPLETE_FENCE_RELEASE,
- &config_1_release);
- if (err == -ENOTTY) {
- GTEST_LOG_(INFO) << "ADF_SIMPLE_POST_CONFIG_V2 not supported on this kernel";
- return;
- }
- ASSERT_GE(err, 0) << "posting " << w << "x" << h << " " <<
- format_str << " buffer failed: " << strerror(-err);
-
- err = sync_wait(config_1_release, 1000);
- ASSERT_EQ(-1, err) <<
- "waiting for config 1's release fence should not have suceeded";
- ASSERT_EQ(ETIME, errno) <<
- "config 1's release fence should have timed out, but failed instead: " <<
- strerror(errno);
-
- int config_2_present;
- err = adf_interface_simple_post_v2(intf, eng_id, w, h,
- format, buf_fd, offset, pitch, -1, ADF_COMPLETE_FENCE_PRESENT,
- &config_2_present);
- ASSERT_GE(err, 0) << "posting " << w << "x" << h << " " <<
- format_str << " buffer failed: " << strerror(-err);
-
- err = sync_wait(config_2_present, 1000);
- ASSERT_EQ(0, err) <<
- "waiting for config 2's present fence failed: " << strerror(errno);
- err = sync_wait(config_1_release, 0);
- ASSERT_EQ(0, err) <<
- "waiting for config 1's release fence failed: " << strerror(errno);
- close(config_1_release);
- close(config_2_present);
-
- int config_3_no_fence;
- err = adf_interface_simple_post_v2(intf, eng_id, w, h,
- format, buf_fd, offset, pitch, -1, ADF_COMPLETE_FENCE_NONE,
- &config_3_no_fence);
- ASSERT_GE(err, 0) << "posting " << w << "x" << h << " " <<
- format_str << " buffer failed: " << strerror(-err);
- ASSERT_EQ(-1, config_3_no_fence) <<
- "fence returned even though the fence type was ADF_COMPLETE_FENCE_NONE";
-
- close(buf_fd);
-}
diff --git a/deprecated-adf/libadfhwc/Android.bp b/deprecated-adf/libadfhwc/Android.bp
deleted file mode 100644
index 57a8d76..0000000
--- a/deprecated-adf/libadfhwc/Android.bp
+++ /dev/null
@@ -1,29 +0,0 @@
-// Copyright (C) 2013 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.
-
-cc_library_static {
- name: "libadfhwc",
- srcs: ["adfhwc.cpp"],
- static_libs: [
- "libadf",
- "liblog",
- "libutils",
- ],
- cflags: [
- "-DLOG_TAG=\"adfhwc\"",
- "-Werror",
- ],
- local_include_dirs: ["include"],
- export_include_dirs: ["include"],
-}
diff --git a/deprecated-adf/libadfhwc/adfhwc.cpp b/deprecated-adf/libadfhwc/adfhwc.cpp
deleted file mode 100644
index 63c0f75..0000000
--- a/deprecated-adf/libadfhwc/adfhwc.cpp
+++ /dev/null
@@ -1,376 +0,0 @@
-/*
- * Copyright (C) 2013 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.
- */
-
-#include <fcntl.h>
-#include <malloc.h>
-#include <poll.h>
-#include <pthread.h>
-#include <sys/resource.h>
-
-#include <log/log.h>
-#include <utils/Vector.h>
-
-#include <adf/adf.h>
-#include <adfhwc/adfhwc.h>
-
-struct adf_hwc_helper {
- adf_hwc_event_callbacks const *event_cb;
- void *event_cb_data;
-
- pthread_t event_thread;
-
- android::Vector<int> intf_fds;
- android::Vector<drm_mode_modeinfo> display_configs;
-};
-
-template<typename T> inline T min(T a, T b) { return (a < b) ? a : b; }
-
-int adf_eventControl(struct adf_hwc_helper *dev, int disp, int event,
- int enabled)
-{
- if (enabled != !!enabled)
- return -EINVAL;
-
- if ((size_t)disp >= dev->intf_fds.size())
- return -EINVAL;
-
- switch (event) {
- case HWC_EVENT_VSYNC:
- return adf_set_event(dev->intf_fds[disp], ADF_EVENT_VSYNC, enabled);
- }
-
- return -EINVAL;
-}
-
-static inline int32_t dpi(uint16_t res, uint16_t size_mm)
-{
- if (size_mm)
- return 1000 * (res * 25.4f) / size_mm;
- return 0;
-}
-
-int adf_blank(struct adf_hwc_helper *dev, int disp, int blank)
-{
- if ((size_t)disp >= dev->intf_fds.size())
- return -EINVAL;
-
- uint8_t dpms_mode = blank ? DRM_MODE_DPMS_OFF : DRM_MODE_DPMS_ON;
- return adf_interface_blank(dev->intf_fds[disp], dpms_mode);
-}
-
-int adf_query_display_types_supported(struct adf_hwc_helper *dev, int *value)
-{
- *value = 0;
- if (dev->intf_fds.size() > 0)
- *value |= HWC_DISPLAY_PRIMARY_BIT;
- if (dev->intf_fds.size() > 1)
- *value |= HWC_DISPLAY_EXTERNAL_BIT;
-
- return 0;
-}
-
-int adf_getDisplayConfigs(struct adf_hwc_helper *dev, int disp,
- uint32_t *configs, size_t *numConfigs)
-{
- if ((size_t)disp >= dev->intf_fds.size())
- return -EINVAL;
-
- adf_interface_data data;
- int err = adf_get_interface_data(dev->intf_fds[disp], &data);
- if (err < 0) {
- ALOGE("failed to get ADF interface data: %s", strerror(err));
- return err;
- }
-
- if (!data.hotplug_detect)
- return -ENODEV;
-
- android::Vector<drm_mode_modeinfo *> unique_configs;
- unique_configs.push_back(&data.current_mode);
- for (size_t i = 0; i < data.n_available_modes; i++)
- if (memcmp(&data.available_modes[i], &data.current_mode,
- sizeof(data.current_mode)))
- unique_configs.push_back(&data.available_modes[i]);
-
- for (size_t i = 0; i < min(*numConfigs, unique_configs.size()); i++) {
- configs[i] = dev->display_configs.size();
- dev->display_configs.push_back(*unique_configs[i]);
- }
- *numConfigs = unique_configs.size();
-
- adf_free_interface_data(&data);
- return 0;
-}
-
-static int32_t adf_display_attribute(const adf_interface_data &data,
- const drm_mode_modeinfo &mode, const uint32_t attribute)
-{
- switch (attribute) {
- case HWC_DISPLAY_VSYNC_PERIOD:
- if (mode.vrefresh)
- return 1000000000 / mode.vrefresh;
- return 0;
-
- case HWC_DISPLAY_WIDTH:
- return mode.hdisplay;
-
- case HWC_DISPLAY_HEIGHT:
- return mode.vdisplay;
-
- case HWC_DISPLAY_DPI_X:
- return dpi(mode.hdisplay, data.width_mm);
-
- case HWC_DISPLAY_DPI_Y:
- return dpi(mode.vdisplay, data.height_mm);
-
- default:
- ALOGE("unknown display attribute %u", attribute);
- return -EINVAL;
- }
-}
-
-int adf_getDisplayAttributes(struct adf_hwc_helper *dev, int disp,
- uint32_t config, const uint32_t *attributes, int32_t *values)
-{
- if ((size_t)disp >= dev->intf_fds.size())
- return -EINVAL;
-
- if (config >= dev->display_configs.size())
- return -EINVAL;
-
- adf_interface_data data;
- int err = adf_get_interface_data(dev->intf_fds[disp], &data);
- if (err < 0) {
- ALOGE("failed to get ADF interface data: %s", strerror(err));
- return err;
- }
-
- for (int i = 0; attributes[i] != HWC_DISPLAY_NO_ATTRIBUTE; i++)
- values[i] = adf_display_attribute(data, dev->display_configs[config],
- attributes[i]);
-
- adf_free_interface_data(&data);
- return 0;
-}
-
-static int32_t adf_display_attribute_hwc2(const adf_interface_data &data,
- const drm_mode_modeinfo &mode, const uint32_t attribute)
-{
- switch (attribute) {
- case HWC2_ATTRIBUTE_VSYNC_PERIOD:
- if (mode.vrefresh)
- return 1000000000 / mode.vrefresh;
- return 0;
-
- case HWC2_ATTRIBUTE_WIDTH:
- return mode.hdisplay;
-
- case HWC2_ATTRIBUTE_HEIGHT:
- return mode.vdisplay;
-
- case HWC2_ATTRIBUTE_DPI_X:
- return dpi(mode.hdisplay, data.width_mm);
-
- case HWC2_ATTRIBUTE_DPI_Y:
- return dpi(mode.vdisplay, data.height_mm);
-
- default:
- ALOGE("unknown display attribute %u", attribute);
- return -EINVAL;
- }
-}
-
-int adf_getDisplayAttributes_hwc2(struct adf_hwc_helper *dev, int disp,
- uint32_t config, const uint32_t *attributes, int32_t *values)
-{
- if ((size_t)disp >= dev->intf_fds.size())
- return -EINVAL;
-
- if (config >= dev->display_configs.size())
- return -EINVAL;
-
- adf_interface_data data;
- int err = adf_get_interface_data(dev->intf_fds[disp], &data);
- if (err < 0) {
- ALOGE("failed to get ADF interface data: %s", strerror(err));
- return err;
- }
-
- for (int i = 0; attributes[i] != HWC2_ATTRIBUTE_INVALID; i++)
- values[i] = adf_display_attribute_hwc2(data,
- dev->display_configs[config], attributes[i]);
-
- adf_free_interface_data(&data);
- return 0;
-}
-
-int adf_set_active_config_hwc2(struct adf_hwc_helper *dev, int disp,
- uint32_t config)
-{
- if ((size_t)disp >= dev->intf_fds.size())
- return -EINVAL;
-
- if (config >= dev->display_configs.size())
- return -EINVAL;
-
- struct drm_mode_modeinfo mode = dev->display_configs[config];
-
- return adf_interface_set_mode(dev->intf_fds[disp], &mode);
-}
-
-static void handle_adf_event(struct adf_hwc_helper *dev, int disp)
-{
- adf_event *event;
- int err = adf_read_event(dev->intf_fds[disp], &event);
- if (err < 0) {
- ALOGE("error reading event from display %d: %s", disp, strerror(err));
- return;
- }
-
- void *vsync_temp;
- adf_vsync_event *vsync;
- adf_hotplug_event *hotplug;
-
- switch (event->type) {
- case ADF_EVENT_VSYNC:
- vsync_temp = event;
- vsync = static_cast<adf_vsync_event *>(vsync_temp);
- // casting directly to adf_vsync_event * makes g++ warn about
- // potential alignment issues that don't apply here
- dev->event_cb->vsync(dev->event_cb_data, disp, vsync->timestamp);
- break;
- case ADF_EVENT_HOTPLUG:
- hotplug = reinterpret_cast<adf_hotplug_event *>(event);
- dev->event_cb->hotplug(dev->event_cb_data, disp, hotplug->connected);
- break;
- default:
- if (event->type < ADF_EVENT_DEVICE_CUSTOM)
- ALOGW("unrecognized event type %u", event->type);
- else if (!dev->event_cb || !dev->event_cb->custom_event)
- ALOGW("unhandled event type %u", event->type);
- else
- dev->event_cb->custom_event(dev->event_cb_data, disp, event);
- }
- free(event);
-}
-
-static void *adf_event_thread(void *data)
-{
- adf_hwc_helper *dev = static_cast<adf_hwc_helper *>(data);
-
- setpriority(PRIO_PROCESS, 0, HAL_PRIORITY_URGENT_DISPLAY);
-
- struct sigaction action = { };
- sigemptyset(&action.sa_mask);
- action.sa_flags = 0;
- action.sa_handler = [](int) { pthread_exit(0); };
-
- if (sigaction(SIGUSR2, &action, NULL) < 0) {
- ALOGE("failed to set thread exit action %s", strerror(errno));
- return NULL;
- }
-
- sigset_t signal_set;
- sigemptyset(&signal_set);
- sigaddset(&signal_set, SIGUSR2);
-
- pthread_sigmask(SIG_UNBLOCK, &signal_set, NULL);
-
- pollfd fds[dev->intf_fds.size()];
- for (size_t i = 0; i < dev->intf_fds.size(); i++) {
- fds[i].fd = dev->intf_fds[i];
- fds[i].events = POLLIN | POLLPRI;
- }
-
- while (true) {
- if (TEMP_FAILURE_RETRY(poll(fds, dev->intf_fds.size(), -1)) < 0) {
- ALOGE("error in event thread: %s", strerror(errno));
- break;
- }
-
- for (size_t i = 0; i < dev->intf_fds.size(); i++)
- if (fds[i].revents & (POLLIN | POLLPRI))
- handle_adf_event(dev, i);
- }
-
- return NULL;
-}
-
-int adf_hwc_open(int *intf_fds, size_t n_intfs,
- const struct adf_hwc_event_callbacks *event_cb, void *event_cb_data,
- struct adf_hwc_helper **dev)
-{
- if (!n_intfs)
- return -EINVAL;
-
- adf_hwc_helper *dev_ret = new adf_hwc_helper;
- dev_ret->event_cb = event_cb;
- dev_ret->event_cb_data = event_cb_data;
-
- int ret;
-
- for (size_t i = 0; i < n_intfs; i++) {
- int dup_intf_fd = dup(intf_fds[i]);
- if (dup_intf_fd < 0) {
- ALOGE("failed to dup interface fd: %s", strerror(errno));
- ret = -errno;
- goto err;
- }
-
- dev_ret->intf_fds.push_back(dup_intf_fd);
-
- ret = adf_set_event(dup_intf_fd, ADF_EVENT_HOTPLUG, 1);
- if (ret < 0 && ret != -EINVAL) {
- ALOGE("failed to enable hotplug event on display %zu: %s",
- i, strerror(errno));
- goto err;
- }
- }
-
- sigset_t signal_set;
- sigemptyset(&signal_set);
- sigaddset(&signal_set, SIGUSR2);
-
- pthread_sigmask(SIG_BLOCK, &signal_set, NULL);
-
- ret = pthread_create(&dev_ret->event_thread, NULL, adf_event_thread,
- dev_ret);
- if (ret) {
- ALOGE("failed to create event thread: %s", strerror(ret));
- goto err;
- }
-
- *dev = dev_ret;
- return 0;
-
-err:
- for (size_t i = 0; i < dev_ret->intf_fds.size(); i++)
- close(dev_ret->intf_fds[i]);
-
- delete dev_ret;
- return ret;
-}
-
-void adf_hwc_close(struct adf_hwc_helper *dev)
-{
- pthread_kill(dev->event_thread, SIGUSR2);
- pthread_join(dev->event_thread, NULL);
-
- for (size_t i = 0; i < dev->intf_fds.size(); i++)
- close(dev->intf_fds[i]);
-
- delete dev;
-}
diff --git a/deprecated-adf/libadfhwc/include/adfhwc/adfhwc.h b/deprecated-adf/libadfhwc/include/adfhwc/adfhwc.h
deleted file mode 100644
index 4f70925..0000000
--- a/deprecated-adf/libadfhwc/include/adfhwc/adfhwc.h
+++ /dev/null
@@ -1,140 +0,0 @@
-/*
- * Copyright (C) 2013 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.
- */
-
-#ifndef _LIBADFHWC_ADFHWC_H_
-#define _LIBADFHWC_ADFHWC_H_
-
-#include <stdbool.h>
-#include <stdint.h>
-#include <sys/cdefs.h>
-#include <video/adf.h>
-
-#include <hardware/hwcomposer.h>
-#include <hardware/hwcomposer2.h>
-
-struct adf_hwc_helper;
-
-struct adf_hwc_event_callbacks {
- /**
- * Called on vsync (required)
- */
- void (*vsync)(void *data, int disp, uint64_t timestamp);
- /**
- * Called on hotplug (required)
- */
- void (*hotplug)(void *data, int disp, bool connected);
- /**
- * Called on hardware-custom ADF events (optional)
- */
- void (*custom_event)(void *data, int disp, struct adf_event *event);
-};
-
-/**
- * Converts HAL pixel formats to equivalent ADF/DRM format FourCCs.
- */
-static inline uint32_t adf_fourcc_for_hal_pixel_format(int format)
-{
- switch (format) {
- case HAL_PIXEL_FORMAT_RGBA_8888:
- return DRM_FORMAT_RGBA8888;
- case HAL_PIXEL_FORMAT_RGBX_8888:
- return DRM_FORMAT_RGBX8888;
- case HAL_PIXEL_FORMAT_RGB_888:
- return DRM_FORMAT_RGB888;
- case HAL_PIXEL_FORMAT_RGB_565:
- return DRM_FORMAT_RGB565;
- case HAL_PIXEL_FORMAT_BGRA_8888:
- return DRM_FORMAT_BGRA8888;
- case HAL_PIXEL_FORMAT_YV12:
- return DRM_FORMAT_YVU420;
- case HAL_PIXEL_FORMAT_YCbCr_422_SP:
- return DRM_FORMAT_NV16;
- case HAL_PIXEL_FORMAT_YCrCb_420_SP:
- return DRM_FORMAT_NV21;
- case HAL_PIXEL_FORMAT_YCbCr_422_I:
- return DRM_FORMAT_YUYV;
- default:
- return 0;
- }
-}
-
-/**
- * Converts HAL display types to equivalent ADF interface flags.
- */
-static inline uint32_t adf_hwc_interface_flag_for_disp(int disp)
-{
- switch (disp) {
- case HWC_DISPLAY_PRIMARY:
- return ADF_INTF_FLAG_PRIMARY;
- case HWC_DISPLAY_EXTERNAL:
- return ADF_INTF_FLAG_EXTERNAL;
- default:
- return 0;
- }
-}
-
-__BEGIN_DECLS
-
-/**
- * Create a HWC helper for the specified ADF interfaces.
- *
- * intf_fds must be indexed by HWC display type: e.g.,
- * intf_fds[HWC_DISPLAY_PRIMARY] is the fd for the primary display
- * interface. n_intfs must be >= 1.
- *
- * The caller retains ownership of the fds in intf_fds and must close()
- * them when they are no longer needed.
- *
- * On error, returns -errno.
- */
-int adf_hwc_open(int *intf_fds, size_t n_intfs,
- const struct adf_hwc_event_callbacks *event_cb, void *event_cb_data,
- struct adf_hwc_helper **dev);
-
-/**
- * Destroys a HWC helper.
- */
-void adf_hwc_close(struct adf_hwc_helper *dev);
-
-/**
- * Generic implementations of common HWC ops.
- *
- * The HWC should not point its ops directly at these helpers. Instead, the HWC
- * should provide stub ops which call these helpers after converting the
- * hwc_composer_device_1* to a struct adf_hwc_helper*.
- */
-int adf_eventControl(struct adf_hwc_helper *dev, int disp, int event,
- int enabled);
-int adf_blank(struct adf_hwc_helper *dev, int disp, int blank);
-int adf_query_display_types_supported(struct adf_hwc_helper *dev, int *value);
-int adf_getDisplayConfigs(struct adf_hwc_helper *dev, int disp,
- uint32_t *configs, size_t *numConfigs);
-int adf_getDisplayAttributes(struct adf_hwc_helper *dev, int disp,
- uint32_t config, const uint32_t *attributes, int32_t *values);
-/**
- * Generic implementation of common HWC2 functions.
- *
- * The HWC2 should not return these functions directly through getFunction.
- * Instead, the HWC2 should return stub functions which call these helpers.
- */
-int adf_getDisplayAttributes_hwc2(struct adf_hwc_helper *dev, int disp,
- uint32_t config, const uint32_t *attributes, int32_t *values);
-int adf_set_active_config_hwc2(struct adf_hwc_helper *dev, int disp,
- uint32_t config);
-
-__END_DECLS
-
-#endif /* _LIBADFHWC_ADFHWC_H_ */
diff --git a/fastboot/fastboot.bash b/fastboot/fastboot.bash
index 406e8b8..f5a3384 100644
--- a/fastboot/fastboot.bash
+++ b/fastboot/fastboot.bash
@@ -109,7 +109,7 @@
cur="${COMP_WORDS[COMP_CWORD]}"
if [[ $i -eq $COMP_CWORD ]]; then
- partitions="boot bootloader dtbo modem odm odm_dlkm oem product radio recovery system vbmeta vendor vendor_dlkm"
+ partitions="boot bootloader dtbo modem odm odm_dlkm oem product pvmfw radio recovery system vbmeta vendor vendor_dlkm"
COMPREPLY=( $(compgen -W "$partitions" -- $cur) )
else
_fastboot_util_complete_local_file "${cur}" '!*.img'
diff --git a/fastboot/fastboot.cpp b/fastboot/fastboot.cpp
index 62f6ac7..f7edf8e 100644
--- a/fastboot/fastboot.cpp
+++ b/fastboot/fastboot.cpp
@@ -147,6 +147,7 @@
{ "odm", "odm.img", "odm.sig", "odm", true, ImageType::Normal },
{ "odm_dlkm", "odm_dlkm.img", "odm_dlkm.sig", "odm_dlkm", true, ImageType::Normal },
{ "product", "product.img", "product.sig", "product", true, ImageType::Normal },
+ { "pvmfw", "pvmfw.img", "pvmfw.sig", "pvmfw", true, ImageType::BootCritical },
{ "recovery", "recovery.img", "recovery.sig", "recovery", true, ImageType::BootCritical },
{ "super", "super.img", "super.sig", "super", true, ImageType::Extra },
{ "system", "system.img", "system.sig", "system", false, ImageType::Normal },
diff --git a/fs_mgr/Android.bp b/fs_mgr/Android.bp
index ac784b2..96cc5c8 100644
--- a/fs_mgr/Android.bp
+++ b/fs_mgr/Android.bp
@@ -170,6 +170,7 @@
defaults: ["fs_mgr_defaults"],
static_libs: [
"libavb_user",
+ "libgsid",
"libutils",
"libvold_binder",
],
diff --git a/fs_mgr/fs_mgr_remount.cpp b/fs_mgr/fs_mgr_remount.cpp
index b8b074e..745dab2 100644
--- a/fs_mgr/fs_mgr_remount.cpp
+++ b/fs_mgr/fs_mgr_remount.cpp
@@ -16,7 +16,6 @@
#include <errno.h>
#include <getopt.h>
-#include <libavb_user/libavb_user.h>
#include <stdio.h>
#include <sys/mount.h>
#include <sys/types.h>
@@ -40,6 +39,8 @@
#include <fs_mgr_overlayfs.h>
#include <fs_mgr_priv.h>
#include <fstab/fstab.h>
+#include <libavb_user/libavb_user.h>
+#include <libgsi/libgsid.h>
namespace {
@@ -52,7 +53,9 @@
"\tpartition\tspecific partition(s) (empty does all)\n"
"\n"
"Remount specified partition(s) read-write, by name or mount point.\n"
- "-R notwithstanding, verity must be disabled on partition(s).";
+ "-R notwithstanding, verity must be disabled on partition(s).\n"
+ "-R within a DSU guest system reboots into the DSU instead of the host system,\n"
+ "this command would enable DSU (one-shot) if not already enabled.";
::exit(exit_status);
}
@@ -137,7 +140,8 @@
REMOUNT_FAILED,
MUST_REBOOT,
BINDER_ERROR,
- CHECKPOINTING
+ CHECKPOINTING,
+ GSID_ERROR,
};
static int do_remount(int argc, char* argv[]) {
@@ -340,6 +344,41 @@
++it;
}
+ // If (1) remount requires a reboot to take effect, (2) system is currently
+ // running a DSU guest and (3) DSU is disabled, then enable DSU so that the
+ // next reboot would not take us back to the host system but stay within
+ // the guest system.
+ if (reboot_later) {
+ if (auto gsid = android::gsi::GetGsiService()) {
+ auto dsu_running = false;
+ if (auto status = gsid->isGsiRunning(&dsu_running); !status.isOk()) {
+ LOG(ERROR) << "Failed to get DSU running state: " << status;
+ return BINDER_ERROR;
+ }
+ auto dsu_enabled = false;
+ if (auto status = gsid->isGsiEnabled(&dsu_enabled); !status.isOk()) {
+ LOG(ERROR) << "Failed to get DSU enabled state: " << status;
+ return BINDER_ERROR;
+ }
+ if (dsu_running && !dsu_enabled) {
+ std::string dsu_slot;
+ if (auto status = gsid->getActiveDsuSlot(&dsu_slot); !status.isOk()) {
+ LOG(ERROR) << "Failed to get active DSU slot: " << status;
+ return BINDER_ERROR;
+ }
+ LOG(INFO) << "DSU is running but disabled, enable DSU so that we stay within the "
+ "DSU guest system after reboot";
+ int error = 0;
+ if (auto status = gsid->enableGsi(/* oneShot = */ true, dsu_slot, &error);
+ !status.isOk() || error != android::gsi::IGsiService::INSTALL_OK) {
+ LOG(ERROR) << "Failed to enable DSU: " << status << ", error code: " << error;
+ return !status.isOk() ? BINDER_ERROR : GSID_ERROR;
+ }
+ LOG(INFO) << "Successfully enabled DSU (one-shot mode)";
+ }
+ }
+ }
+
if (partitions.empty() || just_disabled_verity) {
if (reboot_later) reboot(setup_overlayfs);
if (user_please_reboot_later) {
diff --git a/fs_mgr/libfiemap/image_manager.cpp b/fs_mgr/libfiemap/image_manager.cpp
index 93fc131..841f215 100644
--- a/fs_mgr/libfiemap/image_manager.cpp
+++ b/fs_mgr/libfiemap/image_manager.cpp
@@ -486,15 +486,14 @@
if (!MapWithLoopDeviceList(loop_devices, name, timeout_ms, path)) {
return false;
}
+ } else {
+ auto status_message = "loop:" + loop_devices.back();
+ auto status_file = GetStatusFilePath(name);
+ if (!android::base::WriteStringToFile(status_message, status_file)) {
+ PLOG(ERROR) << "Write failed: " << status_file;
+ return false;
+ }
}
-
- auto status_message = "loop:" + loop_devices.back();
- auto status_file = GetStatusFilePath(name);
- if (!android::base::WriteStringToFile(status_message, status_file)) {
- PLOG(ERROR) << "Write failed: " << status_file;
- return false;
- }
-
auto_detach.Commit();
*path = loop_devices.back();
diff --git a/fs_mgr/libfs_avb/tests/avb_util_test.cpp b/fs_mgr/libfs_avb/tests/avb_util_test.cpp
index 784eb9c..1827566 100644
--- a/fs_mgr/libfs_avb/tests/avb_util_test.cpp
+++ b/fs_mgr/libfs_avb/tests/avb_util_test.cpp
@@ -216,9 +216,11 @@
"Header Block: 256 bytes\n"
"Authentication Block: 1088 bytes\n"
"Auxiliary Block: 2304 bytes\n"
+ "Public key (sha1): 5227b569de003adc7f8ec3fc03e05dfbd969abad\n"
"Algorithm: SHA512_RSA8192\n"
"Rollback Index: 20\n"
"Flags: 0\n"
+ "Rollback Index Location: 0\n"
"Release String: 'unit test'\n"
"Descriptors:\n"
" Hashtree descriptor:\n"
@@ -346,9 +348,11 @@
"Header Block: 256 bytes\n"
"Authentication Block: 576 bytes\n"
"Auxiliary Block: 1216 bytes\n"
+ "Public key (sha1): 2597c218aae470a130f61162feaae70afd97f011\n"
"Algorithm: SHA256_RSA4096\n"
"Rollback Index: 10\n"
"Flags: 0\n"
+ "Rollback Index Location: 0\n"
"Release String: 'unit test'\n"
"Descriptors:\n"
" Hash descriptor:\n"
@@ -639,9 +643,11 @@
"Header Block: 256 bytes\n"
"Authentication Block: 1088 bytes\n"
"Auxiliary Block: 3840 bytes\n"
+ "Public key (sha1): 5227b569de003adc7f8ec3fc03e05dfbd969abad\n"
"Algorithm: SHA256_RSA8192\n"
"Rollback Index: 0\n"
"Flags: 0\n"
+ "Rollback Index Location: 0\n"
"Release String: 'unit test'\n"
"Descriptors:\n"
" Chain Partition descriptor:\n"
@@ -854,9 +860,11 @@
"Header Block: 256 bytes\n"
"Authentication Block: 1088 bytes\n"
"Auxiliary Block: 3840 bytes\n"
+ "Public key (sha1): 5227b569de003adc7f8ec3fc03e05dfbd969abad\n"
"Algorithm: SHA256_RSA8192\n"
"Rollback Index: 0\n"
"Flags: 0\n"
+ "Rollback Index Location: 0\n"
"Release String: 'unit test'\n"
"Descriptors:\n"
" Chain Partition descriptor:\n"
@@ -886,9 +894,11 @@
"Header Block: 256 bytes\n"
"Authentication Block: 576 bytes\n"
"Auxiliary Block: 2176 bytes\n"
+ "Public key (sha1): 2597c218aae470a130f61162feaae70afd97f011\n"
"Algorithm: SHA256_RSA4096\n"
"Rollback Index: 0\n"
"Flags: 0\n"
+ "Rollback Index Location: 0\n"
"Release String: 'unit test'\n"
"Descriptors:\n"
" Chain Partition descriptor:\n"
@@ -936,9 +946,11 @@
"Header Block: 256 bytes\n"
"Authentication Block: 320 bytes\n"
"Auxiliary Block: 960 bytes\n"
+ "Public key (sha1): cdbb77177f731920bbe0a0f94f84d9038ae0617d\n"
"Algorithm: SHA256_RSA2048\n"
"Rollback Index: 0\n"
"Flags: 0\n"
+ "Rollback Index Location: 0\n"
"Release String: 'unit test'\n"
"Descriptors:\n"
" Hash descriptor:\n"
diff --git a/fs_mgr/libfs_avb/tests/basic_test.cpp b/fs_mgr/libfs_avb/tests/basic_test.cpp
index 5a1cd0d..1c47c07 100644
--- a/fs_mgr/libfs_avb/tests/basic_test.cpp
+++ b/fs_mgr/libfs_avb/tests/basic_test.cpp
@@ -59,9 +59,11 @@
"Header Block: 256 bytes\n"
"Authentication Block: 320 bytes\n"
"Auxiliary Block: 576 bytes\n"
+ "Public key (sha1): cdbb77177f731920bbe0a0f94f84d9038ae0617d\n"
"Algorithm: SHA256_RSA2048\n"
"Rollback Index: 0\n"
"Flags: 0\n"
+ "Rollback Index Location: 0\n"
"Release String: 'unit test'\n"
"Descriptors:\n"
" (none)\n",
@@ -89,9 +91,11 @@
"Header Block: 256 bytes\n"
"Authentication Block: 576 bytes\n"
"Auxiliary Block: 1216 bytes\n"
+ "Public key (sha1): 2597c218aae470a130f61162feaae70afd97f011\n"
"Algorithm: SHA256_RSA4096\n"
"Rollback Index: 10\n"
"Flags: 0\n"
+ "Rollback Index Location: 0\n"
"Release String: 'unit test'\n"
"Descriptors:\n"
" Hash descriptor:\n"
@@ -126,9 +130,11 @@
"Header Block: 256 bytes\n"
"Authentication Block: 1088 bytes\n"
"Auxiliary Block: 2304 bytes\n"
+ "Public key (sha1): 5227b569de003adc7f8ec3fc03e05dfbd969abad\n"
"Algorithm: SHA512_RSA8192\n"
"Rollback Index: 20\n"
"Flags: 0\n"
+ "Rollback Index Location: 0\n"
"Release String: 'unit test'\n"
"Descriptors:\n"
" Hashtree descriptor:\n"
@@ -180,9 +186,11 @@
"Header Block: 256 bytes\n"
"Authentication Block: 320 bytes\n"
"Auxiliary Block: 960 bytes\n"
+ "Public key (sha1): cdbb77177f731920bbe0a0f94f84d9038ae0617d\n"
"Algorithm: SHA256_RSA2048\n"
"Rollback Index: 0\n"
"Flags: 0\n"
+ "Rollback Index Location: 0\n"
"Release String: 'unit test'\n"
"Descriptors:\n"
" Hash descriptor:\n"
@@ -249,9 +257,11 @@
"Header Block: 256 bytes\n"
"Authentication Block: 1088 bytes\n"
"Auxiliary Block: 3840 bytes\n"
+ "Public key (sha1): 5227b569de003adc7f8ec3fc03e05dfbd969abad\n"
"Algorithm: SHA256_RSA8192\n"
"Rollback Index: 0\n"
"Flags: 0\n"
+ "Rollback Index Location: 0\n"
"Release String: 'unit test'\n"
"Descriptors:\n"
" Chain Partition descriptor:\n"
diff --git a/fs_mgr/libfs_avb/tests/fs_avb_util_test.cpp b/fs_mgr/libfs_avb/tests/fs_avb_util_test.cpp
index 7c34009..5ec1e90 100644
--- a/fs_mgr/libfs_avb/tests/fs_avb_util_test.cpp
+++ b/fs_mgr/libfs_avb/tests/fs_avb_util_test.cpp
@@ -57,9 +57,11 @@
"Header Block: 256 bytes\n"
"Authentication Block: 576 bytes\n"
"Auxiliary Block: 1280 bytes\n"
+ "Public key (sha1): 2597c218aae470a130f61162feaae70afd97f011\n"
"Algorithm: SHA512_RSA4096\n"
"Rollback Index: 20\n"
"Flags: 0\n"
+ "Rollback Index Location: 0\n"
"Release String: 'unit test'\n"
"Descriptors:\n"
" Hashtree descriptor:\n"
diff --git a/fs_mgr/libsnapshot/android/snapshot/snapshot.proto b/fs_mgr/libsnapshot/android/snapshot/snapshot.proto
index 38c6bf8..36e1169 100644
--- a/fs_mgr/libsnapshot/android/snapshot/snapshot.proto
+++ b/fs_mgr/libsnapshot/android/snapshot/snapshot.proto
@@ -34,7 +34,19 @@
MERGE_COMPLETED = 3;
}
-// Next: 10
+// Next: 3
+enum MergePhase {
+ // No merge is in progress.
+ NO_MERGE = 0;
+
+ // Shrunk partitions can merge.
+ FIRST_PHASE = 1;
+
+ // Grown partitions can merge.
+ SECOND_PHASE = 2;
+}
+
+// Next: 11
message SnapshotStatus {
// Name of the snapshot. This is usually the name of the snapshotted
// logical partition; for example, "system_b".
@@ -87,6 +99,9 @@
// True if compression is enabled, false otherwise.
bool compression_enabled = 9;
+
+ // The old partition size (if none existed, this will be zero).
+ uint64 old_partition_size = 10;
}
// Next: 8
@@ -118,7 +133,7 @@
Cancelled = 7;
};
-// Next: 6
+// Next: 7
message SnapshotUpdateStatus {
UpdateState state = 1;
@@ -136,6 +151,9 @@
// Whether compression/dm-user was used for any snapshots.
bool compression_enabled = 5;
+
+ // Merge phase (if state == MERGING).
+ MergePhase merge_phase = 6;
}
// Next: 4
diff --git a/fs_mgr/libsnapshot/cow_api_test.cpp b/fs_mgr/libsnapshot/cow_api_test.cpp
index defe8d4..a96352a 100644
--- a/fs_mgr/libsnapshot/cow_api_test.cpp
+++ b/fs_mgr/libsnapshot/cow_api_test.cpp
@@ -60,6 +60,7 @@
TEST_F(CowTest, ReadWrite) {
CowOptions options;
+ options.cluster_ops = 0;
CowWriter writer(options);
ASSERT_TRUE(writer.Initialize(cow_->fd));
@@ -137,6 +138,7 @@
TEST_F(CowTest, CompressGz) {
CowOptions options;
+ options.cluster_ops = 0;
options.compression = "gz";
CowWriter writer(options);
@@ -238,6 +240,7 @@
TEST_F(CowTest, CompressTwoBlocks) {
CowOptions options;
options.compression = "gz";
+ options.cluster_ops = 0;
CowWriter writer(options);
ASSERT_TRUE(writer.Initialize(cow_->fd));
@@ -280,6 +283,7 @@
TEST_P(CompressionTest, HorribleSink) {
CowOptions options;
options.compression = GetParam();
+ options.cluster_ops = 0;
CowWriter writer(options);
ASSERT_TRUE(writer.Initialize(cow_->fd));
@@ -309,6 +313,7 @@
TEST_F(CowTest, GetSize) {
CowOptions options;
+ options.cluster_ops = 0;
CowWriter writer(options);
if (ftruncate(cow_->fd, 0) < 0) {
perror("Fails to set temp file size");
@@ -334,6 +339,7 @@
TEST_F(CowTest, AppendLabelSmall) {
CowOptions options;
+ options.cluster_ops = 0;
auto writer = std::make_unique<CowWriter>(options);
ASSERT_TRUE(writer->Initialize(cow_->fd));
@@ -399,6 +405,7 @@
TEST_F(CowTest, AppendLabelMissing) {
CowOptions options;
+ options.cluster_ops = 0;
auto writer = std::make_unique<CowWriter>(options);
ASSERT_TRUE(writer->Initialize(cow_->fd));
@@ -452,6 +459,7 @@
TEST_F(CowTest, AppendExtendedCorrupted) {
CowOptions options;
+ options.cluster_ops = 0;
auto writer = std::make_unique<CowWriter>(options);
ASSERT_TRUE(writer->Initialize(cow_->fd));
@@ -504,6 +512,7 @@
TEST_F(CowTest, AppendbyLabel) {
CowOptions options;
+ options.cluster_ops = 0;
auto writer = std::make_unique<CowWriter>(options);
ASSERT_TRUE(writer->Initialize(cow_->fd));
diff --git a/fs_mgr/libsnapshot/cow_snapuserd_test.cpp b/fs_mgr/libsnapshot/cow_snapuserd_test.cpp
index 4cc0fd3..0addba3 100644
--- a/fs_mgr/libsnapshot/cow_snapuserd_test.cpp
+++ b/fs_mgr/libsnapshot/cow_snapuserd_test.cpp
@@ -255,17 +255,23 @@
ASSERT_TRUE(writer.Initialize(cow_system_->fd));
size_t num_blocks = size_ / options.block_size;
- size_t blk_src_copy = num_blocks;
- size_t blk_end_copy = blk_src_copy + num_blocks;
- size_t source_blk = 0;
+ size_t blk_end_copy = num_blocks * 2;
+ size_t source_blk = num_blocks - 1;
+ size_t blk_src_copy = blk_end_copy - 1;
- while (source_blk < num_blocks) {
+ size_t x = num_blocks;
+ while (1) {
ASSERT_TRUE(writer.AddCopy(source_blk, blk_src_copy));
- source_blk += 1;
- blk_src_copy += 1;
+ x -= 1;
+ if (x == 0) {
+ break;
+ }
+ source_blk -= 1;
+ blk_src_copy -= 1;
}
- ASSERT_EQ(blk_src_copy, blk_end_copy);
+ source_blk = num_blocks;
+ blk_src_copy = blk_end_copy;
ASSERT_TRUE(writer.AddRawBlocks(source_blk, random_buffer_1_.get(), size_));
@@ -280,11 +286,9 @@
// Flush operations
ASSERT_TRUE(writer.Finalize());
-
// Construct the buffer required for validation
orig_buffer_ = std::make_unique<uint8_t[]>(total_base_size_);
std::string zero_buffer(size_, 0);
-
ASSERT_EQ(android::base::ReadFullyAtOffset(base_fd_, orig_buffer_.get(), size_, size_), true);
memcpy((char*)orig_buffer_.get() + size_, random_buffer_1_.get(), size_);
memcpy((char*)orig_buffer_.get() + (size_ * 2), (void*)zero_buffer.c_str(), size_);
diff --git a/fs_mgr/libsnapshot/include/libsnapshot/cow_writer.h b/fs_mgr/libsnapshot/include/libsnapshot/cow_writer.h
index fd43cce..22ddfa6 100644
--- a/fs_mgr/libsnapshot/include/libsnapshot/cow_writer.h
+++ b/fs_mgr/libsnapshot/include/libsnapshot/cow_writer.h
@@ -35,7 +35,7 @@
std::optional<uint64_t> max_blocks;
// Number of CowOperations in a cluster. 0 for no clustering. Cannot be 1.
- uint32_t cluster_ops = 0;
+ uint32_t cluster_ops = 200;
};
// Interface for writing to a snapuserd COW. All operations are ordered; merges
diff --git a/fs_mgr/libsnapshot/include/libsnapshot/snapshot.h b/fs_mgr/libsnapshot/include/libsnapshot/snapshot.h
index 397ff2e..d2ffaa7 100644
--- a/fs_mgr/libsnapshot/include/libsnapshot/snapshot.h
+++ b/fs_mgr/libsnapshot/include/libsnapshot/snapshot.h
@@ -441,7 +441,7 @@
//
// All sizes are specified in bytes, and the device, snapshot, COW partition and COW file sizes
// must be a multiple of the sector size (512 bytes).
- bool CreateSnapshot(LockedFile* lock, SnapshotStatus* status);
+ bool CreateSnapshot(LockedFile* lock, PartitionCowCreator* cow_creator, SnapshotStatus* status);
// |name| should be the base partition name (e.g. "system_a"). Create the
// backing COW image using the size previously passed to CreateSnapshot().
@@ -463,6 +463,10 @@
const std::string& base_device, const std::chrono::milliseconds& timeout_ms,
std::string* path);
+ // Map the source device used for dm-user.
+ bool MapSourceDevice(LockedFile* lock, const std::string& name,
+ const std::chrono::milliseconds& timeout_ms, std::string* path);
+
// Map a COW image that was previous created with CreateCowImage.
std::optional<std::string> MapCowImage(const std::string& name,
const std::chrono::milliseconds& timeout_ms);
@@ -521,11 +525,13 @@
std::string GetMergeStateFilePath() const;
// Helpers for merging.
+ bool MergeSecondPhaseSnapshots(LockedFile* lock);
bool SwitchSnapshotToMerge(LockedFile* lock, const std::string& name);
bool RewriteSnapshotDeviceTable(const std::string& dm_name);
bool MarkSnapshotMergeCompleted(LockedFile* snapshot_lock, const std::string& snapshot_name);
void AcknowledgeMergeSuccess(LockedFile* lock);
void AcknowledgeMergeFailure();
+ MergePhase DecideMergePhase(const SnapshotStatus& status);
std::unique_ptr<LpMetadata> ReadCurrentMetadata();
enum class MetadataPartitionState {
@@ -558,7 +564,8 @@
// UpdateState::MergeNeedsReboot
UpdateState CheckMergeState(const std::function<bool()>& before_cancel);
UpdateState CheckMergeState(LockedFile* lock, const std::function<bool()>& before_cancel);
- UpdateState CheckTargetMergeState(LockedFile* lock, const std::string& name);
+ UpdateState CheckTargetMergeState(LockedFile* lock, const std::string& name,
+ const SnapshotUpdateStatus& update_status);
// Interact with status files under /metadata/ota/snapshots.
bool WriteSnapshotStatus(LockedFile* lock, const SnapshotStatus& status);
@@ -568,12 +575,9 @@
std::string GetSnapshotBootIndicatorPath();
std::string GetRollbackIndicatorPath();
std::string GetForwardMergeIndicatorPath();
+ std::string GetOldPartitionMetadataPath();
- // Return the name of the device holding the "snapshot" or "snapshot-merge"
- // target. This may not be the final device presented via MapSnapshot(), if
- // for example there is a linear segment.
- std::string GetSnapshotDeviceName(const std::string& snapshot_name,
- const SnapshotStatus& status);
+ const LpMetadata* ReadOldPartitionMetadata(LockedFile* lock);
bool MapAllPartitions(LockedFile* lock, const std::string& super_device, uint32_t slot,
const std::chrono::milliseconds& timeout_ms);
@@ -673,8 +677,8 @@
// Helper for RemoveAllSnapshots.
// Check whether |name| should be deleted as a snapshot name.
- bool ShouldDeleteSnapshot(LockedFile* lock, const std::map<std::string, bool>& flashing_status,
- Slot current_slot, const std::string& name);
+ bool ShouldDeleteSnapshot(const std::map<std::string, bool>& flashing_status, Slot current_slot,
+ const std::string& name);
// Create or delete forward merge indicator given |wipe|. Iff wipe is scheduled,
// allow forward merge on FDR.
@@ -722,6 +726,7 @@
bool in_factory_data_reset_ = false;
std::function<bool(const std::string&)> uevent_regen_callback_;
std::unique_ptr<SnapuserdClient> snapuserd_client_;
+ std::unique_ptr<LpMetadata> old_partition_metadata_;
};
} // namespace snapshot
diff --git a/fs_mgr/libsnapshot/include_test/libsnapshot/test_helpers.h b/fs_mgr/libsnapshot/include_test/libsnapshot/test_helpers.h
index 7aef086..ff0047e 100644
--- a/fs_mgr/libsnapshot/include_test/libsnapshot/test_helpers.h
+++ b/fs_mgr/libsnapshot/include_test/libsnapshot/test_helpers.h
@@ -51,8 +51,8 @@
extern std::unique_ptr<SnapshotManager> sm;
extern class TestDeviceInfo* test_device;
extern std::string fake_super;
-static constexpr uint64_t kSuperSize = 16_MiB + 4_KiB;
-static constexpr uint64_t kGroupSize = 16_MiB;
+static constexpr uint64_t kSuperSize = 32_MiB + 4_KiB;
+static constexpr uint64_t kGroupSize = 32_MiB;
// Redirect requests for "super" to our fake super partition.
class TestPartitionOpener final : public android::fs_mgr::PartitionOpener {
diff --git a/fs_mgr/libsnapshot/snapshot.cpp b/fs_mgr/libsnapshot/snapshot.cpp
index f0646fc..b55d9a0 100644
--- a/fs_mgr/libsnapshot/snapshot.cpp
+++ b/fs_mgr/libsnapshot/snapshot.cpp
@@ -132,8 +132,8 @@
return partition_name + "-base";
}
-static std::string GetSnapshotExtraDeviceName(const std::string& snapshot_name) {
- return snapshot_name + "-inner";
+static std::string GetSourceDeviceName(const std::string& partition_name) {
+ return partition_name + "-src";
}
bool SnapshotManager::BeginUpdate() {
@@ -157,6 +157,9 @@
images_->RemoveAllImages();
}
+ // Clear any cached metadata (this allows re-using one manager across tests).
+ old_partition_metadata_ = nullptr;
+
auto state = ReadUpdateState(file.get());
if (state != UpdateState::None) {
LOG(ERROR) << "An update is already in progress, cannot begin a new update";
@@ -255,6 +258,7 @@
GetSnapshotBootIndicatorPath(),
GetRollbackIndicatorPath(),
GetForwardMergeIndicatorPath(),
+ GetOldPartitionMetadataPath(),
};
for (const auto& file : files) {
RemoveFileIfExists(file);
@@ -308,7 +312,8 @@
return WriteUpdateState(lock.get(), UpdateState::Unverified);
}
-bool SnapshotManager::CreateSnapshot(LockedFile* lock, SnapshotStatus* status) {
+bool SnapshotManager::CreateSnapshot(LockedFile* lock, PartitionCowCreator* cow_creator,
+ SnapshotStatus* status) {
CHECK(lock);
CHECK(lock->lock_mode() == LOCK_EX);
CHECK(status);
@@ -349,7 +354,7 @@
status->set_state(SnapshotState::CREATED);
status->set_sectors_allocated(0);
status->set_metadata_sectors(0);
- status->set_compression_enabled(IsCompressionEnabled());
+ status->set_compression_enabled(cow_creator->compression_enabled);
if (!WriteSnapshotStatus(lock, *status)) {
PLOG(ERROR) << "Could not write snapshot status: " << status->name();
@@ -465,8 +470,13 @@
LOG(ERROR) << "Invalid snapshot size for " << base_device << ": " << status.snapshot_size();
return false;
}
+ if (status.device_size() != status.snapshot_size()) {
+ LOG(ERROR) << "Device size and snapshot size must be the same (device size = "
+ << status.device_size() << ", snapshot size = " << status.snapshot_size();
+ return false;
+ }
+
uint64_t snapshot_sectors = status.snapshot_size() / kSectorSize;
- uint64_t linear_sectors = (status.device_size() - status.snapshot_size()) / kSectorSize;
auto& dm = DeviceMapper::Instance();
@@ -474,7 +484,8 @@
// have completed merging, but the start of the merge process is considered
// atomic.
SnapshotStorageMode mode;
- switch (ReadUpdateState(lock)) {
+ SnapshotUpdateStatus update_status = ReadSnapshotUpdateStatus(lock);
+ switch (update_status.state()) {
case UpdateState::MergeCompleted:
case UpdateState::MergeNeedsReboot:
LOG(ERROR) << "Should not create a snapshot device for " << name
@@ -484,52 +495,24 @@
case UpdateState::MergeFailed:
// Note: MergeFailed indicates that a merge is in progress, but
// is possibly stalled. We still have to honor the merge.
- mode = SnapshotStorageMode::Merge;
+ if (DecideMergePhase(status) == update_status.merge_phase()) {
+ mode = SnapshotStorageMode::Merge;
+ } else {
+ mode = SnapshotStorageMode::Persistent;
+ }
break;
default:
mode = SnapshotStorageMode::Persistent;
break;
}
- // The kernel (tested on 4.19) crashes horribly if a device has both a snapshot
- // and a linear target in the same table. Instead, we stack them, and give the
- // snapshot device a different name. It is not exposed to the caller in this
- // case.
- auto snap_name = (linear_sectors > 0) ? GetSnapshotExtraDeviceName(name) : name;
-
DmTable table;
table.Emplace<DmTargetSnapshot>(0, snapshot_sectors, base_device, cow_device, mode,
kSnapshotChunkSize);
- if (!dm.CreateDevice(snap_name, table, dev_path, timeout_ms)) {
- LOG(ERROR) << "Could not create snapshot device: " << snap_name;
+ if (!dm.CreateDevice(name, table, dev_path, timeout_ms)) {
+ LOG(ERROR) << "Could not create snapshot device: " << name;
return false;
}
-
- if (linear_sectors) {
- std::string snap_dev;
- if (!dm.GetDeviceString(snap_name, &snap_dev)) {
- LOG(ERROR) << "Cannot determine major/minor for: " << snap_name;
- return false;
- }
-
- // Our stacking will looks like this:
- // [linear, linear] ; to snapshot, and non-snapshot region of base device
- // [snapshot-inner]
- // [base device] [cow]
- DmTable table;
- table.Emplace<DmTargetLinear>(0, snapshot_sectors, snap_dev, 0);
- table.Emplace<DmTargetLinear>(snapshot_sectors, linear_sectors, base_device,
- snapshot_sectors);
- if (!dm.CreateDevice(name, table, dev_path, timeout_ms)) {
- LOG(ERROR) << "Could not create outer snapshot device: " << name;
- dm.DeleteDevice(snap_name);
- return false;
- }
- }
-
- // :TODO: when merging is implemented, we need to add an argument to the
- // status indicating how much progress is left to merge. (device-mapper
- // does not retain the initial values, so we can't derive them.)
return true;
}
@@ -557,6 +540,36 @@
return std::nullopt;
}
+bool SnapshotManager::MapSourceDevice(LockedFile* lock, const std::string& name,
+ const std::chrono::milliseconds& timeout_ms,
+ std::string* path) {
+ CHECK(lock);
+
+ auto metadata = ReadOldPartitionMetadata(lock);
+ if (!metadata) {
+ LOG(ERROR) << "Could not map source device due to missing or corrupt metadata";
+ return false;
+ }
+
+ auto old_name = GetOtherPartitionName(name);
+ auto slot_suffix = device_->GetSlotSuffix();
+ auto slot = SlotNumberForSlotSuffix(slot_suffix);
+
+ CreateLogicalPartitionParams params = {
+ .block_device = device_->GetSuperDevice(slot),
+ .metadata = metadata,
+ .partition_name = old_name,
+ .timeout_ms = timeout_ms,
+ .device_name = GetSourceDeviceName(name),
+ .partition_opener = &device_->GetPartitionOpener(),
+ };
+ if (!CreateLogicalPartition(std::move(params), path)) {
+ LOG(ERROR) << "Could not create source device for snapshot " << name;
+ return false;
+ }
+ return true;
+}
+
bool SnapshotManager::UnmapSnapshot(LockedFile* lock, const std::string& name) {
CHECK(lock);
@@ -565,13 +578,6 @@
LOG(ERROR) << "Could not delete snapshot device: " << name;
return false;
}
-
- auto snapshot_extra_device = GetSnapshotExtraDeviceName(name);
- if (!dm.DeleteDeviceIfExists(snapshot_extra_device)) {
- LOG(ERROR) << "Could not delete snapshot inner device: " << snapshot_extra_device;
- return false;
- }
-
return true;
}
@@ -676,6 +682,10 @@
}
}
+ bool compression_enabled = false;
+
+ std::vector<std::string> first_merge_group;
+
uint64_t total_cow_file_size = 0;
DmTargetSnapshot::Status initial_target_values = {};
for (const auto& snapshot : snapshots) {
@@ -692,6 +702,11 @@
return false;
}
total_cow_file_size += snapshot_status.cow_file_size();
+
+ compression_enabled |= snapshot_status.compression_enabled();
+ if (DecideMergePhase(snapshot_status) == MergePhase::FIRST_PHASE) {
+ first_merge_group.emplace_back(snapshot);
+ }
}
if (cow_file_size) {
@@ -703,15 +718,28 @@
initial_status.set_sectors_allocated(initial_target_values.sectors_allocated);
initial_status.set_total_sectors(initial_target_values.total_sectors);
initial_status.set_metadata_sectors(initial_target_values.metadata_sectors);
+ initial_status.set_compression_enabled(compression_enabled);
+
+ // If any partitions shrunk, we need to merge them before we merge any other
+ // partitions (see b/177935716). Otherwise, a merge from another partition
+ // may overwrite the source block of a copy operation.
+ const std::vector<std::string>* merge_group;
+ if (first_merge_group.empty()) {
+ merge_group = &snapshots;
+ initial_status.set_merge_phase(MergePhase::SECOND_PHASE);
+ } else {
+ merge_group = &first_merge_group;
+ initial_status.set_merge_phase(MergePhase::FIRST_PHASE);
+ }
// Point of no return - mark that we're starting a merge. From now on every
- // snapshot must be a merge target.
+ // eligible snapshot must be a merge target.
if (!WriteSnapshotUpdateStatus(lock.get(), initial_status)) {
return false;
}
bool rewrote_all = true;
- for (const auto& snapshot : snapshots) {
+ for (const auto& snapshot : *merge_group) {
// If this fails, we have no choice but to continue. Everything must
// be merged. This is not an ideal state to be in, but it is safe,
// because we the next boot will try again.
@@ -744,16 +772,15 @@
// After this, we return true because we technically did switch to a merge
// target. Everything else we do here is just informational.
- auto dm_name = GetSnapshotDeviceName(name, status);
- if (!RewriteSnapshotDeviceTable(dm_name)) {
+ if (!RewriteSnapshotDeviceTable(name)) {
return false;
}
status.set_state(SnapshotState::MERGING);
DmTargetSnapshot::Status dm_status;
- if (!QuerySnapshotStatus(dm_name, nullptr, &dm_status)) {
- LOG(ERROR) << "Could not query merge status for snapshot: " << dm_name;
+ if (!QuerySnapshotStatus(name, nullptr, &dm_status)) {
+ LOG(ERROR) << "Could not query merge status for snapshot: " << name;
}
status.set_sectors_allocated(dm_status.sectors_allocated);
status.set_metadata_sectors(dm_status.metadata_sectors);
@@ -763,33 +790,33 @@
return true;
}
-bool SnapshotManager::RewriteSnapshotDeviceTable(const std::string& dm_name) {
+bool SnapshotManager::RewriteSnapshotDeviceTable(const std::string& name) {
auto& dm = DeviceMapper::Instance();
std::vector<DeviceMapper::TargetInfo> old_targets;
- if (!dm.GetTableInfo(dm_name, &old_targets)) {
- LOG(ERROR) << "Could not read snapshot device table: " << dm_name;
+ if (!dm.GetTableInfo(name, &old_targets)) {
+ LOG(ERROR) << "Could not read snapshot device table: " << name;
return false;
}
if (old_targets.size() != 1 || DeviceMapper::GetTargetType(old_targets[0].spec) != "snapshot") {
- LOG(ERROR) << "Unexpected device-mapper table for snapshot: " << dm_name;
+ LOG(ERROR) << "Unexpected device-mapper table for snapshot: " << name;
return false;
}
std::string base_device, cow_device;
if (!DmTargetSnapshot::GetDevicesFromParams(old_targets[0].data, &base_device, &cow_device)) {
- LOG(ERROR) << "Could not derive underlying devices for snapshot: " << dm_name;
+ LOG(ERROR) << "Could not derive underlying devices for snapshot: " << name;
return false;
}
DmTable table;
table.Emplace<DmTargetSnapshot>(0, old_targets[0].spec.length, base_device, cow_device,
SnapshotStorageMode::Merge, kSnapshotChunkSize);
- if (!dm.LoadTableAndActivate(dm_name, table)) {
- LOG(ERROR) << "Could not swap device-mapper tables on snapshot device " << dm_name;
+ if (!dm.LoadTableAndActivate(name, table)) {
+ LOG(ERROR) << "Could not swap device-mapper tables on snapshot device " << name;
return false;
}
- LOG(INFO) << "Successfully switched snapshot device to a merge target: " << dm_name;
+ LOG(INFO) << "Successfully switched snapshot device to a merge target: " << name;
return true;
}
@@ -903,13 +930,13 @@
UpdateState SnapshotManager::CheckMergeState(LockedFile* lock,
const std::function<bool()>& before_cancel) {
- UpdateState state = ReadUpdateState(lock);
- switch (state) {
+ SnapshotUpdateStatus update_status = ReadSnapshotUpdateStatus(lock);
+ switch (update_status.state()) {
case UpdateState::None:
case UpdateState::MergeCompleted:
// Harmless races are allowed between two callers of WaitForMerge,
// so in both of these cases we just propagate the state.
- return state;
+ return update_status.state();
case UpdateState::Merging:
case UpdateState::MergeNeedsReboot:
@@ -926,10 +953,10 @@
if (HandleCancelledUpdate(lock, before_cancel)) {
return UpdateState::Cancelled;
}
- return state;
+ return update_status.state();
default:
- return state;
+ return update_status.state();
}
std::vector<std::string> snapshots;
@@ -941,8 +968,9 @@
bool failed = false;
bool merging = false;
bool needs_reboot = false;
+ bool wrong_phase = false;
for (const auto& snapshot : snapshots) {
- UpdateState snapshot_state = CheckTargetMergeState(lock, snapshot);
+ UpdateState snapshot_state = CheckTargetMergeState(lock, snapshot, update_status);
switch (snapshot_state) {
case UpdateState::MergeFailed:
failed = true;
@@ -958,6 +986,9 @@
case UpdateState::Cancelled:
cancelled = true;
break;
+ case UpdateState::None:
+ wrong_phase = true;
+ break;
default:
LOG(ERROR) << "Unknown merge status for \"" << snapshot << "\": "
<< "\"" << snapshot_state << "\"";
@@ -977,6 +1008,14 @@
// it in WaitForMerge rather than here and elsewhere.
return UpdateState::MergeFailed;
}
+ if (wrong_phase) {
+ // If we got here, no other partitions are being merged, and nothing
+ // failed to merge. It's safe to move to the next merge phase.
+ if (!MergeSecondPhaseSnapshots(lock)) {
+ return UpdateState::MergeFailed;
+ }
+ return UpdateState::Merging;
+ }
if (needs_reboot) {
WriteUpdateState(lock, UpdateState::MergeNeedsReboot);
return UpdateState::MergeNeedsReboot;
@@ -992,17 +1031,16 @@
return UpdateState::MergeCompleted;
}
-UpdateState SnapshotManager::CheckTargetMergeState(LockedFile* lock, const std::string& name) {
+UpdateState SnapshotManager::CheckTargetMergeState(LockedFile* lock, const std::string& name,
+ const SnapshotUpdateStatus& update_status) {
SnapshotStatus snapshot_status;
if (!ReadSnapshotStatus(lock, name, &snapshot_status)) {
return UpdateState::MergeFailed;
}
- std::string dm_name = GetSnapshotDeviceName(name, snapshot_status);
-
std::unique_ptr<LpMetadata> current_metadata;
- if (!IsSnapshotDevice(dm_name)) {
+ if (!IsSnapshotDevice(name)) {
if (!current_metadata) {
current_metadata = ReadCurrentMetadata();
}
@@ -1016,7 +1054,7 @@
// During a check, we decided the merge was complete, but we were unable to
// collapse the device-mapper stack and perform COW cleanup. If we haven't
// rebooted after this check, the device will still be a snapshot-merge
- // target. If the have rebooted, the device will now be a linear target,
+ // target. If we have rebooted, the device will now be a linear target,
// and we can try cleanup again.
if (snapshot_status.state() == SnapshotState::MERGE_COMPLETED) {
// NB: It's okay if this fails now, we gave cleanup our best effort.
@@ -1024,7 +1062,7 @@
return UpdateState::MergeCompleted;
}
- LOG(ERROR) << "Expected snapshot or snapshot-merge for device: " << dm_name;
+ LOG(ERROR) << "Expected snapshot or snapshot-merge for device: " << name;
return UpdateState::MergeFailed;
}
@@ -1034,9 +1072,15 @@
std::string target_type;
DmTargetSnapshot::Status status;
- if (!QuerySnapshotStatus(dm_name, &target_type, &status)) {
+ if (!QuerySnapshotStatus(name, &target_type, &status)) {
return UpdateState::MergeFailed;
}
+ if (target_type == "snapshot" &&
+ DecideMergePhase(snapshot_status) == MergePhase::SECOND_PHASE &&
+ update_status.merge_phase() == MergePhase::FIRST_PHASE) {
+ // The snapshot is not being merged because it's in the wrong phase.
+ return UpdateState::None;
+ }
if (target_type != "snapshot-merge") {
// We can get here if we failed to rewrite the target type in
// InitiateMerge(). If we failed to create the target in first-stage
@@ -1072,6 +1116,38 @@
return UpdateState::MergeCompleted;
}
+bool SnapshotManager::MergeSecondPhaseSnapshots(LockedFile* lock) {
+ std::vector<std::string> snapshots;
+ if (!ListSnapshots(lock, &snapshots)) {
+ return UpdateState::MergeFailed;
+ }
+
+ SnapshotUpdateStatus update_status = ReadSnapshotUpdateStatus(lock);
+ CHECK(update_status.state() == UpdateState::Merging);
+ CHECK(update_status.merge_phase() == MergePhase::FIRST_PHASE);
+
+ update_status.set_merge_phase(MergePhase::SECOND_PHASE);
+ if (!WriteSnapshotUpdateStatus(lock, update_status)) {
+ return false;
+ }
+
+ bool rewrote_all = true;
+ for (const auto& snapshot : snapshots) {
+ SnapshotStatus snapshot_status;
+ if (!ReadSnapshotStatus(lock, snapshot, &snapshot_status)) {
+ return UpdateState::MergeFailed;
+ }
+ if (DecideMergePhase(snapshot_status) != MergePhase::SECOND_PHASE) {
+ continue;
+ }
+ if (!SwitchSnapshotToMerge(lock, snapshot)) {
+ LOG(ERROR) << "Failed to switch snapshot to a second-phase merge target: " << snapshot;
+ rewrote_all = false;
+ }
+ }
+ return rewrote_all;
+}
+
std::string SnapshotManager::GetSnapshotBootIndicatorPath() {
return metadata_dir_ + "/" + android::base::Basename(kBootIndicatorPath);
}
@@ -1084,6 +1160,10 @@
return metadata_dir_ + "/allow-forward-merge";
}
+std::string SnapshotManager::GetOldPartitionMetadataPath() {
+ return metadata_dir_ + "/old-partition-metadata";
+}
+
void SnapshotManager::AcknowledgeMergeSuccess(LockedFile* lock) {
// It's not possible to remove update state in recovery, so write an
// indicator that cleanup is needed on reboot. If a factory data reset
@@ -1119,21 +1199,20 @@
bool SnapshotManager::OnSnapshotMergeComplete(LockedFile* lock, const std::string& name,
const SnapshotStatus& status) {
- auto dm_name = GetSnapshotDeviceName(name, status);
- if (IsSnapshotDevice(dm_name)) {
+ if (IsSnapshotDevice(name)) {
// We are extra-cautious here, to avoid deleting the wrong table.
std::string target_type;
DmTargetSnapshot::Status dm_status;
- if (!QuerySnapshotStatus(dm_name, &target_type, &dm_status)) {
+ if (!QuerySnapshotStatus(name, &target_type, &dm_status)) {
return false;
}
if (target_type != "snapshot-merge") {
LOG(ERROR) << "Unexpected target type " << target_type
- << " for snapshot device: " << dm_name;
+ << " for snapshot device: " << name;
return false;
}
if (dm_status.sectors_allocated != dm_status.metadata_sectors) {
- LOG(ERROR) << "Merge is unexpectedly incomplete for device " << dm_name;
+ LOG(ERROR) << "Merge is unexpectedly incomplete for device " << name;
return false;
}
if (!CollapseSnapshotDevice(name, status)) {
@@ -1154,23 +1233,21 @@
bool SnapshotManager::CollapseSnapshotDevice(const std::string& name,
const SnapshotStatus& status) {
auto& dm = DeviceMapper::Instance();
- auto dm_name = GetSnapshotDeviceName(name, status);
// Verify we have a snapshot-merge device.
DeviceMapper::TargetInfo target;
- if (!GetSingleTarget(dm_name, TableQuery::Table, &target)) {
+ if (!GetSingleTarget(name, TableQuery::Table, &target)) {
return false;
}
if (DeviceMapper::GetTargetType(target.spec) != "snapshot-merge") {
// This should be impossible, it was checked earlier.
- LOG(ERROR) << "Snapshot device has invalid target type: " << dm_name;
+ LOG(ERROR) << "Snapshot device has invalid target type: " << name;
return false;
}
std::string base_device, cow_device;
if (!DmTargetSnapshot::GetDevicesFromParams(target.data, &base_device, &cow_device)) {
- LOG(ERROR) << "Could not parse snapshot device " << dm_name
- << " parameters: " << target.data;
+ LOG(ERROR) << "Could not parse snapshot device " << name << " parameters: " << target.data;
return false;
}
@@ -1181,42 +1258,6 @@
return false;
}
- if (dm_name != name) {
- // We've derived the base device, but we actually need to replace the
- // table of the outermost device. Do a quick verification that this
- // device looks like we expect it to.
- std::vector<DeviceMapper::TargetInfo> outer_table;
- if (!dm.GetTableInfo(name, &outer_table)) {
- LOG(ERROR) << "Could not validate outer snapshot table: " << name;
- return false;
- }
- if (outer_table.size() != 2) {
- LOG(ERROR) << "Expected 2 dm-linear targets for table " << name
- << ", got: " << outer_table.size();
- return false;
- }
- for (const auto& target : outer_table) {
- auto target_type = DeviceMapper::GetTargetType(target.spec);
- if (target_type != "linear") {
- LOG(ERROR) << "Outer snapshot table may only contain linear targets, but " << name
- << " has target: " << target_type;
- return false;
- }
- }
- if (outer_table[0].spec.length != snapshot_sectors) {
- LOG(ERROR) << "dm-snapshot " << name << " should have " << snapshot_sectors
- << " sectors, got: " << outer_table[0].spec.length;
- return false;
- }
- uint64_t expected_device_sectors = status.device_size() / kSectorSize;
- uint64_t actual_device_sectors = outer_table[0].spec.length + outer_table[1].spec.length;
- if (expected_device_sectors != actual_device_sectors) {
- LOG(ERROR) << "Outer device " << name << " should have " << expected_device_sectors
- << " sectors, got: " << actual_device_sectors;
- return false;
- }
- }
-
uint32_t slot = SlotNumberForSlotSuffix(device_->GetSlotSuffix());
// Create a DmTable that is identical to the base device.
CreateLogicalPartitionParams base_device_params{
@@ -1231,7 +1272,6 @@
return false;
}
- // Note: we are replacing the *outer* table here, so we do not use dm_name.
if (!dm.LoadTableAndActivate(name, table)) {
return false;
}
@@ -1241,22 +1281,17 @@
// flushed remaining I/O. We could in theory replace with dm-zero (or
// re-use the table above), but for now it's better to know why this
// would fail.
- if (dm_name != name && !dm.DeleteDeviceIfExists(dm_name)) {
- LOG(ERROR) << "Unable to delete snapshot device " << dm_name << ", COW cannot be "
- << "reclaimed until after reboot.";
- return false;
- }
-
if (status.compression_enabled()) {
UnmapDmUserDevice(name);
}
-
- // Cleanup the base device as well, since it is no longer used. This does
- // not block cleanup.
auto base_name = GetBaseDeviceName(name);
if (!dm.DeleteDeviceIfExists(base_name)) {
LOG(ERROR) << "Unable to delete base device for snapshot: " << base_name;
}
+ auto source_name = GetSourceDeviceName(name);
+ if (!dm.DeleteDeviceIfExists(source_name)) {
+ LOG(ERROR) << "Unable to delete source device for snapshot: " << source_name;
+ }
return true;
}
@@ -1359,9 +1394,9 @@
continue;
}
- std::string backing_device;
- if (!dm.GetDmDevicePathByName(GetBaseDeviceName(snapshot), &backing_device)) {
- LOG(ERROR) << "Could not get device path for " << GetBaseDeviceName(snapshot);
+ std::string source_device;
+ if (!dm.GetDmDevicePathByName(GetSourceDeviceName(snapshot), &source_device)) {
+ LOG(ERROR) << "Could not get device path for " << GetSourceDeviceName(snapshot);
continue;
}
@@ -1387,7 +1422,7 @@
}
if (transition == InitTransition::SELINUX_DETACH) {
- auto message = misc_name + "," + cow_image_device + "," + backing_device;
+ auto message = misc_name + "," + cow_image_device + "," + source_device;
snapuserd_argv->emplace_back(std::move(message));
// Do not attempt to connect to the new snapuserd yet, it hasn't
@@ -1398,14 +1433,14 @@
}
uint64_t base_sectors =
- snapuserd_client_->InitDmUserCow(misc_name, cow_image_device, backing_device);
+ snapuserd_client_->InitDmUserCow(misc_name, cow_image_device, source_device);
if (base_sectors == 0) {
// Unrecoverable as metadata reads from cow device failed
LOG(FATAL) << "Failed to retrieve base_sectors from Snapuserd";
return false;
}
- CHECK(base_sectors == target.spec.length);
+ CHECK(base_sectors <= target.spec.length);
if (!snapuserd_client_->AttachDmUser(misc_name)) {
// This error is unrecoverable. We cannot proceed because reads to
@@ -1543,7 +1578,7 @@
// Otherwise (UPDATED flag), only delete snapshots if they are not mapped
// as dm-snapshot (for example, after merge completes).
bool should_unmap = current_slot != Slot::Target;
- bool should_delete = ShouldDeleteSnapshot(lock, flashing_status, current_slot, name);
+ bool should_delete = ShouldDeleteSnapshot(flashing_status, current_slot, name);
bool partition_ok = true;
if (should_unmap && !UnmapPartitionWithSnapshot(lock, name)) {
@@ -1577,8 +1612,7 @@
}
// See comments in RemoveAllSnapshots().
-bool SnapshotManager::ShouldDeleteSnapshot(LockedFile* lock,
- const std::map<std::string, bool>& flashing_status,
+bool SnapshotManager::ShouldDeleteSnapshot(const std::map<std::string, bool>& flashing_status,
Slot current_slot, const std::string& name) {
if (current_slot != Slot::Target) {
return true;
@@ -1592,16 +1626,7 @@
// partition flashed, okay to delete obsolete snapshots
return true;
}
- // partition updated, only delete if not dm-snapshot
- SnapshotStatus status;
- if (!ReadSnapshotStatus(lock, name, &status)) {
- LOG(WARNING) << "Unable to read snapshot status for " << name
- << ", guessing snapshot device name";
- auto extra_name = GetSnapshotExtraDeviceName(name);
- return !IsSnapshotDevice(name) && !IsSnapshotDevice(extra_name);
- }
- auto dm_name = GetSnapshotDeviceName(name, status);
- return !IsSnapshotDevice(dm_name);
+ return !IsSnapshotDevice(name);
}
UpdateState SnapshotManager::GetUpdateState(double* progress) {
@@ -1917,24 +1942,35 @@
}
if (live_snapshot_status->compression_enabled()) {
- auto name = GetDmUserCowName(params.GetPartitionName());
+ // Get the source device (eg the view of the partition from before it was resized).
+ std::string source_device_path;
+ if (!MapSourceDevice(lock, params.GetPartitionName(), remaining_time,
+ &source_device_path)) {
+ LOG(ERROR) << "Could not map source device for: " << cow_name;
+ return false;
+ }
+
+ auto source_device = GetSourceDeviceName(params.GetPartitionName());
+ created_devices.EmplaceBack<AutoUnmapDevice>(&dm, source_device);
+
+ if (!WaitForDevice(source_device_path, remaining_time)) {
+ return false;
+ }
std::string cow_path;
if (!GetMappedImageDevicePath(cow_name, &cow_path)) {
LOG(ERROR) << "Could not determine path for: " << cow_name;
return false;
}
-
- // Ensure both |base_path| and |cow_path| are created, for snapuserd.
- if (!WaitForDevice(base_path, remaining_time)) {
- return false;
- }
if (!WaitForDevice(cow_path, remaining_time)) {
return false;
}
+ auto name = GetDmUserCowName(params.GetPartitionName());
+
std::string new_cow_device;
- if (!MapDmUserCow(lock, name, cow_path, base_path, remaining_time, &new_cow_device)) {
+ if (!MapDmUserCow(lock, name, cow_path, source_device_path, remaining_time,
+ &new_cow_device)) {
LOG(ERROR) << "Could not map dm-user device for partition "
<< params.GetPartitionName();
return false;
@@ -1978,12 +2014,18 @@
}
auto& dm = DeviceMapper::Instance();
- std::string base_name = GetBaseDeviceName(target_partition_name);
+ auto base_name = GetBaseDeviceName(target_partition_name);
if (!dm.DeleteDeviceIfExists(base_name)) {
LOG(ERROR) << "Cannot delete base device: " << base_name;
return false;
}
+ auto source_name = GetSourceDeviceName(target_partition_name);
+ if (!dm.DeleteDeviceIfExists(source_name)) {
+ LOG(ERROR) << "Cannot delete source device: " << source_name;
+ return false;
+ }
+
LOG(INFO) << "Successfully unmapped snapshot " << target_partition_name;
return true;
@@ -2285,9 +2327,15 @@
}
bool SnapshotManager::WriteUpdateState(LockedFile* lock, UpdateState state) {
- SnapshotUpdateStatus status = {};
+ SnapshotUpdateStatus status;
status.set_state(state);
- status.set_compression_enabled(IsCompressionEnabled());
+
+ // If we're transitioning between two valid states (eg, we're not beginning
+ // or ending an OTA), then make sure to propagate the compression bit.
+ if (!(state == UpdateState::Initiated || state == UpdateState::None)) {
+ SnapshotUpdateStatus old_status = ReadSnapshotUpdateStatus(lock);
+ status.set_compression_enabled(old_status.compression_enabled());
+ }
return WriteSnapshotUpdateStatus(lock, status);
}
@@ -2398,14 +2446,6 @@
return true;
}
-std::string SnapshotManager::GetSnapshotDeviceName(const std::string& snapshot_name,
- const SnapshotStatus& status) {
- if (status.device_size() != status.snapshot_size()) {
- return GetSnapshotExtraDeviceName(snapshot_name);
- }
- return snapshot_name;
-}
-
bool SnapshotManager::EnsureImageManager() {
if (images_) return true;
@@ -2477,6 +2517,12 @@
auto lock = LockExclusive();
if (!lock) return Return::Error();
+ auto update_state = ReadUpdateState(lock.get());
+ if (update_state != UpdateState::Initiated) {
+ LOG(ERROR) << "Cannot create update snapshots in state " << update_state;
+ return Return::Error();
+ }
+
// TODO(b/134949511): remove this check. Right now, with overlayfs mounted, the scratch
// partition takes up a big chunk of space in super, causing COW images to be created on
// retrofit Virtual A/B devices.
@@ -2539,6 +2585,9 @@
// these devices.
AutoDeviceList created_devices;
+ bool use_compression =
+ IsCompressionEnabled() && manifest.dynamic_partition_metadata().vabc_enabled();
+
PartitionCowCreator cow_creator{
.target_metadata = target_metadata.get(),
.target_suffix = target_suffix,
@@ -2547,7 +2596,7 @@
.current_suffix = current_suffix,
.update = nullptr,
.extra_extents = {},
- .compression_enabled = IsCompressionEnabled(),
+ .compression_enabled = use_compression,
};
auto ret = CreateUpdateSnapshotsInternal(lock.get(), manifest, &cow_creator, &created_devices,
@@ -2571,6 +2620,32 @@
return Return::Error();
}
+ // If compression is enabled, we need to retain a copy of the old metadata
+ // so we can access original blocks in case they are moved around. We do
+ // not want to rely on the old super metadata slot because we don't
+ // guarantee its validity after the slot switch is successful.
+ if (cow_creator.compression_enabled) {
+ auto metadata = current_metadata->Export();
+ if (!metadata) {
+ LOG(ERROR) << "Could not export current metadata";
+ return Return::Error();
+ }
+
+ auto path = GetOldPartitionMetadataPath();
+ if (!android::fs_mgr::WriteToImageFile(path, *metadata.get())) {
+ LOG(ERROR) << "Cannot write old metadata to " << path;
+ return Return::Error();
+ }
+ }
+
+ SnapshotUpdateStatus status = {};
+ status.set_state(update_state);
+ status.set_compression_enabled(cow_creator.compression_enabled);
+ if (!WriteSnapshotUpdateStatus(lock.get(), status)) {
+ LOG(ERROR) << "Unable to write new update state";
+ return Return::Error();
+ }
+
created_devices.Release();
LOG(INFO) << "Successfully created all snapshots for target slot " << target_suffix;
@@ -2663,8 +2738,17 @@
continue;
}
+ // Find the original partition size.
+ auto name = target_partition->name();
+ auto old_partition_name =
+ name.substr(0, name.size() - target_suffix.size()) + cow_creator->current_suffix;
+ auto old_partition = cow_creator->current_metadata->FindPartition(old_partition_name);
+ if (old_partition) {
+ cow_creator_ret->snapshot_status.set_old_partition_size(old_partition->size());
+ }
+
// Store these device sizes to snapshot status file.
- if (!CreateSnapshot(lock, &cow_creator_ret->snapshot_status)) {
+ if (!CreateSnapshot(lock, cow_creator, &cow_creator_ret->snapshot_status)) {
return Return::Error();
}
created_devices->EmplaceBack<AutoDeleteSnapshot>(this, lock, target_partition->name());
@@ -2777,11 +2861,6 @@
bool SnapshotManager::MapUpdateSnapshot(const CreateLogicalPartitionParams& params,
std::string* snapshot_path) {
- if (IsCompressionEnabled()) {
- LOG(ERROR) << "MapUpdateSnapshot cannot be used in compression mode.";
- return false;
- }
-
auto lock = LockShared();
if (!lock) return false;
if (!UnmapPartitionWithSnapshot(lock.get(), params.GetPartitionName())) {
@@ -2790,6 +2869,15 @@
return false;
}
+ SnapshotStatus status;
+ if (!ReadSnapshotStatus(lock.get(), params.GetPartitionName(), &status)) {
+ return false;
+ }
+ if (status.compression_enabled()) {
+ LOG(ERROR) << "Cannot use MapUpdateSnapshot with compressed snapshots";
+ return false;
+ }
+
SnapshotPaths paths;
if (!MapPartitionWithSnapshot(lock.get(), params, SnapshotContext::Update, &paths)) {
return false;
@@ -3350,5 +3438,26 @@
return PerformInitTransition(InitTransition::SECOND_STAGE);
}
+const LpMetadata* SnapshotManager::ReadOldPartitionMetadata(LockedFile* lock) {
+ CHECK(lock);
+
+ if (!old_partition_metadata_) {
+ auto path = GetOldPartitionMetadataPath();
+ old_partition_metadata_ = android::fs_mgr::ReadFromImageFile(path);
+ if (!old_partition_metadata_) {
+ LOG(ERROR) << "Could not read old partition metadata from " << path;
+ return nullptr;
+ }
+ }
+ return old_partition_metadata_.get();
+}
+
+MergePhase SnapshotManager::DecideMergePhase(const SnapshotStatus& status) {
+ if (status.compression_enabled() && status.device_size() < status.old_partition_size()) {
+ return MergePhase::FIRST_PHASE;
+ }
+ return MergePhase::SECOND_PHASE;
+}
+
} // namespace snapshot
} // namespace android
diff --git a/fs_mgr/libsnapshot/snapshot_test.cpp b/fs_mgr/libsnapshot/snapshot_test.cpp
index bb44425..0b8a03a 100644
--- a/fs_mgr/libsnapshot/snapshot_test.cpp
+++ b/fs_mgr/libsnapshot/snapshot_test.cpp
@@ -41,6 +41,7 @@
#include <android/snapshot/snapshot.pb.h>
#include <libsnapshot/test_helpers.h>
+#include "partition_cow_creator.h"
#include "utility.h"
// Mock classes are not used. Header included to ensure mocked class definition aligns with the
@@ -234,7 +235,8 @@
.partition_opener = &opener,
};
- auto result = sm->OpenSnapshotWriter(params, {});
+ auto old_partition = "/dev/block/mapper/" + GetOtherPartitionName(name);
+ auto result = sm->OpenSnapshotWriter(params, {old_partition});
if (!result) {
return AssertionFailure() << "Cannot open snapshot for writing: " << name;
}
@@ -322,7 +324,10 @@
DeltaArchiveManifest manifest;
- auto group = manifest.mutable_dynamic_partition_metadata()->add_groups();
+ auto dynamic_partition_metadata = manifest.mutable_dynamic_partition_metadata();
+ dynamic_partition_metadata->set_vabc_enabled(IsCompressionEnabled());
+
+ auto group = dynamic_partition_metadata->add_groups();
group->set_name("group");
group->set_size(device_size * 2);
group->add_partition_names("test_partition");
@@ -415,13 +420,16 @@
TEST_F(SnapshotTest, CreateSnapshot) {
ASSERT_TRUE(AcquireLock());
+ PartitionCowCreator cow_creator;
+ cow_creator.compression_enabled = IsCompressionEnabled();
+
static const uint64_t kDeviceSize = 1024 * 1024;
SnapshotStatus status;
status.set_name("test-snapshot");
status.set_device_size(kDeviceSize);
status.set_snapshot_size(kDeviceSize);
status.set_cow_file_size(kDeviceSize);
- ASSERT_TRUE(sm->CreateSnapshot(lock_.get(), &status));
+ ASSERT_TRUE(sm->CreateSnapshot(lock_.get(), &cow_creator, &status));
ASSERT_TRUE(CreateCowImage("test-snapshot"));
std::vector<std::string> snapshots;
@@ -436,6 +444,7 @@
ASSERT_EQ(status.state(), SnapshotState::CREATED);
ASSERT_EQ(status.device_size(), kDeviceSize);
ASSERT_EQ(status.snapshot_size(), kDeviceSize);
+ ASSERT_EQ(status.compression_enabled(), cow_creator.compression_enabled);
}
ASSERT_TRUE(sm->UnmapSnapshot(lock_.get(), "test-snapshot"));
@@ -446,38 +455,16 @@
TEST_F(SnapshotTest, MapSnapshot) {
ASSERT_TRUE(AcquireLock());
+ PartitionCowCreator cow_creator;
+ cow_creator.compression_enabled = IsCompressionEnabled();
+
static const uint64_t kDeviceSize = 1024 * 1024;
SnapshotStatus status;
status.set_name("test-snapshot");
status.set_device_size(kDeviceSize);
status.set_snapshot_size(kDeviceSize);
status.set_cow_file_size(kDeviceSize);
- ASSERT_TRUE(sm->CreateSnapshot(lock_.get(), &status));
- ASSERT_TRUE(CreateCowImage("test-snapshot"));
-
- std::string base_device;
- ASSERT_TRUE(CreatePartition("base-device", kDeviceSize, &base_device));
-
- std::string cow_device;
- ASSERT_TRUE(MapCowImage("test-snapshot", 10s, &cow_device));
-
- std::string snap_device;
- ASSERT_TRUE(sm->MapSnapshot(lock_.get(), "test-snapshot", base_device, cow_device, 10s,
- &snap_device));
- ASSERT_TRUE(android::base::StartsWith(snap_device, "/dev/block/dm-"));
-}
-
-TEST_F(SnapshotTest, MapPartialSnapshot) {
- ASSERT_TRUE(AcquireLock());
-
- static const uint64_t kSnapshotSize = 1024 * 1024;
- static const uint64_t kDeviceSize = 1024 * 1024 * 2;
- SnapshotStatus status;
- status.set_name("test-snapshot");
- status.set_device_size(kDeviceSize);
- status.set_snapshot_size(kSnapshotSize);
- status.set_cow_file_size(kSnapshotSize);
- ASSERT_TRUE(sm->CreateSnapshot(lock_.get(), &status));
+ ASSERT_TRUE(sm->CreateSnapshot(lock_.get(), &cow_creator, &status));
ASSERT_TRUE(CreateCowImage("test-snapshot"));
std::string base_device;
@@ -590,8 +577,7 @@
ASSERT_EQ(status.state(), SnapshotState::CREATED);
DeviceMapper::TargetInfo target;
- auto dm_name = init->GetSnapshotDeviceName("test_partition_b", status);
- ASSERT_TRUE(init->IsSnapshotDevice(dm_name, &target));
+ ASSERT_TRUE(init->IsSnapshotDevice("test_partition_b", &target));
ASSERT_EQ(DeviceMapper::GetTargetType(target.spec), "snapshot");
}
@@ -618,8 +604,7 @@
// We should not get a snapshot device now.
DeviceMapper::TargetInfo target;
- auto dm_name = init->GetSnapshotDeviceName("test_partition_b", status);
- ASSERT_FALSE(init->IsSnapshotDevice(dm_name, &target));
+ ASSERT_FALSE(init->IsSnapshotDevice("test_partition_b", &target));
// We should see a cancelled update as well.
lock_ = nullptr;
@@ -854,15 +839,15 @@
group_->add_partition_names("prd");
sys_ = manifest_.add_partitions();
sys_->set_partition_name("sys");
- sys_->set_estimate_cow_size(6_MiB);
+ sys_->set_estimate_cow_size(2_MiB);
SetSize(sys_, 3_MiB);
vnd_ = manifest_.add_partitions();
vnd_->set_partition_name("vnd");
- vnd_->set_estimate_cow_size(6_MiB);
+ vnd_->set_estimate_cow_size(2_MiB);
SetSize(vnd_, 3_MiB);
prd_ = manifest_.add_partitions();
prd_->set_partition_name("prd");
- prd_->set_estimate_cow_size(6_MiB);
+ prd_->set_estimate_cow_size(2_MiB);
SetSize(prd_, 3_MiB);
// Initialize source partition metadata using |manifest_|.
@@ -1050,11 +1035,17 @@
ASSERT_TRUE(sm->UnmapUpdateSnapshot(name));
}
- // Grow all partitions.
+ // Grow all partitions. Set |prd| large enough that |sys| and |vnd|'s COWs
+ // fit in super, but not |prd|.
constexpr uint64_t partition_size = 3788_KiB;
SetSize(sys_, partition_size);
SetSize(vnd_, partition_size);
- SetSize(prd_, partition_size);
+ SetSize(prd_, 18_MiB);
+
+ // Make sure |prd| does not fit in super at all. On VABC, this means we
+ // fake an extra large COW for |vnd| to fill up super.
+ vnd_->set_estimate_cow_size(30_MiB);
+ prd_->set_estimate_cow_size(30_MiB);
AddOperationForPartitions();
@@ -1066,11 +1057,7 @@
auto tgt = MetadataBuilder::New(*opener_, "super", 1);
ASSERT_NE(tgt, nullptr);
ASSERT_NE(nullptr, tgt->FindPartition("sys_b-cow"));
- if (IsCompressionEnabled()) {
- ASSERT_EQ(nullptr, tgt->FindPartition("vnd_b-cow"));
- } else {
- ASSERT_NE(nullptr, tgt->FindPartition("vnd_b-cow"));
- }
+ ASSERT_NE(nullptr, tgt->FindPartition("vnd_b-cow"));
ASSERT_EQ(nullptr, tgt->FindPartition("prd_b-cow"));
// Write some data to target partitions.
@@ -1104,6 +1091,7 @@
// Initiate the merge and wait for it to be completed.
ASSERT_TRUE(init->InitiateMerge());
+ ASSERT_EQ(init->IsSnapuserdRequired(), IsCompressionEnabled());
ASSERT_EQ(UpdateState::MergeCompleted, init->ProcessUpdateState());
// Check that the target partitions have the same content after the merge.
@@ -1128,6 +1116,7 @@
SetSize(sys_, 4_MiB); // grows
SetSize(vnd_, 2_MiB); // shrinks
// prd_b is unchanged
+ ASSERT_TRUE(sm->BeginUpdate());
ASSERT_TRUE(sm->CreateUpdateSnapshots(manifest_));
ASSERT_EQ(4_MiB, GetSnapshotSize("sys_b").value_or(0));
}
@@ -1137,6 +1126,7 @@
TEST_F(SnapshotUpdateTest, CowPartitionDoNotTakeOldPartitions) {
SetSize(sys_, 2_MiB); // shrinks
// vnd_b and prd_b are unchanged.
+ ASSERT_TRUE(sm->BeginUpdate());
ASSERT_TRUE(sm->CreateUpdateSnapshots(manifest_));
auto tgt = MetadataBuilder::New(*opener_, "super", 1);
@@ -1260,6 +1250,11 @@
// Test that at the second update, old COW partition spaces are reclaimed.
TEST_F(SnapshotUpdateTest, ReclaimCow) {
+ // Make sure VABC cows are small enough that they fit in fake_super.
+ sys_->set_estimate_cow_size(64_KiB);
+ vnd_->set_estimate_cow_size(64_KiB);
+ prd_->set_estimate_cow_size(64_KiB);
+
// Execute the first update.
ASSERT_TRUE(sm->BeginUpdate());
ASSERT_TRUE(sm->CreateUpdateSnapshots(manifest_));
@@ -1376,9 +1371,13 @@
TEST_F(SnapshotUpdateTest, MergeCannotRemoveCow) {
// Make source partitions as big as possible to force COW image to be created.
- SetSize(sys_, 5_MiB);
- SetSize(vnd_, 5_MiB);
- SetSize(prd_, 5_MiB);
+ SetSize(sys_, 10_MiB);
+ SetSize(vnd_, 10_MiB);
+ SetSize(prd_, 10_MiB);
+ sys_->set_estimate_cow_size(12_MiB);
+ vnd_->set_estimate_cow_size(12_MiB);
+ prd_->set_estimate_cow_size(12_MiB);
+
src_ = MetadataBuilder::New(*opener_, "super", 0);
ASSERT_NE(src_, nullptr);
src_->RemoveGroupAndPartitions(group_->name() + "_a");
@@ -1676,6 +1675,8 @@
SetSize(sys_, partition_size);
AddOperation(sys_, data_size);
+ sys_->set_estimate_cow_size(partition_size + data_size);
+
// Set hastree extents.
sys_->mutable_hash_tree_data_extent()->set_start_block(0);
sys_->mutable_hash_tree_data_extent()->set_num_blocks(data_size / block_size);
@@ -1716,6 +1717,10 @@
// Test for overflow bit after update
TEST_F(SnapshotUpdateTest, Overflow) {
+ if (IsCompressionEnabled()) {
+ GTEST_SKIP() << "No overflow bit set for userspace COWs";
+ }
+
const auto actual_write_size = GetSize(sys_);
const auto declared_write_size = actual_write_size - 1_MiB;
@@ -1743,12 +1748,15 @@
auto userdata = std::make_unique<LowSpaceUserdata>();
ASSERT_TRUE(userdata->Init(kMaxFree));
- // Grow all partitions to 5_MiB, total 15_MiB. This requires 15 MiB of CoW space. After
- // using the empty space in super (< 1 MiB), it uses at least 14 MiB of /userdata space.
- constexpr uint64_t partition_size = 5_MiB;
+ // Grow all partitions to 10_MiB, total 30_MiB. This requires 30 MiB of CoW space. After
+ // using the empty space in super (< 1 MiB), it uses 30 MiB of /userdata space.
+ constexpr uint64_t partition_size = 10_MiB;
SetSize(sys_, partition_size);
SetSize(vnd_, partition_size);
SetSize(prd_, partition_size);
+ sys_->set_estimate_cow_size(partition_size);
+ vnd_->set_estimate_cow_size(partition_size);
+ prd_->set_estimate_cow_size(partition_size);
AddOperationForPartitions();
@@ -1758,7 +1766,7 @@
ASSERT_FALSE(res);
ASSERT_EQ(Return::ErrorCode::NO_SPACE, res.error_code());
ASSERT_GE(res.required_size(), 14_MiB);
- ASSERT_LT(res.required_size(), 15_MiB);
+ ASSERT_LT(res.required_size(), 40_MiB);
}
class AutoKill final {
diff --git a/fs_mgr/libsnapshot/snapuserd.cpp b/fs_mgr/libsnapshot/snapuserd.cpp
index 573b6a5..9ad4a1a 100644
--- a/fs_mgr/libsnapshot/snapuserd.cpp
+++ b/fs_mgr/libsnapshot/snapuserd.cpp
@@ -324,8 +324,7 @@
reinterpret_cast<struct disk_exception*>((char*)unmerged_buffer + offset);
// Unmerged op by the kernel
- if (merged_de->old_chunk != 0) {
- CHECK(merged_de->new_chunk != 0);
+ if (merged_de->old_chunk != 0 || merged_de->new_chunk != 0) {
CHECK(merged_de->old_chunk == cow_de->old_chunk);
CHECK(merged_de->new_chunk == cow_de->new_chunk);
@@ -334,11 +333,6 @@
continue;
}
- // Merge complete on this exception. However, we don't know how many
- // merged in this cycle; hence break here.
- CHECK(merged_de->new_chunk == 0);
- CHECK(merged_de->old_chunk == 0);
-
break;
}
diff --git a/fs_mgr/libsnapshot/update_engine/update_metadata.proto b/fs_mgr/libsnapshot/update_engine/update_metadata.proto
index dda214e..4a97f81 100644
--- a/fs_mgr/libsnapshot/update_engine/update_metadata.proto
+++ b/fs_mgr/libsnapshot/update_engine/update_metadata.proto
@@ -73,6 +73,7 @@
message DynamicPartitionMetadata {
repeated DynamicPartitionGroup groups = 1;
+ optional bool vabc_enabled = 3;
}
message DeltaArchiveManifest {
diff --git a/fs_mgr/libsnapshot/utility.cpp b/fs_mgr/libsnapshot/utility.cpp
index 7342fd4..4a2af1c 100644
--- a/fs_mgr/libsnapshot/utility.cpp
+++ b/fs_mgr/libsnapshot/utility.cpp
@@ -187,5 +187,13 @@
return android::base::GetBoolProperty("ro.virtual_ab.compression.enabled", false);
}
+std::string GetOtherPartitionName(const std::string& name) {
+ auto suffix = android::fs_mgr::GetPartitionSlotSuffix(name);
+ CHECK(suffix == "_a" || suffix == "_b");
+
+ auto other_suffix = (suffix == "_a") ? "_b" : "_a";
+ return name.substr(0, name.size() - suffix.size()) + other_suffix;
+}
+
} // namespace snapshot
} // namespace android
diff --git a/fs_mgr/libsnapshot/utility.h b/fs_mgr/libsnapshot/utility.h
index 3e6873b..671de9d 100644
--- a/fs_mgr/libsnapshot/utility.h
+++ b/fs_mgr/libsnapshot/utility.h
@@ -131,5 +131,8 @@
bool IsCompressionEnabled();
+// Swap the suffix of a partition name.
+std::string GetOtherPartitionName(const std::string& name);
+
} // namespace snapshot
} // namespace android
diff --git a/fs_mgr/libvbmeta/Android.bp b/fs_mgr/libvbmeta/Android.bp
index bceabab..a299b6e 100644
--- a/fs_mgr/libvbmeta/Android.bp
+++ b/fs_mgr/libvbmeta/Android.bp
@@ -50,4 +50,11 @@
"avbtool",
"vbmake",
],
-}
\ No newline at end of file
+ data: [
+ "data/*",
+ ],
+ // Not unit tests due to several binary and lib dependencies currently hard to replicate in continuous execution
+ test_options: {
+ unit_test: false,
+ },
+}
diff --git a/fs_mgr/libvbmeta/data/testkey_rsa2048.pem b/fs_mgr/libvbmeta/data/testkey_rsa2048.pem
new file mode 100644
index 0000000..867dcff
--- /dev/null
+++ b/fs_mgr/libvbmeta/data/testkey_rsa2048.pem
@@ -0,0 +1,27 @@
+-----BEGIN RSA PRIVATE KEY-----
+MIIEowIBAAKCAQEAxlVR3TIkouAOvH79vaJTgFhpfvVKQIeVkFRZPVXK/zY0Gvrh
+4JAqGjJoW/PfrQv5sdD36qtHH3a+G5hLZ6Ni+t/mtfjucxZfuLGC3kmJ1T3XqEKZ
+gXXI2IR7vVSoImREvDQGEDyJwtHzLANlkbGg0cghVhWZSCAndO8BenalC2v94/rt
+DfkPekH6dgU3Sf40T0sBSeSY94mOzTaqOR2pfV1rWlLRdWmo33zeHBv52Rlbt0dM
+uXAureXWiHztkm5GCBC1dgM+CaxNtizNEgC91KcD0xuRCCM2WxH+r1lpszyIJDct
+YbrFmVEYl/kjQpafhy7Nsk1fqSTyRdriZSYmTQIDAQABAoIBAQC+kJgaCuX8wYAn
+SXWQ0fmdZlXnMNRpcF0a0pD0SAzGb1RdYBXMaXiqtyhiwc53PPxsCDdNecjayIMd
+jJVXPTwLhTruOgMS/bp3gcgWwV34UHV4LJXGOGAE+jbS0hbDBMiudOYmj6RmVshp
+z9G1zZCSQNMXHaWsEYkX59XpzzoB384nRul2QgEtwzUNR9XlpzgtJBLk3SACkvsN
+mQ/DW8IWHXLg8vLn1LzVJ2e3B16H4MoE2TCHxqfMgr03IDRRJogkenQuQsFhevYT
+o/mJyHSWavVgzMHG9I5m+eepF4Wyhj1Y4WyKAuMI+9dHAX/h7Lt8XFCQCh5DbkVG
+zGr34sWBAoGBAOs7n7YZqNaaguovfIdRRsxxZr1yJAyDsr6w3yGImDZYju4c4WY9
+5esO2kP3FA4p0c7FhQF5oOb1rBuHEPp36cpL4aGeK87caqTfq63WZAujoTZpr9Lp
+BRbkL7w/xG7jpQ/clpA8sHzHGQs/nelxoOtC7E118FiRgvD/jdhlMyL9AoGBANfX
+vyoN1pplfT2xR8QOjSZ+Q35S/+SAtMuBnHx3l0qH2bbBjcvM1MNDWjnRDyaYhiRu
+i+KA7tqfib09+XpB3g5D6Ov7ls/Ldx0S/VcmVWtia2HK8y8iLGtokoBZKQ5AaFX2
+iQU8+tC4h69GnJYQKqNwgCUzh8+gHX5Y46oDiTmRAoGAYpOx8lX+czB8/Da6MNrW
+mIZNT8atZLEsDs2ANEVRxDSIcTCZJId7+m1W+nRoaycLTWNowZ1+2ErLvR10+AGY
+b7Ys79Wg9idYaY9yGn9lnZsMzAiuLeyIvXcSqgjvAKlVWrhOQFOughvNWvFl85Yy
+oWSCMlPiTLtt7CCsCKsgKuECgYBgdIp6GZsIfkgclKe0hqgvRoeU4TR3gcjJlM9A
+lBTo+pKhaBectplx9RxR8AnsPobbqwcaHnIfAuKDzjk5mEvKZjClnFXF4HAHbyAF
+nRzZEy9XkWFhc80T5rRpZO7C7qdxmu2aiKixM3V3L3/0U58qULEDbubHMw9bEhAT
+PudI8QKBgHEEiMm/hr9T41hbQi/LYanWnlFw1ue+osKuF8bXQuxnnHNuFT/c+9/A
+vWhgqG6bOEHu+p/IPrYm4tBMYlwsyh4nXCyGgDJLbLIfzKwKAWCtH9LwnyDVhOow
+GH9shdR+sW3Ew97xef02KAH4VlNANEmBV4sQNqWWvsYrcFm2rOdL
+-----END RSA PRIVATE KEY-----
diff --git a/fs_mgr/libvbmeta/super_vbmeta_test.cpp b/fs_mgr/libvbmeta/super_vbmeta_test.cpp
index daed0d1..7329a61 100644
--- a/fs_mgr/libvbmeta/super_vbmeta_test.cpp
+++ b/fs_mgr/libvbmeta/super_vbmeta_test.cpp
@@ -54,7 +54,7 @@
cmd << "avbtool add_hashtree_footer"
<< " --image " << file_name << " --partition_name " << partition_name
<< " --partition_size " << FAKE_PARTITION_SIZE << " --algorithm SHA256_RSA2048"
- << " --key external/avb/test/data/testkey_rsa2048.pem";
+ << " --key data/testkey_rsa2048.pem";
int rc = system(cmd.str().c_str());
EXPECT_TRUE(WIFEXITED(rc));
diff --git a/fs_mgr/tests/adb-remount-test.sh b/fs_mgr/tests/adb-remount-test.sh
index f5bbe35..2433833 100755
--- a/fs_mgr/tests/adb-remount-test.sh
+++ b/fs_mgr/tests/adb-remount-test.sh
@@ -740,7 +740,7 @@
grep -v \
-e "^\(overlay\|tmpfs\|none\|sysfs\|proc\|selinuxfs\|debugfs\|bpf\) " \
-e "^\(binfmt_misc\|cg2_bpf\|pstore\|tracefs\|adb\|mtp\|ptp\|devpts\) " \
- -e "^\(ramdumpfs\|binder\|/sys/kernel/debug\) " \
+ -e "^\(ramdumpfs\|binder\|/sys/kernel/debug\|securityfs\) " \
-e " functionfs " \
-e "^\(/data/media\|/dev/block/loop[0-9]*\) " \
-e "^rootfs / rootfs rw," \
diff --git a/gatekeeperd/Android.bp b/gatekeeperd/Android.bp
index 27a6452..2d9a820 100644
--- a/gatekeeperd/Android.bp
+++ b/gatekeeperd/Android.bp
@@ -28,6 +28,7 @@
shared_libs: [
"libbinder",
+ "libbinder_ndk",
"libgatekeeper",
"libgsi",
"liblog",
@@ -40,6 +41,8 @@
"libhidlbase",
"android.hardware.gatekeeper@1.0",
"libgatekeeper_aidl",
+ "android.hardware.security.keymint-unstable-ndk_platform",
+ "android.security.authorization-ndk_platform",
],
static_libs: ["libscrypt_static"],
diff --git a/gatekeeperd/gatekeeperd.cpp b/gatekeeperd/gatekeeperd.cpp
index b982dbc..941f8c2 100644
--- a/gatekeeperd/gatekeeperd.cpp
+++ b/gatekeeperd/gatekeeperd.cpp
@@ -19,42 +19,45 @@
#include <android/service/gatekeeper/BnGateKeeperService.h>
#include <gatekeeper/GateKeeperResponse.h>
+#include <endian.h>
#include <errno.h>
#include <fcntl.h>
-#include <inttypes.h>
-#include <stdint.h>
#include <unistd.h>
#include <memory>
-#include <android/security/keystore/IKeystoreService.h>
#include <android-base/logging.h>
#include <android-base/properties.h>
+#include <android/binder_ibinder.h>
+#include <android/binder_manager.h>
+#include <android/security/keystore/IKeystoreService.h>
#include <binder/IPCThreadState.h>
#include <binder/IServiceManager.h>
#include <binder/PermissionCache.h>
-#include <gatekeeper/password_handle.h> // for password_handle_t
-#include <hardware/gatekeeper.h>
+#include <gatekeeper/password_handle.h> // for password_handle_t
#include <hardware/hw_auth_token.h>
-#include <keystore/keystore.h> // For error code
#include <keystore/keystore_return_types.h>
#include <libgsi/libgsi.h>
#include <log/log.h>
-#include <utils/Log.h>
#include <utils/String16.h>
-#include <hidl/HidlSupport.h>
+#include <aidl/android/hardware/security/keymint/HardwareAuthToken.h>
+#include <aidl/android/security/authorization/IKeystoreAuthorization.h>
#include <android/hardware/gatekeeper/1.0/IGatekeeper.h>
+#include <hidl/HidlSupport.h>
using android::sp;
-using android::hardware::gatekeeper::V1_0::IGatekeeper;
-using android::hardware::gatekeeper::V1_0::GatekeeperStatusCode;
-using android::hardware::gatekeeper::V1_0::GatekeeperResponse;
using android::hardware::Return;
+using android::hardware::gatekeeper::V1_0::GatekeeperResponse;
+using android::hardware::gatekeeper::V1_0::GatekeeperStatusCode;
+using android::hardware::gatekeeper::V1_0::IGatekeeper;
using ::android::binder::Status;
using ::android::service::gatekeeper::BnGateKeeperService;
using GKResponse = ::android::service::gatekeeper::GateKeeperResponse;
using GKResponseCode = ::android::service::gatekeeper::ResponseCode;
+using ::aidl::android::hardware::security::keymint::HardwareAuthenticatorType;
+using ::aidl::android::hardware::security::keymint::HardwareAuthToken;
+using ::aidl::android::security::authorization::IKeystoreAuthorization;
namespace android {
@@ -62,7 +65,7 @@
static const String16 DUMP_PERMISSION("android.permission.DUMP");
class GateKeeperProxy : public BnGateKeeperService {
-public:
+ public:
GateKeeperProxy() {
clear_state_if_needed_done = false;
hw_device = IGatekeeper::getService();
@@ -73,8 +76,7 @@
}
}
- virtual ~GateKeeperProxy() {
- }
+ virtual ~GateKeeperProxy() {}
void store_sid(uint32_t userId, uint64_t sid) {
char filename[21];
@@ -96,7 +98,7 @@
if (mark_cold_boot() && !is_running_gsi) {
ALOGI("cold boot: clearing state");
if (hw_device) {
- hw_device->deleteAllUsers([](const GatekeeperResponse &){});
+ hw_device->deleteAllUsers([](const GatekeeperResponse&) {});
}
}
@@ -104,7 +106,7 @@
}
bool mark_cold_boot() {
- const char *filename = ".coldboot";
+ const char* filename = ".coldboot";
if (access(filename, F_OK) == -1) {
int fd = open(filename, O_WRONLY | O_TRUNC | O_CREAT, S_IRUSR | S_IWUSR);
if (fd < 0) {
@@ -299,7 +301,36 @@
if (gkResponse->response_code() == GKResponseCode::OK) {
if (gkResponse->payload().size() != 0) {
+ // try to connect to IKeystoreAuthorization AIDL service first.
+ AIBinder* authzAIBinder =
+ AServiceManager_checkService("android.security.authorization");
+ ::ndk::SpAIBinder authzBinder(authzAIBinder);
+ auto authzService = IKeystoreAuthorization::fromBinder(authzBinder);
+ if (authzService) {
+ if (gkResponse->payload().size() != sizeof(hw_auth_token_t)) {
+ LOG(ERROR) << "Incorrect size of AuthToken payload.";
+ return GK_ERROR;
+ }
+
+ const hw_auth_token_t* hwAuthToken =
+ reinterpret_cast<const hw_auth_token_t*>(gkResponse->payload().data());
+ HardwareAuthToken authToken;
+
+ authToken.timestamp.milliSeconds = betoh64(hwAuthToken->timestamp);
+ authToken.challenge = hwAuthToken->challenge;
+ authToken.authenticatorId = hwAuthToken->authenticator_id;
+ authToken.authenticatorType = static_cast<HardwareAuthenticatorType>(
+ betoh32(hwAuthToken->authenticator_type));
+ authToken.mac.assign(&hwAuthToken->hmac[0], &hwAuthToken->hmac[32]);
+ auto result = authzService->addAuthToken(authToken);
+ if (!result.isOk()) {
+ LOG(ERROR) << "Failure in sending AuthToken to AuthorizationService.";
+ return GK_ERROR;
+ }
+ AIBinder_decStrong(authzAIBinder);
+ }
sp<IServiceManager> sm = defaultServiceManager();
+
sp<IBinder> binder = sm->getService(String16("android.security.keystore"));
sp<security::keystore::IKeystoreService> service =
interface_cast<security::keystore::IKeystoreService>(binder);
@@ -310,9 +341,12 @@
if (!binder_result.isOk() ||
!keystore::KeyStoreServiceReturnCode(result).isOk()) {
LOG(ERROR) << "Failure sending auth token to KeyStore: " << result;
+ return GK_ERROR;
}
} else {
- LOG(ERROR) << "Cannot deliver auth token. Unable to communicate with Keystore.";
+ LOG(ERROR) << "Cannot deliver auth token. Unable to communicate with "
+ "Keystore.";
+ return GK_ERROR;
}
}
@@ -366,23 +400,23 @@
}
if (hw_device == NULL) {
- const char *result = "Device not available";
+ const char* result = "Device not available";
write(fd, result, strlen(result) + 1);
} else {
- const char *result = "OK";
+ const char* result = "OK";
write(fd, result, strlen(result) + 1);
}
return OK;
}
-private:
+ private:
sp<IGatekeeper> hw_device;
bool clear_state_if_needed_done;
bool is_running_gsi;
};
-}// namespace android
+} // namespace android
int main(int argc, char* argv[]) {
ALOGI("Starting gatekeeperd...");
diff --git a/healthd/Android.bp b/healthd/Android.bp
index b3de9c4..251a45b 100644
--- a/healthd/Android.bp
+++ b/healthd/Android.bp
@@ -62,29 +62,6 @@
srcs: [
"HealthServiceDefault.cpp",
],
-
- overrides: [
- "healthd",
- ]
-}
-
-cc_binary {
- name: "healthd",
- defaults: ["android.hardware.health@2.0-service_defaults"],
-
- init_rc: ["healthd.rc"],
- srcs: [
- "HealthServiceHealthd.cpp",
- ],
- local_include_dirs: ["include"],
-
- shared_libs: [
- "android.hardware.health@1.0",
- ],
-
- vintf_fragments: [
- "manifest_healthd.xml"
- ],
}
cc_library_static {
diff --git a/healthd/HealthServiceHealthd.cpp b/healthd/HealthServiceHealthd.cpp
deleted file mode 100644
index 5fd2597..0000000
--- a/healthd/HealthServiceHealthd.cpp
+++ /dev/null
@@ -1,93 +0,0 @@
-/*
- * Copyright (C) 2017 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.
- */
-
-#define LOG_TAG "healthd"
-#include <android-base/logging.h>
-
-#include <android/hardware/health/1.0/IHealth.h>
-#include <android/hardware/health/1.0/types.h>
-#include <hal_conversion.h>
-#include <health2/service.h>
-#include <healthd/healthd.h>
-#include <hidl/HidlTransportSupport.h>
-
-using android::OK;
-using android::NAME_NOT_FOUND;
-using android::hardware::health::V1_0::HealthConfig;
-using android::hardware::health::V1_0::HealthInfo;
-using android::hardware::health::V1_0::Result;
-using android::hardware::health::V1_0::hal_conversion::convertFromHealthConfig;
-using android::hardware::health::V1_0::hal_conversion::convertToHealthConfig;
-using android::hardware::health::V1_0::hal_conversion::convertFromHealthInfo;
-using android::hardware::health::V1_0::hal_conversion::convertToHealthInfo;
-
-using IHealthLegacy = android::hardware::health::V1_0::IHealth;
-
-static android::sp<IHealthLegacy> gHealth_1_0;
-
-static int healthd_board_get_energy_counter(int64_t* energy) {
- if (gHealth_1_0 == nullptr) {
- return NAME_NOT_FOUND;
- }
-
- Result result = Result::NOT_SUPPORTED;
- gHealth_1_0->energyCounter([energy, &result](Result ret, int64_t energyOut) {
- result = ret;
- *energy = energyOut;
- });
-
- return result == Result::SUCCESS ? OK : NAME_NOT_FOUND;
-}
-
-void healthd_board_init(struct healthd_config* config) {
- gHealth_1_0 = IHealthLegacy::getService();
-
- if (gHealth_1_0 == nullptr) {
- return;
- }
-
- HealthConfig halConfig{};
- convertToHealthConfig(config, halConfig);
- gHealth_1_0->init(halConfig, [config](const auto& halConfigOut) {
- convertFromHealthConfig(halConfigOut, config);
- // always redirect energy counter queries
- config->energyCounter = healthd_board_get_energy_counter;
- });
- LOG(INFO) << LOG_TAG << ": redirecting calls to 1.0 health HAL";
-}
-
-// TODO(b/68724651): Move this function into healthd_mode_service_2_0_battery_update
-// with logthis returned.
-int healthd_board_battery_update(struct android::BatteryProperties* props) {
- int logthis = 0;
-
- if (gHealth_1_0 == nullptr) {
- return logthis;
- }
-
- HealthInfo info;
- convertToHealthInfo(props, info);
- gHealth_1_0->update(info, [props, &logthis](int32_t ret, const auto& infoOut) {
- logthis = ret;
- convertFromHealthInfo(infoOut, props);
- });
-
- return logthis;
-}
-
-int main() {
- return health_service_main("backup");
-}
diff --git a/healthd/manifest_healthd.xml b/healthd/manifest_healthd.xml
deleted file mode 100644
index 097a7d8..0000000
--- a/healthd/manifest_healthd.xml
+++ /dev/null
@@ -1,11 +0,0 @@
-<manifest version="1.0" type="framework">
- <hal>
- <name>android.hardware.health</name>
- <transport>hwbinder</transport>
- <version>2.0</version>
- <interface>
- <name>IHealth</name>
- <instance>backup</instance>
- </interface>
- </hal>
-</manifest>
diff --git a/init/README.md b/init/README.md
index bcbbfbb..67d55e1 100644
--- a/init/README.md
+++ b/init/README.md
@@ -178,6 +178,8 @@
will reboot into _fatal reboot target_.
The default value of _fatal crash window mins_ is 4, and default value
of _fatal reboot target_ is 'bootloader'.
+ For tests, the fatal reboot can be skipped by setting property
+ `init.svc_debug.no_fatal.<service-name>` to `true` for specified critical service.
`disabled`
> This service will not automatically start with its class.
diff --git a/init/first_stage_init.cpp b/init/first_stage_init.cpp
index 6954c03..f01a6c0 100644
--- a/init/first_stage_init.cpp
+++ b/init/first_stage_init.cpp
@@ -286,7 +286,11 @@
}
}
+
if (want_console == FirstStageConsoleParam::CONSOLE_ON_FAILURE) {
+ if (!DoCreateDevices()) {
+ LOG(ERROR) << "Failed to create device nodes early";
+ }
StartConsole(cmdline);
}
@@ -327,7 +331,7 @@
}
}
- if (!DoFirstStageMount()) {
+ if (!DoFirstStageMount(want_console != FirstStageConsoleParam::CONSOLE_ON_FAILURE)) {
LOG(FATAL) << "Failed to mount required partitions early ...";
}
diff --git a/init/first_stage_mount.cpp b/init/first_stage_mount.cpp
index 7c46281..de72f23 100644
--- a/init/first_stage_mount.cpp
+++ b/init/first_stage_mount.cpp
@@ -82,6 +82,7 @@
// The factory method to create either FirstStageMountVBootV1 or FirstStageMountVBootV2
// based on device tree configurations.
static std::unique_ptr<FirstStageMount> Create();
+ bool DoCreateDevices(); // Creates devices and logical partitions from storage devices
bool DoFirstStageMount(); // Mounts fstab entries read from device tree.
bool InitDevices();
@@ -244,6 +245,28 @@
}
}
+bool FirstStageMount::DoCreateDevices() {
+ if (!InitDevices()) return false;
+
+ // Mount /metadata before creating logical partitions, since we need to
+ // know whether a snapshot merge is in progress.
+ auto metadata_partition = std::find_if(fstab_.begin(), fstab_.end(), [](const auto& entry) {
+ return entry.mount_point == "/metadata";
+ });
+ if (metadata_partition != fstab_.end()) {
+ if (MountPartition(metadata_partition, true /* erase_same_mounts */)) {
+ // Copies DSU AVB keys from the ramdisk to /metadata.
+ // Must be done before the following TrySwitchSystemAsRoot().
+ // Otherwise, ramdisk will be inaccessible after switching root.
+ CopyDsuAvbKeys();
+ }
+ }
+
+ if (!CreateLogicalPartitions()) return false;
+
+ return true;
+}
+
bool FirstStageMount::DoFirstStageMount() {
if (!IsDmLinearEnabled() && fstab_.empty()) {
// Nothing to mount.
@@ -251,8 +274,6 @@
return true;
}
- if (!InitDevices()) return false;
-
if (!MountPartitions()) return false;
return true;
@@ -505,22 +526,6 @@
}
bool FirstStageMount::MountPartitions() {
- // Mount /metadata before creating logical partitions, since we need to
- // know whether a snapshot merge is in progress.
- auto metadata_partition = std::find_if(fstab_.begin(), fstab_.end(), [](const auto& entry) {
- return entry.mount_point == "/metadata";
- });
- if (metadata_partition != fstab_.end()) {
- if (MountPartition(metadata_partition, true /* erase_same_mounts */)) {
- // Copies DSU AVB keys from the ramdisk to /metadata.
- // Must be done before the following TrySwitchSystemAsRoot().
- // Otherwise, ramdisk will be inaccessible after switching root.
- CopyDsuAvbKeys();
- }
- }
-
- if (!CreateLogicalPartitions()) return false;
-
if (!TrySwitchSystemAsRoot()) return false;
if (!SkipMountingPartitions(&fstab_)) return false;
@@ -829,8 +834,18 @@
// Public functions
// ----------------
+// Creates devices and logical partitions from storage devices
+bool DoCreateDevices() {
+ std::unique_ptr<FirstStageMount> handle = FirstStageMount::Create();
+ if (!handle) {
+ LOG(ERROR) << "Failed to create FirstStageMount";
+ return false;
+ }
+ return handle->DoCreateDevices();
+}
+
// Mounts partitions specified by fstab in device tree.
-bool DoFirstStageMount() {
+bool DoFirstStageMount(bool create_devices) {
// Skips first stage mount if we're in recovery mode.
if (IsRecoveryMode()) {
LOG(INFO) << "First stage mount skipped (recovery mode)";
@@ -842,6 +857,11 @@
LOG(ERROR) << "Failed to create FirstStageMount";
return false;
}
+
+ if (create_devices) {
+ if (!handle->DoCreateDevices()) return false;
+ }
+
return handle->DoFirstStageMount();
}
diff --git a/init/first_stage_mount.h b/init/first_stage_mount.h
index 21d87fd..2f4e663 100644
--- a/init/first_stage_mount.h
+++ b/init/first_stage_mount.h
@@ -19,7 +19,8 @@
namespace android {
namespace init {
-bool DoFirstStageMount();
+bool DoCreateDevices();
+bool DoFirstStageMount(bool create_devices);
void SetInitAvbVersionInRecovery();
} // namespace init
diff --git a/init/property_service.cpp b/init/property_service.cpp
index 64d4edc..ce67386 100644
--- a/init/property_service.cpp
+++ b/init/property_service.cpp
@@ -890,6 +890,69 @@
}
}
+// If the ro.product.cpu.abilist* properties have not been explicitly
+// set, derive them from ro.${partition}.product.cpu.abilist* properties.
+static void property_initialize_ro_cpu_abilist() {
+ // From high to low priority.
+ const char* kAbilistSources[] = {
+ "product",
+ "odm",
+ "vendor",
+ "system",
+ };
+ const std::string EMPTY = "";
+ const char* kAbilistProp = "ro.product.cpu.abilist";
+ const char* kAbilist32Prop = "ro.product.cpu.abilist32";
+ const char* kAbilist64Prop = "ro.product.cpu.abilist64";
+
+ // If the properties are defined explicitly, just use them.
+ if (GetProperty(kAbilistProp, EMPTY) != EMPTY) {
+ return;
+ }
+
+ // Find the first source defining these properties by order.
+ std::string abilist32_prop_val;
+ std::string abilist64_prop_val;
+ for (const auto& source : kAbilistSources) {
+ const auto abilist32_prop = std::string("ro.") + source + ".product.cpu.abilist32";
+ const auto abilist64_prop = std::string("ro.") + source + ".product.cpu.abilist64";
+ abilist32_prop_val = GetProperty(abilist32_prop, EMPTY);
+ abilist64_prop_val = GetProperty(abilist64_prop, EMPTY);
+ // The properties could be empty on 32-bit-only or 64-bit-only devices,
+ // but we cannot identify a property is empty or undefined by GetProperty().
+ // So, we assume both of these 2 properties are empty as undefined.
+ if (abilist32_prop_val != EMPTY || abilist64_prop_val != EMPTY) {
+ break;
+ }
+ }
+
+ // Merge ABI lists for ro.product.cpu.abilist
+ auto abilist_prop_val = abilist64_prop_val;
+ if (abilist32_prop_val != EMPTY) {
+ if (abilist_prop_val != EMPTY) {
+ abilist_prop_val += ",";
+ }
+ abilist_prop_val += abilist32_prop_val;
+ }
+
+ // Set these properties
+ const std::pair<const char*, const std::string&> set_prop_list[] = {
+ {kAbilistProp, abilist_prop_val},
+ {kAbilist32Prop, abilist32_prop_val},
+ {kAbilist64Prop, abilist64_prop_val},
+ };
+ for (const auto& [prop, prop_val] : set_prop_list) {
+ LOG(INFO) << "Setting property '" << prop << "' to '" << prop_val << "'";
+
+ std::string error;
+ uint32_t res = PropertySet(prop, prop_val, &error);
+ if (res != PROP_SUCCESS) {
+ LOG(ERROR) << "Error setting property '" << prop << "': err=" << res << " (" << error
+ << ")";
+ }
+ }
+}
+
void PropertyLoadBootDefaults() {
// We read the properties and their values into a map, in order to always allow properties
// loaded in the later property files to override the properties in loaded in the earlier
@@ -972,6 +1035,7 @@
property_initialize_ro_product_props();
property_derive_build_fingerprint();
+ property_initialize_ro_cpu_abilist();
update_sys_usb_config();
}
diff --git a/init/service.cpp b/init/service.cpp
index d84dcd4..f6ce094 100644
--- a/init/service.cpp
+++ b/init/service.cpp
@@ -52,6 +52,7 @@
#endif
using android::base::boot_clock;
+using android::base::GetBoolProperty;
using android::base::GetProperty;
using android::base::Join;
using android::base::make_scope_guard;
@@ -318,17 +319,19 @@
// reboot into bootloader or set crashing property
boot_clock::time_point now = boot_clock::now();
if (((flags_ & SVC_CRITICAL) || is_process_updatable) && !(flags_ & SVC_RESTART)) {
- bool boot_completed = android::base::GetBoolProperty("sys.boot_completed", false);
+ bool boot_completed = GetBoolProperty("sys.boot_completed", false);
if (now < time_crashed_ + fatal_crash_window_ || !boot_completed) {
if (++crash_count_ > 4) {
auto exit_reason = boot_completed ?
"in " + std::to_string(fatal_crash_window_.count()) + " minutes" :
"before boot completed";
if (flags_ & SVC_CRITICAL) {
- // Aborts into `fatal_reboot_target_'.
- SetFatalRebootTarget(fatal_reboot_target_);
- LOG(FATAL) << "critical process '" << name_ << "' exited 4 times "
- << exit_reason;
+ if (!GetBoolProperty("init.svc_debug.no_fatal." + name_, false)) {
+ // Aborts into `fatal_reboot_target_'.
+ SetFatalRebootTarget(fatal_reboot_target_);
+ LOG(FATAL) << "critical process '" << name_ << "' exited 4 times "
+ << exit_reason;
+ }
} else {
LOG(ERROR) << "process with updatable components '" << name_
<< "' exited 4 times " << exit_reason;
diff --git a/libcutils/Android.bp b/libcutils/Android.bp
index cf809f1..d46aeab 100644
--- a/libcutils/Android.bp
+++ b/libcutils/Android.bp
@@ -210,9 +210,6 @@
"uevent.cpp",
],
},
- bionic: {
- header_libs: ["bionic_libc_platform_headers"],
- },
android_arm: {
sanitize: {
diff --git a/libcutils/memory.cpp b/libcutils/memory.cpp
index f526520..5a410c2 100644
--- a/libcutils/memory.cpp
+++ b/libcutils/memory.cpp
@@ -18,19 +18,18 @@
#include <log/log.h>
-#ifdef __BIONIC__
-#include <bionic/malloc.h>
+#if !defined(__APPLE__)
+#include <malloc.h>
#endif
void process_disable_memory_mitigations() {
bool success = false;
#ifdef __BIONIC__
- // TODO(b/158870657) is fixed and scudo is used globally, we can assert when an
- // an error is returned.
-
- success = android_mallopt(M_DISABLE_MEMORY_MITIGATIONS, nullptr, 0);
+ success = mallopt(M_BIONIC_DISABLE_MEMORY_MITIGATIONS, 0);
#endif
+ // TODO: if b/158870657 is fixed and scudo is used globally,
+ // we can assert on failure rather than just log.
if (success) {
ALOGI("Disabled memory mitigations for process.");
} else {
diff --git a/libprocessgroup/cgroup_map.cpp b/libprocessgroup/cgroup_map.cpp
index b82b0ab..5ca0967 100644
--- a/libprocessgroup/cgroup_map.cpp
+++ b/libprocessgroup/cgroup_map.cpp
@@ -71,7 +71,7 @@
if (!HasValue()) return false;
if (state_ == UNKNOWN) {
- if (ACgroupController_getFlags != nullptr) {
+ if (__builtin_available(android 30, *)) {
uint32_t flags = ACgroupController_getFlags(controller_);
state_ = (flags & CGROUPRC_CONTROLLER_FLAG_MOUNTED) != 0 ? USABLE : MISSING;
} else {
@@ -172,7 +172,7 @@
auto controller_count = ACgroupFile_getControllerCount();
for (uint32_t i = 0; i < controller_count; ++i) {
const ACgroupController* controller = ACgroupFile_getController(i);
- if (ACgroupController_getFlags != nullptr) {
+ if (__builtin_available(android 30, *)) {
LOG(INFO) << "\t" << ACgroupController_getName(controller) << " ver "
<< ACgroupController_getVersion(controller) << " path "
<< ACgroupController_getPath(controller) << " flags "
diff --git a/libprocessgroup/cgrouprc/include/android/cgrouprc.h b/libprocessgroup/cgrouprc/include/android/cgrouprc.h
index 7e74432..9a79954 100644
--- a/libprocessgroup/cgrouprc/include/android/cgrouprc.h
+++ b/libprocessgroup/cgrouprc/include/android/cgrouprc.h
@@ -28,8 +28,6 @@
struct ACgroupController;
typedef struct ACgroupController ACgroupController;
-#if __ANDROID_API__ >= __ANDROID_API_Q__
-
// ACgroupFile
/**
@@ -71,8 +69,6 @@
#define CGROUPRC_CONTROLLER_FLAG_MOUNTED 0x1
#define CGROUPRC_CONTROLLER_FLAG_NEEDS_ACTIVATION 0x2
-#if __ANDROID_API__ >= __ANDROID_API_R__
-
/**
* Returns the flags bitmask of the given controller.
* If the given controller is null, return 0.
@@ -80,8 +76,6 @@
__attribute__((warn_unused_result, weak)) uint32_t ACgroupController_getFlags(
const ACgroupController*) __INTRODUCED_IN(30);
-#endif
-
/**
* Returns the name of the given controller.
* If the given controller is null, return nullptr.
@@ -97,5 +91,3 @@
__INTRODUCED_IN(29);
__END_DECLS
-
-#endif
diff --git a/libsync/include/ndk/sync.h b/libsync/include/ndk/sync.h
index 2a59e35..38ccb68 100644
--- a/libsync/include/ndk/sync.h
+++ b/libsync/include/ndk/sync.h
@@ -33,8 +33,6 @@
__BEGIN_DECLS
-#if __ANDROID_API__ >= 26
-
/* Fences indicate the status of an asynchronous task. They are initially
* in unsignaled state (0), and make a one-time transition to either signaled
* (1) or error (< 0) state. A sync file is a collection of one or more fences;
@@ -101,8 +99,6 @@
*/
void sync_file_info_free(struct sync_file_info* info) __INTRODUCED_IN(26);
-#endif /* __ANDROID_API__ >= 26 */
-
__END_DECLS
#endif /* ANDROID_SYNC_H */
diff --git a/rootdir/init.rc b/rootdir/init.rc
index 049301d..21a78c1 100644
--- a/rootdir/init.rc
+++ b/rootdir/init.rc
@@ -749,6 +749,11 @@
mkdir /data/app 0771 system system encryption=Require
mkdir /data/property 0700 root root encryption=Require
+ # create directory for updated font files.
+ mkdir /data/fonts/ 0771 root root encryption=Require
+ mkdir /data/fonts/files 0771 system system
+ mkdir /data/fonts/config 0770 system system
+
# Create directories to push tests to for each linker namespace.
# Create the subdirectories in case the first test is run as root
# so it doesn't end up owned by root.
@@ -856,13 +861,6 @@
wait_for_prop apexd.status activated
perform_apex_config
- # Lock the fs-verity keyring, so no more keys can be added
- exec -- /system/bin/fsverity_init --lock
-
- # After apexes are mounted, tell keymaster early boot has ended, so it will
- # stop allowing use of early-boot keys
- exec - system system -- /system/bin/vdc keymaster earlyBootEnded
-
# Special-case /data/media/obb per b/64566063
mkdir /data/media 0770 media_rw media_rw encryption=None
exec - media_rw media_rw -- /system/bin/chattr +F /data/media
@@ -872,15 +870,22 @@
init_user0
+ # Set SELinux security contexts on upgrade or policy update.
+ restorecon --recursive --skip-ce /data
+
+ # After apexes are mounted, tell keymaster early boot has ended, so it will
+ # stop allowing use of early-boot keys
+ exec - system system -- /system/bin/vdc keymaster earlyBootEnded
+
+ # Lock the fs-verity keyring, so no more keys can be added
+ exec -- /system/bin/fsverity_init --lock
+
# Allow apexd to snapshot and restore device encrypted apex data in the case
# of a rollback. This should be done immediately after DE_user data keys
# are loaded. APEXes should not access this data until this has been
# completed and apexd.status becomes "ready".
exec_start apexd-snapshotde
- # Set SELinux security contexts on upgrade or policy update.
- restorecon --recursive --skip-ce /data
-
# Check any timezone data in /data is newer than the copy in the time zone data
# module, delete if not.
exec - system system -- /system/bin/tzdatacheck /apex/com.android.tzdata/etc/tz /data/misc/zoneinfo
diff --git a/rootdir/ueventd.rc b/rootdir/ueventd.rc
index 64a64d2..aebcd5f 100644
--- a/rootdir/ueventd.rc
+++ b/rootdir/ueventd.rc
@@ -77,3 +77,5 @@
/sys/devices/virtual/usb_composite/* enable 0664 root system
/sys/devices/system/cpu/cpu* cpufreq/scaling_max_freq 0664 system system
/sys/devices/system/cpu/cpu* cpufreq/scaling_min_freq 0664 system system
+/sys/devices/virtual/misc/uhid/*/leds/* brightness 0664 system system
+/sys/devices/virtual/misc/uhid/*/leds/* multi_intensity 0664 system system
diff --git a/trusty/confirmationui/fuzz/fuzz.cpp b/trusty/confirmationui/fuzz/fuzz.cpp
index 9d3008b..df2517c 100644
--- a/trusty/confirmationui/fuzz/fuzz.cpp
+++ b/trusty/confirmationui/fuzz/fuzz.cpp
@@ -14,10 +14,7 @@
* limitations under the License.
*/
-#undef NDEBUG
-
-#include <assert.h>
-#include <log/log.h>
+#include <iostream>
#include <stdlib.h>
#include <trusty/coverage/coverage.h>
#include <trusty/fuzz/counters.h>
@@ -30,6 +27,7 @@
#define TIPC_DEV "/dev/trusty-ipc-dev0"
#define CONFIRMATIONUI_PORT "com.android.trusty.confirmationui"
+#define CONFIRMATIONUI_MODULE_NAME "confirmationui.syms.elf"
/* ConfirmationUI TA's UUID is 7dee2364-c036-425b-b086-df0f6c233c1b */
static struct uuid confirmationui_uuid = {
@@ -48,11 +46,14 @@
uint8_t payload[];
};
-static CoverageRecord record(TIPC_DEV, &confirmationui_uuid);
+static CoverageRecord record(TIPC_DEV, &confirmationui_uuid, CONFIRMATIONUI_MODULE_NAME);
extern "C" int LLVMFuzzerInitialize(int* /* argc */, char*** /* argv */) {
auto ret = record.Open();
- assert(ret.ok());
+ if (!ret.ok()) {
+ std::cerr << ret.error() << std::endl;
+ exit(-1);
+ }
return 0;
}
diff --git a/trusty/coverage/Android.bp b/trusty/coverage/Android.bp
index 6038d44..daa6f03 100644
--- a/trusty/coverage/Android.bp
+++ b/trusty/coverage/Android.bp
@@ -28,6 +28,7 @@
shared_libs: [
"libbase",
"liblog",
+ "libdmabufheap",
],
}
@@ -43,6 +44,7 @@
shared_libs: [
"libbase",
"liblog",
+ "libdmabufheap",
],
require_root: true,
}
diff --git a/trusty/coverage/coverage.cpp b/trusty/coverage/coverage.cpp
index f383dd1..5eccdc5 100644
--- a/trusty/coverage/coverage.cpp
+++ b/trusty/coverage/coverage.cpp
@@ -16,10 +16,12 @@
#define LOG_TAG "coverage"
+#include <BufferAllocator/BufferAllocator.h>
#include <android-base/file.h>
#include <android-base/logging.h>
#include <android-base/unique_fd.h>
#include <assert.h>
+#include <log/log.h>
#include <stdio.h>
#include <sys/mman.h>
#include <sys/uio.h>
@@ -37,6 +39,8 @@
using android::base::ErrnoError;
using android::base::Error;
using std::string;
+using std::to_string;
+using std::unique_ptr;
static inline uintptr_t RoundPageUp(uintptr_t val) {
return (val + (PAGE_SIZE - 1)) & ~(PAGE_SIZE - 1);
@@ -46,12 +50,29 @@
: tipc_dev_(std::move(tipc_dev)),
coverage_srv_fd_(-1),
uuid_(*uuid),
+ sancov_filename_(),
+ record_len_(0),
+ shm_(NULL),
+ shm_len_(0) {}
+
+CoverageRecord::CoverageRecord(string tipc_dev, struct uuid* uuid, string module_name)
+ : tipc_dev_(std::move(tipc_dev)),
+ coverage_srv_fd_(-1),
+ uuid_(*uuid),
+ sancov_filename_(module_name + "." + to_string(getpid()) + ".sancov"),
record_len_(0),
shm_(NULL),
shm_len_(0) {}
CoverageRecord::~CoverageRecord() {
if (shm_) {
+ if (sancov_filename_) {
+ auto res = SaveSancovFile(*sancov_filename_);
+ if (!res.ok()) {
+ ALOGE("Could not write sancov file for module: %s\n", sancov_filename_->c_str());
+ }
+ }
+
munmap((void*)shm_, shm_len_);
}
}
@@ -114,24 +135,23 @@
record_len_ = resp.open_args.record_len;
shm_len_ = RoundPageUp(record_len_);
- fd = memfd_create("trusty-coverage", 0);
+ BufferAllocator allocator;
+
+ fd = allocator.Alloc("system", shm_len_);
if (fd < 0) {
- return ErrnoError() << "failed to create memfd: ";
+ return ErrnoError() << "failed to create dmabuf of size " << shm_len_
+ << " err code: " << fd;
}
- unique_fd memfd(fd);
+ unique_fd dma_buf(fd);
- if (ftruncate(memfd, shm_len_) < 0) {
- return ErrnoError() << "failed to resize memfd: ";
- }
-
- void* shm = mmap(0, shm_len_, PROT_READ | PROT_WRITE, MAP_SHARED, memfd, 0);
+ void* shm = mmap(0, shm_len_, PROT_READ | PROT_WRITE, MAP_SHARED, dma_buf, 0);
if (shm == MAP_FAILED) {
return ErrnoError() << "failed to map memfd: ";
}
req.hdr.cmd = COVERAGE_CLIENT_CMD_SHARE_RECORD;
req.share_record_args.shm_len = shm_len_;
- ret = Rpc(&req, memfd, &resp);
+ ret = Rpc(&req, dma_buf, &resp);
if (!ret.ok()) {
return Error() << "failed to send shared memory: ";
}
diff --git a/trusty/coverage/include/trusty/coverage/coverage.h b/trusty/coverage/include/trusty/coverage/coverage.h
index b6d46eb..5da68da 100644
--- a/trusty/coverage/include/trusty/coverage/coverage.h
+++ b/trusty/coverage/include/trusty/coverage/coverage.h
@@ -16,6 +16,7 @@
#pragma once
+#include <optional>
#include <string>
#include <android-base/result.h>
@@ -32,7 +33,18 @@
class CoverageRecord {
public:
+ /**
+ * Create a coverage record interface. Coverage will not be written to a
+ * sancov output file on completion.
+ */
CoverageRecord(std::string tipc_dev, struct uuid* uuid);
+
+ /**
+ * Create a coverage record interface. On destruction, write this coverage
+ * to the given sancov filename.
+ */
+ CoverageRecord(std::string tipc_dev, struct uuid* uuid, std::string module_name);
+
~CoverageRecord();
Result<void> Open();
void ResetFullRecord();
@@ -58,6 +70,7 @@
std::string tipc_dev_;
unique_fd coverage_srv_fd_;
struct uuid uuid_;
+ std::optional<std::string> sancov_filename_;
size_t record_len_;
volatile void* shm_;
size_t shm_len_;
diff --git a/trusty/fuzz/counters.cpp b/trusty/fuzz/counters.cpp
index 8c79475..1e863ac 100644
--- a/trusty/fuzz/counters.cpp
+++ b/trusty/fuzz/counters.cpp
@@ -21,6 +21,7 @@
#include <trusty/fuzz/counters.h>
#include <android-base/logging.h>
+#include <log/log.h>
#include <trusty/coverage/coverage.h>
#include <trusty/coverage/tipc.h>
@@ -32,7 +33,8 @@
* We don't know how many counters the coverage record will contain. So, eyeball
* the size of this section.
*/
-__attribute__((section("__libfuzzer_extra_counters"))) volatile uint8_t counters[PAGE_SIZE];
+static const size_t kMaxNumCounters = 0x4000;
+__attribute__((section("__libfuzzer_extra_counters"))) volatile uint8_t counters[kMaxNumCounters];
namespace android {
namespace trusty {
@@ -62,8 +64,16 @@
volatile uint8_t* end = NULL;
record_->GetRawCounts(&begin, &end);
+ if (!begin || !end) {
+ ALOGE("Could not get raw counts from coverage record\n");
+ return;
+ }
size_t num_counters = end - begin;
+ if (num_counters > kMaxNumCounters) {
+ ALOGE("Too many counters (%zu) to fit in the extra counters section!\n", num_counters);
+ num_counters = kMaxNumCounters;
+ }
for (size_t i = 0; i < num_counters; i++) {
*(counters + i) = *(begin + i);
}
diff --git a/trusty/fuzz/test/fuzz.cpp b/trusty/fuzz/test/fuzz.cpp
index 28bb3f7..e7913db 100644
--- a/trusty/fuzz/test/fuzz.cpp
+++ b/trusty/fuzz/test/fuzz.cpp
@@ -14,15 +14,12 @@
* limitations under the License.
*/
-#undef NDEBUG
-
-#include <assert.h>
-#include <log/log.h>
#include <stdlib.h>
#include <trusty/coverage/coverage.h>
#include <trusty/fuzz/counters.h>
#include <trusty/fuzz/utils.h>
#include <unistd.h>
+#include <iostream>
using android::trusty::coverage::CoverageRecord;
using android::trusty::fuzz::ExtraCounters;
@@ -43,7 +40,10 @@
extern "C" int LLVMFuzzerInitialize(int* /* argc */, char*** /* argv */) {
auto ret = record.Open();
- assert(ret.ok());
+ if (!ret.ok()) {
+ std::cerr << ret.error() << std::endl;
+ exit(-1);
+ }
return 0;
}
diff --git a/trusty/gatekeeper/fuzz/fuzz.cpp b/trusty/gatekeeper/fuzz/fuzz.cpp
index c0e8abb..7bfd7d1 100644
--- a/trusty/gatekeeper/fuzz/fuzz.cpp
+++ b/trusty/gatekeeper/fuzz/fuzz.cpp
@@ -14,15 +14,12 @@
* limitations under the License.
*/
-#undef NDEBUG
-
-#include <assert.h>
-#include <log/log.h>
#include <stdlib.h>
#include <trusty/coverage/coverage.h>
#include <trusty/fuzz/counters.h>
#include <trusty/fuzz/utils.h>
#include <unistd.h>
+#include <iostream>
using android::trusty::coverage::CoverageRecord;
using android::trusty::fuzz::ExtraCounters;
@@ -30,6 +27,7 @@
#define TIPC_DEV "/dev/trusty-ipc-dev0"
#define GATEKEEPER_PORT "com.android.trusty.gatekeeper"
+#define GATEKEEPER_MODULE_NAME "gatekeeper.syms.elf"
/* Gatekeeper TA's UUID is 38ba0cdc-df0e-11e4-9869-233fb6ae4795 */
static struct uuid gatekeeper_uuid = {
@@ -39,11 +37,14 @@
{0x98, 0x69, 0x23, 0x3f, 0xb6, 0xae, 0x47, 0x95},
};
-static CoverageRecord record(TIPC_DEV, &gatekeeper_uuid);
+static CoverageRecord record(TIPC_DEV, &gatekeeper_uuid, GATEKEEPER_MODULE_NAME);
extern "C" int LLVMFuzzerInitialize(int* /* argc */, char*** /* argv */) {
auto ret = record.Open();
- assert(ret.ok());
+ if (!ret.ok()) {
+ std::cerr << ret.error() << std::endl;
+ exit(-1);
+ }
return 0;
}
diff --git a/trusty/keymaster/TrustyKeymaster.cpp b/trusty/keymaster/TrustyKeymaster.cpp
index 5690031..23e0433 100644
--- a/trusty/keymaster/TrustyKeymaster.cpp
+++ b/trusty/keymaster/TrustyKeymaster.cpp
@@ -37,6 +37,12 @@
if (versionRsp.error != KM_ERROR_OK) {
ALOGW("TA appears not to support GetVersion2, falling back (err = %d)", versionRsp.error);
+ err = trusty_keymaster_connect();
+ if (err) {
+ ALOGE("Failed to connect to trusty keymaster %d", err);
+ return err;
+ }
+
GetVersionRequest versionReq;
GetVersionResponse versionRsp;
GetVersion(versionReq, &versionRsp);
diff --git a/deprecated-adf/libadf/tests/Android.bp b/trusty/keymaster/fuzz/Android.bp
similarity index 66%
copy from deprecated-adf/libadf/tests/Android.bp
copy to trusty/keymaster/fuzz/Android.bp
index 9b3430e..da9f9ec 100644
--- a/deprecated-adf/libadf/tests/Android.bp
+++ b/trusty/keymaster/fuzz/Android.bp
@@ -1,23 +1,19 @@
-//
-// Copyright (C) 2013 The Android Open Source Project
+// Copyright (C) 2020 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
+// 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.
-//
-cc_test {
- name: "adf-unit-tests",
- srcs: ["adf_test.cpp"],
- shared_libs: ["libsync"],
- static_libs: ["libadf"],
- cflags: ["-Werror"],
+cc_fuzz {
+ name: "trusty_keymaster_fuzzer",
+ defaults: ["trusty_fuzzer_defaults"],
+ srcs: ["fuzz.cpp"],
}
diff --git a/trusty/keymaster/fuzz/fuzz.cpp b/trusty/keymaster/fuzz/fuzz.cpp
new file mode 100644
index 0000000..4ac97bb
--- /dev/null
+++ b/trusty/keymaster/fuzz/fuzz.cpp
@@ -0,0 +1,76 @@
+/*
+ * Copyright (C) 2020 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.
+ */
+
+#include <stdlib.h>
+#include <trusty/coverage/coverage.h>
+#include <trusty/fuzz/counters.h>
+#include <trusty/fuzz/utils.h>
+#include <unistd.h>
+#include <iostream>
+
+using android::trusty::coverage::CoverageRecord;
+using android::trusty::fuzz::ExtraCounters;
+using android::trusty::fuzz::TrustyApp;
+
+#define TIPC_DEV "/dev/trusty-ipc-dev0"
+#define KEYMASTER_PORT "com.android.trusty.keymaster"
+#define KEYMASTER_MODULE_FILENAME "keymaster.syms.elf"
+
+/* Keymaster TA's UUID is 5f902ace-5e5c-4cd8-ae54-87b88c22ddaf */
+static struct uuid keymaster_uuid = {
+ 0x5f902ace,
+ 0x5e5c,
+ 0x4cd8,
+ {0xae, 0x54, 0x87, 0xb8, 0x8c, 0x22, 0xdd, 0xaf},
+};
+
+static CoverageRecord record(TIPC_DEV, &keymaster_uuid, KEYMASTER_MODULE_FILENAME);
+
+extern "C" int LLVMFuzzerInitialize(int* /* argc */, char*** /* argv */) {
+ auto ret = record.Open();
+ if (!ret.ok()) {
+ std::cerr << ret.error() << std::endl;
+ exit(-1);
+ }
+ return 0;
+}
+
+extern "C" int LLVMFuzzerTestOneInput(const uint8_t* data, size_t size) {
+ static uint8_t buf[TIPC_MAX_MSG_SIZE];
+
+ ExtraCounters counters(&record);
+ counters.Reset();
+
+ android::trusty::fuzz::TrustyApp ta(TIPC_DEV, KEYMASTER_PORT);
+ auto ret = ta.Connect();
+ if (!ret.ok()) {
+ android::trusty::fuzz::Abort();
+ }
+
+ /* Send message to test server */
+ ret = ta.Write(data, size);
+ if (!ret.ok()) {
+ return -1;
+ }
+
+ /* Read message from test server */
+ ret = ta.Read(&buf, sizeof(buf));
+ if (!ret.ok()) {
+ return -1;
+ }
+
+ return 0;
+}
diff --git a/deprecated-adf/libadf/tests/Android.bp b/trusty/secure_dpu/Android.bp
similarity index 72%
rename from deprecated-adf/libadf/tests/Android.bp
rename to trusty/secure_dpu/Android.bp
index 9b3430e..0d57cea 100644
--- a/deprecated-adf/libadf/tests/Android.bp
+++ b/trusty/secure_dpu/Android.bp
@@ -1,5 +1,4 @@
-//
-// Copyright (C) 2013 The Android Open Source Project
+// Copyright (C) 2021 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.
@@ -12,12 +11,10 @@
// 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.
-//
-cc_test {
- name: "adf-unit-tests",
- srcs: ["adf_test.cpp"],
- shared_libs: ["libsync"],
- static_libs: ["libadf"],
- cflags: ["-Werror"],
+cc_library_headers {
+ name: "secure_dpu_headers",
+ vendor: true,
+
+ export_include_dirs: ["include"],
}
diff --git a/trusty/secure_dpu/include/trusty/secure_dpu/SecureDpu.h b/trusty/secure_dpu/include/trusty/secure_dpu/SecureDpu.h
new file mode 100644
index 0000000..b939d44
--- /dev/null
+++ b/trusty/secure_dpu/include/trusty/secure_dpu/SecureDpu.h
@@ -0,0 +1,113 @@
+/*
+ * Copyright 2020, 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.
+ */
+
+#pragma once
+
+#include <stdint.h>
+
+/**
+ * DOC: Secure DPU
+ *
+ * The Secure DPU works as the persistent channel between the non-secure and the
+ * secure world. The channel is established during the boot up stage of the
+ * non-secure world system. In general, the established channel allows the
+ * secure world applications initiate requests or notifications to the non-secure
+ * world.
+ *
+ * For particular devices, the secure world can only perform operations on the
+ * display when in the TUI session if device-specific setup is done by the
+ * non-secure world. Besides, the non-secure world could allocate framebuffer
+ * for the secure world application if the memory is limited in the secure world
+ * on specific devices.
+ *
+ * Currently, supported requests are to start / stop the secure display mode and
+ * to allocate framebuffer.
+ *
+ * This header file needs to be synced on both the Trusty and the Android
+ * codebase.
+ */
+
+#define SECURE_DPU_PORT_NAME "com.android.trusty.secure_dpu"
+#define SECURE_DPU_MAX_MSG_SIZE 64
+
+/**
+ * enum secure_dpu_cmd - command identifiers for secure_fb interface
+ * @SECURE_DPU_CMD_RESP_BIT:
+ * Message is a response.
+ * @SECURE_DPU_CMD_REQ_SHIFT:
+ * Number of bits used by @SECURE_DPU_CMD_RESP_BIT.
+ * @SECURE_DPU_CMD_START_SECURE_DISPLAY:
+ * Notify the system to start secure display mode
+ * @SECURE_DPU_CMD_STOP_SECURE_DISPLAY:
+ * Notify the system to stop secure display mode
+ * @SECURE_DPU_CMD_ALLOCATE_BUFFER:
+ * Request non-secure world to allocate the buffer
+ */
+enum secure_dpu_cmd {
+ SECURE_DPU_CMD_RESP_BIT = 1,
+ SECURE_DPU_CMD_REQ_SHIFT = 1,
+ SECURE_DPU_CMD_START_SECURE_DISPLAY = (1 << SECURE_DPU_CMD_REQ_SHIFT),
+ SECURE_DPU_CMD_STOP_SECURE_DISPLAY = (2 << SECURE_DPU_CMD_REQ_SHIFT),
+ SECURE_DPU_CMD_ALLOCATE_BUFFER = (3 << SECURE_DPU_CMD_REQ_SHIFT),
+};
+
+/**
+ * struct secure_dpu_allocate_buffer_req - payload for
+ * %SECURE_DPU_CMD_ALLOCATE_BUFFER
+ * request
+ * @buffer_len: Requested length
+ */
+struct secure_dpu_allocate_buffer_req {
+ uint64_t buffer_len;
+};
+
+/**
+ * struct secure_dpu_allocate_buffer_resp - payload for
+ * %SECURE_DPU_CMD_ALLOCATE_BUFFER
+ * response
+ * @buffer_len: Allocated length
+ */
+struct secure_dpu_allocate_buffer_resp {
+ uint64_t buffer_len;
+};
+
+/**
+ * struct secure_fb_req - common structure for secure_fb requests.
+ * @cmd: Command identifier - one of &enum secure_dpu_cmd.
+ */
+struct secure_dpu_req {
+ uint32_t cmd;
+};
+
+/**
+ * struct secure_dpu_resp - common structure for secure_dpu responses.
+ * @cmd: Command identifier - %SECURE_DPU_CMD_RESP_BIT or'ed with the
+ * command identifier of the corresponding
+ * request.
+ * @status: Status of requested operation. One of &enum secure_dpu_error.
+ */
+struct secure_dpu_resp {
+ uint32_t cmd;
+ int32_t status;
+};
+
+enum secure_dpu_error {
+ SECURE_DPU_ERROR_OK = 0,
+ SECURE_DPU_ERROR_FAIL = -1,
+ SECURE_DPU_ERROR_UNINITIALIZED = -2,
+ SECURE_DPU_ERROR_PARAMETERS = -3,
+ SECURE_DPU_ERROR_NO_MEMORY = -4,
+};