Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

No support for arcv2 for Zephyr thread aware debugging #10

Open
jshoen opened this issue Jul 16, 2019 · 14 comments
Open

No support for arcv2 for Zephyr thread aware debugging #10

jshoen opened this issue Jul 16, 2019 · 14 comments

Comments

@jshoen
Copy link

jshoen commented Jul 16, 2019

I am trying to used gdb and openOCD for thread aware debugging of an ARC EMSK board configured with an EM4 CPU. I am using branch: https://github.com/zephyrproject-rtos/openocd/tree/zephyr-20190226. I built openOCD and copied to to the correct locations in the zephyr-sdk tree. I then edited the snps_em_sk_fpga.cfg file to add the '-rtos auto' option to the 'target create' line.

With these changes the openOCD tries to detect the RTOS, but errors out with a message that it cannot detect the arcv2 target:
Info : Zephyr: does it have symbol 0 (mandatory)?
Info : Zephyr: does it have symbol 1 (mandatory)?
Info : Zephyr: does it have symbol 2 (mandatory)?
Info : Zephyr: does it have symbol 3 (optional)?
Info : Zephyr: all mandatory symbols found
Info : Auto-detected RTOS: Zephyr
Info : Zephyr: looking for target: arcv2
Error: Could not find target in Zephyr compatibility list

After that attempting to list threads shows only a single thread (the idle thread) even though multiple threads are running.

When examining the Zephyr_params_list in Zephyr.c it appears that the "cortex_m" is the only supported target.

To reproduce, add the following configuration settings to one of the sample targets such as blinky.
CONFIG_DEBUG=y
CONFIG_INIT_STACKS=y
CONFIG_STACK_SENTINEL=y
CONFIG_ARC_EXCEPTION_DEBUG=y
CONFIG_LOG=y
CONFIG_OPENOCD_SUPPORT=y
Then build and attach gdb with 'make debug'.

@EvgeniiDidin
Copy link
Collaborator

Hi @jshoen,
I am sorry for late response.
I prepared a patch, which introduces support of arcv2 for Zephyr in openOCD:
foss-for-synopsys-dwc-arc-processors/openocd@dbe0952
Now the openocd log is:

Info : 1689 3902 Zephyr.c:673 Zephyr_detect_rtos(): Zephyr: does it have symbol 0 (mandatory)?
Info : 1690 3902 Zephyr.c:673 Zephyr_detect_rtos(): Zephyr: does it have symbol 1 (mandatory)?
Info : 1691 3902 Zephyr.c:673 Zephyr_detect_rtos(): Zephyr: does it have symbol 2 (mandatory)?
Info : 1692 3902 Zephyr.c:673 Zephyr_detect_rtos(): Zephyr: does it have symbol 3 (optional)?
Info : 1693 3902 Zephyr.c:681 Zephyr_detect_rtos(): Zephyr: all mandatory symbols found
Info : 1694 3902 rtos.c:275 rtos_qsymbol(): Auto-detected RTOS: Zephyr
Info : 1695 3902 Zephyr.c:700 Zephyr_create(): Zephyr: looking for target: arcv2
Info : 1696 3902 Zephyr.c:707 Zephyr_create(): Zephyr: target known, params at 0x8de2f8

Currently I am working on correctly reading Thread information: (gdb): info threads

Also I have a question. When you tried to run your binary have you seen such messages in serial port:

***** Exception vector: 0x6, cause code: 0x10, parameter 0x0
Address 0x40
EV_ProtV: Normal vector table in secure memory
Current thread ID = 0x80000320
Faulting instruction address = 0x40
Fatal fault in essential thread! Spinning...

or

**FATAL: ***** Exception vector: 0x6, cause code: 0x10, parameter 0x0
FATAL: Address 0x40
FATAL: Faulting instruction address = 0x40
FATAL: >>> ZEPHYR FATAL ERROR 0: CPU exception
FATAL: Current thread: 0x80000058 (unknown)
FATAL: Halting system

?
And was the result of running (gdb): info threads like:

  Id   Target Id         Frame 
* 1    Remote target     k_cpu_idle () at  /zephyr/arch/arc/core/cpu_idle.S:47

?

@jshoen
Copy link
Author

jshoen commented Aug 7, 2019 via email

@abrodkin
Copy link
Collaborator

