diff options
author | Alexey 'Cluster' Avdyukhin <clusterrr@clusterrr.com> | 2013-09-05 07:56:18 +0400 |
---|---|---|
committer | Alexey 'Cluster' Avdyukhin <clusterrr@clusterrr.com> | 2013-09-05 07:57:03 +0400 |
commit | 06fc50a18b69060e107e51e0f28988ad07cec46f (patch) | |
tree | eedc7b61a29fe718618f809061d9a1f12143839d /Bootloader |
First commit
Diffstat (limited to 'Bootloader')
-rw-r--r-- | Bootloader/Bootloader.aps | 1 | ||||
-rw-r--r-- | Bootloader/avrprog_boot.pnproj | 1 | ||||
-rw-r--r-- | Bootloader/avrprog_boot.pnps | 1 | ||||
-rw-r--r-- | Bootloader/bootloader.aws | 1 | ||||
-rw-r--r-- | Bootloader/chipdef.h | 59 | ||||
-rw-r--r-- | Bootloader/ldscripts_no_vector/avr1.x | 169 | ||||
-rw-r--r-- | Bootloader/ldscripts_no_vector/avr2.x | 169 | ||||
-rw-r--r-- | Bootloader/ldscripts_no_vector/avr3.x | 169 | ||||
-rw-r--r-- | Bootloader/ldscripts_no_vector/avr4.x | 169 | ||||
-rw-r--r-- | Bootloader/ldscripts_no_vector/avr5.x | 172 | ||||
-rw-r--r-- | Bootloader/main | bin | 0 -> 9909 bytes | |||
-rw-r--r-- | Bootloader/main.c | 690 | ||||
-rw-r--r-- | Bootloader/makefile | 671 | ||||
-rw-r--r-- | Bootloader/mega128.h | 39 | ||||
-rw-r--r-- | Bootloader/mega128can.h | 42 | ||||
-rw-r--r-- | Bootloader/mega16.h | 25 | ||||
-rw-r--r-- | Bootloader/mega162.h | 45 | ||||
-rw-r--r-- | Bootloader/mega169.h | 23 | ||||
-rw-r--r-- | Bootloader/mega32.h | 25 | ||||
-rw-r--r-- | Bootloader/mega324p.h | 17 | ||||
-rw-r--r-- | Bootloader/mega64.h | 39 | ||||
-rw-r--r-- | Bootloader/mega644.h | 42 | ||||
-rw-r--r-- | Bootloader/mega644p.h | 17 | ||||
-rw-r--r-- | Bootloader/mega8.h | 25 | ||||
-rw-r--r-- | Bootloader/megaxx4p.h | 47 | ||||
-rw-r--r-- | Bootloader/readme.txt | 267 |
26 files changed, 2925 insertions, 0 deletions
diff --git a/Bootloader/Bootloader.aps b/Bootloader/Bootloader.aps new file mode 100644 index 0000000..2717a37 --- /dev/null +++ b/Bootloader/Bootloader.aps @@ -0,0 +1 @@ +<AVRStudio><MANAGEMENT><ProjectName>Bootloader</ProjectName><Created>28-Aug-2009 01:35:54</Created><LastEdit>29-Aug-2009 21:46:36</LastEdit><ICON>241</ICON><ProjectType>0</ProjectType><Created>28-Aug-2009 01:35:54</Created><Version>4</Version><Build>4, 16, 0, 626</Build><ProjectTypeName>AVR GCC</ProjectTypeName></MANAGEMENT><CODE_CREATION><ObjectFile></ObjectFile><EntryFile></EntryFile><SaveFolder>d:\Coding\AVR\Bootloader\</SaveFolder></CODE_CREATION><DEBUG_TARGET><CURRENT_TARGET>JTAG ICE</CURRENT_TARGET><CURRENT_PART>ATmega16</CURRENT_PART><BREAKPOINTS></BREAKPOINTS><IO_EXPAND><HIDE>false</HIDE></IO_EXPAND><REGISTERNAMES><Register>R00</Register><Register>R01</Register><Register>R02</Register><Register>R03</Register><Register>R04</Register><Register>R05</Register><Register>R06</Register><Register>R07</Register><Register>R08</Register><Register>R09</Register><Register>R10</Register><Register>R11</Register><Register>R12</Register><Register>R13</Register><Register>R14</Register><Register>R15</Register><Register>R16</Register><Register>R17</Register><Register>R18</Register><Register>R19</Register><Register>R20</Register><Register>R21</Register><Register>R22</Register><Register>R23</Register><Register>R24</Register><Register>R25</Register><Register>R26</Register><Register>R27</Register><Register>R28</Register><Register>R29</Register><Register>R30</Register><Register>R31</Register></REGISTERNAMES><COM>Auto</COM><COMType>0</COMType><WATCHNUM>0</WATCHNUM><WATCHNAMES><Pane0></Pane0><Pane1></Pane1><Pane2></Pane2><Pane3></Pane3></WATCHNAMES><BreakOnTrcaeFull>0</BreakOnTrcaeFull></DEBUG_TARGET><Debugger><Triggers></Triggers></Debugger><AVRGCCPLUGIN><FILES><SOURCEFILE>main.c</SOURCEFILE><OTHERFILE>D:\Coding\AVR\Bootloader\makefile</OTHERFILE></FILES><CONFIGS><CONFIG><NAME>default</NAME><USESEXTERNALMAKEFILE>YES</USESEXTERNALMAKEFILE><EXTERNALMAKEFILE>D:\Coding\AVR\Bootloader\makefile</EXTERNALMAKEFILE><PART>atmega16</PART><HEX>1</HEX><LIST>1</LIST><MAP>1</MAP><OUTPUTFILENAME>Bootloader.elf</OUTPUTFILENAME><OUTPUTDIR>default\</OUTPUTDIR><ISDIRTY>1</ISDIRTY><OPTIONS/><INCDIRS/><LIBDIRS/><LIBS/><LINKOBJECTS/><OPTIONSFORALL>-Wall -gdwarf-2 -std=gnu99 -Os -funsigned-char -funsigned-bitfields -fpack-struct -fshort-enums</OPTIONSFORALL><LINKEROPTIONS></LINKEROPTIONS><SEGMENTS/></CONFIG></CONFIGS><LASTCONFIG>default</LASTCONFIG><USES_WINAVR>1</USES_WINAVR><GCC_LOC>C:\WinAVR\bin\avr-gcc.exe</GCC_LOC><MAKE_LOC>C:\WinAVR\utils\bin\make.exe</MAKE_LOC></AVRGCCPLUGIN><ProjectFiles><Files><Name>d:\Coding\AVR\Bootloader\main.c</Name></Files></ProjectFiles><IOView><usergroups/><sort sorted="0" column="0" ordername="1" orderaddress="1" ordergroup="1"/></IOView><Files><File00000><FileId>00000</FileId><FileName>main.c</FileName><Status>1</Status></File00000><File00001><FileId>00001</FileId><FileName>makefile</FileName><Status>1</Status></File00001></Files><Events><Bookmarks></Bookmarks></Events><Trace><Filters></Filters></Trace></AVRStudio> diff --git a/Bootloader/avrprog_boot.pnproj b/Bootloader/avrprog_boot.pnproj new file mode 100644 index 0000000..1777f3c --- /dev/null +++ b/Bootloader/avrprog_boot.pnproj @@ -0,0 +1 @@ +<Project name="avrprog_boot"><File path="chipdef.h"></File><File path="main.c"></File><File path="makefile"></File><File path="mega128.h"></File><File path="mega128can.h"></File><File path="mega16.h"></File><File path="mega169.h"></File><File path="mega32.h"></File><File path="mega8.h"></File><File path="readme.txt"></File><File path="ldscripts_no_vector\avr5.x"></File><File path="main.lss"></File><File path="main.map"></File><File path="ldscripts_no_vector\avr4.x"></File><File path="mega162.h"></File><File path="mega644.h"></File><File path="mega644p.h"></File><File path="megaxx4p.h"></File><File path="mega324p.h"></File></Project>
\ No newline at end of file diff --git a/Bootloader/avrprog_boot.pnps b/Bootloader/avrprog_boot.pnps new file mode 100644 index 0000000..10c6d31 --- /dev/null +++ b/Bootloader/avrprog_boot.pnps @@ -0,0 +1 @@ +<pd><ViewState><e p="avrprog_boot" x="true"></e></ViewState></pd>
\ No newline at end of file diff --git a/Bootloader/bootloader.aws b/Bootloader/bootloader.aws new file mode 100644 index 0000000..ee4c940 --- /dev/null +++ b/Bootloader/bootloader.aws @@ -0,0 +1 @@ +<AVRWorkspace><IOSettings><CurrentRegisters/></IOSettings><part name="ATMEGA16"/><Files><File00000 Name="d:\Coding\AVR\Bootloader\main.c" Position="262 72 979 756" LineCol="76 0" State="Maximized"/><File00001 Name="d:\Coding\AVR\Bootloader\makefile" Position="332 161 839 616" LineCol="440 0" State="Maximized"/></Files></AVRWorkspace> diff --git a/Bootloader/chipdef.h b/Bootloader/chipdef.h new file mode 100644 index 0000000..63f67e7 --- /dev/null +++ b/Bootloader/chipdef.h @@ -0,0 +1,59 @@ +#ifndef CHIPDEF_H +#define CHIPDEF_H + +#include <avr/io.h> + +#if defined (SPMCSR) +#define SPM_REG SPMCSR +#elif defined (SPMCR) +#define SPM_REG SPMCR +#else +#error "AVR processor does not provide bootloader support!" +#endif + +#define APP_END (FLASHEND - (BOOTSIZE * 2)) + +#if (SPM_PAGESIZE > UINT8_MAX) +typedef uint16_t pagebuf_t; +#else +typedef uint8_t pagebuf_t; +#endif + +#if defined(__AVR_ATmega169__) +#include "mega169.h" + +#elif defined(__AVR_ATmega16__) +#include "mega16.h" + +#elif defined(__AVR_ATmega162__) +#include "mega162.h" + +#elif defined(__AVR_ATmega8__) +#include "mega8.h" + +#elif defined(__AVR_ATmega32__) +#include "mega32.h" + +#elif defined(__AVR_ATmega324P__) +#include "mega324p.h" + +#elif defined(__AVR_ATmega64__) +#include "mega64.h" + +#elif defined(__AVR_ATmega644__) +#include "mega644.h" + +#elif defined(__AVR_ATmega644P__) +#include "mega644p.h" + +#elif defined(__AVR_ATmega128__) +#include "mega128.h" + +#elif defined(__AVR_AT90CAN128__) +#include "mega128can.h" + +#else +#error "no definition for MCU available in chipdef.h" +#endif + +#endif diff --git a/Bootloader/ldscripts_no_vector/avr1.x b/Bootloader/ldscripts_no_vector/avr1.x new file mode 100644 index 0000000..77ff9c7 --- /dev/null +++ b/Bootloader/ldscripts_no_vector/avr1.x @@ -0,0 +1,169 @@ +/* Default linker script, for normal executables */ +OUTPUT_FORMAT("elf32-avr","elf32-avr","elf32-avr") +OUTPUT_ARCH(avr:1) +MEMORY +{ + text (rx) : ORIGIN = 0, LENGTH = 8K + data (rw!x) : ORIGIN = 0x800060, LENGTH = 0 + eeprom (rw!x) : ORIGIN = 0x810000, LENGTH = 64K +} +SECTIONS +{ + /* Read-only sections, merged into text segment: */ + .hash : { *(.hash) } + .dynsym : { *(.dynsym) } + .dynstr : { *(.dynstr) } + .gnu.version : { *(.gnu.version) } + .gnu.version_d : { *(.gnu.version_d) } + .gnu.version_r : { *(.gnu.version_r) } + .rel.init : { *(.rel.init) } + .rela.init : { *(.rela.init) } + .rel.text : + { + *(.rel.text) + *(.rel.text.*) + *(.rel.gnu.linkonce.t*) + } + .rela.text : + { + *(.rela.text) + *(.rela.text.*) + *(.rela.gnu.linkonce.t*) + } + .rel.fini : { *(.rel.fini) } + .rela.fini : { *(.rela.fini) } + .rel.rodata : + { + *(.rel.rodata) + *(.rel.rodata.*) + *(.rel.gnu.linkonce.r*) + } + .rela.rodata : + { + *(.rela.rodata) + *(.rela.rodata.*) + *(.rela.gnu.linkonce.r*) + } + .rel.data : + { + *(.rel.data) + *(.rel.data.*) + *(.rel.gnu.linkonce.d*) + } + .rela.data : + { + *(.rela.data) + *(.rela.data.*) + *(.rela.gnu.linkonce.d*) + } + .rel.ctors : { *(.rel.ctors) } + .rela.ctors : { *(.rela.ctors) } + .rel.dtors : { *(.rel.dtors) } + .rela.dtors : { *(.rela.dtors) } + .rel.got : { *(.rel.got) } + .rela.got : { *(.rela.got) } + .rel.bss : { *(.rel.bss) } + .rela.bss : { *(.rela.bss) } + .rel.plt : { *(.rel.plt) } + .rela.plt : { *(.rela.plt) } + /* Internal text space or external memory */ +/DISCARD/ : { *(.vectors); } + .text : + { +/* *(.vectors) */ + __ctors_start = . ; + *(.ctors) + __ctors_end = . ; + __dtors_start = . ; + *(.dtors) + __dtors_end = . ; + *(.progmem.gcc*) + *(.progmem*) + . = ALIGN(2); + *(.init0) /* Start here after reset. */ + *(.init1) + *(.init2) /* Clear __zero_reg__, set up stack pointer. */ + *(.init3) + *(.init4) /* Initialize data and BSS. */ + *(.init5) + *(.init6) /* C++ constructors. */ + *(.init7) + *(.init8) + *(.init9) /* Call main(). */ + *(.text) + . = ALIGN(2); + *(.text.*) + . = ALIGN(2); + *(.fini9) /* _exit() starts here. */ + *(.fini8) + *(.fini7) + *(.fini6) /* C++ destructors. */ + *(.fini5) + *(.fini4) + *(.fini3) + *(.fini2) + *(.fini1) + *(.fini0) /* Infinite loop after program termination. */ + _etext = . ; + } > text + .data : AT (ADDR (.text) + SIZEOF (.text)) + { + PROVIDE (__data_start = .) ; + *(.data) + *(.gnu.linkonce.d*) + . = ALIGN(2); + _edata = . ; + PROVIDE (__data_end = .) ; + } > data + .bss SIZEOF(.data) + ADDR(.data) : + { + PROVIDE (__bss_start = .) ; + *(.bss) + *(COMMON) + PROVIDE (__bss_end = .) ; + } > data + __data_load_start = LOADADDR(.data); + __data_load_end = __data_load_start + SIZEOF(.data); + /* Global data not cleared after reset. */ + .noinit SIZEOF(.bss) + ADDR(.bss) : + { + PROVIDE (__noinit_start = .) ; + *(.noinit*) + PROVIDE (__noinit_end = .) ; + _end = . ; + PROVIDE (__heap_start = .) ; + } > data + .eeprom : + { + *(.eeprom*) + __eeprom_end = . ; + } > eeprom + /* Stabs debugging sections. */ + .stab 0 : { *(.stab) } + .stabstr 0 : { *(.stabstr) } + .stab.excl 0 : { *(.stab.excl) } + .stab.exclstr 0 : { *(.stab.exclstr) } + .stab.index 0 : { *(.stab.index) } + .stab.indexstr 0 : { *(.stab.indexstr) } + .comment 0 : { *(.comment) } + /* DWARF debug sections. + Symbols in the DWARF debugging sections are relative to the beginning + of the section so we begin them at 0. */ + /* DWARF 1 */ + .debug 0 : { *(.debug) } + .line 0 : { *(.line) } + /* GNU DWARF 1 extensions */ + .debug_srcinfo 0 : { *(.debug_srcinfo) } + .debug_sfnames 0 : { *(.debug_sfnames) } + /* DWARF 1.1 and DWARF 2 */ + .debug_aranges 0 : { *(.debug_aranges) } + .debug_pubnames 0 : { *(.debug_pubnames) } + /* DWARF 2 */ + .debug_info 0 : { *(.debug_info) *(.gnu.linkonce.wi.*) } + .debug_abbrev 0 : { *(.debug_abbrev) } + .debug_line 0 : { *(.debug_line) } + .debug_frame 0 : { *(.debug_frame) } + .debug_str 0 : { *(.debug_str) } + .debug_loc 0 : { *(.debug_loc) } + .debug_macinfo 0 : { *(.debug_macinfo) } +} diff --git a/Bootloader/ldscripts_no_vector/avr2.x b/Bootloader/ldscripts_no_vector/avr2.x new file mode 100644 index 0000000..86a9ed6 --- /dev/null +++ b/Bootloader/ldscripts_no_vector/avr2.x @@ -0,0 +1,169 @@ +/* Default linker script, for normal executables */ +OUTPUT_FORMAT("elf32-avr","elf32-avr","elf32-avr") +OUTPUT_ARCH(avr:2) +MEMORY +{ + text (rx) : ORIGIN = 0, LENGTH = 8K + data (rw!x) : ORIGIN = 0x800060, LENGTH = 0xffa0 + eeprom (rw!x) : ORIGIN = 0x810000, LENGTH = 64K +} +SECTIONS +{ + /* Read-only sections, merged into text segment: */ + .hash : { *(.hash) } + .dynsym : { *(.dynsym) } + .dynstr : { *(.dynstr) } + .gnu.version : { *(.gnu.version) } + .gnu.version_d : { *(.gnu.version_d) } + .gnu.version_r : { *(.gnu.version_r) } + .rel.init : { *(.rel.init) } + .rela.init : { *(.rela.init) } + .rel.text : + { + *(.rel.text) + *(.rel.text.*) + *(.rel.gnu.linkonce.t*) + } + .rela.text : + { + *(.rela.text) + *(.rela.text.*) + *(.rela.gnu.linkonce.t*) + } + .rel.fini : { *(.rel.fini) } + .rela.fini : { *(.rela.fini) } + .rel.rodata : + { + *(.rel.rodata) + *(.rel.rodata.*) + *(.rel.gnu.linkonce.r*) + } + .rela.rodata : + { + *(.rela.rodata) + *(.rela.rodata.*) + *(.rela.gnu.linkonce.r*) + } + .rel.data : + { + *(.rel.data) + *(.rel.data.*) + *(.rel.gnu.linkonce.d*) + } + .rela.data : + { + *(.rela.data) + *(.rela.data.*) + *(.rela.gnu.linkonce.d*) + } + .rel.ctors : { *(.rel.ctors) } + .rela.ctors : { *(.rela.ctors) } + .rel.dtors : { *(.rel.dtors) } + .rela.dtors : { *(.rela.dtors) } + .rel.got : { *(.rel.got) } + .rela.got : { *(.rela.got) } + .rel.bss : { *(.rel.bss) } + .rela.bss : { *(.rela.bss) } + .rel.plt : { *(.rel.plt) } + .rela.plt : { *(.rela.plt) } + /* Internal text space or external memory */ +/DISCARD/ : { *(.vectors); } + .text : + { +/* *(.vectors) */ + __ctors_start = . ; + *(.ctors) + __ctors_end = . ; + __dtors_start = . ; + *(.dtors) + __dtors_end = . ; + *(.progmem.gcc*) + *(.progmem*) + . = ALIGN(2); + *(.init0) /* Start here after reset. */ + *(.init1) + *(.init2) /* Clear __zero_reg__, set up stack pointer. */ + *(.init3) + *(.init4) /* Initialize data and BSS. */ + *(.init5) + *(.init6) /* C++ constructors. */ + *(.init7) + *(.init8) + *(.init9) /* Call main(). */ + *(.text) + . = ALIGN(2); + *(.text.*) + . = ALIGN(2); + *(.fini9) /* _exit() starts here. */ + *(.fini8) + *(.fini7) + *(.fini6) /* C++ destructors. */ + *(.fini5) + *(.fini4) + *(.fini3) + *(.fini2) + *(.fini1) + *(.fini0) /* Infinite loop after program termination. */ + _etext = . ; + } > text + .data : AT (ADDR (.text) + SIZEOF (.text)) + { + PROVIDE (__data_start = .) ; + *(.data) + *(.gnu.linkonce.d*) + . = ALIGN(2); + _edata = . ; + PROVIDE (__data_end = .) ; + } > data + .bss SIZEOF(.data) + ADDR(.data) : + { + PROVIDE (__bss_start = .) ; + *(.bss) + *(COMMON) + PROVIDE (__bss_end = .) ; + } > data + __data_load_start = LOADADDR(.data); + __data_load_end = __data_load_start + SIZEOF(.data); + /* Global data not cleared after reset. */ + .noinit SIZEOF(.bss) + ADDR(.bss) : + { + PROVIDE (__noinit_start = .) ; + *(.noinit*) + PROVIDE (__noinit_end = .) ; + _end = . ; + PROVIDE (__heap_start = .) ; + } > data + .eeprom : + { + *(.eeprom*) + __eeprom_end = . ; + } > eeprom + /* Stabs debugging sections. */ + .stab 0 : { *(.stab) } + .stabstr 0 : { *(.stabstr) } + .stab.excl 0 : { *(.stab.excl) } + .stab.exclstr 0 : { *(.stab.exclstr) } + .stab.index 0 : { *(.stab.index) } + .stab.indexstr 0 : { *(.stab.indexstr) } + .comment 0 : { *(.comment) } + /* DWARF debug sections. + Symbols in the DWARF debugging sections are relative to the beginning + of the section so we begin them at 0. */ + /* DWARF 1 */ + .debug 0 : { *(.debug) } + .line 0 : { *(.line) } + /* GNU DWARF 1 extensions */ + .debug_srcinfo 0 : { *(.debug_srcinfo) } + .debug_sfnames 0 : { *(.debug_sfnames) } + /* DWARF 1.1 and DWARF 2 */ + .debug_aranges 0 : { *(.debug_aranges) } + .debug_pubnames 0 : { *(.debug_pubnames) } + /* DWARF 2 */ + .debug_info 0 : { *(.debug_info) *(.gnu.linkonce.wi.*) } + .debug_abbrev 0 : { *(.debug_abbrev) } + .debug_line 0 : { *(.debug_line) } + .debug_frame 0 : { *(.debug_frame) } + .debug_str 0 : { *(.debug_str) } + .debug_loc 0 : { *(.debug_loc) } + .debug_macinfo 0 : { *(.debug_macinfo) } +} diff --git a/Bootloader/ldscripts_no_vector/avr3.x b/Bootloader/ldscripts_no_vector/avr3.x new file mode 100644 index 0000000..12d34ae --- /dev/null +++ b/Bootloader/ldscripts_no_vector/avr3.x @@ -0,0 +1,169 @@ +/* Default linker script, for normal executables */ +OUTPUT_FORMAT("elf32-avr","elf32-avr","elf32-avr") +OUTPUT_ARCH(avr:3) +MEMORY +{ + text (rx) : ORIGIN = 0, LENGTH = 128K + data (rw!x) : ORIGIN = 0x800060, LENGTH = 0xffa0 + eeprom (rw!x) : ORIGIN = 0x810000, LENGTH = 64K +} +SECTIONS +{ + /* Read-only sections, merged into text segment: */ + .hash : { *(.hash) } + .dynsym : { *(.dynsym) } + .dynstr : { *(.dynstr) } + .gnu.version : { *(.gnu.version) } + .gnu.version_d : { *(.gnu.version_d) } + .gnu.version_r : { *(.gnu.version_r) } + .rel.init : { *(.rel.init) } + .rela.init : { *(.rela.init) } + .rel.text : + { + *(.rel.text) + *(.rel.text.*) + *(.rel.gnu.linkonce.t*) + } + .rela.text : + { + *(.rela.text) + *(.rela.text.*) + *(.rela.gnu.linkonce.t*) + } + .rel.fini : { *(.rel.fini) } + .rela.fini : { *(.rela.fini) } + .rel.rodata : + { + *(.rel.rodata) + *(.rel.rodata.*) + *(.rel.gnu.linkonce.r*) + } + .rela.rodata : + { + *(.rela.rodata) + *(.rela.rodata.*) + *(.rela.gnu.linkonce.r*) + } + .rel.data : + { + *(.rel.data) + *(.rel.data.*) + *(.rel.gnu.linkonce.d*) + } + .rela.data : + { + *(.rela.data) + *(.rela.data.*) + *(.rela.gnu.linkonce.d*) + } + .rel.ctors : { *(.rel.ctors) } + .rela.ctors : { *(.rela.ctors) } + .rel.dtors : { *(.rel.dtors) } + .rela.dtors : { *(.rela.dtors) } + .rel.got : { *(.rel.got) } + .rela.got : { *(.rela.got) } + .rel.bss : { *(.rel.bss) } + .rela.bss : { *(.rela.bss) } + .rel.plt : { *(.rel.plt) } + .rela.plt : { *(.rela.plt) } + /* Internal text space or external memory */ +/DISCARD/ : { *(.vectors); } + .text : + { +/* *(.vectors) */ + __ctors_start = . ; + *(.ctors) + __ctors_end = . ; + __dtors_start = . ; + *(.dtors) + __dtors_end = . ; + *(.progmem.gcc*) + *(.progmem*) + . = ALIGN(2); + *(.init0) /* Start here after reset. */ + *(.init1) + *(.init2) /* Clear __zero_reg__, set up stack pointer. */ + *(.init3) + *(.init4) /* Initialize data and BSS. */ + *(.init5) + *(.init6) /* C++ constructors. */ + *(.init7) + *(.init8) + *(.init9) /* Call main(). */ + *(.text) + . = ALIGN(2); + *(.text.*) + . = ALIGN(2); + *(.fini9) /* _exit() starts here. */ + *(.fini8) + *(.fini7) + *(.fini6) /* C++ destructors. */ + *(.fini5) + *(.fini4) + *(.fini3) + *(.fini2) + *(.fini1) + *(.fini0) /* Infinite loop after program termination. */ + _etext = . ; + } > text + .data : AT (ADDR (.text) + SIZEOF (.text)) + { + PROVIDE (__data_start = .) ; + *(.data) + *(.gnu.linkonce.d*) + . = ALIGN(2); + _edata = . ; + PROVIDE (__data_end = .) ; + } > data + .bss SIZEOF(.data) + ADDR(.data) : + { + PROVIDE (__bss_start = .) ; + *(.bss) + *(COMMON) + PROVIDE (__bss_end = .) ; + } > data + __data_load_start = LOADADDR(.data); + __data_load_end = __data_load_start + SIZEOF(.data); + /* Global data not cleared after reset. */ + .noinit SIZEOF(.bss) + ADDR(.bss) : + { + PROVIDE (__noinit_start = .) ; + *(.noinit*) + PROVIDE (__noinit_end = .) ; + _end = . ; + PROVIDE (__heap_start = .) ; + } > data + .eeprom : + { + *(.eeprom*) + __eeprom_end = . ; + } > eeprom + /* Stabs debugging sections. */ + .stab 0 : { *(.stab) } + .stabstr 0 : { *(.stabstr) } + .stab.excl 0 : { *(.stab.excl) } + .stab.exclstr 0 : { *(.stab.exclstr) } + .stab.index 0 : { *(.stab.index) } + .stab.indexstr 0 : { *(.stab.indexstr) } + .comment 0 : { *(.comment) } + /* DWARF debug sections. + Symbols in the DWARF debugging sections are relative to the beginning + of the section so we begin them at 0. */ + /* DWARF 1 */ + .debug 0 : { *(.debug) } + .line 0 : { *(.line) } + /* GNU DWARF 1 extensions */ + .debug_srcinfo 0 : { *(.debug_srcinfo) } + .debug_sfnames 0 : { *(.debug_sfnames) } + /* DWARF 1.1 and DWARF 2 */ + .debug_aranges 0 : { *(.debug_aranges) } + .debug_pubnames 0 : { *(.debug_pubnames) } + /* DWARF 2 */ + .debug_info 0 : { *(.debug_info) *(.gnu.linkonce.wi.*) } + .debug_abbrev 0 : { *(.debug_abbrev) } + .debug_line 0 : { *(.debug_line) } + .debug_frame 0 : { *(.debug_frame) } + .debug_str 0 : { *(.debug_str) } + .debug_loc 0 : { *(.debug_loc) } + .debug_macinfo 0 : { *(.debug_macinfo) } +} diff --git a/Bootloader/ldscripts_no_vector/avr4.x b/Bootloader/ldscripts_no_vector/avr4.x new file mode 100644 index 0000000..6b371f4 --- /dev/null +++ b/Bootloader/ldscripts_no_vector/avr4.x @@ -0,0 +1,169 @@ +/* MODIFIED LINKER SCRIPT - BOOTLOADER: without .vectors */ +OUTPUT_FORMAT("elf32-avr","elf32-avr","elf32-avr") +OUTPUT_ARCH(avr:4) +MEMORY +{ + text (rx) : ORIGIN = 0, LENGTH = 8K + data (rw!x) : ORIGIN = 0x800060, LENGTH = 0xffa0 + eeprom (rw!x) : ORIGIN = 0x810000, LENGTH = 64K +} +SECTIONS +{ + /* Read-only sections, merged into text segment: */ + .hash : { *(.hash) } + .dynsym : { *(.dynsym) } + .dynstr : { *(.dynstr) } + .gnu.version : { *(.gnu.version) } + .gnu.version_d : { *(.gnu.version_d) } + .gnu.version_r : { *(.gnu.version_r) } + .rel.init : { *(.rel.init) } + .rela.init : { *(.rela.init) } + .rel.text : + { + *(.rel.text) + *(.rel.text.*) + *(.rel.gnu.linkonce.t*) + } + .rela.text : + { + *(.rela.text) + *(.rela.text.*) + *(.rela.gnu.linkonce.t*) + } + .rel.fini : { *(.rel.fini) } + .rela.fini : { *(.rela.fini) } + .rel.rodata : + { + *(.rel.rodata) + *(.rel.rodata.*) + *(.rel.gnu.linkonce.r*) + } + .rela.rodata : + { + *(.rela.rodata) + *(.rela.rodata.*) + *(.rela.gnu.linkonce.r*) + } + .rel.data : + { + *(.rel.data) + *(.rel.data.*) + *(.rel.gnu.linkonce.d*) + } + .rela.data : + { + *(.rela.data) + *(.rela.data.*) + *(.rela.gnu.linkonce.d*) + } + .rel.ctors : { *(.rel.ctors) } + .rela.ctors : { *(.rela.ctors) } + .rel.dtors : { *(.rel.dtors) } + .rela.dtors : { *(.rela.dtors) } + .rel.got : { *(.rel.got) } + .rela.got : { *(.rela.got) } + .rel.bss : { *(.rel.bss) } + .rela.bss : { *(.rela.bss) } + .rel.plt : { *(.rel.plt) } + .rela.plt : { *(.rela.plt) } + /* Internal text space or external memory */ +/DISCARD/ : { *(.vectors); } + .text : + { +/* *(.vectors) */ + __ctors_start = . ; + *(.ctors) + __ctors_end = . ; + __dtors_start = . ; + *(.dtors) + __dtors_end = . ; + *(.progmem.gcc*) + *(.progmem*) + . = ALIGN(2); + *(.init0) /* Start here after reset. */ + *(.init1) + *(.init2) /* Clear __zero_reg__, set up stack pointer. */ + *(.init3) + *(.init4) /* Initialize data and BSS. */ + *(.init5) + *(.init6) /* C++ constructors. */ + *(.init7) + *(.init8) + *(.init9) /* Call main(). */ + *(.text) + . = ALIGN(2); + *(.text.*) + . = ALIGN(2); + *(.fini9) /* _exit() starts here. */ + *(.fini8) + *(.fini7) + *(.fini6) /* C++ destructors. */ + *(.fini5) + *(.fini4) + *(.fini3) + *(.fini2) + *(.fini1) + *(.fini0) /* Infinite loop after program termination. */ + _etext = . ; + } > text + .data : AT (ADDR (.text) + SIZEOF (.text)) + { + PROVIDE (__data_start = .) ; + *(.data) + *(.gnu.linkonce.d*) + . = ALIGN(2); + _edata = . ; + PROVIDE (__data_end = .) ; + } > data + .bss SIZEOF(.data) + ADDR(.data) : + { + PROVIDE (__bss_start = .) ; + *(.bss) + *(COMMON) + PROVIDE (__bss_end = .) ; + } > data + __data_load_start = LOADADDR(.data); + __data_load_end = __data_load_start + SIZEOF(.data); + /* Global data not cleared after reset. */ + .noinit SIZEOF(.bss) + ADDR(.bss) : + { + PROVIDE (__noinit_start = .) ; + *(.noinit*) + PROVIDE (__noinit_end = .) ; + _end = . ; + PROVIDE (__heap_start = .) ; + } > data + .eeprom : + { + *(.eeprom*) + __eeprom_end = . ; + } > eeprom + /* Stabs debugging sections. */ + .stab 0 : { *(.stab) } + .stabstr 0 : { *(.stabstr) } + .stab.excl 0 : { *(.stab.excl) } + .stab.exclstr 0 : { *(.stab.exclstr) } + .stab.index 0 : { *(.stab.index) } + .stab.indexstr 0 : { *(.stab.indexstr) } + .comment 0 : { *(.comment) } + /* DWARF debug sections. + Symbols in the DWARF debugging sections are relative to the beginning + of the section so we begin them at 0. */ + /* DWARF 1 */ + .debug 0 : { *(.debug) } + .line 0 : { *(.line) } + /* GNU DWARF 1 extensions */ + .debug_srcinfo 0 : { *(.debug_srcinfo) } + .debug_sfnames 0 : { *(.debug_sfnames) } + /* DWARF 1.1 and DWARF 2 */ + .debug_aranges 0 : { *(.debug_aranges) } + .debug_pubnames 0 : { *(.debug_pubnames) } + /* DWARF 2 */ + .debug_info 0 : { *(.debug_info) *(.gnu.linkonce.wi.*) } + .debug_abbrev 0 : { *(.debug_abbrev) } + .debug_line 0 : { *(.debug_line) } + .debug_frame 0 : { *(.debug_frame) } + .debug_str 0 : { *(.debug_str) } + .debug_loc 0 : { *(.debug_loc) } + .debug_macinfo 0 : { *(.debug_macinfo) } +} diff --git a/Bootloader/ldscripts_no_vector/avr5.x b/Bootloader/ldscripts_no_vector/avr5.x new file mode 100644 index 0000000..a1a1fa2 --- /dev/null +++ b/Bootloader/ldscripts_no_vector/avr5.x @@ -0,0 +1,172 @@ +/* MODIFIED LINKER SCRIPT - BOOTLOADER: without .vectors */ +OUTPUT_FORMAT("elf32-avr","elf32-avr","elf32-avr") +OUTPUT_ARCH(avr:5) +MEMORY +{ + text (rx) : ORIGIN = 0, LENGTH = 128K + data (rw!x) : ORIGIN = 0x800060, LENGTH = 0xffa0 + eeprom (rw!x) : ORIGIN = 0x810000, LENGTH = 64K +} +SECTIONS +{ + /* Read-only sections, merged into text segment: */ + .hash : { *(.hash) } + .dynsym : { *(.dynsym) } + .dynstr : { *(.dynstr) } + .gnu.version : { *(.gnu.version) } + .gnu.version_d : { *(.gnu.version_d) } + .gnu.version_r : { *(.gnu.version_r) } + .rel.init : { *(.rel.init) } + .rela.init : { *(.rela.init) } + .rel.text : + { + *(.rel.text) + *(.rel.text.*) + *(.rel.gnu.linkonce.t*) + } + .rela.text : + { + *(.rela.text) + *(.rela.text.*) + *(.rela.gnu.linkonce.t*) + } + .rel.fini : { *(.rel.fini) } + .rela.fini : { *(.rela.fini) } + .rel.rodata : + { + *(.rel.rodata) + *(.rel.rodata.*) + *(.rel.gnu.linkonce.r*) + } + .rela.rodata : + { + *(.rela.rodata) + *(.rela.rodata.*) + *(.rela.gnu.linkonce.r*) + } + .rel.data : + { + *(.rel.data) + *(.rel.data.*) + *(.rel.gnu.linkonce.d*) + } + .rela.data : + { + *(.rela.data) + *(.rela.data.*) + *(.rela.gnu.linkonce.d*) + } + .rel.ctors : { *(.rel.ctors) } + .rela.ctors : { *(.rela.ctors) } + .rel.dtors : { *(.rel.dtors) } + .rela.dtors : { *(.rela.dtors) } + .rel.got : { *(.rel.got) } + .rela.got : { *(.rela.got) } + .rel.bss : { *(.rel.bss) } + .rela.bss : { *(.rela.bss) } + .rel.plt : { *(.rel.plt) } + .rela.plt : { *(.rela.plt) } + + /* Internal text space or external memory */ + +/* BOOTLOADER-MODIFICATION - not interrupt-vectors */ + /DISCARD/ : { *(.vectors) } + .text : + { +/* *(.vectors) */ /* BOOTLOADER-MODIFICATION ! */ + __ctors_start = . ; + *(.ctors) + __ctors_end = . ; + __dtors_start = . ; + *(.dtors) + __dtors_end = . ; + *(.progmem.gcc*) + *(.progmem*) + . = ALIGN(2); + *(.init0) /* Start here after reset. */ + *(.init1) + *(.init2) /* Clear __zero_reg__, set up stack pointer. */ + *(.init3) + *(.init4) /* Initialize data and BSS. */ + *(.init5) + *(.init6) /* C++ constructors. */ + *(.init7) + *(.init8) + *(.init9) /* Call main(). */ + *(.text) + . = ALIGN(2); + *(.text.*) + . = ALIGN(2); + *(.fini9) /* _exit() starts here. */ + *(.fini8) + *(.fini7) + *(.fini6) /* C++ destructors. */ + *(.fini5) + *(.fini4) + *(.fini3) + *(.fini2) + *(.fini1) + *(.fini0) /* Infinite loop after program termination. */ + _etext = . ; + } > text + .data : AT (ADDR (.text) + SIZEOF (.text)) + { + PROVIDE (__data_start = .) ; + *(.data) + *(.gnu.linkonce.d*) + . = ALIGN(2); + _edata = . ; + PROVIDE (__data_end = .) ; + } > data + .bss SIZEOF(.data) + ADDR(.data) : + { + PROVIDE (__bss_start = .) ; + *(.bss) + *(COMMON) + PROVIDE (__bss_end = .) ; + } > data + __data_load_start = LOADADDR(.data); + __data_load_end = __data_load_start + SIZEOF(.data); + /* Global data not cleared after reset. */ + .noinit SIZEOF(.bss) + ADDR(.bss) : + { + PROVIDE (__noinit_start = .) ; + *(.noinit*) + PROVIDE (__noinit_end = .) ; + _end = . ; + PROVIDE (__heap_start = .) ; + } > data + .eeprom : + { + *(.eeprom*) + __eeprom_end = . ; + } > eeprom + /* Stabs debugging sections. */ + .stab 0 : { *(.stab) } + .stabstr 0 : { *(.stabstr) } + .stab.excl 0 : { *(.stab.excl) } + .stab.exclstr 0 : { *(.stab.exclstr) } + .stab.index 0 : { *(.stab.index) } + .stab.indexstr 0 : { *(.stab.indexstr) } + .comment 0 : { *(.comment) } + /* DWARF debug sections. + Symbols in the DWARF debugging sections are relative to the beginning + of the section so we begin them at 0. */ + /* DWARF 1 */ + .debug 0 : { *(.debug) } + .line 0 : { *(.line) } + /* GNU DWARF 1 extensions */ + .debug_srcinfo 0 : { *(.debug_srcinfo) } + .debug_sfnames 0 : { *(.debug_sfnames) } + /* DWARF 1.1 and DWARF 2 */ + .debug_aranges 0 : { *(.debug_aranges) } + .debug_pubnames 0 : { *(.debug_pubnames) } + /* DWARF 2 */ + .debug_info 0 : { *(.debug_info) *(.gnu.linkonce.wi.*) } + .debug_abbrev 0 : { *(.debug_abbrev) } + .debug_line 0 : { *(.debug_line) } + .debug_frame 0 : { *(.debug_frame) } + .debug_str 0 : { *(.debug_str) } + .debug_loc 0 : { *(.debug_loc) } + .debug_macinfo 0 : { *(.debug_macinfo) } +} diff --git a/Bootloader/main b/Bootloader/main Binary files differnew file mode 100644 index 0000000..c4b93b7 --- /dev/null +++ b/Bootloader/main diff --git a/Bootloader/main.c b/Bootloader/main.c new file mode 100644 index 0000000..87ac22d --- /dev/null +++ b/Bootloader/main.c @@ -0,0 +1,690 @@ +/***************************************************************************** +* +* AVRPROG compatible boot-loader +* Version : 0.85 (Dec. 2008) +* Compiler : avr-gcc 4.1.2 / avr-libc 1.4.6 +* size : depends on features and startup ( minmal features < 512 words) +* by : Martin Thomas, Kaiserslautern, Germany +* eversmith@heizung-thomas.de +* Additional code and improvements contributed by: +* - Uwe Bonnes +* - Bjoern Riemer +* - Olaf Rempel +* +* License : Copyright (c) 2006-2008 M. Thomas, U. Bonnes, O. Rempel +* Free to use. You have to mention the copyright +* owners in source-code and documentation of derived +* work. No warranty! (Yes, you can insert the BSD +* license here) +* +* Tested with ATmega8, ATmega16, ATmega162, ATmega32, ATmega324P, +* ATmega644, ATmega644P, ATmega128, AT90CAN128 +* +* - Initial versions have been based on the Butterfly bootloader-code +* by Atmel Corporation (Authors: BBrandal, PKastnes, ARodland, LHM) +* +**************************************************************************** +* +* See the makefile and readme.txt for information on how to adapt +* the linker-settings to the selected Boot Size (BOOTSIZE=xxxx) and +* the MCU-type. Other configurations futher down in this file. +* +* With BOOT_SIMPLE, minimal features and discarded int-vectors +* this bootloader has should fit into a a 512 word (1024, 0x400 bytes) +* bootloader-section. +* +****************************************************************************/ + +/* ×ŕńňîňŕ ęîíňđîëëĺđŕ (ęâŕđöŕ) */ +#ifndef F_CPU +// #define F_CPU 7372800 +//#define F_CPU (7372800/2) +//#define F_CPU 11059200UL +#define F_CPU 8000000UL +#endif + +/* UART Ńęîđîńňü UART îďňčěŕëüíî 19200 */ +#define BAUDRATE 19200 +//#define BAUDRATE 19200 +//#define BAUDRATE 115200 + +/* Đĺćčě äâîéíîé ńęîđîńňč UART (áčň U2C)*/ +//#define UART_DOUBLESPEED + +/* Čńďîëüçóĺňń˙ âňîđîé UART íŕ mega128 / can128 / mega162 / mega324p / mega644p */ +//#define UART_USE_SECOND + +/* Ňčď óńňđîéńňâŕ: + Äë˙ AVRProg âűáčđŕňü BOOT + Ýňî ęîđđĺęňíîĺ çíŕ÷ĺíčĺ äë˙ bootloader. + avrdude ěîćĺň îďđĺäĺëčňü ňîëüęî part-code äë˙ ISP */ +#define DEVTYPE DEVTYPE_BOOT +//#define DEVTYPE DEVTYPE_ISP + +/* + * Âűáîđ ďîđňŕ äë˙ ęíîďęč âőîäŕ â çŕăđóç÷čę + * ×ňîáű âîéňč â çŕăđóç÷čę íŕäî ÷ňîáű ďđč çŕďóńęĺ ýňŕ ęíîďęŕ çŕěűęŕëŕ ďčí íŕ çĺěëţ + */ +#define BLPORT PORTD +#define BLDDR DDRD +#define BLPIN PIND +#define BLPNUM PIND3 + +/* + * Âűáîđ ďîđňŕ äë˙ číäčęŕňîđŕ đŕáîňű çŕăđóç÷čęŕ + * Ńâĺňîäčîä ăîđčň - ěű â çŕăđóç÷čęĺ + */ + +#define ENABLE_BOOT_LED +#define BIPORT PORTB +#define BIDDR DDRB +#define BIPIN PINB +#define BIPNUM PINB4 + + +/* + * Âűęëţ÷čňü Ńîáŕ÷čé ňŕéěĺđ íŕ âđĺě˙ çŕăđóç÷čęŕ + */ +#define DISABLE_WDT_AT_STARTUP + +/* + * Watchdog-reset is issued at exit + * define the timeout-value here (see avr-libc manual) + */ +#define EXIT_WDT_TIME WDTO_250MS + +/* + * Âűáîđ đĺćčěŕ çŕăđóç÷čęŕ + * SIMPLE-Mode - Çŕăđóç÷čę ńňŕđňóĺň ęîăäŕ íŕćŕňŕ ĺăî ęíîďęŕ + * ďĺđĺőîä ę îńíîâíîé ďđîăđŕěěĺ îńóůĺńňâë˙ĺňń˙ ďîńëĺ ńáđîńŕ + * (ęíîďęŕ äîëćíŕ áűňü îňćŕňŕ) ëčáî ďî ęîěŕíäĺ îň ďđîăđŕěěŕňîđŕ + * Ďđč ýňîě đĺćčěĺ âűâîä íŕ ęíîďęó ęîíôčăóđčđóĺňń˙ ęŕę âőîä-ń ďîäň˙ăîě, + * íî ďđč âűőîäĺ čç çŕăđóç÷čęŕ âńĺ âűńňŕâë˙ĺňń˙ ďî óěîë÷ŕíčţ + * POWERSAVE-Mode - Startup is separated in two loops + * which makes power-saving a little easier if no firmware + * is on the chip. Needs more memory + * BOOTICE-Mode - äë˙ çŕřčâęč JTAGICE ôŕéëŕ upgrade.ebn â Ěĺăó16. + * ÷ňî ďđĺâđŕůŕĺň ĺĺ â JTAG îňëŕä÷čę. Đŕçóěĺĺňń˙ íóćíî äîáŕâčňü âĺńü íĺîáőîäčěűé + * îáâ˙ç íŕ ęđčńňŕëë äë˙ ýňîăî. Č ÷ŕńňîňŕ äîëćíŕ áűňü âĺçäĺ ďđîďčńŕíŕ ęŕę 7372800 + * â F_CPU Äë˙ ńîâěĺńňčěîńňč ń đîäíîé ďđîřčâęîé JTAG ICE + * WAIT-mode Bootloader îćčäŕĺň ęîěŕíäű íŕ âőîä, ĺńëč ĺĺ íĺ áűëî â ňĺ÷ĺíčč ďđîěĺćóňęŕ âđĺěĺíč + * (ęîňîđűé íŕńňđŕčâŕĺňń˙) ňî ďđîčőńîäčň ďĺđĺőîä ę îńíîâíîé ďđîăđŕěěĺ. + */ +#define START_SIMPLE +//#define START_WAIT +//#define START_POWERSAVE +//#define START_BOOTICE + +/* Ęîěŕíäŕ äë˙ âőîäŕ â çŕăđóç÷čę â START_WAIT */ +#define START_WAIT_UARTCHAR 'S' + +/* Âűäĺđćęŕ äë˙ START_WAIT mode ( t = WAIT_TIME * 10ms ) */ +#define WAIT_VALUE 1000 /* ńĺé÷ŕń: 300*10ms = 3000ms = 3sec */ + +/* + * enable/disable readout of fuse and lock-bits + * (AVRPROG has to detect the AVR correctly by device-code + * to show the correct information). + */ +//#define ENABLEREADFUSELOCK + +/* enable/disable write of lock-bits + * WARNING: lock-bits can not be reseted by bootloader (as far as I know) + * Only protection no unprotection, "chip erase" from bootloader only + * clears the flash but does no real "chip erase" (this is not possible + * with a bootloader as far as I know) + * Keep this undefined! + */ +//#define WRITELOCKBITS + +/* + * define the following if the bootloader should not output + * itself at flash read (will fake an empty boot-section) + */ +//#define READ_PROTECT_BOOTLOADER + +#define VERSION_HIGH '0' +#define VERSION_LOW '8' + +#define GET_LOCK_BITS 0x0001 +#define GET_LOW_FUSE_BITS 0x0000 +#define GET_HIGH_FUSE_BITS 0x0003 +#define GET_EXTENDED_FUSE_BITS 0x0002 + +/* Đŕń÷ĺň äĺëčňĺë˙ ÷ŕńňîňű äë˙ USART*/ +#ifdef UART_DOUBLESPEED + + #define UART_CALC_BAUDRATE(baudRate) ((uint32_t)((F_CPU) + ((uint32_t)baudRate * 4UL)) / ((uint32_t)(baudRate) * 8UL) - 1) + +#else + + #define UART_CALC_BAUDRATE(baudRate) ((uint32_t)((F_CPU) + ((uint32_t)baudRate * 8UL)) / ((uint32_t)(baudRate) * 16UL) - 1) + +#endif + + +#include <stdint.h> +#include <avr/io.h> +#include <avr/wdt.h> +#include <avr/boot.h> +#include <avr/pgmspace.h> +#include <avr/eeprom.h> +#include <avr/interrupt.h> +#include <util/delay.h> + +#include "chipdef.h" + +uint8_t gBuffer[SPM_PAGESIZE]; + +#if defined(BOOTLOADERHASNOVECTORS) + #warning "This Bootloader does not link interrupt vectors - see makefile" + /* make the linker happy - it wants to see __vector_default */ + // void __vector_default(void) { ; } + void __vector_default(void) { ; } +#endif + +static void sendchar(uint8_t data) +{ + while (!(UART_STATUS & (1<<UART_TXREADY))); + UART_DATA = data; +} + +static uint8_t recvchar(void) +{ + while (!(UART_STATUS & (1<<UART_RXREADY))); + return UART_DATA; +} + +static inline void eraseFlash(void) +{ + // erase only main section (bootloader protection) + uint32_t addr = 0; + while (APP_END > addr) + { + boot_page_erase(addr); // Perform page erase + boot_spm_busy_wait(); // Wait until the memory is erased. + addr += SPM_PAGESIZE; + } + boot_rww_enable(); +} + +static inline void recvBuffer(pagebuf_t size) +{ + pagebuf_t cnt; + uint8_t *tmp = gBuffer; + + for (cnt = 0; cnt < sizeof(gBuffer); cnt++) + { + *tmp++ = (cnt < size) ? recvchar() : 0xFF; + } +} + +static inline uint16_t writeFlashPage(uint16_t waddr, pagebuf_t size) +{ + uint32_t pagestart = (uint32_t)waddr<<1; + uint32_t baddr = pagestart; + uint16_t data; + uint8_t *tmp = gBuffer; + + do + { + data = *tmp++; + data |= *tmp++ << 8; + boot_page_fill(baddr, data); // call asm routine. + + baddr += 2; // Select next word in memory + size -= 2; // Reduce number of bytes to write by two + } + while (size); // Loop until all bytes written + + boot_page_write(pagestart); + boot_spm_busy_wait(); + boot_rww_enable(); // Re-enable the RWW section + + return baddr>>1; +} + +static inline uint16_t writeEEpromPage(uint16_t address, pagebuf_t size) +{ +/* + uint8_t *tmp = gBuffer; + + do + { + eeprom_write_byte( (uint8_t*)address, *tmp++ ); + address++; // Select next byte + size--; // Decreas number of bytes to write + } + while (size); // Loop until all bytes written + + // eeprom_busy_wait(); +*/ + return address+size; +} + +static inline uint16_t readFlashPage(uint16_t waddr, pagebuf_t size) +{ + uint32_t baddr = (uint32_t)waddr<<1; + uint16_t data; + + do + { + +#ifndef READ_PROTECT_BOOTLOADER +#warning "Bootloader not read-protected" + + #if defined(RAMPZ) + data = pgm_read_word_far(baddr); + #else + data = pgm_read_word_near(baddr); + #endif + +#else + // don't read bootloader + if ( baddr < APP_END ) + { + #if defined(RAMPZ) + data = pgm_read_word_far(baddr); + #else + data = pgm_read_word_near(baddr); + #endif + } + else + { + data = 0xFFFF; // fake empty + } +#endif + sendchar(data); // send LSB + sendchar((data >> 8)); // send MSB + baddr += 2; // Select next word in memory + size -= 2; // Subtract two bytes from number of bytes to read + } + while (size); // Repeat until block has been read + return baddr>>1; +} + +static inline uint16_t readEEpromPage(uint16_t address, pagebuf_t size) +{ + do + { + sendchar( eeprom_read_byte( (uint8_t*)address ) ); + address++; + size--; // Decrease number of bytes to read + } + while (size); // Repeat until block has been read + + return address; +} + +#if defined(ENABLEREADFUSELOCK) +static uint8_t read_fuse_lock(uint16_t addr) +{ + uint8_t mode = (1<<BLBSET) | (1<<SPMEN); + uint8_t retval; + + asm volatile + ( + "movw r30, %3\n\t" /* Z to addr */ \ + "sts %0, %2\n\t" /* set mode in SPM_REG */ \ + "lpm\n\t" /* load fuse/lock value into r0 */ \ + "mov %1,r0\n\t" /* save return value */ \ + : "=m" (SPM_REG), + "=r" (retval) + : "r" (mode), + "r" (addr) + : "r30", "r31", "r0" + ); + return retval; +} +#endif + +static void send_boot(void) +{ + sendchar('A'); + sendchar('V'); + sendchar('R'); + sendchar('B'); + sendchar('O'); + sendchar('O'); + sendchar('T'); +} + +static void (*jump_to_app)(void) = 0x0000; + +int main(void) +{ + uint16_t address = 0; + uint8_t device = 0, val; + + + +#ifdef ENABLE_BOOT_LED // LED ON + BIPORT |= (1<<BIPNUM); + BIDDR |= (1<<BIPNUM); +#endif + + +#ifdef DISABLE_WDT_AT_STARTUP + #ifdef WDT_OFF_SPECIAL + #warning "using target specific watchdog_off" + bootloader_wdt_off(); + #else + cli(); + wdt_reset(); + wdt_disable(); + #endif +#endif + +#ifdef START_POWERSAVE + uint8_t OK = 1; +#endif + + BLDDR &= ~(1<<BLPNUM); // set as Input + BLPORT |= (1<<BLPNUM); // Enable pullup + + // Set baud rate + UART_BAUD_HIGH = (UART_CALC_BAUDRATE(BAUDRATE)>>8) & 0xFF; + UART_BAUD_LOW = (UART_CALC_BAUDRATE(BAUDRATE) & 0xFF); + +#ifdef UART_DOUBLESPEED + UART_STATUS = ( 1<<UART_DOUBLE ); +#endif + + UART_CTRL = UART_CTRL_DATA; + UART_CTRL2 = UART_CTRL2_DATA; + +#if defined(START_POWERSAVE) + /* + This is an adoption of the Butterfly Bootloader startup-sequence. + It may look a little strange but separating the login-loop from + the main parser-loop gives a lot a possibilities (timeout, sleep-modes + etc.). + */ + for(;OK;) + { + if ((BLPIN & (1<<BLPNUM))) + { + // jump to main app if pin is not grounded + BLPORT &= ~(1<<BLPNUM); // set to default + + #ifdef UART_DOUBLESPEED + UART_STATUS &= ~( 1<<UART_DOUBLE ); + #endif + + + #ifdef ENABLE_BOOT_LED // LED OFF + BIPORT &= ~(1<<BIPNUM); + BIDDR &= ~(1<<BIPNUM); + #endif + + jump_to_app(); // Jump to application sector + + } + else + { + val = recvchar(); + /* ESC */ + if (val == 0x1B) + { + // AVRPROG connection + // Wait for signon + while (val != 'S') + val = recvchar(); + + send_boot(); // Report signon + OK = 0; + } + else + { + sendchar('?'); + } + } + // Power-Save code here + } + +#elif defined(START_SIMPLE) + + if ((BLPIN & (1<<BLPNUM))) { +/* + // jump to main app if pin is not grounded + BLPORT &= ~(1<<BLPNUM); // set to default + + #ifdef UART_DOUBLESPEED + UART_STATUS &= ~( 1<<UART_DOUBLE ); + #endif + +*/ + #ifdef ENABLE_BOOT_LED // LED OFF + BIPORT &= ~(1<<BIPNUM); + BIDDR &= ~(1<<BIPNUM); + #endif + + jump_to_app(); // Jump to application sector + } + +#elif defined(START_WAIT) + + uint16_t cnt = 0; + + while (1) { + if (UART_STATUS & (1<<UART_RXREADY)) + if (UART_DATA == START_WAIT_UARTCHAR) + break; + + if (cnt++ >= WAIT_VALUE) { + BLPORT &= ~(1<<BLPNUM); // set to default + + + #ifdef ENABLE_BOOT_LED // LED OFF + BIPORT &= ~(1<<BIPNUM); + BIDDR &= ~(1<<BIPNUM); + #endif + jump_to_app(); // Jump to application sector + } + + _delay_ms(10); + } + send_boot(); + +#elif defined(START_BOOTICE) +#warning "BOOTICE mode - no startup-condition" + +#else +#error "Select START_ condition for bootloader in main.c" +#endif + + + for(;;) + { + val = recvchar(); + // Autoincrement? + if (val == 'a') + { + sendchar('Y'); // Autoincrement is quicker + + //write address + } + else if (val == 'A') + { + address = recvchar(); //read address 8 MSB + address = (address<<8) | recvchar(); + sendchar('\r'); + + // Buffer load support + } + else if (val == 'b') + { + sendchar('Y'); // Report buffer load supported + sendchar((sizeof(gBuffer) >> 8) & 0xFF); // Report buffer size in bytes + sendchar(sizeof(gBuffer) & 0xFF); + + // Start buffer load + } + else if (val == 'B') + { + pagebuf_t size; + size = recvchar() << 8; // Load high byte of buffersize + size |= recvchar(); // Load low byte of buffersize + val = recvchar(); // Load memory type ('E' or 'F') + recvBuffer(size); + + if (device == DEVTYPE) + { + if (val == 'F') + { + address = writeFlashPage(address, size); + } + else if (val == 'E') + { + address = writeEEpromPage(address, size); + } + sendchar('\r'); + } + else + { + sendchar(0); + } + + // Block read + } + else if (val == 'g') + { + pagebuf_t size; + size = recvchar() << 8; // Load high byte of buffersize + size |= recvchar(); // Load low byte of buffersize + val = recvchar(); // Get memtype + + if (val == 'F') + { + address = readFlashPage(address, size); + } + else if (val == 'E') + { + address = readEEpromPage(address, size); + } + + // Chip erase + } + else if (val == 'e') + { + if (device == DEVTYPE) + { + eraseFlash(); + } + sendchar('\r'); + + // Exit upgrade + } + else if (val == 'E') + { + wdt_enable(EXIT_WDT_TIME); // Enable Watchdog Timer to give reset + sendchar('\r'); + + #ifdef WRITELOCKBITS + #warning "Extension 'WriteLockBits' enabled" + // TODO: does not work reliably + // write lockbits + } + else if (val == 'l') + { + if (device == DEVTYPE) + { + // write_lock_bits(recvchar()); + boot_lock_bits_set(recvchar()); // boot.h takes care of mask + boot_spm_busy_wait(); + } + sendchar('\r'); + #endif + // Enter programming mode + } + else if (val == 'P') + { + sendchar('\r'); + + // Leave programming mode + } + else if (val == 'L') + { + sendchar('\r'); + // return programmer type + } + else if (val == 'p') + { + sendchar('S'); // always serial programmer + + #ifdef ENABLEREADFUSELOCK + #warning "Extension 'ReadFuseLock' enabled" + // read "low" fuse bits + } + else if (val == 'F') + { + sendchar(read_fuse_lock(GET_LOW_FUSE_BITS)); + + // read lock bits + } + else if (val == 'r') + { + sendchar(read_fuse_lock(GET_LOCK_BITS)); + + // read high fuse bits + } + else if (val == 'N') + { + sendchar(read_fuse_lock(GET_HIGH_FUSE_BITS)); + // read extended fuse bits + } + else if (val == 'Q') + { + sendchar(read_fuse_lock(GET_EXTENDED_FUSE_BITS)); + #endif + + // Return device type + } + else if (val == 't') + { + sendchar(DEVTYPE); + sendchar(0); + // clear and set LED ignored + } + else if ((val == 'x') || (val == 'y')) + { + recvchar(); + sendchar('\r'); + + // set device + } + else if (val == 'T') + { + device = recvchar(); + sendchar('\r'); + // Return software identifier + } + else if (val == 'S') + { + send_boot(); + + // Return Software Version + } + else if (val == 'V') { + sendchar(VERSION_HIGH); + sendchar(VERSION_LOW); + + // Return Signature Bytes (it seems that + // AVRProg expects the "Atmel-byte" 0x1E last + // but shows it first in the dialog-window) + } + else if (val == 's') + { + sendchar(SIG_BYTE3); + sendchar(SIG_BYTE2); + sendchar(SIG_BYTE1); + + /* ESC */ + } + else if(val != 0x1b) + { + sendchar('?'); + } + } + return 0; +} diff --git a/Bootloader/makefile b/Bootloader/makefile new file mode 100644 index 0000000..390043c --- /dev/null +++ b/Bootloader/makefile @@ -0,0 +1,671 @@ +# Hey Emacs, this is a -*- makefile -*- +# +# Makefile for the AVRProg-compatible Bootloader +# +# based on the +# WinAVR Sample makefile written by Eric B. Weddington, Jörg Wunsch, et al. +# Released to the Public Domain +# Please read the make user manual! +# +# Additional material for this makefile was submitted by: +# Tim Henigan +# Peter Fleury +# Reiner Patommel +# Sander Pool +# Frederik Rouleau +# Markus Pfaff +# +# On command line: +# +# make all = Make software. +# +# make clean = Clean out built project files. +# +# make coff = Convert ELF to AVR COFF (for use with AVR Studio 3.x or VMLAB). +# +# make extcoff = Convert ELF to AVR Extended COFF (for use with AVR Studio +# 4.07 or greater). +# +# make program = Download the hex file to the device, using avrdude. Please +# customize the avrdude settings below first! +# +# make filename.s = Just compile filename.c into the assembler code only +# +# To rebuild project do "make clean" then "make all". +# + +# user defined values + +# MCU name +## MCU = atmega8 +#F_CPU = 11059200UL +#F_CPU = 8000000UL +#BAUDRATE = 9600 +MCU = atmega8 +LFUSE = E4 +HFUSE = DA +MCU_PROGRAMMER = m8 +## MCU = atmega162 +## MCU = atmega169 +## MCU = atmega32 +## MCU = atmega324p +## MCU = atmega64 +## MCU = atmega644 +## MCU = atmega644p +## MCU = atmega128 +## MCU = at90can128 + +################## BOOTLOADER ###################### +# mt: Boot loader support. So far not done with a separate section +# to get the interrupt vector into the bootloader area (for BOOTINTVEC=yes). +# Bootloader address in datasheet and stk500 is given as +# "word", gcc toolchain needs "byte"-address +# (see LDFLAGS further down) + +#/* Select Boot Size in Words (select one, comment out the others) */ +## NO! BOOTSIZE=128 +## NO! BOOTSIZE=256 +BOOTSIZE=512 +#BOOTSIZE=1024 +## BOOTSIZE=2048 + +# /* Select if bootloader should include the inverrupt-vectors +# when selecting 'no' here, the bootloader must not use +# any interrupts and the modified linker-scripts are used. */ +##BOOTINTVEC=yes +BOOTINTVEC=no + +## +ifeq ($(MCU), atmega8) +BFD_MACH=avr4 +ifeq ($(BOOTSIZE), 128) + MT_BOOTLOADER_ADDRESS = 0x1F00 +endif +ifeq ($(BOOTSIZE), 256) + MT_BOOTLOADER_ADDRESS = 0x1E00 +endif +ifeq ($(BOOTSIZE), 512) + MT_BOOTLOADER_ADDRESS = 0x1C00 +endif +ifeq ($(BOOTSIZE), 1024) + MT_BOOTLOADER_ADDRESS = 0x1800 +endif +endif + +## +ifeq ($(MCU), atmega16) +BFD_MACH=avr5 +ifeq ($(BOOTSIZE), 128) + MT_BOOTLOADER_ADDRESS = 0x3F00 +endif +ifeq ($(BOOTSIZE), 256) + MT_BOOTLOADER_ADDRESS = 0x3E00 +endif +ifeq ($(BOOTSIZE), 512) + MT_BOOTLOADER_ADDRESS = 0x3C00 +endif +ifeq ($(BOOTSIZE), 1024) + MT_BOOTLOADER_ADDRESS = 0x3800 +endif +endif + +## +ifeq ($(MCU), atmega162) +BFD_MACH=avr5 +ifeq ($(BOOTSIZE), 128) + MT_BOOTLOADER_ADDRESS = 0x3F00 +endif +ifeq ($(BOOTSIZE), 256) + MT_BOOTLOADER_ADDRESS = 0x3E00 +endif +ifeq ($(BOOTSIZE), 512) + MT_BOOTLOADER_ADDRESS = 0x3C00 +endif +ifeq ($(BOOTSIZE), 1024) + MT_BOOTLOADER_ADDRESS = 0x3800 +endif +endif + +## +ifeq ($(MCU), atmega169) +BFD_MACH=avr5 +ifeq ($(BOOTSIZE), 128) + MT_BOOTLOADER_ADDRESS = 0x3F00 +endif +ifeq ($(BOOTSIZE), 256) + MT_BOOTLOADER_ADDRESS = 0x3E00 +endif +ifeq ($(BOOTSIZE), 512) + MT_BOOTLOADER_ADDRESS = 0x3C00 +endif +ifeq ($(BOOTSIZE), 1024) + MT_BOOTLOADER_ADDRESS = 0x3800 +endif +endif + +## +ifeq ($(MCU), atmega32) +BFD_MACH=avr5 +ifeq ($(BOOTSIZE), 256) + MT_BOOTLOADER_ADDRESS = 0x7E00 +endif +ifeq ($(BOOTSIZE), 512) + MT_BOOTLOADER_ADDRESS = 0x7C00 +endif +ifeq ($(BOOTSIZE), 1024) + MT_BOOTLOADER_ADDRESS = 0x7800 +endif +ifeq ($(BOOTSIZE), 2048) + MT_BOOTLOADER_ADDRESS = 0x7000 +endif +endif + +## +ifeq ($(MCU), atmega324p) +BFD_MACH=avr5 +ifeq ($(BOOTSIZE), 256) + MT_BOOTLOADER_ADDRESS = 0x7E00 +endif +ifeq ($(BOOTSIZE), 512) + MT_BOOTLOADER_ADDRESS = 0x7C00 +endif +ifeq ($(BOOTSIZE), 1024) + MT_BOOTLOADER_ADDRESS = 0x7800 +endif +ifeq ($(BOOTSIZE), 2048) + MT_BOOTLOADER_ADDRESS = 0x7000 +endif +endif + +## +ifeq ($(MCU), atmega64) +BFD_MACH=avr5 +ifeq ($(BOOTSIZE), 512) + MT_BOOTLOADER_ADDRESS = 0xFC00 +endif +ifeq ($(BOOTSIZE), 1024) + MT_BOOTLOADER_ADDRESS = 0xF800 +endif +ifeq ($(BOOTSIZE), 2048) + MT_BOOTLOADER_ADDRESS = 0xF000 +endif +ifeq ($(BOOTSIZE), 4096) + MT_BOOTLOADER_ADDRESS = 0xE000 +endif +endif + +## +ifeq ($(MCU), atmega644) +BFD_MACH=avr5 +ifeq ($(BOOTSIZE), 512) + MT_BOOTLOADER_ADDRESS = 0xFC00 +endif +ifeq ($(BOOTSIZE), 1024) + MT_BOOTLOADER_ADDRESS = 0xF800 +endif +ifeq ($(BOOTSIZE), 2048) + MT_BOOTLOADER_ADDRESS = 0xF000 +endif +ifeq ($(BOOTSIZE), 4096) + MT_BOOTLOADER_ADDRESS = 0xE000 +endif +endif + +## +ifeq ($(MCU), atmega644p) +BFD_MACH=avr5 +ifeq ($(BOOTSIZE), 512) + MT_BOOTLOADER_ADDRESS = 0xFC00 +endif +ifeq ($(BOOTSIZE), 1024) + MT_BOOTLOADER_ADDRESS = 0xF800 +endif +ifeq ($(BOOTSIZE), 2048) + MT_BOOTLOADER_ADDRESS = 0xF000 +endif +ifeq ($(BOOTSIZE), 4096) + MT_BOOTLOADER_ADDRESS = 0xE000 +endif +endif + +## +ifeq ($(MCU), atmega128) +BFD_MACH=avr5 +ifeq ($(BOOTSIZE), 512) + MT_BOOTLOADER_ADDRESS = 0x1FC00 +endif +ifeq ($(BOOTSIZE), 1024) + MT_BOOTLOADER_ADDRESS = 0x1F800 +endif +ifeq ($(BOOTSIZE), 2048) + MT_BOOTLOADER_ADDRESS = 0x1F000 +endif +ifeq ($(BOOTSIZE), 4096) + MT_BOOTLOADER_ADDRESS = 0x1E000 +endif +endif + +## +ifeq ($(MCU), at90can128) +BFD_MACH=avr5 +ifeq ($(BOOTSIZE), 512) + MT_BOOTLOADER_ADDRESS = 0x1FC00 +endif +ifeq ($(BOOTSIZE), 1024) + MT_BOOTLOADER_ADDRESS = 0x1F800 +endif +ifeq ($(BOOTSIZE), 2048) + MT_BOOTLOADER_ADDRESS = 0x1F000 +endif +ifeq ($(BOOTSIZE), 4096) + MT_BOOTLOADER_ADDRESS = 0x1E000 +endif +endif + + +# Output format. (can be srec, ihex, binary) +FORMAT = ihex +#FORMAT = srec + +# Target file name (without extension). +TARGET = main + + +# List C source files here. (C dependencies are automatically generated.) +SRC = $(TARGET).c + + +# List Assembler source files here. +# Make them always end in a capital .S. Files ending in a lowercase .s +# will not be considered source files but generated files (assembler +# output from the compiler), and will be deleted upon "make clean"! +# Even though the DOS/Win* filesystem matches both .s and .S the same, +# it will preserve the spelling of the filenames, and gcc itself does +# care about how the name is spelled on its command-line. +ASRC = + + + +# Optimization level, can be [0, 1, 2, 3, s]. +# 0 = turn off optimization. s = optimize for size. +# (Note: 3 is not always the best optimization level. See avr-libc FAQ.) +OPT = s + +# Debugging format. +# Native formats for AVR-GCC's -g are stabs [default], or dwarf-2. +# AVR (extended) COFF requires stabs, plus an avr-objcopy run. +DEBUG = stabs + +# List any extra directories to look for include files here. +# Each directory must be seperated by a space. +EXTRAINCDIRS = + + +# Compiler flag to set the C Standard level. +# c89 - "ANSI" C +# gnu89 - c89 plus GCC extensions +# c99 - ISO C99 standard (not yet fully implemented) +# gnu99 - c99 plus GCC extensions +CSTANDARD = -std=gnu99 + +# Place -D or -U options here +CDEFS = -DBOOTSIZE=$(BOOTSIZE) + +# Place -I options here +CINCS = + + +# Compiler flags. +# -g*: generate debugging information +# -O*: optimization level +# -f...: tuning, see GCC manual and avr-libc documentation +# -Wall...: warning level +# -Wa,...: tell GCC to pass this to the assembler. +# -adhlns...: create assembler listing +CFLAGS = -g$(DEBUG) +CFLAGS += $(CDEFS) $(CINCS) +CFLAGS += -O$(OPT) +CFLAGS += -funsigned-char -funsigned-bitfields -fpack-struct -fshort-enums +CFLAGS += -Wall -Wstrict-prototypes +CFLAGS += -Wa,-adhlns=$(<:.c=.lst) +CFLAGS += $(patsubst %,-I%,$(EXTRAINCDIRS)) +CFLAGS += $(CSTANDARD) + + + +# Assembler flags. +# -Wa,...: tell GCC to pass this to the assembler. +# -ahlms: create listing +# -gstabs: have the assembler create line number information; note that +# for use in COFF files, additional information about filenames +# and function names needs to be present in the assembler source +# files -- see avr-libc docs [FIXME: not yet described there] +ASFLAGS = -Wa,-adhlns=$(<:.S=.lst),-gstabs + + + +#Additional libraries. + +# Minimalistic printf version +PRINTF_LIB_MIN = -Wl,-u,vfprintf -lprintf_min + +# Floating point printf version (requires MATH_LIB = -lm below) +PRINTF_LIB_FLOAT = -Wl,-u,vfprintf -lprintf_flt + +PRINTF_LIB = + +# Minimalistic scanf version +SCANF_LIB_MIN = -Wl,-u,vfscanf -lscanf_min + +# Floating point + %[ scanf version (requires MATH_LIB = -lm below) +SCANF_LIB_FLOAT = -Wl,-u,vfscanf -lscanf_flt + +SCANF_LIB = + +MATH_LIB = -lm + +# External memory options + +# 64 KB of external RAM, starting after internal RAM (ATmega128!), +# used for variables (.data/.bss) and heap (malloc()). +#EXTMEMOPTS = -Wl,-Tdata=0x801100,--defsym=__heap_end=0x80ffff + +# 64 KB of external RAM, starting after internal RAM (ATmega128!), +# only used for heap (malloc()). +#EXTMEMOPTS = -Wl,--defsym=__heap_start=0x801100,--defsym=__heap_end=0x80ffff + +EXTMEMOPTS = + +# Linker flags. +# -Wl,...: tell GCC to pass this to linker. +# -Map: create map file +# --cref: add cross reference to map file +LDFLAGS = -Wl,-Map=$(TARGET).map,--cref +LDFLAGS += $(EXTMEMOPTS) +LDFLAGS += $(PRINTF_LIB) $(SCANF_LIB) $(MATH_LIB) + +################## BOOTLOADER ###################### +# MT_BOOTLOADER_ADDRESS (=Start of Boot Loader section +# in bytes - not words) as defined above. +LDFLAGS += -Wl,--section-start=.text=$(MT_BOOTLOADER_ADDRESS) + +# check if linker-scripts without interrupt-vectors should +# be used and set linker-option, announce to C-code by define +ifeq ($(BOOTINTVEC), no) +LDFLAGS += -T./ldscripts_no_vector/$(BFD_MACH).x +CFLAGS += -DBOOTLOADERHASNOVECTORS +endif + + +# Programming support using avrdude. Settings and variables. + +# Programming hardware: alf avr910 avrisp bascom bsd +# dt006 pavr picoweb pony-stk200 sp12 stk200 stk500 +# +# Type: avrdude -c ? +# to get a full listing. +# +AVRDUDE_PROGRAMMER = stk500v2 + +# com1 = serial port. Use lpt1 to connect to parallel port. +AVRDUDE_PORT = com1 # programmer connected to serial device +#AVRDUDE_PORT = /dev/ttyS0 # programmer connected to serial device + +AVRDUDE_WRITE_FLASH = -U flash:w:$(TARGET).hex +#AVRDUDE_WRITE_EEPROM = -U eeprom:w:$(TARGET).eep + + +# Uncomment the following if you want avrdude's erase cycle counter. +# Note that this counter needs to be initialized first using -Yn, +# see avrdude manual. +#AVRDUDE_ERASE_COUNTER = -y + +# Uncomment the following if you do /not/ wish a verification to be +# performed after programming the device. +#AVRDUDE_NO_VERIFY = -V + +# Increase verbosity level. Please use this when submitting bug +# reports about avrdude. See <http://savannah.nongnu.org/projects/avrdude> +# to submit bug reports. +#AVRDUDE_VERBOSE = -v -v + +AVRDUDE_FLAGS = -p $(MCU) -P $(AVRDUDE_PORT) -c $(AVRDUDE_PROGRAMMER) +AVRDUDE_FLAGS += $(AVRDUDE_NO_VERIFY) +AVRDUDE_FLAGS += $(AVRDUDE_VERBOSE) +AVRDUDE_FLAGS += $(AVRDUDE_ERASE_COUNTER) + + + +# --------------------------------------------------------------------------- + +# Define directories, if needed. +#DIRAVR = c:/winavr +#DIRAVRBIN = $(DIRAVR)/bin +#DIRAVRUTILS = $(DIRAVR)/utils/bin +#DIRINC = . +#DIRLIB = $(DIRAVR)/avr/lib + + +# Define programs and commands. +#SHELL = $(DIRAVRUTILS)/sh +#NM = $(DIRAVRBIN)/avr-nm +#CC = $(DIRAVRBIN)/avr-gcc +#OBJCOPY = $(DIRAVRBIN)/avr-objcopy +#OBJDUMP= $(DIRAVRBIN)/avr-objdump +#SIZE = $(DIRAVRBIN)/avr-size +#AVRDUDE = $(DIRAVRBIN)/avrdude.sh +#REMOVE = rm -f +#COPY = cp + +# Define programs and commands. +SHELL = sh +CC = avr-gcc +OBJCOPY = avr-objcopy +OBJDUMP = avr-objdump +SIZE = avr-size +NM = avr-nm +AVRDUDE = avrdude +REMOVE = rm -f +COPY = cp +WINSHELL = cmd + + +# Define Messages +# English +MSG_ERRORS_NONE = Errors: none +MSG_BEGIN = -------- begin -------- +MSG_END = -------- end -------- +MSG_SIZE_BEFORE = Size before: +MSG_SIZE_AFTER = Size after: +MSG_COFF = Converting to AVR COFF: +MSG_EXTENDED_COFF = Converting to AVR Extended COFF: +MSG_FLASH = Creating load file for Flash: +MSG_EEPROM = Creating load file for EEPROM: +MSG_EXTENDED_LISTING = Creating Extended Listing: +MSG_SYMBOL_TABLE = Creating Symbol Table: +MSG_LINKING = Linking: +MSG_COMPILING = Compiling: +MSG_ASSEMBLING = Assembling: +MSG_CLEANING = Cleaning project: + + + + +# Define all object files. +OBJ = $(SRC:.c=.o) $(ASRC:.S=.o) + +# Define all listing files. +LST = $(ASRC:.S=.lst) $(SRC:.c=.lst) + + +# Compiler flags to generate dependency files. +### GENDEPFLAGS = -Wp,-M,-MP,-MT,$(*F).o,-MF,.dep/$(@F).d +GENDEPFLAGS = -MD -MP -MF .dep/$(@F).d + +# Combine all necessary flags and optional flags. +# Add target processor to flags. +ALL_CFLAGS = -mmcu=$(MCU) -I. $(CFLAGS) $(GENDEPFLAGS) +ALL_ASFLAGS = -mmcu=$(MCU) -I. -x assembler-with-cpp $(ASFLAGS) + + + + + +# Default target. +all: begin gccversion sizebefore build sizeafter finished end + +build: elf hex eep lss sym + +elf: $(TARGET).elf +hex: $(TARGET).hex +eep: $(TARGET).eep +lss: $(TARGET).lss +sym: $(TARGET).sym + + + +# Eye candy. +# AVR Studio 3.x does not check make's exit code but relies on +# the following magic strings to be generated by the compile job. +begin: + @echo + @echo $(MSG_BEGIN) + +finished: + @echo $(MSG_ERRORS_NONE) + +end: + @echo $(MSG_END) + @echo + + +# Display size of file. +HEXSIZE = $(SIZE) --target=$(FORMAT) $(TARGET).hex +ELFSIZE = $(SIZE) -x -A $(TARGET).elf +sizebefore: + @if [ -f $(TARGET).elf ]; then echo; echo $(MSG_SIZE_BEFORE); $(ELFSIZE); echo; fi + +sizeafter: + @if [ -f $(TARGET).elf ]; then echo; echo $(MSG_SIZE_AFTER); $(ELFSIZE); echo; fi + + + +# Display compiler version information. +gccversion : + @$(CC) --version + + + +# Convert ELF to COFF for use in debugging / simulating in AVR Studio or VMLAB. +COFFCONVERT=$(OBJCOPY) --debugging \ +--change-section-address .data-0x800000 \ +--change-section-address .bss-0x800000 \ +--change-section-address .noinit-0x800000 \ +--change-section-address .eeprom-0x810000 + + +coff: $(TARGET).elf + @echo + @echo $(MSG_COFF) $(TARGET).cof + $(COFFCONVERT) -O coff-avr $< $(TARGET).cof + + +extcoff: $(TARGET).elf + @echo + @echo $(MSG_EXTENDED_COFF) $(TARGET).cof + $(COFFCONVERT) -O coff-ext-avr $< $(TARGET).cof + + + +# Create final output files (.hex, .eep) from ELF output file. +%.hex: %.elf + @echo + @echo $(MSG_FLASH) $@ + $(OBJCOPY) -O $(FORMAT) -R .eeprom $< $@ + +%.eep: %.elf + @echo + @echo $(MSG_EEPROM) $@ + -$(OBJCOPY) -j .eeprom --set-section-flags=.eeprom="alloc,load" \ + --change-section-lma .eeprom=0 -O $(FORMAT) $< $@ + +# Create extended listing file from ELF output file. +%.lss: %.elf + @echo + @echo $(MSG_EXTENDED_LISTING) $@ + $(OBJDUMP) -h -S $< > $@ + +# Create a symbol table from ELF output file. +%.sym: %.elf + @echo + @echo $(MSG_SYMBOL_TABLE) $@ + $(NM) -n $< > $@ + + + +# Link: create ELF output file from object files. +.SECONDARY : $(TARGET).elf +.PRECIOUS : $(OBJ) +%.elf: $(OBJ) + @echo + @echo $(MSG_LINKING) $@ + $(CC) $(ALL_CFLAGS) $(OBJ) --output $@ $(LDFLAGS) + + +# Compile: create object files from C source files. +%.o : %.c + @echo + @echo $(MSG_COMPILING) $< + $(CC) -c $(ALL_CFLAGS) $< -o $@ + + +# Compile: create assembler files from C source files. +%.s : %.c + $(CC) -S $(ALL_CFLAGS) $< -o $@ + + +# Assemble: create object files from assembler source files. +%.o : %.S + @echo + @echo $(MSG_ASSEMBLING) $< + $(CC) -c $(ALL_ASFLAGS) $< -o $@ + + + +# Target: clean project. +clean: begin clean_list finished end + +clean_list : + @echo + @echo $(MSG_CLEANING) + $(REMOVE) $(TARGET).hex + $(REMOVE) $(TARGET).eep + $(REMOVE) $(TARGET).obj + $(REMOVE) $(TARGET).cof + $(REMOVE) $(TARGET).elf + $(REMOVE) $(TARGET).map + $(REMOVE) $(TARGET).obj + $(REMOVE) $(TARGET).a90 + $(REMOVE) $(TARGET).sym + $(REMOVE) $(TARGET).lnk + $(REMOVE) $(TARGET).lss + $(REMOVE) $(OBJ) + $(REMOVE) $(LST) + $(REMOVE) $(SRC:.c=.s) + $(REMOVE) $(SRC:.c=.d) + $(REMOVE) .dep/* + + + +# Include the dependency files. +-include $(shell mkdir .dep 2>/dev/null) $(wildcard .dep/*) + + +# Listing of phony targets. +.PHONY : all begin finish end sizebefore sizeafter gccversion \ +build elf hex eep lss sym coff extcoff \ +clean clean_list program + +program: hex + avrdude -p $(MCU_PROGRAMMER) -c avrisp2 -P usb -U flash:w:main.hex -U lfuse:w:0x$(LFUSE):m -U hfuse:w:0x$(HFUSE):m -v -e +# avrdude -V -p $(MCU_PROGRAMMER) -c ftbb -P ft0 -U flash:w:main.hex -U lfuse:w:0x$(LFUSE):m -U hfuse:w:0x$(HFUSE):m -D diff --git a/Bootloader/mega128.h b/Bootloader/mega128.h new file mode 100644 index 0000000..a8f148c --- /dev/null +++ b/Bootloader/mega128.h @@ -0,0 +1,39 @@ +#ifndef _MEGA128_H_ +#define _MEGA128_H_ + +/* Part-Code ISP */ +#define DEVTYPE_ISP 0x43 +/* Part-Code Boot */ +#define DEVTYPE_BOOT 0x44 + +#define SIG_BYTE1 0x1E +#define SIG_BYTE2 0x97 +#define SIG_BYTE3 0x02 + +#ifndef UART_USE_SECOND +#define UART_BAUD_HIGH UBRR0H +#define UART_BAUD_LOW UBRR0L +#define UART_STATUS UCSR0A +#define UART_TXREADY UDRE0 +#define UART_RXREADY RXC0 +#define UART_DOUBLE U2X0 +#define UART_CTRL UCSR0B +#define UART_CTRL_DATA ((1<<TXEN0) | (1<<RXEN0)) +#define UART_CTRL2 UCSR0C +#define UART_CTRL2_DATA ((1<<UCSZ01) | (1<<UCSZ00)) +#define UART_DATA UDR0 +#else +#define UART_BAUD_HIGH UBRR1H +#define UART_BAUD_LOW UBRR1L +#define UART_STATUS UCSR1A +#define UART_TXREADY UDRE1 +#define UART_RXREADY RXC1 +#define UART_DOUBLE U2X1 +#define UART_CTRL UCSR1B +#define UART_CTRL_DATA ((1<<TXEN1) | (1<<RXEN1)) +#define UART_CTRL2 UCSR1C +#define UART_CTRL2_DATA ((1<<UCSZ11) | (1<<UCSZ10)) +#define UART_DATA UDR1 +#endif + +#endif // #ifndef _MEGA128_H_ diff --git a/Bootloader/mega128can.h b/Bootloader/mega128can.h new file mode 100644 index 0000000..08f6a0d --- /dev/null +++ b/Bootloader/mega128can.h @@ -0,0 +1,42 @@ +#ifndef _MEGA128CAN_H_ +#define _MEGA128CAN_H_ + +/* Dummy: use ATmega128 device-code for now, + must be same as used in avrdude.conf */ +/* Part-Code ISP */ +#define DEVTYPE_ISP 0x43 +/* Part-Code Boot */ +#define DEVTYPE_BOOT 0x44 + +#define SIG_BYTE1 0x1E +#define SIG_BYTE2 0x97 +#define SIG_BYTE3 0x81 + + +#ifndef UART_USE_SECOND +#define UART_BAUD_HIGH UBRR0H +#define UART_BAUD_LOW UBRR0L +#define UART_STATUS UCSR0A +#define UART_TXREADY UDRE0 +#define UART_RXREADY RXC0 +#define UART_DOUBLE U2X0 +#define UART_CTRL UCSR0B +#define UART_CTRL_DATA ((1<<TXEN0) | (1<<RXEN0)) +#define UART_CTRL2 UCSR0C +#define UART_CTRL2_DATA ((1<<UCSZ01) | (1<<UCSZ00)) +#define UART_DATA UDR0 +#else +#define UART_BAUD_HIGH UBRR1H +#define UART_BAUD_LOW UBRR1L +#define UART_STATUS UCSR1A +#define UART_TXREADY UDRE1 +#define UART_RXREADY RXC1 +#define UART_DOUBLE U2X1 +#define UART_CTRL UCSR1B +#define UART_CTRL_DATA ((1<<TXEN1) | (1<<RXEN1)) +#define UART_CTRL2 UCSR1C +#define UART_CTRL2_DATA ((1<<UCSZ11) | (1<<UCSZ10)) +#define UART_DATA UDR1 +#endif + +#endif // #ifndef _MEGA128CAN_H_ diff --git a/Bootloader/mega16.h b/Bootloader/mega16.h new file mode 100644 index 0000000..0c0bbe1 --- /dev/null +++ b/Bootloader/mega16.h @@ -0,0 +1,25 @@ +#ifndef _MEGA16_H_ +#define _MEGA16_H_ + +/* Part-Code ISP */ +#define DEVTYPE_ISP 0x74 +/* Part-Code Boot */ +#define DEVTYPE_BOOT 0x75 + +#define SIG_BYTE1 0x1E +#define SIG_BYTE2 0x94 +#define SIG_BYTE3 0x03 + +#define UART_BAUD_HIGH UBRRH +#define UART_BAUD_LOW UBRRL +#define UART_STATUS UCSRA +#define UART_TXREADY UDRE +#define UART_RXREADY RXC +#define UART_DOUBLE U2X +#define UART_CTRL UCSRB +#define UART_CTRL_DATA ((1<<TXEN) | (1<<RXEN)) +#define UART_CTRL2 UCSRC +#define UART_CTRL2_DATA ((1<<URSEL) | (1<<UCSZ1) | (1<<UCSZ0)) +#define UART_DATA UDR + +#endif // #ifndef _MEGA16_H_ diff --git a/Bootloader/mega162.h b/Bootloader/mega162.h new file mode 100644 index 0000000..c2e30bb --- /dev/null +++ b/Bootloader/mega162.h @@ -0,0 +1,45 @@ +#ifndef _MEGA162_H_ +#define _MEGA162_H_ + +/* Part-Code ISP */ +// documented code (AVR109 AppNote) but not supported by AVRProg 1.40 +// #define DEVTYPE_ISP 0x62 +// fake ATmega16 instead: +#define DEVTYPE_ISP 0x74 +/* Part-Code Boot */ +// documented code but not supported by AVRProg 1.40 +// #define DEVTYPE_BOOT 0x63 +// fake ATmega16: +#define DEVTYPE_BOOT 0x75 + +#define SIG_BYTE1 0x1E +#define SIG_BYTE2 0x94 +#define SIG_BYTE3 0x04 + +#ifndef UART_USE_SECOND +#define UART_BAUD_HIGH UBRR0H +#define UART_BAUD_LOW UBRR0L +#define UART_STATUS UCSR0A +#define UART_TXREADY UDRE0 +#define UART_RXREADY RXC0 +#define UART_DOUBLE U2X0 +#define UART_CTRL UCSR0B +#define UART_CTRL_DATA ((1<<TXEN0) | (1<<RXEN0)) +#define UART_CTRL2 UCSR0C +#define UART_CTRL2_DATA ((1<<URSEL0) | (1<<UCSZ01) | (1<<UCSZ00)) +#define UART_DATA UDR0 +#else +#define UART_BAUD_HIGH UBRR1H +#define UART_BAUD_LOW UBRR1L +#define UART_STATUS UCSR1A +#define UART_TXREADY UDRE1 +#define UART_RXREADY RXC1 +#define UART_DOUBLE U2X1 +#define UART_CTRL UCSR1B +#define UART_CTRL_DATA ((1<<TXEN1) | (1<<RXEN1)) +#define UART_CTRL2 UCSR1C +#define UART_CTRL2_DATA ( (1<<URSEL1) | (1<<UCSZ11) | (1<<UCSZ10)) +#define UART_DATA UDR1 +#endif + +#endif // #ifndef _MEGA162_H_ diff --git a/Bootloader/mega169.h b/Bootloader/mega169.h new file mode 100644 index 0000000..27918e1 --- /dev/null +++ b/Bootloader/mega169.h @@ -0,0 +1,23 @@ +#ifndef _MEGA169_H_ +#define _MEGA169_H_ + +#define DEVTYPE_ISP 0x78 +#define DEVTYPE_BOOT 0x79 + +#define SIG_BYTE3 0x1E +#define SIG_BYTE2 0x94 +#define SIG_BYTE1 0x05 + +#define UART_BAUD_HIGH UBRRH +#define UART_BAUD_LOW UBRRL +#define UART_STATUS UCSRA +#define UART_TXREADY UDRE +#define UART_RXREADY RXC +#define UART_DOUBLE U2X +#define UART_CTRL UCSRB +#define UART_CTRL_DATA ((1<<TXEN) | (1<<RXEN)) +#define UART_CTRL2 UCSRC +#define UART_CTRL2_DATA ((1<<UCSZ1) | (1<<UCSZ0)) +#define UART_DATA UDR + +#endif // #ifndef _MEGA169_H_ diff --git a/Bootloader/mega32.h b/Bootloader/mega32.h new file mode 100644 index 0000000..b09db16 --- /dev/null +++ b/Bootloader/mega32.h @@ -0,0 +1,25 @@ +#ifndef _MEGA32_H_ +#define _MEGA32_H_ + +/* Part-Code ISP */ +#define DEVTYPE_ISP 0x72 +/* Part-Code Boot */ +#define DEVTYPE_BOOT 0x73 + +#define SIG_BYTE1 0x1E +#define SIG_BYTE2 0x95 +#define SIG_BYTE3 0x02 + +#define UART_BAUD_HIGH UBRRH +#define UART_BAUD_LOW UBRRL +#define UART_STATUS UCSRA +#define UART_TXREADY UDRE +#define UART_RXREADY RXC +#define UART_DOUBLE U2X +#define UART_CTRL UCSRB +#define UART_CTRL_DATA ((1<<TXEN) | (1<<RXEN)) +#define UART_CTRL2 UCSRC +#define UART_CTRL2_DATA ((1<<URSEL) | (1<<UCSZ1) | (1<<UCSZ0)) +#define UART_DATA UDR + +#endif // #ifndef _MEGA32_H_ diff --git a/Bootloader/mega324p.h b/Bootloader/mega324p.h new file mode 100644 index 0000000..c29f0e8 --- /dev/null +++ b/Bootloader/mega324p.h @@ -0,0 +1,17 @@ +#ifndef _MEGA324P_H_ +#define _MEGA324P_H_ + +/* I (M. Thomas) could not find an official Boot-ID + for the ATmega324P so pretend it's an ATmega32 */ +/* Part-Code ISP */ +#define DEVTYPE_ISP 0x72 +/* Part-Code Boot */ +#define DEVTYPE_BOOT 0x73 + +#define SIG_BYTE1 0x1E +#define SIG_BYTE2 0x95 +#define SIG_BYTE3 0x08 + +#include "megaxx4p.h" + +#endif // #ifndef _MEGA324P_H_ diff --git a/Bootloader/mega64.h b/Bootloader/mega64.h new file mode 100644 index 0000000..22009c8 --- /dev/null +++ b/Bootloader/mega64.h @@ -0,0 +1,39 @@ +#ifndef _MEGA64_H_ +#define _MEGA64_H_ + +/* Part-Code ISP */ +#define DEVTYPE_ISP 0x45 +/* Part-Code Boot */ +#define DEVTYPE_BOOT 0x46 + +#define SIG_BYTE1 0x1E +#define SIG_BYTE2 0x96 +#define SIG_BYTE3 0x02 + +#ifndef UART_USE_SECOND +#define UART_BAUD_HIGH UBRR0H +#define UART_BAUD_LOW UBRR0L +#define UART_STATUS UCSR0A +#define UART_TXREADY UDRE0 +#define UART_RXREADY RXC0 +#define UART_DOUBLE U2X0 +#define UART_CTRL UCSR0B +#define UART_CTRL_DATA ((1<<TXEN0) | (1<<RXEN0)) +#define UART_CTRL2 UCSR0C +#define UART_CTRL2_DATA ((1<<UCSZ01) | (1<<UCSZ00)) +#define UART_DATA UDR0 +#else +#define UART_BAUD_HIGH UBRR1H +#define UART_BAUD_LOW UBRR1L +#define UART_STATUS UCSR1A +#define UART_TXREADY UDRE1 +#define UART_RXREADY RXC1 +#define UART_DOUBLE U2X1 +#define UART_CTRL UCSR1B +#define UART_CTRL_DATA ((1<<TXEN1) | (1<<RXEN1)) +#define UART_CTRL2 UCSR1C +#define UART_CTRL2_DATA ((1<<UCSZ11) | (1<<UCSZ10)) +#define UART_DATA UDR1 +#endif + +#endif // #ifndef _MEGA64_H_ diff --git a/Bootloader/mega644.h b/Bootloader/mega644.h new file mode 100644 index 0000000..0926944 --- /dev/null +++ b/Bootloader/mega644.h @@ -0,0 +1,42 @@ +#ifndef _MEGA644_H_ +#define _MEGA644_H_ + +/* I (M. Thomas) could not find an official Boot-ID + for the ATmega644 so pretend it's an ATmega64 */ +/* Part-Code ISP */ +#define DEVTYPE_ISP 0x45 +/* Part-Code Boot */ +#define DEVTYPE_BOOT 0x46 + +#define SIG_BYTE1 0x1E +#define SIG_BYTE2 0x96 +#define SIG_BYTE3 0x09 + +#define UART_BAUD_HIGH UBRR0H +#define UART_BAUD_LOW UBRR0L +#define UART_STATUS UCSR0A +#define UART_TXREADY UDRE0 +#define UART_RXREADY RXC0 +#define UART_DOUBLE U2X0 +#define UART_CTRL UCSR0B +#define UART_CTRL_DATA ((1<<TXEN0) | (1<<RXEN0)) +#define UART_CTRL2 UCSR0C +#define UART_CTRL2_DATA ( (1<<UCSZ01) | (1<<UCSZ00)) +#define UART_DATA UDR0 + +#define WDT_OFF_SPECIAL +static inline void bootloader_wdt_off(void) +{ + cli(); + wdt_reset(); + /* Clear WDRF in MCUSR */ + MCUSR &= ~(1<<WDRF); + /* Write logical one to WDCE and WDE */ + /* Keep old prescaler setting to prevent unintentional time-out */ + WDTCSR |= (1<<WDCE) | (1<<WDE); + /* Turn off WDT */ + WDTCSR = 0x00; +} + + +#endif // #ifndef _MEGA644_H_ diff --git a/Bootloader/mega644p.h b/Bootloader/mega644p.h new file mode 100644 index 0000000..4170480 --- /dev/null +++ b/Bootloader/mega644p.h @@ -0,0 +1,17 @@ +#ifndef _MEGA644P_H_ +#define _MEGA644P_H_ + +/* I (M. Thomas) could not find an official Boot-ID + for the ATmega644P so pretend it's an ATmega64 */ +/* Part-Code ISP */ +#define DEVTYPE_ISP 0x45 +/* Part-Code Boot */ +#define DEVTYPE_BOOT 0x46 + +#define SIG_BYTE1 0x1E +#define SIG_BYTE2 0x96 +#define SIG_BYTE3 0x0A + +#include "megaxx4p.h" + +#endif // #ifndef _MEGA644P_H_ diff --git a/Bootloader/mega8.h b/Bootloader/mega8.h new file mode 100644 index 0000000..d101c97 --- /dev/null +++ b/Bootloader/mega8.h @@ -0,0 +1,25 @@ +#ifndef _MEGA8_H_ +#define _MEGA8_H_ + +/* Part-Code ISP */ +#define DEVTYPE_ISP 0x76 +/* Part-Code BOOT */ +#define DEVTYPE_BOOT 0x77 + +#define SIG_BYTE1 0x1E +#define SIG_BYTE2 0x93 +#define SIG_BYTE3 0x07 + +#define UART_BAUD_HIGH UBRRH +#define UART_BAUD_LOW UBRRL +#define UART_STATUS UCSRA +#define UART_TXREADY UDRE +#define UART_RXREADY RXC +#define UART_DOUBLE U2X +#define UART_CTRL UCSRB +#define UART_CTRL_DATA ((1<<TXEN) | (1<<RXEN)) +#define UART_CTRL2 UCSRC +#define UART_CTRL2_DATA ((1<<URSEL) | (1<<UCSZ1) | (1<<UCSZ0)) +#define UART_DATA UDR + +#endif // #ifndef _MEGA8_H_ diff --git a/Bootloader/megaxx4p.h b/Bootloader/megaxx4p.h new file mode 100644 index 0000000..635eaf7 --- /dev/null +++ b/Bootloader/megaxx4p.h @@ -0,0 +1,47 @@ +#ifndef _MEGAxx4_H_ +#define _MEGAxx4_H_ + +#ifndef UART_USE_SECOND +/* UART 0 */ +#define UART_BAUD_HIGH UBRR0H +#define UART_BAUD_LOW UBRR0L +#define UART_STATUS UCSR0A +#define UART_TXREADY UDRE0 +#define UART_RXREADY RXC0 +#define UART_DOUBLE U2X0 +#define UART_CTRL UCSR0B +#define UART_CTRL_DATA ((1<<TXEN0) | (1<<RXEN0)) +#define UART_CTRL2 UCSR0C +#define UART_CTRL2_DATA ( (1<<UCSZ01) | (1<<UCSZ00)) +#define UART_DATA UDR0 +#else +/* UART 1 */ +#define UART_BAUD_HIGH UBRR1H +#define UART_BAUD_LOW UBRR1L +#define UART_STATUS UCSR1A +#define UART_TXREADY UDRE1 +#define UART_RXREADY RXC1 +#define UART_DOUBLE U2X1 +#define UART_CTRL UCSR1B +#define UART_CTRL_DATA ((1<<TXEN1) | (1<<RXEN1)) +#define UART_CTRL2 UCSR1C +#define UART_CTRL2_DATA ( (1<<UCSZ11) | (1<<UCSZ10)) +#define UART_DATA UDR1 +#endif + +#define WDT_OFF_SPECIAL + +static inline void bootloader_wdt_off(void) +{ + cli(); + wdt_reset(); + /* Clear WDRF in MCUSR */ + MCUSR &= ~(1<<WDRF); + /* Write logical one to WDCE and WDE */ + /* Keep old prescaler setting to prevent unintentional time-out */ + WDTCSR |= (1<<WDCE) | (1<<WDE); + /* Turn off WDT */ + WDTCSR = 0x00; +} + +#endif // #ifndef _MEGA644_H_ diff --git a/Bootloader/readme.txt b/Bootloader/readme.txt new file mode 100644 index 0000000..b4c3486 --- /dev/null +++ b/Bootloader/readme.txt @@ -0,0 +1,267 @@ + +====================================================== + + ATMEL AVR UART Bootloader for AVR-GCC/avr-libc + + by Martin Thomas, Kaiserslautern, Germany + mthomas@rhrk.uni-kl.de + eversmith@heizung-thomas.de + http://www.siwawi.arubi.uni-kl.de/avr_projects + + ** Addtional code and improvements contributed ** + ** by Uwe Bonnes, Bjoern Riemer and Olaf Rempel. ** + + Eearly versions of this bootloader-code have been + based on the AVR Butterfly bootloader-source REV02 + which has been available from atmel.com. + +====================================================== + + +Programming-Software (on the "PC-Side"): + +* AVRProg (included in AVRStudio) available at www.atmel.com. + MS-Windows only. AVRProg can be used as stand-alone application. + (avrprog.exe) + +* avrdude available at http://savannah.nongnu.org/projects/avrdude/ + "Multiplattform" + +* Installation instructions at the end of this file. + + +3. Dec. 2008 - Version 0.85 + +* disable U2X before jump to app as suggested be Alexander Döller +* moved UBRR-macros to main.c and changed them. Inspired by code from avr-libc setbaud. + (macros which are commented out (//) are from Pavel Fertser) + +6. Nov. 2008 - Version 0.84 + +* Added definitions for ATmega64 provided by Pavel Fertser - Thanks. + +12. Apr. 2008 - Version 0.83 + +* Added definitions for ATmega644P and ATmega324P +* Tested with ATmega324P, gcc 4.2.2, avr-libc 1.4.6 +* Added testapp to verify "exit bootloader" with + watchdog (n.b.: watchdog-disable called early in testapp) + +27. Jan. 2007 - Version 0.82 + +* Added definitions for ATmega644. +* Using avr-lib's eeprom-functions (old "direct-access"-code + has not been compatible with ATmega644). +* Watchdog-disable at startup (configurable): avoids problems with + repeated login to bootloader. Not needed if the bootloader is + never re-entered again between an "exit programming" and + a system-reset/power-toogle. +* Additional watchdog disable-function for ATmega644. +* Made watchdog-enable time at exit-programming a configuration-value + (define). +* Bootloader read-protection: if enabled the bootloader fakes + an empty boot-section (configurable by define) +Since more of the avr-libc functions's are used this version +should be more portable for other AVRs but the size of the +binary increases a little bit. +Make sure to disable the watchdog early in the user-application +esp. when using a "modern" AVR (i.e. ATmega48/88/168/644/324P/644P). + +3. Dec. 2006 - Version 0.81 + +* Added definitions for ATmega162. +* Fixed init for double-speed (bitmask). Thanks to Bernhard Roth + +28. May 2006 - Version 0.8beta3 + +* Supports discarding of interrupt-vectors which saves some space + if no interrupts are needed in the bootloader. Added option + in makefile to enable this feature, modified LDFLAGS, + additional code in main.c for a pseudo default_interrupt ISR. + The modified linker-scripts have been contributed by + Olaf Rempel (basicly just the .vector-section is not linked). +* Reverted the order of signatur-byte-numbers in part- + configurations to the usual order in the datasheet, + also reverted in main.c for sending the signature. +* Definitions for lock/fuse-readout. +* Updated installation-instruction at the end of this file. +* Added DEVTYPE_ISP/DEVTYPE_BOOT to part-configurations, + added configuration-option for this in main.c. +* A remark about the DEVTYPE: Usualy there are two + Part-Codes/Device-Codes. One is for ISP: AVRProg shows + the type of the AVR. The other code is for bootloading: + AVRprog shows the type plus "BOOT". When a boot-device-code + gets detected by AVRprog it "knows" how do handle the + limited functionality of bootloaders. (When receiving the + ISP-code AVRProg expects an AVR910-type programmer.) + The offset between the codes is usualy 0x01 where the + ISP-code is the smaller value, i.e. ATmega32 ISP-code + is 0x72->"ATmega32" and boot-code is 0x73->"ATmega32 BOOT". + When using avrdude the bootloader's device-code must match + the device-code in the avrdude.conf. Check the avrdude- + code to see if both codes (AVR910 and AVR109) are supported. + -- I have got some e-mails from users which have been + confused by this. Hopefully this explanation is good enough. +* This bootloader lets the watchdog do a reset when the + user selects "Exit programmer" (i.e. in AVRProg) after an + update. Make sure to disable or reset the watchdog early in + your application. + +27. May 2006 - Version 0.8beta2 + +* More very well done improvements contributed by Olaf Rempel. +* Olaf Rempel also modified the STARTUP_WAIT method. + +21. May 2006 - Version 0.8beta + +* Version contributed by Olaf Rempel. He has done a lot of modifications. + -> "cleaner code", smaller binaries. + +09. Feb. 2006 - Version 0.75 + +* additional STARTUP_WAIT support contributed by Bjoern Riemer + +18. Aug. 2005 - Version 0.74 + +* AT90CAN128 support contributed by Uwe Bonnes +* Makefile modifications contributed by Uwe Bonnes + +23. Feb. 2005 - Version 0.7 + +* (Version 0.6 has never been available on the web-page) +* ATmega128 support +* code cleanup +* This version has been tested with ATmega8, ATmega32 and + ATmega128 + +7. Apr. 2004 - Version 0.5 + +* added different startup-methods +* compatible with ATmega8 now +* included makefile adapted to ATmega8 now + (ATmega16 options still available) +* fixed jump to application which did not work + reliably before +* tested with ATmega8 +* minimal options and startup-code result in + bootloader-size < 512 words + +6. Apr. 2004 - Version 0.4 + +* Buffered read of chars from UART during programming +since eeprom-write is too slow for unbuffered +operation. So EEPROM-upload does work now. +* Added BOOTICE-mode to flash JTAGICE-compatible +hardware (ATmega16@7,3Mhz) (if you know about BOOTICE, +you may unterstand why this has been added, if not +just keep the option disabled) +* small changes in (my)boot.h (lock-bit-mask) found +out during the development of the STK-500-compatible +bootloader. But setting lock-bits still does not +work with this bootloader. +* read of the low-fuse byte works (high byte still TODO) +* read of the lock-byte works (write still TODO) + +27. Mar 2004 - Version 0.3 + +Felt that as much functions from avr-libc's boot.h +as possible should be used without modifications. +Latest CVS-version of boot.h is included. +Only the read-routine is still "self-made" based +on ATMELs assembler-code. +EEPROM write on Mega16 does not work (and did not +work with V0.2 too). May be caused by my old Mega16 +chip. Needs testing. Flash read/write and EEPROM +read works. Still only tested with ATmega16. +This version may not work with the ATmega169 any +more. + +24. Mar 2004 - Version 0.2 + +During the development of a data-logger application +with the AVR-Butterfly there was a need to make +some changes in the bootloader. The same problem +again: no IAR compiler. The same way to solve the +problem: a port of the code to avr-gcc/avr-libc. +So this code is based on the ATMEL Butterfly +bootloader source code Rev 0.2 for IAR. + +The bootloader-port for the Butterfly which mimics +the complete functionality of the original +BF-bootloader is availabe at: +www.siwawi.arubi.uni-kl.de/avr_projects + +Atmel used a separate "lib" written in "pure" +assembly to access the low-level functions +for flash read/write. Well, so far I +don't know how to use "mixed language sources" +with the avr-gcc toolchain, so the low-level +routines have been implemented as inline assembler. +The avr-libc boot.h module written by Eric +Weddington served as a template Three of the four +low-level routines found in lowlevel.c come from +boot.h with minimal changes. The read routine has +been developed based on the ATMEL assembler code. + +Ignore the fuse and lock-bit readout. Read and Set is +not enabled (TODO). + + +--------------- Installation ----------------- + +- Change the MCU type in the makefile. + +- Change the boot(loader)-size in Makefile. The needed + space depends on the features selected in main.c + +- Set baudrate in main.c, a doublespeed configuration-option + is available too. + +- Change the F_CPU in main.c to the clock-frequency + of your board. See the datasheet for frequencies + with minimum error at the selected baudrate. + +- Select the start-condition in main.c. + +- Please use at least avr-gcc 3.3.1/avr-libc 1.0 + or WINAVR Sept. 2003 or later to compile and link + this bootloader. + +- Upload the hex-File to the AVR (STK500, STK200, SP12 + evertool, AVR910 etc.) + +- Program the "Boot Flash section size" (BOOTSZ fuses) + according to the boot-size selected in the makefile + i.e. BOOTSZ=00 for boot-size 1024 words (2048 bytes) + on ATmega16 + +- enable the BOOT Reset Vector fuse (BOOTRST=0) + +- Set the lock bits to protect the bootloader from + SPM-writes (Boot Loader Protection Mode 2 in STK500- + plugin) so that it can not overwrite itself. + +- Connect the AVR UART Pins via level-shifter/inverter + (i.e. MAX232) to your PCs COM-Port. + +- Reset the AVR while fullfilling the bootloader start- + condition. (Default: selected pin connected to GND). + The condition must be "true" until you see the + AVRPROG dialog or avrdude connects. + +- Start AVRPROG (AVRStudio/Tools or stand-alone avrprog.exe) + AVRDUDE is supported too, check it's manual + for command-line options. Read the text above for + information about Device-Types and AVRDUDE + +- AVRPROG or AVRDUDE should detect the bootloader. + +- see AVRStudio's online-help for more information how + to use AVRPROG + +- make sure to EXIT from AVRPROG (button) to start + your main-application or toogle power/reset. + + +Feedback welcome, Good luck. +Martin |