Commit Graph

66 Commits

Author SHA1 Message Date
Michael Olbrich
0d8de181b1
Merge pull request #213 from Villemoes/part-fill
image-hd: implement "fill" option for partitions
2023-03-03 12:09:00 +00:00
Rasmus Villemoes
e123753a4f image-hd: implement "fill" option for partitions
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>
2023-02-24 12:52:57 +01:00
Rasmus Villemoes
2bcf9b7471 make insert_data take an "unsigned long long" offset
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>
2023-02-08 14:01:19 +01:00
Ahmad Fatoum
1e224789ba Add Firmware Image Package (FIP) support
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>
2022-04-22 09:51:45 +02:00
Michael Olbrich
cfd0426a62 make rootpath optional
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>
2022-03-25 16:43:36 +01:00
Tomas Mudrunka
b334dd132f Override filesystem source path
Signed-off-by: Tomas Mudrunka <harviecz@gmail.com>
2022-03-25 15:05:27 +00:00
Tomas Mudrunka
1c5457cacd Initial F2FS support
Signed-off-by: Tomas Mudrunka <tomas@mudrunka.cz>
2022-03-25 15:53:00 +01:00
Michael Olbrich
00a7c38e48 util: create new helper to initialize an image
Signed-off-by: Michael Olbrich <m.olbrich@pengutronix.de>
2022-03-25 09:39:57 +01:00
Rasmus Villemoes
dec6e6c4bd image-hd.c: use size of destination block device as image size
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>
2022-01-07 10:47:11 +01:00
Michael Olbrich
90b83bac14 allow specifying 'holes' in the partition section
Signed-off-by: Michael Olbrich <m.olbrich@pengutronix.de>
2021-10-22 15:57:39 +02:00
Michael Olbrich
f606a33426 util: remove unused pad_file function
Signed-off-by: Michael Olbrich <m.olbrich@pengutronix.de>
2021-06-04 16:26:01 +02:00
Michael Olbrich
7d0003b7d8 util: insert_image: allow specifying the fill value
Signed-off-by: Michael Olbrich <m.olbrich@pengutronix.de>
2021-06-04 16:26:01 +02:00
Rasmus Villemoes
5638a9e444 util.c: add insert_image() helper
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>
2021-04-21 14:23:51 +02:00
Rasmus Villemoes
998a118658 image-file.c: allow specifying "don't care" regions
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>
2021-04-21 12:30:18 +02:00
Michael Olbrich
7df972bb6e
Merge pull request #139 from OsterlaD/rauc-intermediate
add rauc intermediate option
2021-04-09 07:25:39 +00:00
Rasmus Villemoes
030e7a3c2e allow each partition to have its own align value
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>
2021-03-28 12:52:36 +02:00
Rasmus Villemoes
9ffd5e0fbb add macro for compile-time assertions
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>
2021-03-28 12:52:36 +02:00
Rasmus Villemoes
9e59a27099 change insert_data() to take const void* instead of const char*
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>
2021-03-26 16:42:34 +01:00
Denis Osterland-Heim
344416f5d9 util: add save string concat with formated string
An example:
```c
char *txt = NULL;
for (int i = 0; i < 5; i++)
	xstrcatf(&txt, " %d", i);
puts(txt);
```
will produce the output:
` 0 1 2 3 4`

Signed-off-by: Denis Osterland-Heim <Denis.Osterland@diehl.com>
2021-02-25 08:26:00 +01:00
Michael Olbrich
84c04645a9 add new image type for android sparse images
Signed-off-by: Michael Olbrich <m.olbrich@pengutronix.de>
2021-01-13 09:02:51 +01:00
Michael Olbrich
a6dff044c2 util: export some more functions
The will be needed in future commits.

Signed-off-by: Michael Olbrich <m.olbrich@pengutronix.de>
2021-01-12 08:45:30 +01:00
Michael Olbrich
a7cd4bb8f7 crc32: add function to allow splitting the crc calculation
This is needed when the input data is not available in on continuous block.

Signed-off-by: Michael Olbrich <m.olbrich@pengutronix.de>
2021-01-12 08:43:46 +01:00
Michael Olbrich
f69064ead3 util: introduce and use xrealloc
Just like xzalloc(). Abort when memory allocations fail.

Signed-off-by: Michael Olbrich <m.olbrich@pengutronix.de>
2020-11-27 11:35:09 +01:00
Rasmus Villemoes
15875c15ba allow specifying an image as temporary
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>
2020-11-17 20:03:42 +01:00
Michael Olbrich
e8cb9b6f49 genimage: make mountpath() argument const
It not modified and this will be needed in the next commit.

