Re: [U-Boot] [PATCH v4 14/20] mtd: spi: Switch to new SPI NOR framework

2019-02-12 Thread Vignesh R


On 13/02/19 1:54 AM, Adam Ford wrote:
> On Tue, Feb 12, 2019 at 1:20 PM Adam Ford  wrote:
>>
>> On Sun, Feb 10, 2019 at 10:37 PM Vignesh R  wrote:
>>>
>>>
>>>
>>> On 11/02/19 9:01 AM, Adam Ford wrote:
 On Tue, Feb 5, 2019 at 12:00 AM Vignesh R  wrote:
>
> Switch spi_flash_* interfaces to call into new SPI NOR framework via MTD
> layer. Fix up sf_dataflash to work in legacy way. And update sandbox to
> use new interfaces/definitions
>
> Signed-off-by: Vignesh R 
> Tested-by: Simon Goldschmidt 
> Tested-by: Stefan Roese 
> Tested-by: Horatiu Vultur 
> Reviewed-by: Jagan Teki 
> Tested-by: Jagan Teki  #zynq-microzed

 This patch appears to break the da850_evm board which boots from SPI
 Flash and initializes the davinci driver with platdata since the
 device tree stuff does not quite work right in SPL.
>>>
>>> Oops, I did test on K2G EVM that has davinci SPI controller with micron
>>> n25q flash but that was with DT. Not sure whats missing with platdata.
>>>

 U-Boot SPL 2019.01-02923-gc4e8862308-dirty (Feb 10 2019 - 21:24:38 -0600)
 Trying to boot from SPI
 SPI probe failed.
 SPL: failed to boot from all boot devices
 ### ERROR ### Please RESET the board ###
>>>
>>> Could you enable debug prints at spi-mem level in drivers/spi/spi-mem.c
>>> (especially debug prints at the end of spi_mem_exec_op()) and post the
>>> logs here?
>>>

 Any suggestions on how to fix the SPI initialization without needing
 the device tree?  I have tried to port the device tree stuff to SPL,
 but I haven't yet been successful so I have had to leave the platdata
 initialization in place.

>>>
>>> I haven't changed any driver names so, platdata to driver bindings
>>> should still be the same. Could you verify if spi_nor_scan() is being
>>> called in drivers/mtd/spi/spi-nor-tiny.c for SPL?
>>
>> I globally turned on DEBUG and I have two logs for you:
>>
>> Not working:
>>
>> U-Boot SPL 2019.01-02923-gc4e8862308-dirty (Feb 12 2019 - 13:04:19 -0600)
>> Trying to boot from SPI
>> uclass_find_device_by_seq: 0 -1
>> uclass_find_device_by_seq: 0 0
>>- -1 -1 'davinci_spi'
>>- not found
>> spi_get_bus_and_cs: Binding new device 'spi_flash', busnum=0, cs=0,
>> driver=spi_flash_std
>> spi_get_bus_and_cs: Error path, created=1, device 'spi_flash'
>> SPI probe failed.
>> SPL: failed to boot from all boot devices
>> ### ERROR ### Please RESET the board ###
>>
>> As a point of reference , I thought I'd show
>> WORKING version (before this patch):
>>
>> U-Boot SPL 2019.01-02922-g2ee6705be0-dirty (Feb 12 2019 - 12:59:49 -0600)
>> Trying to boot from SPI
>> uclass_find_device_by_seq: 0 -1
>> uclass_find_device_by_seq: 0 0
>>- -1 -1 'davinci_spi'
>>- not found
>> spi_get_bus_and_cs: Binding new device 'spi_flash', busnum=0, cs=0,
>> driver=spi_flash_std
>> uclass_find_device_by_seq: 0 -1
>> uclass_find_device_by_seq: 0 0
>>- -1 -1 'spi_flash'
>>- not found
>> spi_flash_std_probe: slave=8001fd60, cs=0
>> davinci_spi_set_speed speed 3000
>> davinci_spi_set_mode mode 3
>> davinci_spi_set_speed speed 3000
>> davinci_spi_set_mode mode 3
>> spi_get_bus_and_cs: bus=8001fbf4, slave=8001fd60
>> SPL: payload image: U-Boot 2019.01-02922-g2ee6705be0   load addr:
>> 0xc107ffc0 size: 405306
>> Jumping to U-Boot
>> loaded - jumping to U-Boot...
>> image entry point: 0xc108
>> ...
>>
>> During this process, I learned a few things.
>> 1.  I am not really using the device tree during SPL like i originally
>> thought and the OF_PLATDATA
>> 2.  Getting SPL to support device tree with or without PLATDATA isn't
>> as straightforward as I hoped
>> 3.  With the knowledge I learned from item 1, I tried to disabled
>> OF_CONTROL during SPL, but this patch also fails to build since it
>> assumes OF_CONTROL is always enabled.
>>
>> If there are any suggestions you might have, I am willing to try them.
>>
> 
> I beleive I have narrowed it down a bit to a chunk of code (int
> device_probe(struct udevice *dev)) located in device.c:
> 
> /* Allocate private data if requested and not reentered */
> if (drv->priv_auto_alloc_size && !dev->priv) {
> dev->priv = alloc_priv(drv->priv_auto_alloc_size, drv->flags);
> if (!dev->priv) {
> printf("Allocate private data if requested and not reentered\n");
> ret = -ENOMEM;
> goto fail;
> }
> }
> 
> I am not sure how the sizes are defined and/or allocated

