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 2015 Toomas Soome <tsoome@me.com>
14# Copyright 2016 RackTop Systems.
15#
16
17include $(SRC)/Makefile.master
18include $(SRC)/boot/Makefile.version
19include $(SRC)/boot/sys/boot/Makefile.inc
20
21CPPFLAGS +=	-I../../../../include -I../../..
22CPPFLAGS +=	-I$(SRC)/uts/intel/sys/acpi
23CPPFLAGS +=	-I$(ZLIB)
24LOADER=		loader
25NEWVERSWHAT=	"ZFS enabled bootstrap loader" x86
26
27# Set by loader Makefile
28CPPFLAGS +=	-I$(ZFSSRC)
29CPPFLAGS +=	-I../libi386
30DPLIBI386=	../libi386/libi386.a
31LIBI386=	-L../libi386 -li386
32
33ROOT_BOOT=	$(ROOT)/boot
34ROOT_BOOT_DEFAULTS=	$(ROOT)/boot/defaults
35ROOT_BOOT_FORTH=	$(ROOT)/boot/forth
36ROOT_BOOT_CONF=		$(ROOT)/boot/conf.d
37ROOTBOOTFILES=$(FILES:%=$(ROOT_BOOT)/%)
38ROOTBOOTFORTH=$(FORTH:%=$(ROOT_BOOT_FORTH)/%)
39ROOTBOOTDEFAULTS=$(DEFFILES:%=$(ROOT_BOOT_DEFAULTS)/%)
40FILEMODE=0444
41
42all: $(LOADER) loader.help
43
44install: all $(ROOTBOOTLOADER)
45
46PROG=		$(LOADER).sym
47
48# architecture-specific loader code
49SRCS=		main.c conf.c vers.c chain.c
50
51CPPFLAGS +=	-DLOADER_GZIP_SUPPORT
52
53# Enable BootForth
54CPPFLAGS +=	-DBOOT_FORTH -I$(SRC)/common/ficl -I../../libficl
55DPLIBFICL=	../../libficl/$(MACH)/libficl.a
56LIBFICL=	-L../../libficl/$(MACH) -lficl
57
58# Always add MI sources
59SRCS +=	boot.c commands.c console.c devopen.c interp.c
60SRCS +=	interp_backslash.c interp_parse.c ls.c misc.c
61SRCS +=	module.c linenoise.c multiboot2.c nvstore.c
62SRCS +=	zfs_cmd.c
63SRCS +=	font.c $(FONT).c tem.c
64
65module.o := CPPFLAGS += -I$(CRYPTOSRC)
66tem.o := CPPFLAGS += $(DEFAULT_CONSOLE_COLOR)
67
68SRCS +=	load_elf32.c load_elf32_obj.c reloc_elf32.c
69SRCS +=	load_elf64.c load_elf64_obj.c reloc_elf64.c
70
71SRCS +=	dev_net.c
72
73SRCS +=	disk.c part.c vdisk.c
74CPPFLAGS += -DLOADER_DISK_SUPPORT
75CPPFLAGS += -DLOADER_GPT_SUPPORT
76CPPFLAGS += -DLOADER_MBR_SUPPORT
77
78SRCS +=  bcache.c
79
80SRCS +=	isapnp.c
81SRCS +=	pnp.c
82
83# Forth interpreter
84SRCS +=	interp_forth.c
85
86CPPFLAGS +=	-I../../common
87CPPFLAGS +=	-I.
88
89CLEANFILES=	vers.c $(LOADER) $(LOADER).sym $(LOADER).bin loader.help
90CLEANFILES +=	$(FONT).c
91
92LDSCRIPT=	ldscript.i386
93LDFLAGS=	-static -T $(LDSCRIPT) -N --gc-sections
94
95# i386 standalone support library
96CPPFLAGS +=	-I.. -I../../../../lib/libstand
97DPLIBSTAND=	../../libstand/$(MACH)/libstand.a
98LIBSTAND=	-L../../libstand/$(MACH) -lstand
99
100# BTX components
101CPPFLAGS +=	-I../btx/lib
102
103# Debug me!
104#CFLAGS+=	-g
105#LDFLAGS+=	-g
106
107include ../Makefile.inc
108
109conf.o := CPPFLAGS += -I../../../cddl/boot/zfs
110multiboot2.o := CPPFLAGS += -I../../../cddl/boot/zfs
111main.o := CPPFLAGS += -I../../../cddl/boot/zfs -I$(SRC)/uts/common/fs/zfs
112zfs_cmd.o := CPPFLAGS += -I../../../cddl/boot/zfs
113
114# For multiboot2.h, must be last, to avoid conflicts
115CPPFLAGS +=	-I$(SRC)/uts/common
116
117vers.c:	../../common/newvers.sh $(SRC)/boot/Makefile.version
118	$(SH) ../../common/newvers.sh $(LOADER_VERSION) $(NEWVERSWHAT)
119
120$(LOADER): $(LOADER).bin $(BTXLDR) $(BTXKERN)
121	$(BTXLD) -f aout -e $(LOADER_ADDRESS) -o $@ -l $(BTXLDR) \
122		-b $(BTXKERN) $(LOADER).bin
123
124$(LOADER).bin: $(LOADER).sym
125	$(CP) $^ $@
126	$(GSTRIP) -R .comment -R .note $@
127
128loader.help: ../../common/help.common help.i386
129	$(CAT) $^ | $(AWK) -f ../../common/merge_help.awk > $@
130
131FILES=	$(LOADER) loader.help
132
133include	../../forth/Makefile.inc
134FORTH +=	pcibios.4th
135
136FILES +=	loader.rc
137FORTH +=	menu.rc
138
139# XXX crt0.o needs to be first for pxeboot(8) to work
140
141DPADD=	$(DPLIBFICL) $(DPLIBI386) $(DPLIBSTAND)
142LDADD=	$(LIBFICL) $(LIBI386) $(LIBSTAND)
143
144CLEANFILES +=	machine x86
145
146machine:
147	$(RM) machine
148	$(SYMLINK) ../../../i386/include machine
149
150x86:
151	$(RM) x86
152	$(SYMLINK) ../../../x86/include x86
153
154OBJS=		$(SRCS:%.c=%.o)
155
156$(OBJS): machine x86
157
158$(PROG): $(OBJS) $(DPADD)
159	$(LD) $(LDFLAGS) -o $@ $(BTXCRT) $(OBJS) $(LDADD)
160
161clean: clobber
162clobber:
163	$(RM) $(CLEANFILES) $(OBJS)
164
165install: all $(ROOT_BOOT_DEFAULTS) $(ROOT_BOOT_FORTH) \
166	$(ROOTBOOTFILES) $(ROOTBOOTDEFAULTS) $(ROOT_BOOT_CONF) $(ROOTBOOTFORTH)
167
168%.o:	../../common/%.c
169	$(COMPILE.c) -o $@ $<
170
171%.o:	../../common/linenoise/%.c
172	$(COMPILE.c) -o $@ $<
173
174%.o: $(SRC)/common/font/%.c
175	$(COMPILE.c) $<
176
177$(FONT).c: $(FONT_DIR)/$(FONT_SRC)
178	$(VTFONTCVT) -f compressed-source -o $@ $(FONT_DIR)/$(FONT_SRC)
179
180$(ROOT_BOOT)/%: ../../forth/% $(ROOT_BOOT)
181	$(INS.file)
182
183$(ROOT_BOOT_DEFAULTS)/%: ../../forth/% $(ROOT_BOOT_DEFAULTS)
184	$(INS.file)
185
186$(ROOT_BOOT_FORTH)/%: ../../forth/% $(ROOT_BOOT_FORTH)
187	$(INS.file)
188
189$(ROOT_BOOT_DEFAULTS) $(ROOT_BOOT_CONF) $(ROOT_BOOT_FORTH):
190	$(INS.dir)
191