stm32f1x: improve variable naming and avoid potential divide-by-zero
[openocd.git] / ecosflash / flash.c
1 /*
2 #####ECOSGPLCOPYRIGHTBEGIN####
3 ## -------------------------------------------
4 ## This file is part of eCos, the Embedded Configurable Operating System.
5 ## Copyright (C) 2008 Øyvind Harboe
6 ##
7 ## eCos is free software; you can redistribute it and/or modify it under
8 ## the terms of the GNU General Public License as published by the Free
9 ## Software Foundation; either version 2 or (at your option) any later version.
10 ##
11 ## eCos is distributed in the hope that it will be useful, but WITHOUT ANY
12 ## WARRANTY; without even the implied warranty of MERCHANTABILITY or
13 ## FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
14 ## for more details.
15 ##
16 ## You should have received a copy of the GNU General Public License along
17 ## with eCos; if not, write to the Free Software Foundation, Inc.,
18 ## 51 Franklin St, Fifth Floor, Boston, MA 02110-1301, USA.
19 ##
20 ## As a special exception, if other files instantiate templates or use macros
21 ## or inline functions from this file, or you compile this file and link it
22 ## with other works to produce a work based on this file, this file does not
23 ## by itself cause the resulting work to be covered by the GNU General Public
24 ## License. However the source code for this file must still be made available
25 ## in accordance with section (3) of the GNU General Public License.
26 ##
27 ## This exception does not invalidate any other reasons why a work based on
28 ## this file might be covered by the GNU General Public License.
29 ## -------------------------------------------
30 #####ECOSGPLCOPYRIGHTEND####
31 */
32
33 #include <string.h>
34 #define _FLASH_PRIVATE_
35 #include <cyg/io/flash.h>
36
37
38
39 int myprintf(char *format, ...)
40 {
41 return 0;
42 }
43
44 extern char _start_bss_clear;
45 extern char __bss_end__;
46
47 int init()
48 {
49 // set up runtime environment
50 char *t;
51 for (t=&_start_bss_clear; t<&__bss_end__; t++)
52 {
53 *t=0;
54 }
55 return flash_init((_printf *)&myprintf);
56
57 }
58
59
60 int checkFlash(void *addr, int len)
61 {
62 // Return error for illegal addresses
63 if ((addr<flash_info.start)||(addr>flash_info.end))
64 return FLASH_ERR_INVALID;
65 if ((((cyg_uint8 *)addr)+len)>(cyg_uint8 *)flash_info.end)
66 return FLASH_ERR_INVALID;
67 return FLASH_ERR_OK;
68 }
69
70
71 int erase(void *address, int len)
72 {
73 int retval;
74 void *failAddress;
75
76 retval=checkFlash(address, len);
77 if (retval!=0)
78 return retval;
79
80 retval=init();
81 if (retval!=0)
82 return retval;
83 return flash_erase(address, len, &failAddress);
84 }
85
86
87
88 extern char _end;
89
90 // Data follows immediately after program, long word aligned.
91 int program(void *buffer, void *address, int len)
92 {
93 int retval;
94 void *failAddress;
95 retval=checkFlash(address, len);
96 if (retval!=0)
97 return retval;
98
99 retval=init();
100 if (retval!=0)
101 return retval;
102 //int flash_program(void *_addr, void *_data, int len, void **err_addr)
103 return flash_program(address, buffer, len, &failAddress);
104 }

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)