xref: /freebsd/stand/i386/loader/Makefile (revision 657729a89dd578d8cfc70d6616f5c65a48a8b33a)
1# $FreeBSD$
2
3HAVE_ZFS=		${MK_LOADER_ZFS}
4
5LOADER_NET_SUPPORT?=	yes
6LOADER_NFS_SUPPORT?=	yes
7LOADER_TFTP_SUPPORT?=	yes
8LOADER_CD9660_SUPPORT?=	yes
9LOADER_EXT2FS_SUPPORT?=	yes
10LOADER_MSDOS_SUPPORT?=	yes
11LOADER_UFS_SUPPORT?=	yes
12LOADER_GZIP_SUPPORT?=	yes
13LOADER_BZIP2_SUPPORT?=	yes
14
15.include <bsd.init.mk>
16
17LOADER?=	loader_${LOADER_INTERP}
18PROG=		${LOADER}.sym
19INTERNALPROG=
20NEWVERSWHAT?=	"bootstrap loader" x86
21VERSION_FILE=	${.CURDIR}/../loader/version
22#
23# There's 640k - 40k maximum space, less however much memory the BIOS uses.  A
24# non-random survey suggests that 20k-25k is a good value for 'most' machines.
25# We also need to subtract maximum stack usage (20-25k).
26#
27# So 640k - 40k - 25k - 25k = 550k = 563,200 bytes, but use 550,000 below for
28# some extra buffer for more complex setups and/or wider BIOS lomem variation.
29#
30# Some systems use more stack or have BIOS reserve more RAM (or both), and will
31# need to set this lower in /etc/src.conf if the above buffer is too small.
32#
33# sudo dd if=/dev/mem bs=1 iseek=0x413 count=2 | hd -d
34#
35# will tell you how many kiB of lomem are available.
36#
37LOADERSIZE?=	550000		# Largest known safe size for loader.bin
38
39.PATH:		${BOOTSRC}/i386/loader
40
41# architecture-specific loader code
42SRCS=		main.c conf.c vers.c chain.c gfx_fb.c 8x16.c
43
44CFLAGS.gfx_fb.c += -I${.CURDIR}/../libi386
45CFLAGS.gfx_fb.c += -I$(SRCTOP)/sys/teken
46CFLAGS.gfx_fb.c += -I${SRCTOP}/sys/cddl/contrib/opensolaris/common/lz4
47CFLAGS.gfx_fb.c += -I${SRCTOP}/contrib/pnglite
48CFLAGS.gfx_fb.c += -DHAVE_MEMCPY -I${SRCTOP}/sys/contrib/zlib
49
50# Include bcache code.
51HAVE_BCACHE=	yes
52
53# Enable PnP and ISA-PnP code.
54HAVE_PNP=	yes
55HAVE_ISABUS=	yes
56
57.if ${MK_LOADER_ZFS} == "yes"
58CFLAGS.main.c+=	-I${SYSDIR}/contrib/openzfs/include
59CFLAGS.main.c+=	-I${SYSDIR}/contrib/openzfs/include/os/freebsd/zfs
60.endif
61
62.if exists(${.CURDIR}/help.i386)
63HELP_FILES=	${.CURDIR}/help.i386
64.endif
65
66# Always add MI sources
67.include	"${BOOTSRC}/loader.mk"
68
69CLEANFILES+=	${LOADER} ${LOADER}.bin 8x16.c
70
71ORG=		0x0
72
73CFLAGS+=	-Wall
74LDFLAGS+=	-static ${LDFLAGS_ORG} -Wl,--gc-sections
75.if ${LINKER_TYPE} == "lld" && ${LINKER_VERSION} >= 130000
76# lld 13 and higher default to garbage collecting start/stop symbols,
77# completely ruining our linker sets. For now, work around it by
78# disabling this un-feature.
79LDFLAGS+=	-Wl,-z,nostart-stop-gc
80.endif
81
82# i386 standalone support library
83LIBI386=	${BOOTOBJ}/i386/libi386/libi386.a
84CFLAGS+=	-I${BOOTSRC}/i386
85
86# Debug me!
87#CFLAGS+=	-g
88#LDFLAGS+=	-g
89
908x16.c: ${SRCTOP}/contrib/terminus/ter-u16b.bdf
91	vtfontcvt -f compressed-source -o ${.TARGET} ${.ALLSRC}
92
93
94${LOADER}: ${LOADER}.bin ${BTXLDR} ${BTXKERN}
95	btxld -v -f aout -e ${LOADER_ADDRESS} -o ${.TARGET} -l ${BTXLDR} \
96		-b ${BTXKERN} ${LOADER}.bin
97
98${LOADER}.bin: ${LOADER}.sym
99	${STRIPBIN} -R .comment -R .note -o ${.TARGET} ${.ALLSRC}
100	@set -- `ls -l ${.TARGET}` ; x=$$((${LOADERSIZE}-$$5)); \
101	    echo "$$x bytes available"; test $$x -ge 0
102
103.if ${MK_LOADER_ZFS} == "yes" && ${LOADER_INTERP} == ${LOADER_DEFAULT_INTERP}
104LINKS+=		${BINDIR}/${LOADER} ${BINDIR}/zfsloader
105.endif
106.if ${LOADER_INTERP} == ${LOADER_DEFAULT_INTERP}
107LINKS+=		${BINDIR}/${LOADER} ${BINDIR}/loader
108.endif
109FILES+=	${LOADER}
110FILESMODE_${LOADER}= ${BINMODE} -b
111
112# Note: crt0.o needs to be first for pxeboot(8) to work. It assumes that the
113# startup code is located at the start of the loader and will jump
114# there. Although btx is more flexible than this, the emulated boot2 environment
115# that pxeldr provides has none of that flexibility assumes an entry point of
116# 0. In addition, pxeldr and cdboot assume that it is loading an a.out file.
117#
118# We must add it to the LDFLAGS instead of the OBJS because the former won't try
119# to clean it. When it is in OBJS, this cleaning can lead to races where
120# btxcrt.o is rebuilt, but boot2 isn't, leading to errors at installation time.
121# LDFLAGS does not have this baggage and will be included first in the list of
122# files.
123LDFLAGS+=	${BTXCRT}
124
125DPADD=	${LDR_INTERP32} ${LIBI386} ${LIBSA32}
126LDADD=	${LDR_INTERP32} ${LIBI386} ${LIBSA32}
127
128.if ${MACHINE_CPUARCH} == "amd64"
129CFLAGS+=	-DLOADER_PREFER_AMD64
130.endif
131
132.include <bsd.prog.mk>
133