"Das U-Boot" Source Tree
0
fork

Configure Feed

Select the types of activity you want to include in your feed.

cmd: nand/sf: isolate legacy code

The 'sf' command is not supposed to rely on the MTD stack, but both
'sf' and 'nand' commands use helpers located in mtd_uboot.c. Despite
their location, these functions do not depend at all on the MTD
stack.

This file (drivers/mtd/mtd_uboot.c) is only compiled if CONFIG_MTD is
selected, which is inconsistent with the current situation. Solve this
by moving these three functions (which are only used by the above two
commands) out of mtd_uboot.c and put them in a C file only compiled
with cmd/sf.c and cmd/nand.c.

Signed-off-by: Miquel Raynal <miquel.raynal@bootlin.com>
[trini: Don't export get_part function now]
Signed-off-by: Tom Rini <trini@konsulko.com>

authored by

Miquel Raynal and committed by
Tom Rini
eb446ef6 587f4457

+121 -101
+2
arch/arm/mach-imx/cmd_nandbcb.c
··· 24 24 #include <linux/mtd/mtd.h> 25 25 #include <nand.h> 26 26 27 + #include "../../../cmd/legacy-mtd-utils.h" 28 + 27 29 #define BF_VAL(v, bf) (((v) & bf##_MASK) >> bf##_OFFSET) 28 30 #define GETBIT(v, n) (((v) >> (n)) & 0x1) 29 31
+3
cmd/Makefile
··· 97 97 obj-$(CONFIG_MP) += mp.o 98 98 obj-$(CONFIG_CMD_MTD) += mtd.o 99 99 obj-$(CONFIG_CMD_MTDPARTS) += mtdparts.o 100 + ifneq ($(CONFIG_CMD_NAND)$(CONFIG_CMD_SF),) 101 + obj-y += legacy-mtd-utils.o 102 + endif 100 103 obj-$(CONFIG_CMD_NAND) += nand.o 101 104 obj-$(CONFIG_CMD_NET) += net.o 102 105 obj-$(CONFIG_CMD_NVEDIT_EFI) += nvedit_efi.o
+99
cmd/legacy-mtd-utils.c
··· 1 + // SPDX-License-Identifier: GPL-2.0+ 2 + 3 + #include <common.h> 4 + #include <jffs2/jffs2.h> 5 + #include <linux/mtd/mtd.h> 6 + #include <linux/mtd/partitions.h> 7 + #include <linux/string.h> 8 + #include <mtd.h> 9 + 10 + static int get_part(const char *partname, int *idx, loff_t *off, loff_t *size, 11 + loff_t *maxsize, int devtype) 12 + { 13 + #ifdef CONFIG_CMD_MTDPARTS 14 + struct mtd_device *dev; 15 + struct part_info *part; 16 + u8 pnum; 17 + int ret; 18 + 19 + ret = mtdparts_init(); 20 + if (ret) 21 + return ret; 22 + 23 + ret = find_dev_and_part(partname, &dev, &pnum, &part); 24 + if (ret) 25 + return ret; 26 + 27 + if (dev->id->type != devtype) { 28 + printf("not same typ %d != %d\n", dev->id->type, devtype); 29 + return -1; 30 + } 31 + 32 + *off = part->offset; 33 + *size = part->size; 34 + *maxsize = part->size; 35 + *idx = dev->id->num; 36 + 37 + return 0; 38 + #else 39 + puts("mtdparts support missing.\n"); 40 + return -1; 41 + #endif 42 + } 43 + 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) 46 + { 47 + if (!str2off(arg, off)) 48 + return get_part(arg, idx, off, size, maxsize, devtype); 49 + 50 + if (*off >= chipsize) { 51 + puts("Offset exceeds device limit\n"); 52 + return -1; 53 + } 54 + 55 + *maxsize = chipsize - *off; 56 + *size = *maxsize; 57 + return 0; 58 + } 59 + 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, 62 + uint64_t chipsize) 63 + { 64 + int ret; 65 + 66 + if (argc == 0) { 67 + *off = 0; 68 + *size = chipsize; 69 + *maxsize = *size; 70 + goto print; 71 + } 72 + 73 + ret = mtd_arg_off(argv[0], idx, off, size, maxsize, devtype, 74 + chipsize); 75 + if (ret) 76 + return ret; 77 + 78 + if (argc == 1) 79 + goto print; 80 + 81 + if (!str2off(argv[1], size)) { 82 + printf("'%s' is not a number\n", argv[1]); 83 + return -1; 84 + } 85 + 86 + if (*size > *maxsize) { 87 + puts("Size exceeds partition or device limit\n"); 88 + return -1; 89 + } 90 + 91 + print: 92 + printf("device %d ", *idx); 93 + if (*size == chipsize) 94 + puts("whole chip\n"); 95 + else 96 + printf("offset 0x%llx, size 0x%llx\n", 97 + (unsigned long long)*off, (unsigned long long)*size); 98 + return 0; 99 + }
+12
cmd/legacy-mtd-utils.h
··· 1 + /* SPDX-License-Identifier: GPL-2.0+ */ 2 + 3 + #ifndef __LEGACY_MTD_UTILS_H 4 + #define __LEGACY_MTD_UTILS_H 5 + 6 + int mtd_arg_off(const char *arg, int *idx, loff_t *off, loff_t *size, 7 + loff_t *maxsize, int devtype, uint64_t chipsize); 8 + int mtd_arg_off_size(int argc, char *const argv[], int *idx, loff_t *off, 9 + loff_t *size, loff_t *maxsize, int devtype, 10 + uint64_t chipsize); 11 + 12 + #endif /* LEGACY_MTD_UTILS_H */
+2
cmd/nand.c
··· 30 30 #include <jffs2/jffs2.h> 31 31 #include <nand.h> 32 32 33 + #include "legacy-mtd-utils.h" 34 + 33 35 #if defined(CONFIG_CMD_MTDPARTS) 34 36 35 37 /* partition handling routines */
+2
cmd/sf.c
··· 18 18 #include <asm/io.h> 19 19 #include <dm/device-internal.h> 20 20 21 + #include "legacy-mtd-utils.h" 22 + 21 23 static struct spi_flash *flash; 22 24 23 25 /*
+1 -1
drivers/mtd/Makefile
··· 3 3 # (C) Copyright 2000-2007 4 4 # Wolfgang Denk, DENX Software Engineering, wd@denx.de. 5 5 6 - ifneq (,$(findstring y,$(CONFIG_MTD)$(CONFIG_CMD_NAND)$(CONFIG_CMD_ONENAND)$(CONFIG_CMD_SF)$(CONFIG_CMD_MTD))) 6 + ifneq (,$(findstring y,$(CONFIG_MTD)$(CONFIG_CMD_ONENAND)$(CONFIG_CMD_MTD))) 7 7 obj-y += mtdcore.o mtd_uboot.o 8 8 endif 9 9 obj-$(CONFIG_DM_MTD) += mtd-uclass.o
-94
drivers/mtd/mtd_uboot.c
··· 7 7 #include <env.h> 8 8 #include <dm/device.h> 9 9 #include <dm/uclass-internal.h> 10 - #include <jffs2/jffs2.h> /* LEGACY */ 11 10 #include <linux/mtd/mtd.h> 12 11 #include <linux/mtd/partitions.h> 13 12 #include <mtd.h> ··· 356 355 return 0; 357 356 } 358 357 #endif /* defined(CONFIG_MTD_PARTITIONS) */ 359 - 360 - /* Legacy */ 361 - 362 - static int get_part(const char *partname, int *idx, loff_t *off, loff_t *size, 363 - loff_t *maxsize, int devtype) 364 - { 365 - #ifdef CONFIG_CMD_MTDPARTS 366 - struct mtd_device *dev; 367 - struct part_info *part; 368 - u8 pnum; 369 - int ret; 370 - 371 - ret = mtdparts_init(); 372 - if (ret) 373 - return ret; 374 - 375 - ret = find_dev_and_part(partname, &dev, &pnum, &part); 376 - if (ret) 377 - return ret; 378 - 379 - if (dev->id->type != devtype) { 380 - printf("not same typ %d != %d\n", dev->id->type, devtype); 381 - return -1; 382 - } 383 - 384 - *off = part->offset; 385 - *size = part->size; 386 - *maxsize = part->size; 387 - *idx = dev->id->num; 388 - 389 - return 0; 390 - #else 391 - puts("mtdparts support missing.\n"); 392 - return -1; 393 - #endif 394 - } 395 - 396 - int mtd_arg_off(const char *arg, int *idx, loff_t *off, loff_t *size, 397 - loff_t *maxsize, int devtype, uint64_t chipsize) 398 - { 399 - if (!str2off(arg, off)) 400 - return get_part(arg, idx, off, size, maxsize, devtype); 401 - 402 - if (*off >= chipsize) { 403 - puts("Offset exceeds device limit\n"); 404 - return -1; 405 - } 406 - 407 - *maxsize = chipsize - *off; 408 - *size = *maxsize; 409 - return 0; 410 - } 411 - 412 - int mtd_arg_off_size(int argc, char *const argv[], int *idx, loff_t *off, 413 - loff_t *size, loff_t *maxsize, int devtype, 414 - uint64_t chipsize) 415 - { 416 - int ret; 417 - 418 - if (argc == 0) { 419 - *off = 0; 420 - *size = chipsize; 421 - *maxsize = *size; 422 - goto print; 423 - } 424 - 425 - ret = mtd_arg_off(argv[0], idx, off, size, maxsize, devtype, 426 - chipsize); 427 - if (ret) 428 - return ret; 429 - 430 - if (argc == 1) 431 - goto print; 432 - 433 - if (!str2off(argv[1], size)) { 434 - printf("'%s' is not a number\n", argv[1]); 435 - return -1; 436 - } 437 - 438 - if (*size > *maxsize) { 439 - puts("Size exceeds partition or device limit\n"); 440 - return -1; 441 - } 442 - 443 - print: 444 - printf("device %d ", *idx); 445 - if (*size == chipsize) 446 - puts("whole chip\n"); 447 - else 448 - printf("offset 0x%llx, size 0x%llx\n", 449 - (unsigned long long)*off, (unsigned long long)*size); 450 - return 0; 451 - }
-6
include/linux/mtd/mtd.h
··· 588 588 (mtd) != NULL; \ 589 589 (mtd) = __mtd_next_device(mtd->index + 1)) 590 590 591 - int mtd_arg_off(const char *arg, int *idx, loff_t *off, loff_t *size, 592 - loff_t *maxsize, int devtype, uint64_t chipsize); 593 - int mtd_arg_off_size(int argc, char *const argv[], int *idx, loff_t *off, 594 - loff_t *size, loff_t *maxsize, int devtype, 595 - uint64_t chipsize); 596 - 597 591 /* drivers/mtd/mtdcore.c */ 598 592 void mtd_get_len_incl_bad(struct mtd_info *mtd, uint64_t offset, 599 593 const uint64_t length, uint64_t *len_incl_bad,