Jump to content

Recommended Posts

Posted

Привет всем!)

 

 

Подскажите, кто может пнёт в правильном направлении, нужно добавить поддержку флэшь SST39VF160

 

$ ./jtag.exe

JTAG Tools 0.6-cvs-20051228

Copyright © 2002, 2003 ETC s.r.o.

JTAG Tools is free software, covered by the GNU General Public License, and you

are

welcome to change it and/or distribute copies of it under certain conditions.

There is absolutely no warranty for JTAG Tools.

 

Warning: JTAG Tools may damage your hardware! Type "quit" to exit!

 

Type "help" for help.

 

jtag> include athsw

Initializing Macraigor Wiggler JTAG Cable on parallel port at 0x378

IR length: 5

Chain length: 1

Device Id: 00000000000000000000000000000001

Manufacturer: Atheros

Part: ar2312

Stepping: 1

Filename: /usr/local/share/jtag/atheros/ar2312/ar2312

ImpCode=01000000010000000100000000000000

EJTAG version: 2.6

EJTAG Implementation flags: R4k ASID_8 NoDMA MIPS32

dev ID=004f man ID=0000

Using CFI flash chip detection, not jedec

Flash not found!

No. Manufacturer Part Stepping Instruction

Register

-------------------------------------------------------------------------------

-------------

0 Atheros ar2312 1 EJTAG_DATA

EJDATA

 

Active bus:

*0: EJTAG compatible bus driver via PrAcc (JTAG part No. 0)

start: 0x00000000, length: 0x20000000, data width: 8 bit

start: 0x20000000, length: 0x20000000, data width: 16 bit

start: 0x40000000, length: 0x20000000, data width: 32 bit

Posted

Спасибо за подсказку, а можно пример поточнее, посмотел, но сам по ходу не разберусь, что к чему обращается и от чего зависит и где именно нужно внести изменения, в файлике amd.c описание про амд флэши есть, в файле jdec.c действительно есть упоминание о флэше SST

/* SST */

#define SST39LF800 0x2781

#define SST39LF160 0x2782

 

но вот типа такого для нее я не нашел, есть только для флешей ST

 

}, {

.mfr_id = MANUFACTURER_ST,

.dev_id = M29W160DT,

.name = "ST M29W160DT",

.size = 0x00200000,

.numeraseregions = 4,

.regions = {

{ .offset = 0x000000, .erasesize = 0x10000, .numblocks = 31 },

{ .offset = 0x1F0000, .erasesize = 0x08000, .numblocks = 1 },

{ .offset = 0x1F8000, .erasesize = 0x02000, .numblocks = 2 },

{ .offset = 0x1FC000, .erasesize = 0x04000, .numblocks = 1 }

я изменил это дело на

/* SST */

#define SST39LF800 0x2781

#define SST39VF160 0x2782

}, {

.mfr_id = MANUFACTURER_SST,

.dev_id = SST39VF160,

.name = "ST SST39VF160",

.size = 0x00200000,

.numeraseregions = 4,

.regions = {

{ .offset = 0x000000, .erasesize = 0x10000, .numblocks = 31 },

{ .offset = 0x1F0000, .erasesize = 0x08000, .numblocks = 1 },

{ .offset = 0x1F8000, .erasesize = 0x02000, .numblocks = 2 },

{ .offset = 0x1FC000, .erasesize = 0x04000, .numblocks = 1 }

Не помогло, может по новой инсталировать надо уже с изменениями? Что еще нужно, или я не так копаю.

 

 

Posted (edited)

Спасибо tchern за помощь =)

Я сам по поиску не находил такую сборку с поддержкой SST, посмотрел в сравнении с той, что у меня. Нашел изменения в файликах, это ваша чтоли?

jtag-brecis-ok_ss\libbrux\flash\detectflash.c

Было

}

 

cfi = &cfi_array->cfi_chips[0]->cfi;

 

/* detect CFI capable devices */

/* TODO: Low chip only */

/* see 4.3.2 in [1] */

printf( _("Query identification string:\n") );

/* see section 2 in [2] */

switch (cfi->identification_string.pri_id_code) {

case CFI_VENDOR_NULL:

s = N_("null");

break;

case CFI_VENDOR_INTEL_ECS:

s = N_("Intel/Sharp Extended Command Set");

break;

case CFI_VENDOR_AMD_SCS:

s = N_("AMD/Fujitsu Standard Command Set");

break;

case CFI_VENDOR_INTEL_SCS:

s = N_("Intel Standard Command Set");

break;

case CFI_VENDOR_AMD_ECS:

s = N_("AMD/Fujitsu Extended Command Set");

break;

case CFI_VENDOR_MITSUBISHI_SCS:

s = N_("Mitsubishi Standard Command Set");

break;

case CFI_VENDOR_MITSUBISHI_ECS:

s = N_("Mitsubishi Extended Command Set");

break;

case CFI_VENDOR_SST_PWCS:

s = N_("Page Write Command Set");

break;

default:

s = N_("unknown!!!");

break;

}

printf( _("\tPrimary Algorithm Command Set and Control Interface ID Code: 0x%04X (%s)\n"), cfi->identification_string.pri_id_code, _(s) );

switch (cfi->identification_string.alt_id_code) {

case CFI_VENDOR_NULL:

s = N_("null");

break;

case CFI_VENDOR_INTEL_ECS:

s = N_("Intel/Sharp Extended Command Set");

break;

case CFI_VENDOR_AMD_SCS:

s = N_("AMD/Fujitsu Standard Command Set");

break;

case CFI_VENDOR_INTEL_SCS:

s = N_("Intel Standard Command Set");

break;

case CFI_VENDOR_AMD_ECS:

s = N_("AMD/Fujitsu Extended Command Set");

break;

case CFI_VENDOR_MITSUBISHI_SCS:

s = N_("Mitsubishi Standard Command Set");

break;

case CFI_VENDOR_MITSUBISHI_ECS:

s = N_("Mitsubishi Extended Command Set");

break;

case CFI_VENDOR_SST_PWCS:

s = N_("Page Write Command Set");

break;

default:

s = N_("unknown!!!");

break;

}

 

сделал

 

}

 

cfi = &cfi_array->cfi_chips[0]->cfi;

 

/* detect CFI capable devices */

/* TODO: Low chip only */

/* see 4.3.2 in [1] */

printf( _("Query identification string:\n") );

/* see section 2 in [2] */

switch (cfi->identification_string.pri_id_code) {

case CFI_VENDOR_NULL:

s = N_("null");

break;

case CFI_VENDOR_INTEL_ECS:

s = N_("Intel/Sharp Extended Command Set");

break;

case CFI_VENDOR_AMD_SCS:

s = N_("AMD/Fujitsu Standard Command Set");

break;

case CFI_VENDOR_INTEL_SCS:

s = N_("Intel Standard Command Set");

break;

case CFI_VENDOR_AMD_ECS:

s = N_("AMD/Fujitsu Extended Command Set");

break;

case CFI_VENDOR_MITSUBISHI_SCS:

s = N_("Mitsubishi Standard Command Set");

break;

case CFI_VENDOR_MITSUBISHI_ECS:

s = N_("Mitsubishi Extended Command Set");

break;

case CFI_VENDOR_SST_SCS:

s = N_("SST Standard Command Set");

break;

case CFI_VENDOR_SST_ECS:

s = N_("SST Extended Command Set");

break;

case CFI_VENDOR_SST_PWCS:

s = N_("Page Write Command Set");

break;

default:

s = N_("unknown!!!");

break;

}

printf( _("\tPrimary Algorithm Command Set and Control Interface ID Code: 0x%04X (%s)\n"), cfi->identification_string.pri_id_code, _(s) );

