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#
15
16include $(SRC)/boot/Makefile.version
17include $(SRC)/boot/Makefile.inc
18
19PROG=		loader.sym
20
21# architecture-specific loader code
22SRCS=	\
23	acpi.c \
24	autoload.c \
25	bootinfo.c \
26	conf.c \
27	copy.c \
28	efi_main.c \
29	font.c \
30	$(FONT).c \
31	framebuffer.c \
32	main.c \
33	memmap.c \
34	mb_header.S \
35	multiboot2.c \
36	nvstore.c \
37	self_reloc.c \
38	tem.c \
39	vers.c
40
41OBJS=	\
42	acpi.o \
43	autoload.o \
44	bootinfo.o \
45	conf.o \
46	copy.o \
47	efi_main.o \
48	font.o \
49	$(FONT).o \
50	framebuffer.o \
51	main.o \
52	memmap.o \
53	mb_header.o \
54	multiboot2.o \
55	nvstore.o \
56	self_reloc.o \
57	tem.o \
58	vers.o
59
60module.o := CPPFLAGS += -I$(CRYPTOSRC)
61tem.o := CPPFLAGS += $(DEFAULT_CONSOLE_COLOR)
62main.o := CPPFLAGS += -I$(SRC)/uts/common/fs/zfs
63
64CPPFLAGS += -I../../../include -I../../../sys
65CPPFLAGS += -I../../../libsa
66
67include ../../Makefile.inc
68
69include ../arch/$(MACHINE)/Makefile.inc
70
71CPPFLAGS +=	-I. -I..
72CPPFLAGS +=	-I../../include
73CPPFLAGS +=	-I../../include/$(MACHINE)
74CPPFLAGS +=	-I$(ZFSSRC)
75CPPFLAGS +=	-I../../../sys/cddl/boot/zfs
76CPPFLAGS +=	-I$(SRC)/uts/intel/sys/acpi
77CPPFLAGS +=	-I$(PNGLITE)
78CPPFLAGS +=	-DNO_PCI -DEFI
79
80DPLIBSA=	../../../libsa/$(MACHINE)/libsa_pics.a
81LIBSA=	-L../../../libsa/$(MACHINE) -lsa_pics
82
83BOOT_FORTH=	yes
84CPPFLAGS +=	-DBOOT_FORTH
85CPPFLAGS +=	-I$(SRC)/common/ficl
86CPPFLAGS +=	-I../../../libficl
87DPLIBFICL=	../../../libficl/$(MACHINE)/libficl_pics.a
88LIBFICL=	-L../../../libficl/$(MACHINE) -lficl_pics
89
90# Always add MI sources
91#
92SRCS +=	boot.c commands.c console.c devopen.c interp.c
93SRCS +=	interp_backslash.c interp_parse.c ls.c misc.c
94SRCS +=	module.c linenoise.c zfs_cmd.c
95
96OBJS += boot.o commands.o console.o devopen.o interp.o \
97	interp_backslash.o interp_parse.o ls.o misc.o \
98	module.o linenoise.o zfs_cmd.o
99
100SRCS +=	load_elf32.c load_elf32_obj.c reloc_elf32.c
101SRCS +=	load_elf64.c load_elf64_obj.c reloc_elf64.c
102
103OBJS += load_elf32.o load_elf32_obj.o reloc_elf32.o \
104	load_elf64.o load_elf64_obj.o reloc_elf64.o
105
106SRCS +=	disk.c part.c dev_net.c vdisk.c
107OBJS += disk.o part.o dev_net.o vdisk.o
108CPPFLAGS += -DLOADER_DISK_SUPPORT
109CPPFLAGS += -DLOADER_GPT_SUPPORT
110CPPFLAGS += -DLOADER_MBR_SUPPORT
111
112part.o := CPPFLAGS += -I$(ZLIB)
113
114SRCS +=  bcache.c
115OBJS +=  bcache.o
116
117# Forth interpreter
118SRCS +=	interp_forth.c
119OBJS +=	interp_forth.o
120CPPFLAGS +=	-I../../../common
121
122# For multiboot2.h, must be last, to avoid conflicts
123CPPFLAGS +=	-I$(SRC)/uts/common
124
125FILES=		$(EFIPROG)
126FILEMODE=	0555
127ROOT_BOOT=	$(ROOT)/boot
128ROOTBOOTFILES=$(FILES:%=$(ROOT_BOOT)/%)
129
130LDSCRIPT=	../arch/$(MACHINE)/ldscript.$(MACHINE)
131LDFLAGS =	-nostdlib --eh-frame-hdr
132LDFLAGS +=	-shared --hash-style=both --enable-new-dtags
133LDFLAGS +=	-T$(LDSCRIPT) -Bsymbolic
134
135CLEANFILES=	$(EFIPROG) loader.sym loader.bin
136CLEANFILES +=	$(FONT).c vers.c
137
138NEWVERSWHAT=	"EFI loader" $(MACHINE)
139
140install: all $(ROOTBOOTFILES)
141
142vers.c:	../../../common/newvers.sh $(SRC)/boot/Makefile.version
143	$(SH) ../../../common/newvers.sh $(LOADER_VERSION) $(NEWVERSWHAT)
144
145$(EFIPROG): loader.bin
146	$(BTXLD) -V $(BOOT_VERSION) -o $@ loader.bin
147
148loader.bin: loader.sym
149	if [ `$(OBJDUMP) -t loader.sym | fgrep '*UND*' | wc -l` != 0 ]; then \
150		$(OBJDUMP) -t loader.sym | fgrep '*UND*'; \
151		exit 1; \
152	fi
153	$(OBJCOPY) --readonly-text -j .peheader -j .text -j .sdata -j .data \
154		-j .dynamic -j .dynsym -j .rel.dyn \
155		-j .rela.dyn -j .reloc -j .eh_frame -j set_Xcommand_set \
156		-j set_Xficl_compile_set \
157		--output-target=$(EFI_TARGET) --subsystem efi-app loader.sym $@
158
159DPLIBEFI=	../../libefi/$(MACHINE)/libefi.a
160LIBEFI=		-L../../libefi/$(MACHINE) -lefi
161
162DPADD=		$(DPLIBFICL) $(DPLIBEFI) $(DPLIBSA) $(LDSCRIPT)
163LDADD=		$(LIBFICL) $(LIBEFI) $(LIBSA)
164
165loader.sym:	$(OBJS) $(DPADD)
166	$(GLD) $(LDFLAGS) -o $@ $(OBJS) $(LDADD)
167
168machine:
169	$(RM) machine
170	$(SYMLINK) ../../../sys/$(MACHINE)/include machine
171
172x86:
173	$(RM) x86
174	$(SYMLINK) ../../../sys/x86/include x86
175
176clean clobber:
177	$(RM) $(CLEANFILES) $(OBJS) machine x86
178
179%.o:	../%.c
180	$(COMPILE.c) $<
181
182%.o:	../arch/$(MACHINE)/%.c
183	$(COMPILE.c) $<
184
185#
186# using -W to silence gas here, as for 32bit build, it will generate warning
187# for start.S because hand crafted .reloc section does not have group name
188#
189%.o:	../arch/$(MACHINE)/%.S
190	$(COMPILE.S) -Wa,-W $<
191
192%.o:	../../../common/%.S
193	$(COMPILE.S) $<
194
195%.o:	../../../common/%.c
196	$(COMPILE.c) $<
197
198%.o:	../../../common/linenoise/%.c
199	$(COMPILE.c) $<
200
201%.o: $(SRC)/common/font/%.c
202	$(COMPILE.c) $<
203
204$(FONT).c: $(FONT_DIR)/$(FONT_SRC)
205	$(VTFONTCVT) -f compressed-source -o $@ $(FONT_DIR)/$(FONT_SRC)
206
207$(ROOT_BOOT)/%: %
208	$(INS.file)
209