Makefile 6.48 KB
Newer Older
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
# Copyright (C) 2012       Alejandro Mery <amery@geeks.cl>
# Copyright (C) 2012,2013  Henrik Nordstrom <henrik@henriknordstrom.net>
# Copyright (C) 2013       Patrick Wood <patrickhwood@gmail.com>
# Copyright (C) 2013       Pat Wood <Pat.Wood@efi.com>
#
# This program is free software: you can redistribute it and/or modify
# it under the terms of the GNU General Public License as published by
# the Free Software Foundation, either version 2 of the License, or
# (at your option) any later version.
#
# This program is distributed in the hope that it will be useful,
# but WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
# GNU General Public License for more details.
#
# You should have received a copy of the GNU General Public License
# along with this program.  If not, see <http://www.gnu.org/licenses/>.

19
20
21
# Windows predefines OS in the environment (to "Windows_NT"), otherwise use uname
OS ?= $(shell uname)

22
CC ?= gcc
23
24
DEFAULT_CFLAGS := -std=c99
DEFAULT_CFLAGS += -Wall -Wextra -Wno-unused-result
Alejandro Mery's avatar
Alejandro Mery committed
25

26
DEFAULT_CFLAGS += -D_POSIX_C_SOURCE=200112L
27
28
# Define _BSD_SOURCE, necessary to expose all endian conversions properly.
# 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
38
DEFAULT_CFLAGS += -Iinclude/

39
# Tools useful on host and target
40
TOOLS = sunxi-fexc sunxi-bootinfo sunxi-fel sunxi-nand-part sunxi-pio
Ian Campbell's avatar
Ian Campbell committed
41
42
43

# Symlinks to sunxi-fexc
FEXC_LINKS = bin2fex fex2bin
Alejandro Mery's avatar
Alejandro Mery committed
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
52
# ARM binaries and images
# Note: To use this target, set/adjust CROSS_COMPILE and MKSUNXIBOOT if needed
53
BINFILES = jtag-loop.sunxi fel-sdboot.sunxi uart0-helloworld-sdboot.sunxi
54
55

MKSUNXIBOOT ?= mksunxiboot
56
57
58
PATH_DIRS := $(shell echo $$PATH | sed -e 's/:/ /g')
# Try to guess a suitable default ARM cross toolchain
CROSS_DEFAULT := arm-none-eabi-
59
60
CROSS_COMPILE ?= $(or $(shell ./find-arm-gcc.sh),$(CROSS_DEFAULT))
CROSS_CC := $(CROSS_COMPILE)gcc
61

Ian Campbell's avatar
Ian Campbell committed
62
63
64
65
66
DESTDIR ?=
PREFIX  ?= /usr/local
BINDIR  ?= $(PREFIX)/bin

.PHONY: all clean tools target-tools install install-tools install-target-tools
67
.PHONY: check
68

Ian Campbell's avatar
Ian Campbell committed
69
tools: $(TOOLS) $(FEXC_LINKS)
70
target-tools: $(TARGET_TOOLS)
Alejandro Mery's avatar
Alejandro Mery committed
71

72
73
all: tools target-tools

74
misc: $(MISC_TOOLS)
75

76
77
binfiles: $(BINFILES)

78
79
install: install-tools
install-all: install-tools install-target-tools
Ian Campbell's avatar
Ian Campbell committed
80
81
82
83
84
85
86
87
88

install-tools: $(TOOLS)
	install -d $(DESTDIR)$(BINDIR)
	@set -ex ; for t in $^ ; do \
		install -m0755 $$t $(DESTDIR)$(BINDIR)/$$t ; \
	done
	@set -ex ; for l in $(FEXC_LINKS) ; do \
		ln -nfs sunxi-fexc $(DESTDIR)$(BINDIR)/$$l ; \
	done
Alejandro Mery's avatar
Alejandro Mery committed
89

Ian Campbell's avatar
Ian Campbell committed
90
91
92
93
94
95
install-target-tools: $(TARGET_TOOLS)
	install -d $(DESTDIR)$(BINDIR)
	@set -ex ; for t in $^ ; do \
		install -m0755 $$t $(DESTDIR)$(BINDIR)/$$t ; \
	done

96
97
98
99
100
101
install-misc: $(MISC_TOOLS)
	install -d $(DESTDIR)$(BINDIR)
	@set -ex ; for t in $^ ; do \
		install -m0755 $$t $(DESTDIR)$(BINDIR)/$$t ; \
	done

Ian Campbell's avatar
Ian Campbell committed
102
103

clean:
104
	make -C tests/ clean
Ian Campbell's avatar
Ian Campbell committed
105
	@rm -vf $(TOOLS) $(FEXC_LINKS) $(TARGET_TOOLS) $(MISC_TOOLS)
106
	@rm -vf version.h *.o *.elf *.sunxi *.bin *.nm *.orig
107

108
$(TOOLS) $(TARGET_TOOLS) $(MISC_TOOLS): Makefile common.h version.h
109

110
fex2bin bin2fex: sunxi-fexc
111
	ln -nsf $< $@
112

113
sunxi-fexc: fexc.h script.h script.c \
Alejandro Mery's avatar
Alejandro Mery committed
114
	script_uboot.h script_uboot.c \
115
116
	script_bin.h script_bin.c \
	script_fex.h script_fex.c
Alejandro Mery's avatar
Alejandro Mery committed
117

