From 5e4b5626085c69fc1e5044183f7f24ff3d863187 Mon Sep 17 00:00:00 2001 From: Olaf Rempel Date: Sun, 5 Oct 2014 14:32:07 +0200 Subject: [PATCH] update Makefile --- .gitignore | 1 + Makefile | 100 ++++++++++++++++++++++++++++------------------------- main.c | 19 ++++++++-- 3 files changed, 70 insertions(+), 50 deletions(-) diff --git a/.gitignore b/.gitignore index 6d36148..d53dd72 100644 --- a/.gitignore +++ b/.gitignore @@ -3,4 +3,5 @@ *.bin *.hex *.lst +*.lss *.map diff --git a/Makefile b/Makefile index 13490e6..e8437df 100644 --- a/Makefile +++ b/Makefile @@ -1,65 +1,71 @@ -PRG = twiboot -OBJ = main.o -MCU_TARGET = atmega88 -OPTIMIZE = -Os +CC := avr-gcc +LD := avr-ld +OBJCOPY := avr-objcopy +OBJDUMP := avr-objdump +SIZE := avr-size -ifeq ($(MCU_TARGET), atmega8) -BOOTLOADER_START=0x1C00 +TARGET = twiboot +SOURCE = $(wildcard *.c) + +# select MCU +MCU = atmega88 + +AVRDUDE_PROG := -c avr910 -b 115200 -P /dev/ttyUSB0 +#AVRDUDE_PROG := -c dragon_isp -P usb + +# --------------------------------------------------------------------------- + +ifeq ($(MCU), atmega8) +# (8Mhz internal RC-Osz., 2.7V BOD) AVRDUDE_MCU=m8 -endif -ifeq ($(MCU_TARGET), atmega88) +AVRDUDE_FUSES=lfuse:w:0x84:m hfuse:w:0xda:m + BOOTLOADER_START=0x1C00 +endif + +ifeq ($(MCU), atmega88) +# (8Mhz internal RC-Osz., 2.7V BOD) AVRDUDE_MCU=m88 +AVRDUDE_FUSES=lfuse:w:0xc2:m hfuse:w:0xdd:m efuse:w:0xfa:m + +BOOTLOADER_START=0x1C00 endif -ifeq ($(MCU_TARGET), atmega168) + +ifeq ($(MCU), atmega168) +# (8Mhz internal RC-Osz., 2.7V BOD) +AVRDUDE_MCU=m168 -F +AVRDUDE_FUSES=lfuse:w:0xc2:m hfuse:w:0xdd:m efuse:w:0xfa:m + BOOTLOADER_START=0x3C00 -AVRDUDE_MCU=m168 endif -DEFS = -DAPP_END=$(BOOTLOADER_START) -LIBS = +# --------------------------------------------------------------------------- -# Override is only needed by avr-lib build system. -override CFLAGS = -g -Wall $(OPTIMIZE) -mmcu=$(MCU_TARGET) $(DEFS) -override LDFLAGS = -Wl,-Map,$(PRG).map,--section-start=.text=$(BOOTLOADER_START) +CFLAGS = -pipe -g -Os -mmcu=$(MCU) -Wall -fdata-sections -ffunction-sections +CFLAGS += -Wa,-adhlns=$(*F).lst -DBOOTLOADER_START=$(BOOTLOADER_START) +LDFLAGS = -Wl,-Map,$(@:.elf=.map),--cref,--relax,--gc-sections,--section-start=.text=$(BOOTLOADER_START) -CC = avr-gcc -OBJCOPY = avr-objcopy -OBJDUMP = avr-objdump -SIZE = avr-size +# --------------------------------------------------------------------------- -all: $(PRG).elf lst text - $(SIZE) -x -A $(PRG).elf +$(TARGET): $(TARGET).elf + @$(SIZE) -B -x --mcu=$(MCU) $< -$(PRG).elf: $(OBJ) - $(CC) $(CFLAGS) $(LDFLAGS) -o $@ $^ $(LIBS) +$(TARGET).elf: $(SOURCE:.c=.o) + @echo " Linking file: $@" + @$(CC) $(CFLAGS) $(LDFLAGS) -o $@ $^ + @$(OBJDUMP) -h -S $@ > $(@:.elf=.lss) + @$(OBJCOPY) -j .text -j .data -O ihex $@ $(@:.elf=.hex) + @$(OBJCOPY) -j .text -j .data -O binary $@ $(@:.elf=.bin) %.o: %.c $(MAKEFILE_LIST) - $(CC) $(CFLAGS) -c $< -o $@ + @echo " Building file: $<" + @$(CC) $(CFLAGS) -o $@ -c $< clean: - rm -rf *.o $(PRG).lst $(PRG).map $(PRG).elf $(PRG).hex $(PRG).bin + rm -rf $(SOURCE:.c=.o) $(SOURCE:.c=.lst) $(addprefix $(TARGET), .elf .map .lss .hex .bin) -lst: $(PRG).lst +install: $(TARGET).elf + avrdude $(AVRDUDE_PROG) -p $(AVRDUDE_MCU) -U flash:w:$(<:.elf=.hex) -%.lst: %.elf - $(OBJDUMP) -h -S $< > $@ - -text: hex bin - -hex: $(PRG).hex -bin: $(PRG).bin - -%.hex: %.elf - $(OBJCOPY) -j .text -j .data -O ihex $< $@ - -%.bin: %.elf - $(OBJCOPY) -j .text -j .data -O binary $< $@ - -install: text - avrdude -c dragon_isp -P usb -p $(AVRDUDE_MCU) -U flash:w:$(PRG).hex - -#fuses: -# avrdude -c dragon_isp -P usb -p $(AVRDUDE_MCU) -U lfuse:w:0xc2:m -# avrdude -c dragon_isp -P usb -p $(AVRDUDE_MCU) -U hfuse:w:0xdd:m -# avrdude -c dragon_isp -P usb -p $(AVRDUDE_MCU) -U efuse:w:0xfa:m +fuses: + avrdude $(AVRDUDE_PROG) -p $(AVRDUDE_MCU) $(patsubst %,-U %, $(AVRDUDE_FUSES)) diff --git a/main.c b/main.c index 6587c3c..e1d36dc 100644 --- a/main.c +++ b/main.c @@ -54,6 +54,7 @@ #endif #define EEPROM_SUPPORT 1 +#define LED_SUPPORT 1 /* 25ms @8MHz */ #define TIMER_RELOAD (0xFF - 195) @@ -61,6 +62,7 @@ /* 40 * 25ms */ #define TIMEOUT 40 +#if LED_SUPPORT #define LED_INIT() DDRB = ((1<> 8) & 0xFF, - APP_END & 0xFF, + (BOOTLOADER_START >> 8) & 0xFF, + BOOTLOADER_START & 0xFF, #if (EEPROM_SUPPORT) ((E2END +1) >> 8 & 0xFF), (E2END +1) & 0xFF @@ -162,7 +175,7 @@ static void write_flash_page(void) uint8_t size = SPM_PAGESIZE; uint8_t *p = buf; - if (pagestart >= APP_END) + if (pagestart >= BOOTLOADER_START) return; boot_page_erase(pagestart);