Signed-off-by: Michael Olbrich <m.olbrich@pengutronix.de>
2020-08-28 15:37:18 +02:00
Andri Yngvason
075db5e0ae image-hd: Add GPT attributes for hiding partitions on Windows
This allows users to instruct Windows 10 to ignore certain partitions to
various extent.

Signed-off-by: Andri Yngvason <andri.yngvason@marel.com>
2020-03-26 10:53:27 +00:00
Michael Olbrich
fb65bd97f8 genimage: allow sanitize_path() to be used elsewhere
Signed-off-by: Michael Olbrich <m.olbrich@pengutronix.de>
2020-01-31 12:53:13 +01:00
Michael Olbrich
f4c889b5fc make it easier to create empty filesystems
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>
2019-09-22 15:07:52 +02:00
Michael Olbrich
f05d2b5292
Merge pull request #62 from michaelolbrich/hd-fill
image-hd: add option to extend the image to the full size
2019-05-11 14:06:22 +00:00
Michael Olbrich
8d9c1a2bd3 genimage: allow percentages for image sizes
Signed-off-by: Michael Olbrich <m.olbrich@pengutronix.de>
2019-05-07 13:05:20 +02:00
Michael Olbrich
9370489c3c util: add helper to extend images to a specified size
Signed-off-by: Michael Olbrich <m.olbrich@pengutronix.de>
2019-05-07 12:40:41 +02:00
Michael Olbrich
3938972096 util: add helper to calculate directory size
Signed-off-by: Michael Olbrich <m.olbrich@pengutronix.de>
2019-05-06 08:59:08 +02:00
Michael Olbrich
e2f88d5af0 config: allow parsing percentages
Signed-off-by: Michael Olbrich <m.olbrich@pengutronix.de>
2019-05-06 08:59:08 +02:00
Michael Olbrich
3552a4d30d image-hd: re-read partition table for block devices
Signed-off-by: Michael Olbrich <m.olbrich@pengutronix.de>
2019-03-01 16:38:16 +01:00
Michael Olbrich
8687e9c639 pad_file/insert_data: support writing to block devices
Signed-off-by: Michael Olbrich <m.olbrich@pengutronix.de>
2019-03-01 16:38:16 +01:00
Michael Olbrich
1033272349 pad_file: use the imageoutfile()
Signed-off-by: Michael Olbrich <m.olbrich@pengutronix.de>
2019-03-01 12:44:01 +01:00
Stefan Sørensen
2c92297e8a hdimage: Add GPT support
Signed-off-by: Stefan Sørensen <stefan.sorensen@spectralink.com>
2019-02-12 09:29:54 +01:00
Alexandre Fournier
9e1e7c5860 add qemu handler 2018-03-19 21:55:28 +01:00
Sascha Hauer
ec65ecc5b4 Add FIT image support
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>
2018-03-19 15:53:26 +01:00
Sascha Hauer
51aac203af cleanup logging
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>
2018-03-19 14:58:34 +01:00
Michael Olbrich
520c4f8bfc util: check asprintf()/vasprintf() return values
Signed-off-by: Michael Olbrich <m.olbrich@pengutronix.de>
2017-11-12 09:33:04 +01:00
Julien Viard de Galbert
5984e56a7f cramfs: add handler to create cramfs filesystem images
Signed-off-by: Julien Viard de Galbert <julien.viarddegalbert@openwide.fr>
Signed-off-by: Michael Olbrich <m.olbrich@pengutronix.de>
2016-09-13 14:51:29 +02:00
Michael Olbrich
6de3e5aaa5 add image type to create rauc bundles
Signed-off-by: Michael Olbrich <m.olbrich@pengutronix.de>
2016-08-15 12:35:48 +02:00
Ladislav Michl
14c17c745c genimage: Add static UBI volumes support
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>
2016-01-12 17:07:31 +01:00
Vivien Didelot
971a17ee5b genimage: constify image in imageoutfile
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>
2015-09-14 08:42:52 +02:00
Michael Olbrich
a0d4704f69 cleanup logging
Signed-off-by: Michael Olbrich <m.olbrich@pengutronix.de>
2014-08-12 11:41:46 +02:00
Juergen Beisert
3171e7020d squashfs: add handler to create squashfs filesystem images
Signed-off-by: Juergen Beisert <jbe@pengutronix.de>
2014-03-10 15:56:58 +01:00
Michael Olbrich
dff2d7c88e cleanup error output
Signed-off-by: Michael Olbrich <m.olbrich@pengutronix.de>
2013-05-02 20:49:21 +02:00
Michael Olbrich
4edee07408 sort image handler
Signed-off-by: Michael Olbrich <m.olbrich@pengutronix.de>
2012-11-24 22:59:58 +01:00
Michael Olbrich
a23519e5bf add cpio image support
Signed-off-by: Michael Olbrich <m.olbrich@pengutronix.de>
2012-09-21 10:22:48 +02:00