Mistake on this page?
Report an issue in GitHub or email us
SFDP.h
1 /*
2  * Copyright (c) 2020, Arm Limited and affiliates.
3  * SPDX-License-Identifier: Apache-2.0
4  *
5  * Licensed under the Apache License, Version 2.0 (the "License");
6  * you may not use this file except in compliance with the License.
7  * You may obtain a copy of the License at
8  *
9  * http://www.apache.org/licenses/LICENSE-2.0
10  *
11  * Unless required by applicable law or agreed to in writing, software
12  * distributed under the License is distributed on an "AS IS" BASIS,
13  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
14  * See the License for the specific language governing permissions and
15  * limitations under the License.
16  */
17 
18 #ifndef SFDP_H
19 #define SFDP_H
20 
21 #include <cstddef>
22 #include <cstdint>
23 #include "blockdevice/BlockDevice.h"
24 #include "platform/Callback.h"
25 
26 namespace mbed {
27 
28 /** \defgroup drivers-internal-api-sfdp SFDP
29  * \ingroup drivers-internal-api
30  * Serial Flash Discoverable Parameters.
31  *
32  * Based on <a href="https://www.jedec.org/standards-documents/docs/jesd216b">JESD216D.01 Standard</a>.
33  * @{
34  */
35 
36 constexpr int SFDP_HEADER_SIZE = 8; ///< Size of an SFDP header in bytes, 2 DWORDS
37 constexpr int SFDP_BASIC_PARAMS_TBL_SIZE = 80; ///< Basic Parameter Table size in bytes, 20 DWORDS
38 constexpr int SFDP_SECTOR_MAP_MAX_REGIONS = 10; ///< Maximum number of regions with different erase granularity
39 
40 // Erase Types Per Region BitMask
41 constexpr int SFDP_ERASE_BITMASK_TYPE4 = 0x08; ///< Erase type 4 (erase granularity) identifier
42 constexpr int SFDP_ERASE_BITMASK_TYPE3 = 0x04; ///< Erase type 3 (erase granularity) identifier
43 constexpr int SFDP_ERASE_BITMASK_TYPE2 = 0x02; ///< Erase type 2 (erase granularity) identifier
44 constexpr int SFDP_ERASE_BITMASK_TYPE1 = 0x01; ///< Erase type 1 (erase granularity) identifier
45 constexpr int SFDP_ERASE_BITMASK_NONE = 0x00; ///< Erase type None
46 constexpr int SFDP_ERASE_BITMASK_ALL = 0x0F; ///< Erase type All
47 
48 constexpr int SFDP_MAX_NUM_OF_ERASE_TYPES = 4; ///< Maximum number of different erase types (erase granularity)
49 
50 /** JEDEC Basic Flash Parameter Table info */
52  uint32_t addr; ///< Address
53  size_t size; ///< Size
54  bd_size_t device_size_bytes;
55  int legacy_erase_instruction; ///< Legacy 4K erase instruction
56 };
57 
58 /** JEDEC Sector Map Table info */
60  uint32_t addr; ///< Address
61  size_t size; ///< Size
62  int region_cnt; ///< Number of erase regions
63  int region_size[SFDP_SECTOR_MAP_MAX_REGIONS]; ///< Erase region size in bytes
64  uint8_t region_erase_types_bitfld[SFDP_SECTOR_MAP_MAX_REGIONS]; ///< Each Region can support a bit combination of any of the 4 Erase Types
65  unsigned int regions_min_common_erase_size; ///< Minimal common erase size for all regions (0 if none exists)
66  bd_size_t region_high_boundary[SFDP_SECTOR_MAP_MAX_REGIONS]; ///< Region high address offset boundary
67  int erase_type_inst_arr[SFDP_MAX_NUM_OF_ERASE_TYPES]; ///< // Up To 4 Erase Types are supported by SFDP (each with its own command Instruction and Size)
68  unsigned int erase_type_size_arr[SFDP_MAX_NUM_OF_ERASE_TYPES]; ///< Erase sizes for all different erase types
69 };
70 
71 /** JEDEC 4-byte Address Instruction Parameter Table info */
73  uint32_t addr; ///< Address
74  size_t size; ///< Size
75  int erase_type_4_byte_inst_arr[SFDP_MAX_NUM_OF_ERASE_TYPES]; ///< // Up To 4 Erase Types are supported by SFDP (each with its own command Instruction and Size)
76 };
77 
78 /** SFDP JEDEC Parameter Table info */
79 struct sfdp_hdr_info {
80  sfdp_bptbl_info bptbl;
81  sfdp_smptbl_info smptbl;
82  sfdp_fbatbl_info fbatbl;
83 };
84 
85 /** Parse SFDP Database
86  * Retrieves all headers from within a memory device and parses the information contained by the headers
87  *
88  * Only JEDEC headers are parsed, not vendor specific ones.
89  *
90  * @param sfdp_reader Callback function used to read headers from within a device
91  * @param[out] sfdp_info Contains the results of parsing the SFDP Database JEDEC headers
92  *
93  * @return MBED_SUCCESS on success, negative error code on failure
94  */
95 int sfdp_parse_headers(Callback<int(bd_addr_t, void *, bd_size_t)> sfdp_reader, sfdp_hdr_info &sfdp_info);
96 
97 /** Parse Sector Map Parameter Table
98  * Retrieves the table from a device and parses the information contained by the table
99  *
100  * @param sfdp_reader Callback function used to read headers from within a device
101  * @param[out] sfdp_info Contains the results of parsing the JEDEC Sector Map Table
102  *
103  * @return MBED_SUCCESS on success, negative error code on failure
104  */
105 int sfdp_parse_sector_map_table(Callback<int(bd_addr_t, void *, bd_size_t)> sfdp_reader, sfdp_hdr_info &sfdp_info);
106 
107 /** Detect page size used for writing on flash
108  *
109  * @param bptbl_ptr Pointer to memory holding a Basic Parameter Table structure
110  * @param bptbl_size Size of memory holding the Basic Parameter Table
111  *
112  * @return Page size
113  */
114 size_t sfdp_detect_page_size(uint8_t *bptbl_ptr, size_t bptbl_size);
115 
116 /** Detect all supported erase types
117  *
118  * @param bptbl_ptr Pointer to memory holding a JEDEC Basic Flash Parameter Table
119  * @param[in,out] sfdp_info Contains the results of parsing erase type instructions and sizes
120  *
121  * @return MBED_SUCCESS on success, negative error code on failure
122  */
123 int sfdp_detect_erase_types_inst_and_size(uint8_t *bptbl_ptr, sfdp_hdr_info &sfdp_info);
124 
125 /** Find the region to which the given offset belongs to
126  *
127  * @param offset Offset value
128  * @param sfdp_info Region information
129  *
130  * @return Region number
131  */
132 int sfdp_find_addr_region(bd_addr_t offset, const sfdp_hdr_info &sfdp_info);
133 
134 /** Finds the largest Erase Type of the Region to which the offset belongs to
135  *
136  * Iterates from highest type to lowest.
137  *
138  * @param bitfield Erase types bit field
139  * @param size Upper limit for region size
140  * @param offset Offset value
141  * @param region Region number
142  * @param smptbl Information about different erase types
143  *
144  * @return Largest erase type
145  */
146 int sfdp_iterate_next_largest_erase_type(uint8_t &bitfield,
147  int size,
148  int offset,
149  int region,
150  const sfdp_smptbl_info &smptbl);
151 
152 /** Detect device density
153  *
154  * @param bptbl_ptr Pointer to memory holding a Basic Parameter Table structure
155  * @param bptbl_info Basic Parameter Table information structure
156  *
157  * @return 0 on success, negative error code on failure
158  */
159 int sfdp_detect_device_density(uint8_t *bptbl_ptr, sfdp_bptbl_info &bptbl_info);
160 
161 /** Detect is it possible to access the whole memory region
162  *
163  * @param bptbl_ptr Pointer to memory holding a Basic Parameter Table structure
164  * @param bptbl_info Basic Parameter Table information structure
165  *
166  * @return 0 on success, negative error code on failure
167  */
168 int sfdp_detect_addressability(uint8_t *bptbl_ptr, sfdp_bptbl_info &bptbl_info);
169 
170 /** @}*/
171 } /* namespace mbed */
172 #endif
JEDEC 4-byte Address Instruction Parameter Table info.
Definition: SFDP.h:72
constexpr int SFDP_SECTOR_MAP_MAX_REGIONS
Maximum number of regions with different erase granularity.
Definition: SFDP.h:38
JEDEC Basic Flash Parameter Table info.
Definition: SFDP.h:51
uint32_t addr
Address.
Definition: SFDP.h:73
constexpr int SFDP_ERASE_BITMASK_TYPE3
Erase type 3 (erase granularity) identifier.
Definition: SFDP.h:42
constexpr int SFDP_MAX_NUM_OF_ERASE_TYPES
Maximum number of different erase types (erase granularity)
Definition: SFDP.h:48
uint32_t addr
Address.
Definition: SFDP.h:52
constexpr int SFDP_ERASE_BITMASK_ALL
Erase type All.
Definition: SFDP.h:46
int sfdp_detect_erase_types_inst_and_size(uint8_t *bptbl_ptr, sfdp_hdr_info &sfdp_info)
Detect all supported erase types.
int legacy_erase_instruction
Legacy 4K erase instruction.
Definition: SFDP.h:55
int sfdp_detect_addressability(uint8_t *bptbl_ptr, sfdp_bptbl_info &bptbl_info)
Detect is it possible to access the whole memory region.
SFDP JEDEC Parameter Table info.
Definition: SFDP.h:79
int region_cnt
Number of erase regions.
Definition: SFDP.h:62
constexpr int SFDP_HEADER_SIZE
Size of an SFDP header in bytes, 2 DWORDS.
Definition: SFDP.h:36
constexpr int SFDP_ERASE_BITMASK_TYPE4
Erase type 4 (erase granularity) identifier.
Definition: SFDP.h:41
unsigned int regions_min_common_erase_size
Minimal common erase size for all regions (0 if none exists)
Definition: SFDP.h:65
constexpr int SFDP_BASIC_PARAMS_TBL_SIZE
Basic Parameter Table size in bytes, 20 DWORDS.
Definition: SFDP.h:37
size_t size
Size.
Definition: SFDP.h:74
int sfdp_iterate_next_largest_erase_type(uint8_t &bitfield, int size, int offset, int region, const sfdp_smptbl_info &smptbl)
Finds the largest Erase Type of the Region to which the offset belongs to.
size_t sfdp_detect_page_size(uint8_t *bptbl_ptr, size_t bptbl_size)
Detect page size used for writing on flash.
int sfdp_find_addr_region(bd_addr_t offset, const sfdp_hdr_info &sfdp_info)
Find the region to which the given offset belongs to.
int sfdp_parse_headers(Callback< int(bd_addr_t, void *, bd_size_t)> sfdp_reader, sfdp_hdr_info &sfdp_info)
Parse SFDP Database Retrieves all headers from within a memory device and parses the information cont...
size_t size
Size.
Definition: SFDP.h:53
int sfdp_parse_sector_map_table(Callback< int(bd_addr_t, void *, bd_size_t)> sfdp_reader, sfdp_hdr_info &sfdp_info)
Parse Sector Map Parameter Table Retrieves the table from a device and parses the information contain...
size_t size
Size.
Definition: SFDP.h:61
constexpr int SFDP_ERASE_BITMASK_NONE
Erase type None.
Definition: SFDP.h:45
JEDEC Sector Map Table info.
Definition: SFDP.h:59
int sfdp_detect_device_density(uint8_t *bptbl_ptr, sfdp_bptbl_info &bptbl_info)
Detect device density.
Callback class based on template specialization.
Definition: Callback.h:53
Definition: ATHandler.h:46
constexpr int SFDP_ERASE_BITMASK_TYPE1
Erase type 1 (erase granularity) identifier.
Definition: SFDP.h:44
uint32_t addr
Address.
Definition: SFDP.h:60
constexpr int SFDP_ERASE_BITMASK_TYPE2
Erase type 2 (erase granularity) identifier.
Definition: SFDP.h:43
Important Information for this Arm website

This site uses cookies to store information on your computer. By continuing to use our site, you consent to our cookies. If you are not happy with the use of these cookies, please review our Cookie Policy to learn how they can be disabled. By disabling cookies, some features of the site will not work.