Jelajahi Sumber

Merge remote-tracking branch 'upstream/lineage-22.2' into HEAD

j7b3y 2 bulan lalu
induk
melakukan
46912d9e14

+ 0 - 1
Android.bp

@@ -6,7 +6,6 @@
 
 soong_namespace {
     imports: [
-        "hardware/qcom-caf/bootctrl",
         "hardware/xiaomi",
         "vendor/qcom/opensource/commonsys-intf/display",
     ],

+ 1 - 12
BoardConfigCommon.mk

@@ -10,8 +10,6 @@ include vendor/xiaomi/sm8450-common/BoardConfigVendor.mk
 COMMON_PATH := device/xiaomi/sm8450-common
 
 # A/B
-AB_OTA_UPDATER := true
-
 AB_OTA_PARTITIONS += \
     boot \
     dtbo \
@@ -67,15 +65,6 @@ TARGET_NO_BOOTLOADER := true
 # Camera
 TARGET_CAMERA_OVERRIDE_FORMAT_FROM_RESERVED := true
 
-# Display
-TARGET_FORCE_HWC_FOR_VIRTUAL_DISPLAYS := true
-TARGET_GRALLOC_HANDLE_HAS_CUSTOM_CONTENT_MD_RESERVED_SIZE := false
-TARGET_USES_DISPLAY_RENDER_INTENTS := true
-TARGET_USES_GRALLOC4 := true
-TARGET_USES_HWC2 := true
-MAX_VIRTUAL_DISPLAY_DIMENSION := 4096
-NUM_FRAMEBUFFER_SURFACE_BUFFERS := 3
-
 # Filesystem
 TARGET_FS_CONFIG_GEN := $(COMMON_PATH)/configs/config.fs
 
@@ -211,7 +200,7 @@ BOARD_EXCLUDE_KERNEL_FROM_RECOVERY_IMAGE := true
 ENABLE_VENDOR_RIL_SERVICE := true
 
 # Security patch level
-VENDOR_SECURITY_PATCH := 2024-11-01
+VENDOR_SECURITY_PATCH := 2025-03-01
 
 # Sepolicy
 include device/qcom/sepolicy_vndr/SEPolicy.mk

+ 1 - 3
audio/audio_effects.xml

@@ -1,5 +1,5 @@
 <?xml version="1.0" encoding="UTF-8"?>
-<!--- Copyright (c) 2018-2019, The Linux Foundation. All rights reserved.            -->
+<!--- Copyright (c) 2018-2019, 2021 The Linux Foundation. All rights reserved.  -->
 <!---                                                                           -->
 <!--- Redistribution and use in source and binary forms, with or without        -->
 <!--- modification, are permitted provided that the following conditions are    -->
@@ -40,7 +40,6 @@
         <library name="audio_pre_processing" path="libqcomvoiceprocessing.so"/>
         <library name="volume_listener" path="libvolumelistener.so"/>
         <library name="audiosphere" path="libasphere.so"/>
-        <library name="shoebox" path="libshoebox.so"/>
     </libraries>
     <effects>
         <effectProxy name="bassboost" library="proxy" uuid="14804144-a5ee-4d24-aa88-0002a5d5c51b">
@@ -87,7 +86,6 @@
         <effect name="voice_helper" library="volume_listener" uuid="0ace5c08-0590-11e5-ae9e-0025b32654a0"/>
         <effect name="notification_helper" library="volume_listener" uuid="0b776dde-0590-11e5-81ba-0025b32654a0"/>
         <effect name="audiosphere" library="audiosphere" uuid="184e62ab-2d19-4364-9d1b-c0a40733866c"/>
-        <effect name="shoebox" library="shoebox" uuid="1eab784c-1a36-4b2a-b7fc-e34c44cab89e"/>
     </effects>
     <postprocess>
         <stream type="music">

+ 0 - 12
bootctrl/Android.bp

@@ -1,12 +0,0 @@
-//
-// Copyright (C) 2022 The LineageOS Project
-//
-// SPDX-License-Identifier: Apache-2.0
-//
-
-cc_library_shared {
-    name: "[email protected]",
-    stem: "[email protected]",
-    defaults: ["[email protected]_defaults"],
-    static_libs: ["libgptutils.xiaomi_sm8450"],
-}

+ 11 - 16
common.mk

@@ -54,8 +54,7 @@ PRODUCT_PACKAGES += \
     [email protected]:64 \
     android.hardware.audio.service \
     [email protected]:64 \
-    [email protected] \
-    [email protected]:64
+    [email protected]
 
 PRODUCT_PACKAGES += \
     audio.bluetooth.default:64 \
@@ -67,18 +66,18 @@ PRODUCT_PACKAGES += \
     audioadsprpcd
 
 PRODUCT_PACKAGES += \
+    lib_bt_aptx:64 \
+    lib_bt_ble:64 \
+    lib_bt_bundle:64 \
     libagm_compress_plugin:64 \
     libagm_mixer_plugin:64 \
     libagm_pcm_plugin:64 \
-    libagmclient:64 \
-    libagmmixer:64 \
     libbatterylistener:64 \
     libfmpal:64 \
     libpalclient:64 \
     libqcompostprocbundle:64 \
     libqcomvisualizer:64 \
     libqcomvoiceprocessing:64 \
-    libsndcardparser:64 \
     libvolumelistener:64
 
 $(foreach sku, taro diwali cape ukee parrot, \
@@ -87,6 +86,10 @@ $(foreach sku, taro diwali cape ukee parrot, \
         $(LOCAL_PATH)/audio/audio_policy_configuration.xml:$(TARGET_COPY_OUT_VENDOR)/etc/audio/sku_$(sku)/audio_policy_configuration.xml \
     ))
 
+PRODUCT_COPY_FILES += \
+    hardware/qcom-caf/sm8450/audio/primary-hal/configs/taro/card-defs.xml:$(TARGET_COPY_OUT_VENDOR)/etc/card-defs.xml \
+    hardware/qcom-caf/sm8450/audio/primary-hal/configs/taro/microphone_characteristics.xml:$(TARGET_COPY_OUT_VENDOR)/etc/microphone_characteristics.xml
+
 PRODUCT_COPY_FILES += \
     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 \
@@ -105,12 +108,8 @@ PRODUCT_COPY_FILES += \
 
 # Boot control
 PRODUCT_PACKAGES += \
-    [email protected]:64 \
-    [email protected]:64 \
-    [email protected]
-
-PRODUCT_PACKAGES_DEBUG += \
-    bootctl:64
+    android.hardware.boot-service.qti \
+    android.hardware.boot-service.qti.recovery
 
 # Camera
 PRODUCT_COPY_FILES += \
@@ -231,6 +230,7 @@ PRODUCT_PACKAGES += \
 
 # Network
 PRODUCT_COPY_FILES += \
+    frameworks/native/data/etc/android.software.ipsec_tunnel_migration.xml:$(TARGET_COPY_OUT_VENDOR)/etc/permissions/android.software.ipsec_tunnel_migration.xml \
     frameworks/native/data/etc/android.software.ipsec_tunnels.xml:$(TARGET_COPY_OUT_VENDOR)/etc/permissions/android.software.ipsec_tunnels.xml
 
 # NFC / Secure Element
@@ -389,9 +389,6 @@ PRODUCT_PACKAGES += \
     update_engine_sideload \
     update_verifier
 
-PRODUCT_PACKAGES_DEBUG += \
-    update_engine_client
-
 # USB
 PRODUCT_PACKAGES += \
     android.hardware.usb-service.qti \
@@ -425,7 +422,6 @@ PRODUCT_COPY_FILES += \
     $(LOCAL_PATH)/rootdir/bin/init.kernel.post_boot-diwali.sh:$(TARGET_COPY_OUT_VENDOR)/bin/init.kernel.post_boot-diwali.sh \
     $(LOCAL_PATH)/rootdir/bin/init.kernel.post_boot-taro.sh:$(TARGET_COPY_OUT_VENDOR)/bin/init.kernel.post_boot-taro.sh \
     $(LOCAL_PATH)/rootdir/bin/init.kernel.post_boot.sh:$(TARGET_COPY_OUT_VENDOR)/bin/init.kernel.post_boot.sh \
-    $(LOCAL_PATH)/rootdir/bin/init.qcom.class_core.sh:$(TARGET_COPY_OUT_VENDOR)/bin/init.qcom.class_core.sh \
     $(LOCAL_PATH)/rootdir/bin/init.qcom.early_boot.sh:$(TARGET_COPY_OUT_VENDOR)/bin/init.qcom.early_boot.sh \
     $(LOCAL_PATH)/rootdir/bin/init.qcom.post_boot.sh:$(TARGET_COPY_OUT_VENDOR)/bin/init.qcom.post_boot.sh \
     $(LOCAL_PATH)/rootdir/bin/init.qcom.sh:$(TARGET_COPY_OUT_VENDOR)/bin/init.qcom.sh \
@@ -451,7 +447,6 @@ PRODUCT_PACKAGES += \
     hostapd \
     hostapd_cli \
     libwifi-hal-qcom:64 \
-    libwpa_client:64 \
     wpa_cli \
     wpa_supplicant \
     wpa_supplicant.conf

+ 5 - 5
extract-files.py

@@ -48,13 +48,17 @@ lib_fixups: lib_fixups_user_type = {
     ): lib_fixup_vendor_suffix,
     (
         'libagm',
+        'libar-acdb',
         'libar-pal',
+        'libats',
+        'liblx-osal',
         'libpalclient',
-        'libwpa_client',
     ): lib_fixup_remove,
 }
 
 blob_fixups: blob_fixups_user_type = {
+    'system_ext/bin/wfdservice64': blob_fixup()
+        .add_needed('libwfdservice_shim.so'),
     'system_ext/lib64/libwfdmmsrc_system.so': blob_fixup()
         .add_needed('libgui_shim.so'),
     'system_ext/lib64/libwfdnative.so': blob_fixup()
@@ -97,12 +101,8 @@ blob_fixups: blob_fixups_user_type = {
        'vendor/etc/media_codecs_ukee.xml',
     ): blob_fixup()
         .regex_replace('.+media_codecs_(google_audio|google_c2|google_telephony|vendor_audio).+\n', ''),
-    'vendor/etc/seccomp_policy/[email protected]': blob_fixup()
-        .add_line_if_missing('gettid: 1'),
     'vendor/etc/seccomp_policy/c2audio.vendor.ext-arm64.policy': blob_fixup()
         .add_line_if_missing('setsockopt: 1'),
-    'vendor/etc/seccomp_policy/wfdhdcphalservice.policy': blob_fixup()
-        .add_line_if_missing('gettid: 1'),
     'vendor/etc/vintf/manifest/c2_manifest_vendor.xml': blob_fixup()
         .regex_replace('.+dolby.+\n', ''),
     'vendor/lib64/vendor.libdpmframework.so': blob_fixup()

+ 0 - 52
gpt-utils/Android.bp

@@ -1,52 +0,0 @@
-soong_config_module_type {
-    name: "ufsbsg_cc_defaults",
-    module_type: "cc_defaults",
-    config_namespace: "ufsbsg",
-    variables: ["ufsframework"],
-    properties: ["cflags"],
-}
-
-soong_config_string_variable {
-    name: "ufsframework",
-    values: ["sg", "bsg"],
-}
-
-ufsbsg_cc_defaults {
-    name: "ufsbsg_defaults",
-    soong_config_variables: {
-        ufsframework: {
-            bsg : {
-               cflags : ["-D_BSG_FRAMEWORK_KERNEL_HEADERS"],
-            },
-        },
-     },
-}
-
-cc_library {
-    name: "libgptutils.xiaomi_sm8450",
-    vendor: true,
-    recovery_available: true,
-    defaults: ["ufsbsg_defaults"],
-    srcs: [
-        "gpt-utils.cpp",
-        "recovery-ufs-bsg.cpp",
-    ],
-    shared_libs: [
-            "libcutils",
-            "liblog",
-            "libz",
-    ],
-    cflags: [
-        "-Wall",
-        "-Wno-unused-parameter",
-    ],
-    sanitize: {
-        cfi: false,
-    },
-    owner: "qti",
-    export_include_dirs: ["."],
-    header_libs: [
-            "qti_kernel_headers",
-            "device_kernel_headers",
-    ],
-}

+ 0 - 1520
gpt-utils/gpt-utils.cpp

@@ -1,1520 +0,0 @@
-/*
- * Copyright (c) 2013,2016,2020 The Linux Foundation. All rights reserved.
- *
- * Redistribution and use in source and binary forms, with or without
- * modification, are permitted provided that the following conditions are
- * met:
- *     * Redistributions of source code must retain the above copyright
- *       notice, this list of conditions and the following disclaimer.
- *     * 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.
- *     * Neither the name of The Linux Foundation 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 "AS IS" AND ANY EXPRESS OR IMPLIED
- * WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF
- * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NON-INFRINGEMENT
- * ARE DISCLAIMED.  IN NO EVENT SHALL THE COPYRIGHT OWNER 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.
- */
-
-#define _LARGEFILE64_SOURCE /* enable lseek64() */
-
-/******************************************************************************
- * INCLUDE SECTION
- ******************************************************************************/
-#include <fcntl.h>
-#include <string.h>
-#include <errno.h>
-#include <sys/stat.h>
-#include <sys/ioctl.h>
-#include <unistd.h>
-#include <linux/fs.h>
-#include <limits.h>
-#include <dirent.h>
-#include <linux/kernel.h>
-#include <map>
-#include <vector>
-#include <string>
-#ifndef __STDC_FORMAT_MACROS
-#define __STDC_FORMAT_MACROS
-#endif
-#include <inttypes.h>
-
-
-#define LOG_TAG "gpt-utils"
-#include <cutils/log.h>
-#include <cutils/properties.h>
-#include "gpt-utils.h"
-#include <zlib.h>
-#include <endian.h>
-
-
-/******************************************************************************
- * DEFINE SECTION
- ******************************************************************************/
-#define BLK_DEV_FILE    "/dev/block/mmcblk0"
-/* list the names of the backed-up partitions to be swapped */
-/* extension used for the backup partitions - tzbak, abootbak, etc. */
-#define BAK_PTN_NAME_EXT    "bak"
-#define XBL_PRIMARY         "/dev/block/bootdevice/by-name/xbl"
-#define XBL_BACKUP          "/dev/block/bootdevice/by-name/xblbak"
-#define XBL_AB_PRIMARY      "/dev/block/bootdevice/by-name/xbl_a"
-#define XBL_AB_SECONDARY    "/dev/block/bootdevice/by-name/xbl_b"
-/* GPT defines */
-#define MAX_LUNS                    26
-//This will allow us to get the root lun path from the path to the partition.
-//i.e: from /dev/block/sdaXXX get /dev/block/sda. The assumption here is that
-//the boot critical luns lie between sda to sdz which is acceptable because
-//only user added external disks,etc would lie beyond that limit which do not
-//contain partitions that interest us here.
-#define PATH_TRUNCATE_LOC (sizeof("/dev/block/sda") - 1)
-
-//From /dev/block/sda get just sda
-#define LUN_NAME_START_LOC (sizeof("/dev/block/") - 1)
-#define BOOT_LUN_A_ID 1
-#define BOOT_LUN_B_ID 2
-/******************************************************************************
- * MACROS
- ******************************************************************************/
-
-
-#define GET_4_BYTES(ptr)    ((uint32_t) *((uint8_t *)(ptr)) | \
-        ((uint32_t) *((uint8_t *)(ptr) + 1) << 8) | \
-        ((uint32_t) *((uint8_t *)(ptr) + 2) << 16) | \
-        ((uint32_t) *((uint8_t *)(ptr) + 3) << 24))
-
-#define GET_8_BYTES(ptr)    ((uint64_t) *((uint8_t *)(ptr)) | \
-        ((uint64_t) *((uint8_t *)(ptr) + 1) << 8) | \
-        ((uint64_t) *((uint8_t *)(ptr) + 2) << 16) | \
-        ((uint64_t) *((uint8_t *)(ptr) + 3) << 24) | \
-        ((uint64_t) *((uint8_t *)(ptr) + 4) << 32) | \
-        ((uint64_t) *((uint8_t *)(ptr) + 5) << 40) | \
-        ((uint64_t) *((uint8_t *)(ptr) + 6) << 48) | \
-        ((uint64_t) *((uint8_t *)(ptr) + 7) << 56))
-
-#define PUT_4_BYTES(ptr, y)   *((uint8_t *)(ptr)) = (y) & 0xff; \
-        *((uint8_t *)(ptr) + 1) = ((y) >> 8) & 0xff; \
-        *((uint8_t *)(ptr) + 2) = ((y) >> 16) & 0xff; \
-        *((uint8_t *)(ptr) + 3) = ((y) >> 24) & 0xff;
-
-/******************************************************************************
- * TYPES
- ******************************************************************************/
-using namespace std;
-enum gpt_state {
-    GPT_OK = 0,
-    GPT_BAD_SIGNATURE,
-    GPT_BAD_CRC
-};
-//List of LUN's containing boot critical images.
-//Required in the case of UFS devices
-struct update_data {
-     char lun_list[MAX_LUNS][PATH_MAX];
-     uint32_t num_valid_entries;
-};
-
-int32_t set_boot_lun(char *sg_dev,uint8_t boot_lun_id);
-/******************************************************************************
- * FUNCTIONS
- ******************************************************************************/
-/**
- *  ==========================================================================
- *
- *  \brief  Read/Write len bytes from/to block dev
- *
- *  \param [in] fd      block dev file descriptor (returned from open)
- *  \param [in] rw      RW flag: 0 - read, != 0 - write
- *  \param [in] offset  block dev offset [bytes] - RW start position
- *  \param [in] buf     Pointer to the buffer containing the data
- *  \param [in] len     RW size in bytes. Buf must be at least that big
- *
- *  \return  0 on success
- *
- *  ==========================================================================
- */
-static int blk_rw(int fd, int rw, int64_t offset, uint8_t *buf, unsigned len)
-{
-    int r;
-
-    if (lseek64(fd, offset, SEEK_SET) < 0) {
-        fprintf(stderr, "block dev lseek64 %" PRIi64 " failed: %s\n", offset,
-                strerror(errno));
-        return -1;
-    }
-
-    if (rw)
-        r = write(fd, buf, len);
-    else
-        r = read(fd, buf, len);
-
-    if (r < 0)
-        fprintf(stderr, "block dev %s failed: %s\n", rw ? "write" : "read",
-                strerror(errno));
-    else
-        r = 0;
-
-    return r;
-}
-
-
-
-/**
- *  ==========================================================================
- *
- *  \brief  Search within GPT for partition entry with the given name
- *  or it's backup twin (name-bak).
- *
- *  \param [in] ptn_name        Partition name to seek
- *  \param [in] pentries_start  Partition entries array start pointer
- *  \param [in] pentries_end    Partition entries array end pointer
- *  \param [in] pentry_size     Single partition entry size [bytes]
- *
- *  \return  First partition entry pointer that matches the name or NULL
- *
- *  ==========================================================================
- */
-static uint8_t *gpt_pentry_seek(const char *ptn_name,
-                                const uint8_t *pentries_start,
-                                const uint8_t *pentries_end,
-                                uint32_t pentry_size)
-{
-    char     *pentry_name;
-    unsigned  len = strlen(ptn_name);
-    unsigned  i;
-    char      name8[MAX_GPT_NAME_SIZE] = {0}; // initialize with null
-
-    for (pentry_name = (char *) (pentries_start + PARTITION_NAME_OFFSET);
-         pentry_name < (char *) pentries_end;
-         pentry_name += pentry_size) {
-
-        /* Partition names in GPT are UTF-16 - ignoring UTF-16 2nd byte */
-        for (i = 0; i < sizeof(name8) / 2; i++)
-            name8[i] = pentry_name[i * 2];
-        name8[i] = '\0';
-
-        if (!strncmp(ptn_name, name8, len)) {
-            if (name8[len] == 0 || !strcmp(&name8[len], BAK_PTN_NAME_EXT))
-                return (uint8_t *) (pentry_name - PARTITION_NAME_OFFSET);
-        }
-    }
-
-    return NULL;
-}
-
-
-
-/**
- *  ==========================================================================
- *
- *  \brief  Swaps boot chain in GPT partition entries array
- *
- *  \param [in] pentries_start  Partition entries array start
- *  \param [in] pentries_end    Partition entries array end
- *  \param [in] pentry_size     Single partition entry size
- *
- *  \return  0 on success, 1 if no backup partitions found
- *
- *  ==========================================================================
- */
-static int gpt_boot_chain_swap(const uint8_t *pentries_start,
-                                const uint8_t *pentries_end,
-                                uint32_t pentry_size)
-{
-    const char ptn_swap_list[][MAX_GPT_NAME_SIZE] = { PTN_SWAP_LIST };
-
-    int backup_not_found = 1;
-    unsigned i;
-
-    for (i = 0; i < ARRAY_SIZE(ptn_swap_list); i++) {
-        uint8_t *ptn_entry;
-        uint8_t *ptn_bak_entry;
-        uint8_t ptn_swap[PTN_ENTRY_SIZE];
-        //Skip the xbl, multiimgoem, multiimgqti partitions on UFS devices. That is handled
-        //seperately.
-        if (gpt_utils_is_ufs_device() && (!strncmp(ptn_swap_list[i],PTN_XBL,strlen(PTN_XBL))
-            || !strncmp(ptn_swap_list[i],PTN_MULTIIMGOEM,strlen(PTN_MULTIIMGOEM))
-            || !strncmp(ptn_swap_list[i],PTN_MULTIIMGQTI,strlen(PTN_MULTIIMGQTI))))
-            continue;
-
-        ptn_entry = gpt_pentry_seek(ptn_swap_list[i], pentries_start,
-                        pentries_end, pentry_size);
-        if (ptn_entry == NULL)
-            continue;
-
-        ptn_bak_entry = gpt_pentry_seek(ptn_swap_list[i],
-                        ptn_entry + pentry_size, pentries_end, pentry_size);
-        if (ptn_bak_entry == NULL) {
-            fprintf(stderr, "'%s' partition not backup - skip safe update\n",
-                    ptn_swap_list[i]);
-            continue;
-        }
-
-        /* swap primary <-> backup partition entries */
-        memcpy(ptn_swap, ptn_entry, PTN_ENTRY_SIZE);
-        memcpy(ptn_entry, ptn_bak_entry, PTN_ENTRY_SIZE);
-        memcpy(ptn_bak_entry, ptn_swap, PTN_ENTRY_SIZE);
-        backup_not_found = 0;
-    }
-
-    return backup_not_found;
-}
-
-
-
-/**
- *  ==========================================================================
- *
- *  \brief  Sets secondary GPT boot chain
- *
- *  \param [in] fd    block dev file descriptor
- *  \param [in] boot  Boot chain to switch to
- *
- *  \return  0 on success
- *
- *  ==========================================================================
- */
-static int gpt2_set_boot_chain(int fd, enum boot_chain boot)
-{
-    int64_t  gpt2_header_offset;
-    uint64_t pentries_start_offset;
-    uint32_t gpt_header_size;
-    uint32_t pentry_size;
-    uint32_t pentries_array_size;
-
-    uint8_t *gpt_header = NULL;
-    uint8_t  *pentries = NULL;
-    uint32_t crc;
-    uint32_t crc_zero;
-    uint32_t blk_size = 0;
-    int r;
-
-
-    crc_zero = crc32(0L, Z_NULL, 0);
-    if (ioctl(fd, BLKSSZGET, &blk_size) != 0) {
-            fprintf(stderr, "Failed to get GPT device block size: %s\n",
-                            strerror(errno));
-            r = -1;
-            goto EXIT;
-    }
-    gpt_header = (uint8_t*)malloc(blk_size);
-    if (!gpt_header) {
-            fprintf(stderr, "Failed to allocate memory to hold GPT block\n");
-            r = -1;
-            goto EXIT;
-    }
-    gpt2_header_offset = lseek64(fd, 0, SEEK_END) - blk_size;
-    if (gpt2_header_offset < 0) {
-        fprintf(stderr, "Getting secondary GPT header offset failed: %s\n",
-                strerror(errno));
-        r = -1;
-        goto EXIT;
-    }
-
-    /* Read primary GPT header from block dev */
-    r = blk_rw(fd, 0, blk_size, gpt_header, blk_size);
-
-    if (r) {
-            fprintf(stderr, "Failed to read primary GPT header from blk dev\n");
-            goto EXIT;
-    }
-    pentries_start_offset =
-        GET_8_BYTES(gpt_header + PENTRIES_OFFSET) * blk_size;
-    pentry_size = GET_4_BYTES(gpt_header + PENTRY_SIZE_OFFSET);
-    pentries_array_size =
-        GET_4_BYTES(gpt_header + PARTITION_COUNT_OFFSET) * pentry_size;
-
-    pentries = (uint8_t *) calloc(1, pentries_array_size);
-    if (pentries == NULL) {
-        fprintf(stderr,
-                    "Failed to alloc memory for GPT partition entries array\n");
-        r = -1;
-        goto EXIT;
-    }
-    /* Read primary GPT partititon entries array from block dev */
-    r = blk_rw(fd, 0, pentries_start_offset, pentries, pentries_array_size);
-    if (r)
-        goto EXIT;
-
-    crc = crc32(crc_zero, pentries, pentries_array_size);
-    if (GET_4_BYTES(gpt_header + PARTITION_CRC_OFFSET) != crc) {
-        fprintf(stderr, "Primary GPT partition entries array CRC invalid\n");
-        r = -1;
-        goto EXIT;
-    }
-
-    /* Read secondary GPT header from block dev */
-    r = blk_rw(fd, 0, gpt2_header_offset, gpt_header, blk_size);
-    if (r)
-        goto EXIT;
-
-    gpt_header_size = GET_4_BYTES(gpt_header + HEADER_SIZE_OFFSET);
-    pentries_start_offset =
-        GET_8_BYTES(gpt_header + PENTRIES_OFFSET) * blk_size;
-
-    if (boot == BACKUP_BOOT) {
-        r = gpt_boot_chain_swap(pentries, pentries + pentries_array_size,
-                                pentry_size);
-        if (r)
-            goto EXIT;
-    }
-
-    crc = crc32(crc_zero, pentries, pentries_array_size);
-    PUT_4_BYTES(gpt_header + PARTITION_CRC_OFFSET, crc);
-
-    /* header CRC is calculated with this field cleared */
-    PUT_4_BYTES(gpt_header + HEADER_CRC_OFFSET, 0);
-    crc = crc32(crc_zero, gpt_header, gpt_header_size);
-    PUT_4_BYTES(gpt_header + HEADER_CRC_OFFSET, crc);
-
-    /* Write the modified GPT header back to block dev */
-    r = blk_rw(fd, 1, gpt2_header_offset, gpt_header, blk_size);
-    if (!r)
-        /* Write the modified GPT partititon entries array back to block dev */
-        r = blk_rw(fd, 1, pentries_start_offset, pentries,
-                    pentries_array_size);
-
-EXIT:
-    if(gpt_header)
-            free(gpt_header);
-    if (pentries)
-            free(pentries);
-    return r;
-}
-
-/**
- *  ==========================================================================
- *
- *  \brief  Checks GPT state (header signature and CRC)
- *
- *  \param [in] fd      block dev file descriptor
- *  \param [in] gpt     GPT header to be checked
- *  \param [out] state  GPT header state
- *
- *  \return  0 on success
- *
- *  ==========================================================================
- */
-static int gpt_get_state(int fd, enum gpt_instance gpt, enum gpt_state *state)
-{
-    int64_t gpt_header_offset;
-    uint32_t gpt_header_size;
-    uint8_t  *gpt_header = NULL;
-    uint32_t crc;
-    uint32_t crc_zero;
-    uint32_t blk_size = 0;
-
-    *state = GPT_OK;
-
-    crc_zero = crc32(0L, Z_NULL, 0);
-    if (ioctl(fd, BLKSSZGET, &blk_size) != 0) {
-            fprintf(stderr, "Failed to get GPT device block size: %s\n",
-                            strerror(errno));
-            goto error;
-    }
-    gpt_header = (uint8_t*)malloc(blk_size);
-    if (!gpt_header) {
-            fprintf(stderr, "gpt_get_state:Failed to alloc memory for header\n");
-            goto error;
-    }
-    if (gpt == PRIMARY_GPT)
-        gpt_header_offset = blk_size;
-    else {
-        gpt_header_offset = lseek64(fd, 0, SEEK_END) - blk_size;
-        if (gpt_header_offset < 0) {
-            fprintf(stderr, "gpt_get_state:Seek to end of GPT part fail\n");
-            goto error;
-        }
-    }
-
-    if (blk_rw(fd, 0, gpt_header_offset, gpt_header, blk_size)) {
-        fprintf(stderr, "gpt_get_state: blk_rw failed\n");
-        goto error;
-    }
-    if (memcmp(gpt_header, GPT_SIGNATURE, sizeof(GPT_SIGNATURE)))
-        *state = GPT_BAD_SIGNATURE;
-    gpt_header_size = GET_4_BYTES(gpt_header + HEADER_SIZE_OFFSET);
-
-    crc = GET_4_BYTES(gpt_header + HEADER_CRC_OFFSET);
-    /* header CRC is calculated with this field cleared */
-    PUT_4_BYTES(gpt_header + HEADER_CRC_OFFSET, 0);
-    if (crc32(crc_zero, gpt_header, gpt_header_size) != crc)
-        *state = GPT_BAD_CRC;
-    free(gpt_header);
-    return 0;
-error:
-    if (gpt_header)
-            free(gpt_header);
-    return -1;
-}
-
-
-
-/**
- *  ==========================================================================
- *
- *  \brief  Sets GPT header state (used to corrupt and fix GPT signature)
- *
- *  \param [in] fd     block dev file descriptor
- *  \param [in] gpt    GPT header to be checked
- *  \param [in] state  GPT header state to set (GPT_OK or GPT_BAD_SIGNATURE)
- *
- *  \return  0 on success
- *
- *  ==========================================================================
- */
-static int gpt_set_state(int fd, enum gpt_instance gpt, enum gpt_state state)
-{
-    int64_t gpt_header_offset;
-    uint32_t gpt_header_size;
-    uint8_t  *gpt_header = NULL;
-    uint32_t crc;
-    uint32_t crc_zero;
-    uint32_t blk_size = 0;
-
-    crc_zero = crc32(0L, Z_NULL, 0);
-    if (ioctl(fd, BLKSSZGET, &blk_size) != 0) {
-            fprintf(stderr, "Failed to get GPT device block size: %s\n",
-                            strerror(errno));
-            goto error;
-    }
-    gpt_header = (uint8_t*)malloc(blk_size);
-    if (!gpt_header) {
-            fprintf(stderr, "Failed to alloc memory for gpt header\n");
-            goto error;
-    }
-    if (gpt == PRIMARY_GPT)
-        gpt_header_offset = blk_size;
-    else {
-        gpt_header_offset = lseek64(fd, 0, SEEK_END) - blk_size;
-        if (gpt_header_offset < 0) {
-            fprintf(stderr, "Failed to seek to end of GPT device\n");
-            goto error;
-        }
-    }
-    if (blk_rw(fd, 0, gpt_header_offset, gpt_header, blk_size)) {
-        fprintf(stderr, "Failed to r/w gpt header\n");
-        goto error;
-    }
-    if (state == GPT_OK)
-        memcpy(gpt_header, GPT_SIGNATURE, sizeof(GPT_SIGNATURE));
-    else if (state == GPT_BAD_SIGNATURE)
-        *gpt_header = 0;
-    else {
-        fprintf(stderr, "gpt_set_state: Invalid state\n");
-        goto error;
-    }
-
-    gpt_header_size = GET_4_BYTES(gpt_header + HEADER_SIZE_OFFSET);
-
-    /* header CRC is calculated with this field cleared */
-    PUT_4_BYTES(gpt_header + HEADER_CRC_OFFSET, 0);
-    crc = crc32(crc_zero, gpt_header, gpt_header_size);
-    PUT_4_BYTES(gpt_header + HEADER_CRC_OFFSET, crc);
-
-    if (blk_rw(fd, 1, gpt_header_offset, gpt_header, blk_size)) {
-        fprintf(stderr, "gpt_set_state: blk write failed\n");
-        goto error;
-    }
-    return 0;
-error:
-    if(gpt_header)
-           free(gpt_header);
-    return -1;
-}
-
-int get_scsi_node_from_bootdevice(const char *bootdev_path,
-                char *sg_node_path,
-                size_t buf_size)
-{
-        char sg_dir_path[PATH_MAX] = {0};
-        char real_path[PATH_MAX] = {0};
-        DIR *scsi_dir = NULL;
-        struct dirent *de;
-        int node_found = 0;
-        if (!bootdev_path || !sg_node_path) {
-                fprintf(stderr, "%s : invalid argument\n",
-                                 __func__);
-                goto error;
-        }
-        if (readlink(bootdev_path, real_path, sizeof(real_path) - 1) < 0) {
-                        fprintf(stderr, "failed to resolve link for %s(%s)\n",
-                                        bootdev_path,
-                                        strerror(errno));
-                        goto error;
-        }
-        if(strlen(real_path) < PATH_TRUNCATE_LOC + 1){
-            fprintf(stderr, "Unrecognized path :%s:\n",
-                           real_path);
-            goto error;
-        }
-        //For the safe side in case there are additional partitions on
-        //the XBL lun we truncate the name.
-        real_path[PATH_TRUNCATE_LOC] = '\0';
-        if(strlen(real_path) < LUN_NAME_START_LOC + 1){
-            fprintf(stderr, "Unrecognized truncated path :%s:\n",
-                           real_path);
-            goto error;
-        }
-        //This will give us /dev/block/sdb/device/scsi_generic
-        //which contains a file sgY whose name gives us the path
-        //to /dev/sgY which we return
-        snprintf(sg_dir_path, sizeof(sg_dir_path) - 1,
-                        "/sys/block/%s/device/scsi_generic",
-                        &real_path[LUN_NAME_START_LOC]);
-        scsi_dir = opendir(sg_dir_path);
-        if (!scsi_dir) {
-                fprintf(stderr, "%s : Failed to open %s(%s)\n",
-                                __func__,
-                                sg_dir_path,
-                                strerror(errno));
-                goto error;
-        }
-        while((de = readdir(scsi_dir))) {
-                if (de->d_name[0] == '.')
-                        continue;
-                else if (!strncmp(de->d_name, "sg", 2)) {
-                          snprintf(sg_node_path,
-                                        buf_size -1,
-                                        "/dev/%s",
-                                        de->d_name);
-                          fprintf(stderr, "%s:scsi generic node is :%s:\n",
-                                          __func__,
-                                          sg_node_path);
-                          node_found = 1;
-                          break;
-                }
-        }
-        if(!node_found) {
-                fprintf(stderr,"%s: Unable to locate scsi generic node\n",
-                               __func__);
-                goto error;
-        }
-        closedir(scsi_dir);
-        return 0;
-error:
-        if (scsi_dir)
-                closedir(scsi_dir);
-        return -1;
-}
-
-
-
-//Swtich betwieen using either the primary or the backup
-//boot LUN for boot. This is required since UFS boot partitions
-//cannot have a backup GPT which is what we use for failsafe
-//updates of the other 'critical' partitions. This function will
-//not be invoked for emmc targets and on UFS targets is only required
-//to be invoked for XBL.
-//
-//The algorithm to do this is as follows:
-//- Find the real block device(eg: /dev/block/sdb) that corresponds
-//  to the /dev/block/bootdevice/by-name/xbl(bak) symlink
-//
-//- Once we have the block device 'node' name(sdb in the above example)
-//  use this node to to locate the scsi generic device that represents
-//  it by checking the file /sys/block/sdb/device/scsi_generic/sgY
-//
-//- Once we locate sgY we call the query ioctl on /dev/sgy to switch
-//the boot lun to either LUNA or LUNB
-int gpt_utils_set_xbl_boot_partition(enum boot_chain chain)
-{
-        struct stat st;
-        ///sys/block/sdX/device/scsi_generic/
-        char sg_dev_node[PATH_MAX] = {0};
-        uint8_t boot_lun_id = 0;
-        const char *boot_dev = NULL;
-
-        if (chain == BACKUP_BOOT) {
-                boot_lun_id = BOOT_LUN_B_ID;
-                if (!stat(XBL_BACKUP, &st))
-                        boot_dev = XBL_BACKUP;
-                else if (!stat(XBL_AB_SECONDARY, &st))
-                        boot_dev = XBL_AB_SECONDARY;
-                else {
-                        fprintf(stderr, "%s: Failed to locate secondary xbl\n",
-                                        __func__);
-                        goto error;
-                }
-        } else if (chain == NORMAL_BOOT) {
-                boot_lun_id = BOOT_LUN_A_ID;
-                if (!stat(XBL_PRIMARY, &st))
-                        boot_dev = XBL_PRIMARY;
-                else if (!stat(XBL_AB_PRIMARY, &st))
-                        boot_dev = XBL_AB_PRIMARY;
-                else {
-                        fprintf(stderr, "%s: Failed to locate primary xbl\n",
-                                        __func__);
-                        goto error;
-                }
-        } else {
-                fprintf(stderr, "%s: Invalid boot chain id\n", __func__);
-                goto error;
-        }
-        //We need either both xbl and xblbak or both xbl_a and xbl_b to exist at
-        //the same time. If not the current configuration is invalid.
-        if((stat(XBL_PRIMARY, &st) ||
-                                stat(XBL_BACKUP, &st)) &&
-                        (stat(XBL_AB_PRIMARY, &st) ||
-                         stat(XBL_AB_SECONDARY, &st))) {
-                fprintf(stderr, "%s:primary/secondary XBL prt not found(%s)\n",
-                                __func__,
-                                strerror(errno));
-                goto error;
-        }
-        fprintf(stderr, "%s: setting %s lun as boot lun\n",
-                        __func__,
-                        boot_dev);
-        if (get_scsi_node_from_bootdevice(boot_dev,
-                                sg_dev_node,
-                                sizeof(sg_dev_node))) {
-                fprintf(stderr, "%s: Failed to get scsi node path for xblbak\n",
-                                __func__);
-                goto error;
-        }
-        /* set boot lun using /dev/sg or /dev/ufs-bsg* */
-        if (set_boot_lun(sg_dev_node, boot_lun_id)) {
-                fprintf(stderr, "%s: Failed to set xblbak as boot partition\n",
-                                __func__);
-                goto error;
-        }
-        return 0;
-error:
-        return -1;
-}
-
-int gpt_utils_is_ufs_device()
-{
-    char bootdevice[PROPERTY_VALUE_MAX] = {0};
-    property_get("ro.boot.bootdevice", bootdevice, "N/A");
-    if (strlen(bootdevice) < strlen(".ufshc") + 1)
-        return 0;
-    return (!strncmp(&bootdevice[strlen(bootdevice) - strlen(".ufshc")],
-                            ".ufshc",
-                            sizeof(".ufshc")));
-}
-//dev_path is the path to the block device that contains the GPT image that
-//needs to be updated. This would be the device which holds one or more critical
-//boot partitions and their backups. In the case of EMMC this function would
-//be invoked only once on /dev/block/mmcblk1 since it holds the GPT image
-//containing all the partitions For UFS devices it could potentially be
-//invoked multiple times, once for each LUN containing critical image(s) and
-//their backups
-int prepare_partitions(enum boot_update_stage stage, const char *dev_path)
-{
-    int r = 0;
-    int fd = -1;
-    int is_ufs = gpt_utils_is_ufs_device();
-    enum gpt_state gpt_prim, gpt_second;
-    enum boot_update_stage internal_stage;
-    struct stat xbl_partition_stat;
-
-    if (!dev_path) {
-        fprintf(stderr, "%s: Invalid dev_path\n",
-                        __func__);
-        r = -1;
-        goto EXIT;
-    }
-    fd = open(dev_path, O_RDWR);
-    if (fd < 0) {
-        fprintf(stderr, "%s: Opening '%s' failed: %s\n",
-                        __func__,
-                       BLK_DEV_FILE,
-                       strerror(errno));
-        r = -1;
-        goto EXIT;
-    }
-    r = gpt_get_state(fd, PRIMARY_GPT, &gpt_prim) ||
-        gpt_get_state(fd, SECONDARY_GPT, &gpt_second);
-    if (r) {
-        fprintf(stderr, "%s: Getting GPT headers state failed\n",
-                        __func__);
-        goto EXIT;
-    }
-
-    /* These 2 combinations are unexpected and unacceptable */
-    if (gpt_prim == GPT_BAD_CRC || gpt_second == GPT_BAD_CRC) {
-        fprintf(stderr, "%s: GPT headers CRC corruption detected, aborting\n",
-                        __func__);
-        r = -1;
-        goto EXIT;
-    }
-    if (gpt_prim == GPT_BAD_SIGNATURE && gpt_second == GPT_BAD_SIGNATURE) {
-        fprintf(stderr, "%s: Both GPT headers corrupted, aborting\n",
-                        __func__);
-        r = -1;
-        goto EXIT;
-    }
-
-    /* Check internal update stage according GPT headers' state */
-    if (gpt_prim == GPT_OK && gpt_second == GPT_OK)
-        internal_stage = UPDATE_MAIN;
-    else if (gpt_prim == GPT_BAD_SIGNATURE)
-        internal_stage = UPDATE_BACKUP;
-    else if (gpt_second == GPT_BAD_SIGNATURE)
-        internal_stage = UPDATE_FINALIZE;
-    else {
-        fprintf(stderr, "%s: Abnormal GPTs state: primary (%d), secondary (%d), "
-                "aborting\n", __func__, gpt_prim, gpt_second);
-        r = -1;
-        goto EXIT;
-    }
-
-    /* Stage already set - ready for update, exitting */
-    if ((int) stage == (int) internal_stage - 1)
-        goto EXIT;
-    /* Unexpected stage given */
-    if (stage != internal_stage) {
-        r = -1;
-        goto EXIT;
-    }
-
-    switch (stage) {
-    case UPDATE_MAIN:
-            if (is_ufs) {
-                if(stat(XBL_PRIMARY, &xbl_partition_stat)||
-                                stat(XBL_BACKUP, &xbl_partition_stat)){
-                        //Non fatal error. Just means this target does not
-                        //use XBL but relies on sbl whose update is handled
-                        //by the normal methods.
-                        fprintf(stderr, "%s: xbl part not found(%s).Assuming sbl in use\n",
-                                        __func__,
-                                        strerror(errno));
-                } else {
-                        //Switch the boot lun so that backup boot LUN is used
-                        r = gpt_utils_set_xbl_boot_partition(BACKUP_BOOT);
-                        if(r){
-                                fprintf(stderr, "%s: Failed to set xbl backup partition as boot\n",
-                                                __func__);
-                                goto EXIT;
-                        }
-                }
-        }
-        //Fix up the backup GPT table so that it actually points to
-        //the backup copy of the boot critical images
-        fprintf(stderr, "%s: Preparing for primary partition update\n",
-                        __func__);
-        r = gpt2_set_boot_chain(fd, BACKUP_BOOT);
-        if (r) {
-            if (r < 0)
-                fprintf(stderr,
-                                "%s: Setting secondary GPT to backup boot failed\n",
-                                __func__);
-            /* No backup partitions - do not corrupt GPT, do not flag error */
-            else
-                r = 0;
-            goto EXIT;
-        }
-        //corrupt the primary GPT so that the backup(which now points to
-        //the backup boot partitions is used)
-        r = gpt_set_state(fd, PRIMARY_GPT, GPT_BAD_SIGNATURE);
-        if (r) {
-            fprintf(stderr, "%s: Corrupting primary GPT header failed\n",
-                            __func__);
-            goto EXIT;
-        }
-        break;
-    case UPDATE_BACKUP:
-        if (is_ufs) {
-                if(stat(XBL_PRIMARY, &xbl_partition_stat)||
-                                stat(XBL_BACKUP, &xbl_partition_stat)){
-                        //Non fatal error. Just means this target does not
-                        //use XBL but relies on sbl whose update is handled
-                        //by the normal methods.
-                        fprintf(stderr, "%s: xbl part not found(%s).Assuming sbl in use\n",
-                                        __func__,
-                                        strerror(errno));
-                } else {
-                        //Switch the boot lun so that backup boot LUN is used
-                        r = gpt_utils_set_xbl_boot_partition(NORMAL_BOOT);
-                        if(r) {
-                                fprintf(stderr, "%s: Failed to set xbl backup partition as boot\n",
-                                                __func__);
-                                goto EXIT;
-                        }
-                }
-        }
-        //Fix the primary GPT header so that is used
-        fprintf(stderr, "%s: Preparing for backup partition update\n",
-                        __func__);
-        r = gpt_set_state(fd, PRIMARY_GPT, GPT_OK);
-        if (r) {
-            fprintf(stderr, "%s: Fixing primary GPT header failed\n",
-                             __func__);
-            goto EXIT;
-        }
-        //Corrupt the scondary GPT header
-        r = gpt_set_state(fd, SECONDARY_GPT, GPT_BAD_SIGNATURE);
-        if (r) {
-            fprintf(stderr, "%s: Corrupting secondary GPT header failed\n",
-                            __func__);
-            goto EXIT;
-        }
-        break;
-    case UPDATE_FINALIZE:
-        //Undo the changes we had made in the UPDATE_MAIN stage so that the
-        //primary/backup GPT headers once again point to the same set of
-        //partitions
-        fprintf(stderr, "%s: Finalizing partitions\n",
-                        __func__);
-        r = gpt2_set_boot_chain(fd, NORMAL_BOOT);
-        if (r < 0) {
-            fprintf(stderr, "%s: Setting secondary GPT to normal boot failed\n",
-                            __func__);
-            goto EXIT;
-        }
-
-        r = gpt_set_state(fd, SECONDARY_GPT, GPT_OK);
-        if (r) {
-            fprintf(stderr, "%s: Fixing secondary GPT header failed\n",
-                            __func__);
-            goto EXIT;
-        }
-        break;
-    default:;
-    }
-
-EXIT:
-    if (fd >= 0) {
-       fsync(fd);
-       close(fd);
-    }
-    return r;
-}
-
-int add_lun_to_update_list(char *lun_path, struct update_data *dat)
-{
-        uint32_t i = 0;
-        struct stat st;
-        if (!lun_path || !dat){
-                fprintf(stderr, "%s: Invalid data",
-                                __func__);
-                return -1;
-        }
-        if (stat(lun_path, &st)) {
-                fprintf(stderr, "%s: Unable to access %s. Skipping adding to list",
-                                __func__,
-                                lun_path);
-                return -1;
-        }
-        if (dat->num_valid_entries == 0) {
-                fprintf(stderr, "%s: Copying %s into lun_list[%d]\n",
-                                __func__,
-                                lun_path,
-                                i);
-                strlcpy(dat->lun_list[0], lun_path,
-                                PATH_MAX * sizeof(char));
-                dat->num_valid_entries = 1;
-        } else {
-                for (i = 0; (i < dat->num_valid_entries) &&
-                                (dat->num_valid_entries < MAX_LUNS - 1); i++) {
-                        //Check if the current LUN is not already part
-                        //of the lun list
-                        if (!strncmp(lun_path,dat->lun_list[i],
-                                                strlen(dat->lun_list[i]))) {
-                                //LUN already in list..Return
-                                return 0;
-                        }
-                }
-                fprintf(stderr, "%s: Copying %s into lun_list[%d]\n",
-                                __func__,
-                                lun_path,
-                                dat->num_valid_entries);
-                //Add LUN path lun list
-                strlcpy(dat->lun_list[dat->num_valid_entries], lun_path,
-                                PATH_MAX * sizeof(char));
-                dat->num_valid_entries++;
-        }
-        return 0;
-}
-
-int prepare_boot_update(enum boot_update_stage stage)
-{
-        int is_ufs = gpt_utils_is_ufs_device();
-        struct stat ufs_dir_stat;
-        struct update_data data;
-        int rcode = 0;
-        uint32_t i = 0;
-        int is_error = 0;
-        const char ptn_swap_list[][MAX_GPT_NAME_SIZE] = { PTN_SWAP_LIST };
-        //Holds /dev/block/bootdevice/by-name/*bak entry
-        char buf[PATH_MAX] = {0};
-        //Holds the resolved path of the symlink stored in buf
-        char real_path[PATH_MAX] = {0};
-
-        if (!is_ufs) {
-                //emmc device. Just pass in path to mmcblk0
-                return prepare_partitions(stage, BLK_DEV_FILE);
-        } else {
-                //Now we need to find the list of LUNs over
-                //which the boot critical images are spread
-                //and set them up for failsafe updates.To do
-                //this we find out where the symlinks for the
-                //each of the paths under
-                ///dev/block/bootdevice/by-name/PTN_SWAP_LIST
-                //actually point to.
-                fprintf(stderr, "%s: Running on a UFS device\n",
-                                __func__);
-                memset(&data, '\0', sizeof(struct update_data));
-                for (i=0; i < ARRAY_SIZE(ptn_swap_list); i++) {
-                        //XBL on UFS does not follow the convention
-                        //of being loaded based on well known GUID'S.
-                        //We take care of switching the UFS boot LUN
-                        //explicitly later on.
-                        if (!strncmp(ptn_swap_list[i],PTN_XBL,strlen(PTN_XBL))
-                            || !strncmp(ptn_swap_list[i],PTN_MULTIIMGOEM,strlen(PTN_MULTIIMGOEM))
-                            || !strncmp(ptn_swap_list[i],PTN_MULTIIMGQTI,strlen(PTN_MULTIIMGQTI)))
-                                continue;
-                        snprintf(buf, sizeof(buf),
-                                        "%s/%sbak",
-                                        BOOT_DEV_DIR,
-                                        ptn_swap_list[i]);
-                        if (stat(buf, &ufs_dir_stat)) {
-                                continue;
-                        }
-                        if (readlink(buf, real_path, sizeof(real_path) - 1) < 0)
-                        {
-                                fprintf(stderr, "%s: readlink error. Skipping %s",
-                                                __func__,
-                                                strerror(errno));
-                        } else {
-                              if(strlen(real_path) < PATH_TRUNCATE_LOC + 1){
-                                    fprintf(stderr, "Unknown path.Skipping :%s:\n",
-                                                real_path);
-                                } else {
-                                    real_path[PATH_TRUNCATE_LOC] = '\0';
-                                    add_lun_to_update_list(real_path, &data);
-                                }
-                        }
-                        memset(buf, '\0', sizeof(buf));
-                        memset(real_path, '\0', sizeof(real_path));
-                }
-                for (i=0; i < data.num_valid_entries; i++) {
-                        fprintf(stderr, "%s: Preparing %s for update stage %d\n",
-                                        __func__,
-                                        data.lun_list[i],
-                                        stage);
-                        rcode = prepare_partitions(stage, data.lun_list[i]);
-                        if (rcode != 0)
-                        {
-                                fprintf(stderr, "%s: Failed to prepare %s.Continuing..\n",
-                                                __func__,
-                                                data.lun_list[i]);
-                                is_error = 1;
-                        }
-                }
-        }
-        if (is_error)
-                return -1;
-        return 0;
-}
-
-//Given a parttion name(eg: rpm) get the path to the block device that
-//represents the GPT disk the partition resides on. In the case of emmc it
-//would be the default emmc dev(/dev/block/mmcblk0). In the case of UFS we look
-//through the /dev/block/bootdevice/by-name/ tree for partname, and resolve
-//the path to the LUN from there.
-static int get_dev_path_from_partition_name(const char *partname,
-                char *buf,
-                size_t buflen)
-{
-        struct stat st;
-        char path[PATH_MAX] = {0};
-        if (!partname || !buf || buflen < ((PATH_TRUNCATE_LOC) + 1)) {
-                ALOGE("%s: Invalid argument", __func__);
-                goto error;
-        }
-        if (gpt_utils_is_ufs_device()) {
-                //Need to find the lun that holds partition partname
-                snprintf(path, sizeof(path),
-                                "%s/%s",
-                                BOOT_DEV_DIR,
-                                partname);
-                if (stat(path, &st)) {
-                        goto error;
-                }
-                if (readlink(path, buf, buflen) < 0)
-                {
-                        goto error;
-                } else {
-                        buf[PATH_TRUNCATE_LOC] = '\0';
-                }
-        } else {
-                snprintf(buf, buflen, BLK_DEV_FILE);
-        }
-        return 0;
-
-error:
-        return -1;
-}
-
-int gpt_utils_get_partition_map(vector<string>& ptn_list,
-                map<string, vector<string>>& partition_map) {
-        char devpath[PATH_MAX] = {'\0'};
-        map<string, vector<string>>::iterator it;
-        if (ptn_list.size() < 1) {
-                fprintf(stderr, "%s: Invalid ptn list\n", __func__);
-                goto error;
-        }
-        //Go through the passed in list
-        for (uint32_t i = 0; i < ptn_list.size(); i++)
-        {
-                //Key in the map is the path to the device that holds the
-                //partition
-                if (get_dev_path_from_partition_name(ptn_list[i].c_str(),
-                                devpath,
-                                sizeof(devpath))) {
-                        //Not necessarily an error. The partition may just
-                        //not be present.
-                        continue;
-                }
-                string path = devpath;
-                it = partition_map.find(path);
-                if (it != partition_map.end()) {
-                        it->second.push_back(ptn_list[i]);
-                } else {
-                        vector<string> str_vec;
-                        str_vec.push_back( ptn_list[i]);
-                        partition_map.insert(pair<string, vector<string>>
-                                        (path, str_vec));
-                }
-                memset(devpath, '\0', sizeof(devpath));
-        }
-        return 0;
-error:
-        return -1;
-}
-
-//Get the block size of the disk represented by decsriptor fd
-static uint32_t gpt_get_block_size(int fd)
-{
-        uint32_t block_size = 0;
-        if (fd < 0) {
-                ALOGE("%s: invalid descriptor",
-                                __func__);
-                goto error;
-        }
-        if (ioctl(fd, BLKSSZGET, &block_size) != 0) {
-                ALOGE("%s: Failed to get GPT dev block size : %s",
-                                __func__,
-                                strerror(errno));
-                goto error;
-        }
-        return block_size;
-error:
-        return 0;
-}
-
-//Write the GPT header present in the passed in buffer back to the
-//disk represented by fd
-static int gpt_set_header(uint8_t *gpt_header, int fd,
-                enum gpt_instance instance)
-{
-        uint32_t block_size = 0;
-        off64_t gpt_header_offset = 0;
-        if (!gpt_header || fd < 0) {
-                ALOGE("%s: Invalid arguments",
-                                __func__);
-                goto error;
-        }
-        block_size = gpt_get_block_size(fd);
-        if (block_size == 0) {
-                ALOGE("%s: Failed to get block size", __func__);
-                goto error;
-        }
-        if (instance == PRIMARY_GPT)
-                gpt_header_offset = block_size;
-        else
-                gpt_header_offset = lseek64(fd, 0, SEEK_END) - block_size;
-        if (gpt_header_offset <= 0) {
-                ALOGE("%s: Failed to get gpt header offset",__func__);
-                goto error;
-        }
-        if (blk_rw(fd, 1, gpt_header_offset, gpt_header, block_size)) {
-                ALOGE("%s: Failed to write back GPT header", __func__);
-                goto error;
-        }
-        return 0;
-error:
-        return -1;
-}
-
-//Read out the GPT header for the disk that contains the partition partname
-static uint8_t* gpt_get_header(const char *partname, enum gpt_instance instance)
-{
-        uint8_t* hdr = NULL;
-        char devpath[PATH_MAX] = {0};
-        int64_t hdr_offset = 0;
-        uint32_t block_size = 0;
-        int fd = -1;
-        if (!partname) {
-                ALOGE("%s: Invalid partition name", __func__);
-                goto error;
-        }
-        if (get_dev_path_from_partition_name(partname, devpath, sizeof(devpath))
-                        != 0) {
-                ALOGE("%s: Failed to resolve path for %s",
-                                __func__,
-                                partname);
-                goto error;
-        }
-        fd = open(devpath, O_RDWR);
-        if (fd < 0) {
-                ALOGE("%s: Failed to open %s : %s",
-                                __func__,
-                                devpath,
-                                strerror(errno));
-                goto error;
-        }
-        block_size = gpt_get_block_size(fd);
-        if (block_size == 0)
-        {
-                ALOGE("%s: Failed to get gpt block size for %s",
-                                __func__,
-                                partname);
-                goto error;
-        }
-
-        hdr = (uint8_t*)malloc(block_size);
-        if (!hdr) {
-                ALOGE("%s: Failed to allocate memory for gpt header",
-                                __func__);
-        }
-        if (instance == PRIMARY_GPT)
-                hdr_offset = block_size;
-        else {
-                hdr_offset = lseek64(fd, 0, SEEK_END) - block_size;
-        }
-        if (hdr_offset < 0) {
-                ALOGE("%s: Failed to get gpt header offset",
-                                __func__);
-                goto error;
-        }
-        if (blk_rw(fd, 0, hdr_offset, hdr, block_size)) {
-                ALOGE("%s: Failed to read GPT header from device",
-                                __func__);
-                goto error;
-        }
-        close(fd);
-        return hdr;
-error:
-        if (fd >= 0)
-                close(fd);
-        if (hdr)
-                free(hdr);
-        return NULL;
-}
-
-//Returns the partition entry array based on the
-//passed in buffer which contains the gpt header.
-//The fd here is the descriptor for the 'disk' which
-//holds the partition
-static uint8_t* gpt_get_pentry_arr(uint8_t *hdr, int fd)
-{
-        uint64_t pentries_start = 0;
-        uint32_t pentry_size = 0;
-        uint32_t block_size = 0;
-        uint32_t pentries_arr_size = 0;
-        uint8_t *pentry_arr = NULL;
-        int rc = 0;
-        if (!hdr) {
-                ALOGE("%s: Invalid header", __func__);
-                goto error;
-        }
-        if (fd < 0) {
-                ALOGE("%s: Invalid fd", __func__);
-                goto error;
-        }
-        block_size = gpt_get_block_size(fd);
-        if (!block_size) {
-                ALOGE("%s: Failed to get gpt block size for",
-                                __func__);
-                goto error;
-        }
-        pentries_start = GET_8_BYTES(hdr + PENTRIES_OFFSET) * block_size;
-        pentry_size = GET_4_BYTES(hdr + PENTRY_SIZE_OFFSET);
-        pentries_arr_size =
-                GET_4_BYTES(hdr + PARTITION_COUNT_OFFSET) * pentry_size;
-        pentry_arr = (uint8_t*)calloc(1, pentries_arr_size);
-        if (!pentry_arr) {
-                ALOGE("%s: Failed to allocate memory for partition array",
-                                __func__);
-                goto error;
-        }
-        rc = blk_rw(fd, 0,
-                        pentries_start,
-                        pentry_arr,
-                        pentries_arr_size);
-        if (rc) {
-                ALOGE("%s: Failed to read partition entry array",
-                                __func__);
-                goto error;
-        }
-        return pentry_arr;
-error:
-        if (pentry_arr)
-                free(pentry_arr);
-        return NULL;
-}
-
-static int gpt_set_pentry_arr(uint8_t *hdr, int fd, uint8_t* arr)
-{
-        uint32_t block_size = 0;
-        uint64_t pentries_start = 0;
-        uint32_t pentry_size = 0;
-        uint32_t pentries_arr_size = 0;
-        int rc = 0;
-        if (!hdr || fd < 0 || !arr) {
-                ALOGE("%s: Invalid argument", __func__);
-                goto error;
-        }
-        block_size = gpt_get_block_size(fd);
-        if (!block_size) {
-                ALOGE("%s: Failed to get gpt block size for",
-                                __func__);
-                goto error;
-        }
-        pentries_start = GET_8_BYTES(hdr + PENTRIES_OFFSET) * block_size;
-        pentry_size = GET_4_BYTES(hdr + PENTRY_SIZE_OFFSET);
-        pentries_arr_size =
-                GET_4_BYTES(hdr + PARTITION_COUNT_OFFSET) * pentry_size;
-        rc = blk_rw(fd, 1,
-                        pentries_start,
-                        arr,
-                        pentries_arr_size);
-        if (rc) {
-                ALOGE("%s: Failed to read partition entry array",
-                                __func__);
-                goto error;
-        }
-        return 0;
-error:
-        return -1;
-}
-
-
-
-//Allocate a handle used by calls to the "gpt_disk" api's
-struct gpt_disk * gpt_disk_alloc()
-{
-        struct gpt_disk *disk;
-        disk = (struct gpt_disk *)malloc(sizeof(struct gpt_disk));
-        if (!disk) {
-                ALOGE("%s: Failed to allocate memory", __func__);
-                goto end;
-        }
-        memset(disk, 0, sizeof(struct gpt_disk));
-end:
-        return disk;
-}
-
-//Free previously allocated/initialized handle
-void gpt_disk_free(struct gpt_disk *disk)
-{
-        if (!disk)
-                return;
-        if (disk->hdr)
-                free(disk->hdr);
-        if (disk->hdr_bak)
-                free(disk->hdr_bak);
-        if (disk->pentry_arr)
-                free(disk->pentry_arr);
-        if (disk->pentry_arr_bak)
-                free(disk->pentry_arr_bak);
-        free(disk);
-        return;
-}
-
-//fills up the passed in gpt_disk struct with information about the
-//disk represented by path dev. Returns 0 on success and -1 on error.
-int gpt_disk_get_disk_info(const char *dev, struct gpt_disk *dsk)
-{
-
-	struct gpt_disk *disk = NULL;
-	int fd = -1;
-	uint32_t gpt_header_size = 0;
-	uint32_t crc_zero;
-
-	crc_zero = crc32(0L, Z_NULL, 0);
-        if (!dsk || !dev) {
-                ALOGE("%s: Invalid arguments", __func__);
-                goto error;
-        }
-        disk = dsk;
-        disk->hdr = gpt_get_header(dev, PRIMARY_GPT);
-        if (!disk->hdr) {
-                ALOGE("%s: Failed to get primary header", __func__);
-                goto error;
-        }
-        gpt_header_size = GET_4_BYTES(disk->hdr + HEADER_SIZE_OFFSET);
-        disk->hdr_crc = crc32(crc_zero, disk->hdr, gpt_header_size);
-        disk->hdr_bak = gpt_get_header(dev, SECONDARY_GPT);
-        if (!disk->hdr_bak) {
-                ALOGE("%s: Failed to get backup header", __func__);
-                goto error;
-        }
-        disk->hdr_bak_crc = crc32(crc_zero, disk->hdr_bak, gpt_header_size);
-
-        //Descriptor for the block device. We will use this for further
-        //modifications to the partition table
-        if (get_dev_path_from_partition_name(dev,
-                                disk->devpath,
-                                sizeof(disk->devpath)) != 0) {
-                ALOGE("%s: Failed to resolve path for %s",
-                                __func__,
-                                dev);
-                goto error;
-        }
-        fd = open(disk->devpath, O_RDWR);
-        if (fd < 0) {
-                ALOGE("%s: Failed to open %s: %s",
-                                __func__,
-                                disk->devpath,
-                                strerror(errno));
-                goto error;
-        }
-        disk->pentry_arr = gpt_get_pentry_arr(disk->hdr, fd);
-        if (!disk->pentry_arr) {
-                ALOGE("%s: Failed to obtain partition entry array",
-                                __func__);
-                goto error;
-        }
-        disk->pentry_arr_bak = gpt_get_pentry_arr(disk->hdr_bak, fd);
-        if (!disk->pentry_arr_bak) {
-                ALOGE("%s: Failed to obtain backup partition entry array",
-                                __func__);
-                goto error;
-        }
-        disk->pentry_size = GET_4_BYTES(disk->hdr + PENTRY_SIZE_OFFSET);
-        disk->pentry_arr_size =
-                GET_4_BYTES(disk->hdr + PARTITION_COUNT_OFFSET) *
-                disk->pentry_size;
-        disk->pentry_arr_crc = GET_4_BYTES(disk->hdr + PARTITION_CRC_OFFSET);
-        disk->pentry_arr_bak_crc = GET_4_BYTES(disk->hdr_bak +
-                        PARTITION_CRC_OFFSET);
-        disk->block_size = gpt_get_block_size(fd);
-        close(fd);
-        disk->is_initialized = GPT_DISK_INIT_MAGIC;
-        return 0;
-error:
-        if (fd >= 0)
-                close(fd);
-        return -1;
-}
-
-//Get pointer to partition entry from a allocated gpt_disk structure
-uint8_t* gpt_disk_get_pentry(struct gpt_disk *disk,
-                const char *partname,
-                enum gpt_instance instance)
-{
-        uint8_t *ptn_arr = NULL;
-        if (!disk || !partname || disk->is_initialized != GPT_DISK_INIT_MAGIC) {
-                ALOGE("%s: Invalid argument",__func__);
-                goto error;
-        }
-        ptn_arr = (instance == PRIMARY_GPT) ?
-                disk->pentry_arr : disk->pentry_arr_bak;
-        return (gpt_pentry_seek(partname, ptn_arr,
-                        ptn_arr + disk->pentry_arr_size ,
-                        disk->pentry_size));
-error:
-        return NULL;
-}
-
-//Update CRC values for the various components of the gpt_disk
-//structure. This function should be called after any of the fields
-//have been updated before the structure contents are written back to
-//disk.
-int gpt_disk_update_crc(struct gpt_disk *disk)
-{
-        uint32_t gpt_header_size = 0;
-        uint32_t crc_zero;
-        crc_zero = crc32(0L, Z_NULL, 0);
-        if (!disk || (disk->is_initialized != GPT_DISK_INIT_MAGIC)) {
-                ALOGE("%s: invalid argument", __func__);
-                goto error;
-        }
-        //Recalculate the CRC of the primary partiton array
-        disk->pentry_arr_crc = crc32(crc_zero,
-                        disk->pentry_arr,
-                        disk->pentry_arr_size);
-        //Recalculate the CRC of the backup partition array
-        disk->pentry_arr_bak_crc = crc32(crc_zero,
-                        disk->pentry_arr_bak,
-                        disk->pentry_arr_size);
-        //Update the partition CRC value in the primary GPT header
-        PUT_4_BYTES(disk->hdr + PARTITION_CRC_OFFSET, disk->pentry_arr_crc);
-        //Update the partition CRC value in the backup GPT header
-        PUT_4_BYTES(disk->hdr_bak + PARTITION_CRC_OFFSET,
-                        disk->pentry_arr_bak_crc);
-        //Update the CRC value of the primary header
-        gpt_header_size = GET_4_BYTES(disk->hdr + HEADER_SIZE_OFFSET);
-        //Header CRC is calculated with its own CRC field set to 0
-        PUT_4_BYTES(disk->hdr + HEADER_CRC_OFFSET, 0);
-        PUT_4_BYTES(disk->hdr_bak + HEADER_CRC_OFFSET, 0);
-        disk->hdr_crc = crc32(crc_zero, disk->hdr, gpt_header_size);
-        disk->hdr_bak_crc = crc32(crc_zero, disk->hdr_bak, gpt_header_size);
-        PUT_4_BYTES(disk->hdr + HEADER_CRC_OFFSET, disk->hdr_crc);
-        PUT_4_BYTES(disk->hdr_bak + HEADER_CRC_OFFSET, disk->hdr_bak_crc);
-        return 0;
-error:
-        return -1;
-}
-
-//Write the contents of struct gpt_disk back to the actual disk
-int gpt_disk_commit(struct gpt_disk *disk)
-{
-        int fd = -1;
-        if (!disk || (disk->is_initialized != GPT_DISK_INIT_MAGIC)){
-                ALOGE("%s: Invalid args", __func__);
-                goto error;
-        }
-        fd = open(disk->devpath, O_RDWR | O_DSYNC);
-        if (fd < 0) {
-                ALOGE("%s: Failed to open %s: %s",
-                                __func__,
-                                disk->devpath,
-                                strerror(errno));
-                goto error;
-        }
-        //Write the primary header
-        if(gpt_set_header(disk->hdr, fd, PRIMARY_GPT) != 0) {
-                ALOGE("%s: Failed to update primary GPT header",
-                                __func__);
-                goto error;
-        }
-        //Write back the primary partition array
-        if (gpt_set_pentry_arr(disk->hdr, fd, disk->pentry_arr)) {
-                ALOGE("%s: Failed to write primary GPT partition arr",
-                                __func__);
-                goto error;
-        }
-        //Write back the secondary header
-        if(gpt_set_header(disk->hdr_bak, fd, SECONDARY_GPT) != 0) {
-                ALOGE("%s: Failed to update secondary GPT header",
-                                __func__);
-                goto error;
-        }
-        //Write back the secondary partition array
-        if (gpt_set_pentry_arr(disk->hdr_bak, fd, disk->pentry_arr_bak)) {
-                ALOGE("%s: Failed to write secondary GPT partition arr",
-                                __func__);
-                goto error;
-        }
-        fsync(fd);
-        close(fd);
-        return 0;
-error:
-        if (fd >= 0)
-                close(fd);
-        return -1;
-}

