Extend configure script to check for environ declaration in stdlib.h.
[openocd.git] / src / helper / tclapi.c
index 2857cb4991399fe5572126e0a4cdf843be46fe7f..d8723a0518749881c133b82c90b540642bb2918b 100644 (file)
 #include "config.h"
 #endif
 
-#include "replacements.h"
-#include "target.h"
-#include "target_request.h"
-
-#include "log.h"
-#include "configuration.h"
-#include "binarybuffer.h"
-#include "jtag.h"
-#include "flash.h"
+#include "tclapi.h"
+#include "../target/target.h"
+#include "../jtag/jtag.h"
+#include "../flash/flash.h"
 
 #include <string.h>
-#include <stdlib.h>
-#include <inttypes.h>
-
-#include <sys/types.h>
-#include <sys/stat.h>
-#include <unistd.h>
-#include <errno.h>
-
-#include <sys/time.h>
-#include <time.h>
 
-#include <time_support.h>
-
-#include <fileio.h>
-#include <image.h>
 
 static int new_int_array_element(Jim_Interp * interp, const char *varname, int idx, u32 val)
 {
@@ -82,13 +63,14 @@ static int jim_mem2array(Jim_Interp *interp, int argc, Jim_Obj *const *argv)
        command_context_t *context;
        long l;
        u32 width;
-       u32 len;
+       int len;
        u32 addr;
-       u32 count;
+       unsigned count;
        u32 v;
        const char *varname;
        u8 buffer[4096];
-       int  i, n, e, retval;
+       unsigned i, n;
+       int e, retval;
 
        /* argv[1] = name of array to receive the data
         * argv[2] = desired width
@@ -259,13 +241,13 @@ static int jim_array2mem(Jim_Interp *interp, int argc, Jim_Obj *const *argv)
        command_context_t *context;
        long l;
        u32 width;
-       u32 len;
+       int len;
        u32 addr;
        u32 count;
        u32 v;
        const char *varname;
        u8 buffer[4096];
-       int  i, n, e, retval;
+       int  n, e, retval;
 
        /* argv[1] = name of array to get the data
         * argv[2] = desired width
@@ -367,7 +349,7 @@ static int jim_array2mem(Jim_Interp *interp, int argc, Jim_Obj *const *argv)
                }
 
                v = 0; /* shut up gcc */
-               for (i = 0 ;i < count ;i++, n++) {
+               for (unsigned i = 0 ;i < count ;i++, n++) {
                        get_int_array_element(interp, varname, n, &v);
                        switch (width) {
                        case 4:
@@ -443,19 +425,13 @@ int Jim_Command_drscan(Jim_Interp *interp, int argc, Jim_Obj *const *args)
                Jim_GetLong(interp, args[i], &bits);
                str = Jim_GetString(args[i+1], &len);
 
-               fields[field_count].device = device;
                fields[field_count].num_bits = bits;
                fields[field_count].out_value = malloc(CEIL(bits, 8));
                str_to_buf(str, len, fields[field_count].out_value, bits, 0);
-               fields[field_count].out_mask = NULL;
                fields[field_count].in_value = fields[field_count].out_value;
-               fields[field_count].in_check_mask = NULL;
-               fields[field_count].in_check_value = NULL;
-               fields[field_count].in_handler = NULL;
-               fields[field_count++].in_handler_priv = NULL;
        }
 
-       jtag_add_dr_scan(num_fields, fields, -1);
+       jtag_add_dr_scan(num_fields, fields, TAP_INVALID);
        retval = jtag_execute_queue();
        if (retval != ERROR_OK)
        {
@@ -489,21 +465,22 @@ int Jim_Command_drscan(Jim_Interp *interp, int argc, Jim_Obj *const *args)
 
 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;
        }
 
+       unsigned flash_banks = flash_get_bank_count();
        if (!flash_banks)
        {
                return JIM_ERR;
        }
 
        Jim_Obj *list=Jim_NewListObj(interp, NULL, 0);
-       for (p = flash_banks; p; p = p->next)
+       for (unsigned i = 0; i < flash_banks; i++)
        {
+               flash_bank_t *p = get_flash_bank_by_num(i);
                Jim_Obj *elem=Jim_NewListObj(interp, NULL, 0);
 
                Jim_ListAppendElement(interp, elem, Jim_NewStringObj(interp, "name", -1));
@@ -525,11 +502,15 @@ static int jim_flash_banks(Jim_Interp *interp, int argc, Jim_Obj *const *argv)
        return JIM_OK;
 }
 
-int tclapi_register_commands()
+int tclapi_register_commands(struct command_context_s *cmd_ctx)
 {
-       register_jim("ocd_mem2array", jim_mem2array, "read memory and return as a TCL array for script processing");
-       register_jim("ocd_array2mem", jim_array2mem, "convert a TCL array to memory locations and write the values");
-       register_jim("drscan", Jim_Command_drscan, "execute DR scan <device> <num_bits> <value> <num_bits1> <value2> ...");
-       register_jim("ocd_flash_banks", jim_flash_banks, "return information about the flash banks");
-
+       register_jim(cmd_ctx, "ocd_mem2array", &jim_mem2array,
+               "read memory and return as a TCL array for script processing");
+       register_jim(cmd_ctx, "ocd_array2mem", &jim_array2mem,
+               "convert a TCL array to memory locations and write the values");
+       register_jim(cmd_ctx, "drscan", &Jim_Command_drscan,
+               "execute DR scan <device> <num_bits> <value> <num_bits1> <value2> ...");
+       register_jim(cmd_ctx, "ocd_flash_banks", &jim_flash_banks,
+               "return information about the flash banks");
+       return ERROR_OK;
 }

Linking to existing account procedure

If you already have an account and want to add another login method you MUST first sign in with your existing account and then change URL to read https://review.openocd.org/login/?link to get to this page again but this time it'll work for linking. Thank you.

SSH host keys fingerprints

1024 SHA256:YKx8b7u5ZWdcbp7/4AeXNaqElP49m6QrwfXaqQGJAOk gerrit-code-review@openocd.zylin.com (DSA)
384 SHA256:jHIbSQa4REvwCFG4cq5LBlBLxmxSqelQPem/EXIrxjk gerrit-code-review@openocd.org (ECDSA)
521 SHA256:UAOPYkU9Fjtcao0Ul/Rrlnj/OsQvt+pgdYSZ4jOYdgs gerrit-code-review@openocd.org (ECDSA)
256 SHA256:A13M5QlnozFOvTllybRZH6vm7iSt0XLxbA48yfc2yfY gerrit-code-review@openocd.org (ECDSA)
256 SHA256:spYMBqEYoAOtK7yZBrcwE8ZpYt6b68Cfh9yEVetvbXg gerrit-code-review@openocd.org (ED25519)
+--[ED25519 256]--+
|=..              |
|+o..   .         |
|*.o   . .        |
|+B . . .         |
|Bo. = o S        |
|Oo.+ + =         |
|oB=.* = . o      |
| =+=.+   + E     |
|. .=o   . o      |
+----[SHA256]-----+
2048 SHA256:0Onrb7/PHjpo6iVZ7xQX2riKN83FJ3KGU0TvI0TaFG4 gerrit-code-review@openocd.zylin.com (RSA)