priv_auto_alloc_size is determined by:
drivers/mtd/spi/sf_probe.c:180: .priv_auto_alloc_size = sizeof(struct 
spi_flash),

Allocation is done at:
./drivers/core/device.c::alloc_priv()
If you are seeing -ENOMEM, it looks calloc() maybe failing in above function.

Could you increase available size of malloc in SPL to a higher value.
I believe you are using da850evm_defconfig. If so, could you change

CONFIG_SPL_SYS_MALLOC_F_LEN=0x800 or higher and see if that helps?


Regards
Vignesh


-- 
Regards
Vignesh
__

Re: [U-Boot] [PATCH v4 14/20] mtd: spi: Switch to new SPI NOR framework

2019-02-12 Thread Adam Ford
On Tue, Feb 12, 2019 at 1:20 PM Adam Ford  wrote:
>
> On Sun, Feb 10, 2019 at 10:37 PM Vignesh R  wrote:
> >
> >
> >
> > On 11/02/19 9:01 AM, Adam Ford wrote:
> > > On Tue, Feb 5, 2019 at 12:00 AM Vignesh R  wrote:
> > >>
> > >> Switch spi_flash_* interfaces to call into new SPI NOR framework via MTD
> > >> layer. Fix up sf_dataflash to work in legacy way. And update sandbox to
> > >> use new interfaces/definitions
> > >>
> > >> Signed-off-by: Vignesh R 
> > >> Tested-by: Simon Goldschmidt 
> > >> Tested-by: Stefan Roese 
> > >> Tested-by: Horatiu Vultur 
> > >> Reviewed-by: Jagan Teki 
> > >> Tested-by: Jagan Teki  #zynq-microzed
> > >
> > > This patch appears to break the da850_evm board which boots from SPI
> > > Flash and initializes the davinci driver with platdata since the
> > > device tree stuff does not quite work right in SPL.
> >
> > Oops, I did test on K2G EVM that has davinci SPI controller with micron
> > n25q flash but that was with DT. Not sure whats missing with platdata.
> >
> > >
> > > U-Boot SPL 2019.01-02923-gc4e8862308-dirty (Feb 10 2019 - 21:24:38 -0600)
> > > Trying to boot from SPI
> > > SPI probe failed.
> > > SPL: failed to boot from all boot devices
> > > ### ERROR ### Please RESET the board ###
> >
> > Could you enable debug prints at spi-mem level in drivers/spi/spi-mem.c
> > (especially debug prints at the end of spi_mem_exec_op()) and post the
> > logs here?
> >
> > >
> > > Any suggestions on how to fix the SPI initialization without needing
> > > the device tree?  I have tried to port the device tree stuff to SPL,
> > > but I haven't yet been successful so I have had to leave the platdata
> > > initialization in place.
> > >
> >
> > I haven't changed any driver names so, platdata to driver bindings
> > should still be the same. Could you verify if spi_nor_scan() is being
> > called in drivers/mtd/spi/spi-nor-tiny.c for SPL?
>
> I globally turned on DEBUG and I have two logs for you:
>
> Not working:
>
> U-Boot SPL 2019.01-02923-gc4e8862308-dirty (Feb 12 2019 - 13:04:19 -0600)
> Trying to boot from SPI
> uclass_find_device_by_seq: 0 -1
> uclass_find_device_by_seq: 0 0
>- -1 -1 'davinci_spi'
>- not found
> spi_get_bus_and_cs: Binding new device 'spi_flash', busnum=0, cs=0,
> driver=spi_flash_std
> spi_get_bus_and_cs: Error path, created=1, device 'spi_flash'
> SPI probe failed.
> SPL: failed to boot from all boot devices
> ### ERROR ### Please RESET the board ###
>
> As a point of reference , I thought I'd show
> WORKING version (before this patch):
>
> U-Boot SPL 2019.01-02922-g2ee6705be0-dirty (Feb 12 2019 - 12:59:49 -0600)
> Trying to boot from SPI
> uclass_find_device_by_seq: 0 -1
> uclass_find_device_by_seq: 0 0
>- -1 -1 'davinci_spi'
>- not found
> spi_get_bus_and_cs: Binding new device 'spi_flash', busnum=0, cs=0,
> driver=spi_flash_std
> uclass_find_device_by_seq: 0 -1
> uclass_find_device_by_seq: 0 0
>- -1 -1 'spi_flash'
>- not found
> spi_flash_std_probe: slave=8001fd60, cs=0
> davinci_spi_set_speed speed 3000
> davinci_spi_set_mode mode 3
> davinci_spi_set_speed speed 3000
> davinci_spi_set_mode mode 3
> spi_get_bus_and_cs: bus=8001fbf4, slave=8001fd60
> SPL: payload image: U-Boot 2019.01-02922-g2ee6705be0   load addr:
> 0xc107ffc0 size: 405306
> Jumping to U-Boot
> loaded - jumping to U-Boot...
> image entry point: 0xc108
> ...
>
> During this process, I learned a few things.
> 1.  I am not really using the device tree during SPL like i originally
> thought and the OF_PLATDATA
> 2.  Getting SPL to support device tree with or without PLATDATA isn't
> as straightforward as I hoped
> 3.  With the knowledge I learned from item 1, I tried to disabled
> OF_CONTROL during SPL, but this patch also fails to build since it
> assumes OF_CONTROL is always enabled.
>
> If there are any suggestions you might have, I am willing to try them.
>