+ 0 - 195
gpt-utils/gpt-utils.h

@@ -1,195 +0,0 @@
-/*
- * Copyright (c) 2013,2016,2020 The Linux Foundation. All rights reserved.
- *
- * Redistribution and use in source and binary forms, with or without
- * modification, are permitted provided that the following conditions are
- * met:
- *     * Redistributions of source code must retain the above copyright
- *       notice, this list of conditions and the following disclaimer.
- *     * 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.
- *     * Neither the name of The Linux Foundation 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 "AS IS" AND ANY EXPRESS OR IMPLIED
- * WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF
- * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NON-INFRINGEMENT
- * ARE DISCLAIMED.  IN NO EVENT SHALL THE COPYRIGHT OWNER 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 __GPT_UTILS_H__
-#define __GPT_UTILS_H__
-#include <vector>
-#include <string>
-#include <map>
-#ifdef __cplusplus
-extern "C" {
-#endif
-#include <unistd.h>
-#include <stdlib.h>
-/******************************************************************************
- * GPT HEADER DEFINES
- ******************************************************************************/
-#define GPT_SIGNATURE               "EFI PART"
-#define HEADER_SIZE_OFFSET          12
-#define HEADER_CRC_OFFSET           16
-#define PRIMARY_HEADER_OFFSET       24
-#define BACKUP_HEADER_OFFSET        32
-#define FIRST_USABLE_LBA_OFFSET     40
-#define LAST_USABLE_LBA_OFFSET      48
-#define PENTRIES_OFFSET             72
-#define PARTITION_COUNT_OFFSET      80
-#define PENTRY_SIZE_OFFSET          84
-#define PARTITION_CRC_OFFSET        88
-
-#define TYPE_GUID_OFFSET            0
-#define TYPE_GUID_SIZE              16
-#define PTN_ENTRY_SIZE              128
-#define UNIQUE_GUID_OFFSET          16
-#define FIRST_LBA_OFFSET            32
-#define LAST_LBA_OFFSET             40
-#define ATTRIBUTE_FLAG_OFFSET       48
-#define PARTITION_NAME_OFFSET       56
-#define MAX_GPT_NAME_SIZE           72
-
-/******************************************************************************
- * AB RELATED DEFINES
- ******************************************************************************/
-//Bit 48 onwords in the attribute field are the ones where we are allowed to
-//store our AB attributes.
-#define AB_FLAG_OFFSET (ATTRIBUTE_FLAG_OFFSET + 6)
-#define GPT_DISK_INIT_MAGIC 0xABCD
-#define AB_PARTITION_ATTR_SLOT_ACTIVE (0x1<<2)
-#define AB_PARTITION_ATTR_BOOT_SUCCESSFUL (0x1<<6)
-#define AB_PARTITION_ATTR_UNBOOTABLE (0x1<<7)
-#define AB_SLOT_ACTIVE_VAL              0x3F
-#define AB_SLOT_INACTIVE_VAL            0x0
-#define AB_SLOT_ACTIVE                  1
-#define AB_SLOT_INACTIVE                0
-#define AB_SLOT_A_SUFFIX                "_a"
-#define AB_SLOT_B_SUFFIX                "_b"
-#define PTN_XBL                         "xbl"
-#define PTN_XBL_CFG                     "xbl_config"
-#define PTN_MULTIIMGOEM                 "multiimgoem"
-#define PTN_MULTIIMGQTI                 "multiimgqti"
-#define PTN_SWAP_LIST                   PTN_XBL, PTN_XBL_CFG, PTN_MULTIIMGOEM, PTN_MULTIIMGQTI, "sbl1", "rpm", "tz", "aboot", "abl", "hyp", "lksecapp", "keymaster", "cmnlib", "cmnlib32", "cmnlib64", "pmic", "apdp", "devcfg", "hosd", "keystore", "msadp", "mdtp", "mdtpsecapp", "dsp", "aop", "qupfw", "vbmeta", "dtbo", "imagefv", "ImageFv", "vm-bootsys", "shrm", "cpucp", "uefi", "aop_config", "uefisecapp", "featenabler", "vendor_boot", "recovery", "qweslicstore", "xbl_ramdump", "vbmeta_system"
-#define AB_PTN_LIST PTN_SWAP_LIST, "boot", "product", "system", "system_ext", "vendor", "vendor_dlkm", "odm", "modem", "bluetooth"
-#define BOOT_DEV_DIR    "/dev/block/bootdevice/by-name"
-
-/******************************************************************************
- * HELPER MACROS
- ******************************************************************************/
-#define ARRAY_SIZE(x) (sizeof(x) / sizeof((x)[0]))
-/******************************************************************************
- * TYPES
- ******************************************************************************/
-enum boot_update_stage {
-	UPDATE_MAIN = 1,
-	UPDATE_BACKUP,
-	UPDATE_FINALIZE
-};
-
-enum gpt_instance {
-	PRIMARY_GPT = 0,
-	SECONDARY_GPT
-};
-
-enum boot_chain {
-	NORMAL_BOOT = 0,
-	BACKUP_BOOT
-};
-
-struct gpt_disk {
-	//GPT primary header
-	uint8_t *hdr;
-	//primary header crc
-	uint32_t hdr_crc;
-	//GPT backup header
-	uint8_t *hdr_bak;
-	//backup header crc
-	uint32_t hdr_bak_crc;
-	//Partition entries array
-	uint8_t *pentry_arr;
-	//Partition entries array for backup table
-	uint8_t *pentry_arr_bak;
-	//Size of the pentry array
-	uint32_t pentry_arr_size;
-	//Size of each element in the pentry array
-	uint32_t pentry_size;
-	//CRC of the partition entry array
-	uint32_t pentry_arr_crc;
-	//CRC of the backup partition entry array
-	uint32_t pentry_arr_bak_crc;
-	//Path to block dev representing the disk
-	char devpath[PATH_MAX];
-	//Block size of disk
-	uint32_t block_size;
-	uint32_t is_initialized;
-};
-
-/******************************************************************************
- * FUNCTION PROTOTYPES
- ******************************************************************************/
-int prepare_boot_update(enum boot_update_stage stage);
-//GPT disk methods
-struct gpt_disk* gpt_disk_alloc();
-//Free previously allocated gpt_disk struct
-void gpt_disk_free(struct gpt_disk *disk);
-//Get the details of the disk holding the partition whose name
-//is passed in via dev
-int gpt_disk_get_disk_info(const char *dev, struct gpt_disk *disk);
-
-//Get pointer to partition entry from a allocated gpt_disk structure
-uint8_t* gpt_disk_get_pentry(struct gpt_disk *disk,
-		const char *partname,
-		enum gpt_instance instance);
-
-//Update the crc fields of the modified disk structure
-int gpt_disk_update_crc(struct gpt_disk *disk);
-
-//Write the contents of struct gpt_disk back to the actual disk
-int gpt_disk_commit(struct gpt_disk *disk);
-
-//Return if the current device is UFS based or not
-int gpt_utils_is_ufs_device();
-
-//Swtich betwieen using either the primary or the backup
-//boot LUN for boot. This is required since UFS boot partitions
-//cannot have a backup GPT which is what we use for failsafe
-//updates of the other 'critical' partitions. This function will
-//not be invoked for emmc targets and on UFS targets is only required
-//to be invoked for XBL.
-//
-//The algorithm to do this is as follows:
-//- Find the real block device(eg: /dev/block/sdb) that corresponds
-//  to the /dev/block/bootdevice/by-name/xbl(bak) symlink
-//
-//- Once we have the block device 'node' name(sdb in the above example)
-//  use this node to to locate the scsi generic device that represents
-//  it by checking the file /sys/block/sdb/device/scsi_generic/sgY
-//
-//- Once we locate sgY we call the query ioctl on /dev/sgy to switch
-//the boot lun to either LUNA or LUNB
-int gpt_utils_set_xbl_boot_partition(enum boot_chain chain);
-
-//Given a vector of partition names as a input and a reference to a map,
-//populate the map to indicate which physical disk each of the partitions
-//sits on. The key in the map is the path to the block device where the
-//partiton lies and the value is a vector of strings indicating which of
-//the passed in partiton names sits on that device.
-int gpt_utils_get_partition_map(std::vector<std::string>& partition_list,
-                std::map<std::string,std::vector<std::string>>& partition_map);
-#ifdef __cplusplus
-}
-#endif
-#endif /* __GPT_UTILS_H__ */

