Skip to content

Commit

Permalink
elfloader-net: Add scripts
Browse files Browse the repository at this point in the history
Use scripts as quick actions for building and running the Unikraft ELF
Loader.

- `defconfig.<plat>.<arch>`: default configs, used by build scripts
- `build.<plat>.<arch>`: scripts for building Unikraft images
- `run.<plat>.<arch>`: scripts for running Unikraft images
- `README.scripts.md`: companion README with instructions

Signed-off-by: Razvan Deaconescu <[email protected]>
  • Loading branch information
razvand committed Nov 29, 2024
1 parent 0a04055 commit a7f08ee
Show file tree
Hide file tree
Showing 7 changed files with 194 additions and 0 deletions.
34 changes: 34 additions & 0 deletions elfloader-net/README.scripts.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,34 @@
# Scripts for the Unikraft ELF Loader with Networking Support

These are companions instruction to the main instructions in the [`README`](README.md).

Use scripts as quick actions for building and running the Unikraft ELF Loader:

## Build for platform of choice

```console
./build.qemu.x86_64
./build.fc.x86_64
```

## Build for platform of choice using a different compiler

```console
CC=/path/to/compiler ./build.<plat>.x86_64
```

e.g.

```console
CC=/usr/bin/gcc-12 ./build.qemu.x86_64
CC=/usr/bin/clang ./build.qemu.x86_64
CC=/usr/bin/gcc-12 ./build.fc.x86_64
CC=/usr/bin/clang ./build.fc.x86_64
```

## Run on platform of choice

```console
./run.qemu.x86_64
./run.fc.x86_64
```
16 changes: 16 additions & 0 deletions elfloader-net/build.fc.x86_64
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
#!/bin/sh

test -d "../repos/unikraft" || git clone https://github.com/unikraft/unikraft ../repos/unikraft
test -d "../repos/apps/elfloader" || git clone https://github.com/unikraft/app-elfloader ../repos/apps/elfloader
test -d "../repos/libs/libelf" || git clone https://github.com/unikraft/lib-libelf ../repos/libs/libelf
test -d "../repos/libs/lwip" || git clone https://github.com/unikraft/lib-lwip ../repos/libs/lwip

make distclean
UK_DEFCONFIG=$(pwd)/defconfig.fc.x86_64 make defconfig
touch Makefile.uk
make prepare
if test -z "$CC"; then
make -j $(nproc)
else
make CC="$CC" -j $(nproc)
fi
16 changes: 16 additions & 0 deletions elfloader-net/build.qemu.x86_64
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
#!/bin/sh

test -d "../repos/unikraft" || git clone https://github.com/unikraft/unikraft ../repos/unikraft
test -d "../repos/apps/elfloader" || git clone https://github.com/unikraft/app-elfloader ../repos/apps/elfloader
test -d "../repos/libs/libelf" || git clone https://github.com/unikraft/lib-libelf ../repos/libs/libelf
test -d "../repos/libs/lwip" || git clone https://github.com/unikraft/lib-lwip ../repos/libs/lwip

