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