Skip to contentSkip to conversation

SPL:Defines function required to env read for IFC & env_nand

RFC New Prabhakar Kushwaha 2 participants 6 messages Sep 16, 2013 – Sep 25, 2013

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

RFC 4/5 SPL:Defines function required to env read for IFC & env_nand

fsl_ifs_spl.c reads data from NAND and store at a memory location in raw mode. It does not used MTD layer.
To read env variable from NAND MTD layer read/write required.

Hence, add mtd_block_isbad & nand_read_skip_bad function required during env variable read.

Also, avoid nand_info during env read for SPL

---
 common/env_nand.c              |    7 ++++---
 drivers/mtd/nand/Makefile      |    2 +-
 drivers/mtd/nand/fsl_ifc_spl.c |   22 ++++++++++++++++++++++
 3 files changed, 27 insertions(+), 4 deletions(-)
common/env_nand.c +4 -3
index 7530962..7a7107f 100644
@@ -246,11 +246,13 @@ int readenv(size_t offset, u_char *buf)
 	u_char *char_ptr;
 
 	blocksize = nand_info[0].erasesize;
+#ifndef CONFIG_SPL_BUILD
 	if (!blocksize)
 		return 1;
-
 	len = min(blocksize, CONFIG_ENV_SIZE);
-
+#else
+	len = CONFIG_ENV_SIZE;
+#endif
 	while (amount_loaded < CONFIG_ENV_SIZE && offset < end) {
 		if (nand_block_isbad(&nand_info[0], offset)) {
 			offset += blocksize;
@@ -396,7 +398,6 @@ void env_relocate_spec(void)
 		return;
 	}
 #endif
-
 	ret = readenv(CONFIG_ENV_OFFSET, (u_char *)buf);
 	if (ret) {
 		set_default_env("!readenv() failed");
drivers/mtd/nand/Makefile +1 -1
index 366dee6..06d5d14 100644
@@ -24,6 +24,7 @@ COBJS-$(CONFIG_SPL_NAND_LOAD) += nand_spl_load.o
 COBJS-$(CONFIG_SPL_NAND_ECC) += nand_ecc.o
 COBJS-$(CONFIG_SPL_NAND_BASE) += nand_base.o
 COBJS-$(CONFIG_SPL_NAND_INIT) += nand.o
+COBJS-$(CONFIG_NAND_FSL_IFC) += fsl_ifc_spl.o
 
 else # not spl
 
@@ -68,7 +69,6 @@ COBJS-$(CONFIG_NAND_DOCG4) += docg4.o
 else  # minimal SPL drivers
 
 COBJS-$(CONFIG_NAND_FSL_ELBC) += fsl_elbc_spl.o
-COBJS-$(CONFIG_NAND_FSL_IFC) += fsl_ifc_spl.o
 COBJS-$(CONFIG_NAND_MXC) += mxc_nand_spl.o
 
 endif # drivers
drivers/mtd/nand/fsl_ifc_spl.c +22 -0
index d462265..e7edacf 100644
@@ -11,6 +11,28 @@
 #include <asm/io.h>
 #include <asm/fsl_ifc.h>
 #include <linux/mtd/nand.h>
+#ifndef CONFIG_SPL_INIT_MINIMAL
+#include <linux/mtd/mtd.h>
+#endif
+
+static void nand_load(unsigned int offs, int uboot_size, uchar *dst);
+
+#ifndef CONFIG_SPL_INIT_MINIMAL
+struct mtd_info nand_info[CONFIG_SYS_MAX_NAND_DEVICE];
+
+int mtd_block_isbad(struct mtd_info *mtd, loff_t ofs)
+{
+	return 0;
+}
+
+int nand_read_skip_bad(struct mtd_info *nand, loff_t offset, size_t *length,
+		size_t *actual, loff_t lim, u_char *buffer)
+{
+	nand_load(offset, *length, buffer);
+	return 0;
+}
+#endif
+
 
 static inline int is_blank(uchar *addr, int page_size)
 {
Signature · 1 line
1.7.9.5
#1 lore raw

RFC 4/5 SPL:Defines function required to env read for IFC & env_nand

Quoted 23 lines · Prabhakar Kushwaha

fsl_ifs_spl.c reads data from NAND and store at a memory location in raw mode. It does not used MTD layer.
To read env variable from NAND MTD layer read/write required.

Hence, add mtd_block_isbad & nand_read_skip_bad function required during env variable read.

Also, avoid nand_info during env read for SPL

---
 common/env_nand.c              |    7 ++++---
 drivers/mtd/nand/Makefile      |    2 +-
 drivers/mtd/nand/fsl_ifc_spl.c |   22 ++++++++++++++++++++++
 3 files changed, 27 insertions(+), 4 deletions(-)
common/env_nand.c +0 -0
index 7530962..7a7107f 100644
@@ -246,11 +246,13 @@ int readenv(size_t offset, u_char *buf)
 	u_char *char_ptr;
 

common/env_nand.c int readenv(size_t offset, u_char *buf) · line 255

Quoted 10 lines
common/env_nand.c +4 -2
 	blocksize = nand_info[0].erasesize;
+#ifndef CONFIG_SPL_BUILD
 	if (!blocksize)
 		return 1;
-
 	len = min(blocksize, CONFIG_ENV_SIZE);
-
+#else
+	len = CONFIG_ENV_SIZE;
+#endif

Use positive logic (ifdef/else, not ifndef/else).

Are you sure that CONFIG_ENV_SIZE will always be appropriate? Shouldn't you use CONFIG_SYS_NAND_BLOCK_SIZE in place of nand_info[0].erasesize?

common/env_nand.c void env_relocate_spec(void) · line 403

Quoted 8 lines
common/env_nand.c +0 -1
@@ -396,7 +398,6 @@ void env_relocate_spec(void)
 		return;
 	}
 #endif
-
 	ret = readenv(CONFIG_ENV_OFFSET, (u_char *)buf);
 	if (ret) {
 		set_default_env("!readenv() failed");

Remove unrelated whitespace changes.

drivers/mtd/nand/Makefile COBJS-$(CONFIG_SPL_NAND_LOAD) += nand_spl_load.o · line 27

Quoted 9 lines
drivers/mtd/nand/Makefile +1 -0
index 366dee6..06d5d14 100644
@@ -24,6 +24,7 @@ COBJS-$(CONFIG_SPL_NAND_LOAD) += nand_spl_load.o
 COBJS-$(CONFIG_SPL_NAND_ECC) += nand_ecc.o
 COBJS-$(CONFIG_SPL_NAND_BASE) += nand_base.o
 COBJS-$(CONFIG_SPL_NAND_INIT) += nand.o
+COBJS-$(CONFIG_NAND_FSL_IFC) += fsl_ifc_spl.o

No, it's still a minimal NAND driver (i.e. it doesn't use fsl_ifc.o). Minimal NAND drivers are not related to minimal SPL init.

Quoted 19 lines
drivers/mtd/nand/fsl_ifc_spl.c +11 -0
index d462265..e7edacf 100644
@@ -11,6 +11,28 @@
 #include <asm/io.h>
 #include <asm/fsl_ifc.h>
 #include <linux/mtd/nand.h>
+#ifndef CONFIG_SPL_INIT_MINIMAL
+#include <linux/mtd/mtd.h>
+#endif
+
+static void nand_load(unsigned int offs, int uboot_size, uchar *dst);
+
+#ifndef CONFIG_SPL_INIT_MINIMAL
+struct mtd_info nand_info[CONFIG_SYS_MAX_NAND_DEVICE];
+
+int mtd_block_isbad(struct mtd_info *mtd, loff_t ofs)
+{

drivers/mtd/nand/fsl_ifc_spl.c line 34

Quoted 10 lines
drivers/mtd/nand/fsl_ifc_spl.c +10 -0
+	return 0;
+}
+
+int nand_read_skip_bad(struct mtd_info *nand, loff_t offset, size_t *length,
+		size_t *actual, loff_t lim, u_char *buffer)
+{
+	nand_load(offset, *length, buffer);
+	return 0;
+}
+#endif

What does this have to do with minimal init?

-Scott

#2 lore raw

RFC 4/5 SPL:Defines function required to env read for IFC & env_nand

Thanks Scott for taking time and reviewing the RFC patch.

Please find my reply in-lined.

Quoted 24 lines · Scott Wood
Quoted 23 lines · Prabhakar Kushwaha

fsl_ifs_spl.c reads data from NAND and store at a memory location in raw mode. It does not used MTD layer.
To read env variable from NAND MTD layer read/write required.

Hence, add mtd_block_isbad & nand_read_skip_bad function required during env variable read.

Also, avoid nand_info during env read for SPL

---
  common/env_nand.c              |    7 ++++---
  drivers/mtd/nand/Makefile      |    2 +-
  drivers/mtd/nand/fsl_ifc_spl.c |   22 ++++++++++++++++++++++
  3 files changed, 27 insertions(+), 4 deletions(-)
common/env_nand.c +0 -0
index 7530962..7a7107f 100644
@@ -246,11 +246,13 @@ int readenv(size_t offset, u_char *buf)
  	u_char *char_ptr;
 
Quoted 11 lines

common/env_nand.c int readenv(size_t offset, u_char *buf) · line 255

Quoted 10 lines
common/env_nand.c +4 -2
  	blocksize = nand_info[0].erasesize;
+#ifndef CONFIG_SPL_BUILD
  	if (!blocksize)
  		return 1;
-
  	len = min(blocksize, CONFIG_ENV_SIZE);
-
+#else
+	len = CONFIG_ENV_SIZE;
+#endif

Use positive logic (ifdef/else, not ifndef/else).

I will fix it.

Quoted 2 lines

Are you sure that CONFIG_ENV_SIZE will always be appropriate? Shouldn't you use CONFIG_SYS_NAND_BLOCK_SIZE in place of nand_info[0].erasesize?

I can use CONFIG_SYS_NAND_BLOCK_SIZE . but i can not use in SPL as its is defined as 128K.

Quoted 9 lines

common/env_nand.c void env_relocate_spec(void) · line 403

Quoted 8 lines
common/env_nand.c +0 -1
@@ -396,7 +398,6 @@ void env_relocate_spec(void)
  		return;
  	}
  #endif
-
  	ret = readenv(CONFIG_ENV_OFFSET, (u_char *)buf);
  	if (ret) {
  		set_default_env("!readenv() failed");

Remove unrelated whitespace changes.

Sure

Quoted 11 lines

drivers/mtd/nand/Makefile COBJS-$(CONFIG_SPL_NAND_LOAD) += nand_spl_load.o · line 27

Quoted 9 lines
drivers/mtd/nand/Makefile +1 -0
index 366dee6..06d5d14 100644
@@ -24,6 +24,7 @@ COBJS-$(CONFIG_SPL_NAND_LOAD) += nand_spl_load.o
  COBJS-$(CONFIG_SPL_NAND_ECC) += nand_ecc.o
  COBJS-$(CONFIG_SPL_NAND_BASE) += nand_base.o
  COBJS-$(CONFIG_SPL_NAND_INIT) += nand.o
+COBJS-$(CONFIG_NAND_FSL_IFC) += fsl_ifc_spl.o

No, it's still a minimal NAND driver (i.e. it doesn't use fsl_ifc.o). Minimal NAND drivers are not related to minimal SPL init.

I will take care of it

Quoted 22 lines
Quoted 22 lines
drivers/mtd/nand/fsl_ifc_spl.c +14 -0
index d462265..e7edacf 100644
@@ -11,6 +11,28 @@
  #include <asm/io.h>
  #include <asm/fsl_ifc.h>
  #include <linux/mtd/nand.h>
+#ifndef CONFIG_SPL_INIT_MINIMAL
+#include <linux/mtd/mtd.h>
+#endif
+
+static void nand_load(unsigned int offs, int uboot_size, uchar *dst);
+
+#ifndef CONFIG_SPL_INIT_MINIMAL
+struct mtd_info nand_info[CONFIG_SYS_MAX_NAND_DEVICE];
+
+int mtd_block_isbad(struct mtd_info *mtd, loff_t ofs)
+{
+	return 0;
+}
+
Quoted 8 lines

drivers/mtd/nand/fsl_ifc_spl.c line 34

Quoted 7 lines
drivers/mtd/nand/fsl_ifc_spl.c +7 -0
+int nand_read_skip_bad(struct mtd_info *nand, loff_t offset, size_t *length,
+		size_t *actual, loff_t lim, u_char *buffer)
+{
+	nand_load(offset, *length, buffer);
+	return 0;
+}
+#endif

What does this have to do with minimal init?

This has nothing to do with minimal init.
These function will comes into during CONFIG_SPL_BUILD and !defined CONFIG_SPL_INIT_MINIMAL.

These function will be used for reading env variables.

Regards,
Prabhakar

#3 lore raw

RFC 4/5 SPL:Defines function required to env read for IFC & env_nand

Quoted 41 lines · Prabhakar Kushwaha

Thanks Scott for taking time and reviewing the RFC patch.

Please find my reply in-lined.

Quoted 24 lines · Scott Wood
Quoted 23 lines · Prabhakar Kushwaha

fsl_ifs_spl.c reads data from NAND and store at a memory location in raw mode. It does not used MTD layer.
To read env variable from NAND MTD layer read/write required.

Hence, add mtd_block_isbad & nand_read_skip_bad function required during env variable read.

Also, avoid nand_info during env read for SPL

---
  common/env_nand.c              |    7 ++++---
  drivers/mtd/nand/Makefile      |    2 +-
  drivers/mtd/nand/fsl_ifc_spl.c |   22 ++++++++++++++++++++++
  3 files changed, 27 insertions(+), 4 deletions(-)
common/env_nand.c +0 -0
index 7530962..7a7107f 100644
@@ -246,11 +246,13 @@ int readenv(size_t offset, u_char *buf)
  	u_char *char_ptr;
 
Quoted 11 lines

common/env_nand.c int readenv(size_t offset, u_char *buf) · line 255

Quoted 10 lines
common/env_nand.c +4 -2
  	blocksize = nand_info[0].erasesize;
+#ifndef CONFIG_SPL_BUILD
  	if (!blocksize)
  		return 1;
-
  	len = min(blocksize, CONFIG_ENV_SIZE);
-
+#else
+	len = CONFIG_ENV_SIZE;
+#endif

Use positive logic (ifdef/else, not ifndef/else).

Quoted 7 lines

I will fix it.

Quoted 2 lines

Are you sure that CONFIG_ENV_SIZE will always be appropriate? Shouldn't you use CONFIG_SYS_NAND_BLOCK_SIZE in place of nand_info[0].erasesize?

I can use CONFIG_SYS_NAND_BLOCK_SIZE . but i can not use in SPL as its is defined as 128K.

You can't redefine the block size to suit your needs. It's a property of the hardware. What difference does it make, as long as CONFIG_ENV_SIZE is smaller?

Quoted 16 lines
Quoted 8 lines
Quoted 8 lines
common/env_nand.c +8 -0
+#ifndef CONFIG_SPL_INIT_MINIMAL
+struct mtd_info nand_info[CONFIG_SYS_MAX_NAND_DEVICE];
+
+int mtd_block_isbad(struct mtd_info *mtd, loff_t ofs)
+{
+	return 0;
+}
+
Quoted 8 lines

common/env_nand.c

Quoted 7 lines
common/env_nand.c +7 -0
+int nand_read_skip_bad(struct mtd_info *nand, loff_t offset, size_t *length,
+		size_t *actual, loff_t lim, u_char *buffer)
+{
+	nand_load(offset, *length, buffer);
+	return 0;
+}
+#endif

What does this have to do with minimal init?

Quoted 1 line

This has nothing to do with minimal init.

Then what does it have to do with CONFIG_SPL_INIT_MINIMAL, which is specifically for configuring minimial init?

Quoted 4 lines

These function will comes into during CONFIG_SPL_BUILD and !defined CONFIG_SPL_INIT_MINIMAL.

These function will be used for reading env variables.

Then use some SPL symbol indicating environment support is needed.

-Scott

#4 lore raw

RFC 4/5 SPL:Defines function required to env read for IFC & env_nand

Quoted 43 lines · Scott Wood
Quoted 42 lines · Prabhakar Kushwaha

Thanks Scott for taking time and reviewing the RFC patch.

Please find my reply in-lined.

Quoted 24 lines · Scott Wood
Quoted 23 lines · Prabhakar Kushwaha

fsl_ifs_spl.c reads data from NAND and store at a memory location in raw mode. It does not used MTD layer.
To read env variable from NAND MTD layer read/write required.

Hence, add mtd_block_isbad & nand_read_skip_bad function required during env variable read.

Also, avoid nand_info during env read for SPL

---
   common/env_nand.c              |    7 ++++---
   drivers/mtd/nand/Makefile      |    2 +-
   drivers/mtd/nand/fsl_ifc_spl.c |   22 ++++++++++++++++++++++
   3 files changed, 27 insertions(+), 4 deletions(-)
common/env_nand.c +0 -0
index 7530962..7a7107f 100644
@@ -246,11 +246,13 @@ int readenv(size_t offset, u_char *buf)
   	u_char *char_ptr;
 
Quoted 11 lines

common/env_nand.c int readenv(size_t offset, u_char *buf) · line 255

Quoted 10 lines
common/env_nand.c +4 -2
   	blocksize = nand_info[0].erasesize;
+#ifndef CONFIG_SPL_BUILD
   	if (!blocksize)
   		return 1;
-
   	len = min(blocksize, CONFIG_ENV_SIZE);
-
+#else
+	len = CONFIG_ENV_SIZE;
+#endif

Use positive logic (ifdef/else, not ifndef/else).

I will fix it.

Quoted 7 lines
Quoted 4 lines
Quoted 2 lines

Are you sure that CONFIG_ENV_SIZE will always be appropriate? Shouldn't you use CONFIG_SYS_NAND_BLOCK_SIZE in place of nand_info[0].erasesize?

I can use CONFIG_SYS_NAND_BLOCK_SIZE . but i can not use in SPL as its is defined as 128K.

You can't redefine the block size to suit your needs. It's a property of the hardware. What difference does it make, as long as CONFIG_ENV_SIZE is smaller?

Earlier code was like
len = min(blocksize, CONFIG_ENV_SIZE) as SPL never defines nand_info.
So the block size is 0.
causing len = 0.

I am avoiding it by setting = CONFIG_ENV_SIZE. No redefinition of block size.

Regards,
Prabhakar

#5 lore raw

RFC 4/5 SPL:Defines function required to env read for IFC & env_nand

Quoted 51 lines · Prabhakar Kushwaha
Quoted 43 lines · Scott Wood
Quoted 42 lines · Prabhakar Kushwaha

Thanks Scott for taking time and reviewing the RFC patch.

Please find my reply in-lined.

Quoted 24 lines · Scott Wood
Quoted 23 lines · Prabhakar Kushwaha

fsl_ifs_spl.c reads data from NAND and store at a memory location in raw mode. It does not used MTD layer.
To read env variable from NAND MTD layer read/write required.

Hence, add mtd_block_isbad & nand_read_skip_bad function required during env variable read.

Also, avoid nand_info during env read for SPL

---
   common/env_nand.c              |    7 ++++---
   drivers/mtd/nand/Makefile      |    2 +-
   drivers/mtd/nand/fsl_ifc_spl.c |   22 ++++++++++++++++++++++
   3 files changed, 27 insertions(+), 4 deletions(-)
common/env_nand.c +0 -0
index 7530962..7a7107f 100644
@@ -246,11 +246,13 @@ int readenv(size_t offset, u_char *buf)
   	u_char *char_ptr;
 
Quoted 11 lines

common/env_nand.c int readenv(size_t offset, u_char *buf) · line 255

Quoted 10 lines
common/env_nand.c +4 -2
   	blocksize = nand_info[0].erasesize;
+#ifndef CONFIG_SPL_BUILD
   	if (!blocksize)
   		return 1;
-
   	len = min(blocksize, CONFIG_ENV_SIZE);
-
+#else
+	len = CONFIG_ENV_SIZE;
+#endif

Use positive logic (ifdef/else, not ifndef/else).

I will fix it.

Quoted 7 lines
Quoted 4 lines
Quoted 2 lines

Are you sure that CONFIG_ENV_SIZE will always be appropriate? Shouldn't you use CONFIG_SYS_NAND_BLOCK_SIZE in place of nand_info[0].erasesize?

I can use CONFIG_SYS_NAND_BLOCK_SIZE . but i can not use in SPL as its is defined as 128K.

You can't redefine the block size to suit your needs. It's a property of the hardware. What difference does it make, as long as CONFIG_ENV_SIZE is smaller?

Quoted 7 lines

Earlier code was like
len = min(blocksize, CONFIG_ENV_SIZE) as SPL never defines nand_info.
So the block size is 0.
causing len = 0.

I am avoiding it by setting = CONFIG_ENV_SIZE. No redefinition of block size.

This is generic code. It's possible (even if a bit unlikely) that some board has an environment that is larger than the block size. That's why the loop exists in the first place (though I'm not sure why it can't be replaced with a single call to nand_read_skip_bad).

Since your problem is with how you determine the block size, just replace the source of the block size but don't touch the min().

-Scott