Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Reworked bootloader code #2

Open
wants to merge 66 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
66 commits
Select commit Hold shift + click to select a range
98b18df
Initial commit of a fully reworked project structure
Jun 1, 2012
87dc369
Move usb_descriptors to per-board config.
Jun 1, 2012
21ce82a
Minor fixes and cleanups
nekromant Jun 1, 2012
49225a3
Add config option to strip usb suspend/resume code
nekromant Jun 1, 2012
1534b6e
Set default options to -Os and no debug.
nekromant Jun 1, 2012
27053af
Fix maple target to compile (Not tested!)
nekromant Jun 1, 2012
182a459
Shut up another warning
nekromant Jun 1, 2012
4d3687b
Add README and TODO
nekromant Jun 1, 2012
1b779d9
Add missing usb_descriptor for maple target
nekromant Jun 1, 2012
eb5ee79
Add some stuff to TODO
nekromant Jun 1, 2012
78a1caa
Shut up the last warnings from usb_regs.h
nekromant Jun 1, 2012
3309716
Change color scheme a little bit
nekromant Jun 1, 2012
91fc618
Add README.porting
nekromant Jun 1, 2012
89bc6c8
Added myself to CREDITS
nekromant Jun 1, 2012
1cfc68b
Update TODO
Jun 1, 2012
ece1037
Make a bunch of vars volatile to work properly with -Os
Jun 1, 2012
689eda0
Added RUNAPP_ALT hack, see README.porting for details
Jun 1, 2012
465f9d9
Fix a typo
Jun 1, 2012
b9ed919
Wrap bootloaderExitCondition in #ifdef's
Jun 1, 2012
7e0defd
Uncomment some quite critical code, that got chewed up
Jun 2, 2012
73d06e4
Implement optional INFO endpoint
nekromant Jun 2, 2012
2e400e2
Include config.h in usb.c
nekromant Jun 2, 2012
ac7facf
Fixes to board files
nekromant Jun 2, 2012
cb4399f
Added initial stuff for Motor Cortex Board
nekromant Jun 2, 2012
863fb00
Add GPIOG definition
nekromant Jun 2, 2012
fdbfdb3
Nove FLASH_PAGE_SIZE to boardconfig
nekromant Jun 2, 2012
99acd2e
Fix TODO/README and add stubs for further DFU refactoring
nekromant Jun 4, 2012
41f2852
Move IO routines to dfu_io.c
Jun 4, 2012
74e6ead
fixe board configs to reflect recent dfu.c changes
Jun 4, 2012
930ba94
Fix FLASH_PAGE_SIZE for maple, added MAPLE RET6 dummy. UNTESTED!!!
nekromant Jun 4, 2012
c8a53e0
Fix typo in configs
nekromant Jun 5, 2012
ab411c0
Some changes to dfu machine
nekromant Jun 5, 2012
24d90c1
Fix README
nekromant Jun 5, 2012
7e1e72f
Add a small developer README
nekromant Jun 5, 2012
4eb9a60
Initial stubs for dfu upload functionality
nekromant Jun 5, 2012
c2b8334
Do an NVIC_SetVectorTable before jump
nekromant Jun 5, 2012
d244d91
Add xilinx sscu driver
nekromant Jun 5, 2012
0d71686
Added licencse stuff to xsscu headers. Let it be MIT
nekromant Jun 5, 2012
5c900d5
Some quite critical fixes
nekromant Jun 5, 2012
4f68f61
Extra special commit with steroids and coffeine
nekromant Jun 5, 2012
ff8ea6b
mcortex: Fix USB disconnection handling
nekromant Jun 5, 2012
c9147d3
Added more porting info
nekromant Jun 6, 2012
f6411b9
mcortex: Minor adjustments to board files
nekromant Jun 6, 2012
a737843
mcortex: Fix USB descriptors to expose all 5 altsettings
nekromant Jun 6, 2012
2b1cd68
Remove loop from dfuFinishUpload, go on blinking after one download
nekromant Jun 6, 2012
d6dea89
Tuned timeouts a little more, should be a little bit faster
nekromant Jun 6, 2012
ba956a3
Performance tuning. No strobe while download, tuned timeouts.
nekromant Jun 6, 2012
d725c1f
More performance tuning.
nekromant Jun 6, 2012
d9655db
Add benchmark results to README
nekromant Jun 6, 2012
af8955b
Do not disable SysTick before jump to app.
nekromant Jun 7, 2012
cb1bf0b
mcortex: changed bootloader condition to fire only by dfu-util command
nekromant Jun 7, 2012
823e6b2
Revert "Do not disable SysTick before jump to app."
nekromant Jun 7, 2012
d63ec7d
dfuToRun: Do not jump to user app from interrupt.
nekromant Jun 8, 2012
b6a01b3
Added optimizing README
nekromant Jun 8, 2012
f99ac99
Updates to optimizing README
Jun 8, 2012
fbcd202
Fix TODO
Jun 8, 2012
0aaddee
maple-ret6: Fix board initialisation code and config
nekromant Jun 8, 2012
c87962b
maple: fix board configuration, according to the upstream
nekromant Jun 8, 2012
35665ad
Add a status matrix
nekromant Jun 8, 2012
0ff05c6
te-stm32f103ret6kit: fix usb disconnection handling
nekromant Jun 9, 2012
23b1b63
Move usb clock enabling to main, since that's common for everything
nekromant Jun 9, 2012
7b126f6
dfu: Only call copyFunc if thiBlocklen is nonzero
nekromant Jun 10, 2012
9e1ddfa
dfu_io: Add proper routines for FPGA download
nekromant Jun 11, 2012
7bd31ae
mcortex: Properly add FPGA target
nekromant Jun 11, 2012
926b930
Update README.status with a better status matrix
nekromant Jun 11, 2012
a5b4b23
main: reordered events to fix enumeration issues. More testing needed
nekromant Jun 23, 2012
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 4 additions & 0 deletions CREDITS
Original file line number Diff line number Diff line change
Expand Up @@ -10,3 +10,7 @@ The fields are: name (N), email (E), web-address (W), description (D).
N: Tormod Volden
E: [email protected]
D: Fixes for DFU compliance