switch (cfi->identification_string.alt_id_code) {

case CFI_VENDOR_NULL:

s = N_("null");

break;

case CFI_VENDOR_INTEL_ECS:

s = N_("Intel/Sharp Extended Command Set");

break;

case CFI_VENDOR_AMD_SCS:

s = N_("AMD/Fujitsu Standard Command Set");

break;

case CFI_VENDOR_INTEL_SCS:

s = N_("Intel Standard Command Set");

break;

case CFI_VENDOR_AMD_ECS:

s = N_("AMD/Fujitsu Extended Command Set");

break;

case CFI_VENDOR_MITSUBISHI_SCS:

s = N_("Mitsubishi Standard Command Set");

break;

case CFI_VENDOR_MITSUBISHI_ECS:

s = N_("Mitsubishi Extended Command Set");

break;

case CFI_VENDOR_SST_SCS:

s = N_("SST Standard Command Set");

break;

case CFI_VENDOR_SST_ECS:

s = N_("SST Extended Command Set");

break;

case CFI_VENDOR_SST_PWCS:

s = N_("Page Write Command Set");

break;

default:

s = N_("unknown!!!");

break;

}

 

jtag-brecis-ok_ss\libbrux\flash\jedec.c

сделал

 

/*SST*/

#define SST39LF800 0x2781

#define SST39LF160 0x2782

#define SST39VF160 0x2782

 

}, {

.mfr_id = MANUFACTURER_SST,

.dev_id = SST39VF160,

.name = "SST SST39VF160",

.size = 0x00200000,

.numeraseregions = 4,

.regions = {

{ .offset = 0x000000, .erasesize = 0x10000, .numblocks = 31 },

{ .offset = 0x1F0000, .erasesize = 0x08000, .numblocks = 1 },

{ .offset = 0x1F8000, .erasesize = 0x02000, .numblocks = 2 },

{ .offset = 0x1FC000, .erasesize = 0x04000, .numblocks = 1 }

}

 

jtag-brecis-ok_ss\include-0.4.2\device\flash\cfi.h

а после инсталяции создается папка C:\cygwin\usr\local\include

он находится в ней по пути C:\cygwin\usr\local\include\openwince\device\flash\cfi.h

 

было

 

/* Algorithm command set & control interface ID codes - see Table 1 in [2] */

 

#define CFI_VENDOR_NULL 0x0000

#define CFI_VENDOR_INTEL_ECS 0x0001

#define CFI_VENDOR_AMD_SCS 0x0002

#define CFI_VENDOR_INTEL_SCS 0x0003

#define CFI_VENDOR_AMD_ECS 0x0004

#define CFI_VENDOR_MITSUBISHI_SCS 0x0100

#define CFI_VENDOR_MITSUBISHI_ECS 0x0101

#define CFI_VENDOR_SGS_SCS 0x0020

#define CFI_VENDOR_SST_SCS 0x00bf

#define CFI_VENDOR_SST_PWCS 0x0102

 

сделал

 

/* Algorithm command set & control interface ID codes - see Table 1 in [2] */

 

#define CFI_VENDOR_NULL 0x0000

#define CFI_VENDOR_INTEL_ECS 0x0001

#define CFI_VENDOR_AMD_SCS 0x0002

#define CFI_VENDOR_INTEL_SCS 0x0003

#define CFI_VENDOR_AMD_ECS 0x0004

#define CFI_VENDOR_MITSUBISHI_SCS 0x0100

#define CFI_VENDOR_MITSUBISHI_ECS 0x0101

#define CFI_VENDOR_SGS_SCS 0x0020

#define CFI_VENDOR_SST_ECS 0x00bf хотя вот здесь сомневаюсь

#define CFI_VENDOR_SST_SCS 0x00bf

#define CFI_VENDOR_SST_PWCS 0x0102

 

jtag-brecis-ok_ss\libbrux\flash\sst.c

 

он похоже из amd.c переделан, а как его правильно подхватить, в оборот то взять.

добавил в него

case 0x2781:

printf( _("SST39LF800") );

break;

case 0x2782:

printf( _("SST39LF160") );

break;

case 0x2782:

printf( _("SST39VF160") );

break;

 

 

flash_driver_t sst_16_flash_driver = {

2, /* buswidth */

N_("SST Standard Command Set"),

N_("supported: SST 39VF160, 39LF160; 1x16 Bit"),

sst_flash_autodetect16,

sst_flash_print_info,

sst_flash_erase_block,

sst_flash_unlock_block,

sst_flash_program,

sst_flash_read_array,

};

 

flash_driver_t sst_8_flash_driver = {

1, /* buswidth */

N_("SST Standard Command Set"),

N_("supported: SST 39VF020, 39LF800; 1x8 Bit"),

sst_flash_autodetect8,

sst_flash_print_info,

sst_flash_erase_block,

sst_flash_unlock_block,

sst_flash_program,

sst_flash_read_array,

};

 

Кстати сборка jtag-brecis-ok_ss без изменений даже прямо из архива не инсталировалась, ошибки вышли, поэтому я в старую просто закинул эти файлы.

 

Выходной день убил, а так и не запустил, эх, помогите же, не хочется здаваться =) , что то я упустил, что вот только.

