diff --git a/.github/workflows/tests.yml b/.github/workflows/tests.yml index d2def99..6b4f136 100644 --- a/.github/workflows/tests.yml +++ b/.github/workflows/tests.yml @@ -9,9 +9,9 @@ jobs: matrix: include: - os: ubuntu-20.04 - pkgs: device-tree-compiler rauc simg2img u-boot-tools + pkgs: device-tree-compiler rauc simg2img u-boot-tools f2fs-tools - os: ubuntu-18.04 - pkgs: device-tree-compiler simg2img u-boot-tools + pkgs: device-tree-compiler simg2img u-boot-tools f2fs-tools steps: - name: Inspect environment diff --git a/Makefile.am b/Makefile.am index 30fe973..738df65 100644 --- a/Makefile.am +++ b/Makefile.am @@ -22,6 +22,7 @@ genimage_SOURCES = \ image-cpio.c \ image-cramfs.c \ image-ext2.c \ + image-f2fs.c \ image-file.c \ image-fit.c \ image-flash.c \ @@ -66,6 +67,7 @@ EXTRA_DIST += \ test/ext4.config \ test/ext4test.0.dump \ test/ext4test.1.dump \ + test/f2fs.config \ test/fit.its \ test/fit.config \ test/flash-types.config \ diff --git a/config.c b/config.c index 9734fe4..c8eb454 100644 --- a/config.c +++ b/config.c @@ -398,6 +398,16 @@ static struct config opts[] = { .opt = CFG_STR("mkfsjffs2", NULL, CFGF_NONE), .env = "GENIMAGE_MKFJFFS2", .def = "mkfs.jffs2", + }, { + .name = "mkfsf2fs", + .opt = CFG_STR("mkfsf2fs", NULL, CFGF_NONE), + .env = "GENIMAGE_MKFSF2FS", + .def = "mkfs.f2fs", + }, { + .name = "sloadf2fs", + .opt = CFG_STR("sloadf2fs", NULL, CFGF_NONE), + .env = "GENIMAGE_SLOADF2FS", + .def = "sload.f2fs", }, { .name = "mkfsubifs", .opt = CFG_STR("mkfsubifs", NULL, CFGF_NONE), diff --git a/genimage.c b/genimage.c index 9071dfc..a568d12 100644 --- a/genimage.c +++ b/genimage.c @@ -44,6 +44,7 @@ static struct image_handler *handlers[] = { &ext2_handler, &ext3_handler, &ext4_handler, + &f2fs_handler, &file_handler, &fit_handler, &flash_handler, diff --git a/genimage.h b/genimage.h index 71291c5..4ceb7c0 100644 --- a/genimage.h +++ b/genimage.h @@ -105,6 +105,7 @@ extern struct image_handler cramfs_handler; extern struct image_handler ext2_handler; extern struct image_handler ext3_handler; extern struct image_handler ext4_handler; +extern struct image_handler f2fs_handler; extern struct image_handler file_handler; extern struct image_handler flash_handler; extern struct image_handler hdimage_handler; diff --git a/image-f2fs.c b/image-f2fs.c new file mode 100644 index 0000000..e4dda24 --- /dev/null +++ b/image-f2fs.c @@ -0,0 +1,68 @@ +/* + * Copyright (c) 2022 Tomas Mudrunka + * + * This program is free software; you can redistribute it and/or modify + * it under the terms of the GNU General Public License version 2 + * as published by the Free Software Foundation. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with this program. If not, see . + */ + +#include +#include +#include +#include +#include + +#include "genimage.h" + +static int f2fs_generate(struct image *image) +{ + int ret; + + char *extraargs = cfg_getstr(image->imagesec, "extraargs"); + char *label = cfg_getstr(image->imagesec, "label"); + + extraargs = cfg_getstr(image->imagesec, "extraargs"); + + ret = prepare_image(image, image->size); + if(ret) + return ret; + + ret = systemp(image, "%s %s %s%s%s %s '%s'", + get_opt("mkfsf2fs"), + label ? "-l" : "", + label ? "'" : "", + label ? label : "", + label ? "'" : "", + extraargs, + imageoutfile(image)); + + if(ret || image->empty) + return ret; + + ret = systemp(image, "%s -f '%s' '%s'", + get_opt("sloadf2fs"), + mountpath(image), + imageoutfile(image)); + + return ret; +} + +static cfg_opt_t f2fs_opts[] = { + CFG_STR("extraargs", "", CFGF_NONE), + CFG_STR("label", NULL, CFGF_NONE), + CFG_END() +}; + +struct image_handler f2fs_handler = { + .type = "f2fs", + .generate = f2fs_generate, + .opts = f2fs_opts, +}; diff --git a/test/basic-images.test b/test/basic-images.test index efddc34..c2245d5 100755 --- a/test/basic-images.test +++ b/test/basic-images.test @@ -339,6 +339,14 @@ test_expect_success mkfs_jffs2 "jffs2" " md5sum -c '${testdir}/jffs2.md5' " +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 && + fsck.f2fs images/test.f2fs +" + exec_test_set_prereq dd exec_test_set_prereq diff exec_test_set_prereq qemu-img diff --git a/test/f2fs.config b/test/f2fs.config new file mode 100644 index 0000000..1c93ba9 --- /dev/null +++ b/test/f2fs.config @@ -0,0 +1,6 @@ +image test.f2fs { + f2fs { + label = "f2fstest" + } + size = 64M +}