[U-Boot] [PATCH 5/5] mtd: spi_flash: preserve Spansion's original value during reboot

2017-09-30 Thread Ahmed Samir Khalil
Spansion flash has QEB in the same status register as well.
Therefore, preserve the original values while rebooting.
Otherwise, some SPI controllers may be unable to access
the flash correctly e.g. receive garbage bytes instead.

Signed-off-by: Ahmed S. Khalil 
---
 drivers/mtd/spi/spi_flash.c | 3 ++-
 1 file changed, 2 insertions(+), 1 deletion(-)

diff --git a/drivers/mtd/spi/spi_flash.c b/drivers/mtd/spi/spi_flash.c
index b6b56fe..2e603ed 100644
--- a/drivers/mtd/spi/spi_flash.c
+++ b/drivers/mtd/spi/spi_flash.c
@@ -984,7 +984,8 @@ int spi_flash_scan(struct spi_flash *flash)
 */
if (JEDEC_MFR(info) == SPI_FLASH_CFI_MFR_ATMEL ||
   (JEDEC_MFR(info) == SPI_FLASH_CFI_MFR_SST) ||
-  (JEDEC_MFR(info) == SPI_FLASH_CFI_MFR_MACRONIX)) {
+  (JEDEC_MFR(info) == SPI_FLASH_CFI_MFR_MACRONIX) ||
+  (JEDEC_MFR(info) == SPI_FLASH_CFI_MFR_SPANSION)) {
u8 sr = 0;
 
if (JEDEC_MFR(info) == SPI_FLASH_CFI_MFR_MACRONIX) {
-- 
2.7.4

___
U-Boot mailing list
U-Boot@lists.denx.de
https://lists.denx.de/listinfo/u-boot


[U-Boot] [PATCH 2/5] mtd: spi_flash: Support clearing status register

2017-09-30 Thread Ahmed Samir Khalil
A function to clear status register-1 after error
flag(s) being triggered.

Signed-off-by: Ahmed S. Khalil 
---
 drivers/mtd/spi/spi_flash.c | 21 +
 1 file changed, 21 insertions(+)

diff --git a/drivers/mtd/spi/spi_flash.c b/drivers/mtd/spi/spi_flash.c
index 34f6888..52dcb84 100644
--- a/drivers/mtd/spi/spi_flash.c
+++ b/drivers/mtd/spi/spi_flash.c
@@ -110,6 +110,27 @@ static int write_cr(struct spi_flash *flash, u8 wc)
 
return 0;
 }
+
+/*
+ * Clear status register-1
+ *
+ * TODO: Check validity for the other flash vendors.
+ */
+static int clear_sr(struct spi_flash *flash)
+{
+   struct spi_slave *spi = flash->spi;
+   u8 cmd, buf;
+   int ret;
+
+   cmd = CMD_CLEAR_STATUS;
+   ret = spi_flash_cmd_write(spi, cmd, 1, buf, 1);
+   if (ret < 0) {
+   debug("SF: fail to clear status register\n");
+   return ret;
+   }
+
+   return ret;
+}
 #endif
 
 #ifdef CONFIG_SPI_FLASH_BAR
-- 
2.7.4

___
U-Boot mailing list
U-Boot@lists.denx.de
https://lists.denx.de/listinfo/u-boot


[U-Boot] [PATCH 3/5] mtd: spi_flash: Clear SR if write/erase error is flagged

2017-09-30 Thread Ahmed Samir Khalil
In case of write or erase error, flags are being
triggered into status register-1. The flags should be
cleared, otherwise they may lead to unstable behavior
for the following operation(s).

Signed-off-by: Ahmed S. Khalil 
---
 drivers/mtd/spi/spi_flash.c | 3 +++
 1 file changed, 3 insertions(+)

diff --git a/drivers/mtd/spi/spi_flash.c b/drivers/mtd/spi/spi_flash.c
index 52dcb84..6f54e10 100644
--- a/drivers/mtd/spi/spi_flash.c
+++ b/drivers/mtd/spi/spi_flash.c
@@ -353,6 +353,9 @@ int spi_flash_cmd_erase_ops(struct spi_flash *flash, u32 
offset, size_t len)
ret = spi_flash_write_common(flash, cmd, sizeof(cmd), NULL, 0);
if (ret < 0) {
debug("SF: erase failed\n");
+#ifdef CONFIG_SPI_FLASH_SPANSION
+   clear_sr(flash);
+#endif
break;
}
 
-- 
2.7.4

___
U-Boot mailing list
U-Boot@lists.denx.de
https://lists.denx.de/listinfo/u-boot


[U-Boot] [PATCH 1/5] mtd: spi: Define CLSR command

2017-09-30 Thread Ahmed Samir Khalil
Define clear status register command to be used
in error handling.

Signed-off-by: Ahmed S. Khalil 
---
 drivers/mtd/spi/sf_internal.h | 3 +++
 1 file changed, 3 insertions(+)

diff --git a/drivers/mtd/spi/sf_internal.h b/drivers/mtd/spi/sf_internal.h
index 839cdbe..42f2b20 100644
--- a/drivers/mtd/spi/sf_internal.h
+++ b/drivers/mtd/spi/sf_internal.h
@@ -71,6 +71,9 @@ enum spi_nor_option_flags {
 # define CMD_EXTNADDR_RDEAR0xC8
 #endif
 
+/* Register access commands */
+#define CMD_CLEAR_STATUS   0x30
+
 /* Common status */
 #define STATUS_WIP BIT(0)
 #define STATUS_QEB_WINSPAN BIT(1)
-- 
2.7.4

___
U-Boot mailing list
U-Boot@lists.denx.de
https://lists.denx.de/listinfo/u-boot


[U-Boot] [PATCH 0/5] Clear error flags & initialization of Spansion

2017-09-30 Thread Ahmed Samir Khalil

This patchset updates serial flash initialization and clear error
flags for Spansion SPI flash.


Testing these patches has been done on S25FL128S and High speed
SPI Controller that do switch back & forth between different modes
(legacy, dual, quad).

* spi_flash_scan: Since Spansion has BP# bits & QEB on the same
register, preserving the original values is recommended.
Otherwise, unstable behavior may occur. e.g. if the last mode
used by the SPI controller was Quad read, while the new scan
should use legacy. In such a case, garbage bytes may be read instead.

* clear_sr: A new function that is used to clear status register-1 of
Spansion when write or erase error occur. Clearing SR is recommended
to avoid problems with the next operation(s), such as Timeout! while
it is already caused by the last operation but not the current one.

TODO: If applicable, the clear_sr() should be done for the other
flash vendors too.

Ahmed Samir Khalil (5):
  mtd: spi: Define CLSR command
  mtd: spi_flash: Support clearing status register
  mtd: spi_flash: Clear SR if write/erase error is flagged
  mtd: spi_flash: Clear SR error flags in case of failed  write
  mtd: spi_flash: preserve Spansion's original value during  reboot

 drivers/mtd/spi/sf_internal.h |  3 +++
 drivers/mtd/spi/spi_flash.c   | 30 +-
 2 files changed, 32 insertions(+), 1 deletion(-)

-- 
2.7.4

___
U-Boot mailing list
U-Boot@lists.denx.de
https://lists.denx.de/listinfo/u-boot


[U-Boot] [PATCH] cmd/nand.c: Remove unnecessarily repeated step

2016-10-11 Thread Ahmed Samir Khalil
Getting the current NAND device is already done once as part
 of nand command. Therefore, repeating this step as part of
 the sub-commands is unnecessary.

Signed-off-by: Ahmed Samir Khalil <engkhali...@gmail.com>
---
 cmd/nand.c | 6 --
 1 file changed, 6 deletions(-)

diff --git a/cmd/nand.c b/cmd/nand.c
index ec7f1df..71ffe85 100644
--- a/cmd/nand.c
+++ b/cmd/nand.c
@@ -528,8 +528,6 @@ static int do_nand(cmd_tbl_t *cmdtp, int flag, int argc, 
char * const argv[])
if (set_dev(dev))
return 1;
 
-   mtd = nand_info[dev];
-
memset(, 0, sizeof(opts));
opts.offset = off;
opts.length = size;
@@ -597,8 +595,6 @@ static int do_nand(cmd_tbl_t *cmdtp, int flag, int argc, 
char * const argv[])
if (set_dev(dev))
return 1;
 
-   mtd = nand_info[dev];
-
if (argc > 4 && !str2long(argv[4], )) {
printf("'%s' is not a number\n", argv[4]);
return 1;
@@ -626,8 +622,6 @@ static int do_nand(cmd_tbl_t *cmdtp, int flag, int argc, 
char * const argv[])
rwsize = size;
}
 
-   mtd = nand_info[dev];
-
if (!s || !strcmp(s, ".jffs2") ||
!strcmp(s, ".e") || !strcmp(s, ".i")) {
if (read)
-- 
2.7.4

___
U-Boot mailing list
U-Boot@lists.denx.de
http://lists.denx.de/mailman/listinfo/u-boot


[U-Boot] [PATCH] cmd/nand.c: Debug additional helpful NAND info

2016-10-11 Thread Ahmed Samir Khalil
While dealing with large chips (e.g. page: 4KB, OOB:224),
 we found it helpful to get these additional NAND info by
 enabling the DEBUG macro instead of full tracing every time
 and consuming time. Especially about the currently in use
 scheme for testing & development.

Signed-off-by: Ahmed Samir Khalil <engkhali...@gmail.com>
---
 cmd/nand.c | 26 ++
 1 file changed, 26 insertions(+)

diff --git a/cmd/nand.c b/cmd/nand.c
index c16ec77..ec7f1df 100644
--- a/cmd/nand.c
+++ b/cmd/nand.c
@@ -283,6 +283,9 @@ usage:
 
 static void nand_print_and_set_info(int idx)
 {
+#ifdef DEBUG
+   unsigned int i;
+#endif
struct mtd_info *mtd = nand_info[idx];
struct nand_chip *chip = mtd_to_nand(mtd);
 
@@ -298,6 +301,29 @@ static void nand_print_and_set_info(int idx)
printf("  options 0x%8x\n", chip->options);
printf("  bbt options 0x%8x\n", chip->bbt_options);
 
+#ifdef DEBUG
+   printf("  Chip delay  %7d us\n", chip->chip_delay);
+   printf("  ECC bytes   %8d b\n", nand->ecclayout->eccbytes);
+   printf("  OOB available %6d b\n\n", nand->ecclayout->oobavail);
+
+   printf("  OOB free = {\n");
+   for (i=0; i < nand->ecclayout->oobfree[i].length; i++) {
+   if( !(nand->ecclayout->oobfree[i].offset<0) )
+   printf("{.offset=%d, ", 
nand->ecclayout->oobfree[i].offset);
+
+   if( !(nand->ecclayout->oobfree[i].length<0) )
+   printf(".length=%d}, \n", 
nand->ecclayout->oobfree[i].length);
+   }
+
+   printf("  };\n\n");
+   printf("  ECC positions = {\n");
+   for (i=0; i < MTD_MAX_ECCPOS_ENTRIES_LARGE; i++) {
+   if(nand->ecclayout->eccpos[i]>0)
+   printf("%d, ", nand->ecclayout->eccpos[i]);
+   }
+   printf("\n  };\n\n");
+#endif
+
/* Set geometry info */
setenv_hex("nand_writesize", mtd->writesize);
setenv_hex("nand_oobsize", mtd->oobsize);
-- 
2.7.4

___
U-Boot mailing list
U-Boot@lists.denx.de
http://lists.denx.de/mailman/listinfo/u-boot


[U-Boot] [PATCH] README: SPI Support: Add & explain undocumented SPI_FLASH options.

2016-06-12 Thread Ahmed Samir Khalil
CONFIG_SPI_FLASH_BAR & CONFIG_SPI_FLASH_MTD are used without
documentation. Documenting these options makes getting startup,
configuration & testing easier.

Signed-off-by: Ahmed Samir Khalil <engkhali...@gmail.com>
---
 README | 10 ++
 1 file changed, 10 insertions(+)

diff --git a/README b/README
index 1d0b946..6c2bea6 100644
--- a/README
+++ b/README
@@ -2689,6 +2689,16 @@ CBFS (Coreboot Filesystem) support
Timeout for waiting until spi transfer completed.
default: (CONFIG_SYS_HZ/100) /* 10 ms */
 
+   CONFIG_SPI_FLASH_BAR
+   change buffer size, so the higher SPI memory bank becomes
+   accessible. This option is for SPI flash with at least two
+   memory banks (usually QSPI larger than 16MiB). For example,
+   check README.ti_qspi_dra_test.
+
+   CONFIG_SPI_FLASH_MTD
+   Register SPI Flash to the MTD subsystem to support mtd
+   partitioning and operations.
+
 - FPGA Support: CONFIG_FPGA
 
Enables FPGA subsystem.
-- 
2.7.4

___
U-Boot mailing list
U-Boot@lists.denx.de
http://lists.denx.de/mailman/listinfo/u-boot


[U-Boot] [PATCH] Drivers: SPI: spi_slave struct has no member called bus nor cs.

2016-06-12 Thread Ahmed Samir Khalil
In case of Driver Model, spi_slave structure (in spi.c) doesn't
have member called bus or cs. Compiler error will be reported
when using the new Driver Model while assigning bus & cs to
non-members. This compiler error becomes obvious while applying
the step-by-step documented in spi-howto.txt

Signed-off-by: Ahmed Samir Khalil <engkhali...@gmail.com>
---
 drivers/spi/spi.c | 2 ++
 1 file changed, 2 insertions(+)

diff --git a/drivers/spi/spi.c b/drivers/spi/spi.c
index 7d81fbd..b02c7ab 100644
--- a/drivers/spi/spi.c
+++ b/drivers/spi/spi.c
@@ -31,8 +31,10 @@ void *spi_do_alloc_slave(int offset, int size, unsigned int 
bus,
if (ptr) {
memset(ptr, '\0', size);
slave = (struct spi_slave *)(ptr + offset);
+#ifndef CONFIG_DM_SPI
slave->bus = bus;
slave->cs = cs;
+#endif
slave->wordlen = SPI_DEFAULT_WORDLEN;
}
 
-- 
2.7.4

___
U-Boot mailing list
U-Boot@lists.denx.de
http://lists.denx.de/mailman/listinfo/u-boot


[U-Boot] [PATCH] README: Device Tree: Add & explain undocumented options.

2016-06-11 Thread Ahmed Samir Khalil
There are no info about these options in the README.
Documenting these options makes getting startup,
configuration & testing easier.

Signed-off-by: Ahmed Samir Khalil <engkhali...@gmail.com>
---
 README | 8 
 1 file changed, 8 insertions(+)

diff --git a/README b/README
index 1d0b946..1c9f778 100644
--- a/README
+++ b/README
@@ -1154,6 +1154,14 @@ The following options need to be configured:
still use the individual files if you need something more
exotic.
 
+   CONFIG_OF_HOSTFILE
+   If this variable is defined, U-Boot will read the device tree
+   from a file on startup. This is only useful for sandbox. You
+   may use either CONFIG_OF_HOSTFILE or CONFIG_OF_CONTROL.
+
+   CONFIG_OF_SPI_FLASH
+   Define to enable setting up a new SPI flash (slave) from an fdt 
node.
+
 - Watchdog:
CONFIG_WATCHDOG
If this variable is defined, it enables watchdog
-- 
2.7.4

___
U-Boot mailing list
U-Boot@lists.denx.de
http://lists.denx.de/mailman/listinfo/u-boot


[U-Boot] [PATCH] README: SPI: Add & explain missed SPI & serial flash options.

2016-06-11 Thread Ahmed Samir Khalil
There are no README documentation about these options of SPI &
serial flash devices. Documenting these options makes getting
startup, configuration & testing easier.

Signed-off-by: Ahmed Samir Khalil <engkhali...@gmail.com>
---
 README | 15 +++
 1 file changed, 15 insertions(+)

diff --git a/README b/README
index 1d0b946..9cf3a05 100644
--- a/README
+++ b/README
@@ -2689,6 +2689,21 @@ CBFS (Coreboot Filesystem) support
Timeout for waiting until spi transfer completed.
default: (CONFIG_SYS_HZ/100) /* 10 ms */
 
+   CONFIG_SPI_FLASH
+   Include SPI flash core, interface, and parameters table,
+   and serial flash probing.
+
+   CONFIG_SPI_FLASH_MTD
+   Register SPI flash to the MTD subsystem. Needed for MTD 
operations.
+
+   CONFIG_SYS_SPI_U_BOOT_OFFS
+   Location in SPI to read U-Boot from.
+
+   CONFIG_DM_SPI, CONFIG_DM_SPI_FLASH
+   Use the Driver Model (DM) for SPI devices, and SPI flash.
+   For more details on how to port legacy driver to the new DM,
+   see doc/driver-model/spi-howto.txt
+
 - FPGA Support: CONFIG_FPGA
 
Enables FPGA subsystem.
-- 
2.7.4

___
U-Boot mailing list
U-Boot@lists.denx.de
http://lists.denx.de/mailman/listinfo/u-boot


[U-Boot] [PATCH] Common: SPL: spl_nand: Fixed debug correct NAND ECC type.

2016-03-25 Thread Ahmed Samir Khalil
In case of #define DEBUG 1 (fordebugging SPL). A bug in
spl_nand_load_image() will be triggered, because it prints
using hw ecc regardless of soft ecc configurations and
initializations.

Signed-off-by: Ahmed Samir 
---
 common/spl/spl_nand.c | 4 
 1 file changed, 4 insertions(+)

diff --git a/common/spl/spl_nand.c b/common/spl/spl_nand.c
index 3e2c074..79388ff 100644
--- a/common/spl/spl_nand.c
+++ b/common/spl/spl_nand.c
@@ -44,7 +44,11 @@ int spl_nand_load_image(void)
int *src __attribute__((unused));
int *dst __attribute__((unused));
 
+#ifdef CONFIG_SPL_NAND_SOFTECC
+   debug("spl: nand - using sw ecc\n");
+#else
debug("spl: nand - using hw ecc\n");
+#endif
nand_init();
 
/*use CONFIG_SYS_TEXT_BASE as temporary storage area */
-- 
2.5.0

___
U-Boot mailing list
U-Boot@lists.denx.de
http://lists.denx.de/mailman/listinfo/u-boot