Skip to content

driver/mtd_spi_nor: fix erase with unaligned addresses#8400

Merged
MichelRottleuthner merged 1 commit intoRIOT-OS:masterfrom
OTAkeys:fix/mtd_erase
Feb 26, 2018
Merged

driver/mtd_spi_nor: fix erase with unaligned addresses#8400
MichelRottleuthner merged 1 commit intoRIOT-OS:masterfrom
OTAkeys:fix/mtd_erase

Conversation

@vincent-d
Copy link
Member

@vincent-d vincent-d commented Jan 22, 2018

Contribution description

Erasing a 32k-block with an unaligned address leaded to erase to 32k-block which contained the address.
This is now fixed.

I'm wondering if we should not refactor a bit the mtd interface to take into account the different erasable sizes on mtd nor flashes, this would be anyway in another PR! -> see #8411

Issues/PRs references

@vincent-d vincent-d added Type: bug The issue reports a bug / The PR fixes a bug (including spelling errors) Area: drivers Area: Device drivers CI: ready for build If set, CI server will compile all applications for all available boards for the labeled PR labels Jan 22, 2018
@vincent-d vincent-d requested a review from jnohlgard January 22, 2018 16:04
Copy link
Member

@smlng smlng left a comment

Choose a reason for hiding this comment

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

minor nits, otherwise looks good

size -= total_size;
}
else if ((dev->flag & SPI_NOR_F_SECT_32K) && (size >= 32768) && ((addr & 0x7FFF) == 0)) {
/* 32 KiO sectors can be erased with sector erase command */
Copy link
Member

Choose a reason for hiding this comment

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

from the command below I'd infer it should be /sector/block/, right?

Copy link
Member Author

Choose a reason for hiding this comment

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

Fixed

mtd_spi_cmd(dev, dev->opcode->wren);

if (size == total_size) {
mtd_spi_cmd(dev, dev->opcode->chip_erase);
Copy link
Member

Choose a reason for hiding this comment

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

you could move this special case above the loop, to avoid some unneeded ops, but I'm okay with leaving this in the loop

Copy link
Member Author

Choose a reason for hiding this comment

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

Yes, but write enable would still be needed first, then I'm not sure there is a significant gain to move out of the loop, at least in terms of code duplication and readability

@vincent-d vincent-d added the Area: fs Area: File systems label Feb 20, 2018
Copy link
Contributor

@MichelRottleuthner MichelRottleuthner left a comment

Choose a reason for hiding this comment

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

Looks good to me. I'd just prefer defines over magic numbers.

mtd_spi_cmd(dev, dev->opcode->chip_erase);
size -= total_size;
}
else if ((dev->flag & SPI_NOR_F_SECT_32K) && (size >= 32768) && ((addr & 0x7FFF) == 0)) {
Copy link
Contributor

Choose a reason for hiding this comment

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

32768 has no ul suffix here like below. Why not use a define for 32786ul, 4096ul (and 0x7FFF)?

Copy link
Member Author

Choose a reason for hiding this comment

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

fixed

size -= total_size;
}
else if ((dev->flag & SPI_NOR_F_SECT_32K) && (size >= 32768) && ((addr & 0x7FFF) == 0)) {
/* 32 KiO blocks can be erased with block erase command */
Copy link
Contributor

Choose a reason for hiding this comment

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

KiB?

Copy link
Member Author

Choose a reason for hiding this comment

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

fixed

Copy link
Contributor

@MichelRottleuthner MichelRottleuthner left a comment

Choose a reason for hiding this comment

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

ACK

@vincent-d
Copy link
Member Author

squashed

@smlng could you ACK?

@MichelRottleuthner MichelRottleuthner merged commit 244eff6 into RIOT-OS:master Feb 26, 2018
@vincent-d vincent-d deleted the fix/mtd_erase branch February 26, 2018 14:48
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

Area: drivers Area: Device drivers Area: fs Area: File systems CI: ready for build If set, CI server will compile all applications for all available boards for the labeled PR Type: bug The issue reports a bug / The PR fixes a bug (including spelling errors)

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants