MCCI Trusted Bootloader
Simple trusted bootloader and tools for small embedded systems
mcci_flash_sfdp.h
Go to the documentation of this file.
1/*
2
3Module: mcci_flash_sfdp.h
4
5Function:
6 Suport for flash chip SFDP spec (JEDEC spec JESD216)
7
8Copyright and License:
9 This file copyright (C) 2021 by
10
11 MCCI Corporation
12 3520 Krums Corners Road
13 Ithaca, NY 14850
14
15 See accompanying LICENSE file for copyright and license information.
16
17Author:
18 Terry Moore, MCCI Corporation April 2021
19
20*/
21
22#ifndef _mcci_flash_sfdp_h_
23#define _mcci_flash_sfdp_h_ /* prevent multiple includes */
24
25#pragma once
26
27#include <stdint.h>
28
29#ifdef __cplusplus
30extern "C" {
31#endif
32
33///
34/// \brief the SFTD header
35///
36typedef struct mcci_flash_sfdp_header_s
37 {
38 uint8_t signature[4]; ///< the signature value for the header.
39 uint8_t properties[4]; ///< the properties for the header.
41
42///
43/// \brief get value of a 32-bit SFDP entry
44///
45/// \param [in] pValue points to a 4-byte field to be fetched.
46///
47static inline uint32_t
49 const uint8_t pValue[4]
50 )
51 {
52 return ((uint32_t)pValue[0] << 0) |
53 ((uint32_t)pValue[1] << 8) |
54 ((uint32_t)pValue[2] << 16) |
55 ((uint32_t)pValue[3] << 24);
56 }
57
58/// \brief return the signature value from an SFDP header
59static inline uint32_t
64
65///
66/// \brief signature of a SFDP header
67///
68/// This is the same as 'S', 'F', 'D', 'P' considered as a little-endian
69/// value.
70///
71#define MCCI_FLASH_SFDP_HEADER_SIGNATURE \
72 ((UINT32_C(0x50) << 24) | (UINT32_C(0x44) << 16) | (UINT32_C(0x46) << 8) | 0x53)
73
74/// \brief return the access protocol value from an SFDP header
75static inline uint8_t
80
81///
82/// \brief SFDP access protocol values
83/// @{
84#define MCCI_FLASH_SFDP_HEADER_PROPERTY_PROTOCOL_NAND1_216D 0xF0 ///< NAND class 1 from JESD216D
85#define MCCI_FLASH_SFDP_HEADER_PROPERTY_PROTOCOL_NAND2_216D 0xF1 ///< NAND class 2 from JESD216D
86#define MCCI_FLASH_SFDP_HEADER_PROPERTY_PROTOCOL_NAND3_CLASS1_D 0xF2 ///< reserved for NOR + NAND1
87#define MCCI_FLASH_SFDP_HEADER_PROPERTY_PROTOCOL_NAND3_CLASS2_D 0xF3 ///< reserved for NOR + NAND2
88#define MCCI_FLASH_SFDP_HEADER_PROPERTY_PROTOCOL_NAND1_216B 0xF4 ///< NAND class 1 from JESD216B
89#define MCCI_FLASH_SFDP_HEADER_PROPERTY_PROTOCOL_NAND2_216B 0xF5 ///< NAND class 2 from JESD216B
90#define MCCI_FLASH_SFDP_HEADER_PROPERTY_PROTOCOL_NAND3_RSV1 0xF6 ///< reserved for NOR + NAND1
91#define MCCI_FLASH_SFDP_HEADER_PROPERTY_PROTOCOL_NAND3_RSV2 0xF7 ///< reserved for NOR + NAND2
92#define MCCI_FLASH_SFDP_HEADER_PROPERTY_PROTOCOL_RSV248 0xF8 ///< reserved
93#define MCCI_FLASH_SFDP_HEADER_PROPERTY_PROTOCOL_RSV249 0xF9 ///< reserved
94#define MCCI_FLASH_SFDP_HEADER_PROPERTY_PROTOCOL_NOR2 0xFA ///< NOR xSPI profile 2, 5-byte addressing SFDP cmd
95#define MCCI_FLASH_SFDP_HEADER_PROPERTY_PROTOCOL_RSV251 0xFB ///< reserved
96#define MCCI_FLASH_SFDP_HEADER_PROPERTY_PROTOCOL_NOR1_3_8W 0xFC ///< NOR xSPI profile 1, 3-byte, 8 wait
97#define MCCI_FLASH_SFDP_HEADER_PROPERTY_PROTOCOL_NOR1_4_20W 0xFD ///< NOR xSPI profile 1, 4 byte, 20 wait
98#define MCCI_FLASH_SFDP_HEADER_PROPERTY_PROTOCOL_NOR1_4_8W 0xFE ///< NOR xSPI profile 1, 4 byte, 8 wait
99#define MCCI_FLASH_SFDP_HEADER_PROPERTY_PROTOCOL_NOR 0xFF ///< Legacy NOR, JESD216B, 3-byte SFDP command w/ 8 wait states
100/// @}
101
102///
103/// \brief Get SFDP version compliance claimed by header.
104///
105/// @{
107 {
108 return ((uint16_t) p->properties[0] << 0) |
109 ((uint16_t) p->properties[1] << 8);
110 }
111
112/// \brief Major and minor version codes
113#define MCCI_FLASH_SFDP_HEADER_PROPERTY_VERSION_JES216D UINT16_C(0x0108) ///< version for JESD216D
114#define MCCI_FLASH_SFDP_HEADER_PROPERTY_VERSION_JES216C UINT16_C(0x0107) ///< version for JESD216C
115#define MCCI_FLASH_SFDP_HEADER_PROPERTY_VERSION_JES216B UINT16_C(0x0106) ///< version for JESD216B
116#define MCCI_FLASH_SFDP_HEADER_PROPERTY_VERSION_JES216A UINT16_C(0x0105) ///< version for JESD216A
117/// @}
118
119
120///
121/// \brief the SFDP parameter header
122///
123typedef struct mcci_flash_sfdp_param_s
124 {
125 uint8_t dword1[4]; ///< low order dword
126 uint8_t dword2[4]; ///< high-order dword
128
129/// \brief return length of parameter table in dwords.
130static inline uint8_t
132 {
133 return p->dword1[3];
134 }
135
136/// \brief return version of parameter table
137static inline uint16_t
139 {
140 return (p->dword1[2] << 8) | p->dword1[1];
141 }
142
143/// \brief return ID of parameter table
144///
145/// @{
146static inline uint16_t
148 {
149 return (p->dword2[3] << 8) | p->dword1[0];
150 }
151
152/// \brief well-known parameter table IDs
153/// @{
154#define MCCI_FLASH_SFDP_ID_BASIC_SPI UINT16_C(0xFF00) ///< Basic SPI protocol
155#define MCCI_FLASH_SFDP_ID_SECTOR_MAP UINT16_C(0xFF81) ///< Sector map
156#define MCCI_FLASH_SFDP_ID_RPMC UINT16_C(0xFF03) ///< Replay Protected Monotonic Counters (RPMC)
157#define MCCI_FLASH_SFDP_ID_4BA_INSTR UINT16_C(0xFF84) ///< 4-byte Address Instruction Table
158#define MCCI_FLASH_SFDP_ID_xSPI1 UINT16_C(0xFF05) ///< eXtended Serial Peripheral Interface (xSPI) Profile 1.0
159#define MCCI_FLASH_SFDP_ID_xSPI2 UINT16_C(0xFF06) ///< eXtended Serial Peripheral Interface (xSPI) Profile 2.0
160#define MCCI_FLASH_SFDP_ID_SCCR_MAP UINT16_C(0xFF87) ///< Status, Control and Configuration Register Map
161#define MCCI_FLASH_SFDP_ID_SCCR_OFFSETS UINT16_C(0xFF88) ///< Status, Control and Configuration Register Map Offsets for Multi-Chip SPI Memory Devices
162#define MCCI_FLASH_SFDP_ID_SCCR_xSPI2 UINT16_C(0xFF09) ///< Status, Control and Configuration Register Map for xSPI Profile 2.0
163#define MCCI_FLASH_SFDP_ID_OCTAL_DDR UINT16_C(0xFF0A) ///< Command Sequences to change to Octal DDR (8D-8D-8D) mode
164#define MCCI_FLASH_SFDP_ID_LL_MSPT UINT16_C(0xFF8B) ///< Long Latency NVM Media Specific Parameter Table (MSPT)
165#define MCCI_FLASH_SFDP_ID_QUAD_IO UINT16_C(0xFF0C) ///< x4 Quad IO with DS
166#define MCCI_FLASH_SFDP_ID_QUAD_DDR UINT16_C(0xFF8D) ///< Command Sequences to change to Quad DDR (4S-4D-4D) mode
167#define MCCI_FLASH_SFDP_ID_RSV8E UINT16_C(0xFF8E) ///< Reserved for next Function Specific Table assignment
168/// @}
169/// @}
170
171/// \brief return pointer to parameter table (PTP)
172static inline uint32_t
174 {
175 return ((uint32_t)p->dword2[0] << 0) |
176 ((uint32_t)p->dword2[1] << 8) |
177 ((uint32_t)p->dword2[2] << 16)
178 ;
179 }
180
181#ifdef __cplusplus
182}
183#endif
184
185#endif /* _mcci_flash_sfdp_h_ */
static uint32_t McciFlashSfdpHeader_getSignature(const mcci_flash_sfdp_header_t *p)
return the signature value from an SFDP header
static uint8_t McciFlashSfdpHeader_getProtocol(const mcci_flash_sfdp_header_t *p)
return the access protocol value from an SFDP header
static uint32_t McciFlashSfdp_get32(const uint8_t pValue[4])
get value of a 32-bit SFDP entry
static uint16_t McciFlashSfdpParam_getVersion(const mcci_flash_sfdp_param_t *p)
return version of parameter table
static uint16_t McciFlashSfdpHeader_getVersion(const mcci_flash_sfdp_header_t *p)
Get SFDP version compliance claimed by header.
static uint8_t McciFlashSfdpParam_getLength(const mcci_flash_sfdp_param_t *p)
return length of parameter table in dwords.
static uint32_t McciFlashSfdpParam_getPTP(const mcci_flash_sfdp_param_t *p)
return pointer to parameter table (PTP)
static uint16_t McciFlashSfdpParam_getID(const mcci_flash_sfdp_param_t *p)
return ID of parameter table
uint8_t properties[4]
the properties for the header.
uint8_t signature[4]
the signature value for the header.
the SFDP parameter header
uint8_t dword1[4]
low order dword
uint8_t dword2[4]
high-order dword