jffs2reset: support fristboot on unmounted UBI overlay
authorDaniel Golle <daniel@makrotopia.org>
Mon, 4 Jan 2021 18:05:07 +0000 (18:05 +0000)
committerDaniel Golle <daniel@makrotopia.org>
Mon, 4 Jan 2021 20:55:32 +0000 (20:55 +0000)
To erase the overlay partitions on systems using UBIFS overlay,
instead of writing the jffs2-marker, truncating the UBI volume to 0
has the desired effect.

Signed-off-by: Daniel Golle <daniel@makrotopia.org>
jffs2reset.c

index 2236e380bd82b9fd5e2c7171549b27cbb3e3ec5c..acff913409da7a7dd271cd16c6f76848905fdc53 100644 (file)
 
 #include <fcntl.h>
 #include <dirent.h>
+#include <stdint.h>
 #include <stdio.h>
 #include <stdlib.h>
 #include <string.h>
 #include <unistd.h>
 #include <getopt.h>
 
+#include <mtd/ubi-user.h>
 
 #include "libfstools/libfstools.h"
 #include "libfstools/volume.h"
@@ -79,6 +81,13 @@ static int jffs2_mark(struct volume *v)
                return -1;
        }
 
+       if (volume_identify(v) == FS_UBIFS) {
+               uint64_t llz = 0;
+               int ret = ioctl(fd, UBI_IOCVOLUP, &llz);
+               close(fd);
+               return ret;
+       }
+
        sz = write(fd, &deadc0de, sizeof(deadc0de));
        close(fd);