49b6dccd0179268f4ae599b934baf37831b8ad10
[openocd.git] / src / flash / nor / faux.c
1 /***************************************************************************
2 * Copyright (C) 2009 √ėyvind Harboe *
3 * oyvind.harboe@zylin.com *
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, see <http://www.gnu.org/licenses/>. *
17 ***************************************************************************/
18
19 #ifdef HAVE_CONFIG_H
20 #include "config.h"
21 #endif
22
23 #include "imp.h"
24 #include <target/image.h>
25 #include "hello.h"
26
27 struct faux_flash_bank {
28 struct target *target;
29 uint8_t *memory;
30 uint32_t start_address;
31 };
32
33 static const int sectorSize = 0x10000;
34
35
36 /* flash bank faux <base> <size> <chip_width> <bus_width> <target#> <driverPath>
37 */
38 FLASH_BANK_COMMAND_HANDLER(faux_flash_bank_command)
39 {
40 struct faux_flash_bank *info;
41
42 if (CMD_ARGC < 6)
43 return ERROR_COMMAND_SYNTAX_ERROR;
44
45 info = malloc(sizeof(struct faux_flash_bank));
46 if (info == NULL) {
47 LOG_ERROR("no memory for flash bank info");
48 return ERROR_FAIL;
49 }
50 info->memory = malloc(bank->size);
51 if (info->memory == NULL) {
52 free(info);
53 LOG_ERROR("no memory for flash bank info");
54 return ERROR_FAIL;
55 }
56 bank->driver_priv = info;
57
58 /* Use 0x10000 as a fixed sector size. */
59 int i = 0;
60 uint32_t offset = 0;
61 bank->num_sectors = bank->size/sectorSize;
62 bank->sectors = malloc(sizeof(struct flash_sector) * bank->num_sectors);
63 for (i = 0; i < bank->num_sectors; i++) {
64 bank->sectors[i].offset = offset;
65 bank->sectors[i].size = sectorSize;
66 offset += bank->sectors[i].size;
67 bank->sectors[i].is_erased = -1;
68 bank->sectors[i].is_protected = 0;
69 }
70
71 info->target = get_target(CMD_ARGV[5]);
72 if (info->target == NULL) {
73 LOG_ERROR("target '%s' not defined", CMD_ARGV[5]);
74 free(info->memory);
75 free(info);
76 return ERROR_FAIL;
77 }
78 return ERROR_OK;
79 }
80
81 static int faux_erase(struct flash_bank *bank, int first, int last)
82 {
83 struct faux_flash_bank *info = bank->driver_priv;
84 memset(info->memory + first*sectorSize, 0xff, sectorSize*(last-first + 1));
85 return ERROR_OK;
86 }
87
88 static int faux_write(struct flash_bank *bank, const uint8_t *buffer, uint32_t offset, uint32_t count)
89 {
90 struct faux_flash_bank *info = bank->driver_priv;
91 memcpy(info->memory + offset, buffer, count);
92 return ERROR_OK;
93 }
94
95 static int faux_info(struct flash_bank *bank, char *buf, int buf_size)
96 {
97 snprintf(buf, buf_size, "faux flash driver");
98 return ERROR_OK;
99 }
100
101 static int faux_probe(struct flash_bank *bank)
102 {
103 return ERROR_OK;
104 }
105
106 static const struct command_registration faux_command_handlers[] = {
107 {
108 .name = "faux",
109 .mode = COMMAND_ANY,
110 .help = "faux flash command group",
111 .chain = hello_command_handlers,
112 },
113 COMMAND_REGISTRATION_DONE
114 };
115
116 const struct flash_driver faux_flash = {
117 .name = "faux",
118 .commands = faux_command_handlers,
119 .flash_bank_command = faux_flash_bank_command,
120 .erase = faux_erase,
121 .write = faux_write,
122 .read = default_flash_read,
123 .probe = faux_probe,
124 .auto_probe = faux_probe,
125 .erase_check = default_flash_blank_check,
126 .info = faux_info,
127 .free_driver_priv = default_flash_free_driver_priv,
128 };

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)