Board file fixes to build Mendel for Excelsior

- multistrap config to make rootfs
- Blank (for now) fstab to make rootfs build happy
- General cleanups of early boot target build rules
- Udev rules for host system
- Minor flash script tweaks

Change-Id: Ie4bdd307d2a4d5967d89dc00f75509f12afd48a8
diff --git a/99-excelsior.rules b/99-excelsior.rules
new file mode 100644
index 0000000..1630790
--- /dev/null
+++ b/99-excelsior.rules
@@ -0,0 +1,6 @@
+SUBSYSTEM=="usb", ATTRS{idProduct}=="6011", ATTRS{idVendor}=="0403",GROUP="plugdev", MODE="0666"
+SUBSYSTEM=="tty", ATTRS{idProduct}=="6011", ATTRS{idVendor}=="0403",GROUP="plugdev", MODE="0666"
+
+ATTRS{idVendor}=="0e8d", ENV{ID_MM_DEVICE_IGNORE}="1"
+SUBSYSTEM=="usb", ATTRS{idProduct}=="0003", ATTRS{idVendor}=="0e8d",GROUP="plugdev", MODE="0666"
+SUBSYSTEM=="tty", ATTRS{idProduct}=="0003", ATTRS{idVendor}=="0e8d",GROUP="plugdev", MODE="0666"
diff --git a/boot.mk b/boot.mk
index 998b4f5..d313077 100644
--- a/boot.mk
+++ b/boot.mk
@@ -18,13 +18,17 @@
 
 include $(ROOTDIR)/build/preamble.mk
 
-boot: $(PRODUCT_OUT)/boot.img
+boot: $(PRODUCT_OUT)/boot_$(USERSPACE_ARCH).img
+
+$(PRODUCT_OUT)/boot_$(USERSPACE_ARCH).img: $(PRODUCT_OUT)/boot.img
+	fallocate -l $(BOOT_SIZE_MB)M $(PRODUCT_OUT)/boot_$(USERSPACE_ARCH).img
+	mkfs.ext2 -F $(PRODUCT_OUT)/boot_$(USERSPACE_ARCH).img
 
 $(PRODUCT_OUT)/boot.img: linux-mtk | out-dirs
 	$(LOG) linux-mtk extract
-	find $(PRODUCT_OUT)/packages -name 'linux-mtk*$(USERSPACE_ARCH)*.deb' | xargs \
+	find $(PRODUCT_OUT)/packages -name 'linux-image*$(USERSPACE_ARCH)*.deb' | xargs \
 	dpkg --fsys-tarfile | \
 	tar --strip-components 2 -C $(PRODUCT_OUT) -xf - ./boot/boot.img
 	$(LOG) linux-mtk finished
 
-.PHONY:: bootloader
+.PHONY:: boot
diff --git a/bootloader.mk b/bootloader.mk
index 3cbfafe..ca3df7d 100644
--- a/bootloader.mk
+++ b/bootloader.mk
@@ -17,8 +17,9 @@
 endif
 
 include $(ROOTDIR)/build/preamble.mk
+include $(ROOTDIR)/board/trustzone.mk
 
-bootloader: $(PRODUCT_OUT)/lk.bin $(PRODUCT_OUT)/lk.img
+bootloader: $(PRODUCT_OUT)/lk.bin $(PRODUCT_OUT)/lk.img $(PRODUCT_OUT)/tz.img
 
 $(PRODUCT_OUT)/lk.bin $(PRODUCT_OUT)/lk.img: lk-bootloader | out-dirs
 	$(LOG) lk-bootloader extract
diff --git a/flash.sh b/flash.sh
index 98aa7e1..4ae5012 100644
--- a/flash.sh
+++ b/flash.sh
@@ -14,12 +14,15 @@
 # See the License for the specific language governing permissions and
 # limitations under the License.
 
+set -e
+
 SCRIPT_DIR=$(dirname $0)
 FLASHTOOLS_DIR=${SCRIPT_DIR}/flashtools
 FBTOOL=${FLASHTOOLS_DIR}/fbtool.py
 EXCELSIOR_DEBUG_RESET_TOOL=${FLASHTOOLS_DIR}/debug_board_reset.py
 DOWNLOAD_AGENT_CONFIG=${FLASHTOOLS_DIR}/dl_addr.ini
 FASTBOOT_TOOL=$(which fastboot)
+USERSPACE_ARCH=arm64
 
 if [ -z ${FASTBOOT_TOOL} ]; then
     echo "Fastboot is not found on this machine. Install fastboot before running this script"; exit 1
