Skip to content
GitLab
Projects
Groups
Snippets
Help
Loading...
Help
Help
Support
Community forum
Keyboard shortcuts
?
Submit feedback
Contribute to GitLab
Sign in / Register
Toggle navigation
Open sidebar
Evan Lojewski
ast2050-flashrom
Commits
73eca80d
Commit
73eca80d
authored
21 years ago
by
Ollie Lho
Browse files
Options
Download
Email Patches
Plain Diff
Remove duplicated code
Corresponding to flashrom svn r14 and coreboot v2 svn r1456.
parent
180850e2
Changes
8
Hide whitespace changes
Inline
Side-by-side
Showing
8 changed files
with
142 additions
and
384 deletions
+142
-384
flash_rom.c
flash_rom.c
+12
-15
jedec.c
jedec.c
+71
-26
jedec.h
jedec.h
+38
-0
pm49fl004.c
pm49fl004.c
+12
-72
sst39sf020.c
sst39sf020.c
+2
-97
sst39sf020.h
sst39sf020.h
+0
-1
sst49lf040.c
sst49lf040.c
+6
-129
w49f002u.c
w49f002u.c
+1
-44
No files found.
flash_rom.c
View file @
73eca80d
...
...
@@ -59,33 +59,30 @@ struct flashchip flashchips[] = {
{
"SST28SF040A"
,
SST_ID
,
SST_28SF040
,
NULL
,
512
,
256
,
probe_28sf040
,
erase_28sf040
,
write_28sf040
,
NULL
},
{
"SST39SF020A"
,
SST_ID
,
SST_39SF020
,
NULL
,
256
,
4096
,
probe_
39sf020
,
erase_39sf020
,
write_39sf020
,
NULL
},
probe_
jedec
,
erase_jedec
,
write_39sf020
,
NULL
},
{
"SST39VF020"
,
SST_ID
,
SST_39VF020
,
NULL
,
256
,
4096
,
probe_
39sf020
,
erase_39sf020
,
write_39sf020
,
NULL
},
probe_
jedec
,
erase_jedec
,
write_39sf020
,
NULL
},
{
"SST49LF040"
,
SST_ID
,
SST_49LF040
,
NULL
,
512
,
4096
,
probe_
49lf040
,
erase_49lf040
,
write_49lf040
,
NULL
},
probe_
jedec
,
erase_jedec
,
write_49lf040
,
NULL
},
{
"SST49LF080A"
,
SST_ID
,
SST_49LF080A
,
NULL
,
1024
,
4096
,
probe_
49lf040
,
erase_49lf040
,
write_49lf040
,
NULL
},
probe_
jedec
,
erase_jedec
,
write_49lf040
,
NULL
},
{
"SST49LF002A"
,
SST_ID
,
SST_49LF002A
,
NULL
,
256
,
4096
,
probe_
49lf040
,
erase_49lf040
,
write_49lf040
,
NULL
},
probe_
jedec
,
erase_jedec
,
write_49lf040
,
NULL
},
{
"SST49LF003A"
,
SST_ID
,
SST_49LF003A
,
NULL
,
384
,
4096
,
probe_
49lf040
,
erase_49lf040
,
write_49lf040
,
NULL
},
probe_
jedec
,
erase_jedec
,
write_49lf040
,
NULL
},
{
"SST49LF004A"
,
SST_ID
,
SST_49LF004A
,
NULL
,
512
,
4096
,
probe_
49lf040
,
erase_49lf040
,
write_49lf040
,
NULL
},
probe_
jedec
,
erase_jedec
,
write_49lf040
,
NULL
},
{
"SST49LF008A"
,
SST_ID
,
SST_49LF008A
,
NULL
,
1024
,
4096
,
probe_49lf040
,
erase_49lf040
,
write_49lf040
,
NULL
},
//By LYH begin
probe_jedec
,
erase_jedec
,
write_49lf040
,
NULL
},
{
"Pm49FL004"
,
PMC_ID
,
PMC_49FL004
,
NULL
,
512
,
64
*
1024
,
probe_49fl004
,
erase_49fl004
,
write_49fl004
,
NULL
},
//END
probe_jedec
,
erase_jedec
,
write_49fl004
,
NULL
},
{
"W29C011"
,
WINBOND_ID
,
W_29C011
,
NULL
,
128
,
128
,
probe_jedec
,
erase_jedec
,
write_jedec
,
NULL
},
{
"W29C020C"
,
WINBOND_ID
,
W_29C020C
,
NULL
,
256
,
128
,
probe_jedec
,
erase_jedec
,
write_jedec
,
NULL
},
{
"W49F002U"
,
WINBOND_ID
,
W_49F002U
,
NULL
,
256
,
128
,
probe_
49f002
,
erase_
49f002
,
write_49f002
,
NULL
},
{
"M29F400BT"
,
ST_ID
,
ST_M29F400BT
,
NULL
,
512
,
64
*
1024
,
probe_
jedec
,
erase_
jedec
,
write_49f002
,
NULL
},
{
"M29F400BT"
,
ST_ID
,
ST_M29F400BT
,
NULL
,
512
,
64
*
1024
,
probe_m29f400bt
,
erase_m29f400bt
,
write_linuxbios_m29f400bt
,
NULL
},
{
"82802ab"
,
137
,
173
,
NULL
,
512
,
64
*
1024
,
probe_82802ab
,
erase_82802ab
,
write_82802ab
,
NULL
},
...
...
@@ -253,7 +250,7 @@ int main (int argc, char * argv[])
exit
(
1
);
}
printf
(
"Reading Flash..."
);
if
(
flash
->
read
==
NULL
)
if
(
flash
->
read
==
NULL
)
memcpy
(
buf
,
(
const
char
*
)
flash
->
virt_addr
,
size
);
else
flash
->
read
(
flash
,
buf
);
...
...
This diff is collapsed.
Click to expand it.
jedec.c
View file @
73eca80d
...
...
@@ -30,44 +30,89 @@
int
probe_jedec
(
struct
flashchip
*
flash
)
{
volatile
char
*
bios
=
flash
->
virt_addr
;
unsigned
char
id1
,
id2
;
volatile
char
*
bios
=
flash
->
virt_addr
;
unsigned
char
id1
,
id2
;
*
(
volatile
char
*
)
(
bios
+
0x5555
)
=
0xAA
;
myusec_delay
(
10
);
*
(
volatile
char
*
)
(
bios
+
0x2AAA
)
=
0x55
;
myusec_delay
(
10
);
*
(
volatile
char
*
)
(
bios
+
0x5555
)
=
0x90
;
myusec_delay
(
10
);
id1
=
*
(
volatile
unsigned
char
*
)
bios
;
id2
=
*
(
volatile
unsigned
char
*
)
(
bios
+
0x01
);
*
(
volatile
char
*
)
(
bios
+
0x5555
)
=
0xAA
;
myusec_delay
(
10
);
*
(
volatile
char
*
)
(
bios
+
0x2AAA
)
=
0x55
;
myusec_delay
(
10
);
*
(
volatile
char
*
)
(
bios
+
0x5555
)
=
0xF0
;
myusec_delay
(
10
);
*
(
volatile
char
*
)
(
bios
+
0x5555
)
=
0xAA
;
*
(
volatile
char
*
)
(
bios
+
0x2AAA
)
=
0x55
;
*
(
volatile
char
*
)
(
bios
+
0x5555
)
=
0x90
;
myusec_delay
(
10
);
printf
(
"%s: id1 0x%x, id2 0x%x
\n
"
,
__FUNCTION__
,
id1
,
id2
);
if
(
id1
==
flash
->
manufacture_id
&&
id2
==
flash
->
model_id
)
return
1
;
id1
=
*
(
volatile
unsigned
char
*
)
bios
;
id2
=
*
(
volatile
unsigned
char
*
)
(
bios
+
0x01
);
return
0
;
}
*
(
volatile
char
*
)
(
bios
+
0x5555
)
=
0xAA
;
*
(
volatile
char
*
)
(
bios
+
0x2AAA
)
=
0x55
;
*
(
volatile
char
*
)
(
bios
+
0x5555
)
=
0xF0
;
int
erase_sector_jedec
(
volatile
char
*
bios
,
unsigned
int
page
)
{
/* Chip erase function does not exist for LPC mode on 49lf040.
* Erase sector-by-sector instead. */
volatile
unsigned
char
*
Temp
;
/* Issue the Sector Erase command to 40LF040 */
Temp
=
bios
+
0x5555
;
/* set up address to be C000:5555h */
*
Temp
=
0xAA
;
/* write data 0xAA to the address */
myusec_delay
(
10
);
Temp
=
bios
+
0x2AAA
;
/* set up address to be C000:2AAAh */
*
Temp
=
0x55
;
/* write data 0x55 to the address */
myusec_delay
(
10
);
Temp
=
bios
+
0x5555
;
/* set up address to be C000:5555h */
*
Temp
=
0x80
;
/* write data 0x80 to the address */
myusec_delay
(
10
);
Temp
=
bios
+
0x5555
;
/* set up address to be C000:5555h */
*
Temp
=
0xAA
;
/* write data 0xAA to the address */
myusec_delay
(
10
);
Temp
=
bios
+
0x2AAA
;
/* set up address to be C000:2AAAh */
*
Temp
=
0x55
;
/* write data 0x55 to the address */
myusec_delay
(
10
);
Temp
=
bios
+
page
;
/* set up address to be the current sector */
*
Temp
=
0x30
;
/* write data 0x30 to the address */
/* wait for Toggle bit ready */
toggle_ready_jedec
(
bios
);
printf
(
"%s: id1 0x%x, id2 0x%x
\n
"
,
__FUNCTION__
,
id1
,
id2
);
if
(
id1
==
flash
->
manufacture_id
&&
id2
==
flash
->
model_id
)
return
1
;
return
0
;
return
(
0
);
}
int
erase_jedec
(
struct
flashchip
*
flash
)
{
volatile
char
*
bios
=
flash
->
virt_addr
;
*
(
volatile
char
*
)
(
bios
+
0x5555
)
=
0xAA
;
*
(
volatile
char
*
)
(
bios
+
0x2AAA
)
=
0x55
;
*
(
volatile
char
*
)
(
bios
+
0x5555
)
=
0x80
;
*
(
volatile
char
*
)
(
bios
+
0x5555
)
=
0xAA
;
*
(
volatile
char
*
)
(
bios
+
0x2AAA
)
=
0x55
;
*
(
volatile
char
*
)
(
bios
+
0x5555
)
=
0x10
;
volatile
unsigned
char
*
bios
=
flash
->
virt_addr
;
volatile
unsigned
char
*
Temp
;
/* Issue the Sector Erase command to 39SF020 */
Temp
=
bios
+
0x5555
;
/* set up address to be C000:5555h */
*
Temp
=
0xAA
;
/* write data 0xAA to the address */
myusec_delay
(
10
);
Temp
=
bios
+
0x2AAA
;
/* set up address to be C000:2AAAh */
*
Temp
=
0x55
;
/* write data 0x55 to the address */
myusec_delay
(
10
);
Temp
=
bios
+
0x5555
;
/* set up address to be C000:5555h */
*
Temp
=
0x80
;
/* write data 0x80 to the address */
myusec_delay
(
10
);
Temp
=
bios
+
0x5555
;
/* set up address to be C000:5555h */
*
Temp
=
0xAA
;
/* write data 0xAA to the address */
myusec_delay
(
10
);
Temp
=
bios
+
0x2AAA
;
/* set up address to be C000:2AAAh */
*
Temp
=
0x55
;
/* write data 0x55 to the address */
myusec_delay
(
10
);
Temp
=
bios
+
0x5555
;
/* set up address to be C000:5555h */
*
Temp
=
0x10
;
/* write data 0x55 to the address */
myusec_delay
(
10
);
toggle_ready_jedec
(
bios
);
return
(
0
);
...
...
This diff is collapsed.
Click to expand it.
jedec.h
View file @
73eca80d
...
...
@@ -45,6 +45,8 @@ extern __inline__ void protect_jedec (volatile char * bios)
usleep
(
200
);
}
extern
int
erase_sector_jedec
(
volatile
char
*
bios
,
unsigned
int
page
);
extern
__inline__
void
write_page_jedec
(
volatile
char
*
bios
,
char
*
src
,
volatile
char
*
dst
,
int
page_size
)
{
...
...
@@ -63,4 +65,40 @@ extern __inline__ void write_page_jedec (volatile char * bios, char * src, volat
toggle_ready_jedec
(
dst
-
1
);
}
static
__inline__
int
write_sector_jedec
(
volatile
char
*
bios
,
unsigned
char
*
src
,
volatile
unsigned
char
*
dst
,
unsigned
int
page_size
)
{
int
i
;
volatile
char
*
Temp
;
for
(
i
=
0
;
i
<
page_size
;
i
++
)
{
if
(
*
dst
!=
0xff
)
{
printf
(
"FATAL: dst %p not erased (val 0x%x
\n
"
,
dst
,
*
dst
);
return
(
-
1
);
}
/* transfer data from source to destination */
if
(
*
src
==
0xFF
)
{
dst
++
,
src
++
;
/* If the data is 0xFF, don't program it */
continue
;
}
Temp
=
(
bios
+
0x5555
);
*
Temp
=
0xAA
;
Temp
=
bios
+
0x2AAA
;
*
Temp
=
0x55
;
Temp
=
bios
+
0x5555
;
*
Temp
=
0xA0
;
*
dst
=
*
src
;
toggle_ready_jedec
(
bios
);
if
(
*
dst
!=
*
src
)
printf
(
"BAD! dst 0x%lx val 0x%x src 0x%x
\n
"
,
(
unsigned
long
)
dst
,
*
dst
,
*
src
);
dst
++
,
src
++
;
}
return
(
0
);
}
#endif
/* !__JEDEC_H__ */
This diff is collapsed.
Click to expand it.
pm49fl004.c
View file @
73eca80d
...
...
@@ -35,23 +35,23 @@ static __inline__ int erase_block_49fl004 ( volatile unsigned char * bios ,unsig
{
volatile
unsigned
char
*
Temp
;
Temp
=
bios
+
0x5555
;
/* set up address to be C000:5555h */
*
Temp
=
0xAA
;
/* write data 0xAA to the address */
Temp
=
bios
+
0x5555
;
/* set up address to be C000:5555h */
*
Temp
=
0xAA
;
/* write data 0xAA to the address */
myusec_delay
(
10
);
Temp
=
bios
+
0x2AAA
;
/* set up address to be C000:2AAAh */
*
Temp
=
0x55
;
/* write data 0x55 to the address */
Temp
=
bios
+
0x2AAA
;
/* set up address to be C000:2AAAh */
*
Temp
=
0x55
;
/* write data 0x55 to the address */
myusec_delay
(
10
);
Temp
=
bios
+
0x5555
;
/* set up address to be C000:5555h */
*
Temp
=
0x80
;
/* write data 0x80 to the address */
Temp
=
bios
+
0x5555
;
/* set up address to be C000:5555h */
*
Temp
=
0x80
;
/* write data 0x80 to the address */
myusec_delay
(
10
);
Temp
=
bios
+
0x5555
;
/* set up address to be C000:5555h */
*
Temp
=
0xAA
;
/* write data 0xAA to the address */
Temp
=
bios
+
0x5555
;
/* set up address to be C000:5555h */
*
Temp
=
0xAA
;
/* write data 0xAA to the address */
myusec_delay
(
10
);
Temp
=
bios
+
0x2AAA
;
/* set up address to be C000:2AAAh */
*
Temp
=
0x55
;
/* write data 0x55 to the address */
Temp
=
bios
+
0x2AAA
;
/* set up address to be C000:2AAAh */
*
Temp
=
0x55
;
/* write data 0x55 to the address */
myusec_delay
(
10
);
Temp
=
bios
+
address
;
/* set up address to be C000:5555h */
*
Temp
=
0x50
;
/* write data 0x5
5
to the address */
Temp
=
bios
+
address
;
/* set up address to be C000:5555h */
*
Temp
=
0x50
;
/* write data 0x5
0
to the address */
/* wait for Toggle bit ready */
toggle_ready_jedec
(
bios
);
...
...
@@ -95,66 +95,6 @@ static __inline__ int write_block_49fl004(volatile char * bios,
return
(
0
);
}
int
probe_49fl004
(
struct
flashchip
*
flash
)
{
volatile
char
*
bios
=
flash
->
virt_addr
;
unsigned
char
id1
,
id2
;
*
(
volatile
char
*
)
(
bios
+
0x5555
)
=
0xAA
;
myusec_delay
(
10
);
*
(
volatile
char
*
)
(
bios
+
0x2AAA
)
=
0x55
;
myusec_delay
(
10
);
*
(
volatile
char
*
)
(
bios
+
0x5555
)
=
0x90
;
myusec_delay
(
10
);
id1
=
*
(
volatile
unsigned
char
*
)
bios
;
id2
=
*
(
volatile
unsigned
char
*
)
(
bios
+
0x01
);
*
(
volatile
char
*
)
(
bios
+
0x5555
)
=
0xAA
;
*
(
volatile
char
*
)
(
bios
+
0x2AAA
)
=
0x55
;
*
(
volatile
char
*
)
(
bios
+
0x5555
)
=
0xF0
;
myusec_delay
(
10
);
printf
(
"%s: id1 0x%x, id2 0x%x
\n
"
,
__FUNCTION__
,
id1
,
id2
);
if
(
id1
==
flash
->
manufacture_id
&&
id2
==
flash
->
model_id
)
return
1
;
return
0
;
}
int
erase_49fl004
(
struct
flashchip
*
flash
)
{
volatile
unsigned
char
*
bios
=
flash
->
virt_addr
;
volatile
unsigned
char
*
Temp
;
Temp
=
bios
+
0x5555
;
/* set up address to be C000:5555h */
*
Temp
=
0xAA
;
/* write data 0xAA to the address */
myusec_delay
(
10
);
Temp
=
bios
+
0x2AAA
;
/* set up address to be C000:2AAAh */
*
Temp
=
0x55
;
/* write data 0x55 to the address */
myusec_delay
(
10
);
Temp
=
bios
+
0x5555
;
/* set up address to be C000:5555h */
*
Temp
=
0x80
;
/* write data 0x80 to the address */
myusec_delay
(
10
);
Temp
=
bios
+
0x5555
;
/* set up address to be C000:5555h */
*
Temp
=
0xAA
;
/* write data 0xAA to the address */
myusec_delay
(
10
);
Temp
=
bios
+
0x2AAA
;
/* set up address to be C000:2AAAh */
*
Temp
=
0x55
;
/* write data 0x55 to the address */
myusec_delay
(
10
);
Temp
=
bios
+
0x5555
;
/* set up address to be C000:5555h */
*
Temp
=
0x10
;
/* write data 0x10 to the address */
/* wait for Toggle bit ready */
toggle_ready_jedec
(
bios
);
return
(
0
);
}
int
write_49fl004
(
struct
flashchip
*
flash
,
unsigned
char
*
buf
)
{
int
i
;
...
...
This diff is collapsed.
Click to expand it.
sst39sf020.c
View file @
73eca80d
...
...
@@ -50,108 +50,13 @@ static __inline__ int erase_sector_39sf020 (volatile char * bios, unsigned long
return
(
0
);
}
static
__inline__
int
write_sector_39sf020
(
volatile
char
*
bios
,
unsigned
char
*
src
,
volatile
unsigned
char
*
dst
,
unsigned
int
page_size
)
{
int
i
;
volatile
char
*
Temp
;
for
(
i
=
0
;
i
<
page_size
;
i
++
)
{
if
(
*
dst
!=
0xff
)
{
printf
(
"FATAL: dst %p not erased (val 0x%x
\n
"
,
dst
,
*
dst
);
return
(
-
1
);
}
/* transfer data from source to destination */
if
(
*
src
==
0xFF
)
{
dst
++
,
src
++
;
/* If the data is 0xFF, don't program it */
continue
;
}
Temp
=
(
bios
+
0x5555
);
*
Temp
=
0xAA
;
Temp
=
bios
+
0x2AAA
;
*
Temp
=
0x55
;
Temp
=
bios
+
0x5555
;
*
Temp
=
0xA0
;
*
dst
=
*
src
;
toggle_ready_jedec
(
bios
);
if
(
*
dst
!=
*
src
)
printf
(
"BAD! dst 0x%lx val 0x%x src 0x%x
\n
"
,
(
unsigned
long
)
dst
,
*
dst
,
*
src
);
dst
++
,
src
++
;
}
return
(
0
);
}
int
probe_39sf020
(
struct
flashchip
*
flash
)
{
volatile
char
*
bios
=
flash
->
virt_addr
;
unsigned
char
id1
,
id2
;
*
(
volatile
char
*
)
(
bios
+
0x5555
)
=
0xAA
;
myusec_delay
(
10
);
*
(
volatile
char
*
)
(
bios
+
0x2AAA
)
=
0x55
;
myusec_delay
(
10
);
*
(
volatile
char
*
)
(
bios
+
0x5555
)
=
0x90
;
myusec_delay
(
10
);
id1
=
*
(
volatile
unsigned
char
*
)
bios
;
id2
=
*
(
volatile
unsigned
char
*
)
(
bios
+
0x01
);
*
(
volatile
char
*
)
(
bios
+
0x5555
)
=
0xAA
;
*
(
volatile
char
*
)
(
bios
+
0x2AAA
)
=
0x55
;
*
(
volatile
char
*
)
(
bios
+
0x5555
)
=
0xF0
;
myusec_delay
(
10
);
printf
(
"%s: id1 0x%x, id2 0x%x
\n
"
,
__FUNCTION__
,
id1
,
id2
);
if
(
id1
==
flash
->
manufacture_id
&&
id2
==
flash
->
model_id
)
return
1
;
return
0
;
}
int
erase_39sf020
(
struct
flashchip
*
flash
)
{
volatile
unsigned
char
*
bios
=
flash
->
virt_addr
;
volatile
unsigned
char
*
Temp
;
/* Issue the Sector Erase command to 39SF020 */
Temp
=
bios
+
0x5555
;
/* set up address to be C000:5555h */
*
Temp
=
0xAA
;
/* write data 0xAA to the address */
myusec_delay
(
10
);
Temp
=
bios
+
0x2AAA
;
/* set up address to be C000:2AAAh */
*
Temp
=
0x55
;
/* write data 0x55 to the address */
myusec_delay
(
10
);
Temp
=
bios
+
0x5555
;
/* set up address to be C000:5555h */
*
Temp
=
0x80
;
/* write data 0x80 to the address */
myusec_delay
(
10
);
Temp
=
bios
+
0x5555
;
/* set up address to be C000:5555h */
*
Temp
=
0xAA
;
/* write data 0xAA to the address */
myusec_delay
(
10
);
Temp
=
bios
+
0x2AAA
;
/* set up address to be C000:2AAAh */
*
Temp
=
0x55
;
/* write data 0x55 to the address */
myusec_delay
(
10
);
Temp
=
bios
+
0x5555
;
/* set up address to be C000:5555h */
*
Temp
=
0x10
;
/* write data 0x55 to the address */
myusec_delay
(
50000
);
return
(
0
);
}
int
write_39sf020
(
struct
flashchip
*
flash
,
unsigned
char
*
buf
)
{
int
i
;
int
total_size
=
flash
->
total_size
*
1024
,
page_size
=
flash
->
page_size
;
volatile
char
*
bios
=
flash
->
virt_addr
;
erase_
39sf020
(
flash
);
erase_
jedec
(
flash
);
printf
(
"Programming Page: "
);
for
(
i
=
0
;
i
<
total_size
/
page_size
;
i
++
)
{
...
...
@@ -160,7 +65,7 @@ int write_39sf020 (struct flashchip * flash, unsigned char * buf)
/* write to the sector */
printf
(
"%04d at address: 0x%08x"
,
i
,
i
*
page_size
);
write_sector_
39sf020
(
bios
,
buf
+
i
*
page_size
,
bios
+
i
*
page_size
,
write_sector_
jedec
(
bios
,
buf
+
i
*
page_size
,
bios
+
i
*
page_size
,
page_size
);
printf
(
"
\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b
"
);
fflush
(
stdout
);
...
...
This diff is collapsed.
Click to expand it.
sst39sf020.h
View file @
73eca80d
...
...
@@ -2,7 +2,6 @@
#define __SST39SF020_H__ 1
extern
int
probe_39sf020
(
struct
flashchip
*
flash
);
extern
int
erase_39sf020
(
struct
flashchip
*
flash
);
extern
int
write_39sf020
(
struct
flashchip
*
flash
,
unsigned
char
*
buf
);
#endif
/* !__SST39SF020_H__ */
This diff is collapsed.
Click to expand it.
sst49lf040.c
View file @
73eca80d
...
...
@@ -37,131 +37,6 @@
#define RESET 0xFF
#define READ_ID 0x90
static
int
erase_sector_49lf040
(
volatile
char
*
bios
,
unsigned
int
page
)
{
/* Chip erase function does not exist for LPC mode on 49lf040.
* Erase sector-by-sector instead. */
volatile
unsigned
char
*
Temp
;
/* Issue the Sector Erase command to 40LF040 */
Temp
=
bios
+
0x5555
;
/* set up address to be C000:5555h */
*
Temp
=
0xAA
;
/* write data 0xAA to the address */
myusec_delay
(
10
);
Temp
=
bios
+
0x2AAA
;
/* set up address to be C000:2AAAh */
*
Temp
=
0x55
;
/* write data 0x55 to the address */
myusec_delay
(
10
);
Temp
=
bios
+
0x5555
;
/* set up address to be C000:5555h */
*
Temp
=
0x80
;
/* write data 0x80 to the address */
myusec_delay
(
10
);
Temp
=
bios
+
0x5555
;
/* set up address to be C000:5555h */
*
Temp
=
0xAA
;
/* write data 0xAA to the address */
myusec_delay
(
10
);
Temp
=
bios
+
0x2AAA
;
/* set up address to be C000:2AAAh */
*
Temp
=
0x55
;
/* write data 0x55 to the address */
myusec_delay
(
10
);
Temp
=
bios
+
page
;
/* set up address to be the current sector */
*
Temp
=
0x30
;
/* write data 0x30 to the address */
/* wait for Toggle bit ready */
toggle_ready_jedec
(
bios
);
return
(
0
);
}
static
__inline__
int
write_sector_49lf040
(
volatile
char
*
bios
,
unsigned
char
*
src
,
volatile
unsigned
char
*
dst
,
unsigned
int
page_size
)
{
int
i
;
volatile
char
*
Temp
;
for
(
i
=
0
;
i
<
page_size
;
i
++
)
{
if
(
*
dst
!=
0xff
)
{
printf
(
"FATAL: dst %p not erased (val 0x%x)
\n
"
,
dst
,
*
dst
);
return
(
-
1
);
}
/* transfer data from source to destination */
if
(
*
src
==
0xFF
)
{
dst
++
,
src
++
;
/* If the data is 0xFF, don't program it */
continue
;
}
Temp
=
(
bios
+
0x5555
);
*
Temp
=
0xAA
;
Temp
=
bios
+
0x2AAA
;
*
Temp
=
0x55
;
Temp
=
bios
+
0x5555
;
*
Temp
=
0xA0
;
*
dst
=
*
src
;
toggle_ready_jedec
(
bios
);
if
(
*
dst
!=
*
src
)
printf
(
"BAD! dst 0x%lx val 0x%x src 0x%x
\n
"
,
(
unsigned
long
)
dst
,
*
dst
,
*
src
);
dst
++
,
src
++
;
}
return
(
0
);
}
int
probe_49lf040
(
struct
flashchip
*
flash
)
{
volatile
char
*
bios
=
flash
->
virt_addr
;
unsigned
char
id1
,
id2
;
*
(
volatile
char
*
)
(
bios
+
0x5555
)
=
0xAA
;
myusec_delay
(
10
);
*
(
volatile
char
*
)
(
bios
+
0x2AAA
)
=
0x55
;
myusec_delay
(
10
);
*
(
volatile
char
*
)
(
bios
+
0x5555
)
=
0x90
;
myusec_delay
(
10
);
id1
=
*
(
volatile
unsigned
char
*
)
bios
;
id2
=
*
(
volatile
unsigned
char
*
)
(
bios
+
0x01
);
*
(
volatile
char
*
)
(
bios
+
0x5555
)
=
0xAA
;
*
(
volatile
char
*
)
(
bios
+
0x2AAA
)
=
0x55
;
*
(
volatile
char
*
)
(
bios
+
0x5555
)
=
0xF0
;
myusec_delay
(
10
);
printf
(
"%s: id1 0x%x, id2 0x%x
\n
"
,
__FUNCTION__
,
id1
,
id2
);
if
(
id1
==
flash
->
manufacture_id
&&
id2
==
flash
->
model_id
)
return
1
;
return
0
;
}
/* Chip erase only works in parallel programming mode for the 49lf040.
* Use sector-erase instead */
int
erase_49lf040
(
struct
flashchip
*
flash
)
{
volatile
unsigned
char
*
bios
=
flash
->
virt_addr
;
volatile
unsigned
char
*
Temp
;
/* Issue the Sector Erase command to 40LF040 */
Temp
=
bios
+
0x5555
;
/* set up address to be C000:5555h */
*
Temp
=
0xAA
;
/* write data 0xAA to the address */
myusec_delay
(
10
);
Temp
=
bios
+
0x2AAA
;
/* set up address to be C000:2AAAh */
*
Temp
=
0x55
;
/* write data 0x55 to the address */
myusec_delay
(
10
);
Temp
=
bios
+
0x5555
;
/* set up address to be C000:5555h */
*
Temp
=
0x80
;
/* write data 0x80 to the address */
myusec_delay
(
10
);
Temp
=
bios
+
0x5555
;
/* set up address to be C000:5555h */
*
Temp
=
0xAA
;
/* write data 0xAA to the address */
myusec_delay
(
10
);
Temp
=
bios
+
0x2AAA
;
/* set up address to be C000:2AAAh */
*
Temp
=
0x55
;
/* write data 0x55 to the address */
myusec_delay
(
10
);
Temp
=
bios
+
0x5555
;
/* set up address to be C000:5555h */
*
Temp
=
0x10
;
/* write data 0x55 to the address */
myusec_delay
(
50000
);
return
(
0
);
}
int
write_49lf040
(
struct
flashchip
*
flash
,
unsigned
char
*
buf
)
{
...
...
@@ -171,13 +46,15 @@ int write_49lf040 (struct flashchip * flash, unsigned char * buf)
printf
(
"Programming Page: "
);
for
(
i
=
0
;
i
<
total_size
/
page_size
;
i
++
)
{
/* erase the page before programming */
erase_sector_49lf040
(
bios
,
i
*
page_size
);
/* erase the page before programming
* Chip erase only works in parallel programming mode for the 49lf040.
* Use sector-erase instead */
erase_sector_jedec
(
bios
,
i
*
page_size
);
/* write to the sector */
printf
(
"%04d at address: 0x%08x "
,
i
,
i
*
page_size
);
write_sector_
49lf040
(
bios
,
buf
+
i
*
page_size
,
bios
+
i
*
page_size
,
page_size
);
write_sector_
jedec
(
bios
,
buf
+
i
*
page_size
,
bios
+
i
*
page_size
,
page_size
);
printf
(
"
\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b
"
);
fflush
(
stdout
);
}
...
...
This diff is collapsed.
Click to expand it.
w49f002u.c
View file @
73eca80d
...
...
@@ -32,49 +32,6 @@
#include "jedec.h"
#include "w49f002u.h"
int
probe_49f002
(
struct
flashchip
*
flash
)
{
volatile
char
*
bios
=
flash
->
virt_addr
;
unsigned
char
id1
,
id2
;
*
(
volatile
char
*
)
(
bios
+
0x5555
)
=
0xAA
;
*
(
volatile
char
*
)
(
bios
+
0x2AAA
)
=
0x55
;
*
(
volatile
char
*
)
(
bios
+
0x5555
)
=
0x90
;
id1
=
*
(
volatile
unsigned
char
*
)
bios
;
id2
=
*
(
volatile
unsigned
char
*
)
(
bios
+
0x01
);
*
(
volatile
char
*
)
(
bios
+
0x5555
)
=
0xAA
;
*
(
volatile
char
*
)
(
bios
+
0x2AAA
)
=
0x55
;
*
(
volatile
char
*
)
(
bios
+
0x5555
)
=
0xF0
;
myusec_delay
(
10
);
printf
(
"%s: id1 0x%x, id2 0x%x
\n
"
,
__FUNCTION__
,
id1
,
id2
);
if
(
id1
==
flash
->
manufacture_id
&&
id2
==
flash
->
model_id
)
return
1
;
return
0
;
}
int
erase_49f002
(
struct
flashchip
*
flash
)
{
volatile
char
*
bios
=
flash
->
virt_addr
;
*
(
bios
+
0x5555
)
=
0xAA
;
*
(
bios
+
0x2AAA
)
=
0x55
;
*
(
bios
+
0x5555
)
=
0x80
;
*
(
bios
+
0x5555
)
=
0xAA
;
*
(
bios
+
0x2AAA
)
=
0x55
;
*
(
bios
+
0x5555
)
=
0x10
;
myusec_delay
(
100
);
toggle_ready_jedec
(
bios
);
return
(
0
);
}
int
write_49f002
(
struct
flashchip
*
flash
,
unsigned
char
*
buf
)
{
int
i
;
...
...
@@ -82,7 +39,7 @@ int write_49f002 (struct flashchip * flash, unsigned char * buf)
volatile
char
*
bios
=
flash
->
virt_addr
;
volatile
char
*
dst
=
bios
;
erase_
49f002
(
flash
);
erase_
jedec
(
flash
);
printf
(
"Programming Page: "
);
for
(
i
=
0
;
i
<
total_size
;
i
++
)
{
...
...
This diff is collapsed.
Click to expand it.
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
.
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment