Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

atmel_nand.c: Empty page error correction fixed. #19

Closed
Closed
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
39 changes: 22 additions & 17 deletions drivers/mtd/nand/raw/atmel_nand.c
Original file line number Diff line number Diff line change
Expand Up @@ -484,21 +484,9 @@ static int pmecc_correction(struct mtd_info *mtd, u32 pmecc_stat, uint8_t *buf,
{
struct nand_chip *nand_chip = mtd_to_nand(mtd);
struct atmel_nand_host *host = nand_get_controller_data(nand_chip);
int i, err_nbr, eccbytes;
uint8_t *buf_pos;

/* SAMA5D4 PMECC IP can correct errors for all 0xff page */
if (host->pmecc_version >= PMECC_VERSION_SAMA5D4)
goto normal_check;

eccbytes = nand_chip->ecc.bytes;
for (i = 0; i < eccbytes; i++)
if (ecc[i] != 0xff)
goto normal_check;
/* Erased page, return OK */
return 0;
int i, err_nbr;
uint8_t *buf_pos, *ecc_pos;

normal_check:
for (i = 0; i < host->pmecc_sector_number; i++) {
err_nbr = 0;
if (pmecc_stat & 0x1) {
Expand All @@ -510,9 +498,26 @@ static int pmecc_correction(struct mtd_info *mtd, u32 pmecc_stat, uint8_t *buf,

err_nbr = pmecc_err_location(mtd);
if (err_nbr == -1) {
dev_err(host->dev, "PMECC: Too many errors\n");
mtd->ecc_stats.failed++;
return -EBADMSG;
/* SAMA5D4 PMECC IP can correct errors for all 0xff page */
if (host->pmecc_version < PMECC_VERSION_SAMA5D4) {
ecc_pos = ecc + i * host->pmecc_bytes_per_sector;

err_nbr = nand_check_erased_ecc_chunk(
buf_pos, host->pmecc_sector_size,
ecc_pos, host->pmecc_bytes_per_sector,
NULL, 0, (host->pmecc_corr_cap * 3) / 4);
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

why the last parameter of nand_check_erased_ecc_chunk() has value (host->pmecc_corr_cap * 3) / 4 ? Shouldn't this be just host->pmecc_corr_cap?

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Hi @ambarus,

You are right! Just host->pmecc_corr_cap is correct. To be honest I don't remember, where this calculation came from.

Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Hi, @ksdd!

No worries, I've already corrected it. Just FYI, I sent the patch on your behalf to u-boot mainline. Once it gets applied by Eugen, and also backported to our u-boot-at91, we'll close this PR.

Cheers,
ta


if (err_nbr < 0) {
dev_err(host->dev, "PMECC: Too many errors\n");
mtd->ecc_stats.failed++;
return -EBADMSG;
}
mtd->ecc_stats.corrected += err_nbr;
} else {
dev_err(host->dev, "PMECC: Too many errors\n");
mtd->ecc_stats.failed++;
return -EBADMSG;
}
} else {
pmecc_correct_data(mtd, buf_pos, ecc, i,
host->pmecc_bytes_per_sector, err_nbr);
Expand Down