Using genimage directly on an eMMC on target, I'm seeing that the
BLKRRPART ioctl fails with EBUSY, presumably because there's still
lots of data in flight, and then subsequent parts of my bootstrap
procedure fail because the expected partitions can't be found.
Whenever we've written some data, we really should ensure that all
data has hit the disk before proceeding, and close() itself is not
synchronous.
Add a fsync_close() helper that does exactly what it says on the
tin. Use that wherever we close an fd that has been open for writing
and actually written to (i.e., no point in doing that in the
reload_partitions() function).
Currently, the return value of these close() calls are ignored, so at
least for now continue to do that, but at least we do see an error
message in case something went wrong.
A test case is updated to reflect the new, and more accurate, disk
usage. It turns out that the lack of this fsync'ing has really created
images which later (long after genimage is done and the test framework
has accepted them) would increase in disk usage, i.e. once the kernel
gets around to write out any buffered data. With current master, one
can observe this:
$ mkdir images input tmp
$ dd if=/dev/zero of=input/part1.img bs=512 count=7 && dd if=/dev/zero of=input/part2.img bs=512 count=11 && touch input/part3.img
$ ./genimage --outputpath=images --inputpath=input --rootpath=/no/such/dir --tmppath=tmp --config test/hdimage.config
$ date ; du -B 1 images/test.hdimage-2
Fri Nov 1 08:20:39 PM CET 2024
61440 images/test.hdimage-2
# Let time pass...
$ date ; du -B 1 images/test.hdimage-2
Fri Nov 1 08:21:10 PM CET 2024
65536 images/test.hdimage-2
Signed-off-by: Rasmus Villemoes <ravi@prevas.dk>
* Avoid checks for unused dependencies
* Replace deprecated "btrfsck" with "btrfs check"
* Check if label has been set
Signed-off-by: Fiona Klute (WIWA) <fiona.klute@gmx.de>
It contains a reserved field that remains uninitialized otherwise and is
written to the output file.
Signed-off-by: Michael Olbrich <m.olbrich@pengutronix.de>
The last partition may not be the one at the end of the image, so it
could happen, that file_size is overwritten with a smaller value.
It's usually not notiable because the value is only used for the initial
image size. The file can grow larger when it is actually filled.
Signed-off-by: Michael Olbrich <m.olbrich@pengutronix.de>
Handle the whole thing separately and more explicitly:
- check if an extended partition is needed first
- insert the extended partition and mark all logical partitions
Signed-off-by: Michael Olbrich <m.olbrich@pengutronix.de>
The current limitation of Genimage is that it is not able to create
MBR images that have primary partitions that start after a logical
partition. This can be useful for images that can be later resized based
on the actual device size - for this operation the partition must be at
the end of the device, and if it is present in a logical partition, it
must be resized first, making it a two-step process.
This commit adds the "forced-primary" flag which can be used to indicate
that the partition should be put into the disk's MBR instead of creating
another logical partition. Validation ensures that this syntax allows to
create such partitions only after an existing logical partition, and
that the maximum number of MBR entries woudn't be exceeded by doing so.
Test cases for valid and invalid configuiration has been added. Also
added few more details in the debug print to make it more obvious how
the MBR/EBR layout looks like.
Signed-off-by: Jan Čermák <sairon@sairon.cz>
All CHS addresses in the EBR should point to absolute address in the
image instead of the relative addresses, currently they are only
LBA-to-CHS conversion of the relative offsets. If correct, output of
`sfdisk -d` of the genimage-produced disk image piped back to `sfdisk
file.img` should produce binary identical (see note below) output.
However, it is not true, because the CHS addresses differ. Even though
the extended partition uses the 0xf type (LBA addressing) and CHS
addressing is limited to 1023 sectors, the generated output should be
comparable to other tools for easier debugging.
With this change the calculation of CHS addresses of the next EBRs and
logical partitions within the extended partition adds the proper offset,
so the addresses are absolute within the image.
Note: At least with the version of sfdisk I have tested with (from
util-linux 2.37.2), the image is not completely identical - there are
one byte differences in the MBR and each MBR. This is because even if
the partition type is set as 0xf, sfdisk produces the extended partition
and all the logical partition with 0x5 type.
Signed-off-by: Jan Čermák <sairon@sairon.cz>
When the volume label is set using tune2fs, the parameter is wrapped in
single quotes, so do the same when the label is set using mke2fs. This
allows the label to contain spaces and other special characters (except
for single quotes!).
Signed-off-by: Ian Abbott <abbotti@mev.co.uk>
Follow-up commit will add a barebox-env type GUID, so the plain
B shortcut will become confusing. In future, there might be even a
partition type GUID for the barebox binary itself making this even more
ambiguous. Avoid the confusion by just removing the B shorthand.
Signed-off-by: Ahmad Fatoum <a.fatoum@pengutronix.de>
We have been supporting fiptool for a while, but failed to document that
it's possible to override the path to it. Remedy that.
Signed-off-by: Ahmad Fatoum <a.fatoum@pengutronix.de>
The old URL now redirects to the libconfuse Repo of the libconfuse
Github Organization. Use the new link directly.
Signed-off-by: Ahmad Fatoum <a.fatoum@pengutronix.de>
This is useful for barebox images on (at least) i.MX8 to be written to
eMMC. There the first 32K of the image must be skipped.
Signed-off-by: Uwe Kleine-König <u.kleine-koenig@pengutronix.de>