118
LIBUSB = libusb-1.0
119
120
LIBUSB_CFLAGS ?= `pkg-config --cflags $(LIBUSB)`
LIBUSB_LIBS ?= `pkg-config --libs $(LIBUSB)`
121
122
123
124
125

ZLIB = zlib
ZLIB_CFLAGS ?= `pkg-config --cflags $(ZLIB)`
ZLIB_LIBS ?= `pkg-config --libs $(ZLIB)`

126
127
ifeq ($(OS),Windows_NT)
	# Windows lacks mman.h / mmap()
128
	DEFAULT_CFLAGS += -DNO_MMAP
129
130
	# portable_endian.h relies on winsock2
	LIBS += -lws2_32
131
endif
132

133
134
HOST_CFLAGS = $(DEFAULT_CFLAGS) $(CFLAGS)

135
136
137
PROGRESS := progress.c progress.h
SOC_INFO := soc_info.c soc_info.h
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
141
	$(CC) $(HOST_CFLAGS) $(LIBUSB_CFLAGS) $(ZLIB_CFLAGS) $(LDFLAGS) -o $@ \
		$(filter %.c,$^) $(LIBS) $(LIBUSB_LIBS) $(ZLIB_LIBS)
142

143
sunxi-nand-part: nand-part-main.c nand-part.c nand-part-a10.h nand-part-a20.h
144
145
146
	$(CC) $(HOST_CFLAGS) -c -o nand-part-main.o nand-part-main.c
	$(CC) $(HOST_CFLAGS) -c -o nand-part-a10.o nand-part.c -D A10
	$(CC) $(HOST_CFLAGS) -c -o nand-part-a20.o nand-part.c -D A20
147
148
	$(CC) $(LDFLAGS) -o $@ nand-part-main.o nand-part-a10.o nand-part-a20.o $(LIBS)

149
sunxi-%: %.c
150
	$(CC) $(HOST_CFLAGS) $(LDFLAGS) -o $@ $(filter %.c,$^) $(LIBS)
151
phoenix_info: phoenix_info.c
152
	$(CC) $(HOST_CFLAGS) $(LDFLAGS) -o $@ $< $(LIBS)
153

154
155
156
157
158
159
%.bin: %.elf
	$(CROSS_COMPILE)objcopy -O binary $< $@

%.sunxi: %.bin
	$(MKSUNXIBOOT) $< $@

160
ARM_ELF_FLAGS = -Os -marm -fpic -Wall
161
ARM_ELF_FLAGS += -fno-common -fno-builtin -ffreestanding -nostdinc -fno-strict-aliasing
162
163
ARM_ELF_FLAGS += -mno-thumb-interwork -fno-stack-protector -fno-toplevel-reorder
ARM_ELF_FLAGS += -Wstrict-prototypes -Wno-format-nonliteral -Wno-format-security
164

165
jtag-loop.elf: jtag-loop.c jtag-loop.lds
166
	$(CROSS_CC) -g $(ARM_ELF_FLAGS) $< -nostdlib -o $@ -T jtag-loop.lds -Wl,-N
167

168
fel-sdboot.elf: fel-sdboot.S fel-sdboot.lds
169
	$(CROSS_CC) -g $(ARM_ELF_FLAGS) $< -nostdlib -o $@ -T fel-sdboot.lds -Wl,-N
170

171
uart0-helloworld-sdboot.elf: uart0-helloworld-sdboot.c uart0-helloworld-sdboot.lds
172
	$(CROSS_CC) -g $(ARM_ELF_FLAGS) $< -nostdlib -o $@ -T uart0-helloworld-sdboot.lds -Wl,-N
173

174
boot_head_sun3i.elf: boot_head.S boot_head.lds
175
	$(CROSS_CC) -g $(ARM_ELF_FLAGS) $< -nostdlib -o $@ -T boot_head.lds -Wl,-N -DMACHID=0x1094
176
177

boot_head_sun4i.elf: boot_head.S boot_head.lds
178
	$(CROSS_CC) -g $(ARM_ELF_FLAGS) $< -nostdlib -o $@ -T boot_head.lds -Wl,-N -DMACHID=0x1008
179
180

boot_head_sun5i.elf: boot_head.S boot_head.lds
181
	$(CROSS_CC) -g $(ARM_ELF_FLAGS) $< -nostdlib -o $@ -T boot_head.lds -Wl,-N -DMACHID=0x102A
182

183
sunxi-bootinfo: bootinfo.c
184

185
186
187
188
189
# "preprocessed" .h files for inclusion of ARM thunk code
headers:
	make -C thunks/ CROSS_COMPILE=$(CROSS_COMPILE)


190
# target tools
191
TARGET_CFLAGS = $(DEFAULT_CFLAGS) -static $(CFLAGS)
192
sunxi-meminfo: meminfo.c
193
	$(CROSS_CC) $(TARGET_CFLAGS) -o $@ $<
194
sunxi-script_extractor: script_extractor.c
195
	$(CROSS_CC) $(TARGET_CFLAGS) -o $@ $<
196

197
198
199
version.h:
	@./autoversion.sh > $@

Alejandro Mery's avatar
Alejandro Mery committed
200
.gitignore: Makefile
201
	@for x in $(TOOLS) $(FEXC_LINKS) $(TARGET_TOOLS) version.h '*.o' '*.swp'; do \
Alejandro Mery's avatar
Alejandro Mery committed
202
		echo "$$x"; \
203
	done | sort -V > $@
204
205
206

check: $(FEXC_LINKS)
	make -C tests/