When bootstrapping, it can be useful to ensure that a partition has
completely known contents, especially when the partition just contains
raw binary data and not a filesystem.
When generating an image file, this is implicitly done already because
the non-written parts of the partition(s) are implicitly zero-filled
when the containing image file is extended to its final size.
But when using genimage to directly populate a block device, no such
implicit zero-filling is done.
Add a "fill" boolean option, and use that to decide between passing
the partition's size or the child image's size to insert_image().
Signed-off-by: Rasmus Villemoes <rasmus.villemoes@prevas.dk>
When using genimage on a 32 bit host and trying to populate a ~8GiB
eMMC with a GPT image, we hit
INFO: hdimage(/dev/mmcblk0): determined size of block device /dev/mmcblk0 to be 7820083200
...
ERROR: hdimage(/dev/mmcblk0): seek /dev/mmcblk0: Invalid argument
ERROR: hdimage(/dev/mmcblk0): failed to write backup GPT table
This is because the "image->size - GPT_SECTORS*512" aka 7820066304
passed from hdimage_insert_gpt() becomes -769868288 when shoehorned
into a "signed long".
Make the offset parameter "unsigned long long" to match the protoype
of insert_image().
Signed-off-by: Rasmus Villemoes <rasmus.villemoes@prevas.dk>
Platforms where ARM Trusted Firmware is the first stage bootloader are
converging to use FIP as bundle format for further firmware including
trusted OS and non secure bootloader. Teach genimage to call fiptool to
generate FIP images.
Signed-off-by: Ahmad Fatoum <a.fatoum@pengutronix.de>
When none of the images need files from the rootpath, then make it
optional. Some types never need it. For others the image must be explicitly
marked as empty.
Fixes: #181
Signed-off-by: Michael Olbrich <m.olbrich@pengutronix.de>
Currently, when writing a GPT image directly to a block device, the
image generation fails when hdimage_insert_gpt() calls extend_file(),
because the computed size of the image (based on the defined
partitions etc.) is smaller than what extend_file() sees when it does
the SEEK_END sanity check.
So when the target is a block device and the image size has not been
set explicitly, set image->size from the actual size of the block
device. In case one has a few board variants with slightly differing
eMMC sizes, that will automatically DTRT - we still do all the sanity
checks that the defined partitions do not exceed the image size etc.
In fact, when writing directly to a block device, we are implicitly
populating the whole device - and in particular, when writing a GPT
image, the backup header must be placed at the end of the
device. There is currently no known use case for setting a non-zero
image size (and having genimage check that is <= the actual size
etc...), so for now enforce that image->size is not set for a block
device target.
Signed-off-by: Rasmus Villemoes <rasmus.villemoes@prevas.dk>
Add a helper that can be used to insert one image into another at a
specific offset. The caller must also pass an explicit size; if the
inserted image is smaller than this (including passing NULL for no
image), the remainder is filled with zero bytes.
This is to transition image-hd.c away from pad_file(), which has a
somewhat awkward interface and assumes the output image is always
built up sequentially.
Signed-off-by: Rasmus Villemoes <rasmus.villemoes@prevas.dk>
Some bootloader images are specially crafted to avoid having any
meaningful code/data in the range from where the MBR table starts (at
offset 440) and to beyond where the GPT array ends (33K), or perhaps
just (if only meant to be used with MBR disks) a hole at [440,512].
In order to use such images, while still doing overlap sanity checks,
one needs a way to tell genimage that certain regions of a file are
not significant and can thus be allowed to be overwritten.
I decided to make this a property of the image rather than something
to specify inside the partition that is to contain the image, since
this is fundamentally a property of the image/the file in question.
Signed-off-by: Rasmus Villemoes <rasmus.villemoes@prevas.dk>
For partitions in the partition table, this defaults to the image's
alignment value, while partitions not listed there use a value of 1,
i.e. no particular alignment requirements.
Signed-off-by: Rasmus Villemoes <rasmus.villemoes@prevas.dk>
Compile-time assertions can be helpful to ensure the compiler actually
lays out sturcts as one expects, and for a lot of other things as
well.
<assert.h> exposes a static_assert() macro that maps to _Static_assert
if one compiles with -std=c11 or later, but I don't think we can
mandate that. Also, that standard macro suffers from the defect of
requiring a separate string message - it's usually completely obvious
from the stringification of the expression what it is that is being
asserted. So just define our own ct_assert().
[Side note: We seem to be relying implicitly on gcc defaulting to some
gnuXX mode - building with -std=c99 or -std=c89 breaks with complaints
about the use of typeof().]
Signed-off-by: Rasmus Villemoes <rasmus.villemoes@prevas.dk>
Arbitrary blobs of data should be passed around via a void pointer (as
evidenced by the need for casts in the majority of callers). If one
doesn't want to rely the compiler extension allowing arithmetic on
void pointers, there's a single conversion to do inside the
implementation.
Signed-off-by: Rasmus Villemoes <rasmus.villemoes@prevas.dk>
When using something like
image @IMAGE@ {
....
partition sysdata {
image = "sysdata"
in-partition-table = true
partition-type-uuid = "L"
}
}
image sysdata {
size = 200M
ext4 {}
empty = true
}
to create a partition containing an empty file system, it's
undesirable to leave such an empty file system image in the output
directory (especially when building with Yocto, where it then gets
copied to the shared deploy directory).
So allow specifying an image as temporary, putting it in in tmppath()
rather than imagepath().
Signed-off-by: Rasmus Villemoes <rasmus.villemoes@prevas.dk>
This is useful when creating multiple images with on config and some of
them should be empty. Also, vfat filesystems cannot be empty right now, so
this makes it possible.
Signed-off-by: Michael Olbrich <m.olbrich@pengutronix.de>
This adds support for U-Boot FIT images to the genimage tool.
FIT images are effectively device tree blobs (dtbs) which have
the actual image data as binary properties in the device tree.
FIT image support works by invoking the U-Boot mkimage tool
with a device tree source file (its) as input. The its file
must be handwritten, but the image data is included automatically
by genimage which generates suitable /incbin/ directives on the
fly.
Images in the its file are in a /images/<imagename> node. The
FIT image is seen as a partitioned device, for each /images/<imagename>
there must be a partition named <imagename> in the genimage config
file section for a FIT image.
Signed-off-by: Sascha Hauer <s.hauer@pengutronix.de>
[mol: add test files to Makefile.am, handle readonly .its file]
Signed-off-by: Michael Olbrich <m.olbrich@pengutronix.de>
We have image_error, image_log, error and logmsg which all do the
actual printing themselves. Create a set of error(), info() and
debug() functions which all do the actual printing in the same
function. Also add the same set of functions with a image_ prefix
to do image specific logging. All messages now get a [type] prefix
to make it easier to distinguish them from the stdout/stderr from
invoked commands (see next patch).
Signed-off-by: Sascha Hauer <s.hauer@pengutronix.de>
[mol: don't change the loglevel numbers]
Signed-off-by: Michael Olbrich <m.olbrich@pengutronix.de>
Bare images (kernel, U-Boot, its environment) need to reside inside
static UBI volumes. Add read-only partition flag and use it for that
purpose. Also make partition's "image" voluntary as ubinize will yell
anyway. Once this behavior gets modified eventually, it will bring us
possibility to create empty volumes ready for runtime update.
Signed-off-by: Ladislav Michl <ladis@linux-mips.org>
Signed-off-by: Michael Olbrich <m.olbrich@pengutronix.de>
Since imageoutfile does not modify the image, make it const.
Signed-off-by: Vivien Didelot <vivien.didelot@savoirfairelinux.com>
Signed-off-by: Sascha Hauer <s.hauer@pengutronix.de>