Yahoo Groups archive

AVR-Chat

Index last updated: 2026-04-28 22:41 UTC

Thread

Passing info from bootloader to application

Passing info from bootloader to application

2014-08-18 by Chuck Hackett

I have an ATMega1284p based application. I have a bootloader installed. My application needs to know the reason for a start/restart (power-on, reset button, brown-out, WDT, etc.).

Before I started using the bootloader my application did this be saving the MCUSR immediately upon startup:

uint8_t mcucsr_mirror __attribute__ ((section (".noinit")));

__attribute__ ((no_instrument_function)) void Restart_ProcessRestart(void) \

__attribute__((naked)) \

__attribute__((section(".init3")));

void Restart_ProcessRestart(void)

{

mcucsr_mirror = MCUSR;

MCUSR = 0;

wdt_disable();

….

With the bootloader installed the MCUSR is getting destroyed by the bootloader so the application does not have access to it.

I have the source to the bootloader.

What is the best way to pass 1 byte of information from the bootloader to the application?

I know that I could define a common ‘mailbox’ memory location but I would like to keep the bootloader application independent.

The current ‘main’ called by the bootloader is defined as:

void (*app_start)(void) = 0x0000;

Can the ‘main’ being called by the bootloader be defined with parameters?

void (*app_start)(uint8_t MCUSR) = 0x0000;

Will this work if an application which does not care about the MCUSR defines it’s ‘main’ as ‘normal’?

void main(void);

If this is not appropriate, can I pass the value in a register?

If so, what register (as I recall GCC requires R1 to be 0)?

I assume assembly code will be required. I have not done assembly programming on the AVR so applicable assembly snippets would be appreciated.

Nope, this is not for homework – I’m 65 and way past school J

Cheers,

Chuck Hackett

"Good judgment comes from experience, experience comes from bad judgment"

7.5" gauge Union Pacific Northern (4-8-4) 844 http://www.whitetrout.net/Chuck

Re: Passing info from bootloader to application

2014-08-18 by dkinzer@gmail.com

The simplest way is to pass the MCUSR value in a register. I recently added code to the OptiBoot bootloader to do this and it has been done this way in the ZBasic bootloader for years. In both cases, register R2 is used but you can choose any register that isn't modified by the startup code prior to your having a chance to store the value. You can find the source code for OptiBoot online; my change was incorporated into v4.6.Don KinzerZBasic Microcontrollershttp://www.zbasic.net

RE: [AVR-Chat] Re: Passing info from bootloader to application

2014-08-19 by Chuck Hackett

Thanks for the info.  I’m digesting it now along with reading some Inline Assembly tutorials so I can understand the code.

 

Cheers,

 

Chuck Hackett

"Good judgment comes from experience, experience comes from bad judgment"

7.5" gauge Union Pacific Northern (4-8-4) 844 http://www.whitetrout.net/Chuck
Show quoted textHide quoted text
From: AVR-Chat@yahoogroups.com [mailto:AVR-Chat@yahoogroups.com] 
Sent: Monday, August 18, 2014 10:32 AM
To: AVR-Chat@yahoogroups.com
Subject: [AVR-Chat] Re: Passing info from bootloader to application

 



The simplest way is to pass the MCUSR value in a register.  I recently added code to the OptiBoot bootloader to do this and it has been done this way in the ZBasic bootloader for years.  In both cases, register R2 is used but you can choose any register that isn't modified by the startup code prior to your having a chance to store the value.  You can find the source code for OptiBoot online; my change was incorporated into v4.6.Don KinzerZBasic Microcontrollershttp://www.zbasic.net 






  _____  

Posted by: dkinzer@gmail.com 

  _____  

  <http://geo.yahoo.com/serv?s=97476590/grpId=4313974/grpspId=1706554205/msgId=18663/stime=1408375950>

Move to quarantaine

This moves the raw source file on disk only. The archive index is not changed automatically, so you still need to run a manual refresh afterward.