mtd: mtd_blk: Fix the way to get Nand mtd_info

Change-Id: I6e47180db41242a92ac74083d5984bcb06d92e9c
Signed-off-by: Jon Lin <jon.lin@rock-chips.com>
This commit is contained in:
Jon Lin 2020-10-15 19:54:08 +08:00 committed by Dingqiang Lin
parent 6f8d5ecc09
commit 6524556d8d
1 changed files with 27 additions and 21 deletions

View File

@ -15,6 +15,9 @@
#include <spi.h> #include <spi.h>
#include <dm/device-internal.h> #include <dm/device-internal.h>
#include <linux/mtd/spi-nor.h> #include <linux/mtd/spi-nor.h>
#ifdef CONFIG_NAND
#include <linux/mtd/nand.h>
#endif
#define MTD_PART_NAND_HEAD "mtdparts=" #define MTD_PART_NAND_HEAD "mtdparts="
#define MTD_ROOT_PART_NUM "ubi.mtd=" #define MTD_ROOT_PART_NUM "ubi.mtd="
@ -38,14 +41,13 @@ int mtd_blk_map_table_init(struct blk_desc *desc,
if (!desc) if (!desc)
return -ENODEV; return -ENODEV;
if (desc->devnum == BLK_MTD_NAND) { switch (desc->devnum) {
#if defined(CONFIG_NAND) case BLK_MTD_NAND:
mtd = dev_get_priv(desc->bdev->parent); case BLK_MTD_SPI_NAND:
#endif
} else if (desc->devnum == BLK_MTD_SPI_NAND) {
#if defined(CONFIG_MTD_SPI_NAND)
mtd = desc->bdev->priv; mtd = desc->bdev->priv;
#endif break;
default:
break;
} }
if (!mtd) { if (!mtd) {
@ -54,6 +56,8 @@ int mtd_blk_map_table_init(struct blk_desc *desc,
blk_total = (mtd->size + mtd->erasesize - 1) >> mtd->erasesize_shift; blk_total = (mtd->size + mtd->erasesize - 1) >> mtd->erasesize_shift;
if (!mtd_map_blk_table) { if (!mtd_map_blk_table) {
mtd_map_blk_table = (int *)malloc(blk_total * sizeof(int)); mtd_map_blk_table = (int *)malloc(blk_total * sizeof(int));
if (!mtd_map_blk_table)
return -ENOMEM;
for (i = 0; i < blk_total; i++) for (i = 0; i < blk_total; i++)
mtd_map_blk_table[i] = MTD_BLK_TABLE_BLOCK_UNKNOWN; mtd_map_blk_table[i] = MTD_BLK_TABLE_BLOCK_UNKNOWN;
} }
@ -374,19 +378,9 @@ ulong mtd_dread(struct udevice *udev, lbaint_t start,
pr_debug("mtd dread %s %lx %lx\n", mtd->name, start, blkcnt); pr_debug("mtd dread %s %lx %lx\n", mtd->name, start, blkcnt);
if (desc->devnum == BLK_MTD_NAND) { if (desc->devnum == BLK_MTD_NAND) {
#if defined(CONFIG_NAND) && !defined(CONFIG_SPL_BUILD)
mtd = dev_get_priv(udev->parent);
if (!mtd)
return 0;
ret = nand_read_skip_bad(mtd, off, &rwsize,
NULL, mtd->size,
(u_char *)(dst));
#else
ret = mtd_map_read(mtd, off, &rwsize, ret = mtd_map_read(mtd, off, &rwsize,
NULL, mtd->size, NULL, mtd->size,
(u_char *)(dst)); (u_char *)(dst));
#endif
if (!ret) if (!ret)
return blkcnt; return blkcnt;
else else
@ -507,22 +501,34 @@ ulong mtd_derase(struct udevice *udev, lbaint_t start,
static int mtd_blk_probe(struct udevice *udev) static int mtd_blk_probe(struct udevice *udev)
{ {
struct mtd_info *mtd = dev_get_uclass_priv(udev->parent); struct mtd_info *mtd;
struct blk_desc *desc = dev_get_uclass_platdata(udev); struct blk_desc *desc = dev_get_uclass_platdata(udev);
int ret, i; int ret, i = 0;
mtd = dev_get_uclass_priv(udev->parent);
if (mtd->type == MTD_NANDFLASH && desc->devnum == BLK_MTD_NAND) {
#ifndef CONFIG_SPL_BUILD
mtd = dev_get_priv(udev->parent);
#endif
}
desc->bdev->priv = mtd; desc->bdev->priv = mtd;
sprintf(desc->vendor, "0x%.4x", 0x2207); sprintf(desc->vendor, "0x%.4x", 0x2207);
memcpy(desc->product, mtd->name, strlen(mtd->name)); memcpy(desc->product, mtd->name, strlen(mtd->name));
memcpy(desc->revision, "V1.00", sizeof("V1.00")); memcpy(desc->revision, "V1.00", sizeof("V1.00"));
if (mtd->type == MTD_NANDFLASH) { if (mtd->type == MTD_NANDFLASH) {
#ifdef CONFIG_NAND
if (desc->devnum == BLK_MTD_NAND) if (desc->devnum == BLK_MTD_NAND)
mtd = dev_get_priv(udev->parent); i = NAND_BBT_SCAN_MAXBLOCKS;
else if (desc->devnum == BLK_MTD_SPI_NAND)
i = NANDDEV_BBT_SCAN_MAXBLOCKS;
#endif
/* /*
* Find the first useful block in the end, * Find the first useful block in the end,
* and it is the end lba of the nand storage. * and it is the end lba of the nand storage.
*/ */
for (i = 0; i < (mtd->size / mtd->erasesize); i++) { for (; i < (mtd->size / mtd->erasesize); i++) {
ret = mtd_block_isbad(mtd, ret = mtd_block_isbad(mtd,
mtd->size - mtd->erasesize * (i + 1)); mtd->size - mtd->erasesize * (i + 1));
if (!ret) { if (!ret) {