mtd: add desc->lba to mtd block device

The desc->lba is based on mtd->size: desc->lba = mtd->size >> 9;

If the mtd storage is spi nand or nand flash, reserve 4 blocks
for BBT(Bad Block Table). Then desc->lba is
desc->lba = (mtd->size >> 9) - (mtd->erasesize >> 9) * 4;

Change-Id: I70702623895fe05cec614c4c3ca5f3f6c41d26ca
Signed-off-by: Jason Zhu <jason.zhu@rock-chips.com>
This commit is contained in:
Jason Zhu 2019-06-18 17:24:58 +08:00 committed by Jianhong Chen
parent 346e1f7dd1
commit f1892190de
1 changed files with 7 additions and 0 deletions

View File

@ -73,10 +73,17 @@ ulong mtd_derase(struct udevice *udev, lbaint_t start,
static int mtd_blk_probe(struct udevice *udev)
{
struct blk_desc *desc = dev_get_uclass_platdata(udev);
struct mtd_info *mtd = dev_get_priv(udev->parent);
sprintf(desc->vendor, "0x%.4x", 0x2207);
memcpy(desc->product, "MTD", sizeof("MTD"));
memcpy(desc->revision, "V1.00", sizeof("V1.00"));
if (mtd->type == MTD_NANDFLASH) {
/* Reserve 4 blocks for BBT(Bad Block Table) */
desc->lba = (mtd->size >> 9) - (mtd->erasesize >> 9) * 4;
} else {
desc->lba = mtd->size >> 9;
}
return 0;
}