Check-in [a39441abc1]
Overview
Comment:Added basic QEMU demo
Downloads: Tarball | ZIP archive | SQL archive
Timelines: family | ancestors | descendants | both | trunk
Files: files | file ages | folders
SHA1: a39441abc19eb535757a264e91fd203e556b38e2
User & Date: rkeene on 2020-06-28 02:42:32
Original User & Date: roykeene on 2020-06-28 02:42:32
Other Links: manifest | tags
Context
2020-06-28
02:49
Added QEMU ignores check-in: 789651b077 user: rkeene tags: trunk
02:42
Added basic QEMU demo check-in: a39441abc1 user: rkeene tags: trunk
2020-05-15
01:25
Use an environment variable to control debug logging at runtime check-in: 2374e0de64 user: rkeene tags: trunk
Changes

Added build/qemu/assemble version [78cb3ad311].









































































































>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
#! /usr/bin/env bash

set -e

# Not included:
#  1. Downloading huge.s from Slackware64 kernels (into boot/)
#  2. Downloading kernel modules package from Slackware64 (into root/)
#  3. Downloading a static Tclkit with TUAPI
#  4. Downloading a static AppFS

make init LDFLAGS=-static
cp init root/bin

rm -f appfs.img
truncate --size 512M appfs.img
sfdisk --no-tell-kernel --no-reread ./appfs.img <<<'label: dos
size=16M type=83 bootable
type=83'

sudo umount x-boot || :
sudo losetup -d /dev/loop3 || :
sudo losetup --partscan /dev/loop3 $(pwd)/appfs.img
sudo chown "$(id -u):$(id -g)" /dev/loop3 /dev/loop3p1 /dev/loop3p2

sudo mke2fs \
  -L 'BOOT' \
  -N 0 \
  -O ^64bit \
  -d boot \
  -m 5 \
  -r 1 \
  -t ext2 \
  /dev/loop3p1

sudo mke2fs \
  -L 'ROOT' \
  -N 0 \
  -O ^64bit \
  -d root \
  -m 5 \
  -r 1 \
  -t ext2 \
  /dev/loop3p2

mkdir x-boot || :
sudo mount /dev/loop3p1 x-boot
sudo extlinux --install $(pwd)/x-boot
sudo umount x-boot
dd if=/usr/lib/EXTLINUX/mbr.bin of=appfs.img conv=notrunc
rmdir x-boot

losetup -d /dev/loop3

Added build/qemu/boot/extlinux.conf version [16eb016414].













>
>
>
>
>
>
1
2
3
4
5
6
DEFAULT appfs
SERIAL 0 9600 0x003

LABEL appfs
	KERNEL vmlinuz
	APPEND root=/dev/vda2 console=tty0 console=ttyS0 consoleblank=0 loglevel=8

Added build/qemu/init.c version [67d154f314].







































































































































































































>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
#include <sys/types.h>
#include <sys/mount.h>
#include <sys/stat.h>
#include <sys/wait.h>
#include <unistd.h>
#include <stdlib.h>
#include <stdarg.h>
#include <stdio.h>

int run(const char *path, ...) {
	va_list ap;
	char **argv;
	int argvMax, argvIdx;
	pid_t pid;
	int pidstat;

	pid = fork();
	if (pid == ((pid_t) -1)) {
		return(-1);
	}
	
	if (pid != 0) {
		waitpid(pid, &pidstat, 0);

		return(pidstat);
	}

	argvMax = 32;
	argv = malloc(sizeof(*argv) * argvMax);

	va_start(ap, path);

	for (argvIdx = 0; argvIdx < argvMax; argvIdx++) {
		argv[argvIdx] = va_arg(ap, char *);
		if (argv[argvIdx] == NULL) {
			break;
		}
	}
	
	va_end(ap);

	execv(path, argv);

	exit(EXIT_FAILURE);
}

int main(int argc, char **argv) {
	/*
	 * Remount root filesystem read-write
	 */
	mount("/dev/vda2", "/", "ext2", MS_REMOUNT, NULL);

	/*
	 * Mount needed filesystems
	 */
	mkdir("/dev", 0755);
	mount("devtmpfs", "/dev", "devtmpfs", 0, NULL);

	mkdir("/tmp", 0755);
	mount("tmpfs", "/tmp", "tmpfs", 0, NULL);

	mkdir("/proc", 0755);
	mount("proc", "/proc", "proc", 0, NULL);

	mkdir("/sys", 0755);
	mount("sysfs", "/sys", "sysfs", 0, NULL);

	/*
	 * Setup networking
	 */
	run("/bin/init-networking", "init-networking", NULL);
	run("/bin/init-fuse", "init-fuse", NULL);

	mkdir("/bin", 0755);
	mkdir("/lib", 0755);
	mkdir("/opt", 0755);
	mkdir("/opt/appfs", 0755);
	mkdir("/var", 0755);
	mkdir("/var/cache", 0755);
	mkdir("/var/cache/appfs", 0755);
	run("/bin/appfsd", "appfsd", "/var/cache/appfs", "/opt/appfs", NULL);

	symlink(".", "/usr");
	symlink("lib", "/lib64");

	symlink("/opt/appfs/core.appfs.rkeene.org/bash/platform/latest/bin/bash", "/bin/bash");
	symlink("/opt/appfs/core.appfs.rkeene.org/coreutils/platform/latest/bin/env", "/bin/env");

	symlink("/bin/bash", "/bin/sh");

	setenv("PATH", "/bin:/opt/appfs/core.appfs.rkeene.org/coreutils/platform/latest/bin", 1);
	run("/bin/appfs-cache", "appfs-cache", "install", "-lib", "core.appfs.rkeene.org", "glibc", NULL);
	run("/bin/appfs-cache", "appfs-cache", "install", "core.appfs.rkeene.org", "coreutils", NULL);
	setenv("PATH", "/bin", 1);

	run("/bin/sh", "sh", NULL);

	return(0);
}

Added build/qemu/root/bin/init-fuse version [3ac2dd4f3a].











>
>
>
>
>
1
2
3
4
5
#! /bin/tclkit

package require tuapi

::tuapi::modprobe fuse

Added build/qemu/root/bin/init-networking version [be0f1f2714].



























>
>
>
>
>
>
>
>
>
>
>
>
>
1
2
3
4
5
6
7
8
9
10
11
12
13
#! /bin/tclkit

package require tuapi

::tuapi::scan_and_load_kernel_modules

::tuapi::ifconfig eth0 address 10.0.2.15 netmask 255.255.255.0 flags {BROADCAST MULTICAST UP}
::tuapi::syscall::route add 0.0.0.0 0.0.0.0 gateway 10.0.2.2 dev eth0

file mkdir /etc   
set fd [open /etc/resolv.conf w]
puts $fd "nameserver 10.0.2.3"
close $fd

Added build/qemu/run version [4b861ef3b6].

















>
>
>
>
>
>
>
>
1
2
3
4
5
6
7
8
#! /usr/bin/env bash

sudo chown $(id -u) /dev/kvm
qemu-system-x86_64  \
	-display none -vga none -serial stdio \
	-m 2048 -enable-kvm -cpu host -smp 2 \
	-net nic -net user \
	-drive file=appfs.img,if=virtio,cache=unsafe