Makefile revision 211677
1# $FreeBSD: head/sys/boot/i386/zfsboot/Makefile 211677 2010-08-23 01:42:09Z imp $
2
3.PATH:		${.CURDIR}/../boot2
4
5FILES=		zfsboot
6
7NM?=		nm
8
9# A value of 0x80 enables LBA support.
10BOOT_BOOT1_FLAGS?=	0x80
11
12BOOT_COMCONSOLE_PORT?= 0x3f8
13BOOT_COMCONSOLE_SPEED?= 9600
14B2SIOFMT?=	0x3
15
16REL1=	0x700
17ORG1=	0x7c00
18ORG2=	0x2000
19
20CFLAGS=	-Os -g \
21	-fno-guess-branch-probability \
22	-fomit-frame-pointer \
23	-fno-unit-at-a-time \
24	-mno-align-long-strings \
25	-mrtd \
26	-mno-mmx -mno-3dnow -mno-sse -mno-sse2 -mno-sse3 \
27	-DBOOT2 \
28	-DFLAGS=${BOOT_BOOT1_FLAGS} \
29	-DSIOPRT=${BOOT_COMCONSOLE_PORT} \
30	-DSIOFMT=${B2SIOFMT} \
31	-DSIOSPD=${BOOT_COMCONSOLE_SPEED} \
32	-I${.CURDIR}/../../zfs \
33	-I${.CURDIR}/../../../cddl/boot/zfs \
34	-I${.CURDIR}/../btx/lib -I. \
35	-I${.CURDIR}/../boot2 \
36	-Wall -Waggregate-return -Wbad-function-cast -Wcast-align \
37	-Wmissing-declarations -Wmissing-prototypes -Wnested-externs \
38	-Wpointer-arith -Wshadow -Wstrict-prototypes -Wwrite-strings \
39	-Winline --param max-inline-insns-single=100
40
41LDFLAGS=-static -N --gc-sections
42
43# Pick up ../Makefile.inc early.
44.include <bsd.init.mk>
45
46CLEANFILES=	zfsboot
47
48zfsboot: zfsboot1 zfsboot2
49	cat zfsboot1 zfsboot2 > zfsboot
50
51CLEANFILES+=	zfsboot1 zfsldr.out zfsldr.o
52
53zfsboot1: zfsldr.out
54	objcopy -S -O binary zfsldr.out ${.TARGET}
55
56zfsldr.out: zfsldr.o
57	${LD} ${LDFLAGS} -e start -Ttext ${ORG1} -o ${.TARGET} zfsldr.o
58
59CLEANFILES+=	zfsboot2 zfsboot.ld zfsboot.ldr zfsboot.bin zfsboot.out \
60		zfsboot.o zfsboot.s zfsboot.s.tmp zfsboot.h sio.o
61
62# We currently allow 32768 bytes for zfsboot - in practice it could be
63# any size up to 3.5Mb but keeping it fixed size simplifies zfsldr.
64# 
65BOOT2SIZE=	32768
66
67zfsboot2: zfsboot.ld
68	@set -- `ls -l zfsboot.ld`; x=$$((${BOOT2SIZE}-$$5)); \
69	    echo "$$x bytes available"; test $$x -ge 0
70	dd if=zfsboot.ld of=${.TARGET} obs=${BOOT2SIZE} conv=osync
71
72zfsboot.ld: zfsboot.ldr zfsboot.bin ${BTXKERN}
73	btxld -v -E ${ORG2} -f bin -b ${BTXKERN} -l zfsboot.ldr \
74	    -o ${.TARGET} -P 1 zfsboot.bin
75
76zfsboot.ldr:
77	cp /dev/null ${.TARGET}
78
79zfsboot.bin: zfsboot.out
80	objcopy -S -O binary zfsboot.out ${.TARGET}
81
82zfsboot.out: ${BTXCRT} zfsboot.o sio.o
83	${LD} ${LDFLAGS} -Ttext ${ORG2} -o ${.TARGET} ${.ALLSRC} ${LIBSTAND}
84
85zfsboot.o: zfsboot.s
86
87SRCS=	zfsboot.c zfsboot.h
88
89zfsboot.s: zfsboot.c zfsboot.h ${.CURDIR}/../../zfs/zfsimpl.c
90	${CC} ${CFLAGS} -S -o zfsboot.s.tmp ${.CURDIR}/zfsboot.c
91	sed -e '/align/d' -e '/nop/d' < zfsboot.s.tmp > zfsboot.s
92	rm -f zfsboot.s.tmp
93
94zfsboot.h: zfsldr.out
95	${NM} -t d ${.ALLSRC} | awk '/([0-9])+ T xread/ \
96	    { x = $$1 - ORG1; \
97	    printf("#define XREADORG %#x\n", REL1 + x) }' \
98	    ORG1=`printf "%d" ${ORG1}` \
99	    REL1=`printf "%d" ${REL1}` > ${.TARGET}
100
101.if ${MACHINE_CPUARCH} == "amd64"
102beforedepend zfsboot.s: machine
103CLEANFILES+=	machine
104machine:
105	ln -sf ${.CURDIR}/../../../i386/include machine
106.endif
107
108.include <bsd.prog.mk>
109