make distclean
UK_DEFCONFIG=$(pwd)/defconfig.qemu.x86_64 make defconfig
touch Makefile.uk
make prepare
if test -z "$CC"; then
make -j $(nproc)
else
make CC="$CC" -j $(nproc)
fi
29 changes: 29 additions & 0 deletions elfloader-net/defconfig.fc.x86_64
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
CONFIG_PLAT_KVM=y
CONFIG_KVM_VMM_FIRECRACKER=y
CONFIG_ARCH_X86_64=y
CONFIG_APPELFLOADER_DEPENDENCIES=y
CONFIG_APPELFLOADER_ARCH_PRCTL=y
CONFIG_APPELFLOADER_BRK=y
CONFIG_APPELFLOADER_CUSTOMAPPNAME=y
CONFIG_APPELFLOADER_STACK_NBPAGES=128
CONFIG_APPELFLOADER_VFSEXEC_EXECBIT=n
CONFIG_APPELFLOADER_VFSEXEC=y
CONFIG_APPELFLOADER_HFS=y
CONFIG_APPELFLOADER_HFS_ETCRESOLVCONF=y
CONFIG_APPELFLOADER_HFS_ETCHOSTS=y
CONFIG_APPELFLOADER_HFS_ETCHOSTNAME=y
CONFIG_APPELFLOADER_HFS_REPLACEEXIST=y
CONFIG_LIBVFSCORE=y
CONFIG_LIBVFSCORE_AUTOMOUNT_UP=y
CONFIG_LIBRAMFS=y
CONFIG_LIBUKCPIO=y
CONFIG_LIBDEVFS=y
CONFIG_LIBDEVFS_AUTOMOUNT=y
# Networking support
CONFIG_LIBLWIP=y
CONFIG_LIBUKNETDEV_EINFO_LIBPARAM=y
# Uncomment for debugging.
#CONFIG_LIBUKDEBUG_PRINTD=y
#CONFIG_LIBUKDEBUG_PRINTK_INFO=y
#CONFIG_LIBSYSCALL_SHIM_STRACE=y
#CONFIG_LIBSYSCALL_SHIM_DEBUG=y
29 changes: 29 additions & 0 deletions elfloader-net/defconfig.qemu.x86_64
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
CONFIG_PLAT_KVM=y
CONFIG_KVM_VMM_QEMU=y
CONFIG_ARCH_X86_64=y
CONFIG_APPELFLOADER_DEPENDENCIES=y
CONFIG_APPELFLOADER_ARCH_PRCTL=y
CONFIG_APPELFLOADER_BRK=y
CONFIG_APPELFLOADER_CUSTOMAPPNAME=y
CONFIG_APPELFLOADER_STACK_NBPAGES=128
CONFIG_APPELFLOADER_VFSEXEC_EXECBIT=n
CONFIG_APPELFLOADER_VFSEXEC=y
CONFIG_APPELFLOADER_HFS=y
CONFIG_APPELFLOADER_HFS_ETCRESOLVCONF=y
CONFIG_APPELFLOADER_HFS_ETCHOSTS=y
CONFIG_APPELFLOADER_HFS_ETCHOSTNAME=y
CONFIG_APPELFLOADER_HFS_REPLACEEXIST=y
CONFIG_LIBVFSCORE=y
CONFIG_LIBVFSCORE_AUTOMOUNT_UP=y
CONFIG_LIBRAMFS=y
CONFIG_LIBUKCPIO=y
CONFIG_LIBDEVFS=y
CONFIG_LIBDEVFS_AUTOMOUNT=y
# Networking support
CONFIG_LIBLWIP=y
CONFIG_LIBUKNETDEV_EINFO_LIBPARAM=y
# Uncomment for debugging.
#CONFIG_LIBUKDEBUG_PRINTD=y
#CONFIG_LIBUKDEBUG_PRINTK_INFO=y
#CONFIG_LIBSYSCALL_SHIM_STRACE=y
#CONFIG_LIBSYSCALL_SHIM_DEBUG=y
34 changes: 34 additions & 0 deletions elfloader-net/run.fc.x86_64
Original file line number Diff line number Diff line change
@@ -0,0 +1,34 @@
#!/bin/sh

if test ! -f "out/elfloader_fc-x86_64"; then
echo "No kernel file out/elfloader_fc-x86_64." 1>&2
echo "Did you run ./build.fc.x86_64 ?" 1>&2
exit 1
fi

{
# Remove previously created network interfaces.
sudo ip link set dev virbr0 down
sudo ip link del dev virbr0
sudo ip link set dev tap0 down
sudo ip link del dev tap0
} > /dev/null 2>&1

# Create tap interface for Firecracker networking.
sudo ip tuntap add dev tap0 mode tap
sudo ip address add 172.44.0.1/24 dev tap0
sudo ip link set dev tap0 up

# Build ELFs.
make -C rootfs/

# Pack filesystem as an initial ramdisk CPIO file.
rm -f initrd.cpio
../repos/unikraft/support/scripts/mkcpio initrd.cpio ./rootfs/

# Remove previously created files.
rm -f firecracker.socket

firecracker-x86_64 \
--api-sock firecracker.socket \
--config-file fc.x86_64.json
36 changes: 36 additions & 0 deletions elfloader-net/run.qemu.x86_64
Original file line number Diff line number Diff line change
@@ -0,0 +1,36 @@
#!/bin/sh

if test ! -f "out/elfloader_qemu-x86_64"; then
echo "No kernel file out/elfloader_qemu-x86_64." 1>&2
echo "Did you run ./build.qemu.x86_64 ?" 1>&2
exit 1
fi

{
# Remove previously created network interface.
sudo ip link set dev virbr0 down
sudo ip link del dev virbr0
sudo ip link set dev tap0 down
sudo ip link del dev tap0
} > /dev/null 2>&1

# Create bridge interface for QEMU networking.
sudo ip link add dev virbr0 type bridge
sudo ip address add 172.44.0.1/24 dev virbr0
sudo ip link set dev virbr0 up

# Build ELFs.
make -C rootfs/

# Pack filesystem as an initial ramdisk CPIO file.
rm -f initrd.cpio
../repos/unikraft/support/scripts/mkcpio initrd.cpio ./rootfs/

sudo qemu-system-x86_64 \
-nographic \
-m 64 \
-cpu max \
-netdev bridge,id=en0,br=virbr0 -device virtio-net-pci,netdev=en0 \
-append "elfloader_qemu-x86_64 netdev.ip=172.44.0.2/24:172.44.0.1::: vfs.fstab=[ \"initrd0:/:extract::ramfs=1:\" ] -- /c-server" \
-kernel out/elfloader_qemu-x86_64 \
-initrd ./initrd.cpio

0 comments on commit a7f08ee

Please sign in to comment.