David Brownell <david-b@pacbell.net>:
authorzwelch <zwelch@b42882b7-edfa-0310-969c-e2dbd0fdcd60>
Fri, 12 Jun 2009 21:43:53 +0000 (21:43 +0000)
committerzwelch <zwelch@b42882b7-edfa-0310-969c-e2dbd0fdcd60>
Fri, 12 Jun 2009 21:43:53 +0000 (21:43 +0000)
Partial fix to the "long IR length" problems.

 - Current code could handle up to 32 bit IR lengths with
   full functionality, if it didn't just reject may of them
   out of hand.  So only reject clear errors, where the IR
   mask (or capture instruction) needs more than IrLen bits.

 - Longer IR lengths can only be handled in BYPASS mode
   for now.  Example:  TI's DSPs use 38-bit IR lengths.
   So we can't issue their IDCODE instructions...

A more complete fix would be able to issue longer instructions;
or minimally, would fail cleanly for the non-BYPASS case.

Note that this *could* make some currently broken scripts fail,
since the previous code accepted garbage values so long as
they didn't use more than 16 bits.

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

src/jtag/core.c
src/jtag/tcl.c

index 4c91abeeed7c8c40d653a60c1e48863b45c72e46..7ed5976ccac8fc24711566ca66bcae64f3af6f04 100644 (file)
@@ -1073,6 +1073,7 @@ void jtag_tap_init(jtag_tap_t *tap)
        tap->expected_mask = malloc(tap->ir_length);
        tap->cur_instr = malloc(tap->ir_length);
 
+       /// @todo cope sanely with ir_length bigger than 32 bits
        buf_set_u32(tap->expected, 0, tap->ir_length, tap->ir_capture_value);
        buf_set_u32(tap->expected_mask, 0, tap->ir_length, tap->ir_capture_mask);
        buf_set_ones(tap->cur_instr, tap->ir_length);
index 152dd762f5a628a719189ed8a50f50a46c644e08..abc100622586b3fa3cfba425ace8396947ef9bdf 100644 (file)
@@ -296,6 +296,15 @@ static int jtag_tap_configure_cmd( Jim_GetOptInfo *goi, jtag_tap_t * tap)
        return JIM_OK;
 }
 
+static int is_bad_irval(int ir_length, jim_wide w)
+{
+       jim_wide v = 1;
+
+       v <<= ir_length;
+       v -= 1;
+       v = ~v;
+       return (w & v) != 0;
+}
 
 extern void jtag_tap_init(jtag_tap_t *tap);
 extern void jtag_tap_free(jtag_tap_t *tap);
@@ -411,22 +420,28 @@ static int jim_newtap_cmd( Jim_GetOptInfo *goi )
                                Jim_SetResult_sprintf( goi->interp, "option: %s bad parameter", n->name );
                                return e;
                        }
-                       if( (w < 0) || (w > 0xffff) ){
-                               /* wacky value */
-                               Jim_SetResult_sprintf( goi->interp, "option: %s - wacky value: %d (0x%x)",
-                                                                          n->name, (int)(w), (int)(w));
-                               return JIM_ERR;
-                       }
                        switch(n->value){
                        case NTAP_OPT_IRLEN:
+                               if (w < (jim_wide) sizeof(pTap->ir_capture_value))
+                                       LOG_WARNING("huge IR length %d", (int) w);
                                pTap->ir_length = w;
                                reqbits &= (~(NTREQ_IRLEN));
                                break;
                        case NTAP_OPT_IRMASK:
+                               if (is_bad_irval(pTap->ir_length, w)) {
+                                       LOG_ERROR("IR mask %x too big",
+                                                       (int) w);
+                                       return ERROR_FAIL;
+                               }
                                pTap->ir_capture_mask = w;
                                reqbits &= (~(NTREQ_IRMASK));
                                break;
                        case NTAP_OPT_IRCAPTURE:
+                               if (is_bad_irval(pTap->ir_length, w)) {
+                                       LOG_ERROR("IR capture %x too big",
+                                                       (int) w);
+                                       return ERROR_FAIL;
+                               }
                                pTap->ir_capture_value = w;
                                reqbits &= (~(NTREQ_IRCAPTURE));
                                break;

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)