"marcel" <M.W.Wijlaars@tue.nl>,
authoroharboe <oharboe@b42882b7-edfa-0310-969c-e2dbd0fdcd60>
Wed, 24 Sep 2008 08:21:34 +0000 (08:21 +0000)
committeroharboe <oharboe@b42882b7-edfa-0310-969c-e2dbd0fdcd60>
Wed, 24 Sep 2008 08:21:34 +0000 (08:21 +0000)
I have the ADuC702x flashdriver working again (see attachment). It adds the option to erase and write the ADuC702x flash

git-svn-id: svn://svn.berlios.de/openocd/trunk@992 b42882b7-edfa-0310-969c-e2dbd0fdcd60

src/flash/Makefile.am
src/flash/flash.c
src/flash/x7026.c [new file with mode: 0644]
src/target/target/aduc702x.cfg

index 418a15c96d696058da0bd397fba33698ebef958f..77e870f1d6a0ec5d27dd5ae7d0898ad95c5e8139 100644 (file)
@@ -2,7 +2,7 @@ INCLUDES = -I$(top_srcdir)/src/helper -I$(top_srcdir)/src/jtag -I$(top_srcdir)/s
 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 x7026.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 \
index 5f9d78bc4a3565d9e7eb3b4497f1ae98e556bd4f..a1b64ade898fed1af0cf8c2df98720faa9038e86 100644 (file)
@@ -69,6 +69,7 @@ extern flash_driver_t cfi_flash;
 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;
@@ -84,6 +85,7 @@ flash_driver_t *flash_drivers[] =
        &at91sam7_flash,
        &str7x_flash,
        &str9x_flash,
+       &x7026_flash,
        &stellaris_flash,
        &str9xpec_flash,
        &stm32x_flash,