N: Andrew 'Necromant' Andrianov
E: [email protected]
D: Portability, cleanups, buildsystem tweeks
331 changes: 98 additions & 233 deletions Makefile
Original file line number Diff line number Diff line change
@@ -1,249 +1,114 @@
# Makefile skeleton adapted from Peter Harrison's - www.micromouse.com
CROSS_COMPILE?=arm-ncrmnt-eabi-
SRCDIR=.
OBJDIR=./build

# MCU name and submodel
MCU = cortex-m3
SUBMDL = stm32f103

# toolchain (using code sourcery now)
TCHAIN = arm-none-eabi
THUMB = -mthumb
THUMB_IW = -mthumb-interwork

# Target file name (without extension).
BUILDDIR = build
TARGET = $(BUILDDIR)/maple_boot

ST_LIB = stm32_lib
ST_USB = usb_lib

# Optimization level [0,1,2,3,s]
OPT = 0
DEBUG = -g
#DEBUG = dwarf-2
TARGET=$(OBJDIR)/ucboot-$(BOARD)

INCDIRS = ./$(ST_LIB) ./$(ST_USB)

CFLAGS = $(DEBUG)
OPT=s
DEBUG=
CFLAGS += -O$(OPT)
CFLAGS += -ffunction-sections -fdata-sections
CFLAGS += -Wall -Wimplicit
CFLAGS += -Wcast-align
CFLAGS += -Wpointer-arith -Wswitch
CFLAGS += -Wredundant-decls -Wreturn-type -Wshadow -Wunused
CFLAGS += -Wa,-adhlns=$(BUILDDIR)/$(subst $(suffix $<),.lst,$<)
CFLAGS += $(patsubst %,-I%,$(INCDIRS))
CFLAGS += -Wa,-adhlns=$(OBJDIR)/$(subst $(suffix $<),.lst,$<)
CFLAGS += -I$(OBJDIR)/

