]> git.sur5r.net Git - openocd/blobdiff - src/ecosboard.c
Allow -expected-id to be specified multiple times when creating a jtag tap
[openocd] / src / ecosboard.c
index f0ec433fd495bbb5259883c9891a475259a10175..34bb55898a27f00fbc98e6172b3a7b7007b77c22 100644 (file)
@@ -98,7 +98,7 @@ struct tftpd_fileops fileops =
 
 #endif
 
-#define ZYLIN_VERSION "1.47"
+#define ZYLIN_VERSION "1.48"
 #define ZYLIN_DATE __DATE__
 #define ZYLIN_TIME __TIME__
 /* hmmm....  we can't pick up the right # during build if we've checked this out
@@ -342,6 +342,9 @@ int handle_zy1000_version_command(struct command_context_s *cmd_ctx, char *cmd,
        return ERROR_OK;
 }
 
+
+
+
 extern flash_driver_t *flash_drivers[];
 extern target_type_t *target_types[];
 
@@ -350,6 +353,9 @@ extern target_type_t *target_types[];
 
 extern char _stext, _etext; // Defined by the linker
 
+static char *start_of_code=&_stext;
+static char *end_of_code=&_etext;
+
 void start_profile(void)
 {
        // This starts up the system-wide profiling, gathering
@@ -367,9 +373,9 @@ void start_profile(void)
        //       too large, the usefulness of the profile is reduced.
 
        // no more interrupts than 1/10ms.
-       //    profile_on(&_stext, &_etext, 16, 10000); // DRAM
        //profile_on((void *)0, (void *)0x40000, 16, 10000); // SRAM
-       profile_on(0, &_etext, 16, 10000); // SRAM & DRAM
+//     profile_on(0, &_etext, 16, 10000); // SRAM & DRAM
+       profile_on(start_of_code, end_of_code, 16, 10000); // Nios DRAM
 }
 #endif
 
@@ -543,10 +549,10 @@ static void setPower(bool power)
        savePower = power;
        if (power)
        {
-               HAL_WRITE_UINT32(0x08000014, 0x8);
+               HAL_WRITE_UINT32(ZY1000_JTAG_BASE+0x14, 0x8);
        } else
        {
-               HAL_WRITE_UINT32(0x08000010, 0x8);
+               HAL_WRITE_UINT32(ZY1000_JTAG_BASE+0x10, 0x8);
        }
 }
 
@@ -797,7 +803,9 @@ void _zylinjtag_diag_write_char(char c, void **param)
                HAL_DIAG_WRITE_CHAR(c);
        }
 
+#ifdef CYGPKG_HAL_ZYLIN_PHI
        printDccChar(c);
+#endif
 }
 
 #define SHOW_RESULT(a, b) diag_printf(#a " failed %d\n", (int)b)
@@ -928,6 +936,72 @@ void openocd_sleep_postlude()
        cyg_mutex_lock(&httpstate.jim_lock);
 }
 
+
+void format(void)
+{
+       diag_printf("Formatting JFFS2...\n");
+
+       cyg_io_handle_t handle;
+
+       Cyg_ErrNo err;
+       err = cyg_io_lookup(CYGDAT_IO_FLASH_BLOCK_DEVICE_NAME_1, &handle);
+       if (err != ENOERR)
+       {
+               diag_printf("Flash Error cyg_io_lookup: %d\n", err);
+               reboot();
+       }
+
+
+       cyg_uint32 len;
+       cyg_io_flash_getconfig_devsize_t ds;
+       len = sizeof (ds);
+       err = cyg_io_get_config(handle,
+                               CYG_IO_GET_CONFIG_FLASH_DEVSIZE, &ds, &len);
+       if (err != ENOERR)
+       {
+               diag_printf("Flash error cyg_io_get_config %d\n", err);
+               reboot();
+       }
+
+       cyg_io_flash_getconfig_erase_t e;
+       void *err_addr;
+       len = sizeof (e);
+
+       e.offset = 0;
+       e.len = ds.dev_size;
+       e.err_address = &err_addr;
+
+       diag_printf("Formatting 0x%08x bytes\n", ds.dev_size);
+       err = cyg_io_get_config(handle, CYG_IO_GET_CONFIG_FLASH_ERASE,
+                               &e, &len);
+       if (err != ENOERR)
+       {
+               diag_printf("Flash erase error %d offset 0x%p\n", err, err_addr);
+               reboot();
+       }
+
+       diag_printf("Flash formatted successfully\n");
+
+       reboot();
+}
+
+
+
+static int
+zylinjtag_Jim_Command_format_jffs2(Jim_Interp *interp,
+                                   int argc,
+               Jim_Obj * const *argv)
+{
+       if (argc != 1)
+       {
+               return JIM_ERR;
+       }
+
+       format();
+       for(;;);
+}
+
+
 static int
 zylinjtag_Jim_Command_rm(Jim_Interp *interp,
                                    int argc,
@@ -1308,6 +1382,7 @@ static void zylinjtag_startNetwork()
     Jim_CreateCommand(httpstate.jim_interp, "mac", zylinjtag_Jim_Command_mac, NULL, NULL);
     Jim_CreateCommand(httpstate.jim_interp, "ip", zylinjtag_Jim_Command_ip, NULL, NULL);
     Jim_CreateCommand(httpstate.jim_interp, "rm", zylinjtag_Jim_Command_rm, NULL, NULL);
+    Jim_CreateCommand(httpstate.jim_interp, "format_jffs2", zylinjtag_Jim_Command_format_jffs2, NULL, NULL);
 
        cyg_httpd_start();
 
@@ -1358,6 +1433,7 @@ print_exception_handler(cyg_addrword_t data, cyg_code_t exception, cyg_addrword_
        char *infoStr = "unknown";
        switch (exception)
        {
+#ifdef CYGNUM_HAL_VECTOR_UNDEF_INSTRUCTION
        case CYGNUM_HAL_VECTOR_UNDEF_INSTRUCTION:
                infoStr = "undefined instruction";
                break;
@@ -1370,6 +1446,7 @@ print_exception_handler(cyg_addrword_t data, cyg_code_t exception, cyg_addrword_
        case CYGNUM_HAL_VECTOR_ABORT_DATA:
                infoStr = "abort data";
                break;
+#endif
        default:
                break;
        }
@@ -1409,7 +1486,6 @@ static char uart_stack[4096];
 static char forwardBuffer[1024]; // NB! must be smaller than a TCP/IP packet!!!!!
 static char backwardBuffer[1024];
 
-static cyg_io_handle_t serial_handle;
 
 void setNoDelay(int session, int flag)
 {
@@ -1493,7 +1569,9 @@ zylinjtag_uart(cyg_addrword_t data)
                        continue;
                }
 
+#ifdef CYGPKG_PROFILE_GPROF
                start_profile();
+#endif
                int actual = 0;
                int actual2 = 0;
                int pos, pos2;
@@ -1680,6 +1758,16 @@ int handle_uart_command(struct command_context_s *cmd_ctx, char *cmd, char **arg
        //get existing serial configuration
        len = sizeof(cyg_serial_info_t);
        int err;
+       cyg_io_handle_t serial_handle;
+
+       err = cyg_io_lookup("/dev/ser0", &serial_handle);
+       if (err != ENOERR)
+       {
+               LOG_ERROR("/dev/ser0 not found\n");
+               return ERROR_FAIL;
+       }
+
+
        err = cyg_io_get_config(serial_handle, CYG_IO_GET_CONFIG_SERIAL_OUTPUT_DRAIN, &buf, &len);
        err = cyg_io_get_config(serial_handle, CYG_IO_GET_CONFIG_SERIAL_INFO, &buf, &len);
        if (err != ENOERR)
@@ -1742,17 +1830,15 @@ int main(int argc, char *argv[])
        ramblockdevice=(cyg_uint8 *)malloc(ramblockdevice_size);
        memset(ramblockdevice, 0xff, ramblockdevice_size);
 
+
+
+#ifdef CYGNUM_HAL_VECTOR_UNDEF_INSTRUCTION
        setHandler(CYGNUM_HAL_VECTOR_UNDEF_INSTRUCTION);
        setHandler(CYGNUM_HAL_VECTOR_ABORT_PREFETCH);
        setHandler(CYGNUM_HAL_VECTOR_ABORT_DATA);
+#endif
 
        int err;
-       err = cyg_io_lookup("/dev/ser0", &serial_handle);
-       if (err != ENOERR)
-       {
-               diag_printf("/dev/ser0 not found\n");
-               reboot();
-       }
 
        setPower(true); // on by default
 
@@ -1803,48 +1889,54 @@ int main(int argc, char *argv[])
        err = mount("/dev/flash1", "/config", "jffs2");
        if (err < 0)
        {
-               diag_printf("unable to mount jffs\n");
-               reboot();
-       }
-
-       /* are we using a ram disk instead of a flash disk? This is used
-        * for ZY1000 live demo...
-        *
-        * copy over flash disk to ram block device
-        */
-       if (boolParam("ramdisk"))
-       {
-               diag_printf("Unmounting /config from flash and using ram instead\n");
-               err=umount("/config");
-               if (err < 0)
+               diag_printf("unable to mount jffs2, falling back to ram disk..\n");
+               err = mount("", "/config", "ramfs");
+               if (err<0)
                {
-                       diag_printf("unable to unmount jffs\n");
+                       diag_printf("unable to mount /config as ramdisk.\n");
                        reboot();
                }
-
-               err = mount("/dev/flash1", "/config2", "jffs2");
-               if (err < 0)
+       } else
+       {
+               /* are we using a ram disk instead of a flash disk? This is used
+                * for ZY1000 live demo...
+                *
+                * copy over flash disk to ram block device
+                */
+               if (boolParam("ramdisk"))
                {
-                       diag_printf("unable to mount jffs\n");
-                       reboot();
-               }
+                       diag_printf("Unmounting /config from flash and using ram instead\n");
+                       err=umount("/config");
+                       if (err < 0)
+                       {
+                               diag_printf("unable to unmount jffs\n");
+                               reboot();
+                       }
 
-               err = mount("/dev/ram", "/config", "jffs2");
-               if (err < 0)
-               {
-                       diag_printf("unable to mount ram block device\n");
-                       reboot();
-               }
+                       err = mount("/dev/flash1", "/config2", "jffs2");
+                       if (err < 0)
+                       {
+                               diag_printf("unable to mount jffs\n");
+                               reboot();
+                       }
 
-//             copydir("/config2", "/config");
-               copyfile("/config2/ip", "/config/ip");
-               copydir("/config2/settings", "/config/settings");
+                       err = mount("", "/config", "ramfs");
+                       if (err < 0)
+                       {
+                               diag_printf("unable to mount ram block device\n");
+                               reboot();
+                       }
 
-               umount("/config2");
-       } else
-       {
-               /* we're not going to use a ram block disk */
-               free(ramblockdevice);
+       //              copydir("/config2", "/config");
+                       copyfile("/config2/ip", "/config/ip");
+                       copydir("/config2/settings", "/config/settings");
+
+                       umount("/config2");
+               } else
+               {
+                       /* we're not going to use a ram block disk */
+                       free(ramblockdevice);
+               }
        }
 
 