There's an expectation to see threads-related functionality similar to Linux, in particular:

  1. Ability to display information about currently available threads.
    That's already done (WIP - https://github.com/foss-for-synopsys-dwc-arc-processors/openocd/tree/topic_zephyr_threads):

     (gdb) info threads
      Id   Target Id                                              Frame
      1    Thread 2147483648 (Name: thread_a, prio:7,useropts:0)  0x80001e20 in threadA_sem ()
      2    Thread 2147484364 (Name: sysworkq, prio:-1,useropts:0) 0x00000031 in _VectorTable ()
    * 3    Thread 2147484028 (Name: idle, prio:15,useropts:1)     k_cpu_idle ()
        at .../git/zephyrproject/zephyr/arch/arc/core/cpu_idle.S:47
      4    Thread 2147483780 (Name: thread_b, prio:7,useropts:0)  0x80001e30 in threadB_sem ()
    
  2. Ability to switch to a random thread and see its context including core registers, use stack unwinding.
    That's not yet done:

     (gdb) thread 2
    Thread ID 2 has terminated.
     (gdb) info threads
      Id   Target Id                                              Frame
      1    Thread 2147483648 (Name: thread_a, prio:7,useropts:0)  0x80001e20 in threadA_sem ()
      2    Thread 2147484364 (Name: sysworkq, prio:-1,useropts:0) 0x00000031 in _VectorTable ()
    * 3    Thread 2147484028 (Name: idle, prio:15,useropts:1)     k_cpu_idle ()
        at /SCRATCH/abrodkin/Projects/sources/git/zephyrproject/zephyr/arch/arc/core/cpu_idle.S:47
      4    Thread 2147483780 (Name: thread_b, prio:7,useropts:0)  0x80001e30 in threadB_sem ()
    

@EvgeniiDidin
Copy link
Collaborator

Hi @jshoen,

Recently I pushed a commit in my development branch:
https://github.com/foss-for-synopsys-dwc-arc-processors/openocd/tree/topic_zephyr_threads
Now it is possible to switch between threads and get registers with "info registers" command.
Note that only callee(r13-r25,gp,fp,r30), blink and status32 registers are saved in stack for each thread.
To demonstrate actual context switch I placed some constants in r13-r25 registers different for each thread(for thread A: 0xabcd2**, for thread B: 0xabcd1**). The GDB output is like:

(gdb) info threads
  Id   Target Id                                             Frame 
  1    Thread 2147483780 (Name: thread_b, prio:7,useropts:0) 0x00000000 in _VectorTable ()
  2    Thread 2147483648 (Name: thread_a, prio:7,useropts:0) 0x00000000 in _VectorTable ()
  3    Thread 2147483912 (Name: logging, prio:14,useropts:0) 0x00000000 in _VectorTable ()
* 4    Thread 2147484200 (Name: idle, prio:15,useropts:1)    k_cpu_idle ()
    at /home/didin/work/OpenOCD/zephyr_openocd_threads/zephyr/zephyr/arch/arc/core/cpu_idle.S:47
