@ -41,34 +41,34 @@
# include <std/mic.h>
# include "flash.h"
# include " chain .h"
# include " bus .h"
static int intel_flash_erase_block ( chain_t * chain , uint32_t adr ) ;
static int intel_flash_unlock_block ( chain_t * chain , uint32_t adr ) ;
static int intel_flash_program ( chain_t * chain , uint32_t adr , uint32_t data ) ;
static int intel_flash_erase_block32 ( chain_t * chain , uint32_t adr ) ;
static int intel_flash_unlock_block32 ( chain_t * chain , uint32_t adr ) ;
static int intel_flash_program32 ( chain_t * chain , uint32_t adr , uint32_t data ) ;
static int intel_flash_erase_block ( bus_t * bus , uint32_t adr ) ;
static int intel_flash_unlock_block ( bus_t * bus , uint32_t adr ) ;
static int intel_flash_program ( bus_t * bus , uint32_t adr , uint32_t data ) ;
static int intel_flash_erase_block32 ( bus_t * bus , uint32_t adr ) ;
static int intel_flash_unlock_block32 ( bus_t * bus , uint32_t adr ) ;
static int intel_flash_program32 ( bus_t * bus , uint32_t adr , uint32_t data ) ;
/* autodetect, we can handle this chip */
static int
intel_flash_autodetect32 ( chain_t * chain , cfi_query_structure_t * cfi )
intel_flash_autodetect32 ( bus_t * bus , cfi_query_structure_t * cfi )
{
return ( cfi - > identification_string . pri_id_code = = CFI_VENDOR_INTEL_ECS ) & & ( bus_width ( chain ) = = 32 ) ;
return ( cfi - > identification_string . pri_id_code = = CFI_VENDOR_INTEL_ECS ) & & ( bus_width ( bus ) = = 32 ) ;
}
static int
intel_flash_autodetect ( chain_t * chain , cfi_query_structure_t * cfi )
intel_flash_autodetect ( bus_t * bus , cfi_query_structure_t * cfi )
{
return ( cfi - > identification_string . pri_id_code = = CFI_VENDOR_INTEL_ECS ) & & ( bus_width ( chain ) = = 16 ) ;
return ( cfi - > identification_string . pri_id_code = = CFI_VENDOR_INTEL_ECS ) & & ( bus_width ( bus ) = = 16 ) ;
}
static
void _intel_flash_print_info ( chain_t * chain , int o )
static void
_intel_flash_print_info ( bus_t * bus , int o )
{
uint32_t mid , cid ;
mid = ( bus_read ( chain , 0x00 < < o ) & 0xFF ) ;
mid = ( bus_read ( bus , 0x00 < < o ) & 0xFF ) ;
switch ( mid ) {
case STD_MIC_INTEL :
printf ( " Manufacturer: %s \n " , STD_MICN_INTEL ) ;
@ -79,7 +79,7 @@ void _intel_flash_print_info( chain_t *chain, int o )
}
printf ( " Chip: " ) ;
cid = ( bus_read ( chain , 0x01 < < o ) & 0xFFFF ) ;
cid = ( bus_read ( bus , 0x01 < < o ) & 0xFFFF ) ;
switch ( cid ) {
case 0x0016 :
printf ( " 28F320J3A \n " ) ;
@ -114,51 +114,51 @@ void _intel_flash_print_info( chain_t *chain, int o )
}
/* Read Array */
bus_write ( chain , 0 < < o , 0x00FF00FF ) ;
bus_write ( bus , 0 < < o , 0x00FF00FF ) ;
}
static
void intel_flash_print_info ( chain_t * chain )
static void
intel_flash_print_info ( bus_t * bus )
{
int o = 1 ;
/* Intel Primary Algorithm Extended Query Table - see Table 5. in [3] */
/* TODO */
/* Clear Status Register */
bus_write ( chain , 0 < < o , 0x0050 ) ;
bus_write ( bus , 0 < < o , 0x0050 ) ;
/* Read Identifier Command */
bus_write ( chain , 0 < < 0 , 0x0090 ) ;
bus_write ( bus , 0 < < 0 , 0x0090 ) ;
_intel_flash_print_info ( chain , o ) ;
_intel_flash_print_info ( bus , o ) ;
}
static
void intel_flash_print_info32 ( chain_t * chain )
static void
intel_flash_print_info32 ( bus_t * bus )
{
int o = 2 ;
/* Intel Primary Algorithm Extended Query Table - see Table 5. in [3] */
/* TODO */
/* Clear Status Register */
bus_write ( chain , 0 < < o , 0x00500050 ) ;
bus_write ( bus , 0 < < o , 0x00500050 ) ;
/* Read Identifier Command */
bus_write ( chain , 0 < < 0 , 0x00900090 ) ;
bus_write ( bus , 0 < < 0 , 0x00900090 ) ;
_intel_flash_print_info ( chain , o ) ;
_intel_flash_print_info ( bus , o ) ;
}
static int
intel_flash_erase_block ( chain_t * chain , uint32_t adr )
intel_flash_erase_block ( bus_t * bus , uint32_t adr )
{
uint16_t sr ;
bus_write ( chain , 0 , CFI_INTEL_CMD_CLEAR_STATUS_REGISTER ) ;
bus_write ( chain , adr , CFI_INTEL_CMD_BLOCK_ERASE ) ;
bus_write ( chain , adr , CFI_INTEL_CMD_CONFIRM ) ;
bus_write ( bus , 0 , CFI_INTEL_CMD_CLEAR_STATUS_REGISTER ) ;
bus_write ( bus , adr , CFI_INTEL_CMD_BLOCK_ERASE ) ;
bus_write ( bus , adr , CFI_INTEL_CMD_CONFIRM ) ;
while ( ! ( ( sr = bus_read ( chain , 0 ) & 0xFE ) & CFI_INTEL_SR_READY ) ) ; /* TODO: add timeout */
while ( ! ( ( sr = bus_read ( bus , 0 ) & 0xFE ) & CFI_INTEL_SR_READY ) ) ; /* TODO: add timeout */
switch ( sr & ~ CFI_INTEL_SR_READY ) {
case 0 :
@ -180,15 +180,15 @@ intel_flash_erase_block( chain_t *chain, uint32_t adr )
}
static int
intel_flash_unlock_block ( chain_t * chain , uint32_t adr )
intel_flash_unlock_block ( bus_t * bus , uint32_t adr )
{
uint16_t sr ;
bus_write ( chain , 0 , CFI_INTEL_CMD_CLEAR_STATUS_REGISTER ) ;
bus_write ( chain , adr , CFI_INTEL_CMD_LOCK_SETUP ) ;
bus_write ( chain , adr , CFI_INTEL_CMD_UNLOCK_BLOCK ) ;
bus_write ( bus , 0 , CFI_INTEL_CMD_CLEAR_STATUS_REGISTER ) ;
bus_write ( bus , adr , CFI_INTEL_CMD_LOCK_SETUP ) ;
bus_write ( bus , adr , CFI_INTEL_CMD_UNLOCK_BLOCK ) ;
while ( ! ( ( sr = bus_read ( chain , 0 ) & 0xFE ) & CFI_INTEL_SR_READY ) ) ; /* TODO: add timeout */
while ( ! ( ( sr = bus_read ( bus , 0 ) & 0xFE ) & CFI_INTEL_SR_READY ) ) ; /* TODO: add timeout */
if ( sr ! = CFI_INTEL_SR_READY ) {
printf ( " flash: unknown error while unblocking \n " ) ;
@ -198,15 +198,15 @@ intel_flash_unlock_block( chain_t *chain, uint32_t adr )
}
static int
intel_flash_program ( chain_t * chain , uint32_t adr , uint32_t data )
intel_flash_program ( bus_t * bus , uint32_t adr , uint32_t data )
{
uint16_t sr ;
bus_write ( chain , 0 , CFI_INTEL_CMD_CLEAR_STATUS_REGISTER ) ;
bus_write ( chain , adr , CFI_INTEL_CMD_PROGRAM1 ) ;
bus_write ( chain , adr , data ) ;
bus_write ( bus , 0 , CFI_INTEL_CMD_CLEAR_STATUS_REGISTER ) ;
bus_write ( bus , adr , CFI_INTEL_CMD_PROGRAM1 ) ;
bus_write ( bus , adr , data ) ;
while ( ! ( ( sr = bus_read ( chain , 0 ) & 0xFE ) & CFI_INTEL_SR_READY ) ) ; /* TODO: add timeout */
while ( ! ( ( sr = bus_read ( bus , 0 ) & 0xFE ) & CFI_INTEL_SR_READY ) ) ; /* TODO: add timeout */
if ( sr ! = CFI_INTEL_SR_READY ) {
printf ( " flash: unknown error while programming \n " ) ;
@ -216,15 +216,15 @@ intel_flash_program( chain_t *chain, uint32_t adr, uint32_t data )
}
static int
intel_flash_erase_block32 ( chain_t * chain , uint32_t adr )
intel_flash_erase_block32 ( bus_t * bus , uint32_t adr )
{
uint32_t sr ;
bus_write ( chain , 0 , ( CFI_INTEL_CMD_CLEAR_STATUS_REGISTER < < 16 ) | CFI_INTEL_CMD_CLEAR_STATUS_REGISTER ) ;
bus_write ( chain , adr , ( CFI_INTEL_CMD_BLOCK_ERASE < < 16 ) | CFI_INTEL_CMD_BLOCK_ERASE ) ;
bus_write ( chain , adr , ( CFI_INTEL_CMD_CONFIRM < < 16 ) | CFI_INTEL_CMD_CONFIRM ) ;
bus_write ( bus , 0 , ( CFI_INTEL_CMD_CLEAR_STATUS_REGISTER < < 16 ) | CFI_INTEL_CMD_CLEAR_STATUS_REGISTER ) ;
bus_write ( bus , adr , ( CFI_INTEL_CMD_BLOCK_ERASE < < 16 ) | CFI_INTEL_CMD_BLOCK_ERASE ) ;
bus_write ( bus , adr , ( CFI_INTEL_CMD_CONFIRM < < 16 ) | CFI_INTEL_CMD_CONFIRM ) ;
while ( ( ( sr = bus_read ( chain , 0 ) & 0x00FE00FE ) & ( ( CFI_INTEL_SR_READY < < 16 ) | CFI_INTEL_SR_READY ) ) ! = ( ( CFI_INTEL_SR_READY < < 16 ) | CFI_INTEL_SR_READY ) ) ; /* TODO: add timeout */
while ( ( ( sr = bus_read ( bus , 0 ) & 0x00FE00FE ) & ( ( CFI_INTEL_SR_READY < < 16 ) | CFI_INTEL_SR_READY ) ) ! = ( ( CFI_INTEL_SR_READY < < 16 ) | CFI_INTEL_SR_READY ) ) ; /* TODO: add timeout */
if ( sr ! = ( ( CFI_INTEL_SR_READY < < 16 ) | CFI_INTEL_SR_READY ) ) {
printf ( " \n sr = 0x%08X \n " , sr ) ;
@ -234,15 +234,15 @@ intel_flash_erase_block32( chain_t *chain, uint32_t adr )
}
static int
intel_flash_unlock_block32 ( chain_t * chain , uint32_t adr )
intel_flash_unlock_block32 ( bus_t * bus , uint32_t adr )
{
uint32_t sr ;
bus_write ( chain , 0 , ( CFI_INTEL_CMD_CLEAR_STATUS_REGISTER < < 16 ) | CFI_INTEL_CMD_CLEAR_STATUS_REGISTER ) ;
bus_write ( chain , adr , ( CFI_INTEL_CMD_LOCK_SETUP < < 16 ) | CFI_INTEL_CMD_LOCK_SETUP ) ;
bus_write ( chain , adr , ( CFI_INTEL_CMD_UNLOCK_BLOCK < < 16 ) | CFI_INTEL_CMD_UNLOCK_BLOCK ) ;
bus_write ( bus , 0 , ( CFI_INTEL_CMD_CLEAR_STATUS_REGISTER < < 16 ) | CFI_INTEL_CMD_CLEAR_STATUS_REGISTER ) ;
bus_write ( bus , adr , ( CFI_INTEL_CMD_LOCK_SETUP < < 16 ) | CFI_INTEL_CMD_LOCK_SETUP ) ;
bus_write ( bus , adr , ( CFI_INTEL_CMD_UNLOCK_BLOCK < < 16 ) | CFI_INTEL_CMD_UNLOCK_BLOCK ) ;
while ( ( ( sr = bus_read ( chain , 0 ) & 0x00FE00FE ) & ( ( CFI_INTEL_SR_READY < < 16 ) | CFI_INTEL_SR_READY ) ) ! = ( ( CFI_INTEL_SR_READY < < 16 ) | CFI_INTEL_SR_READY ) ) ; /* TODO: add timeout */
while ( ( ( sr = bus_read ( bus , 0 ) & 0x00FE00FE ) & ( ( CFI_INTEL_SR_READY < < 16 ) | CFI_INTEL_SR_READY ) ) ! = ( ( CFI_INTEL_SR_READY < < 16 ) | CFI_INTEL_SR_READY ) ) ; /* TODO: add timeout */
if ( sr ! = ( ( CFI_INTEL_SR_READY < < 16 ) | CFI_INTEL_SR_READY ) ) {
printf ( " \n sr = 0x%08X \n " , sr ) ;
@ -252,15 +252,15 @@ intel_flash_unlock_block32( chain_t *chain, uint32_t adr )
}
static int
intel_flash_program32 ( chain_t * chain , uint32_t adr , uint32_t data )
intel_flash_program32 ( bus_t * bus , uint32_t adr , uint32_t data )
{
uint32_t sr ;
bus_write ( chain , 0 , ( CFI_INTEL_CMD_CLEAR_STATUS_REGISTER < < 16 ) | CFI_INTEL_CMD_CLEAR_STATUS_REGISTER ) ;
bus_write ( chain , adr , ( CFI_INTEL_CMD_PROGRAM1 < < 16 ) | CFI_INTEL_CMD_PROGRAM1 ) ;
bus_write ( chain , adr , data ) ;
bus_write ( bus , 0 , ( CFI_INTEL_CMD_CLEAR_STATUS_REGISTER < < 16 ) | CFI_INTEL_CMD_CLEAR_STATUS_REGISTER ) ;
bus_write ( bus , adr , ( CFI_INTEL_CMD_PROGRAM1 < < 16 ) | CFI_INTEL_CMD_PROGRAM1 ) ;
bus_write ( bus , adr , data ) ;
while ( ( ( sr = bus_read ( chain , 0 ) & 0x00FE00FE ) & ( ( CFI_INTEL_SR_READY < < 16 ) | CFI_INTEL_SR_READY ) ) ! = ( ( CFI_INTEL_SR_READY < < 16 ) | CFI_INTEL_SR_READY ) ) ; /* TODO: add timeout */
while ( ( ( sr = bus_read ( bus , 0 ) & 0x00FE00FE ) & ( ( CFI_INTEL_SR_READY < < 16 ) | CFI_INTEL_SR_READY ) ) ! = ( ( CFI_INTEL_SR_READY < < 16 ) | CFI_INTEL_SR_READY ) ) ; /* TODO: add timeout */
if ( sr ! = ( ( CFI_INTEL_SR_READY < < 16 ) | CFI_INTEL_SR_READY ) ) {
printf ( " \n sr = 0x%08X \n " , sr ) ;
@ -270,17 +270,17 @@ intel_flash_program32( chain_t *chain, uint32_t adr, uint32_t data )
}
static void
intel_flash_readarray32 ( chain_t * chain )
intel_flash_readarray32 ( bus_t * bus )
{
/* Read Array */
bus_write ( chain , 0 , 0x00FF00FF ) ;
bus_write ( bus , 0 , 0x00FF00FF ) ;
}
static void
intel_flash_readarray ( chain_t * chain )
intel_flash_readarray ( bus_t * bus )
{
/* Read Array */
bus_write ( chain , 0 , 0x00FF00FF ) ;
bus_write ( bus , 0 , 0x00FF00FF ) ;
}
flash_driver_t intel_32_flash_driver = {