Edited by ruzalit
Posted

Все вроде ка надо

 

если вы взяли только файлы то надо добавить их в /librux/make.am make.in потом ./configure

 

и вот еще вопрос правильно ли это?

 

.size = 0x00200000,

.numeraseregions = 4,

.regions = {

{ .offset = 0x000000, .erasesize = 0x10000, .numblocks = 31 },

{ .offset = 0x1F0000, .erasesize = 0x08000, .numblocks = 1 },

{ .offset = 0x1F8000, .erasesize = 0x02000, .numblocks = 2 },

{ .offset = 0x1FC000, .erasesize = 0x04000, .numblocks = 1 }

}

 

а то чегонибудь затрет не то

 

Posted

Здравствуйте tchern, спасибо Вам за помощь.

Все сделал, как вы мне написали,

Все сделал, как сказали

 

C:\cygwin\usr\local\jtag\libbrux\Makefile

 

добавил

am_libbrux_a_OBJECTS = cmd.$(OBJEXT) help.$(OBJEXT) quit.$(OBJEXT) \

cmd_detectflash.$(OBJEXT) cfi.$(OBJEXT) jedec.$(OBJEXT) \

detectflash.$(OBJEXT) amd.$(OBJEXT) intel.$(OBJEXT) sst.$(OBJEXT)

libbrux_a_SOURCES = \

cmd/cmd.c \

cmd/help.c \

cmd/quit.c \

cmd/cmd_detectflash.c \

flash/cfi.c \

flash/jedec.c \

flash/detectflash.c \

flash/amd.c \

flash/intel.c \

flash/sst.c

 

distclean-compile:

-rm -f *.tab.c

 

include ./$(DEPDIR)/amd.Po

include ./$(DEPDIR)/cfi.Po

include ./$(DEPDIR)/cmd.Po

include ./$(DEPDIR)/cmd_detectflash.Po

include ./$(DEPDIR)/detectflash.Po

include ./$(DEPDIR)/help.Po

include ./$(DEPDIR)/intel.Po

include ./$(DEPDIR)/sst.Po

include ./$(DEPDIR)/jedec.Po

include ./$(DEPDIR)/quit.Po

 

sst.o: flash/sst.c

if $(CC) $(DEFS) $(DEFAULT_INCLUDES) $(INCLUDES) $(AM_CPPFLAGS) $(CPPFLAGS) $(AM_CFLAGS) $(CFLAGS) -MT sst.o -MD -MP -MF "$(DEPDIR)/sst.Tpo" -c -o sst.o `test -f 'flash/sst.c' || echo '$(srcdir)/'`flash/sst.c; \

then mv -f "$(DEPDIR)/sst.Tpo" "$(DEPDIR)/sst.Po"; else rm -f "$(DEPDIR)/sst.Tpo"; exit 1; fi

# source='flash/sst.c' object='sst.o' libtool=no \

# DEPDIR=$(DEPDIR) $(CCDEPMODE) $(depcomp) \

# $(CC) $(DEFS) $(DEFAULT_INCLUDES) $(INCLUDES) $(AM_CPPFLAGS) $(CPPFLAGS) $(AM_CFLAGS) $(CFLAGS) -c -o sst.o `test -f 'flash/sst.c' || echo '$(srcdir)/'`flash/sst.c

 

sst.obj: flash/sst.c

