16k: Define PRODUCT_MAX_PAGE_SIZE_SUPPORTED flag
The PRODUCT_MAX_PAGE_SIZE_SUPPORTED will be used to define the
ELF segment alignment of the binaries (executables and shared
libraries). The alignment is set based on these conditions:
- If PRODUCT_MAX_PAGE_SIZE_SUPPORTED is defined, that value will be
used to align the binaries. If not defined, see condition below:
- If it is a low memory device, 4096 will be the alignment. If it is
not low memory device, see conditon below:
- If VSR vendor API level < 34, 4096 will be the alignment, otherwise
it will be 65536.
Test: Built for in Pixel 4a, 6 and verified the alignment with readelf.
Bug: 276963698
Bug: 276801883
Change-Id: I53a8902ab62e6d378aec84c28bc627f0e8a98500
diff --git a/core/config.mk b/core/config.mk
index 5b02569..31826bf 100644
--- a/core/config.mk
+++ b/core/config.mk
@@ -358,6 +358,51 @@
# are specific to the user's build configuration.
include $(BUILD_SYSTEM)/envsetup.mk
+# Returns true if it is a low memory device, otherwise it returns false.
+define is-low-mem-device
+$(if $(findstring ro.config.low_ram=true,$(PRODUCT_PROPERTY_OVERRIDES)),true,\
+$(if $(findstring ro.config.low_ram=true,$(PRODUCT_DEFAULT_PROPERTY_OVERRIDES)),true,\
+$(if $(findstring ro.config.low_ram=true,$(PRODUCT_COMPATIBLE_PROPERTY_OVERRIDE)),true,\
+$(if $(findstring ro.config.low_ram=true,$(PRODUCT_COMPATIBLE_PROPERTY)),true,\
+$(if $(findstring ro.config.low_ram=true,$(PRODUCT_SYSTEM_DEFAULT_PROPERTIES)),true,\
+$(if $(findstring ro.config.low_ram=true,$(PRODUCT_SYSTEM_EXT_PROPERTIES)),true,\
+$(if $(findstring ro.config.low_ram=true,$(PRODUCT_PRODUCT_PROPERTIES)),true,\
+$(if $(findstring ro.config.low_ram=true,$(PRODUCT_VENDOR_PROPERTIES)),true,\
+$(if $(findstring ro.config.low_ram=true,$(PRODUCT_ODM_PROPERTIES)),true,false)))))))))
+endef
+
+# Get the board API level.
+board_api_level := $(PLATFORM_SDK_VERSION)
+ifdef BOARD_API_LEVEL
+ board_api_level := $(BOARD_API_LEVEL)
+else ifdef BOARD_SHIPPING_API_LEVEL
+ # Vendors with GRF must define BOARD_SHIPPING_API_LEVEL for the vendor API level.
+ board_api_level := $(BOARD_SHIPPING_API_LEVEL)
+endif
+
+# Calculate the VSR vendor API level.
+vsr_vendor_api_level := $(board_api_level)
+
+ifdef PRODUCT_SHIPPING_API_LEVEL
+ vsr_vendor_api_level := $(call math_min,$(PRODUCT_SHIPPING_API_LEVEL),$(board_api_level))
+endif
+
+# Set TARGET_MAX_PAGE_SIZE_SUPPORTED.
+ifdef PRODUCT_MAX_PAGE_SIZE_SUPPORTED
+ TARGET_MAX_PAGE_SIZE_SUPPORTED := $(PRODUCT_MAX_PAGE_SIZE_SUPPORTED)
+else ifeq ($(strip $(call is-low-mem-device)),true)
+ # Low memory device will have 4096 binary alignment.
+ TARGET_MAX_PAGE_SIZE_SUPPORTED := 4096
+else
+ # The default binary alignment for userspace is 4096.
+ TARGET_MAX_PAGE_SIZE_SUPPORTED := 4096
+ # When VSR vendor API level >= 34, binary alignment will be 65536.
+ ifeq ($(call math_gt_or_eq,$(vsr_vendor_api_level),34),true)
+ TARGET_MAX_PAGE_SIZE_SUPPORTED := 65536
+ endif
+endif
+.KATI_READONLY := TARGET_MAX_PAGE_SIZE_SUPPORTED
+
# Pruned directory options used when using findleaves.py
# See envsetup.mk for a description of SCAN_EXCLUDE_DIRS
FIND_LEAVES_EXCLUDES := $(addprefix --prune=, $(SCAN_EXCLUDE_DIRS) .repo .git)