Skip to content

Commit 70a94fd

Browse files
tool: add --override-kernel option
Motivated by the comment here [1]. The main thing this will be useful for is adding debug prints/asserts to the kernel without having to re-compile the whole Microkit SDK. Using kernels that are not compiled with the same configuration or same version that the SDK was compiled will likely cause issues and not work at all. [1]: seL4/seL4#1645 (comment) Signed-off-by: Ivan Velickovic <i.velickovic@unsw.edu.au>
1 parent 36c4f52 commit 70a94fd

2 files changed

Lines changed: 30 additions & 7 deletions

File tree

docs/manual.md

Lines changed: 8 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -456,9 +456,9 @@ The format of the system description is described in a subsequent chapter.
456456

457457
Usage:
458458

459-
microkit [-h] [-o OUTPUT] [-r REPORT]
460-
[--capdl-json CAPDL_SPEC] [--image-type {binary,elf,uimage}]
461-
--board [BOARD] --config CONFIG [--search-path [SEARCH_PATH ...]] system
459+
microkit [-h] [OPTIONS] --board BOARD --config CONFIG [--search-path SEARCH_PATH ...] system
460+
461+
See `microkit --help` for a full list of options.
462462

463463
The path to the system description file, board to build the system for, and configuration to build for must be provided.
464464

@@ -476,6 +476,11 @@ The report can be useful when debugging potential system problems.
476476
This report does not have a fixed format and may change between versions.
477477
It is not intended to be machine readable.
478478

479+
The `--override-kernel` option will override the kernel ELF used for the system rather than from the SDK.
480+
It is important to note that this is largely just for debugging purposes and the Microkit is
481+
highly tied to a specific version and configuration of the kernel. When using this option the kernel
482+
should be the same version and compiled with the same configuration options.
483+
479484
## Image format
480485

481486
### ARM

tool/microkit/src/main.rs

Lines changed: 22 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -42,7 +42,7 @@ const KERNEL_COPY_FILENAME: &str = "sel4.elf";
4242
const KERNEL32_COPY_FILENAME: &str = "sel4_32.elf";
4343

4444
fn print_usage() {
45-
println!("usage: microkit [-h] [-o OUTPUT] [--image-type {{binary,elf,uimage}}] [-r REPORT] --board BOARD --config CONFIG [--capdl-json CAPDL_SPEC] --search-path [SEARCH_PATH ...] system")
45+
println!("usage: microkit [-h] [OPTIONS] --board BOARD --config CONFIG [--search-path SEARCH_PATH ...] system")
4646
}
4747

4848
fn print_help(available_boards: &[String]) {
@@ -54,6 +54,7 @@ fn print_help(available_boards: &[String]) {
5454
println!(" -o, --output OUTPUT");
5555
println!(" -r, --report REPORT");
5656
println!(" --image-type {{binary,elf}}");
57+
println!(" --override-kernel KERNEL (for debugging purposes)");
5758
println!(" --board {}", available_boards.join("\n "));
5859
println!(" --config CONFIG");
5960
println!(" --capdl-json CAPDL_SPEC (JSON format)");
@@ -107,6 +108,7 @@ struct Args<'a> {
107108
output: &'a str,
108109
search_paths: Vec<&'a String>,
109110
output_image_type: Option<&'a str>,
111+
override_kernel: Option<&'a str>,
110112
}
111113

112114
impl<'a> Args<'a> {
@@ -121,6 +123,7 @@ impl<'a> Args<'a> {
121123
let mut board = None;
122124
let mut config = None;
123125
let mut output_image_type = None;
126+
let mut override_kernel = None;
124127

125128
if args.len() <= 1 {
126129
print_usage();
@@ -198,6 +201,17 @@ impl<'a> Args<'a> {
198201
std::process::exit(1);
199202
}
200203
}
204+
"--override-kernel" => {
205+
if i < args.len() - 1 {
206+
override_kernel = Some(args[i + 1].as_str());
207+
i += 1;
208+
} else {
209+
eprintln!(
210+
"microkit: error: argument --override-kernel: expected one argument"
211+
);
212+
std::process::exit(1);
213+
}
214+
}
201215
_ => {
202216
if in_search_path {
203217
search_paths.push(&args[i]);
@@ -252,6 +266,7 @@ impl<'a> Args<'a> {
252266
output,
253267
search_paths,
254268
output_image_type,
269+
override_kernel,
255270
}
256271
}
257272
}
@@ -339,7 +354,10 @@ fn main() -> Result<(), String> {
339354
.join(args.config)
340355
.join("elf");
341356
let loader_elf_path = elf_path.join("loader.elf");
342-
let kernel_elf_path = elf_path.join("sel4.elf");
357+
let kernel_elf_path = match args.override_kernel {
358+
Some(path) => Path::new(path),
359+
None => &elf_path.join("sel4.elf"),
360+
};
343361
let monitor_elf_path = elf_path.join("monitor.elf");
344362
let capdl_init_elf_path = elf_path.join("initialiser.elf");
345363

@@ -596,7 +614,7 @@ fn main() -> Result<(), String> {
596614
match kernel_config.arch {
597615
Arch::X86_64 => (None, None, None),
598616
Arch::Aarch64 | Arch::Riscv64 => {
599-
let kernel_elf = ElfFile::from_path(&kernel_elf_path).unwrap_or_else(|e| {
617+
let kernel_elf = ElfFile::from_path(kernel_elf_path).unwrap_or_else(|e| {
600618
eprintln!(
601619
"ERROR: failed to parse kernel ELF ({}): {}",
602620
kernel_elf_path.display(),
@@ -921,7 +939,7 @@ fn main() -> Result<(), String> {
921939
Ok(size) => {
922940
// Copy the kernel to the build directory as well so users doesn't have to dig through the SDK.
923941
if let Err(copy_err) = fs::copy(
924-
&kernel_elf_path,
942+
kernel_elf_path,
925943
image_out_path.parent().unwrap().join(KERNEL_COPY_FILENAME),
926944
) {
927945
eprintln!("ERROR: couldn't copy the kernel to image's output directory: {copy_err}");

0 commit comments

Comments
 (0)