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