--- /dev/null
+/**
+ * \file
+ * <!--
+ * This file is part of BeRTOS.
+ *
+ * Bertos is free software; you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License as published by
+ * the Free Software Foundation; either version 2 of the License, or
+ * (at your option) any later version.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ * GNU General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with this program; if not, write to the Free Software
+ * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
+ *
+ * As a special exception, you may use this file as part of a free software
+ * library without restriction. Specifically, if other files instantiate
+ * templates or use macros or inline functions from this file, or you compile
+ * this file and link it with other files to produce an executable, this
+ * file does not by itself cause the resulting executable to be covered by
+ * the GNU General Public License. This exception does not however
+ * invalidate any other reasons why the executable file might be covered by
+ * the GNU General Public License.
+ *
+ * Copyright 2003, 2004, 2006 Develer S.r.l. (http://www.develer.com/)
+ * Copyright 2000 Bernardo Innocenti <bernie@codewiz.org>
+ *
+ * -->
+ *
+ * \brief Triface Bootloader.
+ *
+ * \version $Id$
+ *
+ * \author Stefano Fedrigo <aleph@develer.com>
+ * \author Francesco Sacchi <batt@develer.com>
+ * \author Daniele Basile <asterix@develer.com>
+ */
+
+
+#ifndef BOOT_CONFIG_H
+#define BOOT_CONFIG_H
+
+/// Enable watchdog timer.
+#define CONFIG_WATCHDOG 0
+
+/**
+ * Serial port number for kdebug console
+ */
+#define CONFIG_KDEBUG_PORT 1
+
+/**
+ * Serial port baud rate for kdebug console
+ */
+#define CONFIG_KDEBUG_BAUDRATE 115200
+
+/**
+ * printf formatter confguration.
+ *
+ * \sa PRINTF_DISABLED
+ * \sa PRINTF_NOMODIFIERS
+ * \sa PRINTF_REDUCED
+ * \sa PRINTF_NOFLOAT
+ * \sa PRINTF_FULL
+ */
+#undef CONFIG_PRINTF
+#define CONFIG_PRINTF PRINTF_NOMODIFIERS
+
+/**
+ * Bootloader section size.
+ * \note Remember to update this define when changing bootloader size fuses.
+ */
+#define CONFIG_BOOT_SIZE 8192
+
+/**
+ * \name Xmodem parameters
+ * \{
+ */
+#define CONFIG_XMODEM_RECV 1
+#define CONFIG_XMODEM_SEND 0
+#define CONFIG_XMODEM_1KCRC 0
+/* \} */
+
+/**
+ * Multithreading kernel.
+ *
+ * \sa config_kern.h
+ */
+#define CONFIG_KERNEL 0
+
+/**
+ * \name Serial driver parameters
+ * \{
+ */
+ /** [bytes] Size of the outbound FIFO buffer for port 0. */
+ #define CONFIG_UART0_TXBUFSIZE 32
+
+ /** [bytes] Size of the inbound FIFO buffer for port 0. */
+ #define CONFIG_UART0_RXBUFSIZE 64
+
+ /** [bytes] Size of the outbound FIFO buffer for port 1. */
+ #define CONFIG_UART1_TXBUFSIZE 32
+
+ /** [bytes] Size of the inbound FIFO buffer for port 1. */
+ #define CONFIG_UART1_RXBUFSIZE 64
+
+ /** [bytes] Size of the outbound FIFO buffer for SPI port (AVR only). */
+ #define CONFIG_SPI_TXBUFSIZE 16
+
+ /** [bytes] Size of the inbound FIFO buffer for SPI port (AVR only). */
+ #define CONFIG_SPI_RXBUFSIZE 32
+
+ /** SPI data order (AVR only). */
+ #define CONFIG_SPI_DATA_ORDER SER_MSB_FIRST
+
+ /** SPI clock division factor (AVR only). */
+ #define CONFIG_SPI_CLOCK_DIV 16
+
+ /** SPI clock polarity: 0 = normal low, 1 = normal high (AVR only). */
+ #define CONFIG_SPI_CLOCK_POL 0
+
+ /** SPI clock phase: 0 = sample on first edge, 1 = sample on second clock edge (AVR only). */
+ #define CONFIG_SPI_CLOCK_PHASE 0
+
+ /** Default transmit timeout (ms). Set to -1 to disable timeout support */
+ #define CONFIG_SER_TXTIMEOUT 250
+
+ /** Default receive timeout (ms). Set to -1 to disable timeout support */
+ #define CONFIG_SER_RXTIMEOUT 250
+
+ /** Use RTS/CTS handshake */
+ #define CONFIG_SER_HWHANDSHAKE 0
+
+ /** Default baud rate (set to 0 to disable) */
+ #define CONFIG_SER_DEFBAUDRATE 0
+
+ /** Host Port Baud Rate */
+ #define CONFIG_SER_HOSTPORTBAUDRATE 115200
+
+ /** Host Port */
+ #define CONFIG_SER_HOSTPORT 0
+
+ /** Enable ser_gets() and ser_gets_echo() */
+ #define CONFIG_SER_GETS 1
+
+ /** Enable second serial port in emulator. */
+ #define CONFIG_EMUL_UART1 0
+
+ /**
+ * Transmit always something on serial port 0 TX
+ * to avoid interference when sending burst of data,
+ * using AVR multiprocessor serial mode
+ */
+ #define CONFIG_SER_TXFILL 0
+
+ #define CONFIG_SER_STROBE 0
+/*\}*/
+
+/// Hardware timer selection for drv/timer.c
+#define CONFIG_TIMER TIMER_ON_OUTPUT_COMPARE0
+
+/// Disable tests
+#define CONFIG_TEST 0
+#endif /* BOOT_CONFIG_H */
--- /dev/null
+/* Linker script for boot loader */
+
+OUTPUT_FORMAT("elf32-avr","elf32-avr","elf32-avr")
+OUTPUT_ARCH(avr:5)
+MEMORY
+{
+ text (rx) : ORIGIN = 0xE000, LENGTH = 8K
+ data (rw!x) : ORIGIN = 0x800060, LENGTH = 4000
+ eeprom (rw!x) : ORIGIN = 0x810000, LENGTH = 2K
+}
+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 */
+ .text :
+ {
+ KEEP(*(.vectors))
+ __ctors_start = . ;
+ *(.ctors)
+ __ctors_end = . ;
+ __dtors_start = . ;
+ *(.dtors)
+ __dtors_end = . ;
+ *(.progmem.gcc*)
+ *(.progmem*)
+ . = ALIGN(2);
+ KEEP(*(.init0)) /* Start here after reset. */
+ KEEP(*(.init1))
+ KEEP(*(.init2)) /* Clear __zero_reg__, set up stack pointer. */
+ KEEP(*(.init3))
+ KEEP(*(.init4)) /* Initialize data and BSS. */
+ KEEP(*(.init5))
+ KEEP(*(.init6)) /* C++ constructors. */
+ KEEP(*(.init7))
+ KEEP(*(.init8))
+ KEEP(*(.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 .data.* .rodata .rodata.*)
+ *(.gnu.linkonce.d*)
+ . = ALIGN(2);
+ _edata = . ;
+ PROVIDE (__data_end = .) ;
+ } > data
+ .bss SIZEOF(.data) + ADDR(.data) :
+ {
+ PROVIDE (__bss_start = .) ;
+ *(.bss .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 :
+ AT (ADDR (.text) + SIZEOF (.text) + SIZEOF (.data))
+ {
+ *(.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) }
+}
--- /dev/null
+#
+# $Id: boot.mk 15184 2007-02-16 15:09:23Z batt $
+# Copyright 2002, 2003, 2004 Develer S.r.l. (http://www.develer.com/)
+# All rights reserved.
+#
+# Makefile fragment for boot application.
+#
+# Author: Bernardo Innocenti <bernie@develer.com>
+#
+
+
+# Set to 1 for debug builds
+boot_DEBUG = 1
+
+# Our target application
+TRG += boot
+
+boot_MCU = atmega64
+boot_CSRC = \
+ boot/main.c \
+ mware/xmodem.c \
+ drv/ser.c \
+ cpu/avr/drv/ser_avr.c \
+ cpu/avr/drv/flash_avr.c \
+ drv/timer.c \
+ algos/crc.c
+
+boot_CROSS = avr-
+boot_CPPFLAGS = -D'ARCH=(ARCH_TRIFACE|ARCH_BOOT)' -Iboot -Icpu/avr
+boot_CFLAGS = -Os -mcall-prologues
+boot_LDSCRIPT = boot/boot.ld
+boot_LDFLAGS = -Wl,--relax
+
+# Debug stuff
+ifeq ($(boot_DEBUG),1)
+ boot_CFLAGS += -D_DEBUG
+ boot_PCSRC += drv/kdebug.c mware/formatwr.c
+endif
+
--- /dev/null
+/**
+ * \file
+ * <!--
+ * This file is part of BeRTOS.
+ *
+ * Bertos is free software; you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License as published by
+ * the Free Software Foundation; either version 2 of the License, or
+ * (at your option) any later version.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ * GNU General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with this program; if not, write to the Free Software
+ * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
+ *
+ * As a special exception, you may use this file as part of a free software
+ * library without restriction. Specifically, if other files instantiate
+ * templates or use macros or inline functions from this file, or you compile
+ * this file and link it with other files to produce an executable, this
+ * file does not by itself cause the resulting executable to be covered by
+ * the GNU General Public License. This exception does not however
+ * invalidate any other reasons why the executable file might be covered by
+ * the GNU General Public License.
+ *
+ * Copyright 2003, 2004, 2006 Develer S.r.l. (http://www.develer.com/)
+ * Copyright 2000 Bernardo Innocenti <bernie@codewiz.org>
+ *
+ * -->
+ *
+ * \brief Macro for boot loader.
+ *
+ *
+ * \version $Id$
+ *
+ * \author Daniele Basile <asterix@develer.com>
+ * \author Francesco Sacchi <batt@develer.com>
+ */
+
+#ifndef HW_BOOT_H
+#define HW_BOOT_H
+
+#include <avr/io.h>
+
+/* Set up function pointer to RESET vector */
+void (*rom_start)(void) NORETURN = 0x0000;
+
+#define START_APP() rom_start()
+
+#define BOOT_INIT do \
+{ \
+ /* Enable change of Interrupt Vectors */ \
+ MCUCR = BV(IVCE); \
+ /* Move interrupts to boot Flash section */ \
+ MCUCR = BV(IVSEL); \
+} while(0)
+
+#define BOOT_END do \
+{ \
+ /* Enable change of Interrupt Vectors */ \
+ MCUCR = BV(IVCE); \
+ /* Move interrupts to boot Flash section */ \
+ MCUCR = 0; \
+} while(0)
+
+#endif // HW_BOOT_H
+
--- /dev/null
+/**
+ * \file
+ * <!--
+ * This file is part of BeRTOS.
+ *
+ * Bertos is free software; you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License as published by
+ * the Free Software Foundation; either version 2 of the License, or
+ * (at your option) any later version.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ * GNU General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with this program; if not, write to the Free Software
+ * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
+ *
+ * As a special exception, you may use this file as part of a free software
+ * library without restriction. Specifically, if other files instantiate
+ * templates or use macros or inline functions from this file, or you compile
+ * this file and link it with other files to produce an executable, this
+ * file does not by itself cause the resulting executable to be covered by
+ * the GNU General Public License. This exception does not however
+ * invalidate any other reasons why the executable file might be covered by
+ * the GNU General Public License.
+ *
+ * Copyright 2003, 2004, 2006 Develer S.r.l. (http://www.develer.com/)
+ * Copyright 2000 Bernardo Innocenti <bernie@codewiz.org>
+ *
+ * -->
+ *
+ * \brief Flash boot loader main.
+ * This is a simple generic bootloader app.
+ * It requires only a serial port to work.
+ * Try to receive a file through XMODEM protocol
+ * and flash it on program memory.
+ * BOOT_INIT, BOOT_END are macros used to perform special operations
+ * respectively at boot start and boot end and are CPU dependant.
+ * The macro START_APP() jumps to main application start.
+ *
+ * \version $Id$
+ * \author Stefano Fedrigo <aleph@develer.com>
+ * \author Francesco Sacchi <batt@develer.com>
+ * \author Daniele Basile <asterix@develer.com>
+ */
+
+#include <mware/xmodem.h>
+#include <cfg/compiler.h>
+#include <cfg/debug.h>
+#include <cfg/macros.h> /* BV() */
+
+#include <drv/wdt.h>
+#include <drv/ser.h>
+#include <drv/timer.h>
+#include <drv/flash_avr.h>
+
+#include "hw/hw_boot.h"
+
+#include <string.h>
+
+int main(void)
+{
+ KFile fd;
+
+
+ // Set up flash programming functions.
+ flash_avr_init(&fd);
+
+ IRQ_ENABLE;
+
+ BOOT_INIT;
+
+ kdbg_init();
+ timer_init();
+ kprintf("Bertuccia");
+ /* Open the main communication port */
+ Serial *host_port = ser_open(CONFIG_SER_HOSTPORT);
+ ser_setbaudrate(host_port, CONFIG_SER_HOSTPORTBAUDRATE);
+
+ xmodem_recv(host_port, &fd);
+ fd.close(&fd);
+
+ IRQ_DISABLE;
+
+ BOOT_END;
+
+ START_APP();
+}
+++ /dev/null
-/**
- * \file
- * <!--
- * This file is part of BeRTOS.
- *
- * Bertos is free software; you can redistribute it and/or modify
- * it under the terms of the GNU General Public License as published by
- * the Free Software Foundation; either version 2 of the License, or
- * (at your option) any later version.
- *
- * This program is distributed in the hope that it will be useful,
- * but WITHOUT ANY WARRANTY; without even the implied warranty of
- * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
- * GNU General Public License for more details.
- *
- * You should have received a copy of the GNU General Public License
- * along with this program; if not, write to the Free Software
- * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
- *
- * As a special exception, you may use this file as part of a free software
- * library without restriction. Specifically, if other files instantiate
- * templates or use macros or inline functions from this file, or you compile
- * this file and link it with other files to produce an executable, this
- * file does not by itself cause the resulting executable to be covered by
- * the GNU General Public License. This exception does not however
- * invalidate any other reasons why the executable file might be covered by
- * the GNU General Public License.
- *
- * Copyright 2003, 2004, 2006 Develer S.r.l. (http://www.develer.com/)
- * Copyright 2000 Bernardo Innocenti <bernie@codewiz.org>
- *
- * -->
- *
- * \brief Macro for boot loader.
- *
- *
- * \version $Id$
- *
- * \author Daniele Basile <asterix@develer.com>
- * \author Francesco Sacchi <batt@develer.com>
- */
-
-#ifndef HW_BOOT_H
-#define HW_BOOT_H
-
-#include <avr/io.h>
-
-/* Set up function pointer to RESET vector */
-void (*rom_start)(void) NORETURN = 0x0000;
-
-#define START_APP() rom_start()
-
-#define BOOT_INIT do \
-{ \
- /* Enable change of Interrupt Vectors */ \
- MCUCR = BV(IVCE); \
- /* Move interrupts to boot Flash section */ \
- MCUCR = BV(IVSEL); \
-} while(0)
-
-#define BOOT_END do \
-{ \
- /* Enable change of Interrupt Vectors */ \
- MCUCR = BV(IVCE); \
- /* Move interrupts to boot Flash section */ \
- MCUCR = 0; \
-} while(0)
-
-#endif // HW_BOOT_H
-
triface_PCSRC += bertos/mware/formatwr.c
-triface_CFLAGS = -O2 -D'ARCH=0' -fno-strict-aliasing -Iapp/triface -Ibertos/cpu/avr
+triface_CFLAGS = -O2 -D'ARCH=(ARCH_TRIFACE)' -fno-strict-aliasing -Iapp/triface -Ibertos/cpu/avr
triface_LDFLAGS = -Wl
triface_MCU = atmega64
triface_PCSRC += bertos/drv/kdebug.c
endif
+
+boot_EMBEDDED_TGT = 1
+# Set to 1 for debug builds
+boot_DEBUG = 1
+
+# Our target application
+TRG += boot
+
+boot_MCU = atmega64
+boot_CSRC = \
+ app/triface/boot/main.c \
+ bertos/mware/xmodem.c \
+ bertos/drv/ser.c \
+ bertos/cpu/avr/drv/ser_avr.c \
+ bertos/cpu/avr/drv/flash_avr.c \
+ bertos/drv/timer.c \
+ bertos/algos/crc.c
+
+boot_CROSS = avr-
+boot_CPPFLAGS = -D'ARCH=(ARCH_TRIFACE|ARCH_BOOT)' -Iapp/boot -Ibertos/cpu/avr
+boot_CFLAGS = -Os -mcall-prologues
+boot_LDSCRIPT = app/triface/boot/boot.ld
+boot_LDFLAGS = -Wl,--relax
+
+# Debug stuff
+ifeq ($(boot_DEBUG),1)
+ boot_CFLAGS += -D_DEBUG
+ boot_PCSRC += bertos/drv/kdebug.c bertos/mware/formatwr.c
+endif
+