From bbdbc45eeab1b354967a575814e4b4579c2fac53 Mon Sep 17 00:00:00 2001 From: Konsta Date: Wed, 14 Sep 2022 15:06:12 +0300 Subject: [PATCH] initial Raspberry Vanilla AOSP 12 commit * Audio - Based on AOSP hikey audio HAL: https://android.googlesource.com/device/linaro/hikey/+/refs/heads/master/audio/ - ALSA based on Android-x86 - ALSA loop is used to support HDMI audio on Pi 4 because VC4 HDMI audio devices use SNDRV_PCM_FORMAT_IEC958_SUBFRAME_LE that is not supported on Android https://github.com/raspberrypi/linux/issues/4651 https://github.com/raspberrypi/linux/issues/4654 * Bluetooth - AOSP Broadcom vendor stack with some additional fixes from android-rpi * Camera - libcamera for official Raspberry Pi CSI camera modules based on GloDroid - AOSP external camera HAL for UVC USB webcams: https://source.android.com/docs/core/camera/external-usb-cameras * Graphics - OpenGL & Vulkan: upstream Mesa with GloDroid patches - Upstream drm_hwcomposer with force resolution patch from Android-x86 and my additional fixes - minigbm based on GloDroid * Health - Based on AOSP cuttlefish health HAL * Kernel - Merge of Raspberry Pi and AOSP common kernel with my additional fixes and configurations https://github.com/raspberrypi/linux https://android.googlesource.com/kernel/common/ * Lights - Based on LineageOS Xiaomi msm8996-common lights HAL * suspend_blocker - Based on AOSP cuttlefish * v4l2_codec2 - Based on AOSP with my Raspberry Pi 4 specific fixes * Wifi - AOSP Broadcom vendor stack with my additional fixes --- Android.bp | 6 + AndroidProducts.mk | 11 + BoardConfig.mk | 88 +++ README.md | 1 + aosp_rpi4.mk | 16 + audio/Android.bp | 24 + audio/audio_hw.c | 708 ++++++++++++++++++ audio/audio_policy_configuration.xml | 106 +++ audio/vc4-hdmi.conf | 68 ++ bluetooth/bdroid_buildcfg.h | 12 + bluetooth/vnd_rpi4.txt | 14 + boot/config.txt | 45 ++ camera/camera_hal.yaml | 10 + camera/external_camera_config.xml | 59 ++ camera/media_profiles_V1_0.xml | 190 +++++ compatibility_matrix.xml | 58 ++ device.mk | 266 +++++++ health/Android.bp | 33 + health/HealthService.cpp | 20 + ...android.hardware.health@2.0-service.rpi.rc | 5 + ...ndroid.hardware.health@2.0-service.rpi.xml | 11 + light/Android.bp | 24 + light/Light.cpp | 93 +++ light/Light.h | 56 ++ .../android.hardware.light@2.0-service.rpi.rc | 11 + ...android.hardware.light@2.0-service.rpi.xml | 11 + light/service.cpp | 63 ++ manifest.xml | 101 +++ media/media_codecs.xml | 24 + media/media_codecs_v4l2_c2_video.xml | 106 +++ mkbootimg.mk | 27 + mkimg.sh | 72 ++ overlay/AndroidRpiOverlay/Android.bp | 10 + overlay/AndroidRpiOverlay/AndroidManifest.xml | 19 + .../AndroidRpiOverlay/res/values/config.xml | 114 +++ overlay/SettingsProviderRpiOverlay/Android.bp | 10 + .../AndroidManifest.xml | 19 + .../res/values/defaults.xml | 40 + overlay/SettingsRpiOverlay/Android.bp | 10 + .../SettingsRpiOverlay/AndroidManifest.xml | 19 + .../SettingsRpiOverlay/res/values/config.xml | 30 + overlay/SystemUIRpiOverlay/Android.bp | 10 + .../SystemUIRpiOverlay/AndroidManifest.xml | 19 + .../SystemUIRpiOverlay/res/values/config.xml | 26 + overlay/WifiRpiOverlay/Android.bp | 10 + overlay/WifiRpiOverlay/AndroidManifest.xml | 20 + overlay/WifiRpiOverlay/res/values/config.xml | 27 + ramdisk/fstab.rpi4 | 10 + ramdisk/init.rpi4.rc | 39 + ramdisk/init.rpi4.usb.rc | 90 +++ ramdisk/ueventd.rpi4.rc | 23 + seccomp_policy/codec2.vendor.ext.policy | 20 + seccomp_policy/mediacodec.policy | 9 + seccomp_policy/mediaswcodec.policy | 3 + sepolicy/alsa_loop.te | 7 + sepolicy/bluetooth.te | 1 + sepolicy/bootanim.te | 1 + sepolicy/device.te | 1 + sepolicy/file.te | 1 + sepolicy/file_contexts | 49 ++ sepolicy/genfs_contexts | 3 + sepolicy/hal_camera.te | 14 + sepolicy/hal_drm_clearkey.te | 10 + sepolicy/hal_drm_widevine.te | 13 + sepolicy/hal_graphics_allocator_default.te | 1 + sepolicy/hal_graphics_composer_default.te | 2 + sepolicy/init.te | 2 + sepolicy/kernel.te | 4 + sepolicy/mediacodec.te | 1 + sepolicy/mediaprovider.te | 1 + sepolicy/mediaserver.te | 1 + sepolicy/mediaswcodec.te | 2 + sepolicy/netd.te | 2 + sepolicy/platform_app.te | 1 + sepolicy/priv_app.te | 1 + sepolicy/proc_net.te | 1 + sepolicy/surfaceflinger.te | 1 + sepolicy/suspend_blocker.te | 6 + sepolicy/system_app.te | 1 + sepolicy/system_server.te | 2 + sepolicy/te_macros | 8 + sepolicy/untrusted_app_all.te | 1 + suspend_blocker/Android.bp | 11 + suspend_blocker/suspend_blocker_rpi.cpp | 20 + vendor.prop | 42 ++ 85 files changed, 3127 insertions(+) create mode 100644 Android.bp create mode 100644 AndroidProducts.mk create mode 100644 BoardConfig.mk create mode 100644 README.md create mode 100644 aosp_rpi4.mk create mode 100644 audio/Android.bp create mode 100644 audio/audio_hw.c create mode 100644 audio/audio_policy_configuration.xml create mode 100644 audio/vc4-hdmi.conf create mode 100644 bluetooth/bdroid_buildcfg.h create mode 100644 bluetooth/vnd_rpi4.txt create mode 100644 boot/config.txt create mode 100644 camera/camera_hal.yaml create mode 100644 camera/external_camera_config.xml create mode 100644 camera/media_profiles_V1_0.xml create mode 100644 compatibility_matrix.xml create mode 100644 device.mk create mode 100644 health/Android.bp create mode 100644 health/HealthService.cpp create mode 100644 health/android.hardware.health@2.0-service.rpi.rc create mode 100644 health/android.hardware.health@2.0-service.rpi.xml create mode 100644 light/Android.bp create mode 100644 light/Light.cpp create mode 100644 light/Light.h create mode 100644 light/android.hardware.light@2.0-service.rpi.rc create mode 100644 light/android.hardware.light@2.0-service.rpi.xml create mode 100644 light/service.cpp create mode 100644 manifest.xml create mode 100644 media/media_codecs.xml create mode 100644 media/media_codecs_v4l2_c2_video.xml create mode 100644 mkbootimg.mk create mode 100755 mkimg.sh create mode 100644 overlay/AndroidRpiOverlay/Android.bp create mode 100644 overlay/AndroidRpiOverlay/AndroidManifest.xml create mode 100644 overlay/AndroidRpiOverlay/res/values/config.xml create mode 100644 overlay/SettingsProviderRpiOverlay/Android.bp create mode 100644 overlay/SettingsProviderRpiOverlay/AndroidManifest.xml create mode 100644 overlay/SettingsProviderRpiOverlay/res/values/defaults.xml create mode 100644 overlay/SettingsRpiOverlay/Android.bp create mode 100644 overlay/SettingsRpiOverlay/AndroidManifest.xml create mode 100644 overlay/SettingsRpiOverlay/res/values/config.xml create mode 100644 overlay/SystemUIRpiOverlay/Android.bp create mode 100644 overlay/SystemUIRpiOverlay/AndroidManifest.xml create mode 100644 overlay/SystemUIRpiOverlay/res/values/config.xml create mode 100644 overlay/WifiRpiOverlay/Android.bp create mode 100644 overlay/WifiRpiOverlay/AndroidManifest.xml create mode 100644 overlay/WifiRpiOverlay/res/values/config.xml create mode 100644 ramdisk/fstab.rpi4 create mode 100644 ramdisk/init.rpi4.rc create mode 100644 ramdisk/init.rpi4.usb.rc create mode 100644 ramdisk/ueventd.rpi4.rc create mode 100644 seccomp_policy/codec2.vendor.ext.policy create mode 100644 seccomp_policy/mediacodec.policy create mode 100644 seccomp_policy/mediaswcodec.policy create mode 100644 sepolicy/alsa_loop.te create mode 100644 sepolicy/bluetooth.te create mode 100644 sepolicy/bootanim.te create mode 100644 sepolicy/device.te create mode 100644 sepolicy/file.te create mode 100644 sepolicy/file_contexts create mode 100644 sepolicy/genfs_contexts create mode 100644 sepolicy/hal_camera.te create mode 100644 sepolicy/hal_drm_clearkey.te create mode 100644 sepolicy/hal_drm_widevine.te create mode 100644 sepolicy/hal_graphics_allocator_default.te create mode 100644 sepolicy/hal_graphics_composer_default.te create mode 100644 sepolicy/init.te create mode 100644 sepolicy/kernel.te create mode 100644 sepolicy/mediacodec.te create mode 100644 sepolicy/mediaprovider.te create mode 100644 sepolicy/mediaserver.te create mode 100644 sepolicy/mediaswcodec.te create mode 100644 sepolicy/netd.te create mode 100644 sepolicy/platform_app.te create mode 100644 sepolicy/priv_app.te create mode 100644 sepolicy/proc_net.te create mode 100644 sepolicy/surfaceflinger.te create mode 100644 sepolicy/suspend_blocker.te create mode 100644 sepolicy/system_app.te create mode 100644 sepolicy/system_server.te create mode 100644 sepolicy/te_macros create mode 100644 sepolicy/untrusted_app_all.te create mode 100644 suspend_blocker/Android.bp create mode 100644 suspend_blocker/suspend_blocker_rpi.cpp create mode 100644 vendor.prop diff --git a/Android.bp b/Android.bp new file mode 100644 index 0000000..e654877 --- /dev/null +++ b/Android.bp @@ -0,0 +1,6 @@ +// Copyright (C) 2021-2022 KonstaKANG +// +// SPDX-License-Identifier: Apache-2.0 + +soong_namespace { +} diff --git a/AndroidProducts.mk b/AndroidProducts.mk new file mode 100644 index 0000000..044e0f7 --- /dev/null +++ b/AndroidProducts.mk @@ -0,0 +1,11 @@ +# +# Copyright (C) 2021-2022 KonstaKANG +# +# SPDX-License-Identifier: Apache-2.0 +# + +PRODUCT_MAKEFILES := \ + $(LOCAL_DIR)/aosp_rpi4.mk + +COMMON_LUNCH_CHOICES := \ + aosp_rpi4-userdebug diff --git a/BoardConfig.mk b/BoardConfig.mk new file mode 100644 index 0000000..2a3cdc5 --- /dev/null +++ b/BoardConfig.mk @@ -0,0 +1,88 @@ +# +# Copyright (C) 2021-2022 KonstaKANG +# +# SPDX-License-Identifier: Apache-2.0 +# + +DEVICE_PATH := device/brcm/rpi4 + +# Platform +TARGET_NO_BOOTLOADER := true +TARGET_NO_RECOVERY := true + +TARGET_BOARD_PLATFORM := rpi + +TARGET_ARCH := arm64 +TARGET_ARCH_VARIANT := armv8-a +TARGET_CPU_ABI := arm64-v8a +TARGET_CPU_ABI2 := +TARGET_CPU_VARIANT := cortex-a72 + +TARGET_2ND_ARCH := arm +TARGET_2ND_ARCH_VARIANT := armv7-a-neon +TARGET_2ND_CPU_ABI := armeabi-v7a +TARGET_2ND_CPU_ABI2 := armeabi +TARGET_2ND_CPU_VARIANT := cortex-a72 + +# Bluetooth +BOARD_BLUETOOTH_BDROID_BUILDCFG_INCLUDE_DIR := $(DEVICE_PATH)/bluetooth +BOARD_CUSTOM_BT_CONFIG := $(DEVICE_PATH)/bluetooth/vnd_rpi4.txt +BOARD_HAVE_BLUETOOTH := true +BOARD_HAVE_BLUETOOTH_BCM := true + +# Camera +BOARD_LIBCAMERA_IPAS := raspberrypi +BOARD_LIBCAMERA_PIPELINES := raspberrypi +BOARD_LIBCAMERA_USES_MESON_BUILD := true + +# Display +TARGET_SCREEN_DENSITY := 240 + +# Graphics +BOARD_MESA3D_USES_MESON_BUILD := true +BOARD_MESA3D_GALLIUM_DRIVERS := vc4 v3d +BOARD_MESA3D_VULKAN_DRIVERS := broadcom + +# Kernel +BOARD_CUSTOM_BOOTIMG := true +BOARD_CUSTOM_BOOTIMG_MK := $(DEVICE_PATH)/mkbootimg.mk +BOARD_KERNEL_CMDLINE := console=ttyS0,115200 no_console_suspend root=/dev/ram0 rootwait androidboot.hardware=rpi4 + +# Manifest +DEVICE_MANIFEST_FILE := $(DEVICE_PATH)/manifest.xml +DEVICE_MATRIX_FILE := $(DEVICE_PATH)/compatibility_matrix.xml + +# Media +TARGET_ENABLE_MEDIADRM_64 := true + +# Partition sizes +BOARD_FLASH_BLOCK_SIZE := 4096 +BOARD_BOOTIMAGE_PARTITION_SIZE := 134217728 # 128M +BOARD_SYSTEMIMAGE_PARTITION_SIZE := 2147483648 # 2048M +BOARD_USERDATAIMAGE_PARTITION_SIZE := 134217728 # 128M +BOARD_VENDORIMAGE_PARTITION_SIZE := 268435456 # 256M +BOARD_VENDORIMAGE_FILE_SYSTEM_TYPE := ext4 +TARGET_USERIMAGES_SPARSE_EXT_DISABLED := true +TARGET_USERIMAGES_USE_EXT4 := true + +# Properties +TARGET_VENDOR_PROP += $(DEVICE_PATH)/vendor.prop + +# SELinux +BOARD_SEPOLICY_DIRS += device/brcm/rpi4/sepolicy +BOARD_KERNEL_CMDLINE += androidboot.selinux=permissive + +# Treble +BOARD_PROPERTY_OVERRIDES_SPLIT_ENABLED := true +BOARD_VNDK_VERSION := current +PRODUCT_FULL_TREBLE_OVERRIDE := true +TARGET_COPY_OUT_VENDOR := vendor + +# Wifi +BOARD_WLAN_DEVICE := bcmdhd +BOARD_HOSTAPD_DRIVER := NL80211 +BOARD_HOSTAPD_PRIVATE_LIB := lib_driver_cmd_$(BOARD_WLAN_DEVICE) +BOARD_WPA_SUPPLICANT_DRIVER := NL80211 +BOARD_WPA_SUPPLICANT_PRIVATE_LIB := lib_driver_cmd_$(BOARD_WLAN_DEVICE) +WIFI_HIDL_UNIFIED_SUPPLICANT_SERVICE_RC_ENTRY := true +WPA_SUPPLICANT_VERSION := VER_0_8_X diff --git a/README.md b/README.md new file mode 100644 index 0000000..16698c6 --- /dev/null +++ b/README.md @@ -0,0 +1 @@ +Raspberry Vanilla AOSP 12 device configuration for Raspberry Pi 4. diff --git a/aosp_rpi4.mk b/aosp_rpi4.mk new file mode 100644 index 0000000..d4cdc94 --- /dev/null +++ b/aosp_rpi4.mk @@ -0,0 +1,16 @@ +# +# Copyright (C) 2021-2022 KonstaKANG +# +# SPDX-License-Identifier: Apache-2.0 +# + +# Inherit device configuration +$(call inherit-product, device/brcm/rpi4/device.mk) + +# Device identifier. This must come after all inclusions. +PRODUCT_DEVICE := rpi4 +PRODUCT_NAME := aosp_rpi4 +PRODUCT_BRAND := Raspberry +PRODUCT_MODEL := Raspberry Pi 4 +PRODUCT_MANUFACTURER := Raspberry +PRODUCT_RELEASE_NAME := Raspberry Pi 4 diff --git a/audio/Android.bp b/audio/Android.bp new file mode 100644 index 0000000..2b9bc6a --- /dev/null +++ b/audio/Android.bp @@ -0,0 +1,24 @@ +// Copyright (C) 2015 The Android Open Source Project +// Copyright (C) 2021-2022 KonstaKANG +// +// SPDX-License-Identifier: Apache-2.0 + +cc_library_shared { + name: "audio.primary.rpi", + relative_install_path: "hw", + proprietary: true, + srcs: ["audio_hw.c"], + include_dirs: [ + "external/expat/lib", + "external/tinyalsa/include", + "system/media/audio_effects/include", + "system/media/audio_utils/include", + ], + header_libs: ["libhardware_headers"], + shared_libs: [ + "libcutils", + "liblog", + "libtinyalsa", + ], + cflags: ["-Wno-unused-parameter"], +} diff --git a/audio/audio_hw.c b/audio/audio_hw.c new file mode 100644 index 0000000..69a8ecb --- /dev/null +++ b/audio/audio_hw.c @@ -0,0 +1,708 @@ +/* + * Copyright (C) 2016 The Android Open Source Project + * Copyright (C) 2021-2022 KonstaKANG + * + * 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 "audio_hw_rpi" +//#define LOG_NDEBUG 0 + +#include +#include +#include +#include +#include +#include +#include + +#include +#include +#include + +#include +#include +#include + +#include +#include +#include +#include +#include +#include +#include + + +/* Minimum granularity - Arbitrary but small value */ +#define CODEC_BASE_FRAME_COUNT 32 + +/* number of base blocks in a short period (low latency) */ +#define PERIOD_MULTIPLIER 32 /* 21 ms */ +/* number of frames per short period (low latency) */ +#define PERIOD_SIZE (CODEC_BASE_FRAME_COUNT * PERIOD_MULTIPLIER) +/* number of pseudo periods for low latency playback */ +#define PLAYBACK_PERIOD_COUNT 4 +#define PLAYBACK_PERIOD_START_THRESHOLD 2 +#define CODEC_SAMPLING_RATE 48000 +#define CHANNEL_STEREO 2 +#define MIN_WRITE_SLEEP_US 5000 + +struct stub_stream_in { + struct audio_stream_in stream; +}; + +struct alsa_audio_device { + struct audio_hw_device hw_device; + + pthread_mutex_t lock; /* see note below on mutex acquisition order */ + int devices; + struct alsa_stream_in *active_input; + struct alsa_stream_out *active_output; + bool mic_mute; +}; + +struct alsa_stream_out { + struct audio_stream_out stream; + + pthread_mutex_t lock; /* see note below on mutex acquisition order */ + struct pcm_config config; + struct pcm *pcm; + bool unavailable; + int standby; + struct alsa_audio_device *dev; + int write_threshold; + unsigned int written; +}; + +static int get_pcm_card() +{ + char card[PROPERTY_VALUE_MAX]; + property_get("persist.audio.pcm.card", card, "0"); + return atoi(card); +} + +static int get_pcm_device() +{ + char device[PROPERTY_VALUE_MAX]; + property_get("persist.audio.pcm.device", device, "0"); + return atoi(device); +} + +/* must be called with hw device and output stream mutexes locked */ +static int start_output_stream(struct alsa_stream_out *out) +{ + struct alsa_audio_device *adev = out->dev; + + if (out->unavailable) + return -ENODEV; + + /* default to low power: will be corrected in out_write if necessary before first write to + * tinyalsa. + */ + out->write_threshold = PLAYBACK_PERIOD_COUNT * PERIOD_SIZE; + out->config.start_threshold = PLAYBACK_PERIOD_START_THRESHOLD * PERIOD_SIZE; + out->config.avail_min = PERIOD_SIZE; + + out->pcm = pcm_open(get_pcm_card(), get_pcm_device(), PCM_OUT | PCM_MMAP | PCM_NOIRQ | PCM_MONOTONIC, &out->config); + + if (!pcm_is_ready(out->pcm)) { + ALOGE("cannot open pcm_out driver: %s", pcm_get_error(out->pcm)); + pcm_close(out->pcm); + adev->active_output = NULL; + out->unavailable = true; + return -ENODEV; + } + + adev->active_output = out; + return 0; +} + +static uint32_t out_get_sample_rate(const struct audio_stream *stream) +{ + struct alsa_stream_out *out = (struct alsa_stream_out *)stream; + return out->config.rate; +} + +static int out_set_sample_rate(struct audio_stream *stream, uint32_t rate) +{ + ALOGV("out_set_sample_rate: %d", 0); + return -ENOSYS; +} + +static size_t out_get_buffer_size(const struct audio_stream *stream) +{ + ALOGV("out_get_buffer_size: %d", 4096); + + /* return the closest majoring multiple of 16 frames, as + * audioflinger expects audio buffers to be a multiple of 16 frames */ + size_t size = PERIOD_SIZE; + size = ((size + 15) / 16) * 16; + return size * audio_stream_out_frame_size((struct audio_stream_out *)stream); +} + +static audio_channel_mask_t out_get_channels(const struct audio_stream *stream) +{ + ALOGV("out_get_channels"); + struct alsa_stream_out *out = (struct alsa_stream_out *)stream; + return audio_channel_out_mask_from_count(out->config.channels); +} + +static audio_format_t out_get_format(const struct audio_stream *stream) +{ + ALOGV("out_get_format"); + struct alsa_stream_out *out = (struct alsa_stream_out *)stream; + return audio_format_from_pcm_format(out->config.format); +} + +static int out_set_format(struct audio_stream *stream, audio_format_t format) +{ + ALOGV("out_set_format: %d",format); + return -ENOSYS; +} + +static int do_output_standby(struct alsa_stream_out *out) +{ + struct alsa_audio_device *adev = out->dev; + + if (!out->standby) { + pcm_close(out->pcm); + out->pcm = NULL; + adev->active_output = NULL; + out->standby = 1; + } + return 0; +} + +static int out_standby(struct audio_stream *stream) +{ + ALOGV("out_standby"); + struct alsa_stream_out *out = (struct alsa_stream_out *)stream; + int status; + + pthread_mutex_lock(&out->dev->lock); + pthread_mutex_lock(&out->lock); + status = do_output_standby(out); + pthread_mutex_unlock(&out->lock); + pthread_mutex_unlock(&out->dev->lock); + return status; +} + +static int out_dump(const struct audio_stream *stream, int fd) +{ + ALOGV("out_dump"); + return 0; +} + +static int out_set_parameters(struct audio_stream *stream, const char *kvpairs) +{ + ALOGV("out_set_parameters"); + struct alsa_stream_out *out = (struct alsa_stream_out *)stream; + struct alsa_audio_device *adev = out->dev; + struct str_parms *parms; + char value[32]; + int val = 0; + int ret = -EINVAL; + + if (kvpairs == NULL || kvpairs[0] == 0) { + return 0; + } + + parms = str_parms_create_str(kvpairs); + + if (str_parms_get_str(parms, AUDIO_PARAMETER_STREAM_ROUTING, value, sizeof(value)) >= 0) { + val = atoi(value); + pthread_mutex_lock(&adev->lock); + pthread_mutex_lock(&out->lock); + if (((adev->devices & AUDIO_DEVICE_OUT_ALL) != val) && (val != 0)) { + adev->devices &= ~AUDIO_DEVICE_OUT_ALL; + adev->devices |= val; + } + pthread_mutex_unlock(&out->lock); + pthread_mutex_unlock(&adev->lock); + ret = 0; + } + + str_parms_destroy(parms); + return ret; +} + +static char * out_get_parameters(const struct audio_stream *stream, const char *keys) +{ + ALOGV("out_get_parameters"); + return strdup(""); +} + +static uint32_t out_get_latency(const struct audio_stream_out *stream) +{ + ALOGV("out_get_latency"); + struct alsa_stream_out *out = (struct alsa_stream_out *)stream; + return (PERIOD_SIZE * PLAYBACK_PERIOD_COUNT * 1000) / out->config.rate; +} + +static int out_set_volume(struct audio_stream_out *stream, float left, + float right) +{ + ALOGV("out_set_volume: Left:%f Right:%f", left, right); + return 0; +} + +static ssize_t out_write(struct audio_stream_out *stream, const void* buffer, + size_t bytes) +{ + int ret; + struct alsa_stream_out *out = (struct alsa_stream_out *)stream; + struct alsa_audio_device *adev = out->dev; + size_t frame_size = audio_stream_out_frame_size(stream); + size_t out_frames = bytes / frame_size; + + /* acquiring hw device mutex systematically is useful if a low priority thread is waiting + * on the output stream mutex - e.g. executing select_mode() while holding the hw device + * mutex + */ + pthread_mutex_lock(&adev->lock); + pthread_mutex_lock(&out->lock); + if (out->standby) { + ret = start_output_stream(out); + if (ret != 0) { + pthread_mutex_unlock(&adev->lock); + goto exit; + } + out->standby = 0; + } + + pthread_mutex_unlock(&adev->lock); + + ret = pcm_mmap_write(out->pcm, buffer, out_frames * frame_size); + if (ret == 0) { + out->written += out_frames; + } +exit: + pthread_mutex_unlock(&out->lock); + + if (ret != 0) { + usleep((int64_t)bytes * 1000000 / audio_stream_out_frame_size(stream) / + out_get_sample_rate(&stream->common)); + } + + return bytes; +} + +static int out_get_render_position(const struct audio_stream_out *stream, + uint32_t *dsp_frames) +{ + *dsp_frames = 0; + ALOGV("out_get_render_position: dsp_frames: %p", dsp_frames); + return -EINVAL; +} + +static int out_get_presentation_position(const struct audio_stream_out *stream, + uint64_t *frames, struct timespec *timestamp) +{ + struct alsa_stream_out *out = (struct alsa_stream_out *)stream; + int ret = -1; + + if (out->pcm) { + unsigned int avail; + if (pcm_get_htimestamp(out->pcm, &avail, timestamp) == 0) { + size_t kernel_buffer_size = out->config.period_size * out->config.period_count; + int64_t signed_frames = out->written - kernel_buffer_size + avail; + if (signed_frames >= 0) { + *frames = signed_frames; + ret = 0; + } + } + } + + return ret; +} + + +static int out_add_audio_effect(const struct audio_stream *stream, effect_handle_t effect) +{ + ALOGV("out_add_audio_effect: %p", effect); + return 0; +} + +static int out_remove_audio_effect(const struct audio_stream *stream, effect_handle_t effect) +{ + ALOGV("out_remove_audio_effect: %p", effect); + return 0; +} + +static int out_get_next_write_timestamp(const struct audio_stream_out *stream, + int64_t *timestamp) +{ + *timestamp = 0; + ALOGV("out_get_next_write_timestamp: %ld", (long int)(*timestamp)); + return -EINVAL; +} + +/** audio_stream_in implementation **/ +static uint32_t in_get_sample_rate(const struct audio_stream *stream) +{ + ALOGV("in_get_sample_rate"); + return 8000; +} + +static int in_set_sample_rate(struct audio_stream *stream, uint32_t rate) +{ + ALOGV("in_set_sample_rate: %d", rate); + return -ENOSYS; +} + +static size_t in_get_buffer_size(const struct audio_stream *stream) +{ + ALOGV("in_get_buffer_size: %d", 320); + return 320; +} + +static audio_channel_mask_t in_get_channels(const struct audio_stream *stream) +{ + ALOGV("in_get_channels: %d", AUDIO_CHANNEL_IN_MONO); + return AUDIO_CHANNEL_IN_MONO; +} + +static audio_format_t in_get_format(const struct audio_stream *stream) +{ + return AUDIO_FORMAT_PCM_16_BIT; +} + +static int in_set_format(struct audio_stream *stream, audio_format_t format) +{ + return -ENOSYS; +} + +static int in_standby(struct audio_stream *stream) +{ + return 0; +} + +static int in_dump(const struct audio_stream *stream, int fd) +{ + return 0; +} + +static int in_set_parameters(struct audio_stream *stream, const char *kvpairs) +{ + return 0; +} + +static char * in_get_parameters(const struct audio_stream *stream, + const char *keys) +{ + return strdup(""); +} + +static int in_set_gain(struct audio_stream_in *stream, float gain) +{ + return 0; +} + +static ssize_t in_read(struct audio_stream_in *stream, void* buffer, + size_t bytes) +{ + ALOGV("in_read: bytes %zu", bytes); + /* XXX: fake timing for audio input */ + usleep((int64_t)bytes * 1000000 / audio_stream_in_frame_size(stream) / + in_get_sample_rate(&stream->common)); + memset(buffer, 0, bytes); + return bytes; +} + +static uint32_t in_get_input_frames_lost(struct audio_stream_in *stream) +{ + return 0; +} + +static int in_add_audio_effect(const struct audio_stream *stream, effect_handle_t effect) +{ + return 0; +} + +static int in_remove_audio_effect(const struct audio_stream *stream, effect_handle_t effect) +{ + return 0; +} + +static int adev_open_output_stream(struct audio_hw_device *dev, + audio_io_handle_t handle, + audio_devices_t devices, + audio_output_flags_t flags, + struct audio_config *config, + struct audio_stream_out **stream_out, + const char *address __unused) +{ + ALOGV("adev_open_output_stream..."); + + struct alsa_audio_device *ladev = (struct alsa_audio_device *)dev; + struct alsa_stream_out *out; + struct pcm_params *params; + int ret = 0; + + params = pcm_params_get(get_pcm_card(), get_pcm_device(), PCM_OUT); + if (!params) + return -ENOSYS; + + out = (struct alsa_stream_out *)calloc(1, sizeof(struct alsa_stream_out)); + if (!out) + return -ENOMEM; + + out->stream.common.get_sample_rate = out_get_sample_rate; + out->stream.common.set_sample_rate = out_set_sample_rate; + out->stream.common.get_buffer_size = out_get_buffer_size; + out->stream.common.get_channels = out_get_channels; + out->stream.common.get_format = out_get_format; + out->stream.common.set_format = out_set_format; + out->stream.common.standby = out_standby; + out->stream.common.dump = out_dump; + out->stream.common.set_parameters = out_set_parameters; + out->stream.common.get_parameters = out_get_parameters; + out->stream.common.add_audio_effect = out_add_audio_effect; + out->stream.common.remove_audio_effect = out_remove_audio_effect; + out->stream.get_latency = out_get_latency; + out->stream.set_volume = out_set_volume; + out->stream.write = out_write; + out->stream.get_render_position = out_get_render_position; + out->stream.get_next_write_timestamp = out_get_next_write_timestamp; + out->stream.get_presentation_position = out_get_presentation_position; + + out->config.channels = CHANNEL_STEREO; + out->config.rate = CODEC_SAMPLING_RATE; + out->config.format = PCM_FORMAT_S16_LE; + out->config.period_size = PERIOD_SIZE; + out->config.period_count = PLAYBACK_PERIOD_COUNT; + + if (out->config.rate != config->sample_rate || + audio_channel_count_from_out_mask(config->channel_mask) != CHANNEL_STEREO || + out->config.format != pcm_format_from_audio_format(config->format) ) { + config->sample_rate = out->config.rate; + config->format = audio_format_from_pcm_format(out->config.format); + config->channel_mask = audio_channel_out_mask_from_count(CHANNEL_STEREO); + ret = -EINVAL; + } + + ALOGI("adev_open_output_stream selects channels=%d rate=%d format=%d", + out->config.channels, out->config.rate, out->config.format); + + out->dev = ladev; + out->standby = 1; + out->unavailable = false; + + config->format = out_get_format(&out->stream.common); + config->channel_mask = out_get_channels(&out->stream.common); + config->sample_rate = out_get_sample_rate(&out->stream.common); + + *stream_out = &out->stream; + + /* TODO The retry mechanism isn't implemented in AudioPolicyManager/AudioFlinger. */ + ret = 0; + + return ret; +} + +static void adev_close_output_stream(struct audio_hw_device *dev, + struct audio_stream_out *stream) +{ + ALOGV("adev_close_output_stream..."); + free(stream); +} + +static int adev_set_parameters(struct audio_hw_device *dev, const char *kvpairs) +{ + ALOGV("adev_set_parameters"); + return -ENOSYS; +} + +static char * adev_get_parameters(const struct audio_hw_device *dev, + const char *keys) +{ + ALOGV("adev_get_parameters"); + return strdup(""); +} + +static int adev_init_check(const struct audio_hw_device *dev) +{ + ALOGV("adev_init_check"); + return 0; +} + +static int adev_set_voice_volume(struct audio_hw_device *dev, float volume) +{ + ALOGV("adev_set_voice_volume: %f", volume); + return -ENOSYS; +} + +static int adev_set_master_volume(struct audio_hw_device *dev, float volume) +{ + ALOGV("adev_set_master_volume: %f", volume); + return -ENOSYS; +} + +static int adev_get_master_volume(struct audio_hw_device *dev, float *volume) +{ + ALOGV("adev_get_master_volume: %f", *volume); + return -ENOSYS; +} + +static int adev_set_master_mute(struct audio_hw_device *dev, bool muted) +{ + ALOGV("adev_set_master_mute: %d", muted); + return -ENOSYS; +} + +static int adev_get_master_mute(struct audio_hw_device *dev, bool *muted) +{ + ALOGV("adev_get_master_mute: %d", *muted); + return -ENOSYS; +} + +static int adev_set_mode(struct audio_hw_device *dev, audio_mode_t mode) +{ + ALOGV("adev_set_mode: %d", mode); + return 0; +} + +static int adev_set_mic_mute(struct audio_hw_device *dev, bool state) +{ + ALOGV("adev_set_mic_mute: %d",state); + return -ENOSYS; +} + +static int adev_get_mic_mute(const struct audio_hw_device *dev, bool *state) +{ + ALOGV("adev_get_mic_mute"); + return -ENOSYS; +} + +static size_t adev_get_input_buffer_size(const struct audio_hw_device *dev, + const struct audio_config *config) +{ + ALOGV("adev_get_input_buffer_size: %d", 320); + return 320; +} + +static int adev_open_input_stream(struct audio_hw_device __unused *dev, + audio_io_handle_t handle, + audio_devices_t devices, + struct audio_config *config, + struct audio_stream_in **stream_in, + audio_input_flags_t flags __unused, + const char *address __unused, + audio_source_t source __unused) +{ + struct stub_stream_in *in; + + ALOGV("adev_open_input_stream..."); + + in = (struct stub_stream_in *)calloc(1, sizeof(struct stub_stream_in)); + if (!in) + return -ENOMEM; + + in->stream.common.get_sample_rate = in_get_sample_rate; + in->stream.common.set_sample_rate = in_set_sample_rate; + in->stream.common.get_buffer_size = in_get_buffer_size; + in->stream.common.get_channels = in_get_channels; + in->stream.common.get_format = in_get_format; + in->stream.common.set_format = in_set_format; + in->stream.common.standby = in_standby; + in->stream.common.dump = in_dump; + in->stream.common.set_parameters = in_set_parameters; + in->stream.common.get_parameters = in_get_parameters; + in->stream.common.add_audio_effect = in_add_audio_effect; + in->stream.common.remove_audio_effect = in_remove_audio_effect; + in->stream.set_gain = in_set_gain; + in->stream.read = in_read; + in->stream.get_input_frames_lost = in_get_input_frames_lost; + + *stream_in = &in->stream; + return 0; +} + +static void adev_close_input_stream(struct audio_hw_device *dev, + struct audio_stream_in *in) +{ + ALOGV("adev_close_input_stream..."); + return; +} + +static int adev_dump(const audio_hw_device_t *device, int fd) +{ + ALOGV("adev_dump"); + return 0; +} + +static int adev_close(hw_device_t *device) +{ + ALOGV("adev_close"); + free(device); + return 0; +} + +static int adev_open(const hw_module_t* module, const char* name, + hw_device_t** device) +{ + struct alsa_audio_device *adev; + + ALOGV("adev_open: %s", name); + + if (strcmp(name, AUDIO_HARDWARE_INTERFACE) != 0) + return -EINVAL; + + adev = calloc(1, sizeof(struct alsa_audio_device)); + if (!adev) + return -ENOMEM; + + adev->hw_device.common.tag = HARDWARE_DEVICE_TAG; + adev->hw_device.common.version = AUDIO_DEVICE_API_VERSION_2_0; + adev->hw_device.common.module = (struct hw_module_t *) module; + adev->hw_device.common.close = adev_close; + adev->hw_device.init_check = adev_init_check; + adev->hw_device.set_voice_volume = adev_set_voice_volume; + adev->hw_device.set_master_volume = adev_set_master_volume; + adev->hw_device.get_master_volume = adev_get_master_volume; + adev->hw_device.set_master_mute = adev_set_master_mute; + adev->hw_device.get_master_mute = adev_get_master_mute; + adev->hw_device.set_mode = adev_set_mode; + adev->hw_device.set_mic_mute = adev_set_mic_mute; + adev->hw_device.get_mic_mute = adev_get_mic_mute; + adev->hw_device.set_parameters = adev_set_parameters; + adev->hw_device.get_parameters = adev_get_parameters; + adev->hw_device.get_input_buffer_size = adev_get_input_buffer_size; + adev->hw_device.open_output_stream = adev_open_output_stream; + adev->hw_device.close_output_stream = adev_close_output_stream; + adev->hw_device.open_input_stream = adev_open_input_stream; + adev->hw_device.close_input_stream = adev_close_input_stream; + adev->hw_device.dump = adev_dump; + + adev->devices = AUDIO_DEVICE_NONE; + + *device = &adev->hw_device.common; + + return 0; +} + +static struct hw_module_methods_t hal_module_methods = { + .open = adev_open, +}; + +struct audio_module HAL_MODULE_INFO_SYM = { + .common = { + .tag = HARDWARE_MODULE_TAG, + .module_api_version = AUDIO_MODULE_API_VERSION_0_1, + .hal_api_version = HARDWARE_HAL_API_VERSION, + .id = AUDIO_HARDWARE_MODULE_ID, + .name = "Raspberry Pi audio HW HAL", + .author = "The Android Open Source Project", + .methods = &hal_module_methods, + }, +}; diff --git a/audio/audio_policy_configuration.xml b/audio/audio_policy_configuration.xml new file mode 100644 index 0000000..b2647e8 --- /dev/null +++ b/audio/audio_policy_configuration.xml @@ -0,0 +1,106 @@ + + + + + + + Speaker + Built-In Mic + + Speaker + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + diff --git a/audio/vc4-hdmi.conf b/audio/vc4-hdmi.conf new file mode 100644 index 0000000..7fbcb24 --- /dev/null +++ b/audio/vc4-hdmi.conf @@ -0,0 +1,68 @@ +# Configuration for the VC4-HDMI sound card using software IEC958 +# subframe conversion + + +vc4-hdmi.pcm.hdmi.0 { + @args [ CARD AES0 AES1 AES2 AES3 ] + @args.CARD { + type string + } + @args.AES0 { + type integer + } + @args.AES1 { + type integer + } + @args.AES2 { + type integer + } + @args.AES3 { + type integer + } + type iec958 + slave { + format IEC958_SUBFRAME_LE + pcm { + type hooks + slave.pcm { + type hw + card $CARD + device 0 + } + hooks.0 { + type ctl_elems + hook_args [ + { + name "IEC958 Playback Default" + interface PCM + optional true + lock true + preserve true + value [ $AES0 $AES1 $AES2 $AES3 ] + } + ] + } + } + } + status [ $AES0 $AES1 $AES2 $AES3 ] +} + +# default with plug +vc4-hdmi.pcm.default { + @args [ CARD ] + @args.CARD { + type string + } + type plug + slave.pcm { + type softvol + slave.pcm { + @func concat + strings [ "hdmi:" $CARD ] + } + control { + name "PCM Playback Volume" + card $CARD + } + } +} diff --git a/bluetooth/bdroid_buildcfg.h b/bluetooth/bdroid_buildcfg.h new file mode 100644 index 0000000..a8c7909 --- /dev/null +++ b/bluetooth/bdroid_buildcfg.h @@ -0,0 +1,12 @@ +/* + * Copyright (C) 2021-2022 KonstaKANG + * + * SPDX-License-Identifier: Apache-2.0 + */ + +#ifndef _BDROID_BUILDCFG_H +#define _BDROID_BUILDCFG_H + +#define BTM_DEF_LOCAL_NAME "Raspberry Pi 4" + +#endif diff --git a/bluetooth/vnd_rpi4.txt b/bluetooth/vnd_rpi4.txt new file mode 100644 index 0000000..2a3ea0e --- /dev/null +++ b/bluetooth/vnd_rpi4.txt @@ -0,0 +1,14 @@ +BLUETOOTH_UART_DEVICE_PORT = "/dev/ttyAMA0" +FW_PATCHFILE_LOCATION = "/vendor/firmware/brcm/" +FW_PATCH_SETTLEMENT_DELAY_MS = 200 +BT_WAKE_VIA_PROC = FALSE +BT_WAKE_VIA_USERIAL_IOCTL = FALSE +LPM_IDLE_TIMEOUT_MULTIPLE = 5 +SCO_CFG_INCLUDED = FALSE +SCO_PCM_IF_CLOCK_RATE = 2 +BTVND_DBG = FALSE +BTHW_DBG = FALSE +VNDUSERIAL_DBG = FALSE +UPIO_DBG = FALSE +UART_TARGET_BAUD_RATE = 3000000 +USE_CONTROLLER_BDADDR = FALSE diff --git a/boot/config.txt b/boot/config.txt new file mode 100644 index 0000000..7fa5705 --- /dev/null +++ b/boot/config.txt @@ -0,0 +1,45 @@ +# Kernel +arm_64bit=1 +kernel=Image + +# Ramdisk +initramfs ramdisk.img followkernel + +# Audio +dtparam=audio=on + +# Camera +camera_auto_detect=1 +start_x=1 + +# Display +disable_overscan=1 + +# Display panel +#dtoverlay=vc4-kms-dsi-7inch +#dtoverlay=rpi-backlight + +# Graphics acceleration +dtoverlay=vc4-kms-v3d +dtoverlay=cma,cma-384 + +# I2C +#dtparam=i2c_arm=on + +# I2S +#dtparam=i2s=on + +# Serial console +enable_uart=1 + +# SPI +#dtparam=spi=on + +# USB +dtoverlay=dwc2,dr_mode=peripheral +[cm4] +dtoverlay=dwc2,dr_mode=otg +[all] + +# V4L2 +#dtoverlay=rpivid-v4l2 diff --git a/camera/camera_hal.yaml b/camera/camera_hal.yaml new file mode 100644 index 0000000..89d3e0b --- /dev/null +++ b/camera/camera_hal.yaml @@ -0,0 +1,10 @@ +cameras: + "/base/soc/i2c0mux/i2c@1/imx219@10": + location: back + rotation: 0 + "/base/soc/i2c0mux/i2c@1/imx477@1a": + location: back + rotation: 0 + "/base/soc/i2c0mux/i2c@1/ov5647@36": + location: back + rotation: 0 diff --git a/camera/external_camera_config.xml b/camera/external_camera_config.xml new file mode 100644 index 0000000..9db0456 --- /dev/null +++ b/camera/external_camera_config.xml @@ -0,0 +1,59 @@ + + + + + + + 10 + 11 + 12 + 13 + 14 + 15 + 16 + 18 + 19 + 20 + 21 + 22 + 23 + + + + + + + + + + + + + + + + + + + + + + + + diff --git a/camera/media_profiles_V1_0.xml b/camera/media_profiles_V1_0.xml new file mode 100644 index 0000000..4c126ad --- /dev/null +++ b/camera/media_profiles_V1_0.xml @@ -0,0 +1,190 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + diff --git a/compatibility_matrix.xml b/compatibility_matrix.xml new file mode 100644 index 0000000..73d39a9 --- /dev/null +++ b/compatibility_matrix.xml @@ -0,0 +1,58 @@ + + + android.frameworks.displayservice + 1.0 + + IDisplayService + default + + + + android.frameworks.sensorservice + 1.0 + + ISensorManager + default + + + + android.hidl.manager + 1.2 + + IServiceManager + default + + + + android.hidl.memory + 1.0 + + IMapper + ashmem + + + + android.hidl.token + 1.0 + + ITokenManager + default + + + + android.system.net.netd + 1.1 + + INetd + default + + + + android.system.wifi.keystore + 1.0 + + IKeystore + default + + + diff --git a/device.mk b/device.mk new file mode 100644 index 0000000..950afdd --- /dev/null +++ b/device.mk @@ -0,0 +1,266 @@ +# +# Copyright (C) 2021-2022 KonstaKANG +# +# SPDX-License-Identifier: Apache-2.0 +# + +DEVICE_PATH := device/brcm/rpi4 +PRODUCT_SOONG_NAMESPACES += $(DEVICE_PATH) + +$(call inherit-product, $(SRC_TARGET_DIR)/product/core_64_bit.mk) +$(call inherit-product, $(SRC_TARGET_DIR)/product/full_base.mk) +$(call inherit-product, frameworks/native/build/tablet-7in-xhdpi-2048-dalvik-heap.mk) +$(call inherit-product, vendor/brcm/rpi4/rpi4-vendor.mk) + +PRODUCT_AAPT_CONFIG := normal mdpi hdpi +PRODUCT_AAPT_PREF_CONFIG := hdpi +PRODUCT_CHARACTERISTICS := tablet,nosdcard + +# API level +PRODUCT_SHIPPING_API_LEVEL := 32 + +# Audio +PRODUCT_PACKAGES += \ + android.hardware.audio.service \ + android.hardware.audio@7.0-impl \ + android.hardware.audio.effect@7.0-impl \ + audio.primary.rpi \ + audio.r_submix.default \ + audio.usb.default + +PRODUCT_PACKAGES += \ + tinycap \ + tinyhostless \ + tinymix \ + tinypcminfo \ + tinyplay + +PRODUCT_COPY_FILES += \ + $(DEVICE_PATH)/audio/audio_policy_configuration.xml:$(TARGET_COPY_OUT_VENDOR)/etc/audio_policy_configuration.xml \ + frameworks/av/media/libeffects/data/audio_effects.xml:$(TARGET_COPY_OUT_VENDOR)/etc/audio_effects.xml \ + frameworks/av/services/audiopolicy/config/audio_policy_volumes.xml:$(TARGET_COPY_OUT_VENDOR)/etc/audio_policy_volumes.xml \ + frameworks/av/services/audiopolicy/config/default_volume_tables.xml:$(TARGET_COPY_OUT_VENDOR)/etc/default_volume_tables.xml \ + frameworks/av/services/audiopolicy/config/r_submix_audio_policy_configuration.xml:$(TARGET_COPY_OUT_VENDOR)/etc/r_submix_audio_policy_configuration.xml \ + frameworks/av/services/audiopolicy/config/usb_audio_policy_configuration.xml:$(TARGET_COPY_OUT_VENDOR)/etc/usb_audio_policy_configuration.xml + +PRODUCT_PACKAGES += \ + alsa_amixer \ + alsa_aplay \ + alsa_arecord \ + alsa_loop + +PRODUCT_COPY_FILES += \ + $(DEVICE_PATH)/audio/vc4-hdmi.conf:$(TARGET_COPY_OUT_VENDOR)/etc/alsa/cards/vc4-hdmi.conf \ + external/alsa-lib/src/conf/alsa.conf:$(TARGET_COPY_OUT_VENDOR)/etc/alsa/alsa.conf \ + external/alsa-lib/src/conf/cards/aliases.conf:$(TARGET_COPY_OUT_VENDOR)/etc/alsa/cards/aliases.conf \ + external/alsa-lib/src/conf/ctl/default.conf:$(TARGET_COPY_OUT_VENDOR)/etc/alsa/ctl/default.conf \ + external/alsa-lib/src/conf/pcm/center_lfe.conf:$(TARGET_COPY_OUT_VENDOR)/etc/alsa/pcm/center_lfe.conf \ + external/alsa-lib/src/conf/pcm/default.conf:$(TARGET_COPY_OUT_VENDOR)/etc/alsa/pcm/default.conf \ + external/alsa-lib/src/conf/pcm/dmix.conf:$(TARGET_COPY_OUT_VENDOR)/etc/alsa/pcm/dmix.conf \ + external/alsa-lib/src/conf/pcm/dpl.conf:$(TARGET_COPY_OUT_VENDOR)/etc/alsa/pcm/dpl.conf \ + external/alsa-lib/src/conf/pcm/dsnoop.conf:$(TARGET_COPY_OUT_VENDOR)/etc/alsa/pcm/dsnoop.conf \ + external/alsa-lib/src/conf/pcm/front.conf:$(TARGET_COPY_OUT_VENDOR)/etc/alsa/pcm/front.conf \ + external/alsa-lib/src/conf/pcm/hdmi.conf:$(TARGET_COPY_OUT_VENDOR)/etc/alsa/pcm/hdmi.conf \ + external/alsa-lib/src/conf/pcm/iec958.conf:$(TARGET_COPY_OUT_VENDOR)/etc/alsa/pcm/iec958.conf \ + external/alsa-lib/src/conf/pcm/modem.conf:$(TARGET_COPY_OUT_VENDOR)/etc/alsa/pcm/modem.conf \ + external/alsa-lib/src/conf/pcm/rear.conf:$(TARGET_COPY_OUT_VENDOR)/etc/alsa/pcm/rear.conf \ + external/alsa-lib/src/conf/pcm/side.conf:$(TARGET_COPY_OUT_VENDOR)/etc/alsa/pcm/side.conf \ + external/alsa-lib/src/conf/pcm/surround21.conf:$(TARGET_COPY_OUT_VENDOR)/etc/alsa/pcm/surround21.conf \ + external/alsa-lib/src/conf/pcm/surround40.conf:$(TARGET_COPY_OUT_VENDOR)/etc/alsa/pcm/surround40.conf \ + external/alsa-lib/src/conf/pcm/surround41.conf:$(TARGET_COPY_OUT_VENDOR)/etc/alsa/pcm/surround41.conf \ + external/alsa-lib/src/conf/pcm/surround50.conf:$(TARGET_COPY_OUT_VENDOR)/etc/alsa/pcm/surround50.conf \ + external/alsa-lib/src/conf/pcm/surround51.conf:$(TARGET_COPY_OUT_VENDOR)/etc/alsa/pcm/surround51.conf \ + external/alsa-lib/src/conf/pcm/surround71.conf:$(TARGET_COPY_OUT_VENDOR)/etc/alsa/pcm/surround71.conf \ + external/alsa-lib/src/conf/smixer.conf:$(TARGET_COPY_OUT_VENDOR)/etc/alsa/smixer.conf + +# Bluetooth +PRODUCT_PACKAGES += \ + android.hardware.bluetooth@1.0-impl \ + android.hardware.bluetooth@1.0-service \ + libbt-vendor + +PRODUCT_COPY_FILES += \ + frameworks/native/data/etc/android.hardware.bluetooth.xml:$(TARGET_COPY_OUT_VENDOR)/etc/permissions/android.hardware.bluetooth.xml \ + frameworks/native/data/etc/android.hardware.bluetooth_le.xml:$(TARGET_COPY_OUT_VENDOR)/etc/permissions/android.hardware.bluetooth_le.xml + +PRODUCT_PACKAGES += \ + android.hardware.bluetooth.audio@2.0-impl \ + audio.a2dp.default \ + audio.bluetooth.default + +PRODUCT_COPY_FILES += \ + frameworks/av/services/audiopolicy/config/a2dp_in_audio_policy_configuration_7_0.xml:$(TARGET_COPY_OUT_VENDOR)/etc/a2dp_in_audio_policy_configuration_7_0.xml \ + frameworks/av/services/audiopolicy/config/bluetooth_audio_policy_configuration_7_0.xml:$(TARGET_COPY_OUT_VENDOR)/etc/bluetooth_audio_policy_configuration_7_0.xml + +# Camera +PRODUCT_PACKAGES += \ + android.hardware.camera.provider@2.5-external-service + +PRODUCT_COPY_FILES += \ + $(DEVICE_PATH)/camera/external_camera_config.xml:$(TARGET_COPY_OUT_VENDOR)/etc/external_camera_config.xml + +PRODUCT_COPY_FILES += \ + frameworks/native/data/etc/android.hardware.camera.external.xml:$(TARGET_COPY_OUT_VENDOR)/etc/permissions/android.hardware.camera.external.xml + +PRODUCT_PACKAGES += \ + android.hardware.camera.provider@2.5-service_64 \ + camera.libcamera \ + ipa_rpi + +PRODUCT_COPY_FILES += \ + $(DEVICE_PATH)/camera/camera_hal.yaml:$(TARGET_COPY_OUT_VENDOR)/etc/libcamera/camera_hal.yaml \ + external/libcamera/src/ipa/raspberrypi/data/imx219.json:$(TARGET_COPY_OUT_VENDOR)/etc/libcamera/ipa/raspberrypi/imx219.json \ + external/libcamera/src/ipa/raspberrypi/data/imx219_noir.json:$(TARGET_COPY_OUT_VENDOR)/etc/libcamera/ipa/raspberrypi/imx219_noir.json \ + external/libcamera/src/ipa/raspberrypi/data/imx477.json:$(TARGET_COPY_OUT_VENDOR)/etc/libcamera/ipa/raspberrypi/imx477.json \ + external/libcamera/src/ipa/raspberrypi/data/imx477_noir.json:$(TARGET_COPY_OUT_VENDOR)/etc/libcamera/ipa/raspberrypi/imx477_noir.json \ + external/libcamera/src/ipa/raspberrypi/data/ov5647.json:$(TARGET_COPY_OUT_VENDOR)/etc/libcamera/ipa/raspberrypi/ov5647.json \ + external/libcamera/src/ipa/raspberrypi/data/ov5647_noir.json:$(TARGET_COPY_OUT_VENDOR)/etc/libcamera/ipa/raspberrypi/ov5647_noir.json + +PRODUCT_COPY_FILES += \ + frameworks/native/data/etc/android.hardware.camera.xml:$(TARGET_COPY_OUT_VENDOR)/etc/permissions/android.hardware.camera.xml + +PRODUCT_COPY_FILES += \ + $(DEVICE_PATH)/camera/media_profiles_V1_0.xml:$(TARGET_COPY_OUT_VENDOR)/etc/media_profiles_V1_0.xml + +# Debugfs +PRODUCT_SET_DEBUGFS_RESTRICTIONS := false + +# DRM +PRODUCT_PACKAGES += \ + android.hardware.drm@1.0-impl \ + android.hardware.drm@1.0-service \ + android.hardware.drm@1.4-service.clearkey + +# Ethernet +PRODUCT_COPY_FILES += \ + frameworks/native/data/etc/android.hardware.ethernet.xml:$(TARGET_COPY_OUT_VENDOR)/etc/permissions/android.hardware.ethernet.xml + +# Gatekeeper +PRODUCT_PACKAGES += \ + android.hardware.gatekeeper@1.0-service.software + +# Graphics +PRODUCT_PACKAGES += \ + android.hardware.graphics.allocator@4.0-service.minigbm_gbm_mesa \ + android.hardware.graphics.mapper@4.0-impl.minigbm_gbm_mesa + +PRODUCT_PACKAGES += \ + android.hardware.graphics.composer@2.4-service \ + hwcomposer.drm + +PRODUCT_PACKAGES += \ + libEGL_mesa \ + libGLESv1_CM_mesa \ + libGLESv2_mesa \ + libgallium_dri \ + libglapi + +PRODUCT_COPY_FILES += \ + frameworks/native/data/etc/android.software.opengles.deqp.level-2021-03-01.xml:$(TARGET_COPY_OUT_VENDOR)/etc/permissions/android.software.opengles.deqp.level.xml + +PRODUCT_PACKAGES += \ + vulkan.broadcom + +PRODUCT_COPY_FILES += \ + frameworks/native/data/etc/android.hardware.vulkan.level-0.xml:$(TARGET_COPY_OUT_VENDOR)/etc/permissions/android.hardware.vulkan.level.xml \ + frameworks/native/data/etc/android.hardware.vulkan.version-1_0_3.xml:$(TARGET_COPY_OUT_VENDOR)/etc/permissions/android.hardware.vulkan.version.xml \ + frameworks/native/data/etc/android.software.vulkan.deqp.level-2021-03-01.xml:$(TARGET_COPY_OUT_VENDOR)/etc/permissions/android.software.vulkan.deqp.level.xml + +# Health +PRODUCT_PACKAGES += \ + android.hardware.health@2.0-service.rpi + +# Kernel +PRODUCT_COPY_FILES += \ + $(DEVICE_PATH)-kernel/Image:$(PRODUCT_OUT)/kernel + +# Keymaster +PRODUCT_PACKAGES += \ + android.hardware.keymaster@3.0-impl \ + android.hardware.keymaster@3.0-service + +# Lights +PRODUCT_PACKAGES += \ + android.hardware.light@2.0-service.rpi + +# Media +PRODUCT_COPY_FILES += \ + $(DEVICE_PATH)/media/media_codecs.xml:$(TARGET_COPY_OUT_VENDOR)/etc/media_codecs.xml \ + $(DEVICE_PATH)/media/media_codecs_v4l2_c2_video.xml:$(TARGET_COPY_OUT_VENDOR)/etc/media_codecs_v4l2_c2_video.xml \ + frameworks/av/media/libstagefright/data/media_codecs_google_c2_audio.xml:$(TARGET_COPY_OUT_VENDOR)/etc/media_codecs_google_c2_audio.xml \ + frameworks/av/media/libstagefright/data/media_codecs_google_c2_tv.xml:$(TARGET_COPY_OUT_VENDOR)/etc/media_codecs_google_c2_tv.xml \ + frameworks/av/media/libstagefright/data/media_codecs_google_c2_video.xml:$(TARGET_COPY_OUT_VENDOR)/etc/media_codecs_google_c2_video.xml + +# Overlays +PRODUCT_PACKAGES += \ + AndroidRpiOverlay \ + SettingsRpiOverlay \ + SettingsProviderRpiOverlay \ + SystemUIRpiOverlay \ + WifiRpiOverlay + +# Permissions +PRODUCT_COPY_FILES += \ + frameworks/native/data/etc/tablet_core_hardware.xml:$(TARGET_COPY_OUT_VENDOR)/etc/permissions/tablet_core_hardware.xml + +# Power +PRODUCT_PACKAGES += \ + android.hardware.power-service.example + +# Ramdisk +PRODUCT_COPY_FILES += \ + $(DEVICE_PATH)/ramdisk/fstab.rpi4:$(TARGET_COPY_OUT_RAMDISK)/fstab.rpi4 \ + $(DEVICE_PATH)/ramdisk/fstab.rpi4:$(TARGET_COPY_OUT_VENDOR)/etc/fstab.rpi4 \ + $(DEVICE_PATH)/ramdisk/init.rpi4.rc:$(TARGET_COPY_OUT_VENDOR)/etc/init/hw/init.rpi4.rc \ + $(DEVICE_PATH)/ramdisk/init.rpi4.usb.rc:$(TARGET_COPY_OUT_VENDOR)/etc/init/hw/init.rpi4.usb.rc \ + $(DEVICE_PATH)/ramdisk/ueventd.rpi4.rc:$(TARGET_COPY_OUT_VENDOR)/etc/ueventd.rc + +# Seccomp +PRODUCT_COPY_FILES += \ + $(DEVICE_PATH)/seccomp_policy/codec2.vendor.ext.policy:$(TARGET_COPY_OUT_VENDOR)/etc/seccomp_policy/codec2.vendor.ext.policy \ + $(DEVICE_PATH)/seccomp_policy/mediacodec.policy:$(TARGET_COPY_OUT_VENDOR)/etc/seccomp_policy/mediacodec.policy \ + $(DEVICE_PATH)/seccomp_policy/mediaswcodec.policy:$(TARGET_COPY_OUT_VENDOR)/etc/seccomp_policy/mediaswcodec.policy + +# Settings +PRODUCT_PACKAGES += \ + androidx.window.extensions + +# Storage +$(call inherit-product, $(SRC_TARGET_DIR)/product/emulated_storage.mk) + +# Suspend +PRODUCT_PACKAGES += \ + suspend_blocker_rpi + +# USB +PRODUCT_PACKAGES += \ + android.hardware.usb@1.0-service + +PRODUCT_COPY_FILES += \ + frameworks/native/data/etc/android.hardware.usb.accessory.xml:$(TARGET_COPY_OUT_VENDOR)/etc/permissions/android.hardware.usb.accessory.xml \ + frameworks/native/data/etc/android.hardware.usb.host.xml:$(TARGET_COPY_OUT_VENDOR)/etc/permissions/android.hardware.usb.host.xml \ + frameworks/native/data/etc/android.software.midi.xml:$(TARGET_COPY_OUT_VENDOR)/etc/permissions/android.software.midi.xml + +# V4L2 +PRODUCT_SOONG_NAMESPACES += external/v4l2_codec2 + +PRODUCT_PACKAGES += \ + android.hardware.media.c2@1.0-service-v4l2 \ + libc2plugin_store + +# Wifi +PRODUCT_PACKAGES += \ + android.hardware.wifi@1.0-service \ + hostapd \ + hostapd_cli \ + libwpa_client \ + wificond \ + wpa_cli \ + wpa_supplicant \ + wpa_supplicant.conf + +PRODUCT_COPY_FILES += \ + hardware/broadcom/wlan/bcmdhd/config/wpa_supplicant_overlay.conf:$(TARGET_COPY_OUT_VENDOR)/etc/wifi/wpa_supplicant_overlay.conf + +PRODUCT_COPY_FILES += \ + frameworks/native/data/etc/android.hardware.wifi.xml:$(TARGET_COPY_OUT_VENDOR)/etc/permissions/android.hardware.wifi.xml diff --git a/health/Android.bp b/health/Android.bp new file mode 100644 index 0000000..c969bf9 --- /dev/null +++ b/health/Android.bp @@ -0,0 +1,33 @@ +// Copyright (C) 2021-2022 KonstaKANG +// +// SPDX-License-Identifier: Apache-2.0 + +cc_binary { + name: "android.hardware.health@2.0-service.rpi", + init_rc: ["android.hardware.health@2.0-service.rpi.rc"], + vintf_fragments: ["android.hardware.health@2.0-service.rpi.xml"], + proprietary: true, + relative_install_path: "hw", + srcs: [ + "HealthService.cpp", + ], + cflags: [ + "-Wall", + "-Werror", + ], + static_libs: [ + "android.hardware.health@2.0-impl", + "android.hardware.health@1.0-convert", + "libhealthservice", + "libbatterymonitor", + "libhealthstoragedefault", + ], + shared_libs: [ + "libbase", + "libcutils", + "libhidlbase", + "libutils", + "android.hardware.health@2.0", + ], + header_libs: ["libhealthd_headers"], +} diff --git a/health/HealthService.cpp b/health/HealthService.cpp new file mode 100644 index 0000000..51b9574 --- /dev/null +++ b/health/HealthService.cpp @@ -0,0 +1,20 @@ +/* + * Copyright (C) 2021-2022 KonstaKANG + * + * SPDX-License-Identifier: Apache-2.0 + */ + +#include +#include + +int main() { + return health_service_main(); +} + +void healthd_board_init(struct healthd_config*) {} + +int healthd_board_battery_update(struct android::BatteryProperties* battery_props) { + battery_props->chargerAcOnline = true; + battery_props->batteryLevel = 100; + return 0; +} diff --git a/health/android.hardware.health@2.0-service.rpi.rc b/health/android.hardware.health@2.0-service.rpi.rc new file mode 100644 index 0000000..4f20720 --- /dev/null +++ b/health/android.hardware.health@2.0-service.rpi.rc @@ -0,0 +1,5 @@ +service vendor.health-hal-2-0 /vendor/bin/hw/android.hardware.health@2.0-service.rpi + class hal + user system + group system + file /dev/kmsg w diff --git a/health/android.hardware.health@2.0-service.rpi.xml b/health/android.hardware.health@2.0-service.rpi.xml new file mode 100644 index 0000000..a86714b --- /dev/null +++ b/health/android.hardware.health@2.0-service.rpi.xml @@ -0,0 +1,11 @@ + + + android.hardware.health + hwbinder + 2.0 + + IHealth + default + + + diff --git a/light/Android.bp b/light/Android.bp new file mode 100644 index 0000000..1d2a870 --- /dev/null +++ b/light/Android.bp @@ -0,0 +1,24 @@ +// Copyright (C) 2018 The LineageOS Project +// Copyright (C) 2021-2022 KonstaKANG +// +// SPDX-License-Identifier: Apache-2.0 + +cc_binary { + name: "android.hardware.light@2.0-service.rpi", + init_rc: ["android.hardware.light@2.0-service.rpi.rc"], + vintf_fragments: ["android.hardware.light@2.0-service.rpi.xml"], + proprietary: true, + relative_install_path: "hw", + srcs: [ + "Light.cpp", + "service.cpp", + ], + shared_libs: [ + "libbase", + "libcutils", + "libhardware", + "libhidlbase", + "libutils", + "android.hardware.light@2.0", + ], +} diff --git a/light/Light.cpp b/light/Light.cpp new file mode 100644 index 0000000..07a0906 --- /dev/null +++ b/light/Light.cpp @@ -0,0 +1,93 @@ +/* + * Copyright (C) 2018 The LineageOS Project + * Copyright (C) 2021-2022 KonstaKANG + * + * 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 "LightService" + +#include "Light.h" + +#include + +namespace { +using android::hardware::light::V2_0::LightState; + +static constexpr int DEFAULT_MAX_BRIGHTNESS = 255; + +static uint32_t rgbToBrightness(const LightState& state) { + uint32_t color = state.color & 0x00ffffff; + return ((77 * ((color >> 16) & 0xff)) + (150 * ((color >> 8) & 0xff)) + + (29 * (color & 0xff))) >> 8; +} +} // anonymous namespace + +namespace android { +namespace hardware { +namespace light { +namespace V2_0 { +namespace implementation { + +Light::Light(std::pair&& lcd_backlight) + : mLcdBacklight(std::move(lcd_backlight)) { + auto backlightFn(std::bind(&Light::setLcdBacklight, this, std::placeholders::_1)); + mLights.emplace(std::make_pair(Type::BACKLIGHT, backlightFn)); +} + +// Methods from ::android::hardware::light::V2_0::ILight follow. +Return Light::setLight(Type type, const LightState& state) { + auto it = mLights.find(type); + + if (it == mLights.end()) { + return Status::LIGHT_NOT_SUPPORTED; + } + + it->second(state); + + return Status::SUCCESS; +} + +Return Light::getSupportedTypes(getSupportedTypes_cb _hidl_cb) { + std::vector types; + + for (auto const& light : mLights) { + types.push_back(light.first); + } + + _hidl_cb(types); + + return Void(); +} + +void Light::setLcdBacklight(const LightState& state) { + std::lock_guard lock(mLock); + + uint32_t brightness = rgbToBrightness(state); + + // If max panel brightness is not the default (255), + // apply linear scaling across the accepted range. + if (mLcdBacklight.second != DEFAULT_MAX_BRIGHTNESS) { + int old_brightness = brightness; + brightness = brightness * mLcdBacklight.second / DEFAULT_MAX_BRIGHTNESS; + LOG(VERBOSE) << "scaling brightness " << old_brightness << " => " << brightness; + } + + mLcdBacklight.first << brightness << std::endl; +} + +} // namespace implementation +} // namespace V2_0 +} // namespace light +} // namespace hardware +} // namespace android diff --git a/light/Light.h b/light/Light.h new file mode 100644 index 0000000..601a072 --- /dev/null +++ b/light/Light.h @@ -0,0 +1,56 @@ +/* + * Copyright (C) 2018 The LineageOS Project + * Copyright (C) 2021-2022 KonstaKANG + * + * 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 ANDROID_HARDWARE_LIGHT_V2_0_LIGHT_H +#define ANDROID_HARDWARE_LIGHT_V2_0_LIGHT_H + +#include +#include + +#include +#include +#include + +namespace android { +namespace hardware { +namespace light { +namespace V2_0 { +namespace implementation { + +struct Light : public ILight { + Light(std::pair&& lcd_backlight); + + // Methods from ::android::hardware::light::V2_0::ILight follow. + Return setLight(Type type, const LightState& state) override; + Return getSupportedTypes(getSupportedTypes_cb _hidl_cb) override; + + private: + void setLcdBacklight(const LightState& state); + + std::pair mLcdBacklight; + + std::unordered_map> mLights; + std::mutex mLock; +}; + +} // namespace implementation +} // namespace V2_0 +} // namespace light +} // namespace hardware +} // namespace android + +#endif // ANDROID_HARDWARE_LIGHT_V2_0_LIGHT_H diff --git a/light/android.hardware.light@2.0-service.rpi.rc b/light/android.hardware.light@2.0-service.rpi.rc new file mode 100644 index 0000000..42eecc2 --- /dev/null +++ b/light/android.hardware.light@2.0-service.rpi.rc @@ -0,0 +1,11 @@ +on init + chown system system /sys/class/backlight/rpi_backlight/brightness + chmod 660 /sys/class/backlight/rpi_backlight/brightness + +service vendor.light-hal-2-0 /vendor/bin/hw/android.hardware.light@2.0-service.rpi + interface android.hardware.light@2.0::ILight default + class hal + user system + group system + # shutting off lights while powering-off + shutdown critical diff --git a/light/android.hardware.light@2.0-service.rpi.xml b/light/android.hardware.light@2.0-service.rpi.xml new file mode 100644 index 0000000..6bf62e9 --- /dev/null +++ b/light/android.hardware.light@2.0-service.rpi.xml @@ -0,0 +1,11 @@ + + + android.hardware.light + hwbinder + 2.0 + + ILight + default + + + diff --git a/light/service.cpp b/light/service.cpp new file mode 100644 index 0000000..fa6daa4 --- /dev/null +++ b/light/service.cpp @@ -0,0 +1,63 @@ +/* + * Copyright (C) 2018 The LineageOS Project + * Copyright (C) 2021-2022 KonstaKANG + * + * 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 "android.hardware.light@2.0-service.rpi" + +#include +#include +#include + +#include "Light.h" + +// libhwbinder: +using android::hardware::configureRpcThreadpool; +using android::hardware::joinRpcThreadpool; + +// Generated HIDL files +using android::hardware::light::V2_0::ILight; +using android::hardware::light::V2_0::implementation::Light; + +const static std::string kLcdBacklightPath = "/sys/class/backlight/rpi_backlight/brightness"; + +int main() { + uint32_t lcdMaxBrightness = 255; + + std::ofstream lcdBacklight(kLcdBacklightPath); + if (!lcdBacklight) { + LOG(ERROR) << "Failed to open " << kLcdBacklightPath << ", error=" << errno + << " (" << strerror(errno) << ")"; + //return -errno; + } + + android::sp service = new Light( + {std::move(lcdBacklight), lcdMaxBrightness}); + + configureRpcThreadpool(1, true); + + android::status_t status = service->registerAsService(); + + if (status != android::OK) { + LOG(ERROR) << "Cannot register Light HAL service"; + //return 1; + } + + LOG(INFO) << "Light HAL Ready."; + joinRpcThreadpool(); + // Under normal cases, execution will not reach this line. + LOG(ERROR) << "Light HAL failed to join thread pool."; + return 1; +} diff --git a/manifest.xml b/manifest.xml new file mode 100644 index 0000000..1225f39 --- /dev/null +++ b/manifest.xml @@ -0,0 +1,101 @@ + + + android.hardware.audio + hwbinder + 7.0 + + IDevicesFactory + default + + + + android.hardware.audio.effect + hwbinder + 7.0 + + IEffectsFactory + default + + + + android.hardware.bluetooth + hwbinder + 1.0 + + IBluetoothHci + default + + + + android.hardware.bluetooth.audio + hwbinder + 2.0 + + IBluetoothAudioProvidersFactory + default + + + + android.hardware.camera.provider + hwbinder + 2.5 + + ICameraProvider + external/0 + legacy/0 + + + + android.hardware.drm + hwbinder + 1.0 + + ICryptoFactory + default + + + IDrmFactory + default + + + + android.hardware.graphics.composer + hwbinder + 2.4 + + IComposer + default + + + + android.hardware.keymaster + hwbinder + 3.0 + + IKeymasterDevice + default + + + + android.hardware.media.c2 + hwbinder + 1.0 + + IComponentStore + default + + + + android.hardware.media.omx + hwbinder + 1.0 + + IOmx + default + + + IOmxStore + default + + + diff --git a/media/media_codecs.xml b/media/media_codecs.xml new file mode 100644 index 0000000..f14279e --- /dev/null +++ b/media/media_codecs.xml @@ -0,0 +1,24 @@ + + + + + + + + + diff --git a/media/media_codecs_v4l2_c2_video.xml b/media/media_codecs_v4l2_c2_video.xml new file mode 100644 index 0000000..36df458 --- /dev/null +++ b/media/media_codecs_v4l2_c2_video.xml @@ -0,0 +1,106 @@ + + + + + + + + + + + + + + + + + + + + + diff --git a/mkbootimg.mk b/mkbootimg.mk new file mode 100644 index 0000000..8d36d53 --- /dev/null +++ b/mkbootimg.mk @@ -0,0 +1,27 @@ +# +# Copyright (C) 2021-2022 KonstaKANG +# +# SPDX-License-Identifier: Apache-2.0 +# + +DEVICE_PATH := device/brcm/rpi4 +KERNEL_PATH := device/brcm/rpi4-kernel +VENDOR_PATH := vendor/brcm + +RPI_BOOT_OUT := $(PRODUCT_OUT)/rpiboot +$(RPI_BOOT_OUT): $(INSTALLED_RAMDISK_TARGET) + mkdir -p $(RPI_BOOT_OUT) + mkdir -p $(RPI_BOOT_OUT)/overlays + cp $(DEVICE_PATH)/boot/* $(RPI_BOOT_OUT) + cp $(KERNEL_PATH)/Image $(RPI_BOOT_OUT) + cp $(KERNEL_PATH)/bcm2711-rpi-*.dtb $(RPI_BOOT_OUT) + cp $(KERNEL_PATH)/overlays/* $(RPI_BOOT_OUT)/overlays + cp $(PRODUCT_OUT)/ramdisk.img $(RPI_BOOT_OUT) + cp $(VENDOR_PATH)/rpi4/proprietary/boot/* $(RPI_BOOT_OUT) + echo $(BOARD_KERNEL_CMDLINE) > $(RPI_BOOT_OUT)/cmdline.txt + +$(INSTALLED_BOOTIMAGE_TARGET): $(RPI_BOOT_OUT) + $(call pretty,"Target boot image: $@") + dd if=/dev/zero of=$@ bs=1M count=128 + mkfs.fat -F 32 -n "boot" $@ + mcopy -s -i $@ $(RPI_BOOT_OUT)/* :: diff --git a/mkimg.sh b/mkimg.sh new file mode 100755 index 0000000..fa66ba1 --- /dev/null +++ b/mkimg.sh @@ -0,0 +1,72 @@ +#!/bin/bash + +# +# Copyright (C) 2021-2022 KonstaKANG +# +# SPDX-License-Identifier: Apache-2.0 +# + +VERSION=RaspberryVanillaAOSP12 +DATE=$(date +%Y%m%d) +IMGNAME=${VERSION}-${DATE}-rpi4.img +IMGSIZE=7 +OUTDIR=$(pwd | sed 's/\/device\/brcm\/rpi4$//')/out/target/product/rpi4 + +echo "Creating image file ${OUTDIR}/${IMGNAME}..." +sudo dd if=/dev/zero of="${OUTDIR}/${IMGNAME}" bs=1M count=$(echo "${IMGSIZE}*1024" | bc) +sync + +echo "Creating partitions..." +( +echo o +echo n +echo p +echo 1 +echo +echo +128M +echo n +echo p +echo 2 +echo +echo +2048M +echo n +echo p +echo 3 +echo +echo +256M +echo n +echo p +echo +echo +echo t +echo 1 +echo c +echo a +echo 1 +echo w +) | sudo fdisk "${OUTDIR}/${IMGNAME}" +sync + +LOOPDEV=$(sudo kpartx -av "${OUTDIR}/${IMGNAME}" | awk 'NR==1{ sub(/p[0-9]$/, "", $3); print $3 }') +if [ -z ${LOOPDEV} ]; then + echo "Unable to find loop device!" + exit 1 +fi +echo "Image mounted as /dev/${LOOPDEV}" +sleep 1 + +echo "Copying boot..." +sudo dd if=${OUTDIR}/boot.img of=/dev/mapper/${LOOPDEV}p1 bs=1M +echo "Copying system..." +sudo dd if=${OUTDIR}/system.img of=/dev/mapper/${LOOPDEV}p2 bs=1M +echo "Copying vendor..." +sudo dd if=${OUTDIR}/vendor.img of=/dev/mapper/${LOOPDEV}p3 bs=1M +echo "Creating userdata..." +sudo mkfs.ext4 /dev/mapper/${LOOPDEV}p4 -I 512 -L userdata +sudo resize2fs /dev/mapper/${LOOPDEV}p4 1212156 +sync + +sudo kpartx -d "/dev/${LOOPDEV}" +echo "Done, created ${OUTDIR}/${IMGNAME}!" + +exit 0 diff --git a/overlay/AndroidRpiOverlay/Android.bp b/overlay/AndroidRpiOverlay/Android.bp new file mode 100644 index 0000000..aba5a13 --- /dev/null +++ b/overlay/AndroidRpiOverlay/Android.bp @@ -0,0 +1,10 @@ +// Copyright (C) 2021-2022 KonstaKANG +// +// SPDX-License-Identifier: Apache-2.0 + +runtime_resource_overlay { + name: "AndroidRpiOverlay", + resource_dirs: ["res"], + sdk_version: "current", + proprietary: true +} diff --git a/overlay/AndroidRpiOverlay/AndroidManifest.xml b/overlay/AndroidRpiOverlay/AndroidManifest.xml new file mode 100644 index 0000000..97bc586 --- /dev/null +++ b/overlay/AndroidRpiOverlay/AndroidManifest.xml @@ -0,0 +1,19 @@ + + + + + + + diff --git a/overlay/AndroidRpiOverlay/res/values/config.xml b/overlay/AndroidRpiOverlay/res/values/config.xml new file mode 100644 index 0000000..c0697f1 --- /dev/null +++ b/overlay/AndroidRpiOverlay/res/values/config.xml @@ -0,0 +1,114 @@ + + + + + + + false + + + false + + + false + + + true + + + + + + + "wifi,1,1,1,-1,true" + "bluetooth,7,7,2,-1,true" + "ethernet,9,9,9,-1,true" + + + + + + "1,1" + "7,1" + "9,1" + + + + 128 + + + 20 + + + 20 + + + true + + + 1 + + + 2 + + diff --git a/overlay/SettingsProviderRpiOverlay/Android.bp b/overlay/SettingsProviderRpiOverlay/Android.bp new file mode 100644 index 0000000..ef6c530 --- /dev/null +++ b/overlay/SettingsProviderRpiOverlay/Android.bp @@ -0,0 +1,10 @@ +// Copyright (C) 2021-2022 KonstaKANG +// +// SPDX-License-Identifier: Apache-2.0 + +runtime_resource_overlay { + name: "SettingsProviderRpiOverlay", + resource_dirs: ["res"], + sdk_version: "current", + proprietary: true +} diff --git a/overlay/SettingsProviderRpiOverlay/AndroidManifest.xml b/overlay/SettingsProviderRpiOverlay/AndroidManifest.xml new file mode 100644 index 0000000..dbf6564 --- /dev/null +++ b/overlay/SettingsProviderRpiOverlay/AndroidManifest.xml @@ -0,0 +1,19 @@ + + + + + + + diff --git a/overlay/SettingsProviderRpiOverlay/res/values/defaults.xml b/overlay/SettingsProviderRpiOverlay/res/values/defaults.xml new file mode 100644 index 0000000..8a8ac4a --- /dev/null +++ b/overlay/SettingsProviderRpiOverlay/res/values/defaults.xml @@ -0,0 +1,40 @@ + + + + + + + 128 + + + false + + + 0 + + + true + + + true + + + true + true + + diff --git a/overlay/SettingsRpiOverlay/Android.bp b/overlay/SettingsRpiOverlay/Android.bp new file mode 100644 index 0000000..bf70fa0 --- /dev/null +++ b/overlay/SettingsRpiOverlay/Android.bp @@ -0,0 +1,10 @@ +// Copyright (C) 2021-2022 KonstaKANG +// +// SPDX-License-Identifier: Apache-2.0 + +runtime_resource_overlay { + name: "SettingsRpiOverlay", + resource_dirs: ["res"], + sdk_version: "current", + proprietary: true +} diff --git a/overlay/SettingsRpiOverlay/AndroidManifest.xml b/overlay/SettingsRpiOverlay/AndroidManifest.xml new file mode 100644 index 0000000..31546b7 --- /dev/null +++ b/overlay/SettingsRpiOverlay/AndroidManifest.xml @@ -0,0 +1,19 @@ + + + + + + + diff --git a/overlay/SettingsRpiOverlay/res/values/config.xml b/overlay/SettingsRpiOverlay/res/values/config.xml new file mode 100644 index 0000000..6b55694 --- /dev/null +++ b/overlay/SettingsRpiOverlay/res/values/config.xml @@ -0,0 +1,30 @@ + + + + + + + false + + + false + + + false + + diff --git a/overlay/SystemUIRpiOverlay/Android.bp b/overlay/SystemUIRpiOverlay/Android.bp new file mode 100644 index 0000000..525f585 --- /dev/null +++ b/overlay/SystemUIRpiOverlay/Android.bp @@ -0,0 +1,10 @@ +// Copyright (C) 2021-2022 KonstaKANG +// +// SPDX-License-Identifier: Apache-2.0 + +runtime_resource_overlay { + name: "SystemUIRpiOverlay", + resource_dirs: ["res"], + sdk_version: "current", + proprietary: true +} diff --git a/overlay/SystemUIRpiOverlay/AndroidManifest.xml b/overlay/SystemUIRpiOverlay/AndroidManifest.xml new file mode 100644 index 0000000..63511fc --- /dev/null +++ b/overlay/SystemUIRpiOverlay/AndroidManifest.xml @@ -0,0 +1,19 @@ + + + + + + + diff --git a/overlay/SystemUIRpiOverlay/res/values/config.xml b/overlay/SystemUIRpiOverlay/res/values/config.xml new file mode 100644 index 0000000..7267652 --- /dev/null +++ b/overlay/SystemUIRpiOverlay/res/values/config.xml @@ -0,0 +1,26 @@ + + + + + + + + internet,bt,airplane,hotspot,dark,screenrecord + + + diff --git a/overlay/WifiRpiOverlay/Android.bp b/overlay/WifiRpiOverlay/Android.bp new file mode 100644 index 0000000..ef021ce --- /dev/null +++ b/overlay/WifiRpiOverlay/Android.bp @@ -0,0 +1,10 @@ +// Copyright (C) 2021-2022 KonstaKANG +// +// SPDX-License-Identifier: Apache-2.0 + +runtime_resource_overlay { + name: "WifiRpiOverlay", + resource_dirs: ["res"], + sdk_version: "current", + proprietary: true +} diff --git a/overlay/WifiRpiOverlay/AndroidManifest.xml b/overlay/WifiRpiOverlay/AndroidManifest.xml new file mode 100644 index 0000000..ef6c15b --- /dev/null +++ b/overlay/WifiRpiOverlay/AndroidManifest.xml @@ -0,0 +1,20 @@ + + + + + + + diff --git a/overlay/WifiRpiOverlay/res/values/config.xml b/overlay/WifiRpiOverlay/res/values/config.xml new file mode 100644 index 0000000..2c57358 --- /dev/null +++ b/overlay/WifiRpiOverlay/res/values/config.xml @@ -0,0 +1,27 @@ + + + + + + + true + + diff --git a/ramdisk/fstab.rpi4 b/ramdisk/fstab.rpi4 new file mode 100644 index 0000000..ea20614 --- /dev/null +++ b/ramdisk/fstab.rpi4 @@ -0,0 +1,10 @@ +# Android fstab file. +# The filesystem that contains the filesystem checker binary (typically /system) cannot +# specify MF_CHECK, and must come before any filesystems that do specify MF_CHECK + +# +/dev/block/mmcblk0p2 /system ext4 ro,barrier=1 wait,first_stage_mount +/dev/block/mmcblk0p3 /vendor ext4 ro,barrier=1 wait,first_stage_mount +/dev/block/mmcblk0p4 /data ext4 noatime,nosuid,nodev,nomblk_io_submit,errors=panic wait,check,formattable,encryptable=footer,quota +/devices/platform/scb/*.pcie/*/*/*/usb* auto auto defaults voldmanaged=usb:auto +/devices/platform/soc/*.usb/usb* auto auto defaults voldmanaged=usb:auto diff --git a/ramdisk/init.rpi4.rc b/ramdisk/init.rpi4.rc new file mode 100644 index 0000000..008d826 --- /dev/null +++ b/ramdisk/init.rpi4.rc @@ -0,0 +1,39 @@ +import /vendor/etc/init/hw/init.rpi4.usb.rc + +on init + symlink /sdcard /storage/sdcard0 + +on fs + mount_all /vendor/etc/fstab.rpi4 + +on post-fs-data + # Create the directories used by the Wireless subsystem + mkdir /data/vendor/wifi 0770 wifi wifi + mkdir /data/vendor/wifi/wpa 0770 wifi wifi + mkdir /data/vendor/wifi/wpa/sockets 0770 wifi wifi + + # Set indication (checked by vold) that we have finished this action + setprop vold.post_fs_data_done 1 + +on property:sys.boot_completed=1 + # Reinit lmkd to reconfigure lmkd properties + setprop lmkd.reinit 1 + +on property:sys.boot_completed=1 && property:persist.audio.hdmi.device=* + stop alsa_loop + start alsa_loop + +on property:persist.audio.hdmi.device= + stop alsa_loop + +service alsa_loop /vendor/bin/alsa_loop --cdevice=hw:${persist.audio.pcm.card},1 --pdevice=default:CARD=${persist.audio.hdmi.device} + user root + group system + priority 10 + ioprio rt 4 + disabled + +service suspend_blocker_rpi /vendor/bin/suspend_blocker_rpi + class early_hal # Start together with system_suspend HAL + group system + user root diff --git a/ramdisk/init.rpi4.usb.rc b/ramdisk/init.rpi4.usb.rc new file mode 100644 index 0000000..04c38f7 --- /dev/null +++ b/ramdisk/init.rpi4.usb.rc @@ -0,0 +1,90 @@ +on boot + mount configfs none /config + mkdir /config/usb_gadget/g1 0770 shell shell + mkdir /config/usb_gadget/g1/strings/0x409 0770 shell shell + write /config/usb_gadget/g1/bcdDevice 0x0223 + write /config/usb_gadget/g1/bcdUSB 0x0200 + write /config/usb_gadget/g1/idVendor 0x18d1 + write /config/usb_gadget/g1/strings/0x409/serialnumber ${ro.serialno} + write /config/usb_gadget/g1/strings/0x409/manufacturer "Raspberry" + write /config/usb_gadget/g1/strings/0x409/product "Pi 4" + mkdir /config/usb_gadget/g1/functions/ffs.adb + mkdir /config/usb_gadget/g1/functions/ffs.mtp + mkdir /config/usb_gadget/g1/functions/ffs.ptp + mkdir /config/usb_gadget/g1/functions/accessory.gs2 + mkdir /config/usb_gadget/g1/functions/audio_source.gs3 + mkdir /config/usb_gadget/g1/functions/rndis.gs4 + mkdir /config/usb_gadget/g1/functions/midi.gs5 + mkdir /config/usb_gadget/g1/configs/b.1 0770 shell shell + mkdir /config/usb_gadget/g1/configs/b.1/strings/0x409 0770 shell shell + write /config/usb_gadget/g1/configs/b.1/MaxPower 500 + write /config/usb_gadget/g1/os_desc/b_vendor_code 0x1 + write /config/usb_gadget/g1/os_desc/qw_sign "MSFT100" + mkdir /dev/usb-ffs 0775 shell shell + mkdir /dev/usb-ffs/adb 0770 shell shell + mkdir /dev/usb-ffs/mtp 0770 mtp mtp + mkdir /dev/usb-ffs/ptp 0770 mtp mtp + setprop sys.usb.mtp.device_type 3 + symlink /config/usb_gadget/g1/configs/b.1 /config/usb_gadget/g1/os_desc/b.1 + +on property:sys.usb.controller=* + mount functionfs adb /dev/usb-ffs/adb uid=2000,gid=2000 + mount functionfs mtp /dev/usb-ffs/mtp rmode=0770,fmode=0660,uid=1024,gid=1024,no_disconnect=1 + mount functionfs ptp /dev/usb-ffs/ptp rmode=0770,fmode=0660,uid=1024,gid=1024,no_disconnect=1 + setprop sys.usb.configfs 1 + +on property:sys.usb.config=none && property:sys.usb.configfs=1 + write /config/usb_gadget/g1/os_desc/use 0 + +on property:sys.usb.config=mtp && property:sys.usb.configfs=1 + write /config/usb_gadget/g1/idProduct 0x4ee1 + write /config/usb_gadget/g1/os_desc/use 1 + symlink /config/usb_gadget/g1/functions/ffs.mtp /config/usb_gadget/g1/configs/b.1/f1 + +on property:sys.usb.ffs.ready=1 && property:sys.usb.config=mtp,adb && property:sys.usb.configfs=1 + write /config/usb_gadget/g1/idProduct 0x4ee2 + write /config/usb_gadget/g1/os_desc/use 1 + symlink /config/usb_gadget/g1/functions/ffs.mtp /config/usb_gadget/g1/configs/b.1/f1 + +on property:sys.usb.config=rndis && property:sys.usb.configfs=1 + write /config/usb_gadget/g1/idProduct 0x4ee3 + +on property:sys.usb.ffs.ready=1 && property:sys.usb.config=rndis,adb && property:sys.usb.configfs=1 + write /config/usb_gadget/g1/idProduct 0x4ee4 + +on property:sys.usb.config=ptp && property:sys.usb.configfs=1 + write /config/usb_gadget/g1/idProduct 0x4ee5 + write /config/usb_gadget/g1/os_desc/use 1 + symlink /config/usb_gadget/g1/functions/ffs.ptp /config/usb_gadget/g1/configs/b.1/f1 + +on property:sys.usb.ffs.ready=1 && property:sys.usb.config=ptp,adb && property:sys.usb.configfs=1 + write /config/usb_gadget/g1/idProduct 0x4ee6 + write /config/usb_gadget/g1/os_desc/use 1 + symlink /config/usb_gadget/g1/functions/ffs.ptp /config/usb_gadget/g1/configs/b.1/f1 + +on property:sys.usb.ffs.ready=1 && property:sys.usb.config=adb && property:sys.usb.configfs=1 + write /config/usb_gadget/g1/idProduct 0x4ee7 + +on property:sys.usb.config=midi && property:sys.usb.configfs=1 + write /config/usb_gadget/g1/idProduct 0x4ee8 + +on property:sys.usb.ffs.ready=1 && property:sys.usb.config=midi,adb && property:sys.usb.configfs=1 + write /config/usb_gadget/g1/idProduct 0x4ee9 + +on property:sys.usb.config=accessory && property:sys.usb.configfs=1 + write /config/usb_gadget/g1/idProduct 0x2d00 + +on property:sys.usb.ffs.ready=1 && property:sys.usb.config=accessory,adb && property:sys.usb.configfs=1 + write /config/usb_gadget/g1/idProduct 0x2d01 + +on property:sys.usb.config=audio_source && property:sys.usb.configfs=1 + write /config/usb_gadget/g1/idProduct 0x2d02 + +on property:sys.usb.ffs.ready=1 && property:sys.usb.config=audio_source,adb && property:sys.usb.configfs=1 + write /config/usb_gadget/g1/idProduct 0x2d03 + +on property:sys.usb.config=accessory,audio_source && property:sys.usb.configfs=1 + write /config/usb_gadget/g1/idProduct 0x2d04 + +on property:sys.usb.ffs.ready=1 && property:sys.usb.config=accessory,audio_source,adb && property:sys.usb.configfs=1 + write /config/usb_gadget/g1/idProduct 0x2d05 diff --git a/ramdisk/ueventd.rpi4.rc b/ramdisk/ueventd.rpi4.rc new file mode 100644 index 0000000..300bb62 --- /dev/null +++ b/ramdisk/ueventd.rpi4.rc @@ -0,0 +1,23 @@ +# Bluetooth +/dev/ttyAMA0 0660 bluetooth bluetooth +/dev/rfkill 0660 bluetooth bluetooth +/dev/vcio 0660 system bluetooth + +# Camera +/dev/media* 0660 system camera +/dev/v4l-subdev* 0660 system camera +/dev/video* 0660 system camera + +# DMA +/dev/dma_heap/linux,cma 0666 system graphics + +# ION +/dev/ion 0664 system system + +# V4L2 +/dev/media0 0660 media media +/dev/video10 0660 media media +/dev/video11 0660 media media +/dev/video12 0660 media media +/dev/video18 0660 media media +/dev/video19 0660 media media diff --git a/seccomp_policy/codec2.vendor.ext.policy b/seccomp_policy/codec2.vendor.ext.policy new file mode 100644 index 0000000..faaaedc --- /dev/null +++ b/seccomp_policy/codec2.vendor.ext.policy @@ -0,0 +1,20 @@ +# device specific syscalls +_llseek: 1 +epoll_create1: 1 +epoll_ctl: 1 +epoll_pwait: 1 +eventfd2: 1 +fstat64: 1 +fstatat64: 1 +fstatfs64: 1 +getcwd: 1 +getdents64: 1 +geteuid32: 1 +getuid32: 1 +mmap2: 1 +open: 1 +pselect6: 1 +sched_getaffinity: 1 +statfs64: 1 +sysinfo: 1 +ugetrlimit: 1 diff --git a/seccomp_policy/mediacodec.policy b/seccomp_policy/mediacodec.policy new file mode 100644 index 0000000..77bb74e --- /dev/null +++ b/seccomp_policy/mediacodec.policy @@ -0,0 +1,9 @@ +# device specific syscalls +_llseek: 1 +eventfd2: 1 +getcwd: 1 +pselect6: 1 +recvfrom: 1 +sched_getaffinity: 1 +sendto: 1 +sysinfo: 1 diff --git a/seccomp_policy/mediaswcodec.policy b/seccomp_policy/mediaswcodec.policy new file mode 100644 index 0000000..66da4b7 --- /dev/null +++ b/seccomp_policy/mediaswcodec.policy @@ -0,0 +1,3 @@ +# device specific syscalls +sched_getaffinity: 1 +sysinfo: 1 diff --git a/sepolicy/alsa_loop.te b/sepolicy/alsa_loop.te new file mode 100644 index 0000000..eecdf38 --- /dev/null +++ b/sepolicy/alsa_loop.te @@ -0,0 +1,7 @@ +type alsa_loop, domain; +type alsa_loop_exec, exec_type, vendor_file_type, file_type; + +init_daemon_domain(alsa_loop) + +allow alsa_loop audio_device:dir r_dir_perms; +allow alsa_loop audio_device:chr_file rw_file_perms; diff --git a/sepolicy/bluetooth.te b/sepolicy/bluetooth.te new file mode 100644 index 0000000..c700bb3 --- /dev/null +++ b/sepolicy/bluetooth.te @@ -0,0 +1 @@ +allow bluetooth vcio_device:chr_file rw_file_perms; diff --git a/sepolicy/bootanim.te b/sepolicy/bootanim.te new file mode 100644 index 0000000..e8e7494 --- /dev/null +++ b/sepolicy/bootanim.te @@ -0,0 +1 @@ +gpu_access(bootanim) diff --git a/sepolicy/device.te b/sepolicy/device.te new file mode 100644 index 0000000..9226462 --- /dev/null +++ b/sepolicy/device.te @@ -0,0 +1 @@ +type vcio_device, dev_type, mlstrustedobject; diff --git a/sepolicy/file.te b/sepolicy/file.te new file mode 100644 index 0000000..00743ac --- /dev/null +++ b/sepolicy/file.te @@ -0,0 +1 @@ +type sysfs_gpu, fs_type, sysfs_type; diff --git a/sepolicy/file_contexts b/sepolicy/file_contexts new file mode 100644 index 0000000..f063b5a --- /dev/null +++ b/sepolicy/file_contexts @@ -0,0 +1,49 @@ +# Audio +/vendor/bin/alsa_loop u:object_r:alsa_loop_exec:s0 + +# Bluetooth +/dev/ttyAMA0 u:object_r:hci_attach_dev:s0 +/dev/vcio u:object_r:vcio_device:s0 +/sys/class/rfkill/rfkill[0-9]/state u:object_r:sysfs_bluetooth_writable:s0 + +# DRM +/vendor/bin/hw/android\.hardware\.drm@1\.4-service\.clearkey u:object_r:hal_drm_clearkey_exec:s0 +/vendor/bin/hw/android\.hardware\.drm@1\.4-service\.widevine u:object_r:hal_drm_widevine_exec:s0 + +# Gatekeeper +/vendor/bin/hw/android\.hardware\.gatekeeper@1\.0-service.software u:object_r:hal_gatekeeper_default_exec:s0 + +# Graphics +/dev/dri u:object_r:gpu_device:s0 +/dev/dri/card0 u:object_r:gpu_device:s0 +/dev/dri/card1 u:object_r:gpu_device:s0 +/dev/dri/renderD128 u:object_r:gpu_device:s0 +/vendor/bin/hw/android\.hardware\.graphics\.allocator@4\.0-service\.minigbm_gbm_mesa u:object_r:hal_graphics_allocator_default_exec:s0 +/vendor/lib(64)?/dri/libgallium_dri\.so u:object_r:same_process_hal_file:s0 +/vendor/lib(64)?/hw/android\.hardware\.graphics.mapper@4\.0-impl\.minigbm_gbm_mesa\.so u:object_r:same_process_hal_file:s0 +/vendor/lib(64)?/hw/vulkan\.broadcom\.so u:object_r:same_process_hal_file:s0 +/vendor/lib(64)?/libdrm\.so u:object_r:same_process_hal_file:s0 +/vendor/lib(64)?/libgbm_mesa\.so u:object_r:same_process_hal_file:s0 +/vendor/lib{64}?/libgbm_mesa_wrapper\.so u:object_r:same_process_hal_file:s0 +/vendor/lib(64)?/libglapi\.so u:object_r:same_process_hal_file:s0 +/vendor/lib(64)?/libminigbm_gralloc_gbm_mesa\.so u:object_r:same_process_hal_file:s0 + +# Health +/vendor/bin/hw/android\.hardware\.health@2\.0-service.rpi u:object_r:hal_health_default_exec:s0 + +# Lights +/sys/class/backlight/rpi_backlight/brightness u:object_r:sysfs_leds:s0 +/sys/devices/platform/rpi_backlight/backlight/rpi_backlight/brightness u:object_r:sysfs_leds:s0 +/vendor/bin/hw/android\.hardware\.light@2\.0-service.rpi u:object_r:hal_light_default_exec:s0 + +# Partitions +/dev/block/mmcblk0p1 u:object_r:boot_block_device:s0 +/dev/block/mmcblk0p2 u:object_r:system_block_device:s0 +/dev/block/mmcblk0p3 u:object_r:system_block_device:s0 +/dev/block/mmcblk0p4 u:object_r:userdata_block_device:s0 + +# Suspend +/vendor/bin/suspend_blocker_rpi u:object_r:suspend_blocker_exec:s0 + +# V4L2 +/vendor/bin/hw/android\.hardware\.media\.c2@1\.0-service-v4l2(.*)? u:object_r:mediacodec_exec:s0 diff --git a/sepolicy/genfs_contexts b/sepolicy/genfs_contexts new file mode 100644 index 0000000..6a3a935 --- /dev/null +++ b/sepolicy/genfs_contexts @@ -0,0 +1,3 @@ +genfscon sysfs /devices/platform/v3dbus/fec00000.v3d/uevent u:object_r:sysfs_gpu:s0 +genfscon sysfs /devices/platform/gpu/uevent u:object_r:sysfs_gpu:s0 +genfscon sysfs /firmware/devicetree/base/serial-number u:object_r:sysfs_dt_firmware_android:s0 diff --git a/sepolicy/hal_camera.te b/sepolicy/hal_camera.te new file mode 100644 index 0000000..aefd2fe --- /dev/null +++ b/sepolicy/hal_camera.te @@ -0,0 +1,14 @@ +vndbinder_use(hal_camera_default); + +allow hal_camera_default hal_graphics_mapper_hwservice:hwservice_manager find; +hal_client_domain(hal_camera_default, hal_graphics_allocator); +hal_client_domain(hal_camera_default, hal_graphics_composer); + +allow cameraserver device:dir r_dir_perms; +allow cameraserver video_device:dir r_dir_perms; +allow cameraserver video_device:chr_file rw_file_perms; + +allow hal_camera_default gpu_device:dir { open read search }; +allow hal_camera_default gpu_device:chr_file { open read write ioctl map getattr }; +allow cameraserver gpu_device:dir { open read write search getattr }; +allow cameraserver gpu_device:chr_file { open read write ioctl map getattr }; diff --git a/sepolicy/hal_drm_clearkey.te b/sepolicy/hal_drm_clearkey.te new file mode 100644 index 0000000..624e17f --- /dev/null +++ b/sepolicy/hal_drm_clearkey.te @@ -0,0 +1,10 @@ +type hal_drm_clearkey, domain; +type hal_drm_clearkey_exec, exec_type, vendor_file_type, file_type; + +init_daemon_domain(hal_drm_clearkey) + +hal_server_domain(hal_drm_clearkey, hal_drm) + +vndbinder_use(hal_drm_clearkey); + +allow hal_drm_clearkey hal_allocator_server:fd use; diff --git a/sepolicy/hal_drm_widevine.te b/sepolicy/hal_drm_widevine.te new file mode 100644 index 0000000..669a93c --- /dev/null +++ b/sepolicy/hal_drm_widevine.te @@ -0,0 +1,13 @@ +type hal_drm_widevine, domain; +type hal_drm_widevine_exec, exec_type, vendor_file_type, file_type; + +init_daemon_domain(hal_drm_widevine) + +hal_server_domain(hal_drm_widevine, hal_drm) + +vndbinder_use(hal_drm_widevine); + +allow hal_drm_widevine hal_allocator_server:fd use; +allow hal_drm mediacodec:fd use; + +hal_client_domain(hal_drm_widevine, hal_graphics_composer); diff --git a/sepolicy/hal_graphics_allocator_default.te b/sepolicy/hal_graphics_allocator_default.te new file mode 100644 index 0000000..00f38cc --- /dev/null +++ b/sepolicy/hal_graphics_allocator_default.te @@ -0,0 +1 @@ +gpu_access(hal_graphics_allocator_default) diff --git a/sepolicy/hal_graphics_composer_default.te b/sepolicy/hal_graphics_composer_default.te new file mode 100644 index 0000000..a4e1116 --- /dev/null +++ b/sepolicy/hal_graphics_composer_default.te @@ -0,0 +1,2 @@ +vndbinder_use(hal_graphics_composer_default) +gpu_access(hal_graphics_composer_default) diff --git a/sepolicy/init.te b/sepolicy/init.te new file mode 100644 index 0000000..1da3af0 --- /dev/null +++ b/sepolicy/init.te @@ -0,0 +1,2 @@ +allow init kernel:system module_request; +allow init tmpfs:lnk_file create; diff --git a/sepolicy/kernel.te b/sepolicy/kernel.te new file mode 100644 index 0000000..6d977fb --- /dev/null +++ b/sepolicy/kernel.te @@ -0,0 +1,4 @@ +allow kernel self:capability mknod; +allow kernel self:system module_request; +allow kernel device:dir { create write add_name remove_name rmdir }; +allow kernel device:chr_file { create setattr getattr unlink }; diff --git a/sepolicy/mediacodec.te b/sepolicy/mediacodec.te new file mode 100644 index 0000000..6119c90 --- /dev/null +++ b/sepolicy/mediacodec.te @@ -0,0 +1 @@ +gpu_access(mediacodec) diff --git a/sepolicy/mediaprovider.te b/sepolicy/mediaprovider.te new file mode 100644 index 0000000..17b66a8 --- /dev/null +++ b/sepolicy/mediaprovider.te @@ -0,0 +1 @@ +gpu_access(surfaceflinger) diff --git a/sepolicy/mediaserver.te b/sepolicy/mediaserver.te new file mode 100644 index 0000000..922af2c --- /dev/null +++ b/sepolicy/mediaserver.te @@ -0,0 +1 @@ +gpu_access(mediaserver) diff --git a/sepolicy/mediaswcodec.te b/sepolicy/mediaswcodec.te new file mode 100644 index 0000000..57fb75c --- /dev/null +++ b/sepolicy/mediaswcodec.te @@ -0,0 +1,2 @@ +gpu_access(mediaswcodec) +allow mediaswcodec gpu_device:chr_file { getattr ioctl map open read write }; diff --git a/sepolicy/netd.te b/sepolicy/netd.te new file mode 100644 index 0000000..00c4a0a --- /dev/null +++ b/sepolicy/netd.te @@ -0,0 +1,2 @@ +dontaudit netd self:capability sys_module; +allow netd kernel:system module_request; diff --git a/sepolicy/platform_app.te b/sepolicy/platform_app.te new file mode 100644 index 0000000..775e964 --- /dev/null +++ b/sepolicy/platform_app.te @@ -0,0 +1 @@ +gpu_access(platform_app) diff --git a/sepolicy/priv_app.te b/sepolicy/priv_app.te new file mode 100644 index 0000000..05c9e47 --- /dev/null +++ b/sepolicy/priv_app.te @@ -0,0 +1 @@ +gpu_access(priv_app) diff --git a/sepolicy/proc_net.te b/sepolicy/proc_net.te new file mode 100644 index 0000000..0f22770 --- /dev/null +++ b/sepolicy/proc_net.te @@ -0,0 +1 @@ +allow proc_net proc:filesystem associate; diff --git a/sepolicy/surfaceflinger.te b/sepolicy/surfaceflinger.te new file mode 100644 index 0000000..17b66a8 --- /dev/null +++ b/sepolicy/surfaceflinger.te @@ -0,0 +1 @@ +gpu_access(surfaceflinger) diff --git a/sepolicy/suspend_blocker.te b/sepolicy/suspend_blocker.te new file mode 100644 index 0000000..fa6e02a --- /dev/null +++ b/sepolicy/suspend_blocker.te @@ -0,0 +1,6 @@ +type suspend_blocker, domain; +type suspend_blocker_exec, exec_type, vendor_file_type, file_type; + +init_daemon_domain(suspend_blocker); + +wakelock_use(suspend_blocker); diff --git a/sepolicy/system_app.te b/sepolicy/system_app.te new file mode 100644 index 0000000..4a85066 --- /dev/null +++ b/sepolicy/system_app.te @@ -0,0 +1 @@ +gpu_access(system_app) diff --git a/sepolicy/system_server.te b/sepolicy/system_server.te new file mode 100644 index 0000000..954f637 --- /dev/null +++ b/sepolicy/system_server.te @@ -0,0 +1,2 @@ +gpu_access(system_server) +allow system_server self:capability sys_module; diff --git a/sepolicy/te_macros b/sepolicy/te_macros new file mode 100644 index 0000000..15f04d3 --- /dev/null +++ b/sepolicy/te_macros @@ -0,0 +1,8 @@ +##################################### +# gpu_access(client_domain) +# Allow client_domain to communicate with the GPU +define(`gpu_access', ` +allow $1 gpu_device:dir { open read search getattr }; +allow $1 gpu_device:chr_file { open read getattr ioctl map write }; +allow $1 sysfs_gpu:file { getattr open read }; +') diff --git a/sepolicy/untrusted_app_all.te b/sepolicy/untrusted_app_all.te new file mode 100644 index 0000000..c429fc2 --- /dev/null +++ b/sepolicy/untrusted_app_all.te @@ -0,0 +1 @@ +gpu_access(untrusted_app_all) diff --git a/suspend_blocker/Android.bp b/suspend_blocker/Android.bp new file mode 100644 index 0000000..c654459 --- /dev/null +++ b/suspend_blocker/Android.bp @@ -0,0 +1,11 @@ +// Copyright (C) 2019 The Android Open Source Project +// Copyright (C) 2021-2022 KonstaKANG +// +// SPDX-License-Identifier: Apache-2.0 + +cc_binary { + name: "suspend_blocker_rpi", + srcs: ["suspend_blocker_rpi.cpp"], + proprietary: true, + shared_libs: ["libpower"], +} diff --git a/suspend_blocker/suspend_blocker_rpi.cpp b/suspend_blocker/suspend_blocker_rpi.cpp new file mode 100644 index 0000000..8e96ed1 --- /dev/null +++ b/suspend_blocker/suspend_blocker_rpi.cpp @@ -0,0 +1,20 @@ +/* + * Copyright (C) 2019 The Android Open Source Project + * Copyright (C) 2021-2022 KonstaKANG + * + * SPDX-License-Identifier: Apache-2.0 + */ + +#include +#include + +int main() { + auto wl = android::wakelock::WakeLock::tryGet("suspend_blocker_rpi"); // RAII object + if (!wl.has_value()) { + return EXIT_FAILURE; + } + + sigset_t mask; + sigemptyset(&mask); + return sigsuspend(&mask); // Infinite sleep +} diff --git a/vendor.prop b/vendor.prop new file mode 100644 index 0000000..8284a75 --- /dev/null +++ b/vendor.prop @@ -0,0 +1,42 @@ + +# Audio +persist.audio.pcm.card=0 +persist.audio.pcm.device=0 +ro.config.media_vol_default=20 +ro.config.media_vol_steps=25 + +# Bluetooth +ro.rfkilldisabled=1 + +# Camera +media.settings.xml=/vendor/etc/media_profiles_V1_0.xml +ro.hardware.camera=libcamera + +# Display +debug.drm.mode.force=1920x1080 + +# Graphics +ro.hardware.hwcomposer=drm +ro.hardware.vulkan=broadcom +ro.opengles.version=196609 + +# LMKD +ro.lmk.critical=0 +ro.lmk.critical_upgrade=false +ro.lmk.downgrade_pressure=100 +ro.lmk.kill_heaviest_task=true +ro.lmk.kill_timeout_ms=100 +ro.lmk.log_stats=true +ro.lmk.low=1001 +ro.lmk.medium=800 +ro.lmk.upgrade_pressure=100 +ro.lmk.use_minfree_levels=true + +# V4L2 +debug.stagefright.c2-poolmask=0xf50000 +ro.vendor.v4l2_codec2.decode_concurrent_instances=8 +ro.vendor.v4l2_codec2.encode_concurrent_instances=8 + +# Wifi +wifi.interface=wlan0 +