annotate packages/io/flash/current/src/flashiodev.c @ 2729:74dbf4c3f2e1 after-copyright-change-20090129

Update all copyright banners to reflect FSF ownership; fix and improve licence text.
author jlarmour
date Thu, 29 Jan 2009 17:47:46 +0000
parents a2f5434df2cb
children 422d0a343b4d
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
rev   line source
208
e0c0827131d1 Merge from eCos master repository on 2002-05-20-20:11:54-BST
jlarmour
parents:
diff changeset
1 //==========================================================================
e0c0827131d1 Merge from eCos master repository on 2002-05-20-20:11:54-BST
jlarmour
parents:
diff changeset
2 //
e0c0827131d1 Merge from eCos master repository on 2002-05-20-20:11:54-BST
jlarmour
parents:
diff changeset
3 // flashiodev.c
e0c0827131d1 Merge from eCos master repository on 2002-05-20-20:11:54-BST
jlarmour
parents:
diff changeset
4 //
e0c0827131d1 Merge from eCos master repository on 2002-05-20-20:11:54-BST
jlarmour
parents:
diff changeset
5 // Flash device interface to I/O subsystem
e0c0827131d1 Merge from eCos master repository on 2002-05-20-20:11:54-BST
jlarmour
parents:
diff changeset
6 //
e0c0827131d1 Merge from eCos master repository on 2002-05-20-20:11:54-BST
jlarmour
parents:
diff changeset
7 //==========================================================================
2729
74dbf4c3f2e1 Update all copyright banners to reflect FSF ownership; fix and improve licence text.
jlarmour
parents: 2626
diff changeset
8 // ####ECOSGPLCOPYRIGHTBEGIN####
74dbf4c3f2e1 Update all copyright banners to reflect FSF ownership; fix and improve licence text.
jlarmour
parents: 2626
diff changeset
9 // -------------------------------------------
74dbf4c3f2e1 Update all copyright banners to reflect FSF ownership; fix and improve licence text.
jlarmour
parents: 2626
diff changeset
10 // This file is part of eCos, the Embedded Configurable Operating System.
74dbf4c3f2e1 Update all copyright banners to reflect FSF ownership; fix and improve licence text.
jlarmour
parents: 2626
diff changeset
11 // Copyright (C) 1998, 1999, 2000, 2001, 2002, 2004, 2007 Free Software Foundation, Inc.
208
e0c0827131d1 Merge from eCos master repository on 2002-05-20-20:11:54-BST
jlarmour
parents:
diff changeset
12 //
2729
74dbf4c3f2e1 Update all copyright banners to reflect FSF ownership; fix and improve licence text.
jlarmour
parents: 2626
diff changeset
13 // eCos is free software; you can redistribute it and/or modify it under
74dbf4c3f2e1 Update all copyright banners to reflect FSF ownership; fix and improve licence text.
jlarmour
parents: 2626
diff changeset
14 // the terms of the GNU General Public License as published by the Free
74dbf4c3f2e1 Update all copyright banners to reflect FSF ownership; fix and improve licence text.
jlarmour
parents: 2626
diff changeset
15 // Software Foundation; either version 2 or (at your option) any later
74dbf4c3f2e1 Update all copyright banners to reflect FSF ownership; fix and improve licence text.
jlarmour
parents: 2626
diff changeset
16 // version.
208
e0c0827131d1 Merge from eCos master repository on 2002-05-20-20:11:54-BST
jlarmour
parents:
diff changeset
17 //
2729
74dbf4c3f2e1 Update all copyright banners to reflect FSF ownership; fix and improve licence text.
jlarmour
parents: 2626
diff changeset
18 // eCos is distributed in the hope that it will be useful, but WITHOUT
74dbf4c3f2e1 Update all copyright banners to reflect FSF ownership; fix and improve licence text.
jlarmour
parents: 2626
diff changeset
19 // ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
74dbf4c3f2e1 Update all copyright banners to reflect FSF ownership; fix and improve licence text.
jlarmour
parents: 2626
diff changeset
20 // FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
74dbf4c3f2e1 Update all copyright banners to reflect FSF ownership; fix and improve licence text.
jlarmour
parents: 2626
diff changeset
21 // for more details.
208
e0c0827131d1 Merge from eCos master repository on 2002-05-20-20:11:54-BST
jlarmour
parents:
diff changeset
22 //
2729
74dbf4c3f2e1 Update all copyright banners to reflect FSF ownership; fix and improve licence text.
jlarmour
parents: 2626
diff changeset
23 // You should have received a copy of the GNU General Public License
74dbf4c3f2e1 Update all copyright banners to reflect FSF ownership; fix and improve licence text.
jlarmour
parents: 2626
diff changeset
24 // along with eCos; if not, write to the Free Software Foundation, Inc.,
74dbf4c3f2e1 Update all copyright banners to reflect FSF ownership; fix and improve licence text.
jlarmour
parents: 2626
diff changeset
25 // 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
208
e0c0827131d1 Merge from eCos master repository on 2002-05-20-20:11:54-BST
jlarmour
parents:
diff changeset
26 //
2729
74dbf4c3f2e1 Update all copyright banners to reflect FSF ownership; fix and improve licence text.
jlarmour
parents: 2626
diff changeset
27 // As a special exception, if other files instantiate templates or use
74dbf4c3f2e1 Update all copyright banners to reflect FSF ownership; fix and improve licence text.
jlarmour
parents: 2626
diff changeset
28 // macros or inline functions from this file, or you compile this file
74dbf4c3f2e1 Update all copyright banners to reflect FSF ownership; fix and improve licence text.
jlarmour
parents: 2626
diff changeset
29 // and link it with other works to produce a work based on this file,
74dbf4c3f2e1 Update all copyright banners to reflect FSF ownership; fix and improve licence text.
jlarmour
parents: 2626
diff changeset
30 // this file does not by itself cause the resulting work to be covered by
74dbf4c3f2e1 Update all copyright banners to reflect FSF ownership; fix and improve licence text.
jlarmour
parents: 2626
diff changeset
31 // the GNU General Public License. However the source code for this file
74dbf4c3f2e1 Update all copyright banners to reflect FSF ownership; fix and improve licence text.
jlarmour
parents: 2626
diff changeset
32 // must still be made available in accordance with section (3) of the GNU
74dbf4c3f2e1 Update all copyright banners to reflect FSF ownership; fix and improve licence text.
jlarmour
parents: 2626
diff changeset
33 // General Public License v2.
208
e0c0827131d1 Merge from eCos master repository on 2002-05-20-20:11:54-BST
jlarmour
parents:
diff changeset
34 //
2729
74dbf4c3f2e1 Update all copyright banners to reflect FSF ownership; fix and improve licence text.
jlarmour
parents: 2626
diff changeset
35 // This exception does not invalidate any other reasons why a work based
74dbf4c3f2e1 Update all copyright banners to reflect FSF ownership; fix and improve licence text.
jlarmour
parents: 2626
diff changeset
36 // on this file might be covered by the GNU General Public License.
74dbf4c3f2e1 Update all copyright banners to reflect FSF ownership; fix and improve licence text.
jlarmour
parents: 2626
diff changeset
37 // -------------------------------------------
74dbf4c3f2e1 Update all copyright banners to reflect FSF ownership; fix and improve licence text.
jlarmour
parents: 2626
diff changeset
38 // ####ECOSGPLCOPYRIGHTEND####
208
e0c0827131d1 Merge from eCos master repository on 2002-05-20-20:11:54-BST
jlarmour
parents:
diff changeset
39 //==========================================================================
e0c0827131d1 Merge from eCos master repository on 2002-05-20-20:11:54-BST
jlarmour
parents:
diff changeset
40 //#####DESCRIPTIONBEGIN####
e0c0827131d1 Merge from eCos master repository on 2002-05-20-20:11:54-BST
jlarmour
parents:
diff changeset
41 //
e0c0827131d1 Merge from eCos master repository on 2002-05-20-20:11:54-BST
jlarmour
parents:
diff changeset
42 // Author(s): jlarmour
2626
a2f5434df2cb Merge flashv2 branch to trunk, with eCosCentric additions
jlarmour
parents: 1615
diff changeset
43 // Contributors: woehler, Andrew Lunn
a2f5434df2cb Merge flashv2 branch to trunk, with eCosCentric additions
jlarmour
parents: 1615
diff changeset
44 // Date: 2004-12-03
208
e0c0827131d1 Merge from eCos master repository on 2002-05-20-20:11:54-BST
jlarmour
parents:
diff changeset
45 // Purpose:
e0c0827131d1 Merge from eCos master repository on 2002-05-20-20:11:54-BST
jlarmour
parents:
diff changeset
46 // Description:
e0c0827131d1 Merge from eCos master repository on 2002-05-20-20:11:54-BST
jlarmour
parents:
diff changeset
47 //
e0c0827131d1 Merge from eCos master repository on 2002-05-20-20:11:54-BST
jlarmour
parents:
diff changeset
48 //####DESCRIPTIONEND####
e0c0827131d1 Merge from eCos master repository on 2002-05-20-20:11:54-BST
jlarmour
parents:
diff changeset
49 //
e0c0827131d1 Merge from eCos master repository on 2002-05-20-20:11:54-BST
jlarmour
parents:
diff changeset
50 //==========================================================================
e0c0827131d1 Merge from eCos master repository on 2002-05-20-20:11:54-BST
jlarmour
parents:
diff changeset
51
2626
a2f5434df2cb Merge flashv2 branch to trunk, with eCosCentric additions
jlarmour
parents: 1615
diff changeset
52 // INCLUDES
a2f5434df2cb Merge flashv2 branch to trunk, with eCosCentric additions
jlarmour
parents: 1615
diff changeset
53
208
e0c0827131d1 Merge from eCos master repository on 2002-05-20-20:11:54-BST
jlarmour
parents:
diff changeset
54 #include <pkgconf/io_flash.h>
e0c0827131d1 Merge from eCos master repository on 2002-05-20-20:11:54-BST
jlarmour
parents:
diff changeset
55 #include <errno.h>
e0c0827131d1 Merge from eCos master repository on 2002-05-20-20:11:54-BST
jlarmour
parents:
diff changeset
56 #include <cyg/infra/cyg_type.h>
2626
a2f5434df2cb Merge flashv2 branch to trunk, with eCosCentric additions
jlarmour
parents: 1615
diff changeset
57 #include <cyg/infra/cyg_ass.h>
208
e0c0827131d1 Merge from eCos master repository on 2002-05-20-20:11:54-BST
jlarmour
parents:
diff changeset
58 #include <cyg/io/devtab.h>
e0c0827131d1 Merge from eCos master repository on 2002-05-20-20:11:54-BST
jlarmour
parents:
diff changeset
59 #include <cyg/io/config_keys.h>
e0c0827131d1 Merge from eCos master repository on 2002-05-20-20:11:54-BST
jlarmour
parents:
diff changeset
60 #include <cyg/io/flash.h>
e0c0827131d1 Merge from eCos master repository on 2002-05-20-20:11:54-BST
jlarmour
parents:
diff changeset
61 #include <string.h> // memcpy
791
a2dfa8bf3c57 Export RedBoot FIS functions - from Knud Woehler <knud.woehler@microplex.de>
gthomas
parents: 210
diff changeset
62 #include <cyg/hal/hal_if.h>
2626
a2f5434df2cb Merge flashv2 branch to trunk, with eCosCentric additions
jlarmour
parents: 1615
diff changeset
63 #include <cyg/hal/drv_api.h> // mutexes
a2f5434df2cb Merge flashv2 branch to trunk, with eCosCentric additions
jlarmour
parents: 1615
diff changeset
64
a2f5434df2cb Merge flashv2 branch to trunk, with eCosCentric additions
jlarmour
parents: 1615
diff changeset
65 // MACROS
208
e0c0827131d1 Merge from eCos master repository on 2002-05-20-20:11:54-BST
jlarmour
parents:
diff changeset
66
e0c0827131d1 Merge from eCos master repository on 2002-05-20-20:11:54-BST
jlarmour
parents:
diff changeset
67 #define MIN(x,y) ((x)<(y) ? (x) : (y))
2626
a2f5434df2cb Merge flashv2 branch to trunk, with eCosCentric additions
jlarmour
parents: 1615
diff changeset
68 #define MAX(x,y) ((x)>(y) ? (x) : (y))
a2f5434df2cb Merge flashv2 branch to trunk, with eCosCentric additions
jlarmour
parents: 1615
diff changeset
69
a2f5434df2cb Merge flashv2 branch to trunk, with eCosCentric additions
jlarmour
parents: 1615
diff changeset
70 // TYPES
208
e0c0827131d1 Merge from eCos master repository on 2002-05-20-20:11:54-BST
jlarmour
parents:
diff changeset
71
791
a2dfa8bf3c57 Export RedBoot FIS functions - from Knud Woehler <knud.woehler@microplex.de>
gthomas
parents: 210
diff changeset
72 struct flashiodev_priv_t{
2626
a2f5434df2cb Merge flashv2 branch to trunk, with eCosCentric additions
jlarmour
parents: 1615
diff changeset
73 cyg_devtab_entry_t handle;
a2f5434df2cb Merge flashv2 branch to trunk, with eCosCentric additions
jlarmour
parents: 1615
diff changeset
74 cyg_flashaddr_t start;
a2f5434df2cb Merge flashv2 branch to trunk, with eCosCentric additions
jlarmour
parents: 1615
diff changeset
75 cyg_flashaddr_t end;
a2f5434df2cb Merge flashv2 branch to trunk, with eCosCentric additions
jlarmour
parents: 1615
diff changeset
76 cyg_bool valid;
791
a2dfa8bf3c57 Export RedBoot FIS functions - from Knud Woehler <knud.woehler@microplex.de>
gthomas
parents: 210
diff changeset
77 };
2626
a2f5434df2cb Merge flashv2 branch to trunk, with eCosCentric additions
jlarmour
parents: 1615
diff changeset
78 // FUNCTION PROTOTYPES
791
a2dfa8bf3c57 Export RedBoot FIS functions - from Knud Woehler <knud.woehler@microplex.de>
gthomas
parents: 210
diff changeset
79
2626
a2f5434df2cb Merge flashv2 branch to trunk, with eCosCentric additions
jlarmour
parents: 1615
diff changeset
80 static bool flashiodev_init( struct cyg_devtab_entry *tab );
a2f5434df2cb Merge flashv2 branch to trunk, with eCosCentric additions
jlarmour
parents: 1615
diff changeset
81 static Cyg_ErrNo
a2f5434df2cb Merge flashv2 branch to trunk, with eCosCentric additions
jlarmour
parents: 1615
diff changeset
82 flashiodev_lookup(struct cyg_devtab_entry **tab,
a2f5434df2cb Merge flashv2 branch to trunk, with eCosCentric additions
jlarmour
parents: 1615
diff changeset
83 struct cyg_devtab_entry *sub_tab,
a2f5434df2cb Merge flashv2 branch to trunk, with eCosCentric additions
jlarmour
parents: 1615
diff changeset
84 const char *name) ;
a2f5434df2cb Merge flashv2 branch to trunk, with eCosCentric additions
jlarmour
parents: 1615
diff changeset
85 static Cyg_ErrNo
a2f5434df2cb Merge flashv2 branch to trunk, with eCosCentric additions
jlarmour
parents: 1615
diff changeset
86 flashiodev_bread( cyg_io_handle_t handle, void *buf, cyg_uint32 *len,
a2f5434df2cb Merge flashv2 branch to trunk, with eCosCentric additions
jlarmour
parents: 1615
diff changeset
87 cyg_uint32 pos);
a2f5434df2cb Merge flashv2 branch to trunk, with eCosCentric additions
jlarmour
parents: 1615
diff changeset
88 static Cyg_ErrNo
a2f5434df2cb Merge flashv2 branch to trunk, with eCosCentric additions
jlarmour
parents: 1615
diff changeset
89 flashiodev_bwrite( cyg_io_handle_t handle, const void *buf, cyg_uint32 *len,
a2f5434df2cb Merge flashv2 branch to trunk, with eCosCentric additions
jlarmour
parents: 1615
diff changeset
90 cyg_uint32 pos );
a2f5434df2cb Merge flashv2 branch to trunk, with eCosCentric additions
jlarmour
parents: 1615
diff changeset
91 static Cyg_ErrNo
a2f5434df2cb Merge flashv2 branch to trunk, with eCosCentric additions
jlarmour
parents: 1615
diff changeset
92 flashiodev_get_config( cyg_io_handle_t handle,
a2f5434df2cb Merge flashv2 branch to trunk, with eCosCentric additions
jlarmour
parents: 1615
diff changeset
93 cyg_uint32 key,
a2f5434df2cb Merge flashv2 branch to trunk, with eCosCentric additions
jlarmour
parents: 1615
diff changeset
94 void* buf,
a2f5434df2cb Merge flashv2 branch to trunk, with eCosCentric additions
jlarmour
parents: 1615
diff changeset
95 cyg_uint32* len);
a2f5434df2cb Merge flashv2 branch to trunk, with eCosCentric additions
jlarmour
parents: 1615
diff changeset
96 static Cyg_ErrNo
a2f5434df2cb Merge flashv2 branch to trunk, with eCosCentric additions
jlarmour
parents: 1615
diff changeset
97 flashiodev_set_config( cyg_io_handle_t handle,
a2f5434df2cb Merge flashv2 branch to trunk, with eCosCentric additions
jlarmour
parents: 1615
diff changeset
98 cyg_uint32 key,
a2f5434df2cb Merge flashv2 branch to trunk, with eCosCentric additions
jlarmour
parents: 1615
diff changeset
99 const void* buf,
a2f5434df2cb Merge flashv2 branch to trunk, with eCosCentric additions
jlarmour
parents: 1615
diff changeset
100 cyg_uint32* len);
a2f5434df2cb Merge flashv2 branch to trunk, with eCosCentric additions
jlarmour
parents: 1615
diff changeset
101
a2f5434df2cb Merge flashv2 branch to trunk, with eCosCentric additions
jlarmour
parents: 1615
diff changeset
102 // STATICS/GLOBALS
a2f5434df2cb Merge flashv2 branch to trunk, with eCosCentric additions
jlarmour
parents: 1615
diff changeset
103
a2f5434df2cb Merge flashv2 branch to trunk, with eCosCentric additions
jlarmour
parents: 1615
diff changeset
104 static struct flashiodev_priv_t flashiodev_table[CYGNUM_IO_FLASH_BLOCK_DEVICES];
a2f5434df2cb Merge flashv2 branch to trunk, with eCosCentric additions
jlarmour
parents: 1615
diff changeset
105 static cyg_drv_mutex_t flashiodev_table_lock;
a2f5434df2cb Merge flashv2 branch to trunk, with eCosCentric additions
jlarmour
parents: 1615
diff changeset
106
a2f5434df2cb Merge flashv2 branch to trunk, with eCosCentric additions
jlarmour
parents: 1615
diff changeset
107 BLOCK_DEVIO_TABLE( cyg_io_flashdev_ops,
a2f5434df2cb Merge flashv2 branch to trunk, with eCosCentric additions
jlarmour
parents: 1615
diff changeset
108 &flashiodev_bwrite,
a2f5434df2cb Merge flashv2 branch to trunk, with eCosCentric additions
jlarmour
parents: 1615
diff changeset
109 &flashiodev_bread,
a2f5434df2cb Merge flashv2 branch to trunk, with eCosCentric additions
jlarmour
parents: 1615
diff changeset
110 NULL, // no select
a2f5434df2cb Merge flashv2 branch to trunk, with eCosCentric additions
jlarmour
parents: 1615
diff changeset
111 &flashiodev_get_config,
a2f5434df2cb Merge flashv2 branch to trunk, with eCosCentric additions
jlarmour
parents: 1615
diff changeset
112 &flashiodev_set_config
a2f5434df2cb Merge flashv2 branch to trunk, with eCosCentric additions
jlarmour
parents: 1615
diff changeset
113 );
a2f5434df2cb Merge flashv2 branch to trunk, with eCosCentric additions
jlarmour
parents: 1615
diff changeset
114
a2f5434df2cb Merge flashv2 branch to trunk, with eCosCentric additions
jlarmour
parents: 1615
diff changeset
115
a2f5434df2cb Merge flashv2 branch to trunk, with eCosCentric additions
jlarmour
parents: 1615
diff changeset
116 BLOCK_DEVTAB_ENTRY( cyg_io_flashdev,
a2f5434df2cb Merge flashv2 branch to trunk, with eCosCentric additions
jlarmour
parents: 1615
diff changeset
117 "/dev/flash/",
a2f5434df2cb Merge flashv2 branch to trunk, with eCosCentric additions
jlarmour
parents: 1615
diff changeset
118 NULL,
a2f5434df2cb Merge flashv2 branch to trunk, with eCosCentric additions
jlarmour
parents: 1615
diff changeset
119 &cyg_io_flashdev_ops,
a2f5434df2cb Merge flashv2 branch to trunk, with eCosCentric additions
jlarmour
parents: 1615
diff changeset
120 &flashiodev_init,
a2f5434df2cb Merge flashv2 branch to trunk, with eCosCentric additions
jlarmour
parents: 1615
diff changeset
121 &flashiodev_lookup,
a2f5434df2cb Merge flashv2 branch to trunk, with eCosCentric additions
jlarmour
parents: 1615
diff changeset
122 NULL );
a2f5434df2cb Merge flashv2 branch to trunk, with eCosCentric additions
jlarmour
parents: 1615
diff changeset
123
a2f5434df2cb Merge flashv2 branch to trunk, with eCosCentric additions
jlarmour
parents: 1615
diff changeset
124 // FUNCTIONS
208
e0c0827131d1 Merge from eCos master repository on 2002-05-20-20:11:54-BST
jlarmour
parents:
diff changeset
125
e0c0827131d1 Merge from eCos master repository on 2002-05-20-20:11:54-BST
jlarmour
parents:
diff changeset
126 static int dummy_printf( const char *fmt, ... ) {return 0;}
e0c0827131d1 Merge from eCos master repository on 2002-05-20-20:11:54-BST
jlarmour
parents:
diff changeset
127
e0c0827131d1 Merge from eCos master repository on 2002-05-20-20:11:54-BST
jlarmour
parents:
diff changeset
128 static bool
e0c0827131d1 Merge from eCos master repository on 2002-05-20-20:11:54-BST
jlarmour
parents:
diff changeset
129 flashiodev_init( struct cyg_devtab_entry *tab )
e0c0827131d1 Merge from eCos master repository on 2002-05-20-20:11:54-BST
jlarmour
parents:
diff changeset
130 {
2626
a2f5434df2cb Merge flashv2 branch to trunk, with eCosCentric additions
jlarmour
parents: 1615
diff changeset
131 int stat = cyg_flash_init( &dummy_printf );
a2f5434df2cb Merge flashv2 branch to trunk, with eCosCentric additions
jlarmour
parents: 1615
diff changeset
132 cyg_ucount32 i;
208
e0c0827131d1 Merge from eCos master repository on 2002-05-20-20:11:54-BST
jlarmour
parents:
diff changeset
133
2626
a2f5434df2cb Merge flashv2 branch to trunk, with eCosCentric additions
jlarmour
parents: 1615
diff changeset
134 if (stat == CYG_FLASH_ERR_OK)
a2f5434df2cb Merge flashv2 branch to trunk, with eCosCentric additions
jlarmour
parents: 1615
diff changeset
135 {
a2f5434df2cb Merge flashv2 branch to trunk, with eCosCentric additions
jlarmour
parents: 1615
diff changeset
136 for (i=0; i<CYGNUM_IO_FLASH_BLOCK_DEVICES; i++)
a2f5434df2cb Merge flashv2 branch to trunk, with eCosCentric additions
jlarmour
parents: 1615
diff changeset
137 {
a2f5434df2cb Merge flashv2 branch to trunk, with eCosCentric additions
jlarmour
parents: 1615
diff changeset
138 CYG_ASSERT( tab->handlers == &cyg_io_flashdev_ops, "Unexpected handlers - not flashdev_ops" );
a2f5434df2cb Merge flashv2 branch to trunk, with eCosCentric additions
jlarmour
parents: 1615
diff changeset
139 flashiodev_table[i].handle.handlers = &cyg_io_flashdev_ops;
a2f5434df2cb Merge flashv2 branch to trunk, with eCosCentric additions
jlarmour
parents: 1615
diff changeset
140 flashiodev_table[i].handle.status = CYG_DEVTAB_STATUS_BLOCK;
a2f5434df2cb Merge flashv2 branch to trunk, with eCosCentric additions
jlarmour
parents: 1615
diff changeset
141 flashiodev_table[i].handle.priv = &flashiodev_table[i]; // link back
a2f5434df2cb Merge flashv2 branch to trunk, with eCosCentric additions
jlarmour
parents: 1615
diff changeset
142 } // for
a2f5434df2cb Merge flashv2 branch to trunk, with eCosCentric additions
jlarmour
parents: 1615
diff changeset
143 cyg_drv_mutex_init( &flashiodev_table_lock );
a2f5434df2cb Merge flashv2 branch to trunk, with eCosCentric additions
jlarmour
parents: 1615
diff changeset
144 } // if
a2f5434df2cb Merge flashv2 branch to trunk, with eCosCentric additions
jlarmour
parents: 1615
diff changeset
145
a2f5434df2cb Merge flashv2 branch to trunk, with eCosCentric additions
jlarmour
parents: 1615
diff changeset
146 return (stat == CYG_FLASH_ERR_OK);
208
e0c0827131d1 Merge from eCos master repository on 2002-05-20-20:11:54-BST
jlarmour
parents:
diff changeset
147 } // flashiodev_init()
e0c0827131d1 Merge from eCos master repository on 2002-05-20-20:11:54-BST
jlarmour
parents:
diff changeset
148
2626
a2f5434df2cb Merge flashv2 branch to trunk, with eCosCentric additions
jlarmour
parents: 1615
diff changeset
149 #ifdef CYGFUN_IO_FLASH_BLOCK_FROM_DEVOFFSET
a2f5434df2cb Merge flashv2 branch to trunk, with eCosCentric additions
jlarmour
parents: 1615
diff changeset
150 static cyg_uint32
a2f5434df2cb Merge flashv2 branch to trunk, with eCosCentric additions
jlarmour
parents: 1615
diff changeset
151 parsenum( const char **str )
a2f5434df2cb Merge flashv2 branch to trunk, with eCosCentric additions
jlarmour
parents: 1615
diff changeset
152 {
a2f5434df2cb Merge flashv2 branch to trunk, with eCosCentric additions
jlarmour
parents: 1615
diff changeset
153 cyg_uint32 num = 0;
a2f5434df2cb Merge flashv2 branch to trunk, with eCosCentric additions
jlarmour
parents: 1615
diff changeset
154 cyg_uint8 base = 10;
a2f5434df2cb Merge flashv2 branch to trunk, with eCosCentric additions
jlarmour
parents: 1615
diff changeset
155
a2f5434df2cb Merge flashv2 branch to trunk, with eCosCentric additions
jlarmour
parents: 1615
diff changeset
156 // trim leading 0s
a2f5434df2cb Merge flashv2 branch to trunk, with eCosCentric additions
jlarmour
parents: 1615
diff changeset
157 while (**str == '0')
a2f5434df2cb Merge flashv2 branch to trunk, with eCosCentric additions
jlarmour
parents: 1615
diff changeset
158 (*str)++;
a2f5434df2cb Merge flashv2 branch to trunk, with eCosCentric additions
jlarmour
parents: 1615
diff changeset
159 // crudely detect hex by assuming that something with a leading 0x
a2f5434df2cb Merge flashv2 branch to trunk, with eCosCentric additions
jlarmour
parents: 1615
diff changeset
160 // can just match the 'x' with a leading 0 being trimmed.
a2f5434df2cb Merge flashv2 branch to trunk, with eCosCentric additions
jlarmour
parents: 1615
diff changeset
161 if ( (**str == 'x') || (**str == 'X') )
a2f5434df2cb Merge flashv2 branch to trunk, with eCosCentric additions
jlarmour
parents: 1615
diff changeset
162 {
a2f5434df2cb Merge flashv2 branch to trunk, with eCosCentric additions
jlarmour
parents: 1615
diff changeset
163 (*str)++;
a2f5434df2cb Merge flashv2 branch to trunk, with eCosCentric additions
jlarmour
parents: 1615
diff changeset
164 base = 16;
a2f5434df2cb Merge flashv2 branch to trunk, with eCosCentric additions
jlarmour
parents: 1615
diff changeset
165 }
a2f5434df2cb Merge flashv2 branch to trunk, with eCosCentric additions
jlarmour
parents: 1615
diff changeset
166
a2f5434df2cb Merge flashv2 branch to trunk, with eCosCentric additions
jlarmour
parents: 1615
diff changeset
167 while (**str) {
a2f5434df2cb Merge flashv2 branch to trunk, with eCosCentric additions
jlarmour
parents: 1615
diff changeset
168 switch (**str)
a2f5434df2cb Merge flashv2 branch to trunk, with eCosCentric additions
jlarmour
parents: 1615
diff changeset
169 {
a2f5434df2cb Merge flashv2 branch to trunk, with eCosCentric additions
jlarmour
parents: 1615
diff changeset
170 case '0':
a2f5434df2cb Merge flashv2 branch to trunk, with eCosCentric additions
jlarmour
parents: 1615
diff changeset
171 case '1':
a2f5434df2cb Merge flashv2 branch to trunk, with eCosCentric additions
jlarmour
parents: 1615
diff changeset
172 case '2':
a2f5434df2cb Merge flashv2 branch to trunk, with eCosCentric additions
jlarmour
parents: 1615
diff changeset
173 case '3':
a2f5434df2cb Merge flashv2 branch to trunk, with eCosCentric additions
jlarmour
parents: 1615
diff changeset
174 case '4':
a2f5434df2cb Merge flashv2 branch to trunk, with eCosCentric additions
jlarmour
parents: 1615
diff changeset
175 case '5':
a2f5434df2cb Merge flashv2 branch to trunk, with eCosCentric additions
jlarmour
parents: 1615
diff changeset
176 case '6':
a2f5434df2cb Merge flashv2 branch to trunk, with eCosCentric additions
jlarmour
parents: 1615
diff changeset
177 case '7':
a2f5434df2cb Merge flashv2 branch to trunk, with eCosCentric additions
jlarmour
parents: 1615
diff changeset
178 case '8':
a2f5434df2cb Merge flashv2 branch to trunk, with eCosCentric additions
jlarmour
parents: 1615
diff changeset
179 case '9':
a2f5434df2cb Merge flashv2 branch to trunk, with eCosCentric additions
jlarmour
parents: 1615
diff changeset
180 num = (num * base) + (**str-'0');
a2f5434df2cb Merge flashv2 branch to trunk, with eCosCentric additions
jlarmour
parents: 1615
diff changeset
181 break;
a2f5434df2cb Merge flashv2 branch to trunk, with eCosCentric additions
jlarmour
parents: 1615
diff changeset
182 case 'a':
a2f5434df2cb Merge flashv2 branch to trunk, with eCosCentric additions
jlarmour
parents: 1615
diff changeset
183 case 'b':
a2f5434df2cb Merge flashv2 branch to trunk, with eCosCentric additions
jlarmour
parents: 1615
diff changeset
184 case 'c':
a2f5434df2cb Merge flashv2 branch to trunk, with eCosCentric additions
jlarmour
parents: 1615
diff changeset
185 case 'd':
a2f5434df2cb Merge flashv2 branch to trunk, with eCosCentric additions
jlarmour
parents: 1615
diff changeset
186 case 'e':
a2f5434df2cb Merge flashv2 branch to trunk, with eCosCentric additions
jlarmour
parents: 1615
diff changeset
187 case 'f':
a2f5434df2cb Merge flashv2 branch to trunk, with eCosCentric additions
jlarmour
parents: 1615
diff changeset
188 if ( base != 16 )
a2f5434df2cb Merge flashv2 branch to trunk, with eCosCentric additions
jlarmour
parents: 1615
diff changeset
189 return num;
a2f5434df2cb Merge flashv2 branch to trunk, with eCosCentric additions
jlarmour
parents: 1615
diff changeset
190 num = (num * base) + (**str-'a' + 10);
a2f5434df2cb Merge flashv2 branch to trunk, with eCosCentric additions
jlarmour
parents: 1615
diff changeset
191 break;
a2f5434df2cb Merge flashv2 branch to trunk, with eCosCentric additions
jlarmour
parents: 1615
diff changeset
192 case 'A':
a2f5434df2cb Merge flashv2 branch to trunk, with eCosCentric additions
jlarmour
parents: 1615
diff changeset
193 case 'B':
a2f5434df2cb Merge flashv2 branch to trunk, with eCosCentric additions
jlarmour
parents: 1615
diff changeset
194 case 'C':
a2f5434df2cb Merge flashv2 branch to trunk, with eCosCentric additions
jlarmour
parents: 1615
diff changeset
195 case 'D':
a2f5434df2cb Merge flashv2 branch to trunk, with eCosCentric additions
jlarmour
parents: 1615
diff changeset
196 case 'E':
a2f5434df2cb Merge flashv2 branch to trunk, with eCosCentric additions
jlarmour
parents: 1615
diff changeset
197 case 'F':
a2f5434df2cb Merge flashv2 branch to trunk, with eCosCentric additions
jlarmour
parents: 1615
diff changeset
198 if ( base != 16 )
a2f5434df2cb Merge flashv2 branch to trunk, with eCosCentric additions
jlarmour
parents: 1615
diff changeset
199 return num;
a2f5434df2cb Merge flashv2 branch to trunk, with eCosCentric additions
jlarmour
parents: 1615
diff changeset
200 num = (num << 4) + (**str-'A' + 10);
a2f5434df2cb Merge flashv2 branch to trunk, with eCosCentric additions
jlarmour
parents: 1615
diff changeset
201 break;
a2f5434df2cb Merge flashv2 branch to trunk, with eCosCentric additions
jlarmour
parents: 1615
diff changeset
202 default:
a2f5434df2cb Merge flashv2 branch to trunk, with eCosCentric additions
jlarmour
parents: 1615
diff changeset
203 return num;
a2f5434df2cb Merge flashv2 branch to trunk, with eCosCentric additions
jlarmour
parents: 1615
diff changeset
204 } // switch
a2f5434df2cb Merge flashv2 branch to trunk, with eCosCentric additions
jlarmour
parents: 1615
diff changeset
205 (*str)++;
a2f5434df2cb Merge flashv2 branch to trunk, with eCosCentric additions
jlarmour
parents: 1615
diff changeset
206 } // while
a2f5434df2cb Merge flashv2 branch to trunk, with eCosCentric additions
jlarmour
parents: 1615
diff changeset
207
a2f5434df2cb Merge flashv2 branch to trunk, with eCosCentric additions
jlarmour
parents: 1615
diff changeset
208 return num;
a2f5434df2cb Merge flashv2 branch to trunk, with eCosCentric additions
jlarmour
parents: 1615
diff changeset
209 } // parsenum()
a2f5434df2cb Merge flashv2 branch to trunk, with eCosCentric additions
jlarmour
parents: 1615
diff changeset
210 #endif // ifdef CYGFUN_IO_FLASH_BLOCK_FROM_DEVOFFSET
a2f5434df2cb Merge flashv2 branch to trunk, with eCosCentric additions
jlarmour
parents: 1615
diff changeset
211
208
e0c0827131d1 Merge from eCos master repository on 2002-05-20-20:11:54-BST
jlarmour
parents:
diff changeset
212 static Cyg_ErrNo
2626
a2f5434df2cb Merge flashv2 branch to trunk, with eCosCentric additions
jlarmour
parents: 1615
diff changeset
213 flashiodev_lookup(struct cyg_devtab_entry **tab,
a2f5434df2cb Merge flashv2 branch to trunk, with eCosCentric additions
jlarmour
parents: 1615
diff changeset
214 struct cyg_devtab_entry *sub_tab,
a2f5434df2cb Merge flashv2 branch to trunk, with eCosCentric additions
jlarmour
parents: 1615
diff changeset
215 const char *name)
a2f5434df2cb Merge flashv2 branch to trunk, with eCosCentric additions
jlarmour
parents: 1615
diff changeset
216 {
a2f5434df2cb Merge flashv2 branch to trunk, with eCosCentric additions
jlarmour
parents: 1615
diff changeset
217 // We enter with **tab being the entry for /dev/flash only
a2f5434df2cb Merge flashv2 branch to trunk, with eCosCentric additions
jlarmour
parents: 1615
diff changeset
218 // We will leave with **tab instead pointing to a newly configured flash device instance
a2f5434df2cb Merge flashv2 branch to trunk, with eCosCentric additions
jlarmour
parents: 1615
diff changeset
219 // We could allocate the space for recording these dynamically, but that's overkill,
a2f5434df2cb Merge flashv2 branch to trunk, with eCosCentric additions
jlarmour
parents: 1615
diff changeset
220 // so we instead choose the eCos ethos of "let the user decide at configure time".
a2f5434df2cb Merge flashv2 branch to trunk, with eCosCentric additions
jlarmour
parents: 1615
diff changeset
221 // After all there's a good chance there'll be only one or two needed at one time.
a2f5434df2cb Merge flashv2 branch to trunk, with eCosCentric additions
jlarmour
parents: 1615
diff changeset
222
a2f5434df2cb Merge flashv2 branch to trunk, with eCosCentric additions
jlarmour
parents: 1615
diff changeset
223 // There are two styles of path:
a2f5434df2cb Merge flashv2 branch to trunk, with eCosCentric additions
jlarmour
parents: 1615
diff changeset
224 // /dev/flash/fis/<fispartitionname>
a2f5434df2cb Merge flashv2 branch to trunk, with eCosCentric additions
jlarmour
parents: 1615
diff changeset
225 // and
a2f5434df2cb Merge flashv2 branch to trunk, with eCosCentric additions
jlarmour
parents: 1615
diff changeset
226 // /dev/flash/<deviceno>/<offset>[,<length>]
a2f5434df2cb Merge flashv2 branch to trunk, with eCosCentric additions
jlarmour
parents: 1615
diff changeset
227
a2f5434df2cb Merge flashv2 branch to trunk, with eCosCentric additions
jlarmour
parents: 1615
diff changeset
228 cyg_flashaddr_t start=0;
a2f5434df2cb Merge flashv2 branch to trunk, with eCosCentric additions
jlarmour
parents: 1615
diff changeset
229 cyg_flashaddr_t end=0;
a2f5434df2cb Merge flashv2 branch to trunk, with eCosCentric additions
jlarmour
parents: 1615
diff changeset
230 cyg_bool valid = false;
a2f5434df2cb Merge flashv2 branch to trunk, with eCosCentric additions
jlarmour
parents: 1615
diff changeset
231
a2f5434df2cb Merge flashv2 branch to trunk, with eCosCentric additions
jlarmour
parents: 1615
diff changeset
232 #ifdef CYGFUN_IO_FLASH_BLOCK_FROM_FIS
a2f5434df2cb Merge flashv2 branch to trunk, with eCosCentric additions
jlarmour
parents: 1615
diff changeset
233 // First, support FIS
a2f5434df2cb Merge flashv2 branch to trunk, with eCosCentric additions
jlarmour
parents: 1615
diff changeset
234 if ((name[0] == 'f') && (name[1] == 'i') &&
a2f5434df2cb Merge flashv2 branch to trunk, with eCosCentric additions
jlarmour
parents: 1615
diff changeset
235 (name[2] == 's') && (name[3] == '/'))
a2f5434df2cb Merge flashv2 branch to trunk, with eCosCentric additions
jlarmour
parents: 1615
diff changeset
236 {
a2f5434df2cb Merge flashv2 branch to trunk, with eCosCentric additions
jlarmour
parents: 1615
diff changeset
237 CYG_ADDRESS flash_base;
a2f5434df2cb Merge flashv2 branch to trunk, with eCosCentric additions
jlarmour
parents: 1615
diff changeset
238 unsigned long size;
a2f5434df2cb Merge flashv2 branch to trunk, with eCosCentric additions
jlarmour
parents: 1615
diff changeset
239
a2f5434df2cb Merge flashv2 branch to trunk, with eCosCentric additions
jlarmour
parents: 1615
diff changeset
240 if(!CYGACC_CALL_IF_FLASH_FIS_OP(CYGNUM_CALL_IF_FLASH_FIS_GET_FLASH_BASE,
a2f5434df2cb Merge flashv2 branch to trunk, with eCosCentric additions
jlarmour
parents: 1615
diff changeset
241 (char *)&name[4],
a2f5434df2cb Merge flashv2 branch to trunk, with eCosCentric additions
jlarmour
parents: 1615
diff changeset
242 &flash_base))
a2f5434df2cb Merge flashv2 branch to trunk, with eCosCentric additions
jlarmour
parents: 1615
diff changeset
243 return -ENOENT;
a2f5434df2cb Merge flashv2 branch to trunk, with eCosCentric additions
jlarmour
parents: 1615
diff changeset
244
a2f5434df2cb Merge flashv2 branch to trunk, with eCosCentric additions
jlarmour
parents: 1615
diff changeset
245 if(!CYGACC_CALL_IF_FLASH_FIS_OP(CYGNUM_CALL_IF_FLASH_FIS_GET_SIZE,
a2f5434df2cb Merge flashv2 branch to trunk, with eCosCentric additions
jlarmour
parents: 1615
diff changeset
246 (char *)&name[4],
a2f5434df2cb Merge flashv2 branch to trunk, with eCosCentric additions
jlarmour
parents: 1615
diff changeset
247 &size))
a2f5434df2cb Merge flashv2 branch to trunk, with eCosCentric additions
jlarmour
parents: 1615
diff changeset
248 return -ENODEV; // If the previous call worked, then this failing would be very wrong.
a2f5434df2cb Merge flashv2 branch to trunk, with eCosCentric additions
jlarmour
parents: 1615
diff changeset
249 start = flash_base;
a2f5434df2cb Merge flashv2 branch to trunk, with eCosCentric additions
jlarmour
parents: 1615
diff changeset
250 end = flash_base + size - 1;
a2f5434df2cb Merge flashv2 branch to trunk, with eCosCentric additions
jlarmour
parents: 1615
diff changeset
251 valid = true;
a2f5434df2cb Merge flashv2 branch to trunk, with eCosCentric additions
jlarmour
parents: 1615
diff changeset
252 } else
a2f5434df2cb Merge flashv2 branch to trunk, with eCosCentric additions
jlarmour
parents: 1615
diff changeset
253 #endif // ifdef CYGFUN_IO_FLASH_BLOCK_FROM_FIS
a2f5434df2cb Merge flashv2 branch to trunk, with eCosCentric additions
jlarmour
parents: 1615
diff changeset
254 #ifdef CYGFUN_IO_FLASH_BLOCK_FROM_DEVOFFSET
a2f5434df2cb Merge flashv2 branch to trunk, with eCosCentric additions
jlarmour
parents: 1615
diff changeset
255 // Next, support device numbers with offsets encoded in path name
a2f5434df2cb Merge flashv2 branch to trunk, with eCosCentric additions
jlarmour
parents: 1615
diff changeset
256 // Note that for now we assume < 10 flash devices. I think this is reasonable
a2f5434df2cb Merge flashv2 branch to trunk, with eCosCentric additions
jlarmour
parents: 1615
diff changeset
257 // to avoid unnecessary code. It can be changed later if needed.
a2f5434df2cb Merge flashv2 branch to trunk, with eCosCentric additions
jlarmour
parents: 1615
diff changeset
258 if ( (name[0] >= '0') && (name[0] <= '9') )
a2f5434df2cb Merge flashv2 branch to trunk, with eCosCentric additions
jlarmour
parents: 1615
diff changeset
259 {
a2f5434df2cb Merge flashv2 branch to trunk, with eCosCentric additions
jlarmour
parents: 1615
diff changeset
260 cyg_uint32 flashdevno = name[0] - '0';
a2f5434df2cb Merge flashv2 branch to trunk, with eCosCentric additions
jlarmour
parents: 1615
diff changeset
261 int res;
a2f5434df2cb Merge flashv2 branch to trunk, with eCosCentric additions
jlarmour
parents: 1615
diff changeset
262 cyg_flash_info_t info;
a2f5434df2cb Merge flashv2 branch to trunk, with eCosCentric additions
jlarmour
parents: 1615
diff changeset
263 cyg_uint32 offset;
a2f5434df2cb Merge flashv2 branch to trunk, with eCosCentric additions
jlarmour
parents: 1615
diff changeset
264 const char *tempstr;
a2f5434df2cb Merge flashv2 branch to trunk, with eCosCentric additions
jlarmour
parents: 1615
diff changeset
265
a2f5434df2cb Merge flashv2 branch to trunk, with eCosCentric additions
jlarmour
parents: 1615
diff changeset
266 if (name[1] != '/')
a2f5434df2cb Merge flashv2 branch to trunk, with eCosCentric additions
jlarmour
parents: 1615
diff changeset
267 return -ENOTSUP;
a2f5434df2cb Merge flashv2 branch to trunk, with eCosCentric additions
jlarmour
parents: 1615
diff changeset
268 res = cyg_flash_get_info( flashdevno, &info );
a2f5434df2cb Merge flashv2 branch to trunk, with eCosCentric additions
jlarmour
parents: 1615
diff changeset
269 if (CYG_FLASH_ERR_OK != res)
a2f5434df2cb Merge flashv2 branch to trunk, with eCosCentric additions
jlarmour
parents: 1615
diff changeset
270 return -ENOENT;
a2f5434df2cb Merge flashv2 branch to trunk, with eCosCentric additions
jlarmour
parents: 1615
diff changeset
271
a2f5434df2cb Merge flashv2 branch to trunk, with eCosCentric additions
jlarmour
parents: 1615
diff changeset
272 // Now modify with offset and optional length
a2f5434df2cb Merge flashv2 branch to trunk, with eCosCentric additions
jlarmour
parents: 1615
diff changeset
273 tempstr = &name[2];
a2f5434df2cb Merge flashv2 branch to trunk, with eCosCentric additions
jlarmour
parents: 1615
diff changeset
274 offset = parsenum( &tempstr );
a2f5434df2cb Merge flashv2 branch to trunk, with eCosCentric additions
jlarmour
parents: 1615
diff changeset
275
a2f5434df2cb Merge flashv2 branch to trunk, with eCosCentric additions
jlarmour
parents: 1615
diff changeset
276 start = info.start + offset;
a2f5434df2cb Merge flashv2 branch to trunk, with eCosCentric additions
jlarmour
parents: 1615
diff changeset
277 end = info.end;
a2f5434df2cb Merge flashv2 branch to trunk, with eCosCentric additions
jlarmour
parents: 1615
diff changeset
278
a2f5434df2cb Merge flashv2 branch to trunk, with eCosCentric additions
jlarmour
parents: 1615
diff changeset
279 if (*tempstr == ',') // optional length
a2f5434df2cb Merge flashv2 branch to trunk, with eCosCentric additions
jlarmour
parents: 1615
diff changeset
280 {
a2f5434df2cb Merge flashv2 branch to trunk, with eCosCentric additions
jlarmour
parents: 1615
diff changeset
281 cyg_uint32 length;
a2f5434df2cb Merge flashv2 branch to trunk, with eCosCentric additions
jlarmour
parents: 1615
diff changeset
282
a2f5434df2cb Merge flashv2 branch to trunk, with eCosCentric additions
jlarmour
parents: 1615
diff changeset
283 tempstr++;
a2f5434df2cb Merge flashv2 branch to trunk, with eCosCentric additions
jlarmour
parents: 1615
diff changeset
284 length = parsenum( &tempstr );
a2f5434df2cb Merge flashv2 branch to trunk, with eCosCentric additions
jlarmour
parents: 1615
diff changeset
285
a2f5434df2cb Merge flashv2 branch to trunk, with eCosCentric additions
jlarmour
parents: 1615
diff changeset
286 // Check we don't exceed end of device.
a2f5434df2cb Merge flashv2 branch to trunk, with eCosCentric additions
jlarmour
parents: 1615
diff changeset
287 // Note the flash end address is the last byte of addressible flash *not* the base+size
a2f5434df2cb Merge flashv2 branch to trunk, with eCosCentric additions
jlarmour
parents: 1615
diff changeset
288 if ( (start + length - 1) > end )
a2f5434df2cb Merge flashv2 branch to trunk, with eCosCentric additions
jlarmour
parents: 1615
diff changeset
289 return -EINVAL;
a2f5434df2cb Merge flashv2 branch to trunk, with eCosCentric additions
jlarmour
parents: 1615
diff changeset
290 end = start + length - 1;
a2f5434df2cb Merge flashv2 branch to trunk, with eCosCentric additions
jlarmour
parents: 1615
diff changeset
291 }
a2f5434df2cb Merge flashv2 branch to trunk, with eCosCentric additions
jlarmour
parents: 1615
diff changeset
292 valid = true;
a2f5434df2cb Merge flashv2 branch to trunk, with eCosCentric additions
jlarmour
parents: 1615
diff changeset
293 } // else if
a2f5434df2cb Merge flashv2 branch to trunk, with eCosCentric additions
jlarmour
parents: 1615
diff changeset
294 #endif
a2f5434df2cb Merge flashv2 branch to trunk, with eCosCentric additions
jlarmour
parents: 1615
diff changeset
295
a2f5434df2cb Merge flashv2 branch to trunk, with eCosCentric additions
jlarmour
parents: 1615
diff changeset
296 if (valid)
a2f5434df2cb Merge flashv2 branch to trunk, with eCosCentric additions
jlarmour
parents: 1615
diff changeset
297 {
a2f5434df2cb Merge flashv2 branch to trunk, with eCosCentric additions
jlarmour
parents: 1615
diff changeset
298 // Find a slot and use it
a2f5434df2cb Merge flashv2 branch to trunk, with eCosCentric additions
jlarmour
parents: 1615
diff changeset
299 cyg_ucount32 i;
a2f5434df2cb Merge flashv2 branch to trunk, with eCosCentric additions
jlarmour
parents: 1615
diff changeset
300
a2f5434df2cb Merge flashv2 branch to trunk, with eCosCentric additions
jlarmour
parents: 1615
diff changeset
301 cyg_drv_mutex_lock( &flashiodev_table_lock );
a2f5434df2cb Merge flashv2 branch to trunk, with eCosCentric additions
jlarmour
parents: 1615
diff changeset
302 for (i=0; i<CYGNUM_IO_FLASH_BLOCK_DEVICES; i++)
a2f5434df2cb Merge flashv2 branch to trunk, with eCosCentric additions
jlarmour
parents: 1615
diff changeset
303 {
a2f5434df2cb Merge flashv2 branch to trunk, with eCosCentric additions
jlarmour
parents: 1615
diff changeset
304 if ( !flashiodev_table[i].valid ) {
a2f5434df2cb Merge flashv2 branch to trunk, with eCosCentric additions
jlarmour
parents: 1615
diff changeset
305 flashiodev_table[i].start = start;
a2f5434df2cb Merge flashv2 branch to trunk, with eCosCentric additions
jlarmour
parents: 1615
diff changeset
306 flashiodev_table[i].end = end;
a2f5434df2cb Merge flashv2 branch to trunk, with eCosCentric additions
jlarmour
parents: 1615
diff changeset
307 flashiodev_table[i].valid = true;
a2f5434df2cb Merge flashv2 branch to trunk, with eCosCentric additions
jlarmour
parents: 1615
diff changeset
308 cyg_drv_mutex_unlock( &flashiodev_table_lock );
a2f5434df2cb Merge flashv2 branch to trunk, with eCosCentric additions
jlarmour
parents: 1615
diff changeset
309
a2f5434df2cb Merge flashv2 branch to trunk, with eCosCentric additions
jlarmour
parents: 1615
diff changeset
310 *tab = &flashiodev_table[i].handle;
a2f5434df2cb Merge flashv2 branch to trunk, with eCosCentric additions
jlarmour
parents: 1615
diff changeset
311 // Theoretically we could set up the devtab entry more fully, e.g.
a2f5434df2cb Merge flashv2 branch to trunk, with eCosCentric additions
jlarmour
parents: 1615
diff changeset
312 // the name, but I don't see the need!
a2f5434df2cb Merge flashv2 branch to trunk, with eCosCentric additions
jlarmour
parents: 1615
diff changeset
313 return ENOERR;
a2f5434df2cb Merge flashv2 branch to trunk, with eCosCentric additions
jlarmour
parents: 1615
diff changeset
314 } // if
a2f5434df2cb Merge flashv2 branch to trunk, with eCosCentric additions
jlarmour
parents: 1615
diff changeset
315 } // for
a2f5434df2cb Merge flashv2 branch to trunk, with eCosCentric additions
jlarmour
parents: 1615
diff changeset
316 cyg_drv_mutex_unlock( &flashiodev_table_lock );
a2f5434df2cb Merge flashv2 branch to trunk, with eCosCentric additions
jlarmour
parents: 1615
diff changeset
317
a2f5434df2cb Merge flashv2 branch to trunk, with eCosCentric additions
jlarmour
parents: 1615
diff changeset
318 // If we got here we must have reached the end of the table without finding a space
a2f5434df2cb Merge flashv2 branch to trunk, with eCosCentric additions
jlarmour
parents: 1615
diff changeset
319 return -ENOMEM;
a2f5434df2cb Merge flashv2 branch to trunk, with eCosCentric additions
jlarmour
parents: 1615
diff changeset
320 }
a2f5434df2cb Merge flashv2 branch to trunk, with eCosCentric additions
jlarmour
parents: 1615
diff changeset
321 // Wasn't valid, so....
a2f5434df2cb Merge flashv2 branch to trunk, with eCosCentric additions
jlarmour
parents: 1615
diff changeset
322 return -ENOENT;
208
e0c0827131d1 Merge from eCos master repository on 2002-05-20-20:11:54-BST
jlarmour
parents:
diff changeset
323 } // flashiodev_lookup()
e0c0827131d1 Merge from eCos master repository on 2002-05-20-20:11:54-BST
jlarmour
parents:
diff changeset
324
e0c0827131d1 Merge from eCos master repository on 2002-05-20-20:11:54-BST
jlarmour
parents:
diff changeset
325 static Cyg_ErrNo
e0c0827131d1 Merge from eCos master repository on 2002-05-20-20:11:54-BST
jlarmour
parents:
diff changeset
326 flashiodev_bread( cyg_io_handle_t handle, void *buf, cyg_uint32 *len,
e0c0827131d1 Merge from eCos master repository on 2002-05-20-20:11:54-BST
jlarmour
parents:
diff changeset
327 cyg_uint32 pos)
e0c0827131d1 Merge from eCos master repository on 2002-05-20-20:11:54-BST
jlarmour
parents:
diff changeset
328 {
2626
a2f5434df2cb Merge flashv2 branch to trunk, with eCosCentric additions
jlarmour
parents: 1615
diff changeset
329 struct cyg_devtab_entry *tab = (struct cyg_devtab_entry *)handle;
a2f5434df2cb Merge flashv2 branch to trunk, with eCosCentric additions
jlarmour
parents: 1615
diff changeset
330 struct flashiodev_priv_t *dev = (struct flashiodev_priv_t *)tab->priv;
791
a2dfa8bf3c57 Export RedBoot FIS functions - from Knud Woehler <knud.woehler@microplex.de>
gthomas
parents: 210
diff changeset
331
2626
a2f5434df2cb Merge flashv2 branch to trunk, with eCosCentric additions
jlarmour
parents: 1615
diff changeset
332 cyg_flashaddr_t startpos = dev->start + pos;
a2f5434df2cb Merge flashv2 branch to trunk, with eCosCentric additions
jlarmour
parents: 1615
diff changeset
333 Cyg_ErrNo err = ENOERR;
a2f5434df2cb Merge flashv2 branch to trunk, with eCosCentric additions
jlarmour
parents: 1615
diff changeset
334 int flasherr;
a2f5434df2cb Merge flashv2 branch to trunk, with eCosCentric additions
jlarmour
parents: 1615
diff changeset
335
a2f5434df2cb Merge flashv2 branch to trunk, with eCosCentric additions
jlarmour
parents: 1615
diff changeset
336 CYG_ASSERT( dev->handle.handlers == &cyg_io_flashdev_ops, "bad flash operation link" );
a2f5434df2cb Merge flashv2 branch to trunk, with eCosCentric additions
jlarmour
parents: 1615
diff changeset
337 CYG_ASSERT( ((struct flashiodev_priv_t*)(dev->handle.priv))->valid, "operation on not valid flash device instance" );
a2f5434df2cb Merge flashv2 branch to trunk, with eCosCentric additions
jlarmour
parents: 1615
diff changeset
338
208
e0c0827131d1 Merge from eCos master repository on 2002-05-20-20:11:54-BST
jlarmour
parents:
diff changeset
339 #ifdef CYGPKG_INFRA_DEBUG // don't bother checking this all the time
2626
a2f5434df2cb Merge flashv2 branch to trunk, with eCosCentric additions
jlarmour
parents: 1615
diff changeset
340 cyg_flashaddr_t endpos = startpos + *len - 1;
a2f5434df2cb Merge flashv2 branch to trunk, with eCosCentric additions
jlarmour
parents: 1615
diff changeset
341 if ( startpos < dev->start )
a2f5434df2cb Merge flashv2 branch to trunk, with eCosCentric additions
jlarmour
parents: 1615
diff changeset
342 return -EINVAL;
a2f5434df2cb Merge flashv2 branch to trunk, with eCosCentric additions
jlarmour
parents: 1615
diff changeset
343 if ( endpos > dev->end )
a2f5434df2cb Merge flashv2 branch to trunk, with eCosCentric additions
jlarmour
parents: 1615
diff changeset
344 return -EINVAL;
208
e0c0827131d1 Merge from eCos master repository on 2002-05-20-20:11:54-BST
jlarmour
parents:
diff changeset
345 #endif
2626
a2f5434df2cb Merge flashv2 branch to trunk, with eCosCentric additions
jlarmour
parents: 1615
diff changeset
346
a2f5434df2cb Merge flashv2 branch to trunk, with eCosCentric additions
jlarmour
parents: 1615
diff changeset
347 flasherr = cyg_flash_read( startpos,(void *)buf, *len, NULL );
a2f5434df2cb Merge flashv2 branch to trunk, with eCosCentric additions
jlarmour
parents: 1615
diff changeset
348
a2f5434df2cb Merge flashv2 branch to trunk, with eCosCentric additions
jlarmour
parents: 1615
diff changeset
349 if ( flasherr != CYG_FLASH_ERR_OK )
a2f5434df2cb Merge flashv2 branch to trunk, with eCosCentric additions
jlarmour
parents: 1615
diff changeset
350 err = -EIO; // just something sane
a2f5434df2cb Merge flashv2 branch to trunk, with eCosCentric additions
jlarmour
parents: 1615
diff changeset
351 return err;
208
e0c0827131d1 Merge from eCos master repository on 2002-05-20-20:11:54-BST
jlarmour
parents:
diff changeset
352 } // flashiodev_bread()
e0c0827131d1 Merge from eCos master repository on 2002-05-20-20:11:54-BST
jlarmour
parents:
diff changeset
353
e0c0827131d1 Merge from eCos master repository on 2002-05-20-20:11:54-BST
jlarmour
parents:
diff changeset
354 static Cyg_ErrNo
e0c0827131d1 Merge from eCos master repository on 2002-05-20-20:11:54-BST
jlarmour
parents:
diff changeset
355 flashiodev_bwrite( cyg_io_handle_t handle, const void *buf, cyg_uint32 *len,
e0c0827131d1 Merge from eCos master repository on 2002-05-20-20:11:54-BST
jlarmour
parents:
diff changeset
356 cyg_uint32 pos )
2626
a2f5434df2cb Merge flashv2 branch to trunk, with eCosCentric additions
jlarmour
parents: 1615
diff changeset
357 {
a2f5434df2cb Merge flashv2 branch to trunk, with eCosCentric additions
jlarmour
parents: 1615
diff changeset
358 struct cyg_devtab_entry *tab = (struct cyg_devtab_entry *)handle;
a2f5434df2cb Merge flashv2 branch to trunk, with eCosCentric additions
jlarmour
parents: 1615
diff changeset
359 struct flashiodev_priv_t *dev = (struct flashiodev_priv_t *)tab->priv;
a2f5434df2cb Merge flashv2 branch to trunk, with eCosCentric additions
jlarmour
parents: 1615
diff changeset
360
a2f5434df2cb Merge flashv2 branch to trunk, with eCosCentric additions
jlarmour
parents: 1615
diff changeset
361 Cyg_ErrNo err = ENOERR;
a2f5434df2cb Merge flashv2 branch to trunk, with eCosCentric additions
jlarmour
parents: 1615
diff changeset
362 int flasherr;
a2f5434df2cb Merge flashv2 branch to trunk, with eCosCentric additions
jlarmour
parents: 1615
diff changeset
363 cyg_flashaddr_t startpos = dev->start + pos;
a2f5434df2cb Merge flashv2 branch to trunk, with eCosCentric additions
jlarmour
parents: 1615
diff changeset
364
a2f5434df2cb Merge flashv2 branch to trunk, with eCosCentric additions
jlarmour
parents: 1615
diff changeset
365 CYG_ASSERT( dev->handle.handlers == &cyg_io_flashdev_ops, "bad flash operation link" );
a2f5434df2cb Merge flashv2 branch to trunk, with eCosCentric additions
jlarmour
parents: 1615
diff changeset
366 CYG_ASSERT( ((struct flashiodev_priv_t*)(dev->handle.priv))->valid, "operation on not valid flash device instance" );
a2f5434df2cb Merge flashv2 branch to trunk, with eCosCentric additions
jlarmour
parents: 1615
diff changeset
367
a2f5434df2cb Merge flashv2 branch to trunk, with eCosCentric additions
jlarmour
parents: 1615
diff changeset
368 // Unlike some other cases we _do_ do bounds checking on this all the time, because
a2f5434df2cb Merge flashv2 branch to trunk, with eCosCentric additions
jlarmour
parents: 1615
diff changeset
369 // the consequences of writing over the wrong bit of flash are so nasty.
a2f5434df2cb Merge flashv2 branch to trunk, with eCosCentric additions
jlarmour
parents: 1615
diff changeset
370 cyg_flashaddr_t endpos = startpos + *len - 1;
a2f5434df2cb Merge flashv2 branch to trunk, with eCosCentric additions
jlarmour
parents: 1615
diff changeset
371 if ( startpos < dev->start )
a2f5434df2cb Merge flashv2 branch to trunk, with eCosCentric additions
jlarmour
parents: 1615
diff changeset
372 return -EINVAL;
a2f5434df2cb Merge flashv2 branch to trunk, with eCosCentric additions
jlarmour
parents: 1615
diff changeset
373 if ( endpos > dev->end )
a2f5434df2cb Merge flashv2 branch to trunk, with eCosCentric additions
jlarmour
parents: 1615
diff changeset
374 return -EINVAL;
208
e0c0827131d1 Merge from eCos master repository on 2002-05-20-20:11:54-BST
jlarmour
parents:
diff changeset
375
2626
a2f5434df2cb Merge flashv2 branch to trunk, with eCosCentric additions
jlarmour
parents: 1615
diff changeset
376 flasherr = cyg_flash_program( startpos, (void *)buf, *len, NULL );
a2f5434df2cb Merge flashv2 branch to trunk, with eCosCentric additions
jlarmour
parents: 1615
diff changeset
377
a2f5434df2cb Merge flashv2 branch to trunk, with eCosCentric additions
jlarmour
parents: 1615
diff changeset
378 if ( flasherr != CYG_FLASH_ERR_OK )
a2f5434df2cb Merge flashv2 branch to trunk, with eCosCentric additions
jlarmour
parents: 1615
diff changeset
379 err = -EIO; // just something sane
a2f5434df2cb Merge flashv2 branch to trunk, with eCosCentric additions
jlarmour
parents: 1615
diff changeset
380 return err;
208
e0c0827131d1 Merge from eCos master repository on 2002-05-20-20:11:54-BST
jlarmour
parents:
diff changeset
381 } // flashiodev_bwrite()
e0c0827131d1 Merge from eCos master repository on 2002-05-20-20:11:54-BST
jlarmour
parents:
diff changeset
382
e0c0827131d1 Merge from eCos master repository on 2002-05-20-20:11:54-BST
jlarmour
parents:
diff changeset
383 static Cyg_ErrNo
e0c0827131d1 Merge from eCos master repository on 2002-05-20-20:11:54-BST
jlarmour
parents:
diff changeset
384 flashiodev_get_config( cyg_io_handle_t handle,
e0c0827131d1 Merge from eCos master repository on 2002-05-20-20:11:54-BST
jlarmour
parents:
diff changeset
385 cyg_uint32 key,
e0c0827131d1 Merge from eCos master repository on 2002-05-20-20:11:54-BST
jlarmour
parents:
diff changeset
386 void* buf,
e0c0827131d1 Merge from eCos master repository on 2002-05-20-20:11:54-BST
jlarmour
parents:
diff changeset
387 cyg_uint32* len)
e0c0827131d1 Merge from eCos master repository on 2002-05-20-20:11:54-BST
jlarmour
parents:
diff changeset
388 {
2626
a2f5434df2cb Merge flashv2 branch to trunk, with eCosCentric additions
jlarmour
parents: 1615
diff changeset
389 struct cyg_devtab_entry *tab = (struct cyg_devtab_entry *)handle;
a2f5434df2cb Merge flashv2 branch to trunk, with eCosCentric additions
jlarmour
parents: 1615
diff changeset
390 struct flashiodev_priv_t *dev = (struct flashiodev_priv_t *)tab->priv;
791
a2dfa8bf3c57 Export RedBoot FIS functions - from Knud Woehler <knud.woehler@microplex.de>
gthomas
parents: 210
diff changeset
391
2626
a2f5434df2cb Merge flashv2 branch to trunk, with eCosCentric additions
jlarmour
parents: 1615
diff changeset
392 CYG_ASSERT( dev->handle.handlers == &cyg_io_flashdev_ops, "bad flash operation link" );
a2f5434df2cb Merge flashv2 branch to trunk, with eCosCentric additions
jlarmour
parents: 1615
diff changeset
393 CYG_ASSERT( ((struct flashiodev_priv_t*)(dev->handle.priv))->valid, "operation on not valid flash device instance" );
a2f5434df2cb Merge flashv2 branch to trunk, with eCosCentric additions
jlarmour
parents: 1615
diff changeset
394
a2f5434df2cb Merge flashv2 branch to trunk, with eCosCentric additions
jlarmour
parents: 1615
diff changeset
395 switch (key) {
a2f5434df2cb Merge flashv2 branch to trunk, with eCosCentric additions
jlarmour
parents: 1615
diff changeset
396 case CYG_IO_GET_CONFIG_FLASH_ERASE:
208
e0c0827131d1 Merge from eCos master repository on 2002-05-20-20:11:54-BST
jlarmour
parents:
diff changeset
397 {
e0c0827131d1 Merge from eCos master repository on 2002-05-20-20:11:54-BST
jlarmour
parents:
diff changeset
398 #ifdef CYGPKG_INFRA_DEBUG // don't bother checking this all the time
2626
a2f5434df2cb Merge flashv2 branch to trunk, with eCosCentric additions
jlarmour
parents: 1615
diff changeset
399 if (*len != sizeof( cyg_io_flash_getconfig_erase_t ) )
a2f5434df2cb Merge flashv2 branch to trunk, with eCosCentric additions
jlarmour
parents: 1615
diff changeset
400 return -EINVAL;
208
e0c0827131d1 Merge from eCos master repository on 2002-05-20-20:11:54-BST
jlarmour
parents:
diff changeset
401 #endif
2626
a2f5434df2cb Merge flashv2 branch to trunk, with eCosCentric additions
jlarmour
parents: 1615
diff changeset
402 {
a2f5434df2cb Merge flashv2 branch to trunk, with eCosCentric additions
jlarmour
parents: 1615
diff changeset
403 cyg_io_flash_getconfig_erase_t *e = (cyg_io_flash_getconfig_erase_t *)buf;
a2f5434df2cb Merge flashv2 branch to trunk, with eCosCentric additions
jlarmour
parents: 1615
diff changeset
404 cyg_flashaddr_t startpos = dev->start + e->offset;
a2f5434df2cb Merge flashv2 branch to trunk, with eCosCentric additions
jlarmour
parents: 1615
diff changeset
405
a2f5434df2cb Merge flashv2 branch to trunk, with eCosCentric additions
jlarmour
parents: 1615
diff changeset
406 // Unlike some other cases we _do_ do bounds checking on this all the time, because
a2f5434df2cb Merge flashv2 branch to trunk, with eCosCentric additions
jlarmour
parents: 1615
diff changeset
407 // the consequences of erasing the wrong bit of flash are so nasty.
a2f5434df2cb Merge flashv2 branch to trunk, with eCosCentric additions
jlarmour
parents: 1615
diff changeset
408 cyg_flashaddr_t endpos = startpos + e->len - 1;
a2f5434df2cb Merge flashv2 branch to trunk, with eCosCentric additions
jlarmour
parents: 1615
diff changeset
409 if ( startpos < dev->start )
a2f5434df2cb Merge flashv2 branch to trunk, with eCosCentric additions
jlarmour
parents: 1615
diff changeset
410 return -EINVAL;
a2f5434df2cb Merge flashv2 branch to trunk, with eCosCentric additions
jlarmour
parents: 1615
diff changeset
411 if ( endpos > dev->end )
a2f5434df2cb Merge flashv2 branch to trunk, with eCosCentric additions
jlarmour
parents: 1615
diff changeset
412 return -EINVAL;
a2f5434df2cb Merge flashv2 branch to trunk, with eCosCentric additions
jlarmour
parents: 1615
diff changeset
413
a2f5434df2cb Merge flashv2 branch to trunk, with eCosCentric additions
jlarmour
parents: 1615
diff changeset
414 e->flasherr = cyg_flash_erase( startpos, e->len, &e->err_address );
a2f5434df2cb Merge flashv2 branch to trunk, with eCosCentric additions
jlarmour
parents: 1615
diff changeset
415 }
a2f5434df2cb Merge flashv2 branch to trunk, with eCosCentric additions
jlarmour
parents: 1615
diff changeset
416 return ENOERR;
208
e0c0827131d1 Merge from eCos master repository on 2002-05-20-20:11:54-BST
jlarmour
parents:
diff changeset
417 }
2626
a2f5434df2cb Merge flashv2 branch to trunk, with eCosCentric additions
jlarmour
parents: 1615
diff changeset
418
a2f5434df2cb Merge flashv2 branch to trunk, with eCosCentric additions
jlarmour
parents: 1615
diff changeset
419 #ifdef CYGHWR_IO_FLASH_BLOCK_LOCKING
a2f5434df2cb Merge flashv2 branch to trunk, with eCosCentric additions
jlarmour
parents: 1615
diff changeset
420 case CYG_IO_GET_CONFIG_FLASH_LOCK:
208
e0c0827131d1 Merge from eCos master repository on 2002-05-20-20:11:54-BST
jlarmour
parents:
diff changeset
421 {
2626
a2f5434df2cb Merge flashv2 branch to trunk, with eCosCentric additions
jlarmour
parents: 1615
diff changeset
422 #ifdef CYGPKG_INFRA_DEBUG // don't bother checking this all the time
a2f5434df2cb Merge flashv2 branch to trunk, with eCosCentric additions
jlarmour
parents: 1615
diff changeset
423 if (*len != sizeof( cyg_io_flash_getconfig_lock_t ) )
a2f5434df2cb Merge flashv2 branch to trunk, with eCosCentric additions
jlarmour
parents: 1615
diff changeset
424 return -EINVAL;
a2f5434df2cb Merge flashv2 branch to trunk, with eCosCentric additions
jlarmour
parents: 1615
diff changeset
425 #endif
a2f5434df2cb Merge flashv2 branch to trunk, with eCosCentric additions
jlarmour
parents: 1615
diff changeset
426 {
a2f5434df2cb Merge flashv2 branch to trunk, with eCosCentric additions
jlarmour
parents: 1615
diff changeset
427 cyg_io_flash_getconfig_lock_t *d = (cyg_io_flash_getconfig_lock_t *)buf;
a2f5434df2cb Merge flashv2 branch to trunk, with eCosCentric additions
jlarmour
parents: 1615
diff changeset
428 cyg_flashaddr_t startpos = dev->start + d->offset;
208
e0c0827131d1 Merge from eCos master repository on 2002-05-20-20:11:54-BST
jlarmour
parents:
diff changeset
429
2626
a2f5434df2cb Merge flashv2 branch to trunk, with eCosCentric additions
jlarmour
parents: 1615
diff changeset
430 #ifdef CYGPKG_INFRA_DEBUG // don't bother checking this all the time
a2f5434df2cb Merge flashv2 branch to trunk, with eCosCentric additions
jlarmour
parents: 1615
diff changeset
431 cyg_flashaddr_t endpos = startpos + d->len - 1;
a2f5434df2cb Merge flashv2 branch to trunk, with eCosCentric additions
jlarmour
parents: 1615
diff changeset
432 if ( startpos < dev->start )
a2f5434df2cb Merge flashv2 branch to trunk, with eCosCentric additions
jlarmour
parents: 1615
diff changeset
433 return -EINVAL;
a2f5434df2cb Merge flashv2 branch to trunk, with eCosCentric additions
jlarmour
parents: 1615
diff changeset
434 if ( endpos > dev->end )
a2f5434df2cb Merge flashv2 branch to trunk, with eCosCentric additions
jlarmour
parents: 1615
diff changeset
435 return -EINVAL;
a2f5434df2cb Merge flashv2 branch to trunk, with eCosCentric additions
jlarmour
parents: 1615
diff changeset
436 #endif
a2f5434df2cb Merge flashv2 branch to trunk, with eCosCentric additions
jlarmour
parents: 1615
diff changeset
437
a2f5434df2cb Merge flashv2 branch to trunk, with eCosCentric additions
jlarmour
parents: 1615
diff changeset
438 d->flasherr = cyg_flash_lock( startpos, d->len, &d->err_address );
a2f5434df2cb Merge flashv2 branch to trunk, with eCosCentric additions
jlarmour
parents: 1615
diff changeset
439 }
a2f5434df2cb Merge flashv2 branch to trunk, with eCosCentric additions
jlarmour
parents: 1615
diff changeset
440 return ENOERR;
208
e0c0827131d1 Merge from eCos master repository on 2002-05-20-20:11:54-BST
jlarmour
parents:
diff changeset
441 }
e0c0827131d1 Merge from eCos master repository on 2002-05-20-20:11:54-BST
jlarmour
parents:
diff changeset
442
2626
a2f5434df2cb Merge flashv2 branch to trunk, with eCosCentric additions
jlarmour
parents: 1615
diff changeset
443 case CYG_IO_GET_CONFIG_FLASH_UNLOCK:
208
e0c0827131d1 Merge from eCos master repository on 2002-05-20-20:11:54-BST
jlarmour
parents:
diff changeset
444 {
e0c0827131d1 Merge from eCos master repository on 2002-05-20-20:11:54-BST
jlarmour
parents:
diff changeset
445 #ifdef CYGPKG_INFRA_DEBUG // don't bother checking this all the time
2626
a2f5434df2cb Merge flashv2 branch to trunk, with eCosCentric additions
jlarmour
parents: 1615
diff changeset
446 if (*len != sizeof( cyg_io_flash_getconfig_unlock_t ) )
a2f5434df2cb Merge flashv2 branch to trunk, with eCosCentric additions
jlarmour
parents: 1615
diff changeset
447 return -EINVAL;
a2f5434df2cb Merge flashv2 branch to trunk, with eCosCentric additions
jlarmour
parents: 1615
diff changeset
448 #endif
a2f5434df2cb Merge flashv2 branch to trunk, with eCosCentric additions
jlarmour
parents: 1615
diff changeset
449 {
a2f5434df2cb Merge flashv2 branch to trunk, with eCosCentric additions
jlarmour
parents: 1615
diff changeset
450 cyg_io_flash_getconfig_unlock_t *d = (cyg_io_flash_getconfig_unlock_t *)buf;
a2f5434df2cb Merge flashv2 branch to trunk, with eCosCentric additions
jlarmour
parents: 1615
diff changeset
451 cyg_flashaddr_t startpos = dev->start + d->offset;
791
a2dfa8bf3c57 Export RedBoot FIS functions - from Knud Woehler <knud.woehler@microplex.de>
gthomas
parents: 210
diff changeset
452
2626
a2f5434df2cb Merge flashv2 branch to trunk, with eCosCentric additions
jlarmour
parents: 1615
diff changeset
453 #ifdef CYGPKG_INFRA_DEBUG // don't bother checking this all the time
a2f5434df2cb Merge flashv2 branch to trunk, with eCosCentric additions
jlarmour
parents: 1615
diff changeset
454 cyg_flashaddr_t endpos = startpos + d->len - 1;
791
a2dfa8bf3c57 Export RedBoot FIS functions - from Knud Woehler <knud.woehler@microplex.de>
gthomas
parents: 210
diff changeset
455 if ( startpos < dev->start )
2626
a2f5434df2cb Merge flashv2 branch to trunk, with eCosCentric additions
jlarmour
parents: 1615
diff changeset
456 return -EINVAL;
a2f5434df2cb Merge flashv2 branch to trunk, with eCosCentric additions
jlarmour
parents: 1615
diff changeset
457 if ( endpos > dev->end )
a2f5434df2cb Merge flashv2 branch to trunk, with eCosCentric additions
jlarmour
parents: 1615
diff changeset
458 return -EINVAL;
a2f5434df2cb Merge flashv2 branch to trunk, with eCosCentric additions
jlarmour
parents: 1615
diff changeset
459 #endif
a2f5434df2cb Merge flashv2 branch to trunk, with eCosCentric additions
jlarmour
parents: 1615
diff changeset
460 d->flasherr = cyg_flash_unlock( startpos, d->len, &d->err_address );
a2f5434df2cb Merge flashv2 branch to trunk, with eCosCentric additions
jlarmour
parents: 1615
diff changeset
461 }
a2f5434df2cb Merge flashv2 branch to trunk, with eCosCentric additions
jlarmour
parents: 1615
diff changeset
462 return ENOERR;
a2f5434df2cb Merge flashv2 branch to trunk, with eCosCentric additions
jlarmour
parents: 1615
diff changeset
463 }
a2f5434df2cb Merge flashv2 branch to trunk, with eCosCentric additions
jlarmour
parents: 1615
diff changeset
464 #endif
a2f5434df2cb Merge flashv2 branch to trunk, with eCosCentric additions
jlarmour
parents: 1615
diff changeset
465
a2f5434df2cb Merge flashv2 branch to trunk, with eCosCentric additions
jlarmour
parents: 1615
diff changeset
466 case CYG_IO_GET_CONFIG_FLASH_DEVSIZE:
a2f5434df2cb Merge flashv2 branch to trunk, with eCosCentric additions
jlarmour
parents: 1615
diff changeset
467 {
a2f5434df2cb Merge flashv2 branch to trunk, with eCosCentric additions
jlarmour
parents: 1615
diff changeset
468 #ifdef CYGPKG_INFRA_DEBUG // don't bother checking this all the time
a2f5434df2cb Merge flashv2 branch to trunk, with eCosCentric additions
jlarmour
parents: 1615
diff changeset
469 if ( *len != sizeof( cyg_io_flash_getconfig_devsize_t ) )
a2f5434df2cb Merge flashv2 branch to trunk, with eCosCentric additions
jlarmour
parents: 1615
diff changeset
470 return -EINVAL;
a2f5434df2cb Merge flashv2 branch to trunk, with eCosCentric additions
jlarmour
parents: 1615
diff changeset
471 #endif
a2f5434df2cb Merge flashv2 branch to trunk, with eCosCentric additions
jlarmour
parents: 1615
diff changeset
472 {
a2f5434df2cb Merge flashv2 branch to trunk, with eCosCentric additions
jlarmour
parents: 1615
diff changeset
473 cyg_io_flash_getconfig_devsize_t *d =
a2f5434df2cb Merge flashv2 branch to trunk, with eCosCentric additions
jlarmour
parents: 1615
diff changeset
474 (cyg_io_flash_getconfig_devsize_t *)buf;
a2f5434df2cb Merge flashv2 branch to trunk, with eCosCentric additions
jlarmour
parents: 1615
diff changeset
475
a2f5434df2cb Merge flashv2 branch to trunk, with eCosCentric additions
jlarmour
parents: 1615
diff changeset
476 d->dev_size = dev->end - dev->start + 1;
a2f5434df2cb Merge flashv2 branch to trunk, with eCosCentric additions
jlarmour
parents: 1615
diff changeset
477 }
a2f5434df2cb Merge flashv2 branch to trunk, with eCosCentric additions
jlarmour
parents: 1615
diff changeset
478 return ENOERR;
208
e0c0827131d1 Merge from eCos master repository on 2002-05-20-20:11:54-BST
jlarmour
parents:
diff changeset
479 }
e0c0827131d1 Merge from eCos master repository on 2002-05-20-20:11:54-BST
jlarmour
parents:
diff changeset
480
2626
a2f5434df2cb Merge flashv2 branch to trunk, with eCosCentric additions
jlarmour
parents: 1615
diff changeset
481 case CYG_IO_GET_CONFIG_FLASH_DEVADDR:
a2f5434df2cb Merge flashv2 branch to trunk, with eCosCentric additions
jlarmour
parents: 1615
diff changeset
482 {
a2f5434df2cb Merge flashv2 branch to trunk, with eCosCentric additions
jlarmour
parents: 1615
diff changeset
483 #ifdef CYGPKG_INFRA_DEBUG // don't bother checking this all the time
a2f5434df2cb Merge flashv2 branch to trunk, with eCosCentric additions
jlarmour
parents: 1615
diff changeset
484 if ( *len != sizeof( cyg_io_flash_getconfig_devaddr_t ) )
208
e0c0827131d1 Merge from eCos master repository on 2002-05-20-20:11:54-BST
jlarmour
parents:
diff changeset
485 return -EINVAL;
2626
a2f5434df2cb Merge flashv2 branch to trunk, with eCosCentric additions
jlarmour
parents: 1615
diff changeset
486 #endif
a2f5434df2cb Merge flashv2 branch to trunk, with eCosCentric additions
jlarmour
parents: 1615
diff changeset
487 {
a2f5434df2cb Merge flashv2 branch to trunk, with eCosCentric additions
jlarmour
parents: 1615
diff changeset
488 cyg_io_flash_getconfig_devaddr_t *d =
a2f5434df2cb Merge flashv2 branch to trunk, with eCosCentric additions
jlarmour
parents: 1615
diff changeset
489 (cyg_io_flash_getconfig_devaddr_t *)buf;
a2f5434df2cb Merge flashv2 branch to trunk, with eCosCentric additions
jlarmour
parents: 1615
diff changeset
490
a2f5434df2cb Merge flashv2 branch to trunk, with eCosCentric additions
jlarmour
parents: 1615
diff changeset
491 d->dev_addr = dev->start;
a2f5434df2cb Merge flashv2 branch to trunk, with eCosCentric additions
jlarmour
parents: 1615
diff changeset
492 }
a2f5434df2cb Merge flashv2 branch to trunk, with eCosCentric additions
jlarmour
parents: 1615
diff changeset
493 return ENOERR;
208
e0c0827131d1 Merge from eCos master repository on 2002-05-20-20:11:54-BST
jlarmour
parents:
diff changeset
494 }
2626
a2f5434df2cb Merge flashv2 branch to trunk, with eCosCentric additions
jlarmour
parents: 1615
diff changeset
495
a2f5434df2cb Merge flashv2 branch to trunk, with eCosCentric additions
jlarmour
parents: 1615
diff changeset
496 case CYG_IO_GET_CONFIG_FLASH_BLOCKSIZE:
a2f5434df2cb Merge flashv2 branch to trunk, with eCosCentric additions
jlarmour
parents: 1615
diff changeset
497 {
a2f5434df2cb Merge flashv2 branch to trunk, with eCosCentric additions
jlarmour
parents: 1615
diff changeset
498 cyg_io_flash_getconfig_blocksize_t *b =
a2f5434df2cb Merge flashv2 branch to trunk, with eCosCentric additions
jlarmour
parents: 1615
diff changeset
499 (cyg_io_flash_getconfig_blocksize_t *)buf;
a2f5434df2cb Merge flashv2 branch to trunk, with eCosCentric additions
jlarmour
parents: 1615
diff changeset
500 cyg_flashaddr_t pos = dev->start + b->offset;
a2f5434df2cb Merge flashv2 branch to trunk, with eCosCentric additions
jlarmour
parents: 1615
diff changeset
501
a2f5434df2cb Merge flashv2 branch to trunk, with eCosCentric additions
jlarmour
parents: 1615
diff changeset
502 #ifdef CYGPKG_INFRA_DEBUG // don't bother checking this all the time
a2f5434df2cb Merge flashv2 branch to trunk, with eCosCentric additions
jlarmour
parents: 1615
diff changeset
503 if ( pos < dev->start )
a2f5434df2cb Merge flashv2 branch to trunk, with eCosCentric additions
jlarmour
parents: 1615
diff changeset
504 return -EINVAL;
a2f5434df2cb Merge flashv2 branch to trunk, with eCosCentric additions
jlarmour
parents: 1615
diff changeset
505 if ( pos > dev->end )
a2f5434df2cb Merge flashv2 branch to trunk, with eCosCentric additions
jlarmour
parents: 1615
diff changeset
506 return -EINVAL;
a2f5434df2cb Merge flashv2 branch to trunk, with eCosCentric additions
jlarmour
parents: 1615
diff changeset
507 if ( *len != sizeof( cyg_io_flash_getconfig_blocksize_t ) )
a2f5434df2cb Merge flashv2 branch to trunk, with eCosCentric additions
jlarmour
parents: 1615
diff changeset
508 return -EINVAL;
a2f5434df2cb Merge flashv2 branch to trunk, with eCosCentric additions
jlarmour
parents: 1615
diff changeset
509 #endif
a2f5434df2cb Merge flashv2 branch to trunk, with eCosCentric additions
jlarmour
parents: 1615
diff changeset
510
a2f5434df2cb Merge flashv2 branch to trunk, with eCosCentric additions
jlarmour
parents: 1615
diff changeset
511 b->block_size = cyg_flash_block_size( pos );
a2f5434df2cb Merge flashv2 branch to trunk, with eCosCentric additions
jlarmour
parents: 1615
diff changeset
512 return ENOERR;
a2f5434df2cb Merge flashv2 branch to trunk, with eCosCentric additions
jlarmour
parents: 1615
diff changeset
513 }
a2f5434df2cb Merge flashv2 branch to trunk, with eCosCentric additions
jlarmour
parents: 1615
diff changeset
514
a2f5434df2cb Merge flashv2 branch to trunk, with eCosCentric additions
jlarmour
parents: 1615
diff changeset
515 default:
a2f5434df2cb Merge flashv2 branch to trunk, with eCosCentric additions
jlarmour
parents: 1615
diff changeset
516 return -EINVAL;
a2f5434df2cb Merge flashv2 branch to trunk, with eCosCentric additions
jlarmour
parents: 1615
diff changeset
517 }
208
e0c0827131d1 Merge from eCos master repository on 2002-05-20-20:11:54-BST
jlarmour
parents:
diff changeset
518 } // flashiodev_get_config()
e0c0827131d1 Merge from eCos master repository on 2002-05-20-20:11:54-BST
jlarmour
parents:
diff changeset
519
e0c0827131d1 Merge from eCos master repository on 2002-05-20-20:11:54-BST
jlarmour
parents:
diff changeset
520 static Cyg_ErrNo
e0c0827131d1 Merge from eCos master repository on 2002-05-20-20:11:54-BST
jlarmour
parents:
diff changeset
521 flashiodev_set_config( cyg_io_handle_t handle,
e0c0827131d1 Merge from eCos master repository on 2002-05-20-20:11:54-BST
jlarmour
parents:
diff changeset
522 cyg_uint32 key,
e0c0827131d1 Merge from eCos master repository on 2002-05-20-20:11:54-BST
jlarmour
parents:
diff changeset
523 const void* buf,
e0c0827131d1 Merge from eCos master repository on 2002-05-20-20:11:54-BST
jlarmour
parents:
diff changeset
524 cyg_uint32* len)
e0c0827131d1 Merge from eCos master repository on 2002-05-20-20:11:54-BST
jlarmour
parents:
diff changeset
525 {
2626
a2f5434df2cb Merge flashv2 branch to trunk, with eCosCentric additions
jlarmour
parents: 1615
diff changeset
526 struct cyg_devtab_entry *tab = (struct cyg_devtab_entry *)handle;
a2f5434df2cb Merge flashv2 branch to trunk, with eCosCentric additions
jlarmour
parents: 1615
diff changeset
527 struct flashiodev_priv_t *dev = (struct flashiodev_priv_t *)tab->priv;
a2f5434df2cb Merge flashv2 branch to trunk, with eCosCentric additions
jlarmour
parents: 1615
diff changeset
528
a2f5434df2cb Merge flashv2 branch to trunk, with eCosCentric additions
jlarmour
parents: 1615
diff changeset
529 CYG_ASSERT( dev->handle.handlers == &cyg_io_flashdev_ops, "bad flash operation link" );
a2f5434df2cb Merge flashv2 branch to trunk, with eCosCentric additions
jlarmour
parents: 1615
diff changeset
530 CYG_ASSERT( ((struct flashiodev_priv_t*)(dev->handle.priv))->valid, "operation on not valid flash device instance" );
a2f5434df2cb Merge flashv2 branch to trunk, with eCosCentric additions
jlarmour
parents: 1615
diff changeset
531
a2f5434df2cb Merge flashv2 branch to trunk, with eCosCentric additions
jlarmour
parents: 1615
diff changeset
532 switch (key) {
a2f5434df2cb Merge flashv2 branch to trunk, with eCosCentric additions
jlarmour
parents: 1615
diff changeset
533 case CYG_IO_SET_CONFIG_CLOSE:
1411
5e52f3febc7d Specify flash block device names at runtime - from David Woodhouse
gthomas
parents: 1391
diff changeset
534 {
2626
a2f5434df2cb Merge flashv2 branch to trunk, with eCosCentric additions
jlarmour
parents: 1615
diff changeset
535 Cyg_ErrNo err = ENOERR;
a2f5434df2cb Merge flashv2 branch to trunk, with eCosCentric additions
jlarmour
parents: 1615
diff changeset
536 cyg_drv_mutex_lock( &flashiodev_table_lock );
a2f5434df2cb Merge flashv2 branch to trunk, with eCosCentric additions
jlarmour
parents: 1615
diff changeset
537 if (!dev->valid)
a2f5434df2cb Merge flashv2 branch to trunk, with eCosCentric additions
jlarmour
parents: 1615
diff changeset
538 {
a2f5434df2cb Merge flashv2 branch to trunk, with eCosCentric additions
jlarmour
parents: 1615
diff changeset
539 err = -EBADF;
a2f5434df2cb Merge flashv2 branch to trunk, with eCosCentric additions
jlarmour
parents: 1615
diff changeset
540 } else {
a2f5434df2cb Merge flashv2 branch to trunk, with eCosCentric additions
jlarmour
parents: 1615
diff changeset
541 dev->valid = false;
a2f5434df2cb Merge flashv2 branch to trunk, with eCosCentric additions
jlarmour
parents: 1615
diff changeset
542 }
a2f5434df2cb Merge flashv2 branch to trunk, with eCosCentric additions
jlarmour
parents: 1615
diff changeset
543 cyg_drv_mutex_unlock( &flashiodev_table_lock );
a2f5434df2cb Merge flashv2 branch to trunk, with eCosCentric additions
jlarmour
parents: 1615
diff changeset
544 return err;
1411
5e52f3febc7d Specify flash block device names at runtime - from David Woodhouse
gthomas
parents: 1391
diff changeset
545 }
2626
a2f5434df2cb Merge flashv2 branch to trunk, with eCosCentric additions
jlarmour
parents: 1615
diff changeset
546 default:
a2f5434df2cb Merge flashv2 branch to trunk, with eCosCentric additions
jlarmour
parents: 1615
diff changeset
547 return -EINVAL;
a2f5434df2cb Merge flashv2 branch to trunk, with eCosCentric additions
jlarmour
parents: 1615
diff changeset
548 }
208
e0c0827131d1 Merge from eCos master repository on 2002-05-20-20:11:54-BST
jlarmour
parents:
diff changeset
549 } // flashiodev_set_config()
e0c0827131d1 Merge from eCos master repository on 2002-05-20-20:11:54-BST
jlarmour
parents:
diff changeset
550
e0c0827131d1 Merge from eCos master repository on 2002-05-20-20:11:54-BST
jlarmour
parents:
diff changeset
551 // EOF flashiodev.c