1 // SPDX-License-Identifier: GPL-2.0+
4 * Heiko Schocher, DENX Software Engineering, hs@denx.de.
7 #include <linux/mtd/mtd.h>
8 #include <jffs2/jffs2.h>
10 static int get_part(const char *partname, int *idx, loff_t *off, loff_t *size,
11 loff_t *maxsize, int devtype)
13 #ifdef CONFIG_CMD_MTDPARTS
14 struct mtd_device *dev;
15 struct part_info *part;
19 ret = mtdparts_init();
23 ret = find_dev_and_part(partname, &dev, &pnum, &part);
27 if (dev->id->type != devtype) {
28 printf("not same typ %d != %d\n", dev->id->type, devtype);
34 *maxsize = part->size;
39 puts("mtdparts support missing.\n");
44 int mtd_arg_off(const char *arg, int *idx, loff_t *off, loff_t *size,
45 loff_t *maxsize, int devtype, uint64_t chipsize)
47 if (!str2off(arg, off))
48 return get_part(arg, idx, off, size, maxsize, devtype);
50 if (*off >= chipsize) {
51 puts("Offset exceeds device limit\n");
55 *maxsize = chipsize - *off;
60 int mtd_arg_off_size(int argc, char *const argv[], int *idx, loff_t *off,
61 loff_t *size, loff_t *maxsize, int devtype,
73 ret = mtd_arg_off(argv[0], idx, off, size, maxsize, devtype,
81 if (!str2off(argv[1], size)) {
82 printf("'%s' is not a number\n", argv[1]);
86 if (*size > *maxsize) {
87 puts("Size exceeds partition or device limit\n");
92 printf("device %d ", *idx);
93 if (*size == chipsize)
96 printf("offset 0x%llx, size 0x%llx\n",
97 (unsigned long long)*off, (unsigned long long)*size);