AMD64 - Enhance help target for src/test/amd64 build
[dragonfly.git] / test / amd64 / Makefile
CommitLineData
edbdff6b
MD
1# Makefile - manage a qemu system for testing 64 bit DragonFly builds
2#
3# This Makefile will patch and build qemu, do all necessary world and
4# kernel builds, and create a 64 bit root.img disk.
5#
6
4166d988 7# require it to be specified
f50a0df7 8SRCDIR ?= ${.CURDIR}/../..
edbdff6b 9QEMU ?= qemu-0.10.1
edbdff6b
MD
10ROOTSIZE ?= 512M
11
12all: help
13
d8ab33fe 14scratch: qemu world32 world64 kernel64 root64 install64 sysloader
edbdff6b 15 @echo "Run the environment with:"
0d9f5ab9 16 @echo "make QEMUDIR=${QEMUDIR} run"
edbdff6b 17
d8ab33fe 18quickw: quickworld64 quickkernel64 reinstall64 reinstallkernel64 sysloader
edbdff6b 19 @echo "Run the environment with:"
0d9f5ab9 20 @echo "make QEMUDIR=${QEMUDIR} run"
edbdff6b 21
0d9f5ab9
MD
22quick: quickkernel64 reinstallkernel64
23 @echo "Run the environment with:"
24 @echo "make QEMUDIR=${QEMUDIR} run"
edbdff6b
MD
25
26help:
d8ab33fe
MD
27 @echo "Setup Instructions:"
28 @echo ""
29 @echo " setenv QEMUDIR target_dir"
30 @echo ""
31 @echo "Meta target components:"
32 @echo ""
0d9f5ab9
MD
33 @echo " help - this help"
34 @echo " clean - clean up"
d8ab33fe
MD
35 @echo " scratch - build and install everything from scratch"
36 @echo " (this is absolutely everything, except gdb64)"
37 @echo " quick - incremental kernel build & reinstall"
38 @echo " quickw - incremental world & kernel build & reinstall"
39 @echo " run - run qemu with QEMUDIR/root.img"
40 @echo " mount - mount QEMUDIR/root.img at QEMUDIR/root"
0d9f5ab9
MD
41 @echo " umount - unmount"
42 @echo " gdb64 - create /usr/loca/bin/gdb64 - debug 64 bit bins"
d8ab33fe
MD
43 @echo ""
44 @echo "Individual target components:"
45 @echo ""
46 @echo " qemu - fetch, patch, and build qemu"
47 @echo " world32 - build the 32 bit world from scratch"
48 @echo " world64 - build the 64 bit world from scratch"
49 @echo " kernel64 - build the 64 bit kernel from scratch"
50 @echo " root64 - create a new, empty root.img"
51 @echo " install64 - install a 64 bit world & kernel"
52 @echo " into root.img"
53 @echo " quickworld64 - incremental rebuild world64"
54 @echo " quickkernel64 - incremental rebuild kernel64"
55 @echo " reinstall64 - reinstall world64 into root.img"
56 @echo " (just the installworld piece)"
57 @echo " reinstallkernel64 - reinstall kernel64 into root.img"
58 @echo " sysloader - reinstall 32-bit system loader"
59 @echo " (in case the 64 bit loader fails,"
60 @echo " the 32 bit loader can be used)"
61 @echo ""
edbdff6b
MD
62
63# Unmount everything, de-configured VN, and clean up.
64# (check handles umounting/deconfiguring)
65#
66clean: check
67 rm -rf ${QEMUDIR}/${QEMU}.tar.gz ${QEMUDIR}/${QEMU} \
b0fc2716 68 ${QEMUDIR}/${QEMU}-dragonfly.patch \
edbdff6b
MD
69 ${QEMUDIR}/root.img ${QEMUDIR}/root
70
71# Build qemu for Intel 32 and 64 bit environments
72#
73# If configuring with sdl support from pkgsrc add the following
74# options to the configure command:
75#
76# --extra-cflags=-I/usr/pkg/include
77# --extra-ldflags=-L/usr/pkg/lib
78#
79qemu: checkq
80.if !exists(${QEMUDIR}/${QEMU}.tar.gz)
81 cd ${QEMUDIR} && \
82 fetch http://download.savannah.gnu.org/releases/qemu/${QEMU}.tar.gz
83.endif
b0fc2716 84.if !exists(${QEMUDIR}/${QEMU}-dragonfly.patch)
edbdff6b 85 cd ${QEMUDIR} && \
b0fc2716 86 fetch http://pkgbox.dragonflybsd.org/patches/${QEMU}-dragonfly.patch
edbdff6b
MD
87.endif
88 rm -rf ${QEMUDIR}/${QEMU}
89 cd ${QEMUDIR} && tar xvzpf ${QEMU}.tar.gz
b0fc2716 90 cd ${QEMUDIR}/${QEMU} && patch -p1 < ${QEMUDIR}/${QEMU}-dragonfly.patch
edbdff6b
MD
91 cd ${QEMUDIR}/${QEMU} && \
92 ./configure --disable-sdl \
93 --disable-gfx-check \
94 --disable-kqemu \
95 --enable-system \
96 --disable-aio \
97 --disable-kvm \
98 --target-list=i386-softmmu,x86_64-softmmu
99 cd ${QEMUDIR}/${QEMU} && CCVER=gcc34 gmake
100 cd ${QEMUDIR}/${QEMU} && CCVER=gcc34 gmake install
101
102# Build the 32 and 64 bit worlds and the 64 bit kernel
103#
104#
4166d988 105world32: checkq
edbdff6b
MD
106 cd ${SRCDIR} && make -j 4 buildworld
107
4166d988 108world64: checkq
edbdff6b
MD
109 cd ${SRCDIR} && \
110 make -j 4 TARGET_ARCH=amd64 TARGET_PLATFORM=pc64 buildworld
111
4166d988 112kernel64: checkq
edbdff6b
MD
113 cd ${SRCDIR} && \
114 make -j 4 TARGET_ARCH=amd64 TARGET_PLATFORM=pc64 KERNCONF=JG64 \
115 buildkernel
116
117# Quick build - just rebuild the kernel quickly
118#
119#
4166d988 120quickworld64: checkq
0d9f5ab9
MD
121 cd ${SRCDIR} && \
122 make -j 4 TARGET_ARCH=amd64 TARGET_PLATFORM=pc64 quickworld
123
4166d988 124quickkernel64: checkq
edbdff6b
MD
125 cd ${SRCDIR} && \
126 make TARGET_ARCH=amd64 TARGET_PLATFORM=pc64 KERNCONF=JG64 \
127 quickkernel
128
129# Build and mount an empty filesystem for the emulated root disk
130#
131#
132root64: check
133 vnconfig -c -T -S ${ROOTSIZE} -s labels \
134 `cat ${QEMUDIR}/vn.which` ${QEMUDIR}/root.img
135 dd if=/dev/zero of=/dev/`cat ${QEMUDIR}/vn.which` bs=32k count=4
136 fdisk -IB `cat ${QEMUDIR}/vn.which`
137 disklabel -r -w `cat ${QEMUDIR}/vn.which`s1 auto
138 disklabel `cat ${QEMUDIR}/vn.which`s1 > ${QEMUDIR}/label.tmp
139 echo 'a: * 0 4.2BSD' >> ${QEMUDIR}/label.tmp
140 disklabel -R `cat ${QEMUDIR}/vn.which`s1 ${QEMUDIR}/label.tmp
141 disklabel -B `cat ${QEMUDIR}/vn.which`s1
142 newfs /dev/`cat ${QEMUDIR}/vn.which`s1a
143 mkdir -p ${QEMUDIR}/root
144 vnconfig -u `cat ${QEMUDIR}/vn.which`
145 rm -f ${QEMUDIR}/vn.which
146
147mount: check
148 vnconfig -c -s labels `cat ${QEMUDIR}/vn.which` ${QEMUDIR}/root.img
0d9f5ab9 149 fsck -p /dev/`cat ${QEMUDIR}/vn.which`s1a
edbdff6b
MD
150 mount /dev/`cat ${QEMUDIR}/vn.which`s1a ${QEMUDIR}/root
151 @echo "Mounted ${QEMUDIR}/root"
152
153umount: check
154
155# Install a fresh 64 bit world & distribution, and kernel
156#
157#
158install64: mount
159 cd ${SRCDIR} && \
160 make -j 4 TARGET_ARCH=amd64 TARGET_PLATFORM=pc64 \
161 DESTDIR=${QEMUDIR}/root installworld
162 cd ${SRCDIR}/etc && \
163 make -j 4 TARGET_ARCH=amd64 TARGET_PLATFORM=pc64 \
164 DESTDIR=${QEMUDIR}/root distribution
165 echo '/dev/ad1s1a / ufs rw 1 1' > ${QEMUDIR}/root/etc/fstab
166 echo 'proc /proc procfs rw 0 0' >> ${QEMUDIR}/root/etc/fstab
0d9f5ab9 167 echo 'vfs.root.mountfrom="ufs:ad1s1a"' > ${QEMUDIR}/root/boot/loader.conf
edbdff6b
MD
168 (egrep -v '^console' ${QEMUDIR}/root/etc/ttys; echo 'console "/usr/libexec/getty Pc" cons25 on secure') > ${QEMUDIR}/root/etc/ttys.new
169 mv -f ${QEMUDIR}/root/etc/ttys.new ${QEMUDIR}/root/etc/ttys
170 cd ${SRCDIR} && \
171 make -j 4 TARGET_ARCH=amd64 TARGET_PLATFORM=pc64 \
172 DESTDIR=${QEMUDIR}/root KERNCONF=JG64 \
173 NO_MODULES= \
174 installkernel
d8ab33fe
MD
175 @echo "WARNING: 64 bit loader installed, if it doesn't work"
176 @echo " then use 'sysloader' to install the 32 bit one"
edbdff6b
MD
177
178# Quick reinstall - just install a new kernel on top of an existing image
179#
180#
181reinstall64: mount
d8ab33fe
MD
182 @echo "NOTE: Installing native 32 bit loader into root.img."
183 @echo " This loader should still be able to boot the"
184 @echo " 64 bit kernel"
edbdff6b
MD
185 cd ${SRCDIR} && \
186 make -j 4 TARGET_ARCH=amd64 TARGET_PLATFORM=pc64 \
0d9f5ab9
MD
187 DESTDIR=${QEMUDIR}/root installworld
188
189reinstallkernel64: mount
190 cd ${SRCDIR} && \
191 make -j 4 TARGET_ARCH=amd64 TARGET_PLATFORM=pc64 \
edbdff6b
MD
192 DESTDIR=${QEMUDIR}/root KERNCONF=JG64 \
193 NO_MODULES= \
194 installkernel
195
d8ab33fe
MD
196sysloader: mount
197 cp /boot/loader ${QEMUDIR}/root/boot/loader
198 sync
199
edbdff6b
MD
200# Run qemu on our image in 64 bit mode. Make sure we are unmounted so
201# we do not compete against the emulated kernel when writing to root.img.
202# (check does this for us)
203#
204run: check
b0fc2716
MD
205 cd ${QEMUDIR} && qemu-system-x86_64 -curses -hda ${QEMUDIR}/root.img \
206 -m 128 -no-fd-bootchk
edbdff6b
MD
207
208rungdb: check
b0fc2716 209 @echo "RUN WITH: run -curses -hda root.img"
edbdff6b
MD
210 cd ${QEMUDIR} && gdb qemu-system-x86_64
211
0d9f5ab9
MD
212# build a gdb capable of debugging 64 bit binaries
213#
214gdb64:
215 cd /usr/src/gnu/usr.bin/gdb && (make clean; make TARGET_ARCH=amd64)
216 cp /usr/obj/usr/src/gnu/usr.bin/gdb/gdb/gdb /usr/local/bin/gdb64
217 cd /usr/src/gnu/usr.bin/gdb && make clean
edbdff6b
MD
218
219# Make sure we are not mounted and the VN device is unconfigured,
220#
221# Find an unused VN device but do not do anything with it yet.
222#
223checkq:
224.if !defined(QEMUDIR)
4166d988
MD
225 @(echo "must specify QEMUDIR=target or as an environment variable"; exit 1)
226.endif
edbdff6b
MD
227.if exists(${QEMUDIR})
228 @echo "${QEMUDIR} found"
229.else
230 mkdir -p ${QEMUDIR}
231.endif
232
233check: checkq
234.if exists(${QEMUDIR}/vn.which)
235 -umount ${QEMUDIR}/root > /dev/null 2>&1
236 -vnconfig -u `cat ${QEMUDIR}/vn.which` > /dev/null 2>&1
237 rm -f ${QEMUDIR}/vn.which
238.endif
239 (vnconfig -l | fgrep "not in use" > /dev/null) || \
240 (echo "Cannot find unused VN"; exit 1)
241 vnconfig -l | fgrep "not in use" | \
242 cut -f 1 -d : | head -1 > ${QEMUDIR}/vn.which
243 egrep '^vn' ${QEMUDIR}/vn.which > /dev/null || \
244 (echo "VN device selection is bad"; exit 1)