1 // SPDX-License-Identifier: GPL-2.0+
3 #include <jffs2/jffs2.h>
4 #include <linux/mtd/mtd.h>
5 #include <linux/mtd/partitions.h>
6 #include <linux/string.h>
9 static int get_part(const char *partname, int *idx, loff_t *off, loff_t *size,
10 loff_t *maxsize, int devtype)
12 #ifdef CONFIG_CMD_MTDPARTS
13 struct mtd_device *dev;
14 struct part_info *part;
18 ret = mtdparts_init();
22 ret = find_dev_and_part(partname, &dev, &pnum, &part);
26 if (dev->id->type != devtype) {
27 printf("not same typ %d != %d\n", dev->id->type, devtype);
33 *maxsize = part->size;
38 puts("mtdparts support missing.\n");
43 int mtd_arg_off(const char *arg, int *idx, loff_t *off, loff_t *size,
44 loff_t *maxsize, int devtype, uint64_t chipsize)
46 if (!str2off(arg, off))
47 return get_part(arg, idx, off, size, maxsize, devtype);
49 if (*off >= chipsize) {
50 puts("Offset exceeds device limit\n");
54 *maxsize = chipsize - *off;
59 int mtd_arg_off_size(int argc, char *const argv[], int *idx, loff_t *off,
60 loff_t *size, loff_t *maxsize, int devtype,
72 ret = mtd_arg_off(argv[0], idx, off, size, maxsize, devtype,
80 if (!str2off(argv[1], size)) {
81 printf("'%s' is not a number\n", argv[1]);
85 if (*size > *maxsize) {
86 puts("Size exceeds partition or device limit\n");
91 debug("ERROR: Invalid size 0\n");
96 printf("device %d ", *idx);
97 if (*size == chipsize)
100 printf("offset 0x%llx, size 0x%llx\n",
101 (unsigned long long)*off, (unsigned long long)*size);