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