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

espnoob
Posts: 13
Joined: Mon Oct 31, 2022 3:22 pm

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

Postby espnoob » Fri Dec 09, 2022 11:00 am

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!
Last edited by espnoob on Tue Dec 20, 2022 7:41 am, edited 1 time in total.

espnoob
Posts: 13
Joined: Mon Oct 31, 2022 3:22 pm

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

Postby espnoob » Mon Dec 12, 2022 6:30 am

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?

ESP_Sprite
Posts: 9764
Joined: Thu Nov 26, 2015 4:08 am

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

Postby ESP_Sprite » Mon Dec 12, 2022 9:01 am

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)

espnoob
Posts: 13
Joined: Mon Oct 31, 2022 3:22 pm

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

Postby espnoob » Mon Dec 12, 2022 12:39 pm

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!

ESP_Sprite
Posts: 9764
Joined: Thu Nov 26, 2015 4:08 am

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

Postby ESP_Sprite » Tue Dec 13, 2022 1:08 am

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.

espnoob
Posts: 13
Joined: Mon Oct 31, 2022 3:22 pm

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

Postby espnoob » Tue Dec 13, 2022 6:33 am

OK, understood, thanks!

Who is online

Users browsing this forum: atx823, brushlow18 and 247 guests