Initial ramdisk support

- Create initrd library to support definitions and loading
- Allow tools compiled for the host machine to be built by wscript
- Create makerd tool to build initrd from manifest
- Move screenfont to initrd, so don't load framebuffer initially
This commit is contained in:
Justin C. Miller
2018-09-05 22:42:18 -07:00
parent dc40c2f6ad
commit 1758ee4215
20 changed files with 592 additions and 181 deletions

339
wscript
View File

@@ -2,12 +2,6 @@ top = '.'
out = 'build'
from waflib.Build import BuildContext
class TestContext(BuildContext):
cmd = 'test'
variant = 'tests'
def options(opt):
opt.load("nasm clang clang++")
@@ -28,29 +22,14 @@ def options(opt):
help='Font for the console')
def configure(ctx):
import os
import subprocess
def common_configure(ctx):
from os import listdir
from os.path import join, exists
from subprocess import check_output
ctx.find_program("ld", var="LINK_CC")
ctx.env.LINK_CXX = ctx.env.LINK_CC
version = check_output("git describe --always", shell=True).strip()
git_sha = check_output("git rev-parse --short HEAD", shell=True).strip()
ctx.load("nasm clang clang++")
ctx.find_program("objcopy", var="objcopy")
ctx.find_program("objdump", var="objdump")
ctx.find_program("mcopy", var="mcopy")
ctx.find_program("dd", var="dd")
# Override the gcc/g++ tools setting these assuming LD is gcc/g++
ctx.env.SHLIB_MARKER = '-Bdynamic'
ctx.env.STLIB_MARKER = '-Bstatic'
ctx.env.LINKFLAGS_cstlib = ['-Bstatic']
version = subprocess.check_output("git describe --always", shell=True).strip()
git_sha = subprocess.check_output("git rev-parse --short HEAD", shell=True).strip()
env = ctx.env
major, minor, patch_dirty = version.split(".")
dirty = 'dirty' in patch_dirty
patch = patch_dirty.split('-')[0]
@@ -71,17 +50,66 @@ def configure(ctx):
libraries = []
mod_root = join("src", "libraries")
for module in os.listdir(mod_root):
for module in listdir(mod_root):
mod_path = join(mod_root, module)
if exists(join(mod_path, "wscript")):
libraries.append(mod_path)
ctx.env.LIBRARIES = libraries
tools = []
mod_root = join("src", "tools")
for module in listdir(mod_root):
mod_path = join(mod_root, module)
if exists(join(mod_path, "wscript")):
tools.append(mod_path)
ctx.env.TOOLS = tools
drivers = []
mod_root = join("src", "drivers")
for module in os.listdir(mod_root):
for module in listdir(mod_root):
mod_path = join(mod_root, module)
if exists(join(mod_path, "wscript")):
drivers.append(mod_path)
ctx.env.DRIVERS = drivers
ctx.env.append_value('DEFINES', [
'GIT_VERSION="{}"'.format(version),
'GIT_VERSION_WIDE=L"{}"'.format(version),
"VERSION_MAJOR={}".format(major),
"VERSION_MINOR={}".format(minor),
"VERSION_PATCH={}".format(patch),
"VERSION_GITSHA=0x{}{}".format({True:1}.get(dirty, 0), git_sha),
])
ctx.env.append_value('QEMUOPTS', [
'-smp', '1',
'-m', '512',
'-d', 'mmu,int,guest_errors',
'-D', 'popcorn.log',
'-cpu', 'Broadwell',
'-M', 'q35',
'-no-reboot',
'-nographic',
])
if exists('/dev/kvm'):
ctx.env.append_value('QEMUOPTS', ['--enable-kvm'])
def configure(ctx):
from os.path import join, exists
ctx.find_program("ld", var="LINK_CC")
ctx.env.LINK_CXX = ctx.env.LINK_CC
ctx.load("nasm clang clang++")
ctx.find_program("objcopy", var="objcopy")
ctx.find_program("objdump", var="objdump")
# Override the gcc/g++ tools setting these assuming LD is gcc/g++
ctx.env.SHLIB_MARKER = '-Bdynamic'
ctx.env.STLIB_MARKER = '-Bstatic'
ctx.env.LINKFLAGS_cstlib = ['-Bstatic']
baseflags = [
'-nostdlib',
@@ -118,15 +146,6 @@ def configure(ctx):
'error'
]]
ctx.env.append_value('DEFINES', [
'GIT_VERSION="{}"'.format(version),
'GIT_VERSION_WIDE=L"{}"'.format(version),
"VERSION_MAJOR={}".format(major),
"VERSION_MINOR={}".format(minor),
"VERSION_PATCH={}".format(patch),
"VERSION_GITSHA=0x{}{}".format({True:1}.get(dirty, 0), git_sha),
])
ctx.env.append_value('CFLAGS', baseflags)
ctx.env.append_value('CFLAGS', warnflags)
ctx.env.append_value('CFLAGS', ['-ggdb', '-std=c11'])
@@ -150,66 +169,136 @@ def configure(ctx):
'-nostartfiles',
])
ctx.env.append_value('QEMUOPTS', [
'-smp', '1',
'-m', '512',
'-d', 'mmu,int,guest_errors',
'-D', 'popcorn.log',
'-cpu', 'Broadwell',
'-M', 'q35',
'-no-reboot',
'-nographic',
])
if os.path.exists('/dev/kvm'):
ctx.env.append_value('QEMUOPTS', ['--enable-kvm'])
env = ctx.env
ctx.setenv('boot', env=env)
common_configure(ctx)
base_bare = ctx.env
ctx.setenv('boot', env=base_bare)
ctx.recurse(join("src", "boot"))
ctx.setenv('kernel', env=env)
ctx.setenv('kernel', env=base_bare)
ctx.env.append_value('CFLAGS', ['-mcmodel=large'])
ctx.env.append_value('CXXFLAGS', ['-mcmodel=large'])
ctx.env.LIBRARIES = libraries
for mod_path in ctx.env.LIBRARIES:
ctx.recurse(mod_path)
ctx.env.DRIVERS = drivers
for mod_path in ctx.env.DRIVERS:
ctx.recurse(mod_path)
ctx.recurse(join("src", "kernel"))
## Testing configuration
## Tools configuration
##
from waflib.ConfigSet import ConfigSet
ctx.setenv('tests', env=ConfigSet())
ctx.load("clang++")
ctx.env.append_value('INCLUDES', [
join(ctx.path.abspath(), "src", "include"),
join(ctx.path.abspath(), "src", "libraries"),
])
ctx.setenv('tools', env=ConfigSet())
ctx.load('clang++')
ctx.find_program("mcopy", var="mcopy")
ctx.find_program("dd", var="dd")
common_configure(ctx)
ctx.env.CXXFLAGS = ['-g', '-std=c++14', '-fno-rtti']
ctx.env.LINKFLAGS = ['-g']
for mod_path in ctx.env.LIBRARIES:
ctx.recurse(mod_path)
for mod_path in ctx.env.LIBRARIES:
ctx.recurse(mod_path)
## Image configuration
##
ctx.setenv('image', env=ConfigSet())
ctx.find_program("mcopy", var="mcopy")
ctx.find_program("dd", var="dd")
common_configure(ctx)
## Testing configuration
##
from waflib.ConfigSet import ConfigSet
ctx.setenv('tests', env=ConfigSet())
ctx.load('clang++')
common_configure(ctx)
ctx.env.CXXFLAGS = ['-g', '-std=c++14', '-fno-rtti']
ctx.env.LINKFLAGS = ['-g']
ctx.env.LIBRARIES = libraries
for mod_path in ctx.env.LIBRARIES:
ctx.recurse(mod_path)
ctx.recurse(join("src", "tests"))
from waflib.Task import Task
class mcopy(Task):
color = 'YELLOW'
def keyword(self):
return "Updating"
def __str__(self):
node = self.inputs[0]
return node.path_from(node.ctx.launch_node())
def run(self):
from subprocess import check_call as call
from shutil import copy
copy(self.inputs[0].abspath(), self.outputs[0].abspath())
args = self.env.mcopy + ["-i", self.outputs[0].abspath(), "-D", "o"]
b_args = args + [self.inputs[1].abspath(), "::/efi/boot/bootx64.efi"]
call(b_args)
for inp in self.inputs[2:]:
call(args + [inp.abspath(), "::/"])
class addpart(Task):
color = 'YELLOW'
def keyword(self):
return "Updating"
def __str__(self):
node = self.inputs[0]
return node.path_from(node.ctx.launch_node())
def run(self):
from subprocess import check_call as call
from shutil import copy
copy(self.inputs[0].abspath(), self.outputs[0].abspath())
args = self.env.dd + [
"of={}".format(self.outputs[0].abspath()),
"if={}".format(self.inputs[1].abspath()),
"bs=512", "count=91669", "seek=2048", "conv=notrunc"]
call(args)
class makerd(Task):
color = 'YELLOW'
def keyword(self):
return "Creating"
def __str__(self):
node = self.outputs[0]
return node.path_from(node.ctx.launch_node())
def run(self):
from os.path import join
from subprocess import check_call as call
args = [
self.inputs[0].abspath(),
self.inputs[1].abspath(),
self.outputs[0].abspath(),
]
call(args)
def build(bld):
from os.path import join
if not bld.variant:
bld.env = bld.all_envs['boot']
## Boot
#
if bld.variant == 'boot':
bld.recurse(join("src", "boot"))
bld.env = bld.all_envs['kernel']
## Tools
#
elif bld.variant == 'tools':
for mod_path in bld.env.LIBRARIES:
bld.recurse(mod_path)
for mod_path in bld.env.TOOLS:
bld.recurse(mod_path)
## Kernel
#
elif bld.variant == 'kernel':
for mod_path in bld.env.LIBRARIES:
bld.recurse(mod_path)
for mod_path in bld.env.DRIVERS:
@@ -217,67 +306,44 @@ def build(bld):
bld.recurse(join("src", "kernel"))
## Image
#
elif bld.variant == 'image':
src = bld.path
out = bld.path.get_bld()
root = bld.path.get_bld().parent
out = {
'boot': root.make_node('boot'),
'tools': root.make_node('tools'),
'kernel': root.make_node('kernel'),
}
kernel_name = bld.env.KERNEL_FILENAME
disk = out.make_node("popcorn.img")
disk1 = out.make_node("popcorn.fat")
font = out.make_node("screenfont.psf")
disk = root.make_node("popcorn.img")
disk1 = root.make_node("popcorn.fat")
initrd = root.make_node("initrd.img")
bld(
source = src.make_node(join("assets", "ovmf", "x64", "OVMF.fd")),
target = out.make_node("flash.img"),
target = root.make_node("flash.img"),
rule = "cp ${SRC} ${TGT}",
)
bld(
source = src.make_node(join("assets", "fonts", bld.env.FONT_NAME)),
target = font,
rule = "cp ${SRC} ${TGT}",
)
from waflib.Task import Task
class mcopy(Task):
color = 'YELLOW'
def keyword(self):
return "Updating"
def __str__(self):
node = self.inputs[0]
return node.path_from(node.ctx.launch_node())
def run(self):
from subprocess import check_call as call
from shutil import copy
copy(self.inputs[0].abspath(), self.outputs[0].abspath())
args = self.env.mcopy + ["-i", self.outputs[0].abspath(), "-D", "o"]
b_args = args + [self.inputs[1].abspath(), "::/efi/boot/bootx64.efi"]
call(b_args)
for inp in self.inputs[2:]:
call(args + [inp.abspath(), "::/"])
class addpart(Task):
color = 'YELLOW'
def keyword(self):
return "Updating"
def __str__(self):
node = self.inputs[0]
return node.path_from(node.ctx.launch_node())
def run(self):
from subprocess import check_call as call
from shutil import copy
copy(self.inputs[0].abspath(), self.outputs[0].abspath())
args = self.env.dd + [
"of={}".format(self.outputs[0].abspath()),
"if={}".format(self.inputs[1].abspath()),
"bs=512", "count=91669", "seek=2048", "conv=notrunc"]
call(args)
make_rd = makerd(env = bld.env)
make_rd.set_inputs([
out['tools'].make_node(join("src", "tools", "makerd", "makerd")),
src.make_node(join("assets", "initrd.manifest")),
])
make_rd.set_outputs([initrd])
bld.add_to_group(make_rd)
copy_img = mcopy(env = bld.env)
copy_img.set_inputs([
src.make_node(join("assets", "disk.fat")),
out.make_node(join("src", "boot", "boot.efi")),
out.make_node(join("src", "kernel", kernel_name)),
font,
out['boot'].make_node(join("src", "boot", "boot.efi")),
out['kernel'].make_node(join("src", "kernel", kernel_name)),
initrd,
])
copy_img.set_outputs([disk1])
bld.add_to_group(copy_img)
@@ -290,11 +356,44 @@ def build(bld):
copy_part.set_outputs([disk])
bld.add_to_group(copy_part)
elif bld.variant == 'tests':
for mod_path in bld.env.LIBRARIES:
bld.recurse(mod_path)
bld.recurse(join("src", "tests"))
def test(bld):
from os.path import join
for mod_path in bld.env.LIBRARIES:
bld.recurse(mod_path)
bld.recurse(join("src", "tests"))
def build_all(ctx):
from waflib import Options
Options.commands = ['tools', 'kernel', 'boot', 'image'] + Options.commands
from waflib.Build import BuildContext
class TestContext(BuildContext):
cmd = 'test'
variant = 'tests'
class ToolsContext(BuildContext):
cmd = 'tools'
variant = 'tools'
class KernelContext(BuildContext):
cmd = 'kernel'
variant = 'kernel'
class BootContext(BuildContext):
cmd = 'boot'
variant = 'boot'
class ImageContext(BuildContext):
cmd = 'image'
variant = 'image'
class BuildAllContext(BuildContext):
cmd = 'build'
fun = 'build_all'
class QemuContext(BuildContext):