putting const variable in fixed address location

35 views
Skip to first unread message

nishant agrawal

unread,
Oct 28, 2016, 2:16:20 AM10/28/16
to esp-open-rtos mailing list
Hello everyone,
 
I am working on a wireless display using ESP8266. Each of these displays need to have a unique 4 byte address, but I don't want to generate a separate output for each address, nor do I want to put in any kind of user interface to change the address, not worth it at the moment. So I was thinking of putting in a const variable at a fixed address and changing the value directly in the generated binary image. This is what I did for the code.

const uint32_t device_address __attribute__((section(".device_addr"))) = 0x12345678;

This is my addition to the linker script program.ld

MEMORY
{
  dport0_0_seg :                       org = 0x3FF00000, len = 0x10
  dram0_0_seg :                       org = 0x3FFE8000, len = 0x14000
  iram1_0_seg :                       org = 0x40100000, len = 0x08000
/* irom0 section, mapped from SPI flash
  - Origin is offset by 0x2010 to create spacer for second stage bootloader image,
    header.

  - Length is max 8Mbit of mappable flash, minus start offset
*/
  irom0_0_seg :                       org = 0x40202010, len = (1M - 0x2020)
  device_addr_section : org = 0x40202100, len = 0x04
}

Inside SECTIONS, my addition was
 
  .addr_section : ALIGN(4)
  {
KEEP(*(.device_addr))
  } >device_addr_section

When I compile the code after changing the linker and generate the binary, I can see the section device_addr_section in the map file generated but I don't see the value 0x12345678 in the final binary image. When I remove the attribute from the variable device_address, I can see that value in the generated binary image. What is it that I need to add to make sure that this value reflects in the final binary image.

I am not very good with gcc linker so any help would be very appreciated.


Reply all
Reply to author
Forward
0 new messages