+ 0 - 255
gpt-utils/recovery-ufs-bsg.cpp

@@ -1,255 +0,0 @@
-/*
- * Copyright (c) 2020 The Linux Foundation. All rights reserved.
- *
- * Redistribution and use in source and binary forms, with or without
- * modification, are permitted provided that the following conditions are
- * met:
- *     * Redistributions of source code must retain the above copyright
- *       notice, this list of conditions and the following disclaimer.
- *     * 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.
- *     * Neither the name of The Linux Foundation 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 "AS IS" AND ANY EXPRESS OR IMPLIED
- * WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF
- * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NON-INFRINGEMENT
- * ARE DISCLAIMED.  IN NO EVENT SHALL THE COPYRIGHT OWNER 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.
- */
-
-
-#define LOG_TAG "recovery_ufs"
-
-#include "recovery-ufs-bsg.h"
-
-#ifndef _BSG_FRAMEWORK_KERNEL_HEADERS
-#ifndef _GENERIC_KERNEL_HEADERS
-#include <scsi/ufs/ioctl.h>
-#include <scsi/ufs/ufs.h>
-#endif
-#endif
-
-//Size of the buffer that needs to be passed to the UFS ioctl
-#define UFS_ATTR_DATA_SIZE          32
-
-#ifdef _BSG_FRAMEWORK_KERNEL_HEADERS
-static int get_ufs_bsg_dev(void)
-{
-    DIR *dir;
-    struct dirent *ent;
-    int ret = -ENODEV;
-
-    if ((dir = opendir ("/dev")) != NULL) {
-        /* read all the files and directories within directory */
-        while ((ent = readdir(dir)) != NULL) {
-            if (!strcmp(ent->d_name, "ufs-bsg") ||
-                    !strcmp(ent->d_name, "ufs-bsg0")) {
-                snprintf(ufs_bsg_dev, FNAME_SZ, "/dev/%s", ent->d_name);
-                ret = 0;
-                break;
-            }
-        }
-        if (ret)
-            ALOGE("could not find the ufs-bsg dev\n");
-        closedir (dir);
-    } else {
-        /* could not open directory */
-        ALOGE("could not open /dev (error no: %d)\n", errno);
-        ret = -EINVAL;
-    }
-
-    return ret;
-}
-
-int ufs_bsg_dev_open(void)
-{
-    int ret;
-    if (!fd_ufs_bsg) {
-        fd_ufs_bsg = open(ufs_bsg_dev, O_RDWR);
-        ret = errno;
-        if (fd_ufs_bsg < 0) {
-            ALOGE("Unable to open %s (error no: %d)",
-                    ufs_bsg_dev, errno);
-            fd_ufs_bsg = 0;
-            return ret;
-        }
-    }
-    return 0;
-}
-
-void ufs_bsg_dev_close(void)
-{
-    if (fd_ufs_bsg) {
-        close(fd_ufs_bsg);
-        fd_ufs_bsg = 0;
-    }
-}
-
-static int ufs_bsg_ioctl(int fd, struct ufs_bsg_request *req,
-        struct ufs_bsg_reply *rsp, __u8 *buf, __u32 buf_len,
-        enum bsg_ioctl_dir dir)
-{
-    int ret;
-    struct sg_io_v4 sg_io{};
-
-    sg_io.guard = 'Q';
-    sg_io.protocol = BSG_PROTOCOL_SCSI;
-    sg_io.subprotocol = BSG_SUB_PROTOCOL_SCSI_TRANSPORT;
-    sg_io.request_len = sizeof(*req);
-    sg_io.request = (__u64)req;
-    sg_io.response = (__u64)rsp;
-    sg_io.max_response_len = sizeof(*rsp);
-    if (dir == BSG_IOCTL_DIR_FROM_DEV) {
-        sg_io.din_xfer_len = buf_len;
-        sg_io.din_xferp = (__u64)(buf);
-    } else {
-        sg_io.dout_xfer_len = buf_len;
-        sg_io.dout_xferp = (__u64)(buf);
-    }
-
-    ret = ioctl(fd, SG_IO, &sg_io);
-    if (ret)
-        ALOGE("%s: Error from sg_io ioctl (return value: %d, error no: %d, reply result from LLD: %d\n)",
-                __func__, ret, errno, rsp->result);
-
-    if (sg_io.info || rsp->result) {
-        ALOGE("%s: Error from sg_io info (check sg info: device_status: 0x%x, transport_status: 0x%x, driver_status: 0x%x, reply result from LLD: %d\n)",
-                __func__, sg_io.device_status, sg_io.transport_status,
-                sg_io.driver_status, rsp->result);
-        ret = -EAGAIN;
-    }
-
-    return ret;
-}
-
-static void compose_ufs_bsg_query_req(struct ufs_bsg_request *req, __u8 func,
-        __u8 opcode, __u8 idn, __u8 index, __u8 sel,
-        __u16 length)
-{
-    struct utp_upiu_header *hdr = &req->upiu_req.header;
-    struct utp_upiu_query *qr = &req->upiu_req.qr;
-
-    req->msgcode = UTP_UPIU_QUERY_REQ;
-    hdr->dword_0 = DWORD(UTP_UPIU_QUERY_REQ, 0, 0, 0);
-    hdr->dword_1 = DWORD(0, func, 0, 0);
-    hdr->dword_2 = DWORD(0, 0, length >> 8, (__u8)length);
-    qr->opcode = opcode;
-    qr->idn = idn;
-    qr->index = index;
-    qr->selector = sel;
-    qr->length = htobe16(length);
-}
-
-
-static int ufs_query_attr(int fd, __u32 value,
-        __u8 func, __u8 opcode, __u8 idn,
-        __u8 index, __u8 sel)
-{
-    struct ufs_bsg_request req{};
-    struct ufs_bsg_reply rsp{};
-    enum bsg_ioctl_dir dir = BSG_IOCTL_DIR_FROM_DEV;
-    int ret = 0;
-
-    if (opcode == QUERY_REQ_OP_WRITE_DESC || opcode == QUERY_REQ_OP_WRITE_ATTR)
-        dir = BSG_IOCTL_DIR_TO_DEV;
-
-    req.upiu_req.qr.value = htobe32(value);
-
-    compose_ufs_bsg_query_req(&req, func, opcode, idn, index, sel, 0);
-
-    ret = ufs_bsg_ioctl(fd, &req, &rsp, 0, 0, dir);
-    if (ret)
-        ALOGE("%s: Error from ufs_bsg_ioctl (return value: %d, error no: %d\n)",
-                __func__, ret, errno);
-
-    return ret;
-}
-
-int32_t set_boot_lun(char *sg_dev __unused,uint8_t lun_id)
-{
-    int32_t ret;
-    __u32 boot_lun_id  = lun_id;
-
-    ret = get_ufs_bsg_dev();
-    if (ret)
-        return ret;
-    ALOGV("Found the ufs bsg dev: %s\n", ufs_bsg_dev);
-
-    ret = ufs_bsg_dev_open();
-    if (ret)
-        return ret;
-    ALOGV("Opened ufs bsg dev: %s\n", ufs_bsg_dev);
-
-    ret = ufs_query_attr(fd_ufs_bsg, boot_lun_id, QUERY_REQ_FUNC_STD_WRITE,
-            QUERY_REQ_OP_WRITE_ATTR, QUERY_ATTR_IDN_BOOT_LU_EN, 0, 0);
-    if (ret) {
-        ALOGE("Error requesting ufs attr idn %d via query ioctl (return value: %d, error no: %d)",
-                QUERY_ATTR_IDN_BOOT_LU_EN, ret, errno);
-        goto out;
-    }
-out:
-    ufs_bsg_dev_close();
-    return ret;
-}
-#endif
-
-#ifndef _BSG_FRAMEWORK_KERNEL_HEADERS
-int32_t set_boot_lun(char *sg_dev, uint8_t boot_lun_id)
-{
-#ifndef _GENERIC_KERNEL_HEADERS
-        int fd = -1;
-        int rc;
-        struct ufs_ioctl_query_data *data = NULL;
-        size_t ioctl_data_size = sizeof(struct ufs_ioctl_query_data) + UFS_ATTR_DATA_SIZE;
-
-        data = (struct ufs_ioctl_query_data*)malloc(ioctl_data_size);
-        if (!data) {
-                fprintf(stderr, "%s: Failed to alloc query data struct\n",
-                                __func__);
-                goto error;
-        }
-        memset(data, 0, ioctl_data_size);
-        data->opcode = UPIU_QUERY_OPCODE_WRITE_ATTR;
-        data->idn = QUERY_ATTR_IDN_BOOT_LU_EN;
-        data->buf_size = UFS_ATTR_DATA_SIZE;
-        data->buffer[0] = boot_lun_id;
-        fd = open(sg_dev, O_RDWR);
-        if (fd < 0) {
-                fprintf(stderr, "%s: Failed to open %s(%s)\n",
-                                __func__,
-                                sg_dev,
-                                strerror(errno));
-                goto error;
-        }
-        rc = ioctl(fd, UFS_IOCTL_QUERY, data);
-        if (rc) {
-                fprintf(stderr, "%s: UFS query ioctl failed(%s)\n",
-                                __func__,
-                                strerror(errno));
-                goto error;
-        }
-        close(fd);
-        free(data);
-        return 0;
-error:
-        if (fd >= 0)
-                close(fd);
-        if (data)
-                free(data);
-        return -1;
-#else
-        return 0;
-#endif
-}
-#endif
-

