xref: /dragonfly/test/vkernel/Makefile (revision 029e6489)
1# Makefile - set up a vkernel environment for testing the vkernel
2#
3
4# require it to be specified
5SRCDIR ?= ${.CURDIR}/../..
6PHYSMEM ?= 256m
7NCPUS ?= 2
8FSTYPE ?= ufs
9EXTRAOPTS ?=
10MAKE_JOBS?=     $$(sysctl -n hw.ncpu)
11
12all: help
13
14.if ${MACHINE_ARCH} == "x86_64"
15USEKERNEL=VKERNEL64
16.endif
17
18scratch: world kernel root install
19	@echo "Run the environment with:"
20	@echo "make VKDIR=${VKDIR} run"
21
22quickw: quickworld quickkernel reinstall reinstallkernel
23	@echo "Run the environment with:"
24	@echo "make VKDIR=${VKDIR} run"
25
26quick: quickkernel reinstallkernel
27	@echo "Run the environment with:"
28	@echo "make VKDIR=${VKDIR} run"
29
30help:
31	@echo "Setup Instructions:"
32	@echo ""
33	@echo "    setenv ROOTSIZE size (optional)"
34	@echo "    setenv VKDIR target_dir"
35	@echo "    setenv FSTYPE fstype (optional. values: hammer, hammer2, ufs)"
36	@echo "    setenv MAKE_JOBS njobs (optional)"
37	@echo ""
38	@echo "Meta target components:"
39	@echo ""
40	@echo "    help     - this help"
41	@echo "    clean    - clean up"
42	@echo "    scratch  - build and install everything from scratch"
43	@echo "               (this is absolutely everything)"
44	@echo "    quick    - incremental kernel build & reinstall"
45	@echo "    quickw   - incremental world & kernel build & reinstall"
46	@echo "    run      - run vkernel with VKDIR/root.img"
47	@echo "    mount    - mount VKDIR/root.img at VKDIR/root"
48	@echo "    umount   - unmount"
49	@echo "    fsck	    - fsck VKDIR/root.img"
50	@echo ""
51	@echo "Individual target components:"
52	@echo ""
53	@echo "    world             - build the world from scratch"
54	@echo "    root              - create a new, empty root.img"
55	@echo "    install           - install a world & kernel"
56	@echo "                        into root.img"
57	@echo "    leaf		     - additional customization"
58	@echo "    kernel   	     - build vkernel"
59	@echo "    quickworld        - incremental rebuild world"
60	@echo "    quickkernel       - incremental rebuild kernel"
61	@echo "    reinstall         - reinstall world into root.img"
62	@echo "                        (just the installworld piece)"
63	@echo "    reinstallkernel   - reinstall kernel into root.img"
64	@echo ""
65
66# Unmount everything, de-configured VN, and clean up.
67# (check handles umounting/deconfiguring)
68#
69clean: check
70	rm -rf ${VKDIR}/root.img ${VKDIR}/root
71
72# Build the world and kernel
73#
74#
75world: checkq
76	cd ${SRCDIR} && make -j ${MAKE_JOBS} buildworld
77
78kernel: checkq
79	cd ${SRCDIR} && make -j ${MAKE_JOBS} KERNCONF=${USEKERNEL} buildkernel
80
81nativekernel: checkq
82	cd ${SRCDIR} && make -j ${MAKE_JOBS} KERNCONF=${USEKERNEL} nativekernel
83
84# Quick build - just rebuild the kernel quickly
85#
86#
87quickworld: checkq
88	cd ${SRCDIR} && make -j ${MAKE_JOBS} quickworld
89
90quickkernel: checkq
91	cd ${SRCDIR} && make -j ${MAKE_JOBS} KERNCONF=${USEKERNEL} quickkernel
92
93# Build and mount an empty filesystem for the emulated root disk
94#
95# NOTE: root must umount when done because a later dependency may
96#       have a dependency on mount.
97#
98root:	check
99	vnconfig -c -T -S ${ROOTSIZE} `cat ${VKDIR}/vn.which` ${VKDIR}/root.img
100	dd if=/dev/zero of=/dev/`cat ${VKDIR}/vn.which` bs=32k count=4
101	fdisk -IB `cat ${VKDIR}/vn.which`
102	disklabel -r -w `cat ${VKDIR}/vn.which`s1 auto
103	disklabel `cat ${VKDIR}/vn.which`s1 > ${VKDIR}/label.tmp
104.if ${FSTYPE} == "ufs"
105	echo 'a: * 0 4.2BSD' >> ${VKDIR}/label.tmp
106.else
107	echo 'a: * 0 ${FSTYPE}' >> ${VKDIR}/label.tmp
108.endif
109	disklabel -R `cat ${VKDIR}/vn.which`s1 ${VKDIR}/label.tmp
110	disklabel -B `cat ${VKDIR}/vn.which`s1
111	${NEWFS_CMD} ${NEWFS_ARGS} /dev/`cat ${VKDIR}/vn.which`s1a
112	mkdir -p ${VKDIR}/root
113	vnconfig -u `cat ${VKDIR}/vn.which` > /dev/null 2>&1
114
115mount: check
116	vnconfig -c `cat ${VKDIR}/vn.which` ${VKDIR}/root.img
117.	if ${FSTYPE} == "ufs"
118		fsck -p /dev/`cat ${VKDIR}/vn.which`s1a
119.	endif
120	${MOUNT_CMD} /dev/`cat ${VKDIR}/vn.which`s1a ${VKDIR}/root
121	@echo "Mounted ${VKDIR}/root"
122
123umount: check
124
125fsck: check
126	vnconfig -c `cat ${VKDIR}/vn.which` ${VKDIR}/root.img
127	fsck -y /dev/`cat ${VKDIR}/vn.which`s1a
128	make umount
129
130# Install a fresh world & distribution, and kernel
131#
132install: mount
133	cd ${SRCDIR} && \
134	    make -j 4 DESTDIR=${VKDIR}/root NO_BACKUP=TRUE installworld
135	cd ${SRCDIR}/etc && \
136	    make -j 4 DESTDIR=${VKDIR}/root distribution
137.if ${FSTYPE} == "ufs"
138	echo '/dev/vkd0s1a	/	ufs	rw	1 1' > ${VKDIR}/root/etc/fstab
139.else
140	echo '/dev/vkd0s1a	/	${FSTYPE}	rw	0 0' > ${VKDIR}/root/etc/fstab
141.endif
142	echo 'proc		/proc	procfs	rw	0 0' >> ${VKDIR}/root/etc/fstab
143	echo "vfs.root.mountfrom=\"${FSTYPE}:vkd0s1a\"" > ${VKDIR}/root/boot/loader.conf
144	#(egrep -v '^console' ${VKDIR}/root/etc/ttys; echo 'console "/usr/libexec/getty Pc"	cons25	on	secure') > ${VKDIR}/root/etc/ttys.new
145	#mv -f ${VKDIR}/root/etc/ttys.new ${VKDIR}/root/etc/ttys
146	cd ${SRCDIR} && \
147	    make -j 4 \
148		 DESTDIR=${VKDIR}/root KERNCONF=${USEKERNEL} \
149		 installkernel
150	cp ${VKDIR}/root/boot/kernel/kernel ${VKDIR}/vkernel
151
152leaf: mount
153	echo 'ifconfig_vke0="up"' > ${VKDIR}/root/etc/rc.conf
154	echo 'defaultrouter="10.26.0.1"' >> ${VKDIR}/root/etc/rc.conf
155	echo 'search dragonflybsd.org backplane.com' > ${VKDIR}/root/etc/resolv.conf
156	echo 'nameserver 10.0.0.25' >> ${VKDIR}/root/etc/resolv.conf
157	echo 'nameserver 10.0.0.2' >> ${VKDIR}/root/etc/resolv.conf
158	echo 'nameserver 8.8.8.8' >> ${VKDIR}/root/etc/resolv.conf
159	make umount
160	chmod 644 /build/vkernel/root.img
161
162# Quick reinstall - just install a new kernel on top of an existing image
163#
164#
165reinstall: mount
166	cd ${SRCDIR} && \
167	    make -j 4 DESTDIR=${VKDIR}/root NO_BACKUP=TRUE installworld
168
169reinstallkernel: mount
170	cd ${SRCDIR} && \
171	    make -j 4 DESTDIR=${VKDIR}/root KERNCONF=${USEKERNEL} \
172		 installkernel
173	cp ${VKDIR}/root/boot/kernel/kernel ${VKDIR}/vkernel
174
175sysloader: mount
176	cp /boot/loader ${VKDIR}/root/boot/loader
177	sync
178
179# Run the vkernel on our image.  Make sure we are unmounted so
180# we do not compete against the emulated kernel when writing to root.img.
181# (check does this for us)
182#
183run: check
184	mkdir -p /var/vkernel
185	sysctl vm.vkernel_enable=1
186	cd ${VKDIR} && ./vkernel -m ${PHYSMEM} -n ${NCPUS} \
187			-r root.img -U -v \
188			-I /var/run/vknet ${EXTRAOPTS} ${MNTOPTS}
189
190# When running w/ a NFS root
191#
192NFS_IP?= 10.0.0.53
193NFS_NETMASK?= 255.255.255.0
194NFS_ROOT_IP?= 10.0.0.1
195NFS_ROOT_PATH?= /netboot2
196
197run_nfsroot: check
198	cd ${VKDIR} && ./vkernel -m ${PHYSMEM} -n ${NCPUS} -U -v \
199			-I /var/run/vknet \
200			-e 'boot.netif.ip=${NFS_IP}:boot.netif.netmask=${NFS_NETMASK}:boot.netif.name=vke0:boot.nfsroot.server=${NFS_ROOT_IP}:boot.nfsroot.path=${NFS_ROOT_PATH}'
201
202# Make sure we are not mounted and the VN device is unconfigured,
203#
204# Find an unused VN device but do not do anything with it yet.
205#
206checkq:
207.if !defined(VKDIR)
208	@(echo "must specify VKDIR=target or as an environment variable"; /usr/bin/false)
209.endif
210
211.if exists(${VKDIR})
212	@echo "${VKDIR} found"
213.else
214	mkdir -p ${VKDIR}
215.endif
216
217.if ${FSTYPE} == "hammer"
218NEWFS_CMD = newfs_${FSTYPE}
219NEWFS_ARGS = -L VKROOT -f
220MOUNT_CMD = mount_${FSTYPE}
221ROOTSIZE ?= 5G
222MNTOPTS += -e vfs.root.mountfrom=\'${FSTYPE}:vkd0s1a\'
223.elif ${FSTYPE} == "hammer2"
224NEWFS_CMD = newfs_${FSTYPE}
225NEWFS_ARGS = -f
226MOUNT_CMD = mount_${FSTYPE}
227ROOTSIZE ?= 5G
228MNTOPTS += -e vfs.root.mountfrom=\'${FSTYPE}:vkd0s1a\'
229.elif ${FSTYPE} == "ufs"
230NEWFS_CMD = newfs
231NEWFS_ARGS =
232MOUNT_CMD = mount
233ROOTSIZE ?= 2G
234.else
235	@(echo "\"${FSTYPE}\" is not a valid filesystem"; /usr/bin/false)
236.endif
237.if ${FSTYPE} == "hammer" || ${FSTYPE} == "hammer2"
238.endif
239
240
241check: checkq
242.if exists(${VKDIR}/vn.which)
243	-umount ${VKDIR}/root > /dev/null 2>&1
244	-vnconfig -u `cat ${VKDIR}/vn.which` > /dev/null 2>&1
245	rm -f ${VKDIR}/vn.which
246.endif
247	(vnconfig -l | fgrep "not in use" > /dev/null) || \
248	    (echo "Cannot find unused VN"; /usr/bin/false)
249	vnconfig -l | fgrep "not in use" | \
250	    cut -f 1 -d : | head -1 > ${VKDIR}/vn.which
251	egrep '^vn' ${VKDIR}/vn.which > /dev/null || \
252	    (echo "VN device selection is bad"; /usr/bin/false)
253