Go Down

Topic: Reduce bootloader size (Read 2027 times) previous topic - next topic

estratos

Hi,

I'm looking forward to reduce the size of the standard serial bootloader in order to make some room for a custom calibration routine. Is there any thing that may be removed/commented from the standard source file without altering the normal use of the bootloader? This is for a custom Atmega328p board running from the internal RC oscilator. Hence my wish to do some calibrations from the bootloader.

Thanks in advance!

Daniel.

retrolefty

#1
Aug 31, 2012, 05:11 pm Last Edit: Aug 31, 2012, 05:21 pm by retrolefty Reason: 1

Hi,

I'm looking forward to reduce the size of the standard serial bootloader in order to make some room for a custom calibration routine. Is there any thing that may be removed/commented from the standard source file without altering the normal use of the bootloader? This is for a custom Atmega328p board running from the internal RC oscilator. Hence my wish to do some calibrations from the bootloader.

Thanks in advance!

Daniel.



Well I think there is little point in your request. As I understand it the current Uno bootloader already fits inside the smallest flash chunk size the AVR hardware can reserve for a protected bootloader space. I will let ours confirm that statement. If that is indeed the case, making the object size of the bootloader any smaller would not free up any available flash space for you users sketch. I seem to recall reading posted here that the current uno bootloader leaves only 3 bytes free from the size limit it uses for the smallest possible flash memory bootloader reserved area.

Or are you wishing to add your calibration function to the bootloader such that it runs only when the chip is first powered up or upon a hardware reset? If that is the case you could possibly add it to the existing bootloader source code, recompile it and then burn this new bootloading/self-calibrating program into the chip using the next larger size reserved bootloader section of the flash memory. The fuse settings tell the chip what size bootloader area to save and I think the choices are 256, 512, and 1024 bytes, but check the 328p datasheet to confirm that, as I'm pretty old and the old memory can play tricks on me.  ;)

I don't see an advantage to having your calibration function run inside a bootloader area, as just running it from the setup function of your sketch would accomplish the same thing, to be run just once at power up or reset time. But perhaps I'm not fully understanding your requirements?

Lefty

estratos

Thanks Lefty,

I'm using the old 2KB bootloader, with support for the WDT, since I was unable to make optiboot work on my board.

retrolefty


Thanks Lefty,

I'm using the old 2KB bootloader, with support for the WDT, since I was unable to make optiboot work on my board.



I'm pretty sure the uno bootloader for the 328p handles WDT correctly. Probably you should try and figure out why you can't burn and run optiboot on your 328p chip rather then trying to add a function to your old bootloader. And again why not just run your calibration function inside the setup function in your sketch?

estratos


I'm pretty sure the uno bootloader for the 328p handles WDT correctly. Probably you should try and figure out why you can't burn and run optiboot on your 328p chip rather then trying to add a function to your old bootloader.


Not sure why but the bootloader didn't like running at 8MHz, at least from the internal RC oscillator. I even posted a question some time ago but nobody seemed to be using those settings with optiboot.

Quote

And again why not just run your calibration function inside the setup function in your sketch?


This is how I'm running it right now. I just wondered if running the calibration tasks from the bootloader was something possible, mainly because I wanted to run them before comms start.

Thanks again!

Daniel.

retrolefty



I'm pretty sure the uno bootloader for the 328p handles WDT correctly. Probably you should try and figure out why you can't burn and run optiboot on your 328p chip rather then trying to add a function to your old bootloader.


Not sure why but the bootloader didn't like running at 8MHz, at least from the internal RC oscillator. I even posted a question some time ago but nobody seemed to be using those settings with optiboot.

That is a problem, as the standard arduino optiboot is hard coded to run at 16mhz, so the baudrate would be wrong if you run it at 8mhz. You would need a modified optiboot recompiled to run at 8mhz.

Quote

And again why not just run your calibration function inside the setup function in your sketch?


This is how I'm running it right now. I just wondered if running the calibration tasks from the bootloader was something possible, mainly because I wanted to run them before comms start.

Well just place your calibrate function inside your setup function before the comm statements, even add a delay if you wish or need before you execute the comm start statements. You are making a problem where one does not exist I think.  ;)

Thanks again!

Daniel.

estratos

You're right, that was not a problem. Just looking forward to do it a bit smarter  :D

As for optiboot, I remember having tried to hack it for 8MHz but no luck. I should maybe look into this again.

Thank you very much!

Tom Carpenter

Here you go, optiboot for 8MHz for the 328p. It uses 115200Baud

You just need to set the fuses for a 512byte boot partition. I believe the fuse settings should be:
Low = 0xE2
High = 0xD4
Extended = 0xFE
~Tom~

CrossRoads

Can also upload your code with an ISP programmer,
File:Upload Using Programmer
and take all the bootload space back.

Still too big? Time to move up to a bigger chip such as '1284. 16K SRAM, 128K Flash.
Examples at my signature link with 1284 Mini's and '1284 style duemilanove style PCBs available to purchase.
Designing & building electrical circuits for over 25 years.  Screw Shield for Mega/Due/Uno,  Bobuino with ATMega1284P, & other '328P & '1284P creations & offerings at  my website.

pito


Here you go, optiboot for 8MHz for the 328p. It uses 115200Baud

Does the 115k2 uart run reliably at 8MHz ?? There is 7.8% error, though..

Tom Carpenter

I haven't tried it, but that is the bootloader file for the Sparkfun pro mini.
~Tom~

estratos

Finally got to make optiboot work on my custom board. The problem was in that I was incorrectly defining the board in boards.txt. This time I copied the UNO definition and changed f_cpu to 8000000L. Well, now I have enough room to add my calibration routine in the bootloader itself.

Thanks guys for your help!

Daniel.

Go Up