+# SD-Card Images:
+# these values are optimized for a 4GB labeled sdcard that actually holds 7744512 sectors of 512 byte
+# MBR: 2048 sectors
+# Partition 1: 32768 sectors
+# Partition 2: 98304 sectors (configurable)
+# Partition 3: 7611392 sectors (configurable, depends on p2 size)
+
+define Build/boot-scr
+ rm -f $@.bootscript
+ mkimage -A arm -O linux -T script -C none -a 0 -e 0 -d boot.script $@.bootscript
+endef
+
+define Build/boot-img
+ rm -f $@.boot
+ mkfs.fat -C $@.boot 16384
+ $(foreach dts,$(DEVICE_DTS), mcopy -i $@.boot $(DTS_DIR)/$(dts).dtb ::$(dts).dtb)
+ mcopy -i $@.boot $(IMAGE_KERNEL) ::zImage
+ mcopy -i $@.boot $@.bootscript ::boot.scr
+endef
+
+define Build/sdcard-img
+ rm -rf $@ $@.rootfsdata $@.tmp
+ mkdir -p $@.tmp
+ ROOTFS_SIZE=$$(( $(CONFIG_TARGET_ROOTFS_PARTSIZE) * 1024 * 2 )); \
+ DATA_SIZE=$$(( 7709696 - ($(CONFIG_TARGET_ROOTFS_PARTSIZE) * 1024 * 2) )); \
+ make_ext4fs -J -l $$DATA_SIZE $@.rootfsdata $@.tmp && \
+ ./gen_mvebu_sdcard_img.sh 7744512 $@ \
+ "$(BIN_DIR)/uboot-mvebu-clearfog/openwrt-mvebu-clearfog-u-boot-spl.kwb" \
+ c 32768 $@.boot \
+ 83 $$ROOTFS_SIZE $(IMAGE_ROOTFS) \
+ 83 $$DATA_SIZE $@.rootfsdata
+endef