Skip to content

Commit 52a3730

Browse files
committed
tools: add image gen, dev and running utilities
1 parent 05d1872 commit 52a3730

File tree

9 files changed

+133
-0
lines changed

9 files changed

+133
-0
lines changed

tools/create-image.sh

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
#!/bin/sh
2+
3+
FILE="${2:-_disk_image.raw}"
4+
qemu-img create $FILE $1
5+
mke2fs -b 2048 -I 512 -t ext2 $FILE

tools/gen_compile_commands.py

Lines changed: 46 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,46 @@
1+
#!/bin/python3
2+
3+
import sys
4+
import os
5+
import pathlib
6+
import shlex
7+
import json
8+
from dataclasses import dataclass
9+
from typing import Optional
10+
COMPILERS=['gcc', 'clang', 'clang++', 'g++', 'as']
11+
SOURCE_FILE_EXTENSIONS=['.s', '.S', '.c', '.cc']
12+
IGNORED_OPTIONS=['-f no-leading-underscore', '-fno-leading-underscore']
13+
14+
@dataclass
15+
class CompileCommand:
16+
input_file: str
17+
args: list[str]
18+
output_file: Optional[str] = None
19+
20+
commands: list[CompileCommand] = []
21+
22+
for line in sys.stdin.readlines():
23+
command_args = shlex.split(line)
24+
if not any ([command_args[0].endswith(c) for c in COMPILERS]):
25+
continue
26+
27+
filtered_args = []
28+
for i, v in enumerate(command_args):
29+
cv = v + ' ' + command_args[i+1] if i+1 < len(command_args) else None
30+
if v in IGNORED_OPTIONS or (cv is not None and cv in IGNORED_OPTIONS):
31+
continue
32+
filtered_args.append(v)
33+
34+
files = []
35+
for i, arg in enumerate(command_args[1:]):
36+
if arg.startswith("-") or not any([arg.endswith(v) for v in SOURCE_FILE_EXTENSIONS]):
37+
continue
38+
39+
files.append(arg)
40+
41+
for v in files:
42+
commands.append(CompileCommand(input_file=os.path.abspath(v), args=filtered_args))
43+
44+
45+
print(json.dumps([{ 'file': c.input_file, 'directory': os.getcwd(), 'arguments': c.args } for c in commands]), end="")
46+

tools/iso.sh

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
#!/bin/bash
2+
3+
4+
ROOTDIR=`git rev-parse --show-toplevel`
5+
# ${TOOLS_BASEDIR:-.}/tools/make.sh iso
6+
$ROOTDIR/tools/make.sh iso
7+
grub-mkrescue $ROOTDIR/iso/ -o $ROOTDIR/depthos.iso

tools/mount.sh

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
#!/bin/sh
2+
3+
MOUNTDIR=_mnt
4+
5+
if [ "$1" = -u ]; then
6+
umount $MOUNTDIR
7+
else
8+
mount -t ext2 -o loop,rw _disk_image.raw $MOUNTDIR
9+
fi

tools/pci-vendors.awk

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
/^[^#[:blank:]C]/ {
2+
num=""$1; name=$0;
3+
sub("^"num, "", name);
4+
sub("[[:blank:]]+", "", name);
5+
gsub("\"", "\\\"", name);
6+
print "PCI_VENDOR(0x"num",\""name"\")"
7+
}

tools/pkg-config.sh

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
#!/bin/sh
2+
export PKG_CONFIG_SYSROOT_DIR=$SYSROOT
3+
export PKG_CONFIG_LIBDIR=$SYSROOT/usr/lib/pkgconfig
4+
export PKG_CONFIG_PATH=$PKG_CONFIG_LIBDIR
5+
exec pkg-config --static "$@"

tools/qemu.sh