@@ -148,7 +150,7 @@ int flash_register_commands(struct command_context_s *cmd_ctx)
 static int jim_flash_banks(Jim_Interp *interp, int argc, Jim_Obj *const *argv)
 {
        flash_bank_t *p;
-       
+
        if (argc != 1) {
                Jim_WrongNumArgs(interp, 1, argv, "no arguments to flash_banks command");
                return JIM_ERR;
@@ -163,7 +165,7 @@ static int jim_flash_banks(Jim_Interp *interp, int argc, Jim_Obj *const *argv)
        for (p = flash_banks; p; p = p->next)
        {
                Jim_Obj *elem=Jim_NewListObj(interp, NULL, 0);
-               
+
                Jim_ListAppendElement(interp, elem, Jim_NewStringObj(interp, "name", -1));
                Jim_ListAppendElement(interp, elem, Jim_NewStringObj(interp, p->driver->name, -1));
                Jim_ListAppendElement(interp, elem, Jim_NewStringObj(interp, "base", -1));
@@ -174,7 +176,7 @@ static int jim_flash_banks(Jim_Interp *interp, int argc, Jim_Obj *const *argv)
                Jim_ListAppendElement(interp, elem, Jim_NewIntObj(interp, p->bus_width));
                Jim_ListAppendElement(interp, elem, Jim_NewStringObj(interp, "chip_width", -1));
                Jim_ListAppendElement(interp, elem, Jim_NewIntObj(interp, p->chip_width));
-               
+
                Jim_ListAppendElement(interp, list, elem);
        }
 
@@ -188,7 +190,7 @@ int flash_init_drivers(struct command_context_s *cmd_ctx)
        if (flash_banks)
        {
                register_jim(cmd_ctx, "ocd_flash_banks", jim_flash_banks, "return information about the flash banks");
-               
+
                register_command(cmd_ctx, flash_cmd, "info", handle_flash_info_command, COMMAND_EXEC,
                                                 "print info about flash bank <num>");
                register_command(cmd_ctx, flash_cmd, "probe", handle_flash_probe_command, COMMAND_EXEC,
@@ -452,7 +454,7 @@ int handle_flash_erase_check_command(struct command_context_s *cmd_ctx, char *cm
                        command_print(cmd_ctx, "unknown error when checking erase state of flash bank #%s at 0x%8.8x",
                                args[0], p->base);
                }
-               
+
                for (j = 0; j < p->num_sectors; j++)
                {
                        char *erase_state;
@@ -468,7 +470,7 @@ int handle_flash_erase_check_command(struct command_context_s *cmd_ctx, char *cm
                                                j, p->sectors[j].offset, p->sectors[j].size, p->sectors[j].size>>10,
                                                erase_state);
                }
-               
+
        }
 
        return ERROR_OK;
@@ -642,10 +644,10 @@ int handle_flash_write_image_command(struct command_context_s *cmd_ctx, char *cm
        {
                return ERROR_COMMAND_SYNTAX_ERROR;
        }
-       
+
        /* flash auto-erase is disabled by default*/
        int auto_erase = 0;
-       
+
        if (strcmp(args[0], "erase")==0)
        {
                auto_erase = 1;
@@ -653,13 +655,13 @@ int handle_flash_write_image_command(struct command_context_s *cmd_ctx, char *cm
                argc--;
                command_print(cmd_ctx, "auto erase enabled");
        }
-       
+
 
        if (argc < 1)
        {
                return ERROR_COMMAND_SYNTAX_ERROR;
        }
-       
+
        if (!target)
        {
                LOG_ERROR("no target selected");
@@ -722,16 +724,16 @@ int handle_flash_fill_command(struct command_context_s *cmd_ctx, char *cmd, char
        target_t *target = get_current_target(cmd_ctx);
        u32 i;
        int wordsize;
-       
+
        if (argc != 3)
        {
                return ERROR_COMMAND_SYNTAX_ERROR;
        }
-       
+
        address = strtoul(args[0], NULL, 0);
        pattern = strtoul(args[1], NULL, 0);
        count   = strtoul(args[2], NULL, 0);
-       
+
        if(count == 0)
                return ERROR_OK;
 
@@ -750,7 +752,7 @@ int handle_flash_fill_command(struct command_context_s *cmd_ctx, char *cmd, char
        default:
                return ERROR_COMMAND_SYNTAX_ERROR;
        }
-       
+
        chunk_count = MIN(count, (1024 / wordsize));
        switch(wordsize)
        {
@@ -773,7 +775,7 @@ int handle_flash_fill_command(struct command_context_s *cmd_ctx, char *cmd, char
                LOG_ERROR("BUG: can't happen");
                exit(-1);
        }
-       
+
        duration_start_measure(&duration);
 
        flash_set_dirty();
@@ -781,7 +783,7 @@ int handle_flash_fill_command(struct command_context_s *cmd_ctx, char *cmd, char
        if (err == ERROR_OK)
        {
                for (wrote=0; wrote<(count*wordsize); wrote+=sizeof(chunk))
-               { 
+               {
                        int cur_size = MIN( (count*wordsize - wrote) , 1024 );
                        if (err == ERROR_OK)
                        {
@@ -799,7 +801,7 @@ int handle_flash_fill_command(struct command_context_s *cmd_ctx, char *cmd, char
                                break;
                }
        }
-       
+
        duration_stop_measure(&duration, &duration_text);
 
        if(err == ERROR_OK)
@@ -973,7 +975,7 @@ int flash_write(target_t *target, image_t *image, u32 *written, int erase)
        u32 section_offset;
        flash_bank_t *c;
        int *padding;
-       
+
        section = 0;
        section_offset = 0;
 
@@ -987,10 +989,10 @@ int flash_write(target_t *target, image_t *image, u32 *written, int erase)
 
                flash_set_dirty();
        }
-       
+
        /* allocate padding array */
        padding = malloc(image->num_sections * sizeof(padding));
-       
+
        /* loop until we reach end of the image */
        while (section < image->num_sections)
        {
@@ -1001,7 +1003,7 @@ int flash_write(target_t *target, image_t *image, u32 *written, int erase)
                u32 run_address = image->sections[section].base_address + section_offset;
                u32 run_size = image->sections[section].size - section_offset;
                int pad_bytes = 0;
-               
+
                if (image->sections[section].size ==  0)
                {
                        LOG_WARNING("empty section %d", section);
@@ -1039,7 +1041,7 @@ int flash_write(target_t *target, image_t *image, u32 *written, int erase)
                        run_size += image->sections[++section_last].size;
                        run_size += pad_bytes;
                        padding[section_last] = 0;
-                       
+
                        LOG_INFO("Padding image section %d with %d bytes", section_last-1, pad_bytes );
                }
 
@@ -1067,11 +1069,11 @@ int flash_write(target_t *target, image_t *image, u32 *written, int erase)
                                free(padding);
                                return retval;
                        }
-                       
+
                        /* see if we need to pad the section */
                        while (padding[section]--)
                                 (buffer+buffer_size)[size_read++] = 0xff;
-                       
+
                        buffer_size += size_read;
                        section_offset += size_read;
 
@@ -1107,9 +1109,9 @@ int flash_write(target_t *target, image_t *image, u32 *written, int erase)
                if (written != NULL)
                        *written += run_size; /* add run size to total written counter */
        }
-       
+
        free(padding);
-       
+
        return retval;
 }
 
@@ -1120,18 +1122,18 @@ int default_flash_mem_blank_check(struct flash_bank_s *bank)
        int buffer_size = sizeof(buffer);
        int i;
        int nBytes;
-       
+
        if (bank->target->state != TARGET_HALTED)
        {
                LOG_ERROR("Target not halted");
                return ERROR_TARGET_NOT_HALTED;
        }
-       
+
        for (i = 0; i < bank->num_sectors; i++)
        {
                int j;
                bank->sectors[i].is_erased = 1;
-               
+
                for (j = 0; j < bank->sectors[i].size; j += buffer_size)
                {
                        int chunk;
@@ -1141,11 +1143,11 @@ int default_flash_mem_blank_check(struct flash_bank_s *bank)
                        {
                                chunk = (j - bank->sectors[i].size);
                        }
-                       
+
                        retval = target->type->read_memory(target, bank->base + bank->sectors[i].offset + j, 4, chunk/4, buffer);
                        if (retval != ERROR_OK)
                                return retval;
-               
+
                        for (nBytes = 0; nBytes < chunk; nBytes++)
                        {
                                if (buffer[nBytes] != 0xFF)
@@ -1156,7 +1158,7 @@ int default_flash_mem_blank_check(struct flash_bank_s *bank)
                        }
                }
        }
-       
+
        return ERROR_OK;
 }
 
@@ -1167,18 +1169,18 @@ int default_flash_blank_check(struct flash_bank_s *bank)
        int retval;
        int fast_check = 0;
        int blank;
-       
+
        if (bank->target->state != TARGET_HALTED)
        {
                LOG_ERROR("Target not halted");
                return ERROR_TARGET_NOT_HALTED;
        }
-               
+
        for (i = 0; i < bank->num_sectors; i++)
        {
                u32 address = bank->base + bank->sectors[i].offset;
                u32 size = bank->sectors[i].size;
-               
+
                if ((retval = target_blank_check_memory(target, address, size, &blank)) != ERROR_OK)
                {
                        fast_check = 0;
@@ -1190,12 +1192,12 @@ int default_flash_blank_check(struct flash_bank_s *bank)
                        bank->sectors[i].is_erased = 0;
                fast_check = 1;
        }
-               
+
        if (!fast_check)
        {
                LOG_USER("Running slow fallback erase check - add working memory");
                return default_flash_mem_blank_check(bank);
        }
-       
+
        return ERROR_OK;
 }
diff --git a/src/flash/x7026.c b/src/flash/x7026.c
new file mode 100644 (file)
index 0000000..e700a8b
--- /dev/null
@@ -0,0 +1,217 @@
+/***************************************************************************\r
+ *   Copyright (C) 2008 by Kevin McGuire                                   *\r
+ *   Copyright (C) 2008 by Marcel Wijlaars                                 *\r
+ *\r
+ *   This program is free software; you can redistribute it and/or modify  *\r
+ *   it under the terms of the GNU General Public License as published by  *\r
+ *   the Free Software Foundation; either version 2 of the License, or     *\r
+ *   (at your option) any later version.                                   *\r
+ *                                                                         *\r
+ *   This program is distributed in the hope that it will be useful,       *\r
+ *   but WITHOUT ANY WARRANTY; without even the implied warranty of        *\r
+ *   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the         *\r
+ *   GNU General Public License for more details.                          *\r
+ *                                                                         *\r
+ *   You should have received a copy of the GNU General Public License     *\r
+ *   along with this program; if not, write to the                         *\r
+ *   Free Software Foundation, Inc.,                                       *\r
+ *   59 Temple Place - Suite 330, Boston, MA  02111-1307, USA.             *\r
+ ***************************************************************************/\r
+\r
+\r
+#ifdef HAVE_CONFIG_H\r
+#include "config.h"\r
+#endif\r
+\r
+#include "replacements.h"\r
+\r
+#include "flash.h"\r
+#include "target.h"\r
+#include "log.h"\r
+#include "armv4_5.h"\r
+#include "algorithm.h"\r
+#include "binarybuffer.h"\r
+\r
+#include <stdlib.h>\r
+#include <string.h>\r
+#include <unistd.h>\r
+\r
+int x7026_flash_bank_command(struct command_context_s *cmd_ctx, char *cmd, char **args, int argc, struct flash_bank_s *bank);\r
+int x7026_register_commands(struct command_context_s *cmd_ctx);\r
+int x7026_erase(struct flash_bank_s *bank, int first, int last);\r
+int x7026_protect(struct flash_bank_s *bank, int set, int first, int last);\r
+int x7026_write(struct flash_bank_s *bank, u8 *buffer, u32 offset, u32 count);\r
+int x7026_probe(struct flash_bank_s *bank);\r
+int x7026_info(struct flash_bank_s *bank, char *buf, int buf_size);\r
+int x7026_protect_check(struct flash_bank_s *bank);\r
+int x7026_erase_check(struct flash_bank_s *bank);\r
+\r
+#define ADUC7026_FLASH                         0xfffff800\r
+#define ADUC7026_FLASH_FEESTA                  (0*4)\r
+#define ADUC7026_FLASH_FEEMOD                  (1*4)\r
+#define ADUC7026_FLASH_FEECON                  (2*4)\r
+#define ADUC7026_FLASH_FEEDAT                  (3*4)\r
+#define ADUC7026_FLASH_FEEADR                  (4*4)\r
+#define ADUC7026_FLASH_FEESIGN         (5*4)\r
+#define ADUC7026_FLASH_FEEPRO                  (6*4)\r
+#define ADUC7026_FLASH_FEEHIDE         (7*4)\r
+\r
+typedef struct{\r
+       uint32_t        feesta;\r
+       uint32_t        feemod;\r
+       uint32_t        feecon;\r
+       uint32_t        feedat;\r
+       uint32_t        feeadr;\r
+       uint32_t        feesign;\r
+       uint32_t        feepro;\r
+       uint32_t        feehide;\r
+} ADUC7026_FLASH_MMIO;\r
+\r
+typedef struct\r
+{\r
+       unsigned char tmp;\r
+} X7026_BANK;\r
+\r
+flash_driver_t x7026_flash =\r
+{\r
+       .name = "x7026",\r
+       .register_commands = x7026_register_commands,\r
+       .flash_bank_command = x7026_flash_bank_command,\r
+       .erase = x7026_erase,\r
+       .protect = x7026_protect,\r
+       .write = x7026_write,\r
+       .probe = x7026_probe,\r
+       .auto_probe = x7026_probe,\r
+       .erase_check = x7026_erase_check,\r
+       .protect_check = x7026_protect_check,\r
+       .info = x7026_info\r
+};\r
+\r
+int x7026_register_commands(struct command_context_s *cmd_ctx)\r
+{\r
+       printf("x7026_register_commands not implemented yet.\n");\r
+       return ERROR_OK;\r
+}\r
+\r
+/* flash bank str7x <base> <size> 0 0 <target#>  */\r
+int x7026_flash_bank_command(struct command_context_s *cmd_ctx, char *cmd, char **args, int argc, struct flash_bank_s *bank)\r
+{\r
+       X7026_BANK      *nbank;\r
+\r
+       if (argc < 6)\r
+       {\r
+               LOG_WARNING("incomplete flash_bank x7026 configuration");\r
+               return ERROR_FLASH_BANK_INVALID;\r
+       }\r
+\r
+       nbank = malloc(sizeof(X7026_BANK));\r
+       /* just warn that we are used to normally using 0x80000 */\r
+       if(bank->base != 0x80000)\r
+       {\r
+               LOG_WARNING("Default base address is 0x80000 on the ADuC7026!");\r
+       }\r
+       nbank->tmp = 1;\r
+       bank->driver_priv = nbank;\r
+       return ERROR_OK;\r
+}\r
+\r
+int x7026_protect_check(struct flash_bank_s *bank)\r
+{\r
+       printf("x7026_protect_check not implemented yet.\n");\r
+       return ERROR_OK;\r
+}\r
+\r
+int x7026_erase(struct flash_bank_s *bank, int first, int last)\r
+{\r
+       unsigned int    x;\r
+       int                     count;\r
+       u32                     v;\r
+       target_t *target = bank->target;\r
+\r
+       /* mass erase */\r
+       if((first | last) == 0)\r
+       {\r
+               printf("performing mass erase.\n");\r
+               target_write_u32(target, ADUC7026_FLASH + ADUC7026_FLASH_FEEDAT, 0x3cff);\r
+               target_write_u32(target, ADUC7026_FLASH + ADUC7026_FLASH_FEEADR, 0xffc3);\r
+               target_read_u32(target, ADUC7026_FLASH + ADUC7026_FLASH_FEEMOD, &v);\r
+               target_write_u32(target, ADUC7026_FLASH + ADUC7026_FLASH_FEEMOD, v | 0x8);\r
+               target_write_u32(target, ADUC7026_FLASH + ADUC7026_FLASH_FEECON, 0x06);\r
+               for(v = 0x4; v & 0x4;\r
+                       target_read_u32(target, ADUC7026_FLASH + ADUC7026_FLASH_FEESTA, &v));\r
+\r
+               if(!(v & 0x1))\r
+               {\r
+                       printf("mass erase failed.\n");\r
+                       return -1;\r
+               }\r
+               printf("mass erase successful.\n");\r
+               return ERROR_OK;\r
+       }\r
+\r
+       count = last - first;\r
+       for(x = 0; x < (unsigned int)count; ++x)\r
+       {\r
+               target_write_u32(target, ADUC7026_FLASH + ADUC7026_FLASH_FEEADR, bank->base + first * 512 + x * 512);\r
+               target_write_u32(target, ADUC7026_FLASH + ADUC7026_FLASH_FEECON, 0x05);\r
+               for(v = 0x4; v & 0x4; target_read_u32(target, ADUC7026_FLASH + ADUC7026_FLASH_FEESTA, &v));\r
+               if(!(v & 0x1))\r
+               {\r
+                       printf("erase failed for page address %x\n", bank->base + first * 512 + x * 512);\r
+                       return -1;\r
+               }\r
+               printf("erased page address %x\n", bank->base + first * 512 + x * 512);\r
+       }\r
+       return ERROR_OK;\r
+}\r
+\r
+int x7026_protect(struct flash_bank_s *bank, int set, int first, int last)\r
+{\r
+       printf("x7026_protect not implemented yet.\n");\r
+       return -1;\r
+}\r
+\r
+int x7026_write(struct flash_bank_s *bank, u8 *buffer, u32 offset, u32 count)\r
+{\r
+       unsigned int    x;\r
+       u32                     v;\r
+       target_t                *target = bank->target;\r
+       for(x = 0; x < count; x += 2)\r
+       {\r
+               target_write_u32(target, ADUC7026_FLASH + ADUC7026_FLASH_FEEADR, offset + x);\r
+               /* if we able to encounter a single byte instead of a word */\r
+               if((x + 1) == count)\r
+               {\r
+                       target_write_u32(target, ADUC7026_FLASH + ADUC7026_FLASH_FEEDAT, buffer[x]);\r
+               }else{\r
+                       target_write_u32(target, ADUC7026_FLASH + ADUC7026_FLASH_FEEDAT, buffer[x] | (buffer[x+1] << 8));\r
+               }\r
+               target_write_u32(target, ADUC7026_FLASH + ADUC7026_FLASH_FEECON, 0x02);\r
+               for(v = 0x4; v & 0x4; target_read_u32(target, ADUC7026_FLASH + ADUC7026_FLASH_FEESTA, &v));\r
+               if(!(v & 0x1))\r
+               {\r
+                       printf("single write failed for address %x.\n", offset + x);\r
+                       return -1;\r
+               }\r
+               printf("single write for address %x.\n", offset + x);\r
+       }\r
+       return ERROR_OK;\r
+}\r
+\r
+int x7026_probe(struct flash_bank_s *bank)\r
+{\r
+       printf("x7026_probe not implemented yet.\n");\r
+       return ERROR_OK;\r
+}\r
+\r
+int x7026_info(struct flash_bank_s *bank, char *buf, int buf_size)\r
+{\r
+       snprintf(buf, buf_size, "x7026 flash driver info" );\r
+       return -1;\r
+}\r
+\r
+int x7026_erase_check(struct flash_bank_s *bank)\r
+{\r
+       printf("x7026_erase_check not implemented yet.\n");\r
+       return -1;\r
+}\r
index 3bc474f223b3b53564b29356ef6953d95ddeda3d..e3e886202b75f7f3b99cf54fdaa4ccb76b545831 100644 (file)
@@ -1,6 +1,9 @@
 ## -*- tcl -*-
 ##
 
+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
@@ -21,7 +24,7 @@ target arm7tdmi little 0
 #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
@@ -34,5 +37,5 @@ proc watchdog_service {} {
     set watchdog_hdl [after 500 watchdog_service]
 }
 
-[new_target_name] configure -event old-post_halt {  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 }