Skip to content

Commit

Permalink
Set up Banscii for portability
Browse files Browse the repository at this point in the history
Signed-off-by: Nick Spinale <[email protected]>
  • Loading branch information
nspin committed Jun 12, 2024
1 parent e430ff5 commit 316230b
Show file tree
Hide file tree
Showing 7 changed files with 73 additions and 11 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -6,15 +6,15 @@
-->
<system>

<memory_region name="pl011_mmio" size="0x1000" phys_addr="0x9000000" />
<memory_region name="serial_mmio" size="0x1_000" phys_addr="{{ serial_mmio_phys_addr }}" />

<memory_region name="assistant_to_artist" size="0x4_000" />
<memory_region name="artist_to_assistant" size="0x4_000" />

<protection_domain name="pl011_driver" priority="254" pp="true">
<protection_domain name="serial_driver" priority="254" pp="true">
<program_image path="banscii-serial-driver.elf" />
<map mr="pl011_mmio" vaddr="0x2000000" perms="rw" setvar_vaddr="pl011_register_block" />
<irq irq="33" id="0" />
<map mr="serial_mmio" vaddr="0x2_000_000" perms="rw" setvar_vaddr="serial_register_block" />
<irq irq="{{ serial_irq }}" id="0" />
</protection_domain>

<protection_domain name="assistant" priority="252">
Expand All @@ -30,7 +30,7 @@
</protection_domain>

<channel>
<end pd="pl011_driver" id="1" />
<end pd="serial_driver" id="1" />
<end pd="assistant" id="0" />
</channel>

Expand Down
38 changes: 38 additions & 0 deletions crates/examples/microkit/banscii/generate_system_description.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,38 @@
#
# Copyright 2024, Colias Group, LLC
#
# SPDX-License-Identifier: BSD-2-Clause
#

import argparse
import json
import sys
from jinja2 import Template

def main():
parser = argparse.ArgumentParser()
parser.add_argument('--template', type=argparse.FileType('r'), required=True)
parser.add_argument('--board', required=True)
parser.add_argument('-o', type=argparse.FileType('w'), required=True)
args = parser.parse_args()
run(args)

def run(args):
template = Template(args.template.read())
context = mk_context(args.board)
rendered = template.render(context)
args.o.write(rendered)

def mk_context(board):
context = {}

if board == 'qemu_virt_aarch64':
context['serial_mmio_phys_addr'] = 0x9000000
context['serial_irq'] = 33
else:
raise Exception('unsupported configuration')

return context

if __name__ == '__main__':
main()
6 changes: 5 additions & 1 deletion crates/examples/microkit/banscii/pds/serial-driver/Cargo.nix
Original file line number Diff line number Diff line change
Expand Up @@ -12,8 +12,12 @@ mk {
inherit (localCrates)
sel4-microkit-message
sel4-microkit-embedded-hal-adapters
sel4-pl011-driver

;
sel4-microkit = localCrates.sel4-microkit // { default-features = false; };
sel4-pl011-driver = localCrates.sel4-pl011-driver // { optional = true; };
};
features = {
board-qemu_virt_aarch64 = [ "sel4-pl011-driver" ];
};
}
Original file line number Diff line number Diff line change
Expand Up @@ -16,10 +16,13 @@ authors = ["Nick Spinale <[email protected]>"]
edition = "2021"
license = "BSD-2-Clause"

[features]
board-qemu_virt_aarch64 = ["sel4-pl011-driver"]

[dependencies]
sel4-microkit = { path = "../../../../../sel4-microkit", default-features = false }
sel4-microkit-message = { path = "../../../../../sel4-microkit/message" }
sel4-pl011-driver = { path = "../../../../../drivers/sel4-pl011-driver" }
sel4-pl011-driver = { path = "../../../../../drivers/sel4-pl011-driver", optional = true }

[dependencies.sel4-microkit-embedded-hal-adapters]
path = "../../../../../sel4-microkit/embedded-hal-adapters"
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,8 @@

use sel4_microkit::{memory_region_symbol, protection_domain, Channel};
use sel4_microkit_embedded_hal_adapters::serial::driver::Driver;

#[cfg(feature = "board-qemu_virt_aarch64")]
use sel4_pl011_driver::Driver as DriverImpl;

const DEVICE: Channel = Channel::new(0);
Expand All @@ -17,6 +19,6 @@ const ASSISTANT: Channel = Channel::new(1);
#[protection_domain]
fn init() -> Driver<DriverImpl> {
let driver_impl =
unsafe { DriverImpl::new(memory_region_symbol!(pl011_register_block: *mut ()).as_ptr()) };
unsafe { DriverImpl::new(memory_region_symbol!(serial_register_block: *mut ()).as_ptr()) };
Driver::new(driver_impl, DEVICE, ASSISTANT)
}
1 change: 1 addition & 0 deletions hacking/nix/scope/microkit/default.nix
Original file line number Diff line number Diff line change
Expand Up @@ -128,6 +128,7 @@ let
];

passthru = rec {
inherit systemXML;
loader = "${self}/loader.img";
links = [
{ name = "pds"; path = searchPath; }
Expand Down
20 changes: 17 additions & 3 deletions hacking/nix/scope/world/instances/microkit/banscii/default.nix
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@
{ lib, stdenv
, buildPackages, pkgsBuildBuild
, linkFarm, symlinkJoin, writeText, writeScript, runCommand
, callPackage
, python3Packages
, microkit
, mkTask
, sources
Expand All @@ -16,16 +16,19 @@
, mkSeL4RustTargetTriple
, mkMicrokitInstance
, worldConfig
, seL4ConfigJSON

, canSimulate
, mkPD
}:

let
inherit (worldConfig.microkitConfig) board;

pds = {
serial-driver = mkPD rec {
rootCrate = crates.banscii-serial-driver;
release = true;
features = [ "board-${board}" ];
};
assistant = mkPD rec {
rootCrate = crates.banscii-assistant;
Expand All @@ -44,6 +47,8 @@ let
};
};

srcPath = relativePath: sources.srcRoot + "/crates/examples/microkit/banscii/${relativePath}";

in
lib.fix (self: mkMicrokitInstance {
system = microkit.mkSystem {
Expand All @@ -55,7 +60,16 @@ lib.fix (self: mkMicrokitInstance {
"${pds.artist}/bin"
];
};
systemXML = sources.srcRoot + "/crates/examples/microkit/banscii/banscii.system";
systemXML = runCommand "banscii.system" {
nativeBuildInputs = [
python3Packages.jinja2
];
} ''
python3 ${srcPath "generate_system_description.py"} \
--template ${srcPath "banscii.system.template"} \
--board ${board} \
-o $out
'';
};
} // {
inherit pds;
Expand Down

0 comments on commit 316230b

Please sign in to comment.