Merge "flashtools: Added tools needed to flash images."
diff --git a/boot.mk b/boot.mk
new file mode 100644
index 0000000..998b4f5
--- /dev/null
+++ b/boot.mk
@@ -0,0 +1,30 @@
+# Copyright 2018 Google LLC
+#
+# 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
+#
+#     https://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.
+
+ifeq ($(ROOTDIR),)
+$(error $$ROOTDIR IS NOT DEFINED -- don\'t forget to source setup.sh)
+endif
+
+include $(ROOTDIR)/build/preamble.mk
+
+boot: $(PRODUCT_OUT)/boot.img
+
+$(PRODUCT_OUT)/boot.img: linux-mtk | out-dirs
+	$(LOG) linux-mtk extract
+	find $(PRODUCT_OUT)/packages -name 'linux-mtk*$(USERSPACE_ARCH)*.deb' | xargs \
+	dpkg --fsys-tarfile | \
+	tar --strip-components 2 -C $(PRODUCT_OUT) -xf - ./boot/boot.img
+	$(LOG) linux-mtk finished
+
+.PHONY:: bootloader
diff --git a/bootloader.mk b/bootloader.mk
index 65bbf54..3cbfafe 100644
--- a/bootloader.mk
+++ b/bootloader.mk
@@ -18,7 +18,13 @@
 
 include $(ROOTDIR)/build/preamble.mk
 
-bootloader:
-	@echo "Building lk"
+bootloader: $(PRODUCT_OUT)/lk.bin $(PRODUCT_OUT)/lk.img
+
+$(PRODUCT_OUT)/lk.bin $(PRODUCT_OUT)/lk.img: lk-bootloader | out-dirs
+	$(LOG) lk-bootloader extract
+	find $(PRODUCT_OUT)/packages -name 'lk-bootloader*$(USERSPACE_ARCH)*.deb' | xargs \
+	dpkg --fsys-tarfile | \
+	tar --strip-components 2 -C $(PRODUCT_OUT) -xf - ./boot/lk.img ./boot/lk.bin
+	$(LOG) lk-bootloader finished
 
 .PHONY:: bootloader
diff --git a/packages.mk b/packages.mk
index 2a6ee8d..0d89078 100644
--- a/packages.mk
+++ b/packages.mk
@@ -16,3 +16,5 @@
 $(eval $(call make-pbuilder-bsp-package-target,linux-mtk,linux))
 $(eval $(call make-pbuilder-bsp-package-target,lk-bootloader,bootloader))
 $(eval $(call make-pbuilder-bsp-package-target,trustzone,trustzone))
+$(eval $(call make-pbuilder-bsp-package-target,partition-table,bootloader/partition-table))
+$(eval $(call make-pbuilder-bsp-package-target,boot-keys,bootloader/mtk-tools/keys))
diff --git a/partition-table.mk b/partition-table.mk
new file mode 100644
index 0000000..5950eed
--- /dev/null
+++ b/partition-table.mk
@@ -0,0 +1,30 @@
+# Copyright 2018 Google LLC
+#
+# 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
+#
+#     https://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.
+
+ifeq ($(ROOTDIR),)
+$(error $$ROOTDIR IS NOT DEFINED -- don\'t forget to source setup.sh)
+endif
+
+include $(ROOTDIR)/build/preamble.mk
+
+gpt_emmc: $(PRODUCT_OUT)/GPT_EMMC
+
+$(PRODUCT_OUT)/GPT_EMMC: pratition-table | out-dirs
+	$(LOG) partition-table extract
+	find $(PRODUCT_OUT)/packages -name 'partition-table$(USERSPACE_ARCH)*.deb' | xargs \
+	dpkg --fsys-tarfile | \
+	tar --strip-components 2 -C $(PRODUCT_OUT) -xf - ./boot/GPT_EMMC
+	$(LOG) partition-table finished
+
+.PHONY:: partition-table
\ No newline at end of file
diff --git a/trustzone.mk b/trustzone.mk
new file mode 100644
index 0000000..37983ae
--- /dev/null
+++ b/trustzone.mk
@@ -0,0 +1,30 @@
+# Copyright 2018 Google LLC
+#
+# 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
+#
+#     https://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.
+
+ifeq ($(ROOTDIR),)
+$(error $$ROOTDIR IS NOT DEFINED -- don\'t forget to source setup.sh)
+endif
+
+include $(ROOTDIR)/build/preamble.mk
+
+tz: $(PRODUCT_OUT)/tz.img
+
+$(PRODUCT_OUT)/tz.img: trustzone | out-dirs
+	$(LOG) linux-mtk extract
+	find $(PRODUCT_OUT)/packages -name 'trustzone*$(USERSPACE_ARCH)*.deb' | xargs \
+	dpkg --fsys-tarfile | \
+	tar --strip-components 2 -C $(PRODUCT_OUT) -xf - ./boot/tz.img
+	$(LOG) linux-mtk finished
+
+.PHONY:: bootloader