SPM 2.0 writes to self - Advanced AVR 3.0 Core Bootloader

Channel:
Subscribers:
580
Published on ● Video Link: https://www.youtube.com/watch?v=G6KuUT0BXes



Duration: 2:20
6 views
0


Application section writes to application section is almost impossible because the SPM instruction required to write to flash memory is also required to be residing in the bootloader section, but it can be done easily so by defining a function within the bootloader section using linkage switch start-section. This way, the SPM is happily living in the bootloader section, while the application code can write to itself.

One simple function is created to do one page write: 1, SRAM is filled with one page worth of data (64 bytes for the Atmega8); 2, the writeFlash() function is called: A, it fills the flash buffer with the SRAM buffer; B, it erases the whole page; C, it writes to the page with the data from the flash buffer. 3, done! Filling up one page to SRAM before calling the writeFlash() function is more efficient.

Note: Before EEPROM has been done writing, it's not valid to write to buffer nor to the flash.

Note2: SPM 2.0 is the finalized c code using boot.h; It's good enough. SPM 3.0 had already been done with custom written inline asm spm code, but it's only slightly better, but it will not work with larger flash memory MCU, so SPM 3.0 is discarded. The SPM 2.0 writeFlash() code compiled to 94 bytes, less than 2 pages, good enough is good enough.

Note3: Even though how SPM writes to flash is not described in words fully and in detail, the compiled assembly code for writeFlash() are fully commented, line by line, and this is better. For those who can't read assembly, the comments serve as pseudo code for understand how to write with SPM.

Note4: Actually, bad is bad, and for going the extra mile, a simplified routine will be test with simple asm and c. Writing to SPM is actually very simple, and there is no need to write the complicated hard coded routine all in inline asm. It's less portable and hard to understand for beginner. It's less about code optimization, but more out of despite for badly written code using macro. Finally, it can't be called advanced if it can't be done in multiple ways, and c code is more readable than anything else, and easier for the compiler to optimize, and so it's done, using 86 bytes instead of 94 bytes.




Other Videos By Flyandance


2023-03-26New FDxBOOT 1.0.RC - 476 bytes - 4770 B/s @1Mpbs - Bootloader self-program - AVR109/AVR911/butterfly
2023-03-25Spoofing AVR109/AVR911/butterfly - Fixing its retarded protocol and Bootloader AVRdude AVROSP
2023-03-24Bootloader self-program - Juno AVR109 Beta/draft Part 2 - Advanced AVR 3.0 Core
2023-03-23AVR109 Deeper look
2023-03-22Cutting board is over-rated: Cut half onion by hand w/o one
2023-03-21Bare Minimal 2 | .init0 | naked | .ctors | signal | -nostartfiles - Advanced AVR 3.0 Core
2023-03-20Bootloader self-program - Juno AVR109 Rewrite Part 1 - Advanced AVR 3.0 Core
2023-03-19Bootloader self-program - AVR109 speed test avrdude - Advanced AVR 3.0 Core - 1Mbps with 8MHz CPU
2023-03-18Bootloader self-program - AVR109 w/ AVROSP and avrdude - Advanced AVR 3.0 Core
2023-03-17SPM 3.0 writes to self - Advanced AVR 3.0 Core Bootloader
2023-03-16SPM 2.0 writes to self - Advanced AVR 3.0 Core Bootloader
2023-03-14You jump, ijmp - Inline asm Indirect Jump - Advanced AVR 3.0 Core Bootloader
2023-03-05yt-dlp - A ultimate guide (The result of 2 weeks of hard work)
2023-03-03True bare Minimal code - Advanced AVR 3.0 Core Bootloader Pro Part 4 Size does matters getting naked
2023-02-28Bootloader-less Pro - Advanced AVR 3.0 Core - Part 3 - SPM - App Writes to App section - programmer
2023-02-27Bootloader-less Pro - Advanced AVR 3.0 Core - Part 2 - SPM erase self destruction code
2023-02-26Inline ASM - Advanced AVR 3.0 Core - LMP read from flash Load Program Memory
2023-02-25Inline ASM - Advanced AVR 3.0 Core - Finalizing
2023-02-22Inline ASM - Advanced AVR 3.0 Core
2023-02-19Bootloader-less Pro - Advanced AVR 3.0 Core - Part 1 - GCC Sections functions attribute
2023-02-17Script cowboy - the power of one line of code