I beleive I have narrowed it down a bit to a chunk of code (int
device_probe(struct udevice *dev)) located in device.c:

/* Allocate private data if requested and not reentered */
if (drv->priv_auto_alloc_size && !dev->priv) {
dev->priv = alloc_priv(drv->priv_auto_alloc_size, drv->flags);
if (!dev->priv) {
printf("Allocate private data if requested and not reentered\n");
ret = -ENOMEM;
goto fail;
}
}

I am not sure how the sizes are defined and/or allocated

adam


> adam
>
> >
> > Sorry for the trouble.
> >
> > Regards
> > Vignesh
> >
> >
> > --
> > Regards
> > Vignesh
___
U-Boot mailing list
U-Boot@lists.denx.de
https://lists.denx.de/listinfo/u-boot


Re: [U-Boot] [PATCH v4 14/20] mtd: spi: Switch to new SPI NOR framework

2019-02-12 Thread Adam Ford
On Sun, Feb 10, 2019 at 10:37 PM Vignesh R  wrote:
>
>
>
> On 11/02/19 9:01 AM, Adam Ford wrote:
> > On Tue, Feb 5, 2019 at 12:00 AM Vignesh R  wrote:
> >>
> >> Switch spi_flash_* interfaces to call into new SPI NOR framework via MTD
> >> layer. Fix up sf_dataflash to work in legacy way. And update sandbox to
> >> use new interfaces/definitions
> >>
> >> Signed-off-by: Vignesh R 
> >> Tested-by: Simon Goldschmidt 
> >> Tested-by: Stefan Roese 
> >> Tested-by: Horatiu Vultur 
> >> Reviewed-by: Jagan Teki 
> >> Tested-by: Jagan Teki  #zynq-microzed
> >
> > This patch appears to break the da850_evm board which boots from SPI
> > Flash and initializes the davinci driver with platdata since the
> > device tree stuff does not quite work right in SPL.
>
> Oops, I did test on K2G EVM that has davinci SPI controller with micron
> n25q flash but that was with DT. Not sure whats missing with platdata.
>
> >
> > U-Boot SPL 2019.01-02923-gc4e8862308-dirty (Feb 10 2019 - 21:24:38 -0600)
> > Trying to boot from SPI
> > SPI probe failed.
> > SPL: failed to boot from all boot devices
> > ### ERROR ### Please RESET the board ###
>
> Could you enable debug prints at spi-mem level in drivers/spi/spi-mem.c
> (especially debug prints at the end of spi_mem_exec_op()) and post the
> logs here?
>
> >
> > Any suggestions on how to fix the SPI initialization without needing
> > the device tree?  I have tried to port the device tree stuff to SPL,
> > but I haven't yet been successful so I have had to leave the platdata
> > initialization in place.
> >
>
> I haven't changed any driver names so, platdata to driver bindings
> should still be the same. Could you verify if spi_nor_scan() is being
> called in drivers/mtd/spi/spi-nor-tiny.c for SPL?

