Makefile revision 108149
1# $FreeBSD: head/sys/boot/i386/gptboot/Makefile 108149 2002-12-21 02:03:31Z obrien $
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
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=	0x2000
30
31# Decide Level of UFS support.  UFS1_AND_UFS2 doesn't fit.
32
33# BOOT2_UFS?=	UFS2_ONLY
34BOOT2_UFS?=	UFS1_AND_UFS2
35# BOOT2_UFS?=	UFS1_ONLY
36
37CFLAGS=	-elf -ffreestanding -Os -fno-builtin \
38	-fno-guess-branch-probability -fomit-frame-pointer\
39	-mno-align-long-strings \
40	-mrtd \
41	-D${BOOT2_UFS} \
42	-I${.CURDIR}/../../common \
43	-I${.CURDIR}/../btx/lib -I. \
44	-Wall -Waggregate-return -Wbad-function-cast -Wcast-align \
45	-Wmissing-declarations -Wmissing-prototypes -Wnested-externs \
46	-Wpointer-arith -Wshadow -Wstrict-prototypes -Wwrite-strings
47
48LDFLAGS=-nostdlib -static -N --gc-sections
49
50all: boot1 boot2
51
52boot1: boot1.out
53	objcopy -S -O binary boot1.out ${.TARGET}
54
55boot1.out: boot1.o
56	${LD} ${LDFLAGS} -e start -Ttext ${ORG1} -o ${.TARGET} boot1.o
57
58boot1.o: boot1.s
59	${CPP} ${CFLAGS} ${.IMPSRC} | \
60	    ${AS} ${AFLAGS} --defsym FLAGS=${B1FLAGS} -o ${.TARGET}
61
62boot2.o: boot2.c ${.CURDIR}/../../common/ufsread.c
63	${CC} ${CFLAGS} -S -o boot2.s.tmp ${.IMPSRC}
64	sed -e '/align/d' -e '/nop/d' < boot2.s.tmp > boot2.s
65	rm -f boot2.s.tmp
66	${AS} ${AFLAGS} -o boot2.o boot2.s
67
68boot2.h: boot1.out
69	${NM} -t d ${.ALLSRC} | awk '/([0-9])+ T xread/ \
70	 	{ x = $$1 - ORG1; \
71		printf("#define XREADORG %#x\n", REL1 + x) }' \
72	 	ORG1=`printf "%d" ${ORG1}` \
73		REL1=`printf "%d" ${REL1}` > boot2.h
74
75boot2: boot2.ldr boot2.bin ${BTX}/btx/btx
76	btxld -v -E ${ORG2} -f bin -b ${BTX}/btx/btx -l boot2.ldr \
77		-o boot2.ld -P 1 boot2.bin
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
82boot2.ldr:
83	dd if=/dev/zero of=${.TARGET} bs=276 count=1 2>/dev/null
84
85boot2.bin: boot2.out
86	objcopy -S -O binary boot2.out ${.TARGET}
87
88boot2.out: boot2.o sio.o
89	${LD} ${LDFLAGS} -Ttext ${ORG2} -o ${.TARGET} \
90		${BTX}/lib/crt0.o ${.ALLSRC}
91
92boot2.o: boot2.h
93
94sio.o: sio.s
95	${AS} ${AFLAGS} --defsym SIOPRT=${BOOT_COMCONSOLE_PORT} \
96		--defsym SIOFMT=${B2SIOFMT} \
97		--defsym SIOSPD=${BOOT_COMCONSOLE_SPEED} \
98		${.IMPSRC} -o ${.TARGET}
99
100install:
101	${INSTALL} -o ${BINOWN} -g ${BINGRP} -m ${BINMODE} \
102		boot1 ${DESTDIR}${BINDIR}/boot1
103	${INSTALL} -o ${BINOWN} -g ${BINGRP} -m ${BINMODE} \
104		boot2 ${DESTDIR}${BINDIR}/boot2
105
106.include <bsd.prog.mk>
107