if $(CC) $(DEFS) $(DEFAULT_INCLUDES) $(INCLUDES) $(AM_CPPFLAGS) $(CPPFLAGS) $(AM_CFLAGS) $(CFLAGS) -MT sst.obj -MD -MP -MF "$(DEPDIR)/sst.Tpo" -c -o sst.obj `if test -f 'flash/sst.c'; then $(CYGPATH_W) 'flash/sst.c'; else $(CYGPATH_W) '$(srcdir)/flash/sst.c'; fi`; \

then mv -f "$(DEPDIR)/sst.Tpo" "$(DEPDIR)/sst.Po"; else rm -f "$(DEPDIR)/sst.Tpo"; exit 1; fi

# source='flash/sst.c' object='sst.obj' libtool=no \

# DEPDIR=$(DEPDIR) $(CCDEPMODE) $(depcomp) \

# $(CC) $(DEFS) $(DEFAULT_INCLUDES) $(INCLUDES) $(AM_CPPFLAGS) $(CPPFLAGS) $(AM_CFLAGS) $(CFLAGS) -c -o sst.obj `if test -f 'flash/sst.c'; then $(CYGPATH_W) 'flash/sst.c'; else $(CYGPATH_W) '$(srcdir)/flash/sst.c'; fi`

uninstall-info-am:

 

C:\cygwin\usr\local\jtag\libbrux\Makefile\Makefile.am

 

добавил

 

libbrux_a_SOURCES = \

cmd/cmd.c \

cmd/help.c \

cmd/quit.c \

cmd/cmd_detectflash.c \

flash/cfi.c \

flash/jedec.c \

flash/detectflash.c \

flash/amd.c \

flash/intel.c \

flash/sst.c

 

 

C:\cygwin\usr\local\jtag\libbrux\Makefile.in

 

добавил

 

libbrux_a_LIBADD =

am_libbrux_a_OBJECTS = cmd.$(OBJEXT) help.$(OBJEXT) quit.$(OBJEXT) \

cmd_detectflash.$(OBJEXT) cfi.$(OBJEXT) jedec.$(OBJEXT) \

detectflash.$(OBJEXT) amd.$(OBJEXT) intel.$(OBJEXT) sst.$(OBJEXT)

 

noinst_LIBRARIES = libbrux.a

libbrux_a_SOURCES = \

cmd/cmd.c \

cmd/help.c \

cmd/quit.c \

cmd/cmd_detectflash.c \

flash/cfi.c \

flash/jedec.c \

flash/detectflash.c \

flash/amd.c \

flash/intel.c \

flash/sst.c

 

 

@AMDEP_TRUE@@am__include@ @am__quote@./$(DEPDIR)/amd.Po@am__quote@

@AMDEP_TRUE@@am__include@ @am__quote@./$(DEPDIR)/cfi.Po@am__quote@

@AMDEP_TRUE@@am__include@ @am__quote@./$(DEPDIR)/cmd.Po@am__quote@

@AMDEP_TRUE@@am__include@ @am__quote@./$(DEPDIR)/cmd_detectflash.Po@am__quote@

@AMDEP_TRUE@@am__include@ @am__quote@./$(DEPDIR)/detectflash.Po@am__quote@

@AMDEP_TRUE@@am__include@ @am__quote@./$(DEPDIR)/help.Po@am__quote@

@AMDEP_TRUE@@am__include@ @am__quote@./$(DEPDIR)/intel.Po@am__quote@

@AMDEP_TRUE@@am__include@ @am__quote@./$(DEPDIR)/sst.Po@am__quote@

@AMDEP_TRUE@@am__include@ @am__quote@./$(DEPDIR)/jedec.Po@am__quote@

@AMDEP_TRUE@@am__include@ @am__quote@./$(DEPDIR)/quit.Po@am__quote@

 

sst.o: flash/sst.c