(gdb) thread 1
[Switching to thread 1 (Thread 2147483780)]
#0  0x00000000 in _VectorTable ()
(gdb) info registers
r0             0x0                 0
r1             0x0                 0
r2             0x0                 0
r3             0x0                 0
r4             0x0                 0
r5             0x0                 0
r6             0x0                 0
r7             0x0                 0
r8             0x0                 0
r9             0x0                 0
r10            0x0                 0
r11            0x0                 0
r12            0x0                 0
r13            0x80000338          2147484472
r14            0x80000084          2147483780
r15            0x33                51
r16            0xabcd110           180146448
r17            0xabcd111           180146449
r18            0xabcd112           180146450
r19            0xabcd113           180146451
r20            0xabcd114           180146452
r21            0xabcd115           180146453
r22            0xabcd116           180146454
r23            0xabcd117           180146455
r24            0xabcd118           180146456
r25            0xabcd119           180146457
gp             0xaaaaaaaa          0xaaaaaaaa
fp             0xaaaaaaaa          0xaaaaaaaa
sp             0x0                 0x0 <_VectorTable>
ilink          0x0                 0x0 <_VectorTable>
r30            0xabcd11a           180146458
blink          0x5778              0x5778 <z_pend_curr+64>
lp_count       0x0                 0
pcl            0x200806            0x200806
pc             0x0                 0x0 <_VectorTable>
status32       0x200806            [ E0 E1 Z ]
lp_start       0x0                 0x0 <_VectorTable>
lp_end         0x0                 0x0 <_VectorTable>
....
(gdb) thread 2
[Switching to thread 2 (Thread 2147483648)]
#0  0x00000000 in _VectorTable ()
(gdb) info registers
r0             0x0                 0
r1             0x0                 0
r2             0x0                 0
r3             0x0                 0
r4             0x0                 0
r5             0x0                 0
r6             0x0                 0
r7             0x0                 0
r8             0x0                 0
r9             0x0                 0
r10            0x0                 0
r11            0x0                 0
r12            0x0                 0
r13            0x80000000          2147483648
r14            0x62a0              25248
r15            0x80000338          2147484472
r16            0x33                51
r17            0xabcd211           180146705
r18            0xabcd212           180146706
r19            0xabcd213           180146707
r20            0xabcd214           180146708
r21            0xabcd215           180146709
r22            0xabcd216           180146710
r23            0xabcd217           180146711
r24            0xabcd218           180146712
r25            0xabcd219           180146713
gp             0xaaaaaaaa          0xaaaaaaaa
fp             0xaaaaaaaa          0xaaaaaaaa
sp             0x0                 0x0 <_VectorTable>
ilink          0x0                 0x0 <_VectorTable>
r30            0xabcd21a           180146714
blink          0x596c              0x596c <z_tick_sleep+104>
lp_count       0x0                 0
pcl            0x200806            0x200806
pc             0x0                 0x0 <_VectorTable>
status32       0x200806            [ E0 E1 Z ]
lp_start       0x0                 0x0 <_VectorTable>
lp_end         0x0                 0x0 <_VectorTable>
...

One important thing is that I used EMSK_EM7D board which by default has ARC_HAS_SECURE option enabled, which affects stack frame. Currently openocd reads stack considering enabled Security, but I am going to add some checks for correct handling ARC_HAS_SECURE option ASAP. Could you please tell me, does you board has ARC_HAS_SECURE option enabled?

Could you please try this revision of openocd:
foss-for-synopsys-dwc-arc-processors/openocd@6760b2a ?

@jshoen
Copy link
Author

jshoen commented Aug 28, 2019 via email

@EvgeniiDidin
Copy link
Collaborator

Hi @jshoen,

To prevent you waiting my patch I think you should try my branch with such little changes:

