diff options
author | Michael Olbrich <m.olbrich@pengutronix.de> | 2011-05-22 11:23:58 +0200 |
---|---|---|
committer | Michael Olbrich <m.olbrich@pengutronix.de> | 2011-05-31 09:58:12 +0200 |
commit | 55dbdbefba21fa7e36f089bc90641e46c65cae06 (patch) | |
tree | 09d8c34688a8685e7babb2e8d1cce39069c3e094 | |
parent | 0fe2ab6502cb39bbdffe3c6a1095bb7dd72dca86 (diff) | |
download | ptxdist-55dbdbefba21fa7e36f089bc90641e46c65cae06.tar.gz ptxdist-55dbdbefba21fa7e36f089bc90641e46c65cae06.tar.xz |
add helper functions for vfat images
Signed-off-by: Michael Olbrich <m.olbrich@pengutronix.de>
-rw-r--r-- | platforms/image_vfat_tools.in | 7 | ||||
-rw-r--r-- | rules/post/ptxd_make_image_vfat.make | 30 | ||||
-rw-r--r-- | scripts/lib/ptxd_make_image_vfat.sh | 59 |
3 files changed, 96 insertions, 0 deletions
diff --git a/platforms/image_vfat_tools.in b/platforms/image_vfat_tools.in new file mode 100644 index 000000000..ab5b31dff --- /dev/null +++ b/platforms/image_vfat_tools.in @@ -0,0 +1,7 @@ +## SECTION=image + +config IMAGE_VFAT_TOOLS + bool + select HOST_MTOOLS + select HOST_DOSFSTOOLS + diff --git a/rules/post/ptxd_make_image_vfat.make b/rules/post/ptxd_make_image_vfat.make new file mode 100644 index 000000000..872daaef3 --- /dev/null +++ b/rules/post/ptxd_make_image_vfat.make @@ -0,0 +1,30 @@ +# -*-makefile-*- +# +# Copyright (C) 2011 by Michael Olbrich <m.olbrich@pengutronix.de> +# +# See CREDITS for details about who has contributed to this project. +# +# For further information about the PTXdist project and license conditions +# see the README file. +# + +# +# image/vfat +# +# - $1 the image file name +# - $2 the image file size in bytes. Guessed if undefined. +# - $3 file with $src:$dst mappings for the image content +# +image/vfat = \ + $(call ptx/env) \ + image_vfat_file="$(1)" \ + image_vfat_size="$(2)" \ + image_vfat_map="$(3)" \ + ptxd_make_image_vfat + +$(IMAGEDIR)/%.vfat: $(IMAGEDIR)/%.vfat.map + @echo -n "Creating `basename $@` ..." + @$(call image/vfat,$@,$($*_VFAT_SIZE),$<) + @echo "done." + +# vim: syntax=make diff --git a/scripts/lib/ptxd_make_image_vfat.sh b/scripts/lib/ptxd_make_image_vfat.sh new file mode 100644 index 000000000..0a207aaea --- /dev/null +++ b/scripts/lib/ptxd_make_image_vfat.sh @@ -0,0 +1,59 @@ +#!/bin/bash +# +# Copyright (C) 2011 by Michael Olbrich <m.olbrich@pengutronix.de> +# +# See CREDITS for details about who has contributed to this project. +# +# For further information about the PTXdist project and license conditions +# see the README file. +# + +ptxd_make_image_vfat_add() { + local image="${1}" + local src="${2}" + local dst="${3}" + + if [ ! -e "${src}" ]; then + ptxd_bailout "source file '$(ptxd_print_path "${src}")' for '$(ptxd_print_path "${image}") missing!" + fi + MTOOLS_SKIP_CHECK=1 mcopy -i "${image}" "${src}" "::${dst}" +} +export -f ptxd_make_image_vfat_add + +# +# create a vfat image and fill it. +# +# in: +# - $image_vfat_file the image file name +# - $image_vfat_size the image file size in bytes. Guessed if undefined. +# - $image_vfat_map file with $src:$dst mappings for the image content +# +ptxd_make_image_vfat() { + local image="${image_vfat_file}.tmp" + local src dst + + if [ -z "${image_vfat_size}" ]; then + local size=0 + while IFS=: read src dst; do + local tmp="$(du -b "${src}")" + size=$[${size}+${tmp%% *}] + done < "${image_vfat_map}" + # + 10% + size=$[${size}+${size}/10] + # round up to 16k + size=$[(${size}/16384+1)*16384] + image_vfat_size="${size}" + fi + rm -f "${image_vfat_file}" "${image}" && + # just seek to prepare the size for mkfs.vfat + dd if=/dev/zero of="${image}" seek=${image_vfat_size} count=0 bs=1 2>/dev/null && + mkfs.vfat "${image}" >/dev/null && + + while IFS=: read src dst; do + ptxd_make_image_vfat_add "${image}" "${src}" "${dst}" || return + done < "${image_vfat_map}" && + + mv "${image}" "${image_vfat_file}" +} +export -f ptxd_make_image_vfat + |