Bootloader-less Pro - Advanced AVR 3.0 Core - Part 3 - SPM - App Writes to App section - programmer
Boot header from AVR-c actually suck BBC, (Probably written by someone from Britain?) thus SPM and LPM code are rewritten. Bootloader mechanism found in the AVR is good only for the protection part of the feature. Self-program can be done without it with a little bit extra care. Beside on being able to update its own source code, the flash memory can be easily used as flash to store data, for instance a logger that requires a lot of memory can store its data to the flash memory.
Finally succeed after many failed attempts, now even though the filling and erasing code are using avr-c boot header, a better approach had been rewritten. Here demonstrates how application is able to write to its application section. The little led blink code has actually being completely removed and replaced with my typed-in of data. In a real application, the flash page is allocated way down the memory lane so the actual application code will not be over-written.
Getting naked attribute is what made this works, but the spm function needs to go back to application manually, since naked has no return path. This can be easily done in 5 known ways.
PS. similar thing can be done using the badly written avr-c boot header file as well. Writing to itself is actually very simple. It's really just the first step to implementing the program memory space as normal memory for the application.
PPS. Here application section is written to without a bootloader, thus the name Bootloader-less. Technically the code that write to application is still within the bootloader section, since spm instruction only works there for security reason. The advantages of writing to self Bootloader-less are: 1, bootloader can be programmed in combination with the application code at the same time or separately or whatever; 2, Bootloader-less can allocate program memory as normal flash memory easily. 3, The Bootloader-less idea is tested in preparation for creating a programmer which is also self-programmable