diff --git a/jtag/src/bus.h b/jtag/src/bus.h index 73e5931c..c2382417 100644 --- a/jtag/src/bus.h +++ b/jtag/src/bus.h @@ -30,6 +30,7 @@ #include "part.h" typedef struct { + int (*bus_width)( parts *ps ); void (*bus_read_start)( parts *, uint32_t ); uint32_t (*bus_read_next)( parts *, uint32_t ); uint32_t (*bus_read_end)( parts * ); @@ -38,6 +39,7 @@ typedef struct { } bus_driver_t; extern bus_driver_t *bus_driver; +#define bus_width bus_driver->bus_width #define bus_read_start bus_driver->bus_read_start #define bus_read_next bus_driver->bus_read_next #define bus_read_end bus_driver->bus_read_end diff --git a/jtag/src/flash.c b/jtag/src/flash.c index ea5bad5c..9e7b8c9c 100644 --- a/jtag/src/flash.c +++ b/jtag/src/flash.c @@ -50,70 +50,21 @@ void flashmem( parts *ps, FILE *f ) { part *p = ps->parts[0]; - uint8_t boot_sel; int o = 0; - int d = 0; uint32_t adr; -#define D_SA1110 1 -#define D_PXA250 2 - - if (strcmp( p->part, "SA1110" ) == 0) { - printf( "SA1110 detected\n" ); - d = D_SA1110; - bus_driver = &sa1110_bus_driver; - } - if (strcmp( p->part, "PXA250" ) == 0) { - printf( "PXA250 detected\n" ); - d = D_PXA250; - bus_driver = &pxa250_bus_driver; - } - - if (!d) { - printf( "Error: Only PXA250/SA1110 devices supported!\n" ); - return; - } printf( "Note: Supported configuration is 2 x 16 bit only\n" ); - switch (d) { - case D_SA1110: - if (part_get_signal( p, "ROM_SEL" )) { - printf( "ROM_SEL: 32 bits\n" ); - o = 2; - } else { - printf( "ROM_SEL: 16 bits\n" ); - o = 1; - } + switch (bus_width( ps )) { + case 16: + o = 1; break; - case D_PXA250: - boot_sel = (part_get_signal( p, "BOOT_SEL[2]" ) << 2) | (part_get_signal( p, "BOOT_SEL[1]" ) << 1) | part_get_signal( p, "BOOT_SEL[0]" ); - - /* see Table 6-36. in [2] */ - switch (boot_sel) { - case 0: - printf( "BOOT_SEL: Asynchronous 32-bit ROM\n" ); - o = 2; - break; - case 1: - printf( "BOOT_SEL: Asynchronous 16-bit ROM\n" ); - o = 1; - break; - case 2: - case 3: - case 4: - case 5: - case 6: - case 7: - printf( "TODO - BOOT_SEL\n" ); - return; - default: - printf( "BUG in code, file %s, line %d.\n", __FILE__, __LINE__ ); - return; - } + case 32: + o = 2; break; default: - printf( "Unknown device!!!\n" ); - break; + printf( "Error: Unknown bus width!\n" ); + return; } /* EXTEST */ diff --git a/jtag/src/jtag.c b/jtag/src/jtag.c index d6fbc9f7..b73ca6ea 100644 --- a/jtag/src/jtag.c +++ b/jtag/src/jtag.c @@ -36,6 +36,9 @@ #include "tap.h" #include "detect.h" +#include "bus.h" + +bus_driver_t *bus_driver = NULL; static char * get_token( char *buf ) @@ -95,11 +98,17 @@ main( void ) if (ps) parts_free( ps ); ps = detect_parts( "../data" ); + if (!ps->len) + continue; parts_set_instruction( ps, "SAMPLE/PRELOAD" ); parts_shift_instructions( ps ); parts_shift_data_registers( ps ); parts_set_instruction( ps, "BYPASS" ); parts_shift_instructions( ps ); + if (strcmp( ps->parts[0]->part, "SA1110" ) == 0) + bus_driver = &sa1110_bus_driver; + if (strcmp( ps->parts[0]->part, "PXA250" ) == 0) + bus_driver = &pxa250_bus_driver; continue; } diff --git a/jtag/src/pxa250.c b/jtag/src/pxa250.c index 2b9c0c82..55ca011b 100644 --- a/jtag/src/pxa250.c +++ b/jtag/src/pxa250.c @@ -20,6 +20,10 @@ * * Written by Marcel Telka , 2002. * + * Documentation: + * [1] Intel Corporation, "Intel PXA250 and PXA210 Application Processors + * Developer's Manual", February 2002, Order Number: 278522-001 + * */ #include @@ -70,7 +74,7 @@ pxa250_bus_read_start( parts *ps, uint32_t adr ) { part *p = ps->parts[0]; - /* see Figure 6-13 in PXA doc */ + /* see Figure 6-13 in [1] */ part_set_signal( p, "nCS[0]", 1, 0 ); part_set_signal( p, "DQM[0]", 1, 0 ); part_set_signal( p, "DQM[1]", 1, 0 ); @@ -92,7 +96,7 @@ pxa250_bus_read_next( parts *ps, uint32_t adr ) { part *p = ps->parts[0]; - /* see Figure 6-13 in PXA doc */ + /* see Figure 6-13 in [1] */ setup_address( p, adr ); parts_shift_data_registers( ps ); @@ -115,7 +119,7 @@ pxa250_bus_read_end( parts *ps ) { part *p = ps->parts[0]; - /* see Figure 6-13 in PXA doc */ + /* see Figure 6-13 in [1] */ part_set_signal( p, "nCS[0]", 1, 1 ); part_set_signal( p, "nOE", 1, 1 ); part_set_signal( p, "nSDCAS", 1, 1 ); @@ -146,7 +150,7 @@ pxa250_bus_read( parts *ps, uint32_t adr ) void pxa250_bus_write( parts *ps, uint32_t adr, uint32_t data ) { - /* see Figure 6-17 in PXA doc */ + /* see Figure 6-17 in [1] */ part *p = ps->parts[0]; part_set_signal( p, "nCS[0]", 1, 0 ); @@ -170,7 +174,38 @@ pxa250_bus_write( parts *ps, uint32_t adr, uint32_t data ) parts_shift_data_registers( ps ); } +int +pxa250_bus_width( parts *ps ) +{ + part *p = ps->parts[0]; + uint8_t boot_sel = (part_get_signal( p, "BOOT_SEL[2]" ) << 2) + | (part_get_signal( p, "BOOT_SEL[1]" ) << 1) + | part_get_signal( p, "BOOT_SEL[0]" ); + + /* see Table 6-36. in [1] */ + switch (boot_sel) { + case 0: + printf( "BOOT_SEL: Asynchronous 32-bit ROM\n" ); + return 32; + case 1: + printf( "BOOT_SEL: Asynchronous 16-bit ROM\n" ); + return 16; + case 2: + case 3: + case 4: + case 5: + case 6: + case 7: + printf( "TODO - BOOT_SEL\n" ); + return 0; + default: + printf( "BUG in code, file %s, line %d.\n", __FILE__, __LINE__ ); + return 0; + } +} + bus_driver_t pxa250_bus_driver = { + pxa250_bus_width, pxa250_bus_read_start, pxa250_bus_read_next, pxa250_bus_read_end, diff --git a/jtag/src/readmem.c b/jtag/src/readmem.c index 815bd9a6..281c017e 100644 --- a/jtag/src/readmem.c +++ b/jtag/src/readmem.c @@ -41,76 +41,32 @@ #include "part.h" #include "bus.h" -bus_driver_t *bus_driver = NULL; +cfi_query_structure_t *detect_cfi( parts * ); void readmem( parts *ps ) { part *p = ps->parts[0]; - uint8_t boot_sel; int o = 0; - int d = 0; cfi_query_structure_t *cfi; -#define D_SA1110 1 -#define D_PXA250 2 - if (strcmp( p->part, "SA1110" ) == 0) { - printf( "SA1110 detected\n" ); - d = D_SA1110; - bus_driver = &sa1110_bus_driver; - } - if (strcmp( p->part, "PXA250" ) == 0) { - printf( "PXA250 detected\n" ); - d = D_PXA250; - bus_driver = &pxa250_bus_driver; - } - - if (!d) { - printf( "Error: Only PXA250/SA1110 devices supported!\n" ); + if (!bus_driver) { + printf( "Error: Missing bus_driver!\n" ); return; } printf( "Note: Supported configuration is 2 x 16 bit only\n" ); - switch (d) { - case D_SA1110: - if (part_get_signal( p, "ROM_SEL" )) { - printf( "ROM_SEL: 32 bits\n" ); - o = 2; - } else { - printf( "ROM_SEL: 16 bits\n" ); - o = 1; - } - break; - case D_PXA250: - boot_sel = (part_get_signal( p, "BOOT_SEL[2]" ) << 2) | (part_get_signal( p, "BOOT_SEL[1]" ) << 1) | part_get_signal( p, "BOOT_SEL[0]" ); - - /* see Table 6-36. in [2] */ - switch (boot_sel) { - case 0: - printf( "BOOT_SEL: Asynchronous 32-bit ROM\n" ); - o = 2; - break; - case 1: - printf( "BOOT_SEL: Asynchronous 16-bit ROM\n" ); - o = 1; - break; - case 2: - case 3: - case 4: - case 5: - case 6: - case 7: - printf( "TODO - BOOT_SEL\n" ); - return; - default: - printf( "BUG in code, file %s, line %d.\n", __FILE__, __LINE__ ); - return; - } + switch (bus_width( ps )) { + case 16: + o = 1; break; - default: - printf( "Unknown device!!!\n" ); + case 32: + o = 2; break; + default: + printf( "Error: Unknown bus width!\n" ); + return; } /* EXTEST */ diff --git a/jtag/src/sa1110.c b/jtag/src/sa1110.c index 28505274..1285ab8d 100644 --- a/jtag/src/sa1110.c +++ b/jtag/src/sa1110.c @@ -168,7 +168,20 @@ sa1110_bus_write( parts *ps, uint32_t adr, uint32_t data ) parts_shift_data_registers( ps ); } +int +sa1110_bus_width( parts *ps ) +{ + if (part_get_signal( ps->parts[0], "ROM_SEL" )) { + printf( "ROM_SEL: 32 bits\n" ); + return 32; + } else { + printf( "ROM_SEL: 16 bits\n" ); + return 16; + } +} + bus_driver_t sa1110_bus_driver = { + sa1110_bus_width, sa1110_bus_read_start, sa1110_bus_read_next, sa1110_bus_read_end,