1 #
2 # This file and its contents are supplied under the terms of the
3 # Common Development and Distribution License ("CDDL"), version 1.0.
4 # You may only use this file in accordance with the terms of version
5 # 1.0 of the CDDL.
6 #
7 # A full copy of the text of the CDDL should have accompanied this
8 # source. A copy of the CDDL is also available via the Internet at
9 # http://www.illumos.org/license/CDDL.
10 #
11
12 #
13 # Copyright 2016 Toomas Soome <tsoome@me.com>
14 # Copyright 2016 RackTop Systems.
15 #
16
17 include $(SRC)/Makefile.master
18 include $(SRC)/boot/Makefile.version
19
20 CC= $(GCC_ROOT)/bin/gcc
21 LD= $(GNU_ROOT)/bin/gld
22 OBJCOPY= $(GNU_ROOT)/bin/gobjcopy
23 OBJDUMP= $(GNU_ROOT)/bin/gobjdump
24
25 PROG= loader.sym
26 MACHINE= $(MACH64)
27
28 # architecture-specific loader code
29 SRCS= autoload.c bootinfo.c conf.c copy.c efi_main.c main.c \
30 self_reloc.c smbios.c acpi.c vers.c memmap.c multiboot2.c
31 OBJS= autoload.o bootinfo.o conf.o copy.o efi_main.o main.o \
32 self_reloc.o smbios.o acpi.o vers.o memmap.o multiboot2.o
33
34 ASFLAGS=-m64 -fPIC
35 CFLAGS= -O2
36 CPPFLAGS= -nostdinc -I../../../../include -I../../..
37 CPPFLAGS += -I../../../../lib/libstand
38
39 include ../Makefile.inc
40
41 include arch/${MACHINE}/Makefile.inc
42
43 CPPFLAGS += -I.
44 CPPFLAGS += -I./arch/${MACHINE}
45 CPPFLAGS += -I./../include
46 CPPFLAGS += -I./../include/${MACHINE}
47 CPPFLAGS += -I$(SRC)/uts/intel/sys/acpi
48 CPPFLAGS += -I./../../..
49 CPPFLAGS += -I./../../i386/libi386
50 CPPFLAGS += -I./../../zfs
51 CPPFLAGS += -I./../../../cddl/boot/zfs
52 CPPFLAGS += -DNO_PCI -DEFI -DTERM_EMU
53
54 # Export serial numbers, UUID, and asset tag from loader.
55 CPPFLAGS += -DSMBIOS_SERIAL_NUMBERS
56 # Use little-endian UUID format as defined in SMBIOS 2.6.
57 CPPFLAGS += -DSMBIOS_LITTLE_ENDIAN_UUID
58 # Use network-endian UUID format for backward compatibility.
59 #CPPFLAGS += -DSMBIOS_NETWORK_ENDIAN_UUID
60
61 LIBSTAND= ../../libstand/${MACHINE}/libstand.a
62
63 BOOT_FORTH= yes
64 CPPFLAGS += -DBOOT_FORTH -D_STANDALONE
65 CPPFLAGS += -I$(SRC)/common/ficl
66 CPPFLAGS += -I../../ficl
67 LIBFICL= ../../ficl/${MACHINE}/libficl.a
68
69 CPPFLAGS += -I../../zfs
70 LIBZFSBOOT= ../../zfs/${MACHINE}/libzfsboot.a
71
72 #LOADER_FDT_SUPPORT?= no
73 #.if ${MK_FDT} != "no" && ${LOADER_FDT_SUPPORT} != "no"
74 #CFLAGS+= -I${.CURDIR}/../../fdt
75 #CFLAGS+= -I${.OBJDIR}/../../fdt
76 #CFLAGS+= -DLOADER_FDT_SUPPORT
77 #LIBEFI_FDT= ${.OBJDIR}/../../efi/fdt/libefi_fdt.a
78 #LIBFDT= ${.OBJDIR}/../../fdt/libfdt.a
79 #.endif
80
81 # Always add MI sources
82 include ./Makefile.common
83 CPPFLAGS += -I../../common
84
85 # For multiboot2.h, must be last, to avoid conflicts
86 CPPFLAGS += -I$(SRC)/uts/common
87
88 FILES= loader.efi
89 FILEMODE= 0555
90 ROOT_BOOT= $(ROOT)/boot
91 ROOTBOOTFILES=$(FILES:%=$(ROOT_BOOT)/%)
92
93 LDSCRIPT= ./arch/${MACHINE}/ldscript.${MACHINE}
94 LDFLAGS = -nostdlib --eh-frame-hdr -znocombreloc
95 LDFLAGS += -shared --hash-style=both --enable-new-dtags
96 LDFLAGS += -T${LDSCRIPT} -Bsymbolic
97
98 CLEANFILES= vers.c loader.efi
99
100 NEWVERSWHAT= "EFI loader" ${MACHINE}
101
102 all: loader.efi
103
104 install: all $(ROOTBOOTFILES)
105
106 vers.c: ../../common/newvers.sh $(SRC)/boot/Makefile.version
107 $(SH) ../../common/newvers.sh ${LOADER_VERSION} ${NEWVERSWHAT}
108
109 EFI_TARGET= pei-x86-64
110
111 loader.efi: loader.sym
112 if [ `${OBJDUMP} -t loader.sym | fgrep '*UND*' | wc -l` != 0 ]; then \
113 ${OBJDUMP} -t loader.sym | fgrep '*UND*'; \
114 exit 1; \
115 fi
116 ${OBJCOPY} --readonly-text -j .peheader -j .text -j .sdata -j .data \
117 -j .dynamic -j .dynsym -j .rel.dyn \
118 -j .rela.dyn -j .reloc -j .eh_frame -j set_Xcommand_set \
119 -j set_Xficl_compile_set \
120 --output-target=${EFI_TARGET} --subsystem efi-app loader.sym $@
121
122 LIBEFI= ../libefi/libefi.a
123
124 DPADD= ${LIBFICL} ${LIBZFSBOOT} ${LIBEFI} ${LIBFDT} ${LIBEFI_FDT} \
125 ${LIBSTAND} ${LDSCRIPT}
126 LDADD= ${LIBFICL} ${LIBZFSBOOT} ${LIBEFI} ${LIBFDT} ${LIBEFI_FDT} \
127 ${LIBSTAND}
128
129
130 loader.sym: $(OBJS) $(DPADD)
131 $(LD) $(LDFLAGS) -o $@ $(OBJS) $(LDADD)
132
133 CLEANFILES += machine x86
134
135 machine:
136 $(RM) machine
137 $(SYMLINK) ../../../${MACHINE}/include machine
138
139 x86:
140 $(RM) x86
141 $(SYMLINK) ../../../x86/include x86
142
143 $(OBJS): machine x86
144
145 clean clobber:
146 $(RM) $(CLEANFILES) $(OBJS) loader.sym loader.efi
147
148 %.o: %.c
149 $(COMPILE.c) $<
150
151 %.o: ./arch/${MACHINE}/%.c
152 $(COMPILE.c) $<
153
154 %.o: ./arch/${MACHINE}/%.S
155 $(COMPILE.S) $<
156
157 %.o: ../../common/%.c
158 $(COMPILE.c) $<
159
160 %.o: ../../common/linenoise/%.c
161 $(COMPILE.c) $<
162
163 %.o: ../../i386/libi386/%.c
164 $(COMPILE.c) $<
165
166 $(ROOT_BOOT)/%: %
167 $(INS.file)