Makefile 5.54 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
CC ?= gcc
20
CFLAGS = -g -O0 -Wall -Wextra $(EXTRA_CFLAGS)
21
CFLAGS += -std=c99 $(DEFINES)
22
CFLAGS += -Iinclude/
Alejandro Mery's avatar
Alejandro Mery committed
23

24
25
26
27
28
29
DEFINES = -D_POSIX_C_SOURCE=200112L
# Define _BSD_SOURCE, necessary to expose all endian conversions properly.
# See http://linux.die.net/man/3/endian
DEFINES += -D_BSD_SOURCE
# glibc 2.20+ also requires _DEFAULT_SOURCE
DEFINES += -D_DEFAULT_SOURCE
30
31
32
33
ifeq (NetBSD,$(OS))
# add explicit _NETBSD_SOURCE, see https://github.com/linux-sunxi/sunxi-tools/pull/22
DEFINES += -D_NETBSD_SOURCE
endif
34

35
# Tools useful on host and target
Ian Campbell's avatar
Ian Campbell committed
36
37
38
39
TOOLS = sunxi-fexc sunxi-bootinfo sunxi-fel sunxi-nand-part

# Symlinks to sunxi-fexc
FEXC_LINKS = bin2fex fex2bin
Alejandro Mery's avatar
Alejandro Mery committed
40

41
42
43
# Tools which are only useful on the target
TARGET_TOOLS = sunxi-pio

44
MISC_TOOLS = phoenix_info sunxi-nand-image-builder
45

46
47
# ARM binaries and images
# Note: To use this target, set/adjust CROSS_COMPILE and MKSUNXIBOOT if needed
48
BINFILES = fel-pio.bin jtag-loop.sunxi fel-sdboot.sunxi uart0-helloworld-sdboot.sunxi
49

50
CROSS_COMPILE ?= arm-none-eabi-
51
MKSUNXIBOOT ?= mksunxiboot
52

Ian Campbell's avatar
Ian Campbell committed
53
54
55
56
57
DESTDIR ?=
PREFIX  ?= /usr/local
BINDIR  ?= $(PREFIX)/bin

.PHONY: all clean tools target-tools install install-tools install-target-tools
58
59

all: tools target-tools
Alejandro Mery's avatar
Alejandro Mery committed
60

Ian Campbell's avatar
Ian Campbell committed
61
tools: $(TOOLS) $(FEXC_LINKS)
62
target-tools: $(TARGET_TOOLS)
Alejandro Mery's avatar
Alejandro Mery committed
63

64
misc: version.h $(MISC_TOOLS)
65

66
67
binfiles: $(BINFILES)

Ian Campbell's avatar
Ian Campbell committed
68
69
70
71
72
73
74
75
76
77
install: install-tools install-target-tools

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
78

Ian Campbell's avatar
Ian Campbell committed
79
80
81
82
83
84
85
86
87
install-target-tools: $(TARGET_TOOLS)
	install -d $(DESTDIR)$(BINDIR)
	@set -ex ; for t in $^ ; do \
		install -m0755 $$t $(DESTDIR)$(BINDIR)/$$t ; \
	done


clean:
	@rm -vf $(TOOLS) $(FEXC_LINKS) $(TARGET_TOOLS) $(MISC_TOOLS)
88
	@rm -vf version.h *.o *.elf *.sunxi *.bin *.nm *.orig
89

90
$(TOOLS) $(TARGET_TOOLS): Makefile common.h version.h
91

92
fex2bin bin2fex: sunxi-fexc
93
	ln -nsf $< $@
94

95
sunxi-fexc: fexc.h script.h script.c \
Alejandro Mery's avatar
Alejandro Mery committed
96
	script_uboot.h script_uboot.c \
97
98
	script_bin.h script_bin.c \
	script_fex.h script_fex.c
Alejandro Mery's avatar
Alejandro Mery committed
99

100
LIBUSB = libusb-1.0
101
102
LIBUSB_CFLAGS ?= `pkg-config --cflags $(LIBUSB)`
LIBUSB_LIBS ?= `pkg-config --libs $(LIBUSB)`
103
104
105
ifeq ($(OS),Windows_NT)
	# Windows lacks mman.h / mmap()
	DEFINES += -DNO_MMAP
106
107
	# portable_endian.h relies on winsock2
	LIBS += -lws2_32
108
endif
109

