b919f5647e7971a585510c0f23cd6b1bc7962122
[openocd.git] / src / flash / nor / dsp5680xx_flash.c
1 /***************************************************************************
2 * Copyright (C) 2011 by Rodrigo L. Rosa *
3 * rodrigorosa.LG@gmail.com *
4 * *
5 * Based on a file written by: *
6 * Kevin McGuire *
7 * Marcel Wijlaars *
8 * Michael Ashton *
9 * *
10 * This program is free software; you can redistribute it and/or modify *
11 * it under the terms of the GNU General Public License as published by *
12 * the Free Software Foundation; either version 2 of the License, or *
13 * (at your option) any later version. *
14 * *
15 * This program is distributed in the hope that it will be useful, *
16 * but WITHOUT ANY WARRANTY; without even the implied warranty of *
17 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the *
18 * GNU General Public License for more details. *
19 * *
20 * You should have received a copy of the GNU General Public License *
21 * along with this program; if not, write to the *
22 * Free Software Foundation, Inc., *
23 * 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. *
24 ***************************************************************************/
25
26 #ifdef HAVE_CONFIG_H
27 #include "config.h"
28 #endif
29
30 #ifndef DSP5680XX_FLASH_H
31 #define DSP5680XX_FLASH_H
32
33 #include "imp.h"
34 #include <helper/binarybuffer.h>
35 #include <helper/time_support.h>
36 #include <target/algorithm.h>
37 #include <target/dsp5680xx.h>
38
39 struct dsp5680xx_flash_bank {
40 struct working_area *write_algorithm;
41 };
42
43 static int dsp5680xx_build_sector_list(struct flash_bank *bank){
44 uint32_t offset = HFM_FLASH_BASE_ADDR;
45 bank->sectors = malloc(sizeof(struct flash_sector) * bank->num_sectors);
46 int i;
47 for (i = 0; i < bank->num_sectors; ++i){
48 bank->sectors[i].offset = i*HFM_SECTOR_SIZE;
49 bank->sectors[i].size = HFM_SECTOR_SIZE;
50 offset += bank->sectors[i].size;
51 bank->sectors[i].is_erased = -1;
52 bank->sectors[i].is_protected = -1;
53 }
54 LOG_USER("%s not tested yet.",__FUNCTION__);
55 return ERROR_OK;
56
57 }
58
59 // flash bank dsp5680xx 0 0 0 0 <target#>
60 FLASH_BANK_COMMAND_HANDLER(dsp5680xx_flash_bank_command){
61 struct dsp5680xx_flash_bank *nbank;
62
63 nbank = malloc(sizeof(struct dsp5680xx_flash_bank));
64
65 bank->base = HFM_FLASH_BASE_ADDR;
66 bank->size = HFM_SIZE_BYTES; // top 4k not accessible
67 bank->driver_priv = nbank;
68 bank->num_sectors = HFM_SECTOR_COUNT;
69 dsp5680xx_build_sector_list(bank);
70
71 return ERROR_OK;
72 }
73
74 static int dsp5680xx_flash_protect_check(struct flash_bank *bank){
75 int retval = ERROR_OK;
76 uint16_t protected = 0;
77 retval = dsp5680xx_f_protect_check(bank->target,&protected);
78 if(retval != ERROR_OK){
79 for(int i = 0;i<HFM_SECTOR_COUNT;i++)
80 bank->sectors[i].is_protected = -1;
81 return ERROR_OK;
82 }
83 for(int i = 0;i<HFM_SECTOR_COUNT/2;i++){
84 if(protected & 1){
85 bank->sectors[2*i].is_protected = 1;
86 bank->sectors[2*i+1].is_protected = 1;
87 }else{
88 bank->sectors[2*i].is_protected = 0;
89 bank->sectors[2*i+1].is_protected = 0;
90 }
91 protected = (protected >> 1);
92 }
93 return retval;
94 }
95
96 static int dsp5680xx_flash_protect(struct flash_bank *bank, int set, int first, int last){
97 // This applies security to flash module after next reset, it does not actually apply protection (protection refers to undesired access from the core)
98 int retval;
99 if(set)
100 retval = dsp5680xx_f_lock(bank->target);
101 else
102 retval = dsp5680xx_f_unlock(bank->target);
103 return retval;
104 }
105
106 /*
107 static int dsp5680xx_write_block(struct flash_bank *bank, uint8_t *buffer, uint32_t offset, uint32_t count){
108 LOG_USER("%s not implemented",__FUNCTION__);
109 return ERROR_OK;
110 }
111
112 static int dsp5680xx_write_single(struct flash_bank *bank, uint8_t *buffer, uint32_t offset, uint32_t count){
113 LOG_USER("%s not implemented",__FUNCTION__);
114 return ERROR_OK;
115 }
116 */
117
118 //-- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- --
119 //-- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- --
120 // Flash stuff test
121 //-- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- --
122 //-- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- --
123
124 static int dsp5680xx_flash_write(struct flash_bank *bank, uint8_t *buffer, uint32_t offset, uint32_t count){
125 int retval;
126 if((offset + count/2)>bank->size){
127 LOG_ERROR("%s: Flash bank cannot fit data.",__FUNCTION__);
128 return ERROR_FAIL;
129 }
130 if(offset%2){
131 LOG_ERROR("%s: Writing to odd addresses not supported. This chip uses word addressing, Openocd only supports byte addressing. The workaround results in disabling writing to odd byte addresses.",__FUNCTION__);
132 return ERROR_FAIL;
133 }
134 retval = dsp5680xx_f_wr(bank->target, buffer, bank->base + offset/2, count);
135 uint32_t addr_word;
136 for(addr_word = bank->base + offset/2;addr_word<count/2;addr_word+=(HFM_SECTOR_SIZE/2)){
137 if(retval == ERROR_OK)
138 bank->sectors[addr_word/(HFM_SECTOR_SIZE/2)].is_erased = 0;
139 else
140 bank->sectors[addr_word/(HFM_SECTOR_SIZE/2)].is_erased = -1;
141 }
142 return retval;
143 }
144
145 static int dsp5680xx_probe(struct flash_bank *bank){
146 LOG_DEBUG("%s not implemented",__FUNCTION__);
147 return ERROR_OK;
148 }
149
150 static int dsp5680xx_flash_info(struct flash_bank *bank, char *buf, int buf_size){
151 snprintf(buf, buf_size, "\ndsp5680xx flash driver info:\n - Currently only full erase/lock/unlock are implemented. \n - Call with bank==0 and sector 0 to 0.\n - Protect requires arp_init-reset to complete. \n - Before removing protection the master tap must be selected, and arp_init-reset is required to complete unlocking.");
152 return ERROR_OK;
153 }
154 /*
155 static int dsp5680xx_set_write_enable(struct target *target, int enable){
156 LOG_USER("%s not implemented",__FUNCTION__);
157 return ERROR_OK;
158 }
159
160
161 static int dsp5680xx_check_flash_completion(struct target* target, unsigned int timeout_ms){
162 LOG_USER("%s not implemented",__FUNCTION__);
163 return ERROR_OK;
164 }
165 */
166
167 static int dsp5680xx_flash_erase(struct flash_bank * bank, int first, int last){
168 int retval;
169 retval = dsp5680xx_f_erase(bank->target, (uint32_t) first, (uint32_t) last);
170 if(retval == ERROR_OK)
171 for(int i = first;i<=last;i++)
172 bank->sectors[i].is_erased = 1;
173 else
174 // If an error occurred unknown status is set even though some sector could have been correctly erased.
175 for(int i = first;i<=last;i++)
176 bank->sectors[i].is_erased = -1;
177 return retval;
178 }
179
180 static int dsp5680xx_flash_erase_check(struct flash_bank * bank){
181 int retval = ERROR_OK;
182 uint8_t erased = 0;
183 uint32_t i;
184 for(i=0;i<HFM_SECTOR_COUNT;i++){
185 if(bank->sectors[i].is_erased == -1){
186 retval = dsp5680xx_f_erase_check(bank->target,&erased,i);
187 if (retval != ERROR_OK){
188 bank->sectors[i].is_erased = -1;
189 }else{
190 if(erased)
191 bank->sectors[i].is_erased = 1;
192 else
193 bank->sectors[i].is_erased = 0;
194 }
195 }
196 }
197 return retval;
198 }
199
200 struct flash_driver dsp5680xx_flash = {
201 .name = "dsp5680xx_flash",
202 .flash_bank_command = dsp5680xx_flash_bank_command,
203 .erase = dsp5680xx_flash_erase,
204 .protect = dsp5680xx_flash_protect,
205 .write = dsp5680xx_flash_write,
206 //.read = default_flash_read,
207 .probe = dsp5680xx_probe,
208 .auto_probe = dsp5680xx_probe,
209 .erase_check = dsp5680xx_flash_erase_check,
210 .protect_check = dsp5680xx_flash_protect_check,
211 .info = dsp5680xx_flash_info
212 };
213 #endif // dsp5680xx_flash.h

