3 #     Copyright (C) Dean Camera, 2015.
 
   5 #  dean [at] fourwalledcubicle [dot] com
 
   8 # --------------------------------------
 
   9 #         LUFA Project Makefile.
 
  10 # --------------------------------------
 
  12 # Run "make help" for target help.
 
  20 TARGET       = BootloaderMassStorage
 
  21 SRC          = $(TARGET).c Descriptors.c BootloaderAPI.c BootloaderAPITable.S Lib/SCSI.c Lib/VirtualFAT.c $(LUFA_SRC_USB) $(LUFA_SRC_USBCLASS)
 
  22 LUFA_PATH    = ../../LUFA
 
  23 CC_FLAGS     = -DUSE_LUFA_CONFIG_HEADER -IConfig/ -DBOOT_START_ADDR=$(BOOT_START_OFFSET)
 
  24 LD_FLAGS     = -Wl,--section-start=.text=$(BOOT_START_OFFSET) $(BOOT_API_LD_FLAGS)
 
  26 # Flash size and bootloader section sizes of the target, in KB. These must
 
  27 # match the target's total FLASH size and the bootloader size set in the
 
  30 BOOT_SECTION_SIZE_KB  = 8
 
  32 # Bootloader address calculation formulas
 
  33 # Do not modify these macros, but rather modify the dependent values above.
 
  34 CALC_ADDRESS_IN_HEX   = $(shell printf "0x%X" $$(( $(1) )) )
 
  35 BOOT_START_OFFSET     = $(call CALC_ADDRESS_IN_HEX, ($(FLASH_SIZE_KB) - $(BOOT_SECTION_SIZE_KB)) * 1024 )
 
  36 BOOT_SEC_OFFSET       = $(call CALC_ADDRESS_IN_HEX, ($(FLASH_SIZE_KB) * 1024) - ($(strip $(1))) )
 
  38 # Bootloader linker section flags for relocating the API table sections to
 
  39 # known FLASH addresses - these should not normally be user-edited.
 
  40 BOOT_SECTION_LD_FLAG  = -Wl,--section-start=$(strip $(1))=$(call BOOT_SEC_OFFSET, $(3)) -Wl,--undefined=$(strip $(2))
 
  41 BOOT_API_LD_FLAGS     = $(call BOOT_SECTION_LD_FLAG, .apitable_trampolines, BootloaderAPI_Trampolines, 96)
 
  42 BOOT_API_LD_FLAGS    += $(call BOOT_SECTION_LD_FLAG, .apitable_jumptable,   BootloaderAPI_JumpTable,   32)
 
  43 BOOT_API_LD_FLAGS    += $(call BOOT_SECTION_LD_FLAG, .apitable_signatures,  BootloaderAPI_Signatures,  8)
 
  45 # Check if the bootloader needs an AUX section, located before the real bootloader section to store some of the
 
  46 # bootloader code. This is required for 32KB and smaller devices, where the actual bootloader is 6KB but the maximum
 
  47 # bootloader section size is 4KB. The actual usable application space will be reduced by 6KB for these devices.
 
  48 ifeq ($(BOOT_SECTION_SIZE_KB),8)
 
  49   CC_FLAGS           += -DAUX_BOOT_SECTION_SIZE=0
 
  51   AUX_BOOT_SECTION_SIZE_KB = (6 - $(BOOT_SECTION_SIZE_KB))
 
  53   CC_FLAGS           += -DAUX_BOOT_SECTION_SIZE='($(AUX_BOOT_SECTION_SIZE_KB) * 1024)'
 
  54   LD_FLAGS           += -Wl,--section-start=.boot_aux=$(call BOOT_SEC_OFFSET, (($(BOOT_SECTION_SIZE_KB) + $(AUX_BOOT_SECTION_SIZE_KB)) * 1024 - 16))
 
  55   LD_FLAGS           += $(call BOOT_SECTION_LD_FLAG, .boot_aux_trampoline, Boot_AUX_Trampoline, ($(BOOT_SECTION_SIZE_KB) + $(AUX_BOOT_SECTION_SIZE_KB)) * 1024)
 
  61 # Include LUFA build script makefiles
 
  62 include $(LUFA_PATH)/Build/lufa_core.mk
 
  63 include $(LUFA_PATH)/Build/lufa_sources.mk
 
  64 include $(LUFA_PATH)/Build/lufa_build.mk
 
  65 include $(LUFA_PATH)/Build/lufa_cppcheck.mk
 
  66 include $(LUFA_PATH)/Build/lufa_doxygen.mk
 
  67 include $(LUFA_PATH)/Build/lufa_avrdude.mk
 
  68 include $(LUFA_PATH)/Build/lufa_atprogram.mk