@@ -2464,122 +2556,3 @@ static int logfs_fo_close(struct CYG_FILE_TAG *fp)
        return ENOERR;
 }
 
-static bool
-ramiodev_init( struct cyg_devtab_entry *tab )
-{
-       return true;
-}
-
-static Cyg_ErrNo
-ramiodev_bread( cyg_io_handle_t handle, void *buf, cyg_uint32 *len,
-                  cyg_uint32 pos)
-{
-       if (*len+pos>ramblockdevice_size)
-       {
-               *len=ramblockdevice_size-pos;
-       }
-       memcpy(buf, ramblockdevice+pos, *len);
-       return ENOERR;
-}
-
-static Cyg_ErrNo
-ramiodev_bwrite( cyg_io_handle_t handle, const void *buf, cyg_uint32 *len,
-                   cyg_uint32 pos )
-{
-       if (((pos%4)!=0)||(((*len)%4)!=0))
-       {
-               diag_printf("Unaligned write %d %d!", pos, *len);
-       }
-
-       memcpy(ramblockdevice+pos, buf, *len);
-       return ENOERR;
-}
-
-static Cyg_ErrNo
-ramiodev_get_config( cyg_io_handle_t handle,
-                       cyg_uint32 key,
-                       void* buf,
-                       cyg_uint32* len)
-{
-    switch (key) {
-    case CYG_IO_GET_CONFIG_FLASH_ERASE:
-    {
-        if ( *len != sizeof( cyg_io_flash_getconfig_erase_t ) )
-             return -EINVAL;
-        {
-            cyg_io_flash_getconfig_erase_t *e = (cyg_io_flash_getconfig_erase_t *)buf;
-            char *startpos = ramblockdevice + e->offset;
-
-            if (((e->offset%(64*1024))!=0)||((e->len%(64*1024))!=0))
-            {
-               diag_printf("Erease is not aligned %d %d\n", e->offset, e->len);
-            }
-
-            memset(startpos, 0xff, e->len);
-
-            e->flasherr = 0;
-        }
-        return ENOERR;
-    }
-    case CYG_IO_GET_CONFIG_FLASH_DEVSIZE:
-    {
-        if ( *len != sizeof( cyg_io_flash_getconfig_devsize_t ) )
-             return -EINVAL;
-        {
-            cyg_io_flash_getconfig_devsize_t *d =
-                (cyg_io_flash_getconfig_devsize_t *)buf;
-
-                       d->dev_size = ramblockdevice_size;
-        }
-        return ENOERR;
-    }
-
-    case CYG_IO_GET_CONFIG_FLASH_BLOCKSIZE:
-    {
-        cyg_io_flash_getconfig_blocksize_t *b =
-            (cyg_io_flash_getconfig_blocksize_t *)buf;
-        if ( *len != sizeof( cyg_io_flash_getconfig_blocksize_t ) )
-             return -EINVAL;
-
-        // offset unused for now
-               b->block_size = 64*1024;
-        return ENOERR;
-    }
-
-    default:
-        return -EINVAL;
-    }
-}
-
-static Cyg_ErrNo
-ramiodev_set_config( cyg_io_handle_t handle,
-                       cyg_uint32 key,
-                       const void* buf,
-                       cyg_uint32* len)
-{
-
-    switch (key) {
-    default:
-        return -EINVAL;
-    }
-} // ramiodev_set_config()
-
-// get_config/set_config should be added later to provide the other flash
-// operations possible, like erase etc.
-
-BLOCK_DEVIO_TABLE( cyg_io_ramdev1_ops,
-                   &ramiodev_bwrite,
-                   &ramiodev_bread,
-                   0, // no select
-                   &ramiodev_get_config,
-                   &ramiodev_set_config
-    );
-
-
-BLOCK_DEVTAB_ENTRY( cyg_io_ramdev1,
-                    "/dev/ram",
-                    0,
-                    &cyg_io_ramdev1_ops,
-                    &ramiodev_init,
-                    0, // No lookup required
-                    NULL );