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 /** SFDP JEDEC Parameter Table info */
72 struct sfdp_hdr_info {
73  sfdp_bptbl_info bptbl;
74  sfdp_smptbl_info smptbl;
75 };
76 
77 /** Parse SFDP Database
78  * Retrieves all headers from within a memory device and parses the information contained by the headers
79  *
80  * Only JEDEC headers are parsed, not vendor specific ones.
81  *
82  * @param sfdp_reader Callback function used to read headers from within a device
83  * @param[out] sfdp_info Contains the results of parsing the SFDP Database JEDEC headers
84  *
85  * @return MBED_SUCCESS on success, negative error code on failure
86  */
87 int sfdp_parse_headers(Callback<int(bd_addr_t, void *, bd_size_t)> sfdp_reader, sfdp_hdr_info &sfdp_info);
88 
89 /** Parse Sector Map Parameter Table
90  * Retrieves the table from a device and parses the information contained by the table
91  *
92  * @param sfdp_reader Callback function used to read headers from within a device
93  * @param[out] sfdp_info Contains the results of parsing the JEDEC Sector Map Table
94  *
95  * @return MBED_SUCCESS on success, negative error code on failure
96  */
97 int sfdp_parse_sector_map_table(Callback<int(bd_addr_t, void *, bd_size_t)> sfdp_reader, sfdp_hdr_info &sfdp_info);
98 
99 /** Detect page size used for writing on flash
100  *
101  * @param bptbl_ptr Pointer to memory holding a Basic Parameter Table structure
102  * @param bptbl_size Size of memory holding the Basic Parameter Table
103  *
104  * @return Page size
105  */
106 size_t sfdp_detect_page_size(uint8_t *bptbl_ptr, size_t bptbl_size);
107 
108 /** Detect all supported erase types
109  *
110  * @param bptbl_ptr Pointer to memory holding a JEDEC Basic Flash Parameter Table
111  * @param[in,out] sfdp_info Contains the results of parsing erase type instructions and sizes
112  *
113  * @return MBED_SUCCESS on success, negative error code on failure
114  */
115 int sfdp_detect_erase_types_inst_and_size(uint8_t *bptbl_ptr, sfdp_hdr_info &sfdp_info);
116 
117 /** Find the region to which the given offset belongs to
118  *
119  * @param offset Offset value
120  * @param sfdp_info Region information
121  *
122  * @return Region number
123  */
124 int sfdp_find_addr_region(bd_size_t offset, const sfdp_hdr_info &sfdp_info);
125 
126 /** Finds the largest Erase Type of the Region to which the offset belongs to
127  *
128  * Iterates from highest type to lowest.
129  *
130  * @param bitfield Erase types bit field
131  * @param size Upper limit for region size
132  * @param offset Offset value
133  * @param region Region number
134  * @param smptbl Information about different erase types
135  *
136  * @return Largest erase type
137  */
138 int sfdp_iterate_next_largest_erase_type(uint8_t &bitfield,
139  int size,
140  int offset,
141  int region,
142  const sfdp_smptbl_info &smptbl);
143 
144 /** Detect device density
145  *
146  * @param bptbl_ptr Pointer to memory holding a Basic Parameter Table structure
147  * @param bptbl_info Basic Parameter Table information structure
148  *
149  * @return 0 on success, negative error code on failure
150  */
151 int sfdp_detect_device_density(uint8_t *bptbl_ptr, sfdp_bptbl_info &bptbl_info);
152 
153 /** Detect is it possible to access the whole memory region
154  *
155  * @param bptbl_ptr Pointer to memory holding a Basic Parameter Table structure
156  * @param bptbl_info Basic Parameter Table information structure
157  *
158  * @return 0 on success, negative error code on failure
159  */
160 int sfdp_detect_addressability(uint8_t *bptbl_ptr, sfdp_bptbl_info &bptbl_info);
161 
162 /** @}*/
163 } /* namespace mbed */
164 #endif
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
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 sfdp_find_addr_region(bd_size_t offset, const sfdp_hdr_info &sfdp_info)
Find the region to which the given offset belongs to.
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:72
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
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_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.