From cbab5cfe6696b8c288835b62b8c51ceb53cb7262 Mon Sep 17 00:00:00 2001 From: qwert Date: Wed, 16 Jul 2008 14:15:27 +0000 Subject: [PATCH] Import boot from triface, not working for now. git-svn-id: https://src.develer.com/svnoss/bertos/trunk@1485 38d2e660-2303-0410-9eaa-f027e97ec537 --- app/triface/boot/appconfig.h | 167 +++++++++++++++++++++++++++ app/triface/boot/boot.ld | 170 ++++++++++++++++++++++++++++ app/triface/boot/boot.mk | 39 +++++++ app/triface/{ => boot}/hw/hw_boot.h | 0 app/triface/boot/main.c | 90 +++++++++++++++ app/triface/triface.mk | 32 +++++- 6 files changed, 497 insertions(+), 1 deletion(-) create mode 100644 app/triface/boot/appconfig.h create mode 100644 app/triface/boot/boot.ld create mode 100644 app/triface/boot/boot.mk rename app/triface/{ => boot}/hw/hw_boot.h (100%) create mode 100644 app/triface/boot/main.c diff --git a/app/triface/boot/appconfig.h b/app/triface/boot/appconfig.h new file mode 100644 index 00000000..b0a781b2 --- /dev/null +++ b/app/triface/boot/appconfig.h @@ -0,0 +1,167 @@ +/** + * \file + * + * + * \brief Triface Bootloader. + * + * \version $Id$ + * + * \author Stefano Fedrigo + * \author Francesco Sacchi + * \author Daniele Basile + */ + + +#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 */ diff --git a/app/triface/boot/boot.ld b/app/triface/boot/boot.ld new file mode 100644 index 00000000..733f1e99 --- /dev/null +++ b/app/triface/boot/boot.ld @@ -0,0 +1,170 @@ +/* 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) } +} diff --git a/app/triface/boot/boot.mk b/app/triface/boot/boot.mk new file mode 100644 index 00000000..30dc1b08 --- /dev/null +++ b/app/triface/boot/boot.mk @@ -0,0 +1,39 @@ +# +# $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 +# + + +# 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 + diff --git a/app/triface/hw/hw_boot.h b/app/triface/boot/hw/hw_boot.h similarity index 100% rename from app/triface/hw/hw_boot.h rename to app/triface/boot/hw/hw_boot.h diff --git a/app/triface/boot/main.c b/app/triface/boot/main.c new file mode 100644 index 00000000..093a7f91 --- /dev/null +++ b/app/triface/boot/main.c @@ -0,0 +1,90 @@ +/** + * \file + * + * + * \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 + * \author Francesco Sacchi + * \author Daniele Basile + */ + +#include +#include +#include +#include /* BV() */ + +#include +#include +#include +#include + +#include "hw/hw_boot.h" + +#include + +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(); +} diff --git a/app/triface/triface.mk b/app/triface/triface.mk index e3792be5..9e89cf6c 100644 --- a/app/triface/triface.mk +++ b/app/triface/triface.mk @@ -44,7 +44,7 @@ triface_CSRC = \ 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 @@ -56,3 +56,33 @@ ifeq ($(triface_DEBUG),1) 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 + -- 2.25.1