UBI: add max_beb_per1024 parameter / ioctl
cover UBI: add max_beb_per1024 parameter / ioctl
Artem,
This patch serie introduce, step by step the kernel module parameter max_beb_per1024, then the ioctl and finally drop the kernel config option CONFIG_MTD_UBI_BEB_LIMIT.
It's based on top of linux-ubi/master (and I added your patch on sam9_l9260_defconfig).
BTW, I let the BEB value at 30 in sam9_l9260_defconfig, you can set it at 25 if you want (as it's the value from the datasheet).
Best Regards
Richard.
Artem Bityutskiy (1):
arm: sam9_l9260_defconfig: adjust UBI bad eraseblocks limit
Richard Genoud (7):
UBI: separate bad_peb_limit in a function
UBI: introduce MTD_PARAM_MAX_COUNT
UBI: prepare for max_beb_per1024 module parameter addition
UBI: check max_beb_per1024 value in ubi_attach_mtd_dev
UBI: replace MTD_UBI_BEB_LIMIT with module parameter
UBI: add ioctl for max_beb_per1024
UBI: drop CONFIG_MTD_UBI_BEB_LIMIT
arch/arm/configs/sam9_l9260_defconfig | 1 - drivers/mtd/ubi/Kconfig | 26 ------- drivers/mtd/ubi/build.c | 116 +++++++++++++++++++++----------- drivers/mtd/ubi/cdev.c | 3 +- drivers/mtd/ubi/ubi.h | 6 ++- include/mtd/ubi-user.h | 19 +++++- 6 files changed, 101 insertions(+), 70 deletions(-)
Signature · 1 line
1.7.2.5
PATCH 1/8 arm: sam9_l9260_defconfig: adjust UBI bad eraseblocks limit
From: Artem Bityutskiy <[email protected]>
UBI has changed the MTD_UBI_BEB_LIMIT semantics. It used to be a percent of total amount of eraseblock in the partition, and now it is the maximum amount of bad eraseblocks on the entire devise per 1024 eraseblocks. So not only the units changed, but also the meaning. But anyway, old 3% roughly correspond to new 30, so change the defconfig correspondingly.
--- arch/arm/configs/sam9_l9260_defconfig | 2 +- 1 files changed, 1 insertions(+), 1 deletions(-)
arch/arm/configs/sam9_l9260_defconfig +1 -1
@@ -39,7 +39,7 @@ CONFIG_MTD_NAND=y CONFIG_MTD_NAND_ATMEL=y CONFIG_MTD_NAND_PLATFORM=y CONFIG_MTD_UBI=y -CONFIG_MTD_UBI_BEB_LIMIT=3 +CONFIG_MTD_UBI_BEB_LIMIT=30 CONFIG_MTD_UBI_GLUEBI=y CONFIG_BLK_DEV_LOOP=y CONFIG_BLK_DEV_RAM=y
Signature · 1 line
1.7.2.5
PATCH 2/8 UBI: separate bad_peb_limit in a function
In reply to Richard GenoudNo functional changes here, just to prepare for next patch.
--- drivers/mtd/ubi/build.c | 57 ++++++++++++++++++++++++++++------------------- 1 files changed, 34 insertions(+), 23 deletions(-)
drivers/mtd/ubi/build.c +34 -23
@@ -565,6 +565,37 @@ void ubi_free_internal_volumes(struct ubi_device *ubi) } } +static int get_bad_peb_limit (const struct ubi_device *ubi,int max_beb_per1024) +{ +int limit, device_pebs; +uint64_t device_size; + +/* +* We don't want a division by 0, and having max_beb_per1024 == 0 is ok +*/ +if (!max_beb_per1024) +return 0 ; + +/* +* Here we are using size of the entire flash chip and +* not just the MTD partition size because the maximum +* number of bad eraseblocks is a percentage of the +* whole device and bad eraseblocks are not fairly +* distributed over the flash chip. So the worst case +* is that all the bad eraseblocks of the chip are in +* the MTD partition we are attaching (ubi->mtd). +*/ + device_size =mtd_get_device_size (ubi->mtd); + device_pebs =mtd_div_by_eb (device_size, ubi->mtd); + limit =mult_frac (device_pebs, max_beb_per1024,1024 ); + +/* Round it up */ +if (mult_frac (limit,1024 , max_beb_per1024) < device_pebs) + limit +=1 ; + +return limit; +} +/** * io_init - initialize I/O sub-system for a given UBI device. * @ubi: UBI device description object
@@ -582,6 +613,8 @@ void ubi_free_internal_volumes(struct ubi_device *ubi)*/ static int io_init (struct ubi_device *ubi) { +const int max_beb_per1024 =CONFIG_MTD_UBI_BEB_LIMIT ; +if (ubi->mtd->numeraseregions !=0 ) {/* * Some flashes have several erase regions. Different regions
@@ -610,29 +643,7 @@ static int io_init(struct ubi_device *ubi)if (mtd_can_have_bb (ubi->mtd)) { ubi->bad_allowed =1 ; -if (CONFIG_MTD_UBI_BEB_LIMIT >0 ) { -int per1024 =CONFIG_MTD_UBI_BEB_LIMIT ; -int limit, device_pebs; -uint64_t device_size; - -/* -* Here we are using size of the entire flash chip and -* not just the MTD partition size because the maximum -* number of bad eraseblocks is a percentage of the -* whole device and bad eraseblocks are not fairly -* distributed over the flash chip. So the worst case -* is that all the bad eraseblocks of the chip are in -* the MTD partition we are attaching (ubi->mtd). -*/ - device_size =mtd_get_device_size (ubi->mtd); - device_pebs =mtd_div_by_eb (device_size, ubi->mtd); - limit =mult_frac (device_pebs, per1024,1024 ); - -/* Round it up */ -if (mult_frac (limit,1024 , per1024) < device_pebs) - limit +=1 ; - ubi->bad_peb_limit = limit; - } + ubi->bad_peb_limit =get_bad_peb_limit (ubi, max_beb_per1024); }if (ubi->mtd->type ==MTD_NORFLASH ) {
Signature · 1 line
1.7.2.5
PATCH 3/8 UBI: introduce MTD_PARAM_MAX_COUNT
In reply to Richard Genoud--- drivers/mtd/ubi/build.c | 7 +++++-- 1 files changed, 5 insertions(+), 2 deletions(-)
drivers/mtd/ubi/build.c +5 -2
@@ -46,6 +46,9 @@/* Maximum length of the 'mtd=' parameter */ #define MTD_PARAM_LEN_MAX 64 +/* Maximum number of comma-separated items in ht 'mtd=' parameter */ +#define MTD_PARAM_MAX_COUNT 2 +#ifdef CONFIG_MTD_UBI_MODULE #define ubi_is_module () 1#else
@@ -1327,7 +1330,7 @@ static int __init ubi_mtd_param_parse(const char *val, struct kernel_param *kp)struct mtd_dev_param *p;char buf[MTD_PARAM_LEN_MAX ];char *pbuf = &buf[0 ]; -char *tokens[2 ] = {NULL ,NULL }; +char *tokens[MTD_PARAM_MAX_COUNT ];if (!val)return -EINVAL ;
@@ -1357,7 +1360,7 @@ static int __init ubi_mtd_param_parse(const char *val, struct kernel_param *kp)if (buf[len -1 ] =='\n' ) buf[len -1 ] ='\0' ; -for (i =0 ; i <2 ; i++) +for (i =0 ; i <MTD_PARAM_MAX_COUNT ; i++) tokens[i] =strsep (&pbuf,"," );if (pbuf) {
Signature · 1 line
1.7.2.5
PATCH 4/8 UBI: prepare for max_beb_per1024 module parameter addition
In reply to Richard GenoudThis patch prepare the way for the addition of max_beb_per1024 module parameter.
There's no functional change.
--- drivers/mtd/ubi/build.c | 14 ++++++++------ drivers/mtd/ubi/cdev.c | 3 ++- drivers/mtd/ubi/ubi.h | 3 ++- 3 files changed, 12 insertions(+), 8 deletions(-)
drivers/mtd/ubi/build.c +8 -6
@@ -602,6 +602,7 @@ static int get_bad_peb_limit(const struct ubi_device *ubi, int max_beb_per1024)/** * io_init - initialize I/O sub-system for a given UBI device. * @ubi: UBI device description object +* @max_beb_per1024: maximum expected number of bad PEB per 1024 PEB * * If @ubi->vid_hdr_offset or @ubi->leb_start is zero, default offsets are * assumed:
@@ -614,10 +615,8 @@ static int get_bad_peb_limit(const struct ubi_device *ubi, int max_beb_per1024)* This function returns zero in case of success and a negative error code in * case of failure. */ -static int io_init (struct ubi_device *ubi) +static int io_init (struct ubi_device *ubi,int max_beb_per1024) { -const int max_beb_per1024 =CONFIG_MTD_UBI_BEB_LIMIT ; -if (ubi->mtd->numeraseregions !=0 ) {/* * Some flashes have several erase regions. Different regions
@@ -839,6 +838,7 @@ static int autoresize(struct ubi_device *ubi, int vol_id)* @mtd: MTD device description object * @ubi_num: number to assign to the new UBI device * @vid_hdr_offset: VID header offset +* @max_beb_per1024: maximum number of expected bad blocks per 1024 eraseblocks * * This function attaches MTD device @mtd_dev to UBI and assign @ubi_num number * to the newly created UBI device, unless @ubi_num is %UBI_DEV_NUM_AUTO, in
@@ -849,7 +849,8 @@ static int autoresize(struct ubi_device *ubi, int vol_id)* Note, the invocations of this function has to be serialized by the * @ubi_devices_mutex. */ -int ubi_attach_mtd_dev (struct mtd_info *mtd,int ubi_num,int vid_hdr_offset) +int ubi_attach_mtd_dev (struct mtd_info *mtd,int ubi_num, +int vid_hdr_offset,int max_beb_per1024) {struct ubi_device *ubi;int i, err, ref =0 ;
@@ -922,7 +923,7 @@ int ubi_attach_mtd_dev(struct mtd_info *mtd, int ubi_num, int vid_hdr_offset)dbg_msg ("sizeof(struct ubi_ainf_peb) %zu" ,sizeof (struct ubi_ainf_peb ));dbg_msg ("sizeof(struct ubi_wl_entry) %zu" ,sizeof (struct ubi_wl_entry )); - err =io_init (ubi); + err =io_init (ubi, max_beb_per1024);if (err) goto out_free;
@@ -1211,7 +1212,8 @@ static int __init ubi_init(void)mutex_lock (&ubi_devices_mutex); err =ubi_attach_mtd_dev (mtd,UBI_DEV_NUM_AUTO , - p->vid_hdr_offs); + p->vid_hdr_offs, +CONFIG_MTD_UBI_BEB_LIMIT );mutex_unlock (&ubi_devices_mutex);if (err <0 ) {ubi_err ("cannot attach mtd%d" , mtd->index);
drivers/mtd/ubi/cdev.c +2 -1
@@ -1010,7 +1010,8 @@ static long ctrl_cdev_ioctl(struct file *file, unsigned int cmd,* 'ubi_attach_mtd_dev()'. */ mutex_lock (&ubi_devices_mutex); - err =ubi_attach_mtd_dev (mtd, req.ubi_num, req.vid_hdr_offset); + err =ubi_attach_mtd_dev (mtd, req.ubi_num, req.vid_hdr_offset, +CONFIG_MTD_UBI_BEB_LIMIT );mutex_unlock (&ubi_devices_mutex);if (err <0 )put_mtd_device (mtd);
drivers/mtd/ubi/ubi.h +2 -1
@@ -693,7 +693,8 @@ int ubi_io_write_vid_hdr(struct ubi_device *ubi, int pnum, struct ubi_vid_hdr *vid_hdr);/* build.c */ -int ubi_attach_mtd_dev (struct mtd_info *mtd,int ubi_num,int vid_hdr_offset); +int ubi_attach_mtd_dev (struct mtd_info *mtd,int ubi_num, +int vid_hdr_offset,int max_beb_per1024);int ubi_detach_mtd_dev (int ubi_num,int anyway);struct ubi_device *ubi_get_device (int ubi_num);void ubi_put_device (struct ubi_device *ubi);
Signature · 1 line
1.7.2.5
PATCH 5/8 UBI: check max_beb_per1024 value in ubi_attach_mtd_dev
In reply to Richard Genoudmax_beb_per1024 shouldn't be negative, and a 0 value will be treated as the default value.
--- drivers/mtd/ubi/build.c | 10 ++++++++++ 1 files changed, 10 insertions(+), 0 deletions(-)
drivers/mtd/ubi/build.c +10 -0
@@ -855,6 +855,16 @@ int ubi_attach_mtd_dev(struct mtd_info *mtd, int ubi_num,struct ubi_device *ubi;int i, err, ref =0 ; +if (max_beb_per1024 <0 ) +return -EINVAL ; + +/* +* A value of 0 is forced to the default value to keep the same +* behavior between ubiattach command and module parameter +*/ +if (!max_beb_per1024) + max_beb_per1024 =CONFIG_MTD_UBI_BEB_LIMIT ; +/* * Check if we already have the same MTD device attached. *
Signature · 1 line
1.7.2.5
PATCH 6/8 UBI: replace MTD_UBI_BEB_LIMIT with module parameter
In reply to Richard GenoudThis patch provides the possibility to adjust the "maximum expected number of bad blocks per 1024 blocks" (max_beb_per1024) for each mtd device.
The majority of NAND devices have their max_beb_per1024 equal to 20, but sometimes it's more.
Now, we can adjust that via a kernel parameter:
ubi.mtd=<name|num|path>[,<vid_hdr_offs>[,max_beb_per1024]]
--- drivers/mtd/ubi/Kconfig | 2 ++ drivers/mtd/ubi/build.c | 38 ++++++++++++++++++++++++-------------- 2 files changed, 26 insertions(+), 14 deletions(-)
drivers/mtd/ubi/Kconfig +2 -0
@@ -51,6 +51,8 @@ config MTD_UBI_BEB_LIMIT MTD partitions of the same size, UBI will reserve 40 eraseblocks when attaching a partition. + This option can be overridden by the kernel parameter ubi.mtd. + Leave the default value if unsure. config MTD_UBI_GLUEBI
drivers/mtd/ubi/build.c +24 -14
@@ -47,7 +47,7 @@#define MTD_PARAM_LEN_MAX 64/* Maximum number of comma-separated items in ht 'mtd=' parameter */ -#define MTD_PARAM_MAX_COUNT 2 +#define MTD_PARAM_MAX_COUNT 3#ifdef CONFIG_MTD_UBI_MODULE #define ubi_is_module () 1
@@ -60,10 +60,12 @@* @name: MTD character device node path, MTD device name, or MTD device number * string * @vid_hdr_offs: VID header offset +* @max_beb_per1024: maximum expected number of bad blocks per 1024 erase blocks */ struct mtd_dev_param {char name[MTD_PARAM_LEN_MAX ];int vid_hdr_offs; +int max_beb_per1024; };/* Numbers of elements set in the @mtd_dev_param array */
@@ -1222,8 +1224,7 @@ static int __init ubi_init(void)mutex_lock (&ubi_devices_mutex); err =ubi_attach_mtd_dev (mtd,UBI_DEV_NUM_AUTO , - p->vid_hdr_offs, -CONFIG_MTD_UBI_BEB_LIMIT ); + p->vid_hdr_offs, p->max_beb_per1024);mutex_unlock (&ubi_devices_mutex);if (err <0 ) {ubi_err ("cannot attach mtd%d" , mtd->index);
@@ -1343,6 +1344,7 @@ static int __init ubi_mtd_param_parse(const char *val, struct kernel_param *kp)char buf[MTD_PARAM_LEN_MAX ];char *pbuf = &buf[0 ];char *tokens[MTD_PARAM_MAX_COUNT ]; +int err;if (!val)return -EINVAL ;
@@ -1390,23 +1392,31 @@ static int __init ubi_mtd_param_parse(const char *val, struct kernel_param *kp)if (p->vid_hdr_offs <0 )return p->vid_hdr_offs; +if (tokens[2 ]) { + err =kstrtoint (tokens[2 ],10 , &p->max_beb_per1024); +if (err) { +pr_err ("UBI error: bad value for max_beb_per1024 parameter: %s" , + tokens[2 ]); +return -EINVAL ; + } + } + mtd_devs +=1 ;return 0 ; }module_param_call (mtd, ubi_mtd_param_parse,NULL ,NULL ,000 ); -MODULE_PARM_DESC (mtd,"MTD devices to attach. Parameter format: " -"mtd=<name|num|path>[,<vid_hdr_offs>].\n" +MODULE_PARM_DESC(mtd, "MTD devices to attach. Parameter format: mtd=<name|num|path>[,<vid_hdr_offs>[,max_beb_per1024]].\n" "Multiple \"mtd\" parameters may be specified.\n" -"MTD devices may be specified by their number, name, or " -"path to the MTD character device node.\n" -"Optional \"vid_hdr_offs\" parameter specifies UBI VID " -"header position to be used by UBI.\n" -"Example 1: mtd=/dev/mtd0 - attach MTD device " -"/dev/mtd0.\n" -"Example 2: mtd=content,1984 mtd=4 - attach MTD device " -"with name \"content\" using VID header offset 1984, and " -"MTD device number 4 with default VID header offset." ); + "MTD devices may be specified by their number, name, or path to the MTD character device node.\n" + "Optional \"vid_hdr_offs\" parameter specifies UBI VID header position to be used by UBI. (default value if 0 or not set)\n" + "Optional \"max_beb_per1024\" parameter specifies the maximum expected bad eraseblock per 1024 eraseblocks. (default value (" + __stringify(CONFIG_MTD_UBI_BEB_LIMIT) ") if 0 or not set)\n" +"\n" +"Example 1: mtd=/dev/mtd0 - attach MTD device /dev/mtd0.\n" +"Example 2: mtd=content,1984 mtd=4 - attach MTD device with name \"content\" using VID header offset 1984, and MTD device number 4 with default VID header offset.\n" +"Example 3: mtd=/dev/mtd1,0,25 - attach MTD device /dev/mtd1 using default VID header offset and reserve 25*nand_size_in_blocks/1024 erase blocks for bad block handling.\n" +"\t(e.g. if the NAND *chipset* has 4096 PEB, 100 will be reserved for this UBI device)." );MODULE_VERSION (__stringify (UBI_VERSION ));MODULE_DESCRIPTION ("UBI - Unsorted Block Images" );
Signature · 1 line
1.7.2.5
PATCH 7/8 UBI: add ioctl for max_beb_per1024
In reply to Richard GenoudThis patch provides the possibility to adjust the "maximum expected number of bad blocks per 1024 blocks" (max_beb_per1024) for each mtd device from UBI_IOCATT ioctl.
The majority of NAND devices have their max_beb_per1024 equal to 20, but sometimes it's more.
We already could adjust that via a kernel parameter, now we can also use UBI_IOCATT ioctl:
struct ubi_attach_req {
__s32 ubi_num;
__s32 mtd_num;
__s32 vid_hdr_offset;
__u8 max_beb_per1024;
__s8 padding[11];
};--- drivers/mtd/ubi/Kconfig | 3 ++- drivers/mtd/ubi/cdev.c | 2 +- include/mtd/ubi-user.h | 19 ++++++++++++++++++- 3 files changed, 21 insertions(+), 3 deletions(-)
drivers/mtd/ubi/Kconfig +2 -1
@@ -51,7 +51,8 @@ config MTD_UBI_BEB_LIMIT MTD partitions of the same size, UBI will reserve 40 eraseblocks when attaching a partition. - This option can be overridden by the kernel parameter ubi.mtd. + This option can be overridden by the kernel parameter ubi.mtd and the + ioctl UBI_IOCATT. Leave the default value if unsure.
drivers/mtd/ubi/cdev.c +1 -1
@@ -1011,7 +1011,7 @@ static long ctrl_cdev_ioctl(struct file *file, unsigned int cmd,*/ mutex_lock (&ubi_devices_mutex); err =ubi_attach_mtd_dev (mtd, req.ubi_num, req.vid_hdr_offset, -CONFIG_MTD_UBI_BEB_LIMIT ); + req.max_beb_per1024);mutex_unlock (&ubi_devices_mutex);if (err <0 )put_mtd_device (mtd);
include/mtd/ubi-user.h +18 -1
@@ -222,6 +222,7 @@ enum {* @ubi_num: UBI device number to create * @mtd_num: MTD device number to attach * @vid_hdr_offset: VID header offset (use defaults if %0) +* @max_beb_per1024: Maximum expected bad eraseblocks per 1024 eraseblocks * @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
@@ -245,12 +246,28 @@ enum {* be 2KiB-64 bytes = 1984. Note, that this position is not even 512-bytes * aligned, which is OK, as UBI is clever enough to realize this is 4th * sub-page of the first page and add needed padding. +* +* The @max_beb_per1024 is the maximum bad eraseblocks UBI expects on the ubi +* device per 1024 eraseblocks. +* This value is often given in an other form in the NAND datasheet (min NVB +* i.e. minimal number of valid blocks). The maximum expected bad eraseblocks +* per 1024 is then: +* 1024 * (1 - MinNVB / MaxNVB) +* Which gives 20 for most NAND devices. +* This limit is used in order to derive amount of eraseblock UBI reserves for +* handling new bad blocks. +* If the device has more bad eraseblocks than this limit, UBI does not reserve +* any physical eraseblocks for new bad eraseblocks, but attempts to use +* available eraseblocks (if any). +* The accepted range is 0-255. If 0 is given, the default kernel config value +* CONFIG_MTD_UBI_BEB_LIMIT will be used for compatibility. */ struct ubi_attach_req {__s32 ubi_num;__s32 mtd_num;__s32 vid_hdr_offset; -__s8 padding[12 ]; +__u8 max_beb_per1024; +__s8 padding[11 ]; };/**
Signature · 1 line
1.7.2.5
PATCH 8/8 UBI: drop CONFIG_MTD_UBI_BEB_LIMIT
In reply to Richard GenoudThis option can be set by a kernel parameter and an ioctl, so we may not need the kernel config option any more.
--- arch/arm/configs/sam9_l9260_defconfig | 1 - drivers/mtd/ubi/Kconfig | 29 ----------------------------- drivers/mtd/ubi/build.c | 4 ++-- drivers/mtd/ubi/ubi.h | 3 +++ include/mtd/ubi-user.h | 2 +- 5 files changed, 6 insertions(+), 33 deletions(-)
arch/arm/configs/sam9_l9260_defconfig +0 -1
@@ -39,7 +39,6 @@ CONFIG_MTD_NAND=y CONFIG_MTD_NAND_ATMEL=y CONFIG_MTD_NAND_PLATFORM=y CONFIG_MTD_UBI=y -CONFIG_MTD_UBI_BEB_LIMIT=30 CONFIG_MTD_UBI_GLUEBI=y CONFIG_BLK_DEV_LOOP=y CONFIG_BLK_DEV_RAM=y
drivers/mtd/ubi/Kconfig +0 -29
@@ -27,35 +27,6 @@ config MTD_UBI_WL_THRESHOLD life-cycle less than 10000, the threshold should be lessened (e.g., to 128 or 256, although it does not have to be power of 2). -config MTD_UBI_BEB_LIMIT - int "Maximum expected bad eraseblock count per 1024 eraseblocks" - default 20 - range 2 256 - help - This option specifies the maximum bad physical eraseblocks UBI - expects on the MTD device (per 1024 eraseblocks). If the underlying - flash does not admit of bad eraseblocks (e.g. NOR flash), this value - is ignored. - - NAND datasheets often specify the minimum and maximum NVM (Number of - Valid Blocks) for the flashes' endurance lifetime. The maximum - expected bad eraseblocks per 1024 eraseblocks then can be calculated - as "1024 * (1 - MinNVB / MaxNVB)", which gives 20 for most NANDs - (MaxNVB is basically the total count of eraseblocks on the chip). - - To put it differently, if this value is 20, UBI will try to reserve - about 1.9% of physical eraseblocks for bad blocks handling. And that - will be 1.9% of eraseblocks on the entire NAND chip, not just the MTD - partition UBI attaches. This means that if you have, say, a NAND - flash chip admits maximum 40 bad eraseblocks, and it is split on two - MTD partitions of the same size, UBI will reserve 40 eraseblocks when - attaching a partition. - - This option can be overridden by the kernel parameter ubi.mtd and the - ioctl UBI_IOCATT. - - Leave the default value if unsure. - config MTD_UBI_GLUEBI tristate "MTD devices emulation driver (gluebi)" help
drivers/mtd/ubi/build.c +2 -2
@@ -865,7 +865,7 @@ int ubi_attach_mtd_dev(struct mtd_info *mtd, int ubi_num,* behavior between ubiattach command and module parameter */ if (!max_beb_per1024) - max_beb_per1024 =CONFIG_MTD_UBI_BEB_LIMIT ; + max_beb_per1024 =MTD_UBI_DEFAULT_BEB_LIMIT ;/* * Check if we already have the same MTD device attached.
@@ -1411,7 +1411,7 @@ MODULE_PARM_DESC(mtd, "MTD devices to attach. Parameter format: mtd=<name|num|pa"MTD devices may be specified by their number, name, or path to the MTD character device node.\n" "Optional \"vid_hdr_offs\" parameter specifies UBI VID header position to be used by UBI. (default value if 0 or not set)\n" "Optional \"max_beb_per1024\" parameter specifies the maximum expected bad eraseblock per 1024 eraseblocks. (default value (" - __stringify(CONFIG_MTD_UBI_BEB_LIMIT) ") if 0 or not set)\n" + __stringify(MTD_UBI_DEFAULT_BEB_LIMIT) ") if 0 or not set)\n""\n" "Example 1: mtd=/dev/mtd0 - attach MTD device /dev/mtd0.\n" "Example 2: mtd=content,1984 mtd=4 - attach MTD device with name \"content\" using VID header offset 1984, and MTD device number 4 with default VID header offset.\n"
drivers/mtd/ubi/ubi.h +3 -0
@@ -50,6 +50,9 @@/* UBI name used for character devices, sysfs, etc */ #define UBI_NAME_STR "ubi" +/* Default number of maximum expected bad blocks per 1024 eraseblocks */ +#define MTD_UBI_DEFAULT_BEB_LIMIT 20 +/* Normal UBI messages */ #define ubi_msg (fmt, ...) printk(KERN_NOTICE "UBI: " fmt "\n", ##__VA_ARGS__)/* UBI warning messages */
include/mtd/ubi-user.h +1 -1
@@ -260,7 +260,7 @@ enum {* any physical eraseblocks for new bad eraseblocks, but attempts to use * available eraseblocks (if any). * The accepted range is 0-255. If 0 is given, the default kernel config value -* CONFIG_MTD_UBI_BEB_LIMIT will be used for compatibility. +* MTD_UBI_DEFAULT_BEB_LIMIT will be used for compatibility. */ struct ubi_attach_req {__s32 ubi_num;
Signature · 1 line
1.7.2.5
Re: [PATCH 2/8] UBI: separate bad_peb_limit in a function
In reply to Richard GenoudQuoted 3 lines · On Fri, 17 Aug 2012 16:35:18 +0200 Richard Genoud <[email protected]>…
No functional changes here, just to prepare for next patch.
Signed-off-by Richard Genoud <[email protected]>
Re: [PATCH 4/8] UBI: prepare for max_beb_per1024 module parameter addition
In reply to Richard GenoudQuoted 5 lines · On Fri, 17 Aug 2012 16:35:20 +0200 Richard Genoud <[email protected]>…
This patch prepare the way for the addition of
max_beb_per1024module parameter.
There's no functional change.Signed-off-by Richard Genoud <[email protected]>
Re: [PATCH 5/8] UBI: check max_beb_per1024 value in ubi_attach_mtd_dev
In reply to Richard GenoudHi Richard,
drivers/mtd/ubi/build.c int ubi_attach_mtd_dev(struct mtd_info *mtd, int ubi_num, · line 864
Quoted 4 lines · On Fri, 17 Aug 2012 16:35:21 +0200 Richard Genoud <[email protected]>…
drivers/mtd/ubi/build.c +4
-0+/* +* A value of 0 is forced to the default value to keep the same +* behavior between ubiattach command and module parameter +*/
Minor thing.
Since the module parameter is not yet introduced (only in a later patch), and since last part of sentence isn't that important, I would simply state:
+ * Use the default if max_beb_per1024 isn't provided.
or alike.
Regards,
Shmulik
Re: [PATCH 6/8] UBI: replace MTD_UBI_BEB_LIMIT with module parameter
In reply to Richard GenoudHi Richard,
drivers/mtd/ubi/build.c static int __init ubi_mtd_param_parse(const char *val, struct kernel_param *kp) · line 1414
Quoted 4 lines · On Fri, 17 Aug 2012 16:35:22 +0200 Richard Genoud <[email protected]>…
drivers/mtd/ubi/build.c +4
-0+"MTD devices may be specified by their number, name, or path to the MTD character device node.\n" +"Optional \"vid_hdr_offs\" parameter specifies UBI VID header position to be used by UBI. (default value if 0 or not set)\n" +"Optional \"max_beb_per1024\" parameter specifies the maximum expected bad eraseblock per 1024 eraseblocks. (default value (" + __stringify(CONFIG_MTD_UBI_BEB_LIMIT) ") if 0 or not set)\n"
Looks like "mtd=/dev/mtd1,,25" is invalid, although we state "default value if 0 or not set".
Also, lines are exceeding 80 chars, not sure this is more readable than if they were broken.
Regards,
Shmulik
Re: [PATCH 2/8] UBI: separate bad_peb_limit in a function
In reply to Richard GenoudQuoted 3 lines · Richard Genoud
No functional changes here, just to prepare for next patch.
Signed-off-by Richard Genoud <[email protected]>
Pushed this one to linux-ubi, thanks!
Signature · 9 lines
Best Regards, Artem Bityutskiy -------------- next part -------------- A non-text attachment was scrubbed... Name: signature.asc Type: application/pgp-signature Size: 836 bytes Desc: This is a digitally signed message part URL: <http://lists.infradead.org/pipermail/linux-arm-kernel/attachments/20120819/1403a498/attachment.sig>
Re: [PATCH 1/8] arm: sam9_l9260_defconfig: adjust UBI bad eraseblocks limit
In reply to Richard Genoudarch/arm/configs/sam9_l9260_defconfig CONFIG_MTD_NAND=y · line 42
Quoted 10 lines · Richard Genoud
arch/arm/configs/sam9_l9260_defconfig +1
-1@@ -39,7 +39,7 @@ CONFIG_MTD_NAND=y CONFIG_MTD_NAND_ATMEL=y CONFIG_MTD_NAND_PLATFORM=y CONFIG_MTD_UBI=y -CONFIG_MTD_UBI_BEB_LIMIT=3 +CONFIG_MTD_UBI_BEB_LIMIT=30
I'll just remove this from from the defconfig and make it use the default, which is more sensible for this device, as your research showed.
Signature · 9 lines
Best Regards, Artem Bityutskiy -------------- next part -------------- A non-text attachment was scrubbed... Name: signature.asc Type: application/pgp-signature Size: 836 bytes Desc: This is a digitally signed message part URL: <http://lists.infradead.org/pipermail/linux-arm-kernel/attachments/20120819/65142d0c/attachment-0001.sig>
Re: [PATCH 1/8] arm: sam9_l9260_defconfig: adjust UBI bad eraseblocks limit
Quoted 3 lines · Artem Bityutskiy
I'll just remove this from from the defconfig and make it use the default, which is more sensible for this device, as your research showed.
Actually, pushed this patch to l2-mtd.git:
From: Artem Bityutskiy <[email protected]>
Date: Sun, 19 Aug 2012 22:22:23 +0300
Subject: [PATCH] arm: sam9_l9260_defconfig: correct CONFIG_MTD_UBI_BEB_LIMIT
UBI has changed the MTD_UBI_BEB_LIMIT semantics. It used to be a percent of total amount of eraseblock in the partition, and now it is the maximum amount of bad eraseblocks on the entire devise per 1024 eraseblocks. So not only the units changed, but also the meaning.
Richard Genoud <[email protected]> says:
"I found the board:
https://www.olimex.com/dev/sam9-L9260.html
and the nand datasheet:
http://www.rockbox.org/wiki/pub/Main/LyrePrototype/K9xxG08UXM.pdf
page 11, we can see that the max_bad_bebper1024 is 25 (100 for 4096)"
Thus, use "25" for sam9.
--- arch/arm/configs/sam9_l9260_defconfig | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-)
arch/arm/configs/sam9_l9260_defconfig +1 -1
@@ -39,7 +39,7 @@ CONFIG_MTD_NAND=y CONFIG_MTD_NAND_ATMEL=y CONFIG_MTD_NAND_PLATFORM=y CONFIG_MTD_UBI=y -CONFIG_MTD_UBI_BEB_LIMIT=3 +CONFIG_MTD_UBI_BEB_LIMIT=25 CONFIG_MTD_UBI_GLUEBI=y CONFIG_BLK_DEV_LOOP=y CONFIG_BLK_DEV_RAM=y
Signature · 12 lines
1.7.11.2 -- Best Regards, Artem Bityutskiy -------------- next part -------------- A non-text attachment was scrubbed... Name: signature.asc Type: application/pgp-signature Size: 836 bytes Desc: This is a digitally signed message part URL: <http://lists.infradead.org/pipermail/linux-arm-kernel/attachments/20120819/ae63b25d/attachment.sig>
Re: [PATCH 3/8] UBI: introduce MTD_PARAM_MAX_COUNT
In reply to Richard GenoudQuoted 10 lines · Richard Genoud
Signed-off-by Richard Genoud <[email protected]>--- drivers/mtd/ubi/build.c | 7 +++++-- 1 files changed, 5 insertions(+), 2 deletions(-)drivers/mtd/ubi/build.c +0
-0
drivers/mtd/ubi/build.c line 50
Quoted 5 lines
drivers/mtd/ubi/build.c +2
-0@@ -46,6 +46,9 @@/* Maximum length of the 'mtd=' parameter */ #define MTD_PARAM_LEN_MAX 64 +/* Maximum number of comma-separated items in ht 'mtd=' parameter */ +#define MTD_PARAM_MAX_COUNT 2
Fixed the spelling of "the" and pushed to l2-mtd.git, thanks!
Signature · 9 lines
Best Regards, Artem Bityutskiy -------------- next part -------------- A non-text attachment was scrubbed... Name: signature.asc Type: application/pgp-signature Size: 836 bytes Desc: This is a digitally signed message part URL: <http://lists.infradead.org/pipermail/linux-arm-kernel/attachments/20120819/d1b0a538/attachment.sig>
Re: [PATCH 3/8] UBI: introduce MTD_PARAM_MAX_COUNT
In reply to Richard GenoudQuoted 10 lines · Richard Genoud
Signed-off-by Richard Genoud <[email protected]>--- drivers/mtd/ubi/build.c | 7 +++++-- 1 files changed, 5 insertions(+), 2 deletions(-)drivers/mtd/ubi/build.c +0
-0
drivers/mtd/ubi/build.c line 50
Quoted 5 lines
drivers/mtd/ubi/build.c +2
-0@@ -46,6 +46,9 @@/* Maximum length of the 'mtd=' parameter */ #define MTD_PARAM_LEN_MAX 64 +/* Maximum number of comma-separated items in ht 'mtd=' parameter */ +#define MTD_PARAM_MAX_COUNT 2
Fixed the spelling of "the" and pushed to linux-ubi.git, thanks!
Signature · 9 lines
Best Regards, Artem Bityutskiy -------------- next part -------------- A non-text attachment was scrubbed... Name: signature.asc Type: application/pgp-signature Size: 836 bytes Desc: This is a digitally signed message part URL: <http://lists.infradead.org/pipermail/linux-arm-kernel/attachments/20120819/43454bc0/attachment.sig>
Re: [PATCH 5/8] UBI: check max_beb_per1024 value in ubi_attach_mtd_dev
In reply to Shmulik LadkaniHi Shmulik,
2012/8/19 Shmulik Ladkani <[email protected]>:
Quoted 8 lines
Hi Richard,
drivers/mtd/ubi/build.c int ubi_attach_mtd_dev(struct mtd_info *mtd, int ubi_num, · line 864
Quoted 4 lines · On Fri, 17 Aug 2012 16:35:21 +0200 Richard Genoud <[email protected]>…
drivers/mtd/ubi/build.c +4
-0+/* +* A value of 0 is forced to the default value to keep the same +* behavior between ubiattach command and module parameter +*/
Quoted 8 lines
Minor thing.
Since the module parameter is not yet introduced (only in a later patch), and since last part of sentence isn't that important, I would simply state:
+ * Use the default if
max_beb_per1024isn't provided.
That's right, I'll correct that in next version.
Thanks !
Re: [PATCH 6/8] UBI: replace MTD_UBI_BEB_LIMIT with module parameter
In reply to Shmulik Ladkani2012/8/19 Shmulik Ladkani <[email protected]>:
Quoted 10 lines
Hi Richard,
drivers/mtd/ubi/build.c static int __init ubi_mtd_param_parse(const char *val, struct kernel_param *kp) · line 1414
Quoted 4 lines · On Fri, 17 Aug 2012 16:35:22 +0200 Richard Genoud <[email protected]>…
drivers/mtd/ubi/build.c +4
-0+"MTD devices may be specified by their number, name, or path to the MTD character device node.\n" +"Optional \"vid_hdr_offs\" parameter specifies UBI VID header position to be used by UBI. (default value if 0 or not set)\n" +"Optional \"max_beb_per1024\" parameter specifies the maximum expected bad eraseblock per 1024 eraseblocks. (default value (" + __stringify(CONFIG_MTD_UBI_BEB_LIMIT) ") if 0 or not set)\n"Looks like "mtd=/dev/mtd1,,25" is invalid, although we state "default value if 0 or not set".
I'm going to check that.
Quoted 3 lines
Also, lines are exceeding 80 chars, not sure this is more readable than if they were broken.
Actually, I didn't split those lines to make checkpatch happy. Checkpatch.pl doesn't like split strings because they are hard to grep. So there's an exception on the 80 column rule for strings.
Quoted 3 lines
Regards,
Shmulik
Signature · 1 line
for me, ck means con kolivas and not calvin klein... does it mean I'm a geek ?
Re: [PATCH 1/8] arm: sam9_l9260_defconfig: adjust UBI bad eraseblocks limit
In reply to Richard GenoudQuoted 9 lines · Richard Genoud
From: Artem Bityutskiy <[email protected]>
UBI has changed the
MTD_UBI_BEB_LIMITsemantics. It used to be a percent of total amount of eraseblock in the partition, and now it is the maximum amount of bad eraseblocks on the entire devise per 1024 eraseblocks. So not only the units changed, but also the meaning. But anyway, old 3% roughly correspond to new 30, so change the defconfig correspondingly.Signed-off-by Artem Bityutskiy <[email protected]>
simply drop this defconfig
Best Regards,
J.
Re: [PATCH 5/8] UBI: check max_beb_per1024 value in ubi_attach_mtd_dev
In reply to Richard GenoudQuoted 2 lines · Richard Genoud
That's right, I'll correct that in next version.
Thanks !
I've amended this patch, added Shmulik's reviewed-by and pushed to linux-ubi.git, thanks!
Signature · 2 lines
Best Regards, Artem Bityutskiy
Re: [PATCH 6/8] UBI: replace MTD_UBI_BEB_LIMIT with module parameter
In reply to Richard Genoud2012/8/20 Richard Genoud <[email protected]>:
Quoted 4 lines
2012/8/19 Shmulik Ladkani <[email protected]>:
Quoted 3 lines
Hi Richard,
On Fri, 17 Aug 2012 16:35:22 +0200 Richard Genoud <[email protected]> wrote:
Quoted 8 lines
Quoted 7 lines
drivers/mtd/ubi/build.c static int __init ubi_mtd_param_parse(const char *val, struct kernel_param *kp) · line 1414
Quoted 4 lines
drivers/mtd/ubi/build.c +4
-0+"MTD devices may be specified by their number, name, or path to the MTD character device node.\n" +"Optional \"vid_hdr_offs\" parameter specifies UBI VID header position to be used by UBI. (default value if 0 or not set)\n" +"Optional \"max_beb_per1024\" parameter specifies the maximum expected bad eraseblock per 1024 eraseblocks. (default value (" + __stringify(CONFIG_MTD_UBI_BEB_LIMIT) ") if 0 or not set)\n"Looks like "mtd=/dev/mtd1,,25" is invalid, although we state "default value if 0 or not set".
I'm going to check that.
I made a patch to accept empty string value.
I'll send it with the rest of the patch serie.
Regards,
Richard.
Re: [PATCH 5/8] UBI: check max_beb_per1024 value in ubi_attach_mtd_dev
In reply to Artem BityutskiyQuoted 6 lines · Artem Bityutskiy
Quoted 2 lines · Richard Genoud
That's right, I'll correct that in next version.
Thanks !I've amended this patch, added Shmulik's reviewed-by and pushed to linux-ubi.git, thanks!
Sorry, actually I've dropped it - it does not compile :-) Please, send bisectable patch-sets. Anyway, I expect you to re-send patches 5-8.
P.S. I am not sure we need to CC arm mailing list and lkml - I think we spam them unnecessarily and the MTD list is enough.
Signature · 2 lines
Best Regards, Artem Bityutskiy
Re: [PATCH 7/8] UBI: add ioctl for max_beb_per1024
In reply to Richard Genoud2012/8/17 Richard Genoud <[email protected]>:
include/mtd/ubi-user.h enum { · line 271
Quoted 12 lines
+ * The accepted range is 0-255. If 0 is given, the default kernel config value
+ *CONFIG_MTD_UBI_BEB_LIMITwill be used for compatibility.
*/struct ubi_attach_req { __s32 ubi_num; __s32 mtd_num; __s32 vid_hdr_offset;include/mtd/ubi-user.h +2
-1-__s8 padding[12 ]; +__u8 max_beb_per1024; +__s8 padding[11 ]; };
So if I use __u16 instead of __u8, what should be the upper limit ? 1024 ? (1024 is nonsense, but why not...)
Regards,
Richard
Signature · 1 line
for me, ck means con kolivas and not calvin klein... does it mean I'm a geek ?
Re: [PATCH 7/8] UBI: add ioctl for max_beb_per1024
Quoted 13 lines · Richard Genoud
2012/8/17 Richard Genoud <[email protected]>:
include/mtd/ubi-user.h enum { · line 271
Quoted 12 lines
+ * The accepted range is 0-255. If 0 is given, the default kernel config value
+ *CONFIG_MTD_UBI_BEB_LIMITwill be used for compatibility.
*/struct ubi_attach_req { __s32 ubi_num; __s32 mtd_num; __s32 vid_hdr_offset;include/mtd/ubi-user.h +2
-1-__s8 padding[12 ]; +__u8 max_beb_per1024; +__s8 padding[11 ]; };
Quoted 2 lines
So if I use
__u16instead of__u8, what should be the upper limit ? 1024 ? (1024 is nonsense, but why not...)
Pick a reasonably large number, e.g., 768.
Signature · 2 lines
Best Regards, Artem Bityutskiy
Re: [PATCH 3/8] UBI: introduce MTD_PARAM_MAX_COUNT
In reply to Artem Bityutskiy2012/8/19 Artem Bityutskiy <[email protected]>:
Quoted 14 lines · Richard Genoud
Quoted 13 lines
Signed-off-by Richard Genoud <[email protected]>--- drivers/mtd/ubi/build.c | 7 +++++-- 1 files changed, 5 insertions(+), 2 deletions(-)drivers/mtd/ubi/build.c +0
-0@@ -46,6 +46,9 @@/* Maximum length of the 'mtd=' parameter */ #define MTD_PARAM_LEN_MAX 64
Quoted 8 lines
drivers/mtd/ubi/build.c line 50
Quoted 2 lines
drivers/mtd/ubi/build.c +2
-0+/* Maximum number of comma-separated items in ht 'mtd=' parameter */ +#define MTD_PARAM_MAX_COUNT 2Fixed the spelling of "the" and pushed to linux-ubi.git, thanks!
--
Best Regards,
Artem Bityutskiy
Hi Artem,
It seems that this patch has been dropped on linux-ubi/master. Is it a git-reset accident or my patches didn't apply cleanly on it ? Anyway, if you want me to re-send it rebased on top of linux-ubi/master, just ask (I guess there will be a little conflit on the #define)
Best Regards,
Richard.
Signature · 1 line
for me, ck means con kolivas and not calvin klein... does it mean I'm a geek ?
Re: [PATCH 3/8] UBI: introduce MTD_PARAM_MAX_COUNT
Quoted 7 lines · Richard Genoud
Hi Artem,
It seems that this patch has been dropped on linux-ubi/master. Is it a git-reset accident or my patches didn't apply cleanly on it ? Anyway, if you want me to re-send it rebased on top of linux-ubi/master, just ask (I guess there will be a little conflit on the #define)
My mistake, dropped it accidentally - worked late. Sorry, just put it back.
Signature · 2 lines
Best Regards, Artem Bityutskiy