target/arm_dap: clean up dap_configure code 02/6702/2
authorTomas Vanek <vanekt@fbl.cz>
Mon, 15 Nov 2021 14:32:39 +0000 (15:32 +0100)
committerAntonio Borneo <borneo.antonio@gmail.com>
Sat, 20 Nov 2021 14:45:54 +0000 (14:45 +0000)
dap_configure() contained first time init related tasks, as the call to
dap_init_instance() and the check for configured tap.

Move all first time init related stuff to dap_create() to make dap_configure()
usable in eventual stand-alone 'dap configure' command.

Change-Id: Ia86eadb4e960ce54e8581630d01af75720d2318d
Signed-off-by: Tomas Vanek <vanekt@fbl.cz>
Reviewed-on: https://review.openocd.org/c/openocd/+/6702
Tested-by: jenkins
Reviewed-by: Antonio Borneo <borneo.antonio@gmail.com>
Reviewed-by: Matthias Welwarsky <matthias@welwarsky.de>
src/target/arm_dap.c

index 18e77b50fe1b851bb7ea814efcc9a26da3d1c923..0eb55a9cbec076d99625032d7d6791990e6af67b 100644 (file)
@@ -165,11 +165,10 @@ static const struct jim_nvp nvp_config_opts[] = {
 
 static int dap_configure(struct jim_getopt_info *goi, struct arm_dap_object *dap)
 {
-       struct jtag_tap *tap = NULL;
        struct jim_nvp *n;
        int e;
 
-       /* parse config or cget options ... */
+       /* parse config ... */
        while (goi->argc > 0) {
                Jim_SetEmptyResult(goi->interp);
 
@@ -184,11 +183,14 @@ static int dap_configure(struct jim_getopt_info *goi, struct arm_dap_object *dap
                        e = jim_getopt_obj(goi, &o_t);
                        if (e != JIM_OK)
                                return e;
+
+                       struct jtag_tap *tap;
                        tap = jtag_tap_by_jim_obj(goi->interp, o_t);
                        if (!tap) {
                                Jim_SetResultString(goi->interp, "-chain-position is invalid", -1);
                                return JIM_ERR;
                        }
+                       dap->dap.tap = tap;
                        /* loop for more */
                        break;
                }
@@ -200,14 +202,6 @@ static int dap_configure(struct jim_getopt_info *goi, struct arm_dap_object *dap
                }
        }
 
-       if (!tap) {
-               Jim_SetResultString(goi->interp, "-chain-position required when creating DAP", -1);
-               return JIM_ERR;
-       }
-
-       dap_instance_init(&dap->dap);
-       dap->dap.tap = tap;
-
        return JIM_OK;
 }
 
@@ -242,15 +236,21 @@ static int dap_create(struct jim_getopt_info *goi)
        if (!dap)
                return JIM_ERR;
 
-       e = dap_configure(goi, dap);
-       if (e != JIM_OK) {
-               free(dap);
-               return e;
-       }
+       dap_instance_init(&dap->dap);
 
        cp = Jim_GetString(new_cmd, NULL);
        dap->name = strdup(cp);
 
+       e = dap_configure(goi, dap);
+       if (e != JIM_OK)
+               goto err;
+
+       if (!dap->dap.tap) {
+               Jim_SetResultString(goi->interp, "-chain-position required when creating DAP", -1);
+               e = JIM_ERR;
+               goto err;
+       }
+
        struct command_registration dap_commands[] = {
                {
                        .name = cp,
@@ -268,14 +268,18 @@ static int dap_create(struct jim_getopt_info *goi)
 
        e = register_commands_with_data(cmd_ctx, NULL, dap_commands, dap);
        if (e != ERROR_OK) {
-               free(dap->name);
-               free(dap);
-               return JIM_ERR;
+               e = JIM_ERR;
+               goto err;
        }
 
        list_add_tail(&dap->lh, &all_dap);
 
        return JIM_OK;
+
+err:
+       free(dap->name);
+       free(dap);
+       return e;
 }
 
 static int jim_dap_create(Jim_Interp *interp, int argc, Jim_Obj *const *argv)

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)