+ 0 - 131
gpt-utils/recovery-ufs-bsg.h

@@ -1,131 +0,0 @@
-#ifndef __RECOVERY_UFS_BSG_H__
-#define __RECOVERY_UFS_BSG_H__
-
-/*
- * Copyright (c) 2020 The Linux Foundation. All rights reserved.
- *
- * Redistribution and use in source and binary forms, with or without
- * modification, are permitted provided that the following conditions are
- * met:
- *     * Redistributions of source code must retain the above copyright
- *       notice, this list of conditions and the following disclaimer.
- *     * 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.
- *     * Neither the name of The Linux Foundation 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 "AS IS" AND ANY EXPRESS OR IMPLIED
- * WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF
- * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NON-INFRINGEMENT
- * ARE DISCLAIMED.  IN NO EVENT SHALL THE COPYRIGHT OWNER 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 <linux/bsg.h>
-#include <scsi/scsi_bsg_ufs.h>
-#include <endian.h>
-#include <dirent.h>
-#include <string.h>
-
-#include <stdio.h>
-#include <stdlib.h>
-#include <sys/ioctl.h>
-#include <sys/types.h>
-#include <sys/stat.h>
-#include <unistd.h>
-#include <fcntl.h>
-#include <errno.h>
-
-#ifdef ANDROID
-#include "cutils/log.h"
-#endif
-
-#ifdef OE
-#include <syslog.h>
-#define LOGI(...) syslog(LOG_NOTICE, "INFO:" __VA_ARGS__)
-#define LOGV(...) syslog(LOG_NOTICE,"VERB:" __VA_ARGS__)
-#define LOGD(...) syslog(LOG_DEBUG,"DBG:" __VA_ARGS__)
-#define LOGE(...) syslog(LOG_ERR,"ERR:" __VA_ARGS__)
-#define LOGW(...) syslog(LOG_WARNING,"WRN:" __VA_ARGS__)
-#define strlcat(d,s,l) snprintf(d+strlen(d),l,"%s",s)
-#endif
-
-
-
-#define FNAME_SZ 64
-
-#define SG_IO  0x2285
-
-#define DWORD(b3, b2, b1, b0) htobe32((b3 << 24) | (b2 << 16) |\
-        (b1 << 8) | b0)
-
-/* UFS BSG device nodes */
-char ufs_bsg_dev[FNAME_SZ] = "/dev/ufs-bsg";
-
-int fd_ufs_bsg;
-
-int32_t set_ufs_lun(uint8_t lun_id);
-
-#ifdef _BSG_FRAMEWORK_KERNEL_HEADERS
-/* UPIU Transaction Codes */
-enum {
-    UTP_UPIU_NOP_OUT    = 0x00,
-    UTP_UPIU_COMMAND    = 0x01,
-    UTP_UPIU_DATA_OUT   = 0x02,
-    UTP_UPIU_TASK_REQ   = 0x04,
-    UTP_UPIU_QUERY_REQ  = 0x16,
-};
-
-/* UPIU Query Function field */
-enum {
-    QUERY_REQ_FUNC_STD_READ    = 0x01,
-    QUERY_REQ_FUNC_STD_WRITE   = 0x81,
-};
-
-enum query_req_opcode {
-    QUERY_REQ_OP_READ_DESC    = 0x1,
-    QUERY_REQ_OP_WRITE_DESC   = 0x2,
-    QUERY_REQ_OP_READ_ATTR    = 0x3,
-    QUERY_REQ_OP_WRITE_ATTR   = 0x4,
-    QUERY_REQ_OP_READ_FLAG    = 0x5,
-    QUERY_REQ_OP_SET_FLAG     = 0x6,
-    QUERY_REQ_OP_CLEAR_FLAG   = 0x7,
-    QUERY_REQ_OP_TOGGLE_FLAG  = 0x8,
-};
-
-enum query_desc_idn {
-    QUERY_DESC_IDN_DEVICE    = 0x0,
-    QUERY_DESC_IDN_UNIT      = 0x2,
-    QUERY_DESC_IDN_GEOMETRY  = 0x7,
-};
-
-enum query_desc_size {
-    QUERY_DESC_SIZE_DEVICE    = 0x40,
-    QUERY_DESC_SIZE_GEOMETRY  = 0x48,
-    QUERY_DESC_SIZE_UNIT      = 0x23,
-};
-
-enum bsg_ioctl_dir {
-    BSG_IOCTL_DIR_TO_DEV,
-    BSG_IOCTL_DIR_FROM_DEV,
-};
-
-enum query_attr_idn {
-    QUERY_ATTR_IDN_BOOT_LU_EN        = 0x00,
-    QUERY_ATTR_IDN_RESERVED          = 0x01,
-    QUERY_ATTR_IDN_POWER_MODE        = 0x02,
-    QUERY_ATTR_IDN_ACTIVE_ICC_LVL    = 0x03,
-};
-#endif  /*  _BSG_FRAMEWORK_KERNEL_HEADERS */
-
-#endif /* __RECOVERY_UFS_BSG_H__ */

