From 29084dc307d7f1159635131f30d7b890f9b29ffc Mon Sep 17 00:00:00 2001 From: Joseph Coffland Date: Fri, 21 Jul 2017 15:28:22 -0700 Subject: [PATCH] Moved avr/boot --- src/avr/Makefile | 40 ++----- src/boot/.gitignore | 3 + src/boot/Makefile | 116 +++++++++++++++++++++ src/{avr/src/boot => boot/src}/boot.c | 0 src/{avr/src/boot => boot/src}/boot.h | 0 src/{avr/src/boot => boot/src}/sp_driver.S | 0 src/{avr/src/boot => boot/src}/sp_driver.h | 0 7 files changed, 127 insertions(+), 32 deletions(-) create mode 100644 src/boot/.gitignore create mode 100644 src/boot/Makefile rename src/{avr/src/boot => boot/src}/boot.c (100%) rename src/{avr/src/boot => boot/src}/boot.h (100%) rename src/{avr/src/boot => boot/src}/sp_driver.S (100%) rename src/{avr/src/boot => boot/src}/sp_driver.h (100%) diff --git a/src/avr/Makefile b/src/avr/Makefile index 9c6c0d2..892c91e 100644 --- a/src/avr/Makefile +++ b/src/avr/Makefile @@ -2,7 +2,7 @@ PROJECT = bbctrl-avr-firmware MCU = atxmega192a3u CLOCK = 32000000 -VERSION = 0.3.1 +VERSION = 0.4.0 TARGET = $(PROJECT).elf @@ -42,26 +42,11 @@ FUSE4=0xff FUSE5=0xeb # SRC -SRC = $(wildcard src/*.c) -SRC += $(wildcard src/plan/*.c) +SRC = $(wildcard src/*.c) $(wildcard src/plan/*.c) OBJ = $(patsubst src/%.c,build/%.o,$(SRC)) -# Boot SRC -BOOT_SRC = $(wildcard src/boot/*.S) -BOOT_SRC += $(wildcard src/boot/*.c) -BOOT_OBJ = $(patsubst src/%.c,build/%.o,$(BOOT_SRC)) -BOOT_OBJ := $(patsubst src/%.S,build/%.o,$(BOOT_OBJ)) - -BOOT_LDFLAGS = $(LDFLAGS) -Wl,--section-start=.text=0x030000 - # Build -all: - @$(MAKE) $(PROJECT).hex - @$(MAKE) build/vars.json - @$(MAKE) boot - @$(MAKE) size - -boot: boot.hex boot-size +all: $(PROJECT).hex build/vars.json size build/vars.json: src/vars.def @@ -81,9 +66,6 @@ build/%.o: src/%.S $(TARGET): $(OBJ) $(CC) $(LDFLAGS) $(OBJ) $(LIBS) -o $@ -boot.elf: $(BOOT_OBJ) - $(CC) $(BOOT_LDFLAGS) $(BOOT_OBJ) -o $@ - %.hex: %.elf avr-objcopy -O ihex -R .eeprom -R .fuse -R .lock -R .signature $< $@ @@ -93,18 +75,12 @@ boot.elf: $(BOOT_OBJ) %.lss: %.elf avr-objdump -h -S $< > $@ -_size: +size: $(TARGET) @for X in A B C; do\ echo '****************************************************************' ;\ - avr-size -$$X --mcu=$(MCU) $(SIZE_TARGET) ;\ + avr-size -$$X --mcu=$(MCU) $(TARGET) ;\ done -boot-size: boot.elf - @$(MAKE) SIZE_TARGET=$< _size - -size: $(TARGET) - @$(MAKE) SIZE_TARGET=$< _size - # Program init: $(MAKE) erase @@ -125,8 +101,8 @@ program: $(PROJECT).hex verify: $(PROJECT).hex avrdude $(AVRDUDE_OPTS) -U flash:v:$(PROJECT).hex:i -program-boot: boot.hex - avrdude $(AVRDUDE_OPTS) -U flash:w:boot.hex:i +program-boot: + $(MAKE) -C ../boot program fuses: avrdude $(AVRDUDE_OPTS) -U fuse0:w:$(FUSE0):m -U fuse1:w:$(FUSE1):m \ @@ -151,7 +127,7 @@ tidy: clean: tidy rm -rf $(PROJECT).elf $(PROJECT).hex $(PROJECT).eep $(PROJECT).lss \ - $(PROJECT).map build boot.hex boot.elf + $(PROJECT).map build .PHONY: tidy clean size all reset erase program fuses read_fuses prodsig .PHONY: signature usersig diff --git a/src/boot/.gitignore b/src/boot/.gitignore new file mode 100644 index 0000000..acbe7a5 --- /dev/null +++ b/src/boot/.gitignore @@ -0,0 +1,3 @@ +/build +/*.elf +/*.hex diff --git a/src/boot/Makefile b/src/boot/Makefile new file mode 100644 index 0000000..c09a60e --- /dev/null +++ b/src/boot/Makefile @@ -0,0 +1,116 @@ +# Makefile for the project Bulidbotics bootloader +PROJECT = bbctrl-avr-boot +MCU = atxmega192a3u +CLOCK = 32000000 + +TARGET = $(PROJECT).elf + +# Compile flags +CC = avr-gcc +CPP = avr-g++ + +COMMON = -mmcu=$(MCU) -flto -fwhole-program + +CFLAGS += $(COMMON) -Wall -Werror +CFLAGS += -std=gnu99 -DF_CPU=$(CLOCK)UL -O3 +CFLAGS += -funsigned-bitfields -fpack-struct -fshort-enums -funsigned-char +CFLAGS += -MD -MP -MT $@ -MF build/dep/$(@F).d +CFLAGS += -Isrc + +# Linker flags +LDFLAGS += $(COMMON) -Wl,-u,vfprintf -lprintf_flt -lm +LDFLAGS += -Wl,--section-start=.text=0x030000 +LIBS += -lm + +# Programming flags +PROGRAMMER = avrispmkII +PDEV = usb +AVRDUDE_OPTS = -c $(PROGRAMMER) -p $(MCU) -P $(PDEV) + +FUSE0=0xff +FUSE1=0x00 +FUSE2=0xbe +FUSE4=0xff +FUSE5=0xeb + +# SRC +SRC = $(wildcard src/*.S) +SRC += $(wildcard src/*.c) +OBJ = $(patsubst src/%.c,build/%.o,$(SRC)) +OBJ := $(patsubst src/%.S,build/%.o,$(OBJ)) + + +# Build +all: $(TARGET) size + +# Compile +build/%.o: src/%.c + @mkdir -p $(shell dirname $@) + $(CC) $(INCLUDES) $(CFLAGS) -c -o $@ $< + +build/%.o: src/%.S + @mkdir -p $(shell dirname $@) + $(CC) $(INCLUDES) $(CFLAGS) -c -o $@ $< + +# Link +$(TARGET): $(OBJ) + $(CC) $(LDFLAGS) $(OBJ) $(LIBS) -o $@ + +%.hex: %.elf + avr-objcopy -O ihex -R .eeprom -R .fuse -R .lock -R .signature $< $@ + +size: $(TARGET) + @for X in A B C; do\ + echo '****************************************************************' ;\ + avr-size -$$X --mcu=$(MCU) $(TARGET) ;\ + done + +# Program +init: + $(MAKE) erase + -$(MAKE) fuses + $(MAKE) fuses + $(MAKE) program + +reset: + avrdude $(AVRDUDE_OPTS) + +erase: + avrdude $(AVRDUDE_OPTS) -e + +program: $(PROJECT).hex + avrdude $(AVRDUDE_OPTS) -U flash:w:$(PROJECT).hex:i + +verify: $(PROJECT).hex + avrdude $(AVRDUDE_OPTS) -U flash:v:$(PROJECT).hex:i + +fuses: + avrdude $(AVRDUDE_OPTS) -U fuse0:w:$(FUSE0):m -U fuse1:w:$(FUSE1):m \ + -U fuse2:w:$(FUSE2):m -U fuse4:w:$(FUSE4):m -U fuse5:w:$(FUSE5):m + +read_fuses: + avrdude $(AVRDUDE_OPTS) -q -q -U fuse0:r:-:h -U fuse1:r:-:h -U fuse2:r:-:h \ + -U fuse4:r:-:h -U fuse5:r:-:h + +signature: + avrdude $(AVRDUDE_OPTS) -q -q -U signature:r:-:h + +prodsig: + avrdude $(AVRDUDE_OPTS) -q -q -U prodsig:r:-:h + +usersig: + avrdude $(AVRDUDE_OPTS) -q -q -U usersig:r:-:h + +# Clean +tidy: + rm -f $(shell find -name \*~ -o -name \#\*) + +clean: tidy + rm -rf $(PROJECT).elf $(PROJECT).hex $(PROJECT).eep $(PROJECT).lss \ + $(PROJECT).map build + +.PHONY: tidy clean size all reset erase program fuses read_fuses prodsig +.PHONY: signature usersig + +# Dependencies +-include $(shell mkdir -p build/dep) $(wildcard build/dep/*) diff --git a/src/avr/src/boot/boot.c b/src/boot/src/boot.c similarity index 100% rename from src/avr/src/boot/boot.c rename to src/boot/src/boot.c diff --git a/src/avr/src/boot/boot.h b/src/boot/src/boot.h similarity index 100% rename from src/avr/src/boot/boot.h rename to src/boot/src/boot.h diff --git a/src/avr/src/boot/sp_driver.S b/src/boot/src/sp_driver.S similarity index 100% rename from src/avr/src/boot/sp_driver.S rename to src/boot/src/sp_driver.S diff --git a/src/avr/src/boot/sp_driver.h b/src/boot/src/sp_driver.h similarity index 100% rename from src/avr/src/boot/sp_driver.h rename to src/boot/src/sp_driver.h -- 2.27.0