Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Created optiboot_copy #262

Open
wants to merge 3 commits into
base: master
Choose a base branch
from
Open

Conversation

gmattinson
Copy link

Created optiboot_copy which is equivalent to memcpy() for program memory. This allowed me to make self-updating firmware.

To work, your sketch must consume less than half of the available program memory. This allows you to temporarily write your entire sketch to the free flash memory and then use optiboot_copy to copy the sketch from the temporary location to the correct address.

When the copy is done, obviously the return address in the call stack is incorrect. Hence the last line of optiboot_copy calls to a user-specified address instead of returning. In my case, that address is 0 which reboots the device.

@WestfW WestfW added Priority-Low Type-Enhancement Announcement Usually 3rd-party projects related to Optiboot labels Dec 29, 2018
@WestfW
Copy link
Member

WestfW commented Dec 29, 2018

Some discussion here: https://forum.arduino.cc/index.php?topic=586707
This PR will probably not be merged, but I'm happy to have it here as a demo of how this might be done...

Another user has pointed out that this version only works on chips with <=64k of flash.

@JAndrassy
Copy link

JAndrassy commented Dec 29, 2018

@gmattinson boards.txt board variant?

@gmattinson
Copy link
Author

@JAndrassy right, sorry, I forgot about that part. Partially because I didn't know what to do with it since boards.txt only needs to change if you define BIGBOOT to enable these changes. And I only changed it for the ATmega328p since that is the only board I have to test with. Here are the changes I made:

optiboot32.menu.cpu.atmega328p.upload.maximum_size=31744
optiboot32.menu.cpu.atmega328p.bootloader.high_fuses=0xDC

Original values were 32256 and 0xDE. This adjusts the fuses for the new boot loader size (1024 bytes instead of 512 bytes).

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Announcement Usually 3rd-party projects related to Optiboot Priority-Low Type-Enhancement
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants