[U-Boot] [PATCH v5 2/5] mtd: add an mtd method for get_len_incl_bad()

Ben Gardiner
2010-08-31T13:50:59Z

On Mon, Aug 30, 2010 at 4:57 PM, Scott Wood <scottwood@freescale.com> wrote:
> On Mon, 30 Aug 2010 13:38:57 -0400
> Ben Gardiner <bengardiner@nanometrics.ca> wrote:
>> +void mtd_get_len_incl_bad(struct mtd_info *mtd, uint64_t offset,
>> + ? ? ? ? ? ? ? ? ? ? ? const uint64_t length, uint64_t *len_incl_bad,
>> + ? ? ? ? ? ? ? ? ? ? ? int *truncated)
>> +{
>> + ? ? *truncated = 0;
>> + ? ? *len_incl_bad = 0;
>> +
>> + ? ? if (!mtd->block_isbad) {
>> + ? ? ? ? ? ? *len_incl_bad = length;
>> + ? ? ? ? ? ? return;
>> + ? ? }
>> +
>> + ? ? uint64_t len_excl_bad = 0;
>> + ? ? uint64_t block_len;
>> +
>> + ? ? while (len_excl_bad < length) {
>> + ? ? ? ? ? ? block_len = mtd->erasesize - (offset & (mtd->erasesize - 1));
>> +
>> + ? ? ? ? ? ? if (!mtd->block_isbad(mtd, offset & ~(mtd->erasesize - 1)))
>> + ? ? ? ? ? ? ? ? ? ? len_excl_bad += block_len;
>> +
>> + ? ? ? ? ? ? *len_incl_bad += block_len;
>> + ? ? ? ? ? ? offset ? ? ? += block_len;
>> +
>> + ? ? ? ? ? ? if (offset >= mtd->size) {
>> + ? ? ? ? ? ? ? ? ? ? *truncated = 1;
>> + ? ? ? ? ? ? ? ? ? ? break;
>> + ? ? ? ? ? ? }
>> + ? ? }
>
> If this function is called with offset == mtd->size, you should return
> length zero and truncated, without calling block_isbad().

Good point. Will do.

Best Regards,
Ben Gardiner

---
Nanometrics Inc.