+ 2 - 2
media/init.qti.media.sh

@@ -55,7 +55,7 @@ case "$target" in
         esac
         ;;
     "parrot")
-        setprop vendor.mm.target.enable.qcom_parser 1040451
+        setprop vendor.mm.target.enable.qcom_parser 958531
         case "$soc_hwid" in
             568|602|581|582)
                 setprop vendor.media.target_variant "_ravelin"
@@ -75,7 +75,7 @@ case "$target" in
         esac
         ;;
     "taro")
-        setprop vendor.mm.target.enable.qcom_parser 4112471
+        setprop vendor.mm.target.enable.qcom_parser 4096087
         case "$soc_hwid" in
             506|547|564)
                 setprop vendor.media.target_variant "_diwali_v2"

+ 125 - 1
overlay/FrameworksResXiaomi/res/values/config.xml

@@ -1,6 +1,6 @@
 <?xml version="1.0" encoding="utf-8"?>
 <!--
-     Copyright (C) 2024 The LineageOS Project
+     Copyright (C) 2024-2025 The LineageOS Project
      SPDX-License-Identifier: Apache-2.0
 -->
 <resources xmlns:xliff="urn:oasis:names:tc:xliff:document:1.2">
@@ -17,6 +17,130 @@
     <!-- Shutdown if the battery temperature exceeds (this value * 0.1) Celsius. -->
     <integer name="config_shutdownBatteryTemperature">580</integer>
 
+    <!-- Stability requirements in milliseconds for accepting a new brightness level.  This is used
+         for debouncing the light sensor.  Different constants are used to debounce the light sensor
+         when adapting to brighter or darker environments.  This parameter controls how quickly
+         brightness changes occur in response to an observed change in light level that exceeds the
+         hysteresis threshold. -->
+    <integer name="config_autoBrightnessBrighteningLightDebounce">1000</integer>
+    <integer name="config_autoBrightnessDarkeningLightDebounce">2000</integer>
+
+    <!-- The maximum range of gamma adjustment possible using the screen
+         auto-brightness adjustment setting. -->
+    <fraction name="config_autoBrightnessAdjustmentMaxGamma">105%</fraction>
+
+    <!-- Array of ambient lux threshold values. This is used for determining hysteresis constraint
+         values by calculating the index to use for lookup and then setting the constraint value
+         to the corresponding value of the array. The new brightening hysteresis constraint value
+         is the n-th element of config_ambientBrighteningThresholds, and the new darkening
+         hysteresis constraint value is the n-th element of config_ambientDarkeningThresholds.
+
+         The (zero-based) index is calculated as follows: (MAX is the largest index of the array)
+         condition                       calculated index
+         value < level[0]                0
+         level[n] <= value < level[n+1]  n+1
+         level[MAX] <= value             MAX+1 -->
+    <integer-array name="config_ambientThresholdLevels">
+        <item>2</item>
+        <item>3</item>
+        <item>4</item>
+        <item>5</item>
+        <item>6</item>
+        <item>7</item>
+        <item>8</item>
+        <item>9</item>
+        <item>10</item>
+        <item>20</item>
+        <item>30</item>
+        <item>40</item>
+        <item>50</item>
+        <item>60</item>
+        <item>70</item>
+        <item>80</item>
+        <item>90</item>
+        <item>100</item>
+        <item>200</item>
+        <item>300</item>
+        <item>400</item>
+        <item>500</item>
+        <item>1000</item>
+        <item>2000</item>
+        <item>3000</item>
+        <item>4000</item>
+    </integer-array>
+
+    <!-- Array of hysteresis constraint values for brightening, represented as tenths of a
+         percent. The length of this array is assumed to be one greater than
+         config_ambientThresholdLevels. The brightening threshold is calculated as
+         lux * (1.0f + CONSTRAINT_VALUE). When the current lux is higher than this threshold,
+         the screen brightness is recalculated. See the config_ambientThresholdLevels
+         description for how the constraint value is chosen. -->
+    <integer-array name="config_ambientBrighteningThresholds">
+        <item>5186</item>
+        <item>4333</item>
+        <item>3666</item>
+        <item>2999</item>
+        <item>2759</item>
+        <item>2519</item>
+        <item>2279</item>
+        <item>2039</item>
+        <item>1799</item>
+        <item>799</item>
+        <item>527</item>
+        <item>499</item>
+        <item>470</item>
+        <item>517</item>
+        <item>565</item>
+        <item>612</item>
+        <item>660</item>
+        <item>708</item>
+        <item>742</item>
+        <item>636</item>
+        <item>582</item>
+        <item>549</item>
+        <item>369</item>
+        <item>294</item>
+        <item>269</item>
+        <item>220</item>
+        <item>220</item>
+    </integer-array>
+
+    <!-- Array of hysteresis constraint values for darkening, represented as tenths of a
+         percent. The length of this array is assumed to be one greater than
+         config_ambientThresholdLevels. The darkening threshold is calculated as
+         lux * (1.0f - CONSTRAINT_VALUE). When the current lux is lower than this threshold,
+         the screen brightness is recalculated. See the config_ambientThresholdLevels
+         description for how the constraint value is chosen. -->
+    <integer-array name="config_ambientDarkeningThresholds">
+        <item>525</item>
+        <item>683</item>
+        <item>666</item>
+        <item>650</item>
+        <item>640</item>
+        <item>630</item>
+        <item>620</item>
+        <item>610</item>
+        <item>600</item>
+        <item>500</item>
+        <item>500</item>
+        <item>440</item>
+        <item>385</item>
+        <item>382</item>
+        <item>379</item>
+        <item>376</item>
+        <item>373</item>
+        <item>371</item>
+        <item>367</item>
+        <item>387</item>
+        <item>397</item>
+        <item>403</item>
+        <item>380</item>
+        <item>345</item>
+        <item>333</item>
+        <item>283</item>
+        <item>283</item>
+    </integer-array>
+
     <!-- Doze: should the TYPE_PICK_UP_GESTURE sensor be used as a pulse signal. -->
     <bool name="config_dozePulsePickup">true</bool>
 

