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