Makefile 6.29 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
21
CFLAGS += -std=c99 $(DEFINES)
22
CFLAGS += -Iinclude/
Alejandro Mery's avatar
Alejandro Mery committed
23

24
25
26
27
28
29
30
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

31
# Tools useful on host and target
Ian Campbell's avatar
Ian Campbell committed
32
33
34
35
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
36

37
38
39
# Tools which are only useful on the target
TARGET_TOOLS = sunxi-pio

40
41
MISC_TOOLS = phoenix_info

42
43
CROSS_COMPILE ?= arm-none-eabi-

Ian Campbell's avatar
Ian Campbell committed
44
45
46
47
48
DESTDIR ?=
PREFIX  ?= /usr/local
BINDIR  ?= $(PREFIX)/bin

.PHONY: all clean tools target-tools install install-tools install-target-tools
49
50

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

Ian Campbell's avatar
Ian Campbell committed
52
tools: $(TOOLS) $(FEXC_LINKS)
53
target-tools: $(TARGET_TOOLS)
Alejandro Mery's avatar
Alejandro Mery committed
54

55
56
misc: $(MISC_TOOLS)

Ian Campbell's avatar
Ian Campbell committed
57
58
59
60
61
62
63
64
65
66
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
67

Ian Campbell's avatar
Ian Campbell committed
68
69
70
71
72
73
74
75
76
77
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)
	@rm -vf *.o *.elf *.sunxi *.bin *.nm *.orig
78

79
$(TOOLS) $(TARGET_TOOLS): Makefile common.h
80

81
fex2bin bin2fex: sunxi-fexc
82
	ln -nsf $< $@
83

84
sunxi-fexc: fexc.h script.h script.c \
Alejandro Mery's avatar
Alejandro Mery committed
85
	script_uboot.h script_uboot.c \
86
87
	script_bin.h script_bin.c \
	script_fex.h script_fex.c
Alejandro Mery's avatar
Alejandro Mery committed
88

89
90
91
92
LIBUSB = libusb-1.0
LIBUSB_CFLAGS = `pkg-config --cflags $(LIBUSB)`
LIBUSB_LIBS = `pkg-config --libs $(LIBUSB)`

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

96
sunxi-nand-part: nand-part-main.c nand-part.c nand-part-a10.h nand-part-a20.h
97
98
99
100
101
	$(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)

102
sunxi-%: %.c
103
	$(CC) $(CFLAGS) $(LDFLAGS) -o $@ $(filter %.c,$^) $(LIBS)
104

105
fel-pio.bin: fel-pio.elf fel-pio.nm
106
	$(CROSS_COMPILE)objcopy -O binary fel-pio.elf fel-pio.bin
107

108
109
fel-pio.elf: fel-pio.c fel-pio.lds
	$(CROSS_COMPILE)gcc  -g  -Os -fpic  -fno-common -fno-builtin -ffreestanding -nostdinc -mno-thumb-interwork -Wall -Wstrict-prototypes -fno-stack-protector -Wno-format-nonliteral -Wno-format-security -fno-toplevel-reorder  fel-pio.c -nostdlib -o fel-pio.elf -T fel-pio.lds
110
111

fel-pio.nm: fel-pio.elf
112
113
114
115
116
117
118
119
120
121
	$(CROSS_COMPILE)nm fel-pio.elf | grep -v " _" >fel-pio.nm

jtag-loop.elf: jtag-loop.c jtag-loop.lds
	$(CROSS_COMPILE)gcc  -g  -Os  -fpic -fno-common -fno-builtin -ffreestanding -nostdinc -mno-thumb-interwork -Wall -Wstrict-prototypes -fno-stack-protector -Wno-format-nonliteral -Wno-format-security -fno-toplevel-reorder  jtag-loop.c -nostdlib -o jtag-loop.elf -T jtag-loop.lds -Wl,-N

jtag-loop.bin: jtag-loop.elf
	$(CROSS_COMPILE)objcopy -O binary jtag-loop.elf jtag-loop.bin

