mirror of
https://github.com/Evolution-X-Devices/device_xiaomi_sky
synced 2026-02-01 09:40:11 +00:00
sky: setup libinit for different models
Co-authored-by: SebaUbuntu <seba@sebaubuntu.dev>
This commit is contained in:
@@ -87,6 +87,9 @@ BOARD_PREBUILT_DTBOIMAGE := $(KERNEL_PATH)/dtbo.img
|
||||
# Filesystem
|
||||
TARGET_FS_CONFIG_GEN := $(DEVICE_PATH)/configs/config.fs
|
||||
|
||||
# Init
|
||||
TARGET_INIT_VENDOR_LIB := //$(DEVICE_PATH):init_xiaomi_sky
|
||||
|
||||
# Kernel
|
||||
BOARD_KERNEL_PAGESIZE := 4096
|
||||
BOARD_KERNEL_BASE := 0x00000000
|
||||
|
||||
24
libinit/Android.bp
Normal file
24
libinit/Android.bp
Normal file
@@ -0,0 +1,24 @@
|
||||
//
|
||||
// Copyright (C) 2021 The LineageOS Project
|
||||
//
|
||||
// SPDX-License-Identifier: Apache-2.0
|
||||
//
|
||||
|
||||
cc_library_static {
|
||||
name: "libinit_xiaomi_sky",
|
||||
srcs: [
|
||||
"libinit_variant.cpp",
|
||||
"libinit_utils.cpp",
|
||||
],
|
||||
whole_static_libs: ["libbase"],
|
||||
export_include_dirs: ["include"],
|
||||
recovery_available: true,
|
||||
}
|
||||
|
||||
cc_library_static {
|
||||
name: "init_xiaomi_sky",
|
||||
srcs: ["init_xiaomi_sky.cpp"],
|
||||
whole_static_libs: ["libinit_xiaomi_sky"],
|
||||
include_dirs: ["system/core/init"],
|
||||
recovery_available: true,
|
||||
}
|
||||
18
libinit/include/libinit_utils.h
Normal file
18
libinit/include/libinit_utils.h
Normal file
@@ -0,0 +1,18 @@
|
||||
/*
|
||||
* Copyright (C) 2021 The LineageOS Project
|
||||
*
|
||||
* SPDX-License-Identifier: Apache-2.0
|
||||
*/
|
||||
|
||||
#ifndef LIBINIT_UTILS_H
|
||||
#define LIBINIT_UTILS_H
|
||||
|
||||
#include <string>
|
||||
|
||||
void property_override(std::string prop, std::string value, bool add = true);
|
||||
|
||||
void set_ro_build_prop(const std::string &prop, const std::string &value, bool product = false);
|
||||
|
||||
const std::string fingerprint_to_description(const std::string &fingerprint);
|
||||
|
||||
#endif // LIBINIT_UTILS_H
|
||||
30
libinit/include/libinit_variant.h
Normal file
30
libinit/include/libinit_variant.h
Normal file
@@ -0,0 +1,30 @@
|
||||
/*
|
||||
* Copyright (C) 2021 The LineageOS Project
|
||||
*
|
||||
* SPDX-License-Identifier: Apache-2.0
|
||||
*/
|
||||
|
||||
#ifndef LIBINIT_VARIANT_H
|
||||
#define LIBINIT_VARIANT_H
|
||||
|
||||
#include <string>
|
||||
#include <vector>
|
||||
|
||||
typedef struct variant_info {
|
||||
std::string hwc_value;
|
||||
std::string boardid;
|
||||
|
||||
std::string brand;
|
||||
std::string device;
|
||||
std::string marketname;
|
||||
std::string model;
|
||||
std::string mod_device;
|
||||
std::string build_fingerprint;
|
||||
|
||||
} variant_info_t;
|
||||
|
||||
void search_variant(const std::vector<variant_info_t> variants);
|
||||
|
||||
void set_variant_props(const variant_info_t variant);
|
||||
|
||||
#endif // LIBINIT_VARIANT_H
|
||||
60
libinit/init_xiaomi_sky.cpp
Normal file
60
libinit/init_xiaomi_sky.cpp
Normal file
@@ -0,0 +1,60 @@
|
||||
/*
|
||||
* Copyright (C) 2021-2022 The LineageOS Project
|
||||
*
|
||||
* SPDX-License-Identifier: Apache-2.0
|
||||
*/
|
||||
|
||||
#include <libinit_variant.h>
|
||||
#include <libinit_utils.h>
|
||||
|
||||
#include "vendor_init.h"
|
||||
|
||||
#define FINGERPRINT_POCO_IN "POCO/sky:13/TKQ1.221114.001/V14.0.5.0.TMWINXM:user/release-keys"
|
||||
#define FINGERPRINT_REDMI_IN "Redmi/sky:13/TKQ1.221114.001/V14.0.5.0.TMWINXM:user/release-keys"
|
||||
#define FINGERPRINT_CHINA "Redmi/sky/sky:13/TKQ1.221114.001/V14.0.5.0.TMWINXM:user/release-keys"
|
||||
|
||||
static const variant_info_t sky_poco_info = {
|
||||
.hwc_value = "India",
|
||||
.boardid = "S88019EP1",
|
||||
|
||||
.brand = "POCO",
|
||||
.device = "sky",
|
||||
.marketname = "POCO M6 Pro 5G",
|
||||
.model = "23076PC4BI",
|
||||
.mod_device = "sky_in_global",
|
||||
.build_fingerprint = FINGERPRINT_POCO_IN,
|
||||
};
|
||||
|
||||
static const variant_info_t sky_redmi_info = {
|
||||
.hwc_value = "India",
|
||||
.boardid = "S88018EA1",
|
||||
|
||||
.brand = "Redmi",
|
||||
.device = "sky",
|
||||
.marketname = "Redmi 12 5G",
|
||||
.model = "23076RN4BI",
|
||||
.mod_device = "sky_in_global",
|
||||
.build_fingerprint = FINGERPRINT_REDMI_IN,
|
||||
};
|
||||
|
||||
static const variant_info_t sky_china_info = {
|
||||
.hwc_value = "CN",
|
||||
.boardid = "S88019BA1",
|
||||
|
||||
.brand = "Redmi",
|
||||
.device = "sky",
|
||||
.marketname = "Redmi Note 12R",
|
||||
.model = "23076RA4BC",
|
||||
.mod_device = "sky_global",
|
||||
.build_fingerprint = FINGERPRINT_CHINA,
|
||||
};
|
||||
|
||||
static const std::vector<variant_info_t> variants = {
|
||||
sky_poco_info,
|
||||
sky_redmi_info,
|
||||
sky_china_info,
|
||||
};
|
||||
|
||||
void vendor_load_properties() {
|
||||
search_variant(variants);
|
||||
}
|
||||
67
libinit/libinit_utils.cpp
Normal file
67
libinit/libinit_utils.cpp
Normal file
@@ -0,0 +1,67 @@
|
||||
/*
|
||||
* Copyright (C) 2021 The LineageOS Project
|
||||
*
|
||||
* SPDX-License-Identifier: Apache-2.0
|
||||
*/
|
||||
|
||||
#define _REALLY_INCLUDE_SYS__SYSTEM_PROPERTIES_H_
|
||||
#include <sys/_system_properties.h>
|
||||
#include <vector>
|
||||
|
||||
#include <libinit_utils.h>
|
||||
|
||||
void property_override(std::string prop, std::string value, bool add) {
|
||||
auto pi = (prop_info *) __system_property_find(prop.c_str());
|
||||
if (pi != nullptr) {
|
||||
__system_property_update(pi, value.c_str(), value.length());
|
||||
} else if (add) {
|
||||
__system_property_add(prop.c_str(), prop.length(), value.c_str(), value.length());
|
||||
}
|
||||
}
|
||||
|
||||
std::vector<std::string> ro_props_default_source_order = {
|
||||
"odm.",
|
||||
"product.",
|
||||
"system.",
|
||||
"system_ext.",
|
||||
"vendor.",
|
||||
"",
|
||||
};
|
||||
|
||||
void set_ro_build_prop(const std::string &prop, const std::string &value, bool product) {
|
||||
std::string prop_name;
|
||||
|
||||
for (const auto &source : ro_props_default_source_order) {
|
||||
if (product)
|
||||
prop_name = "ro.product." + source + prop;
|
||||
else
|
||||
prop_name = "ro." + source + "build." + prop;
|
||||
|
||||
property_override(prop_name, value, true);
|
||||
}
|
||||
}
|
||||
|
||||
#define FIND_AND_REMOVE(s, delimiter, variable_name) \
|
||||
std::string variable_name = s.substr(0, s.find(delimiter)); \
|
||||
s.erase(0, s.find(delimiter) + delimiter.length());
|
||||
|
||||
const std::string fingerprint_to_description(const std::string &fingerprint) {
|
||||
const std::string delimiter = "/";
|
||||
const std::string delimiter2 = ":";
|
||||
|
||||
std::string build_fingerprint_copy = fingerprint;
|
||||
|
||||
FIND_AND_REMOVE(build_fingerprint_copy, delimiter, brand)
|
||||
FIND_AND_REMOVE(build_fingerprint_copy, delimiter, product)
|
||||
FIND_AND_REMOVE(build_fingerprint_copy, delimiter2, device)
|
||||
FIND_AND_REMOVE(build_fingerprint_copy, delimiter, platform_version)
|
||||
FIND_AND_REMOVE(build_fingerprint_copy, delimiter, build_id)
|
||||
FIND_AND_REMOVE(build_fingerprint_copy, delimiter2, build_number)
|
||||
FIND_AND_REMOVE(build_fingerprint_copy, delimiter, build_variant)
|
||||
std::string build_version_tags = build_fingerprint_copy;
|
||||
|
||||
const std::string description = product + "-" + build_variant + " " + platform_version +
|
||||
" " + build_id + " " + build_number + " " + build_version_tags;
|
||||
|
||||
return description;
|
||||
}
|
||||
44
libinit/libinit_variant.cpp
Normal file
44
libinit/libinit_variant.cpp
Normal file
@@ -0,0 +1,44 @@
|
||||
/*
|
||||
* Copyright (C) 2021 The LineageOS Project
|
||||
*
|
||||
* SPDX-License-Identifier: Apache-2.0
|
||||
*/
|
||||
|
||||
#include <android-base/logging.h>
|
||||
#include <android-base/properties.h>
|
||||
#include <libinit_utils.h>
|
||||
|
||||
#include <libinit_variant.h>
|
||||
|
||||
using android::base::GetProperty;
|
||||
|
||||
#define HWC_PROP "ro.boot.hwc"
|
||||
#define BOARDID_PROP "ro.boot.boardid"
|
||||
|
||||
void search_variant(const std::vector<variant_info_t> variants) {
|
||||
std::string hwc_value = GetProperty(HWC_PROP, "");
|
||||
std::string boardid = GetProperty(BOARDID_PROP, "");
|
||||
|
||||
for (const auto& variant : variants) {
|
||||
if ((variant.hwc_value == "" || variant.hwc_value == hwc_value) &&
|
||||
(variant.boardid == "" || variant.boardid == boardid)) {
|
||||
set_variant_props(variant);
|
||||
break;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
void set_variant_props(const variant_info_t variant) {
|
||||
set_ro_build_prop("brand", variant.brand, true);
|
||||
set_ro_build_prop("device", variant.device, true);
|
||||
set_ro_build_prop("marketname", variant.marketname, true);
|
||||
set_ro_build_prop("model", variant.model, true);
|
||||
set_ro_build_prop("mod_device", variant.mod_device, true);
|
||||
property_override("vendor.usb.product_string", variant.marketname, true);
|
||||
if (access("/system/bin/recovery", F_OK) != 0) {
|
||||
set_ro_build_prop("fingerprint", variant.build_fingerprint);
|
||||
property_override("ro.bootimage.build.fingerprint", variant.build_fingerprint);
|
||||
property_override("bluetooth.device.default_name", variant.marketname, true);
|
||||
property_override("ro.build.description", fingerprint_to_description(variant.build_fingerprint));
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user