Message ID | 1576065216-5249-1-git-send-email-kuldeep.singh@nxp.com |
---|---|
State | Superseded |
Delegated to: | Joe Hershberger |
Headers | show |
Series | net: pfe_eth: Use spi_flash_read API to access flash memory | expand |
> -----Original Message----- > From: Kuldeep Singh <kuldeep.singh@nxp.com> > Sent: Wednesday, December 11, 2019 5:24 PM > To: u-boot@lists.denx.de > Cc: joe.hershberger@ni.com; Priyanka Jain <priyanka.jain@nxp.com>; > tommyhebb@gmail.com; Ashish Kumar <ashish.kumar@nxp.com>; > patrick.delaunay@st.com; simon.k.r.goldschmidt@gmail.com; Yunfeng Ding > <yunfeng.ding@nxp.com>; Kuldeep Singh <kuldeep.singh@nxp.com> > Subject: [PATCH] net: pfe_eth: Use spi_flash_read API to access flash memory > > Current PFE firmware access spi-nor memory directly. New spi-mem > framework does not support direct memory access. So, let's use > spi_flash_read API to access memory instead of directly using it. > Hi Joe, Sorry for early ping. Can you please review this patch as qspi driver sent [1] is dependent on this patch. It helps in resolving booting crash on LS1012ARDB while testing the same. Thanks Kuldeep [1] https://patchwork.ozlabs.org/project/uboot/list/?series=149809 > Signed-off-by: Kuldeep Singh <kuldeep.singh@nxp.com> > --- > drivers/net/pfe_eth/pfe_firmware.c | 44 +++++++++++++++++++++++++++++- > include/configs/ls1012a_common.h | 5 +++- > 2 files changed, 47 insertions(+), 2 deletions(-) > > diff --git a/drivers/net/pfe_eth/pfe_firmware.c > b/drivers/net/pfe_eth/pfe_firmware.c > index e4563f192b..61d1b96305 100644 > --- a/drivers/net/pfe_eth/pfe_firmware.c > +++ b/drivers/net/pfe_eth/pfe_firmware.c > @@ -12,13 +12,14 @@ > > #include <net/pfe_eth/pfe_eth.h> > #include <net/pfe_eth/pfe_firmware.h> > +#include <spi_flash.h> > #ifdef CONFIG_CHAIN_OF_TRUST > #include <fsl_validate.h> > #endif > > #define PFE_FIRMWARE_FIT_CNF_NAME "config@1" > > -static const void *pfe_fit_addr = (void *)CONFIG_SYS_LS_PFE_FW_ADDR; > +static const void *pfe_fit_addr; > > /* > * PFE elf firmware loader. > @@ -159,6 +160,43 @@ static int pfe_fit_check(void) > return ret; > } > > +int pfe_spi_flash_init(void) > +{ > + struct spi_flash *pfe_flash; > + int ret = 0; > + void *addr = malloc(CONFIG_SYS_QE_FMAN_FW_LENGTH); > + > +#ifdef CONFIG_DM_SPI_FLASH > + struct udevice *new; > + > + /* speed and mode will be read from DT */ > + ret = spi_flash_probe_bus_cs(CONFIG_ENV_SPI_BUS, > + CONFIG_ENV_SPI_CS, 0, 0, &new); > + > + pfe_flash = dev_get_uclass_priv(new); > +#else > + pfe_flash = spi_flash_probe(CONFIG_ENV_SPI_BUS, > + CONFIG_ENV_SPI_CS, > + CONFIG_ENV_SPI_MAX_HZ, > + CONFIG_ENV_SPI_MODE); > +#endif > + if (!pfe_flash) { > + printf("SF: probe for pfe ucode failed\n"); > + } else { > + ret = spi_flash_read(pfe_flash, > + CONFIG_SYS_LS_PFE_FW_ADDR, > + CONFIG_SYS_QE_FMAN_FW_LENGTH, > + addr); > + if (ret) > + printf("SF: read for ucode failed\n"); > + > + pfe_fit_addr = addr; > + spi_flash_free(pfe_flash); > + } > + > + return ret; > +} > + > /* > * PFE firmware initialization. > * Loads different firmware files from FIT image. > @@ -183,6 +221,10 @@ int pfe_firmware_init(void) > int ret = 0; > int fw_count; > > + ret = pfe_spi_flash_init(); > + if (ret) > + goto err; > + > ret = pfe_fit_check(); > if (ret) > goto err; > diff --git a/include/configs/ls1012a_common.h > b/include/configs/ls1012a_common.h > index 2579e2fb37..cbc5bff21c 100644 > --- a/include/configs/ls1012a_common.h > +++ b/include/configs/ls1012a_common.h > @@ -36,9 +36,12 @@ > /* Size of malloc() pool */ > #define CONFIG_SYS_MALLOC_LEN (CONFIG_ENV_SIZE + 128 * > 1024) > > +/* PFE */ > +#define CONFIG_SYS_FMAN_FW_ADDR 0x400d0000 > +#define CONFIG_SYS_QE_FMAN_FW_LENGTH 0x10000 > + > /*SPI device */ > #if defined(CONFIG_QSPI_BOOT) || defined(CONFIG_TFABOOT) > -#define CONFIG_SYS_FMAN_FW_ADDR 0x400d0000 > #define CONFIG_SPI_FLASH_SPANSION > #define CONFIG_FSL_SPI_INTERFACE > #define CONFIG_SF_DATAFLASH > -- > 2.17.1
On 11.12.19 12:53, Kuldeep Singh wrote: > Current PFE firmware access spi-nor memory directly. New spi-mem > framework does not support direct memory access. So, let's use > spi_flash_read API to access memory instead of directly using it. > > Signed-off-by: Kuldeep Singh <kuldeep.singh@nxp.com> > --- > drivers/net/pfe_eth/pfe_firmware.c | 44 +++++++++++++++++++++++++++++- > include/configs/ls1012a_common.h | 5 +++- > 2 files changed, 47 insertions(+), 2 deletions(-) > > diff --git a/drivers/net/pfe_eth/pfe_firmware.c b/drivers/net/pfe_eth/pfe_firmware.c > index e4563f192b..61d1b96305 100644 > --- a/drivers/net/pfe_eth/pfe_firmware.c > +++ b/drivers/net/pfe_eth/pfe_firmware.c > @@ -12,13 +12,14 @@ > > #include <net/pfe_eth/pfe_eth.h> > #include <net/pfe_eth/pfe_firmware.h> > +#include <spi_flash.h> > #ifdef CONFIG_CHAIN_OF_TRUST > #include <fsl_validate.h> > #endif > > #define PFE_FIRMWARE_FIT_CNF_NAME "config@1" > > -static const void *pfe_fit_addr = (void *)CONFIG_SYS_LS_PFE_FW_ADDR; > +static const void *pfe_fit_addr; > > /* > * PFE elf firmware loader. > @@ -159,6 +160,43 @@ static int pfe_fit_check(void) > return ret; > } > > +int pfe_spi_flash_init(void) > +{ > + struct spi_flash *pfe_flash; > + int ret = 0; > + void *addr = malloc(CONFIG_SYS_QE_FMAN_FW_LENGTH); > + > +#ifdef CONFIG_DM_SPI_FLASH > + struct udevice *new; > + > + /* speed and mode will be read from DT */ > + ret = spi_flash_probe_bus_cs(CONFIG_ENV_SPI_BUS, > + CONFIG_ENV_SPI_CS, 0, 0, &new); > + > + pfe_flash = dev_get_uclass_priv(new); > +#else > + pfe_flash = spi_flash_probe(CONFIG_ENV_SPI_BUS, > + CONFIG_ENV_SPI_CS, > + CONFIG_ENV_SPI_MAX_HZ, > + CONFIG_ENV_SPI_MODE); > +#endif > + if (!pfe_flash) { > + printf("SF: probe for pfe ucode failed\n"); I think you should return some error code in this case. Currently ret could still be 0 at this point. > + } else { > + ret = spi_flash_read(pfe_flash, > + CONFIG_SYS_LS_PFE_FW_ADDR, > + CONFIG_SYS_QE_FMAN_FW_LENGTH, > + addr); > + if (ret) > + printf("SF: read for ucode failed\n"); > + > + pfe_fit_addr = addr; > + spi_flash_free(pfe_flash); > + } > + > + return ret; > +} > + > /* > * PFE firmware initialization. > * Loads different firmware files from FIT image. > @@ -183,6 +221,10 @@ int pfe_firmware_init(void) > int ret = 0; > int fw_count; > > + ret = pfe_spi_flash_init(); > + if (ret) > + goto err; > + > ret = pfe_fit_check(); > if (ret) > goto err; > diff --git a/include/configs/ls1012a_common.h b/include/configs/ls1012a_common.h > index 2579e2fb37..cbc5bff21c 100644 > --- a/include/configs/ls1012a_common.h > +++ b/include/configs/ls1012a_common.h > @@ -36,9 +36,12 @@ > /* Size of malloc() pool */ > #define CONFIG_SYS_MALLOC_LEN (CONFIG_ENV_SIZE + 128 * 1024) > > +/* PFE */ > +#define CONFIG_SYS_FMAN_FW_ADDR 0x400d0000 > +#define CONFIG_SYS_QE_FMAN_FW_LENGTH 0x10000 > + > /*SPI device */ > #if defined(CONFIG_QSPI_BOOT) || defined(CONFIG_TFABOOT) > -#define CONFIG_SYS_FMAN_FW_ADDR 0x400d0000 > #define CONFIG_SPI_FLASH_SPANSION > #define CONFIG_FSL_SPI_INTERFACE > #define CONFIG_SF_DATAFLASH >
Hi Frieder, > -----Original Message----- > From: Schrempf Frieder <frieder.schrempf@kontron.de> > Sent: Tuesday, January 7, 2020 4:28 PM > To: Kuldeep Singh <kuldeep.singh@nxp.com>; u-boot@lists.denx.de > Cc: Yunfeng Ding <yunfeng.ding@nxp.com>; joe.hershberger@ni.com > Subject: [EXT] Re: [PATCH] net: pfe_eth: Use spi_flash_read API to access flash > memory > > Caution: EXT Email > > On 11.12.19 12:53, Kuldeep Singh wrote: > > Current PFE firmware access spi-nor memory directly. New spi-mem > > framework does not support direct memory access. So, let's use > > spi_flash_read API to access memory instead of directly using it. > > > > Signed-off-by: Kuldeep Singh <kuldeep.singh@nxp.com> > > --- > > drivers/net/pfe_eth/pfe_firmware.c | 44 > +++++++++++++++++++++++++++++- > > include/configs/ls1012a_common.h | 5 +++- > > 2 files changed, 47 insertions(+), 2 deletions(-) > > > > diff --git a/drivers/net/pfe_eth/pfe_firmware.c > > b/drivers/net/pfe_eth/pfe_firmware.c > > index e4563f192b..61d1b96305 100644 > > --- a/drivers/net/pfe_eth/pfe_firmware.c > > +++ b/drivers/net/pfe_eth/pfe_firmware.c > > @@ -12,13 +12,14 @@ > > > > #include <net/pfe_eth/pfe_eth.h> > > #include <net/pfe_eth/pfe_firmware.h> > > +#include <spi_flash.h> > > #ifdef CONFIG_CHAIN_OF_TRUST > > #include <fsl_validate.h> > > #endif > > > > #define PFE_FIRMWARE_FIT_CNF_NAME "config@1" > > > > -static const void *pfe_fit_addr = (void *)CONFIG_SYS_LS_PFE_FW_ADDR; > > +static const void *pfe_fit_addr; > > > > /* > > * PFE elf firmware loader. > > @@ -159,6 +160,43 @@ static int pfe_fit_check(void) > > return ret; > > } > > > > +int pfe_spi_flash_init(void) > > +{ > > + struct spi_flash *pfe_flash; > > + int ret = 0; > > + void *addr = malloc(CONFIG_SYS_QE_FMAN_FW_LENGTH); > > + > > +#ifdef CONFIG_DM_SPI_FLASH > > + struct udevice *new; > > + > > + /* speed and mode will be read from DT */ > > + ret = spi_flash_probe_bus_cs(CONFIG_ENV_SPI_BUS, > > + CONFIG_ENV_SPI_CS, 0, 0, &new); > > + > > + pfe_flash = dev_get_uclass_priv(new); #else > > + pfe_flash = spi_flash_probe(CONFIG_ENV_SPI_BUS, > > + CONFIG_ENV_SPI_CS, > > + CONFIG_ENV_SPI_MAX_HZ, > > + CONFIG_ENV_SPI_MODE); #endif > > + if (!pfe_flash) { > > + printf("SF: probe for pfe ucode failed\n"); > > I think you should return some error code in this case. Currently ret could still > be 0 at this point. Ok. I will return error codes in next version. Thanks Kuldeep > > > + } else { > > + ret = spi_flash_read(pfe_flash, > > + CONFIG_SYS_LS_PFE_FW_ADDR, > > + CONFIG_SYS_QE_FMAN_FW_LENGTH, > > + addr); > > + if (ret) > > + printf("SF: read for ucode failed\n"); > > + > > + pfe_fit_addr = addr; > > + spi_flash_free(pfe_flash); > > + } > > + > > + return ret; > > +} > > + > > /* > > * PFE firmware initialization. > > * Loads different firmware files from FIT image. > > @@ -183,6 +221,10 @@ int pfe_firmware_init(void) > > int ret = 0; > > int fw_count; > > > > + ret = pfe_spi_flash_init(); > > + if (ret) > > + goto err; > > + > > ret = pfe_fit_check(); > > if (ret) > > goto err; > > diff --git a/include/configs/ls1012a_common.h > > b/include/configs/ls1012a_common.h > > index 2579e2fb37..cbc5bff21c 100644 > > --- a/include/configs/ls1012a_common.h > > +++ b/include/configs/ls1012a_common.h > > @@ -36,9 +36,12 @@ > > /* Size of malloc() pool */ > > #define CONFIG_SYS_MALLOC_LEN (CONFIG_ENV_SIZE + 128 * > 1024) > > > > +/* PFE */ > > +#define CONFIG_SYS_FMAN_FW_ADDR 0x400d0000 > > +#define CONFIG_SYS_QE_FMAN_FW_LENGTH 0x10000 > > + > > /*SPI device */ > > #if defined(CONFIG_QSPI_BOOT) || defined(CONFIG_TFABOOT) > > -#define CONFIG_SYS_FMAN_FW_ADDR 0x400d0000 > > #define CONFIG_SPI_FLASH_SPANSION > > #define CONFIG_FSL_SPI_INTERFACE > > #define CONFIG_SF_DATAFLASH > >
diff --git a/drivers/net/pfe_eth/pfe_firmware.c b/drivers/net/pfe_eth/pfe_firmware.c index e4563f192b..61d1b96305 100644 --- a/drivers/net/pfe_eth/pfe_firmware.c +++ b/drivers/net/pfe_eth/pfe_firmware.c @@ -12,13 +12,14 @@ #include <net/pfe_eth/pfe_eth.h> #include <net/pfe_eth/pfe_firmware.h> +#include <spi_flash.h> #ifdef CONFIG_CHAIN_OF_TRUST #include <fsl_validate.h> #endif #define PFE_FIRMWARE_FIT_CNF_NAME "config@1" -static const void *pfe_fit_addr = (void *)CONFIG_SYS_LS_PFE_FW_ADDR; +static const void *pfe_fit_addr; /* * PFE elf firmware loader. @@ -159,6 +160,43 @@ static int pfe_fit_check(void) return ret; } +int pfe_spi_flash_init(void) +{ + struct spi_flash *pfe_flash; + int ret = 0; + void *addr = malloc(CONFIG_SYS_QE_FMAN_FW_LENGTH); + +#ifdef CONFIG_DM_SPI_FLASH + struct udevice *new; + + /* speed and mode will be read from DT */ + ret = spi_flash_probe_bus_cs(CONFIG_ENV_SPI_BUS, + CONFIG_ENV_SPI_CS, 0, 0, &new); + + pfe_flash = dev_get_uclass_priv(new); +#else + pfe_flash = spi_flash_probe(CONFIG_ENV_SPI_BUS, + CONFIG_ENV_SPI_CS, + CONFIG_ENV_SPI_MAX_HZ, + CONFIG_ENV_SPI_MODE); +#endif + if (!pfe_flash) { + printf("SF: probe for pfe ucode failed\n"); + } else { + ret = spi_flash_read(pfe_flash, + CONFIG_SYS_LS_PFE_FW_ADDR, + CONFIG_SYS_QE_FMAN_FW_LENGTH, + addr); + if (ret) + printf("SF: read for ucode failed\n"); + + pfe_fit_addr = addr; + spi_flash_free(pfe_flash); + } + + return ret; +} + /* * PFE firmware initialization. * Loads different firmware files from FIT image. @@ -183,6 +221,10 @@ int pfe_firmware_init(void) int ret = 0; int fw_count; + ret = pfe_spi_flash_init(); + if (ret) + goto err; + ret = pfe_fit_check(); if (ret) goto err; diff --git a/include/configs/ls1012a_common.h b/include/configs/ls1012a_common.h index 2579e2fb37..cbc5bff21c 100644 --- a/include/configs/ls1012a_common.h +++ b/include/configs/ls1012a_common.h @@ -36,9 +36,12 @@ /* Size of malloc() pool */ #define CONFIG_SYS_MALLOC_LEN (CONFIG_ENV_SIZE + 128 * 1024) +/* PFE */ +#define CONFIG_SYS_FMAN_FW_ADDR 0x400d0000 +#define CONFIG_SYS_QE_FMAN_FW_LENGTH 0x10000 + /*SPI device */ #if defined(CONFIG_QSPI_BOOT) || defined(CONFIG_TFABOOT) -#define CONFIG_SYS_FMAN_FW_ADDR 0x400d0000 #define CONFIG_SPI_FLASH_SPANSION #define CONFIG_FSL_SPI_INTERFACE #define CONFIG_SF_DATAFLASH
Current PFE firmware access spi-nor memory directly. New spi-mem framework does not support direct memory access. So, let's use spi_flash_read API to access memory instead of directly using it. Signed-off-by: Kuldeep Singh <kuldeep.singh@nxp.com> --- drivers/net/pfe_eth/pfe_firmware.c | 44 +++++++++++++++++++++++++++++- include/configs/ls1012a_common.h | 5 +++- 2 files changed, 47 insertions(+), 2 deletions(-)