Revision 196 trunk/bootloader/bootloader.c
| bootloader.c (revision 196) | ||
|---|---|---|
| 1 | 1 |
#include "bootloader.h" |
| 2 | 2 |
|
| 3 | 3 |
// Setup the default fuses |
| 4 |
/* |
|
| 4 | 5 |
FUSES = {
|
| 5 | 6 |
.low = (FUSE_SUT0 & FUSE_CKSEL3 & FUSE_CKSEL2 & FUSE_CKSEL0), |
| 6 | 7 |
.high = (FUSE_EESAVE & FUSE_SPIEN), |
| 7 | 8 |
.extended = (FUSE_SELFPRGEN), |
| 8 |
}; |
|
| 9 |
};*/ |
|
| 9 | 10 |
|
| 10 | 11 |
|
| 11 | 12 |
|
| ... | ... | |
| 20 | 21 |
/** |
| 21 | 22 |
* Where we store the jump to user code. The jump address is in words |
| 22 | 23 |
* due to how the rjmp instruction works. It is 1 word below the bootloader |
| 24 |
* We declare it as noreturn to save some space since we will never return |
|
| 25 |
* to the bootloader unless we do a system reset |
|
| 23 | 26 |
*/ |
| 24 |
void (*main_start)(void) = BOOT_START/2 - 1; |
|
| 27 |
void (*main_start)(void) __attribute__((noreturn)) = BOOT_START/2 - 1; |
|
| 25 | 28 |
|
| 26 |
/** |
|
| 27 |
* We declare main as naked so that there is no overhead for entering |
|
| 28 |
* and returning from this function since we don't really care about |
|
| 29 |
* what happens to it after we leave it |
|
| 30 |
*/ |
|
| 31 |
int main(void) __attribute__ ((naked)); |
|
| 32 |
|
|
| 33 | 29 |
typedef union {
|
| 34 | 30 |
uint8_t bytes[2]; |
| 35 | 31 |
int16_t sword; |
| 36 | 32 |
} rjump_t; |
| 37 | 33 |
|
| 38 |
/** |
|
| 39 |
* Restore the reset vector to point to the end of ctors. This |
|
| 40 |
* is because we are stripping out the interrupt vector table |
|
| 41 |
* from the bootloader as we don't use it. |
|
| 42 |
*/ |
|
| 43 |
void ResetVector (void) __attribute__((naked)) |
|
| 44 |
__attribute__((section(".reset")));
|
|
| 45 |
void ResetVector(void) {
|
|
| 46 |
asm("rjmp __ctors_end");
|
|
| 47 |
} |
|
| 48 | 34 |
|
| 49 |
|
|
| 50 | 35 |
// SPM_PAGESIZE is set to 32 bytes |
| 51 | 36 |
void onboard_program_write(uint16_t page, uint8_t *buf) {
|
| 52 | 37 |
uint16_t i; |
Also available in: Unified diff