Using a linker script in GCC to locate functions at specific memory regions

snahmad75
Posts: 445
Joined: Wed Jan 24, 2018 6:32 pm

Using a linker script in GCC to locate functions at specific memory regions

Postby snahmad75 » Mon Sep 17, 2018 9:13 pm

Hi,


I did try to follow this example. https://www.silabs.com/community/mcu/32 ... scrip-s5bu

no luck.

I just need to define my structure at specified RAM location ( fix address) on Esp32.

Is it possible. how can i do it. kindly give me full example including changing Esp32 linker file.

ESP_Angus
Posts: 2344
Joined: Sun May 08, 2016 4:11 am

Re: Using a linker script in GCC to locate functions at specific memory regions

Postby ESP_Angus » Mon Sep 17, 2018 11:52 pm

Hi snahmad,

The ESP-IDF is quite a complex development environment compared to very simple microcontrollers, so this can require some care and has some potential pitfalls.

Can you please explain exactly what you aim to do? (ie for what purpose do you want to place a function at a specific memory address?)

Angus

snahmad75
Posts: 445
Joined: Wed Jan 24, 2018 6:32 pm

Re: Using a linker script in GCC to locate functions at specific memory regions

Postby snahmad75 » Tue Sep 18, 2018 9:00 am

Hi Angus,

We have a need for an application to open and read an ESP32 BIN file to extract various data values, including the firmware version number. To achieve this, the application needs to look in a defined (external) Flash ROM address to find this table of values.

We defined a MEMORY block (in esp32.ld) at the very beginning of external Flash ROM:
drom0_boftable_seg (R) : org = 0x3F400018, len = 0x100 /* Data table */

We defined a SECTION (in esp32.common.ld):
.drom0_boftable 0x3F400018 :
{
KEEP(*(.bof_table))
} > drom0_boftable_seg

We defined the data table in a project code module:
const BOFTablePtr_s _MainAppDT[] __attribute__((__section__(".bof_table"))) = {
/* 1st Vector */
<pointer 1>,
/* 2nd Vector */
<pointer 2>,

/* Last Vector */
(void*)NULL
};

We feel that we're close, so any help you can offer will be gratefully received.

ESP_Angus
Posts: 2344
Joined: Sun May 08, 2016 4:11 am

Re: Using a linker script in GCC to locate functions at specific memory regions

Postby ESP_Angus » Wed Sep 19, 2018 12:02 am

I think I understand. You want to read this metadata externally, yes? ie the application runs on a computer and parses the .bin files.

If so, writing to a fixed memory address only gets you part way. Because the ESP32 has an MMU, there's no guarantee that a virtual memory address (like 0x3F400018) corresponds to a particular address in the .bin file. You'd need to parse the .bin file format in order to determine that information.

(This is different on a much simpler micro like the one you linked, where there's no MMU and the physical flash layout always has a fixed correspondence to the virtual address space.)

You can do it that way, but it's a lot of extra complexity that I would recommend avoiding.

One other way is to append the information "out of band" to the .bin file:
  • Generate the .bin file normally from the build process
  • Pad the .bin file with 0xFFs to (Size of partition - 0x100)
  • Append the 0x100 bytes (or whatever) of metadata there
  • Read it from an external app by seeking to the end of the .bin file, or read it from inside the ESP32 with esp_partition_mmap().
Another way to get a canonical "app identifier" which ESP-IDF uses is a SHA-256 hash of all the image content. You can get these from "esptool.py --chip esp32 image_info path/to/binfile.bin" or esp_partition_get_sha256() (new in IDF V3.2). You'd still need an external lookup table from SHA identifier to other metadata. This has the advantage that even if you accidentally deploy two .bin files with the same metadata but different content, you can differentiate them.

Who is online

Users browsing this forum: ESP_ondrej, ESP_Roland and 121 guests