g12: Add build task for dtb/dtbo images
authorJan Altensen <info@stricted.net>
Sat, 19 Jun 2021 20:20:27 +0000 (22:20 +0200)
committerNolen Johnson <johnsonnolen@gmail.com>
Tue, 27 Jul 2021 21:18:15 +0000 (17:18 -0400)
Change-Id: Ia0518fd7de611a0fb190900e7a86f2c8e571e585

build/tasks/2ndbootloader.mk [new file with mode: 0644]

diff --git a/build/tasks/2ndbootloader.mk b/build/tasks/2ndbootloader.mk
new file mode 100644 (file)
index 0000000..e36f76b
--- /dev/null
@@ -0,0 +1,55 @@
+#
+# Copyright (C) 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.
+#
+
+ifneq ($(filter g12a g12b sm1, $(TARGET_AMLOGIC_SOC)),)
+
+MKDTBOIMG := $(HOST_OUT_EXECUTABLES)/mkdtboimg.py
+DTBTARGET := $(PRODUCT_OUT)/dtb.img
+DTBTOOL := $(HOST_OUT_EXECUTABLES)/dtbToolAmlogic$(HOST_EXECUTABLE_SUFFIX)
+DTBTMP := $(PRODUCT_OUT)/tmp_dt
+DTBDIR := $(PRODUCT_OUT)/obj/KERNEL_OBJ/arch/arm64/boot/dts/amlogic
+DTCDIR := $(PRODUCT_OUT)/obj/KERNEL_OBJ/scripts/dtc/
+
+TARGET_DTBO_NAME ?= amlogicandroid_p_overlay_dt
+
+define aml-compress-dtb
+       if [ -n "$(shell find $(1) -size +200k)" ]; then \
+               echo "$(1) > 200k will be gziped"; \
+               mv $(1) $(1).orig; \
+               $(MINIGZIP) -c $(1).orig > $(1); \
+       fi;
+endef
+
+$(INSTALLED_2NDBOOTLOADER_TARGET): $(INSTALLED_KERNEL_TARGET) $(DTBTOOL) | $(ACP) $(MINIGZIP)
+ifeq ($(words $(TARGET_DTB_NAME)),1)
+       $(hide) $(ACP) $(DTBDIR)/$(TARGET_DTB_NAME).dtb $(DTBTARGET);
+       $(hide) $(call aml-compress-dtb, $(DTBTARGET))
+       $(hide) $(ACP) $(DTBTARGET) $@;
+else
+       $(hide) mkdir -p $(DTBTMP);
+       $(foreach aDts, $(TARGET_DTB_NAME), \
+               $(ACP) $(DTBDIR)/$(strip $(aDts)).dtb $(DTBTMP)/$(strip $(aDts)).dtb; \
+       )
+       $(hide) $(DTBTOOL) -o $(DTBTARGET) -p $(DTCDIR) $(DTBTMP)
+       $(hide) $(call aml-compress-dtb, $(DTBTARGET))
+       $(hide) $(ACP) $(DTBTARGET) $@;
+       $(hide) rm -rf $(DTBTMP);
+endif
+
+$(BOARD_PREBUILT_DTBOIMAGE): $(INSTALLED_KERNEL_TARGET) $(MKDTBOIMG)
+       $(MKDTBOIMG) create $@ $(DTBDIR)/$(TARGET_DTBO_NAME).dtb
+
+endif