I globally turned on DEBUG and I have two logs for you:

Not working:

U-Boot SPL 2019.01-02923-gc4e8862308-dirty (Feb 12 2019 - 13:04:19 -0600)
Trying to boot from SPI
uclass_find_device_by_seq: 0 -1
uclass_find_device_by_seq: 0 0
   - -1 -1 'davinci_spi'
   - not found
spi_get_bus_and_cs: Binding new device 'spi_flash', busnum=0, cs=0,
driver=spi_flash_std
spi_get_bus_and_cs: Error path, created=1, device 'spi_flash'
SPI probe failed.
SPL: failed to boot from all boot devices
### ERROR ### Please RESET the board ###

As a point of reference , I thought I'd show
WORKING version (before this patch):

U-Boot SPL 2019.01-02922-g2ee6705be0-dirty (Feb 12 2019 - 12:59:49 -0600)
Trying to boot from SPI
uclass_find_device_by_seq: 0 -1
uclass_find_device_by_seq: 0 0
   - -1 -1 'davinci_spi'
   - not found
spi_get_bus_and_cs: Binding new device 'spi_flash', busnum=0, cs=0,
driver=spi_flash_std
uclass_find_device_by_seq: 0 -1
uclass_find_device_by_seq: 0 0
   - -1 -1 'spi_flash'
   - not found
spi_flash_std_probe: slave=8001fd60, cs=0
davinci_spi_set_speed speed 3000
davinci_spi_set_mode mode 3
davinci_spi_set_speed speed 3000
davinci_spi_set_mode mode 3
spi_get_bus_and_cs: bus=8001fbf4, slave=8001fd60
SPL: payload image: U-Boot 2019.01-02922-g2ee6705be0   load addr:
0xc107ffc0 size: 405306
Jumping to U-Boot
loaded - jumping to U-Boot...
image entry point: 0xc108
...

