summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorMichael Olbrich <m.olbrich@pengutronix.de>2019-05-11 14:03:45 +0000
committerGitHub <noreply@github.com>2019-05-11 14:03:45 +0000
commite685816116362afa64b15e510cc4a2d04a63243c (patch)
treecc596e17ceff18b34f49edc0d1e650abb66106d7
parent28152c298beb5796625bc5f1cceec7eda18e1d17 (diff)
parent1ff8c61b30dd94ee9094568c373d4ed2daceed27 (diff)
downloadgenimage-e685816116362afa64b15e510cc4a2d04a63243c.tar.gz
genimage-e685816116362afa64b15e510cc4a2d04a63243c.tar.xz
Merge pull request #59 from michaelolbrich/autoresize
hdimge: allow the last partition to fill the rest of the image
-rw-r--r--README.rst12
-rw-r--r--image-hd.c73
-rw-r--r--test/hdimage.config3
3 files changed, 57 insertions, 31 deletions
diff --git a/README.rst b/README.rst
index 67a648a..92ae9e8 100644
--- a/README.rst
+++ b/README.rst
@@ -89,12 +89,16 @@ Partition options:
:offset: The offset of this partition as a total offset to the beginning
of the device.
-:size: The size of this partition in bytes. The last partition may have
- size 0 to make this partition use the rest of the available space
- on the device.
+:size: The size of this partition in bytes. If the size and
+ autoresize are both not set then the size of the partition
+ image is used.
:partition-type: Used by dos partition tables to specify the partition type.
:image: The image file this partition shall be filled with
-:autoresize: used by ubi (FIXME: do we need this? Isn't size = 0 enough)
+:autoresize: Boolean specifying that the partition should be resized
+ automatically. For UBI volumes this means that the
+ ``autoresize`` flag is set. Only one volume can have this flag.
+ For hd images this can be used for the last partition. If set
+ the partition will fill the remaining space of the image.
:bootable: Boolean specifying whether to set the bootable flag.
:in-partition-table: Boolean specifying whether to include this partition in
the partition table.
diff --git a/image-hd.c b/image-hd.c
index 1f80ae7..90f550e 100644
--- a/image-hd.c
+++ b/image-hd.c
@@ -404,7 +404,7 @@ static unsigned long long roundup(unsigned long long value, unsigned long long a
static int hdimage_setup(struct image *image, cfg_t *cfg)
{
struct partition *part;
- int has_extended;
+ int has_extended, autoresize = 0;
unsigned int partition_table_entries = 0;
unsigned long long now = 0;
struct hdimage *hd = xzalloc(sizeof(*hd));
@@ -448,33 +448,15 @@ static int hdimage_setup(struct image *image, cfg_t *cfg)
partition_table_entries = 0;
list_for_each_entry(part, &image->partitions, list) {
- if (part->image) {
- struct image *child = image_get(part->image);
- if (!child) {
- image_error(image, "could not find %s\n",
- part->image);
- return -EINVAL;
- }
- if (!part->size) {
- if (part->in_partition_table)
- part->size = roundup(child->size, hd->align);
- else
- part->size = child->size;
- } else if (child->size > part->size) {
- image_error(image, "part %s size (%lld) too small for %s (%lld)\n",
- part->name, part->size, child->file, child->size);
- return -EINVAL;
- }
- }
- if (!part->size) {
- image_error(image, "part %s size must not be zero\n",
- part->name);
+ if (autoresize) {
+ image_error(image, "'autoresize' is only supported "
+ "for the last partition\n");
return -EINVAL;
}
- if (part->in_partition_table && (part->size % 512)) {
- image_error(image, "part %s size (%lld) must be a "
- "multiple of 1 sector (512 bytes)\n",
- part->name, part->size);
+ autoresize = part->autoresize;
+ if (autoresize && image->size == 0) {
+ image_error(image, "the images size must be specified "
+ "when using a 'autoresize' partition\n");
return -EINVAL;
}
if (hd->gpt) {
@@ -538,6 +520,45 @@ static int hdimage_setup(struct image *image, cfg_t *cfg)
}
part->offset = roundup(now, hd->align);
}
+ if (autoresize) {
+ long long partsize = image->size - now;
+ if (hd->gpt)
+ partsize -= GPT_SECTORS * 512;
+ if (partsize < 0) {
+ image_error(image, "partitions exceed device size\n");
+ return -EINVAL;
+ }
+ part->size = partsize;
+ }
+ if (part->image) {
+ struct image *child = image_get(part->image);
+ if (!child) {
+ image_error(image, "could not find %s\n",
+ part->image);
+ return -EINVAL;
+ }
+ if (!part->size) {
+ if (part->in_partition_table)
+ part->size = roundup(child->size, hd->align);
+ else
+ part->size = child->size;
+ } else if (child->size > part->size) {
+ image_error(image, "part %s size (%lld) too small for %s (%lld)\n",
+ part->name, part->size, child->file, child->size);
+ return -EINVAL;
+ }
+ }
+ if (!part->size) {
+ image_error(image, "part %s size must not be zero\n",
+ part->name);
+ return -EINVAL;
+ }
+ if (part->in_partition_table && (part->size % 512)) {
+ image_error(image, "part %s size (%lld) must be a "
+ "multiple of 1 sector (512 bytes)\n",
+ part->name, part->size);
+ return -EINVAL;
+ }
now = part->offset + part->size;
}
diff --git a/test/hdimage.config b/test/hdimage.config
index 7287b6d..117e69f 100644
--- a/test/hdimage.config
+++ b/test/hdimage.config
@@ -68,7 +68,8 @@ image test.hdimage-2 {
}
partition part6 {
image = "part2.img"
- size = 1M
+ autoresize = true
partition-type = 0x83
}
+ size = 12M
}