From ce9024e6a8ea3e5c4294ebe6c61a0a062b9706a9 Mon Sep 17 00:00:00 2001
From: David Brown <david.brown@linaro.org>
Date: Thu, 16 Jun 2016 13:15:49 -0600
Subject: [PATCH] hikey: Use mtools to avoid sudo during build

Instead of using sudo/mount to build the FAT image, use commands from
the mtools package to copy files into the FAT image.  This eliminates
the requirement to use sudo during the build.  It also removes a small
sleep necessary to make umount work.

Signed-off-by: David Brown <david.brown@linaro.org>
Reviewed-by: Jens Wiklander <jens.wiklander@linaro.org>
Reviewed-by: Jerome Forissier <jerome.forissier@linaro.org>
Reviewed-by: Joakim Bech <joakim.bech@linaro.org>
---
 hikey.mk | 28 +++++++++-------------------
 1 file changed, 9 insertions(+), 19 deletions(-)

diff --git a/hikey.mk b/hikey.mk
index 0ddf9bd..765672a 100644
--- a/hikey.mk
+++ b/hikey.mk
@@ -334,25 +334,15 @@ GRUBCFG = $(PATCHES_PATH)/grub/grub_uart0.cfg
 endif
 
 boot-img: linux update_rootfs edk2 grub
-	sudo -p "[sudo] Password:" true
-	if [ -d .tmpbootimg ] ; then sudo rm -rf .tmpbootimg ; fi
-	mkdir -p .tmpbootimg
-	dd if=/dev/zero of=$(BOOT_IMG) bs=512 count=131072 status=none
-	sudo mkfs.vfat -n "BOOT IMG" $(BOOT_IMG) >/dev/null
-	sudo mount -o loop,rw,sync $(BOOT_IMG) .tmpbootimg
-	sudo cp $(LINUX_PATH)/arch/arm64/boot/Image $(DTB) .tmpbootimg/
-	sudo mkdir -p .tmpbootimg/EFI/BOOT
-	sudo cp $(OUT_PATH)/grubaa64.efi .tmpbootimg/EFI/BOOT/
-	sudo cp $(GRUBCFG) .tmpbootimg/EFI/BOOT/grub.cfg
-	sudo cp $(GEN_ROOTFS_PATH)/filesystem.cpio.gz .tmpbootimg/initrd.img
-	sudo cp $(EDK2_PATH)/Build/HiKey/$(EDK2_BUILD)_GCC49/AARCH64/AndroidFastbootApp.efi .tmpbootimg/EFI/BOOT/fastboot.efi
-	# We cannot figure out why we need the sleep here, but from time to time
-	# we can see that we get "device/resource busy" when trying to unmount
-	# .tmpbootimg below. A short sleep seems to solve the problem and has to
-	# be here until we figure out why this happens.
-	sleep 3
-	sudo umount .tmpbootimg
-	sudo rm -rf .tmpbootimg
+	rm -f $(BOOT_IMG)
+	mformat -i $(BOOT_IMG) -n 64 -h 255 -T 131072 -v "BOOT IMG" -C ::
+	mcopy -i $(BOOT_IMG) $(LINUX_PATH)/arch/arm64/boot/Image $(DTB) ::
+	mmd -i $(BOOT_IMG) ::/EFI
+	mmd -i $(BOOT_IMG) ::/EFI/BOOT
+	mcopy -i $(BOOT_IMG) $(OUT_PATH)/grubaa64.efi ::/EFI/BOOT/
+	mcopy -i $(BOOT_IMG) $(GRUBCFG) ::/EFI/BOOT/grub.cfg
+	mcopy -i $(BOOT_IMG) $(GEN_ROOTFS_PATH)/filesystem.cpio.gz ::/initrd.img
+	mcopy -i $(BOOT_IMG) $(EDK2_PATH)/Build/HiKey/$(EDK2_BUILD)_GCC49/AARCH64/AndroidFastbootApp.efi ::/EFI/BOOT/fastboot.efi
 
 .PHONY: boot-img-clean
 boot-img-clean:
-- 
GitLab