During this process, I learned a few things.
1.  I am not really using the device tree during SPL like i originally
thought and the OF_PLATDATA
2.  Getting SPL to support device tree with or without PLATDATA isn't
as straightforward as I hoped
3.  With the knowledge I learned from item 1, I tried to disabled
OF_CONTROL during SPL, but this patch also fails to build since it
assumes OF_CONTROL is always enabled.

If there are any suggestions you might have, I am willing to try them.

adam

>
> Sorry for the trouble.
>
> Regards
> Vignesh
>
>
> --
> Regards
> Vignesh
___
U-Boot mailing list
U-Boot@lists.denx.de
https://lists.denx.de/listinfo/u-boot


Re: [U-Boot] [PATCH v4 14/20] mtd: spi: Switch to new SPI NOR framework

2019-02-10 Thread Vignesh R


On 11/02/19 9:01 AM, Adam Ford wrote:
> On Tue, Feb 5, 2019 at 12:00 AM Vignesh R  wrote:
>>
>> Switch spi_flash_* interfaces to call into new SPI NOR framework via MTD
>> layer. Fix up sf_dataflash to work in legacy way. And update sandbox to
>> use new interfaces/definitions
>>
>> Signed-off-by: Vignesh R 
>> Tested-by: Simon Goldschmidt 
>> Tested-by: Stefan Roese 
>> Tested-by: Horatiu Vultur 
>> Reviewed-by: Jagan Teki 
>> Tested-by: Jagan Teki  #zynq-microzed
> 
> This patch appears to break the da850_evm board which boots from SPI
> Flash and initializes the davinci driver with platdata since the
> device tree stuff does not quite work right in SPL.

Oops, I did test on K2G EVM that has davinci SPI controller with micron
n25q flash but that was with DT. Not sure whats missing with platdata.

> 
> U-Boot SPL 2019.01-02923-gc4e8862308-dirty (Feb 10 2019 - 21:24:38 -0600)
> Trying to boot from SPI
> SPI probe failed.
> SPL: failed to boot from all boot devices
> ### ERROR ### Please RESET the board ###

Could you enable debug prints at spi-mem level in drivers/spi/spi-mem.c
(especially debug prints at the end of spi_mem_exec_op()) and post the
logs here?

> 
> Any suggestions on how to fix the SPI initialization without needing
> the device tree?  I have tried to port the device tree stuff to SPL,
> but I haven't yet been successful so I have had to leave the platdata
> initialization in place.
> 

I haven't changed any driver names so, platdata to driver bindings
should still be the same. Could you verify if spi_nor_scan() is being
called in drivers/mtd/spi/spi-nor-tiny.c for SPL?

Sorry for the trouble.

Regards
Vignesh


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


Re: [U-Boot] [PATCH v4 14/20] mtd: spi: Switch to new SPI NOR framework

2019-02-10 Thread Adam Ford
On Tue, Feb 5, 2019 at 12:00 AM Vignesh R  wrote:
>
> Switch spi_flash_* interfaces to call into new SPI NOR framework via MTD
> layer. Fix up sf_dataflash to work in legacy way. And update sandbox to
> use new interfaces/definitions
>
> Signed-off-by: Vignesh R 
> Tested-by: Simon Goldschmidt 
> Tested-by: Stefan Roese 
> Tested-by: Horatiu Vultur 
> Reviewed-by: Jagan Teki 
> Tested-by: Jagan Teki  #zynq-microzed

This patch appears to break the da850_evm board which boots from SPI
Flash and initializes the davinci driver with platdata since the
device tree stuff does not quite work right in SPL.

U-Boot SPL 2019.01-02923-gc4e8862308-dirty (Feb 10 2019 - 21:24:38 -0600)
Trying to boot from SPI
SPI probe failed.
SPL: failed to boot from all boot devices
### ERROR ### Please RESET the board ###

