@@ -55,6 +55,7 @@ typedef void * libubi_t;
* most of the users want)
* @max_beb_per1024: Maximum expected bad eraseblocks per 1024 eraseblocks
* @disable_fm: whether disable fastmap
+ * @need_resv_pool: whether reserve free pebs for filling pool/wl_pool
*/
struct ubi_attach_request
{
@@ -64,6 +65,7 @@ struct ubi_attach_request
int vid_hdr_offset;
int max_beb_per1024;
bool disable_fm;
+ bool need_resv_pool;
};
/**
@@ -236,6 +236,7 @@ enum {
* @vid_hdr_offset: VID header offset (use defaults if %0)
* @max_beb_per1024: maximum expected number of bad PEB per 1024 PEBs
* @disable_fm: whether disable fastmap
+ * @need_resv_pool: whether reserve free pebs for filling pool/wl_pool
* @padding: reserved for future, not used, has to be zeroed
*
* This data structure is used to specify MTD device UBI has to attach and the
@@ -282,7 +283,8 @@ struct ubi_attach_req {
int32_t vid_hdr_offset;
int16_t max_beb_per1024;
int8_t disable_fm;
- int8_t padding[9];
+ int8_t need_resv_pool;
+ int8_t padding[8];
};
/*
@@ -768,6 +768,7 @@ int ubi_attach(libubi_t desc, const char *node, struct ubi_attach_request *req)
r.mtd_num = req->mtd_num;
r.vid_hdr_offset = req->vid_hdr_offset;
r.disable_fm = req->disable_fm ? 1 : 0;
+ r.need_resv_pool = req->need_resv_pool ? 1 : 0;
if (req->max_beb_per1024) {
/*
@@ -43,6 +43,7 @@ struct args {
const char *dev;
int max_beb_per1024;
bool disable_fm;
+ bool need_resv_pool;
};
static struct args args = {
@@ -53,6 +54,7 @@ static struct args args = {
.dev = NULL,
.max_beb_per1024 = 0,
.disable_fm = false,
+ .need_resv_pool = false,
};
static const char doc[] = PROGRAM_NAME " version " VERSION
@@ -71,6 +73,9 @@ static const char optionsstr[] =
" Allowed range is 0-768, 0 means the default kernel value.\n"
"-f, --disable-fastmap don't create new fastmap and do full scanning (existed\n"
" fastmap will be destroyed) for the given ubi device.\n"
+"-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"
"-h, --help print help message\n"
"-V, --version print program version";
@@ -78,7 +83,7 @@ static const char usage[] =
"Usage: " PROGRAM_NAME " [<UBI control device node file name>]\n"
"\t[-m <MTD device number>] [-d <UBI device number>] [-p <path to device>]\n"
"\t[--mtdn=<MTD device number>] [--devn=<UBI device number>]\n"
-"\t[--dev-path=<path to device>] [-f] [--disable-fastmap]\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"
"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"
@@ -98,6 +103,7 @@ static const struct option long_options[] = {
{ .name = "vid-hdr-offset", .has_arg = 1, .flag = NULL, .val = 'O' },
{ .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 = "help", .has_arg = 0, .flag = NULL, .val = 'h' },
{ .name = "version", .has_arg = 0, .flag = NULL, .val = 'V' },
{ NULL, 0, NULL, 0},
@@ -108,7 +114,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:fhV", long_options, NULL);
+ key = getopt_long(argc, argv, "p:m:d:O:b:frhV", long_options, NULL);
if (key == -1)
break;
@@ -152,6 +158,10 @@ static int parse_opt(int argc, char * const argv[])
args.disable_fm = true;
break;
+ case 'r':
+ args.need_resv_pool = true;
+ break;
+
case 'h':
printf("%s\n\n", doc);
printf("%s\n\n", usage);
@@ -223,6 +233,7 @@ int main(int argc, char * const argv[])
req.mtd_dev_node = args.dev;
req.max_beb_per1024 = args.max_beb_per1024;
req.disable_fm = args.disable_fm;
+ req.need_resv_pool = args.need_resv_pool;
err = ubi_attach(libubi, args.node, &req);
if (err < 0) {
The ioctl UBI_IOCATT has been extended with need_resv_pool parameter in [1]. This parameter is used for deciding whether to reserve PEBs for filling pool/wl_pool for target ubi device. This parameter will be effective when fastmap is enabled, which will slow down the frequency of updating fastmap by filling more free PEBs in pool/wl_pool. See details in [2]. [1] https://git.kernel.org/pub/scm/linux/kernel/git/torvalds/linux.git/commit/?id=ac085cfe57df2cc1d7a5c4c5e64b8780c8ad452f [2] https://bugzilla.kernel.org/show_bug.cgi?id=217787 Signed-off-by: Zhihao Cheng <chengzhihao1@huawei.com> --- include/libubi.h | 2 ++ include/mtd/ubi-user.h | 4 +++- lib/libubi.c | 1 + ubi-utils/ubiattach.c | 15 +++++++++++++-- 4 files changed, 19 insertions(+), 3 deletions(-)