From 6dc4871e5a2b48f2c17c7b2fc90f001be10d9df2 Mon Sep 17 00:00:00 2001 From: Marcel Telka Date: Thu, 12 Jun 2003 12:55:10 +0000 Subject: [PATCH] 2003-06-12 Marcel Telka * flash/amd.c (amd_flash_autodetect, amd_flash_print_info, amd_flash_erase_block) (amd_flash_unlock_block, amd_flash_program, amd_flash_read_array): Modified for new flash_driver_t declared in brux/flash.h in include module. * flash/intel.c (intel_flash_autodetect32, intel_flash_autodetect, intel_flash_print_info) (intel_flash_print_info32, intel_flash_erase_block, intel_flash_unlock_block, intel_flash_program) (intel_flash_erase_block32, intel_flash_unlock_block32, intel_flash_program32, intel_flash_readarray32) (intel_flash_readarray): Ditto. git-svn-id: https://urjtag.svn.sourceforge.net/svnroot/urjtag/trunk@483 b68d4a1b-bc3d-0410-92ed-d4ac073336b7 --- libbrux/ChangeLog | 10 ++++++++ libbrux/flash/amd.c | 35 ++++++++++++++++------------ libbrux/flash/intel.c | 54 +++++++++++++++++++++++++------------------ 3 files changed, 62 insertions(+), 37 deletions(-) diff --git a/libbrux/ChangeLog b/libbrux/ChangeLog index 1b9926e1..3aefea9f 100644 --- a/libbrux/ChangeLog +++ b/libbrux/ChangeLog @@ -1,3 +1,13 @@ +2003-06-12 Marcel Telka + + * flash/amd.c (amd_flash_autodetect, amd_flash_print_info, amd_flash_erase_block) + (amd_flash_unlock_block, amd_flash_program, amd_flash_read_array): Modified for new flash_driver_t + declared in brux/flash.h in include module. + * flash/intel.c (intel_flash_autodetect32, intel_flash_autodetect, intel_flash_print_info) + (intel_flash_print_info32, intel_flash_erase_block, intel_flash_unlock_block, intel_flash_program) + (intel_flash_erase_block32, intel_flash_unlock_block32, intel_flash_program32, intel_flash_readarray32) + (intel_flash_readarray): Ditto. + 2003-06-10 Marcel Telka * flash/amd.c: Changed include header files. diff --git a/libbrux/flash/amd.c b/libbrux/flash/amd.c index e15ff2f4..5f5f8858 100644 --- a/libbrux/flash/amd.c +++ b/libbrux/flash/amd.c @@ -20,6 +20,7 @@ * 02111-1307, USA. * * Written by August Hörandl + * Modified by Marcel Telka , 2003. * * Documentation: * [1] Advanced Micro Devices, "Am29LV640D/Am29LV641D", @@ -40,21 +41,22 @@ #include #include +#include #include "flash.h" static int dbg = 0; -static int amd_flash_erase_block( bus_t *bus, uint32_t adr ); -static int amd_flash_unlock_block( bus_t *bus, uint32_t adr ); -static int amd_flash_program( bus_t *bus, uint32_t adr, uint32_t data ); -static void amd_flash_read_array( bus_t *bus ); +static int amd_flash_erase_block( cfi_array_t *cfi_array, uint32_t adr ); +static int amd_flash_unlock_block( cfi_array_t *cfi_array, uint32_t adr ); +static int amd_flash_program( cfi_array_t *cfi_array, uint32_t adr, uint32_t data ); +static void amd_flash_read_array( cfi_array_t *cfi_array ); /* autodetect, we can handle this chip */ static int -amd_flash_autodetect( bus_t *bus, cfi_query_structure_t *cfi ) +amd_flash_autodetect( cfi_array_t *cfi_array ) { - return (cfi->identification_string.pri_id_code == CFI_VENDOR_AMD_SCS); + return (cfi_array->cfi_chips[0]->cfi.identification_string.pri_id_code == CFI_VENDOR_AMD_SCS); } /* @@ -147,10 +149,11 @@ amdisprotected( parts *ps, uint32_t adr ) #endif /* 0 */ static void -amd_flash_print_info( bus_t *bus ) +amd_flash_print_info( cfi_array_t *cfi_array ) { int o = 2; int mid, cid, prot; + bus_t *bus = cfi_array->bus; bus_write( bus, 0x0555 << o, 0x00aa00aa ); /* autoselect p29 */ bus_write( bus, 0x02aa << o, 0x00550055 ); @@ -158,7 +161,7 @@ amd_flash_print_info( bus_t *bus ) mid = bus_read( bus, 0x00 << o ) & 0xFFFF; cid = bus_read( bus, 0x01 << o ) & 0xFFFF; prot = bus_read( bus, 0x02 << o ) & 0xFF; - amd_flash_read_array( bus ); /* AMD reset */ + amd_flash_read_array( cfi_array ); /* AMD reset */ printf( _("Chip: AMD Flash\n\tManufacturer: ") ); switch (mid) { case 0x0001: @@ -181,9 +184,10 @@ amd_flash_print_info( bus_t *bus ) } static int -amd_flash_erase_block( bus_t *bus, uint32_t adr ) +amd_flash_erase_block( cfi_array_t *cfi_array, uint32_t adr ) { int o = 2; + bus_t *bus = cfi_array->bus; printf("flash_erase_block 0x%08X\n", adr); @@ -198,28 +202,29 @@ amd_flash_erase_block( bus_t *bus, uint32_t adr ) if (amdstatus( bus, adr, 0xffff )) { printf( "flash_erase_block 0x%08X DONE\n", adr ); - amd_flash_read_array( bus ); /* AMD reset */ + amd_flash_read_array( cfi_array ); /* AMD reset */ return 0; } printf( "flash_erase_block 0x%08X FAILED\n", adr ); /* Read Array */ - amd_flash_read_array( bus ); /* AMD reset */ + amd_flash_read_array( cfi_array ); /* AMD reset */ return CFI_INTEL_ERROR_UNKNOWN; } static int -amd_flash_unlock_block( bus_t *bus, uint32_t adr ) +amd_flash_unlock_block( cfi_array_t *cfi_array, uint32_t adr ) { printf( "flash_unlock_block 0x%08X IGNORE\n", adr ); return 0; } static int -amd_flash_program( bus_t *bus, uint32_t adr, uint32_t data ) +amd_flash_program( cfi_array_t *cfi_array, uint32_t adr, uint32_t data ) { int o = 2; int status; + bus_t *bus = cfi_array->bus; if (dbg) printf("\nflash_program 0x%08X = 0x%08X\n", adr, data); @@ -236,10 +241,10 @@ amd_flash_program( bus_t *bus, uint32_t adr, uint32_t data ) } static void -amd_flash_read_array( bus_t *bus ) +amd_flash_read_array( cfi_array_t *cfi_array ) { /* Read Array */ - bus_write( bus, 0x0, 0x00F000F0 ); /* AMD reset */ + bus_write( cfi_array->bus, 0x0, 0x00F000F0 ); /* AMD reset */ } flash_driver_t amd_32_flash_driver = { diff --git a/libbrux/flash/intel.c b/libbrux/flash/intel.c index 00cfb073..16bfe6a3 100644 --- a/libbrux/flash/intel.c +++ b/libbrux/flash/intel.c @@ -43,27 +43,28 @@ #include #include +#include #include "flash.h" -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 ); +static int intel_flash_erase_block( cfi_array_t *cfi_array, uint32_t adr ); +static int intel_flash_unlock_block( cfi_array_t *cfi_array, uint32_t adr ); +static int intel_flash_program( cfi_array_t *cfi_array, uint32_t adr, uint32_t data ); +static int intel_flash_erase_block32( cfi_array_t *cfi_array, uint32_t adr ); +static int intel_flash_unlock_block32( cfi_array_t *cfi_array, uint32_t adr ); +static int intel_flash_program32( cfi_array_t *cfi_array, uint32_t adr, uint32_t data ); /* autodetect, we can handle this chip */ static int -intel_flash_autodetect32( bus_t *bus, cfi_query_structure_t *cfi ) +intel_flash_autodetect32( cfi_array_t *cfi_array ) { - return (cfi->identification_string.pri_id_code == CFI_VENDOR_INTEL_ECS) && (bus_width( bus, 0 ) == 32); + return (cfi_array->cfi_chips[0]->cfi.identification_string.pri_id_code == CFI_VENDOR_INTEL_ECS) && (bus_width( cfi_array->bus, 0 ) == 32); } static int -intel_flash_autodetect( bus_t *bus, cfi_query_structure_t *cfi ) +intel_flash_autodetect( cfi_array_t *cfi_array ) { - return (cfi->identification_string.pri_id_code == CFI_VENDOR_INTEL_ECS) && (bus_width( bus, 0 ) == 16); + return (cfi_array->cfi_chips[0]->cfi.identification_string.pri_id_code == CFI_VENDOR_INTEL_ECS) && (bus_width( cfi_array->bus, 0 ) == 16); } static void @@ -121,9 +122,11 @@ _intel_flash_print_info( bus_t *bus, int o ) } static void -intel_flash_print_info( bus_t *bus ) +intel_flash_print_info( cfi_array_t *cfi_array ) { int o = 1; + bus_t *bus = cfi_array->bus; + /* Intel Primary Algorithm Extended Query Table - see Table 5. in [3] */ /* TODO */ @@ -137,9 +140,10 @@ intel_flash_print_info( bus_t *bus ) } static void -intel_flash_print_info32( bus_t *bus ) +intel_flash_print_info32( cfi_array_t *cfi_array ) { int o = 2; + bus_t *bus = cfi_array->bus; /* Intel Primary Algorithm Extended Query Table - see Table 5. in [3] */ /* TODO */ @@ -153,9 +157,10 @@ intel_flash_print_info32( bus_t *bus ) } static int -intel_flash_erase_block( bus_t *bus, uint32_t adr ) +intel_flash_erase_block( cfi_array_t *cfi_array, uint32_t adr ) { uint16_t sr; + bus_t *bus = cfi_array->bus; bus_write( bus, 0, CFI_INTEL_CMD_CLEAR_STATUS_REGISTER ); bus_write( bus, adr, CFI_INTEL_CMD_BLOCK_ERASE ); @@ -183,9 +188,10 @@ intel_flash_erase_block( bus_t *bus, uint32_t adr ) } static int -intel_flash_unlock_block( bus_t *bus, uint32_t adr ) +intel_flash_unlock_block( cfi_array_t *cfi_array, uint32_t adr ) { uint16_t sr; + bus_t *bus = cfi_array->bus; bus_write( bus, 0, CFI_INTEL_CMD_CLEAR_STATUS_REGISTER ); bus_write( bus, adr, CFI_INTEL_CMD_LOCK_SETUP ); @@ -201,9 +207,10 @@ intel_flash_unlock_block( bus_t *bus, uint32_t adr ) } static int -intel_flash_program( bus_t *bus, uint32_t adr, uint32_t data ) +intel_flash_program( cfi_array_t *cfi_array, uint32_t adr, uint32_t data ) { uint16_t sr; + bus_t *bus = cfi_array->bus; bus_write( bus, 0, CFI_INTEL_CMD_CLEAR_STATUS_REGISTER ); bus_write( bus, adr, CFI_INTEL_CMD_PROGRAM1 ); @@ -219,9 +226,10 @@ intel_flash_program( bus_t *bus, uint32_t adr, uint32_t data ) } static int -intel_flash_erase_block32( bus_t *bus, uint32_t adr ) +intel_flash_erase_block32( cfi_array_t *cfi_array, uint32_t adr ) { uint32_t sr; + bus_t *bus = cfi_array->bus; 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 ); @@ -237,9 +245,10 @@ intel_flash_erase_block32( bus_t *bus, uint32_t adr ) } static int -intel_flash_unlock_block32( bus_t *bus, uint32_t adr ) +intel_flash_unlock_block32( cfi_array_t *cfi_array, uint32_t adr ) { uint32_t sr; + bus_t *bus = cfi_array->bus; 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 ); @@ -255,9 +264,10 @@ intel_flash_unlock_block32( bus_t *bus, uint32_t adr ) } static int -intel_flash_program32( bus_t *bus, uint32_t adr, uint32_t data ) +intel_flash_program32( cfi_array_t *cfi_array, uint32_t adr, uint32_t data ) { uint32_t sr; + bus_t *bus = cfi_array->bus; 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 ); @@ -273,17 +283,17 @@ intel_flash_program32( bus_t *bus, uint32_t adr, uint32_t data ) } static void -intel_flash_readarray32( bus_t *bus ) +intel_flash_readarray32( cfi_array_t *cfi_array ) { /* Read Array */ - bus_write( bus, 0, 0x00FF00FF ); + bus_write( cfi_array->bus, 0, 0x00FF00FF ); } static void -intel_flash_readarray( bus_t *bus ) +intel_flash_readarray( cfi_array_t *cfi_array ) { /* Read Array */ - bus_write( bus, 0, 0x00FF00FF ); + bus_write( cfi_array->bus, 0, 0x00FF00FF ); } flash_driver_t intel_32_flash_driver = {