+ 1 - 3
properties/vendor.prop

@@ -7,8 +7,6 @@ audio.deep_buffer.media=true
 audio.offload.video=true
 persist.vendor.audio.auto.scenario=true
 persist.vendor.audio.ha_proxy.enabled=true
-persist.vendor.audio.misound.disable=true
-persist.vendor.audio.misoundasc=false
 ro.af.client_heap_size_kbyte=7168
 ro.audio.flinger_standbytime_ms=2000
 ro.audio.monitorRotation=true
@@ -194,7 +192,7 @@ persist.vendor.radio.enableadvancedscan=true
 persist.vendor.radio.procedure_bytes=SKIP
 persist.vendor.radio.sib16_support=1
 ro.telephony.default_network=33,33
-ro.vendor.radio.build_profile=u-stable
+ro.vendor.radio.build_profile=v-stable
 telephony.active_modems.max_count=2
 telephony.lteOnCdmaDevice=1
 

+ 39 - 35
proprietary-files.txt

@@ -1,11 +1,9 @@
-# All unpinned blobs below are extracted from diting V816.0.10.0.ULFMIXM
+# All unpinned blobs below are extracted from cupid OS2.0.1.0.VLCMIXM
 
 # Current blobs with ELF checks disabled:
-# libcne, libmasc, lowi-server, qms depend on libwpa_client, which is a gnu makefile target
-# libmcs depends on libagm, which is decommonized
+# libmcs depends on libar-acdb, libagm, libats, liblx-osal which are gnu makefile targets
 # libqc2audio_hwaudiocodec depends on libpalclient, which is a gnu makefile target
-# libqtigefar depends on libar-pal, which is decommonized
-# [email protected] depends on libagm, which is decommonized
+# libqtigefar depends on libar-pal, which is a gnu makefile target
 
 # ADSP
 vendor/bin/adsprpcd
@@ -20,31 +18,15 @@ vendor/lib64/hw/[email protected]
 vendor/etc/models/acd/event.eai
 vendor/etc/models/acd/music.eai
 vendor/etc/models/acd/speech.eai
-vendor/lib64/hw/gyro_fusion_interface.so
 vendor/lib64/libadm.so
-vendor/lib64/libar-acdb.so
-vendor/lib64/libar-gpr.so
-vendor/lib64/libar-gsl.so
-vendor/lib64/libats.so
 vendor/lib64/libaudio_log_utils.so
-vendor/lib64/libaudiocloudctrl.so
-vendor/lib64/libaudioroute_ext.so
 vendor/lib64/libcapiv2svacnnvendor.so
 vendor/lib64/libcapiv2svarnnvendor.so
 vendor/lib64/libcapiv2uvvendor.so
-vendor/lib64/liblx-ar_util.so
-vendor/lib64/liblx-osal.so
 vendor/lib64/libmcs.so;DISABLE_CHECKELF
-vendor/lib64/libmisight.so
 vendor/lib64/libpal_net_if.so
 vendor/lib64/libqtigefar.so;DISABLE_CHECKELF
-vendor/lib64/libresampler.so
-vendor/lib64/libxlog.so
-vendor/lib64/[email protected];DISABLE_CHECKELF
-
-# Audio soundfx
 vendor/lib64/soundfx/libasphere.so
-vendor/lib64/soundfx/libshoebox.so
 
 # Bluetooth
 vendor/bin/hw/[email protected]
@@ -56,10 +38,6 @@ vendor/lib64/hw/[email protected]
 vendor/lib64/hw/[email protected]
 vendor/lib64/hw/[email protected]
 vendor/lib64/hw/[email protected]
-vendor/lib64/lib_bt_aptx.so
-vendor/lib64/lib_bt_ble.so
-vendor/lib64/lib_bt_bundle.so
-vendor/lib64/lib_bt_lhdc.so
 vendor/lib64/libbluetooth_audio_session_qti.so
 vendor/lib64/libbluetooth_audio_session_qti_2_1.so
 vendor/lib64/libbtnv.so
@@ -78,7 +56,7 @@ vendor/lib64/libsdsprpc.so
 # CNE
 vendor/app/CneApp/CneApp.apk;REQUIRED=CneApp.libvndfwk_detect_jni.qti_vendor_symlink
 vendor/bin/cnd
-vendor/bin/qms;DISABLE_CHECKELF
+vendor/bin/qms
 vendor/etc/cne/mwqem.conf
 vendor/etc/cne/profileMwqem.xml
 vendor/etc/cne/wqeclient/ATT/ATT_profile1.xml
@@ -113,11 +91,11 @@ vendor/etc/cne/wqeclient/VZW/VZW_profile7.xml
 vendor/etc/default-permissions/com.qualcomm.qti.cne.xml
 vendor/etc/init/cnd.rc
 vendor/etc/init/qms.rc
-vendor/lib64/libcne.so;DISABLE_CHECKELF
+vendor/lib64/libcne.so
 vendor/lib64/libcneapiclient.so
 vendor/lib64/libcneoplookup.so
 vendor/lib64/libcneqmiutils.so
-vendor/lib64/libmasc.so;DISABLE_CHECKELF
+vendor/lib64/libmasc.so
 vendor/lib64/libshsc.so
 vendor/lib64/libwms.so
 vendor/lib64/libwqe.so
@@ -177,6 +155,7 @@ vendor/etc/init/[email protected]
 vendor/lib64/hw/[email protected]
 
 # Diag
+system/lib64/vendor.qti.diaghal-V1-ndk.so
 system_ext/lib64/[email protected]
 vendor/bin/diag-router
 vendor/etc/init/vendor.qti.diag.rc
@@ -327,7 +306,7 @@ vendor/lib64/hw/[email protected]
 vendor/app/CACertService/CACertService.apk|ea18679b8a6cdf4f9f00b7fb5d7a86e12be38f23
 vendor/bin/edgnss-daemon|11e295ebe350de7312a2ab97f25ccbbae48ed8a4
 vendor/bin/loc_launcher|dbc5addc025360fd04dec5b024d476514a6f613f
-vendor/bin/lowi-server;DISABLE_CHECKELF|0a8998f8190c282a14fed9e33691b54a2dc6d3e9
+vendor/bin/lowi-server|0a8998f8190c282a14fed9e33691b54a2dc6d3e9
 vendor/bin/mlid|ab9291752d37ae8165cb78a6a635d48f7a668c70
 vendor/bin/xtra-daemon|e4a632e4b1b6ac75e1921bcd0a17fd0450ccf906
 vendor/etc/init/loc-launcher.rc|2942e599cec7c3491aa170bf9606713ce3d07689
@@ -411,8 +390,8 @@ vendor/lib64/libllvm-qgl.so
 vendor/lib64/hw/vulkan.adreno.so
 
 # Hotword Enrollment
-product/priv-app/HotwordEnrollmentOKGoogleHEXAGON_WIDEBAND/HotwordEnrollmentOKGoogleHEXAGON_WIDEBAND.apk
 product/priv-app/HotwordEnrollmentXGoogleHEXAGON_WIDEBAND/HotwordEnrollmentXGoogleHEXAGON_WIDEBAND.apk
+product/priv-app/HotwordEnrollmentYGoogleHEXAGON_WIDEBAND/HotwordEnrollmentYGoogleHEXAGON_WIDEBAND.apk
 system_ext/etc/permissions/com.android.hotwordenrollment.common.util.xml
 system_ext/framework/com.android.hotwordenrollment.common.util.jar
 
@@ -635,7 +614,6 @@ product/framework/uimgbamanagerlibrary.jar
 product/framework/uimservicelibrary.jar
 system_ext/app/AtFwd2/AtFwd2.apk
 system_ext/app/ImsRcsService/ImsRcsService.apk
-system_ext/app/QtiTelephony/QtiTelephony.apk
 system_ext/app/QtiTelephonyService/QtiTelephonyService.apk
 system_ext/etc/permissions/qcrilhook.xml
 system_ext/etc/permissions/qti_permissions.xml
@@ -666,7 +644,8 @@ system_ext/lib64/libimsmedia_jni.so;SYMLINK=system_ext/priv-app/ims/lib/arm64/li
 system_ext/lib64/vendor.qti.ImsRtpService-V1-ndk.so
 system_ext/lib64/[email protected]
 system_ext/lib64/[email protected]
-system_ext/priv-app/ims/ims.apk
+system_ext/priv-app/QtiTelephony/QtiTelephony.apk;REQUIRED=QtiTelephonyCompat
+system_ext/priv-app/ims/ims.apk;REQUIRED=QtiTelephonyCompat
 system_ext/priv-app/qcrilmsgtunnel/qcrilmsgtunnel.apk
 vendor/app/IWlanService/IWlanService.apk
 vendor/bin/ATFWD-daemon
@@ -701,6 +680,29 @@ vendor/etc/init/ssgtzd.rc
 vendor/etc/init/vendor.qti.rmt_storage.rc
 vendor/etc/init/vendor.qti.tftp.rc
 vendor/etc/permissions/noRil/apq_excluded_telephony_features.xml
+vendor/etc/qcril_database/upgrade/config/10.0_config.sql;FILEGROUP=proprietary_rildb_config_sql_files
+vendor/etc/qcril_database/upgrade/config/11.0_config.sql;FILEGROUP=proprietary_rildb_config_sql_files
+vendor/etc/qcril_database/upgrade/config/12.0_config.sql;FILEGROUP=proprietary_rildb_config_sql_files
+vendor/etc/qcril_database/upgrade/config/13.0_config.sql;FILEGROUP=proprietary_rildb_config_sql_files
+vendor/etc/qcril_database/upgrade/config/14.0_config.sql;FILEGROUP=proprietary_rildb_config_sql_files
+vendor/etc/qcril_database/upgrade/config/16.0_config.sql;FILEGROUP=proprietary_rildb_config_sql_files
+vendor/etc/qcril_database/upgrade/config/6.0_config.sql;FILEGROUP=proprietary_rildb_config_sql_files
+vendor/etc/qcril_database/upgrade/config/7.0_config.sql;FILEGROUP=proprietary_rildb_config_sql_files
+vendor/etc/qcril_database/upgrade/config/8.0_config.sql;FILEGROUP=proprietary_rildb_config_sql_files
+vendor/etc/qcril_database/upgrade/config/9.0_config.sql;FILEGROUP=proprietary_rildb_config_sql_files
+vendor/etc/qcril_database/upgrade/other/0_initial_qcrilnr.sql;FILEGROUP=proprietary_rildb_other_sql_files
+vendor/etc/qcril_database/upgrade/other/10_version_update_ecc_table.sql;FILEGROUP=proprietary_rildb_other_sql_files
+vendor/etc/qcril_database/upgrade/other/11_version_update_ecc_table.sql;FILEGROUP=proprietary_rildb_other_sql_files
+vendor/etc/qcril_database/upgrade/other/12_version_update_ecc_table.sql;FILEGROUP=proprietary_rildb_other_sql_files
+vendor/etc/qcril_database/upgrade/other/1_version_intro_qcrilnr.sql;FILEGROUP=proprietary_rildb_other_sql_files
+vendor/etc/qcril_database/upgrade/other/2_version_add_wps_config_qcrilnr.sql;FILEGROUP=proprietary_rildb_other_sql_files
+vendor/etc/qcril_database/upgrade/other/3_version_update_wps_config_qcrilnr.sql;FILEGROUP=proprietary_rildb_other_sql_files
+vendor/etc/qcril_database/upgrade/other/4_version_update_ecc_table_qcrilnr.sql;FILEGROUP=proprietary_rildb_other_sql_files
+vendor/etc/qcril_database/upgrade/other/5_version_update_ecc_table_qcrilnr.sql;FILEGROUP=proprietary_rildb_other_sql_files
+vendor/etc/qcril_database/upgrade/other/6_version_change_property_table_qcrilnr.sql;FILEGROUP=proprietary_rildb_other_sql_files
+vendor/etc/qcril_database/upgrade/other/7_version_update_ecc_table_qcrilnr.sql;FILEGROUP=proprietary_rildb_other_sql_files
+vendor/etc/qcril_database/upgrade/other/8_version_update_ecc_table.sql;FILEGROUP=proprietary_rildb_other_sql_files
+vendor/etc/qcril_database/upgrade/other/9_version_update_ecc_table.sql;FILEGROUP=proprietary_rildb_other_sql_files
 vendor/etc/seccomp_policy/[email protected]
 vendor/etc/seccomp_policy/imsrtp.policy
 vendor/etc/seccomp_policy/[email protected]
@@ -854,9 +856,9 @@ vendor/lib64/[email protected];MODULE_SUFFIX=_vendor
 vendor/bin/hw/[email protected]
 vendor/etc/init/[email protected]
 vendor/lib64/[email protected]
-vendor/lib64/jcos_nq_client.so
-vendor/lib64/ls_nq_client.so
-vendor/lib64/se_nq_extn_client.so
+vendor/lib64/jcos_nq_client-v1.so
+vendor/lib64/ls_nq_client-v1.so
+vendor/lib64/se_nq_extn_client-v1.so
 
 # Sensors
 vendor/bin/hw/[email protected]
@@ -944,6 +946,7 @@ vendor/etc/init/qconfig.rc
 vendor/etc/init/vppservice.rc
 vendor/etc/vintf/manifest/[email protected]
 vendor/etc/vintf/manifest/[email protected]
+vendor/lib64/libmisight.so
 vendor/lib64/libvppcommon.so
 vendor/lib64/libvpphcp.so
 vendor/lib64/libvpphvx.so
@@ -998,6 +1001,7 @@ system_ext/lib64/libwfduibcsinkinterface.so
 system_ext/lib64/libwfduibcsrc.so
 system_ext/lib64/libwfduibcsrcinterface.so
 system_ext/lib64/[email protected]
+system_ext/lib64/vendor.qti.hardware.wifidisplaysession_aidl-V1-ndk.so
 system_ext/priv-app/WfdService/WfdService.apk
 vendor/bin/wfdhdcphalservice
 vendor/bin/wfdvndservice

+ 41 - 0
qcril-database/Android.bp

@@ -0,0 +1,41 @@
+//
+// SPDX-FileCopyrightText: 2025 The LineageOS Project
+// SPDX-License-Identifier: Apache-2.0
+//
+
+filegroup {
+    name: "rildb_config_sql_files",
+    srcs: [
+        "config/15.0_config.sql",
+        "config/15.1_config.sql",
+        "config/15.2_config.sql",
+    ],
+}
+
+genrule {
+    name: "qcril_config_database",
+    enabled: true,
+    srcs: [
+        "//vendor/xiaomi/sm8450-common:proprietary_rildb_other_sql_files",
+        "//vendor/xiaomi/sm8450-common:proprietary_rildb_config_sql_files",
+        ":rildb_config_sql_files",
+    ],
+    tools: [
+        "generate_qcril_db",
+    ],
+    cmd: "$(location generate_qcril_db) $(out) $(in)",
+    out: ["qcrilNr.db"],
+}
+
+prebuilt_etc {
+    name: "qcrilNrDb_vendor",
+    filename: "qcrilNr.db",
+    src: ":qcril_config_database",
+    relative_install_path: "qcril_database",
+    vendor: true,
+    required: [
+        "15.0_config.sql",
+        "15.1_config.sql",
+        "15.2_config.sql",
+    ],
+}

+ 8 - 0
qcril-database/config/15.0_config.sql

@@ -0,0 +1,8 @@
+/*
+  SPDX-FileCopyrightText: 2024 The LineageOS Project
+  SPDX-License-Identifier: Apache-2.0
+*/
+
+CREATE TABLE IF NOT EXISTS qcril_properties_table (property TEXT PRIMARY KEY NOT NULL, def_val TEXT, value TEXT);
+INSERT OR REPLACE INTO qcril_properties_table(property, def_val) VALUES('qcrildb_version',15.0);
+UPDATE qcril_properties_table SET def_val="true" WHERE property="persist.vendor.radio.unicode_op_names";

+ 8 - 0
qcril-database/config/15.1_config.sql

@@ -0,0 +1,8 @@
+/*
+  SPDX-FileCopyrightText: 2024 The LineageOS Project
+  SPDX-License-Identifier: Apache-2.0
+*/
+
+CREATE TABLE IF NOT EXISTS qcril_properties_table (property TEXT PRIMARY KEY NOT NULL, def_val TEXT, value TEXT);
+INSERT OR REPLACE INTO qcril_properties_table(property, def_val) VALUES('qcrildb_version',15.1);
+UPDATE qcril_properties_table SET def_val="false" WHERE property="persist.vendor.radio.redir_party_num";

+ 8 - 0
qcril-database/config/15.2_config.sql

@@ -0,0 +1,8 @@
+/*
+  SPDX-FileCopyrightText: 2025 The LineageOS Project
+  SPDX-License-Identifier: Apache-2.0
+*/
+
+CREATE TABLE IF NOT EXISTS qcril_properties_table (property TEXT PRIMARY KEY NOT NULL, def_val TEXT, value TEXT);
+INSERT OR REPLACE INTO qcril_properties_table(property, def_val) VALUES('qcrildb_version',15.2);
+UPDATE qcril_properties_table SET def_val="0" WHERE property="persist.vendor.radio.poweron_opt";

+ 25 - 0
qcril-database/config/Android.bp

@@ -0,0 +1,25 @@
+//
+// SPDX-FileCopyrightText: 2025 The LineageOS Project
+// SPDX-License-Identifier: Apache-2.0
+//
+
+prebuilt_etc {
+    name: "15.0_config.sql",
+    src: "15.0_config.sql",
+    relative_install_path: "qcril_database/upgrade/config",
+    vendor: true,
+}
+
+prebuilt_etc {
+    name: "15.1_config.sql",
+    src: "15.1_config.sql",
+    relative_install_path: "qcril_database/upgrade/config",
+    vendor: true,
+}
+
+prebuilt_etc {
+    name: "15.2_config.sql",
+    src: "15.2_config.sql",
+    relative_install_path: "qcril_database/upgrade/config",
+    vendor: true,
+}

+ 0 - 163
rootdir/bin/init.qcom.class_core.sh

