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 ${LOADER}: machine x86
  49 
  50 install: all $(ROOTBOOTLOADER)
  51 
  52 PROG=           ${LOADER}.sym
  53 INTERNALPROG=
  54 
  55 # architecture-specific loader code
  56 SRCS=           main.c conf.c vers.c chain.c
  57 
  58 CPPFLAGS +=     -DLOADER_TFTP_SUPPORT -DLOADER_GZIP_SUPPORT
  59 
  60 # Enable BootForth
  61 CPPFLAGS +=     -DBOOT_FORTH -I$(SRC)/common/ficl -I../../ficl
  62 LIBFICL=        ../../ficl/i386/libficl.a
  63 
  64 # Always add MI sources
  65 SRCS += boot.c commands.c console.c devopen.c interp.c
  66 SRCS += interp_backslash.c interp_parse.c ls.c misc.c
  67 SRCS += module.c panic.c linenoise.c
  68 
  69 SRCS += load_elf32.c load_elf32_obj.c reloc_elf32.c
  70 SRCS += load_elf64.c load_elf64_obj.c reloc_elf64.c
  71 
  72 SRCS += dev_net.c
  73 
  74 SRCS += disk.c part.c
  75 CPPFLAGS += -DLOADER_DISK_SUPPORT
  76 SRCS += crc32.c
  77 CPPFLAGS += -DLOADER_GPT_SUPPORT
  78 CPPFLAGS += -DLOADER_MBR_SUPPORT
  79 
  80 SRCS +=  bcache.c
  81 
  82 SRCS += isapnp.c
  83 SRCS += pnp.c
  84 
  85 # Forth interpreter
  86 SRCS += interp_forth.c
  87 
  88 MAN +=  loader.8
  89 MAN +=  zfsloader.8
  90 CPPFLAGS +=     -I../../common
  91 CPPFLAGS +=     -I.
  92 
  93 CLEANFILES=     vers.c ${LOADER} ${LOADER}.sym ${LOADER}.bin loader.help
  94 
  95 CFLAGS +=       -Wall
  96 LDFLAGS=        -static -Ttext 0x0
  97 
  98 # i386 standalone support library
  99 CPPFLAGS +=     -I.. -I../../../../lib/libstand
 100 LIBSTAND=       ../../libstand/i386/libstand.a
 101 
 102 # BTX components
 103 CPPFLAGS +=     -I../btx/lib
 104 
 105 # Debug me!
 106 #CFLAGS+=       -g
 107 #LDFLAGS+=      -g
 108 
 109 include ../Makefile.inc
 110 
 111 vers.c: ../../common/newvers.sh version
 112         $(SH) ../../common/newvers.sh version ${NEWVERSWHAT}
 113 
 114 ${LOADER}: ${LOADER}.bin ${BTXLDR} ${BTXKERN}
 115         $(BTXLD) -v -f aout -e ${LOADER_ADDRESS} -o $@ -l ${BTXLDR} \
 116                 -b ${BTXKERN} ${LOADER}.bin
 117 
 118 ${LOADER}.bin: ${LOADER}.sym
 119         $(CP) $^ $@
 120         $(GSTRIP) -R .comment -R .note $@
 121 
 122 loader.help: ../../common/help.common help.i386
 123         $(CAT) $^ | $(AWK) -f ../../common/merge_help.awk > $@
 124 
 125 FILES=  ${LOADER} loader.help
 126 
 127 include ../../forth/Makefile.inc
 128 FORTH +=        pcibios.4th
 129 
 130 FILES +=        loader.rc
 131 FORTH +=        menu.rc
 132 
 133 # XXX crt0.o needs to be first for pxeboot(8) to work
 134 
 135 DPADD=  ${LIBFICL} ${LIBZFSBOOT} ${LIBI386} ${LIBSTAND}
 136 LDADD=  ${LIBFICL} ${LIBZFSBOOT} ${LIBI386} ${LIBSTAND}
 137 
 138 CLEANFILES +=   machine x86
 139 CFLAGS +=       -DLOADER_PREFER_AMD64
 140 
 141 machine:
 142         $(RM) machine
 143         $(SYMLINK) ../../../i386/include machine
 144 
 145 x86:
 146         $(RM) x86
 147         $(SYMLINK) ../../../x86/include x86
 148 
 149 OBJS=           $(SRCS:%.c=%.o)
 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)