MEDIA_TYPE = u-boot binaries

TARGET = u-boot-binaries
EXTRANAME = $(MEDIUM)/

.PHONY: u-boot-binaries
u-boot-binaries:
	mkdir -p $(SOME_DEST)/$(EXTRANAME)/
	set -e; while read LINE; \
	do \
	  if [ -n "$${LINE}" ] && ! echo $${LINE}|grep -q -e "^#"; then \
	    set -- $${LINE}; \
	    mkdir -p "$(SOME_DEST)/$(EXTRANAME)/$$1"; \
	    if [ -n "$$2" ]; then \
	      echo "Providing u-boot binaries for $$1 ..."; \
	      cp "$$2" "$(SOME_DEST)/$(EXTRANAME)/$$1/"; \
	      dd 2>/dev/null if="$$2" of="$(SOME_DEST)/$(EXTRANAME)/$$1/$$1.sdcard.img" bs=512 seek="$$3"; \
	      pigz -9nm "$(SOME_DEST)/$(EXTRANAME)/$$1/$$(basename $$2)"; \
	    fi; \
	    if [ -n "$$4" ]; then \
	      cp "$$4" "$(SOME_DEST)/$(EXTRANAME)/$$1/"; \
	      dd 2>/dev/null if="$$4" of="$(SOME_DEST)/$(EXTRANAME)/$$1/$$1.sdcard.img" bs=512 seek="$$5" conv=notrunc; \
	      pigz -9nm "$(SOME_DEST)/$(EXTRANAME)/$$1/$$(basename $$4)"; \
	    fi; \
	    pigz -9nm "$(SOME_DEST)/$(EXTRANAME)/$$1/$$1.sdcard.img"; \
	    update-manifest "$(SOME_DEST)/$(EXTRANAME)$$1" "u-boot image for $$1"; \
	  fi ;\
	done < boot/arm/u-boot-image-config
