Mercurial > ecos
annotate packages/devs/flash/synthv2/current/src/synth.c @ 2696:b1cdd12003cd
* src/synth.c: Fixed error check of mmap call.
| author | asl |
|---|---|
| date | Mon, 22 Dec 2008 20:05:02 +0000 |
| parents | 5ba0b3e7a0cb |
| children | 99efb5fe625e |
| rev | line source |
|---|---|
|
2629
50cf5ea58609
Merge flashv2 branch to trunk, with eCosCentric additions
jlarmour
parents:
diff
changeset
|
1 //========================================================================== |
|
50cf5ea58609
Merge flashv2 branch to trunk, with eCosCentric additions
jlarmour
parents:
diff
changeset
|
2 // |
|
50cf5ea58609
Merge flashv2 branch to trunk, with eCosCentric additions
jlarmour
parents:
diff
changeset
|
3 // synth.c |
|
50cf5ea58609
Merge flashv2 branch to trunk, with eCosCentric additions
jlarmour
parents:
diff
changeset
|
4 // |
|
50cf5ea58609
Merge flashv2 branch to trunk, with eCosCentric additions
jlarmour
parents:
diff
changeset
|
5 // Flash programming |
|
50cf5ea58609
Merge flashv2 branch to trunk, with eCosCentric additions
jlarmour
parents:
diff
changeset
|
6 // |
|
50cf5ea58609
Merge flashv2 branch to trunk, with eCosCentric additions
jlarmour
parents:
diff
changeset
|
7 //========================================================================== |
|
50cf5ea58609
Merge flashv2 branch to trunk, with eCosCentric additions
jlarmour
parents:
diff
changeset
|
8 //####ECOSGPLCOPYRIGHTBEGIN#### |
|
50cf5ea58609
Merge flashv2 branch to trunk, with eCosCentric additions
jlarmour
parents:
diff
changeset
|
9 // ------------------------------------------- |
|
50cf5ea58609
Merge flashv2 branch to trunk, with eCosCentric additions
jlarmour
parents:
diff
changeset
|
10 // This file is part of eCos, the Embedded Configurable Operating System. |
|
50cf5ea58609
Merge flashv2 branch to trunk, with eCosCentric additions
jlarmour
parents:
diff
changeset
|
11 // Copyright (C) 1998, 1999, 2000, 2001, 2002 Red Hat, Inc. |
|
50cf5ea58609
Merge flashv2 branch to trunk, with eCosCentric additions
jlarmour
parents:
diff
changeset
|
12 // |
|
50cf5ea58609
Merge flashv2 branch to trunk, with eCosCentric additions
jlarmour
parents:
diff
changeset
|
13 // eCos is free software; you can redistribute it and/or modify it under |
|
50cf5ea58609
Merge flashv2 branch to trunk, with eCosCentric additions
jlarmour
parents:
diff
changeset
|
14 // the terms of the GNU General Public License as published by the Free |
|
50cf5ea58609
Merge flashv2 branch to trunk, with eCosCentric additions
jlarmour
parents:
diff
changeset
|
15 // Software Foundation; either version 2 or (at your option) any later version. |
|
50cf5ea58609
Merge flashv2 branch to trunk, with eCosCentric additions
jlarmour
parents:
diff
changeset
|
16 // |
|
50cf5ea58609
Merge flashv2 branch to trunk, with eCosCentric additions
jlarmour
parents:
diff
changeset
|
17 // eCos is distributed in the hope that it will be useful, but WITHOUT ANY |
|
50cf5ea58609
Merge flashv2 branch to trunk, with eCosCentric additions
jlarmour
parents:
diff
changeset
|
18 // WARRANTY; without even the implied warranty of MERCHANTABILITY or |
|
50cf5ea58609
Merge flashv2 branch to trunk, with eCosCentric additions
jlarmour
parents:
diff
changeset
|
19 // FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License |
|
50cf5ea58609
Merge flashv2 branch to trunk, with eCosCentric additions
jlarmour
parents:
diff
changeset
|
20 // for more details. |
|
50cf5ea58609
Merge flashv2 branch to trunk, with eCosCentric additions
jlarmour
parents:
diff
changeset
|
21 // |
|
50cf5ea58609
Merge flashv2 branch to trunk, with eCosCentric additions
jlarmour
parents:
diff
changeset
|
22 // You should have received a copy of the GNU General Public License along |
|
50cf5ea58609
Merge flashv2 branch to trunk, with eCosCentric additions
jlarmour
parents:
diff
changeset
|
23 // with eCos; if not, write to the Free Software Foundation, Inc., |
|
50cf5ea58609
Merge flashv2 branch to trunk, with eCosCentric additions
jlarmour
parents:
diff
changeset
|
24 // 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA. |
|
50cf5ea58609
Merge flashv2 branch to trunk, with eCosCentric additions
jlarmour
parents:
diff
changeset
|
25 // |
|
50cf5ea58609
Merge flashv2 branch to trunk, with eCosCentric additions
jlarmour
parents:
diff
changeset
|
26 // As a special exception, if other files instantiate templates or use macros |
|
50cf5ea58609
Merge flashv2 branch to trunk, with eCosCentric additions
jlarmour
parents:
diff
changeset
|
27 // or inline functions from this file, or you compile this file and link it |
|
50cf5ea58609
Merge flashv2 branch to trunk, with eCosCentric additions
jlarmour
parents:
diff
changeset
|
28 // with other works to produce a work based on this file, this file does not |
|
50cf5ea58609
Merge flashv2 branch to trunk, with eCosCentric additions
jlarmour
parents:
diff
changeset
|
29 // by itself cause the resulting work to be covered by the GNU General Public |
|
50cf5ea58609
Merge flashv2 branch to trunk, with eCosCentric additions
jlarmour
parents:
diff
changeset
|
30 // License. However the source code for this file must still be made available |
|
50cf5ea58609
Merge flashv2 branch to trunk, with eCosCentric additions
jlarmour
parents:
diff
changeset
|
31 // in accordance with section (3) of the GNU General Public License. |
|
50cf5ea58609
Merge flashv2 branch to trunk, with eCosCentric additions
jlarmour
parents:
diff
changeset
|
32 // |
|
50cf5ea58609
Merge flashv2 branch to trunk, with eCosCentric additions
jlarmour
parents:
diff
changeset
|
33 // This exception does not invalidate any other reasons why a work based on |
|
50cf5ea58609
Merge flashv2 branch to trunk, with eCosCentric additions
jlarmour
parents:
diff
changeset
|
34 // this file might be covered by the GNU General Public License. |
|
50cf5ea58609
Merge flashv2 branch to trunk, with eCosCentric additions
jlarmour
parents:
diff
changeset
|
35 // |
|
50cf5ea58609
Merge flashv2 branch to trunk, with eCosCentric additions
jlarmour
parents:
diff
changeset
|
36 // Alternative licenses for eCos may be arranged by contacting Red Hat, Inc. |
|
50cf5ea58609
Merge flashv2 branch to trunk, with eCosCentric additions
jlarmour
parents:
diff
changeset
|
37 // at http://sources.redhat.com/ecos/ecos-license/ |
|
50cf5ea58609
Merge flashv2 branch to trunk, with eCosCentric additions
jlarmour
parents:
diff
changeset
|
38 // ------------------------------------------- |
|
50cf5ea58609
Merge flashv2 branch to trunk, with eCosCentric additions
jlarmour
parents:
diff
changeset
|
39 //####ECOSGPLCOPYRIGHTEND#### |
|
50cf5ea58609
Merge flashv2 branch to trunk, with eCosCentric additions
jlarmour
parents:
diff
changeset
|
40 //========================================================================== |
|
50cf5ea58609
Merge flashv2 branch to trunk, with eCosCentric additions
jlarmour
parents:
diff
changeset
|
41 //#####DESCRIPTIONBEGIN#### |
|
50cf5ea58609
Merge flashv2 branch to trunk, with eCosCentric additions
jlarmour
parents:
diff
changeset
|
42 // |
|
50cf5ea58609
Merge flashv2 branch to trunk, with eCosCentric additions
jlarmour
parents:
diff
changeset
|
43 // Author(s): andrew.lunn@ascom.ch |
|
50cf5ea58609
Merge flashv2 branch to trunk, with eCosCentric additions
jlarmour
parents:
diff
changeset
|
44 // Contributors: jlarmour |
|
50cf5ea58609
Merge flashv2 branch to trunk, with eCosCentric additions
jlarmour
parents:
diff
changeset
|
45 // Date: 2001-10-30 |
|
50cf5ea58609
Merge flashv2 branch to trunk, with eCosCentric additions
jlarmour
parents:
diff
changeset
|
46 // Purpose: |
|
50cf5ea58609
Merge flashv2 branch to trunk, with eCosCentric additions
jlarmour
parents:
diff
changeset
|
47 // Description: |
|
50cf5ea58609
Merge flashv2 branch to trunk, with eCosCentric additions
jlarmour
parents:
diff
changeset
|
48 // |
|
50cf5ea58609
Merge flashv2 branch to trunk, with eCosCentric additions
jlarmour
parents:
diff
changeset
|
49 //####DESCRIPTIONEND#### |
|
50cf5ea58609
Merge flashv2 branch to trunk, with eCosCentric additions
jlarmour
parents:
diff
changeset
|
50 // |
|
50cf5ea58609
Merge flashv2 branch to trunk, with eCosCentric additions
jlarmour
parents:
diff
changeset
|
51 //========================================================================== |
|
50cf5ea58609
Merge flashv2 branch to trunk, with eCosCentric additions
jlarmour
parents:
diff
changeset
|
52 |
|
50cf5ea58609
Merge flashv2 branch to trunk, with eCosCentric additions
jlarmour
parents:
diff
changeset
|
53 #include <pkgconf/devs_flash_synth_v2.h> |
|
50cf5ea58609
Merge flashv2 branch to trunk, with eCosCentric additions
jlarmour
parents:
diff
changeset
|
54 |
|
50cf5ea58609
Merge flashv2 branch to trunk, with eCosCentric additions
jlarmour
parents:
diff
changeset
|
55 #include <cyg/hal/hal_io.h> |
|
50cf5ea58609
Merge flashv2 branch to trunk, with eCosCentric additions
jlarmour
parents:
diff
changeset
|
56 #include <cyg/infra/cyg_ass.h> |
|
50cf5ea58609
Merge flashv2 branch to trunk, with eCosCentric additions
jlarmour
parents:
diff
changeset
|
57 #include <string.h> |
|
50cf5ea58609
Merge flashv2 branch to trunk, with eCosCentric additions
jlarmour
parents:
diff
changeset
|
58 |
|
50cf5ea58609
Merge flashv2 branch to trunk, with eCosCentric additions
jlarmour
parents:
diff
changeset
|
59 #include <cyg/io/flash.h> |
|
50cf5ea58609
Merge flashv2 branch to trunk, with eCosCentric additions
jlarmour
parents:
diff
changeset
|
60 #include <cyg/io/flash_dev.h> |
|
50cf5ea58609
Merge flashv2 branch to trunk, with eCosCentric additions
jlarmour
parents:
diff
changeset
|
61 #include <cyg/flash/synth.h> |
|
50cf5ea58609
Merge flashv2 branch to trunk, with eCosCentric additions
jlarmour
parents:
diff
changeset
|
62 |
|
50cf5ea58609
Merge flashv2 branch to trunk, with eCosCentric additions
jlarmour
parents:
diff
changeset
|
63 #ifndef MIN |
|
50cf5ea58609
Merge flashv2 branch to trunk, with eCosCentric additions
jlarmour
parents:
diff
changeset
|
64 #define MIN(x,y) ((x)<(y) ? (x) : (y)) |
|
50cf5ea58609
Merge flashv2 branch to trunk, with eCosCentric additions
jlarmour
parents:
diff
changeset
|
65 #endif |
|
50cf5ea58609
Merge flashv2 branch to trunk, with eCosCentric additions
jlarmour
parents:
diff
changeset
|
66 |
|
50cf5ea58609
Merge flashv2 branch to trunk, with eCosCentric additions
jlarmour
parents:
diff
changeset
|
67 static int |
|
50cf5ea58609
Merge flashv2 branch to trunk, with eCosCentric additions
jlarmour
parents:
diff
changeset
|
68 synth_flash_init(struct cyg_flash_dev *dev) |
|
50cf5ea58609
Merge flashv2 branch to trunk, with eCosCentric additions
jlarmour
parents:
diff
changeset
|
69 { |
|
50cf5ea58609
Merge flashv2 branch to trunk, with eCosCentric additions
jlarmour
parents:
diff
changeset
|
70 struct cyg_flash_synth_priv *priv = (struct cyg_flash_synth_priv*)dev->priv; |
|
50cf5ea58609
Merge flashv2 branch to trunk, with eCosCentric additions
jlarmour
parents:
diff
changeset
|
71 cyg_flashaddr_t base; |
|
50cf5ea58609
Merge flashv2 branch to trunk, with eCosCentric additions
jlarmour
parents:
diff
changeset
|
72 int flags=CYG_HAL_SYS_MAP_SHARED; |
|
50cf5ea58609
Merge flashv2 branch to trunk, with eCosCentric additions
jlarmour
parents:
diff
changeset
|
73 |
|
50cf5ea58609
Merge flashv2 branch to trunk, with eCosCentric additions
jlarmour
parents:
diff
changeset
|
74 priv->flashfd = |
|
50cf5ea58609
Merge flashv2 branch to trunk, with eCosCentric additions
jlarmour
parents:
diff
changeset
|
75 cyg_hal_sys_open(priv->filename, |
|
50cf5ea58609
Merge flashv2 branch to trunk, with eCosCentric additions
jlarmour
parents:
diff
changeset
|
76 CYG_HAL_SYS_O_RDWR, |
|
50cf5ea58609
Merge flashv2 branch to trunk, with eCosCentric additions
jlarmour
parents:
diff
changeset
|
77 CYG_HAL_SYS_S_IRWXU|CYG_HAL_SYS_S_IRWXG| |
|
50cf5ea58609
Merge flashv2 branch to trunk, with eCosCentric additions
jlarmour
parents:
diff
changeset
|
78 CYG_HAL_SYS_S_IRWXO); |
|
50cf5ea58609
Merge flashv2 branch to trunk, with eCosCentric additions
jlarmour
parents:
diff
changeset
|
79 if (priv->flashfd == -ENOENT) { |
|
50cf5ea58609
Merge flashv2 branch to trunk, with eCosCentric additions
jlarmour
parents:
diff
changeset
|
80 long w, bytesleft; |
|
50cf5ea58609
Merge flashv2 branch to trunk, with eCosCentric additions
jlarmour
parents:
diff
changeset
|
81 char buf[128]; |
|
50cf5ea58609
Merge flashv2 branch to trunk, with eCosCentric additions
jlarmour
parents:
diff
changeset
|
82 |
|
50cf5ea58609
Merge flashv2 branch to trunk, with eCosCentric additions
jlarmour
parents:
diff
changeset
|
83 priv->flashfd = cyg_hal_sys_open( |
|
50cf5ea58609
Merge flashv2 branch to trunk, with eCosCentric additions
jlarmour
parents:
diff
changeset
|
84 priv->filename, |
|
50cf5ea58609
Merge flashv2 branch to trunk, with eCosCentric additions
jlarmour
parents:
diff
changeset
|
85 CYG_HAL_SYS_O_RDWR|CYG_HAL_SYS_O_CREAT, |
|
50cf5ea58609
Merge flashv2 branch to trunk, with eCosCentric additions
jlarmour
parents:
diff
changeset
|
86 CYG_HAL_SYS_S_IRWXU|CYG_HAL_SYS_S_IRWXG|CYG_HAL_SYS_S_IRWXO); |
|
50cf5ea58609
Merge flashv2 branch to trunk, with eCosCentric additions
jlarmour
parents:
diff
changeset
|
87 CYG_ASSERT( priv->flashfd >= 0, |
|
50cf5ea58609
Merge flashv2 branch to trunk, with eCosCentric additions
jlarmour
parents:
diff
changeset
|
88 "Opening of the file for the synth flash failed!"); |
|
50cf5ea58609
Merge flashv2 branch to trunk, with eCosCentric additions
jlarmour
parents:
diff
changeset
|
89 // fill with 0xff |
|
50cf5ea58609
Merge flashv2 branch to trunk, with eCosCentric additions
jlarmour
parents:
diff
changeset
|
90 memset( buf, 0xff, sizeof(buf) ); |
|
50cf5ea58609
Merge flashv2 branch to trunk, with eCosCentric additions
jlarmour
parents:
diff
changeset
|
91 bytesleft = priv->block_size * priv->blocks + |
|
50cf5ea58609
Merge flashv2 branch to trunk, with eCosCentric additions
jlarmour
parents:
diff
changeset
|
92 priv->boot_block_size * priv->boot_blocks; |
|
50cf5ea58609
Merge flashv2 branch to trunk, with eCosCentric additions
jlarmour
parents:
diff
changeset
|
93 |
|
50cf5ea58609
Merge flashv2 branch to trunk, with eCosCentric additions
jlarmour
parents:
diff
changeset
|
94 while (bytesleft > 0) { |
|
50cf5ea58609
Merge flashv2 branch to trunk, with eCosCentric additions
jlarmour
parents:
diff
changeset
|
95 int bytesneeded; |
|
50cf5ea58609
Merge flashv2 branch to trunk, with eCosCentric additions
jlarmour
parents:
diff
changeset
|
96 bytesneeded = bytesleft < sizeof(buf) ? |
|
50cf5ea58609
Merge flashv2 branch to trunk, with eCosCentric additions
jlarmour
parents:
diff
changeset
|
97 bytesleft : sizeof(buf); |
|
50cf5ea58609
Merge flashv2 branch to trunk, with eCosCentric additions
jlarmour
parents:
diff
changeset
|
98 |
|
50cf5ea58609
Merge flashv2 branch to trunk, with eCosCentric additions
jlarmour
parents:
diff
changeset
|
99 w = cyg_hal_sys_write( priv->flashfd, buf, |
|
50cf5ea58609
Merge flashv2 branch to trunk, with eCosCentric additions
jlarmour
parents:
diff
changeset
|
100 bytesneeded ); |
|
50cf5ea58609
Merge flashv2 branch to trunk, with eCosCentric additions
jlarmour
parents:
diff
changeset
|
101 CYG_ASSERT(w == bytesneeded, |
|
50cf5ea58609
Merge flashv2 branch to trunk, with eCosCentric additions
jlarmour
parents:
diff
changeset
|
102 "initialization of flash file failed"); |
|
50cf5ea58609
Merge flashv2 branch to trunk, with eCosCentric additions
jlarmour
parents:
diff
changeset
|
103 bytesleft -= bytesneeded; |
|
50cf5ea58609
Merge flashv2 branch to trunk, with eCosCentric additions
jlarmour
parents:
diff
changeset
|
104 } // while |
|
50cf5ea58609
Merge flashv2 branch to trunk, with eCosCentric additions
jlarmour
parents:
diff
changeset
|
105 } |
|
50cf5ea58609
Merge flashv2 branch to trunk, with eCosCentric additions
jlarmour
parents:
diff
changeset
|
106 CYG_ASSERT( priv->flashfd >= 0, |
|
50cf5ea58609
Merge flashv2 branch to trunk, with eCosCentric additions
jlarmour
parents:
diff
changeset
|
107 "Opening of the file for the synth flash failed!"); |
|
50cf5ea58609
Merge flashv2 branch to trunk, with eCosCentric additions
jlarmour
parents:
diff
changeset
|
108 if ( priv->flashfd <= 0 ) { |
|
50cf5ea58609
Merge flashv2 branch to trunk, with eCosCentric additions
jlarmour
parents:
diff
changeset
|
109 return CYG_FLASH_ERR_HWR; |
|
50cf5ea58609
Merge flashv2 branch to trunk, with eCosCentric additions
jlarmour
parents:
diff
changeset
|
110 } |
|
50cf5ea58609
Merge flashv2 branch to trunk, with eCosCentric additions
jlarmour
parents:
diff
changeset
|
111 |
|
50cf5ea58609
Merge flashv2 branch to trunk, with eCosCentric additions
jlarmour
parents:
diff
changeset
|
112 if (dev->start != 0) { |
|
50cf5ea58609
Merge flashv2 branch to trunk, with eCosCentric additions
jlarmour
parents:
diff
changeset
|
113 flags |= CYG_HAL_SYS_MAP_FIXED; |
|
50cf5ea58609
Merge flashv2 branch to trunk, with eCosCentric additions
jlarmour
parents:
diff
changeset
|
114 } |
|
2643
5ba0b3e7a0cb
* src/synth.c: Removed cyg_hal_sys_do_mmap() wrapper function.
asl
parents:
2629
diff
changeset
|
115 base = (cyg_flashaddr_t)cyg_hal_sys_mmap( |
|
2629
50cf5ea58609
Merge flashv2 branch to trunk, with eCosCentric additions
jlarmour
parents:
diff
changeset
|
116 (void *)dev->start, |
|
50cf5ea58609
Merge flashv2 branch to trunk, with eCosCentric additions
jlarmour
parents:
diff
changeset
|
117 priv->blocks * priv->block_size + |
|
50cf5ea58609
Merge flashv2 branch to trunk, with eCosCentric additions
jlarmour
parents:
diff
changeset
|
118 priv->boot_block_size * priv->boot_blocks, |
|
50cf5ea58609
Merge flashv2 branch to trunk, with eCosCentric additions
jlarmour
parents:
diff
changeset
|
119 CYG_HAL_SYS_PROT_READ, |
|
50cf5ea58609
Merge flashv2 branch to trunk, with eCosCentric additions
jlarmour
parents:
diff
changeset
|
120 flags, |
|
50cf5ea58609
Merge flashv2 branch to trunk, with eCosCentric additions
jlarmour
parents:
diff
changeset
|
121 priv->flashfd, |
|
50cf5ea58609
Merge flashv2 branch to trunk, with eCosCentric additions
jlarmour
parents:
diff
changeset
|
122 0l); |
| 2696 | 123 CYG_ASSERT( base != -1, "mmap of flash file failed!" ); |
| 124 if (base == -1) { | |
|
2629
50cf5ea58609
Merge flashv2 branch to trunk, with eCosCentric additions
jlarmour
parents:
diff
changeset
|
125 return CYG_FLASH_ERR_HWR; |
|
50cf5ea58609
Merge flashv2 branch to trunk, with eCosCentric additions
jlarmour
parents:
diff
changeset
|
126 } |
|
50cf5ea58609
Merge flashv2 branch to trunk, with eCosCentric additions
jlarmour
parents:
diff
changeset
|
127 dev->start = base; |
|
50cf5ea58609
Merge flashv2 branch to trunk, with eCosCentric additions
jlarmour
parents:
diff
changeset
|
128 dev->end = base + (priv->blocks * priv->block_size) + |
|
50cf5ea58609
Merge flashv2 branch to trunk, with eCosCentric additions
jlarmour
parents:
diff
changeset
|
129 (priv->boot_blocks * priv->boot_block_size) - 1; |
|
50cf5ea58609
Merge flashv2 branch to trunk, with eCosCentric additions
jlarmour
parents:
diff
changeset
|
130 if (priv->boot_blocks) { |
|
50cf5ea58609
Merge flashv2 branch to trunk, with eCosCentric additions
jlarmour
parents:
diff
changeset
|
131 if (priv->boot_block_bottom) { |
|
50cf5ea58609
Merge flashv2 branch to trunk, with eCosCentric additions
jlarmour
parents:
diff
changeset
|
132 priv->block_info[0].block_size = priv->boot_block_size; |
|
50cf5ea58609
Merge flashv2 branch to trunk, with eCosCentric additions
jlarmour
parents:
diff
changeset
|
133 priv->block_info[0].blocks = priv->boot_blocks; |
|
50cf5ea58609
Merge flashv2 branch to trunk, with eCosCentric additions
jlarmour
parents:
diff
changeset
|
134 priv->block_info[1].block_size = priv->block_size; |
|
50cf5ea58609
Merge flashv2 branch to trunk, with eCosCentric additions
jlarmour
parents:
diff
changeset
|
135 priv->block_info[1].blocks = priv->blocks; |
|
50cf5ea58609
Merge flashv2 branch to trunk, with eCosCentric additions
jlarmour
parents:
diff
changeset
|
136 } else { |
|
50cf5ea58609
Merge flashv2 branch to trunk, with eCosCentric additions
jlarmour
parents:
diff
changeset
|
137 priv->block_info[0].block_size = priv->block_size; |
|
50cf5ea58609
Merge flashv2 branch to trunk, with eCosCentric additions
jlarmour
parents:
diff
changeset
|
138 priv->block_info[0].blocks = priv->blocks; |
|
50cf5ea58609
Merge flashv2 branch to trunk, with eCosCentric additions
jlarmour
parents:
diff
changeset
|
139 priv->block_info[1].block_size = priv->boot_block_size; |
|
50cf5ea58609
Merge flashv2 branch to trunk, with eCosCentric additions
jlarmour
parents:
diff
changeset
|
140 priv->block_info[1].blocks = priv->boot_blocks; |
|
50cf5ea58609
Merge flashv2 branch to trunk, with eCosCentric additions
jlarmour
parents:
diff
changeset
|
141 } |
|
50cf5ea58609
Merge flashv2 branch to trunk, with eCosCentric additions
jlarmour
parents:
diff
changeset
|
142 dev->num_block_infos = 2; |
|
50cf5ea58609
Merge flashv2 branch to trunk, with eCosCentric additions
jlarmour
parents:
diff
changeset
|
143 } else { |
|
50cf5ea58609
Merge flashv2 branch to trunk, with eCosCentric additions
jlarmour
parents:
diff
changeset
|
144 priv->block_info[0].block_size = priv->block_size; |
|
50cf5ea58609
Merge flashv2 branch to trunk, with eCosCentric additions
jlarmour
parents:
diff
changeset
|
145 priv->block_info[0].blocks = priv->blocks; |
|
50cf5ea58609
Merge flashv2 branch to trunk, with eCosCentric additions
jlarmour
parents:
diff
changeset
|
146 dev->num_block_infos = 1; |
|
50cf5ea58609
Merge flashv2 branch to trunk, with eCosCentric additions
jlarmour
parents:
diff
changeset
|
147 } |
|
50cf5ea58609
Merge flashv2 branch to trunk, with eCosCentric additions
jlarmour
parents:
diff
changeset
|
148 dev->block_info = &priv->block_info[0]; |
|
50cf5ea58609
Merge flashv2 branch to trunk, with eCosCentric additions
jlarmour
parents:
diff
changeset
|
149 |
|
50cf5ea58609
Merge flashv2 branch to trunk, with eCosCentric additions
jlarmour
parents:
diff
changeset
|
150 return CYG_FLASH_ERR_OK; |
|
50cf5ea58609
Merge flashv2 branch to trunk, with eCosCentric additions
jlarmour
parents:
diff
changeset
|
151 } |
|
50cf5ea58609
Merge flashv2 branch to trunk, with eCosCentric additions
jlarmour
parents:
diff
changeset
|
152 |
|
50cf5ea58609
Merge flashv2 branch to trunk, with eCosCentric additions
jlarmour
parents:
diff
changeset
|
153 /* This helps speed up the erase. */ |
|
50cf5ea58609
Merge flashv2 branch to trunk, with eCosCentric additions
jlarmour
parents:
diff
changeset
|
154 static char empty[4096]; |
|
50cf5ea58609
Merge flashv2 branch to trunk, with eCosCentric additions
jlarmour
parents:
diff
changeset
|
155 static cyg_bool empty_inited = false; |
|
50cf5ea58609
Merge flashv2 branch to trunk, with eCosCentric additions
jlarmour
parents:
diff
changeset
|
156 |
|
50cf5ea58609
Merge flashv2 branch to trunk, with eCosCentric additions
jlarmour
parents:
diff
changeset
|
157 // Return the size of the block which is at the given address. |
|
50cf5ea58609
Merge flashv2 branch to trunk, with eCosCentric additions
jlarmour
parents:
diff
changeset
|
158 // __inline__ so that we know it will be in RAM, not ROM. |
|
50cf5ea58609
Merge flashv2 branch to trunk, with eCosCentric additions
jlarmour
parents:
diff
changeset
|
159 static __inline__ size_t |
|
50cf5ea58609
Merge flashv2 branch to trunk, with eCosCentric additions
jlarmour
parents:
diff
changeset
|
160 flash_block_size(struct cyg_flash_dev *dev, const cyg_flashaddr_t addr) |
|
50cf5ea58609
Merge flashv2 branch to trunk, with eCosCentric additions
jlarmour
parents:
diff
changeset
|
161 { |
|
50cf5ea58609
Merge flashv2 branch to trunk, with eCosCentric additions
jlarmour
parents:
diff
changeset
|
162 int i; |
|
50cf5ea58609
Merge flashv2 branch to trunk, with eCosCentric additions
jlarmour
parents:
diff
changeset
|
163 size_t offset; |
|
50cf5ea58609
Merge flashv2 branch to trunk, with eCosCentric additions
jlarmour
parents:
diff
changeset
|
164 |
|
50cf5ea58609
Merge flashv2 branch to trunk, with eCosCentric additions
jlarmour
parents:
diff
changeset
|
165 |
|
50cf5ea58609
Merge flashv2 branch to trunk, with eCosCentric additions
jlarmour
parents:
diff
changeset
|
166 CYG_ASSERT((addr >= dev->start) && (addr <= dev->end), "Not inside device"); |
|
50cf5ea58609
Merge flashv2 branch to trunk, with eCosCentric additions
jlarmour
parents:
diff
changeset
|
167 |
|
50cf5ea58609
Merge flashv2 branch to trunk, with eCosCentric additions
jlarmour
parents:
diff
changeset
|
168 offset = addr - dev->start; |
|
50cf5ea58609
Merge flashv2 branch to trunk, with eCosCentric additions
jlarmour
parents:
diff
changeset
|
169 for (i=0; i < dev->num_block_infos; i++) { |
|
50cf5ea58609
Merge flashv2 branch to trunk, with eCosCentric additions
jlarmour
parents:
diff
changeset
|
170 if (offset < (dev->block_info[i].blocks * dev->block_info[i].block_size)) |
|
50cf5ea58609
Merge flashv2 branch to trunk, with eCosCentric additions
jlarmour
parents:
diff
changeset
|
171 return dev->block_info[i].block_size; |
|
50cf5ea58609
Merge flashv2 branch to trunk, with eCosCentric additions
jlarmour
parents:
diff
changeset
|
172 offset = offset - |
|
50cf5ea58609
Merge flashv2 branch to trunk, with eCosCentric additions
jlarmour
parents:
diff
changeset
|
173 (dev->block_info[i].blocks * dev->block_info[i].block_size); |
|
50cf5ea58609
Merge flashv2 branch to trunk, with eCosCentric additions
jlarmour
parents:
diff
changeset
|
174 } |
|
50cf5ea58609
Merge flashv2 branch to trunk, with eCosCentric additions
jlarmour
parents:
diff
changeset
|
175 CYG_FAIL("Programming error"); |
|
50cf5ea58609
Merge flashv2 branch to trunk, with eCosCentric additions
jlarmour
parents:
diff
changeset
|
176 return 0; |
|
50cf5ea58609
Merge flashv2 branch to trunk, with eCosCentric additions
jlarmour
parents:
diff
changeset
|
177 } |
|
50cf5ea58609
Merge flashv2 branch to trunk, with eCosCentric additions
jlarmour
parents:
diff
changeset
|
178 |
|
50cf5ea58609
Merge flashv2 branch to trunk, with eCosCentric additions
jlarmour
parents:
diff
changeset
|
179 static int |
|
50cf5ea58609
Merge flashv2 branch to trunk, with eCosCentric additions
jlarmour
parents:
diff
changeset
|
180 synth_flash_erase_block(struct cyg_flash_dev *dev, |
|
50cf5ea58609
Merge flashv2 branch to trunk, with eCosCentric additions
jlarmour
parents:
diff
changeset
|
181 cyg_flashaddr_t block_base) |
|
50cf5ea58609
Merge flashv2 branch to trunk, with eCosCentric additions
jlarmour
parents:
diff
changeset
|
182 { |
|
50cf5ea58609
Merge flashv2 branch to trunk, with eCosCentric additions
jlarmour
parents:
diff
changeset
|
183 const struct cyg_flash_synth_priv *priv = dev->priv; |
|
50cf5ea58609
Merge flashv2 branch to trunk, with eCosCentric additions
jlarmour
parents:
diff
changeset
|
184 int offset = (int)block_base; |
|
50cf5ea58609
Merge flashv2 branch to trunk, with eCosCentric additions
jlarmour
parents:
diff
changeset
|
185 size_t remaining; |
|
50cf5ea58609
Merge flashv2 branch to trunk, with eCosCentric additions
jlarmour
parents:
diff
changeset
|
186 int write_size; |
|
50cf5ea58609
Merge flashv2 branch to trunk, with eCosCentric additions
jlarmour
parents:
diff
changeset
|
187 |
|
50cf5ea58609
Merge flashv2 branch to trunk, with eCosCentric additions
jlarmour
parents:
diff
changeset
|
188 offset -= dev->start; |
|
50cf5ea58609
Merge flashv2 branch to trunk, with eCosCentric additions
jlarmour
parents:
diff
changeset
|
189 |
|
50cf5ea58609
Merge flashv2 branch to trunk, with eCosCentric additions
jlarmour
parents:
diff
changeset
|
190 cyg_hal_sys_lseek(priv->flashfd, offset, |
|
50cf5ea58609
Merge flashv2 branch to trunk, with eCosCentric additions
jlarmour
parents:
diff
changeset
|
191 CYG_HAL_SYS_SEEK_SET); |
|
50cf5ea58609
Merge flashv2 branch to trunk, with eCosCentric additions
jlarmour
parents:
diff
changeset
|
192 |
|
50cf5ea58609
Merge flashv2 branch to trunk, with eCosCentric additions
jlarmour
parents:
diff
changeset
|
193 if (!empty_inited) { |
|
50cf5ea58609
Merge flashv2 branch to trunk, with eCosCentric additions
jlarmour
parents:
diff
changeset
|
194 memset(empty, 0xff, sizeof(empty)); |
|
50cf5ea58609
Merge flashv2 branch to trunk, with eCosCentric additions
jlarmour
parents:
diff
changeset
|
195 empty_inited = true; |
|
50cf5ea58609
Merge flashv2 branch to trunk, with eCosCentric additions
jlarmour
parents:
diff
changeset
|
196 } |
|
50cf5ea58609
Merge flashv2 branch to trunk, with eCosCentric additions
jlarmour
parents:
diff
changeset
|
197 |
|
50cf5ea58609
Merge flashv2 branch to trunk, with eCosCentric additions
jlarmour
parents:
diff
changeset
|
198 remaining = flash_block_size(dev, block_base); |
|
50cf5ea58609
Merge flashv2 branch to trunk, with eCosCentric additions
jlarmour
parents:
diff
changeset
|
199 |
|
50cf5ea58609
Merge flashv2 branch to trunk, with eCosCentric additions
jlarmour
parents:
diff
changeset
|
200 while (remaining) { |
|
50cf5ea58609
Merge flashv2 branch to trunk, with eCosCentric additions
jlarmour
parents:
diff
changeset
|
201 write_size = MIN(remaining, sizeof(empty)); |
|
50cf5ea58609
Merge flashv2 branch to trunk, with eCosCentric additions
jlarmour
parents:
diff
changeset
|
202 cyg_hal_sys_write(priv->flashfd, empty, write_size); |
|
50cf5ea58609
Merge flashv2 branch to trunk, with eCosCentric additions
jlarmour
parents:
diff
changeset
|
203 remaining -= write_size; |
|
50cf5ea58609
Merge flashv2 branch to trunk, with eCosCentric additions
jlarmour
parents:
diff
changeset
|
204 } |
|
50cf5ea58609
Merge flashv2 branch to trunk, with eCosCentric additions
jlarmour
parents:
diff
changeset
|
205 return CYG_FLASH_ERR_OK; |
|
50cf5ea58609
Merge flashv2 branch to trunk, with eCosCentric additions
jlarmour
parents:
diff
changeset
|
206 } |
|
50cf5ea58609
Merge flashv2 branch to trunk, with eCosCentric additions
jlarmour
parents:
diff
changeset
|
207 |
|
50cf5ea58609
Merge flashv2 branch to trunk, with eCosCentric additions
jlarmour
parents:
diff
changeset
|
208 static int |
|
50cf5ea58609
Merge flashv2 branch to trunk, with eCosCentric additions
jlarmour
parents:
diff
changeset
|
209 synth_flash_program (struct cyg_flash_dev *dev, |
|
50cf5ea58609
Merge flashv2 branch to trunk, with eCosCentric additions
jlarmour
parents:
diff
changeset
|
210 cyg_flashaddr_t base, |
|
50cf5ea58609
Merge flashv2 branch to trunk, with eCosCentric additions
jlarmour
parents:
diff
changeset
|
211 const void* data, size_t len) |
|
50cf5ea58609
Merge flashv2 branch to trunk, with eCosCentric additions
jlarmour
parents:
diff
changeset
|
212 { |
|
50cf5ea58609
Merge flashv2 branch to trunk, with eCosCentric additions
jlarmour
parents:
diff
changeset
|
213 const struct cyg_flash_synth_priv *priv = dev->priv; |
|
50cf5ea58609
Merge flashv2 branch to trunk, with eCosCentric additions
jlarmour
parents:
diff
changeset
|
214 int offset = base; |
|
50cf5ea58609
Merge flashv2 branch to trunk, with eCosCentric additions
jlarmour
parents:
diff
changeset
|
215 offset -= dev->start; |
|
50cf5ea58609
Merge flashv2 branch to trunk, with eCosCentric additions
jlarmour
parents:
diff
changeset
|
216 |
|
50cf5ea58609
Merge flashv2 branch to trunk, with eCosCentric additions
jlarmour
parents:
diff
changeset
|
217 cyg_hal_sys_lseek(priv->flashfd, offset, CYG_HAL_SYS_SEEK_SET); |
|
50cf5ea58609
Merge flashv2 branch to trunk, with eCosCentric additions
jlarmour
parents:
diff
changeset
|
218 cyg_hal_sys_write(priv->flashfd, data, len); |
|
50cf5ea58609
Merge flashv2 branch to trunk, with eCosCentric additions
jlarmour
parents:
diff
changeset
|
219 |
|
50cf5ea58609
Merge flashv2 branch to trunk, with eCosCentric additions
jlarmour
parents:
diff
changeset
|
220 return CYG_FLASH_ERR_OK; |
|
50cf5ea58609
Merge flashv2 branch to trunk, with eCosCentric additions
jlarmour
parents:
diff
changeset
|
221 } |
|
50cf5ea58609
Merge flashv2 branch to trunk, with eCosCentric additions
jlarmour
parents:
diff
changeset
|
222 |
|
50cf5ea58609
Merge flashv2 branch to trunk, with eCosCentric additions
jlarmour
parents:
diff
changeset
|
223 #define QUERY "Linux Synthetic Flash" |
|
50cf5ea58609
Merge flashv2 branch to trunk, with eCosCentric additions
jlarmour
parents:
diff
changeset
|
224 |
|
50cf5ea58609
Merge flashv2 branch to trunk, with eCosCentric additions
jlarmour
parents:
diff
changeset
|
225 static size_t |
|
50cf5ea58609
Merge flashv2 branch to trunk, with eCosCentric additions
jlarmour
parents:
diff
changeset
|
226 synth_flash_query(struct cyg_flash_dev *dev, void * data, |
|
50cf5ea58609
Merge flashv2 branch to trunk, with eCosCentric additions
jlarmour
parents:
diff
changeset
|
227 size_t len) |
|
50cf5ea58609
Merge flashv2 branch to trunk, with eCosCentric additions
jlarmour
parents:
diff
changeset
|
228 { |
|
50cf5ea58609
Merge flashv2 branch to trunk, with eCosCentric additions
jlarmour
parents:
diff
changeset
|
229 memcpy(data,QUERY,sizeof(QUERY)); |
|
50cf5ea58609
Merge flashv2 branch to trunk, with eCosCentric additions
jlarmour
parents:
diff
changeset
|
230 return sizeof(QUERY); |
|
50cf5ea58609
Merge flashv2 branch to trunk, with eCosCentric additions
jlarmour
parents:
diff
changeset
|
231 } |
|
50cf5ea58609
Merge flashv2 branch to trunk, with eCosCentric additions
jlarmour
parents:
diff
changeset
|
232 |
|
50cf5ea58609
Merge flashv2 branch to trunk, with eCosCentric additions
jlarmour
parents:
diff
changeset
|
233 const CYG_FLASH_FUNS(cyg_flash_synth_funs, |
|
50cf5ea58609
Merge flashv2 branch to trunk, with eCosCentric additions
jlarmour
parents:
diff
changeset
|
234 synth_flash_init, |
|
50cf5ea58609
Merge flashv2 branch to trunk, with eCosCentric additions
jlarmour
parents:
diff
changeset
|
235 synth_flash_query, |
|
50cf5ea58609
Merge flashv2 branch to trunk, with eCosCentric additions
jlarmour
parents:
diff
changeset
|
236 synth_flash_erase_block, |
|
50cf5ea58609
Merge flashv2 branch to trunk, with eCosCentric additions
jlarmour
parents:
diff
changeset
|
237 synth_flash_program, |
|
50cf5ea58609
Merge flashv2 branch to trunk, with eCosCentric additions
jlarmour
parents:
diff
changeset
|
238 NULL, // read |
|
50cf5ea58609
Merge flashv2 branch to trunk, with eCosCentric additions
jlarmour
parents:
diff
changeset
|
239 cyg_flash_devfn_lock_nop, |
|
50cf5ea58609
Merge flashv2 branch to trunk, with eCosCentric additions
jlarmour
parents:
diff
changeset
|
240 cyg_flash_devfn_unlock_nop); |
|
50cf5ea58609
Merge flashv2 branch to trunk, with eCosCentric additions
jlarmour
parents:
diff
changeset
|
241 |
|
50cf5ea58609
Merge flashv2 branch to trunk, with eCosCentric additions
jlarmour
parents:
diff
changeset
|
242 static struct cyg_flash_synth_priv synth_flash_priv = { |
|
50cf5ea58609
Merge flashv2 branch to trunk, with eCosCentric additions
jlarmour
parents:
diff
changeset
|
243 .block_size = CYGNUM_FLASH_SYNTH_V2_BLOCKSIZE, |
|
50cf5ea58609
Merge flashv2 branch to trunk, with eCosCentric additions
jlarmour
parents:
diff
changeset
|
244 .blocks = CYGNUM_FLASH_SYNTH_V2_NUMBLOCKS, |
|
50cf5ea58609
Merge flashv2 branch to trunk, with eCosCentric additions
jlarmour
parents:
diff
changeset
|
245 .boot_block_size = CYGNUM_FLASH_SYNTH_V2_BOOT_BLOCKSIZE, |
|
50cf5ea58609
Merge flashv2 branch to trunk, with eCosCentric additions
jlarmour
parents:
diff
changeset
|
246 .boot_blocks = CYGNUM_FLASH_SYNTH_V2_NUMBOOT_BLOCKS, |
|
50cf5ea58609
Merge flashv2 branch to trunk, with eCosCentric additions
jlarmour
parents:
diff
changeset
|
247 .boot_block_bottom = CYGNUM_FLASH_SYNTH_V2_BOOT_BLOCK_BOTTOM, |
|
50cf5ea58609
Merge flashv2 branch to trunk, with eCosCentric additions
jlarmour
parents:
diff
changeset
|
248 .filename = CYGDAT_FLASH_SYNTH_V2_FILENAME, |
|
50cf5ea58609
Merge flashv2 branch to trunk, with eCosCentric additions
jlarmour
parents:
diff
changeset
|
249 .flashfd = -1 |
|
50cf5ea58609
Merge flashv2 branch to trunk, with eCosCentric additions
jlarmour
parents:
diff
changeset
|
250 }; |
|
50cf5ea58609
Merge flashv2 branch to trunk, with eCosCentric additions
jlarmour
parents:
diff
changeset
|
251 |
|
50cf5ea58609
Merge flashv2 branch to trunk, with eCosCentric additions
jlarmour
parents:
diff
changeset
|
252 CYG_FLASH_DRIVER(cyg_flash_synth_flashdev, |
|
50cf5ea58609
Merge flashv2 branch to trunk, with eCosCentric additions
jlarmour
parents:
diff
changeset
|
253 &cyg_flash_synth_funs, |
|
50cf5ea58609
Merge flashv2 branch to trunk, with eCosCentric additions
jlarmour
parents:
diff
changeset
|
254 0, // flags |
|
50cf5ea58609
Merge flashv2 branch to trunk, with eCosCentric additions
jlarmour
parents:
diff
changeset
|
255 CYGMEM_FLASH_SYNTH_V2_BASE, // Start, if 0 will be updated by init |
|
50cf5ea58609
Merge flashv2 branch to trunk, with eCosCentric additions
jlarmour
parents:
diff
changeset
|
256 0, // end, filled in by init |
|
50cf5ea58609
Merge flashv2 branch to trunk, with eCosCentric additions
jlarmour
parents:
diff
changeset
|
257 0, // number of block_info's, filled in by init |
|
50cf5ea58609
Merge flashv2 branch to trunk, with eCosCentric additions
jlarmour
parents:
diff
changeset
|
258 synth_flash_priv.block_info, |
|
50cf5ea58609
Merge flashv2 branch to trunk, with eCosCentric additions
jlarmour
parents:
diff
changeset
|
259 &synth_flash_priv); |
|
50cf5ea58609
Merge flashv2 branch to trunk, with eCosCentric additions
jlarmour
parents:
diff
changeset
|
260 |
|
50cf5ea58609
Merge flashv2 branch to trunk, with eCosCentric additions
jlarmour
parents:
diff
changeset
|
261 // EOF synth.c |
