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 2015 Toomas Soome <tsoome@me.com>
  14 # Copyright 2016 RackTop Systems.
  15 #
  16 
  17 include $(SRC)/Makefile.master
  18 
  19 CFLAGS= -O2
  20 CPPFLAGS= -DSTAND -nostdinc -I../../../../include -I../../..
  21 LOADER=         zfsloader
  22 NEWVERSWHAT=    "ZFS enabled bootstrap loader" x86
  23 MAN=
  24 
  25 # Set by zfsloader Makefile
  26 CPPFLAGS +=     -DLOADER_ZFS_SUPPORT -I../../zfs
  27 CPPFLAGS +=     -I../libi386
  28 LIBZFSBOOT=     ../../zfs/i386/libzfsboot.a
  29 LIBI386=        ../libi386/libi386.a
  30 
  31 # loader.help build needs better awk
  32 AWK=            /usr/xpg4/bin/awk
  33 LD=             $(GNU_ROOT)/bin/gld
  34 CC=             $(GCC_ROOT)/bin/gcc
  35 OBJCOPY=        $(GNU_ROOT)/bin/gobjcopy
  36 GSTRIP=         $(GNU_ROOT)/bin/gstrip
  37 ROOT_BOOT=      $(ROOT)/boot
  38 ROOT_BOOT_DEFAULTS=     $(ROOT)/boot/defaults
  39 ROOT_BOOT_FORTH=        $(ROOT)/boot/forth
  40 ROOT_BOOT_CONF=         $(ROOT)/boot/conf.d
  41 ROOTBOOTFILES=$(FILES:%=$(ROOT_BOOT)/%)
  42 ROOTBOOTFORTH=$(FORTH:%=$(ROOT_BOOT_FORTH)/%)
  43 ROOTBOOTDEFAULTS=$(DEFFILES:%=$(ROOT_BOOT_DEFAULTS)/%)
  44 FILEMODE=0444
  45 
  46 all: ${LOADER} loader.help
  47 
  48 install: all $(ROOTBOOTLOADER)
  49 
  50 PROG=           ${LOADER}.sym
  51 INTERNALPROG=
  52 
  53 # architecture-specific loader code
  54 SRCS=           main.c conf.c vers.c chain.c
  55 
  56 CPPFLAGS +=     -DLOADER_TFTP_SUPPORT -DLOADER_GZIP_SUPPORT
  57 
  58 # Enable BootForth
  59 CPPFLAGS +=     -DBOOT_FORTH -I$(SRC)/common/ficl -I../../ficl
  60 LIBFICL=        ../../ficl/i386/libficl.a
  61 
  62 # Always add MI sources
  63 SRCS += boot.c commands.c console.c devopen.c interp.c
  64 SRCS += interp_backslash.c interp_parse.c ls.c misc.c
  65 SRCS += module.c panic.c linenoise.c
  66 
  67 SRCS += load_elf32.c load_elf32_obj.c reloc_elf32.c
  68 SRCS += load_elf64.c load_elf64_obj.c reloc_elf64.c
  69 
  70 SRCS += dev_net.c
  71 
  72 SRCS += disk.c part.c
  73 CPPFLAGS += -DLOADER_DISK_SUPPORT
  74 SRCS += crc32.c
  75 CPPFLAGS += -DLOADER_GPT_SUPPORT
  76 CPPFLAGS += -DLOADER_MBR_SUPPORT
  77 
  78 SRCS +=  bcache.c
  79 
  80 SRCS += isapnp.c
  81 SRCS += pnp.c
  82 
  83 # Forth interpreter
  84 SRCS += interp_forth.c
  85 
  86 MAN +=  loader.8
  87 MAN +=  zfsloader.8
  88 CPPFLAGS +=     -I../../common
  89 CPPFLAGS +=     -I.
  90 
  91 CLEANFILES=     vers.c ${LOADER} ${LOADER}.sym ${LOADER}.bin loader.help
  92 
  93 CFLAGS +=       -Wall
  94 LDFLAGS=        -static -Ttext 0x0
  95 
  96 # i386 standalone support library
  97 CPPFLAGS +=     -I.. -I../../../../lib/libstand
  98 LIBSTAND=       ../../libstand/i386/libstand.a
  99 
 100 # BTX components
 101 CPPFLAGS +=     -I../btx/lib
 102 
 103 # Debug me!
 104 #CFLAGS+=       -g
 105 #LDFLAGS+=      -g
 106 
 107 include ../Makefile.inc
 108 
 109 vers.c: ../../common/newvers.sh version
 110         $(SH) ../../common/newvers.sh version ${NEWVERSWHAT}
 111 
 112 ${LOADER}: ${LOADER}.bin ${BTXLDR} ${BTXKERN}
 113         $(BTXLD) -v -f aout -e ${LOADER_ADDRESS} -o $@ -l ${BTXLDR} \
 114                 -b ${BTXKERN} ${LOADER}.bin
 115 
 116 ${LOADER}.bin: ${LOADER}.sym
 117         $(CP) $^ $@
 118         $(GSTRIP) -R .comment -R .note $@
 119 
 120 loader.help: ../../common/help.common help.i386
 121         $(CAT) $^ | $(AWK) -f ../../common/merge_help.awk > $@
 122 
 123 FILES=  ${LOADER} loader.help
 124 
 125 include ../../forth/Makefile.inc
 126 FORTH +=        pcibios.4th
 127 
 128 FILES +=        loader.rc
 129 FORTH +=        menu.rc
 130 
 131 # XXX crt0.o needs to be first for pxeboot(8) to work
 132 
 133 DPADD=  ${LIBFICL} ${LIBZFSBOOT} ${LIBI386} ${LIBSTAND}
 134 LDADD=  ${LIBFICL} ${LIBZFSBOOT} ${LIBI386} ${LIBSTAND}
 135 
 136 CLEANFILES +=   machine x86
 137 CFLAGS +=       -DLOADER_PREFER_AMD64
 138 
 139 machine:
 140         $(RM) machine
 141         $(SYMLINK) ../../../i386/include machine
 142 
 143 x86:
 144         $(RM) x86
 145         $(SYMLINK) ../../../x86/include x86
 146 
 147 OBJS=           $(SRCS:%.c=%.o)
 148 
 149 ${OBJS}: machine x86
 150 
 151 ${PROG}: ${OBJS} $(LDADD)
 152         $(LD) $(LDFLAGS) -o $@ $(BTXCRT) $(OBJS) $(LDADD)
 153 
 154 clean: clobber
 155 clobber:
 156         $(RM) $(CLEANFILES) $(OBJS)
 157 
 158 install: all $(ROOT_BOOT_DEFAULTS) $(ROOT_BOOT_FORTH) \
 159         $(ROOTBOOTFILES) $(ROOTBOOTDEFAULTS) $(ROOT_BOOT_CONF) $(ROOTBOOTFORTH)
 160 
 161 %.o:    ../../common/%.c
 162         $(COMPILE.c) -o $@ $<
 163 
 164 %.o:    ../../common/linenoise/%.c
 165         $(COMPILE.c) -o $@ $<
 166 
 167 $(ROOT_BOOT)/%: ../../forth/%
 168         $(INS.file)
 169 
 170 $(ROOT_BOOT_DEFAULTS)/%: ../../forth/%
 171         $(INS.file)
 172 
 173 $(ROOT_BOOT_FORTH)/%: ../../forth/%
 174         $(INS.file)
 175 
 176 $(ROOT_BOOT_DEFAULTS) $(ROOT_BOOT_CONF) $(ROOT_BOOT_FORTH):
 177         $(INS.dir)