build: Add dtbo task
Change-Id: I1101cb204ab583a204447d63e6a031a17179dfe7
(cherry picked from commit 8bffb053db418022c7cba5d67234412edd675862)
diff --git a/build/tasks/dtbo.mk b/build/tasks/dtbo.mk
new file mode 100644
index 0000000..dc3a98a
--- /dev/null
+++ b/build/tasks/dtbo.mk
@@ -0,0 +1,37 @@
+ifneq ($(TARGET_NO_KERNEL),true)
+ifeq ($(strip $(BOARD_KERNEL_SEPARATED_DTBO)),true)
+
+MKDTIMG := $(HOST_OUT_EXECUTABLES)/mkdtimg$(HOST_EXECUTABLE_SUFFIX)
+
+INSTALLED_DTBOIMAGE_TARGET := $(PRODUCT_OUT)/dtbo.img
+
+# Most specific paths must come first in possible_dtbo_dirs
+possible_dtbo_dirs = $(KERNEL_OUT)/arch/$(KERNEL_ARCH)/boot/dts $(KERNEL_OUT)/arch/arm/boot/dts
+
+define build-dtboimage-target
+ $(call pretty,"Target dtbo image: $(INSTALLED_DTBOIMAGE_TARGET)")
+ $(hide) for dir in $(possible_dtbo_dirs); do \
+ if [ -d "$$dir" ]; then \
+ dtbo_dir="$$dir"; \
+ break; \
+ fi; \
+ done; \
+ $(MKDTIMG) create $@ --page_size=$(BOARD_KERNEL_PAGESIZE) $$(find "$$dtbo_dir" -name '*.dtbo')
+ $(hide) chmod a+r $@
+endef
+
+ifeq ($(BOARD_AVB_ENABLE),true)
+$(INSTALLED_DTBOIMAGE_TARGET): $(AVBTOOL) $(BOARD_AVB_DTBO_KEY_PATH) $(MKDTIMG) $(INSTALLED_KERNEL_TARGET)
+ $(build-dtboimage-target)
+ $(AVBTOOL) add_hash_footer \
+ --image $@ \
+ --partition_size $(BOARD_DTBOIMG_PARTITION_SIZE) \
+ --partition_name dtbo $(INTERNAL_AVB_DTBO_SIGNING_ARGS) \
+ $(BOARD_AVB_DTBO_ADD_HASH_FOOTER_ARGS)
+else
+$(INSTALLED_DTBOIMAGE_TARGET): $(MKDTIMG) $(INSTALLED_KERNEL_TARGET)
+ $(build-dtboimage-target)
+endif
+
+endif # BOARD_KERNEL_SEPARATED_DTBO
+endif # TARGET_NO_KERNEL