@am__fastdepCC_TRUE@ if $(CC) $(DEFS) $(DEFAULT_INCLUDES) $(INCLUDES) $(AM_CPPFLAGS) $(CPPFLAGS) $(AM_CFLAGS) $(CFLAGS) -MT sst.o -MD -MP -MF "$(DEPDIR)/sst.Tpo" -c -o sst.o `test -f 'flash/sst.c' || echo '$(srcdir)/'`flash/sst.c; \

@am__fastdepCC_TRUE@ then mv -f "$(DEPDIR)/sst.Tpo" "$(DEPDIR)/sst.Po"; else rm -f "$(DEPDIR)/sst.Tpo"; exit 1; fi

@AMDEP_TRUE@@am__fastdepCC_FALSE@ source='flash/sst.c' object='sst.o' libtool=no @AMDEPBACKSLASH@

@AMDEP_TRUE@@am__fastdepCC_FALSE@ DEPDIR=$(DEPDIR) $(CCDEPMODE) $(depcomp) @AMDEPBACKSLASH@

@am__fastdepCC_FALSE@ $(CC) $(DEFS) $(DEFAULT_INCLUDES) $(INCLUDES) $(AM_CPPFLAGS) $(CPPFLAGS) $(AM_CFLAGS) $(CFLAGS) -c -o sst.o `test -f 'flash/sst.c' || echo '$(srcdir)/'`flash/sst.c

 

sst.obj: flash/sst.c

@am__fastdepCC_TRUE@ if $(CC) $(DEFS) $(DEFAULT_INCLUDES) $(INCLUDES) $(AM_CPPFLAGS) $(CPPFLAGS) $(AM_CFLAGS) $(CFLAGS) -MT sst.obj -MD -MP -MF "$(DEPDIR)/sst.Tpo" -c -o sst.obj `if test -f 'flash/sst.c'; then $(CYGPATH_W) 'flash/sst.c'; else $(CYGPATH_W) '$(srcdir)/flash/sst.c'; fi`; \

@am__fastdepCC_TRUE@ then mv -f "$(DEPDIR)/sst.Tpo" "$(DEPDIR)/sst.Po"; else rm -f "$(DEPDIR)/sst.Tpo"; exit 1; fi

@AMDEP_TRUE@@am__fastdepCC_FALSE@ source='flash/sst.c' object='sst.obj' libtool=no @AMDEPBACKSLASH@

@AMDEP_TRUE@@am__fastdepCC_FALSE@ DEPDIR=$(DEPDIR) $(CCDEPMODE) $(depcomp) @AMDEPBACKSLASH@

@am__fastdepCC_FALSE@ $(CC) $(DEFS) $(DEFAULT_INCLUDES) $(INCLUDES) $(AM_CPPFLAGS) $(CPPFLAGS) $(AM_CFLAGS) $(CFLAGS) -c -o sst.obj `if test -f 'flash/sst.c'; then $(CYGPATH_W) 'flash/sst.c'; else $(CYGPATH_W) '$(srcdir)/flash/sst.c'; fi`

uninstall-info-am:

 

Все проинсталировалось, jtag собрался, но все одно, не видит флэша.

 

По поводу того, правильные ли это параметры флэша, не знаю, взял из соседней ST тоже 2MB флэшка,

 

size = 0x00200000,

.numeraseregions = 4,

.regions = {

{ .offset = 0x000000, .erasesize = 0x10000, .numblocks = 31 },

{ .offset = 0x1F0000, .erasesize = 0x08000, .numblocks = 1 },

{ .offset = 0x1F8000, .erasesize = 0x02000, .numblocks = 2 },

{ .offset = 0x1FC000, .erasesize = 0x04000, .numblocks = 1 }

}

 

скажу только, что флэшка по описанию

 

sst39vf160

Sector: 512

Size: 2MB

ID:278200BF

Width:16-bit

 

Прошу не бросать меня на пол пути, помогите до конца дойти.

 

 

 

 

 

 

 

Вот кстати из jtager-0.3.0.tar.tar

нашел файлик sst39vf160.c

 

 

