mirror of
https://github.com/pengutronix/genimage.git
synced 2024-11-23 01:34:12 +08:00
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>
This commit is contained in:
parent
d44f4aaec4
commit
cfd0426a62
15
config.c
15
config.c
@ -284,14 +284,19 @@ const char *inputpath(void)
|
||||
return inputpath;
|
||||
}
|
||||
|
||||
static const char *cached_rootpath;
|
||||
|
||||
void disable_rootpath(void)
|
||||
{
|
||||
cached_rootpath = "";
|
||||
}
|
||||
|
||||
const char *rootpath(void)
|
||||
{
|
||||
static const char *rootpath;
|
||||
if (!cached_rootpath)
|
||||
cached_rootpath = abspath(get_opt("rootpath"));
|
||||
|
||||
if (!rootpath)
|
||||
rootpath = abspath(get_opt("rootpath"));
|
||||
|
||||
return rootpath;
|
||||
return cached_rootpath;
|
||||
}
|
||||
|
||||
const char *tmppath(void)
|
||||
|
21
genimage.c
21
genimage.c
@ -426,7 +426,18 @@ static int collect_mountpoints(void)
|
||||
{
|
||||
struct image *image;
|
||||
struct mountpoint *mp;
|
||||
int ret, need_mtime_fixup = 0;
|
||||
int ret, need_mtime_fixup = 0, need_root = 0;
|
||||
|
||||
list_for_each_entry(image, &images, list) {
|
||||
if (!(image->empty || image->handler->no_rootpath || image->srcpath)) {
|
||||
need_root = 1;
|
||||
break;
|
||||
}
|
||||
}
|
||||
if (!need_root) {
|
||||
disable_rootpath();
|
||||
return 0;
|
||||
}
|
||||
|
||||
add_root_mountpoint();
|
||||
|
||||
@ -480,6 +491,9 @@ const char *mountpath(const struct image *image)
|
||||
|
||||
struct mountpoint *mp;
|
||||
|
||||
if (image->empty || image->handler->no_rootpath)
|
||||
return "";
|
||||
|
||||
mp = image->mp;
|
||||
if (!mp)
|
||||
mp = get_mountpoint("");
|
||||
@ -805,6 +819,11 @@ int main(int argc, char *argv[])
|
||||
list_add_tail(&child->list, &images);
|
||||
child->file = part->image;
|
||||
child->handler = &file_handler;
|
||||
if (child->handler->parse) {
|
||||
ret = child->handler->parse(child, child->imagesec);
|
||||
if (ret)
|
||||
goto cleanup;
|
||||
}
|
||||
parse_holes(child, part->cfg);
|
||||
}
|
||||
}
|
||||
|
@ -19,6 +19,7 @@ void image_debug(struct image *image, const char *fmt, ...) __attribute__ ((form
|
||||
void xasprintf(char **strp, const char *fmt, ...) __attribute__ ((format(printf, 2, 3)));
|
||||
void xstrcatf(char **strp, const char *fmt, ...) __attribute__ ((format(printf, 2, 3)));
|
||||
|
||||
void disable_rootpath(void);
|
||||
const char *imagepath(void);
|
||||
const char *inputpath(void);
|
||||
const char *rootpath(void);
|
||||
@ -81,6 +82,7 @@ struct image {
|
||||
|
||||
struct image_handler {
|
||||
char *type;
|
||||
cfg_bool_t no_rootpath;
|
||||
int (*parse)(struct image *i, cfg_t *cfg);
|
||||
int (*setup)(struct image *i, cfg_t *cfg);
|
||||
int (*generate)(struct image *i);
|
||||
|
@ -395,6 +395,7 @@ static cfg_opt_t android_sparse_opts[] = {
|
||||
|
||||
struct image_handler android_sparse_handler = {
|
||||
.type = "android-sparse",
|
||||
.no_rootpath = cfg_true,
|
||||
.generate = android_sparse_generate,
|
||||
.parse = android_sparse_parse,
|
||||
.setup = android_sparse_setup,
|
||||
|
11
image-file.c
11
image-file.c
@ -89,6 +89,16 @@ static int file_setup(struct image *image, cfg_t *cfg)
|
||||
return 0;
|
||||
}
|
||||
|
||||
static int file_parse(struct image *image, cfg_t *cfg)
|
||||
{
|
||||
/* File type images are used for custom types so assume that the
|
||||
* rootpath is need when a pre/post command is defined */
|
||||
if (!image->exec_pre && !image->exec_post)
|
||||
image->empty = cfg_true;
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
||||
static cfg_opt_t file_opts[] = {
|
||||
CFG_STR("name", NULL, CFGF_NONE),
|
||||
CFG_BOOL("copy", cfg_true, CFGF_NONE),
|
||||
@ -100,6 +110,7 @@ struct image_handler file_handler = {
|
||||
.type = "file",
|
||||
.generate = file_generate,
|
||||
.setup = file_setup,
|
||||
.parse = file_parse,
|
||||
.opts = file_opts,
|
||||
};
|
||||
|
||||
|
@ -118,6 +118,7 @@ static cfg_opt_t fit_opts[] = {
|
||||
|
||||
struct image_handler fit_handler = {
|
||||
.type = "fit",
|
||||
.no_rootpath = cfg_true,
|
||||
.generate = fit_generate,
|
||||
.parse = fit_parse,
|
||||
.opts = fit_opts,
|
||||
|
@ -153,6 +153,7 @@ static cfg_opt_t flash_opts[] = {
|
||||
|
||||
struct image_handler flash_handler = {
|
||||
.type = "flash",
|
||||
.no_rootpath = cfg_true,
|
||||
.generate = flash_generate,
|
||||
.setup = flash_setup,
|
||||
.opts = flash_opts,
|
||||
|
@ -932,6 +932,7 @@ static cfg_opt_t hdimage_opts[] = {
|
||||
|
||||
struct image_handler hdimage_handler = {
|
||||
.type = "hdimage",
|
||||
.no_rootpath = cfg_true,
|
||||
.generate = hdimage_generate,
|
||||
.setup = hdimage_setup,
|
||||
.opts = hdimage_opts,
|
||||
|
@ -97,6 +97,7 @@ static cfg_opt_t qemu_opts[] = {
|
||||
|
||||
struct image_handler qemu_handler = {
|
||||
.type = "qemu",
|
||||
.no_rootpath = cfg_true,
|
||||
.generate = qemu_generate,
|
||||
.setup = qemu_setup,
|
||||
.opts = qemu_opts,
|
||||
|
@ -236,6 +236,7 @@ static cfg_opt_t rauc_opts[] = {
|
||||
|
||||
struct image_handler rauc_handler = {
|
||||
.type = "rauc",
|
||||
.no_rootpath = cfg_true,
|
||||
.generate = rauc_generate,
|
||||
.parse = rauc_parse,
|
||||
.setup = rauc_setup,
|
||||
|
@ -123,6 +123,7 @@ static cfg_opt_t ubi_opts[] = {
|
||||
|
||||
struct image_handler ubi_handler = {
|
||||
.type = "ubi",
|
||||
.no_rootpath = cfg_true,
|
||||
.generate = ubi_generate,
|
||||
.setup = ubi_setup,
|
||||
.opts = ubi_opts,
|
||||
|
@ -14,7 +14,7 @@ set -- -v "$@"
|
||||
|
||||
filelist_orig="$(pwd)/file-list.orig"
|
||||
filelist_test="$(pwd)/file-list.test"
|
||||
root_orig="$(pwd)/root"
|
||||
root_orig="$(pwd)/root.orig"
|
||||
root_test="$(pwd)/root.test"
|
||||
|
||||
setup_data() {
|
||||
@ -27,7 +27,7 @@ setup_data() {
|
||||
cp "${testdir}"/*.conf* "${testdir}"/*.sh .
|
||||
}
|
||||
|
||||
run_genimage() {
|
||||
run_genimage_impl() {
|
||||
if [ "$verbose" = "t" ]; then
|
||||
vargs="--loglevel=3"
|
||||
fi
|
||||
@ -41,12 +41,20 @@ run_genimage() {
|
||||
${vargs} \
|
||||
--outputpath=images \
|
||||
--inputpath=input \
|
||||
--rootpath=root \
|
||||
--rootpath="${root}" \
|
||||
--tmppath=tmp \
|
||||
${extra_opts} \
|
||||
--config "${1}"
|
||||
}
|
||||
|
||||
run_genimage_root() {
|
||||
root="root.orig" run_genimage_impl "${@}"
|
||||
}
|
||||
|
||||
run_genimage() {
|
||||
root="/this/directory/does/not/exist" run_genimage_impl "${@}"
|
||||
}
|
||||
|
||||
func_check() {
|
||||
local ret="$?"
|
||||
set +x
|
||||
@ -129,7 +137,7 @@ set -o pipefail
|
||||
|
||||
exec_test_set_prereq cpio
|
||||
test_expect_success cpio "cpio" "
|
||||
run_genimage cpio.config test.cpio &&
|
||||
run_genimage_root cpio.config test.cpio &&
|
||||
zcat images/test.cpio | cpio --extract -t | grep -v '^\.$' | sort > '${filelist_test}' &&
|
||||
check_size_range images/test.cpio 400 550 &&
|
||||
check_filelist
|
||||
@ -137,7 +145,7 @@ test_expect_success cpio "cpio" "
|
||||
|
||||
exec_test_set_prereq mkcramfs
|
||||
test_expect_success mkcramfs "cramfs" "
|
||||
run_genimage cramfs.config test.cramfs &&
|
||||
run_genimage_root cramfs.config test.cramfs &&
|
||||
check_size images/test.cramfs 4096
|
||||
"
|
||||
|
||||
@ -199,17 +207,17 @@ check_ext() {
|
||||
exec_test_set_prereq genext2fs
|
||||
exec_test_set_prereq e2fsck
|
||||
test_expect_success genext2fs,e2fsck "ext2" "
|
||||
run_genimage ext2.config test.ext2 &&
|
||||
run_genimage_root ext2.config test.ext2 &&
|
||||
check_ext images/test.ext2 ext2test 4194304 genext2fs
|
||||
"
|
||||
|
||||
test_expect_success genext2fs,e2fsck "ext2percent" "
|
||||
run_genimage ext2percent.config test.ext2 &&
|
||||
run_genimage_root ext2percent.config test.ext2 &&
|
||||
check_ext images/test.ext2 ext2test-percent 69632 genext2fs
|
||||
"
|
||||
|
||||
test_expect_success genext2fs,e2fsck "ext3" "
|
||||
run_genimage ext3.config test.ext3 &&
|
||||
run_genimage_root ext3.config test.ext3 &&
|
||||
check_ext images/test.ext3 ext3test 4194304 genext2fs
|
||||
"
|
||||
|
||||
@ -221,7 +229,7 @@ test_expect_success genext2fs,e2fsck "ext4" "
|
||||
# make sure mke2fs supports '-d root-directory'
|
||||
[ "$(mke2fs |& sed -n 's/.*\(-d \).*/\1/p')" = "-d " ] && test_set_prereq mke2fs
|
||||
test_expect_success mke2fs,e2fsck "mke2fs" "
|
||||
run_genimage mke2fs.config mke2fs.ext4 &&
|
||||
run_genimage_root mke2fs.config mke2fs.ext4 &&
|
||||
check_ext images/mke2fs.ext4 mke2fs 33554432 mke2fs
|
||||
"
|
||||
|
||||
@ -329,13 +337,13 @@ test_expect_success "hdimage syntax" "
|
||||
|
||||
exec_test_set_prereq genisoimage
|
||||
test_expect_success genisoimage "iso" "
|
||||
run_genimage iso.config test.iso &&
|
||||
run_genimage_root iso.config test.iso &&
|
||||
check_size_range images/test.iso 300000 400000
|
||||
"
|
||||
|
||||
exec_test_set_prereq mkfs.jffs2
|
||||
test_expect_success mkfs_jffs2 "jffs2" "
|
||||
run_genimage jffs2.config test.jffs2 &&
|
||||
run_genimage_root jffs2.config test.jffs2 &&
|
||||
md5sum -c '${testdir}/jffs2.md5'
|
||||
"
|
||||
|
||||
@ -343,7 +351,7 @@ exec_test_set_prereq mkfs.f2fs
|
||||
exec_test_set_prereq sload.f2fs
|
||||
exec_test_set_prereq fsck.f2fs
|
||||
test_expect_success mkfs_f2fs,sload_f2fs,fsck_f2fs "f2fs" "
|
||||
run_genimage f2fs.config test.f2fs &&
|
||||
run_genimage_root f2fs.config test.f2fs &&
|
||||
fsck.f2fs images/test.f2fs
|
||||
"
|
||||
|
||||
@ -360,7 +368,7 @@ test_expect_success dd,diff,qemu-img "qemu" "
|
||||
|
||||
exec_test_set_prereq mksquashfs
|
||||
test_expect_success mksquashfs "squashfs" "
|
||||
run_genimage squashfs.config test.squashfs &&
|
||||
run_genimage_root squashfs.config test.squashfs &&
|
||||
check_size_range images/test.squashfs 4000 4100 &&
|
||||
unsquashfs -ls images/test.squashfs | sed -n '/squashfs-root/s;squashfs-root/;;p' | sort > '${filelist_test}' &&
|
||||
check_filelist
|
||||
@ -368,7 +376,7 @@ test_expect_success mksquashfs "squashfs" "
|
||||
|
||||
exec_test_set_prereq tar
|
||||
test_expect_success tar "tar" "
|
||||
run_genimage tar.config test.tar.gz &&
|
||||
run_genimage_root tar.config test.tar.gz &&
|
||||
check_size_range images/test.tar.gz 500 600 &&
|
||||
zcat images/test.tar.gz | tar -t | sed -n -e 's;/$;;' -e 's;^\./\(..*\)$;\1;p' | sort > '${filelist_test}' &&
|
||||
check_filelist
|
||||
@ -376,7 +384,7 @@ test_expect_success tar "tar" "
|
||||
|
||||
exec_test_set_prereq mkfs.ubifs
|
||||
test_expect_success mkfs_ubifs "ubifs" "
|
||||
run_genimage ubifs.config test.ubifs &&
|
||||
run_genimage_root ubifs.config test.ubifs &&
|
||||
check_size_range images/test.ubifs 200000 300000
|
||||
"
|
||||
|
||||
@ -397,7 +405,7 @@ exec_test_set_prereq dd
|
||||
exec_test_set_prereq mkdosfs
|
||||
exec_test_set_prereq mcopy
|
||||
test_expect_success dd,mkdosfs,mcopy "vfat" "
|
||||
run_genimage vfat.config test.vfat &&
|
||||
run_genimage_root vfat.config test.vfat &&
|
||||
fsck.fat -p images/test.vfat | tee fsck.log &&
|
||||
test_must_fail grep -q 'Filesystem was changed' fsck.log &&
|
||||
check_size images/test.vfat 4193280 &&
|
||||
@ -473,11 +481,11 @@ setup_exec_files() {
|
||||
|
||||
test_expect_success "exec" "
|
||||
setup_exec_files &&
|
||||
run_genimage exec.config"
|
||||
run_genimage_root exec.config"
|
||||
|
||||
test_expect_success "exec-fail" "
|
||||
setup_exec_files &&
|
||||
test_must_fail run_genimage exec-fail.config"
|
||||
test_must_fail run_genimage_root exec-fail.config"
|
||||
|
||||
setup_gpt_files() {
|
||||
rm -rf input &&
|
||||
|
@ -12,7 +12,7 @@ test "${OUTPUTPATH}" = "${PWD}/images"
|
||||
: INPUTPATH
|
||||
test "${INPUTPATH}" = "${PWD}/input"
|
||||
: ROOTPATH
|
||||
test "${ROOTPATH}" = "${PWD}/root"
|
||||
test "${ROOTPATH}" = "${PWD}/root.orig"
|
||||
: TMPPATH
|
||||
test "${TMPPATH}" = "${PWD}/tmp"
|
||||
: IMAGE
|
||||
|
@ -3,5 +3,6 @@ image test.ext4 {
|
||||
label = "ext4test"
|
||||
fs-timestamp = "20000101000000"
|
||||
}
|
||||
srcpath = "root.orig"
|
||||
size = 4M
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user