git diff src/rtos/Zephyr.c
diff --git a/src/rtos/Zephyr.c b/src/rtos/Zephyr.c
index 9568ccc97..bdbdb7da0 100644
--- a/src/rtos/Zephyr.c
+++ b/src/rtos/Zephyr.c
@@ -203,11 +203,11 @@ static const struct stack_register_offset arc_cpu_saved[] = {
         { 30,   -1,  32 }, //r30
         { 31,   0,  32 }, //BLINK
         { 64,   -1,  32 }, // pc
-        { 67,   8,  32 } // status32  NOTE: change "8" to "4" if ARC_HAS_SECURE is disabled
+        { 67,   4,  32 } // status32  NOTE: change "8" to "4" if ARC_HAS_SECURE is disabled
 };
 
 static const struct rtos_register_stacking arc_cpu_saved_stacking = {
-       .stack_registers_size = 12,   //NOTE: change to 8 if ARC_HAS_SECURE is disabled
+       .stack_registers_size = 8,   //NOTE: change to 8 if ARC_HAS_SECURE is disabled
        .stack_growth_direction = -1,
        .num_output_registers = ARRAY_SIZE(arc_cpu_saved),
        .register_offsets = arc_cpu_saved,

I tested this on em9d(no ARC_HAS_SECURE) and it worked fine.

@EvgeniiDidin
Copy link
Collaborator

Hi @jshoen,

I fixed an error and added changes from previous message in the latest patch.
Could you please try the latest revision:
foss-for-synopsys-dwc-arc-processors/openocd@9dbc8a1

@jshoen
Copy link
Author

jshoen commented Aug 30, 2019 via email

@EvgeniiDidin
Copy link
Collaborator

Hi @jshoen,

Could you please revert your changes and try to configure openocd with "--disable-werror" option. After that "make" should finish without errors.

@jshoen
Copy link
Author

jshoen commented Aug 30, 2019 via email

@EvgeniiDidin
Copy link
Collaborator

Hi Jay,

The series of patches, which introduces Zephyr thread aware debugging for arcv2 is already in zephyr-20191003 branch:
#15
#17

Also I created a patch for GDB, which is necessary for OpenOCD<->Zephyr thread aware debugging on ARC:
http://patchwork.sourceware.org/patch/35764/
zephyrproject-rtos/sdk-ng#146

I guess the issue is resolved, Zephyr thread aware debugging for arcv2 now is supported.

@EvgeniiDidin
Copy link
Collaborator

Hi Jay,
I'm wondering if you still have any issues with YYY then I'd like to get more details about that.
Also please note that the next Zephyr release v2.1 is going to be published soon (see https://lists.zephyrproject.org/g/announce/message/76) and would be really good to have that issue closed by the time of release so we may claim Zephyr thread-aware debugging support for ARC is now in place and known to work.

@jshoen
Copy link
Author

jshoen commented Nov 12, 2019 via email

@jshoen
Copy link
Author

jshoen commented Nov 14, 2019 via email

abrodkin added a commit to abrodkin/openocd that referenced this issue Nov 10, 2021
In zephyrproject-rtos/zephyr#35284 it was
found that use of "verify_image" command for ARC boards lead to
OpenOCD segfault:
--------------------------->8--------------------------
 Program received signal SIGSEGV, Segmentation fault.
 0x0000000000000000 in ?? ()
 (gdb) bt
 #0  0x0000000000000000 in ?? ()
 zephyrproject-rtos#1  0x0000000000455e27 in target_checksum_memory (target=target@entry=0xa52450, address=2415919104, size=19952, crc=crc@entry=0x7fffffffcf64) at src/target/target.c:2522
 zephyrproject-rtos#2  0x0000000000456066 in handle_verify_image_command_internal (cmd=0x7fffffffd040, verify=IMAGE_VERIFY) at src/target/target.c:3846
 zephyrproject-rtos#3  0x000000000047e4ca in run_command (num_words=2, words=0xa80800, c=0x9f3ea0, context=0x9a7010) at src/helper/command.c:582
 zephyrproject-rtos#4  exec_command (argv=0x7fffffffd140, argc=<optimized out>, c=0x9f3ea0, cmd_ctx=0x9a7010, interp=0x9a7070) at src/helper/command.c:950
 zephyrproject-rtos#5  jim_command_dispatch (interp=0x9a7070, argc=<optimized out>, argv=0x7fffffffd140) at src/helper/command.c:1001
 zephyrproject-rtos#6  0x00000000005b839a in JimInvokeCommand (interp=interp@entry=0x9a7070, objc=objc@entry=2, objv=objv@entry=0x7fffffffd140) at jim.c:10514
 zephyrproject-rtos#7  0x00000000005b8fbc in Jim_EvalObj (interp=interp@entry=0x9a7070, scriptObjPtr=scriptObjPtr@entry=0x9e96d0) at jim.c:11006
 zephyrproject-rtos#8  0x00000000005bb12b in Jim_EvalSource (interp=interp@entry=0x9a7070, filename=filename@entry=0x0, lineno=lineno@entry=0,
     script=script@entry=0x9e0db0 "verify_image build/zephyr/zephyr.elf") at jim.c:11298
 zephyrproject-rtos#9  0x000000000047df5f in command_run_line (context=context@entry=0x9a7010, line=0x9e0db0 "verify_image build/zephyr/zephyr.elf") at src/helper/command.c:626
 zephyrproject-rtos#10 0x000000000047f6b8 in parse_config_file (cmd_ctx=cmd_ctx@entry=0x9a7010) at src/helper/configuration.c:136
 zephyrproject-rtos#11 0x00000000004053ae in openocd_thread (cmd_ctx=0x9a7010, argv=0x7fffffffd378, argc=18) at src/openocd.c:296
 zephyrproject-rtos#12 openocd_main (argc=18, argv=0x7fffffffd378) at src/openocd.c:356
 zephyrproject-rtos#13 0x00007ffff710d505 in __libc_start_main () from /lib64/libc.so.6
 zephyrproject-rtos#14 0x0000000000404e9e in _start ()
--------------------------->8--------------------------

That happens because we used to have ".checksum_memory" undefined
for ARC. And it was undefined on purpose as we never got to implement
a target-executed applet for CRC calculation.

But there seems to be a work-around of using real memory read back
via JTAG. And for that we just need to return anything != ERROR_OK
from ".checksum_memory()" callback. Which we do here.

Now image verification works for ARC as well!

Signed-off-by: Alexey Brodkin <[email protected]>
galak pushed a commit that referenced this issue Nov 10, 2021
In zephyrproject-rtos/zephyr#35284 it was
found that use of "verify_image" command for ARC boards lead to
OpenOCD segfault:
--------------------------->8--------------------------
 Program received signal SIGSEGV, Segmentation fault.
 0x0000000000000000 in ?? ()
 (gdb) bt
 #0  0x0000000000000000 in ?? ()
 #1  0x0000000000455e27 in target_checksum_memory (target=target@entry=0xa52450, address=2415919104, size=19952, crc=crc@entry=0x7fffffffcf64) at src/target/target.c:2522
 #2  0x0000000000456066 in handle_verify_image_command_internal (cmd=0x7fffffffd040, verify=IMAGE_VERIFY) at src/target/target.c:3846
 #3  0x000000000047e4ca in run_command (num_words=2, words=0xa80800, c=0x9f3ea0, context=0x9a7010) at src/helper/command.c:582
 #4  exec_command (argv=0x7fffffffd140, argc=<optimized out>, c=0x9f3ea0, cmd_ctx=0x9a7010, interp=0x9a7070) at src/helper/command.c:950
 #5  jim_command_dispatch (interp=0x9a7070, argc=<optimized out>, argv=0x7fffffffd140) at src/helper/command.c:1001
 #6  0x00000000005b839a in JimInvokeCommand (interp=interp@entry=0x9a7070, objc=objc@entry=2, objv=objv@entry=0x7fffffffd140) at jim.c:10514
 #7  0x00000000005b8fbc in Jim_EvalObj (interp=interp@entry=0x9a7070, scriptObjPtr=scriptObjPtr@entry=0x9e96d0) at jim.c:11006
 #8  0x00000000005bb12b in Jim_EvalSource (interp=interp@entry=0x9a7070, filename=filename@entry=0x0, lineno=lineno@entry=0,
     script=script@entry=0x9e0db0 "verify_image build/zephyr/zephyr.elf") at jim.c:11298
 #9  0x000000000047df5f in command_run_line (context=context@entry=0x9a7010, line=0x9e0db0 "verify_image build/zephyr/zephyr.elf") at src/helper/command.c:626
 #10 0x000000000047f6b8 in parse_config_file (cmd_ctx=cmd_ctx@entry=0x9a7010) at src/helper/configuration.c:136
 #11 0x00000000004053ae in openocd_thread (cmd_ctx=0x9a7010, argv=0x7fffffffd378, argc=18) at src/openocd.c:296
 #12 openocd_main (argc=18, argv=0x7fffffffd378) at src/openocd.c:356
 #13 0x00007ffff710d505 in __libc_start_main () from /lib64/libc.so.6
 #14 0x0000000000404e9e in _start ()