@@ -1,163 +0,0 @@
-#!/vendor/bin/sh
-
-# Copyright (c) 2012-2013, The Linux Foundation. All rights reserved.
-#
-# Redistribution and use in source and binary forms, with or without
-# modification, are permitted provided that the following conditions are met:
-#     * Redistributions of source code must retain the above copyright
-#       notice, this list of conditions and the following disclaimer.
-#     * 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.
-#     * Neither the name of The Linux Foundation 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, FITNESS FOR A PARTICULAR PURPOSE AND
-# NON-INFRINGEMENT ARE DISCLAIMED.  IN NO EVENT SHALL THE COPYRIGHT OWNER 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.
-#
-
-# Set platform variables
-target=`getprop ro.board.platform`
-if [ -f /sys/devices/soc0/hw_platform ]; then
-    soc_hwplatform=`cat /sys/devices/soc0/hw_platform` 2> /dev/null
-else
-    soc_hwplatform=`cat /sys/devices/system/soc/soc0/hw_platform` 2> /dev/null
-fi
-if [ -f /sys/devices/soc0/soc_id ]; then
-    soc_hwid=`cat /sys/devices/soc0/soc_id` 2> /dev/null
-else
-    soc_hwid=`cat /sys/devices/system/soc/soc0/id` 2> /dev/null
-fi
-if [ -f /sys/devices/soc0/platform_version ]; then
-    soc_hwver=`cat /sys/devices/soc0/platform_version` 2> /dev/null
-else
-    soc_hwver=`cat /sys/devices/system/soc/soc0/platform_version` 2> /dev/null
-fi
-
-
-# Dynamic Memory Managment (DMM) provides a sys file system to the userspace
-# that can be used to plug in/out memory that has been configured as unstable.
-# This unstable memory can be in Active or In-Active State.
-# Each of which the userspace can request by writing to a sys file.
-#
-# ro.dev.dmm = 1; Indicates that DMM is enabled in the Android User Space. This
-# property is set in the Android system properties file.
-#
-# If ro.dev.dmm.dpd.start_address is set here then the target has a memory
-# configuration that supports DynamicMemoryManagement.
-init_DMM()
-{
-    block=-1
-
-    case "$target" in
-    "msm7630_surf" | "msm7630_1x" | "msm7630_fusion" | "msm8960")
-        ;;
-    *)
-        return
-        ;;
-    esac
-
-    mem="/sys/devices/system/memory"
-    op=`cat $mem/movable_start_bytes`
-    case "$op" in
-    "0")
-        log -p i -t DMM DMM Disabled. movable_start_bytes not set: $op
-        ;;
-
-    "$mem/movable_start_bytes: No such file or directory ")
-        log -p i -t DMM DMM Disabled. movable_start_bytes does not exist: $op
-        ;;
-
-    *)
-        log -p i -t DMM DMM available. movable_start_bytes at $op
-        movable_start_bytes=0x`cat $mem/movable_start_bytes`
-        block_size_bytes=0x`cat $mem/block_size_bytes`
-        block=$((#${movable_start_bytes}/${block_size_bytes}))
-
-        chown -h system.system $mem/memory$block/state
-        chown -h system.system $mem/probe
-        chown -h system.system $mem/active
-        chown -h system.system $mem/remove
-
-        case "$target" in
-        "msm7630_surf" | "msm7630_1x" | "msm7630_fusion")
-            echo $movable_start_bytes > $mem/probe
-            case "$?" in
-            "0")
-                log -p i -t DMM $movable_start_bytes to physical hotplug succeeded.
-                ;;
-            *)
-                log -p e -t DMM $movable_start_bytes to physical hotplug failed.
-                return
-                ;;
-            esac
-
-            echo online > $mem/memory$block/state
-            case "$?" in
-            "0")
-                log -p i -t DMM \'echo online\' to logical hotplug succeeded.
-                ;;
-            *)
-                log -p e -t DMM \'echo online\' to logical hotplug failed.
-                return
-                ;;
-            esac
-            ;;
-        esac
-
-        setprop ro.dev.dmm.dpd.start_address $movable_start_bytes
-        setprop ro.dev.dmm.dpd.block $block
-        ;;
-    esac
-
-    case "$target" in
-    "msm8960")
-        return
-        ;;
-    esac
-
-    # For 7X30 targets:
-    # ro.dev.dmm.dpd.start_address is set when the target has a 2x256Mb memory
-    # configuration. This is also used to indicate that the target is capable of
-    # setting EBI-1 to Deep Power Down or Self Refresh.
-    op=`cat $mem/low_power_memory_start_bytes`
-    case "$op" in
-    "0")
-        log -p i -t DMM Self-Refresh-Only Disabled. low_power_memory_start_bytes not set:$op
-        ;;
-    "$mem/low_power_memory_start_bytes No such file or directory ")
-        log -p i -t DMM Self-Refresh-Only Disabled. low_power_memory_start_bytes does not exist:$op
-        ;;
-    *)
-        log -p i -t DMM Self-Refresh-Only available. low_power_memory_start_bytes at $op
-        ;;
-    esac
-}
-
-case "$target" in
-    "msm7630_surf" | "msm7630_1x" | "msm7630_fusion")
-        insmod /system/lib/modules/ss_mfcinit.ko
-        insmod /system/lib/modules/ss_vencoder.ko
-        insmod /system/lib/modules/ss_vdecoder.ko
-        chmod -h 0666 /dev/ss_mfc_reg
-        chmod -h 0666 /dev/ss_vdec
-        chmod -h 0666 /dev/ss_venc
-
-        init_DMM
-        ;;
-
-    "msm8960")
-        init_DMM
-        ;;
-esac

+ 0 - 348
rootdir/bin/init.qcom.early_boot.sh

@@ -89,318 +89,6 @@ function set_density_by_fb() {
     fi
 }
 
-target=`getprop ro.board.platform`
-case "$target" in
-    "msm7630_surf" | "msm7630_1x" | "msm7630_fusion")
-        case "$soc_hwplatform" in
-            "FFA" | "SVLTE_FFA")
-                # linking to surf_keypad_qwerty.kcm.bin instead of surf_keypad_numeric.kcm.bin so that
-                # the UI keyboard works fine.
-                ln -s  /system/usr/keychars/surf_keypad_qwerty.kcm.bin /system/usr/keychars/surf_keypad.kcm.bin
-                ;;
-            "Fluid")
-                setprop vendor.display.lcd_density 240
-                setprop qcom.bt.dev_power_class 2
-                ;;
-            *)
-                ln -s  /system/usr/keychars/surf_keypad_qwerty.kcm.bin /system/usr/keychars/surf_keypad.kcm.bin
-                ;;
-        esac
-        ;;
-     "sm6150")
-         case "$soc_hwplatform" in
-             "ADP")
-                 setprop vendor.display.lcd_density 160
-                 ;;
-         esac
-         case "$soc_hwid" in
-             365|366)
-                 sku_ver=`cat /sys/devices/platform/soc/aa00000.qcom,vidc1/sku_version` 2> /dev/null
-                 setprop vendor.media.target.version 1
-                 if [ $sku_ver -eq 1 ]; then
-                     setprop vendor.media.target.version 2
-                 fi
-                 ;;
-             355|369|377|384)
-                 setprop vendor.chre.enabled 0
-                 ;;
-             *)
-         esac
-         ;;
-    "msm8660")
-        case "$soc_hwplatform" in
-            "Fluid")
-                setprop vendor.display.lcd_density 240
-                ;;
-            "Dragon")
-                setprop ro.sound.alsa "WM8903"
-                ;;
-        esac
-        ;;
-
-    "msm8960")
-        # lcd density is write-once. Hence the separate switch case
-        case "$soc_hwplatform" in
-            "Liquid")
-                if [ "$soc_hwver" == "196608" ]; then # version 0x30000 is 3D sku
-                    setprop ro.sf.hwrotation 90
-                fi
-
-                setprop vendor.display.lcd_density 160
-                ;;
-            "MTP")
-                setprop vendor.display.lcd_density 240
-                ;;
-            *)
-                case "$soc_hwid" in
-                    "109")
-                        setprop vendor.display.lcd_density 160
-                        ;;
-                    *)
-                        setprop vendor.display.lcd_density 240
-                        ;;
-                esac
-            ;;
-        esac
-
-        #Set up composition type based on the target
-        case "$soc_hwid" in
-            87)
-                #8960
-                setprop debug.composition.type dyn
-                ;;
-            153|154|155|156|157|138)
-                #8064 V2 PRIME | 8930AB | 8630AB | 8230AB | 8030AB | 8960AB
-                setprop debug.composition.type c2d
-                ;;
-            *)
-        esac
-        ;;
-
-    "msm8974")
-        case "$soc_hwplatform" in
-            "Liquid")
-                setprop vendor.display.lcd_density 160
-                # Liquid do not have hardware navigation keys, so enable
-                # Android sw navigation bar
-                setprop ro.hw.nav_keys 0
-                ;;
-            "Dragon")
-                setprop vendor.display.lcd_density 240
-                ;;
-            *)
-                setprop vendor.display.lcd_density 320
-                ;;
-        esac
-        ;;
-
-    "msm8226")
-        case "$soc_hwplatform" in
-            *)
-                setprop vendor.display.lcd_density 320
-                ;;
-        esac
-        ;;
-
-    "msm8610" | "apq8084" | "mpq8092")
-        case "$soc_hwplatform" in
-            *)
-                setprop vendor.display.lcd_density 240
-                ;;
-        esac
-        ;;
-    "apq8084")
-        case "$soc_hwplatform" in
-            "Liquid")
-                setprop vendor.display.lcd_density 320
-                # Liquid do not have hardware navigation keys, so enable
-                # Android sw navigation bar
-                setprop ro.hw.nav_keys 0
-                ;;
-            "SBC")
-                setprop vendor.display.lcd_density 200
-                # SBC do not have hardware navigation keys, so enable
-                # Android sw navigation bar
-                setprop qemu.hw.mainkeys 0
-                ;;
-            *)
-                setprop vendor.display.lcd_density 480
-                ;;
-        esac
-        ;;
-    "msm8996")
-        case "$soc_hwplatform" in
-            "Dragon")
-                setprop vendor.display.lcd_density 240
-                setprop qemu.hw.mainkeys 0
-                ;;
-            "ADP")
-                setprop vendor.display.lcd_density 160
-                setprop qemu.hw.mainkeys 0
-                ;;
-            "SBC")
-                setprop vendor.display.lcd_density 240
-                setprop qemu.hw.mainkeys 0
-                ;;
-            *)
-                setprop vendor.display.lcd_density 560
-                ;;
-        esac
-        ;;
-    "msm8937" | "msm8940")
-        # Set vendor.opengles.version based on chip id.
-        # MSM8937 and MSM8940  variants supports OpenGLES 3.1
-        # 196608 is decimal for 0x30000 to report version 3.0
-        # 196609 is decimal for 0x30001 to report version 3.1
-        # 196610 is decimal for 0x30002 to report version 3.2
-        case "$soc_hwid" in
-            294|295|296|297|298|313|353|354|363|364)
-                setprop vendor.opengles.version 196610
-                if [ $soc_hwid = 354 ]
-                then
-                    setprop vendor.media.target.version 1
-                    log -t BOOT -p i "SDM429 early_boot prop set for: HwID '$soc_hwid'"
-                fi
-                ;;
-            303|307|308|309|320)
-                # Vulkan is not supported for 8917 variants
-                setprop vendor.opengles.version 196608
-                setprop persist.graphics.vulkan.disable true
-                ;;
-            *)
-                setprop vendor.opengles.version 196608
-                ;;
-        esac
-        ;;
-    "msm8909")
-        case "$soc_hwplatform" in
-            *)
-                setprop persist.graphics.vulkan.disable true
-                ;;
-        esac
-        ;;
-    "msm8998" | "apq8098_latv")
-        case "$soc_hwplatform" in
-            *)
-                setprop vendor.display.lcd_density 560
-                ;;
-        esac
-        ;;
-    "sdm845")
-        case "$soc_hwplatform" in
-            *)
-                if [ $fb_width -le 1600 ]; then
-                    setprop vendor.display.lcd_density 560
-                else
-                    setprop vendor.display.lcd_density 640
-                fi
-                ;;
-        esac
-        ;;
-    "msmnile")
-        case "$soc_hwplatform" in
-            *)
-                if [ $fb_width -le 1600 ]; then
-                    setprop vendor.display.lcd_density 560
-                else
-                    setprop vendor.display.lcd_density 640
-                fi
-                ;;
-        esac
-        ;;
-    "kona")
-        case "$soc_hwplatform" in
-            *)
-                setprop vendor.media.target_variant "_kona"
-                if [ $fb_width -le 1600 ]; then
-                    setprop vendor.display.lcd_density 560
-                else
-                    setprop vendor.display.lcd_density 640
-                fi
-                ;;
-        esac
-        ;;
-    "lito")
-        case "$soc_hwid" in
-            400|440)
-                sku_ver=`cat /sys/devices/platform/soc/aa00000.qcom,vidc1/sku_version` 2> /dev/null
-                if [ $sku_ver -eq 1 ]; then
-                    setprop vendor.media.target.version 1
-                fi
-                ;;
-            434|459)
-                sku_ver=`cat /sys/devices/platform/soc/aa00000.qcom,vidc1/sku_version` 2> /dev/null
-                setprop vendor.media.target.version 2
-                if [ $sku_ver -eq 1 ]; then
-                    setprop vendor.media.target.version 3
-                fi
-                ;;
-        esac
-        ;;
-    "bengal")
-        case "$soc_hwid" in
-            441)
-                setprop vendor.fastrpc.disable.cdsprpcd.daemon 1
-                setprop vendor.gralloc.disable_ubwc 1
-
-                # 196609 is decimal for 0x30001 to report version 3.1
-                setprop vendor.opengles.version 196609
-                ;;
-            471)
-                #scuba APQ
-                setprop vendor.gralloc.disable_ubwc 1
-                ;;
-        esac
-        ;;
-    "sdm710" | "msmpeafowl")
-        case "$soc_hwplatform" in
-            *)
-                if [ $fb_width -le 1600 ]; then
-                    setprop vendor.display.lcd_density 560
-                else
-                    setprop vendor.display.lcd_density 640
-                fi
-
-                sku_ver=`cat /sys/devices/platform/soc/aa00000.qcom,vidc1/sku_version` 2> /dev/null
-                if [ $sku_ver -eq 1 ]; then
-                    setprop vendor.media.target.version 1
-                fi
-                ;;
-        esac
-        ;;
-    "msm8953")
-        cap_ver = 1
-                if [ -e "/sys/devices/platform/soc/1d00000.qcom,vidc/capability_version" ]; then
-                    cap_ver=`cat /sys/devices/platform/soc/1d00000.qcom,vidc/capability_version` 2> /dev/null
-                else
-                    cap_ver=`cat /sys/devices/soc/1d00000.qcom,vidc/capability_version` 2> /dev/null
-                fi
-
-                if [ $cap_ver -eq 1 ]; then
-                    setprop vendor.media.target.version 1
-                fi
-                ;;
-    #Set property to differentiate SDM660 & SDM455
-    #SOC ID for SDM455 is 385
-    "sdm660")
-        case "$soc_hwplatform" in
-            *)
-                if [ $fb_width -le 1600 ]; then
-                    setprop vendor.display.lcd_density 560
-                else
-                    setprop vendor.display.lcd_density 640
-                fi
-
-                if [ $soc_hwid -eq 385 ]; then
-                    setprop vendor.media.target.version 1
-                fi
-                ;;
-        esac
-        ;;
-    "holi")
-        setprop vendor.media.target_variant "_holi"
-        ;;
-esac
 
 baseband=`getprop ro.baseband`
 #enable atfwd daemon all targets except sda, apq, qcs
@@ -418,42 +106,6 @@ esac
 set_density_by_fb
 
 
-# set Lilliput LCD density for ADP
-product=`getprop ro.board.platform`
-
-case "$product" in
-        "msmnile_au")
-         setprop vendor.display.lcd_density 160
-         echo 902400000 > /sys/class/devfreq/soc:qcom,cpu0-cpu-l3-lat/min_freq
-         echo 1612800000 > /sys/class/devfreq/soc:qcom,cpu0-cpu-l3-lat/max_freq
-         echo 902400000 > /sys/class/devfreq/soc:qcom,cpu4-cpu-l3-lat/min_freq
-         echo 1612800000 > /sys/class/devfreq/soc:qcom,cpu4-cpu-l3-lat/max_freq
-         ;;
-        *)
-        ;;
-esac
-case "$product" in
-        "sm6150_au")
-         setprop vendor.display.lcd_density 160
-         ;;
-        *)
-        ;;
-esac
-case "$product" in
-        "sdmshrike_au")
-         setprop vendor.display.lcd_density 160
-         ;;
-        *)
-        ;;
-esac
-
-case "$product" in
-        "msmnile_gvmq")
-         setprop vendor.display.lcd_density 160
-         ;;
-        *)
-        ;;
-esac
 # Setup display nodes & permissions
 # HDMI can be fb1 or fb2
 # Loop through the sysfs nodes and determine

File diff ditekan karena terlalu besar
+ 0 - 5632
rootdir/bin/init.qcom.post_boot.sh


+ 0 - 390
rootdir/bin/init.qcom.sh

@@ -27,118 +27,6 @@
 # ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
 #
 