@@ -35,7 +38,7 @@
 
 reset_excelsior_to_rom() {
   echo "Reset Excelsior to ROM"
-  ${EXCELSIOR_DEBUG_RESET_TOOL} --rom &
+  LANG=en_US.UTF-8 LC_ALL=en_US.UTF-8 python3 ${EXCELSIOR_DEBUG_RESET_TOOL} --rom &
 }
 
 load_lk_to_ram() {
@@ -45,23 +48,22 @@
 
 erase_mmc() {
   echo "Erase EMMC"
-  ${FASTBOOT_TOOL} erase mmc0
   ${FASTBOOT_TOOL} erase mmc0boot0
   ${FASTBOOT_TOOL} erase mmc0boot1
 }
 
 flash_images() {
     pushd ${PRODUCT_OUT}
-    ${FASTBOOT_TOOL} erase mmc0
     ${FASTBOOT_TOOL} flash mmc0 GPT_EMMC
     ${FASTBOOT_TOOL} flash mmc0boot0 lk.img
     ${FASTBOOT_TOOL} flash TEE1 tz.img
     ${FASTBOOT_TOOL} flash BOOTIMG1 boot.img
-    ${FASTBOOT_TOOL} flash ROOTFS rootfs.img
+    ${FASTBOOT_TOOL} flash BOOT boot_${USERSPACE_ARCH}.img
+    ${FASTBOOT_TOOL} flash ROOTFS rootfs_${USERSPACE_ARCH}.img
     popd
 }
 
-ln -sf ${SCRIPT_DIR}/dl_addr.ini ${PRODUCT_OUT}/dl_addr.ini
+ln -sf ${ROOTDIR}/board/flashtools/dl_addr.ini ${PRODUCT_OUT}/dl_addr.ini
 reset_excelsior_to_rom
 sleep 1
 load_lk_to_ram
@@ -70,3 +72,4 @@
 sleep 1
 flash_images
 sleep 1
+${FASTBOOT_TOOL} reboot
diff --git a/fstab.emmc b/fstab.emmc
new file mode 100644
index 0000000..e69de29
--- /dev/null
+++ b/fstab.emmc
diff --git a/multistrap.conf b/multistrap.conf
new file mode 100644
index 0000000..a954413
--- /dev/null
+++ b/multistrap.conf
@@ -0,0 +1,12 @@
+[General]
+arch=USERSPACE_ARCH
+cleanup=true
+unpack=true
+bootstrap=main
+aptsources=main
+noauth=true
+
+[main]
+packages=MAIN_PACKAGES
+source=https://packages.cloud.google.com/apt
+suite=mendel-animal
diff --git a/packages.mk b/packages.mk
index 0d89078..7fae06d 100644
--- a/packages.mk
+++ b/packages.mk
@@ -13,8 +13,7 @@
 # limitations under the License.
 
 $(eval $(call make-pbuilder-bsp-package-target,u-boot-mkimage,bootloader/mtk-tools/u-boot-mkimage))
-$(eval $(call make-pbuilder-bsp-package-target,linux-mtk,linux))
+$(eval $(call make-pbuilder-bsp-package-target,linux-mtk,linux,u-boot-mkimage))
 $(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,trustzone,trustzone,boot-keys))
 $(eval $(call make-pbuilder-bsp-package-target,boot-keys,bootloader/mtk-tools/keys))
diff --git a/partition-table.mk b/partition-table.mk
index 5950eed..34a8766 100644
--- a/partition-table.mk
+++ b/partition-table.mk
@@ -18,13 +18,14 @@
 
 include $(ROOTDIR)/build/preamble.mk
 
-gpt_emmc: $(PRODUCT_OUT)/GPT_EMMC
+partition-table: $(PRODUCT_OUT)/GPT_EMMC
 
-$(PRODUCT_OUT)/GPT_EMMC: pratition-table | out-dirs
+$(PRODUCT_OUT)/GPT_EMMC: $(ROOTDIR)/bootloader/partition-table/partition_emmc.xml | 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
+	make -C $(ROOTDIR)/bootloader/partition-table clean
+	make -C $(ROOTDIR)/bootloader/partition-table
+	cp $(ROOTDIR)/bootloader/partition-table/build-gpt/GPT_EMMC $(PRODUCT_OUT)
+	make -C $(ROOTDIR)/bootloader/partition-table clean
 	$(LOG) partition-table finished
 
-.PHONY:: partition-table
\ No newline at end of file
+.PHONY:: partition-table
diff --git a/rootfs.mk b/rootfs.mk
index e202271..f2e6d89 100644
--- a/rootfs.mk
+++ b/rootfs.mk
@@ -12,7 +12,9 @@
 # See the License for the specific language governing permissions and
 # limitations under the License.
 
-BSP_BASE_PACKAGES :=
-
+BSP_BASE_PACKAGES := \
+    linux-image-4.4.22-aiy \
+    lk-bootloader \
+    trustzone
 
 BSP_GUI_PACKAGES :=
diff --git a/trustzone.mk b/trustzone.mk
index 37983ae..9210da5 100644
--- a/trustzone.mk
+++ b/trustzone.mk
@@ -27,4 +27,4 @@
 	tar --strip-components 2 -C $(PRODUCT_OUT) -xf - ./boot/tz.img
 	$(LOG) linux-mtk finished
 
-.PHONY:: bootloader
+.PHONY:: tz