Hello,
I have patch for openocd so it can write and erase the flash memory on an ADuC
702x microcontroller.
The patch worked with an older version of openocd. Now I've applied the patch
to the latest SVN code and suddenly the program segfaults when try to write or
erase the device. Can anyone help me make it work again?
The original code was written by Kevin McGuire I think, I can't find the
original web page any more. all the credits for the patch should go to Mr.
McGuire
Thanks in advance,
Marcel Wijlaars
diff -Nur svn_openocd/src/aduc702x.cfg new_openocd/src/aduc702x.cfg
--- svn_openocd/src/aduc702x.cfg 1970-01-01 01:00:00.000000000 +0100
+++ new_openocd/src/aduc702x.cfg 2008-09-18 21:24:47.000000000 +0200
@@ -0,0 +1,54 @@
+## -*- tcl -*-
+##
+
+#daemon configuration
+telnet_port 4444
+gdb_port 3333
+
+#interface
+interface ft2232
+ft2232_device_desc "Olimex OpenOCD JTAG"
+ft2232_serial "FTQ2C9N6"
+ft2232_layout "olimex-jtag"
+ft2232_vid_pid 0x15ba 0x0003
+
+jtag_speed 0
+jtag_nsrst_delay 200
+jtag_ntrst_delay 200
+
+# This is for the case that TRST/SRST is not wired on your JTAG adaptor.
+# Don't really need them anyways.
+reset_config none
+
+## JTAG scan chain
+#format L IRC IRCM IDCODE (Length, IR Capture, IR Capture Mask, IDCODE)
+jtag_device 4 0x1 0xf 0xe
+
+##
+## Target configuration
+##
+target arm7tdmi little 0
+
+## software initiated reset (if your SRST isn't wired)
+#proc target_0_reset {} { mwb 0x0ffff0230 04 }
+
+# use top 1k of SRAM for as temporary JTAG memory
+#working_area 0 0x11C00 0x400 backup
+
+## flash configuration
+## AdUC702x not yet spported :(
+flash bank x7026 0x80000 0x10000 2 2 0
+
+## If you use the watchdog, the following code makes sure that the board
+## doesn't reboot when halted via JTAG. Yes, on the older generation
+## AdUC702x, timer3 continues running even when the CPU is halted.
+
+proc watchdog_service {} {
+ global watchdog_hdl
+ mww 0xffff036c 0
+# puts "watchdog!!"
+ set watchdog_hdl [after 500 watchdog_service]
+}
+
+[new_target_name] configure -event reset-halt-post { watchdog_service }
+[new_target_name] configure -event old-pre_resume { global watchdog_hdl; after cancel $watchdog_hdl }
diff -Nur svn_openocd/src/flash/7026.c new_openocd/src/flash/7026.c
--- svn_openocd/src/flash/7026.c 1970-01-01 01:00:00.000000000 +0100
+++ new_openocd/src/flash/7026.c 2008-09-18 14:40:03.000000000 +0200
@@ -0,0 +1,198 @@
+/* Original file fome Kevin McGuire */
+/* Movified by Marcel Wijlaars */
+
+#ifdef HAVE_CONFIG_H
+#include "config.h"
+#endif
+
+#include "replacements.h"
+
+#include "flash.h"
+#include "target.h"
+#include "log.h"
+#include "armv4_5.h"
+#include "algorithm.h"
+#include "binarybuffer.h"
+
+#include <stdlib.h>
+#include <string.h>
+#include <unistd.h>
+
+int x7026_flash_bank_command(struct command_context_s *cmd_ctx, char *cmd, char **args, int argc, struct flash_bank_s *bank);
+int x7026_register_commands(struct command_context_s *cmd_ctx);
+int x7026_erase(struct flash_bank_s *bank, int first, int last);
+int x7026_protect(struct flash_bank_s *bank, int set, int first, int last);
+int x7026_write(struct flash_bank_s *bank, u8 *buffer, u32 offset, u32 count);
+int x7026_probe(struct flash_bank_s *bank);
+int x7026_info(struct flash_bank_s *bank, char *buf, int buf_size);
+int x7026_protect_check(struct flash_bank_s *bank);
+int x7026_erase_check(struct flash_bank_s *bank);
+
+#define ADUC7026_FLASH 0xfffff800
+#define ADUC7026_FLASH_FEESTA (0*4)
+#define ADUC7026_FLASH_FEEMOD (1*4)
+#define ADUC7026_FLASH_FEECON (2*4)
+#define ADUC7026_FLASH_FEEDAT (3*4)
+#define ADUC7026_FLASH_FEEADR (4*4)
+#define ADUC7026_FLASH_FEESIGN (5*4)
+#define ADUC7026_FLASH_FEEPRO (6*4)
+#define ADUC7026_FLASH_FEEHIDE (7*4)
+
+typedef struct{
+ uint32_t feesta;
+ uint32_t feemod;
+ uint32_t feecon;
+ uint32_t feedat;
+ uint32_t feeadr;
+ uint32_t feesign;
+ uint32_t feepro;
+ uint32_t feehide;
+} ADUC7026_FLASH_MMIO;
+
+typedef struct
+{
+ unsigned char tmp;
+} X7026_BANK;
+
+flash_driver_t x7026_flash =
+{
+ .name = "x7026",
+ .register_commands = x7026_register_commands,
+ .flash_bank_command = x7026_flash_bank_command,
+ .erase = x7026_erase,
+ .protect = x7026_protect,
+ .write = x7026_write,
+ .probe = x7026_probe,
+ .erase_check = x7026_erase_check,
+ .protect_check = x7026_protect_check,
+ .info = x7026_info
+};
+
+int x7026_register_commands(struct command_context_s *cmd_ctx)
+{
+ printf("x7026_register_commands not implemented yet.\n");
+ return ERROR_OK;
+}
+
+/* flash bank str7x <base> <size> 0 0 <target#> */
+int x7026_flash_bank_command(struct command_context_s *cmd_ctx, char *cmd, char **args, int argc, struct flash_bank_s *bank)
+{
+ X7026_BANK *nbank;
+
+ if (argc < 6)
+ {
+ LOG_WARNING("incomplete flash_bank x7026 configuration");
+ return ERROR_FLASH_BANK_INVALID;
+ }
+
+ nbank = malloc(sizeof(X7026_BANK));
+ /* just warn that we are used to normally using 0x80000 */
+ if(bank->base != 0x80000)
+ {
+ LOG_WARNING("Default base address is 0x80000 on the ADuC7026!");
+ }
+ nbank->tmp = 1;
+ bank->driver_priv = nbank;
+ return ERROR_OK;
+}
+
+int x7026_protect_check(struct flash_bank_s *bank)
+{
+ printf("x7026_protect_check not implemented yet.\n");
+ return ERROR_OK;
+}
+
+int x7026_erase(struct flash_bank_s *bank, int first, int last)
+{
+ unsigned int x;
+ int count;
+ u32 v;
+ target_t *target = bank->target;
+
+ /* mass erase */
+ if((first | last) == 0)
+ {
+ printf("performing mass erase.\n");
+ target_write_u32(target, ADUC7026_FLASH + ADUC7026_FLASH_FEEDAT, 0x3cff);
+ target_write_u32(target, ADUC7026_FLASH + ADUC7026_FLASH_FEEADR, 0xffc3);
+ target_read_u32(target, ADUC7026_FLASH + ADUC7026_FLASH_FEEMOD, &v);
+ target_write_u32(target, ADUC7026_FLASH + ADUC7026_FLASH_FEEMOD, v | 0x8);
+ target_write_u32(target, ADUC7026_FLASH + ADUC7026_FLASH_FEECON, 0x06);
+ for(v = 0x4; v & 0x4;
+ target_read_u32(target, ADUC7026_FLASH + ADUC7026_FLASH_FEESTA, &v));
+
+ if(!(v & 0x1))
+ {
+ printf("mass erase failed.\n");
+ return -1;
+ }
+ printf("mass erase successful.\n");
+ return ERROR_OK;
+ }
+
+ count = last - first;
+ for(x = 0; x < (unsigned int)count; ++x)
+ {
+ target_write_u32(target, ADUC7026_FLASH + ADUC7026_FLASH_FEEADR, bank->base + first * 512 + x * 512);
+ target_write_u32(target, ADUC7026_FLASH + ADUC7026_FLASH_FEECON, 0x05);
+ for(v = 0x4; v & 0x4; target_read_u32(target, ADUC7026_FLASH + ADUC7026_FLASH_FEESTA, &v));
+ if(!(v & 0x1))
+ {
+ printf("erase failed for page address %x\n", bank->base + first * 512 + x * 512);
+ return -1;
+ }
+ printf("erased page address %x\n", bank->base + first * 512 + x * 512);
+ }
+ return ERROR_OK;
+}
+
+int x7026_protect(struct flash_bank_s *bank, int set, int first, int last)
+{
+ printf("x7026_protect not implemented yet.\n");
+ return -1;
+}
+
+int x7026_write(struct flash_bank_s *bank, u8 *buffer, u32 offset, u32 count)
+{
+ unsigned int x;
+ u32 v;
+ target_t *target = bank->target;
+ for(x = 0; x < count; x += 2)
+ {
+ target_write_u32(target, ADUC7026_FLASH + ADUC7026_FLASH_FEEADR, offset + x);
+ /* if we able to encounter a single byte instead of a word */
+ if((x + 1) == count)
+ {
+ target_write_u32(target, ADUC7026_FLASH + ADUC7026_FLASH_FEEDAT, buffer[x]);
+ }else{
+ target_write_u32(target, ADUC7026_FLASH + ADUC7026_FLASH_FEEDAT, buffer[x] | (buffer[x+1] << 8));
+ }
+ target_write_u32(target, ADUC7026_FLASH + ADUC7026_FLASH_FEECON, 0x02);
+ for(v = 0x4; v & 0x4; target_read_u32(target, ADUC7026_FLASH + ADUC7026_FLASH_FEESTA, &v));
+ if(!(v & 0x1))
+ {
+ printf("single write failed for address %x.\n", offset + x);
+ return -1;
+ }
+ printf("single write for address %x.\n", offset + x);
+ }
+ return ERROR_OK;
+}
+
+int x7026_probe(struct flash_bank_s *bank)
+{
+ printf("x7026_probe not implemented yet.\n");
+ return -1;
+}
+
+int x7026_info(struct flash_bank_s *bank, char *buf, int buf_size)
+{
+ snprintf(buf, buf_size, "x7026 flash driver info" );
+ return -1;
+}
+
+int x7026_erase_check(struct flash_bank_s *bank)
+{
+ printf("x7026_erase_check not implemented yet.\n");
+ return -1;
+}
diff -Nur svn_openocd/src/flash/Makefile.am new_openocd/src/flash/Makefile.am
--- svn_openocd/src/flash/Makefile.am 2008-09-17 15:30:40.000000000 +0200
+++ new_openocd/src/flash/Makefile.am 2008-09-19 00:44:35.000000000 +0200
@@ -2,7 +2,7 @@
AM_CPPFLAGS = -DPKGLIBDIR=\"$(pkglibdir)\" @CPPFLAGS@
METASOURCES = AUTO
noinst_LIBRARIES = libflash.a
-libflash_a_SOURCES = flash.c lpc2000.c cfi.c non_cfi.c at91sam7.c str7x.c str9x.c nand.c lpc3180_nand_controller.c \
+libflash_a_SOURCES = flash.c lpc2000.c cfi.c non_cfi.c at91sam7.c str7x.c str9x.c 7026.c nand.c lpc3180_nand_controller.c \
stellaris.c str9xpec.c stm32x.c tms470.c ecos.c \
s3c24xx_nand.c s3c2410_nand.c s3c2412_nand.c s3c2440_nand.c s3c2443_nand.c lpc288x.c ocl.c
noinst_HEADERS = flash.h lpc2000.h cfi.h non_cfi.h at91sam7.h str7x.h str9x.h nand.h lpc3180_nand_controller.h \
diff -Nur svn_openocd/src/flash/Makefile.in new_openocd/src/flash/Makefile.in
--- svn_openocd/src/flash/Makefile.in 2008-09-17 16:18:34.000000000 +0200
+++ new_openocd/src/flash/Makefile.in 2008-09-19 00:46:42.000000000 +0200
@@ -54,7 +54,7 @@
libflash_a_LIBADD =
am_libflash_a_OBJECTS = flash.$(OBJEXT) lpc2000.$(OBJEXT) \
cfi.$(OBJEXT) non_cfi.$(OBJEXT) at91sam7.$(OBJEXT) \
- str7x.$(OBJEXT) str9x.$(OBJEXT) nand.$(OBJEXT) \
+ str7x.$(OBJEXT) str9x.$(OBJEXT) 7026.$(OBJEXT) nand.$(OBJEXT) \
lpc3180_nand_controller.$(OBJEXT) stellaris.$(OBJEXT) \
str9xpec.$(OBJEXT) stm32x.$(OBJEXT) tms470.$(OBJEXT) \
ecos.$(OBJEXT) s3c24xx_nand.$(OBJEXT) s3c2410_nand.$(OBJEXT) \
@@ -205,7 +205,7 @@
AM_CPPFLAGS = -DPKGLIBDIR=\"$(pkglibdir)\" @CPPFLAGS@
METASOURCES = AUTO
noinst_LIBRARIES = libflash.a
-libflash_a_SOURCES = flash.c lpc2000.c cfi.c non_cfi.c at91sam7.c str7x.c str9x.c nand.c lpc3180_nand_controller.c \
+libflash_a_SOURCES = flash.c lpc2000.c cfi.c non_cfi.c at91sam7.c str7x.c str9x.c 7026.c nand.c lpc3180_nand_controller.c \
stellaris.c str9xpec.c stm32x.c tms470.c ecos.c \
s3c24xx_nand.c s3c2410_nand.c s3c2412_nand.c s3c2440_nand.c s3c2443_nand.c lpc288x.c ocl.c
@@ -278,6 +278,7 @@
@AMDEP_TRUE@@am__include@ @[EMAIL PROTECTED]/$(DEPDIR)/[EMAIL PROTECTED]@
@AMDEP_TRUE@@am__include@ @[EMAIL PROTECTED]/$(DEPDIR)/[EMAIL PROTECTED]@
@AMDEP_TRUE@@am__include@ @[EMAIL PROTECTED]/$(DEPDIR)/[EMAIL PROTECTED]@
[EMAIL PROTECTED]@@am__include@ @[EMAIL PROTECTED]/$(DEPDIR)/[EMAIL PROTECTED]@
@AMDEP_TRUE@@am__include@ @[EMAIL PROTECTED]/$(DEPDIR)/[EMAIL PROTECTED]@
@AMDEP_TRUE@@am__include@ @[EMAIL PROTECTED]/$(DEPDIR)/[EMAIL PROTECTED]@
diff -Nur svn_openocd/src/flash/flash.c new_openocd/src/flash/flash.c
--- svn_openocd/src/flash/flash.c 2008-09-17 15:30:40.000000000 +0200
+++ new_openocd/src/flash/flash.c 2008-09-17 22:08:51.000000000 +0200
@@ -66,6 +66,7 @@
extern flash_driver_t at91sam7_flash;
extern flash_driver_t str7x_flash;
extern flash_driver_t str9x_flash;
+extern flash_driver_t x7026_flash;
extern flash_driver_t stellaris_flash;
extern flash_driver_t str9xpec_flash;
extern flash_driver_t stm32x_flash;
@@ -81,6 +82,7 @@
&at91sam7_flash,
&str7x_flash,
&str9x_flash,
+ &x7026_flash,
&stellaris_flash,
&str9xpec_flash,
&stm32x_flash,
_______________________________________________
Openocd-development mailing list
[email protected]
https://lists.berlios.de/mailman/listinfo/openocd-development