Initial commit

This commit is contained in:
domenico
2025-06-24 16:03:39 +02:00
commit f3256cdaf2
6949 changed files with 1441681 additions and 0 deletions

55
tools/mtd-utils/Makefile Normal file
View File

@@ -0,0 +1,55 @@
#
# Copyright (C) 2006-2015 OpenWrt.org
#
# This is free software, licensed under the GNU General Public License v2.
# See /LICENSE for more information.
#
include $(TOPDIR)/rules.mk
PKG_NAME:=mtd-utils
PKG_VERSION:=2.1.1
PKG_SOURCE:=$(PKG_NAME)-$(PKG_VERSION).tar.bz2
PKG_SOURCE_URL:=ftp://ftp.infradead.org/pub/mtd-utils/
PKG_HASH:=8d15e8b70f036d6af1a66011f8ca0e048e9675fa7983d33bea92c24313a232d2
PKG_FIXUP:=autoreconf
include $(INCLUDE_DIR)/host-build.mk
ifneq ($(HOST_OS),Linux)
HOST_CFLAGS += \
-I$(CURDIR)/include \
-Dloff_t=off_t \
-D__BYTE_ORDER=BYTE_ORDER \
-include endian.h \
-DNO_NATIVE_SUPPORT \
-include fls.h
endif
HOST_CONFIGURE_VARS+= \
UUID_CFLAGS="-I$(STAGING_DIR_HOST)/include/e2fsprogs/uuid"
HOST_CONFIGURE_ARGS+= \
--disable-tests \
--without-crypto \
--without-xattr \
--without-zstd \
--without-lzo
HOST_MAKE_FLAGS += \
PROGRAMS="mkfs.jffs2 ubinize mkfs.ubifs"
define Host/Install
$(CP) \
$(HOST_BUILD_DIR)/mkfs.jffs2 \
$(HOST_BUILD_DIR)/mkfs.ubifs \
$(HOST_BUILD_DIR)/ubinize \
$(STAGING_DIR_HOST)/bin/
endef
define Host/Clean
rm -f $(STAGING_DIR_HOST)/bin/{mkfs.jffs2,mkfs.ubifs,ubinize}
endef
$(eval $(call HostBuild))

View File

@@ -0,0 +1,2 @@
#include <string.h>
#define fls local_fls

View File

@@ -0,0 +1,18 @@
#ifndef _LINUX_TYPES_H
#define _LINUX_TYPES_H
#include <mtd/ubi-media.h>
typedef uint16_t __u16;
typedef uint32_t __u32;
typedef uint64_t __u64;
typedef __u16 __le16;
typedef __u32 __le32;
typedef __u64 __le64;
typedef __u64 off64_t;
typedef __u16 __sum16;
typedef __u32 __wsum;
#endif /* _LINUX_TYPES_H */

View File

@@ -0,0 +1,11 @@
--- a/jffsX-utils/mkfs.jffs2.c
+++ b/jffsX-utils/mkfs.jffs2.c
@@ -427,7 +427,7 @@ static int interpret_table_entry(struct
if (sscanf (line, "%" SCANF_PREFIX "s %c %lo %lu %lu %lu %lu %lu %lu %lu",
SCANF_STRING(name), &type, &mode, &uid, &gid, &major, &minor,
- &start, &increment, &count) < 0)
+ &start, &increment, &count) < 10)
{
return 1;
}

View File

