-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathMakefile
145 lines (112 loc) · 3.93 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
141
142
143
144
ARCH := aarch64
CROSS_COMPILE := aarch64-linux-gnu-
AS := $(CROSS_COMPILE)as
CC := $(CROSS_COMPILE)gcc
LD := $(CROSS_COMPILE)ld
OBJCOPY := $(CROSS_COMPILE)objcopy
DTC := dtc
OUT_DIR := $(CURDIR)/out
GNUEFI_DIR = $(CURDIR)/external/gnu-efi
GNUEFI_OUT = $(GNUEFI_DIR)/$(ARCH)
LIBFDT_INC = $(CURDIR)/external/dtc/libfdt/
SYSREG_INC = $(CURDIR)/external/arm64-sysreg-lib/include
SUBSYSTEM_APP = 10 # EFI Application
SUBSYSTEM_RT = 12 # EFI Runtime driver
CFLAGS += \
-I$(GNUEFI_DIR)/inc/ -I$(GNUEFI_DIR)/inc/$(ARCH) -I$(GNUEFI_DIR)/inc/protocol \
-I$(SYSREG_INC) -I$(LIBFDT_INC) -Isrc/include \
-fpic -fshort-wchar -fno-stack-protector -ffreestanding \
-DCONFIG_$(ARCH) -D__MAKEWITH_GNUEFI -DGNU_EFI_USE_MS_ABI \
-mstrict-align
LDFLAGS += \
-Wl,--no-wchar-size-warning \
-e efi_main \
-s -Wl,-Bsymbolic -nostdlib -shared \
-L $(GNUEFI_OUT)/lib/ -L $(GNUEFI_OUT)/gnuefi \
LIBS = \
-lefi -lgnuefi \
-T $(GNUEFI_DIR)/gnuefi/elf_$(ARCH)_efi.lds
LIBEFI_A := $(GNUEFI_OUT)/lib/libefi.a
LIBGNUEFI_A := $(GNUEFI_OUT)/gnuefi/libgnuefi.a
CRT0_O := $(GNUEFI_OUT)/gnuefi/crt0-efi-$(ARCH).o
LIBFDT_OBJS := \
$(OUT_DIR)/external/dtc/libfdt/fdt.o \
$(OUT_DIR)/external/dtc/libfdt/fdt_ro.o \
$(OUT_DIR)/external/dtc/libfdt/fdt_wip.o \
$(OUT_DIR)/external/dtc/libfdt/fdt_sw.o \
$(OUT_DIR)/external/dtc/libfdt/fdt_rw.o \
$(OUT_DIR)/external/dtc/libfdt/fdt_empty_tree.o \
$(OUT_DIR)/external/dtc/libfdt/fdt_addresses.o \
$(OUT_DIR)/external/dtc/libfdt/fdt_check.o \
$(OUT_DIR)/external/dtc/libfdt/fdt_overlay.o \
$(OUT_DIR)/external/dtc/libfdt/fdt_strerror.o \
DTBHACK_LDFLAGS := \
-Wl,--defsym=EFI_SUBSYSTEM=$(SUBSYSTEM_APP)
DTBHACK_OBJS := \
$(OUT_DIR)/src/dtbhack_main.o \
$(OUT_DIR)/src/util.o \
$(OUT_DIR)/src/arch.o \
$(OUT_DIR)/src/libc.o \
$(LIBFDT_OBJS)
SLTEST_LDFLAGS := \
-Wl,--defsym=EFI_SUBSYSTEM=$(SUBSYSTEM_APP)
SLTEST_OBJS := \
$(OUT_DIR)/src/test_main.o \
$(OUT_DIR)/src/util.o \
$(OUT_DIR)/src/arch.o \
$(OUT_DIR)/src/sl.o \
$(OUT_DIR)/src/trans.o \
SLBOUNCE_LDFLAGS := \
-Wl,--defsym=EFI_SUBSYSTEM=$(SUBSYSTEM_RT)
SLBOUNCE_OBJS := \
$(OUT_DIR)/src/bounce_main.o \
$(OUT_DIR)/src/util.o \
$(OUT_DIR)/src/arch.o \
$(OUT_DIR)/src/sl.o \
$(OUT_DIR)/src/trans.o \
DTBS := \
$(OUT_DIR)/dtbo/sc7180-symbols.dtbo \
$(OUT_DIR)/dtbo/sc7180-el2.dtbo \
$(OUT_DIR)/dtbo/sc8280xp-symbols.dtbo \
$(OUT_DIR)/dtbo/sc8280xp-el2.dtbo \
$(OUT_DIR)/dtbo/x1e-el2.dtbo \
all: $(OUT_DIR)/sltest.efi $(OUT_DIR)/slbounce.efi $(OUT_DIR)/dtbhack.efi
.INTERMEDIATE: $(GNUEFI_DIR)/inc/elf.h
$(GNUEFI_DIR)/inc/elf.h:
ln -sf /usr/include/elf.h $(GNUEFI_DIR)/inc/elf.h
$(LIBEFI_A): $(GNUEFI_DIR)/inc/elf.h
@echo [ DEP ] $@
@$(MAKE) -C$(GNUEFI_DIR) CROSS_COMPILE=$(CROSS_COMPILE) ARCH=$(ARCH) lib
$(LIBGNUEFI_A): $(GNUEFI_DIR)/inc/elf.h
@echo [ DEP ] $@
@$(MAKE) -C$(GNUEFI_DIR) CROSS_COMPILE=$(CROSS_COMPILE) ARCH=$(ARCH) gnuefi
$(OUT_DIR)/sltest.so: $(SLTEST_OBJS) $(LIBEFI_A) $(LIBGNUEFI_A)
@echo [ LD ] $$(basename $@)
@$(CC) $(SLTEST_LDFLAGS) $(LDFLAGS) $(CRT0_O) $(SLTEST_OBJS) -o $@ $(LIBS)
$(OUT_DIR)/slbounce.so: $(SLBOUNCE_OBJS) $(LIBEFI_A) $(LIBGNUEFI_A)
@echo [ LD ] $$(basename $@)
@$(CC) $(SLBOUNCE_LDFLAGS) $(LDFLAGS) $(CRT0_O) $(SLBOUNCE_OBJS) -o $@ $(LIBS)
$(OUT_DIR)/dtbhack.so: $(DTBHACK_OBJS) $(LIBEFI_A) $(LIBGNUEFI_A)
@echo [ LD ] $$(basename $@)
@$(CC) $(DTBHACK_LDFLAGS) $(LDFLAGS) $(CRT0_O) $(DTBHACK_OBJS) -o $@ $(LIBS)
$(OUT_DIR)/%.efi: $(OUT_DIR)/%.so
@echo [ CPY ] $$(basename $@)
@$(OBJCOPY) -j .text -j .sdata -j .data -j .dynamic -j .dynsym -j .rel* \
-j .rela* -j .reloc -j .eh_frame -O binary $< $@
$(OUT_DIR)/%.o: %.c
@echo [ CC ] $$(basename $@)
@mkdir -p $(dir $@)
@$(CC) $(CFLAGS) -c $< -o $@
$(OUT_DIR)/%.o: %.s
@echo [ ASM ] $$(basename $@)
@mkdir -p $(dir $@)
@$(AS) -c $< -o $@
dtbs: $(DTBS)
$(OUT_DIR)/%.dtbo: %.dtso
@echo [ DTC ] $$(basename $@)
@mkdir -p $(dir $@)
@$(DTC) -O dtb -I dts --align 16 -o $@ $<
.PHONY: clean
clean:
rm -rf $(OUT_DIR)
$(MAKE) -C$(GNUEFI_DIR) ARCH=$(ARCH) clean