From bbb804e57f2fde108eba4085623dc1bf55fffcca Mon Sep 17 00:00:00 2001 From: Yongqin Liu Date: Tue, 21 Apr 2020 17:52:44 +0800 Subject: db845c: move the normal fstab path to /vendor/etc/fstab.db845c as it is required by the GetFstabPath funtion defined here: https://android.googlesource.com/platform/system/core/+/refs/heads/master/fs_mgr/fs_mgr_fstab.cpp#411 and the fstab.ramdisk.common does not need to be copied to vendor partition. Test: boot up db845c with android-5.4 and android-mainline kernels, and tested with vts-kernel -m VtsKernelEncryptionTest Signed-off-by: Yongqin Liu Change-Id: Ib2ec7277e3b4e912546841174bdcb5638578ed33 --- db845c/device.mk | 3 +-- init.common.rc | 4 ++-- 2 files changed, 3 insertions(+), 4 deletions(-) diff --git a/db845c/device.mk b/db845c/device.mk index 5cdd38d..cc5b973 100644 --- a/db845c/device.mk +++ b/db845c/device.mk @@ -24,8 +24,7 @@ PRODUCT_COPY_FILES := \ $(DB845C_KERNEL_DIR)/Image.gz:kernel \ $(DB845C_KERNEL_DIR)/sdm845-db845c.dtb:dtb.img \ device/linaro/dragonboard/fstab.ramdisk.common:$(TARGET_COPY_OUT_RAMDISK)/fstab.db845c \ - device/linaro/dragonboard/fstab.ramdisk.common:$(TARGET_COPY_OUT_VENDOR)/etc/fstab.db845c \ - device/linaro/dragonboard/fstab.common:$(TARGET_COPY_OUT_VENDOR)/etc/init/fstab.db845c \ + device/linaro/dragonboard/fstab.common:$(TARGET_COPY_OUT_VENDOR)/etc/fstab.db845c \ device/linaro/dragonboard/init.common.rc:$(TARGET_COPY_OUT_VENDOR)/etc/init/init.db845c.rc \ device/linaro/dragonboard/init.common.usb.rc:$(TARGET_COPY_OUT_VENDOR)/etc/init/init.db845c.usb.rc \ device/linaro/dragonboard/common.kl:$(TARGET_COPY_OUT_VENDOR)/usr/keylayout/db845c.kl diff --git a/init.common.rc b/init.common.rc index 988a5e1..2ce8b0a 100644 --- a/init.common.rc +++ b/init.common.rc @@ -2,8 +2,8 @@ import init.${ro.hardware}.usb.rc import init.${ro.hardware}.power.rc on fs - mount_all /vendor/etc/init/fstab.${ro.hardware} - swapon_all /vendor/etc/init/fstab.${ro.hardware} + mount_all /vendor/etc/fstab.${ro.hardware} + swapon_all /vendor/etc/fstab.${ro.hardware} on post-fs # set RLIMIT_MEMLOCK to 64MB -- cgit v1.2.3 From bed1321ddcf66ccd8b9d4065ad9aeea38b04436a Mon Sep 17 00:00:00 2001 From: Yongqin Liu Date: Tue, 21 Apr 2020 17:57:54 +0800 Subject: fstab.common: adding options for userdata partition to enable FBE according to the document here: https://source.android.com/security/encryption/file-based Test: boot up db845c with android-5.4 and android-mainline kernels, and tested with vts-kernel -m VtsKernelEncryptionTest Signed-off-by: Yongqin Liu Change-Id: I6ad25b5fef31bef77893f6d5e267568489116fae --- fstab.common | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/fstab.common b/fstab.common index ad29337..b23e7f8 100644 --- a/fstab.common +++ b/fstab.common @@ -2,5 +2,5 @@ # # 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/platform/soc@0/1d84000.ufshc/by-name/userdata /data ext4 discard,noauto_da_alloc,data=ordered,user_xattr,barrier=1 wait,formattable +/dev/block/platform/soc@0/1d84000.ufshc/by-name/userdata /data ext4 discard,noatime,noauto_da_alloc,data=ordered,user_xattr,barrier=1,inlinecrypt wait,formattable,fileencryption=aes-256-xts:aes-256-cts:v2+inlinecrypt_optimized /dev/block/by-name/metadata /metadata ext4 noatime,nosuid,nodev,discard wait,formattable -- cgit v1.2.3 From 7cc6a2d9d7041917780d2311e66747e8ec789b60 Mon Sep 17 00:00:00 2001 From: Amit Pundir Date: Thu, 23 Apr 2020 21:39:03 +0530 Subject: db845c: Set Ethernet MAC address on boot db845c development boards do not have unique Ethernet MAC address. All boards share same MAC address and it cause problems while running CTS tests on db845c in a lab with multiple db845c boards connected. Set the Ethernet MAC address based on board's unique serial number as a workaround for now. Signed-off-by: Amit Pundir Change-Id: I1c5b63b7d6cbf5e55ac40980b5823cc6bb4f44d3 --- db845c/device.mk | 5 +++++ db845c/eth_mac_addr.rc | 9 +++++++++ db845c/eth_mac_addr.sh | 15 +++++++++++++++ sepolicy/eth_mac_addr.te | 12 ++++++++++++ sepolicy/file_contexts | 2 ++ 5 files changed, 43 insertions(+) create mode 100644 db845c/eth_mac_addr.rc create mode 100644 db845c/eth_mac_addr.sh create mode 100644 sepolicy/eth_mac_addr.te diff --git a/db845c/device.mk b/db845c/device.mk index cc5b973..b37e06f 100644 --- a/db845c/device.mk +++ b/db845c/device.mk @@ -43,5 +43,10 @@ PRODUCT_PACKAGES += \ PRODUCT_COPY_FILES += \ device/linaro/dragonboard/qcom/init.qcom.rc:$(TARGET_COPY_OUT_VENDOR)/etc/init/init.qcom.rc +# Install scripts to set Ethernet MAC address +PRODUCT_COPY_FILES += \ + $(LOCAL_PATH)/eth_mac_addr.rc:/system/etc/init/eth_mac_addr.rc \ + $(LOCAL_PATH)/eth_mac_addr.sh:/system/bin/eth_mac_addr.sh + # Copy firmware files $(call inherit-product-if-exists, $(LOCAL_PATH)/firmware/device.mk) diff --git a/db845c/eth_mac_addr.rc b/db845c/eth_mac_addr.rc new file mode 100644 index 0000000..e710c19 --- /dev/null +++ b/db845c/eth_mac_addr.rc @@ -0,0 +1,9 @@ +service eth_mac_addr /system/bin/eth_mac_addr.sh + class core + user root + group system + disabled + oneshot + +on post-fs-data + start eth_mac_addr diff --git a/db845c/eth_mac_addr.sh b/db845c/eth_mac_addr.sh new file mode 100644 index 0000000..bdc1ba7 --- /dev/null +++ b/db845c/eth_mac_addr.sh @@ -0,0 +1,15 @@ +#! /system/bin/sh +# Set eth0 mac address. +# +# Get the unique board serial number from /proc/cmdline, +# prepend '0's to the serial number to fill 5 LSBs of the +# MAC address and prepend "02" as MSB to prepare a 6 byte +# locally administered unicast MAC address. +# Format the output in xx:xx:xx:xx:xx:xx format for the +# "ip" set address command to work. + +SERIALNO=`cat /proc/cmdline | grep -o serialno.* | cut -f2 -d'=' | awk '{printf("02%010s\n", $1)}' | sed 's/\(..\)/\1:/g' | sed '$s/:$//'` + +/system/bin/ip link set dev eth0 down +/system/bin/ip link set dev eth0 address "${SERIALNO}" +/system/bin/ip link set dev eth0 up diff --git a/sepolicy/eth_mac_addr.te b/sepolicy/eth_mac_addr.te new file mode 100644 index 0000000..d2e4e1a --- /dev/null +++ b/sepolicy/eth_mac_addr.te @@ -0,0 +1,12 @@ +type eth_mac_addr, domain, coredomain; +type eth_mac_addr_exec, exec_type, system_file_type, file_type; +init_daemon_domain(eth_mac_addr); + +allow eth_mac_addr proc_cmdline:file { open read }; +allow eth_mac_addr rootfs:dir { open read }; +allow eth_mac_addr self:capability net_admin; +allow eth_mac_addr self:netlink_route_socket { bind create getattr nlmsg_readpriv nlmsg_write read setopt write }; +allow eth_mac_addr self:udp_socket { create ioctl }; +allow eth_mac_addr shell_exec:file { execute getattr map read }; +allow eth_mac_addr system_file:file execute_no_trans; +allow eth_mac_addr toolbox_exec:file { execute execute_no_trans getattr map open read }; diff --git a/sepolicy/file_contexts b/sepolicy/file_contexts index 165f3b3..247e1ab 100644 --- a/sepolicy/file_contexts +++ b/sepolicy/file_contexts @@ -29,6 +29,8 @@ /data/vendor/readwrite(/.*)? u:object_r:tqftpserv_vendor_data_file:s0 /data/vendor/readonly(/.*)? u:object_r:tqftpserv_vendor_data_file:s0 +/system/bin/eth_mac_addr\.sh u:object_r:eth_mac_addr_exec:s0 + /vendor/bin/hw/android\.hardware\.gatekeeper@1\.0-service\.software u:object_r:hal_gatekeeper_default_exec:s0 /vendor/bin/pd-mapper u:object_r:pd_mapper_exec:s0 /vendor/bin/qrtr-cfg u:object_r:qrtr_exec:s0 -- cgit v1.2.3 From 3c5b0b607280b0497f0f176e197008ccf5397c59 Mon Sep 17 00:00:00 2001 From: Amit Pundir Date: Tue, 14 Apr 2020 22:22:30 +0530 Subject: db845c: firmware: Add adsp and modem jason file Downloaded from: https://git.kernel.org/pub/scm/linux/kernel/git/firmware/linux-firmware.git/tree/qcom/sdm845 at commit 64dba0fedb22 ("Merge branch 'a630-zap' of https://github.com/andersson/linux-firmware") Signed-off-by: Amit Pundir Change-Id: I95e8bd0ef30c7aa58db4fc8e269f13fa62727022 --- db845c/firmware/Android.mk | 4 +++- db845c/firmware/adspua.jsn | 27 +++++++++++++++++++++++++++ db845c/firmware/device.mk | 4 +++- db845c/firmware/modemuw.jsn | 33 +++++++++++++++++++++++++++++++++ 4 files changed, 66 insertions(+), 2 deletions(-) create mode 100644 db845c/firmware/adspua.jsn create mode 100644 db845c/firmware/modemuw.jsn diff --git a/db845c/firmware/Android.mk b/db845c/firmware/Android.mk index 3af24e3..6c3dc4b 100644 --- a/db845c/firmware/Android.mk +++ b/db845c/firmware/Android.mk @@ -34,6 +34,7 @@ sdm845_firmware_files += \ adsp.b12 \ adsp.b13 \ adsp.mdt \ + adspua.jsn \ cdsp.b00 \ cdsp.b01 \ cdsp.b02 \ @@ -104,7 +105,8 @@ firmware_files += \ # wifi/modem/mba sdm845_firmware_files += \ mba.mbn \ - modem.mbn + modem.mbn \ + modemuw.jsn # License firmware_files += \ diff --git a/db845c/firmware/adspua.jsn b/db845c/firmware/adspua.jsn new file mode 100644 index 0000000..e75e83f --- /dev/null +++ b/db845c/firmware/adspua.jsn @@ -0,0 +1,27 @@ +{ + "sr_version": { + "major": 1, + "minor": 1, + "patch": 1 + }, + "sr_domain": { + "soc": "msm", + "domain": "adsp", + "subdomain": "audio_pd", + "qmi_instance_id": 74 + }, + "sr_service": [ + { + "provider": "tms", + "service": "servreg", + "service_data_valid": 0, + "service_data": 0 + }, + { + "provider": "avs", + "service": "audio", + "service_data_valid": 0, + "service_data": 0 + } + ] +} diff --git a/db845c/firmware/device.mk b/db845c/firmware/device.mk index 7611aa8..78a1d8f 100644 --- a/db845c/firmware/device.mk +++ b/db845c/firmware/device.mk @@ -28,6 +28,7 @@ PRODUCT_PACKAGES += \ adsp.b12 \ adsp.b13 \ adsp.mdt \ + adspua.jsn \ cdsp.b00 \ cdsp.b01 \ cdsp.b02 \ @@ -50,7 +51,8 @@ PRODUCT_PACKAGES += \ PRODUCT_PACKAGES += \ mba.mbn \ - modem.mbn + modem.mbn \ + modemuw.jsn # Venus # Video encoder/decoder accelerator diff --git a/db845c/firmware/modemuw.jsn b/db845c/firmware/modemuw.jsn new file mode 100644 index 0000000..4322190 --- /dev/null +++ b/db845c/firmware/modemuw.jsn @@ -0,0 +1,33 @@ +{ + "sr_version": { + "major": 1, + "minor": 1, + "patch": 1 + }, + "sr_domain": { + "soc": "msm", + "domain": "modem", + "subdomain": "wlan_pd", + "qmi_instance_id": 180 + }, + "sr_service": [ + { + "provider": "kernel", + "service": "elf_loader", + "service_data_valid": 0, + "service_data": 0 + }, + { + "provider": "tms", + "service": "servreg", + "service_data_valid": 0, + "service_data": 0 + }, + { + "provider": "wlan", + "service": "fw", + "service_data_valid": 0, + "service_data": 0 + } + ] +} -- cgit v1.2.3 From aab5ced6ec820b19c167b4ad23cc299b6966e93b Mon Sep 17 00:00:00 2001 From: Amit Pundir Date: Thu, 16 Apr 2020 10:02:40 +0530 Subject: qcom: pd-mapper: Syncup with upstream github project Syncup with https://github.com/andersson/pd-mapper upstream project up to commit: ab5074fdd5e4 ("pd-mapper: Use remoteproc firmware to find jsons") Signed-off-by: Amit Pundir Change-Id: I4ad3c07977c1e41a657c6c0479ad6dee9c154374 --- qcom/pd-mapper/Makefile | 2 + qcom/pd-mapper/assoc.c | 158 ++++++++++++++++ qcom/pd-mapper/assoc.h | 54 ++++++ qcom/pd-mapper/json.c | 451 +++++++++++++++++++++++++++++++++++++++++++++ qcom/pd-mapper/json.h | 67 +++++++ qcom/pd-mapper/pd-mapper.c | 203 +++++++++++++++++++- 6 files changed, 931 insertions(+), 4 deletions(-) create mode 100644 qcom/pd-mapper/assoc.c create mode 100644 qcom/pd-mapper/assoc.h create mode 100644 qcom/pd-mapper/json.c create mode 100644 qcom/pd-mapper/json.h diff --git a/qcom/pd-mapper/Makefile b/qcom/pd-mapper/Makefile index ca58003..908dbfd 100644 --- a/qcom/pd-mapper/Makefile +++ b/qcom/pd-mapper/Makefile @@ -8,6 +8,8 @@ bindir := $(prefix)/bin servicedir := $(prefix)/lib/systemd/system SRCS := pd-mapper.c \ + assoc.c \ + json.c \ servreg_loc.c OBJS := $(SRCS:.c=.o) diff --git a/qcom/pd-mapper/assoc.c b/qcom/pd-mapper/assoc.c new file mode 100644 index 0000000..692c882 --- /dev/null +++ b/qcom/pd-mapper/assoc.c @@ -0,0 +1,158 @@ +/* + * Copyright (c) 2013, Bjorn Andersson + * All rights reserved. + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions are met: + * + * 1. Redistributions of source code must retain the above copyright notice, + * this list of conditions and the following disclaimer. + * + * 2. Redistributions in binary form must reproduce the above copyright notice, + * this list of conditions and the following disclaimer in the documentation + * and/or other materials provided with the distribution. + * + * 3. Neither the name of the copyright holder nor the names of its contributors + * may be used to endorse or promote products derived from this software without + * specific prior written permission. + * + * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" + * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE + * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE + * ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE + * LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR + * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF + * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS + * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN + * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) + * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE + * POSSIBILITY OF SUCH DAMAGE. + */ + +#include +#include +#include +#include + +#include "assoc.h" + +static unsigned long assoc_hash(const char *value) +{ + unsigned long hash = 0; + unsigned long g; + const char *v = value; + + while (*v) { + hash = (hash << 4) + *(v++); + g = hash & 0xF0000000L; + if (g) + hash ^= g >> 24; + hash &= ~g; + } + + return hash; +} + +void assoc_init(struct assoc *assoc, unsigned long size) +{ + assert(size > 0); + + assoc->size = size; + assoc->fill = 0; + assoc->keys = calloc(size, sizeof(const char *)); + assoc->values = malloc(size * sizeof(void *)); +} + +void *assoc_get(struct assoc *assoc, const char *key) +{ + unsigned long hash; + + hash = assoc_hash(key) % assoc->size; + while (assoc->keys[hash]) { + if (!strcmp(assoc->keys[hash], key)) + return assoc->values[hash]; + + hash = (hash + 1) % assoc->size; + } + + return NULL; +} + +static void _assoc_set(struct assoc *assoc, const char *key, void *value) +{ + struct assoc new_set; + unsigned long hash; + unsigned long i; + + assert(assoc->fill < assoc->size); + + /* Grow set at 80% utilization */ + if (5 * assoc->fill > 4 * assoc->size) { + assoc_init(&new_set, assoc->size * 5 / 4); + + for (i = 0; i < assoc->size; i++) + if (assoc->keys[i]) + assoc_set(&new_set, assoc->keys[i], + assoc->values[i]); + + free(assoc->keys); + free(assoc->values); + + assoc->keys = new_set.keys; + assoc->values = new_set.values; + assoc->fill = new_set.fill; + assoc->size = new_set.size; + } + + hash = assoc_hash(key) % assoc->size; + while (assoc->keys[hash]) { + if (!strcmp(assoc->keys[hash], key)) { + assoc->values[hash] = value; + return; + } + + hash = (hash + 1) % assoc->size; + } + + assoc->keys[hash] = key; + assoc->values[hash] = value; + assoc->fill++; +} + +void assoc_set(struct assoc *assoc, const char *key, void *value) +{ + _assoc_set(assoc, strdup(key), value); +} + +const char *assoc_next(struct assoc *assoc, void **value, unsigned long *iter) +{ + unsigned long it = *iter; + + while (!assoc->keys[it] && it < assoc->size) + it++; + + if (it == assoc->size) + return NULL; + + *iter = it + 1; + + if (it < assoc->size) { + if (value) + *value = assoc->values[it]; + return assoc->keys[it]; + } else { + return NULL; + } +} + +void assoc_destroy(struct assoc *assoc) +{ + unsigned long i; + + for (i = 0; i < assoc->size; i++) + free((void*)assoc->keys[i]); + + free(assoc->keys); + free(assoc->values); + assoc->size = 0; +} diff --git a/qcom/pd-mapper/assoc.h b/qcom/pd-mapper/assoc.h new file mode 100644 index 0000000..25d00fa --- /dev/null +++ b/qcom/pd-mapper/assoc.h @@ -0,0 +1,54 @@ +/* + * Copyright (c) 2013, Bjorn Andersson + * All rights reserved. + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions are met: + * + * 1. Redistributions of source code must retain the above copyright notice, + * this list of conditions and the following disclaimer. + * + * 2. Redistributions in binary form must reproduce the above copyright notice, + * this list of conditions and the following disclaimer in the documentation + * and/or other materials provided with the distribution. + * + * 3. Neither the name of the copyright holder nor the names of its contributors + * may be used to endorse or promote products derived from this software without + * specific prior written permission. + * + * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" + * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE + * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE + * ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE + * LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR + * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF + * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS + * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN + * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) + * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE + * POSSIBILITY OF SUCH DAMAGE. + */ + +#ifndef __ASSOC_H__ +#define __ASSOC_H__ + +struct assoc { + unsigned long size; + unsigned long fill; + + const char **keys; + void **values; +}; + +void assoc_init(struct assoc *assoc, unsigned long size); +void *assoc_get(struct assoc *assoc, const char *key); +void assoc_set(struct assoc *assoc, const char *key, void *value); +const char *assoc_next(struct assoc *assoc, void **value, unsigned long *iter); +void assoc_destroy(struct assoc *assoc); + +#define assoc_foreach(key, value, assoc, iter) \ + for ((iter) = 0, (key) = assoc_next((assoc), (value), &(iter)); \ + (key); \ + (key) = assoc_next((assoc), (value), &(iter))) + +#endif diff --git a/qcom/pd-mapper/json.c b/qcom/pd-mapper/json.c new file mode 100644 index 0000000..e08afa4 --- /dev/null +++ b/qcom/pd-mapper/json.c @@ -0,0 +1,451 @@ +/* + * Copyright (c) 2018-2019, Linaro Ltd. + * All rights reserved. + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions are met: + * + * 1. Redistributions of source code must retain the above copyright notice, + * this list of conditions and the following disclaimer. + * + * 2. Redistributions in binary form must reproduce the above copyright notice, + * this list of conditions and the following disclaimer in the documentation + * and/or other materials provided with the distribution. + * + * 3. Neither the name of the copyright holder nor the names of its contributors + * may be used to endorse or promote products derived from this software without + * specific prior written permission. + * + * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" + * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE + * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE + * ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE + * LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR + * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF + * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS + * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN + * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) + * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE + * POSSIBILITY OF SUCH DAMAGE. + */ +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include "json.h" + +static const char *input_buf; +static int input_pos; +static int input_len; + +static int json_parse_array(struct json_value *array); +static int json_parse_object(struct json_value *object); +static int json_parse_property(struct json_value *value); + +static int input(void) +{ + if (input_pos >= input_len) + return 0; + + return input_buf[input_pos++]; +} + +static void unput(void) +{ + input_pos--; +} + +static void json_skip_whitespace(void) +{ + int ch; + + while ((ch = input()) && isspace(ch)) + ; + unput(); +} + +static int json_parse_string(struct json_value *value) +{ + char buf[128]; + char *b = buf; + int ch; + + ch = input(); + if (ch != '"') { + unput(); + return 0; + } + + while ((ch = input()) && ch != '"' && b - buf < sizeof(buf) - 1) + *b++ = ch; + *b = '\0'; + + if (!ch) + return -1; + + value->type = JSON_TYPE_STRING; + value->u.string = strdup(buf); + + return 1; +} + +static int json_parse_number(struct json_value *value) +{ + char buf[20]; + char *b = buf; + int ch; + + while ((ch = input()) && isdigit(ch) && b - buf < sizeof(buf) - 1) + *b++ = ch; + *b = '\0'; + unput(); + + if (b == buf) + return 0; + + value->type = JSON_TYPE_NUMBER; + value->u.number = strtod(buf, NULL); + + return 1; +} + +static int json_parse_keyword(struct json_value *value) +{ + const char *match; + const char *m; + int ch; + + ch = input(); + switch (ch) { + case 't': + match = "true"; + value->type = JSON_TYPE_TRUE; + break; + case 'f': + match = "false"; + value->type = JSON_TYPE_FALSE; + break; + case 'n': + match = "null"; + value->type = JSON_TYPE_NULL; + break; + default: + unput(); + return 0; + } + + m = match; + while (*m && *m++ == ch) + ch = input(); + unput(); + + return *m == '\0' ? 1 : -1; +} + +static int json_parse_value(struct json_value *value) +{ + int ret; + + json_skip_whitespace(); + + ret = json_parse_object(value); + if (ret) + goto out; + + ret = json_parse_array(value); + if (ret) + goto out; + + ret = json_parse_string(value); + if (ret) + goto out; + + ret = json_parse_number(value); + if (ret) + goto out; + + ret = json_parse_keyword(value); + if (ret) + goto out; + + fprintf(stderr, "unable to match a value\n"); + return -1; + +out: + json_skip_whitespace(); + return ret; +} + +static int json_parse_array(struct json_value *array) +{ + struct json_value *value; + struct json_value *last = NULL; + int ret; + int ch; + + ch = input(); + if (ch != '[') { + unput(); + return 0; + } + + array->type = JSON_TYPE_ARRAY; + do { + value = calloc(1, sizeof(*value)); + if (!value) + return -1; + + ret = json_parse_value(value); + if (ret <= 0) { + free(value); + return -1; + } + + if (!array->u.value) + array->u.value = value; + if (last) + last->next = value; + last = value; + + ch = input(); + if (ch == ']') { + return 1; + } + + } while (ch == ','); + + fprintf(stderr, "expected ',' got '%c'\n", ch); + + return -1; +} + +static int json_parse_object(struct json_value *object) +{ + struct json_value *value; + struct json_value *last = NULL; + int ret; + int ch; + + ch = input(); + if (ch != '{') { + unput(); + return 0; + } + + object->type = JSON_TYPE_OBJECT; + + do { + value = calloc(1, sizeof(*value)); + if (!value) + return -1; + + ret = json_parse_property(value); + if (ret <= 0) { + free(value); + return -1; + } + + if (!object->u.value) + object->u.value = value; + if (last) + last->next = value; + last = value; + + ch = input(); + if (ch == '}') { + return 1; + } + } while (ch == ','); + + return -1; +} + +static int json_parse_property(struct json_value *value) +{ + struct json_value key; + int ret; + int ch; + + json_skip_whitespace(); + + ret = json_parse_string(&key); + if (ret <= 0) + return -1; + + value->key = key.u.string; + + json_skip_whitespace(); + + ch = input(); + if (ch != ':') + return -1; + + ret = json_parse_value(value); + if (ret <= 0) + return -1; + + return 1; +} + +struct json_value *json_parse(const char *json) +{ + struct json_value *root; + int ret; + + input_buf = json; + input_pos = 0; + input_len = strlen(input_buf); + + root = calloc(1, sizeof(*root)); + if (!root) + return NULL; + + ret = json_parse_value(root); + if (ret != 1) { + free(root); + return NULL; + } + + return root; +} + +struct json_value *json_parse_file(const char *file) +{ + struct json_value *root; + struct stat sb; + int ret; + int fd; + + fd = open(file, O_RDONLY); + if (fd < 0) { + fprintf(stderr, "failed to open %s: %s\n", file, strerror(errno)); + return NULL; + } + + ret = fstat(fd, &sb); + if (ret < 0) + return NULL; + + input_pos = 0; + input_len = sb.st_size; + input_buf = malloc(sb.st_size); + + ret = read(fd, (char *)input_buf, input_len); + + close(fd); + + if (ret != input_len) { + fprintf(stderr, "failed to read %d bytes form %s\n", input_len, file); + return NULL; + } + + root = calloc(1, sizeof(*root)); + if (!root) + return NULL; + + ret = json_parse_value(root); + if (ret != 1) { + json_free(root); + return NULL; + } + + return root; +} + +struct json_value *json_get_child(struct json_value *object, const char *key) +{ + struct json_value *it; + + if(object->type != JSON_TYPE_OBJECT) + return NULL; + + for (it = object->u.value; it; it = it->next) { + if (!strcmp(it->key, key)) + return it; + } + + return NULL; +} + +int json_count_children(struct json_value *array) +{ + struct json_value *it; + int count = 0; + + if (!array || array->type != JSON_TYPE_ARRAY) + return -1; + + for (it = array->u.value; it; it = it->next) + count++; + + return count; +} + +int json_get_number(struct json_value *object, const char *key, double *number) +{ + struct json_value *it; + + if (!object || object->type != JSON_TYPE_OBJECT) + return -1; + + for (it = object->u.value; it; it = it->next) { + if (!strcmp(it->key, key)) { + if (it->type != JSON_TYPE_NUMBER) + return -1; + + *number = it->u.number; + return 0; + } + } + + return -1; +} + +const char *json_get_string(struct json_value *object, const char *key) +{ + struct json_value *it; + + if (!object || object->type != JSON_TYPE_OBJECT) + return NULL; + + for (it = object->u.value; it; it = it->next) { + if (!strcmp(it->key, key)) { + if (it->type != JSON_TYPE_STRING) + return NULL; + + return it->u.string; + } + } + + return NULL; +} + +void json_free(struct json_value *value) +{ + struct json_value *next; + struct json_value *it; + + free((char *)value->key); + + switch (value->type) { + case JSON_TYPE_OBJECT: + case JSON_TYPE_ARRAY: + it = value->u.value; + while (it) { + next = it->next; + json_free(it); + it = next; + } + break; + case JSON_TYPE_STRING: + free((char *)value->u.string); + break; + } + + free(value); +} diff --git a/qcom/pd-mapper/json.h b/qcom/pd-mapper/json.h new file mode 100644 index 0000000..91790a0 --- /dev/null +++ b/qcom/pd-mapper/json.h @@ -0,0 +1,67 @@ +/* + * Copyright (c) 2019, Linaro Ltd. + * All rights reserved. + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions are met: + * + * 1. Redistributions of source code must retain the above copyright notice, + * this list of conditions and the following disclaimer. + * + * 2. Redistributions in binary form must reproduce the above copyright notice, + * this list of conditions and the following disclaimer in the documentation + * and/or other materials provided with the distribution. + * + * 3. Neither the name of the copyright holder nor the names of its contributors + * may be used to endorse or promote products derived from this software without + * specific prior written permission. + * + * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" + * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE + * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE + * ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE + * LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR + * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF + * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS + * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN + * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) + * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE + * POSSIBILITY OF SUCH DAMAGE. + */ +#ifndef __JSON_H__ +#define __JSON_H__ + + +enum { + JSON_TYPE_UNKNOWN, + JSON_TYPE_TRUE, + JSON_TYPE_FALSE, + JSON_TYPE_NULL, + JSON_TYPE_NUMBER, + JSON_TYPE_STRING, + JSON_TYPE_ARRAY, + JSON_TYPE_OBJECT, +}; + +struct json_value { + const char *key; + + int type; + union { + double number; + const char *string; + struct json_value *value; + } u; + + struct json_value *next; +}; + +struct json_value *json_parse(const char *json); +struct json_value *json_parse_file(const char *file); +int json_count_children(struct json_value *array); +struct json_value *json_get_child(struct json_value *object, const char *key); +int json_get_number(struct json_value *object, const char *key, double *number); +const char *json_get_string(struct json_value *object, const char *key); +void json_free(struct json_value *value); + +#endif diff --git a/qcom/pd-mapper/pd-mapper.c b/qcom/pd-mapper/pd-mapper.c index 543dfb3..f26710d 100644 --- a/qcom/pd-mapper/pd-mapper.c +++ b/qcom/pd-mapper/pd-mapper.c @@ -28,13 +28,21 @@ * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE * POSSIBILITY OF SUCH DAMAGE. */ +#include +#include +#include #include +#include +#include +#include #include #include #include #include #include +#include "assoc.h" +#include "json.h" #include "servreg_loc.h" struct pd_map { @@ -43,10 +51,7 @@ struct pd_map { int instance; }; -static const struct pd_map pd_maps[] = { - { "kernel/elf_loader", "msm/modem/wlan_pd", 1 }, - {} -}; +static struct pd_map *pd_maps; static void handle_get_domain_list(int sock, const struct qrtr_packet *pkt) { @@ -113,6 +118,187 @@ respond: } } +static int pd_load_map(const char *file) +{ + static int num_pd_maps; + struct json_value *sr_service; + struct json_value *sr_domain; + struct json_value *root; + struct json_value *it; + const char *subdomain; + const char *provider; + const char *service; + const char *domain; + const char *soc; + struct pd_map *newp; + struct pd_map *map; + double number; + int count; + int ret; + + root = json_parse_file(file); + if (!root) + return -1; + + sr_domain = json_get_child(root, "sr_domain"); + soc = json_get_string(sr_domain, "soc"); + domain = json_get_string(sr_domain, "domain"); + subdomain = json_get_string(sr_domain, "subdomain"); + ret = json_get_number(sr_domain, "qmi_instance_id", &number); + if (ret) + return ret; + + if (!soc || !domain || !subdomain) { + fprintf(stderr, "failed to parse sr_domain\n"); + return -1; + } + + sr_service = json_get_child(root, "sr_service"); + count = json_count_children(sr_service); + if (count < 0) + return count; + + newp = realloc(pd_maps, (num_pd_maps + count + 1) * sizeof(*newp)); + if (!newp) + return -1; + pd_maps = newp; + + for (it = sr_service->u.value; it; it = it->next) { + provider = json_get_string(it, "provider"); + service = json_get_string(it, "service"); + + if (!provider || !service) { + fprintf(stderr, + "failed to parse provdider or service from %s\n", + file); + return -1; + } + + map = &pd_maps[num_pd_maps++]; + + map->service = malloc(strlen(provider) + strlen(service) + 2); + sprintf((char *)map->service, "%s/%s", provider, service); + + map->domain = malloc(strlen(soc) + strlen(domain) + strlen(subdomain) + 3); + sprintf((char *)map->domain, "%s/%s/%s", soc, domain, subdomain); + + map->instance = number; + } + + pd_maps[num_pd_maps].service = NULL; + + json_free(root); + + return 0; +} + +#define FIRMWARE_BASE "/lib/firmware/" + +static int pd_enumerate_jsons(struct assoc *json_set) +{ + char firmware_value[PATH_MAX]; + char json_path[PATH_MAX]; + char firmware_attr[32]; + struct dirent *fw_de; + char path[PATH_MAX]; + struct dirent *de; + int firmware_fd; + DIR *class_dir; + int class_fd; + DIR *fw_dir; + size_t len; + size_t n; + + class_fd = open("/sys/class/remoteproc", O_RDONLY | O_DIRECTORY); + if (class_fd < 0) { + warn("failed to open remoteproc class"); + return -1; + } + + class_dir = fdopendir(class_fd); + if (!class_dir) { + warn("failed to opendir"); + goto close_class; + } + + while ((de = readdir(class_dir)) != NULL) { + if (!strcmp(de->d_name, ".") || !strcmp(de->d_name, "..")) + continue; + + if (strlen(de->d_name) + sizeof("/firmware") > sizeof(firmware_attr)) + continue; + + strcpy(firmware_attr, de->d_name); + strcat(firmware_attr, "/firmware"); + + firmware_fd = openat(class_fd, firmware_attr, O_RDONLY); + if (firmware_fd < 0) + continue; + + n = read(firmware_fd, firmware_value, sizeof(firmware_value)); + close(firmware_fd); + if (n < 0) { + continue; + } + + if (strlen(FIRMWARE_BASE) + strlen(firmware_value) + 1 > sizeof(path)) + continue; + + strcpy(path, FIRMWARE_BASE); + strcat(path, dirname(firmware_value)); + + fw_dir = opendir(path); + while ((fw_de = readdir(fw_dir)) != NULL) { + if (!strcmp(fw_de->d_name, ".") || !strcmp(fw_de->d_name, "..")) + continue; + + len = strlen(fw_de->d_name); + if (len < 5 || strcmp(&fw_de->d_name[len - 4], ".jsn")) + continue; + + if (strlen(FIRMWARE_BASE) + strlen(firmware_value) + 1 + + strlen(fw_de->d_name) + 1 > sizeof(path)) + continue; + + strcpy(json_path, path); + strcat(json_path, "/"); + strcat(json_path, fw_de->d_name); + + assoc_set(json_set, json_path, NULL); + } + + closedir(fw_dir); + } + + closedir(class_dir); +close_class: + close(class_fd); + + return 0; +} + +static int pd_load_maps(void) +{ + struct assoc json_set; + unsigned long it; + const char *jsn; + int ret = 0; + + assoc_init(&json_set, 20); + + pd_enumerate_jsons(&json_set); + + assoc_foreach(jsn, NULL, &json_set, it) { + ret = pd_load_map(jsn); + if (ret < 0) + break; + } + + assoc_destroy(&json_set); + + return ret; +} + int main(int argc __unused, char **argv __unused) { struct sockaddr_qrtr sq; @@ -123,6 +309,15 @@ int main(int argc __unused, char **argv __unused) int ret; int fd; + ret = pd_load_maps(); + if (ret) + exit(1); + + if (!pd_maps) { + fprintf(stderr, "no pd maps available\n"); + exit(1); + } + fd = qrtr_open(0); if (fd < 0) { fprintf(stderr, "failed to open qrtr socket\n"); -- cgit v1.2.3 From 4f619fba658deb64633165bdae0efea47db42952 Mon Sep 17 00:00:00 2001 From: Amit Pundir Date: Tue, 14 Apr 2020 22:45:05 +0530 Subject: qcom: pd-mapper: Null terminate firmware_value string Null terminate firmware_value string to prevent strlen() read past the end of buffer. Otherwise pd-mapper will crash: console:/ # pd-mapper FORTIFY: strlen: detected read past end of buffer Aborted 134|console:/ # Signed-off-by: Amit Pundir Change-Id: Id0b9e1dda2bae12e3a36f1ce40376d1161878894 --- qcom/pd-mapper/pd-mapper.c | 2 ++ 1 file changed, 2 insertions(+) diff --git a/qcom/pd-mapper/pd-mapper.c b/qcom/pd-mapper/pd-mapper.c index f26710d..c7db57f 100644 --- a/qcom/pd-mapper/pd-mapper.c +++ b/qcom/pd-mapper/pd-mapper.c @@ -241,6 +241,8 @@ static int pd_enumerate_jsons(struct assoc *json_set) continue; } + firmware_value[n] = '\0'; + if (strlen(FIRMWARE_BASE) + strlen(firmware_value) + 1 > sizeof(path)) continue; -- cgit v1.2.3 From b951ef2442aab86b76d3270b4657c4fbccc58af6 Mon Sep 17 00:00:00 2001 From: Amit Pundir Date: Tue, 14 Apr 2020 22:48:17 +0530 Subject: qcom: pd-mapper: Use /vendor/firmware path for AOSP Signed-off-by: Amit Pundir Change-Id: I44f1d53cb16bc91e05be530c55e15a2657660be6 --- qcom/pd-mapper/pd-mapper.c | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/qcom/pd-mapper/pd-mapper.c b/qcom/pd-mapper/pd-mapper.c index c7db57f..664b77d 100644 --- a/qcom/pd-mapper/pd-mapper.c +++ b/qcom/pd-mapper/pd-mapper.c @@ -192,7 +192,11 @@ static int pd_load_map(const char *file) return 0; } +#ifndef ANDROID #define FIRMWARE_BASE "/lib/firmware/" +#else +#define FIRMWARE_BASE "/vendor/firmware/" +#endif static int pd_enumerate_jsons(struct assoc *json_set) { -- cgit v1.2.3 From 4429e581cd6d90ab6a35d26df46e998b1d61d6f2 Mon Sep 17 00:00:00 2001 From: Amit Pundir Date: Tue, 14 Apr 2020 22:15:09 +0530 Subject: qcom: pd-mapper: Update Android.bp srcs Signed-off-by: Amit Pundir Change-Id: I8b6f6907fd27e775fd399b109cd660372a6a6252 --- qcom/pd-mapper/Android.bp | 2 ++ 1 file changed, 2 insertions(+) diff --git a/qcom/pd-mapper/Android.bp b/qcom/pd-mapper/Android.bp index 84c065f..3bdbc32 100644 --- a/qcom/pd-mapper/Android.bp +++ b/qcom/pd-mapper/Android.bp @@ -3,6 +3,8 @@ cc_binary { vendor: true, srcs: [ "pd-mapper.c", + "assoc.c", + "json.c", "servreg_loc.c", ], shared_libs: ["libqrtr"], -- cgit v1.2.3 From 537853d9360cba5ca812c3047f12f953c9fd4942 Mon Sep 17 00:00:00 2001 From: Amit Pundir Date: Wed, 15 Apr 2020 15:45:01 +0530 Subject: sepolicy: pd-mapper: Fix denials introduced by new pd-mapper changes Signed-off-by: Amit Pundir Change-Id: If72dc1f82f2d5752e9c5998a1f2f7c21fb25ec1d --- sepolicy/pd_mapper.te | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/sepolicy/pd_mapper.te b/sepolicy/pd_mapper.te index 6eb348e..2e48a86 100644 --- a/sepolicy/pd_mapper.te +++ b/sepolicy/pd_mapper.te @@ -4,3 +4,7 @@ type pd_mapper_exec, exec_type, vendor_file_type, file_type; init_daemon_domain(pd_mapper); allow pd_mapper self:qipcrtr_socket { create getattr read setopt write }; +allow pd_mapper sysfs_rmtfs:dir search; +allow pd_mapper sysfs_rmtfs:file { open read }; +allow pd_mapper sysfs_tqftpserv:dir { open read search }; +allow pd_mapper sysfs_tqftpserv:file { open read }; -- cgit v1.2.3 From bf70b7d649e7d705042b007dfc22fc788fc2f1d4 Mon Sep 17 00:00:00 2001 From: Bjorn Andersson Date: Sun, 1 Mar 2020 18:02:13 -0800 Subject: qcom: qrtr: ns: Go dormant when exsting name server is found With the introduction of the in-kernel nameserver launching the user space qrtr-ns will fail, but typically other services depends on its presence. As such, go dormant instead of failing when noticed that the name service is already present. Signed-off-by: Bjorn Andersson Signed-off-by: Amit Pundir Change-Id: I62aa002294e6980bab0b5e1b7282212b8d2c3d57 --- qcom/qrtr/src/ns.c | 16 +++++++++++++++- 1 file changed, 15 insertions(+), 1 deletion(-) diff --git a/qcom/qrtr/src/ns.c b/qcom/qrtr/src/ns.c index 4b88a9c..393cc68 100644 --- a/qcom/qrtr/src/ns.c +++ b/qcom/qrtr/src/ns.c @@ -685,6 +685,14 @@ static void node_mi_free(struct map_item *mi) free(node); } +static void go_dormant(int sock) +{ + close(sock); + + for (;;) + sleep(UINT_MAX); +} + static void usage(const char *progname) { fprintf(stderr, "%s [-f] [-s] []\n", progname); @@ -760,8 +768,14 @@ int main(int argc, char **argv) ctx.local_node = sq.sq_node; rc = bind(ctx.sock, (void *)&sq, sizeof(sq)); - if (rc < 0) + if (rc < 0) { + if (errno == EADDRINUSE) { + PLOGE("nameserver already running, going dormant"); + go_dormant(ctx.sock); + } + PLOGE_AND_EXIT("bind control socket"); + } ctx.bcast_sq.sq_family = AF_QIPCRTR; ctx.bcast_sq.sq_node = QRTR_NODE_BCAST; -- cgit v1.2.3 From 2cf92a4173d774ad491709f80fe8fe3aa1698e6a Mon Sep 17 00:00:00 2001 From: Amit Pundir Date: Wed, 15 Apr 2020 13:56:36 +0530 Subject: qcom: qrtr: Disable qrtr-ns and qrtr-cfg No need to run qrtr-ns and qrtr-cfg services explicitly. They are moved to kernel now starting from v5.7-rc1. We are keeping qrtr-lookup around for debugging. Signed-off-by: Amit Pundir Change-Id: I02d72e73ef3d64fed1c024a97cec3560241aff22 --- db845c/device.mk | 3 +-- qcom/init.qcom.rc | 13 +------------ sepolicy/file_contexts | 3 --- sepolicy/qrtr.te | 8 -------- 4 files changed, 2 insertions(+), 25 deletions(-) delete mode 100644 sepolicy/qrtr.te diff --git a/db845c/device.mk b/db845c/device.mk index b37e06f..23299ad 100644 --- a/db845c/device.mk +++ b/db845c/device.mk @@ -32,10 +32,9 @@ PRODUCT_COPY_FILES := \ # Build generic Audio HAL PRODUCT_PACKAGES := audio.primary.db845c +# Build and install Qcom userspace tools to talk to dsp and modem PRODUCT_PACKAGES += \ pd-mapper \ - qrtr-ns \ - qrtr-cfg \ qrtr-lookup \ rmtfs \ tqftpserv diff --git a/qcom/init.qcom.rc b/qcom/init.qcom.rc index 303fc9a..6325127 100644 --- a/qcom/init.qcom.rc +++ b/qcom/init.qcom.rc @@ -1,10 +1,3 @@ -service qrtr-ns /vendor/bin/qrtr-ns -f 1 - class core - user root - group system - disabled - oneshot - service pd_mapper /vendor/bin/pd-mapper class core user root @@ -26,11 +19,6 @@ service rmtfs /vendor/bin/rmtfs -o /dev/block/platform/soc@0/1d84000.ufshc/by-na disabled oneshot -on early-init - exec - root -- /vendor/bin/qrtr-cfg 1 - start qrtr-ns - start pd_mapper - on post-fs-data mkdir /data/vendor mkdir /data/vendor/tmp @@ -39,5 +27,6 @@ on post-fs-data mkdir /data/vendor/readonly/firmware mkdir /data/vendor/readonly/firmware/image write /sys/class/firmware/timeout 1 + start pd_mapper start tqftpserv start rmtfs diff --git a/sepolicy/file_contexts b/sepolicy/file_contexts index 247e1ab..532b1c9 100644 --- a/sepolicy/file_contexts +++ b/sepolicy/file_contexts @@ -33,8 +33,6 @@ /vendor/bin/hw/android\.hardware\.gatekeeper@1\.0-service\.software u:object_r:hal_gatekeeper_default_exec:s0 /vendor/bin/pd-mapper u:object_r:pd_mapper_exec:s0 -/vendor/bin/qrtr-cfg u:object_r:qrtr_exec:s0 -/vendor/bin/qrtr-ns u:object_r:qrtr_exec:s0 /vendor/bin/rmtfs u:object_r:rmtfs_exec:s0 /vendor/bin/tqftpserv u:object_r:tqftpserv_exec:s0 @@ -44,4 +42,3 @@ /vendor/lib(64)?/libdrm_freedreno\.so u:object_r:same_process_hal_file:s0 /vendor/lib(64)?/libgbm\.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)?/libqrtr\.so u:object_r:same_process_hal_file:s0 diff --git a/sepolicy/qrtr.te b/sepolicy/qrtr.te deleted file mode 100644 index 8344398..0000000 --- a/sepolicy/qrtr.te +++ /dev/null @@ -1,8 +0,0 @@ -type qrtr, domain; -type qrtr_exec, exec_type, vendor_file_type, file_type; -init_daemon_domain(qrtr) - -allow qrtr self:capability net_admin; -allow qrtr self:capability sys_admin; -allow qrtr self:qipcrtr_socket create_socket_perms_no_ioctl; -allow qrtr self:netlink_route_socket { create nlmsg_write read write }; -- cgit v1.2.3 From a1004bef0ea568882526ad3f4a0c33fb19c4d220 Mon Sep 17 00:00:00 2001 From: Amit Pundir Date: Wed, 15 Apr 2020 17:27:21 +0530 Subject: sepolicy: Cleanup and cosmetic changes No functional changes. Renamed few labels and removed older kernel support. Earlier I named few framework sysfs labels based on the execs accessing those sysfs entries. For example: /sys/class/remoteproc u:object_r:sysfs_tqftpserv:s0 just because tqftpserv was the only binary which needed access of remoteproc sysfs. That was short sighted and I try to fix some of such cosmetic mistakes in this patch. All the remoteproc sysfs entries (adsp/cdsp) are labeled as sysfs_remoteproc. Also removed few sysfs entries needed to bring display on obsolete v5.3 and older kernels. Signed-off-by: Amit Pundir Change-Id: I9b09be07d9f74708a6be89408b565dde7c184dfd --- sepolicy/file.te | 3 ++- sepolicy/file_contexts | 13 +++++-------- sepolicy/genfs_contexts | 9 +++------ sepolicy/pd_mapper.te | 6 ++---- sepolicy/rmtfs.te | 8 +++++--- sepolicy/tqftpserv.te | 4 ++-- 6 files changed, 19 insertions(+), 24 deletions(-) diff --git a/sepolicy/file.te b/sepolicy/file.te index 3e31092..4a0ada7 100644 --- a/sepolicy/file.te +++ b/sepolicy/file.te @@ -1,6 +1,7 @@ type sysfs_gpu, fs_type, sysfs_type; +type sysfs_mss, fs_type, sysfs_type; type sysfs_rmtfs, fs_type, sysfs_type; -type sysfs_tqftpserv, fs_type, sysfs_type; +type sysfs_remoteproc, fs_type, sysfs_type; type dri_device, dev_type; type rmtfs_device, dev_type; type modem_block_device, dev_type; diff --git a/sepolicy/file_contexts b/sepolicy/file_contexts index 532b1c9..3279734 100644 --- a/sepolicy/file_contexts +++ b/sepolicy/file_contexts @@ -11,19 +11,16 @@ /dev/qcom_rmtfs_mem1 u:object_r:rmtfs_device:s0 /dev/ttyMSM0 u:object_r:console_device:s0 -/sys/bus/platform/drivers/qcom-q6v5-mss u:object_r:sysfs_rmtfs:s0 +/sys/bus/platform/drivers/qcom-q6v5-mss u:object_r:sysfs_mss:s0 /sys/devices/platform/88f00000.memory/rmtfs u:object_r:sysfs_rmtfs:s0 -/sys/devices/platform/soc/ae00000.mdss u:object_r:sysfs_gpu:s0 -/sys/devices/platform/soc/c440000.spmi/spmi-0/0-00/c440000.spmi:pmic@0:rtc@6000/rtc u:object_r:sysfs_rtc:s0 - -# sysfs path changed in v5.4+ kernel for sdm845 devices -/sys/devices/platform/soc@0/4080000.remoteproc u:object_r:sysfs_rmtfs:s0 +/sys/devices/platform/soc@0/4080000.remoteproc u:object_r:sysfs_remoteproc:s0 /sys/devices/platform/soc@0/ae00000.mdss u:object_r:sysfs_gpu:s0 /sys/devices/platform/soc@0/c440000.spmi/spmi-0/0-00/c440000.spmi:pmic@0:rtc@6000/rtc u:object_r:sysfs_rtc:s0 -/sys/class/remoteproc u:object_r:sysfs_tqftpserv:s0 -/sys/devices/platform/remoteproc-cdsp/remoteproc/remoteproc2/firmware u:object_r:sysfs_tqftpserv:s0 +/sys/class/remoteproc u:object_r:sysfs_remoteproc:s0 +/sys/devices/platform/remoteproc-adsp/remoteproc u:object_r:sysfs_remoteproc:s0 +/sys/devices/platform/remoteproc-cdsp/remoteproc u:object_r:sysfs_remoteproc:s0 /data/vendor/tmp(/.*)? u:object_r:tqftpserv_vendor_data_file:s0 /data/vendor/readwrite(/.*)? u:object_r:tqftpserv_vendor_data_file:s0 diff --git a/sepolicy/genfs_contexts b/sepolicy/genfs_contexts index caed6c0..ee8b953 100644 --- a/sepolicy/genfs_contexts +++ b/sepolicy/genfs_contexts @@ -1,9 +1,6 @@ genfscon sysfs /devices/platform/88f00000.memory/rmtfs u:object_r:sysfs_rmtfs:s0 -genfscon sysfs /devices/platform/soc/ae00000.mdss u:object_r:sysfs_gpu:s0 -genfscon sysfs /devices/platform/soc/c440000.spmi/spmi-0/0-00/c440000.spmi:pmic@0:rtc@6000 u:object_r:sysfs_rtc:s0 - -genfscon sysfs /devices/platform/remoteproc-cdsp/remoteproc/remoteproc2/firmware u:object_r:sysfs_tqftpserv:s0 -# sysfs path changed in v5.4+ kernel for sdm845 devices -genfscon sysfs /devices/platform/soc@0/4080000.remoteproc u:object_r:sysfs_rmtfs:s0 +genfscon sysfs /devices/platform/remoteproc-adsp/remoteproc u:object_r:sysfs_remoteproc:s0 +genfscon sysfs /devices/platform/remoteproc-cdsp/remoteproc u:object_r:sysfs_remoteproc:s0 +genfscon sysfs /devices/platform/soc@0/4080000.remoteproc u:object_r:sysfs_remoteproc:s0 genfscon sysfs /devices/platform/soc@0/ae00000.mdss u:object_r:sysfs_gpu:s0 genfscon sysfs /devices/platform/soc@0/c440000.spmi/spmi-0/0-00/c440000.spmi:pmic@0:rtc@6000 u:object_r:sysfs_rtc:s0 diff --git a/sepolicy/pd_mapper.te b/sepolicy/pd_mapper.te index 2e48a86..597d7db 100644 --- a/sepolicy/pd_mapper.te +++ b/sepolicy/pd_mapper.te @@ -4,7 +4,5 @@ type pd_mapper_exec, exec_type, vendor_file_type, file_type; init_daemon_domain(pd_mapper); allow pd_mapper self:qipcrtr_socket { create getattr read setopt write }; -allow pd_mapper sysfs_rmtfs:dir search; -allow pd_mapper sysfs_rmtfs:file { open read }; -allow pd_mapper sysfs_tqftpserv:dir { open read search }; -allow pd_mapper sysfs_tqftpserv:file { open read }; +allow pd_mapper sysfs_remoteproc:dir { open read search }; +allow pd_mapper sysfs_remoteproc:file { open read }; diff --git a/sepolicy/rmtfs.te b/sepolicy/rmtfs.te index fff2e64..7cef38f 100644 --- a/sepolicy/rmtfs.te +++ b/sepolicy/rmtfs.te @@ -8,6 +8,8 @@ allow rmtfs modem_block_device:blk_file { open read }; allow rmtfs rmtfs_device:chr_file { open read write }; allow rmtfs self:capability net_admin; allow rmtfs self:qipcrtr_socket { bind create getattr read setopt write }; -allow rmtfs sysfs_rmtfs:dir { open read search}; -allow rmtfs sysfs_rmtfs:file r_file_perms; -allow rmtfs sysfs_rmtfs:file write; +allow rmtfs sysfs_mss:dir { open read search }; +allow rmtfs sysfs_remoteproc:dir { open read search }; +allow rmtfs sysfs_remoteproc:file { open write }; +allow rmtfs sysfs_rmtfs:dir search; +allow rmtfs sysfs_rmtfs:file { open read }; diff --git a/sepolicy/tqftpserv.te b/sepolicy/tqftpserv.te index 46f3926..d437c0d 100644 --- a/sepolicy/tqftpserv.te +++ b/sepolicy/tqftpserv.te @@ -4,7 +4,7 @@ type tqftpserv_exec, exec_type, vendor_file_type, file_type; init_daemon_domain(tqftpserv); allow tqftpserv self:qipcrtr_socket { connect create getattr read setopt write }; -allow tqftpserv sysfs_tqftpserv:dir { open read search }; -allow tqftpserv sysfs_tqftpserv:file { open read }; +allow tqftpserv sysfs_remoteproc:dir { open read search }; +allow tqftpserv sysfs_remoteproc:file { open read }; allow tqftpserv tqftpserv_vendor_data_file:dir { add_name create open read search write }; allow tqftpserv tqftpserv_vendor_data_file:file { create open write }; -- cgit v1.2.3 From 1641199f230d7926891a9c6a9d09b6c9b8f411db Mon Sep 17 00:00:00 2001 From: Amit Pundir Date: Wed, 26 Feb 2020 13:24:11 +0530 Subject: audio: Set analog port as default audio out For db845c, set Analog stereo speakers port as default audio out since HDMI audio out is WIP. "PCM_DEVICE 0" corresponds to HDMI audio out (WIP). "PCM_DEVICE 1" is 8 Ohm Analog speakers. Change-Id: I818fe380ab0f4094f7364aa4357045b1927dc56b Signed-off-by: Amit Pundir --- audio/audio_hw.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/audio/audio_hw.c b/audio/audio_hw.c index 805e2cd..13eb468 100644 --- a/audio/audio_hw.c +++ b/audio/audio_hw.c @@ -40,7 +40,7 @@ #include #define PCM_CARD 0 -#define PCM_DEVICE 0 +#define PCM_DEVICE 1 #define OUT_PERIOD_MS 15 -- cgit v1.2.3 From 65502d4b52be218340911dd902d6f068e2924e37 Mon Sep 17 00:00:00 2001 From: Amit Pundir Date: Wed, 26 Feb 2020 13:28:54 +0530 Subject: audio: Set Analog and HDMI mixer controls Set Analog and HDMI mixer controls for db845c on boot completion using tinymix. Put a 1 second sleep in-between pd-mapper and tinymix to let sound/codecs initialized properly before setting mixer controls. Also made sure that audio out interface is ready before audioserver service get started. Change-Id: Ib321559815e5d22d224fc36a1fe6c21f52df3eec Signed-off-by: Amit Pundir --- qcom/init.qcom.rc | 28 +++++++++++++++++++++++++++- sepolicy/file_contexts | 1 + sepolicy/tinymix.te | 7 +++++++ 3 files changed, 35 insertions(+), 1 deletion(-) create mode 100644 sepolicy/tinymix.te diff --git a/qcom/init.qcom.rc b/qcom/init.qcom.rc index 6325127..5867179 100644 --- a/qcom/init.qcom.rc +++ b/qcom/init.qcom.rc @@ -19,6 +19,33 @@ service rmtfs /vendor/bin/rmtfs -o /dev/block/platform/soc@0/1d84000.ufshc/by-na disabled oneshot +on post-fs + start pd_mapper + exec - root -- /system/bin/sleep 1 + exec - system audio -- /system/bin/tinymix "QUAT_MI2S_RX Audio Mixer MultiMedia1" 1 + exec - system audio -- /system/bin/tinymix "SLIM RX0 MUX" AIF1_PB + exec - system audio -- /system/bin/tinymix "SLIM RX0 MUX" ZERO + exec - system audio -- /system/bin/tinymix "SLIM RX1 MUX" ZERO + exec - system audio -- /system/bin/tinymix "SLIM RX2 MUX" ZERO + exec - system audio -- /system/bin/tinymix "SLIM RX3 MUX" ZERO + exec - system audio -- /system/bin/tinymix "SLIM RX4 MUX" ZERO + exec - system audio -- /system/bin/tinymix "SLIM RX5 MUX" ZERO + exec - system audio -- /system/bin/tinymix "SLIM RX6 MUX" AIF1_PB + exec - system audio -- /system/bin/tinymix "SLIM RX7 MUX" AIF1_PB + exec - system audio -- /system/bin/tinymix "RX INT7_1 MIX1 INP0" RX6 + exec - system audio -- /system/bin/tinymix "RX INT8_1 MIX1 INP0" RX7 + exec - system audio -- /system/bin/tinymix "COMP7 Switch" 1 + exec - system audio -- /system/bin/tinymix "COMP8 Switch" 1 + exec - system audio -- /system/bin/tinymix "SpkrLeft COMP Switch" 1 + exec - system audio -- /system/bin/tinymix "SpkrLeft BOOST Switch" 1 + exec - system audio -- /system/bin/tinymix "SpkrLeft VISENSE Switch" 0 + exec - system audio -- /system/bin/tinymix "SpkrLeft DAC Switch" 1 + exec - system audio -- /system/bin/tinymix "SpkrRight COMP Switch" 1 + exec - system audio -- /system/bin/tinymix "SpkrRight BOOST Switch" 1 + exec - system audio -- /system/bin/tinymix "SpkrRight VISENSE Switch" 0 + exec - system audio -- /system/bin/tinymix "SpkrRight DAC Switch" 1 + exec - system audio -- /system/bin/tinymix "SLIMBUS_0_RX Audio Mixer MultiMedia2" 1 + on post-fs-data mkdir /data/vendor mkdir /data/vendor/tmp @@ -27,6 +54,5 @@ on post-fs-data mkdir /data/vendor/readonly/firmware mkdir /data/vendor/readonly/firmware/image write /sys/class/firmware/timeout 1 - start pd_mapper start tqftpserv start rmtfs diff --git a/sepolicy/file_contexts b/sepolicy/file_contexts index 3279734..f223cc4 100644 --- a/sepolicy/file_contexts +++ b/sepolicy/file_contexts @@ -27,6 +27,7 @@ /data/vendor/readonly(/.*)? u:object_r:tqftpserv_vendor_data_file:s0 /system/bin/eth_mac_addr\.sh u:object_r:eth_mac_addr_exec:s0 +/system/bin/tinymix u:object_r:tinymix_exec:s0 /vendor/bin/hw/android\.hardware\.gatekeeper@1\.0-service\.software u:object_r:hal_gatekeeper_default_exec:s0 /vendor/bin/pd-mapper u:object_r:pd_mapper_exec:s0 diff --git a/sepolicy/tinymix.te b/sepolicy/tinymix.te new file mode 100644 index 0000000..75dc071 --- /dev/null +++ b/sepolicy/tinymix.te @@ -0,0 +1,7 @@ +type tinymix, domain, coredomain; +type tinymix_exec, exec_type, system_file_type, file_type; + +init_daemon_domain(tinymix) + +allow tinymix audio_device:chr_file { ioctl open read write }; +allow tinymix audio_device:dir search; -- cgit v1.2.3