xref: /dragonfly/test/vkernel/Makefile (revision b4f25088)
1# Makefile - set up a vkernel environment for testing the vkernel
2#
3
4# require it to be specified
5SRCDIR ?= ${.CURDIR}/../..
6ROOTSIZE ?= 2048M
7PHYSMEM ?= 256m
8NCPUS ?= 2
9
10all: help
11
12.if ${MACHINE_ARCH} == "i386"
13USEKERNEL=VKERNEL
14.else
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 ""
36	@echo "Meta target components:"
37	@echo ""
38	@echo "    help     - this help"
39	@echo "    clean    - clean up"
40	@echo "    scratch  - build and install everything from scratch"
41	@echo "               (this is absolutely everything)"
42	@echo "    quick    - incremental kernel build & reinstall"
43	@echo "    quickw   - incremental world & kernel build & reinstall"
44	@echo "    run      - run vkernel with VKDIR/root.img"
45	@echo "    mount    - mount VKDIR/root.img at VKDIR/root"
46	@echo "    umount   - unmount"
47	@echo ""
48	@echo "Individual target components:"
49	@echo ""
50	@echo "    world             - build the world from scratch"
51	@echo "    root              - create a new, empty root.img"
52	@echo "    install           - install a world & kernel"
53	@echo "                        into root.img"
54	@echo "    leaf		     - additional customizatio"
55	@echo "    kernel   	     - build vkernel"
56	@echo "    quickworld        - incremental rebuild world"
57	@echo "    quickkernel       - incremental rebuild kernel"
58	@echo "    reinstall         - reinstall world into root.img"
59	@echo "                        (just the installworld piece)"
60	@echo "    reinstallkernel   - reinstall kernel into root.img"
61	@echo ""
62
63# Unmount everything, de-configured VN, and clean up.
64# (check handles umounting/deconfiguring)
65#
66clean: check
67	rm -rf ${VKDIR}/root.img ${VKDIR}/root
68
69# Build the world and kernel
70#
71#
72world: checkq
73	cd ${SRCDIR} && make -j 4 buildworld
74
75kernel: checkq
76	cd ${SRCDIR} && make -j 4 KERNCONF=${USEKERNEL} buildkernel
77
78# Quick build - just rebuild the kernel quickly
79#
80#
81quickworld: checkq
82	cd ${SRCDIR} && make -j 4 quickworld
83
84quickkernel: checkq
85	cd ${SRCDIR} && make KERNCONF=${USEKERNEL} quickkernel
86
87# Build and mount an empty filesystem for the emulated root disk
88#
89# NOTE: root must umount when done because a later dependency may
90#       have a dependency on mount.
91#
92root:	check
93	vnconfig -c -T -S ${ROOTSIZE} -s labels \
94	    `cat ${VKDIR}/vn.which` ${VKDIR}/root.img
95	dd if=/dev/zero of=/dev/`cat ${VKDIR}/vn.which` bs=32k count=4
96	fdisk -IB `cat ${VKDIR}/vn.which`
97	disklabel -r -w `cat ${VKDIR}/vn.which`s1 auto
98	disklabel `cat ${VKDIR}/vn.which`s1 > ${VKDIR}/label.tmp
99	echo 'a: * 0 4.2BSD' >> ${VKDIR}/label.tmp
100	disklabel -R `cat ${VKDIR}/vn.which`s1 ${VKDIR}/label.tmp
101	disklabel -B `cat ${VKDIR}/vn.which`s1
102	newfs /dev/`cat ${VKDIR}/vn.which`s1a
103	mkdir -p ${VKDIR}/root
104	vnconfig -u `cat ${VKDIR}/vn.which` > /dev/null 2>&1
105
106mount: check
107	vnconfig -c -s labels `cat ${VKDIR}/vn.which` ${VKDIR}/root.img
108	fsck -p /dev/`cat ${VKDIR}/vn.which`s1a
109	mount /dev/`cat ${VKDIR}/vn.which`s1a ${VKDIR}/root
110	@echo "Mounted ${VKDIR}/root"
111
112umount: check
113
114# Install a fresh world & distribution, and kernel
115#
116install: mount
117	cd ${SRCDIR} && \
118	    make -j 4 DESTDIR=${VKDIR}/root installworld
119	cd ${SRCDIR}/etc && \
120	    make -j 4 DESTDIR=${VKDIR}/root distribution
121	echo '/dev/vkd0s1a	/	ufs	rw	1 1' > ${VKDIR}/root/etc/fstab
122	echo 'proc		/proc	procfs	rw	0 0' >> ${VKDIR}/root/etc/fstab
123	echo 'vfs.root.mountfrom="ufs:vkd0s1a"' > ${VKDIR}/root/boot/loader.conf
124	#(egrep -v '^console' ${VKDIR}/root/etc/ttys; echo 'console "/usr/libexec/getty Pc"	cons25	on	secure') > ${VKDIR}/root/etc/ttys.new
125	#mv -f ${VKDIR}/root/etc/ttys.new ${VKDIR}/root/etc/ttys
126	cd ${SRCDIR} && \
127	    make -j 4 \
128		 DESTDIR=${VKDIR}/root KERNCONF=${USEKERNEL} \
129		 NO_MODULES= \
130		 installkernel
131	cp ${VKDIR}/root/boot/kernel/kernel ${VKDIR}/vkernel
132
133leaf: mount
134	echo 'ifconfig_vke0="up"' > ${VKDIR}/root/etc/rc.conf
135	echo 'defaultrouter="10.26.0.1"' >> ${VKDIR}/root/etc/rc.conf
136
137# Quick reinstall - just install a new kernel on top of an existing image
138#
139#
140reinstall: mount
141	cd ${SRCDIR} && make -j 4 DESTDIR=${VKDIR}/root installworld
142
143reinstallkernel: mount
144	cd ${SRCDIR} && \
145	    make -j 4 DESTDIR=${VKDIR}/root KERNCONF=${USEKERNEL} \
146		 NO_MODULES= installkernel
147	cp ${VKDIR}/root/boot/kernel/kernel ${VKDIR}/vkernel
148
149sysloader: mount
150	cp /boot/loader ${VKDIR}/root/boot/loader
151	sync
152
153# Run the vkernel on our image.  Make sure we are unmounted so
154# we do not compete against the emulated kernel when writing to root.img.
155# (check does this for us)
156#
157run: check
158	mkdir -p /var/vkernel
159	sysctl vm.vkernel_enable=1
160	cd ${VKDIR} && ./vkernel -m ${PHYSMEM} -n ${NCPUS} \
161			-r root.img -U -v \
162			-I /var/run/vknet
163
164# When running w/ a NFS root
165#
166NFS_IP?= 10.0.0.53
167NFS_NETMASK?= 255.255.255.0
168NFS_ROOT_IP?= 10.0.0.1
169NFS_ROOT_PATH?= /netboot2
170
171run_nfsroot: check
172	cd ${VKDIR} && ./vkernel -m ${PHYSMEM} -n ${NCPUS} -U -v \
173			-I /var/run/vknet \
174			-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}'
175
176# Make sure we are not mounted and the VN device is unconfigured,
177#
178# Find an unused VN device but do not do anything with it yet.
179#
180checkq:
181.if !defined(VKDIR)
182	@(echo "must specify VKDIR=target or as an environment variable"; /usr/bin/false)
183.endif
184.if exists(${VKDIR})
185	@echo "${VKDIR} found"
186.else
187	mkdir -p ${VKDIR}
188.endif
189
190check: checkq
191.if exists(${VKDIR}/vn.which)
192	-umount ${VKDIR}/root > /dev/null 2>&1
193	-vnconfig -u `cat ${VKDIR}/vn.which` > /dev/null 2>&1
194	rm -f ${VKDIR}/vn.which
195.endif
196	(vnconfig -l | fgrep "not in use" > /dev/null) || \
197	    (echo "Cannot find unused VN"; /usr/bin/false)
198	vnconfig -l | fgrep "not in use" | \
199	    cut -f 1 -d : | head -1 > ${VKDIR}/vn.which
200	egrep '^vn' ${VKDIR}/vn.which > /dev/null || \
201	    (echo "VN device selection is bad"; /usr/bin/false)
202