--------------------------->8--------------------------

That happens because we used to have ".checksum_memory" undefined
for ARC. And it was undefined on purpose as we never got to implement
a target-executed applet for CRC calculation.

But there seems to be a work-around of using real memory read back
via JTAG. And for that we just need to return anything != ERROR_OK
from ".checksum_memory()" callback. Which we do here.

Now image verification works for ARC as well!

Signed-off-by: Alexey Brodkin <[email protected]>
aaillet pushed a commit to iotbzh/openocd that referenced this issue May 9, 2022
In zephyrproject-rtos/zephyr#35284 it was
found that use of "verify_image" command for ARC boards lead to
OpenOCD segfault:
--------------------------->8--------------------------
 Program received signal SIGSEGV, Segmentation fault.
 0x0000000000000000 in ?? ()
 (gdb) bt
 #0  0x0000000000000000 in ?? ()
 zephyrproject-rtos#1  0x0000000000455e27 in target_checksum_memory (target=target@entry=0xa52450, address=2415919104, size=19952, crc=crc@entry=0x7fffffffcf64) at src/target/target.c:2522
 zephyrproject-rtos#2  0x0000000000456066 in handle_verify_image_command_internal (cmd=0x7fffffffd040, verify=IMAGE_VERIFY) at src/target/target.c:3846
 zephyrproject-rtos#3  0x000000000047e4ca in run_command (num_words=2, words=0xa80800, c=0x9f3ea0, context=0x9a7010) at src/helper/command.c:582
 zephyrproject-rtos#4  exec_command (argv=0x7fffffffd140, argc=<optimized out>, c=0x9f3ea0, cmd_ctx=0x9a7010, interp=0x9a7070) at src/helper/command.c:950
 zephyrproject-rtos#5  jim_command_dispatch (interp=0x9a7070, argc=<optimized out>, argv=0x7fffffffd140) at src/helper/command.c:1001
 zephyrproject-rtos#6  0x00000000005b839a in JimInvokeCommand (interp=interp@entry=0x9a7070, objc=objc@entry=2, objv=objv@entry=0x7fffffffd140) at jim.c:10514
 zephyrproject-rtos#7  0x00000000005b8fbc in Jim_EvalObj (interp=interp@entry=0x9a7070, scriptObjPtr=scriptObjPtr@entry=0x9e96d0) at jim.c:11006
 zephyrproject-rtos#8  0x00000000005bb12b in Jim_EvalSource (interp=interp@entry=0x9a7070, filename=filename@entry=0x0, lineno=lineno@entry=0,
     script=script@entry=0x9e0db0 "verify_image build/zephyr/zephyr.elf") at jim.c:11298
 zephyrproject-rtos#9  0x000000000047df5f in command_run_line (context=context@entry=0x9a7010, line=0x9e0db0 "verify_image build/zephyr/zephyr.elf") at src/helper/command.c:626
 zephyrproject-rtos#10 0x000000000047f6b8 in parse_config_file (cmd_ctx=cmd_ctx@entry=0x9a7010) at src/helper/configuration.c:136
 zephyrproject-rtos#11 0x00000000004053ae in openocd_thread (cmd_ctx=0x9a7010, argv=0x7fffffffd378, argc=18) at src/openocd.c:296
 zephyrproject-rtos#12 openocd_main (argc=18, argv=0x7fffffffd378) at src/openocd.c:356
 zephyrproject-rtos#13 0x00007ffff710d505 in __libc_start_main () from /lib64/libc.so.6
 zephyrproject-rtos#14 0x0000000000404e9e in _start ()