jtag-loop.sunxi: jtag-loop.bin
	mksunxiboot jtag-loop.bin jtag-loop.sunxi
122

123
124
fel-sdboot.elf: fel-sdboot.c fel-sdboot.lds
	$(CROSS_COMPILE)gcc  -g  -Os  -fpic -fno-common -fno-builtin -ffreestanding -nostdinc -mno-thumb-interwork -Wall -Wstrict-prototypes -fno-stack-protector -Wno-format-nonliteral -Wno-format-security -fno-toplevel-reorder  fel-sdboot.c -nostdlib -o fel-sdboot.elf -T fel-sdboot.lds -Wl,-N
125

126
127
fel-sdboot.bin: fel-sdboot.elf
	$(CROSS_COMPILE)objcopy -O binary fel-sdboot.elf fel-sdboot.bin
128

129
130
fel-sdboot.sunxi: fel-sdboot.bin
	mksunxiboot fel-sdboot.bin fel-sdboot.sunxi
131

132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
boot_head_sun3i.elf: boot_head_sun3i.S boot_head_sun3i.lds
	$(CROSS_COMPILE)gcc  -g  -Os  -fpic -fno-common -fno-builtin -ffreestanding -nostdinc -mno-thumb-interwork -Wall -Wstrict-prototypes -fno-stack-protector -Wno-format-nonliteral -Wno-format-security -fno-toplevel-reorder  boot_head.S -nostdlib -o boot_head_sun3i.elf -T boot_head.lds -Wl,-N -DMACHID=0x1094

boot_head_sun3i.bin: boot_head_sun3i.elf
	$(CROSS_COMPILE)objcopy -O binary boot_head_sun3i.elf boot_head_sun3i.bin

boot_head_sun4i.elf: boot_head.S boot_head.lds
	$(CROSS_COMPILE)gcc  -g  -Os  -fpic -fno-common -fno-builtin -ffreestanding -nostdinc -mno-thumb-interwork -Wall -Wstrict-prototypes -fno-stack-protector -Wno-format-nonliteral -Wno-format-security -fno-toplevel-reorder  boot_head.S -nostdlib -o boot_head_sun4i.elf -T boot_head.lds -Wl,-N -DMACHID=0x1008

boot_head_sun4i.bin: boot_head_sun4i.elf
	$(CROSS_COMPILE)objcopy -O binary boot_head_sun4i.elf boot_head_sun4i.bin

boot_head_sun5i.elf: boot_head.S boot_head.lds
	$(CROSS_COMPILE)gcc  -g  -Os  -fpic -fno-common -fno-builtin -ffreestanding -nostdinc -mno-thumb-interwork -Wall -Wstrict-prototypes -fno-stack-protector -Wno-format-nonliteral -Wno-format-security -fno-toplevel-reorder  boot_head.S -nostdlib -o boot_head_sun5i.elf -T boot_head.lds -Wl,-N -DMACHID=0x102A

boot_head_sun5i.bin: boot_head_sun5i.elf
	$(CROSS_COMPILE)objcopy -O binary boot_head_sun5i.elf boot_head_sun5i.bin

150
sunxi-bootinfo: bootinfo.c
151

152
sunxi-meminfo: meminfo.c
153
154
	$(CROSS_COMPILE)gcc -g -O0 -Wall -static -o $@ $^

155
156
157
sunxi-script_extractor: script_extractor.c
	$(CROSS_COMPILE)gcc -g -O0 -Wall -static -o $@ $^

Alejandro Mery's avatar
Alejandro Mery committed
158
.gitignore: Makefile
Ian Campbell's avatar
Ian Campbell committed
159
	@for x in $(TOOLS) $(FEXC_LINKS) $(TARGET_TOOLS) '*.o' '*.swp'; do \
Alejandro Mery's avatar
Alejandro Mery committed
160
		echo "$$x"; \
Alejandro Mery's avatar
Alejandro Mery committed
161
	done > $@