1
0
mirror of https://bitbucket.org/librepilot/librepilot.git synced 2024-12-01 09:24:10 +01:00

build: Add support for BL_Updaters to top-level makefile

New targets:
 - make blupd_all_clean
 - make blupd_all
 - make blupd_openpilot
 - make blupd_ahrs
 - make blupd_coptercontrol
 - make blupd_pipxtreme

These targets are also included in the 'all_flight' target.
This commit is contained in:
Stacey Sheldon 2011-03-26 13:09:11 +00:00
parent 2301600f11
commit 18ea93119f
8 changed files with 172 additions and 326 deletions

View File

@ -278,20 +278,30 @@ uavobjects_clean:
#
##############################
FW_TARGETS := openpilot ahrs coptercontrol pipxtreme ins
BL_TARGETS := $(addprefix bl_, $(FW_TARGETS))
FW_TARGETS := openpilot ahrs coptercontrol pipxtreme ins
BL_TARGETS := $(addprefix bl_, $(FW_TARGETS))
BLUPD_TARGETS := $(addprefix blupd_, $(FW_TARGETS))
# FIXME: The INS build doesn't have a bootloader or bootloader
# updater yet so we need to filter them out to prevent errors.
BL_TARGETS := $(filter-out bl_ins, $(BL_TARGETS))
BLUPD_TARGETS := $(filter-out blupd_ins, $(BLUPD_TARGETS))
.PHONY: all_fw all_fw_clean
all_fw: $(addsuffix _bin, $(FW_TARGETS))
all_fw_clean: $(addsuffix _clean, $(FW_TARGETS))
.PHONY: all_bw all_bw_clean
.PHONY: all_bl all_bl_clean
all_bl: $(addsuffix _elf, $(BL_TARGETS))
all_bl_clean: $(addsuffix _clean, $(BL_TARGETS))
.PHONY: all_blupd all_blupd_clean
all_blupd: $(addsuffix _elf, $(BLUPD_TARGETS))
all_blupd_clean: $(addsuffix _clean, $(BLUPD_TARGETS))
.PHONY: all_flight all_flight_clean
all_flight: all_fw all_bl
all_flight_clean: all_fw_clean all_bl_clean
all_flight: all_fw all_bl all_blupd
all_flight_clean: all_fw_clean all_bl_clean all_blupd_clean
.PHONY: openpilot
openpilot: openpilot_bin
@ -307,6 +317,7 @@ openpilot_clean:
.PHONY: bl_openpilot
bl_openpilot: bl_openpilot_elf
bl_openpilot_bino: bl_openpilot_elf
bl_openpilot_%:
$(V1) mkdir -p $(BUILD_DIR)/bl_openpilot/dep
@ -317,6 +328,20 @@ bl_openpilot_clean:
$(V0) @echo " CLEAN $@"
$(V1) $(RM) -fr $(BUILD_DIR)/bl_openpilot
blupd_openpilot_%: bl_openpilot_bino
$(V1) mkdir -p $(BUILD_DIR)/blupd_openpilot/dep
$(V1) $(MAKE) -r --no-print-directory \
OUTDIR="$(BUILD_DIR)/blupd_openpilot" TCHAIN_PREFIX="$(ARM_SDK_PREFIX)" \
REMOVE_CMD="$(RM)" OOCD_EXE="$(OPENOCD)" \
BOARD=STM3210E_OP MODEL=HD MODEL_SUFFIX=_OP USE_BOOTLOADER=YES \
BLOBJ=$(BUILD_DIR)/bl_openpilot/OpenPilot_BL.bin.o \
-C $(ROOT_DIR)/flight/Bootloaders/BootloaderUpdater $*
.PHONY: blupd_openpilot_clean
blupd_openpilot_clean:
$(V0) @echo " CLEAN $@"
$(V1) $(RM) -fr $(BUILD_DIR)/blupd_openpilot
.PHONY: ahrs
ahrs: ahrs_bin
@ -331,6 +356,7 @@ ahrs_clean:
.PHONY: bl_ahrs
bl_ahrs: bl_ahrs_elf
bl_ahrs_bino: bl_ahrs_elf
bl_ahrs_%:
$(V1) mkdir -p $(BUILD_DIR)/bl_ahrs/dep
@ -341,6 +367,20 @@ bl_ahrs_clean:
$(V0) @echo " CLEAN $@"
$(V1) $(RM) -fr $(BUILD_DIR)/bl_ahrs
blupd_ahrs_%: bl_ahrs_bino bl_ahrs
$(V1) mkdir -p $(BUILD_DIR)/blupd_ahrs/dep
$(V1) $(MAKE) -r --no-print-directory \
OUTDIR="$(BUILD_DIR)/blupd_ahrs" TCHAIN_PREFIX="$(ARM_SDK_PREFIX)" \
REMOVE_CMD="$(RM)" OOCD_EXE="$(OPENOCD)" \
BOARD=STM32103CB_AHRS MODEL=MD USE_BOOTLOADER=YES \
BLOBJ=$(BUILD_DIR)/bl_ahrs/AHRS_BL.bin.o \
-C $(ROOT_DIR)/flight/Bootloaders/BootloaderUpdater $*
.PHONY: blupd_ahrs_clean
blupd_ahrs_clean:
$(V0) @echo " CLEAN $@"
$(V1) $(RM) -fr $(BUILD_DIR)/blupd_ahrs
.PHONY: coptercontrol
coptercontrol: coptercontrol_bin
@ -355,6 +395,7 @@ coptercontrol_clean:
.PHONY: bl_coptercontrol
bl_coptercontrol: bl_coptercontrol_elf
bl_coptercontrol_bino: bl_coptercontrol_elf
bl_coptercontrol_%:
$(V1) mkdir -p $(BUILD_DIR)/bl_coptercontrol/dep
@ -365,6 +406,20 @@ bl_coptercontrol_clean:
$(V0) @echo " CLEAN $@"
$(V1) $(RM) -fr $(BUILD_DIR)/bl_coptercontrol
blupd_coptercontrol_%: bl_coptercontrol_bino
$(V1) mkdir -p $(BUILD_DIR)/blupd_coptercontrol/dep
$(V1) $(MAKE) -r --no-print-directory \
OUTDIR="$(BUILD_DIR)/blupd_coptercontrol" TCHAIN_PREFIX="$(ARM_SDK_PREFIX)" \
REMOVE_CMD="$(RM)" OOCD_EXE="$(OPENOCD)" \
BOARD=STM32103CB_CC_Rev1 MODEL=MD MODEL_SUFFIX=_CC USE_BOOTLOADER=YES \
BLOBJ=$(BUILD_DIR)/bl_coptercontrol/CopterControl_BL.bin.o \
-C $(ROOT_DIR)/flight/Bootloaders/BootloaderUpdater $*
.PHONY: blupd_coptercontrol_clean
blupd_coptercontrol_clean:
$(V0) @echo " CLEAN $@"
$(V1) $(RM) -fr $(BUILD_DIR)/blupd_coptercontrol
.PHONY: pipxtreme
pipxtreme: pipxtreme_bin
@ -379,6 +434,7 @@ pipxtreme_clean:
.PHONY: bl_pipxtreme
bl_pipxtreme: bl_pipxtreme_elf
bl_pipxtreme_bino: bl_pipxtreme_elf
bl_pipxtreme_%:
$(V1) mkdir -p $(BUILD_DIR)/bl_pipxtreme/dep
@ -389,6 +445,21 @@ bl_pipxtreme_clean:
$(V0) @echo " CLEAN $@"
$(V1) $(RM) -fr $(BUILD_DIR)/bl_pipxtreme
blupd_pipxtreme_%: bl_pipxtreme_bino
$(V1) mkdir -p $(BUILD_DIR)/blupd_pipxtreme/dep
$(V1) $(MAKE) -r --no-print-directory \
OUTDIR="$(BUILD_DIR)/blupd_pipxtreme" TCHAIN_PREFIX="$(ARM_SDK_PREFIX)" \
REMOVE_CMD="$(RM)" OOCD_EXE="$(OPENOCD)" \
BOARD=STM32103CB_PIPXTREME MODEL=MD MODEL_SUFFIX=_CC USE_BOOTLOADER=YES \
BLOBJ=$(BUILD_DIR)/bl_pipxtreme/PipXtreme_BL.bin.o \
-C $(ROOT_DIR)/flight/Bootloaders/BootloaderUpdater $*
.PHONY: blupd_pipxtreme_clean
blupd_pipxtreme_clean:
$(V0) @echo " CLEAN $@"
$(V1) $(RM) -fr $(BUILD_DIR)/blupd_pipxtreme
.PHONY: ins
ins: ins_bin

