Advertisement
Guest User

Untitled

a guest
Mar 13th, 2019
276
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 7.89 KB | None | 0 0
  1. # Copyright (C) 2012 Alejandro Mery <amery@geeks.cl>
  2. # Copyright (C) 2012,2013 Henrik Nordstrom <henrik@henriknordstrom.net>
  3. # Copyright (C) 2013 Patrick Wood <patrickhwood@gmail.com>
  4. # Copyright (C) 2013 Pat Wood <Pat.Wood@efi.com>
  5. #
  6. # This program is free software: you can redistribute it and/or modify
  7. # it under the terms of the GNU General Public License as published by
  8. # the Free Software Foundation, either version 2 of the License, or
  9. # (at your option) any later version.
  10. #
  11. # This program is distributed in the hope that it will be useful,
  12. # but WITHOUT ANY WARRANTY; without even the implied warranty of
  13. # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  14. # GNU General Public License for more details.
  15. #
  16. # You should have received a copy of the GNU General Public License
  17. # along with this program. If not, see <http://www.gnu.org/licenses/>.
  18.  
  19. # Windows predefines OS in the environment (to "Windows_NT"), otherwise use uname
  20. OS ?= $(shell uname)
  21.  
  22. CC ?= gcc
  23. DEFAULT_CFLAGS := -std=c99
  24. DEFAULT_CFLAGS += -Wall -Wextra -Wno-unused-result
  25.  
  26. DEFAULT_CFLAGS += -D_POSIX_C_SOURCE=200112L
  27. # Define _BSD_SOURCE, necessary to expose all endian conversions properly.
  28. # See http://linux.die.net/man/3/endian
  29. DEFAULT_CFLAGS += -D_BSD_SOURCE
  30. # glibc 2.20+ also requires _DEFAULT_SOURCE
  31. DEFAULT_CFLAGS += -D_DEFAULT_SOURCE
  32. ifeq ($(OS),NetBSD)
  33. # add explicit _NETBSD_SOURCE, see https://github.com/linux-sunxi/sunxi-tools/pull/22
  34. DEFAULT_CFLAGS += -D_NETBSD_SOURCE
  35. endif
  36.  
  37. DEFAULT_CFLAGS += -Iinclude/
  38.  
  39. # Tools useful on host and target
  40. TOOLS = sunxi-fexc sunxi-bootinfo sunxi-fel sunxi-nand-part sunxi-pio
  41.  
  42. # Symlinks to sunxi-fexc
  43. FEXC_LINKS = bin2fex fex2bin
  44.  
  45. # Tools which are only useful on the target
  46. TARGET_TOOLS = sunxi-meminfo
  47.  
  48. # Misc tools (of more "exotic" nature) not part of our default build / install
  49. MISC_TOOLS = phoenix_info sunxi-nand-image-builder
  50.  
  51. # ARM binaries and images
  52. # Note: To use this target, set/adjust CROSS_COMPILE and MKSUNXIBOOT if needed
  53. BINFILES = uart0-helloworld-sdboot.sunxi jtag-loop.sunxi fel-sdboot.sunxi
  54.  
  55. MKSUNXIBOOT ?= mksunxiboot
  56. PATH_DIRS := $(shell echo $$PATH | sed -e 's/:/ /g')
  57.  
  58. # Try to guess a suitable default ARM cross toolchain
  59. #CROSS_DEFAULT := arm-none-eabi-
  60. #CROSS_COMPILE ?= $(or $(shell ./find-arm-gcc.sh),$(CROSS_DEFAULT))
  61. #CROSS_CC := $(CROSS_COMPILE)gcc
  62.  
  63. CROSS_CC := arm-none-eabi-gcc
  64. #CROSS_CC := ~/Downloads/gcc-linaro-7.3.1-2018.05-x86_64_arm-linux-gnueabihf/bin/arm-linux-gnueabihf-gcc
  65. #CROSS_CC := ~/Downloads/gcc-linaro-7.3.1-2018.05-x86_64_arm-eabi/bin/arm-eabi-gcc
  66.  
  67. DESTDIR ?=
  68. PREFIX ?= /usr/local
  69. BINDIR ?= $(PREFIX)/bin
  70.  
  71. .PHONY: all clean tools target-tools install install-tools install-target-tools
  72. .PHONY: check
  73.  
  74. tools: $(TOOLS) $(FEXC_LINKS)
  75. target-tools: $(TARGET_TOOLS)
  76.  
  77. all: tools target-tools
  78.  
  79. misc: $(MISC_TOOLS)
  80.  
  81. binfiles: $(BINFILES)
  82.  
  83. install: install-tools
  84. install-all: install-tools install-target-tools
  85.  
  86. install-tools: $(TOOLS)
  87. install -d $(DESTDIR)$(BINDIR)
  88. @set -ex ; for t in $^ ; do \
  89. install -m0755 $$t $(DESTDIR)$(BINDIR)/$$t ; \
  90. done
  91. @set -ex ; for l in $(FEXC_LINKS) ; do \
  92. ln -nfs sunxi-fexc $(DESTDIR)$(BINDIR)/$$l ; \
  93. done
  94.  
  95. install-target-tools: $(TARGET_TOOLS)
  96. install -d $(DESTDIR)$(BINDIR)
  97. @set -ex ; for t in $^ ; do \
  98. install -m0755 $$t $(DESTDIR)$(BINDIR)/$$t ; \
  99. done
  100.  
  101. install-misc: $(MISC_TOOLS)
  102. install -d $(DESTDIR)$(BINDIR)
  103. @set -ex ; for t in $^ ; do \
  104. install -m0755 $$t $(DESTDIR)$(BINDIR)/$$t ; \
  105. done
  106.  
  107.  
  108. clean:
  109. make -C tests/ clean
  110. @rm -vf $(TOOLS) $(FEXC_LINKS) $(TARGET_TOOLS) $(MISC_TOOLS)
  111. @rm -vf version.h *.o *.elf *.sunxi *.bin *.nm *.orig
  112.  
  113. $(TOOLS) $(TARGET_TOOLS) $(MISC_TOOLS): Makefile common.h version.h
  114.  
  115. fex2bin bin2fex: sunxi-fexc
  116. ln -nsf $< $@
  117.  
  118. sunxi-fexc: fexc.h script.h script.c \
  119. script_uboot.h script_uboot.c \
  120. script_bin.h script_bin.c \
  121. script_fex.h script_fex.c
  122.  
  123. LIBUSB = libusb-1.0
  124. LIBUSB_CFLAGS ?= `pkg-config --cflags $(LIBUSB)`
  125. LIBUSB_LIBS ?= `pkg-config --libs $(LIBUSB)`
  126. ifeq ($(OS),Windows_NT)
  127. # Windows lacks mman.h / mmap()
  128. DEFAULT_CFLAGS += -DNO_MMAP
  129. # portable_endian.h relies on winsock2
  130. LIBS += -lws2_32
  131. endif
  132.  
  133. HOST_CFLAGS = $(DEFAULT_CFLAGS) $(CFLAGS)
  134.  
  135. PROGRESS := progress.c progress.h
  136. SOC_INFO := soc_info.c soc_info.h
  137. FEL_LIB := fel_lib.c fel_lib.h
  138.  
  139. sunxi-fel: fel.c thunks/fel-to-spl-thunk.h $(PROGRESS) $(SOC_INFO) $(FEL_LIB)
  140. $(CC) $(HOST_CFLAGS) $(LIBUSB_CFLAGS) $(LDFLAGS) -o $@ $(filter %.c,$^) $(LIBS) $(LIBUSB_LIBS)
  141.  
  142. sunxi-nand-part: nand-part-main.c nand-part.c nand-part-a10.h nand-part-a20.h
  143. $(CC) $(HOST_CFLAGS) -c -o nand-part-main.o nand-part-main.c
  144. $(CC) $(HOST_CFLAGS) -c -o nand-part-a10.o nand-part.c -D A10
  145. $(CC) $(HOST_CFLAGS) -c -o nand-part-a20.o nand-part.c -D A20
  146. $(CC) $(LDFLAGS) -o $@ nand-part-main.o nand-part-a10.o nand-part-a20.o $(LIBS)
  147.  
  148. sunxi-%: %.c
  149. $(CC) $(HOST_CFLAGS) $(LDFLAGS) -o $@ $(filter %.c,$^) $(LIBS)
  150. phoenix_info: phoenix_info.c
  151. $(CC) $(HOST_CFLAGS) $(LDFLAGS) -o $@ $< $(LIBS)
  152.  
  153. %.bin: %.elf
  154. $(CROSS_COMPILE)objcopy -O binary $< $@
  155.  
  156. %.sunxi: %.bin
  157. $(MKSUNXIBOOT) $< $@
  158.  
  159. #ARM_ELF_FLAGS = -Os
  160.  
  161. #ARM_ELF_FLAGS = -marm -fpic -Wall
  162. #ARM_ELF_FLAGS += -fno-common -fno-builtin -ffreestanding -nostdinc -fno-strict-aliasing
  163. #ARM_ELF_FLAGS += -mno-thumb-interwork -fno-stack-protector -fno-toplevel-reorder
  164. #ARM_ELF_FLAGS += -Wstrict-prototypes -Wno-format-nonliteral -Wno-format-security
  165.  
  166. #ARM_ELF_FLAGS += -mcpu=cortex-a8
  167. #ARM_ELF_FLAGS += -mcpu=cortex-a7
  168. #ARM_ELF_FLAGS += -g0
  169. #ARM_ELF_FLAGS += -fomit-frame-pointer
  170. #necessary for divisions
  171. #ARM_ELF_FLAGS += -L
  172. #ARM_ELF_FLAGS += -ffreestanding
  173.  
  174.  
  175. ARM_ELF_FLAGS = -Os -marm -fpic -Wall
  176. #ARM_ELF_FLAGS = -marm -fpic -Wall
  177.  
  178.  
  179. ARM_ELF_FLAGS += -fno-common -fno-builtin -ffreestanding -nostdinc -fno-strict-aliasing
  180. ARM_ELF_FLAGS += -mno-thumb-interwork -fno-stack-protector -fno-toplevel-reorder
  181. ARM_ELF_FLAGS += -Wstrict-prototypes -Wno-format-nonliteral -Wno-format-security
  182.  
  183.  
  184. #ARM_ELF_FLAGS = -marm -fpic -Wall -fomit-frame-pointer
  185. #ARM_ELF_FLAGS += -mcpu=cortex-a7
  186.  
  187. main.elf: main.c main.lds
  188. #$(CROSS_CC) -g $(ARM_ELF_FLAGS) $< -nostdlib -o $@ -T main.lds -Wl,-N,-lgcc
  189. $(CROSS_CC) -g $(ARM_ELF_FLAGS) $< -nostdlib -o $@ -T main.lds -Wl,-N
  190.  
  191.  
  192.  
  193.  
  194. jtag-loop.elf: jtag-loop.c jtag-loop.lds
  195. $(CROSS_CC) -g $(ARM_ELF_FLAGS) $< -nostdlib -o $@ -T jtag-loop.lds -Wl,-N
  196.  
  197. fel-sdboot.elf: fel-sdboot.S fel-sdboot.lds
  198. $(CROSS_CC) -g $(ARM_ELF_FLAGS) $< -nostdlib -o $@ -T fel-sdboot.lds -Wl,-N
  199.  
  200.  
  201. uart0-helloworld-sdboot.elf: uart0-helloworld-sdboot.c uart0-helloworld-sdboot.lds
  202. $(CROSS_CC) -g $(ARM_ELF_FLAGS) $< -nostdlib -o $@ -T uart0-helloworld-sdboot.lds -Wl,-N
  203.  
  204.  
  205. sbrom_test.elf: sbrom_test.c sbrom_test.lds
  206. $(CROSS_CC) -g $(ARM_ELF_FLAGS) $< -nostdlib -o $@ -T sbrom_test.lds -Wl,-N
  207.  
  208. burn_secure_bit.elf: burn_secure_bit.c burn_secure_bit.lds
  209. $(CROSS_CC) -g $(ARM_ELF_FLAGS) $< -nostdlib -o $@ -T burn_secure_bit.lds -Wl,-N
  210.  
  211.  
  212. boot_head_sun3i.elf: boot_head.S boot_head.lds
  213. $(CROSS_CC) -g $(ARM_ELF_FLAGS) $< -nostdlib -o $@ -T boot_head.lds -Wl,-N -DMACHID=0x1094
  214.  
  215. boot_head_sun4i.elf: boot_head.S boot_head.lds
  216. $(CROSS_CC) -g $(ARM_ELF_FLAGS) $< -nostdlib -o $@ -T boot_head.lds -Wl,-N -DMACHID=0x1008
  217.  
  218. boot_head_sun5i.elf: boot_head.S boot_head.lds
  219. $(CROSS_CC) -g $(ARM_ELF_FLAGS) $< -nostdlib -o $@ -T boot_head.lds -Wl,-N -DMACHID=0x102A
  220.  
  221. sunxi-bootinfo: bootinfo.c
  222.  
  223. # "preprocessed" .h files for inclusion of ARM thunk code
  224. headers:
  225. make -C thunks/ CROSS_COMPILE=$(CROSS_COMPILE)
  226.  
  227.  
  228. # target tools
  229. TARGET_CFLAGS = $(DEFAULT_CFLAGS) -static $(CFLAGS)
  230. sunxi-meminfo: meminfo.c
  231. $(CROSS_CC) $(TARGET_CFLAGS) -o $@ $<
  232. sunxi-script_extractor: script_extractor.c
  233. $(CROSS_CC) $(TARGET_CFLAGS) -o $@ $<
  234.  
  235. version.h:
  236. @./autoversion.sh > $@
  237.  
  238. .gitignore: Makefile
  239. @for x in $(TOOLS) $(FEXC_LINKS) $(TARGET_TOOLS) version.h '*.o' '*.swp'; do \
  240. echo "$$x"; \
  241. done | sort -V > $@
  242.  
  243. check: $(FEXC_LINKS)
  244. make -C tests/
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement