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  +#! /usr/bin/env bash
            2  +
            3  +set -e
            4  +
            5  +# Not included:
            6  +#  1. Downloading huge.s from Slackware64 kernels (into boot/)
            7  +#  2. Downloading kernel modules package from Slackware64 (into root/)
            8  +#  3. Downloading a static Tclkit with TUAPI
            9  +#  4. Downloading a static AppFS
           10  +
           11  +make init LDFLAGS=-static
           12  +cp init root/bin
           13  +
           14  +rm -f appfs.img
           15  +truncate --size 512M appfs.img
           16  +sfdisk --no-tell-kernel --no-reread ./appfs.img <<<'label: dos
           17  +size=16M type=83 bootable
           18  +type=83'
           19  +
           20  +sudo umount x-boot || :
           21  +sudo losetup -d /dev/loop3 || :
           22  +sudo losetup --partscan /dev/loop3 $(pwd)/appfs.img
           23  +sudo chown "$(id -u):$(id -g)" /dev/loop3 /dev/loop3p1 /dev/loop3p2
           24  +
           25  +sudo mke2fs \
           26  +  -L 'BOOT' \
           27  +  -N 0 \
           28  +  -O ^64bit \
           29  +  -d boot \
           30  +  -m 5 \
           31  +  -r 1 \
           32  +  -t ext2 \
           33  +  /dev/loop3p1
           34  +
           35  +sudo mke2fs \
           36  +  -L 'ROOT' \
           37  +  -N 0 \
           38  +  -O ^64bit \
           39  +  -d root \
           40  +  -m 5 \
           41  +  -r 1 \
           42  +  -t ext2 \
           43  +  /dev/loop3p2
           44  +
           45  +mkdir x-boot || :
           46  +sudo mount /dev/loop3p1 x-boot
           47  +sudo extlinux --install $(pwd)/x-boot
           48  +sudo umount x-boot
           49  +dd if=/usr/lib/EXTLINUX/mbr.bin of=appfs.img conv=notrunc
           50  +rmdir x-boot
           51  +
           52  +losetup -d /dev/loop3

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

            1  +DEFAULT appfs
            2  +SERIAL 0 9600 0x003
            3  +
            4  +LABEL appfs
            5  +	KERNEL vmlinuz
            6  +	APPEND root=/dev/vda2 console=tty0 console=ttyS0 consoleblank=0 loglevel=8

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

            1  +#include <sys/types.h>
            2  +#include <sys/mount.h>
            3  +#include <sys/stat.h>
            4  +#include <sys/wait.h>
            5  +#include <unistd.h>
            6  +#include <stdlib.h>
            7  +#include <stdarg.h>
            8  +#include <stdio.h>
            9  +
           10  +int run(const char *path, ...) {
           11  +	va_list ap;
           12  +	char **argv;
           13  +	int argvMax, argvIdx;
           14  +	pid_t pid;
           15  +	int pidstat;
           16  +
           17  +	pid = fork();
           18  +	if (pid == ((pid_t) -1)) {
           19  +		return(-1);
           20  +	}
           21  +	
           22  +	if (pid != 0) {
           23  +		waitpid(pid, &pidstat, 0);
           24  +
           25  +		return(pidstat);
           26  +	}
           27  +
           28  +	argvMax = 32;
           29  +	argv = malloc(sizeof(*argv) * argvMax);
           30  +
           31  +	va_start(ap, path);
           32  +
           33  +	for (argvIdx = 0; argvIdx < argvMax; argvIdx++) {
           34  +		argv[argvIdx] = va_arg(ap, char *);
           35  +		if (argv[argvIdx] == NULL) {
           36  +			break;
           37  +		}
           38  +	}
           39  +	
           40  +	va_end(ap);
           41  +
           42  +	execv(path, argv);
           43  +
           44  +	exit(EXIT_FAILURE);
           45  +}
           46  +
           47  +int main(int argc, char **argv) {
           48  +	/*
           49  +	 * Remount root filesystem read-write
           50  +	 */
           51  +	mount("/dev/vda2", "/", "ext2", MS_REMOUNT, NULL);
           52  +
           53  +	/*
           54  +	 * Mount needed filesystems
           55  +	 */
           56  +	mkdir("/dev", 0755);
           57  +	mount("devtmpfs", "/dev", "devtmpfs", 0, NULL);
           58  +
           59  +	mkdir("/tmp", 0755);
           60  +	mount("tmpfs", "/tmp", "tmpfs", 0, NULL);
           61  +
           62  +	mkdir("/proc", 0755);
           63  +	mount("proc", "/proc", "proc", 0, NULL);
           64  +
           65  +	mkdir("/sys", 0755);
           66  +	mount("sysfs", "/sys", "sysfs", 0, NULL);
           67  +
           68  +	/*
           69  +	 * Setup networking
           70  +	 */
           71  +	run("/bin/init-networking", "init-networking", NULL);
           72  +	run("/bin/init-fuse", "init-fuse", NULL);
           73  +
           74  +	mkdir("/bin", 0755);
           75  +	mkdir("/lib", 0755);
           76  +	mkdir("/opt", 0755);
           77  +	mkdir("/opt/appfs", 0755);
           78  +	mkdir("/var", 0755);
           79  +	mkdir("/var/cache", 0755);
           80  +	mkdir("/var/cache/appfs", 0755);
           81  +	run("/bin/appfsd", "appfsd", "/var/cache/appfs", "/opt/appfs", NULL);
           82  +
           83  +	symlink(".", "/usr");
           84  +	symlink("lib", "/lib64");
           85  +
           86  +	symlink("/opt/appfs/core.appfs.rkeene.org/bash/platform/latest/bin/bash", "/bin/bash");
           87  +	symlink("/opt/appfs/core.appfs.rkeene.org/coreutils/platform/latest/bin/env", "/bin/env");
           88  +
           89  +	symlink("/bin/bash", "/bin/sh");
           90  +
           91  +	setenv("PATH", "/bin:/opt/appfs/core.appfs.rkeene.org/coreutils/platform/latest/bin", 1);
           92  +	run("/bin/appfs-cache", "appfs-cache", "install", "-lib", "core.appfs.rkeene.org", "glibc", NULL);
           93  +	run("/bin/appfs-cache", "appfs-cache", "install", "core.appfs.rkeene.org", "coreutils", NULL);
           94  +	setenv("PATH", "/bin", 1);
           95  +
           96  +	run("/bin/sh", "sh", NULL);
           97  +
           98  +	return(0);
           99  +}

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

            1  +#! /bin/tclkit
            2  +
            3  +package require tuapi
            4  +
            5  +::tuapi::modprobe fuse

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

            1  +#! /bin/tclkit
            2  +
            3  +package require tuapi
            4  +
            5  +::tuapi::scan_and_load_kernel_modules
            6  +
            7  +::tuapi::ifconfig eth0 address 10.0.2.15 netmask 255.255.255.0 flags {BROADCAST MULTICAST UP}
            8  +::tuapi::syscall::route add 0.0.0.0 0.0.0.0 gateway 10.0.2.2 dev eth0
            9  +
           10  +file mkdir /etc   
           11  +set fd [open /etc/resolv.conf w]
           12  +puts $fd "nameserver 10.0.2.3"
           13  +close $fd

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

            1  +#! /usr/bin/env bash
            2  +
            3  +sudo chown $(id -u) /dev/kvm
            4  +qemu-system-x86_64  \
            5  +	-display none -vga none -serial stdio \
            6  +	-m 2048 -enable-kvm -cpu host -smp 2 \
            7  +	-net nic -net user \
            8  +	-drive file=appfs.img,if=virtio,cache=unsafe