Skip to contentSkip to conversation

Support SPI NAND in fastboot protocol

PATCH In review Alexey Romanov 3 participants 17 messages Jan 9, 2024 – Jan 15, 2024

Subsystems (2)
lore
Share & tools
lore
#0 lore raw

v2 cover Support SPI NAND in fastboot protocol

Currently, fastboot in U-Boot doens't support SPI NAND devices. This patchset adds support for SPI NAND in fastboot nand subsystem.

Changes V1 -> V2:

- Rebase patchset over u-boot/next.
- Move nand_unregister(), nand_reinit() and nang_page_size() functions to NAND core folder too.
- Move changes about CMD_RET_FAILURE/SUCCESS into separate patches.

Alexey Romanov (14):
nand: move NAND initialization API to nand/core.c
nand: don't overwrite mtd name in nand_register()
nand: move nand_util.c to NAND core folder
nand: move nand_erase_opts() to core NAND folder
spi: add board_nand_init() function
spi: use nand_register() instead of add_mtd_device()
mtdparts: use negative error codes
mtdparts: use CMD_RET_FAILURE define
jffs2: use negative error codes
jffs2: use CMD_RET_FAILURE/SUCCESS defines
cmd: allow to enable CMD_NAND for SPI NAND devices
fastboot: check device type for SPI NAND too
fastboot: enable FASTBOOT_FLASH option for SPI NAND devices
fastboot: fb_nand: add missing newlines in pr_err() macro

 cmd/Kconfig                      |   2 +-
 cmd/jffs2.c                      |  45 +-
 cmd/mtdparts.c                   | 154 +++----
 drivers/fastboot/Kconfig         |   4 +-
 drivers/fastboot/fb_nand.c       |  12 +-
 drivers/mtd/Kconfig              |   2 +-
 drivers/mtd/nand/Kconfig         |  10 +
 drivers/mtd/nand/Makefile        |   2 +-
 drivers/mtd/nand/core.c          | 193 +++++++++
 drivers/mtd/nand/raw/Kconfig     |  10 -
 drivers/mtd/nand/raw/nand.c      | 182 --------
 drivers/mtd/nand/raw/nand_util.c | 664 -----------------------------
 drivers/mtd/nand/spi/Kconfig     |   1 +
 drivers/mtd/nand/spi/core.c      |  17 +-
 drivers/mtd/nand/util.c          | 709 +++++++++++++++++++++++++++++++
 include/nand.h                   |   2 +
 16 files changed, 1042 insertions(+), 967 deletions(-)
 create mode 100644 drivers/mtd/nand/util.c
Signature · 1 line
2.30.1
#1 lore raw

PATCH v2 1/14 nand: move NAND initialization API to nand/core.c

nand_register() and nand_init() is generic API for both RAW and SPI NAND's. We have to move this functions from drivers/mtd/nand/raw/nand.c to drivers/mtd/nand/core.c.

Functions designed to work with RAW NAND should remain in drivers/mtd/nand/raw/nand.c.

---
 drivers/mtd/Kconfig          |   2 +-
 drivers/mtd/nand/Kconfig     |  10 ++
 drivers/mtd/nand/core.c      | 189 +++++++++++++++++++++++++++++++++++
 drivers/mtd/nand/raw/Kconfig |  10 --
 drivers/mtd/nand/raw/nand.c  | 182 ---------------------------------
 include/nand.h               |   2 +
 6 files changed, 202 insertions(+), 193 deletions(-)
drivers/mtd/Kconfig +1 -1
index c56840c849..1902351719 100644
@@ -260,7 +260,7 @@ config SYS_NAND_MAX_ECCPOS
 
 config SYS_NAND_MAX_CHIPS
 	int "NAND max chips"
-	depends on MTD_RAW_NAND || CMD_ONENAND || TARGET_S5PC210_UNIVERSAL || \
+	depends on MTD_RAW_NAND || MTD_SPI_NAND || CMD_ONENAND || TARGET_S5PC210_UNIVERSAL || \
 		SPL_OMAP3_ID_NAND
 	default 1
 	help
drivers/mtd/nand/Kconfig +10 -0
index 78ae04bdcb..9a1d4ac0dc 100644
@@ -1,6 +1,16 @@
 config MTD_NAND_CORE
 	tristate
 
+config SYS_MAX_NAND_DEVICE
+	int "Maximum number of NAND devices to support"
+	default 1
+
+config SYS_NAND_SELF_INIT
+	bool
+	help
+	  This option, if enabled, provides more flexible and linux-like
+	  NAND initialization process.
+
 source "drivers/mtd/nand/raw/Kconfig"
 
 source "drivers/mtd/nand/spi/Kconfig"
drivers/mtd/nand/core.c +189 -0

207 lines not on this page · raw message

drivers/mtd/nand/raw/Kconfig +0 -10
index bb9994b862..c3003962f3 100644
@@ -3,12 +3,6 @@ menuconfig MTD_RAW_NAND
 	bool "Raw NAND Device Support"
 if MTD_RAW_NAND
 
-config SYS_NAND_SELF_INIT
-	bool
-	help
-	  This option, if enabled, provides more flexible and linux-like
-	  NAND initialization process.
-
 config SPL_SYS_NAND_SELF_INIT
 	bool
 	depends on !SPL_NAND_SIMPLE
@@ -29,10 +23,6 @@ config TPL_NAND_INIT
 config SPL_NAND_INIT
 	bool
 
-config SYS_MAX_NAND_DEVICE
-	int "Maximum number of NAND devices to support"
-	default 1
-
 config SYS_NAND_DRIVER_ECC_LAYOUT
 	bool "Omit standard ECC layouts to save space"
 	help
drivers/mtd/nand/raw/nand.c +0 -182

195 lines not on this page · raw message

include/nand.h +2 -0
index 220ffa202e..766cd04aea 100644
@@ -28,6 +28,8 @@ void nand_unregister(struct mtd_info *mtd);
 struct nand_chip;
 
 extern int board_nand_init(struct nand_chip *nand);
+
+void nand_init_chip(int index);
 #endif
 
 extern int nand_curr_device;
Signature · 1 line
2.30.1
#2 lore raw

PATCH v2 2/14 nand: don't overwrite mtd name in nand_register()

In reply to Alexey Romanov

We use this function in SPI NAND subsystem, which already filled mtd->name field with "spi-nand0" string.

---
 drivers/mtd/nand/core.c | 10 +++++++---
 1 file changed, 7 insertions(+), 3 deletions(-)
drivers/mtd/nand/core.c +7 -3
index f792ef844a..f67421f0cb 100644
@@ -23,7 +23,7 @@
 int nand_curr_device = -1;
 
 static struct mtd_info *nand_info[CONFIG_SYS_MAX_NAND_DEVICE];