110
sunxi-fel: fel.c fel-to-spl-thunk.h progress.c progress.h
111
112
	$(CC) $(CFLAGS) $(LIBUSB_CFLAGS) $(LDFLAGS) -o $@ $(filter %.c,$^) $(LIBS) $(LIBUSB_LIBS)

113
sunxi-nand-part: nand-part-main.c nand-part.c nand-part-a10.h nand-part-a20.h
114
115
116
117
118
	$(CC) $(CFLAGS) -c -o nand-part-main.o nand-part-main.c
	$(CC) $(CFLAGS) -c -o nand-part-a10.o nand-part.c -D A10
	$(CC) $(CFLAGS) -c -o nand-part-a20.o nand-part.c -D A20
	$(CC) $(LDFLAGS) -o $@ nand-part-main.o nand-part-a10.o nand-part-a20.o $(LIBS)

119
sunxi-%: %.c
120
	$(CC) $(CFLAGS) $(LDFLAGS) -o $@ $(filter %.c,$^) $(LIBS)
121

122
123
124
125
126
127
%.bin: %.elf
	$(CROSS_COMPILE)objcopy -O binary $< $@

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

128
fel-pio.bin: fel-pio.elf fel-pio.nm
129

130
ARM_ELF_FLAGS = -Os -marm -fpic -Wall
131
ARM_ELF_FLAGS += -fno-common -fno-builtin -ffreestanding -nostdinc -fno-strict-aliasing
132
133
ARM_ELF_FLAGS += -mno-thumb-interwork -fno-stack-protector -fno-toplevel-reorder
ARM_ELF_FLAGS += -Wstrict-prototypes -Wno-format-nonliteral -Wno-format-security
134

135
fel-pio.elf: fel-pio.c fel-pio.lds
136
	$(CROSS_COMPILE)gcc  -g  $(ARM_ELF_FLAGS)  $< -nostdlib -o $@ -T fel-pio.lds
137
138

fel-pio.nm: fel-pio.elf
139
	$(CROSS_COMPILE)nm $< | grep -v " _" >$@
140
141

jtag-loop.elf: jtag-loop.c jtag-loop.lds
142
	$(CROSS_COMPILE)gcc  -g  $(ARM_ELF_FLAGS)  $< -nostdlib -o $@ -T jtag-loop.lds -Wl,-N
143

144
fel-sdboot.elf: fel-sdboot.S fel-sdboot.lds
145
	$(CROSS_COMPILE)gcc  -g  $(ARM_ELF_FLAGS)  $< -nostdlib -o $@ -T fel-sdboot.lds -Wl,-N
146

147
148
149
uart0-helloworld-sdboot.elf: uart0-helloworld-sdboot.c uart0-helloworld-sdboot.lds
	$(CROSS_COMPILE)gcc  -g  $(ARM_ELF_FLAGS)  $< -nostdlib -o $@ -T uart0-helloworld-sdboot.lds -Wl,-N

150
151
boot_head_sun3i.elf: boot_head.S boot_head.lds
	$(CROSS_COMPILE)gcc  -g  $(ARM_ELF_FLAGS)  $< -nostdlib -o $@ -T boot_head.lds -Wl,-N -DMACHID=0x1094
152
153

boot_head_sun4i.elf: boot_head.S boot_head.lds
154
	$(CROSS_COMPILE)gcc  -g  $(ARM_ELF_FLAGS)  $< -nostdlib -o $@ -T boot_head.lds -Wl,-N -DMACHID=0x1008
155
156

boot_head_sun5i.elf: boot_head.S boot_head.lds
157
	$(CROSS_COMPILE)gcc  -g  $(ARM_ELF_FLAGS)  $< -nostdlib -o $@ -T boot_head.lds -Wl,-N -DMACHID=0x102A
158

159
sunxi-bootinfo: bootinfo.c
160

161
sunxi-meminfo: meminfo.c
162
163
	$(CROSS_COMPILE)gcc -g -O0 -Wall -static -o $@ $^

164
165
166
sunxi-script_extractor: script_extractor.c
	$(CROSS_COMPILE)gcc -g -O0 -Wall -static -o $@ $^

167
168
169
version.h:
	@./autoversion.sh > $@

Alejandro Mery's avatar
Alejandro Mery committed
170
.gitignore: Makefile
171
	@for x in $(TOOLS) $(FEXC_LINKS) $(TARGET_TOOLS) version.h '*.o' '*.swp'; do \
Alejandro Mery's avatar
Alejandro Mery committed
172
		echo "$$x"; \
173
	done | sort -V > $@