Makefile revision 104668
1# $FreeBSD: head/sys/boot/i386/gptboot/Makefile 104668 2002-10-08 07:52:28Z phk $
2
3PROG=		boot2
4NOMAN=
5STRIP=
6BINDIR?=	/boot
7BINMODE=	444
8CLEANFILES+=	boot1 boot1.out boot1.o \
9		boot2.ldr boot2.bin boot2.ld boot2.out boot2.o boot2.h \
10		boot2.s sio.o divdi3.o moddi3.o qdivrem.o
11
12NM?=		nm
13
14# A value of 0x80 enables LBA support.
15B1FLAGS=	0x80
16
17BOOT_COMCONSOLE_PORT?= 0x3f8
18BOOT_COMCONSOLE_SPEED?= 9600
19B2SIOFMT?=	0x3
20
21.if exists(${.OBJDIR}/../btx)
22BTX=	${.OBJDIR}/../btx
23.else
24BTX=	${.CURDIR}/../btx
25.endif
26
27ORG1=	0x7c00
28ORG2=	0x1000
29
30# Setting this to anything else gives UFS1+2 support and larger
31# boot2 binary.
32BOOT2_UFS?=	UFS1_ONLY
33
34CFLAGS=	-elf -ffreestanding -Os -fno-builtin \
35	-fno-guess-branch-probability \
36	-mrtd \
37	-I${.CURDIR}/../../common \
38	-I${.CURDIR}/../btx/lib -I. \
39	-Wall -Waggregate-return -Wbad-function-cast -Wcast-align \
40	-Wmissing-declarations -Wmissing-prototypes -Wnested-externs \
41	-Wpointer-arith -Wshadow -Wstrict-prototypes -Wwrite-strings
42
43.if ${BOOT2_UFS} == "UFS1_ONLY"
44CFLAGS+= -D${BOOT2_UFS}
45.else
46
47.endif
48
49LDFLAGS=-nostdlib -static -N
50
51all: boot1 boot2
52
53boot1: boot1.out
54	objcopy -S -O binary boot1.out ${.TARGET}
55
56boot1.out: boot1.o
57	${LD} ${LDFLAGS} -e start -Ttext ${ORG1} -o ${.TARGET} boot1.o
58
59boot1.o: boot1.s
60	${CPP} ${CFLAGS} ${.IMPSRC} | \
61	    ${AS} ${AFLAGS} --defsym FLAGS=${B1FLAGS} -o ${.TARGET}
62
63boot2.o: boot2.c ${.CURDIR}/../../common/ufsread.c
64	${CC} ${CFLAGS} -S -o boot2.s.tmp ${.IMPSRC}
65	sed -e '/align/d' -e '/nop/d' < boot2.s.tmp > boot2.s
66	rm -f boot2.s.tmp
67	${AS} ${AFLAGS} -o boot2.o boot2.s
68
69boot2.h: boot1.out
70	${NM} -t d ${.ALLSRC} | awk '/([0-9])+ T xread/ \
71	 	{ x = $$1 - ORG1; printf("#define XREADORG 0x7%x\n", x) }' \
72	 	ORG1=`printf "%d" ${ORG1}` > boot2.h
73
74boot2: boot2.ldr boot2.bin ${BTX}/btx/btx
75	btxld -v -E ${ORG2} -f bin -b ${BTX}/btx/btx -l boot2.ldr \
76		-o boot2.ld -P 1 boot2.bin
77.if ${BOOT2_UFS} == "UFS1_ONLY"
78	@ls -l boot2.ld | awk '{ x = 7680 - $$5; \
79		print x " bytes available"; if (x < 0) exit 1 }'
80	dd if=boot2.ld of=${.TARGET} obs=7680 conv=osync 2>/dev/null
81.else
82	@ls -l boot2.ld | awk '{ x = 9728 - $$5; \
83		print x " bytes available"; if (x < 0) exit 1 }'
84	dd if=boot2.ld of=${.TARGET} obs=9728 conv=osync 2>/dev/null
85.endif
86
87boot2.ldr:
88	dd if=/dev/zero of=${.TARGET} bs=512 count=1 2>/dev/null
89
90boot2.bin: boot2.out
91	objcopy -S -O binary boot2.out ${.TARGET}
92
93.if ${BOOT2_UFS} == "UFS1_ONLY"
94boot2.out: boot2.o sio.o
95.else
96boot2.out: boot2.o sio.o divdi3.o moddi3.o qdivrem.o
97.endif
98	${LD} ${LDFLAGS} -Ttext ${ORG2} -o ${.TARGET} \
99		${BTX}/lib/crt0.o ${.ALLSRC}
100
101boot2.o: boot2.h
102
103sio.o: sio.s
104	${AS} ${AFLAGS} --defsym SIOPRT=${BOOT_COMCONSOLE_PORT} \
105		--defsym SIOFMT=${B2SIOFMT} \
106		--defsym SIOSPD=${BOOT_COMCONSOLE_SPEED} \
107		${.IMPSRC} -o ${.TARGET}
108
109moddi3.o: ${.CURDIR}/../../../libkern/moddi3.c
110	${CC} ${CFLAGS} -I${.CURDIR}/../../../ -c ${.IMPSRC}
111
112divdi3.o: ${.CURDIR}/../../../libkern/divdi3.c
113	${CC} ${CFLAGS} -I${.CURDIR}/../../../ -c ${.IMPSRC}
114
115qdivrem.o: ${.CURDIR}/../../../libkern/qdivrem.c
116	${CC} ${CFLAGS} -I${.CURDIR}/../../../ -c ${.IMPSRC}
117
118install:
119	${INSTALL} -o ${BINOWN} -g ${BINGRP} -m ${BINMODE} \
120		boot1 ${DESTDIR}${BINDIR}/boot1
121	${INSTALL} -o ${BINOWN} -g ${BINGRP} -m ${BINMODE} \
122		boot2 ${DESTDIR}${BINDIR}/boot2
123
124.include <bsd.prog.mk>
125