fix noise in gdb console when single stepping. Remove printing of log before processi...
[openocd.git] / src / flash / x7026.c
1 /***************************************************************************
2 * Copyright (C) 2008 by Kevin McGuire *
3 * Copyright (C) 2008 by Marcel Wijlaars *
4 *
5 * This program is free software; you can redistribute it and/or modify *
6 * it under the terms of the GNU General Public License as published by *
7 * the Free Software Foundation; either version 2 of the License, or *
8 * (at your option) any later version. *
9 * *
10 * This program is distributed in the hope that it will be useful, *
11 * but WITHOUT ANY WARRANTY; without even the implied warranty of *
12 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the *
13 * GNU General Public License for more details. *
14 * *
15 * You should have received a copy of the GNU General Public License *
16 * along with this program; if not, write to the *
17 * Free Software Foundation, Inc., *
18 * 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. *
19 ***************************************************************************/
20
21
22 #ifdef HAVE_CONFIG_H
23 #include "config.h"
24 #endif
25
26 #include "replacements.h"
27
28 #include "flash.h"
29 #include "target.h"
30 #include "log.h"
31 #include "armv4_5.h"
32 #include "algorithm.h"
33 #include "binarybuffer.h"
34
35 #include <stdlib.h>
36 #include <string.h>
37 #include <unistd.h>
38
39 int x7026_flash_bank_command(struct command_context_s *cmd_ctx, char *cmd, char **args, int argc, struct flash_bank_s *bank);
40 int x7026_register_commands(struct command_context_s *cmd_ctx);
41 int x7026_erase(struct flash_bank_s *bank, int first, int last);
42 int x7026_protect(struct flash_bank_s *bank, int set, int first, int last);
43 int x7026_write(struct flash_bank_s *bank, u8 *buffer, u32 offset, u32 count);
44 int x7026_probe(struct flash_bank_s *bank);
45 int x7026_info(struct flash_bank_s *bank, char *buf, int buf_size);
46 int x7026_protect_check(struct flash_bank_s *bank);
47 int x7026_erase_check(struct flash_bank_s *bank);
48
49 #define ADUC7026_FLASH 0xfffff800
50 #define ADUC7026_FLASH_FEESTA (0*4)
51 #define ADUC7026_FLASH_FEEMOD (1*4)
52 #define ADUC7026_FLASH_FEECON (2*4)
53 #define ADUC7026_FLASH_FEEDAT (3*4)
54 #define ADUC7026_FLASH_FEEADR (4*4)
55 #define ADUC7026_FLASH_FEESIGN (5*4)
56 #define ADUC7026_FLASH_FEEPRO (6*4)
57 #define ADUC7026_FLASH_FEEHIDE (7*4)
58
59 typedef struct{
60 uint32_t feesta;
61 uint32_t feemod;
62 uint32_t feecon;
63 uint32_t feedat;
64 uint32_t feeadr;
65 uint32_t feesign;
66 uint32_t feepro;
67 uint32_t feehide;
68 } ADUC7026_FLASH_MMIO;
69
70 typedef struct
71 {
72 unsigned char tmp;
73 } X7026_BANK;
74
75 flash_driver_t x7026_flash =
76 {
77 .name = "x7026",
78 .register_commands = x7026_register_commands,
79 .flash_bank_command = x7026_flash_bank_command,
80 .erase = x7026_erase,
81 .protect = x7026_protect,
82 .write = x7026_write,
83 .probe = x7026_probe,
84 .auto_probe = x7026_probe,
85 .erase_check = x7026_erase_check,
86 .protect_check = x7026_protect_check,
87 .info = x7026_info
88 };
89
90 int x7026_register_commands(struct command_context_s *cmd_ctx)
91 {
92 printf("x7026_register_commands not implemented yet.\n");
93 return ERROR_OK;
94 }
95
96 /* flash bank str7x <base> <size> 0 0 <target#> */
97 int x7026_flash_bank_command(struct command_context_s *cmd_ctx, char *cmd, char **args, int argc, struct flash_bank_s *bank)
98 {
99 X7026_BANK *nbank;
100
101 if (argc < 6)
102 {
103 LOG_WARNING("incomplete flash_bank x7026 configuration");
104 return ERROR_FLASH_BANK_INVALID;
105 }
106
107 nbank = malloc(sizeof(X7026_BANK));
108 /* just warn that we are used to normally using 0x80000 */
109 if(bank->base != 0x80000)
110 {
111 LOG_WARNING("Default base address is 0x80000 on the ADuC7026!");
112 }
113 nbank->tmp = 1;
114 bank->driver_priv = nbank;
115 return ERROR_OK;
116 }
117
118 int x7026_protect_check(struct flash_bank_s *bank)
119 {
120 printf("x7026_protect_check not implemented yet.\n");
121 return ERROR_OK;
122 }
123
124 int x7026_erase(struct flash_bank_s *bank, int first, int last)
125 {
126 unsigned int x;
127 int count;
128 u32 v;
129 target_t *target = bank->target;
130
131 /* mass erase */
132 if((first | last) == 0)
133 {
134 printf("performing mass erase.\n");
135 target_write_u32(target, ADUC7026_FLASH + ADUC7026_FLASH_FEEDAT, 0x3cff);
136 target_write_u32(target, ADUC7026_FLASH + ADUC7026_FLASH_FEEADR, 0xffc3);
137 target_read_u32(target, ADUC7026_FLASH + ADUC7026_FLASH_FEEMOD, &v);
138 target_write_u32(target, ADUC7026_FLASH + ADUC7026_FLASH_FEEMOD, v | 0x8);
139 target_write_u32(target, ADUC7026_FLASH + ADUC7026_FLASH_FEECON, 0x06);
140 for(v = 0x4; v & 0x4;
141 target_read_u32(target, ADUC7026_FLASH + ADUC7026_FLASH_FEESTA, &v));
142
143 if(!(v & 0x1))
144 {
145 printf("mass erase failed.\n");
146 return -1;
147 }
148 printf("mass erase successful.\n");
149 return ERROR_OK;
150 }
151
152 count = last - first;
153 for(x = 0; x < (unsigned int)count; ++x)
154 {
155 target_write_u32(target, ADUC7026_FLASH + ADUC7026_FLASH_FEEADR, bank->base + first * 512 + x * 512);
156 target_write_u32(target, ADUC7026_FLASH + ADUC7026_FLASH_FEECON, 0x05);
157 for(v = 0x4; v & 0x4; target_read_u32(target, ADUC7026_FLASH + ADUC7026_FLASH_FEESTA, &v));
158 if(!(v & 0x1))
159 {
160 printf("erase failed for page address %x\n", bank->base + first * 512 + x * 512);
161 return -1;
162 }
163 printf("erased page address %x\n", bank->base + first * 512 + x * 512);
164 }
165 return ERROR_OK;
166 }
167
168 int x7026_protect(struct flash_bank_s *bank, int set, int first, int last)
169 {
170 printf("x7026_protect not implemented yet.\n");
171 return -1;
172 }
173
174 int x7026_write(struct flash_bank_s *bank, u8 *buffer, u32 offset, u32 count)
175 {
176 unsigned int x;
177 u32 v;
178 target_t *target = bank->target;
179 for(x = 0; x < count; x += 2)
180 {
181 target_write_u32(target, ADUC7026_FLASH + ADUC7026_FLASH_FEEADR, offset + x);
182 /* if we able to encounter a single byte instead of a word */
183 if((x + 1) == count)
184 {
185 target_write_u32(target, ADUC7026_FLASH + ADUC7026_FLASH_FEEDAT, buffer[x]);
186 }else{
187 target_write_u32(target, ADUC7026_FLASH + ADUC7026_FLASH_FEEDAT, buffer[x] | (buffer[x+1] << 8));
188 }
189 target_write_u32(target, ADUC7026_FLASH + ADUC7026_FLASH_FEECON, 0x02);
190 for(v = 0x4; v & 0x4; target_read_u32(target, ADUC7026_FLASH + ADUC7026_FLASH_FEESTA, &v));
191 if(!(v & 0x1))
192 {
193 printf("single write failed for address %x.\n", offset + x);
194 return -1;
195 }
196 printf("single write for address %x.\n", offset + x);
197 }
198 return ERROR_OK;
199 }
200
201 int x7026_probe(struct flash_bank_s *bank)
202 {
203 printf("x7026_probe not implemented yet.\n");
204 return ERROR_OK;
205 }
206
207 int x7026_info(struct flash_bank_s *bank, char *buf, int buf_size)
208 {
209 snprintf(buf, buf_size, "x7026 flash driver info" );
210 return -1;
211 }
212
213 int x7026_erase_check(struct flash_bank_s *bank)
214 {
215 printf("x7026_erase_check not implemented yet.\n");
216 return -1;
217 }

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)