diff options
author | Alexander Koskovich <zvnexus@outlook.com> | 2020-09-19 22:46:54 -0700 |
---|---|---|
committer | alk3pInjection <webmaster@raspii.tech> | 2022-01-16 08:24:08 +0800 |
commit | 274938fb7853f337a60c0c1bcadf7c2795c7ac10 (patch) | |
tree | 9f71c4a2d32d62bf1d89abc79054038e6ed2a643 | |
parent | 0477a29ba8886b814a3ad66165dd9cb50e15bfe1 (diff) |
common: Add a couple makefiles from LA.UM.9.14.r1-18600.02-LAHAINA.QSSI12.0
* DLKM for kernel modules, and a task to generate extra
images, e.g. DTBO.
Change-Id: I9dceb8c786af6e42b4160a8e12f94b1d03df49ce
-rw-r--r-- | dlkm/AndroidKernelModule.mk | 222 | ||||
-rw-r--r-- | dlkm/Build_external_kernelmodule.mk | 118 | ||||
-rw-r--r-- | generate_extra_images.mk | 272 |
3 files changed, 612 insertions, 0 deletions
diff --git a/dlkm/AndroidKernelModule.mk b/dlkm/AndroidKernelModule.mk new file mode 100644 index 0000000..2d2ddad --- /dev/null +++ b/dlkm/AndroidKernelModule.mk @@ -0,0 +1,222 @@ +# Get the number of CPU cores. This is the number of parallel jobs to be passed to make command. +NCORES := $(shell grep -c ^processor /proc/cpuinfo) +ifeq ($(NCORES),) + NCORES := 8 +endif + +DISABLE_THIS_DLKM := $(strip $(TARGET_KERNEL_DLKM_DISABLE)) + +ifeq ($(DISABLE_THIS_DLKM),true) +ifneq (,$(filter $(LOCAL_MODULE),$(TARGET_KERNEL_DLKM_OVERRIDE))) + DISABLE_THIS_DLKM = false +else +endif +endif + +ifeq ($(DISABLE_THIS_DLKM),true) +$(warning DLKM '$(LOCAL_MODULE)' disabled for target) +else + +# Assign external kernel modules to the DLKM class +LOCAL_MODULE_CLASS := DLKM + +# Set the default install path to system/lib/modules +LOCAL_MODULE_PATH := $(strip $(LOCAL_MODULE_PATH)) +ifeq ($(LOCAL_MODULE_PATH),) + LOCAL_MODULE_PATH := $(TARGET_OUT)/lib/modules +endif +GKI_LOCAL_MODULE := $(LOCAL_MODULE_PATH)/gki/$(LOCAL_MODULE) + +# Set the default Kbuild file path to LOCAL_PATH +KBUILD_FILE := $(strip $(KBUILD_FILE)) +ifeq ($(KBUILD_FILE),) + KBUILD_FILE := $(LOCAL_PATH)/Kbuild +endif + +# Get rid of any whitespace +LOCAL_MODULE_KBUILD_NAME := $(strip $(LOCAL_MODULE_KBUILD_NAME)) + +include $(BUILD_SYSTEM)/base_rules.mk + +# Intermediate directory where the kernel modules are created +# by the kernel build system. Ideally this would be the same +# directory as LOCAL_BUILT_MODULE, but because we're using +# relative paths for both O= and M=, we don't have much choice +KBUILD_OUT_DIR := $(TARGET_OUT_INTERMEDIATES)/$(LOCAL_PATH) +KBUILD_OUT_DIR_GKI := $(TARGET_OUT_INTERMEDIATES)/$(LOCAL_PATH)/gki + +# The kernel build system doesn't support parallel kernel module builds +# that share the same output directory. Thus, in order to build multiple +# kernel modules that reside in a single directory (and therefore have +# the same output directory), there must be just one invocation of the +# kernel build system that builds all the modules of a given directory. +# +# Therefore, all kernel modules must depend on the same, unique target +# that invokes the kernel build system and builds all of the modules +# for the directory. The $(KBUILD_TARGET) target serves this purpose. +KBUILD_TARGET := $(KBUILD_OUT_DIR)/buildko.timestamp +KBUILD_TARGET_GKI := $(KBUILD_OUT_DIR_GKI)/buildko.timestamp + +# Path to the intermediate location where the kernel build +# system creates the kernel module. +KBUILD_MODULE := $(KBUILD_OUT_DIR)/$(LOCAL_MODULE) +KBUILD_MODULE_GKI := $(KBUILD_OUT_DIR_GKI)/$(LOCAL_MODULE) + +# Maintain separate kbuild options for gki compilation. +# Default back to KBUILD_OPTIONS +ifeq "$(KBUILD_OPTIONS_GKI)" "" +KBUILD_OPTIONS_GKI := $(KBUILD_OPTIONS) +endif + +# Since we only invoke the kernel build system once per directory, +# each kernel module must depend on the same target. +$(KBUILD_MODULE): kbuild_out := $(KBUILD_OUT_DIR)/$(LOCAL_MODULE_KBUILD_NAME) +$(KBUILD_MODULE): $(KBUILD_TARGET) +$(KBUILD_MODULE): $(LOCAL_ADDITIONAL_DEPENDENCIES) +ifneq "$(LOCAL_MODULE_KBUILD_NAME)" "" + mv -f $(kbuild_out) $@ +endif + +# To ensure KERNEL_OUT and TARGET_PREBUILT_INT_KERNEL are defined, +# kernel_definitions.mk must be included. While m and regular +# make builds will include kernel_definitions.mk, mm and mmm builds +# do not. Therefore, we need to explicitly include kernel_definitions.mk. +# It is safe to include it more than once because the entire file is +# guarded by "ifeq ($(TARGET_PREBUILT_KERNEL),) ... endif". +# If the kernel_definitions.mk is not found, fallback to the AndroidKernel.mk +ifneq ($(wildcard device/qcom/kernelscripts/kernel_definitions.mk),) +TARGET_KERNEL_PATH := device/qcom/kernelscripts/kernel_definitions.mk +else +TARGET_KERNEL_PATH := $(TARGET_KERNEL_SOURCE)/AndroidKernel.mk +endif +include $(TARGET_KERNEL_PATH) + +# Simply copy the kernel module from where the kernel build system +# created it to the location where the Android build system expects it. +# If LOCAL_MODULE_DEBUG_ENABLE is set, strip debug symbols. So that, +# the final images generated by ABS will have the stripped version of +# the modules +ifeq ($(TARGET_KERNEL_VERSION),3.18) + MODULE_SIGN_FILE := perl ./$(TARGET_KERNEL_SOURCE)/scripts/sign-file + MODSECKEY := $(KERNEL_OUT)/signing_key.priv + MODPUBKEY := $(KERNEL_OUT)/signing_key.x509 +else + MODULE_SIGN_FILE := $(KERNEL_OUT)/scripts/sign-file + MODSECKEY := $(KERNEL_OUT)/certs/signing_key.pem + MODPUBKEY := $(KERNEL_OUT)/certs/signing_key.x509 +endif + +# Define a function for signing the module +define sign_module + mkdir -p $(dir $2) + cp $1 $1.unstripped + $(TARGET_STRIP) --strip-debug $1 + cp $1 $1.stripped + @sh -c "\ + KMOD_SIG_ALL=`cat $3/.config | grep CONFIG_MODULE_SIG_ALL | cut -d'=' -f2`; \ + KMOD_SIG_HASH=`cat $3/.config | grep CONFIG_MODULE_SIG_HASH | cut -d'=' -f2 | sed 's/\"//g'`; \ + if [ \"\$$KMOD_SIG_ALL\" = \"y\" ] && [ -n \"\$$KMOD_SIG_HASH\" ]; then \ + echo \"Signing kernel module: \" `basename $1`; \ + cp $1 $1.unsigned; \ + $(MODULE_SIGN_FILE) \$$KMOD_SIG_HASH $(MODSECKEY) $(MODPUBKEY) $1; \ + fi; \ + " +endef + +$(LOCAL_BUILT_MODULE): local_module_gki := $(GKI_LOCAL_MODULE) +$(LOCAL_BUILT_MODULE): $(KBUILD_MODULE) $(GKI_LOCAL_MODULE) | $(ACP) + $(call sign_module, $<, $@, $(KERNEL_OUT)) + $(transform-prebuilt-to-target) + + +# Ensure the kernel module created by the kernel build system, as +# well as all the other intermediate files, are removed during a clean. +$(cleantarget): PRIVATE_CLEAN_FILES := $(PRIVATE_CLEAN_FILES) $(KBUILD_OUT_DIR) + +# Add a separate target for gki which can be invoked from +# kernel_defintions.mk. This target will be invoked to compile gki modules +# for qgki builds. +$(GKI_LOCAL_MODULE): kbuild_module_gki := $(KBUILD_MODULE_GKI) +$(GKI_LOCAL_MODULE): kbuild_out_gki := $(KBUILD_OUT_DIR_GKI)/$(LOCAL_MODULE_KBUILD_NAME) +$(GKI_LOCAL_MODULE): $(KBUILD_TARGET_GKI) +ifneq ($(GKI_KERNEL_OUT),) +ifneq "$(LOCAL_MODULE_KBUILD_NAME)" "" + mv -f $(kbuild_out_gki) $(kbuild_module_gki) +endif + $(call sign_module, $(kbuild_module_gki), $@, $(GKI_KERNEL_OUT)) + cp -f $(kbuild_module_gki) $@ +endif + +# This should really be cleared in build/core/clear-vars.mk, but for +# the time being, we need to clear it ourselves +LOCAL_MODULE_KBUILD_NAME := +LOCAL_MODULE_DEBUG_ENABLE := + +# Since this file will be included more than once for directories +# with more than one kernel module, the shared KBUILD_TARGET rule should +# only be defined once to avoid "overriding commands ..." warnings. +ifndef $(KBUILD_TARGET)_RULE +$(KBUILD_TARGET)_RULE := 1 + +# Kernel modules have to be built after: +# * the kernel config has been created +# * host executables, like scripts/basic/fixdep, have been built +# (otherwise parallel invocations of the kernel build system will +# fail as they all try to compile these executables at the same time) +# * a full kernel build (to make module versioning work) +# +# For these reasons, kernel modules are dependent on +# TARGET_PREBUILT_INT_KERNEL which will ensure all of the above. +# +# NOTE: Due to a bug in the kernel build system when using a Kbuild file +# and relative paths for both O= and M=, the Kbuild file must +# be copied to the output directory. +# +# NOTE: The following paths are equivalent: +# $(KBUILD_OUT_DIR) +# $(KERNEL_OUT)/../$(LOCAL_PATH) + + +$(KBUILD_TARGET): local_path := $(LOCAL_PATH) +$(KBUILD_TARGET): kbuild_options := $(KBUILD_OPTIONS) +$(KBUILD_TARGET): kbuild_out_dir := $(KBUILD_OUT_DIR) +$(KBUILD_TARGET): $(TARGET_PREBUILT_INT_KERNEL) $(GKI_TARGET_PREBUILT_KERNEL) $(LOCAL_ADDITIONAL_DEPENDENCIES) $(KBUILD_TARGET_GKI) + @mkdir -p $(kbuild_out_dir) + $(hide) cp -f $(local_path)/Kbuild $(kbuild_out_dir)/Kbuild + $(MAKE) -j$(NCORES) -C $(KERNEL_OUT) M=$(KERNEL_TO_BUILD_ROOT_OFFSET)$(local_path) ARCH=$(KERNEL_ARCH) CROSS_COMPILE=$(KERNEL_CROSS_COMPILE) $(real_cc) $(KERNEL_CFLAGS) modules $(kbuild_options) ANDROID_BUILD_TOP=$$(pwd) + touch $@ + +# Define a target to build buildko.timestamp for gki modules as well. +# To maintain GKI1.0 compatibility modules are compiled for gki and +# qgki kernels. This target only runs if qgki kernel is being compiled. + +$(KBUILD_TARGET_GKI): local_path := $(LOCAL_PATH) +$(KBUILD_TARGET_GKI): local_module := $(LOCAL_MODULE) +$(KBUILD_TARGET_GKI): kbuild_out_dir_gki := $(KBUILD_OUT_DIR)/gki +$(KBUILD_TARGET_GKI): kbuild_options_gki := $(KBUILD_OPTIONS_GKI) +$(KBUILD_TARGET_GKI): kbuild_out_dir := $(KBUILD_OUT_DIR) +$(KBUILD_TARGET_GKI): local_depends := $(LOCAL_ADDITIONAL_DEPENDENCIES) +$(KBUILD_TARGET_GKI): $(TARGET_PREBUILT_INT_KERNEL) $(LOCAL_ADDITIONAL_DEPENDENCIES) $(GKI_TARGET_PREBUILT_KERNEL) +ifneq ($(GKI_KERNEL_OUT),) + rm -rf $(kbuild_out_dir) + mkdir -p $(kbuild_out_dir) + $(hide) cp -f $(local_path)/Kbuild $(kbuild_out_dir)/Kbuild + $(MAKE) -j$(NCORES) -C $(GKI_KERNEL_OUT) M=$(KERNEL_TO_BUILD_ROOT_OFFSET)$(local_path) ARCH=$(KERNEL_ARCH) CROSS_COMPILE=$(KERNEL_CROSS_COMPILE) $(real_cc) $(KERNEL_CFLAGS) modules $(kbuild_options_gki) ANDROID_BUILD_TOP=$$(pwd) + @mkdir -p $(TARGET_OUT_INTERMEDIATES)/tmp_$(local_module) + mv $(kbuild_out_dir)/* $(TARGET_OUT_INTERMEDIATES)/tmp_$(local_module) + @mkdir -p $(kbuild_out_dir_gki) + mv $(TARGET_OUT_INTERMEDIATES)/tmp_$(local_module)/* $(kbuild_out_dir_gki) + rm -rf $(TARGET_OUT_INTERMEDIATES)/tmp_$(local_module) + touch $@ +endif +endif +endif + +# Once the KBUILD_OPTIONS variable has been used for the target +# that's specific to the LOCAL_PATH, clear it. If this isn't done, +# then every kernel module would need to explicitly set KBUILD_OPTIONS, +# or the variable would have to be cleared in 'include $(CLEAR_VARS)' +# which would require a change to build/core. +KBUILD_OPTIONS := +LOCAL_ADDITIONAL_DEPENDENCIES := +KBUILD_OPTIONS_GKI := diff --git a/dlkm/Build_external_kernelmodule.mk b/dlkm/Build_external_kernelmodule.mk new file mode 100644 index 0000000..6e586b1 --- /dev/null +++ b/dlkm/Build_external_kernelmodule.mk @@ -0,0 +1,118 @@ +DISABLE_THIS_DLKM := $(strip $(TARGET_KERNEL_DLKM_DISABLE)) + +## Input Arguments: +# LOCAL_MODULE: name of the .ko to be generated (e.g. kp_module.ko) +# LOCAL_MODULE_PATH: location to put the module, $(KERNEL_MODULES_OUT) +# for a common output directory +# LOCAL_MODULE_KBUILD_NAME: name of the .ko that is generated by kbuild (see below) +# LOCAL_ADDITIONAL_DEPENDENCIES: just that +# KBUILD_OPTIONS: Additional parameters to give to kbuild when compiling module + +ifeq ($(DISABLE_THIS_DLKM),true) +ifneq (,$(filter $(LOCAL_MODULE),$(TARGET_KERNEL_DLKM_OVERRIDE))) + DISABLE_THIS_DLKM = false +else +endif +endif + +ifeq ($(DISABLE_THIS_DLKM),true) +$(warning DLKM '$(LOCAL_MODULE)' disabled for target) +else + +# Assign external kernel modules to the DLKM class +LOCAL_MODULE_CLASS := DLKM + +# Set the default install path to system/lib/modules +LOCAL_MODULE_PATH := $(strip $(LOCAL_MODULE_PATH)) +ifeq ($(LOCAL_MODULE_PATH),) + LOCAL_MODULE_PATH := $(TARGET_OUT)/lib/modules +endif + +# LOCAL_MODULE_KBUILD_NAME is the name of the .ko that kernel makefiles generate +# for instance, one could write my_device.ko, but want it to be called +# the_device.ko on vendor image (and rest of Android build system) +ifeq ($(LOCAL_MODULE_KBUILD_NAME),) + LOCAL_MODULE_KBUILD_NAME := $(LOCAL_MODULE) +endif +LOCAL_MODULE_KBUILD_NAME := $(strip $(LOCAL_MODULE_KBUILD_NAME)) + +include $(BUILD_SYSTEM)/base_rules.mk + +################################################################################ +KERNEL_PLATFORM_PATH:=kernel_platform +KERNEL_PLATFORM_OUT_DIR:=$(TARGET_OUT_INTERMEDIATES)/KERNEL_OBJ + +ifeq ($(wildcard $(KERNEL_PLATFORM_OUT_DIR)/),) +$(error "$(KERNEL_PLATFORM_OUT_DIR) doesn't exist. Have you run kernel_platform/build/android/prepare.sh?") +endif +################################################################################ +# Intermediate directory where the kernel modules are created +# by the kernel platform. Ideally this would be the same +# directory as LOCAL_BUILT_MODULE, but because we're using +# relative paths for both O= and M=, we don't have much choice +MODULE_KP_OUT_DIR := $(KERNEL_PLATFORM_OUT_DIR)/$(LOCAL_PATH) + +# The kernel build system doesn't support parallel kernel module builds +# that share the same output directory. Thus, in order to build multiple +# kernel modules that reside in a single directory (and therefore have +# the same output directory), there must be just one invocation of the +# kernel build system that builds all the modules of a given directory. +# +# Therefore, all kernel modules must depend on the same, unique target +# that invokes the kernel build system and builds all of the modules +# for the directory. The $(MODULE_KP_COMBINED_TARGET) target serves this purpose. +MODULE_KP_COMBINED_TARGET := $(MODULE_KP_OUT_DIR)/buildko.timestamp +# When MODULE_KP_COMBINED_TARGET is built, then out pops the MODULE_KP_TARGET (by essentially running `make modules`) +MODULE_KP_TARGET := $(MODULE_KP_OUT_DIR)/$(LOCAL_MODULE_KBUILD_NAME) + +# The final built module for Android Build System +$(LOCAL_BUILT_MODULE): $(MODULE_KP_TARGET) | $(ACP) + $(transform-prebuilt-to-target) + +# To build the module inside kernel_platform, depend on the kbuild_target +$(MODULE_KP_TARGET): $(MODULE_KP_COMBINED_TARGET) +$(MODULE_KP_TARGET): $(LOCAL_ADDITIONAL_DEPENDENCIES) + +# Ensure the kernel module created by the kernel build system, as +# well as all the other intermediate files, are removed during a clean. +$(cleantarget): PRIVATE_CLEAN_FILES := $(PRIVATE_CLEAN_FILES) $(MODULE_KP_OUT_DIR) + +# Since this file will be included more than once for directories +# with more than one kernel module, the shared KBUILD_TARGET rule should +# only be defined once to avoid "overriding commands ..." warnings. +ifndef $(MODULE_KP_COMBINED_TARGET)_RULE +$(MODULE_KP_COMBINED_TARGET)_RULE := 1 + +# Kernel modules have to be built after: +# * the kernel config has been created +# * host executables, like scripts/basic/fixdep, have been built +# (otherwise parallel invocations of the kernel build system will +# fail as they all try to compile these executables at the same time) +# * a full kernel build (to make module versioning work) +$(MODULE_KP_COMBINED_TARGET): local_path := $(LOCAL_PATH) +$(MODULE_KP_COMBINED_TARGET): kbuild_options := $(KBUILD_OPTIONS) +$(MODULE_KP_COMBINED_TARGET): $(LOCAL_ADDITIONAL_DEPENDENCIES) $(LOCAL_SRC_FILES) + # Create a symlink so that Kernel Platform thinks module source lives inside + # kernel platform directory structure. + # this makes finding the output much less confusing and helps prevent + # possibility of conflicting output folders if we were to use relative path + # outside the kernel_platform directory structure. Kbuild output goes to: + # $(KERNEL_PLATFORM_OUT_DIR)/$(MODULE_KP_SYMLINK)/$(LOCAL_PATH) + (cd $(KERNEL_PLATFORM_PATH) && \ + EXT_MODULES=la/$(local_path) \ + ./build/build_module.sh $(kbuild_options) \ + ANDROID_BUILD_TOP=$$(realpath $$(pwd)/$(KERNEL_PLATFORM_TO_ROOT)) \ + ) + touch $@ + +endif +endif + +# Once the KBUILD_OPTIONS variable has been used for the target +# that's specific to the LOCAL_PATH, clear it. If this isn't done, +# then every kernel module would need to explicitly set KBUILD_OPTIONS, +# or the variable would have to be cleared in 'include $(CLEAR_VARS)' +# which would require a change to build/core. +KBUILD_OPTIONS := +LOCAL_ADDITIONAL_DEPENDENCIES := +LOCAL_MODULE_KBUILD_NAME := diff --git a/generate_extra_images.mk b/generate_extra_images.mk new file mode 100644 index 0000000..30a75fe --- /dev/null +++ b/generate_extra_images.mk @@ -0,0 +1,272 @@ +# This makefile is used to generate extra images for QCOM targets +# persist, device tree & NAND images required for different QCOM targets. + +# These variables are required to make sure that the required +# files/targets are available before generating NAND images. +# This file is included from device/qcom/<TARGET>/AndroidBoard.mk +# and gets parsed before build/core/Makefile, which has these +# variables defined. build/core/Makefile will overwrite these +# variables again. +ifneq ($(strip $(TARGET_NO_KERNEL)),true) + +ifneq ($(strip $(BOARD_KERNEL_BINARIES)),) + BUILT_BOOTIMAGE_TARGET := $(foreach k,$(subst kernel,boot,$(BOARD_KERNEL_BINARIES)), $(PRODUCT_OUT)/$(k).img) +else + BUILT_BOOTIMAGE_TARGET := $(PRODUCT_OUT)/boot.img +endif + +INSTALLED_BOOTIMAGE_TARGET := $(BUILT_BOOTIMAGE_TARGET) + +ifeq ($(PRODUCT_BUILD_RAMDISK_IMAGE),true) +INSTALLED_RAMDISK_TARGET := $(PRODUCT_OUT)/ramdisk.img +endif +ifeq ($(PRODUCT_BUILD_SYSTEM_IMAGE),true) +INSTALLED_SYSTEMIMAGE := $(PRODUCT_OUT)/system.img +endif +ifeq ($(PRODUCT_BUILD_USERDATA_IMAGE),true) +INSTALLED_USERDATAIMAGE_TARGET := $(PRODUCT_OUT)/userdata.img +endif +ifneq ($(TARGET_NO_RECOVERY), true) +INSTALLED_RECOVERYIMAGE_TARGET := $(PRODUCT_OUT)/recovery.img +else +INSTALLED_RECOVERYIMAGE_TARGET := +endif +recovery_ramdisk := $(PRODUCT_OUT)/ramdisk-recovery.img +INSTALLED_USBIMAGE_TARGET := $(PRODUCT_OUT)/usbdisk.img +endif + +#---------------------------------------------------------------------- +# Generate persist image (persist.img) +#---------------------------------------------------------------------- +ifneq ($(strip $(BOARD_PERSISTIMAGE_PARTITION_SIZE)),) +ifneq ($(strip $(TARGET_NO_KERNEL)),true) + +TARGET_OUT_PERSIST := $(PRODUCT_OUT)/persist + +INTERNAL_PERSISTIMAGE_FILES := \ + $(filter $(TARGET_OUT_PERSIST)/%,$(ALL_DEFAULT_INSTALLED_MODULES)) + +INSTALLED_PERSISTIMAGE_TARGET := $(PRODUCT_OUT)/persist.img + +define build-persistimage-target + $(call pretty,"Target persist fs image: $(INSTALLED_PERSISTIMAGE_TARGET)") + @mkdir -p $(TARGET_OUT_PERSIST) + $(hide) PATH=$(HOST_OUT_EXECUTABLES):$${PATH} $(MKEXTUSERIMG) $(TARGET_OUT_PERSIST) $@ ext4 persist $(BOARD_PERSISTIMAGE_PARTITION_SIZE) + $(hide) chmod a+r $@ + $(hide) $(call assert-max-image-size,$@,$(BOARD_PERSISTIMAGE_PARTITION_SIZE)) +endef + +$(INSTALLED_PERSISTIMAGE_TARGET): $(MKEXTUSERIMG) $(MAKE_EXT4FS) $(INTERNAL_PERSISTIMAGE_FILES) + $(build-persistimage-target) + +ALL_DEFAULT_INSTALLED_MODULES += $(INSTALLED_PERSISTIMAGE_TARGET) +ALL_MODULES.$(LOCAL_MODULE).INSTALLED += $(INSTALLED_PERSISTIMAGE_TARGET) +droidcore: $(INSTALLED_PERSISTIMAGE_TARGET) + +.PHONY: persistimage +persistimage: $(INSTALLED_PERSISTIMAGE_TARGET) + +endif +endif + +#---------------------------------------------------------------------- +# Generate metadata image (metadata.img) +# As of now this in empty at build and data is runtime generated only, +# so create an empty fs +#---------------------------------------------------------------------- +ifneq ($(strip $(BOARD_METADATAIMAGE_PARTITION_SIZE)),) + +TARGET_OUT_METADATA := $(PRODUCT_OUT)/metadata + +INSTALLED_METADATAIMAGE_TARGET := $(PRODUCT_OUT)/metadata.img + +define build-metadataimage-target + $(call pretty,"Target metadata fs image: $(INSTALLED_METADATAIMAGE_TARGET)") + @mkdir -p $(TARGET_OUT_METADATA) + $(hide)PATH=$(HOST_OUT_EXECUTABLES):$${PATH} $(MKEXTUSERIMG) -s $(TARGET_OUT_METADATA) $@ ext4 metadata $(BOARD_METADATAIMAGE_PARTITION_SIZE) + $(hide) chmod a+r $@ +endef + +$(INSTALLED_METADATAIMAGE_TARGET): $(MKEXTUSERIMG) $(MAKE_EXT4FS) + $(build-metadataimage-target) + +ALL_DEFAULT_INSTALLED_MODULES += $(INSTALLED_METADATAIMAGE_TARGET) +ALL_MODULES.$(LOCAL_MODULE).INSTALLED += $(INSTALLED_METADATAIMAGE_TARGET) +droidcore: $(INSTALLED_METADATAIMAGE_TARGET) + +.PHONY: metadataimage +metadataimage: $(INSTALLED_METADATAIMAGE_TARGET) + +endif + +#---------------------------------------------------------------------- +# Generate device tree overlay image (dtbo.img) +#---------------------------------------------------------------------- +ifneq ($(strip $(TARGET_NO_KERNEL)),true) +ifeq ($(strip $(BOARD_KERNEL_SEPARATED_DTBO)),true) + +MKDTIMG := $(HOST_OUT_EXECUTABLES)/mkdtimg$(HOST_EXECUTABLE_SUFFIX) + +# Most specific paths must come first in possible_dtbo_dirs +possible_dtbo_dirs = $(KERNEL_OUT)/arch/$(TARGET_KERNEL_ARCH)/boot/dts $(KERNEL_OUT)/arch/arm/boot/dts +$(shell mkdir -p $(possible_dtbo_dirs)) +dtbo_dir = $(firstword $(wildcard $(possible_dtbo_dirs))) +dtbo_objs = $(shell find $(dtbo_dir) -name \*.dtbo) + +define build-dtboimage-target + $(call pretty,"Target dtbo image: $(BOARD_PREBUILT_DTBOIMAGE)") + $(hide) $(MKDTIMG) create $@ --page_size=$(BOARD_KERNEL_PAGESIZE) $(dtbo_objs) + $(hide) chmod a+r $@ +endef + +# Definition of BOARD_PREBUILT_DTBOIMAGE is in AndroidBoardCommon.mk +# so as to ensure it is defined well in time to set the dependencies on +# BOARD_PREBUILT_DTBOIMAGE +$(BOARD_PREBUILT_DTBOIMAGE): $(MKDTIMG) $(INSTALLED_KERNEL_TARGET) + $(build-dtboimage-target) + +endif +endif + +#---------------------------------------------------------------------- +# Generate device tree image (dt.img) +#---------------------------------------------------------------------- +ifneq ($(strip $(TARGET_NO_KERNEL)),true) +ifeq ($(strip $(BOARD_KERNEL_SEPARATED_DT)),true) +ifeq ($(strip $(BUILD_TINY_ANDROID)),true) +include device/qcom/common/dtbtool/Android.mk +endif + +DTBTOOL := $(HOST_OUT_EXECUTABLES)/dtbTool$(HOST_EXECUTABLE_SUFFIX) + +INSTALLED_DTIMAGE_TARGET := $(PRODUCT_OUT)/dt.img + +# Most specific paths must come first in possible_dtb_dirs +possible_dtb_dirs = $(KERNEL_OUT)/arch/$(TARGET_KERNEL_ARCH)/boot/dts/qcom/ $(KERNEL_OUT)/arch/arm/boot/dts/qcom/ $(KERNEL_OUT)/arch/$(TARGET_KERNEL_ARCH)/boot/dts/ $(KERNEL_OUT)/arch/arm/boot/dts/ $(KERNEL_OUT)/arch/arm/boot/ +dtb_dir = $(firstword $(wildcard $(possible_dtb_dirs))) + +define build-dtimage-target + $(call pretty,"Target dt image: $(INSTALLED_DTIMAGE_TARGET)") + $(hide) $(DTBTOOL) -o $@ -s $(BOARD_KERNEL_PAGESIZE) -p $(KERNEL_OUT)/scripts/dtc/ $(dtb_dir) + $(hide) chmod a+r $@ +endef + +$(INSTALLED_DTIMAGE_TARGET): $(DTBTOOL) $(INSTALLED_KERNEL_TARGET) + $(build-dtimage-target) + +ALL_DEFAULT_INSTALLED_MODULES += $(INSTALLED_DTIMAGE_TARGET) +ALL_MODULES.$(LOCAL_MODULE).INSTALLED += $(INSTALLED_DTIMAGE_TARGET) +endif +endif + +#--------------------------------------------------------------------- +# Generate usbdisk.img FAT32 image +# Please NOTICE: the valid max size of usbdisk.bin is 10GB +#--------------------------------------------------------------------- +ifneq ($(strip $(BOARD_USBIMAGE_PARTITION_SIZE_KB)),) +define build-usbimage-target + $(hide) mkfs.vfat -n "Internal SD" -F 32 -C $(PRODUCT_OUT)/usbdisk.tmp $(BOARD_USBIMAGE_PARTITION_SIZE_KB) + $(hide) dd if=$(PRODUCT_OUT)/usbdisk.tmp of=$(INSTALLED_USBIMAGE_TARGET) bs=1024 count=20480 + $(hide) rm -f $(PRODUCT_OUT)/usbdisk.tmp +endef + +$(INSTALLED_USBIMAGE_TARGET): + $(build-usbimage-target) +ALL_DEFAULT_INSTALLED_MODULES += $(INSTALLED_USBIMAGE_TARGET) +ALL_MODULES.$(LOCAL_MODULE).INSTALLED += $(INSTALLED_DTIMAGE_TARGET) +endif + +##################################################################################################### +# support for small user data image + +ifneq ($(strip $(BOARD_SMALL_USERDATAIMAGE_PARTITION_SIZE)),) +# Don't build userdata.img if it's extfs but no partition size +skip_userdata.img := +ifdef INTERNAL_USERIMAGES_EXT_VARIANT +ifndef BOARD_USERDATAIMAGE_PARTITION_SIZE +skip_userdata.img := true +endif +endif + +ifneq ($(skip_userdata.img),true) + +INSTALLED_SMALL_USERDATAIMAGE_TARGET := $(PRODUCT_OUT)/userdata_small.img + +define build-small-userdataimage + @echo "target small userdata image" + $(hide) mkdir -p $(1) + $(hide) $(MKEXTUSERIMG) -s $(TARGET_OUT_DATA) $(2) ext4 data $(BOARD_SMALL_USERDATAIMAGE_PARTITION_SIZE) + $(hide) chmod a+r $@ + $(hide) $(call assert-max-image-size,$@,$(BOARD_SMALL_USERDATAIMAGE_PARTITION_SIZE)) +endef + + +$(INSTALLED_SMALL_USERDATAIMAGE_TARGET): $(MKEXTUSERIMG) $(MAKE_EXT4FS) $(INSTALLED_USERDATAIMAGE_TARGET) + $(hide) $(call build-small-userdataimage,$(PRODUCT_OUT),$(INSTALLED_SMALL_USERDATAIMAGE_TARGET)) + +ALL_DEFAULT_INSTALLED_MODULES += $(INSTALLED_SMALL_USERDATAIMAGE_TARGET) +ALL_MODULES.$(LOCAL_MODULE).INSTALLED += $(INSTALLED_SMALL_USERDATAIMAGE_TARGET) + +endif + +endif + +################################################################################################### + +.PHONY: aboot +ifeq ($(USESECIMAGETOOL), true) +aboot: $(TARGET_SIGNED_BOOTLOADER) gensecimage_install +else +aboot: $(INSTALLED_BOOTLOADER_MODULE) +endif + +.PHONY: kernel +kernel: $(INSTALLED_BOOTIMAGE_TARGET) $(INSTALLED_DTBOIMAGE_TARGET) + +.PHONY: dtboimage +dtboimage: $(INSTALLED_DTBOIMAGE_TARGET) + +.PHONY: recoveryimage +recoveryimage: $(INSTALLED_RECOVERYIMAGE_TARGET) + +.PHONY: kernelclean +kernelclean: + $(hide) make -C $(TARGET_KERNEL_SOURCE) O=$(KERNEL_TO_BUILD_ROOT_OFFSET)$(PRODUCT_OUT)/obj/KERNEL_OBJ/ ARCH=$(TARGET_ARCH) CROSS_COMPILE=arm-eabi- clean + $(hide) make -C $(TARGET_KERNEL_SOURCE) O=$(KERNEL_TO_BUILD_ROOT_OFFSET)$(PRODUCT_OUT)/obj/KERNEL_OBJ/ ARCH=$(TARGET_ARCH) CROSS_COMPILE=arm-eabi- mrproper + $(hide) make -C $(TARGET_KERNEL_SOURCE) O=$(KERNEL_TO_BUILD_ROOT_OFFSET)$(PRODUCT_OUT)/obj/KERNEL_OBJ/ ARCH=$(TARGET_ARCH) CROSS_COMPILE=arm-eabi- distclean + $(hide) if [ -f "$(INSTALLED_BOOTIMAGE_TARGET)" ]; then rm $(INSTALLED_BOOTIMAGE_TARGET); fi + $(hide) if [ -f "$(INSTALLED_BOOTIMAGE_TARGET).nonsecure" ]; then rm $(INSTALLED_BOOTIMAGE_TARGET).nonsecure; fi + $(hide) if [ -f "$(PRODUCT_OUT)/kernel" ]; then rm $(PRODUCT_OUT)/kernel; fi + @echo "kernel cleanup done" + +# Set correct dependency for kernel modules +ifneq ($(BOARD_VENDOR_KERNEL_MODULES),) +$(BOARD_VENDOR_KERNEL_MODULES): $(INSTALLED_BOOTIMAGE_TARGET) +endif +ifneq ($(BOARD_RECOVERY_KERNEL_MODULES),) +$(BOARD_RECOVERY_KERNEL_MODULES): $(INSTALLED_BOOTIMAGE_TARGET) +endif + +define board-vendorkernel-ota + $(call pretty,"Processing following kernel modules for vendor: $(BOARD_VENDOR_KERNEL_MODULES)") + $(if $(BOARD_VENDOR_KERNEL_MODULES), \ + $(call build-image-kernel-modules,$(BOARD_VENDOR_KERNEL_MODULES),$(TARGET_OUT_VENDOR),vendor/,$(call intermediates-dir-for,PACKAGING,depmod_vendor))) +endef + +# Adding support for vendor module for OTA +ifeq ($(ENABLE_VENDOR_IMAGE), false) +.PHONY: otavendormod +otavendormod: $(BOARD_VENDOR_KERNEL_MODULES) + $(board-vendorkernel-ota) + +.PHONY: otavendormod-nodeps +otavendormod-nodeps: + @echo "make board-vendorkernel-ota: ignoring dependencies" + $(board-vendorkernel-ota) + +$(BUILT_SYSTEMIMAGE): otavendormod + +endif + +#Print PRODUCT_PACKAGES & PRODUCT_PACKAGES_DEBUG to output log +$(call dump-products) |