freebsd-skq/stand/i386/loader/Makefile
Warner Losh e713d3a013 boot: fix OBJS to not include BTX's crt0.o
According to comments in the Makefile, to make pxeboot work we need to
have crt0.o first. This is needed because the simplified loader in
pxeboot assumes that the startup code is at offset 0 in this binary. In
normal booting, the start address can be obtained from headers of the
binary, but since pxeboot encodes this as a pure binary, it has no way
of knowing where that is and assumes 0. Added comments to that effect
in the Makefile.

We've done this by adding it to OBJS before all the other .o's are
added. However, there's a problem. This also adds it to the CLEANFILES
variable, which causes it to be removed from multiple places. The
dependencies may also cause it to be re-built at a time that's after
boot2 is built. This causes installs to fail because at install time
boot2 is considered to be out of date and the programs to rebuild it are
no longer in the path.

Cope with this problem by just adding it to LDFLAGS instead.

Glanced at by:		kevans ("I thought that went in ages ago")
Sponsored by:		Netflix
Differential Revision:	https://reviews.freebsd.org/D28876
2021-05-06 13:08:30 -06:00

113 lines
3.1 KiB
Makefile

# $FreeBSD$
HAVE_ZFS= ${MK_LOADER_ZFS}
LOADER_NET_SUPPORT?= yes
LOADER_NFS_SUPPORT?= yes
LOADER_TFTP_SUPPORT?= yes
LOADER_CD9660_SUPPORT?= yes
LOADER_EXT2FS_SUPPORT?= yes
LOADER_MSDOS_SUPPORT?= yes
LOADER_UFS_SUPPORT?= yes
LOADER_GZIP_SUPPORT?= yes
LOADER_BZIP2_SUPPORT?= yes
.include <bsd.init.mk>
LOADER?= loader_${LOADER_INTERP}
PROG= ${LOADER}.sym
INTERNALPROG=
NEWVERSWHAT?= "bootstrap loader" x86
VERSION_FILE= ${.CURDIR}/../loader/version
.PATH: ${BOOTSRC}/i386/loader
# architecture-specific loader code
SRCS= main.c conf.c vers.c chain.c gfx_fb.c 8x16.c
CFLAGS.gfx_fb.c += -I${.CURDIR}/../libi386
CFLAGS.gfx_fb.c += -I$(SRCTOP)/sys/teken
CFLAGS.gfx_fb.c += -I${SRCTOP}/sys/cddl/contrib/opensolaris/common/lz4
CFLAGS.gfx_fb.c += -I${SRCTOP}/contrib/pnglite
CFLAGS.gfx_fb.c += -DHAVE_MEMCPY -I${SRCTOP}/sys/contrib/zlib
# Include bcache code.
HAVE_BCACHE= yes
# Enable PnP and ISA-PnP code.
HAVE_PNP= yes
HAVE_ISABUS= yes
.if ${MK_LOADER_FIREWIRE} == "yes"
CFLAGS+= -DLOADER_FIREWIRE_SUPPORT
LIBFIREWIRE= ${BOOTOBJ}/i386/libfirewire/libfirewire.a
.endif
.if ${MK_LOADER_ZFS} == "yes"
CFLAGS.main.c+= -I${SYSDIR}/contrib/openzfs/include
CFLAGS.main.c+= -I${SYSDIR}/contrib/openzfs/include/os/freebsd/zfs
.endif
.if exists(${.CURDIR}/help.i386)
HELP_FILES= ${.CURDIR}/help.i386
.endif
# Always add MI sources
.include "${BOOTSRC}/loader.mk"
CLEANFILES+= ${LOADER} ${LOADER}.bin 8x16.c
ORG= 0x0
CFLAGS+= -Wall
LDFLAGS+= -static ${LDFLAGS_ORG} -Wl,--gc-sections
# i386 standalone support library
LIBI386= ${BOOTOBJ}/i386/libi386/libi386.a
CFLAGS+= -I${BOOTSRC}/i386
# Debug me!
#CFLAGS+= -g
#LDFLAGS+= -g
8x16.c: ${SRCTOP}/contrib/terminus/ter-u16b.bdf
vtfontcvt -f compressed-source -o ${.TARGET} ${.ALLSRC}
${LOADER}: ${LOADER}.bin ${BTXLDR} ${BTXKERN}
btxld -v -f aout -e ${LOADER_ADDRESS} -o ${.TARGET} -l ${BTXLDR} \
-b ${BTXKERN} ${LOADER}.bin
${LOADER}.bin: ${LOADER}.sym
${STRIPBIN} -R .comment -R .note -o ${.TARGET} ${.ALLSRC}
.if ${MK_LOADER_ZFS} == "yes" && ${LOADER_INTERP} == ${LOADER_DEFAULT_INTERP}
LINKS+= ${BINDIR}/${LOADER} ${BINDIR}/zfsloader
.endif
.if ${LOADER_INTERP} == ${LOADER_DEFAULT_INTERP}
LINKS+= ${BINDIR}/${LOADER} ${BINDIR}/loader
.endif
FILES+= ${LOADER}
FILESMODE_${LOADER}= ${BINMODE} -b
# Note: crt0.o needs to be first for pxeboot(8) to work. It assumes that the
# startup code is located at the start of the loader and will jump
# there. Although btx is more flexible than this, the emulated boot2 environment
# that pxeloader provides has none of that flexibility because it lacks access
# to the a.out/elf headers and assumes an entry point of 0.
#
# We must add it to the LDFLAGS instead of the OBJS becauce the former won't try
# to clean it. When it is in OBJS, this cleaning can lead to races where
# btxcrt.o is rebuilt, but boot2 isn't, leading to errors at installation time.
# LDFLAGS does not have this baggage and will be included first in the list of
# files.
LDFLAGS+= ${BTXCRT}
DPADD= ${LDR_INTERP32} ${LIBFIREWIRE} ${LIBI386} ${LIBSA32}
LDADD= ${LDR_INTERP32} ${LIBFIREWIRE} ${LIBI386} ${LIBSA32}
.if ${MACHINE_CPUARCH} == "amd64"
CFLAGS+= -DLOADER_PREFER_AMD64
.endif
.include <bsd.prog.mk>