-target=`getprop ro.board.platform`
-low_ram=`getprop ro.config.low_ram`
-if [ -f /sys/devices/soc0/soc_id ]; then
-    platformid=`cat /sys/devices/soc0/soc_id`
-else
-    platformid=`cat /sys/devices/system/soc/soc0/id`
-fi
-
-start_battery_monitor()
-{
-	if ls /sys/bus/spmi/devices/qpnp-bms-*/fcc_data ; then
-		chown -h root.system /sys/module/pm8921_bms/parameters/*
-		chown -h root.system /sys/module/qpnp_bms/parameters/*
-		chown -h root.system /sys/bus/spmi/devices/qpnp-bms-*/fcc_data
-		chown -h root.system /sys/bus/spmi/devices/qpnp-bms-*/fcc_temp
-		chown -h root.system /sys/bus/spmi/devices/qpnp-bms-*/fcc_chgcyl
-		chmod 0660 /sys/module/qpnp_bms/parameters/*
-		chmod 0660 /sys/module/pm8921_bms/parameters/*
-		mkdir -p /data/bms
-		chown -h root.system /data/bms
-		chmod 0770 /data/bms
-		start battery_monitor
-	fi
-}
-
-start_charger_monitor()
-{
-	if ls /sys/module/qpnp_charger/parameters/charger_monitor; then
-		chown -h root.system /sys/module/qpnp_charger/parameters/*
-		chown -h root.system /sys/class/power_supply/battery/input_current_max
-		chown -h root.system /sys/class/power_supply/battery/input_current_trim
-		chown -h root.system /sys/class/power_supply/battery/input_current_settled
-		chown -h root.system /sys/class/power_supply/battery/voltage_min
-		chmod 0664 /sys/class/power_supply/battery/input_current_max
-		chmod 0664 /sys/class/power_supply/battery/input_current_trim
-		chmod 0664 /sys/class/power_supply/battery/input_current_settled
-		chmod 0664 /sys/class/power_supply/battery/voltage_min
-		chmod 0664 /sys/module/qpnp_charger/parameters/charger_monitor
-		start charger_monitor
-	fi
-}
-
-start_vm_bms()
-{
-	if [ -e /dev/vm_bms ]; then
-		chown -h root.system /sys/class/power_supply/bms/current_now
-		chown -h root.system /sys/class/power_supply/bms/voltage_ocv
-		chmod 0664 /sys/class/power_supply/bms/current_now
-		chmod 0664 /sys/class/power_supply/bms/voltage_ocv
-		start vm_bms
-	fi
-}
-
-start_msm_irqbalance_8939()
-{
-	if [ -f /vendor/bin/msm_irqbalance ]; then
-		case "$platformid" in
-		    "239" | "293" | "294" | "295" | "304" | "338" | "313" | "353" | "354")
-			start vendor.msm_irqbalance;;
-		    "349" | "350" )
-			start vendor.msm_irqbal_lb;;
-		esac
-	fi
-}
-
-start_msm_irqbalance_msmnile()
-{
-         if [ -f /vendor/bin/msm_irqbalance ]; then
-                start vendor.msm_irqbalance
-         fi
-}
-
-start_msm_irqbalance_kona()
-{
-         if [ -f /vendor/bin/msm_irqbalance ]; then
-                start vendor.msm_irqbalance
-         fi
-}
-
-start_msm_irqbalance_lito()
-{
-         if [ -f /vendor/bin/msm_irqbalance ]; then
-                start vendor.msm_irqbalance
-         fi
-}
-
-start_msm_irqbalance_atoll()
-{
-         if [ -f /vendor/bin/msm_irqbalance ]; then
-                start vendor.msm_irqbalance
-         fi
-}
-
-start_msm_irqbalance660()
-{
-	if [ -f /vendor/bin/msm_irqbalance ]; then
-		case "$platformid" in
-		    "317" | "321" | "324" | "325" | "326" | "336" | "345" | "346" | "360" | "393")
-			start vendor.msm_irqbalance;;
-		    "318" | "327" | "385")
-			start vendor.msm_irqbl_sdm630;;
-		esac
-	fi
-}
-
-start_msm_irqbalance()
-{
-	if [ -f /vendor/bin/msm_irqbalance ]; then
-			start vendor.msm_irqbalance
-	fi
-}
-
 baseband=`getprop ro.baseband`
 echo 1 > /proc/sys/net/ipv6/conf/default/accept_ra_defrtr
 
@@ -148,284 +36,6 @@ case "$baseband" in
         ;;
 esac
 
-case "$target" in
-    "msm7630_surf" | "msm7630_1x" | "msm7630_fusion")
-        if [ -f /sys/devices/soc0/hw_platform ]; then
-            value=`cat /sys/devices/soc0/hw_platform`
-        else
-            value=`cat /sys/devices/system/soc/soc0/hw_platform`
-        fi
-        case "$value" in
-            "Fluid")
-             start profiler_daemon;;
-        esac
-        ;;
-    "msm8660" )
-        if [ -f /sys/devices/soc0/hw_platform ]; then
-            platformvalue=`cat /sys/devices/soc0/hw_platform`
-        else
-            platformvalue=`cat /sys/devices/system/soc/soc0/hw_platform`
-        fi
-        case "$platformvalue" in
-            "Fluid")
-                start profiler_daemon;;
-        esac
-        ;;
-    "msm8960")
-        case "$baseband" in
-            "msm")
-                start_battery_monitor;;
-        esac
-
-        if [ -f /sys/devices/soc0/hw_platform ]; then
-            platformvalue=`cat /sys/devices/soc0/hw_platform`
-        else
-            platformvalue=`cat /sys/devices/system/soc/soc0/hw_platform`
-        fi
-        case "$platformvalue" in
-             "Fluid")
-                 start profiler_daemon;;
-             "Liquid")
-                 start profiler_daemon;;
-        esac
-        ;;
-    "msm8974")
-        platformvalue=`cat /sys/devices/soc0/hw_platform`
-        case "$platformvalue" in
-             "Fluid")
-                 start profiler_daemon;;
-             "Liquid")
-                 start profiler_daemon;;
-        esac
-        case "$baseband" in
-            "msm")
-                start_battery_monitor
-                ;;
-        esac
-        start_charger_monitor
-        ;;
-    "sdm660")
-        if [ -f /sys/devices/soc0/soc_id ]; then
-             soc_id=`cat /sys/devices/soc0/soc_id`
-        else
-             soc_id=`cat /sys/devices/system/soc/soc0/id`
-        fi
-
-        if [ -f /sys/devices/soc0/hw_platform ]; then
-             hw_platform=`cat /sys/devices/soc0/hw_platform`
-        else
-             hw_platform=`cat /sys/devices/system/soc/soc0/hw_platform`
-        fi
-
-        case "$soc_id" in
-             "317" | "324" | "325" | "326" | "318" | "327" )
-                  case "$hw_platform" in
-                       "Surf")
-                                    setprop qemu.hw.mainkeys 0
-                                    ;;
-                       "MTP")
-                                    setprop qemu.hw.mainkeys 0
-                                    ;;
-                       "RCM")
-                                    setprop qemu.hw.mainkeys 0
-                                    ;;
-                       "QRD")
-                                    setprop qemu.hw.mainkeys 0
-                                    ;;
-                  esac
-                  ;;
-       esac
-        start_msm_irqbalance660
-        ;;
-    "apq8084")
-        platformvalue=`cat /sys/devices/soc0/hw_platform`
-        case "$platformvalue" in
-             "Fluid")
-                 start profiler_daemon;;
-             "Liquid")
-                 start profiler_daemon;;
-        esac
-        ;;
-    "msm8226")
-        start_charger_monitor
-        ;;
-    "msm8610")
-        start_charger_monitor
-        ;;
-    "msm8916")
-        start_vm_bms
-        start_msm_irqbalance_8939
-        if [ -f /sys/devices/soc0/soc_id ]; then
-            soc_id=`cat /sys/devices/soc0/soc_id`
-        else
-            soc_id=`cat /sys/devices/system/soc/soc0/id`
-        fi
-
-        if [ -f /sys/devices/soc0/platform_subtype_id ]; then
-             platform_subtype_id=`cat /sys/devices/soc0/platform_subtype_id`
-        fi
-        if [ -f /sys/devices/soc0/hw_platform ]; then
-             hw_platform=`cat /sys/devices/soc0/hw_platform`
-        fi
-        case "$soc_id" in
-             "239")
-                  case "$hw_platform" in
-                       "Surf")
-                            case "$platform_subtype_id" in
-                                 "1")
-                                      setprop qemu.hw.mainkeys 0
-                                      ;;
-                            esac
-                            ;;
-                       "MTP")
-                          case "$platform_subtype_id" in
-                               "3")
-                                    setprop qemu.hw.mainkeys 0
-                                    ;;
-                          esac
-                          ;;
-                  esac
-                  ;;
-        esac
-        ;;
-    "msm8994" | "msm8992" | "msm8998" | "apq8098_latv" | "sdm845" | "sdm710" | "qcs605" | "sm6150" | "trinket" | "bengal")
-        start_msm_irqbalance
-        ;;
-    "msm8996")
-        if [ -f /sys/devices/soc0/hw_platform ]; then
-             hw_platform=`cat /sys/devices/soc0/hw_platform`
-        fi
-        case "$hw_platform" in
-                "MTP" | "CDP")
-                #Loop through the sysfs nodes and determine the correct sysfs to change the permission and ownership.
-                        for count in 0 1 2 3 4 5 6 7 8 9 10
-                        do
-                                dir="/sys/devices/soc/75ba000.i2c/i2c-12/12-0020/input/input"$count
-                                if [ -d "$dir" ]; then
-                                     chmod 0660 $dir/secure_touch_enable
-                                     chmod 0440 $dir/secure_touch
-                                     chown system.drmrpc $dir/secure_touch_enable
-                                     chown system.drmrpc $dir/secure_touch
-                                     break
-                                fi
-                        done
-                        ;;
-        esac
-        ;;
-    "msm8909")
-        start_vm_bms
-        ;;
-    "msmnile")
-        start_msm_irqbalance_msmnile
-        ;;
-    "kona")
-        start_msm_irqbalance_kona
-        ;;
-    "lito")
-        start_msm_irqbalance_lito
-        ;;
-    "atoll")
-        start_msm_irqbalance_atoll
-        ;;
-    "msm8937")
-        start_msm_irqbalance_8939
-        if [ -f /sys/devices/soc0/soc_id ]; then
-            soc_id=`cat /sys/devices/soc0/soc_id`
-        else
-            soc_id=`cat /sys/devices/system/soc/soc0/id`
-        fi
-
-        if [ -f /sys/devices/soc0/hw_platform ]; then
-             hw_platform=`cat /sys/devices/soc0/hw_platform`
-        else
-             hw_platform=`cat /sys/devices/system/soc/soc0/hw_platform`
-        fi
-	if [ "$low_ram" != "true" ]; then
-             case "$soc_id" in
-                  "294" | "295" | "303" | "307" | "308" | "309" | "313" | "320" | "353" | "354" | "363" | "364")
-                       case "$hw_platform" in
-                            "Surf")
-                                    setprop qemu.hw.mainkeys 0
-                                    ;;
-                            "MTP")
-                                    setprop qemu.hw.mainkeys 0
-                                    ;;
-                            "RCM")
-                                    setprop qemu.hw.mainkeys 0
-                                    ;;
-                            "QRD")
-                                    setprop qemu.hw.mainkeys 0
-                                    ;;
-                       esac
-                       ;;
-             esac
-        fi
-        ;;
-    "msm8953")
-	start_msm_irqbalance_8939
-        if [ -f /sys/devices/soc0/soc_id ]; then
-            soc_id=`cat /sys/devices/soc0/soc_id`
-        else
-            soc_id=`cat /sys/devices/system/soc/soc0/id`
-        fi
-
-        if [ -f /sys/devices/soc0/hw_platform ]; then
-             hw_platform=`cat /sys/devices/soc0/hw_platform`
-        else
-             hw_platform=`cat /sys/devices/system/soc/soc0/hw_platform`
-        fi
-        case "$soc_id" in
-             "293" | "304" | "338" | "351" | "349" | "350" )
-                  case "$hw_platform" in
-                       "Surf")
-                                    setprop qemu.hw.mainkeys 0
-                                    ;;
-                       "MTP")
-                                    setprop qemu.hw.mainkeys 0
-                                    ;;
-                       "RCM")
-                                    setprop qemu.hw.mainkeys 0
-                                    ;;
-                       "QRD")
-                                    setprop qemu.hw.mainkeys 0
-                                    ;;
-                  esac
-                  ;;
-       esac
-        ;;
-    "sdm710")
-        if [ -f /sys/devices/soc0/soc_id ]; then
-            soc_id=`cat /sys/devices/soc0/soc_id`
-        else
-            soc_id=`cat /sys/devices/system/soc/soc0/id`
-        fi
-
-        if [ -f /sys/devices/soc0/hw_platform ]; then
-             hw_platform=`cat /sys/devices/soc0/hw_platform`
-        else
-             hw_platform=`cat /sys/devices/system/soc/soc0/hw_platform`
-        fi
-        case "$soc_id" in
-             "336" | "337" | "347" | "360" | "393" )
-                  case "$hw_platform" in
-                       "Surf")
-                                    setprop qemu.hw.mainkeys 0
-                                    ;;
-                       "MTP")
-                                    setprop qemu.hw.mainkeys 0
-                                    ;;
-                       "RCM")
-                                    setprop qemu.hw.mainkeys 0
-                                    ;;
-                       "QRD")
-                                    setprop qemu.hw.mainkeys 0
-                                    ;;
-                  esac
-                  ;;
-       esac
-        ;;
-esac
-
 #
 # Make modem config folder and copy firmware config to that folder for RIL
 #

+ 0 - 5
rootdir/etc/init.qcom.rc

@@ -488,11 +488,6 @@ on property:vendor.media.target_variant=*
     setprop ro.media.xml_variant.codecs ${vendor.media.target_variant}
     setprop ro.media.xml_variant.codecs_performance ${vendor.media.target_variant}
 
-service qcom-c_core-sh  /vendor/bin/init.qcom.class_core.sh
-    class core
-    user root
-    oneshot
-
 service qcom-c_main-sh /vendor/bin/init.class_main.sh
     class main
     user root

+ 3 - 0
rootdir/etc/init.recovery.qcom.rc

@@ -48,3 +48,6 @@ on fs
 
 on property:dev.mnt.blk.firmware=*
     write /sys/kernel/boot_adsp/boot 1
+
+on property:init.svc.fastbootd=running
+    umount /firmware

+ 1 - 1
rootdir/etc/init.xiaomi_sm8450.rc

@@ -147,7 +147,7 @@ service vendor.audio-hal /vendor/bin/hw/android.hardware.audio.service
     class hal
     user audioserver
     # media gid needed for /dev/fm (radio) and for /data/misc/media (tee)
-    group audio camera drmrpc inet media mediadrm net_bt net_bt_admin net_bw_acct oem_2901 wakelock context_hub
+    group audio camera drmrpc inet media mediadrm net_bt net_bt_admin net_bw_acct oem_2901 wakelock context_hub system
     capabilities BLOCK_SUSPEND SYS_NICE
     # setting RLIMIT_RTPRIO allows binder RT priority inheritance
     rlimit rtprio 10 10

+ 3 - 1
sensors/sensor-notifier/include/SensorNotifierUtils.h

@@ -6,7 +6,9 @@
 
 #pragma once
 
+#include <memory>
+
 #include <display/drm/mi_disp.h>
 
 bool readBool(int fd);
-disp_event_resp* parseDispEvent(int fd);
+std::shared_ptr<disp_event_resp> parseDispEvent(int fd);

+ 1 - 1
sensors/sensor-notifier/notifiers/AodNotifier.cpp

@@ -91,7 +91,7 @@ void AodNotifier::notify() {
             continue;
         }
 
-        struct disp_event_resp* response = parseDispEvent(disp_fd_.get());
+        std::shared_ptr<disp_event_resp> response = parseDispEvent(disp_fd_.get());
         if (response == nullptr) {
             continue;
         }

+ 1 - 1
sensors/sensor-notifier/notifiers/LightNotifier.cpp

@@ -93,7 +93,7 @@ void LightNotifier::notify() {
             continue;
         }
 
-        struct disp_event_resp* response = parseDispEvent(disp_fd_.get());
+        std::shared_ptr<disp_event_resp> response = parseDispEvent(disp_fd_.get());
         if (response == nullptr) {
             continue;
         }

+ 2 - 2
sensors/sensor-notifier/notifiers/NonUiNotifier.cpp

@@ -35,8 +35,8 @@ class NonUiSensorCallback : public IEventQueueCallback {
 
     Return<void> onEvent(const Event& e) {
         struct touch_mode_request request = {
-            .mode = TOUCH_MODE_NONUI_MODE,
-            .value = static_cast<int>(e.u.scalar),
+                .mode = TOUCH_MODE_NONUI_MODE,
+                .value = static_cast<int>(e.u.scalar),
         };
         ioctl(touch_fd_.get(), TOUCH_IOC_SET_CUR_VALUE, &request);
 

+ 7 - 3
sensors/sensor-notifier/utils/SensorNotifierUtils.cpp

@@ -29,7 +29,7 @@ bool readBool(int fd) {
     return c != '0';
 }
 
-disp_event_resp* parseDispEvent(int fd) {
+std::shared_ptr<disp_event_resp> parseDispEvent(int fd) {
     disp_event header;
     ssize_t headerSize = read(fd, &header, sizeof(header));
     if (headerSize < sizeof(header)) {
@@ -37,8 +37,12 @@ disp_event_resp* parseDispEvent(int fd) {
         return nullptr;
     }
 
-    struct disp_event_resp* response =
-            reinterpret_cast<struct disp_event_resp*>(malloc(header.length));
+    std::shared_ptr<disp_event_resp> response(static_cast<disp_event_resp*>(malloc(header.length)),
+                                              free);
+    if (!response) {
+        LOG(ERROR) << "failed to allocate memory for display event response";
+        return nullptr;
+    }
     response->base = header;
 
     int dataLength = response->base.length - sizeof(response->base);

+ 1 - 4
sepolicy/vendor/file_contexts

@@ -64,9 +64,6 @@
 # Modem
 /dev/smd8 u:object_r:vendor_radio_smd_device:s0
 
-# NFC
-/vendor/bin/hw/android\.hardware\.nfc-service\.nxp u:object_r:hal_nfc_default_exec:s0
-
 # Sensors
 /(vendor|system/vendor)/bin/hw/android\.hardware\.sensors-service\.xiaomi-multihal u:object_r:hal_sensors_default_exec:s0
 /(vendor|system/vendor)/bin/sensor-notifier u:object_r:vendor_sensor_notifier_exec:s0
@@ -83,4 +80,4 @@
 
 # Touchscreen
 /dev/xiaomi-touch u:object_r:touchfeature_device:s0
-/vendor/bin/hw/vendor\.lineage\.touch@1\.0-service\.xiaomi u:object_r:hal_lineage_touch_default_exec:s0
+/vendor/bin/hw/vendor\.lineage\.touch@1\.0-service\.xiaomi u:object_r:hal_lineage_touch_default_exec:s0

+ 0 - 2
sepolicy/vendor/service_contexts

@@ -1,2 +0,0 @@
-# NFC
-vendor.nxp.nxpnfc_aidl.INxpNfc/default    u:object_r:hal_nfc_service:s0

+ 19 - 12
udfps/UdfpsHandler.cpp

@@ -41,7 +41,7 @@ using ::aidl::android::hardware::biometrics::fingerprint::AcquiredInfo;
 
 namespace {
 
-static disp_event_resp* parseDispEvent(int fd) {
+static std::shared_ptr<disp_event_resp> parseDispEvent(int fd) {
     disp_event header;
     ssize_t headerSize = read(fd, &header, sizeof(header));
     if (headerSize < sizeof(header)) {
@@ -49,8 +49,12 @@ static disp_event_resp* parseDispEvent(int fd) {
         return nullptr;
     }
 
-    struct disp_event_resp* response =
-            reinterpret_cast<struct disp_event_resp*>(malloc(header.length));
+    std::shared_ptr<disp_event_resp> response(static_cast<disp_event_resp*>(malloc(header.length)),
+                                              free);
+    if (!response) {
+        LOG(ERROR) << "failed to allocate memory for display event response";
+        return nullptr;
+    }
     response->base = header;
 
     int dataLength = response->base.length - sizeof(response->base);
@@ -84,21 +88,24 @@ class XiaomiSm8450UdfpsHander : public UdfpsHandler {
 
         // Thread to listen for fod ui changes
         std::thread([this]() {
-            int fd = open(DISP_FEATURE_PATH, O_RDWR);
+            android::base::unique_fd fd(open(DISP_FEATURE_PATH, O_RDWR));
             if (fd < 0) {
                 LOG(ERROR) << "failed to open " << DISP_FEATURE_PATH << " , err: " << fd;
                 return;
             }
 
             // Register for FOD events
-            disp_event_req req;
-            req.base.flag = 0;
-            req.base.disp_id = MI_DISP_PRIMARY;
-            req.type = MI_DISP_EVENT_FOD;
-            ioctl(fd, MI_DISP_IOCTL_REGISTER_EVENT, &req);
+            struct disp_event_req displayEventRequest = {
+                    .base = displayBasePrimary,
+                    .type = MI_DISP_EVENT_FOD,
+            };
+            if (ioctl(fd.get(), MI_DISP_IOCTL_REGISTER_EVENT, &displayEventRequest) < 0) {
+                LOG(ERROR) << "failed to register FOD event";
+                return;
+            }
 
             struct pollfd dispEventPoll = {
-                    .fd = fd,
+                    .fd = fd.get(),
                     .events = POLLIN,
                     .revents = 0,
             };
@@ -110,8 +117,8 @@ class XiaomiSm8450UdfpsHander : public UdfpsHandler {
                     continue;
                 }
 
-                struct disp_event_resp* response = parseDispEvent(fd);
-                if (response == nullptr) {
+                std::shared_ptr<disp_event_resp> response = parseDispEvent(fd.get());
+                if (!response) {
                     continue;
                 }
 

Beberapa file tidak ditampilkan karena terlalu banyak file yang berubah dalam diff ini