1 /* Copyright (c) 2011,2012 Simon Schubert <2@0x2c.org>.
2 * Modifications by Jacob Alexander 2014 <haata@kiibohd.com>
4 * This program is free software: you can redistribute it and/or modify
5 * it under the terms of the GNU General Public License as published by
6 * the Free Software Foundation, either version 3 of the License, or
7 * (at your option) any later version.
9 * This program is distributed in the hope that it will be useful,
10 * but WITHOUT ANY WARRANTY; without even the implied warranty of
11 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
12 * GNU General Public License for more details.
14 * You should have received a copy of the GNU General Public License
15 * along with this program. If not, see <http://www.gnu.org/licenses/>.
21 // ----- Local Includes -----
23 #include "mchck-cdefs.h"
27 // ----- Structs -----
30 UNION_STRUCT_START(8);
39 CTASSERT_SIZE_BIT(struct FTFL_FSTAT_t, 8);
42 UNION_STRUCT_START(8);
53 CTASSERT_SIZE_BIT(struct FTFL_FCNFG_t, 8);
56 UNION_STRUCT_START(8);
58 FTFL_FSEC_SEC_UNSECURE = 2,
59 FTFL_FSEC_SEC_SECURE = 3
62 FTFL_FSEC_FSLACC_DENY = 1,
63 FTFL_FSEC_FSLACC_GRANT = 3
66 FTFL_FSEC_MEEN_DISABLE = 2,
67 FTFL_FSEC_MEEN_ENABLE = 3
70 FTFL_FSEC_KEYEN_DISABLE = 1,
71 FTFL_FSEC_KEYEN_ENABLE = 2
75 CTASSERT_SIZE_BIT(struct FTFL_FSEC_t, 8);
78 UNION_STRUCT_START(8);
80 uint8_t ezport_dis : 1;
85 CTASSERT_SIZE_BIT(struct FTFL_FOPT_t, 8);
88 * The FCOOB is a weird register file, because it is double big endian,
89 * which makes for odd gaps and for some data that is big endian, and for
90 * some that is little endian.
96 FTFL_FCMD_READ_1s_BLOCK = 0x00,
97 FTFL_FCMD_READ_1s_SECTION = 0x01,
98 FTFL_FCMD_PROGRAM_CHECK = 0x02,
99 FTFL_FCMD_READ_RESOURCE = 0x03,
100 FTFL_FCMD_PROGRAM_LONGWORD = 0x06,
101 FTFL_FCMD_ERASE_BLOCK = 0x08,
102 FTFL_FCMD_ERASE_SECTOR = 0x09,
103 FTFL_FCMD_PROGRAM_SECTION = 0x0b,
104 FTFL_FCMD_READ_1s_ALL_BLOCKS = 0x40,
105 FTFL_FCMD_READ_ONCE = 0x41,
106 FTFL_FCMD_PROGRAM_ONCE = 0x43,
107 FTFL_FCMD_ERASE_ALL_BLOCKS = 0x44,
108 FTFL_FCMD_VERIFY_KEY = 0x45,
109 FTFL_FCMD_PROGRAM_PARTITION = 0x80,
110 FTFL_FCMD_SET_FLEXRAM = 0x81
116 enum FTFL_FCMD fcmd : 8;
118 enum FTFL_MARGIN_CHOICE {
119 FTFL_MARGIN_NORMAL = 0x00,
120 FTFL_MARGIN_USER = 0x01,
121 FTFL_MARGIN_FACTORY = 0x02
124 struct ftfl_data_num_words {
126 enum FTFL_FCMD fcmd : 8;
128 enum FTFL_MARGIN_CHOICE margin : 8;
133 enum FTFL_FCMD fcmd : 8;
135 enum FTFL_MARGIN_CHOICE margin : 8;
140 enum FTFL_FCMD fcmd : 8;
143 enum FTFL_RESOURCE_SELECT {
144 FTFL_RESOURCE_IFR = 0x00,
145 FTFL_RESOURCE_VERSION = 0x01
146 } resource_select : 8;
150 enum FTFL_FCMD fcmd : 8;
155 enum FTFL_FCMD fcmd : 8;
157 struct ftfl_data_num_words program_section;
160 enum FTFL_MARGIN_CHOICE margin : 8;
161 enum FTFL_FCMD fcmd : 8;
162 } read_1s_all_blocks;
163 struct ftfl_cmd_once {
166 enum FTFL_FCMD fcmd : 8;
169 struct ftfl_cmd_once program_once;
172 enum FTFL_FCMD fcmd : 8;
176 enum FTFL_FCMD fcmd : 8;
181 enum FTFL_FCMD fcmd : 8;
184 /* the following enum is analogous to enum
185 * SIM_FLEXNVM_PARTITION in sim.h, but this one is padded
186 * with four 1-bits to make an 8-bit value.
189 enum FTFL_FLEXNVM_PARTITION {
190 FTFL_FLEXNVM_DATA_32_EEPROM_0 = 0xF0,
191 FTFL_FLEXNVM_DATA_24_EEPROM_8 = 0xF1,
192 FTFL_FLEXNVM_DATA_16_EEPROM_16 = 0xF2,
193 FTFL_FLEXNVM_DATA_8_EEPROM_24 = 0xF9,
194 FTFL_FLEXNVM_DATA_0_EEPROM_32 = 0xF3
195 } flexnvm_partition : 8;
196 enum FTFL_EEPROM_SIZE {
197 FTFL_EEPROM_SIZE_0 = 0x3f,
198 FTFL_EEPROM_SIZE_32 = 0x39,
199 FTFL_EEPROM_SIZE_64 = 0x38,
200 FTFL_EEPROM_SIZE_128 = 0x37,
201 FTFL_EEPROM_SIZE_256 = 0x36,
202 FTFL_EEPROM_SIZE_512 = 0x35,
203 FTFL_EEPROM_SIZE_1024 = 0x34,
204 FTFL_EEPROM_SIZE_2048 = 0x33
209 enum FTFL_FLEXRAM_FUNCTION {
210 FTFL_FLEXRAM_EEPROM = 0x00,
211 FTFL_FLEXRAM_RAM = 0xff
212 } flexram_function : 8;
213 enum FTFL_FCMD fcmd : 8;
216 CTASSERT_SIZE_BYTE(union FTFL_FCCOB_t, 12);
219 struct FTFL_FSTAT_t fstat;
220 struct FTFL_FCNFG_t fcnfg;
221 struct FTFL_FSEC_t fsec;
222 struct FTFL_FOPT_t fopt;
223 union FTFL_FCCOB_t fccob;
228 CTASSERT_SIZE_BYTE(struct FTFL_t, 0x18);
230 /* Flash Configuration Field, see Sub-Family Reference Manual, section 28.3.1 */
231 struct FTFL_CONFIG_t {
234 struct FTFL_FSEC_t fsec;
235 struct FTFL_FOPT_t fopt;
239 CTASSERT_SIZE_BYTE(struct FTFL_CONFIG_t, 16);
241 extern volatile struct FTFL_t FTFL;
242 extern char FlexRAM[];
243 extern struct FTFL_CONFIG_t FTFL_CONFIG;