Replace kernel-deb targets with a pbuilder package

Change-Id: Ib99eeecc4b0ddf99e64adc24530fc8913e9b7c61
diff --git a/Makefile b/Makefile
index da8a7da..3a0686a 100644
--- a/Makefile
+++ b/Makefile
@@ -22,7 +22,6 @@
 # various odd reasons (duplicate targets such as depcheck, etc.)
 boot-targets:
 	+make -f $(ROOTDIR)/build/Makefile u-boot
-	+make -f $(ROOTDIR)/build/Makefile kernel
 	+make -f $(ROOTDIR)/build/Makefile boot
 	+make -f $(ROOTDIR)/build/Makefile partition-table
 	+make -f $(ROOTDIR)/build/Makefile rootfs
@@ -34,8 +33,6 @@
 
 include $(ROOTDIR)/build/boot.mk
 include $(ROOTDIR)/build/img2simg.mk
-include $(ROOTDIR)/build/kernel.mk
-include $(ROOTDIR)/build/kernel-modules.mk
 include $(ROOTDIR)/build/partition-table.mk
 include $(ROOTDIR)/build/prereqs.mk
 include $(ROOTDIR)/build/rootfs.mk
diff --git a/kernel-modules.mk b/kernel-modules.mk
deleted file mode 100644
index 989ec2f..0000000
--- a/kernel-modules.mk
+++ /dev/null
@@ -1,41 +0,0 @@
-ifeq ($(ROOTDIR),)
-$(error $$ROOTDIR IS NOT DEFINED -- don\'t forget to source setup.sh)
-endif
-
-include $(ROOTDIR)/build/preamble.mk
-
-REQUIRED_MODULES :=
-
-MODULES_DIRS := $(wildcard $(ROOTDIR)/modules/*)
-MODULES := $(foreach module,$(MODULES_DIRS),$(notdir $(module)))
-MODULES := $(sort $(MODULES) $(REQUIRED_MODULES))
-
-PREBUILT_MODULES_ROOT ?= /google/data/ro/teams/spacepark/enterprise/kokoro/prod/spacepark/enterprise/debs
-
-define make-module-target
-$1: $(PRODUCT_OUT)/.$1
-ifeq (,$$(wildcard $(ROOTDIR)/modules/$1/*))
-$(PRODUCT_OUT)/.$1: $(PRODUCT_OUT)
-	$$(warning "No source for $1")
-	cp $(PREBUILT_MODULES_ROOT)/$1.deb $(PRODUCT_OUT)
-else
-$(PRODUCT_OUT)/.$1: $$(shell find $(ROOTDIR)/modules/$1 -type f) $(KERNEL_OUT_DIR)/.config $(KERNEL_OUT_DIR)/arch/arm64/boot/Image
-	mkdir -p $(PRODUCT_OUT)/obj/MODULE_OBJ/$1/debian
-	cp -afs $(ROOTDIR)/modules/$1/* $(PRODUCT_OUT)/obj/MODULE_OBJ/$1
-	cp -r $(ROOTDIR)/build/$1-debian/* $(PRODUCT_OUT)/obj/MODULE_OBJ/$1/debian/
-	+cd $(PRODUCT_OUT)/obj/MODULE_OBJ/$1; \
-		DEB_HOST_ARCH=arm64 \
-		ROOT_CMD=fakeroot \
-		$(KERNEL_OPTIONS) \
-		KSRC=$(KERNEL_SRC_DIR) \
-		KOUT=$(KERNEL_OUT_DIR) \
-		debian/rules kdist_image
-	touch $(PRODUCT_OUT)/.$1
-endif
-endef
-
-$(foreach module,$(MODULES),$(eval $(call make-module-target,$(module))))
-
-modules:: $(foreach module,$(MODULES),$(PRODUCT_OUT)/.$(module))
-.NOTPARALLEL: modules
-.PHONY:: modules
diff --git a/kernel.mk b/kernel.mk
deleted file mode 100644
index d94bea4..0000000
--- a/kernel.mk
+++ /dev/null
@@ -1,40 +0,0 @@
-ifeq ($(ROOTDIR),)
-$(error $$ROOTDIR IS NOT DEFINED -- don\'t forget to source setup.sh)
-endif
-
-include $(ROOTDIR)/build/preamble.mk
-
-$(KERNEL_OUT_DIR):
-	mkdir -p $(KERNEL_OUT_DIR)
-
-$(KERNEL_OUT_DIR)/.config: $(ROOTDIR)/board/defconfig | $(KERNEL_OUT_DIR)
-	+make -C $(KERNEL_SRC_DIR) O=$(KERNEL_OUT_DIR) $(KERNEL_OPTIONS) mrproper defconfig
-	cat $(ROOTDIR)/board/defconfig | tee -a $(KERNEL_OUT_DIR)/.config
-	+make -C $(KERNEL_SRC_DIR) O=$(KERNEL_OUT_DIR) $(KERNEL_OPTIONS) olddefconfig
-
-$(KERNEL_OUT_DIR)/arch/arm64/boot/Image: $(KERNEL_OUT_DIR)/.config
-		+make -C $(KERNEL_SRC_DIR) O=$(KERNEL_OUT_DIR) $(KERNEL_OPTIONS) Image modules dtbs
-
-kernel-deb: $(PRODUCT_OUT)/packages/linux-image-4.9.51-aiy_1_arm64.deb
-
-kernel: $(KERNEL_OUT_DIR)/arch/arm64/boot/Image $(KERNEL_OUT_DIR)/arch/arm64/boot/dts/freescale/fsl-imx8mq-phanbell.dtb
-
-$(PRODUCT_OUT)/packages/linux-image-4.9.51-aiy_1_arm64.deb: $(KERNEL_OUT_DIR)/.config | out-dirs
-	+make -C $(KERNEL_SRC_DIR) O=$(KERNEL_OUT_DIR) $(KERNEL_OPTIONS) \
-		KDEB_PKGVERSION=1 KBUILD_IMAGE=Image deb-pkg
-	mv $(KERNEL_OUT_DIR)/../linux-image-4.9.51-aiy_1_arm64.deb $(PRODUCT_OUT)/packages
-	mv $(KERNEL_OUT_DIR)/../linux-headers-4.9.51-aiy_1_arm64.deb $(PRODUCT_OUT)/packages
-
-targets::
-	@echo "kernel - builds the kernel and boot partition"
-
-clean::
-	+make -C $(KERNEL_SRC_DIR) mrproper
-
-.NOTPARALLEL: kernel kernel-deb
-# Mark the deb as phony so we ensure that we rely on the kbuild system for
-# incremental builds.
-.PHONY:: kernel \
-         kernel-deb \
-         $(KERNEL_OUT_DIR)/arch/arm64/boot/dts/freescale/fsl-imx8mq-phanbell.dtb \
-         $(KERNEL_OUT_DIR)/arch/arm64/boot/Image \
diff --git a/packages.mk b/packages.mk
index 51b5508..19841df 100644
--- a/packages.mk
+++ b/packages.mk
@@ -92,15 +92,17 @@
 $(eval $(call make-pbuilder-package-target,wayland-protocols-imx,wayland-protocols-imx))
 $(eval $(call make-pbuilder-package-target,weston-imx,weston-imx,wayland-protocols-imx))
 
-$(eval $(call make-pbuilder-package-target,imx-gpu-viv,imx-gpu-viv,,kernel-deb,binary))
+$(eval $(call make-pbuilder-package-target,linux-imx,linux-imx))
+
+$(eval $(call make-pbuilder-package-target,imx-gpu-viv,imx-gpu-viv,linux-imx,,binary))
 $(eval $(call make-pbuilder-package-target,libdrm-imx,libdrm-imx))
-$(eval $(call make-pbuilder-package-target,imx-vpu-hantro,imx-vpu-hantro,,kernel-deb,binary))
+$(eval $(call make-pbuilder-package-target,imx-vpu-hantro,imx-vpu-hantro,linux-imx,,binary))
 $(eval $(call make-pbuilder-package-target,imx-vpuwrap,imx-vpuwrap,imx-vpu-hantro,,binary))
 $(eval $(call make-pbuilder-package-target,imx-gstreamer,imx-gstreamer))
 $(eval $(call make-pbuilder-package-target,imx-gst-plugins-base,imx-gst-plugins-base,imx-gstreamer))
 $(eval $(call make-pbuilder-package-target,imx-gst-plugins-good,imx-gst-plugins-good,imx-gst-plugins-base))
 $(eval $(call make-pbuilder-package-target,imx-gst-plugins-bad,imx-gst-plugins-bad,\
-	libdrm-imx imx-gst-plugins-base,kernel-deb))
+	libdrm-imx imx-gst-plugins-base linux-imx))
 $(eval $(call make-pbuilder-package-target,imx-gst1.0-plugin,imx-gst1.0-plugin,\
 	imx-vpuwrap imx-gst-plugins-bad))
 
diff --git a/rootfs.mk b/rootfs.mk
index 6dcaaee..d4981d5 100644
--- a/rootfs.mk
+++ b/rootfs.mk
@@ -96,7 +96,6 @@
                        $(ROOTDIR)/board/fstab.emmc \
                        $(ROOTDIR)/build/boot.mk \
                        $(ROOTDIR)/cache/packages.tgz \
-                       kernel-deb \
                        | $(PRODUCT_OUT)/boot.img \
                          /usr/bin/qemu-aarch64-static
 	cp $(ROOTFS_RAW_IMG) $(ROOTFS_PATCHED_IMG).wip
diff --git a/signing.mk b/signing.mk
index 7a83db8..ee48433 100644
--- a/signing.mk
+++ b/signing.mk
@@ -5,7 +5,7 @@
 include $(ROOTDIR)/build/preamble.mk
 
 make-repo: $(PRODUCT_OUT)/repo/debian_repo/dists/stable/Release
-$(PRODUCT_OUT)/repo/debian_repo/dists/stable/Release: $(ROOTDIR)/build/distributions | kernel-deb modules packages-tarball
+$(PRODUCT_OUT)/repo/debian_repo/dists/stable/Release: $(ROOTDIR)/build/distributions | packages-tarball
 	mkdir -p $(PRODUCT_OUT)/repo
 	mkdir -p $(PRODUCT_OUT)/repo/debian_repo
 	mkdir -p $(PRODUCT_OUT)/repo/deb_repo_config