# Aeembler Flags
ASFLAGS = -Wa,-adhlns=$(BUILDDIR)/$(<:.s=.lst)#,--g$(DEBUG)
GENDEPFLAGS = -MD -MP -MF $(@).d

CFLAGS += -mcpu=$(MCU) $(THUMB) $(THUMB_IW) $(GENDEPFLAGS)
ASFLAGS = -Wa,-adhlns=$(OBJDIR)/$(<:.s=.lst)#,--g$(DEBUG)
ASFLAGS += -mcpu=$(MCU) $(THUMB) $(THUMB_IW) -x assembler-with-cpp
ASFLAGS += $(GENDEPFLAGS)
LDFLAGS = -nostartfiles -Wl,-Map=$(TARGET).map,--cref,--gc-sections
LDFLAGS += -lc -lgcc

# Set the linker script
LDFLAGS +=-T$(ST_LIB)/c_only_md.ld

# Define programs and commands.
SHELL = sh
CC = $(TCHAIN)-gcc
CPP = $(TCHAIN)-g++
AR = $(TCHAIN)-ar
OBJCOPY = $(TCHAIN)-objcopy
OBJDUMP = $(TCHAIN)-objdump
SIZE = $(TCHAIN)-size
NM = $(TCHAIN)-nm
REMOVE = rm -f
REMOVEDIR = rm -r
COPY = cp

# Define Messages
# English
MSG_ERRORS_NONE = Errors: none
MSG_BEGIN = "-------- begin --------"
MSG_ETAGS = Created TAGS File
MSG_END = -------- end --------
MSG_SIZE_BEFORE = Size before:
MSG_SIZE_AFTER = Size after:
MSG_FLASH = Creating load file for Flash:
MSG_EXTENDED_LISTING = Creating Extended Listing:
MSG_SYMBOL_TABLE = Creating Symbol Table:
MSG_LINKING = Linking:
MSG_COMPILING = Compiling C:
MSG_ASSEMBLING = Assembling:
MSG_CLEANING = Cleaning project:

# Combine all necessary flags and optional flags.
# Add target processor to flags.
GENDEPFLAGS = -MD -MP -MF .dep/$(@F).d
ALL_CFLAGS = -mcpu=$(MCU) $(THUMB_IW) -I. $(CFLAGS) $(GENDEPFLAGS)
ALL_ASFLAGS = -mcpu=$(MCU) $(THUMB_IW) -I. -x assembler-with-cpp $(ASFLAGS)

# --------------------------------------------- #
# file management
ASRC = $(ST_LIB)/c_only_startup.s $(ST_LIB)/cortexm3_macro.s

STM32SRCS =

_STM32USBSRCS = usb_regs.c \
usb_int.c \
usb_init.c \
usb_core.c \
usb_mem.c

STM32USBSRCS = $(patsubst %, $(ST_USB)/%,$(_STM32USBSRCS))

SRCS = usb.c usb_callbacks.c usb_descriptor.c main.c hardware.c dfu.c


SRC = $(SRCS) $(STM32SRCS) $(STM32USBSRCS)

# Define all object files.
_COBJ = $(SRC:.c=.o)
_AOBJ = $(ASRC:.s=.o)
COBJ = $(patsubst %, $(BUILDDIR)/%,$(_COBJ))
AOBJ = $(patsubst %, $(BUILDDIR)/%,$(_AOBJ))

# Define all listing files.
_LST = $(ASRC:.s=.lst)
_LST += $(SRC:.c=.lst)
LST = $(patsubst %, $(BUILDDIR)/%,$(_LST))

# Display size of file.
HEXSIZE = $(SIZE) --target=binary $(TARGET).hex
ELFSIZE = $(SIZE) -A $(TARGET).elf

# go!
all: begin gccversion build sizeafter finished end
build: elf bin lss sym