/*

* mtd/sst39vf160.c : implements the read/write ops of SST39VF160 flash chip.

*

* Copyright © 2003, Rongkai Zhan <zhanrk@163.com>

*

* This program is free software; you can redistribute it and/or modify

* it under the terms of the GNU General Public License as published by

* the Free Software Foundation; either version 2 of the License, or

* (at your option) any later version.

*

* This program is distributed in the hope that it will be useful,

* but WITHOUT ANY WARRANTY; without even the implied warranty of

* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the

* GNU General Public License for more details.

*

* You should have received a copy of the GNU General Public License

* along with this program; if not, write to the Free Software

* Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA

*/

 

/* $Id: sst39vf160.c,v 1.2 2004/10/17 08:04:28 zhanrk Exp $ */

 

/*

* References:

* [1] <<SST39LF160/SST39VF160 datasheet>>

*/

 

#include <unistd.h>

#include <stdio.h>

#include <stdlib.h>

#include <string.h>

 

#include "jtager.h"

#include "target.h"

#include "flash.h"

 

#define MANU_ID 0x00BF /* SST Manufacturer ID code */

#define DEVICE_ID 0x2782 /* SST 39VF160 device code */

 

#define SECTOR_SIZE (2 * 1024 * 2) /* 2K words = 4K Bytes */

#define CHIP_SIZE (1024 * 1024 * 2) /* 1M words = 2M Bytes */

#define CHIP_BASE (sst39vf160.base)

 

#define SECTOR_MASK (SECTOR_SIZE - 1)

 

#define CMD_ADDR1 (sst39vf160.base + (0x5555 << 1))

#define CMD_ADDR2 (sst39vf160.base + (0x2aaa << 1))

 

#define DQ6_MASK 0x40

#define DQ7_MASK 0x80

 

flash_t sst39vf160;

 

static int chip_probe(u32 base)

{

u16 id1 = 0, id2 = 0;

u16 softid_cmd[4] = {0xAAAA, 0x5555, 0x9090, 0xF0F0};

u16 old1, old2;

u32 old_base = CHIP_BASE;

int ret;

 

CHIP_BASE = base; /* update chip base address */

 

/* save the contents of these two memory units */

old1 = read16(CMD_ADDR1);

old2 = read16(CMD_ADDR2);

 

/* write ID commands */

write16(softid_cmd[0], CMD_ADDR1);

write16(softid_cmd[1], CMD_ADDR2);

write16(softid_cmd[2], CMD_ADDR1);

 

/* read MANU_ID & DEVICE_ID */

id1 = read16(base + (0x00 << 1));

id2 = read16(base + (0x01 << 1));

 

/* check Manufacture ID and Device ID */

if ((id1 == MANU_ID) && (id2 == DEVICE_ID))

ret = 0;

else

ret = -1;

 

/* Software ID Exit / CFI Exit */

write16(softid_cmd[0], CMD_ADDR1);

write16(softid_cmd[1], CMD_ADDR2);

write16(softid_cmd[3], CMD_ADDR1);

 

if (ret) {

CHIP_BASE = old_base;

write16(old1, CMD_ADDR1);

write16(old2, CMD_ADDR2);

}

return ret;

} /* end of chip_probe (...) */

 

/*

* DQ6 is still toggling bit?

*/

static int chip_is_busy(u32 addr)

{

u16 oldval, newval;

u32 count = 0;

int ret = -1, timeout = 0;

 

addr = addr16_align(addr);

 

while (1) {

oldval = read16(addr);

newval = read16(addr);

if ((oldval & DQ6_MASK) == (newval & DQ6_MASK)) {

/* DQ6 stops toggle */

ret = 0;

break;

}

 

count++;

if (count > 0xF0000000) {

timeout = 1;

break;

}

}

 

if (timeout) {

/*

* oh, this is the last chance for success.

*/

oldval = read16(addr);

newval = read16(addr);

if ((oldval & DQ6_MASK) == (newval & DQ6_MASK))

ret = 0;

else

ret = -1;

}

return ret;

}

 

/**

* erase_sector - erase one sector

* @addr: any address in the sector to be erased.

*

* Return value: If success, return 0. Otherwise, return -1.

*/

static int erase_sector(u32 addr)