--------------------------->8--------------------------

That happens because we used to have ".checksum_memory" undefined
for ARC. And it was undefined on purpose as we never got to implement
a target-executed applet for CRC calculation.

But there seems to be a work-around of using real memory read back
via JTAG. And for that we just need to return anything != ERROR_OK
from ".checksum_memory()" callback. Which we do here.

Now image verification works for ARC as well!

Signed-off-by: Alexey Brodkin <[email protected]>
stephanosio pushed a commit that referenced this issue Jun 14, 2022
In zephyrproject-rtos/zephyr#35284 it was
found that use of "verify_image" command for ARC boards lead to
OpenOCD segfault:
--------------------------->8--------------------------
 Program received signal SIGSEGV, Segmentation fault.
 0x0000000000000000 in ?? ()
 (gdb) bt
 #0  0x0000000000000000 in ?? ()
 #1  0x0000000000455e27 in target_checksum_memory (target=target@entry=0xa52450, address=2415919104, size=19952, crc=crc@entry=0x7fffffffcf64) at src/target/target.c:2522
 #2  0x0000000000456066 in handle_verify_image_command_internal (cmd=0x7fffffffd040, verify=IMAGE_VERIFY) at src/target/target.c:3846
 #3  0x000000000047e4ca in run_command (num_words=2, words=0xa80800, c=0x9f3ea0, context=0x9a7010) at src/helper/command.c:582
 #4  exec_command (argv=0x7fffffffd140, argc=<optimized out>, c=0x9f3ea0, cmd_ctx=0x9a7010, interp=0x9a7070) at src/helper/command.c:950
 #5  jim_command_dispatch (interp=0x9a7070, argc=<optimized out>, argv=0x7fffffffd140) at src/helper/command.c:1001
 #6  0x00000000005b839a in JimInvokeCommand (interp=interp@entry=0x9a7070, objc=objc@entry=2, objv=objv@entry=0x7fffffffd140) at jim.c:10514
 #7  0x00000000005b8fbc in Jim_EvalObj (interp=interp@entry=0x9a7070, scriptObjPtr=scriptObjPtr@entry=0x9e96d0) at jim.c:11006
 #8  0x00000000005bb12b in Jim_EvalSource (interp=interp@entry=0x9a7070, filename=filename@entry=0x0, lineno=lineno@entry=0,
     script=script@entry=0x9e0db0 "verify_image build/zephyr/zephyr.elf") at jim.c:11298
 #9  0x000000000047df5f in command_run_line (context=context@entry=0x9a7010, line=0x9e0db0 "verify_image build/zephyr/zephyr.elf") at src/helper/command.c:626
 #10 0x000000000047f6b8 in parse_config_file (cmd_ctx=cmd_ctx@entry=0x9a7010) at src/helper/configuration.c:136
 #11 0x00000000004053ae in openocd_thread (cmd_ctx=0x9a7010, argv=0x7fffffffd378, argc=18) at src/openocd.c:296
 #12 openocd_main (argc=18, argv=0x7fffffffd378) at src/openocd.c:356
 #13 0x00007ffff710d505 in __libc_start_main () from /lib64/libc.so.6
 #14 0x0000000000404e9e in _start ()
