From 26c28d229b38ca95d15b98cb2bb3acce5ccc66bd Mon Sep 17 00:00:00 2001
From: Philipp Claves <pclaves@web.de>
Date: Sun, 11 Dec 2011 00:21:00 +0100
Subject: [PATCH] Add eeprom generation with KEY= option to makefile. ruby
 interpreter (>= 1.9.x) required.

---
 ATMegaCard/Makefile | 24 +++++++++++++++---------
 1 file changed, 15 insertions(+), 9 deletions(-)

diff --git a/ATMegaCard/Makefile b/ATMegaCard/Makefile
index 4288b35..8e5e590 100644
--- a/ATMegaCard/Makefile
+++ b/ATMegaCard/Makefile
@@ -146,8 +146,11 @@ AVRDUDE_PORT = usb        # programmer connected to USB port
 #AVRDUDE_PORT = lpt1	       # programmer connected to parallel port
 
 AVRDUDE_WRITE_FLASH = -U flash:w:$(TARGET).hex $(FUSE_BITS)
-#AVRDUDE_WRITE_EEPROM = -U eeprom:w:$(TARGET).eep
 
+ifneq ($(KEY),)
+	EEPROM_GEN_CMD=./eeprom_gen.rb $(TARGET).eep $(KEY)
+	AVRDUDE_WRITE_EEPROM = -U eeprom:w:$(TARGET).eep
+endif
 #AVRDUDE_FLAGS = -p $(MCU) -P $(AVRDUDE_PORT) -b 115200 -c $(AVRDUDE_PROGRAMMER)
 AVRDUDE_FLAGS = -B 1 -p $(MCU) -P $(AVRDUDE_PORT) -c $(AVRDUDE_PROGRAMMER)
 
@@ -227,7 +230,7 @@ ALL_ASFLAGS = -mmcu=$(MCU) -I. -x assembler-with-cpp $(ASFLAGS)
 
 
 # Default target.
-all: begin gccversion sizebefore $(TARGET).elf $(TARGET).hex $(TARGET).eep \
+all: begin gccversion sizebefore $(TARGET).elf $(TARGET).hex \
 	$(TARGET).lss $(TARGET).sym sizeafter finished end
 
 
@@ -286,7 +289,7 @@ extcoff: $(TARGET).elf
 
 
 # Program the device.  
-program: $(TARGET).hex $(TARGET).eep
+program: $(TARGET).hex eepromgen
 	$(AVRDUDE) $(AVRDUDE_FLAGS) $(AVRDUDE_WRITE_FLASH) $(AVRDUDE_WRITE_EEPROM)
 
 
@@ -298,11 +301,11 @@ program: $(TARGET).hex $(TARGET).eep
 	@echo $(MSG_FLASH) $@
 	$(OBJCOPY) -O $(FORMAT) -R .eeprom $< $@
 
-%.eep: %.elf
-	@echo
-	@echo $(MSG_EEPROM) $@
-	-$(OBJCOPY) -j .eeprom --set-section-flags=.eeprom="alloc,load" \
-	--change-section-lma .eeprom=0 -O $(FORMAT) $< $@
+# %.eep: %.elf
+# 	@echo
+# 	@echo $(MSG_EEPROM) $@
+# 	-$(OBJCOPY) -j .eeprom --set-section-flags=.eeprom="alloc,load" \
+# 	--change-section-lma .eeprom=0 -O $(FORMAT) $< $@
 
 # Create extended listing file from ELF output file.
 %.lss: %.elf
@@ -317,6 +320,9 @@ program: $(TARGET).hex $(TARGET).eep
 	avr-nm -n $< > $@
 
 
+eepromgen:
+	@echo
+	$(EEPROM_GEN_CMD)
 
 # Link: create ELF output file from object files.
 .SECONDARY : $(TARGET).elf
@@ -394,5 +400,5 @@ clean_list :
 
 # Listing of phony targets.
 .PHONY : all begin finish end sizebefore sizeafter gccversion coff extcoff \
-	clean clean_list program
+	clean clean_list program eepromgen
 
-- 
GitLab