bin: $(TARGET).bin
elf: $(TARGET).elf
lss: $(TARGET).lss
sym: $(TARGET).sym
dfu: $(TARGET).bin
sudo dfu-util -d 0110:1001 -a 0 -D $(TARGET).bin

begin:
mkdir -p build/stm32_lib
mkdir -p build/usb_lib
@echo --
@echo $(MSG_BEGIN)
@echo $(COBJ)

finished:
@echo $(MSG_ERRORS_NONE)
tags:
etags `find . -name "*.c" -o -name "*.cpp" -o -name "*.h"`
@echo $(MSG_ETAGS)
end:
@echo $(MSG_END)
@echo
sizeafter:
@if [ -f $(TARGET).elf ]; then echo; echo $(MSG_SIZE_AFTER); $(ELFSIZE); echo; fi
gccversion:
@$(CC) --version

program:
@echo "Flash-programming with OpenOCD"
cp $(TARGET).bin flash/tmpflash.bin
cd flash && openocd -f flash.cfg

program_serial:
@echo "Flash-programming with stm32loader.py"
./flash/stm32loader.py -p /dev/ttyUSB0 -evw build/maple_boot.bin

debug: $(TARGET).bin
@echo "Flash-programming with OpenOCD - DEBUG"
cp $(TARGET).bin flash/tmpflash.bin
cd flash && openocd -f debug.cfg

install: $(TARGET).bin
cp $(TARGET).bin build/main.bin
openocd -f flash/perry_flash.cfg

run: $(TARGET).bin
openocd -f flash/run.cfg

# Create final output file (.hex) from ELF output file.
%.hex: %.elf
@echo
@echo $(MSG_FLASH) $@
$(OBJCOPY) -O binary $< $@

# Create final output file (.bin) from ELF output file.
%.bin: %.elf
@echo
@echo $(MSG_FLASH) $@
$(OBJCOPY) -O binary $< $@


# Create extended listing file from ELF output file.
# testing: option -C
%.lss: %.elf
@echo
@echo $(MSG_EXTENDED_LISTING) $@
$(OBJDUMP) -h -S -D $< > $@


# 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 : $(COBJ) $(AOBJ)

%.elf: $(COBJ) $(AOBJ)
@echo
@echo $(MSG_LINKING) $@
$(CC) $(THUMB) $(ALL_CFLAGS) $(AOBJ) $(COBJ) --output $@ $(LDFLAGS)

# Compile: create object files from C source files. ARM/Thumb
$(COBJ) : $(BUILDDIR)/%.o : %.c
@echo
@echo $(MSG_COMPILING) $<
$(CC) -c $(THUMB) $(ALL_CFLAGS) $< -o $@

# Assemble: create object files from assembler source files. ARM/Thumb
$(AOBJ) : $(BUILDDIR)/%.o : %.s
@echo
@echo $(MSG_ASSEMBLING) $<
$(CC) -c $(THUMB) $(ALL_ASFLAGS) $< -o $@

clean: begin clean_list finished end

clean_list :
@echo
@echo $(MSG_CLEANING)
$(REMOVE) $(TARGET).hex
$(REMOVE) $(TARGET).bin
$(REMOVE) $(TARGET).obj
$(REMOVE) $(TARGET).elf
$(REMOVE) $(TARGET).map
$(REMOVE) $(TARGET).obj
$(REMOVE) $(TARGET).a90
$(REMOVE) $(TARGET).sym
$(REMOVE) $(TARGET).lnk
$(REMOVE) $(TARGET).lss
$(REMOVE) $(COBJ)
$(REMOVE) $(AOBJ)
$(REMOVE) $(LST)
$(REMOVE) flash/tmpflash.bin
# $(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 tags end sizeafter gccversion \
build elf hex bin lss sym clean clean_list program cscope

cscope:
rm -rf *.cscope
find . -iname "*.[hcs]" | grep -v examples | xargs cscope -R -b

#TODO:...
LDFLAGS +=-T$(SRCDIR)/src/startup/c_only_md.ld