Lines changed: 28 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,28 @@
1+
#!/bin/bash
2+
3+
QEMU=qemu-system-i386
4+
BOOT_ISO=depthos.iso
5+
DISK_IMAGE=_disk_image.raw
6+
# QEMU_ARGS="-M pc-i440fx-2.8 -m 4G -monitor tcp:127.0.0.1:55555 -serial stdio"
7+
# COMMON_ARGS=( "-M pc-i440fx-2.8 -m 1G -serial stdio" ) # -d trace:ide_data_*
8+
COMMON_ARGS=( "-m 1G -serial stdio" ) # -d trace:ide_data_*
9+
DRIVE_BOOT="-drive id=boot,file=$BOOT_ISO,format=raw,if=none,unit=0"
10+
DRIVE_STOR="-drive id=disk1,file=$DISK_IMAGE,format=raw,if=none,unit=1"
11+
DEV_ARGS=( "-device ide-hd,drive=boot,bus=ide.0 -device ide-hd,drive=disk1,bus=ide.0" )
12+
13+
# while getopts "dl" opt; do
14+
# case "$opt" in
15+
# d)
16+
# QEMU_ARGS="${QEMU_ARGS} -s -S"
17+
# ;;
18+
# l)
19+
# QEMU_ARGS="${QEMU_ARGS} -d int,pcall,cpu,fpu -D qemu.log"
20+
# ;;
21+
# esac
22+
# done
23+
24+
# qemu-system-i386 -M pc-i440fx-2.8 -drive id=boot,file=depthos.iso,format=raw,if=none -device ahci,id=ahbus -device ide-cd,drive=boot -m 4G -monitor none -serial stdio
25+
26+
echo $QEMU ${COMMON_ARGS[@]} ${DRIVE_BOOT} ${DRIVE_STOR} ${DEV_ARGS[@]} $@
27+
$QEMU ${COMMON_ARGS[@]} ${DRIVE_BOOT} ${DRIVE_STOR} ${DEV_ARGS[@]} $@
28+
# -device ide-hd,drive=boot,bus=ide.0 -device ide-cd,drive=disk1,bus=ide.0

tools/run.sh

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
#!/bin/sh
2+
3+
4+
ROOTDIR=`git rev-parse --show-toplevel`
5+
6+
$ROOTDIR/tools/iso.sh
7+
$ROOTDIR/tools/qemu.sh $@

tools/sync.sh

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,19 @@
1+
#!/bin/bash
2+
3+
FSDIR=disk-fs
4+
ROOTDIR=`git rev-parse --show-toplevel`
5+
MOUNTDIR=_mnt
6+
IMG=_disk_image.raw
7+
# RSYNC_FLAGS="-vacI --update"
8+
# RSYNC_FLAGS="-vacu"
9+
RSYNC_FLAGS="-vacu"
10+
echo -n "Mounting... " && mount -t ext2 -o loop,rw ${ROOTDIR}/${IMG} ${ROOTDIR}/${MOUNTDIR} && echo "done"
11+
# cp -r "${ROOTDIR}/${FSDIR}"/* _mnt
12+
# echo "SYSROOT: ${SYSROOT}"
13+
[ -n "${SYSROOT}" ] && echo "rsync ${RSYNC_FLAGS} ${SYSROOT}/ ${ROOTDIR}/${MOUNTDIR}" && echo -n "Syncing sysroot... " && rsync ${RSYNC_FLAGS} ${SYSROOT}/ ${ROOTDIR}/${MOUNTDIR} && echo "done"
14+
15+
echo "rsync ${RSYNC_FLAGS} ${ROOTDIR}/${FSDIR}/ ${ROOTDIR}/${MOUNTDIR}"
16+
echo -n "Syncing template directory... " && rsync ${RSYNC_FLAGS} ${ROOTDIR}/${FSDIR}/ ${ROOTDIR}/${MOUNTDIR} && echo "done"
17+
sleep 1
18+
echo -n "Unmounting... " && umount ${ROOTDIR}/${MOUNTDIR} && echo "done"
19+

0 commit comments

Comments
 (0)