2021-09-15 10:26:37 -04:00
|
|
|
#!/bin/bash
|
2024-04-22 07:48:54 -04:00
|
|
|
#DivestOS: A mobile operating system divested from the norm.
|
|
|
|
#Copyright (c) 2017-2023 Divested Computing Group
|
2021-09-15 10:26:37 -04:00
|
|
|
#
|
|
|
|
#This program is free software: you can redistribute it and/or modify
|
|
|
|
#it under the terms of the GNU General Public License as published by
|
|
|
|
#the Free Software Foundation, either version 3 of the License, or
|
|
|
|
#(at your option) any later version.
|
|
|
|
#
|
|
|
|
#This program is distributed in the hope that it will be useful,
|
|
|
|
#but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
|
|
#MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
|
|
|
#GNU General Public License for more details.
|
|
|
|
#
|
|
|
|
#You should have received a copy of the GNU General Public License
|
|
|
|
#along with this program. If not, see <https://www.gnu.org/licenses/>.
|
2021-10-16 19:15:19 -04:00
|
|
|
umask 0022;
|
2021-10-16 15:28:15 -04:00
|
|
|
set -euo pipefail;
|
2021-10-16 19:15:19 -04:00
|
|
|
source "$DOS_SCRIPTS_COMMON/Shell.sh";
|
2021-09-15 10:26:37 -04:00
|
|
|
|
2021-09-15 11:48:07 -04:00
|
|
|
echo "Post tweaks...";
|
|
|
|
|
2021-09-15 10:26:37 -04:00
|
|
|
#Workaround broken MSM_DLOAD_MODE=y+PANIC_ON_OOPS=y for devices that oops on shutdown
|
|
|
|
#MSM_DLOAD_MODE can't be disabled as it breaks compile
|
|
|
|
sed -i 's/set_dload_mode(in_panic)/set_dload_mode(0)/' kernel/*/*/arch/arm/mach-msm/restart.c &>/dev/null || true;
|
|
|
|
|
2023-07-14 17:35:48 -04:00
|
|
|
#Increase power efficiency of KSM
|
|
|
|
sed -i 's/bool use_deferred_timer;/bool use_deferred_timer = true;/' kernel/*/*/mm/ksm.c &>/dev/null || true;
|
|
|
|
sed -i 's/unsigned int ksm_thread_sleep_millisecs = 20;/unsigned int ksm_thread_sleep_millisecs = 500;/' kernel/*/*/mm/ksm.c &>/dev/null || true;
|
2023-07-14 15:45:35 -04:00
|
|
|
|
2023-07-14 17:35:48 -04:00
|
|
|
if [ "$DOS_USE_KSM" = true ]; then
|
|
|
|
#Enable slub/slab merging
|
2023-07-14 15:45:35 -04:00
|
|
|
sed -i 's/static int slub_nomerge;/static int slub_nomerge = 0;/' kernel/*/*/mm/slub.c &>/dev/null || true; #2.6.22-3.17
|
|
|
|
sed -i 's/static int slab_nomerge;/static int slab_nomerge = 0;/' kernel/*/*/mm/slab_common.c &>/dev/null || true; #3.18-4.12
|
|
|
|
sed -i 's/static bool slab_nomerge = !IS_ENABLED(CONFIG_SLAB_MERGE_DEFAULT);/static bool slab_nomerge = false;/' kernel/*/*/mm/slab_common.c &>/dev/null || true; #4.13+
|
|
|
|
sed -i 's/static bool slab_nomerge __ro_after_init = !IS_ENABLED(CONFIG_SLAB_MERGE_DEFAULT);/static bool slab_nomerge __ro_after_init = false;/' kernel/*/*/mm/slab_common.c &>/dev/null || true; #4.13+
|
2024-05-09 12:23:17 -04:00
|
|
|
sed -i 's/static bool slab_nomerge __ro_after_init = !IS_ENABLED(CONFIG_SLAB_MERGE_DEFAULT);/static bool slab_nomerge __ro_after_init = false;/' kernel/*/*/*/*/mm/slab_common.c &>/dev/null || true; #4.13+
|
2023-07-14 15:45:35 -04:00
|
|
|
else
|
|
|
|
#Disable slub/slab merging
|
|
|
|
sed -i 's/static int slub_nomerge;/static int slub_nomerge = 1;/' kernel/*/*/mm/slub.c &>/dev/null || true; #2.6.22-3.17
|
|
|
|
sed -i 's/static int slab_nomerge;/static int slab_nomerge = 1;/' kernel/*/*/mm/slab_common.c &>/dev/null || true; #3.18-4.12
|
|
|
|
sed -i 's/static bool slab_nomerge = !IS_ENABLED(CONFIG_SLAB_MERGE_DEFAULT);/static bool slab_nomerge = true;/' kernel/*/*/mm/slab_common.c &>/dev/null || true; #4.13+
|
|
|
|
sed -i 's/static bool slab_nomerge __ro_after_init = !IS_ENABLED(CONFIG_SLAB_MERGE_DEFAULT);/static bool slab_nomerge __ro_after_init = true;/' kernel/*/*/mm/slab_common.c &>/dev/null || true; #4.13+
|
2024-05-09 12:23:17 -04:00
|
|
|
sed -i 's/static bool slab_nomerge __ro_after_init = !IS_ENABLED(CONFIG_SLAB_MERGE_DEFAULT);/static bool slab_nomerge __ro_after_init = true;/' kernel/*/*/*/*/mm/slab_common.c &>/dev/null || true; #4.13+
|
2023-07-14 15:45:35 -04:00
|
|
|
fi;
|
2023-07-13 11:24:46 -04:00
|
|
|
|
2024-05-09 12:16:25 -04:00
|
|
|
#Enable BPF JIT hardening
|
|
|
|
sed -i 's/int bpf_jit_harden __read_mostly;/int bpf_jit_harden __read_mostly = 2;/' kernel/*/*/kernel/bpf/core.c &>/dev/null || true;
|
2024-05-09 12:23:17 -04:00
|
|
|
sed -i 's/int bpf_jit_harden __read_mostly;/int bpf_jit_harden __read_mostly = 2;/' kernel/*/*/*/*/kernel/bpf/core.c &>/dev/null || true;
|
2024-05-09 12:16:25 -04:00
|
|
|
sed -i 's/int bpf_jit_harden __read_mostly;/int bpf_jit_harden __read_mostly = 2;/' kernel/*/*/kernel/bpf/core.c &>/dev/null || true;
|
|
|
|
|
2021-09-15 11:48:07 -04:00
|
|
|
#Enable page poisoning
|
|
|
|
#Commented as set by defconfig
|
|
|
|
#sed -i 's/= IS_ENABLED(CONFIG_PAGE_POISONING_ENABLE_DEFAULT);/= true;/' kernel/*/*/mm/page_poison.c &>/dev/null || true; #4.4+ #XXX: shouldn't be enabled past 5.3
|
|
|
|
|
2022-04-05 20:41:01 -04:00
|
|
|
#Build speedup
|
2023-03-08 00:22:01 -05:00
|
|
|
[[ -f build/soong/cc/tidy.go ]] && sed -i 's/flags.Tidy = true/flags.Tidy = false/' build/soong/cc/tidy.go; #Disable clang-tidy (kdrag0n)
|
2022-04-05 20:41:01 -04:00
|
|
|
|
2022-04-12 16:44:53 -04:00
|
|
|
#Reduce memory usage
|
|
|
|
awk -i inplace '!/persist.device_config.runtime_native.usap_pool_enabled=true/' device/*/*/*.prop &>/dev/null || true;
|
|
|
|
awk -i inplace '!/config_pinnerCameraApp/' device/*/*/overlay/frameworks/base/core/res/res/values/config.xml &>/dev/null || true;
|
|
|
|
|
2023-07-13 11:24:46 -04:00
|
|
|
#Allow Work Profiles in low_ram mode
|
|
|
|
sed -i '/android.software.managed_users/s/notLowRam="true"//' frameworks/native/data/etc/handheld_core_hardware.xml || true;
|
|
|
|
|
2021-09-15 11:48:07 -04:00
|
|
|
cd "$DOS_BUILD_BASE";
|
2021-10-16 15:28:15 -04:00
|
|
|
echo -e "\e[0;32m[SCRIPT COMPLETE] Post tweaks complete\e[0m";
|