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