Boot Loader Support
– Read-While-Write
Self-Programming
The Boot Loader Support provides a real Read-While-Write Self-Programming mechanism for downloading and uploading program code by the MCU itself. This feature allows flexible application software updates controlled by the MCU using a Flash-resi- dent Boot Loader program. The Boot Loader program can use any available data interface and associated protocol to read code and write (program) that code into the Flash memory, or read the code from the Program memory. The program code within the Boot Loader section has the capability to write into the entire Flash, including the Boot Loader Memory. The Boot Loader can thus even modify itself, and it can also erase itself from the code if the feature is not needed anymore. The size of the Boot Loader Memory is configurable with fuses and the Boot Loader has two separate sets of Boot Lock Bits which can be set independently. This gives the user a unique flexibility to select different levels of protection.
Boot Loader Features
•Read-While-Write Self-Programming
•Flexible Boot Memory Size
•High Security (Separate Boot Lock Bits for a Flexible Protection)
•Separate Fuse to Select Reset Vector
•Optimized Page(1) Size
•Code Efficient Algorithm
•Efficient Read-Modify-Write Support
Note: 1. A page is a section in the Flash consisting of several bytes (see Table 89 on page 222) used during programming. The page organization does not affect normal operation.
Application and Boot
Loader Flash Sections
Application Section
The Flash memory is organized in two main sections, the Application section and the Boot loader section (see Figure 102). The size of the different sections is configured by the BOOTSZ Fuses as shown in Table 82 on page 217 and Figure 102. These two sections can have different level of protection since they have different sets of Lock Bits.
The application section is the section of the Flash that is used for storing the application code. The protection level for the application section can be selected by the application boot Lock Bits (Boot Lock Bits 0), see Table 78 on page 209. The application section can never store any Boot Loader code since the SPM instruction is disabled when executed from the application section.
BLS – Boot Loader Section While the application section is used for storing the application code, the The Boot Loader software must be located in the BLS since the SPM instruction can initiate a programming when executing from the BLS only. The SPM instruction can access the entire Flash, including the BLS itself. The protection level for the Boot Loader section can be selected by the Boot Loader Lock Bits (Boot Lock Bits 1), see Table 79 on page 209.
Read-While-Write and No
Read-While-Write Flash
Sections
Whether the CPU supports Read-While-Write or if the CPU is halted during a Boot Loader software update is dependent on which address that is being programmed. In addition to the two sections that are configurable by the BOOTSZ Fuses as described above, the Flash is also divided into two fixed sections, the Read-While-Write (RWW) section and the No Read-While-Write (NRWW) section. The limit between the RWWand NRWW sections is given in Table 83 on page 218 and Figure 102 on page 208. The main difference between the two sections is:
•When erasing or writing a page located inside the RWW section, the NRWW section can be read during the operation.
•When erasing or writing a page located inside the NRWW section, the CPU is halted during the entire operation.
206 ATmega8(L)
2486O–AVR–10/04
ATmega8(L)
Note that the user software can never read any code that is located inside the RWW section during a Boot Loader software operation. The syntax “Read-While-Write section” refers to which section that is being programmed (erased or written), not which section that actually is being read during a Boot Loader software update.
RWW – Read-While-Write If a Boot Loader software update is programming a page inside the RWW section, it is Section possible to read code from the Flash, but only code that is located in the NRWW section. During an on-going programming, the software must ensure that the RWW section never is being read. If the user software is trying to read code that is located inside the RWW section (i.e. by a call/rjmp/lpm or an interrupt) during programming, the software might end up in an unknown state. To avoid this, the interrupts should either be disabled or moved to the Boot Loader Section. The Boot Loader Section is always located in the NRWW section. The RWW Section Busy bit (RWWSB) in the Store Program memory Control Register (SPMCR) will be read as logical one as long as the RWW section is blocked for reading. After a programming is completed, the RWWSB must be cleared by software before reading code located in the RWW section. See “Store Program Memory
Control Register – SPMCR” on page 210. for details on how to clear RWWSB.
NRWW – No Read-While-Write The code located in the NRWW section can be read when the Boot Loader software is Section updating a page in the RWW section. When the Boot Loader code updates the NRWW
section, the CPU is halted during the entire page erase or page write operation.
Table 77. Read-While-Write Features
Which Section does the Z- |
Which Section Can be |
|
Read-While- |
pointer Address during the |
Read during |
Is the CPU |
Write |
Programming? |
Programming? |
Halted? |
Supported? |
|
|
|
|
RWW section |
NRWW section |
No |
Yes |
|
|
|
|
NRWW section |
None |
Yes |
No |
|
|
|
|
Figure 101. Read-While-Write vs. No Read-While-Write
Read-While-Write
(RWW) Section
|
Z-pointer |
|
Addresses NRWW |
Z-pointer |
section |
|
Addresses RWW |
No Read-While-Write |
section |
(NRWW) Section |
|
CPU is Halted |
Code Located in |
during the Operation |
|
NRWW Section |
|
Can be Read during |
|
the Operation |
|
207
2486O–AVR–10/04