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 /scripts | |
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>
Diffstat (limited to 'scripts')
-rw-r--r-- | scripts/lib/ptxd_make_image_vfat.sh | 59 |
1 files changed, 59 insertions, 0 deletions
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 + |