summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorMichael Olbrich <m.olbrich@pengutronix.de>2019-09-21 12:20:03 +0200
committerMichael Olbrich <m.olbrich@pengutronix.de>2019-09-22 15:07:52 +0200
commitf4c889b5fc71a8cfff832bc41adf7a7c193ac3ee (patch)
tree22b8b7860c67f9c14710ac656de16be40f2760a5
parent3300b46aeb61d8eb0a723b7a3947ae4d95ba3666 (diff)
downloadgenimage-f4c889b5fc71a8cfff832bc41adf7a7c193ac3ee.tar.gz
genimage-f4c889b5fc71a8cfff832bc41adf7a7c193ac3ee.tar.xz
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>
-rw-r--r--README.rst5
-rw-r--r--genimage.c2
-rw-r--r--genimage.h1
-rw-r--r--image-ext2.c16
-rw-r--r--image-jffs2.c9
-rw-r--r--image-ubifs.c6
-rw-r--r--image-vfat.c5
-rw-r--r--util.c2
8 files changed, 33 insertions, 13 deletions
diff --git a/README.rst b/README.rst
index 2f62e85..e6ecd97 100644
--- a/README.rst
+++ b/README.rst
@@ -76,6 +76,11 @@ Here are all options for images:
:mountpoint: mountpoint if image refers to a filesystem image. The
default is "/". The content of "${rootpath}${mountpoint}"
will be used used fill the filesystem.
+:empty: If this is set to true, then the specified rootpath and
+ mountpoint are ignored for this image and an empty
+ filesystem is created. This option is only used for
+ writeable filesystem types, such as extX, vfat, ubifs and
+ jffs2. This defaults to false.
:exec-pre: Custom command to run before generating the image.
:exec-post: Custom command to run after generating the image.
:flashtype: refers to a flash section. Optional for non flash like images
diff --git a/genimage.c b/genimage.c
index aafd3b7..528c597 100644
--- a/genimage.c
+++ b/genimage.c
@@ -105,6 +105,7 @@ static cfg_opt_t image_common_opts[] = {
CFG_STR("name", NULL, CFGF_NONE),
CFG_STR("size", NULL, CFGF_NONE),
CFG_STR("mountpoint", NULL, CFGF_NONE),
+ CFG_BOOL("empty", cfg_false, CFGF_NONE),
CFG_STR("exec-pre", NULL, CFGF_NONE),
CFG_STR("exec-post", NULL, CFGF_NONE),
CFG_STR("flashtype", NULL, CFGF_NONE),
@@ -672,6 +673,7 @@ int main(int argc, char *argv[])
image->size = cfg_getint_suffix_percent(imagesec, "size",
&image->size_is_percent);
image->mountpoint = cfg_getstr(imagesec, "mountpoint");
+ image->empty = cfg_getbool(imagesec, "empty");
image->exec_pre = cfg_getstr(imagesec, "exec-pre");
image->exec_post = cfg_getstr(imagesec, "exec-post");
if (image->file[0] == '/')
diff --git a/genimage.h b/genimage.h
index eabcc46..357f842 100644
--- a/genimage.h
+++ b/genimage.h
@@ -53,6 +53,7 @@ struct image {
unsigned long long size;
cfg_bool_t size_is_percent;
const char *mountpoint;
+ cfg_bool_t empty;
const char *exec_pre;
const char *exec_post;
unsigned char partition_type;
diff --git a/image-ext2.c b/image-ext2.c
index 8ce76be..a1f53ff 100644
--- a/image-ext2.c
+++ b/image-ext2.c
@@ -39,10 +39,12 @@ static int ext2_generate_genext2fs(struct image *image)
const char *extraargs = cfg_getstr(image->imagesec, "extraargs");
const char *label = cfg_getstr(image->imagesec, "label");
- ret = systemp(image, "%s -d '%s' --size-in-blocks=%lld -i 16384 '%s' %s",
+ ret = systemp(image, "%s %s%s%s --size-in-blocks=%lld -i 16384 '%s' %s",
get_opt("genext2fs"),
- mountpath(image), image->size / 1024, imageoutfile(image),
- extraargs);
+ image->empty ? "" : "-d '",
+ image->empty ? "" : mountpath(image),
+ image->empty ? "" : "'",
+ image->size / 1024, imageoutfile(image), extraargs);
if (ret)
return ret;
@@ -76,11 +78,13 @@ static int ext2_generate_mke2fs(struct image *image)
if (is_block_device(imageoutfile(image)))
pad_file(image, NULL, 2048, 0x0, MODE_OVERWRITE);
- return systemp(image, "%s%s -t %s%s -E 'root_owner=%s,%s'%s -d '%s' %s %s%s '%s' %lld",
+ return systemp(image, "%s%s -t %s%s -E 'root_owner=%s,%s'%s %s%s%s %s %s%s '%s' %lld",
ext->conf_env, get_opt("mke2fs"), image->handler->type,
ext->usage_type_args, root_owner, options, ext->size_features,
- mountpath(image), extraargs,
- label ? "-L " : "", label ? label : "",
+ image->empty ? "" : "-d '",
+ image->empty ? "" : mountpath(image),
+ image->empty ? "" : "'",
+ extraargs, label ? "-L " : "", label ? label : "",
imageoutfile(image), image->size / 1024);
}
diff --git a/image-jffs2.c b/image-jffs2.c
index 6c8dd52..8376e40 100644
--- a/image-jffs2.c
+++ b/image-jffs2.c
@@ -29,10 +29,13 @@ static int jffs2_generate(struct image *image)
extraargs = cfg_getstr(image->imagesec, "extraargs");
- ret = systemp(image, "%s --eraseblock=%d -d '%s' -o '%s' %s",
+ ret = systemp(image, "%s --eraseblock=%d %s%s%s -o '%s' %s",
get_opt("mkfsjffs2"),
- image->flash_type->pebsize, mountpath(image), imageoutfile(image),
- extraargs);
+ image->flash_type->pebsize,
+ image->empty ? "" : "-d '",
+ image->empty ? "" : mountpath(image),
+ image->empty ? "" : "'",
+ imageoutfile(image), extraargs);
return ret;
}
diff --git a/image-ubifs.c b/image-ubifs.c
index 994d733..79ff2ca 100644
--- a/image-ubifs.c
+++ b/image-ubifs.c
@@ -34,9 +34,11 @@ static int ubifs_generate(struct image *image)
else
max_leb_cnt = image->size / image->flash_type->lebsize;
- ret = systemp(image, "%s -d '%s' -e %d -m %d -c %d -o '%s' %s",
+ ret = systemp(image, "%s %s%s%s -e %d -m %d -c %d -o '%s' %s",
get_opt("mkfsubifs"),
- mountpath(image),
+ image->empty ? "" : "-d '",
+ image->empty ? "" : mountpath(image),
+ image->empty ? "" : "'",
image->flash_type->lebsize,
image->flash_type->minimum_io_unit_size,
max_leb_cnt,
diff --git a/image-vfat.c b/image-vfat.c
index f16242c..d3f7bdb 100644
--- a/image-vfat.c
+++ b/image-vfat.c
@@ -65,8 +65,9 @@ static int vfat_generate(struct image *image)
if (!list_empty(&image->partitions))
return 0;
- ret = systemp(image, "MTOOLS_SKIP_CHECK=1 %s -bsp -i '%s' '%s'/* ::",
- get_opt("mcopy"), imageoutfile(image), mountpath(image));
+ if (!image->empty)
+ ret = systemp(image, "MTOOLS_SKIP_CHECK=1 %s -bsp -i '%s' '%s'/* ::",
+ get_opt("mcopy"), imageoutfile(image), mountpath(image));
return ret;
}
diff --git a/util.c b/util.c
index f659548..120112e 100644
--- a/util.c
+++ b/util.c
@@ -657,5 +657,7 @@ static unsigned long long dir_size(struct image *image, int dirfd,
unsigned long long image_dir_size(struct image *image)
{
+ if (image->empty)
+ return 0;
return dir_size(image, AT_FDCWD, mountpath(image), 4096);
}