View File

@ -22,6 +22,9 @@
# 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
#####
WHEREAMI := $(dir $(lastword $(MAKEFILE_LIST)))
TOP := $(realpath $(WHEREAMI)/../../../)
include $(TOP)/make/firmware-defs.mk
# Set developer code and compile options
# Set to YES to compile for debugging
@ -54,11 +57,6 @@ endif
FLASH_TOOL = OPENOCD
# YES enables -mthumb option to flags for source-files listed
# in SRC and CPPSRC
USE_THUMB_MODE = YES
# MCU name, submodel and board
# - MCU used for compiler-option (-mcpu)
# - MODEL used for linker-script name (-T) and passed as define
@ -160,7 +158,7 @@ CPPSRCARM =
# 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 = $(PIOSSTM32F10X)/startup_stm32f10x_$(MODEL).S
ASRC = $(PIOSSTM32F10X)/startup_stm32f10x_$(MODEL)$(MODEL_SUFFIX).S
# List Assembler source files here which must be assembled in ARM-Mode..
ASRCARM =
@ -339,44 +337,14 @@ OOCD_CL+=-c "verify_image $(OOCD_LOADFILE)"
OOCD_CL+=-c "reset run"
# terminate OOCD after programming
OOCD_CL+=-c shutdown
# ---------------------------------------------------------------------------
# Define programs and commands.
CC = $(TCHAIN_PREFIX)gcc
CPP = $(TCHAIN_PREFIX)g++
AR = $(TCHAIN_PREFIX)ar
OBJCOPY = $(TCHAIN_PREFIX)objcopy
OBJDUMP = $(TCHAIN_PREFIX)objdump
SIZE = $(TCHAIN_PREFIX)size
NM = $(TCHAIN_PREFIX)nm
REMOVE = $(REMOVE_CMD) -f
###SHELL = sh
###COPY = cp
# Define Messages
# English
MSG_ERRORS_NONE = Errors: none
MSG_BEGIN = ${quote}-------- begin (mode: $(RUN_MODE)) --------${quote}
MSG_END = ${quote}-------- end --------${quote}
MSG_MODINIT = ${quote}**** Generating ModInit.c${quote}
MSG_SIZE_BEFORE = ${quote}Size before:${quote}
MSG_SIZE_AFTER = ${quote}Size after build:${quote}
MSG_LOAD_FILE = ${quote}Creating load file:${quote}
MSG_EXTENDED_LISTING = ${quote}Creating Extended Listing/Disassembly:${quote}
MSG_SYMBOL_TABLE = ${quote}Creating Symbol Table:${quote}
MSG_LINKING = ${quote}**** Linking :${quote}
MSG_COMPILING = ${quote}**** Compiling C :${quote}
MSG_COMPILING_ARM = ${quote}**** Compiling C (ARM-only):${quote}
MSG_COMPILINGCPP = ${quote}Compiling C++ :${quote}
MSG_COMPILINGCPP_ARM = ${quote}Compiling C++ (ARM-only):${quote}
MSG_ASSEMBLING = ${quote}**** Assembling:${quote}
MSG_ASSEMBLING_ARM = ${quote}****Assembling (ARM-only):${quote}
MSG_CLEANING = ${quote}Cleaning project:${quote}
MSG_FORMATERROR = ${quote}Can not handle output-format${quote}
MSG_ASMFROMC = ${quote}Creating asm-File from C-Source:${quote}
MSG_ASMFROMC_ARM = ${quote}Creating asm-File from C-Source (ARM-only):${quote}
# List of all source files.
ALLSRC = $(ASRCARM) $(ASRC) $(SRCARM) $(SRC) $(CPPSRCARM) $(CPPSRC)
# List of all source files without directory and file-extension.
@ -392,14 +360,7 @@ DEPFILES = $(addprefix $(OUTDIR)/dep/, $(addsuffix .o.d, $(ALLSRCBASE)))
# Default target.
#all: begin gccversion sizebefore build sizeafter finished end
all: begin gccversion build sizeafter finished end
elf: $(OUTDIR)/$(TARGET).elf
lss: $(OUTDIR)/$(TARGET).lss
sym: $(OUTDIR)/$(TARGET).sym
hex: $(OUTDIR)/$(TARGET).hex
bin: $(OUTDIR)/$(TARGET).bin
all: build
ifeq ($(LOADFORMAT),ihex)
build: elf hex sym
@ -415,51 +376,6 @@ endif
endif
endif
# Eye candy.
begin:
## @echo
@echo $(MSG_BEGIN)
ifeq ($(SOURCE_BL), NULL)
@echo ${quote}Please specify the source bootloader binary with SOURCE_BL=source_name${quote}
@exit 2
endif
ifeq ($(BOARD), NULL)
@echo ${quote}Please specify the board name with BOARD=board_name (STM3210E_OP,STM32103CB_AHRS,STM32103CB_PIPXTREME,STM32103CB_CC_Rev1)${quote}
@exit 2
endif
ifeq ($(MODEL), NULL)
@echo ${quote}Please specify the chip model with MODEL=MD/HD${quote}
@exit 2
endif
python file_to_array.py $(SOURCE_BL) bl_array.h
#UNAME := $(shell python file_to_array.py $(SOURCE_BL) bl_array.h)
###########################################################################################################
finished:
## @echo $(MSG_ERRORS_NONE)
end:
@echo $(MSG_END)
## @echo
# Display sizes of sections.
ELFSIZE = $(SIZE) -A $(OUTDIR)/$(TARGET).elf
sizebefore:
# @if [ -f $(OUTDIR)/$(TARGET).elf ]; then echo; echo $(MSG_SIZE_BEFORE); $(ELFSIZE); echo; fi
sizeafter:
# @if [ -f $(OUTDIR)/$(TARGET).elf ]; then echo; echo $(MSG_SIZE_AFTER); $(ELFSIZE); echo; fi
@echo $(MSG_SIZE_AFTER)
$(ELFSIZE)
# Display compiler version information.
gccversion :
@$(CC) --version
# @echo $(ALLOBJ)
# Program the device.
ifeq ($(FLASH_TOOL),OPENOCD)
# Program the device with Dominic Rath's OPENOCD in "batch-mode", needs cfg and "reset-script".
@ -468,132 +384,71 @@ program: $(OUTDIR)/$(TARGET).elf
$(OOCD_EXE) $(OOCD_CL)
endif
# Create final output file (.hex) from ELF output file.
%.hex: %.elf
## @echo
@echo $(MSG_LOAD_FILE) $@
$(OBJCOPY) -O ihex $< $@
# Create final output file (.bin) from ELF output file.
%.bin: %.elf
## @echo
@echo $(MSG_LOAD_FILE) $@
$(OBJCOPY) -O binary $< $@
# Create extended listing file/disassambly from ELF output file.
# using objdump testing: option -C
%.lss: %.elf
## @echo
@echo $(MSG_EXTENDED_LISTING) $@
$(OBJDUMP) -h -S -C -r $< > $@
# $(OBJDUMP) -x -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 : $(ALLOBJ)
%.elf: $(ALLOBJ)
@echo $(MSG_LINKING) $@
# use $(CC) for C-only projects or $(CPP) for C++-projects:
$(CC) $(THUMB) $(CFLAGS) $(ALLOBJ) --output $@ $(LDFLAGS)
# $(CPP) $(THUMB) $(CFLAGS) $(ALLOBJ) --output $@ $(LDFLAGS)
$(eval $(call LINK_TEMPLATE, $(OUTDIR)/$(TARGET).elf, $(ALLOBJ) $(BLOBJ)))
# Assemble: create object files from assembler source files.
define ASSEMBLE_TEMPLATE
$(OUTDIR)/$(notdir $(basename $(1))).o : $(1)
## @echo
@echo $(MSG_ASSEMBLING) $$< to $$@
$(CC) -c $(THUMB) $$(ASFLAGS) $$< -o $$@
endef
$(foreach src, $(ASRC), $(eval $(call ASSEMBLE_TEMPLATE, $(src))))
# Assemble: create object files from assembler source files. ARM-only
define ASSEMBLE_ARM_TEMPLATE
$(OUTDIR)/$(notdir $(basename $(1))).o : $(1)
## @echo
@echo $(MSG_ASSEMBLING_ARM) $$< to $$@
$(CC) -c $$(ASFLAGS) $$< -o $$@
endef
$(foreach src, $(ASRCARM), $(eval $(call ASSEMBLE_ARM_TEMPLATE, $(src))))
# Compile: create object files from C source files.
define COMPILE_C_TEMPLATE
$(OUTDIR)/$(notdir $(basename $(1))).o : $(1)
## @echo
@echo $(MSG_COMPILING) $$< to $$@
$(CC) -c $(THUMB) $$(CFLAGS) $$(CONLYFLAGS) $$< -o $$@
endef
$(foreach src, $(SRC), $(eval $(call COMPILE_C_TEMPLATE, $(src))))
# Compile: create object files from C source files. ARM-only
define COMPILE_C_ARM_TEMPLATE
$(OUTDIR)/$(notdir $(basename $(1))).o : $(1)
## @echo
@echo $(MSG_COMPILING_ARM) $$< to $$@
$(CC) -c $$(CFLAGS) $$(CONLYFLAGS) $$< -o $$@
endef
$(foreach src, $(SRCARM), $(eval $(call COMPILE_C_ARM_TEMPLATE, $(src))))
# Compile: create object files from C++ source files.
define COMPILE_CPP_TEMPLATE
$(OUTDIR)/$(notdir $(basename $(1))).o : $(1)
## @echo
@echo $(MSG_COMPILINGCPP) $$< to $$@
$(CC) -c $(THUMB) $$(CFLAGS) $$(CPPFLAGS) $$< -o $$@
endef
$(foreach src, $(CPPSRC), $(eval $(call COMPILE_CPP_TEMPLATE, $(src))))
# Compile: create object files from C++ source files. ARM-only
define COMPILE_CPP_ARM_TEMPLATE
$(OUTDIR)/$(notdir $(basename $(1))).o : $(1)
## @echo
@echo $(MSG_COMPILINGCPP_ARM) $$< to $$@
$(CC) -c $$(CFLAGS) $$(CPPFLAGS) $$< -o $$@
endef
$(foreach src, $(CPPSRCARM), $(eval $(call COMPILE_CPP_ARM_TEMPLATE, $(src))))
# Compile: create assembler files from C source files. ARM/Thumb
$(SRC:.c=.s) : %.s : %.c
@echo $(MSG_ASMFROMC) $< to $@
$(CC) $(THUMB) -S $(CFLAGS) $(CONLYFLAGS) $< -o $@
$(eval $(call PARTIAL_COMPILE_TEMPLATE, SRC))
# Compile: create assembler files from C source files. ARM only
$(SRCARM:.c=.s) : %.s : %.c
@echo $(MSG_ASMFROMC_ARM) $< to $@
$(CC) -S $(CFLAGS) $(CONLYFLAGS) $< -o $@
$(eval $(call PARTIAL_COMPILE_ARM_TEMPLATE, SRCARM))
$(OUTDIR)/$(TARGET).bin.o: $(OUTDIR)/$(TARGET).bin
.PHONY: elf lss sym hex bin bino
elf: $(OUTDIR)/$(TARGET).elf
lss: $(OUTDIR)/$(TARGET).lss
sym: $(OUTDIR)/$(TARGET).sym
hex: $(OUTDIR)/$(TARGET).hex
bin: $(OUTDIR)/$(TARGET).bin
bino: $(OUTDIR)/$(TARGET).bin.o
# Display sizes of sections.
$(eval $(call SIZE_TEMPLATE, $(OUTDIR)/$(TARGET).elf))
.PHONY: size
size: $(OUTDIR)/$(TARGET).elf_size
# Generate Doxygen documents
docs:
doxygen $(DOXYGENDIR)/doxygen.cfg
# Target: clean project.
clean: begin clean_list finished end
clean_list :
## @echo
@echo $(MSG_CLEANING)
$(REMOVE) $(OUTDIR)/$(TARGET).map
$(REMOVE) $(OUTDIR)/$(TARGET).elf
$(REMOVE) $(OUTDIR)/$(TARGET).hex
$(REMOVE) $(OUTDIR)/$(TARGET).bin
$(REMOVE) $(OUTDIR)/$(TARGET).sym
$(REMOVE) $(OUTDIR)/$(TARGET).lss
$(REMOVE) $(ALLOBJ)
$(REMOVE) $(LSTFILES)
$(REMOVE) $(DEPFILES)
$(REMOVE) $(SRC:.c=.s)
$(REMOVE) $(SRCARM:.c=.s)
$(REMOVE) $(CPPSRC:.cpp=.s)
$(REMOVE) $(CPPSRCARM:.cpp=.s)
$(V1) $(REMOVE) $(OUTDIR)/$(TARGET).map
$(V1) $(REMOVE) $(OUTDIR)/$(TARGET).elf
$(V1) $(REMOVE) $(OUTDIR)/$(TARGET).hex
$(V1) $(REMOVE) $(OUTDIR)/$(TARGET).bin
$(V1) $(REMOVE) $(OUTDIR)/$(TARGET).sym
$(V1) $(REMOVE) $(OUTDIR)/$(TARGET).lss
$(V1) $(REMOVE) $(OUTDIR)/$(TARGET).bin.o
$(V1) $(REMOVE) $(ALLOBJ)
$(V1) $(REMOVE) $(LSTFILES)
$(V1) $(REMOVE) $(DEPFILES)
$(V1) $(REMOVE) $(SRC:.c=.s)
$(V1) $(REMOVE) $(SRCARM:.c=.s)
$(V1) $(REMOVE) $(CPPSRC:.cpp=.s)
$(V1) $(REMOVE) $(CPPSRCARM:.cpp=.s)
# Create output files directory
@ -611,9 +466,5 @@ else
-include $(shell mkdir -p $(OUTDIR) 2>/dev/null) $(shell mkdir $(OUTDIR)/dep 2>/dev/null) $(wildcard $(OUTDIR)/dep/*)
endif
# Listing of phony targets.
.PHONY : all begin finish end sizebefore sizeafter gccversion \
build elf hex bin lss sym clean clean_list program
.PHONY : all build clean clean_list program

View File

@ -1,105 +0,0 @@
# Convert binary file to a hex encoded array for inclusion in C projects
import os
import struct
import sys
import logging
class BinToArray:
def __init__(self):
pass
def ConvertFileToArray(self, strInFile, strOutFile, integerSize, ignoreBytes, endianNess):
""" Reads binary file at location strInFile and writes out a C array of hex values
Parameters -
strInFile - Path and filename of binary file to convert
strOutFile - Path and filename of output. Suggested extension is .c or .cpp
integerSize - Size in bytes of output array elements. Array generated is always
of type uint8, uint16, uint32. These types would need to be defined using
typedef if they don't exist, or the user can replace the type name with the
appropriate keyword valid for the compiler size conventions
ignoreBytes - Number of bytes to ignore at the beginning of binary file. Helps
strip out file headers and only encode the payload/data.
endianNess - Only used for integerSize of 2 or 4. 'l' for Little Endian, 'b' for
Big Endian
"""
# Check integerSize value
if integerSize not in (1, 2, 4):
logging.debug("Integer Size parameter must be 1, 2 or 4")
return
# endif
# Open input file
try:
fileIn = open(strInFile, 'rb')
except IOError, err:
logging.debug("Could not open input file %s" % (strInFile))
return
# end try
# Open input file
try:
fileOut = open(strOutFile, 'w')
except IOError, err:
logging.debug("Could not open output file %s" % (strOutFile))
return
# end try
# Start array definition preamble
inFileName = os.path.basename(strInFile)
strVarType = "uint%d_t" % (integerSize * 8)
fileOut.write("// Array representation of binary file %s\n\n\n" % (inFileName))
fileOut.write("static %s dataArray[] = {\n" % strVarType)
# Convert and write array into C file
fileIn.seek(ignoreBytes)
if integerSize == 1:
bufChunk = fileIn.read(20)
while bufChunk != '':
fileOut.write(" ")
for byteVal in bufChunk:
fileOut.write("0x%02x, " % ord(byteVal))
# end for
fileOut.write("\n")
bufChunk = fileIn.read(20)
# end while
else:
if endianNess == 'l' and integerSize == 2:
endianFormatter = '<H'
maxWordsPerLine = 10
elif endianNess == 'l' and integerSize == 4:
endianFormatter = '<L'
maxWordsPerLine = 6
elif endianNess == 'b' and integerSize == 2:
endianFormatter = '>H'
maxWordsPerLine = 10
elif endianNess == 'b' and integerSize == 4:
endianFormatter = '>L'
maxWordsPerLine = 6
# endif
bufChunk = fileIn.read(integerSize)
i = 0
fileOut.write(" ")
while bufChunk != '':
wordVal = struct.unpack(endianFormatter, bufChunk)
if integerSize == 2:
fileOut.write("0x%04x, " % wordVal)
else:
fileOut.write("0x%08x, " % wordVal)
# endif
i += 1
if i == maxWordsPerLine:
fileOut.write("\n ")
i = 0
# endif
bufChunk = fileIn.read(integerSize)
# end while
# end if
# Close array definition
fileOut.write("\n };\n")
fileIn.close()
fileOut.close()
if __name__ == "__main__":
print(sys.argv[0])
logging.basicConfig(level=logging.DEBUG)
converter = BinToArray()
converter.ConvertFileToArray(
sys.argv[1], sys.argv[2], 4, 0, 'l')

View File

@ -27,13 +27,25 @@
*/
/* Bootloader Includes */
#include <pios.h>
#include <bl_array.h>
#include <stdbool.h>
#define MAX_WRI_RETRYS 3
/* Prototype of PIOS_Board_Init() function */
extern void PIOS_Board_Init(void);
extern void FLASH_Download();
void error(int);
/* The ADDRESSES of the _binary_* symbols are the important
* data. This is non-intuitive for _binary_size where you
* might expect its value to hold the size but you'd be wrong.
*/
extern void _binary_start;
extern void _binary_end;
extern void _binary_size;
const uint32_t * embedded_image_start = (uint32_t *) &(_binary_start);
const uint32_t * embedded_image_end = (uint32_t *) &(_binary_end);
const uint32_t embedded_image_size = (uint32_t) &(_binary_size);
int main() {
PIOS_SYS_Init();
@ -43,63 +55,70 @@ int main() {
PIOS_LED_Off(LED1);
/// Self overwrite check
uint32_t base_adress = SCB->VTOR;
if (0x08000000 + (sizeof(dataArray)) > base_adress)
uint32_t base_address = SCB->VTOR;
if ((0x08000000 + embedded_image_size) > base_address)
error(LED1);
///
FLASH_Unlock();
/// Bootloader memory space erase
uint32_t pageAdress;
pageAdress = 0x08000000;
uint8_t fail = FALSE;
while ((pageAdress < base_adress) || (fail == TRUE)) {
uint32_t pageAddress;
pageAddress = 0x08000000;
bool fail = false;
while ((pageAddress < base_address) && (fail == false)) {
for (int retry = 0; retry < MAX_DEL_RETRYS; ++retry) {
if (FLASH_ErasePage(pageAdress) == FLASH_COMPLETE) {
fail = FALSE;
if (FLASH_ErasePage(pageAddress) == FLASH_COMPLETE) {
fail = false;
break;
} else {
fail = TRUE;
fail = true;
}
}
#ifdef STM32F10X_HD
pageAdress += 2048;
pageAddress += 2048;
#elif defined (STM32F10X_MD)
pageAdress += 1024;
pageAddress += 1024;
#endif
}
if (fail == TRUE)
if (fail == true)
error(LED1);
///
/// Bootloader programing
for (int x = 0; x < sizeof(dataArray)/sizeof(uint32_t); ++x) {
int result = 0;
for (uint32_t offset = 0; offset < embedded_image_size/sizeof(uint32_t); ++offset) {
bool result = false;
PIOS_LED_Toggle(LED1);
for (int retry = 0; retry < MAX_WRI_RETRYS; ++retry) {
if (result == 0) {
result = (FLASH_ProgramWord(0x08000000 + (x * 4), dataArray[x])
== FLASH_COMPLETE) ? 1 : 0;
for (uint8_t retry = 0; retry < MAX_WRI_RETRYS; ++retry) {
if (result == false) {
result = (FLASH_ProgramWord(0x08000000 + (offset * 4), embedded_image_start[offset])
== FLASH_COMPLETE) ? true : false;
}
}
if (result == 0)
if (result == false)
error(LED1);
}
///
for (int x=0;x<3;++x) {
for (uint8_t x = 0; x < 3; ++x) {
PIOS_LED_On(LED1);
PIOS_DELAY_WaitmS(1000);
PIOS_LED_Off(LED1);
PIOS_DELAY_WaitmS(1000);
}
}
/// Invalidate the bootloader updater so we won't run
/// the update again on the next power cycle.
FLASH_ProgramWord(base_address, 0);
FLASH_Lock();
for (;;) {
PIOS_DELAY_WaitmS(1000);
}
}
void error(int led) {
for (;;) {
PIOS_LED_On(led);

View File

@ -193,7 +193,7 @@ CPPSRCARM =
# 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 = $(PIOSSTM32F10X)/startup_stm32f10x_$(MODEL).S
ASRC = $(PIOSSTM32F10X)/startup_stm32f10x_$(MODEL)$(MODEL_SUFFIX).S
# List Assembler source files here which must be assembled in ARM-Mode..
ASRCARM =

View File

@ -4,6 +4,11 @@ MEMORY
SRAM (rwx) : ORIGIN = 0x20000000, LENGTH = 0x00005000
}
/* Stub out these functions since we don't use them anyway */
PROVIDE ( vPortSVCHandler = 0 ) ;
PROVIDE ( xPortPendSVHandler = 0 ) ;
PROVIDE ( xPortSysTickHandler = 0 ) ;
_estack = 0x20004FF0;
/* Section Definitions */

View File

@ -4,6 +4,11 @@ MEMORY
SRAM (rwx) : ORIGIN = 0x20000000, LENGTH = 0x00005000
}
/* Stub out these functions since we don't use them anyway */
PROVIDE ( vPortSVCHandler = 0 ) ;
PROVIDE ( xPortPendSVHandler = 0 ) ;
PROVIDE ( xPortSysTickHandler = 0 ) ;
_estack = 0x20004FF0;
/* Section Definitions */

View File

@ -59,10 +59,10 @@ PROVIDE ( HardFault_Handler = 0 ) ;
PROVIDE ( MemManage_Handler = 0 ) ;
PROVIDE ( BusFault_Handler = 0 ) ;
PROVIDE ( UsageFault_Handler = 0 ) ;
PROVIDE ( SVC_Handler = 0 ) ;
PROVIDE ( vPortSVCHandler = 0 ) ;
PROVIDE ( DebugMon_Handler = 0 ) ;
PROVIDE ( PendSV_Handler = 0 ) ;
PROVIDE ( SysTick_Handler = 0 ) ;
PROVIDE ( xPortPendSVHandler = 0 ) ;
PROVIDE ( xPortSysTickHandler = 0 ) ;
PROVIDE ( WWDG_IRQHandler = 0 ) ;
PROVIDE ( PVD_IRQHandler = 0 ) ;