Variable address in .map file

Go To Last Post
10 posts / 0 new
Author
Message
#1
  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

Hi. I have a single variable which I would like to share between bootloader and application. Since it's only one variable, the simplest thing to do is to find its address and hardcode address in application. I realise this is bad practice, however:

 

1) I am 100% certain that I won't change bootloader any further code since the logic works as it should

and

2) Since bootloader in question is (modified) LUFA Mass Storage bootloader running on 32u4, which makes heavy use of AUX sections and some other workarounds to make it fit, I don't want to mess with linker scripts and my own sections.

 

I've placed variable in .noinit section, and I can see it in map file:

 

 

What I don't understand is - how do I access/modify it in application?

This topic has a solution.
Last Edited: Tue. Dec 27, 2016 - 07:40 PM
This reply has been marked as the solution. 
  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

This appears to be a GCC (i.e. toolchain-dependent) question rather than a general AVR question.

 

But in general, isn't the answer that you use the name?

 

softTrig = 1;

Where is the declaration?  Where is the definition?  If the definition is in the current compiler unit, then the above is sufficient, right?  Otherwise, an extern might be needed so the linker can sort it out.

 

 

You can put lipstick on a pig, but it is still a pig.

I've never met a pig I didn't like, as long as you have some salt and pepper.

  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

Sorry for the incomplete post. Variable is defined in bootloader code, like this:

 

uint16_t softTrig __attribute__ ((section (".noinit")));

 

What I want is to access that variable in application code.

 

  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

But bootloader and app both have a CRT? There's every chance the do_copy_data() /do_clear_bss() in one or the other (or both) will be initialising RAM location 0x028B. So what is the purpose of this modification? Are you planning to write the location in the app code then jump back to the boot code somehow avoiding  its CRT?

  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

Wouldn't be better to put this in EEPROM?

 

 

Click Link: Get Free Stock: Retire early! PM for strategy

share.robinhood.com/jamesc3274
get $5 free gold/silver https://www.onegold.com/join/713...

 

 

 

 

  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

BTW if you want to try it:

 

#define SOFT_TRIG *( (uint16_t *) 0x28b)

 

then just

 

SOFT_TRIG = 1;

  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

clawson wrote:

But bootloader and app both have a CRT?

 

I'm not sure what's CRT.

 

clawson wrote:
There's every chance the do_copy_data() /do_clear_bss() in one or the other (or both) will be initialising RAM location 0x028B.

 

I see. What I want to do is to enter bootloader via software. I've already implemented entry into bootloader using external switch, but I would also like ability to enter bootloader using application. Application would simply change the variable to specific value and reset the microcontroller using watchdog reset (BTRST fuse is set), so that bootloader entry logic basically boils down to:

 

if BUTTON_PRESSED || softTrig == MAGIC_VALUE

ENTER BOOTLOADER

ELSE

ENTER APPLICATION

 

What would be bullet-proof solution, if I can't rely on hardcoding the memory location?

Last Edited: Tue. Dec 27, 2016 - 07:47 PM
  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

Shantea wrote:
What would be bullet-proof solution, if I can't rely on hardcoding the memory location?

I don't know about the "bulletproof", but I would

ki0bk wrote:
Wouldn't be better to put this in EEPROM?

...put it in EEPROM.

You can put lipstick on a pig, but it is still a pig.

I've never met a pig I didn't like, as long as you have some salt and pepper.

  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

I'd rather not use EEPROM is any other way is possible. Anyway, I think I've figured some parts of solution:

 

1) I have defined custom start location of .noinit for bootloader. Since I know that I'm only going to use a single uint16_t variable, I've placed it 2 bytes before .data end with this linker option:

 

-Wl,--section-start=.noinit=0x00800AFD

 

Now, when I look at map file for Bootloader, I see this:

.noinit         0x00800afd        0x2
                [!provide]                PROVIDE (__noinit_start, .)
 *(.noinit*)
 .noinit        0x00800afd        0x2 BootloaderMassStorage.o
                0x00800afd                softTrig
                [!provide]                PROVIDE (__noinit_end, .)
                0x00800aff                _end = .
                [!provide]                PROVIDE (__heap_start, .)

This seems right so far. Then, I've tried to do the same with application. I've declared test variable in my main.cpp application file:

 

uint16_t testVar __attribute__ ((section (".noinit")));

However, looking at map output for application, .noinit looks different, and also testVar isn't listed. Start address does seem right though.

 

.noinit         0x00800afd        0x0
                [!provide]                PROVIDE (__noinit_start, .)
 *(.noinit*)
                [!provide]                PROVIDE (__noinit_end, .)
                0x00800afd                _end = .
                [!provide]                PROVIDE (__heap_start, .)

 

What am I missing here?

  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

Shantea wrote:
I'd rather not use EEPROM ...

So, tell more about that.  Once your mechanism is properly invoked to communicate between bootloader and app, when the signal is in EEPROM it will survive power cycles and external resets and probably even cosmic rays.  The SRAM solution won't.

 

I'm certainly no GCC guru.  But if you have shared stuff between bootloader and app, don't you just put the same boottrig.c into both your bootloader and app builds, putting the section at the same address with the linker for both?  It seems straightforward.

You can put lipstick on a pig, but it is still a pig.

I've never met a pig I didn't like, as long as you have some salt and pepper.