Page 1 of 1

[Solved] Read flash memory in debugger (incl. reserved regions)

Posted: Fri Dec 09, 2022 11:00 am
by espnoob
Hi,

is it, in principle, possible to read flash memory in GDB?

I have tried to print the partition table at address 0x8000. But only zeros are returned.
The chip in question is an ESP32S3 with 32MB external flash memory.

Maybe some lowlevel openocd command can be used?

Thanks!

Re: Read flash memory in debugger (incl. reserved regions)

Posted: Mon Dec 12, 2022 6:30 am
by espnoob
Nothing?
Printing flash memory should be possible (for internal memory, but also for external memory because it is mapped into address space).

Maybe the MMU interferes during runtime?

Re: Read flash memory in debugger (incl. reserved regions)

Posted: Mon Dec 12, 2022 9:01 am
by ESP_Sprite
Only the text&rodata portions (by default) are mapped into the address space, not the entire flash. I think you can access flash directly by running the OpenOCD 'flash read_bank' command. (Note in gdb you would use 'mon flash read_bank' to pass the command through to openocd)

Re: Read flash memory in debugger (incl. reserved regions)

Posted: Mon Dec 12, 2022 12:39 pm
by espnoob
Hello Sprite,

thanks for the pointers.

Indeed, some data can be dumped with "mon flash read_bank"; for just printing to the screen "mon flash mdb" seems to work fine, too.

I still seem to miss something: suppose I have a custom partition table with an entry for data at offset 0xF000 and suppose that
data gets written to the partition using the partition API (e.g. esp_partition_write_raw).

Should I be able to read the memory at the given offset after the write operations are finished? Is there some other mechanism
(mmap?) involved? What about NVS?

Thanks!

Re: Read flash memory in debugger (incl. reserved regions)

Posted: Tue Dec 13, 2022 1:08 am
by ESP_Sprite
You would need to mmap (part of) the partition for it to be visible as memory; as I said before, by default only the text/rodata segments of your program are mmap'ped in. So NVS also wouldn't be visible unless you mmap the partition manually.

Re: Read flash memory in debugger (incl. reserved regions)

Posted: Tue Dec 13, 2022 6:33 am
by espnoob
OK, understood, thanks!