3 * Heiko Schocher, DENX Software Engineering, hs@denx.de.
5 * SPDX-License-Identifier: GPL-2.0+
8 #include <linux/mtd/mtd.h>
9 #include <jffs2/jffs2.h>
11 static int get_part(const char *partname, int *idx, loff_t *off, loff_t *size,
12 loff_t *maxsize, int devtype)
14 #ifdef CONFIG_CMD_MTDPARTS
15 struct mtd_device *dev;
16 struct part_info *part;
20 ret = mtdparts_init();
24 ret = find_dev_and_part(partname, &dev, &pnum, &part);
28 if (dev->id->type != devtype) {
29 printf("not same typ %d != %d\n", dev->id->type, devtype);
35 *maxsize = part->size;
40 puts("mtdparts support missing.\n");
45 int mtd_arg_off(const char *arg, int *idx, loff_t *off, loff_t *size,
46 loff_t *maxsize, int devtype, uint64_t chipsize)
48 if (!str2off(arg, off))
49 return get_part(arg, idx, off, size, maxsize, devtype);
51 if (*off >= chipsize) {
52 puts("Offset exceeds device limit\n");
56 *maxsize = chipsize - *off;
61 int mtd_arg_off_size(int argc, char *const argv[], int *idx, loff_t *off,
62 loff_t *size, loff_t *maxsize, int devtype,
74 ret = mtd_arg_off(argv[0], idx, off, size, maxsize, devtype,
82 if (!str2off(argv[1], size)) {
83 printf("'%s' is not a number\n", argv[1]);
87 if (*size > *maxsize) {
88 puts("Size exceeds partition or device limit\n");
93 printf("device %d ", *idx);
94 if (*size == chipsize)
97 printf("offset 0x%llx, size 0x%llx\n",
98 (unsigned long long)*off, (unsigned long long)*size);