cmd: nand/sf: update legacy mtd code
Base the legacy code to found MTD partition on MTD stack.
This patch allows to found a MTD partition when they are
are not defined in mtdparts variable but in device tree
after commit dc339bf784
("mtd: add support for parsing
partitions defined in OF").
This patch also removes dependency with CONFIG_CMD_MTDPARTS
as the selection of MTD partitions is not linked to the
command to modified the mtdparts variables.
Signed-off-by: Patrick Delaunay <patrick.delaunay@foss.st.com>
Change-Id: I797845e1a7cb936f822bc1b2e554babf70cf1ea5
Reviewed-on: https://gerrit.st.com/c/mpu/oe/st/u-boot/+/289325
ACI: CITOOLS <MDG-smet-aci-reviews@list.st.com>
ACI: CIBUILD <MDG-smet-aci-builds@list.st.com>
Reviewed-by: Patrice CHOTARD <patrice.chotard@foss.st.com>
Domain-Review: Patrice CHOTARD <patrice.chotard@foss.st.com>
This commit is contained in:
parent
d5a1622ae1
commit
bcae9c3d27
1 changed files with 46 additions and 24 deletions
|
@ -1,44 +1,66 @@
|
|||
// SPDX-License-Identifier: GPL-2.0+
|
||||
|
||||
#include <common.h>
|
||||
#include <jffs2/jffs2.h>
|
||||
#include <linux/mtd/mtd.h>
|
||||
#include <linux/mtd/partitions.h>
|
||||
#include <linux/string.h>
|
||||
#include <mtd.h>
|
||||
|
||||
static int get_part(const char *partname, int *idx, loff_t *off, loff_t *size,
|
||||
loff_t *maxsize, int devtype)
|
||||
/* mapping between legacy parameter and MTD device type */
|
||||
bool check_devtype(int devtype, u_char mtdtype)
|
||||
{
|
||||
#ifdef CONFIG_CMD_MTDPARTS
|
||||
struct mtd_device *dev;
|
||||
struct part_info *part;
|
||||
u8 pnum;
|
||||
int ret;
|
||||
if (devtype == MTD_DEV_TYPE_NOR && mtdtype == MTD_NORFLASH)
|
||||
return true;
|
||||
|
||||
ret = mtdparts_init();
|
||||
if (ret)
|
||||
return ret;
|
||||
if ((devtype == MTD_DEV_TYPE_NAND || devtype == MTD_DEV_TYPE_ONENAND) &&
|
||||
(mtdtype == MTD_NANDFLASH || mtdtype == MTD_NANDFLASH))
|
||||
return true;
|
||||
|
||||
ret = find_dev_and_part(partname, &dev, &pnum, &part);
|
||||
if (ret)
|
||||
return ret;
|
||||
return false;
|
||||
}
|
||||
|
||||
if (dev->id->type != devtype) {
|
||||
printf("not same typ %d != %d\n", dev->id->type, devtype);
|
||||
|
||||
static int get_part(const char *partname, int *idx, loff_t *off, loff_t *size,
|
||||
loff_t *maxsize, int devtype)
|
||||
{
|
||||
struct mtd_info *mtd;
|
||||
struct mtd_info *partition;
|
||||
bool part_found = false;
|
||||
int part_num;
|
||||
|
||||
if (!IS_ENABLED(CONFIG_MTD)) {
|
||||
puts("mtd support missing.\n");
|
||||
return -1;
|
||||
}
|
||||
/* register partitions with MTDIDS/MTDPARTS or OF fallback */
|
||||
mtd_probe_devices();
|
||||
|
||||
*off = part->offset;
|
||||
*size = part->size;
|
||||
*maxsize = part->size;
|
||||
*idx = dev->id->num;
|
||||
mtd_for_each_device(mtd) {
|
||||
printf("%s:%d(%d, %s)\n", __func__, __LINE__, mtd->type, mtd->name);
|
||||
if (mtd_is_partition(mtd) &&
|
||||
check_devtype(devtype, mtd->type) &&
|
||||
(!strcmp(partname, mtd->name))) {
|
||||
part_found = true;
|
||||
break;
|
||||
}
|
||||
}
|
||||
if (!part_found)
|
||||
return -1;
|
||||
|
||||
*off = mtd->offset;
|
||||
*size = mtd->size;
|
||||
*maxsize = mtd->size;
|
||||
|
||||
/* loop on partition list as index is not accessbile in MTD */
|
||||
part_num = 0;
|
||||
list_for_each_entry(partition, &mtd->parent->partitions, node) {
|
||||
part_num++;
|
||||
if (partition == mtd)
|
||||
break;
|
||||
}
|
||||
|
||||
*idx = part_num;
|
||||
return 0;
|
||||
#else
|
||||
puts("mtdparts support missing.\n");
|
||||
return -1;
|
||||
#endif
|
||||
}
|
||||
|
||||
int mtd_arg_off(const char *arg, int *idx, loff_t *off, loff_t *size,
|
||||
|
|
Loading…
Add table
Reference in a new issue