diff --git a/Android.mk b/Android.mk new file mode 100644 index 0000000..20bfbaf --- /dev/null +++ b/Android.mk @@ -0,0 +1,28 @@ +# +# Copyright (C) 2011 The Android Open-Source Project +# +# Licensed under the Apache License, Version 2.0 (the "License"); +# you may not use this file except in compliance with the License. +# You may obtain a copy of the License at +# +# http://www.apache.org/licenses/LICENSE-2.0 +# +# Unless required by applicable law or agreed to in writing, software +# distributed under the License is distributed on an "AS IS" BASIS, +# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +# See the License for the specific language governing permissions and +# limitations under the License. +# + +# WARNING: Everything listed here will be built on ALL platforms, +# including x86, the emulator, and the SDK. Modules must be uniquely +# named (liblights.panda), and must build everywhere, or limit themselves +# to only building on ARM if they include assembly. Individual makefiles +# are responsible for having their own logic, for fine-grained control. + +LOCAL_PATH := $(call my-dir) + +# if some modules are built directly from this directory (not subdirectories), +# their rules should be written here. + +include $(call all-makefiles-under,$(LOCAL_PATH)) diff --git a/build/core/certs.mk b/build/core/certs.mk new file mode 100644 index 0000000..f00e275 --- /dev/null +++ b/build/core/certs.mk @@ -0,0 +1,5 @@ +# Allow custom build keys +ifneq (${ROM_KEYS_PATH},) + PRODUCT_DEFAULT_DEV_CERTIFICATE := ${ROM_KEYS_PATH}/releasekey + PRODUCT_EXTRA_RECOVERY_KEYS := $(PRODUCT_DEFAULT_DEV_CERTIFICATE) +endif diff --git a/build/core/qcom_target.mk b/build/core/qcom_target.mk new file mode 100644 index 0000000..ef3a091 --- /dev/null +++ b/build/core/qcom_target.mk @@ -0,0 +1,27 @@ +# Bring in Qualcomm helper macros +include vendor/twrp/build/core/qcom_utils.mk + +# Target-specific configuration +ifeq ($(BOARD_USES_QCOM_HARDWARE),true) + qcom_flags := -DQCOM_HARDWARE + ifeq ($(TARGET_USES_QCOM_BSP),true) + qcom_flags += -DQCOM_BSP + qcom_flags += -DQTI_BSP + endif + +# TARGET_GLOBAL_CFLAGS += $(qcom_flags) +# TARGET_GLOBAL_CPPFLAGS += $(qcom_flags) + PRIVATE_TARGET_GLOBAL_CFLAGS += $(qcom_flags) + PRIVATE_TARGET_GLOBAL_CPPFLAGS += $(qcom_flags) + + # Multiarch needs these too.. +# 2ND_TARGET_GLOBAL_CFLAGS += $(qcom_flags) +# 2ND_TARGET_GLOBAL_CPPFLAGS += $(qcom_flags) +# 2ND_CLANG_TARGET_GLOBAL_CFLAGS += $(qcom_flags) +# 2ND_CLANG_TARGET_GLOBAL_CPPFLAGS += $(qcom_flags) + + TARGET_COMPILE_WITH_MSM_KERNEL := true + MSM_VIDC_TARGET_LIST := msm8974 msm8610 msm8226 apq8084 msm8916 msm8937 msm8952 msm8953 msm8994 msm8909 msm8992 msm8996 msm8998 sdm660 sdm710 sdm845 +endif + + diff --git a/build/core/qcom_utils.mk b/build/core/qcom_utils.mk new file mode 100755 index 0000000..9c11c18 --- /dev/null +++ b/build/core/qcom_utils.mk @@ -0,0 +1,242 @@ +# Board platforms lists to be used for +# TARGET_BOARD_PLATFORM specific featurization +QCOM_BOARD_PLATFORMS := msm7627_surf +QCOM_BOARD_PLATFORMS += msm7627_6x +QCOM_BOARD_PLATFORMS += msm7627a +QCOM_BOARD_PLATFORMS += msm7630_surf +QCOM_BOARD_PLATFORMS += msm7630_fusion +QCOM_BOARD_PLATFORMS += msm8226 +QCOM_BOARD_PLATFORMS += msm8660 +QCOM_BOARD_PLATFORMS += msm8909 +QCOM_BOARD_PLATFORMS += msm8916 +QCOM_BOARD_PLATFORMS += msm8939 +QCOM_BOARD_PLATFORMS += msm8937 +QCOM_BOARD_PLATFORMS += msm8952 +QCOM_BOARD_PLATFORMS += msm8953 +QCOM_BOARD_PLATFORMS += msm8960 +QCOM_BOARD_PLATFORMS += msm8974 +QCOM_BOARD_PLATFORMS += msm8992 +QCOM_BOARD_PLATFORMS += msm8994 +QCOM_BOARD_PLATFORMS += msm8996 +QCOM_BOARD_PLATFORMS += msm8998 +QCOM_BOARD_PLATFORMS += apq8084 +QCOM_BOARD_PLATFORMS += sdm660 +QCOM_BOARD_PLATFORMS += sdm710 +QCOM_BOARD_PLATFORMS += sdm845 + +MSM7K_BOARD_PLATFORMS := msm7630_surf +MSM7K_BOARD_PLATFORMS += msm7630_fusion +MSM7K_BOARD_PLATFORMS += msm7627_surf +MSM7K_BOARD_PLATFORMS += msm7627_6x +MSM7K_BOARD_PLATFORMS += msm7627a +MSM7K_BOARD_PLATFORMS += msm7k + +QSD8K_BOARD_PLATFORMS := qsd8k + + +# vars for use by utils +empty := +space := $(empty) $(empty) +colon := $(empty):$(empty) +underscore := $(empty)_$(empty) + +# $(call match-word,w1,w2) +# checks if w1 == w2 +# How it works +# if (w1-w2 not empty or w2-w1 not empty) then not_match else match +# +# returns true or empty +#$(warning :$(1): :$(2): :$(subst $(1),,$(2)):) \ +#$(warning :$(2): :$(1): :$(subst $(2),,$(1)):) \ +# +define match-word +$(strip \ + $(if $(or $(subst $(1),$(empty),$(2)),$(subst $(2),$(empty),$(1))),,true) \ +) +endef + +# $(call find-word-in-list,w,wlist) +# finds an exact match of word w in word list wlist +# +# How it works +# fill wlist spaces with colon +# wrap w with colon +# search word w in list wl, if found match m, return stripped word w +# +# returns stripped word or empty +define find-word-in-list +$(strip \ + $(eval wl:= $(colon)$(subst $(space),$(colon),$(strip $(2)))$(colon)) \ + $(eval w:= $(colon)$(strip $(1))$(colon)) \ + $(eval m:= $(findstring $(w),$(wl))) \ + $(if $(m),$(1),) \ +) +endef + +# $(call match-word-in-list,w,wlist) +# does an exact match of word w in word list wlist +# How it works +# if the input word is not empty +# return output of an exact match of word w in wordlist wlist +# else +# return empty +# returns true or empty +define match-word-in-list +$(strip \ + $(if $(strip $(1)), \ + $(call match-word,$(call find-word-in-list,$(1),$(2)),$(strip $(1))), \ + ) \ +) +endef + +# $(call match-prefix,p,delim,w/wlist) +# matches prefix p in wlist using delimiter delim +# +# How it works +# trim the words in wlist w +# if find-word-in-list returns not empty +# return true +# else +# return empty +# +define match-prefix +$(strip \ + $(eval w := $(strip $(1)$(strip $(2)))) \ + $(eval text := $(patsubst $(w)%,$(1),$(3))) \ + $(if $(call match-word-in-list,$(1),$(text)),true,) \ +) +endef + +# ---- +# The following utilities are meant for board platform specific +# featurisation + +# $(call get-vendor-board-platforms,v) +# returns list of board platforms for vendor v +define get-vendor-board-platforms +$($(1)_BOARD_PLATFORMS) +endef + +# $(call is-board-platform,bp) +# returns true or empty +define is-board-platform +$(call match-word,$(1),$(TARGET_BOARD_PLATFORM)) +endef + +# $(call is-not-board-platform,bp) +# returns true or empty +define is-not-board-platform +$(if $(call match-word,$(1),$(TARGET_BOARD_PLATFORM)),,true) +endef + +# $(call is-board-platform-in-list,bpl) +# returns true or empty +define is-board-platform-in-list +$(call match-word-in-list,$(TARGET_BOARD_PLATFORM),$(1)) +endef + +# $(call is-vendor-board-platform,vendor) +# returns true or empty +define is-vendor-board-platform +$(strip \ + $(call match-word-in-list,$(TARGET_BOARD_PLATFORM),\ + $(call get-vendor-board-platforms,$(1)) \ + ) \ +) +endef + +# $(call is-chipset-in-board-platform,chipset) +# does a prefix match of chipset in TARGET_BOARD_PLATFORM +# uses underscore as a delimiter +# +# returns true or empty +define is-chipset-in-board-platform +$(call match-prefix,$(1),$(underscore),$(TARGET_BOARD_PLATFORM)) +endef + +# $(call is-chipset-prefix-in-board-platform,prefix) +# does a chipset prefix match in TARGET_BOARD_PLATFORM +# assumes '_' and 'a' as the delimiter to the chipset prefix +# +# How it works +# if ($(prefix)_ or $(prefix)a match in board platform) +# return true +# else +# return empty +# +define is-chipset-prefix-in-board-platform +$(strip \ + $(eval delim_a := $(empty)a$(empty)) \ + $(if \ + $(or \ + $(call match-prefix,$(1),$(delim_a),$(TARGET_BOARD_PLATFORM)), \ + $(call match-prefix,$(1),$(underscore),$(TARGET_BOARD_PLATFORM)), \ + ), \ + true, \ + ) \ +) +endef + +#---- +# The following utilities are meant for Android Code Name +# specific featurisation +# +# refer http://source.android.com/source/build-numbers.html +# for code names and associated sdk versions +CUPCAKE_SDK_VERSIONS := 3 +DONUT_SDK_VERSIONS := 4 +ECLAIR_SDK_VERSIONS := 5 6 7 +FROYO_SDK_VERSIONS := 8 +GINGERBREAD_SDK_VERSIONS := 9 10 +HONEYCOMB_SDK_VERSIONS := 11 12 13 +ICECREAM_SANDWICH_SDK_VERSIONS := 14 15 +JELLY_BEAN_SDK_VERSIONS := 16 17 18 +KITKAT_SDK_VERSIONS := 19 +LOLLIPOP_SDK_VERSIONS := 21 22 +MARSHMALLOW_SDK_VERSIONS := 23 +NOUGAT_SDK_VERSIONS := 24 25 +OREO_SDK_VERSIONS := 26 + +# $(call is-platform-sdk-version-at-least,version) +# version is a numeric SDK_VERSION defined above +define is-platform-sdk-version-at-least +$(strip \ + $(if $(filter 1,$(shell echo "$$(( $(PLATFORM_SDK_VERSION) >= $(1) ))" )), \ + true, \ + ) \ +) +endef + +# $(call is-android-codename,codename) +# codename is one of cupcake,donut,eclair,froyo,gingerbread,icecream +# please refer the $(codename)_SDK_VERSIONS declared above +define is-android-codename +$(strip \ + $(if \ + $(call match-word-in-list,$(PLATFORM_SDK_VERSION),$($(1)_SDK_VERSIONS)), \ + true, \ + ) \ +) +endef + +# $(call is-android-codename-in-list,cnlist) +# cnlist is combination/list of android codenames +define is-android-codename-in-list +$(strip \ + $(eval acn := $(empty)) \ + $(foreach \ + i,$(1),\ + $(eval acn += \ + $(if \ + $(call \ + match-word-in-list,\ + $(PLATFORM_SDK_VERSION),\ + $($(i)_SDK_VERSIONS)\ + ),\ + true,\ + )\ + )\ + ) \ + $(if $(strip $(acn)),true,) \ +) +endef diff --git a/build/envsetup.sh b/build/envsetup.sh new file mode 100755 index 0000000..6c91704 --- /dev/null +++ b/build/envsetup.sh @@ -0,0 +1,152 @@ +function __print_build_functions_help() { +cat < /dev/null` + do + echo "including $f" + . $f + done + unset f + + if [ $# -eq 0 ]; then + # No arguments, so let's have the full menu + lunch + else + echo "z$target" | grep -q "-" + if [ $? -eq 0 ]; then + # A buildtype was specified, assume a full device name + lunch $target + else + # This is probably just the model name + if [ -z "$variant" ]; then + variant="userdebug" + fi + lunch twrp_$target-$variant + fi + fi + return $? +} + +alias bib=breakfast + +function fixup_common_out_dir() { + common_out_dir=$(get_build_var OUT_DIR)/target/common + target_device=$(get_build_var TARGET_DEVICE) + if [ ! -z $ANDROID_FIXUP_COMMON_OUT ]; then + if [ -d ${common_out_dir} ] && [ ! -L ${common_out_dir} ]; then + mv ${common_out_dir} ${common_out_dir}-${target_device} + ln -s ${common_out_dir}-${target_device} ${common_out_dir} + else + [ -L ${common_out_dir} ] && rm ${common_out_dir} + mkdir -p ${common_out_dir}-${target_device} + ln -s ${common_out_dir}-${target_device} ${common_out_dir} + fi + else + [ -L ${common_out_dir} ] && rm ${common_out_dir} + mkdir -p ${common_out_dir} + fi +} + +# Make using all available CPUs +function mka() { + m "$@" +} + +function pushboot() { + if [ ! -f $OUT/$* ]; then + echo "File not found: $OUT/$*" + return 1 + fi + + adb root + sleep 1 + adb wait-for-device + adb remount + + adb push $OUT/$* /$* + adb reboot +} + +function repopick() { + set_stuff_for_environment + T=$(gettop) + $T/vendor/twrp/build/tools/repopick.py $@ +} + +function aospremote() +{ + if ! git rev-parse --git-dir &> /dev/null + then + echo ".git directory not found. Please run this from the root directory of the Android repository you wish to set up." + return 1 + fi + git remote rm aosp 2> /dev/null + local PROJECT=$(pwd -P | sed -e "s#$ANDROID_BUILD_TOP\/##; s#-caf.*##; s#\/default##") + # Google moved the repo location in Oreo + if [ $PROJECT = "build/make" ] + then + PROJECT="build" + fi + if (echo $PROJECT | grep -qv "^device") + then + local PFX="platform/" + fi + git remote add aosp https://android.googlesource.com/$PFX$PROJECT + echo "Remote 'aosp' created" +} + +function cafremote() +{ + if ! git rev-parse --git-dir &> /dev/null + then + echo ".git directory not found. Please run this from the root directory of the Android repository you wish to set up." + return 1 + fi + git remote rm caf 2> /dev/null + local PROJECT=$(pwd -P | sed -e "s#$ANDROID_BUILD_TOP\/##; s#-caf.*##; s#\/default##") + # Google moved the repo location in Oreo + if [ $PROJECT = "build/make" ] + then + PROJECT="build" + fi + if [[ $PROJECT =~ "qcom/opensource" ]]; + then + PROJECT=$(echo $PROJECT | sed -e "s#qcom\/opensource#qcom-opensource#") + fi + if (echo $PROJECT | grep -qv "^device") + then + local PFX="platform/" + fi + git remote add caf https://source.codeaurora.org/quic/la/$PFX$PROJECT + echo "Remote 'caf' created" +} + +# Enable SD-LLVM if available +if [ -d $(gettop)/vendor/qcom/sdclang ]; then + export SDCLANG=true + export SDCLANG_PATH="vendor/qcom/sdclang/4.0.2/prebuilt/linux-x86_64/bin" + export SDCLANG_LTO_DEFS="vendor/qcom/sdclang/sdllvm-lto-defs.mk" + export SDCLANG_CONFIG="vendor/qcom/sdclang/sdclang.json" + export SDCLANG_AE_CONFIG="vendor/qcom/sdclang/sdclangAE.json" +fi + +# Empty the vts makefile +if [ -s $(gettop)/frameworks/base/services/core/xsd/vts/Android.mk ]; then + echo -n "" > $(gettop)/frameworks/base/services/core/xsd/vts/Android.mk +fi diff --git a/build/soong/Android.bp b/build/soong/Android.bp new file mode 100644 index 0000000..78123c5 --- /dev/null +++ b/build/soong/Android.bp @@ -0,0 +1,85 @@ +// TWRP soong configs + +bootstrap_go_package { + name: "soong-twrp-generator", + pkgPath: "twrp/soong/generator", + deps: [ + "blueprint", + "blueprint-pathtools", + "soong", + "soong-android", + "soong-shared", + ], + srcs: [ + "generator/generator.go", + "generator/variables.go", + ], + pluginFor: ["soong_build"], +} + +twrp_generator { + name: "generated_kernel_includes", + + // The headers make command + cmd: "$(PATH_OVERRIDE_SOONG) $(KERNEL_MAKE_CMD) $(KERNEL_MAKE_FLAGS) -C $(TARGET_KERNEL_HEADERS_SOURCE) O=$(KERNEL_BUILD_OUT_PREFIX)$(genDir) ARCH=$(KERNEL_ARCH) $(KERNEL_CROSS_COMPILE) headers_install", + + // Directories that can be imported by a cc_* module generated_headers property + export_include_dirs: [ + "usr/audio/include/uapi", + "usr/include", + "usr/include/audio/include/uapi", + "usr/techpack/audio/include", + ], + + // Sources for dependency tracking + dep_root: "$(TARGET_KERNEL_HEADERS_SOURCE)", + dep_files: [ + "Makefile", + "include/**/*", + "arch/$(KERNEL_ARCH)/include/**/*", + "techpack/audio/include/**/*", + ], +} + +cc_library_headers { + name: "generated_kernel_headers", + generated_headers: ["generated_kernel_includes"], + export_generated_headers: ["generated_kernel_includes"], + vendor_available: true, + recovery_available: true, +} + +soong_config_module_type { + name: "vendor_init", + module_type: "cc_defaults", + config_namespace: "twrpGlobalVars", + value_variables: ["target_init_vendor_lib"], + properties: ["whole_static_libs"], +} + +vendor_init { + name: "vendor_init_defaults", + soong_config_variables: { + target_init_vendor_lib: { + whole_static_libs: ["%s"], + }, + }, +} + +soong_config_module_type { + name: "enforce_ab_ota_partition_list", + module_type: "cc_defaults", + config_namespace: "twrpGlobalVars", + bool_variables: ["target_enforce_ab_ota_partition_list"], + properties: ["cflags"], +} + +enforce_ab_ota_partition_list { + name: "enforce_ab_ota_partition_list_defaults", + soong_config_variables: { + target_enforce_ab_ota_partition_list: { + cflags: ["-DTARGET_ENFORCE_AB_OTA_PARTITION_LIST"], + }, + }, +} + diff --git a/build/soong/generator/generator.go b/build/soong/generator/generator.go new file mode 100644 index 0000000..9ee0e7a --- /dev/null +++ b/build/soong/generator/generator.go @@ -0,0 +1,296 @@ +// Copyright 2015 Google Inc. All rights reserved. +// Copyright (C) 2018,2021 The LineageOS Project +// +// Licensed under the Apache License, Version 2.0 (the "License"); +// you may not use this file except in compliance with the License. +// You may obtain a copy of the License at +// +// http://www.apache.org/licenses/LICENSE-2.0 +// +// Unless required by applicable law or agreed to in writing, software +// distributed under the License is distributed on an "AS IS" BASIS, +// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +// See the License for the specific language governing permissions and +// limitations under the License. + +package generator + +import ( + "fmt" + "strings" + + "github.com/google/blueprint" + "github.com/google/blueprint/bootstrap" + "github.com/google/blueprint/proptools" + + "android/soong/android" + "path/filepath" +) + +func init() { + android.RegisterModuleType("twrp_generator", GeneratorFactory) +} + +var String = proptools.String + +var ( + pctx = android.NewPackageContext("android/soong/generator") +) + +type HostToolProvider interface { + HostToolPath() android.OptionalPath +} + +type hostToolDependencyTag struct { + blueprint.BaseDependencyTag +} + +var hostToolDepTag hostToolDependencyTag + +type generatorProperties struct { + // The command to run on one or more input files. Cmd supports substitution of a few variables + // (the actual substitution is implemented in GenerateAndroidBuildActions below) + // + // Available variables for substitution: + // + // $(location): the path to the first entry in tools or tool_files + // $(location