Makefile 5.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193
  1. # Copyright (c) 2009 Openmoko Inc.
  2. #
  3. # This program is free software: you can redistribute it and/or modify
  4. # it under the terms of the GNU General Public License as published by
  5. # the Free Software Foundation, either version 3 of the License, or
  6. # (at your option) any later version.
  7. #
  8. # This program is distributed in the hope that it will be useful,
  9. # but WITHOUT ANY WARRANTY; without even the implied warranty of
  10. # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  11. # GNU General Public License for more details.
  12. #
  13. # You should have received a copy of the GNU General Public License
  14. # along with this program. If not, see <http://www.gnu.org/licenses/>.
  15. # to minimise code in boot loader only remove all write functions
  16. # from file system code
  17. FATFS_MODE = read-only
  18. # +++START_UPDATE_MAKEFILE: Start of auto included code
  19. # The text between the +++ and --- tags is copied by the
  20. # UpdateMakefiles script. Do not remove or change these tags.
  21. # ---
  22. # Autodetect root directory
  23. define FIND_ROOT_DIR
  24. while : ; do \
  25. d=$$(pwd) ; \
  26. [ -d "$${d}/samo-lib" ] && echo $${d} && exit 0 ; \
  27. [ X"/" = X"$${d}" ] && echo ROOT_DIRECTORY_NOT_FOUND && exit 1 ; \
  28. cd .. ; \
  29. done
  30. endef
  31. ROOT_DIR := $(shell ${FIND_ROOT_DIR})
  32. # Directory of Makefile includes
  33. MK_DIR := ${ROOT_DIR}/samo-lib/Mk
  34. # Include the initial Makefile setup
  35. include ${MK_DIR}/definitions.mk
  36. # ---END_UPDATE_MAKEFILE: End of auto included code
  37. $(call REQUIRED_BINARY, ${AWK}, awk)
  38. # set this to 0 or 1 to control the battery indicator in menu.c
  39. BATTERY_METER ?= 0
  40. # use update YES or NO
  41. # YES => only change serial number if mbr version is ok
  42. # NO => full update even if this will downgrade the mbr
  43. FLASH_ROM_MAP_FILE ?= SAMO_A1.mapfile
  44. FLASH07 ?= ${HOST_TOOLS}/flash07/flash07
  45. IMAGE07 ?= ${HOST_TOOLS}/flash07/image07
  46. ifeq (YES,$(strip ${FLASH_TEST_JIG}))
  47. BOOT_FILE ?= ${HOST_TOOLS}/jackknife/jakebrake
  48. PROTECT = --protect
  49. else
  50. BOOT_FILE ?= ${HOST_TOOLS}/jackknife/jackknife
  51. PROTECT =
  52. endif
  53. LIBS += ${DRIVERS_LIB}
  54. LIBS += ${FATFS_LIB}
  55. LIBS += ${DRIVERS_LIB}
  56. LIBS += ${MINI_LIBC_LIB}
  57. LIBS += $(shell ${CC} -print-libgcc-file-name)
  58. LDFLAGS = -static --strip-all -s --no-gc-sections -N -L${MINI_LIBC}
  59. INCLUDES = -I${FATFS_INCLUDE}
  60. INCLUDES += -I${FATFS_CONFIG_INCLUDE}
  61. INCLUDES += -I${MINI_LIBC_INCLUDE}
  62. INCLUDES += -I${DRIVERS_INCLUDE}
  63. INCLUDES += -I${SAMO_LIB_INCLUDE}
  64. OBJCOPY_FLAGS = -I elf32-c33 -O binary
  65. OBJCOPY_SECTIONS = --only-section=.text
  66. OBJCOPY_SECTIONS += --only-section=.rodata
  67. OBJCOPY_SECTIONS += --only-section=.data
  68. TARGETS = ${FLASH_ROM_MAP_FILE} mbr serial.header
  69. APPLICATIONS =
  70. APPLICATION_CLEAN =
  71. CFLAGS += -DBATTERY_METER="${BATTERY_METER}"
  72. vpath %.c
  73. .PHONY: all
  74. all: ${TARGETS} all-applications flash.rom
  75. # Master boot record - a multiple program boot loader
  76. ${FLASH_ROM_MAP_FILE}:
  77. cp SAMO_A1.mapfile-default ${FLASH_ROM_MAP_FILE}
  78. flash.rom: ${FLASH_ROM_MAP_FILE} ${TARGETS} all-applications
  79. ${IMAGE07} --image-file="$@" --map-file="${FLASH_ROM_MAP_FILE}"
  80. mbr.elf: mbr.o
  81. ${CC} -o $@ ${LDFLAGS} $^ -Wl,'-Ttext=0',-Map,${@:.elf=.map}
  82. ${OBJDUMP} --disassemble-all $@ > ${@:.elf=.dump}
  83. mbr: mbr.elf
  84. ${RM} "$@"
  85. ${OBJCOPY} ${OBJCOPY_FLAGS} ${OBJCOPY_SECTIONS} --set-start=0 $< $@
  86. @c=$$(wc --bytes < "$@") ; \
  87. echo mbr size = $${c} bytes, max = 512 bytes ; \
  88. if [ "$${c}" -gt 512 ]; then ${RM} "$@"; exit 99; fi
  89. mbr-rs232: SAMO_A1.mapfile-rs232 mbr
  90. cp SAMO_A1.mapfile-rs232 ${FLASH_ROM_MAP_FILE}
  91. # macro to create application rules
  92. # $call MAKE_APP, app_name, file1.o file2.o, <optional pre-depends>)
  93. # Note: 1. list of objects/pre-depends are _space_ separated
  94. # 2. eeprom is removed as this is provided by mbr
  95. # 3. strip and _NO_ spaces after comma (make passes all spaces to arguments)
  96. MAKE_APP = $(eval $(call MAKE_APP1,$(strip ${1}),$(strip ${2}),$(strip ${3})))
  97. define MAKE_APP1
  98. APPLICATIONS += ${1}
  99. APPLICATIONS_CLEAN += ${1} ${1}.elf ${1}.header
  100. ${1}.elf: ${2} application.lds ${1}.o $${LIBS}
  101. $${LD} -T application.lds -o $$@ $${LDFLAGS} ${1}.o $${LIBS} -Map $${@:.elf=.map}
  102. $${OBJDUMP} --disassemble-all $$@ > $${@:.elf=.dump}
  103. ${1}: ${1}.elf ${1}.header
  104. $${OBJCOPY} $${OBJCOPY_FLAGS} $${OBJCOPY_SECTIONS} $$< $$@
  105. endef
  106. # Applications for the boot loader
  107. IMAGE_HEADERS = splash.h empty.h adjust.h
  108. $(call MAKE_APP,version)
  109. $(call MAKE_APP,menu,${IMAGE_HEADERS})
  110. $(call MAKE_APP,hello)
  111. $(call MAKE_APP,memory-test)
  112. $(call MAKE_APP,hw-test)
  113. $(call MAKE_APP,file-loader)
  114. $(call MAKE_APP,rs232-loader)
  115. # rule to build all above applications
  116. .PHONY: all-applications
  117. all-applications: ${APPLICATIONS}
  118. ifeq (YES,$(strip ${FLASH_UPDATE}))
  119. UPDATE_ARGS = --update
  120. else
  121. UPDATE_ARGS =
  122. endif
  123. flash-mbr: all
  124. time ${FLASH07} ${PROTECT} --port="${BOOTLOADER_TTY}" --aux-port="${BOOTLOADER_AUX}" --boot="${BOOT_FILE}" \
  125. --map-file="${FLASH_ROM_MAP_FILE}" ${UPDATE_ARGS}
  126. # serial number must be padded with 0xFF as that is
  127. # the value of erased FLASH memory bytes
  128. # Note: the dd commands below are required to pad and truncate
  129. # the serial number correctly
  130. # the swapped bs and count are intentional as the () code
  131. # produces two writes and the final dd takes just 32 bytes
  132. .PHONY: always-build
  133. serial.header: always-build
  134. ( echo -n ${SERIAL_NUMBER} ; \
  135. dd bs=32 count=1 if=/dev/zero | tr '\0' '\377' ; \
  136. ) | dd bs=1 count=32 > "$@"
  137. .PHONY: install
  138. install: all
  139. @if [ ! -d "${DESTDIR}" ] ; then echo DESTDIR: "'"${DESTDIR}"'" is not a directory ; exit 1; fi
  140. ${COPY} flash.rom "${DESTDIR}"
  141. .PHONY: clean
  142. clean:
  143. ${RM} ${TARGETS} ${APPLICATIONS_CLEAN} ${IMAGE_HEADERS}
  144. ${RM} *.o *.elf *.d *.p *.asm33 *.header *.map *.rom *.dump
  145. # application headers
  146. %.header: %.c
  147. ${AWK} -f GenerateApplicationHeader.awk "$<" >"$@"
  148. include ${MK_DIR}/rules.mk