freebsd-skq/stand/efi/boot1/Makefile

129 lines
3.5 KiB
Makefile
Raw Normal View History

# $FreeBSD$
MAN=
.include <bsd.init.mk>
MK_SSP= no
MK_FORTH= no
PROG= boot1.sym
INTERNALPROG=
WARNS?= 6
# We implement a slightly non-standard %S in that it always takes a
# CHAR16 that's common in UEFI-land instead of a wchar_t. This only
# seems to matter on arm64 where wchar_t defaults to an int instead
# of a short. There's no good cast to use here so just ignore the
# warnings for now.
CWARNFLAGS.boot1.c+= -Wno-format
# Disable warnings that are currently incompatible with the zfs boot code
CWARNFLAGS.zfs_module.c += -Wno-array-bounds
CWARNFLAGS.zfs_module.c += -Wno-cast-align
CWARNFLAGS.zfs_module.c += -Wno-cast-qual
CWARNFLAGS.zfs_module.c += -Wno-missing-prototypes
CWARNFLAGS.zfs_module.c += -Wno-sign-compare
CWARNFLAGS.zfs_module.c += -Wno-unused-parameter
CWARNFLAGS.zfs_module.c += -Wno-unused-function
# architecture-specific loader code
SRCS= boot1.c self_reloc.c start.S ufs_module.c
.if ${MK_ZFS} != "no"
SRCS+= zfs_module.c
CFLAGS.zfs_module.c+= -I${ZFSSRC}
CFLAGS.zfs_module.c+= -I${SYSDIR}/cddl/boot/zfs
CFLAGS.zfs_module.c+= -I${SYSDIR}/crypto/skein
CFLAGS.zfs_module.c+= -DEFI_ZFS_BOOT
LIBZFSBOOT= ${BOOTOBJ}/zfs/libzfsboot.a
.endif
.if ${COMPILER_TYPE} == "gcc" && ${COMPILER_VERSION} > 40201
CWARNFLAGS.self_reloc.c+= -Wno-error=maybe-uninitialized
.endif
CFLAGS+= -I${EFIINC}
CFLAGS+= -I${EFIINCMD}
CFLAGS+= -I${SYSDIR}/contrib/dev/acpica/include
CFLAGS+= -DEFI_UFS_BOOT
.ifdef(EFI_DEBUG)
CFLAGS+= -DEFI_DEBUG
.endif
# Always add MI sources and REGULAR efi loader bits
.PATH: ${EFISRC}/loader/arch/${MACHINE}
.PATH: ${EFISRC}/loader
.PATH: ${LDRSRC}
CFLAGS+= -I${LDRSRC}
FILES= boot1.efi boot1.efifat
FILESMODE_boot1.efi= ${BINMODE}
LDSCRIPT= ${EFISRC}/loader/arch/${MACHINE}/ldscript.${MACHINE}
LDFLAGS+= -Wl,-T${LDSCRIPT},-Bsymbolic,-znotext -shared
.if ${MACHINE_CPUARCH} == "aarch64"
CFLAGS+= -mgeneral-regs-only
.endif
.if ${MACHINE_CPUARCH} == "amd64" || ${MACHINE_CPUARCH} == "i386"
CFLAGS+= -fPIC
LDFLAGS+= -Wl,-znocombreloc
.endif
LIBEFI= ${BOOTOBJ}/efi/libefi/libefi.a
#
# Add libstand for the runtime functions used by the compiler - for example
# __aeabi_* (arm) or __divdi3 (i386).
# as well as required string and memory functions for all platforms.
#
DPADD+= ${LIBEFI} ${LIBZFSBOOT} ${LIBSA}
LDADD+= ${LIBEFI} ${LIBZFSBOOT} ${LIBSA}
DPADD+= ${LDSCRIPT}
NM?= nm
OBJCOPY?= objcopy
.if ${MACHINE_CPUARCH} == "amd64"
EFI_TARGET= efi-app-x86_64
.elif ${MACHINE_CPUARCH} == "i386"
EFI_TARGET= efi-app-ia32
.else
EFI_TARGET= binary
.endif
# Arbitrarily set the PE/COFF header timestamps to 1 Jan 2016 00:00:00
# for build reproducibility.
SOURCE_DATE_EPOCH?=1451606400
boot1.efi: ${PROG}
if ${NM} ${.ALLSRC} | grep ' U '; then \
echo "Undefined symbols in ${.ALLSRC}"; \
exit 1; \
fi
SOURCE_DATE_EPOCH=${SOURCE_DATE_EPOCH} \
${OBJCOPY} -j .peheader -j .text -j .sdata -j .data \
-j .dynamic -j .dynsym -j .rel.dyn \
-j .rela.dyn -j .reloc -j .eh_frame \
--output-target=${EFI_TARGET} ${.ALLSRC} ${.TARGET}
# The following inserts our objects into a template FAT file system
# created by generate-fat.sh
.include "${.CURDIR}/Makefile.fat"
boot1.efifat: boot1.efi
@set -- `ls -l ${.ALLSRC}`; \
x=$$(($$5-${BOOT1_MAXSIZE})); \
if [ $$x -ge 0 ]; then \
echo "boot1 $$x bytes too large; regenerate FAT templates?" >&2 ;\
exit 1; \
fi
echo ${.OBJDIR}
Increase EFI boot file size frok 128k to 384k generate_fat.sh does the following: - create an 800kb zero-filled file - create an md device backed by this file - format the device fat12 - mount the filesystem - create the EFI ESP directory structure - create the EFI boot file (BOOTx64 for amd64, BOOTaa64 for aarch64, etc) - Adds a marker to the beginning of the file, and pad it to 384kb - 384kb was chosen as it is less than half of 800kb, thus allowing users to keep a backup of their older boot file in the small partition - Unmount the filesystem - Scan the image and find the offset where the marker was inserted - The process requires root, to make image generation easier, images for each architecture are pregenerated, compressed with xz, and checked into svn. The Makefile that generates boot1.efifat does the following: - Ensure the compiled boot1.efi file is no larger than the generated image - Decompress the template created by generate-fat.sh - dd the contents of boot1.efi into boot1.efifat starting at the offset where the marker is found. This allows any file less than the maximum size to be written into the fat filesystem without having to mount it, so no root privileges are required. Later work by imp and myself makes bsdinstall create a 200mb fat16 instead of using this process, but it is retained to make image generation easier. Submitted by: Eric McCorkle (original version) Reviewed by: emaste, tsoome, Eric McCorkle MFC after: 1 month Differential Revision: https://reviews.freebsd.org/D9680
2017-09-13 17:00:02 +00:00
xz -d -c ${.CURDIR}/fat-${MACHINE}.tmpl.xz > ${.TARGET}
${DD} if=${.ALLSRC} of=${.TARGET} seek=${BOOT1_OFFSET} conv=notrunc
CLEANFILES+= boot1.efi boot1.efifat
.include <bsd.prog.mk>