JTAG: jtag_tap_init() bugfixes
[openocd.git] / src / jtag / core.c
index 7c85839b0ae4fe4576145c3ebdfd8a2ff700e2b3..08cfe436b236a41b94a009ef2a72b3abc6bfc404 100644 (file)
@@ -1204,20 +1204,29 @@ done:
 
 void jtag_tap_init(jtag_tap_t *tap)
 {
+       unsigned ir_len_bits;
+       unsigned ir_len_bytes;
+
        assert(0 != tap->ir_length);
 
-       /// @todo fix, this allocates one byte per bit for all three fields!
-       tap->expected = malloc(tap->ir_length);
-       tap->expected_mask = malloc(tap->ir_length);
-       tap->cur_instr = malloc(tap->ir_length);
+       ir_len_bits = tap->ir_length;
+       ir_len_bytes = CEIL(ir_len_bits, 8);
 
-       /// @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);
+       tap->expected = calloc(1, ir_len_bytes);
+       tap->expected_mask = calloc(1, ir_len_bytes);
+       tap->cur_instr = malloc(ir_len_bytes);
+
+       /// @todo cope better with ir_length bigger than 32 bits
+       if (ir_len_bits > 32)
+               ir_len_bits = 32;
 
-       // place TAP in bypass mode
+       buf_set_u32(tap->expected, 0, ir_len_bits, tap->ir_capture_value);
+       buf_set_u32(tap->expected_mask, 0, ir_len_bits, tap->ir_capture_mask);
+
+       // TAP will be in bypass mode after jtag_validate_ircapture()
        tap->bypass = 1;
+       buf_set_ones(tap->cur_instr, tap->ir_length);
+
        // register the reset callback for the TAP
        jtag_register_event_callback(&jtag_reset_callback, tap);
 

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)