1530d68baSNigel Croxon# 2530d68baSNigel Croxon# Copyright (C) 1999-2001 Hewlett-Packard Co. 3530d68baSNigel Croxon# Contributed by David Mosberger <davidm@hpl.hp.com> 4530d68baSNigel Croxon# Contributed by Stephane Eranian <eranian@hpl.hp.com> 5530d68baSNigel Croxon# 6530d68baSNigel Croxon# All rights reserved. 7530d68baSNigel Croxon# 8530d68baSNigel Croxon# Redistribution and use in source and binary forms, with or without 9530d68baSNigel Croxon# modification, are permitted provided that the following conditions 10530d68baSNigel Croxon# are met: 11530d68baSNigel Croxon# 12530d68baSNigel Croxon# * Redistributions of source code must retain the above copyright 13530d68baSNigel Croxon# notice, this list of conditions and the following disclaimer. 14530d68baSNigel Croxon# * Redistributions in binary form must reproduce the above 15530d68baSNigel Croxon# copyright notice, this list of conditions and the following 16530d68baSNigel Croxon# disclaimer in the documentation and/or other materials 17530d68baSNigel Croxon# provided with the distribution. 18530d68baSNigel Croxon# * Neither the name of Hewlett-Packard Co. nor the names of its 19530d68baSNigel Croxon# contributors may be used to endorse or promote products derived 20530d68baSNigel Croxon# from this software without specific prior written permission. 21530d68baSNigel Croxon# 22530d68baSNigel Croxon# THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND 23530d68baSNigel Croxon# CONTRIBUTORS "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, 24530d68baSNigel Croxon# INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF 25530d68baSNigel Croxon# MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE 26530d68baSNigel Croxon# DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS 27530d68baSNigel Croxon# BE LIABLE FOR ANYDIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, 28530d68baSNigel Croxon# OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, 29530d68baSNigel Croxon# PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR 30530d68baSNigel Croxon# PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY 31530d68baSNigel Croxon# THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR 32530d68baSNigel Croxon# TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF 33530d68baSNigel Croxon# THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF 34530d68baSNigel Croxon# SUCH DAMAGE. 35530d68baSNigel Croxon# 36530d68baSNigel Croxon 37530d68baSNigel CroxonSRCDIR = . 38530d68baSNigel Croxon 39530d68baSNigel CroxonVPATH = $(SRCDIR) 40530d68baSNigel Croxon 41530d68baSNigel Croxoninclude $(SRCDIR)/../Make.defaults 42530d68baSNigel Croxon 43530d68baSNigel CroxonTOPDIR = $(SRCDIR)/.. 44530d68baSNigel Croxon 45530d68baSNigel CroxonCDIR=$(TOPDIR)/.. 46530d68baSNigel CroxonLINUX_HEADERS = /usr/src/sys/build 473f9a6569SCallum FarmerAPPSDIR = $(LIBDIR)/gnuefi/apps 48530d68baSNigel CroxonCPPFLAGS += -D__KERNEL__ -I$(LINUX_HEADERS)/include 49530d68baSNigel CroxonCRTOBJS = ../gnuefi/crt0-efi-$(ARCH).o 50530d68baSNigel Croxon 51530d68baSNigel CroxonLDSCRIPT = $(TOPDIR)/gnuefi/elf_$(ARCH)_efi.lds 52530d68baSNigel Croxonifneq (,$(findstring FreeBSD,$(OS))) 53530d68baSNigel CroxonLDSCRIPT = $(TOPDIR)/gnuefi/elf_$(ARCH)_fbsd_efi.lds 54530d68baSNigel Croxonendif 55530d68baSNigel Croxon 56530d68baSNigel CroxonLDFLAGS += -shared -Bsymbolic -L../lib -L../gnuefi $(CRTOBJS) 57530d68baSNigel Croxon 58530d68baSNigel CroxonLOADLIBES += -lefi -lgnuefi 59530d68baSNigel CroxonLOADLIBES += $(LIBGCC) 60530d68baSNigel CroxonLOADLIBES += -T $(LDSCRIPT) 61530d68baSNigel Croxon 62530d68baSNigel CroxonTARGET_BSDRIVERS = drv0.efi 63530d68baSNigel CroxonTARGET_RTDRIVERS = 64530d68baSNigel Croxon 65530d68baSNigel Croxonifneq ($(HAVE_EFI_OBJCOPY),) 66530d68baSNigel Croxon 67530d68baSNigel CroxonFORMAT := --target efi-app-$(ARCH) 68530d68baSNigel Croxon$(TARGET_BSDRIVERS): FORMAT=--target efi-bsdrv-$(ARCH) 69530d68baSNigel Croxon$(TARGET_RTDRIVERS): FORMAT=--target efi-rtdrv-$(ARCH) 70530d68baSNigel Croxon 71530d68baSNigel Croxonelse 72530d68baSNigel Croxon 73530d68baSNigel CroxonSUBSYSTEM := 0xa 74530d68baSNigel Croxon$(TARGET_BSDRIVERS): SUBSYSTEM = 0xb 75530d68baSNigel Croxon$(TARGET_RTDRIVERS): SUBSYSTEM = 0xc 76530d68baSNigel Croxon 77530d68baSNigel CroxonFORMAT := -O binary 78530d68baSNigel CroxonLDFLAGS += --defsym=EFI_SUBSYSTEM=$(SUBSYSTEM) 79530d68baSNigel Croxon 80530d68baSNigel Croxonendif 81530d68baSNigel Croxon 825c0de15dSLoGin 835c0de15dSLoGin 84823f0493SLoGinDRAGON_STUB_FILES:= dragon_stub-main.c stub.c helper.c fdt.c secureboot.c elf.c mem.c alignedmem.c random.c 8578b790faSLoGinDRAGON_STUB_FILES += lib/vsprintf.c lib/hexdump.c lib/ctype.c lib/cmdline.c lib/string.c 863e6106c4SLoGin__LIBFDT_DIR=lib/libfdt 873e6106c4SLoGinDRAGON_STUB_FILES += $(__LIBFDT_DIR)/fdt_addresses.c $(__LIBFDT_DIR)/fdt_empty_tree.c $(__LIBFDT_DIR)/fdt_overlay.c $(__LIBFDT_DIR)/fdt_ro.c \ 883e6106c4SLoGin $(__LIBFDT_DIR)/fdt_rw.c $(__LIBFDT_DIR)/fdt_strerror.c $(__LIBFDT_DIR)/fdt_sw.c $(__LIBFDT_DIR)/fdt_wip.c \ 893e6106c4SLoGin $(__LIBFDT_DIR)/fdt.c 903e6106c4SLoGin 913e6106c4SLoGinINCDIR += -I$(TOPDIR)/apps/lib/libfdt 9278b790faSLoGin 9378b790faSLoGinifeq ($(ARCH), riscv64) 9478b790faSLoGin DRAGON_STUB_FILES += riscv-stub.c 95823f0493SLoGin INCDIR += -I$(TOPDIR)/inc/dragonstub/linux/arch/riscv 9678b790faSLoGinendif 9778b790faSLoGin 985c0de15dSLoGin# 把*.c的列表转换为*.o的列表 995c0de15dSLoGinDRAGON_STUB_OBJS := $(patsubst %.c,%.o,$(DRAGON_STUB_FILES)) 100fe0ee6eaSLoGinPAYLOAD_ELF_OBJ= 101*bf26173fSLoGin# 将'/', '.', '-'替换为'_' 102*bf26173fSLoGinPAYLOAD_PATH_REPLACEMENT=_binary_$(shell echo "$(PAYLOAD_ELF)" | sed 's/\//_/g' | sed 's/\./_/g' | sed 's/\-/_/g') 1035c0de15dSLoGin 104f412fd2aSLoGin 1055c0de15dSLoGindragon_stub: $(DRAGON_STUB_OBJS) 106f412fd2aSLoGin @echo "Building dragon_stub..." 107f412fd2aSLoGin 108fe0ee6eaSLoGinifeq ($(PAYLOAD_ELF),) 109fe0ee6eaSLoGin @echo "PAYLOAD_ELF is not set, not merging..." 1105c0de15dSLoGin $(LD) $(LDFLAGS) $^ -o dragon_stub.so $(LOADLIBES) 111fe0ee6eaSLoGinelse 112fe0ee6eaSLoGin# 把DragonStub和目标ELF合并 113fe0ee6eaSLoGin @echo "Merging DragonStub and $(PAYLOAD_ELF)..." 114fe0ee6eaSLoGin $(LD) -r -b binary $(PAYLOAD_ELF) -o payload.o.stage1 --no-relax 115fe0ee6eaSLoGin $(OBJCOPY) --redefine-sym $(PAYLOAD_PATH_REPLACEMENT)_start=_binary_payload_start \ 116fe0ee6eaSLoGin --redefine-sym $(PAYLOAD_PATH_REPLACEMENT)_end=_binary_payload_end \ 117fe0ee6eaSLoGin --redefine-sym $(PAYLOAD_PATH_REPLACEMENT)_size=_binary_payload_size \ 118fe0ee6eaSLoGin payload.o.stage1 payload.o 119fe0ee6eaSLoGin $(LD) $(LDFLAGS) --no-relax $^ payload.o -o dragon_stub.so $(LOADLIBES) 120fe0ee6eaSLoGin 121fe0ee6eaSLoGinendif 122fe0ee6eaSLoGin 1235c0de15dSLoGin $(OBJCOPY) -j .text -j .sdata -j .data -j .dynamic -j .rodata -j .rel \ 1245c0de15dSLoGin -j .rela -j .rel.* -j .rela.* -j .rel* -j .rela* \ 1255c0de15dSLoGin -j .areloc -j .reloc $(FORMAT) dragon_stub.so dragon_stub.efi 1265c0de15dSLoGin 1275c0de15dSLoGin 128f412fd2aSLoGinTARGETS = $(TARGET_BSDRIVERS) $(TARGET_RTDRIVERS) dragon_stub 129530d68baSNigel Croxon 130530d68baSNigel Croxonall: $(TARGETS) 131530d68baSNigel Croxon 1324f8b339fSPeter Jonesctors_test.so : ctors_fns.o ctors_test.o 1334f8b339fSPeter Jones 134530d68baSNigel Croxonclean: 135530d68baSNigel Croxon rm -f $(TARGETS) *~ *.o *.so 136530d68baSNigel Croxon 1373f9a6569SCallum Farmerinstall: 1383f9a6569SCallum Farmer mkdir -p $(INSTALLROOT)$(APPSDIR) 1393f9a6569SCallum Farmer $(INSTALL) -m 644 $(TARGETS) $(INSTALLROOT)$(APPSDIR) 1403f9a6569SCallum Farmer 141530d68baSNigel Croxon.PHONY: install 142530d68baSNigel Croxon 143530d68baSNigel Croxoninclude $(SRCDIR)/../Make.rules 144