AMD64 - Enhance help target for src/test/amd64 build
[dragonfly.git] / test / amd64 / Makefile
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
7 # require it to be specified
8 SRCDIR ?= ${.CURDIR}/../..
9 QEMU ?= qemu-0.10.1
10 ROOTSIZE ?= 512M
11
12 all: help
13
14 scratch: qemu world32 world64 kernel64 root64 install64 sysloader
15         @echo "Run the environment with:"
16         @echo "make QEMUDIR=${QEMUDIR} run"
17
18 quickw: quickworld64 quickkernel64 reinstall64 reinstallkernel64 sysloader
19         @echo "Run the environment with:"
20         @echo "make QEMUDIR=${QEMUDIR} run"
21
22 quick: quickkernel64 reinstallkernel64
23         @echo "Run the environment with:"
24         @echo "make QEMUDIR=${QEMUDIR} run"
25
26 help:
27         @echo "Setup Instructions:"
28         @echo ""
29         @echo "    setenv QEMUDIR target_dir"
30         @echo ""
31         @echo "Meta target components:"
32         @echo ""
33         @echo "    help     - this help"
34         @echo "    clean    - clean up"
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"
41         @echo "    umount   - unmount"
42         @echo "    gdb64    - create /usr/loca/bin/gdb64 - debug 64 bit bins"
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 ""
62
63 # Unmount everything, de-configured VN, and clean up.
64 # (check handles umounting/deconfiguring)
65 #
66 clean: check
67         rm -rf ${QEMUDIR}/${QEMU}.tar.gz ${QEMUDIR}/${QEMU} \
68                 ${QEMUDIR}/${QEMU}-dragonfly.patch \
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 #
79 qemu: 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
84 .if !exists(${QEMUDIR}/${QEMU}-dragonfly.patch)
85         cd ${QEMUDIR} && \
86             fetch http://pkgbox.dragonflybsd.org/patches/${QEMU}-dragonfly.patch
87 .endif
88         rm -rf ${QEMUDIR}/${QEMU}
89         cd ${QEMUDIR} && tar xvzpf ${QEMU}.tar.gz
90         cd ${QEMUDIR}/${QEMU} && patch -p1 < ${QEMUDIR}/${QEMU}-dragonfly.patch
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 #
105 world32: checkq
106         cd ${SRCDIR} && make -j 4 buildworld
107
108 world64: checkq
109         cd ${SRCDIR} && \
110             make -j 4 TARGET_ARCH=amd64 TARGET_PLATFORM=pc64 buildworld
111
112 kernel64: checkq
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 #
120 quickworld64: checkq
121         cd ${SRCDIR} && \
122             make -j 4 TARGET_ARCH=amd64 TARGET_PLATFORM=pc64 quickworld
123
124 quickkernel64: checkq
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 #
132 root64: 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
147 mount: check
148         vnconfig -c -s labels `cat ${QEMUDIR}/vn.which` ${QEMUDIR}/root.img
149         fsck -p /dev/`cat ${QEMUDIR}/vn.which`s1a
150         mount /dev/`cat ${QEMUDIR}/vn.which`s1a ${QEMUDIR}/root
151         @echo "Mounted ${QEMUDIR}/root"
152
153 umount: check
154
155 # Install a fresh 64 bit world & distribution, and kernel
156 #
157 #
158 install64: 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
167         echo 'vfs.root.mountfrom="ufs:ad1s1a"' > ${QEMUDIR}/root/boot/loader.conf
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
175         @echo "WARNING: 64 bit loader installed, if it doesn't work"
176         @echo "         then use 'sysloader' to install the 32 bit one"
177
178 # Quick reinstall - just install a new kernel on top of an existing image
179 #
180 #
181 reinstall64: mount
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"
185         cd ${SRCDIR} && \
186             make -j 4 TARGET_ARCH=amd64 TARGET_PLATFORM=pc64 \
187                  DESTDIR=${QEMUDIR}/root installworld
188
189 reinstallkernel64: mount
190         cd ${SRCDIR} && \
191             make -j 4 TARGET_ARCH=amd64 TARGET_PLATFORM=pc64 \
192                  DESTDIR=${QEMUDIR}/root KERNCONF=JG64 \
193                  NO_MODULES= \
194                  installkernel
195
196 sysloader: mount
197         cp /boot/loader ${QEMUDIR}/root/boot/loader
198         sync
199
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 #
204 run: check
205         cd ${QEMUDIR} && qemu-system-x86_64 -curses -hda ${QEMUDIR}/root.img \
206                                             -m 128 -no-fd-bootchk
207
208 rungdb: check
209         @echo "RUN WITH:  run -curses -hda root.img"
210         cd ${QEMUDIR} && gdb qemu-system-x86_64
211
212 # build a gdb capable of debugging 64 bit binaries
213 #
214 gdb64:
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
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 #
223 checkq:
224 .if !defined(QEMUDIR)
225         @(echo "must specify QEMUDIR=target or as an environment variable"; exit 1)
226 .endif
227 .if exists(${QEMUDIR})
228         @echo "${QEMUDIR} found"
229 .else
230         mkdir -p ${QEMUDIR}
231 .endif
232
233 check: 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)