{

u16 erase_sector_cmd[6] = {0xAAAA, 0x5555, 0x8080,

0xAAAA, 0x5555, 0x3030};

u32 sector_addr = addr & (~((u32)SECTOR_SIZE - 1));

int ret;

 

write16(erase_sector_cmd[0], CMD_ADDR1);

write16(erase_sector_cmd[1], CMD_ADDR2);

write16(erase_sector_cmd[2], CMD_ADDR1);

write16(erase_sector_cmd[3], CMD_ADDR1);

write16(erase_sector_cmd[4], CMD_ADDR2);

write16(erase_sector_cmd[5], sector_addr);

 

/* chip is busy ? */

sector_addr += (SECTOR_SIZE - 2);

ret = chip_is_busy(sector_addr);

return ret;

} /* end of erase_sector(...) */

 

static int erase_chip(void)

{

u16 erase_chip_cmd[6] = {0xAAAA, 0x5555, 0x8080,

0xAAAA, 0x5555, 0x1010};

u32 base, wait = 500000;

int ret;

 

write16(erase_chip_cmd[0], CMD_ADDR1);

write16(erase_chip_cmd[1], CMD_ADDR2);

write16(erase_chip_cmd[2], CMD_ADDR1);

write16(erase_chip_cmd[3], CMD_ADDR1);

write16(erase_chip_cmd[4], CMD_ADDR2);

write16(erase_chip_cmd[5], CMD_ADDR1);

 

/*

* Chip erase is a long way, we just wait for a while.

*/

while (wait)

wait--;

 

base = CHIP_BASE + (CHIP_SIZE - 2);

ret = chip_is_busy(base);

 

return ret;

} /* end of erase_chip() */

 

/**

* flash_write - write flash memory with the source data from target memory or host buffer

* @start_address: The flash start address to be written.

* @bytenr: how many bytes are to be written.

* @source_address: The address of source data.

* @from_host: If from_host == 0, we read the source data from a target memory block

* If from_host != 0, we read the source data from a host buffer.

*/

static int flash_write(u32 start_address, u32 bytenr, u32 source_address, int from_host)

{

u16 pgm_cmd[3] = {0xAAAA, 0x5555, 0xA0A0};

u32 current_addr;

int i, retry, ret;

u16 data;

 

if ((start_address < CHIP_BASE)

|| (start_address + bytenr - 1) > (CHIP_BASE + CHIP_SIZE - 1))

return -1; /* out of range */

 

/* align address with the 16-bit word boundary */

current_addr = addr16_align(start_address);

 

for (i = 0; i < (bytenr/2); i++) {

if (from_host)

data = *(u16 *)source_address; /* read data from host buffer */

else

data = read16(source_address);

source_address += 2;

if (data == 0xFFFF) {

current_addr += 2;

continue;

}

retry = 0;

retry_pgm:

write16(pgm_cmd[0], CMD_ADDR1);

write16(pgm_cmd[1], CMD_ADDR2);

write16(pgm_cmd[2], CMD_ADDR1);

write16(data, current_addr);

 

ret = chip_is_busy(current_addr);

if (ret && retry < 3) {

retry++;

goto retry_pgm;

} else if (ret) {

break; /* failure */

}

 

current_addr += 2;

if ((i + 1)%(2*1024) == 0) {

printf(".");

fflush(stdout);

}

} /* end of for (i = 0; ... ) */

 

return ret;

} /* end of flash_write(...) */

 

flash_t sst39vf160 = {

.name = "sst39vf160",

.mfr_id = MANU_ID,

.dev_id = DEVICE_ID,

.base = 0x0L, /* start physical address */

.chip_size = CHIP_SIZE,

.sector_size = SECTOR_SIZE,

.bus_width = 16,

 

.probe = chip_probe,

.erase_sector = erase_sector,

.erase_chip = erase_chip,

.write = flash_write,

};

 

 

его можно прикрутить как нибудь?

 

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Paste as plain text instead

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...
На сайте используются файлы cookie и сервисы аналитики для корректной работы форума и улучшения качества обслуживания. Продолжая использовать сайт, вы соглашаетесь с использованием файлов cookie и с Политикой конфиденциальности.