Skip to contentSkip to conversation

5p80: Add SFDP support

PATCH In review Cédric Le Goater 3 participants 16 messages Sep 2, 2020 – Oct 7, 2020

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

v2 cover 5p80: Add SFDP support

Hello,

JEDEC STANDARD JESD216 for Serial Flash Discovery Parameters (SFDP) provides a mean to describe the features of a serial flash device using a set of internal parameter tables. Support in Linux has been added some time ago and the spi-nor driver is using it more often to detect the flash settings and even flash models.

This is the initial framework for the RDSFDP command giving access to a private SFDP area under the flash.

The patches available here :

https://github.com/legoater/qemu/commits/aspeed-5.2

Thanks,

C.

Changes in v2:

- fixed dummy value
- replaced 'sfdp' table by a 'sfdp_read' handler
- more SFDP tables
- fixed Aspeed SMC support
- introduced mx25l25635f chip model for test under Linux.

Cédric Le Goater (9):
m25p80: Add basic support for the SFDP command
m25p80: Add the n25q256a SFDP table
m25p80: Add the mx25l25635e SFPD table
m25p80: Add the mx25l25635f SFPD table
m25p80: Add the mx66l1g45g SFDP table
m25p80: Add the w25q256 SFPD table
m25p80: Add the w25q512jv SFPD table
arm/aspeed: Replace mx25l25635e chip model
aspeed/smc: Add support for RDSFDP command

 hw/block/m25p80_sfdp.h      |  27 ++++
 include/hw/ssi/aspeed_smc.h |   1 +
 hw/arm/aspeed.c             |   6 +-
 hw/block/m25p80.c           |  47 +++++-
 hw/block/m25p80_sfdp.c      | 296 ++++++++++++++++++++++++++++++++++++
 hw/ssi/aspeed_smc.c         |  21 ++-
 MAINTAINERS                 |   2 +-
 hw/block/meson.build        |   1 +
 hw/block/trace-events       |   1 +
 9 files changed, 385 insertions(+), 17 deletions(-)
 create mode 100644 hw/block/m25p80_sfdp.h
 create mode 100644 hw/block/m25p80_sfdp.c
Signature · 1 line
2.25.4
#1 lore raw

PATCH v2 1/9 m25p80: Add basic support for the SFDP command

JEDEC STANDARD JESD216 for Serial Flash Discovery Parameters (SFDP) provides a mean to describe the features of a serial flash device using a set of internal parameter tables.

This is the initial framework for the RDSFDP command giving access to a private SFDP area under the flash. This area now needs to be populated with the flash device characteristics, using a new 'sfdp_read' handler under FlashPartInfo.

---
 hw/block/m25p80_sfdp.h | 18 ++++++++++++++++++
 hw/block/m25p80.c      | 27 +++++++++++++++++++++++++++
 MAINTAINERS            |  2 +-
 hw/block/trace-events  |  1 +
 4 files changed, 47 insertions(+), 1 deletion(-)
 create mode 100644 hw/block/m25p80_sfdp.h
hw/block/m25p80_sfdp.h new file +18 -0
new file mode 100644
index 000000000000..230b07ef3308
@@ -0,0 +1,18 @@
+/*
+ * M25P80 SFDP
+ *
+ * Copyright (c) 2020, IBM Corporation.
+ *
+ * This code is licensed under the GPL version 2 or later. See the
+ * COPYING file in the top-level directory.
+ */
+
+#ifndef HW_M25P80_SFDP_H
+#define HW_M25P80_SFDP_H
+
+/*
+ * SFDP area has a 3 bytes address space.
+ */
+#define M25P80_SFDP_MAX_SIZE  (1 << 24)
+
+#endif
hw/block/m25p80.c +27 -0
index 15824450cd10..4d6133b3594e 100644
@@ -33,6 +33,7 @@
 #include "qemu/error-report.h"
 #include "qapi/error.h"
 #include "trace.h"
+#include "m25p80_sfdp.h"
 
 /* Fields for FlashPartInfo->flags */
 
@@ -72,6 +73,7 @@ typedef struct FlashPartInfo {
      * This field inform how many die is in the chip.
      */
     uint8_t die_cnt;
+    uint8_t (*sfdp_read)(uint32_t sfdp_addr);
 } FlashPartInfo;
 
 /* adapted from linux */
@@ -336,6 +338,7 @@ typedef enum {
     BULK_ERASE = 0xc7,
     READ_FSR = 0x70,
     RDCR = 0x15,
+    RDSFDP = 0x5a,
 
     READ = 0x03,
     READ4 = 0x13,
@@ -401,6 +404,7 @@ typedef enum {
     STATE_COLLECTING_DATA,
     STATE_COLLECTING_VAR_LEN_DATA,
     STATE_READING_DATA,
+    STATE_READING_SFDP,
 } CMDState;
 
 typedef enum {
@@ -622,6 +626,8 @@ static inline int get_addr_length(Flash *s)
     }
 
    switch (s->cmd_in_progress) {
+   case RDSFDP:
+       return 3;
    case PP4:
    case PP4_4:
    case QPP_4:
@@ -747,6 +753,11 @@ static void complete_collecting_data(Flash *s)
                           " by device\n");
         }
         break;
+
+    case RDSFDP:
+        s->state = STATE_READING_SFDP;
+        break;
+
     default:
         break;
     }
@@ -1163,6 +1174,16 @@ static void decode_new_cmd(Flash *s, uint32_t value)
     case RSTQIO:
         s->quad_enable = false;
         break;
+    case RDSFDP:
+        if (s->pi->sfdp_read) {
+            s->needed_bytes = get_addr_length(s) + 8 ; /* SFDP addr + dummy */
+            s->pos = 0;
+            s->len = 0;
+            s->state = STATE_COLLECTING_DATA;
+            break;
+        }
+        /* Fallthrough */
+
     default:
         s->pos = 0;
         s->len = 1;
@@ -1259,6 +1280,12 @@ static uint32_t m25p80_transfer8(SSISlave *ss, uint32_t tx)
             }
         }
         break;
+    case STATE_READING_SFDP:
+        assert(s->pi->sfdp_read);
+        r = s->pi->sfdp_read(s->cur_addr);
+        trace_m25p80_read_sfdp(s, s->cur_addr, (uint8_t)r);
+        s->cur_addr = (s->cur_addr + 1) & (M25P80_SFDP_MAX_SIZE - 1);
+        break;
 
     default:
     case STATE_IDLE:
MAINTAINERS +1 -1
index 5a22c8be4296..dc8769b8303e 100644
@@ -1669,7 +1669,7 @@ SSI
 M: Alistair Francis <[email protected]>
 S: Maintained
 F: hw/ssi/*
-F: hw/block/m25p80.c
+F: hw/block/m25p80*
 F: include/hw/ssi/ssi.h
 X: hw/ssi/xilinx_*
 F: tests/qtest/m25p80-test.c
hw/block/trace-events +1 -0
index 958fcc5508d1..53d377ca2b46 100644
@@ -152,5 +152,6 @@ m25p80_page_program(void *s, uint32_t addr, uint8_t tx) "[%p] page program cur_a
 m25p80_transfer(void *s, uint8_t state, uint32_t len, uint8_t needed, uint32_t pos, uint32_t cur_addr, uint8_t t) "[%p] Transfer state 0x%"PRIx8" len 0x%"PRIx32" needed 0x%"PRIx8" pos 0x%"PRIx32" addr 0x%"PRIx32" tx 0x%"PRIx8
 m25p80_read_byte(void *s, uint32_t addr, uint8_t v) "[%p] Read byte 0x%"PRIx32"=0x%"PRIx8
 m25p80_read_data(void *s, uint32_t pos, uint8_t v) "[%p] Read data 0x%"PRIx32"=0x%"PRIx8
+m25p80_read_sfdp(void *s, uint32_t addr, uint8_t v) "[%p] Read SFDP 0x%"PRIx32"=0x%"PRIx8
 m25p80_binding(void *s) "[%p] Binding to IF_MTD drive"
 m25p80_binding_no_bdrv(void *s) "[%p] No BDRV - binding to RAM"
Signature · 1 line
2.25.4
#2 lore raw

PATCH v2 2/9 m25p80: Add the n25q256a SFDP table

In reply to Cédric Le Goater

The same values were collected on 4 differents OpenPower systems, palmettos, romulus and tacoma.

The SFDP table size is defined as being 0x100 bytes but it could be bigger. Only the mandatory table for basic features is available at byte 0x30.

---
 hw/block/m25p80_sfdp.h |  2 ++
 hw/block/m25p80.c      |  6 +++--
 hw/block/m25p80_sfdp.c | 58 ++++++++++++++++++++++++++++++++++++++++++
 hw/block/meson.build   |  1 +
 4 files changed, 65 insertions(+), 2 deletions(-)
 create mode 100644 hw/block/m25p80_sfdp.c
hw/block/m25p80_sfdp.h +2 -0
index 230b07ef3308..d3a0a778ae84 100644
@@ -15,4 +15,6 @@
  */
 #define M25P80_SFDP_MAX_SIZE  (1 << 24)
 
+extern uint8_t m25p80_sfdp_n25q256a(uint32_t addr);
+
 #endif