@@ -0,0 +1,175 @@
--- a/jffsX-utils/compr_lzo.c
+++ b/jffsX-utils/compr_lzo.c
@@ -26,7 +26,6 @@
#include <string.h>
#ifndef WITHOUT_LZO
-#include <asm/types.h>
#include <linux/jffs2.h>
#include <lzo/lzo1x.h>
#include "compr.h"
--- a/jffsX-utils/compr_zlib.c
+++ b/jffsX-utils/compr_zlib.c
@@ -39,7 +39,6 @@
#include <zlib.h>
#undef crc32
#include <stdio.h>
-#include <asm/types.h>
#include <linux/jffs2.h>
#include "common.h"
#include "compr.h"
--- a/jffsX-utils/rbtree.h
+++ b/jffsX-utils/rbtree.h
@@ -94,8 +94,7 @@ static inline struct page * rb_insert_pa
#ifndef _LINUX_RBTREE_H
#define _LINUX_RBTREE_H
-#include <linux/kernel.h>
-#include <linux/stddef.h>
+#include <stddef.h>
struct rb_node
{
--- a/include/mtd/ubi-media.h
+++ b/include/mtd/ubi-media.h
@@ -30,7 +30,15 @@
#ifndef __UBI_MEDIA_H__
#define __UBI_MEDIA_H__
+#ifdef __linux__
#include <asm/byteorder.h>
+#else
+#include <stdint.h>
+typedef uint8_t __u8;
+typedef uint16_t __be16;
+typedef uint32_t __be32;
+typedef uint64_t __be64;
+#endif
/* The version of UBI images supported by this implementation */
#define UBI_VERSION 1
--- a/ubifs-utils/mkfs.ubifs/mkfs.ubifs.h
+++ b/ubifs-utils/mkfs.ubifs/mkfs.ubifs.h
@@ -32,7 +32,17 @@
#include <endian.h>
#include <byteswap.h>
#include <linux/types.h>
+#ifdef __linux__
#include <linux/fs.h>
+# if defined(__x86_64__) && defined(__ILP32__)
+# define llseek lseek64
+# endif
+#else
+# ifndef O_LARGEFILE
+# define O_LARGEFILE 0
+# endif
+# define llseek lseek
+#endif
#include <getopt.h>
#include <sys/types.h>
--- a/ubifs-utils/mkfs.ubifs/mkfs.ubifs.c
+++ b/ubifs-utils/mkfs.ubifs/mkfs.ubifs.c
@@ -1503,6 +1503,7 @@ static int add_inode(struct stat *st, in
if (c->default_compr != UBIFS_COMPR_NONE)
use_flags |= UBIFS_COMPR_FL;
+#ifndef NO_NATIVE_SUPPORT
if (flags & FS_COMPR_FL)
use_flags |= UBIFS_COMPR_FL;
if (flags & FS_SYNC_FL)
@@ -1515,6 +1516,7 @@ static int add_inode(struct stat *st, in
use_flags |= UBIFS_DIRSYNC_FL;
if (fctx)
use_flags |= UBIFS_CRYPT_FL;
+#endif
memset(ino, 0, UBIFS_INO_NODE_SZ);
ino_key_init(&key, inum);
@@ -1600,7 +1602,9 @@ static int add_dir_inode(const char *pat
fd = dirfd(dir);
if (fd == -1)
return sys_err_msg("dirfd failed");
+#ifndef NO_NATIVE_SUPPORT
if (ioctl(fd, FS_IOC_GETFLAGS, &flags) == -1)
+#endif
flags = 0;
}
@@ -1811,6 +1815,7 @@ static int add_file(const char *path_nam
dn->ch.node_type = UBIFS_DATA_NODE;
key_write(&key, &dn->key);
out_len = NODE_BUFFER_SIZE - UBIFS_DATA_NODE_SZ;
+#ifndef NO_NATIVE_SUPPORT
if (c->default_compr == UBIFS_COMPR_NONE &&
!c->encrypted && (flags & FS_COMPR_FL))
#ifdef WITHOUT_LZO
@@ -1819,6 +1824,7 @@ static int add_file(const char *path_nam
use_compr = UBIFS_COMPR_LZO;
#endif
else
+#endif
use_compr = c->default_compr;
compr_type = compress_data(buf, bytes_read, &dn->data,
&out_len, use_compr);
@@ -1876,7 +1882,9 @@ static int add_non_dir(const char *path_
if (fd == -1)
return sys_err_msg("failed to open file '%s'",
path_name);
+#ifndef NO_NATIVE_SUPPORT
if (ioctl(fd, FS_IOC_GETFLAGS, &flags) == -1)
+#endif
flags = 0;
if (close(fd) == -1)
return sys_err_msg("failed to close file '%s'",
--- a/ubifs-utils/mkfs.ubifs/devtable.c
+++ b/ubifs-utils/mkfs.ubifs/devtable.c
@@ -135,6 +135,7 @@ static int interpret_table_entry(const c
unsigned int mode = 0755, uid = 0, gid = 0, major = 0, minor = 0;
unsigned int start = 0, increment = 0, count = 0;
+ buf[1023] = 0;
if (sscanf(line, "%1023s %c %o %u %u %u %u %u %u %u",
buf, &type, &mode, &uid, &gid, &major, &minor,
&start, &increment, &count) < 0)
@@ -145,10 +146,10 @@ static int interpret_table_entry(const c
buf, type, mode, uid, gid, major, minor, start,
increment, count);
- len = strnlen(buf, 1024);
+ len = strlen(buf);
if (len == 0)
return err_msg("empty path");
- if (len == 1024)
+ if (len == 1023)
return err_msg("too long path");
if (buf[0] != '/')
--- a/include/common.h
+++ b/include/common.h
@@ -26,7 +26,6 @@
#include <string.h>
#include <fcntl.h>
#include <errno.h>
-#include <features.h>
#include <inttypes.h>
#include <unistd.h>
#include <sys/sysmacros.h>
--- a/include/mtd/ubifs-media.h
+++ b/include/mtd/ubifs-media.h
@@ -33,7 +33,15 @@
#ifndef __UBIFS_MEDIA_H__
#define __UBIFS_MEDIA_H__
+#ifdef __linux__
#include <asm/byteorder.h>
+#else
+#include <stdint.h>
+typedef uint8_t __u8;
+typedef uint16_t __be16;
+typedef uint32_t __be32;
+typedef uint64_t __be64;
+#endif
/* UBIFS node magic number (must not have the padding byte first or last) */
#define UBIFS_NODE_MAGIC 0x06101831

File diff suppressed because it is too large Load Diff

View File

@@ -0,0 +1,14 @@
--- a/include/mtd/mtd-abi.h
+++ b/include/mtd/mtd-abi.h
@@ -171,9 +171,9 @@ struct otp_info {
/* Get info about OOB modes (e.g., RAW, PLACE, AUTO) - legacy interface */
#define MEMGETOOBSEL _IOR('M', 10, struct nand_oobinfo)
/* Check if an eraseblock is bad */
-#define MEMGETBADBLOCK _IOW('M', 11, __kernel_loff_t)
+#define MEMGETBADBLOCK _IOW('M', 11, loff_t)
/* Mark an eraseblock as bad */
-#define MEMSETBADBLOCK _IOW('M', 12, __kernel_loff_t)
+#define MEMSETBADBLOCK _IOW('M', 12, loff_t)
/* Set OTP (One-Time Programmable) mode (factory vs. user) */
#define OTPSELECT _IOR('M', 13, int)
/* Get number of OTP (One-Time Programmable) regions */

View File

@@ -0,0 +1,89 @@
--- a/lib/libubigen.c
+++ b/lib/libubigen.c
@@ -122,8 +122,9 @@ int ubigen_add_volume(const struct ubige
return 0;
}
-void ubigen_init_ec_hdr(const struct ubigen_info *ui,
- struct ubi_ec_hdr *hdr, long long ec)
+static void __ubigen_init_ec_hdr(const struct ubigen_info *ui,
+ struct ubi_ec_hdr *hdr, long long ec,
+ int eof)
{
uint32_t crc;
@@ -136,10 +137,22 @@ void ubigen_init_ec_hdr(const struct ubi
hdr->data_offset = cpu_to_be32(ui->data_offs);
hdr->image_seq = cpu_to_be32(ui->image_seq);
+ if (eof) {
+ hdr->padding1[0] = 'E';
+ hdr->padding1[1] = 'O';
+ hdr->padding1[2] = 'F';
+ }
+
crc = mtd_crc32(UBI_CRC32_INIT, hdr, UBI_EC_HDR_SIZE_CRC);
hdr->hdr_crc = cpu_to_be32(crc);
}
+void ubigen_init_ec_hdr(const struct ubigen_info *ui,
+ struct ubi_ec_hdr *hdr, long long ec)
+{
+ __ubigen_init_ec_hdr(ui, hdr, ec, 0);
+}
+
void ubigen_init_vid_hdr(const struct ubigen_info *ui,
const struct ubigen_vol_info *vi,
struct ubi_vid_hdr *hdr, int lnum,
@@ -307,6 +320,39 @@ int ubigen_write_layout_vol(const struct
}
free(outbuf);
+ return 0;
+
+out_free:
+ free(outbuf);
+ return -1;
+}
+
+int ubigen_write_eof_markers(const struct ubigen_info *ui, long long ec,
+ int count, int out_fd)
+{
+ char *outbuf;
+ int peb_size = ui->peb_size;
+
+ outbuf = malloc(peb_size);
+ if (!outbuf) {
+ sys_errmsg("cannot allocate %d bytes of memory", peb_size);
+ return -1;
+ }
+
+ memset(outbuf, 0xFF, peb_size);
+ __ubigen_init_ec_hdr(ui, (struct ubi_ec_hdr *)outbuf, ec, 1);
+
+ while (count) {
+ if (write(out_fd, outbuf, peb_size) != peb_size) {
+ sys_errmsg("cannot write %d bytes to the output file",
+ peb_size);
+ goto out_free;
+ }
+
+ count--;
+ }
+
+ free(outbuf);
return 0;
out_free:
--- a/include/libubigen.h
+++ b/include/libubigen.h
@@ -188,6 +188,9 @@ int ubigen_write_layout_vol(const struct
long long ec1, long long ec2,
struct ubi_vtbl_record *vtbl, int fd);
+int ubigen_write_eof_markers(const struct ubigen_info *ui, long long ec,
+ int count, int out_fd);
+
#ifdef __cplusplus
}
#endif

View File

@@ -0,0 +1,68 @@
--- a/ubi-utils/ubinize.c
+++ b/ubi-utils/ubinize.c
@@ -60,6 +60,8 @@ static const char optionsstr[] =
" (default is 1)\n"
"-Q, --image-seq=<num> 32-bit UBI image sequence number to use\n"
" (by default a random number is picked)\n"
+"-E, --eof-markers=<num> number of eof-markers to put at the end of the\n"
+" output image\n"
"-v, --verbose be verbose\n"
"-h, --help print help message\n"
"-V, --version print program version\n\n";
@@ -79,6 +81,7 @@ static const struct option long_options[
{ .name = "erase-counter", .has_arg = 1, .flag = NULL, .val = 'e' },
{ .name = "ubi-ver", .has_arg = 1, .flag = NULL, .val = 'x' },
{ .name = "image-seq", .has_arg = 1, .flag = NULL, .val = 'Q' },
+ { .name = "eof-markers", .has_arg = 1, .flag = NULL, .val = 'E' },
{ .name = "verbose", .has_arg = 0, .flag = NULL, .val = 'v' },
{ .name = "help", .has_arg = 0, .flag = NULL, .val = 'h' },
{ .name = "version", .has_arg = 0, .flag = NULL, .val = 'V' },
@@ -98,6 +101,7 @@ struct args {
uint32_t image_seq;
int verbose;
dictionary *dict;
+ int eof_markers;
};
static struct args args = {
@@ -116,7 +120,7 @@ static int parse_opt(int argc, char * co
int key, error = 0;
unsigned long int image_seq;
- key = getopt_long(argc, argv, "o:p:m:s:O:e:x:Q:vhV", long_options, NULL);
+ key = getopt_long(argc, argv, "o:p:m:s:O:e:x:Q:E:vhV", long_options, NULL);
if (key == -1)
break;
@@ -176,6 +180,12 @@ static int parse_opt(int argc, char * co
args.image_seq = image_seq;
break;
+ case 'E':
+ args.eof_markers = simple_strtoul(optarg, &error);
+ if (error)
+ return errmsg("bad number of eof-markers: \"%s\"", optarg);
+ break;
+
case 'v':
args.verbose = 1;
break;
@@ -582,6 +592,18 @@ int main(int argc, char * const argv[])
printf("\n");
}
+ if (args.eof_markers) {
+ verbose(args.verbose, "writing %d eof-marker blocks",
+ args.eof_markers);
+
+ err = ubigen_write_eof_markers(&ui, args.ec, args.eof_markers,
+ args.out_fd);
+ if (err) {
+ errmsg("cannot write eof-marker blocks");
+ goto out_free;
+ }
+ }
+
verbose(args.verbose, "writing layout volume");
err = ubigen_write_layout_vol(&ui, 0, 1, args.ec, args.ec, vtbl, args.out_fd);

View File

@@ -0,0 +1,60 @@
--- a/jffsX-utils/mkfs.jffs2.c
+++ b/jffsX-utils/mkfs.jffs2.c
@@ -109,7 +109,7 @@ static char *rootdir = default_rootdir;
static int verbose = 0;
static int squash_uids = 0;
static int squash_perms = 0;
-static int fake_times = 0;
+static time_t fixed_timestamp = -1;
int target_endian = __BYTE_ORDER;
static uint32_t find_hardlink(struct filesystem_entry *e)
@@ -250,8 +250,8 @@ static struct filesystem_entry *add_host
mode &= ~(S_ISUID | S_ISGID);
}
}
- if (fake_times) {
- timestamp = 0;
+ if (fixed_timestamp != -1) {
+ timestamp = fixed_timestamp;
}
entry = xcalloc(1, sizeof(struct filesystem_entry));
@@ -1557,6 +1557,20 @@ static void parse_image(void){
close(in_fd);
}
+static void set_source_date_epoch() {
+ char *env = getenv("SOURCE_DATE_EPOCH");
+ char *endptr = env;
+ errno = 0;
+ if (env && *env) {
+ fixed_timestamp = strtoull(env, &endptr, 10);
+ if (errno || (endptr && *endptr != '\0')) {
+ fprintf(stderr, "Invalid SOURCE_DATE_EPOCH");
+ exit(1);
+ }
+ }
+}
+
+
int main(int argc, char **argv)
{
int c, opt;
@@ -1575,6 +1589,7 @@ int main(int argc, char **argv)
warn_page_size = 1; /* warn user if page size not 4096 */
jffs2_compressors_init();
+ set_source_date_epoch();
while ((opt = getopt_long(argc, argv,
"D:d:r:s:o:qUPfh?vVe:lbp::nc:m:x:X:Lty:i:", long_options, &c)) >= 0)
@@ -1625,7 +1640,7 @@ int main(int argc, char **argv)
break;
case 'f':
- fake_times = 1;
+ fixed_timestamp = 0;
break;
case 'h':