Skip to content

Commit

Permalink
Merge branch 'main' into clk_driver
Browse files Browse the repository at this point in the history
Signed-off-by: Terry Bai <[email protected]>
  • Loading branch information
terryzbai authored Nov 18, 2024
2 parents bd71cc8 + c2bb0a4 commit cc87eaf
Show file tree
Hide file tree
Showing 37 changed files with 4,693 additions and 76 deletions.
15 changes: 13 additions & 2 deletions .github/workflows/examples.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@ jobs:
wget https://github.com/seL4/microkit/releases/download/1.4.1/microkit-sdk-1.4.1-linux-x86-64.tar.gz
tar xf microkit-sdk-1.4.1-linux-x86-64.tar.gz
- name: Install dependencies (via apt)
run: sudo apt update && sudo apt install -y make llvm lld xxd
run: sudo apt update && sudo apt install -y make llvm lld imagemagick
- name: Download and install AArch64 GCC toolchain
run: |
wget -O aarch64-toolchain.tar.xz https://trustworthy.systems/Downloads/microkit/arm-gnu-toolchain-12.3.rel1-x86_64-aarch64-none-elf.tar.xz
Expand All @@ -36,6 +36,17 @@ jobs:
- name: Build and run examples
run: ./ci/examples.sh ${PWD}/microkit-sdk-1.4.1
shell: bash
build_linux_x86_64_nix:
name: Linux x86-64 (Nix)
runs-on: ubuntu-24.04
steps:
- name: Checkout repository
uses: actions/checkout@v4
- name: Setup Nix
uses: cachix/install-nix-action@v27
- name: Build and run examples
run: nix develop -c bash -c './ci/examples.sh $MICROKIT_SDK'
shell: bash
build_macos_arm64:
name: macOS ARM64
runs-on: macos-14
Expand All @@ -48,7 +59,7 @@ jobs:
tar xf microkit-sdk-1.4.1-macos-aarch64.tar.gz
- name: Install dependencies (via Homebrew)
run: |
brew install llvm lld make
brew install llvm lld make imagemagick
echo "/opt/homebrew/opt/llvm/bin:$PATH" >> $GITHUB_PATH
- name: Install Zig
uses: mlugg/[email protected]
Expand Down
8 changes: 8 additions & 0 deletions .reuse/dep5
Original file line number Diff line number Diff line change
Expand Up @@ -3,16 +3,24 @@ Upstream-Name: seL4 Device Driver Framework
Source: https://github.com/au-ts/sddf

Files:
flake.lock
CHANGES.md
build.zig.zon
examples/i2c/build.zig.zon
examples/serial/build.zig.zon
examples/timer/build.zig.zon
examples/blk/build.zig.zon
examples/blk/basic_data.txt
examples/blk/basic_data.h
examples/gpu/build.zig.zon
Copyright: UNSW
License: BSD-2-Clause

Files:
examples/gpu/fb_img.jpeg
Copyright: UNSW
License: CC-BY-SA-4.0

