1 |
786 |
skrzyp |
//==========================================================================
|
2 |
|
|
//
|
3 |
|
|
// flash.h
|
4 |
|
|
//
|
5 |
|
|
// Flash programming - external interfaces
|
6 |
|
|
//
|
7 |
|
|
//==========================================================================
|
8 |
|
|
// ####ECOSGPLCOPYRIGHTBEGIN####
|
9 |
|
|
// -------------------------------------------
|
10 |
|
|
// This file is part of eCos, the Embedded Configurable Operating System.
|
11 |
|
|
// Copyright (C) 1998, 1999, 2000, 2001, 2002, 2003, 2004, 2005, 2009 Free Software Foundation, Inc.
|
12 |
|
|
//
|
13 |
|
|
// eCos is free software; you can redistribute it and/or modify it under
|
14 |
|
|
// the terms of the GNU General Public License as published by the Free
|
15 |
|
|
// Software Foundation; either version 2 or (at your option) any later
|
16 |
|
|
// version.
|
17 |
|
|
//
|
18 |
|
|
// eCos is distributed in the hope that it will be useful, but WITHOUT
|
19 |
|
|
// ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
|
20 |
|
|
// FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
|
21 |
|
|
// for more details.
|
22 |
|
|
//
|
23 |
|
|
// You should have received a copy of the GNU General Public License
|
24 |
|
|
// along with eCos; if not, write to the Free Software Foundation, Inc.,
|
25 |
|
|
// 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
|
26 |
|
|
//
|
27 |
|
|
// As a special exception, if other files instantiate templates or use
|
28 |
|
|
// macros or inline functions from this file, or you compile this file
|
29 |
|
|
// and link it with other works to produce a work based on this file,
|
30 |
|
|
// this file does not by itself cause the resulting work to be covered by
|
31 |
|
|
// the GNU General Public License. However the source code for this file
|
32 |
|
|
// must still be made available in accordance with section (3) of the GNU
|
33 |
|
|
// General Public License v2.
|
34 |
|
|
//
|
35 |
|
|
// This exception does not invalidate any other reasons why a work based
|
36 |
|
|
// on this file might be covered by the GNU General Public License.
|
37 |
|
|
// -------------------------------------------
|
38 |
|
|
// ####ECOSGPLCOPYRIGHTEND####
|
39 |
|
|
//==========================================================================
|
40 |
|
|
//#####DESCRIPTIONBEGIN####
|
41 |
|
|
//
|
42 |
|
|
// Author(s): gthomas
|
43 |
|
|
// Contributors: gthomas, Andrew Lunn, bartv
|
44 |
|
|
// Date: 2000-07-14
|
45 |
|
|
// Purpose:
|
46 |
|
|
// Description:
|
47 |
|
|
//
|
48 |
|
|
//####DESCRIPTIONEND####
|
49 |
|
|
//
|
50 |
|
|
//==========================================================================
|
51 |
|
|
|
52 |
|
|
#ifndef _IO_FLASH_H_
|
53 |
|
|
#define _IO_FLASH_H_
|
54 |
|
|
|
55 |
|
|
#include <pkgconf/system.h>
|
56 |
|
|
#include <pkgconf/io_flash.h>
|
57 |
|
|
#include <stddef.h>
|
58 |
|
|
#include <cyg/infra/cyg_type.h>
|
59 |
|
|
#ifdef CYGPKG_KERNEL
|
60 |
|
|
#include <cyg/kernel/kapi.h>
|
61 |
|
|
#endif
|
62 |
|
|
|
63 |
|
|
// Currently a 32-bit quantity. In future this may be 64-bits on some
|
64 |
|
|
// platforms, e.g. to support very large nand flashes which can only
|
65 |
|
|
// be accessed indirectly.
|
66 |
|
|
typedef CYG_ADDRESS cyg_flashaddr_t;
|
67 |
|
|
|
68 |
|
|
typedef struct cyg_flash_block_info
|
69 |
|
|
{
|
70 |
|
|
size_t block_size;
|
71 |
|
|
cyg_uint32 blocks;
|
72 |
|
|
} cyg_flash_block_info_t;
|
73 |
|
|
|
74 |
|
|
// Information about what one device driver drives
|
75 |
|
|
typedef struct {
|
76 |
|
|
cyg_flashaddr_t start; // First address
|
77 |
|
|
cyg_flashaddr_t end; // Last address
|
78 |
|
|
cyg_uint32 num_block_infos; // Number of entries
|
79 |
|
|
const cyg_flash_block_info_t* block_info; // Info about block sizes
|
80 |
|
|
} cyg_flash_info_t;
|
81 |
|
|
|
82 |
|
|
typedef int cyg_flash_printf(const char *fmt, ...);
|
83 |
|
|
__externC int cyg_flash_init( cyg_flash_printf *pf );
|
84 |
|
|
__externC int cyg_flash_set_printf(const cyg_flashaddr_t flash_base,
|
85 |
|
|
cyg_flash_printf *pf);
|
86 |
|
|
__externC void cyg_flash_set_global_printf(cyg_flash_printf *pf);
|
87 |
|
|
__externC int cyg_flash_get_info(cyg_uint32 devno,
|
88 |
|
|
cyg_flash_info_t * info);
|
89 |
|
|
__externC int cyg_flash_get_info_addr(const cyg_flashaddr_t flash_base,
|
90 |
|
|
cyg_flash_info_t * info);
|
91 |
|
|
__externC int cyg_flash_verify_addr(const cyg_flashaddr_t address);
|
92 |
|
|
__externC size_t cyg_flash_block_size(const cyg_flashaddr_t flash_base);
|
93 |
|
|
__externC int cyg_flash_read(const cyg_flashaddr_t flash_base,
|
94 |
|
|
void *ram_base,
|
95 |
|
|
size_t len,
|
96 |
|
|
cyg_flashaddr_t *err_address);
|
97 |
|
|
__externC int cyg_flash_erase(cyg_flashaddr_t flash_base,
|
98 |
|
|
size_t len,
|
99 |
|
|
cyg_flashaddr_t *err_address);
|
100 |
|
|
__externC int cyg_flash_program(cyg_flashaddr_t flash_base,
|
101 |
|
|
const void *ram_base,
|
102 |
|
|
size_t len,
|
103 |
|
|
cyg_flashaddr_t *err_address);
|
104 |
|
|
__externC int cyg_flash_lock(const cyg_flashaddr_t flash_base,
|
105 |
|
|
size_t len,
|
106 |
|
|
cyg_flashaddr_t *err_address);
|
107 |
|
|
__externC int cyg_flash_unlock(const cyg_flashaddr_t flash_base,
|
108 |
|
|
size_t len,
|
109 |
|
|
cyg_flashaddr_t *err_address);
|
110 |
|
|
__externC const char *cyg_flash_errmsg(const int err);
|
111 |
|
|
#ifdef CYGPKG_KERNEL
|
112 |
|
|
__externC int cyg_flash_mutex_lock(const cyg_flashaddr_t from,
|
113 |
|
|
size_t len);
|
114 |
|
|
__externC int cyg_flash_mutex_unlock(const cyg_flashaddr_t from,
|
115 |
|
|
size_t len);
|
116 |
|
|
#endif
|
117 |
|
|
|
118 |
|
|
#define CYG_FLASH_ERR_OK 0x00 // No error - operation complete
|
119 |
|
|
#define CYG_FLASH_ERR_INVALID 0x01 // Invalid FLASH address
|
120 |
|
|
#define CYG_FLASH_ERR_ERASE 0x02 // Error trying to erase
|
121 |
|
|
#define CYG_FLASH_ERR_LOCK 0x03 // Error trying to lock/unlock
|
122 |
|
|
#define CYG_FLASH_ERR_PROGRAM 0x04 // Error trying to program
|
123 |
|
|
#define CYG_FLASH_ERR_PROTOCOL 0x05 // Generic error
|
124 |
|
|
#define CYG_FLASH_ERR_PROTECT 0x06 // Device/region is write-protected
|
125 |
|
|
#define CYG_FLASH_ERR_NOT_INIT 0x07 // FLASH info not yet initialized
|
126 |
|
|
#define CYG_FLASH_ERR_HWR 0x08 // Hardware (configuration?) problem
|
127 |
|
|
#define CYG_FLASH_ERR_ERASE_SUSPEND 0x09 // Device is in erase suspend mode
|
128 |
|
|
#define CYG_FLASH_ERR_PROGRAM_SUSPEND 0x0a // Device is in program suspend mode
|
129 |
|
|
#define CYG_FLASH_ERR_DRV_VERIFY 0x0b // Driver failed to verify data
|
130 |
|
|
#define CYG_FLASH_ERR_DRV_TIMEOUT 0x0c // Driver timed out
|
131 |
|
|
#define CYG_FLASH_ERR_DRV_WRONG_PART 0x0d // Driver does not support device
|
132 |
|
|
#define CYG_FLASH_ERR_LOW_VOLTAGE 0x0e // Not enough juice to complete job
|
133 |
|
|
|
134 |
|
|
#ifdef CYGSEM_IO_FLASH_LEGACY_API
|
135 |
|
|
typedef int _printf(const char *fmt, ...);
|
136 |
|
|
|
137 |
|
|
externC int flash_init(_printf *pf);
|
138 |
|
|
externC int flash_erase(void *base, int len, void **err_address);
|
139 |
|
|
externC int flash_program(void *flash_base, void *ram_base, int len,
|
140 |
|
|
void **err_address);
|
141 |
|
|
externC int flash_read(void *flash_base, void *ram_base, int len,
|
142 |
|
|
void **err_address);
|
143 |
|
|
externC void flash_dev_query(void *data);
|
144 |
|
|
#ifdef CYGHWR_IO_FLASH_BLOCK_LOCKING
|
145 |
|
|
externC int flash_lock(void *base, int len, void **err_address);
|
146 |
|
|
externC int flash_unlock(void *base, int len, void **err_address);
|
147 |
|
|
#endif
|
148 |
|
|
externC int flash_verify_addr(void *base);
|
149 |
|
|
externC int flash_get_limits(void *base, void **start, void **end);
|
150 |
|
|
externC int flash_get_block_info(int *block_size, int *blocks);
|
151 |
|
|
externC bool flash_code_overlaps(void *start, void *end);
|
152 |
|
|
externC char *flash_errmsg(int err);
|
153 |
|
|
#endif // CYGSEM_IO_FLASH_LEGACY_API
|
154 |
|
|
|
155 |
|
|
#if defined(CYGSEM_IO_FLASH_LEGACY_API) || defined(CYGHWR_IO_FLASH_DEVICE_LEGACY)
|
156 |
|
|
#define FLASH_ERR_OK CYG_FLASH_ERR_OK
|
157 |
|
|
#define FLASH_ERR_INVALID CYG_FLASH_ERR_INVALID
|
158 |
|
|
#define FLASH_ERR_ERASE CYG_FLASH_ERR_ERASE
|
159 |
|
|
#define FLASH_ERR_LOCK CYG_FLASH_ERR_LOCK
|
160 |
|
|
#define FLASH_ERR_PROGRAM CYG_FLASH_ERR_PROGRAM
|
161 |
|
|
#define FLASH_ERR_PROTOCOL CYG_FLASH_ERR_PROTOCOL
|
162 |
|
|
#define FLASH_ERR_PROTECT CYG_FLASH_ERR_PROTECT
|
163 |
|
|
#define FLASH_ERR_NOT_INIT CYG_FLASH_ERR_NOT_INIT
|
164 |
|
|
#define FLASH_ERR_HWR CYG_FLASH_ERR_HWR
|
165 |
|
|
#define FLASH_ERR_ERASE_SUSPEND CYG_FLASH_ERR_ERASE_SUSPEND
|
166 |
|
|
#define FLASH_ERR_PROGRAM_SUSPEND CYG_FLASH_ERR_PROGRAM_SUSPEND
|
167 |
|
|
#define FLASH_ERR_DRV_VERIFY CYG_FLASH_ERR_DRV_VERIFY
|
168 |
|
|
#define FLASH_ERR_DRV_TIMEOUT CYG_FLASH_ERR_DRV_TIMEOUT
|
169 |
|
|
#define FLASH_ERR_DRV_WRONG_PART CYG_FLASH_ERR_DRV_WRONG_PART
|
170 |
|
|
#define FLASH_ERR_LOW_VOLTAGE CYG_FLASH_ERR_LOW_VOLTAGE
|
171 |
|
|
#endif
|
172 |
|
|
|
173 |
|
|
#if defined(CYGPKG_IO_FLASH_BLOCK_DEVICE) || \
|
174 |
|
|
defined(CYGPKG_IO_FLASH_BLOCK_DEVICE_LEGACY)
|
175 |
|
|
typedef struct {
|
176 |
|
|
CYG_ADDRESS offset;
|
177 |
|
|
size_t len;
|
178 |
|
|
int flasherr;
|
179 |
|
|
cyg_flashaddr_t err_address;
|
180 |
|
|
} cyg_io_flash_getconfig_erase_t;
|
181 |
|
|
|
182 |
|
|
typedef cyg_io_flash_getconfig_erase_t cyg_io_flash_getconfig_lock_t;
|
183 |
|
|
typedef cyg_io_flash_getconfig_erase_t cyg_io_flash_getconfig_unlock_t;
|
184 |
|
|
|
185 |
|
|
typedef struct {
|
186 |
|
|
size_t dev_size;
|
187 |
|
|
} cyg_io_flash_getconfig_devsize_t;
|
188 |
|
|
|
189 |
|
|
typedef struct {
|
190 |
|
|
cyg_flashaddr_t dev_addr;
|
191 |
|
|
} cyg_io_flash_getconfig_devaddr_t;
|
192 |
|
|
|
193 |
|
|
typedef struct {
|
194 |
|
|
CYG_ADDRESS offset;
|
195 |
|
|
size_t block_size;
|
196 |
|
|
} cyg_io_flash_getconfig_blocksize_t;
|
197 |
|
|
#endif
|
198 |
|
|
|
199 |
|
|
#endif // _IO_FLASH_H_
|