diff --git a/firmware/Makefile b/firmware/Makefile index 5b220d9ad7..7785798352 100644 --- a/firmware/Makefile +++ b/firmware/Makefile @@ -58,6 +58,10 @@ ifeq ($(USE_SMART_BUILD),) USE_SMART_BUILD = no endif +ifeq ($(USE_BOOTLOADER),) + USE_BOOTLOADER = no +endif + # # Build global options ############################################################################## @@ -137,6 +141,10 @@ include $(PROJECT_DIR)/controllers/system/system.mk include $(PROJECT_DIR)/controllers/trigger/trigger.mk include $(PROJECT_DIR)/console/console.mk +ifeq ($(USE_BOOTLOADER),yes) +include $(PROJECT_DIR)/bootloader/bootloader.mk +endif + # Define linker script file here ifeq ($(LDSCRIPT),) LDSCRIPT= config/stm32f4ems/STM32F407xG_CCM.ld @@ -151,6 +159,7 @@ CSRC = $(STARTUPSRC) \ $(HALSRC) \ $(PLATFORMSRC) \ $(BOARDSRC) \ + $(BOOTLOADERSRC) \ $(CHIBIOS)/os/various/syscalls.c \ $(CHIBIOS)/os/hal/lib/streams/memstreams.c \ $(CHIBIOS)/os/hal/lib/streams/chprintf.c \ @@ -222,6 +231,7 @@ INCDIR = $(PORTINC) \ $(HALINC) \ $(PLATFORMINC) \ $(BOARDINC) \ + $(BOOTLOADERINC) \ $(CHCPPINC) \ $(CHIBIOS)/os/hal/lib/streams \ $(CHIBIOS)/os/various \ diff --git a/firmware/config/stm32f4ems/STM32F407xG_CCM_bootloader.ld b/firmware/config/stm32f4ems/STM32F407xG_CCM_bootloader.ld new file mode 100644 index 0000000000..f0c267dbbc --- /dev/null +++ b/firmware/config/stm32f4ems/STM32F407xG_CCM_bootloader.ld @@ -0,0 +1,64 @@ +/* + ChibiOS - Copyright (C) 2006..2015 Giovanni Di Sirio + + Licensed under the Apache License, Version 2.0 (the "License"); + you may not use this file except in compliance with the License. + You may obtain a copy of the License at + + http://www.apache.org/licenses/LICENSE-2.0 + + Unless required by applicable law or agreed to in writing, software + distributed under the License is distributed on an "AS IS" BASIS, + WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + See the License for the specific language governing permissions and + limitations under the License. +*/ + +/* + * STM32F407xG memory setup. + * Note: Use of ram1 and ram2 is mutually exclusive with use of ram0. + */ +MEMORY +{ + bl : org = 0x08000000, len = 16k + flash : org = 0x08008000, len = 864k + ram0 : org = 0x20000000, len = 128k /* SRAM1 + SRAM2 */ + ram1 : org = 0x20000000, len = 112k /* SRAM1 */ + ram2 : org = 0x2001C000, len = 16k /* SRAM2 */ + ram3 : org = 0x00000000, len = 0 + ram4 : org = 0x10000000, len = 64k /* CCM SRAM */ + ram5 : org = 0x40024000, len = 4k /* BCKP SRAM */ + ram6 : org = 0x00000000, len = 0 + ram7 : org = 0x00000000, len = 0 +} + +/* RAM region to be used for Main stack. This stack accommodates the processing + of all exceptions and interrupts*/ +REGION_ALIAS("MAIN_STACK_RAM", ram0); + +/* RAM region to be used for the process stack. This is the stack used by + the main() function.*/ +REGION_ALIAS("PROCESS_STACK_RAM", ram0); + +/* RAM region to be used for data segment.*/ +REGION_ALIAS("DATA_RAM", ram0); + +/* RAM region to be used for BSS segment.*/ +REGION_ALIAS("BSS_RAM", ram0); + +/* RAM region to be used for the default heap.*/ +REGION_ALIAS("HEAP_RAM", ram0); + +/* Bootloader section */ +SECTIONS +{ +.bl : ALIGN(4) + { + . = ALIGN(4); + *(.bl) + *(.bl.*) + . = ALIGN(4); + } > bl AT > bl +} + +INCLUDE rules.ld diff --git a/firmware/rusefi.cpp b/firmware/rusefi.cpp index aa4a78cd62..32aebaea6e 100644 --- a/firmware/rusefi.cpp +++ b/firmware/rusefi.cpp @@ -119,6 +119,10 @@ #include "engine_emulator.h" #endif /* EFI_ENGINE_EMULATOR */ +#if defined(EFI_BOOTLOADER_INCLUDE_CODE) || defined(__DOXYGEN__) +#include "bootloader/bootloader.h" +#endif /* EFI_BOOTLOADER_INCLUDE_CODE */ + LoggingWithStorage sharedLogger("main"); bool main_loop_started = false; @@ -251,5 +255,10 @@ int getRusEfiVersion(void) { return 123; // this is here to make the compiler happy about the unused array if (UNUSED_CCM_SIZE[0] * 0 != 0) return 3211; // this is here to make the compiler happy about the unused array +#if defined(EFI_BOOTLOADER_INCLUDE_CODE) || defined(__DOXYGEN__) + // make bootloader code happy too + if (initBootloader() != 0) + return 123; +#endif /* EFI_BOOTLOADER_INCLUDE_CODE */ return 20170529; }