Linking to existing account procedure

If you already have an account and want to add another login method you MUST first sign in with your existing account and then change URL to read https://review.openocd.org/login/?link to get to this page again but this time it'll work for linking. Thank you.

SSH host keys fingerprints

1024 SHA256:YKx8b7u5ZWdcbp7/4AeXNaqElP49m6QrwfXaqQGJAOk gerrit-code-review@openocd.zylin.com (DSA)
384 SHA256:jHIbSQa4REvwCFG4cq5LBlBLxmxSqelQPem/EXIrxjk gerrit-code-review@openocd.org (ECDSA)
521 SHA256:UAOPYkU9Fjtcao0Ul/Rrlnj/OsQvt+pgdYSZ4jOYdgs gerrit-code-review@openocd.org (ECDSA)
256 SHA256:A13M5QlnozFOvTllybRZH6vm7iSt0XLxbA48yfc2yfY gerrit-code-review@openocd.org (ECDSA)
256 SHA256:spYMBqEYoAOtK7yZBrcwE8ZpYt6b68Cfh9yEVetvbXg gerrit-code-review@openocd.org (ED25519)
+--[ED25519 256]--+
|=..              |
|+o..   .         |
|*.o   . .        |
|+B . . .         |
|Bo. = o S        |
|Oo.+ + =         |
|oB=.* = . o      |
| =+=.+   + E     |
|. .=o   . o      |
+----[SHA256]-----+
2048 SHA256:0Onrb7/PHjpo6iVZ7xQX2riKN83FJ3KGU0TvI0TaFG4 gerrit-code-review@openocd.zylin.com (RSA)