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