build: New makefiles and stdio example
Signed-off-by: Louis Solofrizzo <lsolofrizzo@online.net>
This commit is contained in:
parent
69b2dc41d7
commit
4cf27f5081
8 changed files with 78 additions and 12 deletions
3
unikernel-demo/.gitignore
vendored
Normal file
3
unikernel-demo/.gitignore
vendored
Normal file
|
|
@ -0,0 +1,3 @@
|
|||
*.cmd
|
||||
*.img
|
||||
*.o
|
||||
17
unikernel-demo/Makefile
Normal file
17
unikernel-demo/Makefile
Normal file
|
|
@ -0,0 +1,17 @@
|
|||
all:
|
||||
$(MAKE) -C ../../../whiterose/ UKL=$(CURDIR) bzImage
|
||||
|
||||
../../disk.img:
|
||||
qemu-img create ../../disk.img 0g
|
||||
mkfs.ext2 ../../disk.img
|
||||
mkdir tmp_mnt
|
||||
sudo mount -o loop ../../disk.img tmp_mnt
|
||||
sudo debootstrap --arch amd64 jessie tmp_mnt
|
||||
sudo umount tmp_mnt
|
||||
rmdir tmp_mnt
|
||||
|
||||
qemu: ../../disk.img
|
||||
qemu-system-x86_64 -enable-kvm -s -m 1G -nographic -cpu host\
|
||||
-kernel ../../../whiterose/arch/x86/boot/bzImage\
|
||||
-append "console=ttyS0 ukl quiet root=/dev/sda"\
|
||||
-hda ../../disk.img
|
||||
|
|
@ -2,11 +2,34 @@
|
|||
|
||||
### setup
|
||||
|
||||
##### Requirements
|
||||
- qemu
|
||||
- debootstrap
|
||||
|
||||
##### Clone & Configure the kernel
|
||||
```
|
||||
mkdir unikernel && cd unikernel
|
||||
git clone https://github.com/ne02ptzero/whiterose
|
||||
(cd whiterose && make defconfig)
|
||||
cd whiterose && make defconfig
|
||||
```
|
||||
|
||||
It will apply the default of the linux kernel, with UKL support. If you're
|
||||
trying to run this on exotic hardware, now is a good time to change the
|
||||
configuration. As long as you keep `CONFIG_UKL_LINUX` to `true`, you should be
|
||||
fine.
|
||||
|
||||
##### Clone && Running the examples
|
||||
```
|
||||
git clone https://github.com/jzck/unikernel-demo
|
||||
cd unikernel-demo
|
||||
make && make run
|
||||
```
|
||||
|
||||
Each example come with a Makefile. For example, if you want to run the unistd
|
||||
example, simply do:
|
||||
```
|
||||
make -C fs1/unistd all qemu
|
||||
```
|
||||
|
||||
Or stdio:
|
||||
```
|
||||
make -C fs1/stdio all qemu
|
||||
```
|
||||
|
|
|
|||
|
|
@ -1,9 +0,0 @@
|
|||
export ukl-obj-m := main.o
|
||||
|
||||
all:
|
||||
$(MAKE) -C ../../whiterose/ UKL=$(PWD) bzImage
|
||||
|
||||
qemu:
|
||||
qemu-system-x86_64 -enable-kvm -s -m 1G -nographic -cpu host\
|
||||
-kernel ../whiterose/arch/x86/boot/bzImage\
|
||||
-append "console=ttyS0 ukl quiet"\
|
||||
3
unikernel-demo/fs1/stdio/Makefile
Normal file
3
unikernel-demo/fs1/stdio/Makefile
Normal file
|
|
@ -0,0 +1,3 @@
|
|||
export ukl-obj-m := main.o
|
||||
|
||||
include ../../Makefile
|
||||
26
unikernel-demo/fs1/stdio/main.c
Normal file
26
unikernel-demo/fs1/stdio/main.c
Normal file
|
|
@ -0,0 +1,26 @@
|
|||
#include <stdio.h>
|
||||
|
||||
#include <unistd.h>
|
||||
#include <fcntl.h>
|
||||
|
||||
#ifndef USERSPACE
|
||||
#define main ukl_main
|
||||
#endif
|
||||
|
||||
int main(void) {
|
||||
FILE *f = fopen("/etc/passwd", "r");
|
||||
ssize_t ret;
|
||||
char buf[256] = { 0 };
|
||||
|
||||
if (f == NULL)
|
||||
{
|
||||
fputs("Cannot open /etc/passwd\n", stderr);
|
||||
return 1;
|
||||
}
|
||||
|
||||
while ((ret = fread(buf, 1, sizeof(buf), f)))
|
||||
fwrite(buf, ret, 1, stdout);
|
||||
|
||||
fclose(f);
|
||||
return 0;
|
||||
}
|
||||
3
unikernel-demo/fs1/unistd/Makefile
Normal file
3
unikernel-demo/fs1/unistd/Makefile
Normal file
|
|
@ -0,0 +1,3 @@
|
|||
export ukl-obj-m := main.o
|
||||
|
||||
include ../../Makefile
|
||||
Loading…
Reference in a new issue