OpenOCD
mflash.h
Go to the documentation of this file.
1 /***************************************************************************
2  * Copyright (C) 2007-2008 by unsik Kim <donari75@gmail.com> *
3  * *
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 2 of the License, or *
7  * (at your option) any later version. *
8  * *
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. *
13  * *
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/>. *
16  ***************************************************************************/
17 
18 #ifndef OPENOCD_FLASH_MFLASH_H
19 #define OPENOCD_FLASH_MFLASH_H
20 
22 
23 typedef unsigned long mg_io_uint32;
24 typedef unsigned short mg_io_uint16;
25 typedef unsigned char mg_io_uint8;
26 
28  char port[2];
29  signed short num;
30 };
31 
33  const char *name;
34  int (*set_gpio_to_output)(struct mflash_gpio_num gpio);
35  int (*set_gpio_output_val)(struct mflash_gpio_num gpio, uint8_t val);
36 };
37 
38 typedef struct _mg_io_type_drv_info {
39 
47  mg_io_uint16 vendor_unique1[3]; /* 07/08/09 */
48 
49  mg_io_uint8 serial_number[20]; /* 10~19 */
50 
54 
55  mg_io_uint8 firmware_revision[8]; /* 23~26 */
56  mg_io_uint8 model_number[40]; /* 27 */
57 
59  mg_io_uint8 vendor_unique2; /* 47 high byte */
61 
64 
65  mg_io_uint8 vendor_unique3; /* 51 low byte */
66  mg_io_uint8 pio_cycle_timing_mode; /* 51 high byte */
67  mg_io_uint8 vendor_unique4; /* 52 low byte */
68  mg_io_uint8 dma_cycle_timing_mode; /* 52 high byte */
76  mg_io_uint8 multi_sector_setting_valid; /* 59 high (low bit) */
77 
80 
90  mg_io_uint8 reserved3[22];
105  mg_io_uint8 reserved6[68];
107  mg_io_uint8 vendor_uniq_bytes[62];
109  mg_io_uint8 reserved7[186];
110 
113 
115 
116 typedef struct _mg_pll_t {
117  unsigned int lock_cyc;
118  unsigned short feedback_div; /* 9bit divider */
119  unsigned char input_div; /* 5bit divider */
120  unsigned char output_div; /* 2bit divider */
121 } mg_pll_t;
122 
123 struct mg_drv_info {
125  uint32_t tot_sects;
126 };
127 
128 struct mflash_bank {
129  uint32_t base;
130 
131  struct mflash_gpio_num rst_pin;
132 
134  struct target *target;
136 };
137 
138 int mflash_register_commands(struct command_context *cmd_ctx);
139 
140 #define MG_MFLASH_SECTOR_SIZE (0x200) /* 512Bytes = 2^9 */
141 #define MG_MFLASH_SECTOR_SIZE_MASK (0x200-1)
142 #define MG_MFLASH_SECTOR_SIZE_SHIFT (9)
143 
144 #define MG_BUFFER_OFFSET 0x8000
145 #define MG_REG_OFFSET 0xC000
146 #define MG_REG_FEATURE 0x2 /* write case */
147 #define MG_REG_ERROR 0x2 /* read case */
148 #define MG_REG_SECT_CNT 0x4
149 #define MG_REG_SECT_NUM 0x6
150 #define MG_REG_CYL_LOW 0x8
151 #define MG_REG_CYL_HIGH 0xA
152 #define MG_REG_DRV_HEAD 0xC
153 #define MG_REG_COMMAND 0xE /* write case */
154 #define MG_REG_STATUS 0xE /* read case */
155 #define MG_REG_DRV_CTRL 0x10
156 #define MG_REG_BURST_CTRL 0x12
157 
158 #define MG_OEM_DISK_WAIT_TIME_LONG 15000 /* msec */
159 #define MG_OEM_DISK_WAIT_TIME_NORMAL 3000 /* msec */
160 #define MG_OEM_DISK_WAIT_TIME_SHORT 1000 /* msec */
161 
162 #define MG_PLL_CLK_OUT 66000000.0 /* 66Mhz */
163 #define MG_PLL_MAX_FEEDBACKDIV_VAL 512
164 #define MG_PLL_MAX_INPUTDIV_VAL 32
165 #define MG_PLL_MAX_OUTPUTDIV_VAL 4
166 
167 #define MG_PLL_STD_INPUTCLK 12000000.0 /* 12Mhz */
168 #define MG_PLL_STD_LOCKCYCLE 10000
169 
170 #define MG_UNLOCK_OTP_AREA 0xFF
171 
172 #define MG_FILEIO_CHUNK 1048576
173 
174 #define ERROR_MG_IO (-1600)
175 #define ERROR_MG_TIMEOUT (-1601)
176 #define ERROR_MG_INVALID_PLL (-1603)
177 #define ERROR_MG_INTERFACE (-1604)
178 #define ERROR_MG_INVALID_OSC (-1605)
179 #define ERROR_MG_UNSUPPORTED_SOC (-1606)
180 
181 typedef enum _mg_io_type_wait {
182 
186  mg_io_wait_drq = 4, /* wait for data request */
187  mg_io_wait_drq_noerr = 5, /* wait for DRQ but ignore the error status bit */
188  mg_io_wait_rdy_noerr = 6 /* wait for ready, but ignore error status bit */
189 
191 
192 /*= "Status Register" bit masks. */
194 
195  mg_io_rbit_status_error = 0x01, /* error bit in status register */
196  mg_io_rbit_status_corrected_error = 0x04, /* corrected error in status register */
197  mg_io_rbit_status_data_req = 0x08, /* data request bit in status register */
198  mg_io_rbit_status_seek_done = 0x10, /* DSC - Drive Seek Complete */
199  mg_io_rbit_status_write_fault = 0x20, /* DWF - Drive Write Fault */
202 
204 
205 /*= "Error Register" bit masks. */
207 
213 
215 
216 /* = "Device Control Register" bit. */
217 typedef enum _mg_io_type_rbit_devc {
218 
219  mg_io_rbit_devc_intr = 0x02, /* interrupt enable bit (1:disable, 0:enable) */
220  mg_io_rbit_devc_srst = 0x04 /* softwrae reset bit (1:assert, 0:de-assert) */
221 
223 
224 /* "Drive Select/Head Register" values. */
225 typedef enum _mg_io_type_rval_dev {
226 
227  mg_io_rval_dev_must_be_on = 0x80, /* These 1 bits are always on */
233 
235 
236 typedef enum _mg_io_type_cmd {
239 
243 
244  mg_io_cmd_idle = 0x97, /* 0xE3 */
245  mg_io_cmd_idle_immediate = 0x95, /* 0xE1 */
246 
247  mg_io_cmd_setsleep = 0x99, /* 0xE6 */
248  mg_io_cmd_stdby = 0x96, /* 0xE2 */
249  mg_io_cmd_stdby_immediate = 0x94, /* 0xE0 */
250 
253 
257 
259 
260 typedef enum _mg_feature_id {
262 } mg_feature_id;
263 
264 typedef enum _mg_feature_val {
269 
270 typedef enum _mg_vcmd {
271  mg_vcmd_update_xipinfo = 0xFA, /* FWPATCH commmand through IOM I/O */
272  mg_vcmd_verify_fwpatch = 0xFB, /* FWPATCH commmand through IOM I/O */
273  mg_vcmd_update_stgdrvinfo = 0xFC, /* IOM identificatin info program command */
274  mg_vcmd_prep_fwpatch = 0xFD, /* FWPATCH commmand through IOM I/O */
275  mg_vcmd_exe_fwpatch = 0xFE, /* FWPATCH commmand through IOM I/O */
277  mg_vcmd_purge_nand = 0x8C, /* Only for Seagle */
281 } mg_vcmd;
282 
283 typedef enum _mg_opmode {
284  mg_op_mode_xip = 1, /* TRUE XIP */
285  mg_op_mode_snd = 2, /* BOOT + Storage */
286  mg_op_mode_stg = 0 /* Only Storage */
287 } mg_opmode;
288 
289 #endif /* OPENOCD_FLASH_MFLASH_H */
mg_io_uint16 total_user_addressable_sectors_hi
Definition: mflash.h:79
struct mg_drv_info * drv_info
Definition: mflash.h:135
unsigned int lock_cyc
Definition: mflash.h:117
_mg_io_type_cmd
Definition: mflash.h:236
unsigned char mg_io_uint8
Definition: mflash.h:25
_mg_io_type_rbit_status
Definition: mflash.h:193
signed short num
Definition: mflash.h:29
enum _mg_io_type_rbit_error mg_io_type_rbit_error
mg_io_uint16 capabilities
Definition: mflash.h:62
mg_io_uint16 req_time_for_security_er_done
Definition: mflash.h:100
_mg_io_type_rbit_devc
Definition: mflash.h:217
struct mflash_gpio_drv * gpio_drv
Definition: mflash.h:133
mg_io_uint8 maximum_block_transfer
Definition: mflash.h:58
mg_io_uint16 req_time_for_enhan_security_er_done
Definition: mflash.h:101
mg_io_uint8 vendor_unique2
Definition: mflash.h:59
const char * name
Definition: mflash.h:33
uint32_t tot_sects
Definition: mflash.h:125
mg_io_uint8 pio_cycle_timing_mode
Definition: mflash.h:66
struct _mg_io_type_drv_info mg_io_type_drv_info
mg_io_uint16 minor_ver_num
Definition: mflash.h:92
mg_io_uint16 unformatted_bytes_per_sector
Definition: mflash.h:45
mg_io_uint16 re_of_hw_rst
Definition: mflash.h:104
mg_io_uint16 feature_cmd_set_suprt2
Definition: mflash.h:95
mg_io_uint16 total_user_addressable_sectors_lo
Definition: mflash.h:78
mg_io_uint8 vendor_unique3
Definition: mflash.h:65
enum _mg_vcmd mg_vcmd
mg_io_uint16 current_sector_capacity_lo
Definition: mflash.h:73
mg_io_uint16 number_of_cylinders
Definition: mflash.h:41
enum _mg_opmode mg_opmode
_mg_feature_val
Definition: mflash.h:264
mg_io_uint16 scts_per_secure_data_unit
Definition: mflash.h:111
mg_io_uint16 number_of_current_heads
Definition: mflash.h:71
_mg_io_type_wait
Definition: mflash.h:181
mg_io_uint16 reserved4
Definition: mflash.h:99
mg_io_uint16 number_of_heads
Definition: mflash.h:43
enum _mg_io_type_rval_dev mg_io_type_rval_dev
uint32_t base
Definition: mflash.h:129
mg_io_uint8 single_dma_transfer_active
Definition: mflash.h:82
_mg_io_type_rval_dev
Definition: mflash.h:225
mg_io_uint16 feature_cmd_set_suprt0
Definition: mflash.h:93
mg_io_uint16 unformatted_bytes_per_track
Definition: mflash.h:44
unsigned char output_div
Definition: mflash.h:120
struct target * target
Definition: mflash.h:134
mg_io_uint16 min_dma_cyc
Definition: mflash.h:86
mg_io_uint16 feature_cmd_set_suprt1
Definition: mflash.h:94
mg_io_uint16 number_of_ecc_bytes
Definition: mflash.h:53
mg_io_uint16 reserved2
Definition: mflash.h:63
unsigned short mg_io_uint16
Definition: mflash.h:24
mg_io_uint16 adv_pio_mode
Definition: mflash.h:85
enum _mg_io_type_rbit_status mg_io_type_rbit_status
mg_io_uint16 major_ver_num
Definition: mflash.h:91
unsigned char input_div
Definition: mflash.h:119
mg_io_type_drv_info drv_id
Definition: mflash.h:124
mg_io_uint16 recommend_dma_cyc
Definition: mflash.h:87
mg_io_uint16 buffer_type
Definition: mflash.h:51
mg_io_uint16 general_configuration
Definition: mflash.h:40
mg_io_uint8 multi_dma_modes_supported
Definition: mflash.h:83
mg_io_uint16 cfa_pwr_mode
Definition: mflash.h:108
unsigned long mg_io_uint32
Definition: mflash.h:21
enum _mg_io_type_cmd mg_io_type_cmd
mg_io_uint16 reserved1
Definition: mflash.h:42
mg_io_uint16 sectors_per_track
Definition: mflash.h:46
mg_io_uint16 integrity_word
Definition: mflash.h:112
mg_io_uint16 dword_io
Definition: mflash.h:60
mg_io_uint8 single_dma_modes_supported
Definition: mflash.h:81
mg_io_uint8 dma_cycle_timing_mode
Definition: mflash.h:68
mg_io_uint16 translation_fields_valid
Definition: mflash.h:69
enum _mg_feature_val mg_feature_val
struct _mg_pll_t mg_pll_t
_mg_io_type_rbit_error
Definition: mflash.h:206
enum _mg_feature_id mg_feature_id
mg_io_uint8 multi_dma_transfer_active
Definition: mflash.h:84
mg_io_uint16 adv_pwr_mgm_lvl_val
Definition: mflash.h:102
enum _mg_io_type_wait mg_io_type_wait
mg_io_uint16 min_pio_cyc_no_iordy
Definition: mflash.h:88
_mg_feature_id
Definition: mflash.h:260
mg_io_uint8 multi_sector_setting_valid
Definition: mflash.h:76
mg_io_uint16 security_stas
Definition: mflash.h:106
mg_io_uint16 number_of_current_cylinders
Definition: mflash.h:70
int mflash_register_commands(struct command_context *cmd_ctx)
Definition: mflash.c:1446
mg_io_uint8 multi_sector_count
Definition: mflash.h:75
mg_io_uint16 feature_cmd_set_en1
Definition: mflash.h:97
mg_io_uint16 current_sector_capacity_hi
Definition: mflash.h:74
_mg_vcmd
Definition: mflash.h:270
mg_io_uint16 reserved5
Definition: mflash.h:103
mg_io_uint16 feature_cmd_set_en0
Definition: mflash.h:96
enum _mg_io_type_rbit_devc mg_io_type_rbit_devc
mg_io_uint16 current_sectors_per_track
Definition: mflash.h:72
char port[2]
Definition: mflash.h:28
_mg_opmode
Definition: mflash.h:283
Definition: target.h:126
mg_io_uint8 vendor_unique4
Definition: mflash.h:67
mg_io_uint16 feature_cmd_set_en2
Definition: mflash.h:98
mg_io_uint16 min_pio_cyc_with_iordy
Definition: mflash.h:89
mg_io_uint16 buffer_sector_size
Definition: mflash.h:52
unsigned short feedback_div
Definition: mflash.h:118