--------------------------->8--------------------------

That happens because we used to have ".checksum_memory" undefined
for ARC. And it was undefined on purpose as we never got to implement
a target-executed applet for CRC calculation.

But there seems to be a work-around of using real memory read back
via JTAG. And for that we just need to return anything != ERROR_OK
from ".checksum_memory()" callback. Which we do here.

Now image verification works for ARC as well!

Signed-off-by: Alexey Brodkin <[email protected]>
stephanosio pushed a commit to stephanosio/zephyr-openocd that referenced this issue Jun 14, 2022
In zephyrproject-rtos/zephyr#35284 it was
found that use of "verify_image" command for ARC boards lead to
OpenOCD segfault:
--------------------------->8--------------------------
 Program received signal SIGSEGV, Segmentation fault.
 0x0000000000000000 in ?? ()
 (gdb) bt
 #0  0x0000000000000000 in ?? ()
 zephyrproject-rtos#1  0x0000000000455e27 in target_checksum_memory (target=target@entry=0xa52450, address=2415919104, size=19952, crc=crc@entry=0x7fffffffcf64) at src/target/target.c:2522
 zephyrproject-rtos#2  0x0000000000456066 in handle_verify_image_command_internal (cmd=0x7fffffffd040, verify=IMAGE_VERIFY) at src/target/target.c:3846
 zephyrproject-rtos#3  0x000000000047e4ca in run_command (num_words=2, words=0xa80800, c=0x9f3ea0, context=0x9a7010) at src/helper/command.c:582
 zephyrproject-rtos#4  exec_command (argv=0x7fffffffd140, argc=<optimized out>, c=0x9f3ea0, cmd_ctx=0x9a7010, interp=0x9a7070) at src/helper/command.c:950
 zephyrproject-rtos#5  jim_command_dispatch (interp=0x9a7070, argc=<optimized out>, argv=0x7fffffffd140) at src/helper/command.c:1001
 zephyrproject-rtos#6  0x00000000005b839a in JimInvokeCommand (interp=interp@entry=0x9a7070, objc=objc@entry=2, objv=objv@entry=0x7fffffffd140) at jim.c:10514
 zephyrproject-rtos#7  0x00000000005b8fbc in Jim_EvalObj (interp=interp@entry=0x9a7070, scriptObjPtr=scriptObjPtr@entry=0x9e96d0) at jim.c:11006
 zephyrproject-rtos#8  0x00000000005bb12b in Jim_EvalSource (interp=interp@entry=0x9a7070, filename=filename@entry=0x0, lineno=lineno@entry=0,
     script=script@entry=0x9e0db0 "verify_image build/zephyr/zephyr.elf") at jim.c:11298
 zephyrproject-rtos#9  0x000000000047df5f in command_run_line (context=context@entry=0x9a7010, line=0x9e0db0 "verify_image build/zephyr/zephyr.elf") at src/helper/command.c:626
 zephyrproject-rtos#10 0x000000000047f6b8 in parse_config_file (cmd_ctx=cmd_ctx@entry=0x9a7010) at src/helper/configuration.c:136
 zephyrproject-rtos#11 0x00000000004053ae in openocd_thread (cmd_ctx=0x9a7010, argv=0x7fffffffd378, argc=18) at src/openocd.c:296
 zephyrproject-rtos#12 openocd_main (argc=18, argv=0x7fffffffd378) at src/openocd.c:356
 zephyrproject-rtos#13 0x00007ffff710d505 in __libc_start_main () from /lib64/libc.so.6
 zephyrproject-rtos#14 0x0000000000404e9e in _start ()
