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