Pass -EUCLEN to userspace?
Hi All,
I am currently working on a program similar to ubihealthd, just for raw mtd pages, not UBI. Basically I want to find out in userspace if my Nand needs scrubbing. Is it possible somehow to get this information in userspace?
So far I can count the number of bitflips corrected using the ECCGETSTATS ioctl. Also I can read the bitflip_threshold from /sys/class/mtdx/bitflip_threshold. The problem is now that I can only read full pages, but the bitflip threshold is per ecc_step_size. Simply dividing by the number of ecc_steps is not accurate. Any way to solve this?
Sascha
Signature · 4 lines
Pengutronix e.K. | | Industrial Linux Solutions | http://www.pengutronix.de/ | Peiner Str. 6-8, 31137 Hildesheim, Germany | Phone: +49-5121-206917-0 | Amtsgericht Hildesheim, HRA 2686 | Fax: +49-5121-206917-5555 |
Hi Sascha,
Quoted 5 lines · On Wed, 20 Apr 2016 15:25:16 +0200 Sascha Hauer <[email protected]> wrote:
Hi All,
I am currently working on a program similar to ubihealthd, just for raw mtd pages, not UBI. Basically I want to find out in userspace if my Nand needs scrubbing. Is it possible somehow to get this information in userspace?
Actually we discussed that a year ago with Richard. I told him that we should put the read/write/erase statistics at the MTD level so that other MTD users (including userspace programs) could use the same infra for non-UBI partitions (I need that for the UBOOT and SPL partitions).
My suggestion was to store those information at the MTD level, and let UBI implement its own scrubbing layer on top of that, but Richard decided to go for a simpler approach for its first implementation.
Quoted 7 lines
So far I can count the number of bitflips corrected using the ECCGETSTATS ioctl. Also I can read the
bitflip_thresholdfrom/sys/class/mtdx/bitflip_threshold. The problem is now that I can only read full pages, but the bitflip threshold is perecc_step_size. Simply dividing by the number ofecc_stepsis not accurate. Any way to solve this?
Hm, you're right, then we'll need to expose those information through a different ioctl.
Regards,
Boris
Signature · 3 lines
Boris Brezillon, Free Electrons Embedded Linux and Kernel engineering http://free-electrons.com
+ Richard, Daniel and Brian,
Quoted 35 lines · On Fri, 22 Apr 2016 17:24:56 +0200 Boris Brezillon…
Hi Sascha,
Quoted 5 lines · On Wed, 20 Apr 2016 15:25:16 +0200 Sascha Hauer <[email protected]> wrote:
Hi All,
I am currently working on a program similar to ubihealthd, just for raw mtd pages, not UBI. Basically I want to find out in userspace if my Nand needs scrubbing. Is it possible somehow to get this information in userspace?
Actually we discussed that a year ago with Richard. I told him that we should put the read/write/erase statistics at the MTD level so that other MTD users (including userspace programs) could use the same infra for non-UBI partitions (I need that for the UBOOT and SPL partitions).
My suggestion was to store those information at the MTD level, and let UBI implement its own scrubbing layer on top of that, but Richard decided to go for a simpler approach for its first implementation.
Quoted 7 lines
So far I can count the number of bitflips corrected using the ECCGETSTATS ioctl. Also I can read the
bitflip_thresholdfrom/sys/class/mtdx/bitflip_threshold. The problem is now that I can only read full pages, but the bitflip threshold is perecc_step_size. Simply dividing by the number ofecc_stepsis not accurate. Any way to solve this?Hm, you're right, then we'll need to expose those information through a different ioctl.
Regards,
Boris
Signature · 3 lines
Boris Brezillon, Free Electrons Embedded Linux and Kernel engineering http://free-electrons.com
Richard Weinberger
maintainerSascha, Boris,
Am 22.04.2016 um 17:28 schrieb Boris Brezillon:
Quoted 4 lines
Quoted 4 lines
Quoted 3 lines
I am currently working on a program similar to ubihealthd, just for raw mtd pages, not UBI. Basically I want to find out in userspace if my Nand needs scrubbing. Is it possible somehow to get this information in userspace?
Quoted 8 lines
Quoted 8 lines
Actually we discussed that a year ago with Richard. I told him that we should put the read/write/erase statistics at the MTD level so that other MTD users (including userspace programs) could use the same infra for non-UBI partitions (I need that for the UBOOT and SPL partitions).
My suggestion was to store those information at the MTD level, and let UBI implement its own scrubbing layer on top of that, but Richard decided to go for a simpler approach for its first implementation.
Yeah, I did a first implementation on UBI layer as it had everything we need and I didn't want to replicate UBI at MTD level.
Another reason is that we were not sure how sophisticated ubihealthd needs to be.
Sasha, what exactly is your use case and why is the UBI approach not sufficient for you? On Linux MTD access should only happen through UBI and UBOOT/SPL partitions stay untouched.
Thanks,
//richard
Quoted 16 lines · On Fri, 22 Apr 2016 17:48:35 +0200 Richard Weinberger <[email protected]> wrote:
Sascha, Boris,
Am 22.04.2016 um 17:28 schrieb Boris Brezillon:
Quoted 4 lines
Quoted 4 lines
Quoted 3 lines
I am currently working on a program similar to ubihealthd, just for raw mtd pages, not UBI. Basically I want to find out in userspace if my Nand needs scrubbing. Is it possible somehow to get this information in userspace?
Quoted 8 lines
Quoted 8 lines
Actually we discussed that a year ago with Richard. I told him that we should put the read/write/erase statistics at the MTD level so that other MTD users (including userspace programs) could use the same infra for non-UBI partitions (I need that for the UBOOT and SPL partitions).
My suggestion was to store those information at the MTD level, and let UBI implement its own scrubbing layer on top of that, but Richard decided to go for a simpler approach for its first implementation.
Quoted 6 lines
Yeah, I did a first implementation on UBI layer as it had everything we need and I didn't want to replicate UBI at MTD level.
Another reason is that we were not sure how sophisticated ubihealthd needs to be.Sasha, what exactly is your use case and why is the UBI approach not sufficient for you? On Linux MTD access should only happen through UBI and UBOOT/SPL partitions stay untouched.
Fair enough. So all we'll need is a way to retrieve the maximum number of bitflips for a given block, so that the userspace deamon can periodically read the SPL and bootloader blocks and decide to scrub those blocks if the number of bitflips exceed the threshold.
Signature · 3 lines
Boris Brezillon, Free Electrons Embedded Linux and Kernel engineering http://free-electrons.com
Richard Weinberger
maintainerAm 22.04.2016 um 18:11 schrieb Boris Brezillon:
Quoted 7 lines
Quoted 2 lines
Sasha, what exactly is your use case and why is the UBI approach not sufficient for you? On Linux MTD access should only happen through UBI and UBOOT/SPL partitions stay untouched.
Fair enough. So all we'll need is a way to retrieve the maximum number of bitflips for a given block, so that the userspace deamon can periodically read the SPL and bootloader blocks and decide to scrub those blocks if the number of bitflips exceed the threshold.
How can we scrub non-UBI blocks in a power cut safe way? Unless we have a backup SPL/booloader.
Thanks,
//richard
Quoted 11 lines · On Fri, 22 Apr 2016 20:20:20 +0200 Richard Weinberger <[email protected]> wrote:
Am 22.04.2016 um 18:11 schrieb Boris Brezillon:
Quoted 7 lines
Quoted 2 lines
Sasha, what exactly is your use case and why is the UBI approach not sufficient for you? On Linux MTD access should only happen through UBI and UBOOT/SPL partitions stay untouched.
Fair enough. So all we'll need is a way to retrieve the maximum number of bitflips for a given block, so that the userspace deamon can periodically read the SPL and bootloader blocks and decide to scrub those blocks if the number of bitflips exceed the threshold.
How can we scrub non-UBI blocks in a power cut safe way? Unless we have a backup SPL/booloader.
Of course this assumes you have backup partitions.
Signature · 3 lines
Boris Brezillon, Free Electrons Embedded Linux and Kernel engineering http://free-electrons.com
Quoted 16 lines · Richard Weinberger
Sascha, Boris,
Am 22.04.2016 um 17:28 schrieb Boris Brezillon:
Quoted 4 lines
Quoted 4 lines
Quoted 3 lines
I am currently working on a program similar to ubihealthd, just for raw mtd pages, not UBI. Basically I want to find out in userspace if my Nand needs scrubbing. Is it possible somehow to get this information in userspace?
Quoted 8 lines
Quoted 8 lines
Actually we discussed that a year ago with Richard. I told him that we should put the read/write/erase statistics at the MTD level so that other MTD users (including userspace programs) could use the same infra for non-UBI partitions (I need that for the UBOOT and SPL partitions).
My suggestion was to store those information at the MTD level, and let UBI implement its own scrubbing layer on top of that, but Richard decided to go for a simpler approach for its first implementation.
Quoted 6 lines
Yeah, I did a first implementation on UBI layer as it had everything we need and I didn't want to replicate UBI at MTD level.
Another reason is that we were not sure how sophisticated ubihealthd needs to be.Sasha, what exactly is your use case and why is the UBI approach not sufficient for you? On Linux MTD access should only happen through UBI and UBOOT/SPL partitions stay untouched.
On i.MX6 the Bootloader in Nand can indeed be redundant, so it's possible to scrub the pages. This is exactly our usecase, we want to be able to detect bitflips in the bootloader area.
Note that on i.MX6 the first page in the first n blocks on Nand contains a structure called FCB (flash control block). This is not encoded with the standard ECC algorithm used on the other areas in Nand. Reading these pages will always return -EBABDMSG, they have to be read in raw mode. That just to say that a "maximum bitflips per block" might not be sufficient.
Sascha
Signature · 4 lines
Pengutronix e.K. | | Industrial Linux Solutions | http://www.pengutronix.de/ | Peiner Str. 6-8, 31137 Hildesheim, Germany | Phone: +49-5121-206917-0 | Amtsgericht Hildesheim, HRA 2686 | Fax: +49-5121-206917-5555 |
Quoted 24 lines · On Mon, 25 Apr 2016 07:28:57 +0200 Sascha Hauer <[email protected]> wrote:
Quoted 16 lines · Richard Weinberger
Sascha, Boris,
Am 22.04.2016 um 17:28 schrieb Boris Brezillon:
Quoted 4 lines
Quoted 4 lines
Quoted 3 lines
I am currently working on a program similar to ubihealthd, just for raw mtd pages, not UBI. Basically I want to find out in userspace if my Nand needs scrubbing. Is it possible somehow to get this information in userspace?
Quoted 8 lines
Quoted 8 lines
Actually we discussed that a year ago with Richard. I told him that we should put the read/write/erase statistics at the MTD level so that other MTD users (including userspace programs) could use the same infra for non-UBI partitions (I need that for the UBOOT and SPL partitions).
My suggestion was to store those information at the MTD level, and let UBI implement its own scrubbing layer on top of that, but Richard decided to go for a simpler approach for its first implementation.
Quoted 6 lines
Yeah, I did a first implementation on UBI layer as it had everything we need and I didn't want to replicate UBI at MTD level.
Another reason is that we were not sure how sophisticated ubihealthd needs to be.Sasha, what exactly is your use case and why is the UBI approach not sufficient for you? On Linux MTD access should only happen through UBI and UBOOT/SPL partitions stay untouched.
Quoted 9 lines
On i.MX6 the Bootloader in Nand can indeed be redundant, so it's possible to scrub the pages. This is exactly our usecase, we want to be able to detect bitflips in the bootloader area.
Note that on i.MX6 the first page in the first n blocks on Nand contains a structure called FCB (flash control block). This is not encoded with the standard ECC algorithm used on the other areas in Nand. Reading these pages will always return-EBABDMSG, they have to be read in raw mode. That just to say that a "maximum bitflips per block" might not be sufficient.
Okay, pretty much the same use-case we have on sunxi platforms: the SPL partition is written in raw mode because the page layout (in-band/ECC data disposition) is not the one we're using for the rest of the NAND. For this specific partition, I see 2 solutions that you can implement in userspace to count the number of bitflips:
1/ read the partition page by page in raw mode and compare each
page to a reference file. This implies having a reference file stored on your FS.
2/ if you know the ECC algorithm (and the platform specific config,
like the polynomial for a BCH engine) then you can create a tool doing the ECC error detection in userspace.
Signature · 3 lines
Boris Brezillon, Free Electrons Embedded Linux and Kernel engineering http://free-electrons.com
Quoted 43 lines · Boris Brezillon
Quoted 24 lines · On Mon, 25 Apr 2016 07:28:57 +0200 Sascha Hauer <[email protected]> wrote:
Quoted 16 lines · Richard Weinberger
Sascha, Boris,
Am 22.04.2016 um 17:28 schrieb Boris Brezillon:
Quoted 4 lines
Quoted 4 lines
Quoted 3 lines
I am currently working on a program similar to ubihealthd, just for raw mtd pages, not UBI. Basically I want to find out in userspace if my Nand needs scrubbing. Is it possible somehow to get this information in userspace?
Quoted 8 lines
Quoted 8 lines
Actually we discussed that a year ago with Richard. I told him that we should put the read/write/erase statistics at the MTD level so that other MTD users (including userspace programs) could use the same infra for non-UBI partitions (I need that for the UBOOT and SPL partitions).
My suggestion was to store those information at the MTD level, and let UBI implement its own scrubbing layer on top of that, but Richard decided to go for a simpler approach for its first implementation.
Quoted 6 lines
Yeah, I did a first implementation on UBI layer as it had everything we need and I didn't want to replicate UBI at MTD level.
Another reason is that we were not sure how sophisticated ubihealthd needs to be.Sasha, what exactly is your use case and why is the UBI approach not sufficient for you? On Linux MTD access should only happen through UBI and UBOOT/SPL partitions stay untouched.
Quoted 9 lines
On i.MX6 the Bootloader in Nand can indeed be redundant, so it's possible to scrub the pages. This is exactly our usecase, we want to be able to detect bitflips in the bootloader area.
Note that on i.MX6 the first page in the first n blocks on Nand contains a structure called FCB (flash control block). This is not encoded with the standard ECC algorithm used on the other areas in Nand. Reading these pages will always return-EBABDMSG, they have to be read in raw mode. That just to say that a "maximum bitflips per block" might not be sufficient.Okay, pretty much the same use-case we have on sunxi platforms: the SPL partition is written in raw mode because the page layout (in-band/ECC data disposition) is not the one we're using for the rest of the NAND. For this specific partition, I see 2 solutions that you can implement in userspace to count the number of bitflips:
Quoted 6 lines
1/ read the partition page by page in raw mode and compare each
page to a reference file. This implies having a reference file stored on your FS.
2/ if you know the ECC algorithm (and the platform specific config,
like the polynomial for a BCH engine) then you can create a tool doing the ECC error detection in userspace.
I can do the ECC calculation for the FBCs in userspace, that's no problem. I was referring to:
Quoted 2 lines
Fair enough. So all we'll need is a way to retrieve the maximum number of bitflips for a given block
When a block contains both FCB and data protected with regular ECC in other pages, an algorithm retrieving the maximum number of bitlfips for a given block might stumble over the bad data in the page containing the FCB. So I think we need the maximum number of bitflips per page, not per block.
Sascha
Signature · 4 lines
Pengutronix e.K. | | Industrial Linux Solutions | http://www.pengutronix.de/ | Peiner Str. 6-8, 31137 Hildesheim, Germany | Phone: +49-5121-206917-0 | Amtsgericht Hildesheim, HRA 2686 | Fax: +49-5121-206917-5555 |
Quoted 54 lines · On Mon, 25 Apr 2016 10:22:11 +0200 Sascha Hauer <[email protected]> wrote:
Quoted 43 lines · Boris Brezillon
Quoted 24 lines · On Mon, 25 Apr 2016 07:28:57 +0200 Sascha Hauer <[email protected]> wrote:
Quoted 16 lines · Richard Weinberger
Sascha, Boris,
Am 22.04.2016 um 17:28 schrieb Boris Brezillon:
Quoted 4 lines
Quoted 4 lines
Quoted 3 lines
I am currently working on a program similar to ubihealthd, just for raw mtd pages, not UBI. Basically I want to find out in userspace if my Nand needs scrubbing. Is it possible somehow to get this information in userspace?
Quoted 8 lines
Quoted 8 lines
Actually we discussed that a year ago with Richard. I told him that we should put the read/write/erase statistics at the MTD level so that other MTD users (including userspace programs) could use the same infra for non-UBI partitions (I need that for the UBOOT and SPL partitions).
My suggestion was to store those information at the MTD level, and let UBI implement its own scrubbing layer on top of that, but Richard decided to go for a simpler approach for its first implementation.
Quoted 6 lines
Yeah, I did a first implementation on UBI layer as it had everything we need and I didn't want to replicate UBI at MTD level.
Another reason is that we were not sure how sophisticated ubihealthd needs to be.Sasha, what exactly is your use case and why is the UBI approach not sufficient for you? On Linux MTD access should only happen through UBI and UBOOT/SPL partitions stay untouched.
Quoted 9 lines
On i.MX6 the Bootloader in Nand can indeed be redundant, so it's possible to scrub the pages. This is exactly our usecase, we want to be able to detect bitflips in the bootloader area.
Note that on i.MX6 the first page in the first n blocks on Nand contains a structure called FCB (flash control block). This is not encoded with the standard ECC algorithm used on the other areas in Nand. Reading these pages will always return-EBABDMSG, they have to be read in raw mode. That just to say that a "maximum bitflips per block" might not be sufficient.Okay, pretty much the same use-case we have on sunxi platforms: the SPL partition is written in raw mode because the page layout (in-band/ECC data disposition) is not the one we're using for the rest of the NAND. For this specific partition, I see 2 solutions that you can implement in userspace to count the number of bitflips:
Quoted 6 lines
1/ read the partition page by page in raw mode and compare each
page to a reference file. This implies having a reference file stored on your FS.
2/ if you know the ECC algorithm (and the platform specific config,
like the polynomial for a BCH engine) then you can create a tool doing the ECC error detection in userspace.I can do the ECC calculation for the FBCs in userspace, that's no problem. I was referring to:
Quoted 8 lines
Quoted 2 lines
Fair enough. So all we'll need is a way to retrieve the maximum number of bitflips for a given block
When a block contains both FCB and data protected with regular ECC in other pages, an algorithm retrieving the maximum number of bitlfips for a given block might stumble over the bad data in the page containing the FCB. So I think we need the maximum number of bitflips per page, not per block.
Oh, so you mix 2 different page layout in the same partition (we try to avoid that, even if this means loosing some space) :-/.
Regarding the maximum number of bitflips per chunk, maybe we can make it part of the ioctl request instead of saving the statistics at the MTD level.
How about creating a new ioctl taking a pointer to this struct as a parameter:
struct mtd_extended_read_ops {
/* Existing params */
unsigned int mode;
size_t len;
size_t retlen;
size_t ooblen;
size_t oobretlen;
uint32_t ooboffs;
void *datbuf;
void *oobbuf;
/*
* Param containing the maximum number of bitflips for this
* read request.
*/
unsigned int max_bitflips;
};Signature · 3 lines
Boris Brezillon, Free Electrons Embedded Linux and Kernel engineering http://free-electrons.com
Quoted 60 lines · Boris Brezillon
Quoted 57 lines · On Mon, 25 Apr 2016 10:22:11 +0200 Sascha Hauer <[email protected]> wrote:
Quoted 43 lines · Boris Brezillon
Quoted 24 lines · On Mon, 25 Apr 2016 07:28:57 +0200 Sascha Hauer <[email protected]> wrote:
Quoted 16 lines · Richard Weinberger
Sascha, Boris,
Am 22.04.2016 um 17:28 schrieb Boris Brezillon:
Quoted 4 lines
Quoted 4 lines
Quoted 3 lines
I am currently working on a program similar to ubihealthd, just for raw mtd pages, not UBI. Basically I want to find out in userspace if my Nand needs scrubbing. Is it possible somehow to get this information in userspace?
Quoted 8 lines
Quoted 8 lines
Actually we discussed that a year ago with Richard. I told him that we should put the read/write/erase statistics at the MTD level so that other MTD users (including userspace programs) could use the same infra for non-UBI partitions (I need that for the UBOOT and SPL partitions).
My suggestion was to store those information at the MTD level, and let UBI implement its own scrubbing layer on top of that, but Richard decided to go for a simpler approach for its first implementation.
Quoted 6 lines
Yeah, I did a first implementation on UBI layer as it had everything we need and I didn't want to replicate UBI at MTD level.
Another reason is that we were not sure how sophisticated ubihealthd needs to be.Sasha, what exactly is your use case and why is the UBI approach not sufficient for you? On Linux MTD access should only happen through UBI and UBOOT/SPL partitions stay untouched.
Quoted 9 lines
On i.MX6 the Bootloader in Nand can indeed be redundant, so it's possible to scrub the pages. This is exactly our usecase, we want to be able to detect bitflips in the bootloader area.
Note that on i.MX6 the first page in the first n blocks on Nand contains a structure called FCB (flash control block). This is not encoded with the standard ECC algorithm used on the other areas in Nand. Reading these pages will always return-EBABDMSG, they have to be read in raw mode. That just to say that a "maximum bitflips per block" might not be sufficient.Okay, pretty much the same use-case we have on sunxi platforms: the SPL partition is written in raw mode because the page layout (in-band/ECC data disposition) is not the one we're using for the rest of the NAND. For this specific partition, I see 2 solutions that you can implement in userspace to count the number of bitflips:
Quoted 6 lines
1/ read the partition page by page in raw mode and compare each
page to a reference file. This implies having a reference file stored on your FS.
2/ if you know the ECC algorithm (and the platform specific config,
like the polynomial for a BCH engine) then you can create a tool doing the ECC error detection in userspace.I can do the ECC calculation for the FBCs in userspace, that's no problem. I was referring to:
Quoted 2 lines
Fair enough. So all we'll need is a way to retrieve the maximum number of bitflips for a given block
Quoted 8 lines
Quoted 5 lines
When a block contains both FCB and data protected with regular ECC in other pages, an algorithm retrieving the maximum number of bitlfips for a given block might stumble over the bad data in the page containing the FCB. So I think we need the maximum number of bitflips per page, not per block.
Oh, so you mix 2 different page layout in the same partition (we try to avoid that, even if this means loosing some space) :-/.
I wasn't really aware of this. The way we have it now allows us to create a single partition containing the bootloader. Splitting this up into multiple partitions wouldn't be as flexible.
Quoted 17 lines
Regarding the maximum number of bitflips per chunk, maybe we can make it part of the ioctl request instead of saving the statistics at the MTD level.
How about creating a new ioctl taking a pointer to this struct as a parameter:
struct mtd_extended_read_ops { /* Existing params */ unsigned int mode; size_t len; size_t retlen; size_t ooblen; size_t oobretlen; uint32_t ooboffs; void *datbuf;
Quoted 8 lines
void *oobbuf; /* * Param containing the maximum number of bitflips for this * read request. */ unsigned int max_bitflips; };
Not sure how this ioctl exactly should look like, but this would solve the problem.
This also solves another problem. Right now calling the ECCGETSTATS ioctl before and after the read operation assumes that there are no concurrent readers on the mtd device.
Sascha
Signature · 4 lines
Pengutronix e.K. | | Industrial Linux Solutions | http://www.pengutronix.de/ | Peiner Str. 6-8, 31137 Hildesheim, Germany | Phone: +49-5121-206917-0 | Amtsgericht Hildesheim, HRA 2686 | Fax: +49-5121-206917-5555 |
Quoted 67 lines · On Mon, 25 Apr 2016 11:14:16 +0200 Sascha Hauer <[email protected]> wrote:
Quoted 66 lines · Boris Brezillon
Quoted 62 lines · On Mon, 25 Apr 2016 10:22:11 +0200 Sascha Hauer <[email protected]> wrote:
Quoted 43 lines · Boris Brezillon
Quoted 24 lines · On Mon, 25 Apr 2016 07:28:57 +0200 Sascha Hauer <[email protected]> wrote:
Quoted 16 lines · Richard Weinberger
Sascha, Boris,
Am 22.04.2016 um 17:28 schrieb Boris Brezillon:
Quoted 4 lines
Quoted 4 lines
Quoted 3 lines
I am currently working on a program similar to ubihealthd, just for raw mtd pages, not UBI. Basically I want to find out in userspace if my Nand needs scrubbing. Is it possible somehow to get this information in userspace?
Quoted 8 lines
Quoted 8 lines
Actually we discussed that a year ago with Richard. I told him that we should put the read/write/erase statistics at the MTD level so that other MTD users (including userspace programs) could use the same infra for non-UBI partitions (I need that for the UBOOT and SPL partitions).
My suggestion was to store those information at the MTD level, and let UBI implement its own scrubbing layer on top of that, but Richard decided to go for a simpler approach for its first implementation.
Quoted 6 lines
Yeah, I did a first implementation on UBI layer as it had everything we need and I didn't want to replicate UBI at MTD level.
Another reason is that we were not sure how sophisticated ubihealthd needs to be.Sasha, what exactly is your use case and why is the UBI approach not sufficient for you? On Linux MTD access should only happen through UBI and UBOOT/SPL partitions stay untouched.
Quoted 9 lines
On i.MX6 the Bootloader in Nand can indeed be redundant, so it's possible to scrub the pages. This is exactly our usecase, we want to be able to detect bitflips in the bootloader area.
Note that on i.MX6 the first page in the first n blocks on Nand contains a structure called FCB (flash control block). This is not encoded with the standard ECC algorithm used on the other areas in Nand. Reading these pages will always return-EBABDMSG, they have to be read in raw mode. That just to say that a "maximum bitflips per block" might not be sufficient.Okay, pretty much the same use-case we have on sunxi platforms: the SPL partition is written in raw mode because the page layout (in-band/ECC data disposition) is not the one we're using for the rest of the NAND. For this specific partition, I see 2 solutions that you can implement in userspace to count the number of bitflips:
Quoted 6 lines
1/ read the partition page by page in raw mode and compare each
page to a reference file. This implies having a reference file stored on your FS.
2/ if you know the ECC algorithm (and the platform specific config,
like the polynomial for a BCH engine) then you can create a tool doing the ECC error detection in userspace.I can do the ECC calculation for the FBCs in userspace, that's no problem. I was referring to:
Quoted 2 lines
Fair enough. So all we'll need is a way to retrieve the maximum number of bitflips for a given block
When a block contains both FCB and data protected with regular ECC in other pages, an algorithm retrieving the maximum number of bitlfips for a given block might stumble over the bad data in the page containing the FCB. So I think we need the maximum number of bitflips per page, not per block.
Quoted 4 lines
Quoted 2 lines
Oh, so you mix 2 different page layout in the same partition (we try to avoid that, even if this means loosing some space) :-/.
I wasn't really aware of this.
By "we" I meant on the sunxi platform. This kind of thing has never been documented, so you're currently not infringing any rule, I just find it easier when everything is well separated...
Quoted 30 lines
The way we have it now allows us to
create a single partition containing the bootloader. Splitting this up into multiple partitions wouldn't be as flexible.Quoted 17 lines
Regarding the maximum number of bitflips per chunk, maybe we can make it part of the ioctl request instead of saving the statistics at the MTD level.
How about creating a new ioctl taking a pointer to this struct as a parameter:
struct mtd_extended_read_ops { /* Existing params */ unsigned int mode; size_t len; size_t retlen; size_t ooblen; size_t oobretlen; uint32_t ooboffs; void *datbuf;Quoted 8 lines
void *oobbuf; /* * Param containing the maximum number of bitflips for this * read request. */ unsigned int max_bitflips; };
Quoted 2 lines
Not sure how this ioctl exactly should look like, but this would solve the problem.
Let me design a quick prototype, I'll let you follow up with the patch submission process...
Quoted 4 lines
This also solves another problem. Right now calling the ECCGETSTATS ioctl before and after the read operation assumes that there are no concurrent readers on the mtd device.
That's true.
Signature · 3 lines
Boris Brezillon, Free Electrons Embedded Linux and Kernel engineering http://free-electrons.com
Quoted 26 lines · On Mon, 25 Apr 2016 11:26:16 +0200 Boris Brezillon…
Quoted 26 lines
Quoted 25 lines
Regarding the maximum number of bitflips per chunk, maybe we can make it part of the ioctl request instead of saving the statistics at the MTD level.
How about creating a new ioctl taking a pointer to this struct as a parameter:
struct mtd_extended_read_ops { /* Existing params */ unsigned int mode; size_t len; size_t retlen; size_t ooblen; size_t oobretlen; uint32_t ooboffs; void *datbuf; void *oobbuf; /* * Param containing the maximum number of bitflips for this * read request. */ unsigned int max_bitflips; };
Quoted 5 lines
Quoted 2 lines
Not sure how this ioctl exactly should look like, but this would solve the problem.
Let me design a quick prototype, I'll let you follow up with the patch submission process...
Below is an untested patch adding a new ioctl returning the ECC/read stats. Feel free to debug/enhance this implementation and submit it to the MTD ML.
--->8---
From 2c07a2a015e6c0bdc2f9d91c9a1b971903da0493 Mon Sep 17 00:00:00 2001
From: Boris Brezillon <[email protected]>
Date: Mon, 25 Apr 2016 16:05:06 +0200
Subject: [PATCH] mtd: add a the MEMREAD ioctl to attach ECC stats to the read
request
TODO: add proper commit message + split changes into several patches.
--- drivers/mtd/devices/docg3.c | 10 +++++ drivers/mtd/mtdchar.c | 76 ++++++++++++++++++++++++++++++++++++++ drivers/mtd/mtdcore.c | 9 +++++ drivers/mtd/nand/nand_base.c | 10 +++++ drivers/mtd/onenand/onenand_base.c | 11 ++++++ include/linux/mtd/mtd.h | 7 ++++ include/uapi/mtd/mtd-abi.h | 50 +++++++++++++++++++++++++ 7 files changed, 173 insertions(+)
drivers/mtd/devices/docg3.c +10 -0
@@ -885,6 +885,8 @@ static int doc_read_oob(struct mtd_info *mtd, loff_t from,u8 *buf = ops->datbuf;size_t len, ooblen, nbdata, nboob;u8 hwecc[DOC_ECC_BCH_SIZE ], eccconf1; +struct mtd_req_stats *reqstats = ops->stats; +struct mtd_ecc_stats stats;int max_bitflips =0 ;if (buf)
@@ -912,6 +914,7 @@ static int doc_read_oob(struct mtd_info *mtd, loff_t from, ret =0 ; skip = from %DOC_LAYOUT_PAGE_SIZE ;mutex_lock (&docg3->cascade->lock); + stats = mtd->ecc_stats;while (ret >=0 && (len >0 || ooblen >0 )) {calc_block_sector (from - skip, &block0, &block1, &page, &ofs, docg3->reliable);
@@ -983,6 +986,13 @@ static int doc_read_oob(struct mtd_info *mtd, loff_t from, } out: +if (reqstats) { + restats->corrected_bitflips += mtd->ecc_stats.corrected - + stats.corrected; + restats->uncorrectable_errors += mtd->ecc_stats.failed - + stats.failed; + } +mutex_unlock (&docg3->cascade->lock);return ret; err_in_read:
drivers/mtd/mtdchar.c +76 -0
88 lines not on this page · raw message
drivers/mtd/mtdcore.c +9 -0
@@ -988,6 +988,11 @@ int mtd_read_oob(struct mtd_info *mtd, loff_t from, struct mtd_oob_ops *ops)return -EOPNOTSUPP ;ledtrig_mtd_activity (); + +/* Make sure all counters are initialized to zero. */ +if (ops->stats) +memset (ops->stats,0 ,sizeof (*ops->stats)); +/* * In cases where ops->datbuf != NULL, mtd->_read_oob() has semantics * similar to mtd->_read(), returning a non-negative integer
@@ -999,6 +1004,10 @@ int mtd_read_oob(struct mtd_info *mtd, loff_t from, struct mtd_oob_ops *ops)return ret_code;if (mtd->ecc_strength ==0 )return 0 ;/* device lacks ecc */ + +if (ops->stats) + ops->stats->max_bitflips = ret_code; +return ret_code >= mtd->bitflip_threshold ? -EUCLEAN :0 ; }EXPORT_SYMBOL_GPL (mtd_read_oob);
drivers/mtd/nand/nand_base.c +10 -0
@@ -2162,6 +2162,8 @@ static int nand_do_read_oob(struct mtd_info *mtd, loff_t from,static int nand_read_oob (struct mtd_info *mtd,loff_t from,struct mtd_oob_ops *ops) { +struct mtd_req_stats *reqstats = ops->stats; +struct mtd_ecc_stats stats;int ret = -ENOTSUPP ; ops->retlen =0 ;
@@ -2185,11 +2187,19 @@ static int nand_read_oob(struct mtd_info *mtd, loff_t from, goto out; } + stats = mtd->ecc_stats;if (!ops->datbuf) ret =nand_do_read_oob (mtd, from, ops);else ret =nand_do_read_ops (mtd, from, ops); +if (reqstats) { + reqstats->uncorrectable_errors += mtd->ecc_stats.failed - + stats.failed; + reqstats->corrected_bitflips += mtd->ecc_stats.corrected - + stats.corrected; + } + out:nand_release_device (mtd);return ret;
drivers/mtd/onenand/onenand_base.c +11 -0
@@ -1491,6 +1491,8 @@ static int onenand_read_oob(struct mtd_info *mtd, loff_t from, struct mtd_oob_ops *ops) {struct onenand_chip *this = mtd->priv; +struct mtd_req_stats *reqstats = ops->stats; +struct mtd_ecc_stats stats;int ret;switch (ops->mode) {
@@ -1504,12 +1506,21 @@ static int onenand_read_oob(struct mtd_info *mtd, loff_t from, }onenand_get_device (mtd,FL_READING ); + stats = mtd->ecc_stats; +if (ops->datbuf) ret =ONENAND_IS_4KB_PAGE (this) ?onenand_mlc_read_ops_nolock (mtd, from, ops) :onenand_read_ops_nolock (mtd, from, ops);else ret =onenand_read_oob_nolock (mtd, from, ops); + +if (reqstats) { + reqstats->corrected_bitflips += mtd->ecc_stats.corrected - + stats.corrected; + reqstats->uncorrectable_errors += mtd->ecc_stats.failed - + stats.failed; + }onenand_release_device (mtd);return ret;
include/linux/mtd/mtd.h +7 -0
@@ -64,6 +64,12 @@ struct mtd_erase_region_info {unsigned long *lockmap;/* If keeping bitmap of locks */ }; +struct mtd_req_stats { +unsigned int max_bitflips; +unsigned int corrected_bitflips; +unsigned int uncorrectable_errors; +}; +/** * struct mtd_oob_ops - oob operation operands * @mode: operation mode
@@ -92,6 +98,7 @@ struct mtd_oob_ops {uint32_t ooboffs;uint8_t *datbuf;uint8_t *oobbuf; +struct mtd_req_stats *stats; };#define MTD_MAX_OOBFREE_ENTRIES_LARGE 32
include/uapi/mtd/mtd-abi.h +50 -0
62 lines not on this page · raw message
Re: Pass -EUCLEAN to userspace?
Fixed typo in subject, maybe this helps finding this thread in the archives.
Quoted 32 lines · Boris Brezillon
Quoted 29 lines · On Mon, 25 Apr 2016 11:26:16 +0200 Boris Brezillon…
Quoted 28 lines
Quoted 17 lines
Regarding the maximum number of bitflips per chunk, maybe we can make it part of the ioctl request instead of saving the statistics at the MTD level.
How about creating a new ioctl taking a pointer to this struct as a parameter:
struct mtd_extended_read_ops { /* Existing params */ unsigned int mode; size_t len; size_t retlen; size_t ooblen; size_t oobretlen; uint32_t ooboffs; void *datbuf;Quoted 8 lines
void *oobbuf; /* * Param containing the maximum number of bitflips for this * read request. */ unsigned int max_bitflips; };Not sure how this ioctl exactly should look like, but this would solve the problem.
Quoted 6 lines
Quoted 2 lines
Let me design a quick prototype, I'll let you follow up with the patch submission process...
Below is an untested patch adding a new ioctl returning the ECC/read stats. Feel free to debug/enhance this implementation and submit it to the MTD ML.
Thanks Boris, I'll give it a try.
Sascha
Signature · 4 lines
Pengutronix e.K. | | Industrial Linux Solutions | http://www.pengutronix.de/ | Peiner Str. 6-8, 31137 Hildesheim, Germany | Phone: +49-5121-206917-0 | Amtsgericht Hildesheim, HRA 2686 | Fax: +49-5121-206917-5555 |