Skip to contentSkip to conversation

tools: mkimage: Add support for i.MXRT FlexSPI Header

PATCH Applied Jesse Taube 3 participants 8 messages Jan 24, 2024 – Feb 8, 2024 Arm i.MX and Layerscape

lore
Share & tools
lore
#0 lore raw

PATCH 1/1 tools: mkimage: Add support for i.MXRT FlexSPI Header

Modify imx8m Flex SPI Configuration Block to work with imxrt. Add more Flex SPI configuration options to Kconfig.

---
 include/imximage.h | 42 +++++++++++++------------
 tools/Kconfig      | 21 +++++++++++++
 tools/imx8mimage.c | 41 ++++++++++++------------
 tools/imximage.c   | 77 ++++++++++++++++++++++++++++++++++++++++++++++
 4 files changed, 143 insertions(+), 38 deletions(-)
include/imximage.h +23 -19
index c1ecc0b7cb..a951699d0a 100644
@@ -210,33 +210,37 @@ typedef struct {
 	uint8_t datasetup;
 	uint8_t coladdrwidth;
 	uint8_t devcfgenable;
-	uint8_t reserved_2[3];
+	uint8_t deviceModeType;
+	uint16_t waitTimeCfgCommands;
 	uint8_t devmodeseq[4];
-	uint8_t devmodearg[4];
+	uint32_t devmodearg;
 	uint8_t cmd_enable;
-	uint8_t reserved_3[3];
+	uint8_t configModeType[3];
 	uint8_t cmd_seq[16] ;
 	uint8_t cmd_arg[16];
-	uint8_t controllermisc[4];
+	uint32_t controllermisc;
 	uint8_t dev_type;
 	uint8_t sflash_pad;
 	uint8_t serial_clk;
-	uint8_t lut_custom ;
-	uint8_t reserved_4[8];
-	uint8_t sflashA1[4];
-	uint8_t sflashA2[4];
-	uint8_t sflashB1[4];
-	uint8_t sflashB2[4];
-	uint8_t cspadover[4];
-	uint8_t sclkpadover[4];
-	uint8_t datapadover[4];
-	uint8_t dqspadover[4];
-	uint8_t timeout[4];
-	uint8_t commandInt[4];
-	uint8_t datavalid[4];
-	uint8_t busyoffset[2];
-	uint8_t busybitpolarity[2];
+	uint8_t lut_custom;
+	uint8_t reserved_2[8];
+	uint32_t sflashA1;
+	uint32_t sflashA2;
+	uint32_t sflashB1;
+	uint32_t sflashB2;
+	uint32_t cspadover;
+	uint32_t sclkpadover;
+	uint32_t datapadover;
+	uint32_t dqspadover;
+	uint32_t timeout;
+	uint32_t commandInt;
+	uint16_t datavalid[2];
+	uint16_t busyoffset;
+	uint16_t busybitpolarity;
 	uint8_t lut[256];
+	uint8_t lutCustomSeq[48];
+	uint8_t reserved_3[16];
+
 } __attribute__((packed)) fspi_conf;
 
 typedef void (*set_dcd_val_t)(struct imx_header *imxhdr,
tools/Kconfig +21 -0
index f01ed783e6..667807b331 100644
@@ -148,6 +148,27 @@ config SERIAL_CLK_FREQUENCY
 	  Chip specific frequency: other value 30MHz
 	  1-30MHz  2-50MHz 3-60MHz 4-75MHz 5-80MHz 6-100MHz 7-133MHz 8-166MHz
 
+config FSPI_COL_ADDR_W
+	hex "Column Address With"
+	default 0x00
+	depends on FSPI_CONF_HEADER
+	help
+	  Default 0. For HyperBus protocol, it is fixed to 3
+
+config FSPI_CONTROLLER_MISC
+	hex "FSPI miscellaneous control"
+	default 0x00000000
+	depends on FSPI_CONF_HEADER
+	help
+	  Default 0. [0x40] Controller Misc Options
+
+config FSPI_FLASH_A1_SIZE
+	hex "Size in bytes of Flash A1"
+	default 0x10000000
+	depends on FSPI_CONF_HEADER
+	help
+	  Size of Flash connected to A1 in bytes
+
 config LUT_CUSTOM_SEQUENCE
 	hex "Enable Custom Look Up Table(LUT) Sequence"
 	default 0x00
tools/imx8mimage.c +22 -19

58 lines not on this page · raw message

tools/imximage.c +77 -0

95 lines not on this page · raw message

Signature · 1 line
2.43.0
reviewer
#1 lore raw

Hi Adam,

Quoted 5 lines · Jesse Taube

Modify imx8m Flex SPI Configuration Block to work with imxrt. Add more Flex SPI configuration options to Kconfig.

Could you please test it on imx8mn_beacon_fspi_defconfig ?

#2 lore raw
Quoted 11 lines · Fabio Estevam

Hi Adam,

Quoted 5 lines · Jesse Taube

Modify imx8m Flex SPI Configuration Block to work with imxrt. Add more Flex SPI configuration options to Kconfig.

Could you please test it on imx8mn_beacon_fspi_defconfig ?

Yes. I was planning on doing it this weekend. I'll try to get it done sooner and report back the results.

adam

Tested-by on v1 1/1
#3 lore raw
In reply to Jesse Taube
Quoted 5 lines · Jesse Taube

Modify imx8m Flex SPI Configuration Block to work with imxrt. Add more Flex SPI configuration options to Kconfig.

I had to go back in time, because it appears the current version of 'master' doesn't fully boot the FSPI, but when I applied this patch against a working version, it still worked when I was done. I'll try to git bisect the issue when I have time, but for now:

adam

Quoted 268 lines
---
 include/imximage.h | 42 +++++++++++++------------
 tools/Kconfig      | 21 +++++++++++++
 tools/imx8mimage.c | 41 ++++++++++++------------
 tools/imximage.c   | 77 ++++++++++++++++++++++++++++++++++++++++++++++
 4 files changed, 143 insertions(+), 38 deletions(-)
include/imximage.h +23 -19
index c1ecc0b7cb..a951699d0a 100644
@@ -210,33 +210,37 @@ typedef struct {
        uint8_t datasetup;
        uint8_t coladdrwidth;
        uint8_t devcfgenable;
-       uint8_t reserved_2[3];
+       uint8_t deviceModeType;
+       uint16_t waitTimeCfgCommands;
        uint8_t devmodeseq[4];
-       uint8_t devmodearg[4];
+       uint32_t devmodearg;
        uint8_t cmd_enable;
-       uint8_t reserved_3[3];
+       uint8_t configModeType[3];
        uint8_t cmd_seq[16] ;
        uint8_t cmd_arg[16];
-       uint8_t controllermisc[4];
+       uint32_t controllermisc;
        uint8_t dev_type;
        uint8_t sflash_pad;
        uint8_t serial_clk;
-       uint8_t lut_custom ;
-       uint8_t reserved_4[8];
-       uint8_t sflashA1[4];
-       uint8_t sflashA2[4];
-       uint8_t sflashB1[4];
-       uint8_t sflashB2[4];
-       uint8_t cspadover[4];
-       uint8_t sclkpadover[4];
-       uint8_t datapadover[4];
-       uint8_t dqspadover[4];
-       uint8_t timeout[4];
-       uint8_t commandInt[4];
-       uint8_t datavalid[4];
-       uint8_t busyoffset[2];
-       uint8_t busybitpolarity[2];
+       uint8_t lut_custom;
+       uint8_t reserved_2[8];
+       uint32_t sflashA1;
+       uint32_t sflashA2;
+       uint32_t sflashB1;
+       uint32_t sflashB2;
+       uint32_t cspadover;
+       uint32_t sclkpadover;
+       uint32_t datapadover;
+       uint32_t dqspadover;
+       uint32_t timeout;
+       uint32_t commandInt;
+       uint16_t datavalid[2];
+       uint16_t busyoffset;
+       uint16_t busybitpolarity;
        uint8_t lut[256];
+       uint8_t lutCustomSeq[48];
+       uint8_t reserved_3[16];
+
 } __attribute__((packed)) fspi_conf;
 
 typedef void (*set_dcd_val_t)(struct imx_header *imxhdr,
tools/Kconfig +21 -0
index f01ed783e6..667807b331 100644
@@ -148,6 +148,27 @@ config SERIAL_CLK_FREQUENCY
          Chip specific frequency: other value 30MHz
          1-30MHz  2-50MHz 3-60MHz 4-75MHz 5-80MHz 6-100MHz 7-133MHz 8-166MHz
 
+config FSPI_COL_ADDR_W
+       hex "Column Address With"
+       default 0x00
+       depends on FSPI_CONF_HEADER
+       help
+         Default 0. For HyperBus protocol, it is fixed to 3
+
+config FSPI_CONTROLLER_MISC
+       hex "FSPI miscellaneous control"
+       default 0x00000000
+       depends on FSPI_CONF_HEADER
+       help
+         Default 0. [0x40] Controller Misc Options
+
+config FSPI_FLASH_A1_SIZE
+       hex "Size in bytes of Flash A1"
+       default 0x10000000
+       depends on FSPI_CONF_HEADER
+       help
+         Size of Flash connected to A1 in bytes
+
 config LUT_CUSTOM_SEQUENCE
        hex "Enable Custom Look Up Table(LUT) Sequence"
        default 0x00
tools/imx8mimage.c +22 -19
index 21075c2379..939f829a9f 100644
@@ -426,36 +426,39 @@ static int generate_fspi_header (int ifd)
        .read_sample = CONFIG_READ_CLK_SOURCE,
        .datahold =  0x03,
        .datasetup = 0x03,
-       .coladdrwidth = 0x00,
+       .coladdrwidth = CONFIG_FSPI_COL_ADDR_W,
        .devcfgenable = 0x00,
-       .reserved_2 = {0x00, 0x00, 0x00},
+       .deviceModeType = 0x00,
+       .waitTimeCfgCommands = 0x0000,
        .devmodeseq =  {0x00, 0x00, 0x00, 0x00},
-       .devmodearg =  {0x00, 0x00, 0x00, 0x00},
+       .devmodearg =  0x00000000,
        .cmd_enable =  0x00,
-       .reserved_3 = {0x00},
+       .configModeType = {0x00},
        .cmd_seq = {0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
                                                        0x00, 0x00, 0x00, 0x00, 0x00, 0x00},
        .cmd_arg = {0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
                                                        0x00, 0x00, 0x00, 0x00, 0x00, 0x00},
-       .controllermisc = {0x00, 0x00, 0x00, 0x00},
+       .controllermisc = cpu_to_le32(CONFIG_FSPI_CONTROLLER_MISC),
        .dev_type = CONFIG_DEVICE_TYPE,
        .sflash_pad = CONFIG_FLASH_PAD_TYPE,
        .serial_clk = CONFIG_SERIAL_CLK_FREQUENCY,
        .lut_custom = CONFIG_LUT_CUSTOM_SEQUENCE,
-       .reserved_4 = {0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00},
-       .sflashA1  =  {0x00, 0x00, 0x00, 0x10},
-       .sflashA2 = {0x00, 0x00, 0x00, 0x00},
-       .sflashB1 = {0x00, 0x00, 0x00, 0x00},
-       .sflashB2 =  {0x00, 0x00, 0x00, 0x00},
-       .cspadover = {0x00, 0x00, 0x00, 0x00},
-       .sclkpadover = {0x00, 0x00, 0x00, 0x00},
-       .datapadover = {0x00, 0x00, 0x00, 0x00},
-       .dqspadover = {0x00, 0x00, 0x00, 0x00},
-       .timeout =  {0x00, 0x00, 0x00, 0x00},
-       .commandInt = {0x00, 0x00, 0x00, 0x00},
-       .datavalid  = {0x00, 0x00, 0x00, 0x00},
-       .busyoffset = {0x00, 0x00},
-       .busybitpolarity = {0x00, 0x00},
+       .reserved_2 = {0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00},
+       .sflashA1  =  cpu_to_le32(CONFIG_FSPI_FLASH_A1_SIZE),
+       .sflashA2 = 0x00000000,
+       .sflashB1 = 0x00000000,
+       .sflashB2 = 0x00000000,
+       .cspadover = 0x00000000,
+       .sclkpadover = 0x00000000,
+       .datapadover = 0x00000000,
+       .dqspadover = 0x00000000,
+       .timeout =  0x00000000,
+       .commandInt = 0x00000000,
+       .datavalid  = {0x0000, 0x0000},
+       .busyoffset = 0x0000,
+       .busybitpolarity = 0x0000,
+       .lutCustomSeq = {0x00},
+       .reserved_3 = {0x00}
        };
 
        for (val = strtok(lut_str, ","); val; val = strtok(NULL, ",")) {
tools/imximage.c +77 -1
index b3da1f244c..2df4c7dd49 100644
@@ -908,6 +908,64 @@ int imximage_check_params(struct image_tool_params *params)
                (params->xflag) || !(strlen(params->imagename));
 }
 
+#ifdef CONFIG_FSPI_CONF_HEADER
+static void generate_fspi_header(int ifd)
+{
+       int i = 0;
+       char *val;
+       char lut_str[] = CONFIG_LUT_SEQUENCE;
+
+       fspi_conf fspi_conf_data = {
+       .tag = {0x46, 0x43, 0x46, 0x42},
+       .version = {0x00, 0x00, 0x01, 0x56},
+       .reserved_1 = {0x00, 0x00, 0x00, 0x00},
+       .read_sample = CONFIG_READ_CLK_SOURCE,
+       .datahold =  0x03,
+       .datasetup = 0x03,
+       .coladdrwidth = CONFIG_FSPI_COL_ADDR_W,
+       .devcfgenable = 0x00,
+       .deviceModeType = 0x00,
+       .waitTimeCfgCommands = 0x0000,
+       .devmodeseq =  {0x00, 0x00, 0x00, 0x00},
+       .devmodearg =  0x00000000,
+       .cmd_enable =  0x00,
+       .configModeType = {0x00},
+       .cmd_seq = {0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
+                                                       0x00, 0x00, 0x00, 0x00, 0x00, 0x00},
+       .cmd_arg = {0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
+                                                       0x00, 0x00, 0x00, 0x00, 0x00, 0x00},
+       .controllermisc = cpu_to_le32(CONFIG_FSPI_CONTROLLER_MISC),
+       .dev_type = CONFIG_DEVICE_TYPE,
+       .sflash_pad = CONFIG_FLASH_PAD_TYPE,
+       .serial_clk = CONFIG_SERIAL_CLK_FREQUENCY,
+       .lut_custom = CONFIG_LUT_CUSTOM_SEQUENCE,
+       .reserved_2 = {0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00},
+       .sflashA1  =  cpu_to_le32(CONFIG_FSPI_FLASH_A1_SIZE),
+       .sflashA2 = 0x00000000,
+       .sflashB1 = 0x00000000,
+       .sflashB2 = 0x00000000,
+       .cspadover = 0x00000000,
+       .sclkpadover = 0x00000000,
+       .datapadover = 0x00000000,
+       .dqspadover = 0x00000000,
+       .timeout =  0x00000000,
+       .commandInt = 0x00000000,
+       .datavalid  = {0x0000, 0x0000},
+       .busyoffset = 0x0000,
+       .busybitpolarity = 0x0000,
+       .lutCustomSeq = {0x00},
+       .reserved_3 = {0x00}
+       };
+
+       for (val = strtok(lut_str, ","); val; val = strtok(NULL, ","))
+               fspi_conf_data.lut[i++] = strtoul(val, NULL, 16);
+
+       lseek(ifd, 0, SEEK_CUR);
+       if (write(ifd, &fspi_conf_data, sizeof(fspi_conf_data)) == -1)
+               exit(EXIT_FAILURE);
+}
+#endif
+
 static int imximage_generate(struct image_tool_params *params,
        struct image_type_params *tparams)
 {
@@ -917,6 +975,11 @@ static int imximage_generate(struct image_tool_params *params,
        char *datafile = params->datafile;
        uint32_t pad_len, header_size;
 
+#ifdef CONFIG_FSPI_CONF_HEADER
+       int fspi_fd;
+       char *fspi;
+#endif
+
        memset(&imximage_header, 0, sizeof(imximage_header));
 
        /*
@@ -977,6 +1040,20 @@ static int imximage_generate(struct image_tool_params *params,
 
        pad_len = ROUND(sbuf.st_size, 4096) - sbuf.st_size;
 
+#ifdef CONFIG_FSPI_CONF_HEADER
+       fspi = CONFIG_FSPI_CONF_FILE;
+       fspi_fd = open(fspi, O_RDWR | O_CREAT, S_IRWXU);
+       if (fspi_fd < 0) {
+               fprintf(stderr, "Can't open %s: %s\n",
+                       fspi, strerror(errno));
+               exit(EXIT_FAILURE);
+       }
+
+       generate_fspi_header(fspi_fd);
+       close(fspi_fd);
+
+#endif
+
        return pad_len;
 }
 
--

2.43.0

reviewer
#4 lore raw

Hi Adam,

Quoted 6 lines · Adam Ford

I had to go back in time, because it appears the current version of 'master' doesn't fully boot the FSPI, but when I applied this patch against a working version, it still worked when I was done. I'll try to git bisect the issue when I have time, but for now:

Thanks for testing, appreciate it. I will queue this one.

Hopefully, we can figure out the cause of the regression.

#5 lore raw
Quoted 5 lines · Fabio Estevam

Hi Adam,

On Thu, Jan 25, 2024 at 7:37 PM Adam Ford <[email protected]> wrote:

Quoted 9 lines
Quoted 6 lines

I had to go back in time, because it appears the current version of 'master' doesn't fully boot the FSPI, but when I applied this patch against a working version, it still worked when I was done. I'll try to git bisect the issue when I have time, but for now:

Thanks for testing, appreciate it. I will queue this one.

No problem. Sorry it took so long.

Quoted 1 line

Hopefully, we can figure out the cause of the regression.

I must have done something wrong when I tested this before, because it's working fine for me now even when applied against the main trunk, so I think all is good.

adam