-static char dev_name[CONFIG_SYS_MAX_NAND_DEVICE][8];
+static char dev_name[CONFIG_SYS_MAX_NAND_DEVICE][16];
 static unsigned long total_nand_size; /* in kiB */
 
 /**
@@ -289,8 +289,12 @@ int nand_register(int devnum, struct mtd_info *mtd)
 
 	nand_info[devnum] = mtd;
 
-	sprintf(dev_name[devnum], "nand%d", devnum);
-	mtd->name = dev_name[devnum];
+	if (!strlen(mtd->name)) {
+		snprintf(dev_name[devnum], ARRAY_SIZE(dev_name[devnum]), "nand%d", devnum);
+		mtd->name = dev_name[devnum];
+	} else {
+		strlcpy(dev_name[devnum], mtd->name, ARRAY_SIZE(dev_name[devnum]));
+	}
 
 #ifdef CONFIG_MTD
 	/*
Signature · 1 line
2.30.1
#3 lore raw

PATCH v2 3/14 nand: move nand_util.c to NAND core folder

In reply to Alexey Romanov

This is right place for this API. Now, fastboot code uses this
API: these functions should be available regardless of the selected NAND type (RAW / SPI).

---
 drivers/mtd/nand/Makefile        |   2 +-
 drivers/mtd/nand/raw/nand_util.c | 511 -----------------------------
 drivers/mtd/nand/util.c          | 543 +++++++++++++++++++++++++++++++
 3 files changed, 544 insertions(+), 512 deletions(-)
 create mode 100644 drivers/mtd/nand/util.c
drivers/mtd/nand/Makefile +1 -1
index 96e186600a..301b1bceff 100644
@@ -1,7 +1,7 @@
 # SPDX-License-Identifier: GPL-2.0+
 
 ifeq ($(CONFIG_SPL_BUILD)$(CONFIG_TPL_BUILD),)
-nandcore-objs := core.o bbt.o
+nandcore-objs := core.o bbt.o util.o
 obj-$(CONFIG_MTD_NAND_CORE) += nandcore.o
 obj-$(CONFIG_MTD_RAW_NAND) += raw/
 obj-$(CONFIG_MTD_SPI_NAND) += spi/
drivers/mtd/nand/raw/nand_util.c +0 -511

520 lines not on this page · raw message

drivers/mtd/nand/util.c new file +543 -0

543 lines not on this page · raw message

Signature · 1 line
2.30.1
#4 lore raw

PATCH v2 4/14 nand: move nand_erase_opts() to core NAND folder

In reply to Alexey Romanov

Currently nand_erase_opts() placed in the nand/raw/ folder, because it uses the RAW NAND specific API (struct nand_chip). This patch move it to core NAND folder and make function generic, for both RAW/SPI NAND's usage.

Also, nand_erase_opts() used in fastboot/fb_nand.c, cmd/nand.c and env/nand.c code. This is also the reason why we should move it to core folder and make it more general.

---
 drivers/mtd/nand/raw/nand_util.c | 153 ----------------------------
 drivers/mtd/nand/util.c          | 166 +++++++++++++++++++++++++++++++
 2 files changed, 166 insertions(+), 153 deletions(-)
drivers/mtd/nand/raw/nand_util.c +0 -153
index 9c18ce63b9..f7704d4697 100644
@@ -32,159 +32,6 @@
 #include <linux/mtd/mtd.h>
 #include <linux/mtd/rawnand.h>
 #include <nand.h>
-#include <jffs2/jffs2.h>
-
-typedef struct erase_info	erase_info_t;
-
-/* support only for native endian JFFS2 */
-#define cpu_to_je16(x) (x)
-#define cpu_to_je32(x) (x)
-
-/**
- * nand_erase_opts: - erase NAND flash with support for various options
- *		      (jffs2 formatting)
- *
- * @param mtd		nand mtd instance to erase
- * @param opts		options,  @see struct nand_erase_options
- * Return:		0 in case of success
- *
- * This code is ported from flash_eraseall.c from Linux mtd utils by
- * Arcom Control System Ltd.
- */
-int nand_erase_opts(struct mtd_info *mtd,
-		    const nand_erase_options_t *opts)
-{
-	struct jffs2_unknown_node cleanmarker;
-	erase_info_t erase;
-	unsigned long erase_length, erased_length; /* in blocks */
-	int result;
-	int percent_complete = -1;
-	const char *mtd_device = mtd->name;
-	struct mtd_oob_ops oob_opts;
-	struct nand_chip *chip = mtd_to_nand(mtd);
-
-	if ((opts->offset & (mtd->erasesize - 1)) != 0) {
-		printf("Attempt to erase non block-aligned data\n");
-		return -1;
-	}
-
-	memset(&erase, 0, sizeof(erase));
-	memset(&oob_opts, 0, sizeof(oob_opts));
-
-	erase.mtd = mtd;
-	erase.len = mtd->erasesize;
-	erase.addr = opts->offset;
-	erase_length = lldiv(opts->length + mtd->erasesize - 1,
-			     mtd->erasesize);
-
-	cleanmarker.magic = cpu_to_je16(JFFS2_MAGIC_BITMASK);
-	cleanmarker.nodetype = cpu_to_je16(JFFS2_NODETYPE_CLEANMARKER);
-	cleanmarker.totlen = cpu_to_je32(8);
-
-	/* scrub option allows to erase badblock. To prevent internal
-	 * check from erase() method, set block check method to dummy
-	 * and disable bad block table while erasing.
-	 */
-	if (opts->scrub) {
-		erase.scrub = opts->scrub;
-		/*
-		 * We don't need the bad block table anymore...
-		 * after scrub, there are no bad blocks left!
-		 */
-		if (chip->bbt) {
-			kfree(chip->bbt);
-		}
-		chip->bbt = NULL;
-		chip->options &= ~NAND_BBT_SCANNED;
-	}
-
-	for (erased_length = 0;
-	     erased_length < erase_length;
-	     erase.addr += mtd->erasesize) {
-
-		schedule();
-
-		if (opts->lim && (erase.addr >= (opts->offset + opts->lim))) {
-			puts("Size of erase exceeds limit\n");
-			return -EFBIG;
-		}
-		if (!opts->scrub) {
-			int ret = mtd_block_isbad(mtd, erase.addr);
-			if (ret > 0) {
-				if (!opts->quiet)
-					printf("\rSkipping %s at  "
-					       "0x%08llx                 "
-					       "                         \n",
-					       ret == 1 ? "bad block" : "bbt reserved",
-					       erase.addr);
-
-				if (!opts->spread)
-					erased_length++;
-
-				continue;
-
-			} else if (ret < 0) {
-				printf("\n%s: MTD get bad block failed: %d\n",
-				       mtd_device,
-				       ret);
-				return -1;
-			}
-		}
-
-		erased_length++;
-
-		result = mtd_erase(mtd, &erase);
-		if (result != 0) {
-			printf("\n%s: MTD Erase failure: %d\n",
-			       mtd_device, result);
-			continue;
-		}
-
-		/* format for JFFS2 ? */
-		if (opts->jffs2 && chip->ecc.layout->oobavail >= 8) {
-			struct mtd_oob_ops ops;
-			ops.ooblen = 8;
-			ops.datbuf = NULL;
-			ops.oobbuf = (uint8_t *)&cleanmarker;
-			ops.ooboffs = 0;
-			ops.mode = MTD_OPS_AUTO_OOB;
-
-			result = mtd_write_oob(mtd, erase.addr, &ops);
-			if (result != 0) {
-				printf("\n%s: MTD writeoob failure: %d\n",
-				       mtd_device, result);
-				continue;
-			}
-		}
-
-		if (!opts->quiet) {
-			unsigned long long n = erased_length * 100ULL;
-			int percent;
-
-			do_div(n, erase_length);
-			percent = (int)n;
-
-			/* output progress message only at whole percent
-			 * steps to reduce the number of messages printed
-			 * on (slow) serial consoles
-			 */
-			if (percent != percent_complete) {
-				percent_complete = percent;
-
-				printf("\rErasing at 0x%llx -- %3d%% complete.",
-				       erase.addr, percent);
-
-				if (opts->jffs2 && result == 0)
-					printf(" Cleanmarker written at 0x%llx.",
-					       erase.addr);
-			}
-		}
-	}
-	if (!opts->quiet)
-		printf("\n");
-
-	return 0;
-}
 
 #ifdef CONFIG_CMD_NAND_LOCK_UNLOCK
 
drivers/mtd/nand/util.c +166 -0

176 lines not on this page · raw message

Signature · 1 line
2.30.1
#5 lore raw

PATCH v2 5/14 spi: add board_nand_init() function

In reply to Alexey Romanov

By analogy with RAW NAND drivers, select SYS_NAND_SELF_INIT option and implement board_nand_init() function. It will be called from nand_init().

---
 drivers/mtd/nand/spi/Kconfig |  1 +
 drivers/mtd/nand/spi/core.c  | 14 ++++++++++++++
 2 files changed, 15 insertions(+)
drivers/mtd/nand/spi/Kconfig +1 -0
index 0777dfdf0a..c9ca76a1c9 100644
@@ -2,6 +2,7 @@ menuconfig MTD_SPI_NAND
 	bool "SPI NAND device Support"
 	depends on DM_MTD && DM_SPI
 	select MTD_NAND_CORE
+	select SYS_NAND_SELF_INIT
 	select SPI_MEM
 	help
 	  This is the framework for the SPI NAND device drivers.
drivers/mtd/nand/spi/core.c +14 -0
index 8ca33459f9..07e521dbf5 100644
@@ -28,6 +28,7 @@
 #include <spi-mem.h>
 #include <dm/device_compat.h>
 #include <dm/devres.h>
+#include <dm/uclass.h>
 #include <linux/bitops.h>
 #include <linux/bug.h>
 #include <linux/mtd/spinand.h>
@@ -1287,3 +1288,16 @@ U_BOOT_DRIVER(spinand) = {
 	.priv_auto	= sizeof(struct spinand_device),
 	.probe = spinand_probe,
 };
+
+void board_nand_init(void)
+{
+	struct udevice *dev;
+	int ret;
+
+	ret = uclass_get_device_by_driver(UCLASS_SPI,
+					  DM_DRIVER_GET(spinand),
+					  &dev);
+	if (ret && ret != -ENODEV)
+		log_err("Failed to initialize SPI NAND driver. (error %d)\n",
+			ret);
+}
Signature · 1 line
2.30.1
#6 lore raw

PATCH v2 6/14 spi: use nand_register() instead of add_mtd_device()

In reply to Alexey Romanov

Most functions that work with NAND device (for example fastboot), use the get_nand_dev_by_index() function to work with NAND MTD. In order to use this feature, SPI NAND must be registered via nand_register().

---
 drivers/mtd/nand/spi/core.c | 3 ++-
 1 file changed, 2 insertions(+), 1 deletion(-)
drivers/mtd/nand/spi/core.c +2 -1
index 07e521dbf5..2a3dbcfcb4 100644
@@ -23,6 +23,7 @@
 #else
 #include <common.h>
 #include <errno.h>
+#include <nand.h>
 #include <watchdog.h>
 #include <spi.h>
 #include <spi-mem.h>
@@ -1213,7 +1214,7 @@ static int spinand_probe(struct udevice *dev)
 #ifndef __UBOOT__
 	ret = mtd_device_register(mtd, NULL, 0);
 #else
-	ret = add_mtd_device(mtd);
+	ret = nand_register(0, mtd);
 #endif
 	if (ret)
 		goto err_spinand_cleanup;
Signature · 1 line
2.30.1
#7 lore raw

PATCH v2 7/14 mtdparts: use negative error codes

In reply to Alexey Romanov

It is bad practice to use such error codes. Error codes must be negative.

Also, fastboot code expects that if successful, mtdparts functions will return a value greater than 0. You can see fastboot_nand_get_part_info() functions calls inside getvar_get_part_info().

---
 cmd/mtdparts.c | 134 ++++++++++++++++++++++++-------------------------
 1 file changed, 67 insertions(+), 67 deletions(-)
cmd/mtdparts.c +67 -67
index b31db73ebf..00c07014b2 100644
@@ -299,7 +299,7 @@ static void current_save(void)
  * @param type mtd type
  * @param num mtd number
  * @param mtd a pointer to an mtd_info instance (output)
