blob: 0a207aaeac6fb175065aec4edc0a68fe9d75709d (
plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
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
|