forked from pcercuei/UBIBoot
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Makefile
140 lines (110 loc) · 3.24 KB
/
Makefile
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
ifeq ($(CONFIG),)
CONFIGS:=$(foreach CFG,$(wildcard config-*.mk),$(CFG:config-%.mk=%))
$(error Please specify CONFIG, possible values: $(CONFIGS))
endif
include config-$(CONFIG).mk
ifdef V
CMD:=
SUM:=@\#
else
CMD:=@
SUM:=@echo
endif
CROSS_COMPILE ?= mipsel-linux-
CC = $(CROSS_COMPILE)gcc
LD = $(CROSS_COMPILE)ld
OBJCOPY = $(CROSS_COMPILE)objcopy
OBJDUMP = $(CROSS_COMPILE)objdump
NM = $(CROSS_COMPILE)nm
CFLAGS := -Wall -Os -fno-pic -mno-abicalls -mno-check-zero-division -ffreestanding -flto
CFLAGS += $(CFLAGS_all)
CPPFLAGS := -DBOARD_$(BOARD) -DJZ_VERSION=$(JZ_VERSION)
LDFLAGS := -nostdlib -EL
ifneq ($(findstring $(JZ_VERSION),JZ4740 JZ4750),)
LDFLAGS += -T ldscripts/target-jz4740.ld
endif
ifneq ($(findstring $(JZ_VERSION),JZ4760 JZ4770),)
LDFLAGS += -T ldscripts/target-jz4760.ld
ifeq ($(STAGE1_ONLY),)
LDFLAGS += -Wl,--defsym=LOAD_OFFSET=0x200
endif
endif
OUTDIR := output/$(CONFIG)
OBJS := utils.o mmc.o fat.o head.o uimage.o
ifdef GC_FUNCTIONS
CFLAGS += -ffunction-sections
LDFLAGS += -Wl,--gc-sections
endif
ifdef USE_SERIAL
CPPFLAGS += -DUSE_SERIAL
OBJS += serial.o
endif
ifdef BKLIGHT_ON
CPPFLAGS += -DBKLIGHT_ON
endif
ifdef USE_NAND
CPPFLAGS += -DUSE_NAND
OBJS += nand.o
ifeq ($(JZ_VERSION),4740)
OBJS += bch-jz4740.o
else
OBJS += bch-jz4750.o
endif
endif
ifdef USE_UBI
CPPFLAGS += -DUSE_UBI
OBJS += ubi.o
endif
ifdef STAGE1_ONLY
CPPFLAGS += -DSTAGE1_ONLY
endif
.PHONY: all clean map
BINFILES := $(foreach VARIANT,$(VARIANTS),$(OUTDIR)/ubiboot$(if $(STAGE1_ONLY),-stage1)-$(VARIANT).bin)
ELFFILES := $(foreach VARIANT,$(VARIANTS),$(OUTDIR)/ubiboot-$(VARIANT).elf)
OBJFILES := $(addprefix $(OUTDIR)/,$(OBJS))
all: $(BINFILES)
$(ELFFILES): $(OUTDIR)/ubiboot-%.elf: \
$(OUTDIR)/main_%.o $(OUTDIR)/board-$(BOARD)_%.o $(OBJFILES)
@mkdir -p $(@D)
$(SUM) " LD $@"
$(CMD)$(CC) $(CFLAGS) $(LDFLAGS) $^ -o $@
$(BINFILES): $(OUTDIR)/ubiboot$(if $(STAGE1_ONLY),-stage1)-%.bin: $(OUTDIR)/ubiboot-%.elf
@mkdir -p $(@D)
$(SUM) " BIN $@"
$(CMD)$(OBJCOPY) -O binary $< $@
$(OUTDIR)/%.o: src/%.c
@mkdir -p $(@D)
$(SUM) " CC $@"
$(CMD)$(CC) $(CFLAGS) $(CPPFLAGS) -c $< -o $@
$(OUTDIR)/%.o: src/%.S
@mkdir -p $(@D)
$(SUM) " CC $@"
$(CMD)$(CC) $(CFLAGS) $(CPPFLAGS) -c $< -o $@
CFLAGS_FOR_VARIANT=$(CFLAGS) -DVARIANT="\"$(1)\"" $(CFLAGS_$(1))
$(OUTDIR)/board-$(BOARD)_%.o: src/board-$(BOARD).c
@mkdir -p $(@D)
$(SUM) " CC $@"
$(CMD)$(CC) $(CPPFLAGS) \
$(call CFLAGS_FOR_VARIANT,$(@:$(OUTDIR)/board-$(BOARD)_%.o=%)) \
-c $< -o $@
$(OUTDIR)/main_%.o: src/main.c
@mkdir -p $(@D)
$(SUM) " CC $@"
$(CMD)$(CC) $(CPPFLAGS) \
$(call CFLAGS_FOR_VARIANT,$(@:$(OUTDIR)/main_%.o=%)) \
-c $< -o $@
MAPFILES := $(foreach VARIANT,$(VARIANTS),$(OUTDIR)/System-$(VARIANT).map)
DISFILES := $(foreach VARIANT,$(VARIANTS),$(OUTDIR)/System-$(VARIANT).disasm)
SECFILES := $(foreach VARIANT,$(VARIANTS),$(OUTDIR)/System-$(VARIANT).sections)
map: $(MAPFILES) $(DISFILES) $(SECFILES)
$(MAPFILES): $(OUTDIR)/System-%.map: $(OUTDIR)/ubiboot-%.elf
@mkdir -p $(@D)
$(NM) -n $< > $@
$(DISFILES): $(OUTDIR)/System-%.disasm: $(OUTDIR)/ubiboot-%.elf
@mkdir -p $(@D)
$(OBJDUMP) -D $< > $@
$(SECFILES): $(OUTDIR)/System-%.sections: $(OUTDIR)/ubiboot-%.elf
$(OBJDUMP) -h $< > $@
clean:
$(SUM) " RM $(OUTDIR)"
$(CMD)rm -rf $(OUTDIR)