1 /* Copyright (c) 2011,2012 Simon Schubert <2@0x2c.org>.
2 * Modifications by Jacob Alexander 2014-2015 <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/>.
20 // ----- Local Includes -----
22 #include "mchck-cdefs.h"
26 // ----- Structs -----
29 UNION_STRUCT_START(8);
38 CTASSERT_SIZE_BIT(struct FTFL_FSTAT_t, 8);
41 UNION_STRUCT_START(8);
52 CTASSERT_SIZE_BIT(struct FTFL_FCNFG_t, 8);
55 UNION_STRUCT_START(8);
57 FTFL_FSEC_SEC_UNSECURE = 2,
58 FTFL_FSEC_SEC_SECURE = 3
61 FTFL_FSEC_FSLACC_DENY = 1,
62 FTFL_FSEC_FSLACC_GRANT = 3
65 FTFL_FSEC_MEEN_DISABLE = 2,
66 FTFL_FSEC_MEEN_ENABLE = 3
69 FTFL_FSEC_KEYEN_DISABLE = 1,
70 FTFL_FSEC_KEYEN_ENABLE = 2
74 CTASSERT_SIZE_BIT(struct FTFL_FSEC_t, 8);
77 UNION_STRUCT_START(8);
79 uint8_t ezport_dis : 1;
84 CTASSERT_SIZE_BIT(struct FTFL_FOPT_t, 8);
87 * The FCOOB is a weird register file, because it is double big endian,
88 * which makes for odd gaps and for some data that is big endian, and for
89 * some that is little endian.
95 FTFL_FCMD_READ_1s_BLOCK = 0x00,
96 FTFL_FCMD_READ_1s_SECTION = 0x01,
97 FTFL_FCMD_PROGRAM_CHECK = 0x02,
98 FTFL_FCMD_READ_RESOURCE = 0x03,
99 FTFL_FCMD_PROGRAM_LONGWORD = 0x06,
100 FTFL_FCMD_ERASE_BLOCK = 0x08,
101 FTFL_FCMD_ERASE_SECTOR = 0x09,
102 FTFL_FCMD_PROGRAM_SECTION = 0x0b,
103 FTFL_FCMD_READ_1s_ALL_BLOCKS = 0x40,
104 FTFL_FCMD_READ_ONCE = 0x41,
105 FTFL_FCMD_PROGRAM_ONCE = 0x43,
106 FTFL_FCMD_ERASE_ALL_BLOCKS = 0x44,
107 FTFL_FCMD_VERIFY_KEY = 0x45,
108 FTFL_FCMD_PROGRAM_PARTITION = 0x80,
109 FTFL_FCMD_SET_FLEXRAM = 0x81
115 enum FTFL_FCMD fcmd : 8;
117 enum FTFL_MARGIN_CHOICE {
118 FTFL_MARGIN_NORMAL = 0x00,
119 FTFL_MARGIN_USER = 0x01,
120 FTFL_MARGIN_FACTORY = 0x02
123 struct ftfl_data_num_words {
125 enum FTFL_FCMD fcmd : 8;
127 enum FTFL_MARGIN_CHOICE margin : 8;
132 enum FTFL_FCMD fcmd : 8;
134 enum FTFL_MARGIN_CHOICE margin : 8;
139 enum FTFL_FCMD fcmd : 8;
142 enum FTFL_RESOURCE_SELECT {
143 FTFL_RESOURCE_IFR = 0x00,
144 FTFL_RESOURCE_VERSION = 0x01
145 } resource_select : 8;
149 enum FTFL_FCMD fcmd : 8;
154 enum FTFL_FCMD fcmd : 8;
156 struct ftfl_data_num_words program_section;
159 enum FTFL_MARGIN_CHOICE margin : 8;
160 enum FTFL_FCMD fcmd : 8;
161 } read_1s_all_blocks;
162 struct ftfl_cmd_once {
165 enum FTFL_FCMD fcmd : 8;
168 struct ftfl_cmd_once program_once;
171 enum FTFL_FCMD fcmd : 8;
175 enum FTFL_FCMD fcmd : 8;
180 enum FTFL_FCMD fcmd : 8;
183 /* the following enum is analogous to enum
184 * SIM_FLEXNVM_PARTITION in sim.h, but this one is padded
185 * with four 1-bits to make an 8-bit value.
188 enum FTFL_FLEXNVM_PARTITION {
189 FTFL_FLEXNVM_DATA_32_EEPROM_0 = 0xF0,
190 FTFL_FLEXNVM_DATA_24_EEPROM_8 = 0xF1,
191 FTFL_FLEXNVM_DATA_16_EEPROM_16 = 0xF2,
192 FTFL_FLEXNVM_DATA_8_EEPROM_24 = 0xF9,
193 FTFL_FLEXNVM_DATA_0_EEPROM_32 = 0xF3
194 } flexnvm_partition : 8;
195 enum FTFL_EEPROM_SIZE {
196 FTFL_EEPROM_SIZE_0 = 0x3f,
197 FTFL_EEPROM_SIZE_32 = 0x39,
198 FTFL_EEPROM_SIZE_64 = 0x38,
199 FTFL_EEPROM_SIZE_128 = 0x37,
200 FTFL_EEPROM_SIZE_256 = 0x36,
201 FTFL_EEPROM_SIZE_512 = 0x35,
202 FTFL_EEPROM_SIZE_1024 = 0x34,
203 FTFL_EEPROM_SIZE_2048 = 0x33
208 enum FTFL_FLEXRAM_FUNCTION {
209 FTFL_FLEXRAM_EEPROM = 0x00,
210 FTFL_FLEXRAM_RAM = 0xff
211 } flexram_function : 8;
212 enum FTFL_FCMD fcmd : 8;
215 CTASSERT_SIZE_BYTE(union FTFL_FCCOB_t, 12);
218 struct FTFL_FSTAT_t fstat;
219 struct FTFL_FCNFG_t fcnfg;
220 struct FTFL_FSEC_t fsec;
221 struct FTFL_FOPT_t fopt;
222 union FTFL_FCCOB_t fccob;
227 CTASSERT_SIZE_BYTE(struct FTFL_t, 0x18);
229 /* Flash Configuration Field, see Sub-Family Reference Manual, section 28.3.1 */
230 struct FTFL_CONFIG_t {
233 struct FTFL_FSEC_t fsec;
234 struct FTFL_FOPT_t fopt;
238 CTASSERT_SIZE_BYTE(struct FTFL_CONFIG_t, 16);
240 extern volatile struct FTFL_t FTFL;
241 extern char FlexRAM[];
242 extern struct FTFL_CONFIG_t FTFL_CONFIG;