1 #
   2 # This file and its contents are supplied under the terms of the
   3 # Common Development and Distribution License ("CDDL"), version 1.0.
   4 # You may only use this file in accordance with the terms of version
   5 # 1.0 of the CDDL.
   6 #
   7 # A full copy of the text of the CDDL should have accompanied this
   8 # source.  A copy of the CDDL is also available via the Internet at
   9 # http://www.illumos.org/license/CDDL.
  10 #
  11 
  12 #
  13 # Copyright 2016 Toomas Soome <tsoome@me.com>
  14 #
  15 
  16 include $(SRC)/Makefile.master
  17 
  18 CC=             $(GCC_ROOT)/bin/gcc
  19 LD=             $(GNU_ROOT)/bin/gld
  20 OBJCOPY=        $(GNU_ROOT)/bin/gobjcopy
  21 OBJDUMP=        $(GNU_ROOT)/bin/gobjdump
  22 
  23 PROG=           loader.sym
  24 MACHINE=        $(MACH64)
  25 
  26 # architecture-specific loader code
  27 SRCS=   autoload.c bootinfo.c conf.c copy.c devicename.c main.c self_reloc.c \
  28         smbios.c biosacpi.c vers.c
  29 OBJS= autoload.o bootinfo.o conf.o copy.o devicename.o main.o self_reloc.o \
  30         smbios.o biosacpi.o vers.o
  31 
  32 ASFLAGS=-m64 -fPIC
  33 CFLAGS= -O2
  34 CPPFLAGS= -nostdinc -I../../../../include -I../../..
  35 CPPFLAGS += -I../../../../lib/libstand
  36 
  37 include ../Makefile.inc
  38 
  39 include arch/${MACHINE}/Makefile.inc
  40 
  41 CPPFLAGS +=     -I.
  42 CPPFLAGS +=     -I./arch/${MACHINE}
  43 CPPFLAGS +=     -I./../include
  44 CPPFLAGS +=     -I./../include/${MACHINE}
  45 CPPFLAGS +=     -I./../../../contrib/dev/acpica/include
  46 CPPFLAGS +=     -I./../../..
  47 CPPFLAGS +=     -I./../../i386/libi386
  48 CPPFLAGS +=     -I./../../zfs
  49 CPPFLAGS +=     -I./../../../cddl/boot/zfs
  50 CPPFLAGS +=     -DEFI_ZFS_BOOT
  51 CPPFLAGS +=     -DNO_PCI -DEFI -DTERM_EMU
  52 
  53 LIBSTAND=       ../../libstand/${MACHINE}/libstand.a
  54 
  55 BOOT_FORTH=     yes
  56 CPPFLAGS +=     -DBOOT_FORTH -DSTAND
  57 CPPFLAGS +=     -I$(SRC)/common/ficl
  58 CPPFLAGS +=     -I../../ficl
  59 LIBFICL=        ../../ficl/${MACHINE}/libficl.a
  60 
  61 CPPFLAGS +=     -I../../zfs
  62 LIBZFSBOOT=     ../../zfs/${MACHINE}/libzfsboot.a
  63 
  64 #LOADER_FDT_SUPPORT?=   no
  65 #.if ${MK_FDT} != "no" && ${LOADER_FDT_SUPPORT} != "no"
  66 #CFLAGS+=       -I${.CURDIR}/../../fdt
  67 #CFLAGS+=       -I${.OBJDIR}/../../fdt
  68 #CFLAGS+=       -DLOADER_FDT_SUPPORT
  69 #LIBEFI_FDT=    ${.OBJDIR}/../../efi/fdt/libefi_fdt.a
  70 #LIBFDT=                ${.OBJDIR}/../../fdt/libfdt.a
  71 #.endif
  72 
  73 # Always add MI sources
  74 include ./Makefile.common
  75 CPPFLAGS +=     -I../../common
  76 
  77 FILES=  loader.efi
  78 FILEMODE=       0555
  79 ROOT_BOOT=      $(ROOT)/boot
  80 ROOTBOOTFILES=$(FILES:%=$(ROOT_BOOT)/%)
  81 
  82 LDSCRIPT=       ./arch/${MACHINE}/ldscript.${MACHINE}
  83 LDFLAGS =       -nostdlib --eh-frame-hdr -znocombreloc
  84 LDFLAGS +=      -shared --hash-style=both --enable-new-dtags
  85 LDFLAGS +=      -T${LDSCRIPT} -Bsymbolic
  86 
  87 CLEANFILES=     vers.c loader.efi
  88 
  89 NEWVERSWHAT=    "EFI loader" ${MACHINE}
  90 
  91 all: machine x86 loader.efi
  92 install: all $(ROOTBOOTFILES)
  93 
  94 vers.c: ../../common/newvers.sh ../../efi/loader/version
  95         $(SH) ../../common/newvers.sh version ${NEWVERSWHAT}
  96 
  97 EFI_TARGET=     pei-x86-64
  98 
  99 loader.efi: loader.sym
 100         if [ `${OBJDUMP} -t loader.sym | fgrep '*UND*' | wc -l` != 0 ]; then \
 101                 ${OBJDUMP} -t loader.sym | fgrep '*UND*'; \
 102                 exit 1; \
 103         fi
 104         ${OBJCOPY} --readonly-text -j .peheader -j .text -j .sdata -j .data \
 105                 -j .dynamic -j .dynsym -j .rel.dyn \
 106                 -j .rela.dyn -j .reloc -j .eh_frame -j set_Xcommand_set \
 107                 --output-target=${EFI_TARGET} --subsystem efi-app loader.sym $@
 108 
 109 LIBEFI=         ../libefi/libefi.a
 110 
 111 DPADD=          ${LIBFICL} ${LIBZFSBOOT} ${LIBEFI} ${LIBFDT} ${LIBEFI_FDT} \
 112                 ${LIBSTAND} ${LDSCRIPT}
 113 LDADD=          ${LIBFICL} ${LIBZFSBOOT} ${LIBEFI} ${LIBFDT} ${LIBEFI_FDT} \
 114                 ${LIBSTAND}
 115 
 116 
 117 loader.sym:     $(OBJS) $(DPADD)
 118         $(LD) $(LDFLAGS) -o $@ $(OBJS) $(LDADD)
 119 
 120 beforedepend ${OBJS}: machine
 121 
 122 CLEANFILES +=   machine x86
 123 
 124 machine:
 125         $(RM) machine
 126         $(SYMLINK) ../../../${MACHINE}/include machine
 127 
 128 x86:
 129         $(RM) x86
 130         $(SYMLINK) ../../../x86/include x86
 131 
 132 clean clobber:
 133         $(RM) $(CLEANFILES) $(OBJS) loader.sym loader.efi
 134 
 135 %.o:    %.c
 136         $(COMPILE.c) $<
 137 
 138 %.o:    ./arch/${MACHINE}/%.c
 139         $(COMPILE.c) $<
 140 
 141 %.o:    ./arch/${MACHINE}/%.S
 142         $(COMPILE.S) $<
 143 
 144 %.o:    ../../common/%.c
 145         $(COMPILE.c) $<
 146 
 147 %.o:    ../../common/linenoise/%.c
 148         $(COMPILE.c) $<
 149 
 150 %.o: ../../i386/libi386/%.c
 151         $(COMPILE.c) $<
 152 
 153 $(ROOT_BOOT)/%: %
 154         $(INS.file)