1 # Makefile - manage a qemu system for testing 64 bit DragonFly builds
3 # This Makefile will patch and build qemu, do all necessary world and
4 # kernel builds, and create a 64 bit root.img disk.
7 # require it to be specified
8 SRCDIR ?= ${.CURDIR}/../..
14 scratch: qemu world32 world64 kernel64 root64 install64 sysloader
15 @echo "Run the environment with:"
16 @echo "make QEMUDIR=${QEMUDIR} run"
18 quickw: quickworld64 quickkernel64 reinstall64 reinstallkernel64 sysloader
19 @echo "Run the environment with:"
20 @echo "make QEMUDIR=${QEMUDIR} run"
22 quick: quickkernel64 reinstallkernel64
23 @echo "Run the environment with:"
24 @echo "make QEMUDIR=${QEMUDIR} run"
27 @echo "Setup Instructions:"
29 @echo " setenv QEMUDIR target_dir"
31 @echo "Meta target components:"
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"
44 @echo "Individual target components:"
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)"
63 # Unmount everything, de-configured VN, and clean up.
64 # (check handles umounting/deconfiguring)
67 rm -rf ${QEMUDIR}/${QEMU}.tar.gz ${QEMUDIR}/${QEMU} \
68 ${QEMUDIR}/${QEMU}-dragonfly.patch \
69 ${QEMUDIR}/root.img ${QEMUDIR}/root
71 # Build qemu for Intel 32 and 64 bit environments
73 # If configuring with sdl support from pkgsrc add the following
74 # options to the configure command:
76 # --extra-cflags=-I/usr/pkg/include
77 # --extra-ldflags=-L/usr/pkg/lib
80 .if !exists(${QEMUDIR}/${QEMU}.tar.gz)
82 fetch http://download.savannah.gnu.org/releases/qemu/${QEMU}.tar.gz
84 .if !exists(${QEMUDIR}/${QEMU}-dragonfly.patch)
86 fetch http://pkgbox.dragonflybsd.org/patches/${QEMU}-dragonfly.patch
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 \
98 --target-list=i386-softmmu,x86_64-softmmu
99 cd ${QEMUDIR}/${QEMU} && CCVER=gcc34 gmake
100 cd ${QEMUDIR}/${QEMU} && CCVER=gcc34 gmake install
102 # Build the 32 and 64 bit worlds and the 64 bit kernel
106 cd ${SRCDIR} && make -j 4 buildworld
110 make -j 4 TARGET_ARCH=amd64 TARGET_PLATFORM=pc64 buildworld
114 make -j 4 TARGET_ARCH=amd64 TARGET_PLATFORM=pc64 KERNCONF=JG64 \
117 # Quick build - just rebuild the kernel quickly
122 make -j 4 TARGET_ARCH=amd64 TARGET_PLATFORM=pc64 quickworld
124 quickkernel64: checkq
126 make TARGET_ARCH=amd64 TARGET_PLATFORM=pc64 KERNCONF=JG64 \
129 # Build and mount an empty filesystem for the emulated root disk
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
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"
155 # Install a fresh 64 bit world & distribution, and kernel
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
171 make -j 4 TARGET_ARCH=amd64 TARGET_PLATFORM=pc64 \
172 DESTDIR=${QEMUDIR}/root KERNCONF=JG64 \
175 @echo "WARNING: 64 bit loader installed, if it doesn't work"
176 @echo " then use 'sysloader' to install the 32 bit one"
178 # Quick reinstall - just install a new kernel on top of an existing image
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"
186 make -j 4 TARGET_ARCH=amd64 TARGET_PLATFORM=pc64 \
187 DESTDIR=${QEMUDIR}/root installworld
189 reinstallkernel64: mount
191 make -j 4 TARGET_ARCH=amd64 TARGET_PLATFORM=pc64 \
192 DESTDIR=${QEMUDIR}/root KERNCONF=JG64 \
197 cp /boot/loader ${QEMUDIR}/root/boot/loader
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)
205 cd ${QEMUDIR} && qemu-system-x86_64 -curses -hda ${QEMUDIR}/root.img \
206 -m 128 -no-fd-bootchk
209 @echo "RUN WITH: run -curses -hda root.img"
210 cd ${QEMUDIR} && gdb qemu-system-x86_64
212 # build a gdb capable of debugging 64 bit binaries
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
219 # Make sure we are not mounted and the VN device is unconfigured,
221 # Find an unused VN device but do not do anything with it yet.
224 .if !defined(QEMUDIR)
225 @(echo "must specify QEMUDIR=target or as an environment variable"; exit 1)
227 .if exists(${QEMUDIR})
228 @echo "${QEMUDIR} found"
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
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)