- * Return: 0 if device is valid, 1 otherwise
+ * Return: 0 if device is valid, -errno otherwise
  */
 static int get_mtd_info(u8 type, u8 num, struct mtd_info **mtd)
 {
@@ -309,7 +309,7 @@ static int get_mtd_info(u8 type, u8 num, struct mtd_info **mtd)
 	*mtd = get_mtd_device_nm(mtd_dev);
 	if (IS_ERR(*mtd)) {
 		printf("Device %s not found!\n", mtd_dev);
-		return 1;
+		return -ENODEV;
 	}
 	put_mtd_device(*mtd);
 
@@ -323,7 +323,7 @@ static int get_mtd_info(u8 type, u8 num, struct mtd_info **mtd)
  *
  * @param id of the parent device
  * @param part partition to validate
- * Return: 0 if partition is valid, 1 otherwise
+ * Return: 0 if partition is valid, -errno otherwise
  */
 static int part_validate_eraseblock(struct mtdids *id, struct part_info *part)
 {
@@ -333,7 +333,7 @@ static int part_validate_eraseblock(struct mtdids *id, struct part_info *part)
 	u64 offset, size;
 
 	if (get_mtd_info(id->type, id->num, &mtd))
-		return 1;
+		return -EINVAL;
 
 	part->sector_size = mtd->erasesize;
 
@@ -347,14 +347,14 @@ static int part_validate_eraseblock(struct mtdids *id, struct part_info *part)
 			printf("%s%d: partition (%s) start offset"
 			       "alignment incorrect\n",
 			       MTD_DEV_TYPE(id->type), id->num, part->name);
-			return 1;
+			return -EINVAL;
 		}
 
 		size = part->size;
 		if (do_div(size, mtd->erasesize)) {
 			printf("%s%d: partition (%s) size alignment incorrect\n",
 			       MTD_DEV_TYPE(id->type), id->num, part->name);
-			return 1;
+			return -EINVAL;
 		}
 	} else {
 		/*
@@ -374,7 +374,7 @@ static int part_validate_eraseblock(struct mtdids *id, struct part_info *part)
 
 		printf("%s%d: partition (%s) start offset alignment incorrect\n",
 		       MTD_DEV_TYPE(id->type), id->num, part->name);
-		return 1;
+		return -EINVAL;
 
 	start_ok:
 
@@ -393,7 +393,7 @@ static int part_validate_eraseblock(struct mtdids *id, struct part_info *part)
 
 		printf("%s%d: partition (%s) size alignment incorrect\n",
 		       MTD_DEV_TYPE(id->type), id->num, part->name);
-		return 1;
+		return -EINVAL;
 
 	end_ok:
 		return 0;
@@ -410,7 +410,7 @@ static int part_validate_eraseblock(struct mtdids *id, struct part_info *part)
  *
  * @param id of the parent device
  * @param part partition to validate
- * Return: 0 if partition is valid, 1 otherwise
+ * Return: 0 if partition is valid, -errno otherwise
  */
 static int part_validate(struct mtdids *id, struct part_info *part)
 {
@@ -420,18 +420,18 @@ static int part_validate(struct mtdids *id, struct part_info *part)
 	if (part->offset > id->size) {
 		printf("%s: offset %08llx beyond flash size %08llx\n",
 				id->mtd_id, part->offset, id->size);
-		return 1;
+		return -EINVAL;
 	}
 
 	if ((part->offset + part->size) <= part->offset) {
 		printf("%s%d: partition (%s) size too big\n",
 				MTD_DEV_TYPE(id->type), id->num, part->name);
-		return 1;
+		return -EINVAL;
 	}
 
 	if (part->offset + part->size > id->size) {
 		printf("%s: partitioning exceeds flash size\n", id->mtd_id);
-		return 1;
+		return -EINVAL;
 	}
 
 	/*
@@ -446,7 +446,7 @@ static int part_validate(struct mtdids *id, struct part_info *part)
  *
  * @param dev device to delete partition from
  * @param part partition to delete
- * Return: 0 on success, 1 otherwise
+ * Return: 0 on success, -ernno otherwise
  */
 static int part_del(struct mtd_device *dev, struct part_info *part)
 {
@@ -544,7 +544,7 @@ static int part_sort_add(struct mtd_device *dev, struct part_info *part)
 		/* be compliant with kernel cmdline, allow only one partition at offset zero */
 		if ((new_pi->offset == pi->offset) && (pi->offset == 0)) {
 			printf("cannot add second partition at offset 0\n");
-			return 1;
+			return -EINVAL;
 		}
 
 		if (new_pi->offset <= pi->offset) {
@@ -574,17 +574,17 @@ static int part_sort_add(struct mtd_device *dev, struct part_info *part)
  *
  * @param dev device to which partition is added
  * @param part partition to be added
- * Return: 0 on success, 1 otherwise
+ * Return: 0 on success, -errno otherwise
  */
 static int part_add(struct mtd_device *dev, struct part_info *part)
 {
 	/* verify alignment and size */
 	if (part_validate(dev->id, part) != 0)
-		return 1;
+		return -EINVAL;
 
 	/* partition is ok, add it to the list */
 	if (part_sort_add(dev, part) != 0)
-		return 1;
+		return -EINVAL;
 
 	return 0;
 }
@@ -596,7 +596,7 @@ static int part_add(struct mtd_device *dev, struct part_info *part)
  * @param partdef pointer to the partition definition string i.e. <part-def>
  * @param ret output pointer to next char after parse completes (output)
  * @param retpart pointer to the allocated partition (output)
- * Return: 0 on success, 1 otherwise
+ * Return: 0 on success, -errno otherwise
  */
 static int part_parse(const char *const partdef, const char **ret, struct part_info **retpart)
 {
@@ -622,7 +622,7 @@ static int part_parse(const char *const partdef, const char **ret, struct part_i
 		size = memsize_parse(p, &p);
 		if (size < MIN_PART_SIZE) {
 			printf("partition size too small (%llx)\n", size);
-			return 1;
+			return -EINVAL;
 		}
 	}
 
@@ -638,12 +638,12 @@ static int part_parse(const char *const partdef, const char **ret, struct part_i
 		name = ++p;
 		if ((p = strchr(name, ')')) == NULL) {
 			printf("no closing ) found in partition name\n");
-			return 1;
+			return -EINVAL;
 		}
 		name_len = p - name + 1;
 		if ((name_len - 1) == 0) {
 			printf("empty partition name\n");
-			return 1;
+			return -EINVAL;
 		}
 		p++;
 	} else {
@@ -664,7 +664,7 @@ static int part_parse(const char *const partdef, const char **ret, struct part_i
 		if (size == SIZE_REMAINING) {
 			*ret = NULL;
 			printf("no partitions allowed after a fill-up partition\n");
-			return 1;
+			return -EINVAL;
 		}
 		*ret = ++p;
 	} else if ((*p == ';') || (*p == '\0')) {
@@ -672,14 +672,14 @@ static int part_parse(const char *const partdef, const char **ret, struct part_i
 	} else {
 		printf("unexpected character '%c' at the end of partition\n", *p);
 		*ret = NULL;
-		return 1;
+		return -EINVAL;
 	}
 
 	/*  allocate memory */
 	part = (struct part_info *)malloc(sizeof(struct part_info) + name_len);
 	if (!part) {
 		printf("out of memory\n");
-		return 1;
+		return -ENOMEM;
 	}
 	memset(part, 0, sizeof(struct part_info) + name_len);
 	part->size = size;
@@ -714,14 +714,14 @@ static int part_parse(const char *const partdef, const char **ret, struct part_i
  * @param type mtd type
  * @param num mtd number
  * @param size a pointer to the size of the mtd device (output)
- * Return: 0 if device is valid, 1 otherwise
+ * Return: 0 if device is valid, -errno otherwise
  */
 static int mtd_device_validate(u8 type, u8 num, u64 *size)
 {
 	struct mtd_info *mtd = NULL;
 
 	if (get_mtd_info(type, num, &mtd))
-		return 1;
+		return -EINVAL;
 
 	*size = mtd->size;
 
@@ -732,7 +732,7 @@ static int mtd_device_validate(u8 type, u8 num, u64 *size)
  * Delete all mtd devices from a supplied devices list, free memory allocated for
  * each device and delete all device partitions.
  *
- * Return: 0 on success, 1 otherwise
+ * Return: 0 on success, -errno otherwise
  */
 static int device_delall(struct list_head *head)
 {
@@ -756,7 +756,7 @@ static int device_delall(struct list_head *head)
  * from device list and device memory is freed.
  *
  * @param dev device to be deleted
- * Return: 0 on success, 1 otherwise
+ * Return: 0 on success, -errno otherwise
  */
 static int device_del(struct mtd_device *dev)
 {
@@ -835,7 +835,7 @@ static void device_add(struct mtd_device *dev)
  * @param mtd_dev pointer to the device definition string i.e. <mtd-dev>
  * @param ret output pointer to next char after parse completes (output)
  * @param retdev pointer to the allocated device (output)
- * Return: 0 on success, 1 otherwise
+ * Return: 0 on success, -errno otherwise
  */
 static int device_parse(const char *const mtd_dev, const char **ret, struct mtd_device **retdev)
 {
@@ -864,7 +864,7 @@ static int device_parse(const char *const mtd_dev, const char **ret, struct mtd_
 	mtd_id = p = mtd_dev;
 	if (!(p = strchr(mtd_id, ':'))) {
 		printf("no <mtd-id> identifier\n");
-		return 1;
+		return -EINVAL;
 	}
 	mtd_id_len = p - mtd_id + 1;
 	p++;
@@ -872,7 +872,7 @@ static int device_parse(const char *const mtd_dev, const char **ret, struct mtd_
 	/* verify if we have a valid device specified */
 	if ((id = id_find_by_mtd_id(mtd_id, mtd_id_len - 1)) == NULL) {
 		printf("invalid mtd device '%.*s'\n", mtd_id_len - 1, mtd_id);
-		return 1;
+		return -ENODEV;
 	}
 
 	pend = strchr(p, ';');
@@ -915,7 +915,7 @@ static int device_parse(const char *const mtd_dev, const char **ret, struct mtd_
 	}
 	if (err == 1) {
 		part_delall(&tmp_list);
-		return 1;
+		return -EINVAL;
 	}
 
 	debug("\ntotal partitions: %d\n", num_parts);
@@ -932,14 +932,14 @@ static int device_parse(const char *const mtd_dev, const char **ret, struct mtd_
 			printf("unexpected character '%c' at the end of device\n", *p);
 			if (ret)
 				*ret = NULL;
-			return 1;
+			return -EINVAL;
 		}
 	}
 
 	/* allocate memory for mtd_device structure */
 	if ((dev = (struct mtd_device *)malloc(sizeof(struct mtd_device))) == NULL) {
 		printf("out of memory\n");
-		return 1;
+		return -ENOMEM;
 	}
 	memset(dev, 0, sizeof(struct mtd_device));
 	dev->id = id;
@@ -953,7 +953,7 @@ static int device_parse(const char *const mtd_dev, const char **ret, struct mtd_
 		list_del(entry);
 		if (part_sort_add(dev, part) != 0) {
 			device_del(dev);
-			return 1;
+			return -EINVAL;
 		}
 	}
 
@@ -966,7 +966,7 @@ static int device_parse(const char *const mtd_dev, const char **ret, struct mtd_
 /**
  * Initialize global device list.
  *
- * Return: 0 on success, 1 otherwise
+ * Return: 0 on success, -errno otherwise
  */
 static int mtd_devices_init(void)
 {
@@ -1037,7 +1037,7 @@ static struct mtdids* id_find_by_mtd_id(const char *mtd_id, unsigned int mtd_id_
  * @param ret_id output pointer to next char after parse completes (output)
  * @param dev_type parsed device type (output)
  * @param dev_num parsed device number (output)
- * Return: 0 on success, 1 otherwise
+ * Return: 0 on success, -errno otherwise
  */
 int mtd_id_parse(const char *id, const char **ret_id, u8 *dev_type,
 		 u8 *dev_num)
@@ -1059,12 +1059,12 @@ int mtd_id_parse(const char *id, const char **ret_id, u8 *dev_type,
 		p += 8;
 	} else {
 		printf("incorrect device type in %s\n", id);
-		return 1;
+		return -EINVAL;
 	}
 
 	if (!isdigit(*p)) {
 		printf("incorrect device number in %s\n", id);
-		return 1;
+		return -EINVAL;
 	}
 
 	*dev_num = simple_strtoul(p, (char **)&p, 0);
@@ -1079,7 +1079,7 @@ int mtd_id_parse(const char *id, const char **ret_id, u8 *dev_type,
  *
  * @param buf output buffer holding generated mtdparts string (output)
  * @param buflen buffer size
- * Return: 0 on success, 1 otherwise
+ * Return: 0 on success, -errno otherwise
  */
 static int generate_mtdparts(char *buf, u32 buflen)
 {
@@ -1195,7 +1195,7 @@ static int generate_mtdparts(char *buf, u32 buflen)
 
 cleanup:
 	last_parts[0] = '\0';
-	return 1;
+	return -EINVAL;
 }
 
 /**
@@ -1204,7 +1204,7 @@ cleanup:
  *
  * @param buf output buffer holding generated mtdparts string (output)
  * @param buflen buffer size
- * Return: 0 on success, 1 otherwise
+ * Return: 0 on success, -errno otherwise
  */
 static int generate_mtdparts_save(char *buf, u32 buflen)
 {
@@ -1342,7 +1342,7 @@ static void list_partitions(void)
  * @param dev pointer to the requested device (output)
  * @param part_num verified partition number (output)
  * @param part pointer to requested partition (output)
- * Return: 0 on success, 1 otherwise
+ * Return: 0 on success, -errno otherwise
  */
 int find_dev_and_part(const char *id, struct mtd_device **dev,
 		u8 *part_num, struct part_info **part)
@@ -1370,27 +1370,27 @@ int find_dev_and_part(const char *id, struct mtd_device **dev,
 	*part_num = 0;
 
 	if (mtd_id_parse(p, &p, &type, &dnum) != 0)
-		return 1;
+		return -EINVAL;
 
 	if ((*p++ != ',') || (*p == '\0')) {
 		printf("no partition number specified\n");
-		return 1;
+		return -EINVAL;
 	}
 	pnum = simple_strtoul(p, (char **)&p, 0);
 	if (*p != '\0') {
 		printf("unexpected trailing character '%c'\n", *p);
-		return 1;
+		return -EINVAL;
 	}
 
 	if ((*dev = device_find(type, dnum)) == NULL) {
 		printf("no such device %s%d\n", MTD_DEV_TYPE(type), dnum);
-		return 1;
+		return -ENODEV;
 	}
 
 	if ((*part = mtd_part_info(*dev, pnum)) == NULL) {
 		printf("no such partition\n");
 		*dev = NULL;
-		return 1;
+		return -EINVAL;
 	}
 
 	*part_num = pnum;
@@ -1402,7 +1402,7 @@ int find_dev_and_part(const char *id, struct mtd_device **dev,
  * Find and delete partition. For partition id format see find_dev_and_part().
  *
  * @param id string describing device and partition
- * Return: 0 on success, 1 otherwise
+ * Return: 0 on success, -errno otherwise
  */
 static int delete_partition(const char *id)
 {
@@ -1417,17 +1417,17 @@ static int delete_partition(const char *id)
 				part->name, part->size, part->offset);
 
 		if (part_del(dev, part) != 0)
-			return 1;
+			return -EINVAL;
 
 		if (generate_mtdparts_save(last_parts, MTDPARTS_MAXLEN) != 0) {
 			printf("generated mtdparts too long, resetting to null\n");
-			return 1;
+			return -EINVAL;
 		}
 		return 0;
 	}
 
 	printf("partition %s not found\n", id);
-	return 1;
+	return -ENOENT;
 }
 
 #if defined(CONFIG_CMD_MTDPARTS_SPREAD)
@@ -1478,7 +1478,7 @@ static void spread_partition(struct mtd_info *mtd, struct part_info *part,
  * as big as their mtdparts environment variable sizes and they each start
  * on a good block.
  *
- * Return: 0 on success, 1 otherwise
+ * Return: 0 on success, -errno otherwise
  */
 static int spread_partitions(void)
 {
@@ -1493,7 +1493,7 @@ static int spread_partitions(void)
 		dev = list_entry(dentry, struct mtd_device, link);
 
 		if (get_mtd_info(dev->id->type, dev->id->num, &mtd))
-			return 1;
+			return -EINVAL;
 
 		part_num = 0;
 		cur_offs = 0;
@@ -1519,7 +1519,7 @@ static int spread_partitions(void)
 
 	if (generate_mtdparts_save(last_parts, MTDPARTS_MAXLEN) != 0) {
 		printf("generated mtdparts too long, resetting to null\n");
-		return 1;
+		return -EINVAL;
 	}
 	return 0;
 }
@@ -1547,7 +1547,7 @@ static const char *env_get_mtdparts(char *buf)
  * for each entry. Add created devices to the global devices list.
  *
  * @param mtdparts string specifing mtd partitions
- * Return: 0 on success, 1 otherwise
+ * Return: 0 on success, -errno otherwise
  */
 static int parse_mtdparts(const char *const mtdparts)
 {
@@ -1605,7 +1605,7 @@ static int parse_mtdparts(const char *const mtdparts)
  * to the global mtdids list.
  *
  * @param ids mapping string
- * Return: 0 on success, 1 otherwise
+ * Return: 0 on success, -errno otherwise
  */
 static int parse_mtdids(const char *const ids)
 {
@@ -1646,7 +1646,7 @@ static int parse_mtdids(const char *const ids)
 
 		/* check if requested device exists */
 		if (mtd_device_validate(type, num, &size) != 0)
-			return 1;
+			return -EINVAL;
 
 		/* locate <mtd-id> */
 		mtd_id = p;
@@ -1704,7 +1704,7 @@ static int parse_mtdids(const char *const ids)
 			list_del(entry);
 			free(id_tmp);
 		}
-		return 1;
+		return -EINVAL;
 	}
 
 	return 0;
@@ -1715,7 +1715,7 @@ static int parse_mtdids(const char *const ids)
  * Parse and initialize global mtdids mapping and create global
  * device/partition list.
  *
- * Return: 0 on success, 1 otherwise
+ * Return: 0 on success, -errno otherwise
  */
 int mtdparts_init(void)
 {
@@ -1768,12 +1768,12 @@ int mtdparts_init(void)
 			env_set("mtdids", (char *)ids);
 		} else {
 			printf("mtdids not defined, no default present\n");
-			return 1;
+			return -ENXIO;
 		}
 	}
 	if (strlen(ids) > MTDIDS_MAXLEN - 1) {
 		printf("mtdids too long (> %d)\n", MTDIDS_MAXLEN);
-		return 1;
+		return -EINVAL;
 	}
 
 	/* use defaults when mtdparts variable is not defined
@@ -1789,7 +1789,7 @@ int mtdparts_init(void)
 
 	if (parts && (strlen(parts) > MTDPARTS_MAXLEN - 1)) {
 		printf("mtdparts too long (> %d)\n", MTDPARTS_MAXLEN);
-		return 1;
+		return -EINVAL;
 	}
 
 	/* check if we have already parsed those mtdids */
@@ -1800,7 +1800,7 @@ int mtdparts_init(void)
 
 		if (parse_mtdids(ids) != 0) {
 			mtd_devices_init();
-			return 1;
+			return -EINVAL;
 		}
 
 		/* ok it's good, save new ids */
@@ -1810,11 +1810,11 @@ int mtdparts_init(void)
 	/* parse partitions if either mtdparts or mtdids were updated */
 	if (parts && ((last_parts[0] == '\0') || ((strcmp(last_parts, parts) != 0)) || ids_changed)) {
 		if (parse_mtdparts(parts) != 0)
-			return 1;
+			return -EINVAL;
 
 		if (list_empty(&devices)) {
 			printf("mtdparts_init: no valid partitions\n");
-			return 1;
+			return -ENXIO;
 		}
 
 		/* ok it's good, save new parts */
@@ -2022,7 +2022,7 @@ static int do_mtdparts(struct cmd_tbl *cmdtp, int flag, int argc,
 		debug("add tmpbuf: %s\n", tmpbuf);
 
 		if ((device_parse(tmpbuf, NULL, &dev) != 0) || (!dev))
-			return 1;
+			return -EINVAL;
 
 		debug("+ %s\t%d\t%s\n", MTD_DEV_TYPE(dev->id->type),
 				dev->id->num, dev->id->mtd_id);
Signature · 1 line
2.30.1
Reviewed-by on v2 7/14
#8 lore raw

Re: [PATCH v2 07/14] mtdparts: use negative error codes

Hi

Quoted 576 lines · Alexey Romanov

It is bad practice to use such error codes. Error codes must be negative.

Also, fastboot code expects that if successful, mtdparts functions will return a value greater than 0. You can see fastboot_nand_get_part_info() functions calls inside getvar_get_part_info().

---
 cmd/mtdparts.c | 134 ++++++++++++++++++++++++-------------------------
 1 file changed, 67 insertions(+), 67 deletions(-)
cmd/mtdparts.c +67 -68
index b31db73ebf..00c07014b2 100644
@@ -299,7 +299,7 @@ static void current_save(void)
  * @param type mtd type
  * @param num mtd number
  * @param mtd a pointer to an mtd_info instance (output)
- * Return: 0 if device is valid, 1 otherwise
+ * Return: 0 if device is valid, -errno otherwise
  */
 static int get_mtd_info(u8 type, u8 num, struct mtd_info **mtd)
 {
@@ -309,7 +309,7 @@ static int get_mtd_info(u8 type, u8 num, struct mtd_info **mtd)
        *mtd = get_mtd_device_nm(mtd_dev);
        if (IS_ERR(*mtd)) {
                printf("Device %s not found!\n", mtd_dev);
-               return 1;
+               return -ENODEV;
        }
        put_mtd_device(*mtd);
 
@@ -323,7 +323,7 @@ static int get_mtd_info(u8 type, u8 num, struct mtd_info **mtd)
  *
  * @param id of the parent device
  * @param part partition to validate
- * Return: 0 if partition is valid, 1 otherwise
+ * Return: 0 if partition is valid, -errno otherwise
  */
 static int part_validate_eraseblock(struct mtdids *id, struct part_info *part)
 {
@@ -333,7 +333,7 @@ static int part_validate_eraseblock(struct mtdids *id, struct part_info *part)
        u64 offset, size;
 
        if (get_mtd_info(id->type, id->num, &mtd))
-               return 1;
+               return -EINVAL;
 
        part->sector_size = mtd->erasesize;
 
@@ -347,14 +347,14 @@ static int part_validate_eraseblock(struct mtdids *id, struct part_info *part)
                        printf("%s%d: partition (%s) start offset"
                               "alignment incorrect\n",
                               MTD_DEV_TYPE(id->type), id->num, part->name);
-                       return 1;
+                       return -EINVAL;
                }
 
                size = part->size;
                if (do_div(size, mtd->erasesize)) {
                        printf("%s%d: partition (%s) size alignment incorrect\n",
                               MTD_DEV_TYPE(id->type), id->num, part->name);
-                       return 1;
+                       return -EINVAL;
                }
        } else {
                /*
@@ -374,7 +374,7 @@ static int part_validate_eraseblock(struct mtdids *id, struct part_info *part)
 
                printf("%s%d: partition (%s) start offset alignment incorrect\n",
                       MTD_DEV_TYPE(id->type), id->num, part->name);
-               return 1;
+               return -EINVAL;
 
        start_ok:
 
@@ -393,7 +393,7 @@ static int part_validate_eraseblock(struct mtdids *id, struct part_info *part)
 
                printf("%s%d: partition (%s) size alignment incorrect\n",
                       MTD_DEV_TYPE(id->type), id->num, part->name);
-               return 1;
+               return -EINVAL;
 
        end_ok:
                return 0;
@@ -410,7 +410,7 @@ static int part_validate_eraseblock(struct mtdids *id, struct part_info *part)
  *
  * @param id of the parent device
  * @param part partition to validate
- * Return: 0 if partition is valid, 1 otherwise
+ * Return: 0 if partition is valid, -errno otherwise
  */
 static int part_validate(struct mtdids *id, struct part_info *part)
 {
@@ -420,18 +420,18 @@ static int part_validate(struct mtdids *id, struct part_info *part)
        if (part->offset > id->size) {
                printf("%s: offset %08llx beyond flash size %08llx\n",
                                id->mtd_id, part->offset, id->size);
-               return 1;
+               return -EINVAL;
        }
 
        if ((part->offset + part->size) <= part->offset) {
                printf("%s%d: partition (%s) size too big\n",
                                MTD_DEV_TYPE(id->type), id->num, part->name);
-               return 1;
+               return -EINVAL;
        }
 
        if (part->offset + part->size > id->size) {
                printf("%s: partitioning exceeds flash size\n", id->mtd_id);
-               return 1;
+               return -EINVAL;
        }
 
        /*
@@ -446,7 +446,7 @@ static int part_validate(struct mtdids *id, struct part_info *part)
  *
  * @param dev device to delete partition from
  * @param part partition to delete
- * Return: 0 on success, 1 otherwise
+ * Return: 0 on success, -ernno otherwise
  */
 static int part_del(struct mtd_device *dev, struct part_info *part)
 {
@@ -544,7 +544,7 @@ static int part_sort_add(struct mtd_device *dev, struct part_info *part)
                /* be compliant with kernel cmdline, allow only one partition at offset zero */
                if ((new_pi->offset == pi->offset) && (pi->offset == 0)) {
                        printf("cannot add second partition at offset 0\n");
-                       return 1;
+                       return -EINVAL;
                }
 
                if (new_pi->offset <= pi->offset) {
@@ -574,17 +574,17 @@ static int part_sort_add(struct mtd_device *dev, struct part_info *part)
  *
  * @param dev device to which partition is added
  * @param part partition to be added
- * Return: 0 on success, 1 otherwise
+ * Return: 0 on success, -errno otherwise
  */
 static int part_add(struct mtd_device *dev, struct part_info *part)
 {
        /* verify alignment and size */
        if (part_validate(dev->id, part) != 0)
-               return 1;
+               return -EINVAL;
 
        /* partition is ok, add it to the list */
        if (part_sort_add(dev, part) != 0)
-               return 1;
+               return -EINVAL;
 
        return 0;
 }
@@ -596,7 +596,7 @@ static int part_add(struct mtd_device *dev, struct part_info *part)
  * @param partdef pointer to the partition definition string i.e. <part-def>
  * @param ret output pointer to next char after parse completes (output)
  * @param retpart pointer to the allocated partition (output)
- * Return: 0 on success, 1 otherwise
+ * Return: 0 on success, -errno otherwise
  */
 static int part_parse(const char *const partdef, const char **ret, struct part_info **retpart)
 {
@@ -622,7 +622,7 @@ static int part_parse(const char *const partdef, const char **ret, struct part_i
                size = memsize_parse(p, &p);
                if (size < MIN_PART_SIZE) {
                        printf("partition size too small (%llx)\n", size);
-                       return 1;
+                       return -EINVAL;
                }
        }
 
@@ -638,12 +638,12 @@ static int part_parse(const char *const partdef, const char **ret, struct part_i
                name = ++p;
                if ((p = strchr(name, ')')) == NULL) {
                        printf("no closing ) found in partition name\n");
-                       return 1;
+                       return -EINVAL;
                }
                name_len = p - name + 1;
                if ((name_len - 1) == 0) {
                        printf("empty partition name\n");
-                       return 1;
+                       return -EINVAL;
                }
                p++;
        } else {
@@ -664,7 +664,7 @@ static int part_parse(const char *const partdef, const char **ret, struct part_i
                if (size == SIZE_REMAINING) {
                        *ret = NULL;
                        printf("no partitions allowed after a fill-up partition\n");
-                       return 1;
+                       return -EINVAL;
                }
                *ret = ++p;
        } else if ((*p == ';') || (*p == '\0')) {
@@ -672,14 +672,14 @@ static int part_parse(const char *const partdef, const char **ret, struct part_i
        } else {
                printf("unexpected character '%c' at the end of partition\n", *p);
                *ret = NULL;
-               return 1;
+               return -EINVAL;
        }
 
        /*  allocate memory */
        part = (struct part_info *)malloc(sizeof(struct part_info) + name_len);
        if (!part) {
                printf("out of memory\n");
-               return 1;
+               return -ENOMEM;
        }
        memset(part, 0, sizeof(struct part_info) + name_len);
        part->size = size;
@@ -714,14 +714,14 @@ static int part_parse(const char *const partdef, const char **ret, struct part_i
  * @param type mtd type
  * @param num mtd number
  * @param size a pointer to the size of the mtd device (output)
- * Return: 0 if device is valid, 1 otherwise
+ * Return: 0 if device is valid, -errno otherwise
  */
 static int mtd_device_validate(u8 type, u8 num, u64 *size)
 {
        struct mtd_info *mtd = NULL;
 
        if (get_mtd_info(type, num, &mtd))
-               return 1;
+               return -EINVAL;
 
        *size = mtd->size;
 
@@ -732,7 +732,7 @@ static int mtd_device_validate(u8 type, u8 num, u64 *size)
  * Delete all mtd devices from a supplied devices list, free memory allocated for
  * each device and delete all device partitions.
  *
- * Return: 0 on success, 1 otherwise
+ * Return: 0 on success, -errno otherwise
  */
 static int device_delall(struct list_head *head)
 {
@@ -756,7 +756,7 @@ static int device_delall(struct list_head *head)
  * from device list and device memory is freed.
  *
  * @param dev device to be deleted
- * Return: 0 on success, 1 otherwise
+ * Return: 0 on success, -errno otherwise
  */
 static int device_del(struct mtd_device *dev)
 {
@@ -835,7 +835,7 @@ static void device_add(struct mtd_device *dev)
  * @param mtd_dev pointer to the device definition string i.e. <mtd-dev>
  * @param ret output pointer to next char after parse completes (output)
  * @param retdev pointer to the allocated device (output)
- * Return: 0 on success, 1 otherwise
+ * Return: 0 on success, -errno otherwise
  */
 static int device_parse(const char *const mtd_dev, const char **ret, struct mtd_device **retdev)
 {
@@ -864,7 +864,7 @@ static int device_parse(const char *const mtd_dev, const char **ret, struct mtd_
        mtd_id = p = mtd_dev;
        if (!(p = strchr(mtd_id, ':'))) {
                printf("no <mtd-id> identifier\n");
-               return 1;
+               return -EINVAL;
        }
        mtd_id_len = p - mtd_id + 1;
        p++;
@@ -872,7 +872,7 @@ static int device_parse(const char *const mtd_dev, const char **ret, struct mtd_
        /* verify if we have a valid device specified */
        if ((id = id_find_by_mtd_id(mtd_id, mtd_id_len - 1)) == NULL) {
                printf("invalid mtd device '%.*s'\n", mtd_id_len - 1, mtd_id);
-               return 1;
+               return -ENODEV;
        }
 
        pend = strchr(p, ';');
@@ -915,7 +915,7 @@ static int device_parse(const char *const mtd_dev, const char **ret, struct mtd_
        }
        if (err == 1) {
                part_delall(&tmp_list);
-               return 1;
+               return -EINVAL;
        }
 
        debug("\ntotal partitions: %d\n", num_parts);
@@ -932,14 +932,14 @@ static int device_parse(const char *const mtd_dev, const char **ret, struct mtd_
                        printf("unexpected character '%c' at the end of device\n", *p);
                        if (ret)
                                *ret = NULL;
-                       return 1;
+                       return -EINVAL;
                }
        }
 
        /* allocate memory for mtd_device structure */
        if ((dev = (struct mtd_device *)malloc(sizeof(struct mtd_device))) == NULL) {
                printf("out of memory\n");
-               return 1;
+               return -ENOMEM;
        }
        memset(dev, 0, sizeof(struct mtd_device));
        dev->id = id;
@@ -953,7 +953,7 @@ static int device_parse(const char *const mtd_dev, const char **ret, struct mtd_
                list_del(entry);
                if (part_sort_add(dev, part) != 0) {
                        device_del(dev);
-                       return 1;
+                       return -EINVAL;
                }
        }
 
@@ -966,7 +966,7 @@ static int device_parse(const char *const mtd_dev, const char **ret, struct mtd_
 /**
  * Initialize global device list.
  *
- * Return: 0 on success, 1 otherwise
+ * Return: 0 on success, -errno otherwise
  */
 static int mtd_devices_init(void)
 {
@@ -1037,7 +1037,7 @@ static struct mtdids* id_find_by_mtd_id(const char *mtd_id, unsigned int mtd_id_
  * @param ret_id output pointer to next char after parse completes (output)
  * @param dev_type parsed device type (output)
  * @param dev_num parsed device number (output)
- * Return: 0 on success, 1 otherwise
+ * Return: 0 on success, -errno otherwise
  */
 int mtd_id_parse(const char *id, const char **ret_id, u8 *dev_type,
                 u8 *dev_num)
@@ -1059,12 +1059,12 @@ int mtd_id_parse(const char *id, const char **ret_id, u8 *dev_type,
                p += 8;
        } else {
                printf("incorrect device type in %s\n", id);
-               return 1;
+               return -EINVAL;
        }
 
        if (!isdigit(*p)) {
                printf("incorrect device number in %s\n", id);
-               return 1;
+               return -EINVAL;
        }
 
        *dev_num = simple_strtoul(p, (char **)&p, 0);
@@ -1079,7 +1079,7 @@ int mtd_id_parse(const char *id, const char **ret_id, u8 *dev_type,
  *
  * @param buf output buffer holding generated mtdparts string (output)
  * @param buflen buffer size
- * Return: 0 on success, 1 otherwise
+ * Return: 0 on success, -errno otherwise
  */
 static int generate_mtdparts(char *buf, u32 buflen)
 {
@@ -1195,7 +1195,7 @@ static int generate_mtdparts(char *buf, u32 buflen)
 
 cleanup:
        last_parts[0] = '\0';
-       return 1;
+       return -EINVAL;
 }
 
 /**
@@ -1204,7 +1204,7 @@ cleanup:
  *
  * @param buf output buffer holding generated mtdparts string (output)
  * @param buflen buffer size
- * Return: 0 on success, 1 otherwise
+ * Return: 0 on success, -errno otherwise
  */
 static int generate_mtdparts_save(char *buf, u32 buflen)
 {
@@ -1342,7 +1342,7 @@ static void list_partitions(void)
  * @param dev pointer to the requested device (output)
  * @param part_num verified partition number (output)
  * @param part pointer to requested partition (output)
- * Return: 0 on success, 1 otherwise
+ * Return: 0 on success, -errno otherwise
  */
 int find_dev_and_part(const char *id, struct mtd_device **dev,
                u8 *part_num, struct part_info **part)
@@ -1370,27 +1370,27 @@ int find_dev_and_part(const char *id, struct mtd_device **dev,
        *part_num = 0;
 
        if (mtd_id_parse(p, &p, &type, &dnum) != 0)
-               return 1;
+               return -EINVAL;
 
        if ((*p++ != ',') || (*p == '\0')) {
                printf("no partition number specified\n");
-               return 1;
+               return -EINVAL;
        }
        pnum = simple_strtoul(p, (char **)&p, 0);
        if (*p != '\0') {
                printf("unexpected trailing character '%c'\n", *p);
-               return 1;
+               return -EINVAL;
        }
 
        if ((*dev = device_find(type, dnum)) == NULL) {
                printf("no such device %s%d\n", MTD_DEV_TYPE(type), dnum);
-               return 1;
+               return -ENODEV;
        }
 
        if ((*part = mtd_part_info(*dev, pnum)) == NULL) {
                printf("no such partition\n");
                *dev = NULL;
-               return 1;
+               return -EINVAL;
        }
 
        *part_num = pnum;
@@ -1402,7 +1402,7 @@ int find_dev_and_part(const char *id, struct mtd_device **dev,
  * Find and delete partition. For partition id format see find_dev_and_part().
  *
  * @param id string describing device and partition
- * Return: 0 on success, 1 otherwise
+ * Return: 0 on success, -errno otherwise
  */
 static int delete_partition(const char *id)
 {
@@ -1417,17 +1417,17 @@ static int delete_partition(const char *id)
                                part->name, part->size, part->offset);
 
                if (part_del(dev, part) != 0)
-                       return 1;
+                       return -EINVAL;
 
                if (generate_mtdparts_save(last_parts, MTDPARTS_MAXLEN) != 0) {
                        printf("generated mtdparts too long, resetting to null\n");
-                       return 1;
+                       return -EINVAL;
                }
                return 0;
        }
 
        printf("partition %s not found\n", id);
-       return 1;
+       return -ENOENT;
 }
 
 #if defined(CONFIG_CMD_MTDPARTS_SPREAD)
@@ -1478,7 +1478,7 @@ static void spread_partition(struct mtd_info *mtd, struct part_info *part,
  * as big as their mtdparts environment variable sizes and they each start
  * on a good block.
  *
- * Return: 0 on success, 1 otherwise
+ * Return: 0 on success, -errno otherwise
  */
 static int spread_partitions(void)
 {
@@ -1493,7 +1493,7 @@ static int spread_partitions(void)
                dev = list_entry(dentry, struct mtd_device, link);
 
                if (get_mtd_info(dev->id->type, dev->id->num, &mtd))
-                       return 1;
+                       return -EINVAL;
 
                part_num = 0;
                cur_offs = 0;
@@ -1519,7 +1519,7 @@ static int spread_partitions(void)
 
        if (generate_mtdparts_save(last_parts, MTDPARTS_MAXLEN) != 0) {
                printf("generated mtdparts too long, resetting to null\n");
-               return 1;
+               return -EINVAL;
        }
        return 0;
 }
@@ -1547,7 +1547,7 @@ static const char *env_get_mtdparts(char *buf)
  * for each entry. Add created devices to the global devices list.
  *
  * @param mtdparts string specifing mtd partitions
- * Return: 0 on success, 1 otherwise
+ * Return: 0 on success, -errno otherwise
  */
 static int parse_mtdparts(const char *const mtdparts)
 {
@@ -1605,7 +1605,7 @@ static int parse_mtdparts(const char *const mtdparts)
  * to the global mtdids list.
  *
  * @param ids mapping string
- * Return: 0 on success, 1 otherwise
+ * Return: 0 on success, -errno otherwise
  */
 static int parse_mtdids(const char *const ids)
 {
@@ -1646,7 +1646,7 @@ static int parse_mtdids(const char *const ids)
 
                /* check if requested device exists */
                if (mtd_device_validate(type, num, &size) != 0)
-                       return 1;
+                       return -EINVAL;
 
                /* locate <mtd-id> */
                mtd_id = p;
@@ -1704,7 +1704,7 @@ static int parse_mtdids(const char *const ids)
                        list_del(entry);
                        free(id_tmp);
                }
-               return 1;
+               return -EINVAL;
        }
 
        return 0;
@@ -1715,7 +1715,7 @@ static int parse_mtdids(const char *const ids)
  * Parse and initialize global mtdids mapping and create global
  * device/partition list.
  *
- * Return: 0 on success, 1 otherwise
+ * Return: 0 on success, -errno otherwise
  */
 int mtdparts_init(void)
 {
@@ -1768,12 +1768,12 @@ int mtdparts_init(void)
                        env_set("mtdids", (char *)ids);
                } else {
                        printf("mtdids not defined, no default present\n");
-                       return 1;
+                       return -ENXIO;
                }
        }
        if (strlen(ids) > MTDIDS_MAXLEN - 1) {
                printf("mtdids too long (> %d)\n", MTDIDS_MAXLEN);
-               return 1;
+               return -EINVAL;
        }
 
        /* use defaults when mtdparts variable is not defined
@@ -1789,7 +1789,7 @@ int mtdparts_init(void)
 
        if (parts && (strlen(parts) > MTDPARTS_MAXLEN - 1)) {
                printf("mtdparts too long (> %d)\n", MTDPARTS_MAXLEN);
-               return 1;
+               return -EINVAL;
        }
 
        /* check if we have already parsed those mtdids */
@@ -1800,7 +1800,7 @@ int mtdparts_init(void)
 
                if (parse_mtdids(ids) != 0) {
                        mtd_devices_init();
-                       return 1;
+                       return -EINVAL;
                }
 
                /* ok it's good, save new ids */
@@ -1810,11 +1810,11 @@ int mtdparts_init(void)
        /* parse partitions if either mtdparts or mtdids were updated */
        if (parts && ((last_parts[0] == '\0') || ((strcmp(last_parts, parts) != 0)) || ids_changed)) {
                if (parse_mtdparts(parts) != 0)
-                       return 1;
+                       return -EINVAL;
 
                if (list_empty(&devices)) {
                        printf("mtdparts_init: no valid partitions\n");
-                       return 1;
+                       return -ENXIO;
                }
 
                /* ok it's good, save new parts */
@@ -2022,7 +2022,7 @@ static int do_mtdparts(struct cmd_tbl *cmdtp, int flag, int argc,
                debug("add tmpbuf: %s\n", tmpbuf);
 
                if ((device_parse(tmpbuf, NULL, &dev) != 0) || (!dev))
-                       return 1;
+                       return -EINVAL;
 
                debug("+ %s\t%d\t%s\n", MTD_DEV_TYPE(dev->id->type),
                                dev->id->num, dev->id->mtd_id);
--
Quoted 2 lines

2.30.1

Signature · 11 lines
Michael Nazzareno Trimarchi
Co-Founder & Chief Executive Officer
M. +39 347 913 2170
[email protected]
__________________________________

Amarula Solutions BV
Joop Geesinkweg 125, 1114 AB, Amsterdam, NL
T. +31 (0)85 111 9172
[email protected]
www.amarulasolutions.com
#9 lore raw

PATCH v2 8/14 mtdparts: use CMD_RET_FAILURE define

In reply to Alexey Romanov

Use 'return CMD_RET_FAILURE' define instead of 'return 1'.

---
 cmd/mtdparts.c | 20 ++++++++++----------
 1 file changed, 10 insertions(+), 10 deletions(-)
cmd/mtdparts.c +10 -10
index 00c07014b2..392ee511c9 100644
@@ -1923,15 +1923,15 @@ static int do_chpart(struct cmd_tbl *cmdtp, int flag, int argc,
 	u8 pnum;
 
 	if (mtdparts_init() !=0)
-		return 1;
+		return CMD_RET_FAILURE;
 
 	if (argc < 2) {
 		printf("no partition id specified\n");
-		return 1;
+		return CMD_RET_FAILURE;
 	}
 
 	if (find_dev_and_part(argv[1], &dev, &pnum, &part) != 0)
-		return 1;
+		return CMD_RET_FAILURE;
 
 	current_mtd_dev = dev;
 	current_mtd_partnum = pnum;
@@ -1978,7 +1978,7 @@ static int do_mtdparts(struct cmd_tbl *cmdtp, int flag, int argc,
 
 	/* make sure we are in sync with env variables */
 	if (mtdparts_init() != 0)
-		return 1;
+		return CMD_RET_FAILURE;
 
 	if (argc == 1) {
 		list_partitions();
@@ -2000,11 +2000,11 @@ static int do_mtdparts(struct cmd_tbl *cmdtp, int flag, int argc,
 		struct part_info *p;
 
 		if (mtd_id_parse(argv[2], NULL, &type, &num) != 0)
-			return 1;
+			return CMD_RET_FAILURE;
 
 		if ((id = id_find(type, num)) == NULL) {
 			printf("no such device %s defined in mtdids variable\n", argv[2]);
-			return 1;
+			return CMD_RET_FAILURE;
 		}
 
 		len = strlen(id->mtd_id) + 1;	/* 'mtd_id:' */
@@ -2015,7 +2015,7 @@ static int do_mtdparts(struct cmd_tbl *cmdtp, int flag, int argc,
 
 		if (len >= PART_ADD_DESC_MAXLEN) {
 			printf("too long partition description\n");
-			return 1;
+			return CMD_RET_FAILURE;
 		}
 		sprintf(tmpbuf, "%s:%s(%s)%s",
 				id->mtd_id, argv[3], argv[4], argv[5] ? argv[5] : "");
@@ -2031,7 +2031,7 @@ static int do_mtdparts(struct cmd_tbl *cmdtp, int flag, int argc,
 
 #if defined(CONFIG_CMD_MTDPARTS_SPREAD)
 		if (get_mtd_info(dev->id->type, dev->id->num, &mtd))
-			return 1;
+			return CMD_RET_FAILURE;
 
 		if (!strcmp(&argv[1][3], ".spread")) {
 			spread_partition(mtd, p, &next_offset);
@@ -2045,12 +2045,12 @@ static int do_mtdparts(struct cmd_tbl *cmdtp, int flag, int argc,
 		} else if (part_add(dev_tmp, p) != 0) {
 			/* merge new partition with existing ones*/
 			device_del(dev);
-			return 1;
+			return CMD_RET_FAILURE;
 		}
 
 		if (generate_mtdparts_save(last_parts, MTDPARTS_MAXLEN) != 0) {
 			printf("generated mtdparts too long, resetting to null\n");
-			return 1;
+			return CMD_RET_FAILURE;
 		}
 
 		return 0;
Signature · 1 line
2.30.1
#10 lore raw

PATCH v2 9/14 jffs2: use negative error codes

In reply to Alexey Romanov

It is bad practice to use such error codes. Error codes must be negative.

---
 cmd/jffs2.c | 29 +++++++++++++++--------------
 1 file changed, 15 insertions(+), 14 deletions(-)
cmd/jffs2.c +15 -14
index e00fcc2022..15bf8c0edf 100644
@@ -151,7 +151,7 @@ extern int cramfs_info (struct part_info *info);
  * Check device number to be within valid range for given device type.
  *
  * @param dev device to validate
- * Return: 0 if device is valid, 1 otherwise
+ * Return: 0 if device is valid, -errno otherwise
  */
 static int mtd_device_validate(u8 type, u8 num, u32 *size)
 {
@@ -191,7 +191,7 @@ static int mtd_device_validate(u8 type, u8 num, u32 *size)
 	} else
 		printf("Unknown defice type %d\n", type);
 
-	return 1;
+	return -EINVAL;
 }
 
 /**
@@ -202,7 +202,7 @@ static int mtd_device_validate(u8 type, u8 num, u32 *size)
  * @param ret_id output pointer to next char after parse completes (output)
  * @param dev_type parsed device type (output)
  * @param dev_num parsed device number (output)
- * Return: 0 on success, 1 otherwise
+ * Return: 0 on success, -errno otherwise
  */
 static int mtd_id_parse(const char *id, const char **ret_id, u8 *dev_type, u8 *dev_num)
 {
@@ -220,12 +220,12 @@ static int mtd_id_parse(const char *id, const char **ret_id, u8 *dev_type, u8 *d
 		p += 7;
 	} else {
 		printf("incorrect device type in %s\n", id);
-		return 1;
+		return -EINVAL;
 	}
 
 	if (!isdigit(*p)) {
 		printf("incorrect device number in %s\n", id);
-		return 1;
+		return -EINVAL;
 	}
 
 	*dev_num = simple_strtoul(p, (char **)&p, 0);
@@ -328,7 +328,7 @@ static inline u32 get_part_sector_size(struct mtdids *id, struct part_info *part
  * 'Static' version of command line mtdparts_init() routine. Single partition on
  * a single device configuration.
  *
- * Return: 0 on success, 1 otherwise
+ * Return: 0 on success, -errno otherwise
  */
 int mtdparts_init(void)
 {
@@ -348,7 +348,7 @@ int mtdparts_init(void)
 					sizeof(struct mtdids));
 		if (!current_mtd_dev) {
 			printf("out of memory\n");
-			return 1;
+			return -ENOMEM;
 		}
 		memset(current_mtd_dev, 0, sizeof(struct mtd_device) +
 		       sizeof(struct part_info) + sizeof(struct mtdids));
@@ -365,7 +365,7 @@ int mtdparts_init(void)
 				(mtd_device_validate(id->type, id->num, &size) != 0)) {
 			printf("incorrect device: %s%d\n", MTD_DEV_TYPE(id->type), id->num);
 			free(current_mtd_dev);
-			return 1;
+			return -EINVAL;
 		}
 		id->size = size;
 		INIT_LIST_HEAD(&id->link);
@@ -500,15 +500,16 @@ int do_jffs2_fsload(struct cmd_tbl *cmdtp, int flag, int argc,
 			size = jffs2_1pass_load((char *)offset, part, filename);
 		}
 
-		if (size > 0) {
-			printf("### %s load complete: %d bytes loaded to 0x%lx\n",
-				fsname, size, offset);
-			env_set_hex("filesize", size);
-		} else {
+		if (size <= 0) {
 			printf("### %s LOAD ERROR<%x> for %s!\n", fsname, size, filename);
+			return 1;
 		}
 
-		return !(size > 0);
+		printf("### %s load complete: %d bytes loaded to 0x%lx\n",
+			fsname, size, offset);
+		env_set_hex("filesize", size);
+
+		return 0;
 	}
 	return 1;
 }
Signature · 1 line
2.30.1
#11 lore raw

PATCH v2 10/14 jffs2: use CMD_RET_FAILURE/SUCCESS defines

In reply to Alexey Romanov

Use CMD_RET_FAILURE and CMD_RET_SUCCESS defines instead of 1 and 0.

---
 cmd/jffs2.c | 20 ++++++++++----------
 1 file changed, 10 insertions(+), 10 deletions(-)
cmd/jffs2.c +10 -10
index 15bf8c0edf..d5aa9bcc7e 100644
@@ -485,7 +485,7 @@ int do_jffs2_fsload(struct cmd_tbl *cmdtp, int flag, int argc,
 
 	/* make sure we are in sync with env variables */
 	if (mtdparts_init() !=0)
-		return 1;
+		return CMD_RET_FAILURE;
 
 	if ((part = jffs2_part_info(current_mtd_dev, current_mtd_partnum))){
 
@@ -502,16 +502,16 @@ int do_jffs2_fsload(struct cmd_tbl *cmdtp, int flag, int argc,
 
 		if (size <= 0) {
 			printf("### %s LOAD ERROR<%x> for %s!\n", fsname, size, filename);
-			return 1;
+			return CMD_RET_FAILURE;
 		}
 
 		printf("### %s load complete: %d bytes loaded to 0x%lx\n",
 			fsname, size, offset);
 		env_set_hex("filesize", size);
 
-		return 0;
+		return CMD_RET_SUCCESS;
 	}
-	return 1;
+	return CMD_RET_FAILURE;
 }
 
 /**
@@ -535,7 +535,7 @@ int do_jffs2_ls(struct cmd_tbl *cmdtp, int flag, int argc, char *const argv[])
 
 	/* make sure we are in sync with env variables */
 	if (mtdparts_init() !=0)
-		return 1;
+		return CMD_RET_FAILURE;
 
 	if ((part = jffs2_part_info(current_mtd_dev, current_mtd_partnum))){
 
@@ -547,9 +547,9 @@ int do_jffs2_ls(struct cmd_tbl *cmdtp, int flag, int argc, char *const argv[])
 			ret = jffs2_1pass_ls(part, filename);
 		}
 
-		return ret ? 0 : 1;
+		return ret ? CMD_RET_SUCCESS : CMD_RET_FAILURE;
 	}
-	return 1;
+	return CMD_RET_FAILURE;
 }
 
 /**
@@ -571,7 +571,7 @@ int do_jffs2_fsinfo(struct cmd_tbl *cmdtp, int flag, int argc,
 
 	/* make sure we are in sync with env variables */
 	if (mtdparts_init() !=0)
-		return 1;
+		return CMD_RET_FAILURE;
 
 	if ((part = jffs2_part_info(current_mtd_dev, current_mtd_partnum))){
 
@@ -586,9 +586,9 @@ int do_jffs2_fsinfo(struct cmd_tbl *cmdtp, int flag, int argc,
 			ret = jffs2_1pass_info(part);
 		}
 
-		return ret ? 0 : 1;
+		return ret ? CMD_RET_SUCCESS : CMD_RET_FAILURE;
 	}
-	return 1;
+	return CMD_RET_FAILURE;
 }
 
 /***************************************************/
Signature · 1 line
2.30.1
#12 lore raw

PATCH v2 11/14 cmd: allow to enable CMD_NAND for SPI NAND devices

In reply to Alexey Romanov

Boards with SPI NAND also can use this command.

---
 cmd/Kconfig | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)
cmd/Kconfig +1 -1
index 26aeeeed03..4332894184 100644
@@ -1381,7 +1381,7 @@ config CMD_MUX
 config CMD_NAND
 	bool "nand"
 	default y if NAND_SUNXI
-	depends on MTD_RAW_NAND
+	depends on MTD_RAW_NAND || MTD_SPI_NAND
 	help
 	  NAND support.
 
Signature · 1 line
2.30.1
#13 lore raw

PATCH v2 12/14 fastboot: check device type for SPI NAND too

In reply to Alexey Romanov

SPI NAND devices also supports 'fastboot erase / flash' commands.

---
 drivers/fastboot/fb_nand.c | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)
drivers/fastboot/fb_nand.c +1 -1
index bbe26ddcc9..6d94bfdc45 100644
@@ -54,7 +54,7 @@ static int fb_nand_lookup(const char *partname,
 		return ret;
 	}
 
-	if (dev->id->type != MTD_DEV_TYPE_NAND) {
+	if (dev->id->type != MTD_DEV_TYPE_NAND && dev->id->type != MTD_DEV_TYPE_SPINAND) {
 		pr_err("partition '%s' is not stored on a NAND device",
 		      partname);
 		fastboot_fail("not a NAND device", response);
Signature · 1 line
2.30.1
#14 lore raw

PATCH v2 13/14 fastboot: enable FASTBOOT_FLASH option for SPI NAND devices

In reply to Alexey Romanov

From now we can use FASTBOOT_FLASH_NAND option for SPI NAND.

---
 drivers/fastboot/Kconfig | 4 ++--
 1 file changed, 2 insertions(+), 2 deletions(-)
drivers/fastboot/Kconfig +2 -2
index 11fc0fe1c8..733dedb30d 100644
@@ -87,7 +87,7 @@ config FASTBOOT_USB_DEV
 config FASTBOOT_FLASH
 	bool "Enable FASTBOOT FLASH command"
 	default y if ARCH_SUNXI || ARCH_ROCKCHIP
-	depends on MMC || (MTD_RAW_NAND && CMD_MTDPARTS)
+	depends on MMC || ((MTD_RAW_NAND || MTD_SPI_NAND) && CMD_MTDPARTS)
 	select IMAGE_SPARSE
 	help
 	  The fastboot protocol includes a "flash" command for writing
@@ -113,7 +113,7 @@ config FASTBOOT_FLASH_MMC
 
 config FASTBOOT_FLASH_NAND
 	bool "FASTBOOT on NAND"
-	depends on MTD_RAW_NAND && CMD_MTDPARTS
+	depends on (MTD_RAW_NAND || MTD_SPI_NAND) && CMD_MTDPARTS
 
 endchoice
 
Signature · 1 line
2.30.1
#15 lore raw

PATCH v2 14/14 fastboot: fb_nand: add missing newlines in pr_err() macro

In reply to Alexey Romanov

pr_err() doesn't add an newline symbol when printing.

---
 drivers/fastboot/fb_nand.c | 10 +++++-----
 1 file changed, 5 insertions(+), 5 deletions(-)
drivers/fastboot/fb_nand.c +5 -5
index 6d94bfdc45..6516c4ef29 100644
@@ -49,13 +49,13 @@ static int fb_nand_lookup(const char *partname,
 
 	ret = find_dev_and_part(partname, &dev, &pnum, part);
 	if (ret) {
-		pr_err("cannot find partition: '%s'", partname);
+		pr_err("cannot find partition: '%s'\n", partname);
 		fastboot_fail("cannot find partition", response);
 		return ret;
 	}
 
 	if (dev->id->type != MTD_DEV_TYPE_NAND && dev->id->type != MTD_DEV_TYPE_SPINAND) {
-		pr_err("partition '%s' is not stored on a NAND device",
+		pr_err("partition '%s' is not stored on a NAND device\n",
 		      partname);
 		fastboot_fail("not a NAND device", response);
 		return -EINVAL;
@@ -179,7 +179,7 @@ void fastboot_nand_flash_write(const char *cmd, void *download_buffer,
 
 	ret = fb_nand_lookup(cmd, &mtd, &part, response);
 	if (ret) {
-		pr_err("invalid NAND device");
+		pr_err("invalid NAND device\n");
 		fastboot_fail("invalid NAND device", response);
 		return;
 	}
@@ -243,7 +243,7 @@ void fastboot_nand_erase(const char *cmd, char *response)
 
 	ret = fb_nand_lookup(cmd, &mtd, &part, response);
 	if (ret) {
-		pr_err("invalid NAND device");
+		pr_err("invalid NAND device\n");
 		fastboot_fail("invalid NAND device", response);
 		return;
 	}
@@ -254,7 +254,7 @@ void fastboot_nand_erase(const char *cmd, char *response)
 
 	ret = _fb_nand_erase(mtd, part);
 	if (ret) {
-		pr_err("failed erasing from device %s", mtd->name);
+		pr_err("failed erasing from device %s\n", mtd->name);
 		fastboot_fail("failed erasing from device", response);
 		return;
 	}
Signature · 1 line
2.30.1
#16 lore raw
In reply to Alexey Romanov

Hi Alexey,

Quoted 47 lines · Alexey Romanov

Currently, fastboot in U-Boot doens't support SPI NAND devices. This patchset adds support for SPI NAND in fastboot nand subsystem.

Changes V1 -> V2:

- Rebase patchset over u-boot/next.
- Move nand_unregister(), nand_reinit() and nang_page_size() functions to NAND core folder too.
- Move changes about CMD_RET_FAILURE/SUCCESS into separate patches.

Alexey Romanov (14):
nand: move NAND initialization API to nand/core.c
nand: don't overwrite mtd name in nand_register()
nand: move nand_util.c to NAND core folder
nand: move nand_erase_opts() to core NAND folder
spi: add board_nand_init() function
spi: use nand_register() instead of add_mtd_device()
mtdparts: use negative error codes
mtdparts: use CMD_RET_FAILURE define
jffs2: use negative error codes
jffs2: use CMD_RET_FAILURE/SUCCESS defines
cmd: allow to enable CMD_NAND for SPI NAND devices
fastboot: check device type for SPI NAND too
fastboot: enable FASTBOOT_FLASH option for SPI NAND devices
fastboot: fb_nand: add missing newlines in pr_err() macro

 cmd/Kconfig                      |   2 +-
 cmd/jffs2.c                      |  45 +-
 cmd/mtdparts.c                   | 154 +++----
 drivers/fastboot/Kconfig         |   4 +-
 drivers/fastboot/fb_nand.c       |  12 +-
 drivers/mtd/Kconfig              |   2 +-
 drivers/mtd/nand/Kconfig         |  10 +
 drivers/mtd/nand/Makefile        |   2 +-
 drivers/mtd/nand/core.c          | 193 +++++++++
 drivers/mtd/nand/raw/Kconfig     |  10 -
 drivers/mtd/nand/raw/nand.c      | 182 --------
 drivers/mtd/nand/raw/nand_util.c | 664 -----------------------------
 drivers/mtd/nand/spi/Kconfig     |   1 +
 drivers/mtd/nand/spi/core.c      |  17 +-
 drivers/mtd/nand/util.c          | 709 +++++++++++++++++++++++++++++++
 include/nand.h                   |   2 +
 16 files changed, 1042 insertions(+), 967 deletions(-)
 create mode 100644 drivers/mtd/nand/util.c
Quoted 3 lines

--
2.30.1

The series doesn't pass te CI tests.
Following an example of errors :

Building current source for 1 boards (1 thread, 64 jobs per thread) 59 sandbox: + sandbox
60+/usr/bin/ld: /tmp/ccyLvZ90.ltrans5.ltrans.o: in function `set_dev':
61+cmd/nand.c:239: undefined reference to get_nand_dev_by_index' 62+/usr/bin/ld: cmd/nand.c:244: undefined reference to nand_curr_device' 63+/usr/bin/ld: /tmp/ccyLvZ90.ltrans5.ltrans.o: in function `nand_print_and_set_info':
64+cmd/nand.c:411: undefined reference to get_nand_dev_by_index' 65+/usr/bin/ld: /tmp/ccyLvZ90.ltrans5.ltrans.o: in function nand_load_image':
66+cmd/nand.c:1002: undefined reference to nand_read_skip_bad' 67+/usr/bin/ld: cmd/nand.c:1037: undefined reference to nand_read_skip_bad' 68+/usr/bin/ld: /tmp/ccyLvZ90.ltrans5.ltrans.o: in function `do_nand':
69+cmd/nand.c:511: undefined reference to nand_curr_device' 70+/usr/bin/ld: cmd/nand.c:563: undefined reference to get_nand_dev_by_index' 71+/usr/bin/ld: cmd/nand.c:635: undefined reference to get_nand_dev_by_index' 72+/usr/bin/ld: cmd/nand.c:657: undefined reference to nand_erase_opts' 73+/usr/bin/ld: cmd/nand.c:705: undefined reference to get_nand_dev_by_index' 74+/usr/bin/ld: cmd/nand.c:480: undefined reference to get_nand_dev_by_index' 75+/usr/bin/ld: cmd/nand.c:734: undefined reference to get_nand_dev_by_index' 76+/usr/bin/ld: cmd/nand.c:740: undefined reference to nand_read_skip_bad' 77+/usr/bin/ld: cmd/nand.c:743: undefined reference to nand_write_skip_bad' 78+/usr/bin/ld: cmd/nand.c:456: undefined reference to nand_verify_page_oob' 79+/usr/bin/ld: /tmp/ccyLvZ90.ltrans5.ltrans.o: in function `do_nandboot':
80+cmd/nand.c:1093: undefined reference to get_nand_dev_by_index' 81+/usr/bin/ld: cmd/nand.c:1137: undefined reference to get_nand_dev_by_index' 82+/usr/bin/ld: /tmp/ccyLvZ90.ltrans8.ltrans.o: in function `initr_nand.lto_priv.0':
83+common/board_r.c:370: undefined reference to nand_init' 84+/usr/bin/ld: common/board_r.c:371: undefined reference to nand_size' 85+/usr/bin/ld: /tmp/ccyLvZ90.ltrans14.ltrans.o: in function `sand_nand_remove':
86+drivers/mtd/nand/raw/sand_nand.c:462: undefined reference to `nand_unregister'
87+/usr/bin/ld: /tmp/ccyLvZ90.ltrans14.ltrans.o: in function `sand_nand_probe':
88+drivers/mtd/nand/raw/sand_nand.c:628: undefined reference to nand_register' 89+/usr/bin/ld: /tmp/ccyLvZ90.ltrans41.ltrans.o: in function dm_test_nand':
90+test/dm/nand.c:31: undefined reference to get_nand_dev_by_index' 91+/usr/bin/ld: test/dm/nand.c:51: undefined reference to nand_erase_opts' 92+/usr/bin/ld: test/dm/nand.c:55: undefined reference to nand_read_skip_bad' 93+/usr/bin/ld: test/dm/nand.c:68: undefined reference to nand_write_skip_bad' 94+/usr/bin/ld: test/dm/nand.c:73: undefined reference to nand_read_skip_bad' 95+/usr/bin/ld: test/dm/nand.c:81: undefined reference to nand_erase_opts' 96+/usr/bin/ld: test/dm/nand.c:84: undefined reference to `nand_read_skip_bad' 97+collect2: error: ld returned 1 exit status
98+make[1]: *** [Makefile:1766: u-boot] Error 1
99+make: *** [Makefile:177: sub-make] Error 2
100 0 0 1 /1 sandbox

Please fix the errors.

Thanks and regards,
Dario

Signature · 17 lines
Dario Binacchi

Senior Embedded Linux Developer

[email protected]

__________________________________


Amarula Solutions SRL

Via Le Canevare 30, 31100 Treviso, Veneto, IT

T. +39 042 243 5310
[email protected]

www.amarulasolutions.com