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
15 @echo "Run the environment with:"
16 @echo "make QEMUDIR=${QEMUDIR} run"
18 quickw: quickworld64 quickkernel64 reinstall64 reinstallkernel64
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 "setenv QEMUDIR target_dir"
28 @echo "make [help | clean | scratch | quick | quickw"
29 @echo "make [run | mount | umount]"
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"
41 # Unmount everything, de-configured VN, and clean up.
42 # (check handles umounting/deconfiguring)
45 rm -rf ${QEMUDIR}/${QEMU}.tar.gz ${QEMUDIR}/${QEMU} \
46 ${QEMUDIR}/${QEMU}-dragonfly.patch \
47 ${QEMUDIR}/root.img ${QEMUDIR}/root
49 # Build qemu for Intel 32 and 64 bit environments
51 # If configuring with sdl support from pkgsrc add the following
52 # options to the configure command:
54 # --extra-cflags=-I/usr/pkg/include
55 # --extra-ldflags=-L/usr/pkg/lib
58 .if !exists(${QEMUDIR}/${QEMU}.tar.gz)
60 fetch http://download.savannah.gnu.org/releases/qemu/${QEMU}.tar.gz
62 .if !exists(${QEMUDIR}/${QEMU}-dragonfly.patch)
64 fetch http://pkgbox.dragonflybsd.org/patches/${QEMU}-dragonfly.patch
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 \
76 --target-list=i386-softmmu,x86_64-softmmu
77 cd ${QEMUDIR}/${QEMU} && CCVER=gcc34 gmake
78 cd ${QEMUDIR}/${QEMU} && CCVER=gcc34 gmake install
80 # Build the 32 and 64 bit worlds and the 64 bit kernel
84 cd ${SRCDIR} && make -j 4 buildworld
88 make -j 4 TARGET_ARCH=amd64 TARGET_PLATFORM=pc64 buildworld
92 make -j 4 TARGET_ARCH=amd64 TARGET_PLATFORM=pc64 KERNCONF=JG64 \
95 # Quick build - just rebuild the kernel quickly
100 make -j 4 TARGET_ARCH=amd64 TARGET_PLATFORM=pc64 quickworld
102 quickkernel64: checkq
104 make TARGET_ARCH=amd64 TARGET_PLATFORM=pc64 KERNCONF=JG64 \
107 # Build and mount an empty filesystem for the emulated root disk
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
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"
133 # Install a fresh 64 bit world & distribution, and kernel
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
149 make -j 4 TARGET_ARCH=amd64 TARGET_PLATFORM=pc64 \
150 DESTDIR=${QEMUDIR}/root KERNCONF=JG64 \
154 # Quick reinstall - just install a new kernel on top of an existing image
159 make -j 4 TARGET_ARCH=amd64 TARGET_PLATFORM=pc64 \
160 DESTDIR=${QEMUDIR}/root installworld
162 reinstallkernel64: mount
164 make -j 4 TARGET_ARCH=amd64 TARGET_PLATFORM=pc64 \
165 DESTDIR=${QEMUDIR}/root KERNCONF=JG64 \
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)
174 cd ${QEMUDIR} && qemu-system-x86_64 -curses -hda ${QEMUDIR}/root.img \
175 -m 128 -no-fd-bootchk
178 @echo "RUN WITH: run -curses -hda root.img"
179 cd ${QEMUDIR} && gdb qemu-system-x86_64
181 # build a gdb capable of debugging 64 bit binaries
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
188 # Make sure we are not mounted and the VN device is unconfigured,
190 # Find an unused VN device but do not do anything with it yet.
193 .if !defined(QEMUDIR)
194 @(echo "must specify QEMUDIR=target or as an environment variable"; exit 1)
196 .if exists(${QEMUDIR})
197 @echo "${QEMUDIR} found"
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
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)