Makefile revision 108016
1# $FreeBSD: head/sys/boot/i386/gptboot/Makefile 108016 2002-12-18 07:13:53Z imp $
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	-mrtd \
40	-D${BOOT2_UFS} \
41	-I${.CURDIR}/../../common \
42	-I${.CURDIR}/../btx/lib -I. \
43	-Wall -Waggregate-return -Wbad-function-cast -Wcast-align \
44	-Wmissing-declarations -Wmissing-prototypes -Wnested-externs \
45	-Wpointer-arith -Wshadow -Wstrict-prototypes -Wwrite-strings
46
47LDFLAGS=-nostdlib -static -N --gc-sections
48
49all: boot1 boot2
50
51boot1: boot1.out
52	objcopy -S -O binary boot1.out ${.TARGET}
53
54boot1.out: boot1.o
55	${LD} ${LDFLAGS} -e start -Ttext ${ORG1} -o ${.TARGET} boot1.o
56
57boot1.o: boot1.s
58	${CPP} ${CFLAGS} ${.IMPSRC} | \
59	    ${AS} ${AFLAGS} --defsym FLAGS=${B1FLAGS} -o ${.TARGET}
60
61boot2.o: boot2.c ${.CURDIR}/../../common/ufsread.c
62	${CC} ${CFLAGS} -S -o boot2.s.tmp ${.IMPSRC}
63	sed -e '/align/d' -e '/nop/d' < boot2.s.tmp > boot2.s
64	rm -f boot2.s.tmp
65	${AS} ${AFLAGS} -o boot2.o boot2.s
66
67boot2.h: boot1.out
68	${NM} -t d ${.ALLSRC} | awk '/([0-9])+ T xread/ \
69	 	{ x = $$1 - ORG1; \
70		printf("#define XREADORG %#x\n", REL1 + x) }' \
71	 	ORG1=`printf "%d" ${ORG1}` \
72		REL1=`printf "%d" ${REL1}` > 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	@ls -l boot2.ld | awk '{ x = 7680 - $$5; \
78		print x " bytes available"; if (x < 0) exit 1 }'
79	dd if=boot2.ld of=${.TARGET} obs=7680 conv=osync 2>/dev/null
80
81boot2.ldr:
82	dd if=/dev/zero of=${.TARGET} bs=276 count=1 2>/dev/null
83
84boot2.bin: boot2.out
85	objcopy -S -O binary boot2.out ${.TARGET}
86
87boot2.out: boot2.o sio.o
88	${LD} ${LDFLAGS} -Ttext ${ORG2} -o ${.TARGET} \
89		${BTX}/lib/crt0.o ${.ALLSRC}
90
91boot2.o: boot2.h
92
93sio.o: sio.s
94	${AS} ${AFLAGS} --defsym SIOPRT=${BOOT_COMCONSOLE_PORT} \
95		--defsym SIOFMT=${B2SIOFMT} \
96		--defsym SIOSPD=${BOOT_COMCONSOLE_SPEED} \
97		${.IMPSRC} -o ${.TARGET}
98
99install:
100	${INSTALL} -o ${BINOWN} -g ${BINGRP} -m ${BINMODE} \
101		boot1 ${DESTDIR}${BINDIR}/boot1
102	${INSTALL} -o ${BINOWN} -g ${BINGRP} -m ${BINMODE} \
103		boot2 ${DESTDIR}${BINDIR}/boot2
104
105.include <bsd.prog.mk>
106