hw/block/m25p80.c +4 -2
index 4d6133b3594e..dbfd88b41a12 100644
@@ -234,11 +234,13 @@ static const FlashPartInfo known_devices[] = {
     { INFO("n25q128a11",  0x20bb18,      0,  64 << 10, 256, ER_4K) },
     { INFO("n25q128a13",  0x20ba18,      0,  64 << 10, 256, ER_4K) },
     { INFO("n25q256a11",  0x20bb19,      0,  64 << 10, 512, ER_4K) },
-    { INFO("n25q256a13",  0x20ba19,      0,  64 << 10, 512, ER_4K) },
+    { INFO("n25q256a13",  0x20ba19,      0,  64 << 10, 512, ER_4K),
+      .sfdp_read = m25p80_sfdp_n25q256a },
     { INFO("n25q512a11",  0x20bb20,      0,  64 << 10, 1024, ER_4K) },
     { INFO("n25q512a13",  0x20ba20,      0,  64 << 10, 1024, ER_4K) },
     { INFO("n25q128",     0x20ba18,      0,  64 << 10, 256, 0) },
-    { INFO("n25q256a",    0x20ba19,      0,  64 << 10, 512, ER_4K) },
+    { INFO("n25q256a",    0x20ba19,      0,  64 << 10, 512, ER_4K),
+      .sfdp_read = m25p80_sfdp_n25q256a },
     { INFO("n25q512a",    0x20ba20,      0,  64 << 10, 1024, ER_4K) },
     { INFO("n25q512ax3",  0x20ba20,  0x1000,  64 << 10, 1024, ER_4K) },
     { INFO("mt25ql512ab", 0x20ba20, 0x1044, 64 << 10, 1024, ER_4K | ER_32K) },
hw/block/m25p80_sfdp.c new file +58 -0

58 lines not on this page · raw message

hw/block/meson.build +1 -0
index 78cad8f7cba1..6f0380a12081 100644
@@ -10,6 +10,7 @@ softmmu_ss.add(when: 'CONFIG_ONENAND', if_true: files('onenand.c'))
 softmmu_ss.add(when: 'CONFIG_PFLASH_CFI01', if_true: files('pflash_cfi01.c'))
 softmmu_ss.add(when: 'CONFIG_PFLASH_CFI02', if_true: files('pflash_cfi02.c'))
 softmmu_ss.add(when: 'CONFIG_SSI_M25P80', if_true: files('m25p80.c'))
+softmmu_ss.add(when: 'CONFIG_SSI_M25P80', if_true: files('m25p80_sfdp.c'))
 softmmu_ss.add(when: 'CONFIG_SWIM', if_true: files('swim.c'))
 softmmu_ss.add(when: 'CONFIG_XEN', if_true: files('xen-block.c'))
 softmmu_ss.add(when: 'CONFIG_SH4', if_true: files('tc58128.c'))
Signature · 1 line
2.25.4
#3 lore raw

Re: [PATCH v2 2/9] m25p80: Add the n25q256a SFDP table

Hi Cedric,

Quoted 21 lines · Cédric Le Goater

The same values were collected on 4 differents OpenPower systems, palmettos, romulus and tacoma.

The SFDP table size is defined as being 0x100 bytes but it could be bigger. Only the mandatory table for basic features is available at byte 0x30.

---
 hw/block/m25p80_sfdp.h |  2 ++
 hw/block/m25p80.c      |  6 +++--
 hw/block/m25p80_sfdp.c | 58 ++++++++++++++++++++++++++++++++++++++++++
 hw/block/meson.build   |  1 +
 4 files changed, 65 insertions(+), 2 deletions(-)
 create mode 100644 hw/block/m25p80_sfdp.c
hw/block/m25p80_sfdp.h +0 -0
index 230b07ef3308..d3a0a778ae84 100644

hw/block/m25p80_sfdp.h line 18

Quoted 4 lines
hw/block/m25p80_sfdp.h +1 -0
@@ -15,4 +15,6 @@
  */
 #define M25P80_SFDP_MAX_SIZE  (1 << 24)
 
+extern uint8_t m25p80_sfdp_n25q256a(uint32_t addr);

s/extern//

Quoted 74 lines
hw/block/m25p80_sfdp.h +1 -0
+
 #endif
hw/block/m25p80.c +4 -2
index 4d6133b3594e..dbfd88b41a12 100644
@@ -234,11 +234,13 @@ static const FlashPartInfo known_devices[] = {
     { INFO("n25q128a11",  0x20bb18,      0,  64 << 10, 256, ER_4K) },
     { INFO("n25q128a13",  0x20ba18,      0,  64 << 10, 256, ER_4K) },
     { INFO("n25q256a11",  0x20bb19,      0,  64 << 10, 512, ER_4K) },
-    { INFO("n25q256a13",  0x20ba19,      0,  64 << 10, 512, ER_4K) },
+    { INFO("n25q256a13",  0x20ba19,      0,  64 << 10, 512, ER_4K),
+      .sfdp_read = m25p80_sfdp_n25q256a },
     { INFO("n25q512a11",  0x20bb20,      0,  64 << 10, 1024, ER_4K) },
     { INFO("n25q512a13",  0x20ba20,      0,  64 << 10, 1024, ER_4K) },
     { INFO("n25q128",     0x20ba18,      0,  64 << 10, 256, 0) },
-    { INFO("n25q256a",    0x20ba19,      0,  64 << 10, 512, ER_4K) },
+    { INFO("n25q256a",    0x20ba19,      0,  64 << 10, 512, ER_4K),
+      .sfdp_read = m25p80_sfdp_n25q256a },
     { INFO("n25q512a",    0x20ba20,      0,  64 << 10, 1024, ER_4K) },
     { INFO("n25q512ax3",  0x20ba20,  0x1000,  64 << 10, 1024, ER_4K) },
     { INFO("mt25ql512ab", 0x20ba20, 0x1044, 64 << 10, 1024, ER_4K | ER_32K) },
hw/block/m25p80_sfdp.c new file +46 -0
new file mode 100644
index 000000000000..24ec05de79a1
@@ -0,0 +1,58 @@
+/*
+ * M25P80 Serial Flash Discoverable Parameter (SFDP)
+ *
+ * Copyright (c) 2020, IBM Corporation.
+ *
+ * This code is licensed under the GPL version 2 or later. See the
+ * COPYING file in the top-level directory.
+ */
+
+#include "qemu/osdep.h"
+#include "qemu/host-utils.h"
+#include "m25p80_sfdp.h"
+
+#define define_sfdp_read(model)                                       \
+    uint8_t m25p80_sfdp_##model(uint32_t addr)                        \
+    {                                                                 \
+        assert(is_power_of_2(sizeof(sfdp_##model)));                  \
+        return sfdp_##model[addr & (sizeof(sfdp_##model) - 1)];       \
+    }
+
+/*
+ * Micron
+ */
+static const uint8_t sfdp_n25q256a[] = {
+    0x53, 0x46, 0x44, 0x50, 0x00, 0x01, 0x00, 0xff,
+    0x00, 0x00, 0x01, 0x09, 0x30, 0x00, 0x00, 0xff,
+    0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff,
+    0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff,
+    0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff,
+    0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff,
+    0xe5, 0x20, 0xfb, 0xff, 0xff, 0xff, 0xff, 0x0f,
+    0x29, 0xeb, 0x27, 0x6b, 0x08, 0x3b, 0x27, 0xbb,
+    0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0x27, 0xbb,
+    0xff, 0xff, 0x29, 0xeb, 0x0c, 0x20, 0x10, 0xd8,
+    0x00, 0x00, 0x00, 0x00, 0xff, 0xff, 0xff, 0xff,
+    0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff,
+    0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff,
+    0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff,
+    0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff,
+    0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff,
+    0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff,
+    0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff,
+    0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff,
+    0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff,
+    0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff,
+    0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff,

hw/block/m25p80_sfdp.c line 56

Quoted 10 lines
hw/block/m25p80_sfdp.c new file +10 -0
+    0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff,
+    0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff,
+    0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff,
+    0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff,
+    0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff,
+    0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff,
+    0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff,
+    0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff,
+    0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff,
+    0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff,

Looking at the SFDP spec I have it says that reserved locations (unused or not yet defined memory in the address space) are recommended to return 0xFF. Do you think we could use that and somehow and return 0xFF by default above instead of having them in the array? (The file will not grow as fast then)

Best regards,
Francisco Iglesias

Quoted 17 lines
hw/block/m25p80_sfdp.c new file +2 -0
+};
+define_sfdp_read(n25q256a);
hw/block/meson.build +1 -0
index 78cad8f7cba1..6f0380a12081 100644
@@ -10,6 +10,7 @@ softmmu_ss.add(when: 'CONFIG_ONENAND', if_true: files('onenand.c'))
 softmmu_ss.add(when: 'CONFIG_PFLASH_CFI01', if_true: files('pflash_cfi01.c'))
 softmmu_ss.add(when: 'CONFIG_PFLASH_CFI02', if_true: files('pflash_cfi02.c'))
 softmmu_ss.add(when: 'CONFIG_SSI_M25P80', if_true: files('m25p80.c'))
+softmmu_ss.add(when: 'CONFIG_SSI_M25P80', if_true: files('m25p80_sfdp.c'))
 softmmu_ss.add(when: 'CONFIG_SWIM', if_true: files('swim.c'))
 softmmu_ss.add(when: 'CONFIG_XEN', if_true: files('xen-block.c'))
 softmmu_ss.add(when: 'CONFIG_SH4', if_true: files('tc58128.c'))
Signature · 1 line
2.25.4
#4 lore raw

PATCH v2 3/9 m25p80: Add the mx25l25635e SFPD table

In reply to Cédric Le Goater

The SFDP table is 0x80 bytes long. The mandatory table for basic features is available at byte 0x30 and an extra Macronix specific table is available at 0x60.

4B opcodes are not supported.

---
 hw/block/m25p80_sfdp.h |  3 +++
 hw/block/m25p80.c      |  3 ++-
 hw/block/m25p80_sfdp.c | 26 ++++++++++++++++++++++++++
 3 files changed, 31 insertions(+), 1 deletion(-)
hw/block/m25p80_sfdp.h +3 -0
index d3a0a778ae84..0c46e669b335 100644
@@ -17,4 +17,7 @@
 
 extern uint8_t m25p80_sfdp_n25q256a(uint32_t addr);
 
+extern uint8_t m25p80_sfdp_mx25l25635e(uint32_t addr);
+
+
 #endif
hw/block/m25p80.c +2 -1
index dbfd88b41a12..757beab3065f 100644
@@ -219,7 +219,8 @@ static const FlashPartInfo known_devices[] = {
     { INFO("mx25l6405d",  0xc22017,      0,  64 << 10, 128, 0) },
     { INFO("mx25l12805d", 0xc22018,      0,  64 << 10, 256, 0) },
     { INFO("mx25l12855e", 0xc22618,      0,  64 << 10, 256, 0) },
-    { INFO6("mx25l25635e", 0xc22019,     0xc22019,  64 << 10, 512, 0) },
+    { INFO6("mx25l25635e", 0xc22019,     0xc22019,  64 << 10, 512, 0),
+      .sfdp_read = m25p80_sfdp_mx25l25635e },
     { INFO("mx25l25655e", 0xc22619,      0,  64 << 10, 512, 0) },
     { INFO("mx66l51235f", 0xc2201a,      0,  64 << 10, 1024, ER_4K | ER_32K) },
     { INFO("mx66u51235f", 0xc2253a,      0,  64 << 10, 1024, ER_4K | ER_32K) },
hw/block/m25p80_sfdp.c +26 -0
index 24ec05de79a1..6499c4c39954 100644
@@ -56,3 +56,29 @@ static const uint8_t sfdp_n25q256a[] = {
     0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff,
 };
 define_sfdp_read(n25q256a);
+
+
+/*
+ * Matronix
+ */
+
+/* mx25l25635e. No 4B opcodes */
+static const uint8_t sfdp_mx25l25635e[] = {
+    0x53, 0x46, 0x44, 0x50, 0x00, 0x01, 0x01, 0xff,
+    0x00, 0x00, 0x01, 0x09, 0x30, 0x00, 0x00, 0xff,
+    0xc2, 0x00, 0x01, 0x04, 0x60, 0x00, 0x00, 0xff,
+    0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff,
+    0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff,
+    0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff,
+    0xe5, 0x20, 0xf3, 0xff, 0xff, 0xff, 0xff, 0x0f,
+    0x44, 0xeb, 0x08, 0x6b, 0x08, 0x3b, 0x04, 0xbb,
+    0xee, 0xff, 0xff, 0xff, 0xff, 0xff, 0x00, 0xff,
+    0xff, 0xff, 0x00, 0xff, 0x0c, 0x20, 0x0f, 0x52,
+    0x10, 0xd8, 0x00, 0xff, 0xff, 0xff, 0xff, 0xff,
+    0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff,
+    0x00, 0x36, 0x00, 0x27, 0xf7, 0x4f, 0xff, 0xff,
+    0xd9, 0xc8, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff,
+    0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff,
+    0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff,
+};
+define_sfdp_read(mx25l25635e)
Signature · 1 line
2.25.4
#5 lore raw

PATCH v2 4/9 m25p80: Add the mx25l25635f SFPD table

In reply to Cédric Le Goater

The mx25l25635e and mx25l25635f chips have the same JEDEC id but the mx25l25635f has more capabilities reported in the SFDP table. Support for 4B opcodes is of interest because it is exploited by the Linux kernel.

The SFDP table size is 0x200 bytes long. The mandatory table for basic features is available at byte 0x30 and an extra Macronix specific table is available at 0x60.

---
 hw/block/m25p80_sfdp.h |  1 +
 hw/block/m25p80.c      |  2 ++
 hw/block/m25p80_sfdp.c | 68 ++++++++++++++++++++++++++++++++++++++++++
 3 files changed, 71 insertions(+)
hw/block/m25p80_sfdp.h +1 -0
index 0c46e669b335..87690a173c78 100644
@@ -18,6 +18,7 @@
 extern uint8_t m25p80_sfdp_n25q256a(uint32_t addr);
 
 extern uint8_t m25p80_sfdp_mx25l25635e(uint32_t addr);
+extern uint8_t m25p80_sfdp_mx25l25635f(uint32_t addr);
 
 
 #endif
hw/block/m25p80.c +2 -0
index 757beab3065f..fe4e8c8716d8 100644
@@ -221,6 +221,8 @@ static const FlashPartInfo known_devices[] = {
     { INFO("mx25l12855e", 0xc22618,      0,  64 << 10, 256, 0) },
     { INFO6("mx25l25635e", 0xc22019,     0xc22019,  64 << 10, 512, 0),
       .sfdp_read = m25p80_sfdp_mx25l25635e },
+    { INFO6("mx25l25635f", 0xc22019,     0xc22019,  64 << 10, 512, 0),
+      .sfdp_read = m25p80_sfdp_mx25l25635f },
     { INFO("mx25l25655e", 0xc22619,      0,  64 << 10, 512, 0) },
     { INFO("mx66l51235f", 0xc2201a,      0,  64 << 10, 1024, ER_4K | ER_32K) },
     { INFO("mx66u51235f", 0xc2253a,      0,  64 << 10, 1024, ER_4K | ER_32K) },
hw/block/m25p80_sfdp.c +68 -0

71 lines not on this page · raw message

Signature · 1 line
2.25.4
#6 lore raw

PATCH v2 5/9 m25p80: Add the mx66l1g45g SFDP table

In reply to Cédric Le Goater

The SFDP table size is 0x200 bytes long. The mandatory table for basic features is available at byte 0x30 plus some more Macronix specific tables.

---
 hw/block/m25p80_sfdp.h |  2 +-
 hw/block/m25p80.c      |  3 +-
 hw/block/m25p80_sfdp.c | 68 ++++++++++++++++++++++++++++++++++++++++++
 3 files changed, 71 insertions(+), 2 deletions(-)
hw/block/m25p80_sfdp.h +1 -1
index 87690a173c78..468e3434151b 100644
@@ -19,6 +19,6 @@ extern uint8_t m25p80_sfdp_n25q256a(uint32_t addr);
 
 extern uint8_t m25p80_sfdp_mx25l25635e(uint32_t addr);
 extern uint8_t m25p80_sfdp_mx25l25635f(uint32_t addr);
-
+extern uint8_t m25p80_sfdp_mx66l1g45g(uint32_t addr);
 
 #endif
hw/block/m25p80.c +2 -1
index fe4e8c8716d8..9f1fe01c0d05 100644
@@ -227,7 +227,8 @@ static const FlashPartInfo known_devices[] = {
     { INFO("mx66l51235f", 0xc2201a,      0,  64 << 10, 1024, ER_4K | ER_32K) },
     { INFO("mx66u51235f", 0xc2253a,      0,  64 << 10, 1024, ER_4K | ER_32K) },
     { INFO("mx66u1g45g",  0xc2253b,      0,  64 << 10, 2048, ER_4K | ER_32K) },
-    { INFO("mx66l1g45g",  0xc2201b,      0,  64 << 10, 2048, ER_4K | ER_32K) },
+    { INFO("mx66l1g45g",  0xc2201b,      0,  64 << 10, 2048, ER_4K | ER_32K),
+      .sfdp_read = m25p80_sfdp_mx66l1g45g },
 
     /* Micron */
     { INFO("n25q032a11",  0x20bb16,      0,  64 << 10,  64, ER_4K) },
hw/block/m25p80_sfdp.c +68 -0

71 lines not on this page · raw message

Signature · 1 line
2.25.4
#7 lore raw

PATCH v2 6/9 m25p80: Add the w25q256 SFPD table

In reply to Cédric Le Goater

The SFDP table size is 0x100 bytes long. Only the mandatory table for basic features is available at byte 0x80.

---
 hw/block/m25p80_sfdp.h |  2 ++
 hw/block/m25p80.c      |  3 ++-
 hw/block/m25p80_sfdp.c | 40 ++++++++++++++++++++++++++++++++++++++++
 3 files changed, 44 insertions(+), 1 deletion(-)
hw/block/m25p80_sfdp.h +2 -0
index 468e3434151b..f60429ab8542 100644
@@ -21,4 +21,6 @@ extern uint8_t m25p80_sfdp_mx25l25635e(uint32_t addr);
 extern uint8_t m25p80_sfdp_mx25l25635f(uint32_t addr);
 extern uint8_t m25p80_sfdp_mx66l1g45g(uint32_t addr);
 
+extern uint8_t m25p80_sfdp_w25q256(uint32_t addr);
+
 #endif
hw/block/m25p80.c +2 -1
index 9f1fe01c0d05..b5626a62082a 100644
@@ -327,7 +327,8 @@ static const FlashPartInfo known_devices[] = {
     { INFO("w25q64",      0xef4017,      0,  64 << 10, 128, ER_4K) },
     { INFO("w25q80",      0xef5014,      0,  64 << 10,  16, ER_4K) },
     { INFO("w25q80bl",    0xef4014,      0,  64 << 10,  16, ER_4K) },
-    { INFO("w25q256",     0xef4019,      0,  64 << 10, 512, ER_4K) },
+    { INFO("w25q256",     0xef4019,      0,  64 << 10, 512, ER_4K),
+      .sfdp_read = m25p80_sfdp_w25q256 },
     { INFO("w25q512jv",   0xef4020,      0,  64 << 10, 1024, ER_4K) },
 };
 
hw/block/m25p80_sfdp.c +40 -0
index 38c3ced34d2e..5b011559d43d 100644
@@ -218,3 +218,43 @@ static const uint8_t sfdp_mx66l1g45g[] = {
     0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff,
 };
 define_sfdp_read(mx66l1g45g);
+
+/*
+ * Windbond
+ */
+
+static const uint8_t sfdp_w25q256[] = {
+    0x53, 0x46, 0x44, 0x50, 0x00, 0x01, 0x00, 0xff,
+    0x00, 0x00, 0x01, 0x09, 0x80, 0x00, 0x00, 0xff,
+    0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff,
+    0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff,
+    0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff,
+    0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff,
+    0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff,
+    0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff,
+    0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff,
+    0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff,
+    0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff,
+    0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff,
+    0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff,
+    0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff,
+    0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff,
+    0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff,
+    0xe5, 0x20, 0xf3, 0xff, 0xff, 0xff, 0xff, 0x0f,
+    0x44, 0xeb, 0x08, 0x6b, 0x08, 0x3b, 0x42, 0xbb,
+    0xfe, 0xff, 0xff, 0xff, 0xff, 0xff, 0x00, 0x00,
+    0xff, 0xff, 0x21, 0xeb, 0x0c, 0x20, 0x0f, 0x52,
+    0x10, 0xd8, 0x00, 0x00, 0xff, 0xff, 0xff, 0xff,
+    0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff,
+    0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff,
+    0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff,
+    0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff,
+    0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff,
+    0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff,
+    0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff,
+    0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff,
+    0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff,
+    0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff,
+    0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff,
+};
+define_sfdp_read(w25q256);
Signature · 1 line
2.25.4
#8 lore raw

PATCH v2 7/9 m25p80: Add the w25q512jv SFPD table

In reply to Cédric Le Goater

The SFDP table size is 0x100 bytes long. The mandatory table for basic features is available at byte 0x80 and two extra Winbond specifics table are available at 0xC0 and 0xF0.

---
 hw/block/m25p80_sfdp.h |  1 +
 hw/block/m25p80.c      |  3 ++-
 hw/block/m25p80_sfdp.c | 36 ++++++++++++++++++++++++++++++++++++
 3 files changed, 39 insertions(+), 1 deletion(-)
hw/block/m25p80_sfdp.h +1 -0
index f60429ab8542..62f140a2fcef 100644
@@ -22,5 +22,6 @@ extern uint8_t m25p80_sfdp_mx25l25635f(uint32_t addr);
 extern uint8_t m25p80_sfdp_mx66l1g45g(uint32_t addr);
 
 extern uint8_t m25p80_sfdp_w25q256(uint32_t addr);
+extern uint8_t m25p80_sfdp_w25q512jv(uint32_t addr);
 
 #endif
hw/block/m25p80.c +2 -1
index b5626a62082a..4f41a68f741c 100644
@@ -329,7 +329,8 @@ static const FlashPartInfo known_devices[] = {
     { INFO("w25q80bl",    0xef4014,      0,  64 << 10,  16, ER_4K) },
     { INFO("w25q256",     0xef4019,      0,  64 << 10, 512, ER_4K),
       .sfdp_read = m25p80_sfdp_w25q256 },
-    { INFO("w25q512jv",   0xef4020,      0,  64 << 10, 1024, ER_4K) },
+    { INFO("w25q512jv",   0xef4020,      0,  64 << 10, 1024, ER_4K),
+      .sfdp_read = m25p80_sfdp_w25q512jv },
 };
 
 typedef enum {
hw/block/m25p80_sfdp.c +36 -0
index 5b011559d43d..dad3d7e64f9f 100644
@@ -258,3 +258,39 @@ static const uint8_t sfdp_w25q256[] = {
     0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff,
 };
 define_sfdp_read(w25q256);
+
+static const uint8_t sfdp_w25q512jv[] = {
+    0x53, 0x46, 0x44, 0x50, 0x06, 0x01, 0x01, 0xff,
+    0x00, 0x06, 0x01, 0x10, 0x80, 0x00, 0x00, 0xff,
+    0x84, 0x00, 0x01, 0x02, 0xd0, 0x00, 0x00, 0xff,
+    0x03, 0x00, 0x01, 0x02, 0xf0, 0x00, 0x00, 0xff,
+    0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff,
+    0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff,
+    0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff,
+    0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff,
+    0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff,
+    0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff,
+    0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff,
+    0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff,
+    0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff,
+    0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff,
+    0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff,
+    0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff,
+    0xe5, 0x20, 0xfb, 0xff, 0xff, 0xff, 0xff, 0x1f,
+    0x44, 0xeb, 0x08, 0x6b, 0x08, 0x3b, 0x42, 0xbb,
+    0xfe, 0xff, 0xff, 0xff, 0xff, 0xff, 0x00, 0x00,
+    0xff, 0xff, 0x40, 0xeb, 0x0c, 0x20, 0x0f, 0x52,
+    0x10, 0xd8, 0x00, 0x00, 0x36, 0x02, 0xa6, 0x00,
+    0x82, 0xea, 0x14, 0xe2, 0xe9, 0x63, 0x76, 0x33,
+    0x7a, 0x75, 0x7a, 0x75, 0xf7, 0xa2, 0xd5, 0x5c,
+    0x19, 0xf7, 0x4d, 0xff, 0xe9, 0x70, 0xf9, 0xa5,
+    0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff,
+    0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff,
+    0xff, 0x0a, 0xf0, 0xff, 0x21, 0xff, 0xdc, 0xff,
+    0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff,
+    0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff,
+    0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff,
+    0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff,
+    0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff,
+};
+define_sfdp_read(w25q512jv);
Signature · 1 line
2.25.4
#9 lore raw

PATCH v2 8/9 arm/aspeed: Replace mx25l25635e chip model

In reply to Cédric Le Goater

A mx25l25635f chip model is generally found on these machines. It's newer and uses 4B opcodes which is better to exercise the support in the Linux kernel.

---
 hw/arm/aspeed.c | 6 +++---
 1 file changed, 3 insertions(+), 3 deletions(-)
hw/arm/aspeed.c +3 -3
index 8bfb1c79ddc5..df65d949b7e6 100644
@@ -609,7 +609,7 @@ static void aspeed_machine_palmetto_class_init(ObjectClass *oc, void *data)
     amc->soc_name  = "ast2400-a1";
     amc->hw_strap1 = PALMETTO_BMC_HW_STRAP1;
     amc->fmc_model = "n25q256a";
-    amc->spi_model = "mx25l25635e";
+    amc->spi_model = "mx25l25635f";
     amc->num_cs    = 1;
     amc->i2c_init  = palmetto_bmc_i2c_init;
     mc->default_ram_size       = 256 * MiB;
@@ -643,7 +643,7 @@ static void aspeed_machine_ast2500_evb_class_init(ObjectClass *oc, void *data)
     amc->soc_name  = "ast2500-a1";
     amc->hw_strap1 = AST2500_EVB_HW_STRAP1;
     amc->fmc_model = "w25q256";
-    amc->spi_model = "mx25l25635e";
+    amc->spi_model = "mx25l25635f";
     amc->num_cs    = 1;
     amc->i2c_init  = ast2500_evb_i2c_init;
     mc->default_ram_size       = 512 * MiB;
@@ -710,7 +710,7 @@ static void aspeed_machine_witherspoon_class_init(ObjectClass *oc, void *data)
     mc->desc       = "OpenPOWER Witherspoon BMC (ARM1176)";
     amc->soc_name  = "ast2500-a1";
     amc->hw_strap1 = WITHERSPOON_BMC_HW_STRAP1;
-    amc->fmc_model = "mx25l25635e";
+    amc->fmc_model = "mx25l25635f";
     amc->spi_model = "mx66l1g45g";
     amc->num_cs    = 2;
     amc->i2c_init  = witherspoon_bmc_i2c_init;
Signature · 1 line
2.25.4
Reviewed-by on v2 8/9
#10 lore raw

Re: [PATCH v2 8/9] arm/aspeed: Replace mx25l25635e chip model

Quoted 5 lines · Cédric Le Goater

A mx25l25635f chip model is generally found on these machines. It's newer and uses 4B opcodes which is better to exercise the support in the Linux kernel.

Quoted 38 lines
---
 hw/arm/aspeed.c | 6 +++---
 1 file changed, 3 insertions(+), 3 deletions(-)
hw/arm/aspeed.c +3 -3
index 8bfb1c79ddc5..df65d949b7e6 100644
@@ -609,7 +609,7 @@ static void aspeed_machine_palmetto_class_init(ObjectClass *oc, void *data)
     amc->soc_name  = "ast2400-a1";
     amc->hw_strap1 = PALMETTO_BMC_HW_STRAP1;
     amc->fmc_model = "n25q256a";
-    amc->spi_model = "mx25l25635e";
+    amc->spi_model = "mx25l25635f";
     amc->num_cs    = 1;
     amc->i2c_init  = palmetto_bmc_i2c_init;
     mc->default_ram_size       = 256 * MiB;
@@ -643,7 +643,7 @@ static void aspeed_machine_ast2500_evb_class_init(ObjectClass *oc, void *data)
     amc->soc_name  = "ast2500-a1";
     amc->hw_strap1 = AST2500_EVB_HW_STRAP1;
     amc->fmc_model = "w25q256";
-    amc->spi_model = "mx25l25635e";
+    amc->spi_model = "mx25l25635f";
     amc->num_cs    = 1;
     amc->i2c_init  = ast2500_evb_i2c_init;
     mc->default_ram_size       = 512 * MiB;
@@ -710,7 +710,7 @@ static void aspeed_machine_witherspoon_class_init(ObjectClass *oc, void *data)
     mc->desc       = "OpenPOWER Witherspoon BMC (ARM1176)";
     amc->soc_name  = "ast2500-a1";
     amc->hw_strap1 = WITHERSPOON_BMC_HW_STRAP1;
-    amc->fmc_model = "mx25l25635e";
+    amc->fmc_model = "mx25l25635f";
     amc->spi_model = "mx66l1g45g";
     amc->num_cs    = 2;
     amc->i2c_init  = witherspoon_bmc_i2c_init;
Signature · 1 line
2.25.4
#11 lore raw

PATCH v2 9/9 aspeed/smc: Add support for RDSFDP command

In reply to Cédric Le Goater

Modify the snooping routine to handle RDSFDP, 1 dummy and 3 bytes address space.

---
 include/hw/ssi/aspeed_smc.h |  1 +
 hw/ssi/aspeed_smc.c         | 21 ++++++++++++++-------
 2 files changed, 15 insertions(+), 7 deletions(-)
include/hw/ssi/aspeed_smc.h +1 -0
index 6fbbb238f158..5f477eb9cf97 100644
@@ -115,6 +115,7 @@ typedef struct AspeedSMCState {
 
     AspeedSMCFlash *flashes;
 
+    uint8_t snoop_addr_width;
     uint8_t snoop_index;
     uint8_t snoop_dummies;
 } AspeedSMCState;
hw/ssi/aspeed_smc.c +14 -7
index 795784e5f364..594f34668e7a 100644
@@ -778,10 +778,15 @@ typedef enum {
     PP = 0x2,           PP_4 = 0x12,
     DPP = 0xa2,
     QPP = 0x32,         QPP_4 = 0x34,
+    RDSFDP = 0x5a,
 } FlashCMD;
 
-static int aspeed_smc_num_dummies(uint8_t command)
+static int aspeed_smc_num_dummies(AspeedSMCFlash *fl, uint8_t command)
 {
+    AspeedSMCState *s = fl->controller;
+
+    s->snoop_addr_width = aspeed_smc_flash_is_4byte(fl) ? 4 : 3;
+
     switch (command) { /* check for dummies */
     case READ: /* no dummy bytes/cycles */
     case PP:
@@ -798,6 +803,9 @@ static int aspeed_smc_num_dummies(uint8_t command)
     case DOR_4:
     case QOR_4:
         return 1;
+    case RDSFDP:
+        s->snoop_addr_width = 3;
+        return 1;
     case DIOR:
     case DIOR_4:
         return 2;
@@ -813,8 +821,6 @@ static bool aspeed_smc_do_snoop(AspeedSMCFlash *fl,  uint64_t data,
                                 unsigned size)
 {
     AspeedSMCState *s = fl->controller;
-    uint8_t addr_width = aspeed_smc_flash_is_4byte(fl) ? 4 : 3;
-
     trace_aspeed_smc_do_snoop(fl->id, s->snoop_index, s->snoop_dummies,
                               (uint8_t) data & 0xff);
 
@@ -823,7 +829,7 @@ static bool aspeed_smc_do_snoop(AspeedSMCFlash *fl,  uint64_t data,
 
     } else if (s->snoop_index == SNOOP_START) {
         uint8_t cmd = data & 0xff;
-        int ndummies = aspeed_smc_num_dummies(cmd);
+        int ndummies = aspeed_smc_num_dummies(fl, cmd);
 
         /*
          * No dummy cycles are expected with the current command. Turn
@@ -836,7 +842,7 @@ static bool aspeed_smc_do_snoop(AspeedSMCFlash *fl,  uint64_t data,
 
         s->snoop_dummies = ndummies * 8;
 
-    } else if (s->snoop_index >= addr_width + 1) {
+    } else if (s->snoop_index >= s->snoop_addr_width + 1) {
 
         /* The SPI transfer has reached the dummy cycles sequence */
         for (; s->snoop_dummies; s->snoop_dummies--) {
@@ -1407,10 +1413,11 @@ static void aspeed_smc_realize(DeviceState *dev, Error **errp)
 
 static const VMStateDescription vmstate_aspeed_smc = {
     .name = "aspeed.smc",
-    .version_id = 2,
-    .minimum_version_id = 2,
+    .version_id = 3,
+    .minimum_version_id = 3,
     .fields = (VMStateField[]) {
         VMSTATE_UINT32_ARRAY(regs, AspeedSMCState, ASPEED_SMC_R_MAX),
+        VMSTATE_UINT8(snoop_addr_width, AspeedSMCState),
         VMSTATE_UINT8(snoop_index, AspeedSMCState),
         VMSTATE_UINT8(snoop_dummies, AspeedSMCState),
         VMSTATE_END_OF_LIST()
Signature · 1 line
2.25.4
#12 lore raw

Re: [PATCH v2 9/9] aspeed/smc: Add support for RDSFDP command

Hi Cedric,

Quoted 26 lines · Cédric Le Goater

Modify the snooping routine to handle RDSFDP, 1 dummy and 3 bytes address space.

---
 include/hw/ssi/aspeed_smc.h |  1 +
 hw/ssi/aspeed_smc.c         | 21 ++++++++++++++-------
 2 files changed, 15 insertions(+), 7 deletions(-)
include/hw/ssi/aspeed_smc.h +1 -0
index 6fbbb238f158..5f477eb9cf97 100644
@@ -115,6 +115,7 @@ typedef struct AspeedSMCState {
 
     AspeedSMCFlash *flashes;
 
+    uint8_t snoop_addr_width;
     uint8_t snoop_index;
     uint8_t snoop_dummies;
 } AspeedSMCState;
hw/ssi/aspeed_smc.c +0 -0
index 795784e5f364..594f34668e7a 100644

hw/ssi/aspeed_smc.c typedef enum { · line 784

Quoted 8 lines
hw/ssi/aspeed_smc.c +2 -1
@@ -778,10 +778,15 @@ typedef enum {
     PP = 0x2,           PP_4 = 0x12,
     DPP = 0xa2,
     QPP = 0x32,         QPP_4 = 0x34,
+    RDSFDP = 0x5a,
 } FlashCMD;
 
-static int aspeed_smc_num_dummies(uint8_t command)
+static int aspeed_smc_num_dummies(AspeedSMCFlash *fl, uint8_t command)

Should the function be renamed to reflect that it also calculates the address width now? (An alternative could be to create a new function for the address width calculation)

The patch looks good to me else!

Best regards,
Francisco Iglesias

Quoted 62 lines
hw/ssi/aspeed_smc.c +12 -6
 {
+    AspeedSMCState *s = fl->controller;
+
+    s->snoop_addr_width = aspeed_smc_flash_is_4byte(fl) ? 4 : 3;
+
     switch (command) { /* check for dummies */
     case READ: /* no dummy bytes/cycles */
     case PP:
@@ -798,6 +803,9 @@ static int aspeed_smc_num_dummies(uint8_t command)
     case DOR_4:
     case QOR_4:
         return 1;
+    case RDSFDP:
+        s->snoop_addr_width = 3;
+        return 1;
     case DIOR:
     case DIOR_4:
         return 2;
@@ -813,8 +821,6 @@ static bool aspeed_smc_do_snoop(AspeedSMCFlash *fl,  uint64_t data,
                                 unsigned size)
 {
     AspeedSMCState *s = fl->controller;
-    uint8_t addr_width = aspeed_smc_flash_is_4byte(fl) ? 4 : 3;
-
     trace_aspeed_smc_do_snoop(fl->id, s->snoop_index, s->snoop_dummies,
                               (uint8_t) data & 0xff);
 
@@ -823,7 +829,7 @@ static bool aspeed_smc_do_snoop(AspeedSMCFlash *fl,  uint64_t data,
 
     } else if (s->snoop_index == SNOOP_START) {
         uint8_t cmd = data & 0xff;
-        int ndummies = aspeed_smc_num_dummies(cmd);
+        int ndummies = aspeed_smc_num_dummies(fl, cmd);
 
         /*
          * No dummy cycles are expected with the current command. Turn
@@ -836,7 +842,7 @@ static bool aspeed_smc_do_snoop(AspeedSMCFlash *fl,  uint64_t data,
 
         s->snoop_dummies = ndummies * 8;
 
-    } else if (s->snoop_index >= addr_width + 1) {
+    } else if (s->snoop_index >= s->snoop_addr_width + 1) {
 
         /* The SPI transfer has reached the dummy cycles sequence */
         for (; s->snoop_dummies; s->snoop_dummies--) {
@@ -1407,10 +1413,11 @@ static void aspeed_smc_realize(DeviceState *dev, Error **errp)
 
 static const VMStateDescription vmstate_aspeed_smc = {
     .name = "aspeed.smc",
-    .version_id = 2,
-    .minimum_version_id = 2,
+    .version_id = 3,
+    .minimum_version_id = 3,
     .fields = (VMStateField[]) {
         VMSTATE_UINT32_ARRAY(regs, AspeedSMCState, ASPEED_SMC_R_MAX),
+        VMSTATE_UINT8(snoop_addr_width, AspeedSMCState),
         VMSTATE_UINT8(snoop_index, AspeedSMCState),
         VMSTATE_UINT8(snoop_dummies, AspeedSMCState),
         VMSTATE_END_OF_LIST()
Signature · 1 line
2.25.4
maintainer Reviewed-by Tested-by on the v2 series
#13 lore raw
In reply to Cédric Le Goater
Quoted 9 lines · Cédric Le Goater

Hello,

JEDEC STANDARD JESD216 for Serial Flash Discovery Parameters (SFDP) provides a mean to describe the features of a serial flash device using a set of internal parameter tables. Support in Linux has been added some time ago and the spi-nor driver is using it more often to detect the flash settings and even flash models.

Quoted 6 lines

This is the initial framework for the RDSFDP command giving access to a private SFDP area under the flash.

The patches available here :

https://github.com/legoater/qemu/commits/aspeed-5.2

Note that these need to be rebased on master; there are some minor conflicts.

These patches have proved essential in debugging a recent kernel regression. Thanks for adding this support Cédric.

Cheers,

Joel

Quoted 40 lines

Thanks,

C.

Changes in v2:

- fixed dummy value
- replaced 'sfdp' table by a 'sfdp_read' handler
- more SFDP tables
- fixed Aspeed SMC support
- introduced mx25l25635f chip model for test under Linux.

Cédric Le Goater (9):
m25p80: Add basic support for the SFDP command
m25p80: Add the n25q256a SFDP table
m25p80: Add the mx25l25635e SFPD table
m25p80: Add the mx25l25635f SFPD table
m25p80: Add the mx66l1g45g SFDP table
m25p80: Add the w25q256 SFPD table
m25p80: Add the w25q512jv SFPD table
arm/aspeed: Replace mx25l25635e chip model
aspeed/smc: Add support for RDSFDP command

 hw/block/m25p80_sfdp.h      |  27 ++++
 include/hw/ssi/aspeed_smc.h |   1 +
 hw/arm/aspeed.c             |   6 +-
 hw/block/m25p80.c           |  47 +++++-
 hw/block/m25p80_sfdp.c      | 296 ++++++++++++++++++++++++++++++++++++
 hw/ssi/aspeed_smc.c         |  21 ++-
 MAINTAINERS                 |   2 +-
 hw/block/meson.build        |   1 +
 hw/block/trace-events       |   1 +
 9 files changed, 385 insertions(+), 17 deletions(-)
 create mode 100644 hw/block/m25p80_sfdp.h
 create mode 100644 hw/block/m25p80_sfdp.c

--
2.25.4

maintainer
#14 lore raw
Quoted 18 lines · Joel Stanley
Quoted 9 lines · Cédric Le Goater

Hello,

JEDEC STANDARD JESD216 for Serial Flash Discovery Parameters (SFDP) provides a mean to describe the features of a serial flash device using a set of internal parameter tables. Support in Linux has been added some time ago and the spi-nor driver is using it more often to detect the flash settings and even flash models.

Quoted 6 lines

This is the initial framework for the RDSFDP command giving access to a private SFDP area under the flash.

The patches available here :

https://github.com/legoater/qemu/commits/aspeed-5.2

Quoted 7 lines

Note that these need to be rebased on master; there are some minor conflicts.

These patches have proved essential in debugging a recent kernel regression. Thanks for adding this support Cédric.

For reference, an OpenBMC UBI based NOR image with an upstream (5.8, 5.9-rc) kernel can be used to reproduce the bug as follows:

qemu-system-arm -M witherspoon-bmc -nic user -nographic \
-drive file=obmc-phosphor-image-witherspoon.ubi.mtd,format=raw,if=mtd \
-kernel aspeed-g5-dev/arch/arm/boot/zImage \
-dtb aspeed-g5-dev/arch/arm/boot/dts/aspeed-bmc-opp-witherspoon.dtb \
-append "console=ttyS4,115200n8 ubi.mtd=obmc-ubi,0,0,0
ubi.mtd=alt-obmc-ubi,0,0,4 ro rootfstype=squashfs ubi.block=0,1 root=/dev/ubiblock0_1"

The ubi.mtd can be found here[1].

This assumes you're running qemu with this series applied, and an upstream kernel built with aspeed_g5_defconfig:

git checkout v5.8
CROSS_COMPILE="ccache arm-linux-gnueabi-" ARCH=arm make -j8 O=aspeed-g5-dev aspeed_g5_defconfig
CROSS_COMPILE="ccache arm-linux-gnueabi-" ARCH=arm make -j8 O=aspeed-g5-dev

The fix for the Linux kernel issue is on the linux-mtd list[2]. WIthout the fix, the kernel will fail to attach the UBI volume:

[    1.453224] ubi0: default fastmap pool size: 25
[    1.453370] ubi0: default fastmap WL pool size: 12
[    1.453505] ubi0: attaching mtd3
[    1.467316] ubi0 error: ubi_compare_lebs: unsupported on-flash UBI format
[    1.467902] ubi0 error: ubi_attach_mtd_dev: failed to attach mtd3, error -22

With the fix, the system will boot through to userspace.

Cheers,

Joel

[1] https://jenkins.openbmc.org/view/latest/job/latest-master/label=docker-builder,target=witherspoon/lastSuccessfulBuild/artifact/openbmc/build/tmp/deploy/images/witherspoon/obmc-phosphor-image-witherspoon.ubi.mtd
[2] https://lore.kernel.org/linux-mtd/CACPK8XceL_QHCQOhfus27rei0vwfRJAFjfL6JkVw9pwxJj2d6Q@mail.gmail.com/

Quoted 45 lines

Cheers,

Joel

Quoted 40 lines

Thanks,

C.

Changes in v2:

- fixed dummy value
- replaced 'sfdp' table by a 'sfdp_read' handler
- more SFDP tables
- fixed Aspeed SMC support
- introduced mx25l25635f chip model for test under Linux.

Cédric Le Goater (9):
m25p80: Add basic support for the SFDP command
m25p80: Add the n25q256a SFDP table
m25p80: Add the mx25l25635e SFPD table
m25p80: Add the mx25l25635f SFPD table
m25p80: Add the mx66l1g45g SFDP table
m25p80: Add the w25q256 SFPD table
m25p80: Add the w25q512jv SFPD table
arm/aspeed: Replace mx25l25635e chip model
aspeed/smc: Add support for RDSFDP command

 hw/block/m25p80_sfdp.h      |  27 ++++
 include/hw/ssi/aspeed_smc.h |   1 +
 hw/arm/aspeed.c             |   6 +-
 hw/block/m25p80.c           |  47 +++++-
 hw/block/m25p80_sfdp.c      | 296 ++++++++++++++++++++++++++++++++++++
 hw/ssi/aspeed_smc.c         |  21 ++-
 MAINTAINERS                 |   2 +-
 hw/block/meson.build        |   1 +
 hw/block/trace-events       |   1 +
 9 files changed, 385 insertions(+), 17 deletions(-)
 create mode 100644 hw/block/m25p80_sfdp.h
 create mode 100644 hw/block/m25p80_sfdp.c

--
2.25.4

#15 lore raw
In reply to Joel Stanley
Quoted 17 lines · Joel Stanley
Quoted 9 lines · Cédric Le Goater

Hello,

JEDEC STANDARD JESD216 for Serial Flash Discovery Parameters (SFDP) provides a mean to describe the features of a serial flash device using a set of internal parameter tables. Support in Linux has been added some time ago and the spi-nor driver is using it more often to detect the flash settings and even flash models.

Quoted 6 lines

This is the initial framework for the RDSFDP command giving access to a private SFDP area under the flash.

The patches available here :

https://github.com/legoater/qemu/commits/aspeed-5.2

Quoted 7 lines

Note that these need to be rebased on master; there are some minor conflicts.

These patches have proved essential in debugging a recent kernel regression. Thanks for adding this support Cédric.

We have been discussing offline with Francisco of a more subtle approach to reduce the size of the definitions of the SFDP tables. I agree that the current approach is brutal (and efficient :) but I haven't had time to take a close look at his proposal. See below.

    typedef struct SFDPSection {
        const uint32_t addr;
        const uint32_t size;
        const uint32_t wrap_sz;
        const uint8_t *data;
    } SFDPSection;
    
    #define SFDP_RAW(start_addr, vals...) \
    {                                     \
      .addr = start_addr,                 \
      .size = sizeof((uint8_t[]){vals}),  \
      .data = (const uint8_t[]){vals}     \
    }
    
    #define SFDP_RAW_WRAP(start_addr, _wrap_sz, vals...) \
    {                                     \
      .addr = start_addr,                 \
      .size = sizeof((uint8_t[]){vals}),  \
      .wrap_sz = _wrap_sz,                \
      .data = (const uint8_t[]){vals}     \
    }
    
    #define SFDP_TABLE_END() { 0 }
    #define IS_SFDP_END(x) (x.size == 0)
    
    #define M35T4545_WRAP_SZ 0x100
    
    static const SFDPTable m35t4545 = {
        SFDP_RAW_WRAP(0, M35T4545_WRAP_SZ,
                      0x53, 0x46, 0x44, 0x50, 0x00, 0x01, 0x00, 0xff,
                      0x00, 0x00, 0x01, 0x09, 0x30, 0x00, 0x00, 0xff),
    
        SFDP_RAW(0x38,
                 0xe5, 0x20, 0xfb, 0xff, 0xff, 0xff, 0xff, 0x0f,
                 0x29, 0xeb, 0x27, 0x6b, 0x08, 0x3b, 0x27, 0xbb,
                 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0x27, 0xbb,
                 0xff, 0xff, 0x29, 0xeb, 0x0c, 0x20, 0x10, 0xd8,
                 0x00, 0x00, 0x00, 0x00, 0xff, 0xff, 0xff, 0xff),
    
        SFDP_TABLE_END()
    };
    
    uint8_t m25p80_sfdp_read(SFDPTable t, uint32_t addr)
    {
        if (t[0].wrap_sz) {
            addr &= (t.wrap_sz-1);
        }
    
        for (int i = 0; !IS_SFDP_END(t[i]); i++) {
            if (addr >= t[i].addr && addr < (t[i].addr + t[i].size)) {
                return t[i].data[addr];
            }
        }
        return 0xFF;
    }

The SFDP header (SFDP_RAW_WRAP) contains the list of the SFDP tables, the first being the BFPT at offset 0x30. It would be nice to be able to build the list in the header from the different table definitions.

C.