aboutsummaryrefslogtreecommitdiff
path: root/ubi-utils/ubiattach.c
diff options
context:
space:
mode:
authorRan Hongyun <ranhongyun1@huawei.com>2026-07-23 10:37:06 +0800
committerDavid Oberhollenzer <david.oberhollenzer@sigma-star.at>2026-08-03 07:42:07 +0200
commit76641773be73141652c6be5c45f53c91efd144e4 (patch)
tree7839e77069f3b22136cb6d136ad4e7ada15a0f37 /ubi-utils/ubiattach.c
parentd1f2d1270c15e373c4e4b5bfbe0a83c7bcf6e793 (diff)
ubi-utils: add wear-leveling threshold parameter to ubiattachHEADmaster
Add wl_threshold support end-to-end: expose the kernel's wear-leveling threshold via a new --wl-threshold / -w option in ubiattach, plumb it through libubi, and define it by replacing 4 bytes of padding in struct ubi_attach_req. Valid range is 2-65536; 0 means use the kernel default. Signed-off-by: Ran Hongyun <ranhongyun1@huawei.com> Signed-off-by: David Oberhollenzer <david.oberhollenzer@sigma-star.at>
Diffstat (limited to 'ubi-utils/ubiattach.c')
-rw-r--r--ubi-utils/ubiattach.c24
1 files changed, 23 insertions, 1 deletions
diff --git a/ubi-utils/ubiattach.c b/ubi-utils/ubiattach.c
index 11e171b..0789a5f 100644
--- a/ubi-utils/ubiattach.c
+++ b/ubi-utils/ubiattach.c
@@ -44,6 +44,7 @@ struct args {
int max_beb_per1024;
bool disable_fm;
bool need_resv_pool;
+ int wl_threshold;
};
static struct args args = {
@@ -55,6 +56,7 @@ static struct args args = {
.max_beb_per1024 = 0,
.disable_fm = false,
.need_resv_pool = false,
+ .wl_threshold = 0,
};
static const char doc[] = PROGRAM_NAME " version " VERSION
@@ -76,6 +78,9 @@ static const char optionsstr[] =
"-r, --reserve-pool Slow down the frequency of updating fastmap by reserving\n"
" pebs for filling pool/wl_pool, which can prolong flash\n"
" service life.\n"
+"-w, --wl-threshold Set the wear-leveling threshold for this UBI device.\n"
+" If 0, the kernel default value is used.\n"
+" Accepted range is 2-65536.\n"
"-h, --help print help message\n"
"-V, --version print program version";
@@ -85,6 +90,7 @@ static const char usage[] =
"\t[--mtdn=<MTD device number>] [--devn=<UBI device number>]\n"
"\t[--dev-path=<path to device>] [-f] [--disable-fastmap] [-r] [--reserve-pool]\n"
"\t[--max-beb-per1024=<maximum bad block number per 1024 blocks>]\n"
+"\t[--wl-threshold=<wear-leveling threshold>]\n"
"UBI control device defaults to " DEFAULT_CTRL_DEV " if not supplied.\n"
"Example 1: " PROGRAM_NAME " -p /dev/mtd0 - attach /dev/mtd0 to UBI\n"
"Example 2: " PROGRAM_NAME " -m 0 - attach MTD device 0 (mtd0) to UBI\n"
@@ -104,6 +110,7 @@ static const struct option long_options[] = {
{ .name = "max-beb-per1024", .has_arg = 1, .flag = NULL, .val = 'b' },
{ .name = "disable-fastmap", .has_arg = 0, .flag = NULL, .val = 'f' },
{ .name = "reserve-pool", .has_arg = 0, .flag = NULL, .val = 'r' },
+ { .name = "wl-threshold", .has_arg = 1, .flag = NULL, .val = 'w' },
{ .name = "help", .has_arg = 0, .flag = NULL, .val = 'h' },
{ .name = "version", .has_arg = 0, .flag = NULL, .val = 'V' },
{ NULL, 0, NULL, 0},
@@ -114,7 +121,7 @@ static int parse_opt(int argc, char * const argv[])
while (1) {
int key, error = 0;
- key = getopt_long(argc, argv, "p:m:d:O:b:frhV", long_options, NULL);
+ key = getopt_long(argc, argv, "p:m:d:O:b:frw:hV", long_options, NULL);
if (key == -1)
break;
@@ -162,6 +169,20 @@ static int parse_opt(int argc, char * const argv[])
args.need_resv_pool = true;
break;
+ case 'w':
+ {
+ unsigned long tmp = simple_strtoul(optarg, &error);
+
+ if (error || (tmp && (tmp < 2 || tmp > 65536)))
+ return errmsg("bad wear-leveling threshold: \"%s\" (2-65536)",
+ optarg);
+ if (tmp == 0)
+ warnmsg("wear-leveling threshold use the default kernel value");
+ args.wl_threshold = tmp;
+
+ break;
+ }
+
case 'h':
printf("%s\n\n", doc);
printf("%s\n\n", usage);
@@ -234,6 +255,7 @@ int main(int argc, char * const argv[])
req.max_beb_per1024 = args.max_beb_per1024;
req.disable_fm = args.disable_fm;
req.need_resv_pool = args.need_resv_pool;
+ req.wl_threshold = args.wl_threshold;
err = ubi_attach(libubi, args.node, &req);
if (err < 0) {