Hi all,

I've found an interesting issue while working with 64 MiB external QSPI
flash bank. Bank is memory mapped, so 'default_flash_read()' is used in the
flash driver. OpenOCD consumes as much as 6.8 GiB (!!!) of RAM when I am
trying to read (flash read_bank) or verify (flash verify_bank) the contents
of this bank. This is reproducible with JTAG transport only.

That was surprising so I've made small investigation and found that most of
the memory is allocated in:
cmd_queue_alloc (commands.c) - 4.2 GiB
dap_cmd_new (adi_v5_jtag.c) - 2.25GiB

This happens because JTAG queue size is not limited in any way. OpenOCD
queues 16 million of AP reads allocating all corresponding data structures.
Full valgrind log is available on pastebin:
https://pastebin.com/raw/0vjHXxk6

Some of the possible solutions to the problem are:
[1] Check the number of queued commands in adi_v5_jtag.c within
jtag_(dp|ap)_q_(read|write) functions and forcibly execute the queue by
calling dap_run() when number of queued commands exceeds some limit. I am
currently testing this approach and it seems to work correctly, but this
change affects all targets so I am not sure if it will not make things
broken.

[2] Read data in small chunks (e.g. 64 KiB) in
handle_flash_read_bank_command etc. This is more safe but it does not cover
all possible cases.

Any suggestion on this? I am ready to submit the patch [1] to gerrit but I
would like to hear the opinion of the community.

Thanks,
Bohdan Tymkiv
_______________________________________________
OpenOCD-devel mailing list
[email protected]
https://lists.sourceforge.net/lists/listinfo/openocd-devel

Reply via email to