You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
 
 
 
 
 
 

290 lines
10 KiB

  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. #ifndef OPENOCD_FLASH_MFLASH_H
  18. #define OPENOCD_FLASH_MFLASH_H
  19. struct command_context;
  20. typedef unsigned long mg_io_uint32;
  21. typedef unsigned short mg_io_uint16;
  22. typedef unsigned char mg_io_uint8;
  23. struct mflash_gpio_num {
  24. char port[2];
  25. signed short num;
  26. };
  27. struct mflash_gpio_drv {
  28. const char *name;
  29. int (*set_gpio_to_output)(struct mflash_gpio_num gpio);
  30. int (*set_gpio_output_val)(struct mflash_gpio_num gpio, uint8_t val);
  31. };
  32. typedef struct _mg_io_type_drv_info {
  33. mg_io_uint16 general_configuration; /* 00 */
  34. mg_io_uint16 number_of_cylinders; /* 01 */
  35. mg_io_uint16 reserved1; /* 02 */
  36. mg_io_uint16 number_of_heads; /* 03 */
  37. mg_io_uint16 unformatted_bytes_per_track; /* 04 */
  38. mg_io_uint16 unformatted_bytes_per_sector; /* 05 */
  39. mg_io_uint16 sectors_per_track; /* 06 */
  40. mg_io_uint16 vendor_unique1[3]; /* 07/08/09 */
  41. mg_io_uint8 serial_number[20]; /* 10~19 */
  42. mg_io_uint16 buffer_type; /* 20 */
  43. mg_io_uint16 buffer_sector_size; /* 21 */
  44. mg_io_uint16 number_of_ecc_bytes; /* 22 */
  45. mg_io_uint8 firmware_revision[8]; /* 23~26 */
  46. mg_io_uint8 model_number[40]; /* 27 */
  47. mg_io_uint8 maximum_block_transfer; /* 47 low byte */
  48. mg_io_uint8 vendor_unique2; /* 47 high byte */
  49. mg_io_uint16 dword_io; /* 48 */
  50. mg_io_uint16 capabilities; /* 49 */
  51. mg_io_uint16 reserved2; /* 50 */
  52. mg_io_uint8 vendor_unique3; /* 51 low byte */
  53. mg_io_uint8 pio_cycle_timing_mode; /* 51 high byte */
  54. mg_io_uint8 vendor_unique4; /* 52 low byte */
  55. mg_io_uint8 dma_cycle_timing_mode; /* 52 high byte */
  56. mg_io_uint16 translation_fields_valid; /* 53 (low bit) */
  57. mg_io_uint16 number_of_current_cylinders; /* 54 */
  58. mg_io_uint16 number_of_current_heads; /* 55 */
  59. mg_io_uint16 current_sectors_per_track; /* 56 */
  60. mg_io_uint16 current_sector_capacity_lo; /* 57 & 58 */
  61. mg_io_uint16 current_sector_capacity_hi; /* 57 & 58 */
  62. mg_io_uint8 multi_sector_count; /* 59 low */
  63. mg_io_uint8 multi_sector_setting_valid; /* 59 high (low bit) */
  64. mg_io_uint16 total_user_addressable_sectors_lo; /* 60 & 61 */
  65. mg_io_uint16 total_user_addressable_sectors_hi; /* 60 & 61 */
  66. mg_io_uint8 single_dma_modes_supported; /* 62 low byte */
  67. mg_io_uint8 single_dma_transfer_active; /* 62 high byte */
  68. mg_io_uint8 multi_dma_modes_supported; /* 63 low byte */
  69. mg_io_uint8 multi_dma_transfer_active; /* 63 high byte */
  70. mg_io_uint16 adv_pio_mode;
  71. mg_io_uint16 min_dma_cyc;
  72. mg_io_uint16 recommend_dma_cyc;
  73. mg_io_uint16 min_pio_cyc_no_iordy;
  74. mg_io_uint16 min_pio_cyc_with_iordy;
  75. mg_io_uint8 reserved3[22];
  76. mg_io_uint16 major_ver_num;
  77. mg_io_uint16 minor_ver_num;
  78. mg_io_uint16 feature_cmd_set_suprt0;
  79. mg_io_uint16 feature_cmd_set_suprt1;
  80. mg_io_uint16 feature_cmd_set_suprt2;
  81. mg_io_uint16 feature_cmd_set_en0;
  82. mg_io_uint16 feature_cmd_set_en1;
  83. mg_io_uint16 feature_cmd_set_en2;
  84. mg_io_uint16 reserved4;
  85. mg_io_uint16 req_time_for_security_er_done;
  86. mg_io_uint16 req_time_for_enhan_security_er_done;
  87. mg_io_uint16 adv_pwr_mgm_lvl_val;
  88. mg_io_uint16 reserved5;
  89. mg_io_uint16 re_of_hw_rst;
  90. mg_io_uint8 reserved6[68];
  91. mg_io_uint16 security_stas;
  92. mg_io_uint8 vendor_uniq_bytes[62];
  93. mg_io_uint16 cfa_pwr_mode;
  94. mg_io_uint8 reserved7[186];
  95. mg_io_uint16 scts_per_secure_data_unit;
  96. mg_io_uint16 integrity_word;
  97. } mg_io_type_drv_info;
  98. typedef struct _mg_pll_t {
  99. unsigned int lock_cyc;
  100. unsigned short feedback_div; /* 9bit divider */
  101. unsigned char input_div; /* 5bit divider */
  102. unsigned char output_div; /* 2bit divider */
  103. } mg_pll_t;
  104. struct mg_drv_info {
  105. mg_io_type_drv_info drv_id;
  106. uint32_t tot_sects;
  107. };
  108. struct mflash_bank {
  109. uint32_t base;
  110. struct mflash_gpio_num rst_pin;
  111. struct mflash_gpio_drv *gpio_drv;
  112. struct target *target;
  113. struct mg_drv_info *drv_info;
  114. };
  115. int mflash_register_commands(struct command_context *cmd_ctx);
  116. #define MG_MFLASH_SECTOR_SIZE (0x200) /* 512Bytes = 2^9 */
  117. #define MG_MFLASH_SECTOR_SIZE_MASK (0x200-1)
  118. #define MG_MFLASH_SECTOR_SIZE_SHIFT (9)
  119. #define MG_BUFFER_OFFSET 0x8000
  120. #define MG_REG_OFFSET 0xC000
  121. #define MG_REG_FEATURE 0x2 /* write case */
  122. #define MG_REG_ERROR 0x2 /* read case */
  123. #define MG_REG_SECT_CNT 0x4
  124. #define MG_REG_SECT_NUM 0x6
  125. #define MG_REG_CYL_LOW 0x8
  126. #define MG_REG_CYL_HIGH 0xA
  127. #define MG_REG_DRV_HEAD 0xC
  128. #define MG_REG_COMMAND 0xE /* write case */
  129. #define MG_REG_STATUS 0xE /* read case */
  130. #define MG_REG_DRV_CTRL 0x10
  131. #define MG_REG_BURST_CTRL 0x12
  132. #define MG_OEM_DISK_WAIT_TIME_LONG 15000 /* msec */
  133. #define MG_OEM_DISK_WAIT_TIME_NORMAL 3000 /* msec */
  134. #define MG_OEM_DISK_WAIT_TIME_SHORT 1000 /* msec */
  135. #define MG_PLL_CLK_OUT 66000000.0 /* 66Mhz */
  136. #define MG_PLL_MAX_FEEDBACKDIV_VAL 512
  137. #define MG_PLL_MAX_INPUTDIV_VAL 32
  138. #define MG_PLL_MAX_OUTPUTDIV_VAL 4
  139. #define MG_PLL_STD_INPUTCLK 12000000.0 /* 12Mhz */
  140. #define MG_PLL_STD_LOCKCYCLE 10000
  141. #define MG_UNLOCK_OTP_AREA 0xFF
  142. #define MG_FILEIO_CHUNK 1048576
  143. #define ERROR_MG_IO (-1600)
  144. #define ERROR_MG_TIMEOUT (-1601)
  145. #define ERROR_MG_INVALID_PLL (-1603)
  146. #define ERROR_MG_INTERFACE (-1604)
  147. #define ERROR_MG_INVALID_OSC (-1605)
  148. #define ERROR_MG_UNSUPPORTED_SOC (-1606)
  149. typedef enum _mg_io_type_wait {
  150. mg_io_wait_bsy = 1,
  151. mg_io_wait_not_bsy = 2,
  152. mg_io_wait_rdy = 3,
  153. mg_io_wait_drq = 4, /* wait for data request */
  154. mg_io_wait_drq_noerr = 5, /* wait for DRQ but ignore the error status bit */
  155. mg_io_wait_rdy_noerr = 6 /* wait for ready, but ignore error status bit */
  156. } mg_io_type_wait;
  157. /*= "Status Register" bit masks. */
  158. typedef enum _mg_io_type_rbit_status {
  159. mg_io_rbit_status_error = 0x01, /* error bit in status register */
  160. mg_io_rbit_status_corrected_error = 0x04, /* corrected error in status register */
  161. mg_io_rbit_status_data_req = 0x08, /* data request bit in status register */
  162. mg_io_rbit_status_seek_done = 0x10, /* DSC - Drive Seek Complete */
  163. mg_io_rbit_status_write_fault = 0x20, /* DWF - Drive Write Fault */
  164. mg_io_rbit_status_ready = 0x40,
  165. mg_io_rbit_status_busy = 0x80
  166. } mg_io_type_rbit_status;
  167. /*= "Error Register" bit masks. */
  168. typedef enum _mg_io_type_rbit_error {
  169. mg_io_rbit_err_general = 0x01,
  170. mg_io_rbit_err_aborted = 0x04,
  171. mg_io_rbit_err_bad_sect_num = 0x10,
  172. mg_io_rbit_err_uncorrectable = 0x40,
  173. mg_io_rbit_err_bad_block = 0x80
  174. } mg_io_type_rbit_error;
  175. /* = "Device Control Register" bit. */
  176. typedef enum _mg_io_type_rbit_devc {
  177. mg_io_rbit_devc_intr = 0x02, /* interrupt enable bit (1:disable, 0:enable) */
  178. mg_io_rbit_devc_srst = 0x04 /* softwrae reset bit (1:assert, 0:de-assert) */
  179. } mg_io_type_rbit_devc;
  180. /* "Drive Select/Head Register" values. */
  181. typedef enum _mg_io_type_rval_dev {
  182. mg_io_rval_dev_must_be_on = 0x80, /* These 1 bits are always on */
  183. mg_io_rval_dev_drv_master = (0x00 | mg_io_rval_dev_must_be_on), /* Master */
  184. mg_io_rval_dev_drv_slave0 = (0x10 | mg_io_rval_dev_must_be_on), /* Slave0 */
  185. mg_io_rval_dev_drv_slave1 = (0x20 | mg_io_rval_dev_must_be_on), /* Slave1 */
  186. mg_io_rval_dev_drv_slave2 = (0x30 | mg_io_rval_dev_must_be_on), /* Slave2 */
  187. mg_io_rval_dev_lba_mode = (0x40 | mg_io_rval_dev_must_be_on)
  188. } mg_io_type_rval_dev;
  189. typedef enum _mg_io_type_cmd {
  190. mg_io_cmd_read = 0x20,
  191. mg_io_cmd_write = 0x30,
  192. mg_io_cmd_setmul = 0xC6,
  193. mg_io_cmd_readmul = 0xC4,
  194. mg_io_cmd_writemul = 0xC5,
  195. mg_io_cmd_idle = 0x97, /* 0xE3 */
  196. mg_io_cmd_idle_immediate = 0x95, /* 0xE1 */
  197. mg_io_cmd_setsleep = 0x99, /* 0xE6 */
  198. mg_io_cmd_stdby = 0x96, /* 0xE2 */
  199. mg_io_cmd_stdby_immediate = 0x94, /* 0xE0 */
  200. mg_io_cmd_identify = 0xEC,
  201. mg_io_cmd_set_feature = 0xEF,
  202. mg_io_cmd_confirm_write = 0x3C,
  203. mg_io_cmd_confirm_read = 0x40,
  204. mg_io_cmd_wakeup = 0xC3
  205. } mg_io_type_cmd;
  206. typedef enum _mg_feature_id {
  207. mg_feature_id_transmode = 0x3
  208. } mg_feature_id;
  209. typedef enum _mg_feature_val {
  210. mg_feature_val_trans_default = 0x0,
  211. mg_feature_val_trans_vcmd = 0x3,
  212. mg_feature_val_trand_vcmds = 0x2
  213. } mg_feature_val;
  214. typedef enum _mg_vcmd {
  215. mg_vcmd_update_xipinfo = 0xFA, /* FWPATCH commmand through IOM I/O */
  216. mg_vcmd_verify_fwpatch = 0xFB, /* FWPATCH commmand through IOM I/O */
  217. mg_vcmd_update_stgdrvinfo = 0xFC, /* IOM identificatin info program command */
  218. mg_vcmd_prep_fwpatch = 0xFD, /* FWPATCH commmand through IOM I/O */
  219. mg_vcmd_exe_fwpatch = 0xFE, /* FWPATCH commmand through IOM I/O */
  220. mg_vcmd_wr_pll = 0x8B,
  221. mg_vcmd_purge_nand = 0x8C, /* Only for Seagle */
  222. mg_vcmd_lock_otp = 0x8D,
  223. mg_vcmd_rd_otp = 0x8E,
  224. mg_vcmd_wr_otp = 0x8F
  225. } mg_vcmd;
  226. typedef enum _mg_opmode {
  227. mg_op_mode_xip = 1, /* TRUE XIP */
  228. mg_op_mode_snd = 2, /* BOOT + Storage */
  229. mg_op_mode_stg = 0 /* Only Storage */
  230. } mg_opmode;
  231. #endif /* OPENOCD_FLASH_MFLASH_H */