--------------------------->8--------------------------

That happens because we used to have ".checksum_memory" undefined
for ARC. And it was undefined on purpose as we never got to implement
a target-executed applet for CRC calculation.

But there seems to be a work-around of using real memory read back
via JTAG. And for that we just need to return anything != ERROR_OK
from ".checksum_memory()" callback. Which we do here.

Now image verification works for ARC as well!

Signed-off-by: Alexey Brodkin <[email protected]>
stephanosio pushed a commit that referenced this issue Jun 14, 2022
In zephyrproject-rtos/zephyr#35284 it was
found that use of "verify_image" command for ARC boards lead to
OpenOCD segfault:
--------------------------->8--------------------------
 Program received signal SIGSEGV, Segmentation fault.
 0x0000000000000000 in ?? ()
 (gdb) bt
 #0  0x0000000000000000 in ?? ()
 #1  0x0000000000455e27 in target_checksum_memory (target=target@entry=0xa52450, address=2415919104, size=19952, crc=crc@entry=0x7fffffffcf64) at src/target/target.c:2522
 #2  0x0000000000456066 in handle_verify_image_command_internal (cmd=0x7fffffffd040, verify=IMAGE_VERIFY) at src/target/target.c:3846
 #3  0x000000000047e4ca in run_command (num_words=2, words=0xa80800, c=0x9f3ea0, context=0x9a7010) at src/helper/command.c:582
 #4  exec_command (argv=0x7fffffffd140, argc=<optimized out>, c=0x9f3ea0, cmd_ctx=0x9a7010, interp=0x9a7070) at src/helper/command.c:950
 #5  jim_command_dispatch (interp=0x9a7070, argc=<optimized out>, argv=0x7fffffffd140) at src/helper/command.c:1001
 #6  0x00000000005b839a in JimInvokeCommand (interp=interp@entry=0x9a7070, objc=objc@entry=2, objv=objv@entry=0x7fffffffd140) at jim.c:10514
 #7  0x00000000005b8fbc in Jim_EvalObj (interp=interp@entry=0x9a7070, scriptObjPtr=scriptObjPtr@entry=0x9e96d0) at jim.c:11006
 #8  0x00000000005bb12b in Jim_EvalSource (interp=interp@entry=0x9a7070, filename=filename@entry=0x0, lineno=lineno@entry=0,
     script=script@entry=0x9e0db0 "verify_image build/zephyr/zephyr.elf") at jim.c:11298
 #9  0x000000000047df5f in command_run_line (context=context@entry=0x9a7010, line=0x9e0db0 "verify_image build/zephyr/zephyr.elf") at src/helper/command.c:626
 #10 0x000000000047f6b8 in parse_config_file (cmd_ctx=cmd_ctx@entry=0x9a7010) at src/helper/configuration.c:136
 #11 0x00000000004053ae in openocd_thread (cmd_ctx=0x9a7010, argv=0x7fffffffd378, argc=18) at src/openocd.c:296
 #12 openocd_main (argc=18, argv=0x7fffffffd378) at src/openocd.c:356
 #13 0x00007ffff710d505 in __libc_start_main () from /lib64/libc.so.6
 #14 0x0000000000404e9e in _start ()
--------------------------->8--------------------------

That happens because we used to have ".checksum_memory" undefined
for ARC. And it was undefined on purpose as we never got to implement
a target-executed applet for CRC calculation.

But there seems to be a work-around of using real memory read back
via JTAG. And for that we just need to return anything != ERROR_OK
from ".checksum_memory()" callback. Which we do here.

Now image verification works for ARC as well!

Signed-off-by: Alexey Brodkin <[email protected]>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants