• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1#!/bin/bash
2# The following is a synthesis of info in:
3#
4#  http://vmsplice.net/~stefan/stefanha-kernel-recipes-2015.pdf
5#  http://git.kernel.org/cgit/linux/kernel/git/torvalds/linux.git/tree/README
6#
7KBASE=../../linux
8#APPEND="console=ttyS0"
9
10function die {
11    echo "$*"
12    exit 1
13}
14
15pushd ..
16make test || die "failed to make test of libcap tree"
17make -C progs tcapsh-static || die "failed to make progs/tcapsh-static"
18popd
19
20# Assumes desired make *config (eg. make defconfig) is already done.
21pushd $KBASE
22pwd
23make V=1 all || die "failed to build kernel: $0"
24popd
25
26HERE=$(/bin/pwd)
27
28cat > fs.conf <<EOF
29file /init test-init.sh 0755 0 0
30dir /etc 0755 0 0
31file /etc/passwd test-passwd 0444 0 0
32dir /lib 0755 0 0
33dir /proc 0755 0 0
34dir /dev 0755 0 0
35dir /sys 0755 0 0
36dir /sbin 0755 0 0
37file /sbin/busybox /usr/sbin/busybox 0755 0 0
38dir /bin 0755 0 0
39file /bin/myprompt test-prompt.sh 0755 0 0
40file /bin/bash test-bash.sh 0755 0 0
41dir /usr 0755 0 0
42dir /usr/bin 0755 0 0
43dir /root 0755 0 0
44file /root/quicktest.sh $HERE/../progs/quicktest.sh 0755 0 0
45file /root/setcap $HERE/../progs/setcap 0755 0 0
46file /root/getcap $HERE/../progs/getcap 0755 0 0
47file /root/capsh $HERE/../progs/capsh 0755 0 0
48file /root/getpcaps $HERE/../progs/getpcaps 0755 0 0
49file /root/tcapsh-static $HERE/../progs/tcapsh-static 0755 0 0
50file /root/exit $HERE/exit 0755 0 0
51file /root/uns_test $HERE/../tests/uns_test 0755 0 0
52EOF
53
54# convenience for some local experiments
55if [ -f "$HERE/extras.sh" ]; then
56    echo "local, uncommitted enhancements to kernel test"
57    . "$HERE/extras.sh"
58fi
59
60if [ -f "$HERE/interactive" ]; then
61    echo "file /root/interactive $HERE/interactive 0755 0 0" >> fs.conf
62fi
63
64COMMANDS="awk cat chmod cp dmesg fgrep id less ln ls mkdir mount pwd rm rmdir sh sort umount uniq vi"
65for f in $COMMANDS; do
66    echo slink /bin/$f /sbin/busybox 0755 0 0 >> fs.conf
67done
68
69UCOMMANDS="id cut"
70for f in $UCOMMANDS; do
71    echo slink /usr/bin/$f /sbin/busybox 0755 0 0 >> fs.conf
72done
73
74$KBASE/usr/gen_init_cpio fs.conf | gzip -9 > initramfs.img
75
76KERNEL=$KBASE/arch/$(uname -m)/boot/bzImage
77
78qemu-system-$(uname -m) -m 1024 \
79		   -kernel $KERNEL \
80		   -initrd initramfs.img \
81		   -append "$APPEND" \
82		   -smp sockets=2,dies=1,cores=4 \
83		   -device isa-debug-exit
84