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