Files: libco/*
Copyright: byuu and the higan team
License: ISC
Expand Down
51 changes: 37 additions & 14 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -27,28 +27,51 @@ The latest design documentation can be found [here](https://trustworthy.systems/
More information about the sDDF project can be found on the Trustworthy Systems website
[here](https://trustworthy.systems/projects/drivers/).

## Building and running examples
## Dependencies

You can find examples making use of the sDDF in the `examples/` directory. Each example has its
own README for how to build and run it.
* Microkit SDK 1.4.1
* GNU Make
* Clang and LLVM bintools

## Dependencies
The Microkit SDK can be acquired from [here](https://github.com/seL4/microkit/releases/tag/1.4.1).

sDDF is primarily compiled via Makefiles, but the [Zig](https://ziglang.org) build system is also
available. If you are intending on using Zig instead of Make, please see https://ziglang.org/download/.

See the instructions below for installing the rest of the dependencies based on your
machine:

### apt

### Toolchain
On apt based Linux distributions run the following commands:

Any C toolchain should work but most testing and experimentation is currently performed with
the `aarch64-none-elf` GCC toolchain distributed by ARM. You can download it from
[here](https://developer.arm.com/downloads/-/arm-gnu-toolchain-downloads).
```sh
sudo apt install make llvm lld
```

The specific version used for testing is:
`aarch64-none-elf-gcc (GNU Toolchain for the A-profile Architecture 10.2-2020.11 (arm-10.16)) 10.2.1 20201103`.
### Homebrew

### Microkit SDK
On macOS, you can install the dependencies via Homebrew:
```sh
brew install llvm lld make
```

The sDDF is built using the [seL4 Microkit](https://github.com/seL4/microkit) (version 1.4.1).
### Nix

There is a Nix flake available in the repository, so you can get a development shell via:
```sh
nix develop
```

Note that this will set the `MICROKIT_SDK` environment variable to the SDK path, you do not
need to download the Microkit SDK manually.

## Examples

You can find examples making use of the sDDF in the `examples/` directory. Each example has its
own README for how to build and run it.

You can download version 1.4.1 of Microkit SDK from
[here](https://github.com/seL4/microkit/releases/tag/1.4.1).
Note that some examples may have dependencies in addition to the ones listed in this README.

## Developing sDDF

Expand Down
55 changes: 55 additions & 0 deletions build.zig
Original file line number Diff line number Diff line change
Expand Up @@ -47,6 +47,10 @@ const DriverClass = struct {
ds3231,
pn532,
};

const Gpu = enum {
virtio,
};
};

const util_src = [_][]const u8{
Expand Down Expand Up @@ -307,6 +311,32 @@ fn addNetworkDriver(
return driver;
}

fn addGpuDriver(
b: *std.Build,
gpu_config_include: LazyPath,
util: *std.Build.Step.Compile,
class: DriverClass.Gpu,
target: std.Build.ResolvedTarget,
optimize: std.builtin.OptimizeMode,
) *std.Build.Step.Compile {
const driver = addPd(b, .{
.name = b.fmt("driver_gpu_{s}.elf", .{ @tagName(class) }),
.target = target,
.optimize = optimize,
.strip = false,
});
const source = b.fmt("drivers/gpu/{s}/gpu.c", .{ @tagName(class) });
driver.addCSourceFile(.{
.file = b.path(source),
});
driver.addIncludePath(gpu_config_include);
driver.addIncludePath(b.path(b.fmt("drivers/gpu/{s}/", .{ @tagName(class) })));
driver.addIncludePath(b.path("include"));
driver.linkLibrary(util);

return driver;
}

fn addPd(b: *std.Build, options: std.Build.ExecutableOptions) *std.Build.Step.Compile {
const pd = b.addExecutable(options);
pd.addObjectFile(libmicrokit);
Expand All @@ -329,6 +359,7 @@ pub fn build(b: *std.Build) void {
const i2c_client_include_option = b.option([]const u8, "i2c_client_include", "Include path to client config header") orelse "";
const clk_conf_include_option = b.option([]const u8, "clk_conf_include", "Include path to client config header") orelse "";
const dtb_path = b.option([]const u8, "dtb_path", "Path to the DTB file") orelse "";
const gpu_config_include_option = b.option([]const u8, "gpu_config_include", "Include path to gpu config header") orelse "";

// TODO: Right now this is not super ideal. What's happening is that we do not
// always need a serial config include, but we must always specify it
Expand All @@ -340,6 +371,7 @@ pub fn build(b: *std.Build) void {
const net_config_include = LazyPath{ .cwd_relative = net_config_include_option };
const i2c_client_include = LazyPath{ .cwd_relative = i2c_client_include_option };
const clk_client_include = LazyPath{ .cwd_relative = clk_conf_include_option };
const gpu_config_include = LazyPath{ .cwd_relative = gpu_config_include_option };
// libmicrokit
// We're declaring explicitly here instead of with anonymous structs due to a bug. See https://github.com/ziglang/zig/issues/19832
libmicrokit = LazyPath{ .cwd_relative = libmicrokit_opt.? };
Expand Down Expand Up @@ -452,6 +484,29 @@ pub fn build(b: *std.Build) void {
b.installArtifact(driver);
}

// Gpu components
const gpu_virt = addPd(b, .{
.name = "gpu_virt.elf",
.target = target,
.optimize = optimize,
.strip = false,
});
gpu_virt.addCSourceFile(.{
.file = b.path("gpu/components/virt.c"),
});
gpu_virt.addIncludePath(gpu_config_include);
gpu_virt.addIncludePath(b.path("include"));
gpu_virt.linkLibrary(util);
gpu_virt.linkLibrary(util_putchar_debug);
b.installArtifact(gpu_virt);

// Gpu drivers
inline for (std.meta.fields(DriverClass.Gpu)) |class| {
const driver = addGpuDriver(b, gpu_config_include, util, @enumFromInt(class.value), target, optimize);
driver.linkLibrary(util_putchar_debug);
b.installArtifact(driver);
}

// Timer drivers
inline for (std.meta.fields(DriverClass.Timer)) |class| {
const driver = addTimerDriver(b, util, @enumFromInt(class.value), target, optimize);
Expand Down
1 change: 1 addition & 0 deletions build.zig.zon
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@
"drivers",
"benchmark",
"blk",
"gpu",
"i2c",
"include",
"libco",
Expand Down
40 changes: 40 additions & 0 deletions ci/examples.sh
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,7 @@ I2C=true
SERIAL=true
TIMER=true
BLK=true
GPU=true

build_network_echo_server_make() {
BOARD=$1
Expand Down Expand Up @@ -155,6 +156,31 @@ build_blk_zig() {
popd
}

build_gpu_make() {
BOARD=$1
CONFIG=$2
echo "CI|INFO: building gpu example with Make, board: ${BOARD}, config: ${CONFIG}"
BUILD_DIR="${PWD}/${CI_BUILD_DIR}/examples/gpu/make/${BOARD}/${CONFIG}"
rm -rf ${BUILD_DIR}
mkdir -p ${BUILD_DIR}
make -j${NUM_JOBS} -C ${SDDF}/examples/gpu \
BUILD_DIR=${BUILD_DIR} \
MICROKIT_CONFIG=${CONFIG} \
MICROKIT_SDK=${SDK_PATH} \
MICROKIT_BOARD=${BOARD}
}

build_gpu_zig() {
BOARD=$1
CONFIG=$2
echo "CI|INFO: building gpu example with Zig, board: ${BOARD}, config: ${CONFIG}"
BUILD_DIR="${PWD}/${CI_BUILD_DIR}/examples/gpu/zig/${BOARD}/${CONFIG}"
rm -rf ${BUILD_DIR}
pushd ${SDDF}/examples/gpu
zig build -Dsdk=${SDK_PATH} -Dboard=${BOARD} -Dconfig=${CONFIG} -p ${BUILD_DIR}
popd
}

network() {
BOARDS=("odroidc4" "imx8mm_evk" "maaxboard" "qemu_virt_aarch64")
CONFIGS=("debug" "release" "benchmark")
Expand Down Expand Up @@ -231,13 +257,27 @@ blk() {
done
}

gpu() {
BOARDS=("qemu_virt_aarch64")
CONFIGS=("debug" "release")
for BOARD in "${BOARDS[@]}"
do
for CONFIG in "${CONFIGS[@]}"
do
build_gpu_make ${BOARD} ${CONFIG}
build_gpu_zig ${BOARD} ${CONFIG}
done
done
}

# Only run the examples that have been enabled
$NETWORK && network
$I2C && i2c
$TIMER && timer
$SERIAL && serial
$MMC && mmc
$BLK && blk
$GPU && gpu

echo ""
echo "CI|INFO: Passed all sDDF tests"
Loading

0 comments on commit cc87eaf

Please sign in to comment.