Any suggestions on how to fix the SPI initialization without needing
the device tree?  I have tried to port the device tree stuff to SPL,
but I haven't yet been successful so I have had to leave the platdata
initialization in place.

adam
> ---
>  drivers/mtd/spi/Kconfig|   2 +
>  drivers/mtd/spi/Makefile   |   4 +-
>  drivers/mtd/spi/sandbox.c  |  36 +++---
>  drivers/mtd/spi/sf_dataflash.c |  11 +-
>  drivers/mtd/spi/sf_internal.h  | 225 ++---
>  drivers/mtd/spi/sf_probe.c |  32 +++--
>  drivers/mtd/spi/spi-nor-core.c |  59 +
>  drivers/spi/stm32_qspi.c   |   4 +-
>  include/spi_flash.h| 105 ---
>  9 files changed, 113 insertions(+), 365 deletions(-)
>
> diff --git a/drivers/mtd/spi/Kconfig b/drivers/mtd/spi/Kconfig
> index 4ba95d58b371..e3b40fc157d6 100644
> --- a/drivers/mtd/spi/Kconfig
> +++ b/drivers/mtd/spi/Kconfig
> @@ -27,6 +27,8 @@ config SPI_FLASH_SANDBOX
>
>  config SPI_FLASH
> bool "Legacy SPI Flash Interface support"
> +   depends on SPI
> +   select SPI_MEM
> help
>   Enable the legacy SPI flash support. This will include basic
>   standard support for things like probing, read / write, and
> diff --git a/drivers/mtd/spi/Makefile b/drivers/mtd/spi/Makefile
> index b4c7e1c98bd5..70058d3df2b9 100644
> --- a/drivers/mtd/spi/Makefile
> +++ b/drivers/mtd/spi/Makefile
> @@ -9,7 +9,7 @@ ifdef CONFIG_SPL_BUILD
>  obj-$(CONFIG_SPL_SPI_BOOT) += fsl_espi_spl.o
>  endif
>
> -obj-$(CONFIG_SPI_FLASH) += sf_probe.o spi_flash.o spi_flash_ids.o sf.o
> -obj-$(CONFIG_SPI_FLASH_DATAFLASH) += sf_dataflash.o
> +obj-$(CONFIG_SPI_FLASH) += sf_probe.o spi-nor-core.o
> +obj-$(CONFIG_SPI_FLASH_DATAFLASH) += sf_dataflash.o sf.o
>  obj-$(CONFIG_SPI_FLASH_MTD) += sf_mtd.o
>  obj-$(CONFIG_SPI_FLASH_SANDBOX) += sandbox.o
> diff --git a/drivers/mtd/spi/sandbox.c b/drivers/mtd/spi/sandbox.c
> index 7b9891cb981c..084c66e9840b 100644
> --- a/drivers/mtd/spi/sandbox.c
> +++ b/drivers/mtd/spi/sandbox.c
> @@ -92,7 +92,7 @@ struct sandbox_spi_flash {
> /* The current flash status (see STAT_XXX defines above) */
> u16 status;
> /* Data describing the flash we're emulating */
> -   const struct spi_flash_info *data;
> +   const struct flash_info *data;
> /* The file on disk to serv up data from */
> int fd;
>  };
> @@ -122,7 +122,7 @@ static int sandbox_sf_probe(struct udevice *dev)
> /* spec = idcode:file */
> struct sandbox_spi_flash *sbsf = dev_get_priv(dev);
> size_t len, idname_len;
> -   const struct spi_flash_info *data;
> +   const struct flash_info *data;
> struct sandbox_spi_flash_plat_data *pdata = dev_get_platdata(dev);
> struct sandbox_state *state = state_get_current();
> struct dm_spi_slave_platdata *slave_plat;
> @@ -155,7 +155,7 @@ static int sandbox_sf_probe(struct udevice *dev)
> idname_len = strlen(spec);
> debug("%s: device='%s'\n", __func__, spec);
>
> -   for (data = spi_flash_ids; data->name; data++) {
> +   for (data = spi_nor_ids; data->name; data++) {
> len = strlen(data->name);
> if (idname_len != len)
> continue;
> @@ -243,43 +243,43 @@ static int sandbox_sf_process_cmd(struct 
> sandbox_spi_flash *sbsf, const u8 *rx,
>
> sbsf->cmd = rx[0];
> switch (sbsf->cmd) {
> -   case CMD_READ_ID:
> +   case SPINOR_OP_RDID:
> sbsf->state = SF_ID;
> sbsf->cmd = SF_ID;
> break;
> -   case CMD_READ_ARRAY_FAST:
> +   case SPINOR_OP_READ_FAST:
> sbsf->pad_addr_bytes = 1;
> -   case CMD_READ_ARRAY_SLOW:
> -   case CMD_PAGE_PROGRAM:
> +   case SPINOR_OP_READ:
> +   case SPINOR_OP_PP:
> sbsf->state = SF_ADDR;
> break;
> -   case CMD_WRITE_DISABLE:
> +   case SPINOR_OP_WRDI:
> debug(" write disabled\n");
> sbsf->status &= ~STAT_WEL;
> break;
> -   case CMD_READ_STATUS:
> +   case SPINOR_OP_RDSR:
> sbsf->sta

[U-Boot] [PATCH v4 14/20] mtd: spi: Switch to new SPI NOR framework

2019-02-04 Thread Vignesh R
Switch spi_flash_* interfaces to call into new SPI NOR framework via MTD
layer. Fix up sf_dataflash to work in legacy way. And update sandbox to
use new interfaces/definitions

Signed-off-by: Vignesh R 
Tested-by: Simon Goldschmidt 
Tested-by: Stefan Roese 
Tested-by: Horatiu Vultur 
Reviewed-by: Jagan Teki 
Tested-by: Jagan Teki  #zynq-microzed
---
 drivers/mtd/spi/Kconfig|   2 +
 drivers/mtd/spi/Makefile   |   4 +-
 drivers/mtd/spi/sandbox.c  |  36 +++---
 drivers/mtd/spi/sf_dataflash.c |  11 +-
 drivers/mtd/spi/sf_internal.h  | 225 ++---
 drivers/mtd/spi/sf_probe.c |  32 +++--
 drivers/mtd/spi/spi-nor-core.c |  59 +
 drivers/spi/stm32_qspi.c   |   4 +-
 include/spi_flash.h| 105 ---
 9 files changed, 113 insertions(+), 365 deletions(-)

diff --git a/drivers/mtd/spi/Kconfig b/drivers/mtd/spi/Kconfig
index 4ba95d58b371..e3b40fc157d6 100644
--- a/drivers/mtd/spi/Kconfig
+++ b/drivers/mtd/spi/Kconfig
@@ -27,6 +27,8 @@ config SPI_FLASH_SANDBOX
 
 config SPI_FLASH
bool "Legacy SPI Flash Interface support"
+   depends on SPI
+   select SPI_MEM
help
  Enable the legacy SPI flash support. This will include basic
  standard support for things like probing, read / write, and
diff --git a/drivers/mtd/spi/Makefile b/drivers/mtd/spi/Makefile
index b4c7e1c98bd5..70058d3df2b9 100644
--- a/drivers/mtd/spi/Makefile
+++ b/drivers/mtd/spi/Makefile
@@ -9,7 +9,7 @@ ifdef CONFIG_SPL_BUILD
 obj-$(CONFIG_SPL_SPI_BOOT) += fsl_espi_spl.o
 endif
 
-obj-$(CONFIG_SPI_FLASH) += sf_probe.o spi_flash.o spi_flash_ids.o sf.o
-obj-$(CONFIG_SPI_FLASH_DATAFLASH) += sf_dataflash.o
+obj-$(CONFIG_SPI_FLASH) += sf_probe.o spi-nor-core.o
+obj-$(CONFIG_SPI_FLASH_DATAFLASH) += sf_dataflash.o sf.o
 obj-$(CONFIG_SPI_FLASH_MTD) += sf_mtd.o
 obj-$(CONFIG_SPI_FLASH_SANDBOX) += sandbox.o
diff --git a/drivers/mtd/spi/sandbox.c b/drivers/mtd/spi/sandbox.c
index 7b9891cb981c..084c66e9840b 100644
--- a/drivers/mtd/spi/sandbox.c
+++ b/drivers/mtd/spi/sandbox.c
@@ -92,7 +92,7 @@ struct sandbox_spi_flash {
/* The current flash status (see STAT_XXX defines above) */
u16 status;
/* Data describing the flash we're emulating */
-   const struct spi_flash_info *data;
+   const struct flash_info *data;
/* The file on disk to serv up data from */
int fd;
 };
@@ -122,7 +122,7 @@ static int sandbox_sf_probe(struct udevice *dev)
/* spec = idcode:file */
struct sandbox_spi_flash *sbsf = dev_get_priv(dev);
size_t len, idname_len;
-   const struct spi_flash_info *data;
+   const struct flash_info *data;
struct sandbox_spi_flash_plat_data *pdata = dev_get_platdata(dev);
struct sandbox_state *state = state_get_current();
struct dm_spi_slave_platdata *slave_plat;
@@ -155,7 +155,7 @@ static int sandbox_sf_probe(struct udevice *dev)
idname_len = strlen(spec);
debug("%s: device='%s'\n", __func__, spec);
 
-   for (data = spi_flash_ids; data->name; data++) {
+   for (data = spi_nor_ids; data->name; data++) {
len = strlen(data->name);
if (idname_len != len)
continue;
@@ -243,43 +243,43 @@ static int sandbox_sf_process_cmd(struct 
sandbox_spi_flash *sbsf, const u8 *rx,
 
sbsf->cmd = rx[0];
switch (sbsf->cmd) {
-   case CMD_READ_ID:
+   case SPINOR_OP_RDID:
sbsf->state = SF_ID;
sbsf->cmd = SF_ID;
break;
-   case CMD_READ_ARRAY_FAST:
+   case SPINOR_OP_READ_FAST:
sbsf->pad_addr_bytes = 1;
-   case CMD_READ_ARRAY_SLOW:
-   case CMD_PAGE_PROGRAM:
+   case SPINOR_OP_READ:
+   case SPINOR_OP_PP:
sbsf->state = SF_ADDR;
break;
-   case CMD_WRITE_DISABLE:
+   case SPINOR_OP_WRDI:
debug(" write disabled\n");
sbsf->status &= ~STAT_WEL;
break;
-   case CMD_READ_STATUS:
+   case SPINOR_OP_RDSR:
sbsf->state = SF_READ_STATUS;
break;
-   case CMD_READ_STATUS1:
+   case SPINOR_OP_RDSR2:
sbsf->state = SF_READ_STATUS1;
break;
-   case CMD_WRITE_ENABLE:
+   case SPINOR_OP_WREN:
debug(" write enabled\n");
sbsf->status |= STAT_WEL;
break;
-   case CMD_WRITE_STATUS:
+   case SPINOR_OP_WRSR:
sbsf->state = SF_WRITE_STATUS;
break;
default: {
int flags = sbsf->data->flags;
 
/* we only support erase here */
-   if (sbsf->cmd == CMD_ERASE_CHIP) {
+   if (sbsf->cmd == SPINOR_OP_CHIP_ERASE) {
sbsf->erase_size = sbsf->data->sector_size *
sbsf->data->n_sectors;
-   } else if (sbsf->cmd == CMD_ERASE_4K && (flag