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