Detecting bootloader version?

Is there some way to detected via a compile directive, or if not, via some run-time variable the boot-loader that is being used?

Specifically I am interested in being able to tell the difference between: o Arduino Pro or Pro Mini (3.3v, 8Mhz) w/ATmega328 o the Optiboot version of that.

I am tripping up over the handing of the watchdog in the 'normal' bootloader and though I have a workaround for most of my situation, it comes with some understand side effects. I want to be able to decide (at compile time would be best) which bootloader is being targeted and have my code adjust to either the preferred way of operation if it is the Optiboot version, or the slightly dysfunctional workaround if it is not...

If there some #define I can do an #ifdef against? Or some runtime variable I can do a straight If statement with?

I have thought about declaring a veriable and using the address of it (or perhaps the address of the setup() function), and if it is under say 1K assume the Optiboot is being used, but that seems a bit unstable. Plus I would have to research the load order that is used by the Arduino IDE :D

Thank you, -al-

It's possible to download the bootloader and work out which type/version it is. With enough determination, and working outside the Arduino IDE, you could do this as part of the upload process and define corresponding preprocessor definitions to get the appropriate code options compiled in. It does not seem like a very practical approach though. An intermediate solution would be to download/recognise the bootloader manually and then manually edit #define assignments within your sketch to reflect that before building it.

If you were willing to customise the IDE installation, you could define a different board type for each board/bootloader combination and define some bootloader-specific preprocessor definitions. That would still rely on your manually selecting the right board/bootloader type within the IDE.

I guess that what you're really hoping for is some way for the sketch to work out where the bootloader code is stored and read the code to work out which bootloader it is. I'm not sure, but I suspect that the sketch doesn't have access to program memory containing the bootloader. Even if it did have access, finding and analysing the bootloader would be an extremely difficult task and I doubt that it would be practical to do this generically i.e. supporting different chip types and bootloader section sizes.

PeterH:

I guess that what you’re really hoping for is some way for the sketch to work out where the bootloader code is stored and read the code to work out which bootloader it is. I’m not sure, but I suspect that the sketch doesn’t have access to program memory containing the bootloader. Even if it did have access, finding and analysing the bootloader would be an extremely difficult task and I doubt that it would be practical to do this generically i.e. supporting different chip types and bootloader section sizes.

Hello, Thank you. Yes, that is my goal - to be able to ID the bootloader installed w/o doing any further modifications. My thinking is: I have an OK workaround in the code for people who just use the out-of-the-box Arduino IDE install, but really do want to be able to fully use the Watchdogs properly - which the out-of-the-box bootloader will not do. (This is a 3.3v only statement, the Uno bootloader works fine. But then, it is already an Optiboot version in the as-shipped Arduino IDE - more here: VSR Alternator Regulator: Solving watchdog non-support in 3.3v Arduinos with optiBoot).

Of course, I could simply REQUIRE people always install the Optiboot bootloader for the 3.3v version before using my sketch, but wanted to make it more user flexible and user friendly…

-al-