CROSS_CC=$(CROSS_COMPILE)gcc
CROSS_AS=$(CROSS_COMPILE)as
CROSS_LD=$(CROSS_COMPILE)ld
CROSS_OBJCOPY=$(CROSS_COMPILE)objcopy
CROSS_OBJDUMP=$(CROSS_COMPILE)objdump

# Pretty colors
tb_ylw=$(shell echo -e '\e[1;33m')
tb_blu=$(shell echo -e '\e[1;34m')
tb_pur=$(shell echo -e '\e[1;35m')
col_rst=$(shell echo -e '\e[0m')
tb_grn=$(shell echo -e '\e[1;32m')

ifneq ($(V),y)
SILENT_CC = @echo ' $(tb_ylw)[CC]$(col_rst) ' $(@F);
SILENT_AS = @echo ' $(tb_blu)[AS]$(col_rst) ' $(@F);
SILENT_LD = @echo ' $(tb_pur)[LD]$(col_rst) ' $(@F);
SILENT_OBJCOPY = @echo ' $(tb_pur)[OBJCOPY]$(col_rst) ' $(@F);
SILENT_OBJDUMP = @echo ' $(tb_pur)[OBJDUMP]$(col_rst) ' $(OBJDUMP);
SILENT_INFO = @echo ' $(tb_grn)[INFO]$(col_rst) Build for board $(tb_grn)$(BOARD)$(col_rst) complete';
#Shut up this crap
MAKEFLAGS+=--no-print-directory
endif

# This is a dirty hack, since I don't want to
# recurse properly into dirs with recusive make invocation
# and the only method of reading submakes descending into subdirs,
# without recusive invocation I came up with looks like shit
# Anyway, this would be a bit too much for such a project

define suck_directory
-include $(SRCDIR)/$(1)/Makefile
mkdirs+=$(OBJDIR)/$(1)
objects+=$$(addprefix $(OBJDIR)/$(1)/,$$(objects-$(2)))
endef

$(eval $(call suck_directory,src/common,common))
$(eval $(call suck_directory,src/usb_lib,usb_lib))
$(eval $(call suck_directory,src/startup,startup))
$(eval $(call suck_directory,boards/$(BOARD),y))

all:
@$(foreach d,$(shell ls $(SRCDIR)/boards/),make BOARD=$(d) build;)

-include $(addsuffix .d,$(objects))

$(OBJDIR)/%.o: $(SRCDIR)/%.c
$(SILENT_CC) $(CROSS_CC) $(CFLAGS) -c -o $(@) $<

$(OBJDIR)/%.o: $(SRCDIR)/%.S
$(SILENT_AS) $(CROSS_CC) $(ASFLAGS) -c -o $(@) $<

$(OBJDIR)/%.o: $(SRCDIR)/%.s
$(SILENT_AS) $(CROSS_CC) $(ASFLAGS) -c -o $(@) $<

$(OBJDIR)/%.elf: $(objects)
$(SILENT_LD) $(CROSS_CC) $(CFLAGS) --output $(@) $(LDFLAGS) $(objects)

$(OBJDIR)/%.bin: $(OBJDIR)/%.elf
$(SILENT_OBJCOPY) $(CROSS_OBJCOPY) -O binary $< $@

#config.h symlink voodoo ensures we'll get stuff properly rebuilt
warmup:
@mkdir -p $(OBJDIR)
@$(foreach d,$(mkdirs),mkdir -p $(d);)
@ln -sf $(abspath $(SRCDIR)/boards/$(BOARD)/config.h) $(OBJDIR)/config.h
@touch $(OBJDIR)/config.h

build: warmup $(OBJDIR)/ucboot-$(BOARD).bin
$(SILENT_INFO)

clean:
@rm -Rfv $(OBJDIR)
help:
@echo "To build for a board, run 'make BOARD=boardname build'"
@echo "To build for all avaliable boards run make"
@echo "Use CROSS_COMPILE to set toolchain prefix"
@echo "USE V=y for verbose build"
@echo "Have fun"

.PRECIOUS: $(objects) $(TARGET).bin $(TARGET).elf
.PHONY: warmup
Loading