-
Notifications
You must be signed in to change notification settings - Fork 71
Add support for prefilling memory regions from data files at compile time #434
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Open
dreamliner787-9
wants to merge
3
commits into
seL4:main
Choose a base branch
from
au-ts:issue_248
base: main
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Open
Changes from all commits
Commits
Show all changes
3 commits
Select commit
Hold shift + click to select a range
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,68 @@ | ||
| # | ||
| # Copyright 2026, UNSW | ||
| # | ||
| # SPDX-License-Identifier: BSD-2-Clause | ||
| # | ||
| ifeq ($(strip $(BUILD_DIR)),) | ||
| $(error BUILD_DIR must be specified) | ||
| endif | ||
|
|
||
| ifeq ($(strip $(MICROKIT_SDK)),) | ||
| $(error MICROKIT_SDK must be specified) | ||
| endif | ||
|
|
||
| ifeq ($(strip $(MICROKIT_BOARD)),) | ||
| $(error MICROKIT_BOARD must be specified) | ||
| endif | ||
|
|
||
| ifeq ($(strip $(MICROKIT_CONFIG)),) | ||
| $(error MICROKIT_CONFIG must be specified) | ||
| endif | ||
|
|
||
| BOARD_DIR := $(MICROKIT_SDK)/board/$(MICROKIT_BOARD)/$(MICROKIT_CONFIG) | ||
|
|
||
| ARCH := ${shell grep 'CONFIG_SEL4_ARCH ' $(BOARD_DIR)/include/kernel/gen_config.h | cut -d' ' -f4} | ||
|
|
||
| ifeq ($(ARCH),aarch64) | ||
| TARGET_TRIPLE := aarch64-none-elf | ||
| CFLAGS_ARCH := -mstrict-align | ||
| else ifeq ($(ARCH),riscv64) | ||
| TARGET_TRIPLE := riscv64-unknown-elf | ||
| CFLAGS_ARCH := -march=rv64imafdc_zicsr_zifencei -mabi=lp64d | ||
| else ifeq ($(ARCH),x86_64) | ||
| TARGET_TRIPLE := x86_64-linux-gnu | ||
| CFLAGS_ARCH := -march=x86-64 -mtune=generic | ||
| else | ||
| $(error Unsupported ARCH) | ||
| endif | ||
|
|
||
| ifeq ($(strip $(LLVM)),True) | ||
| CC := clang -target $(TARGET_TRIPLE) | ||
| AS := clang -target $(TARGET_TRIPLE) | ||
| LD := ld.lld | ||
| else | ||
| CC := $(TARGET_TRIPLE)-gcc | ||
| LD := $(TARGET_TRIPLE)-ld | ||
| AS := $(TARGET_TRIPLE)-as | ||
| endif | ||
|
|
||
| MICROKIT_TOOL ?= $(MICROKIT_SDK)/bin/microkit | ||
|
|
||
| IMAGES := mr_prefill.elf | ||
| CFLAGS := -nostdlib -ffreestanding -g3 -O3 -I$(BOARD_DIR)/include $(CFLAGS_ARCH) | ||
| LDFLAGS := -L$(BOARD_DIR)/lib -z noexecstack | ||
| LIBS := -lmicrokit -Tmicrokit.ld | ||
|
|
||
| IMAGE_FILE = $(BUILD_DIR)/loader.img | ||
| REPORT = $(BUILD_DIR)/report.txt | ||
|
|
||
| all: $(IMAGE_FILE) | ||
|
|
||
| $(BUILD_DIR)/mr_prefill.o: mr_prefill.c Makefile | ||
| $(CC) -c $(CFLAGS) -Wall -Wno-unused-function -Werror $< -o $@ | ||
|
|
||
| $(BUILD_DIR)/mr_prefill.elf: $(BUILD_DIR)/mr_prefill.o | ||
| $(LD) $(LDFLAGS) $^ $(LIBS) -o $@ | ||
|
|
||
| $(IMAGE_FILE): $(addprefix $(BUILD_DIR)/, $(IMAGES)) mr_prefill.system | ||
| $(MICROKIT_TOOL) mr_prefill.system --search-path $(BUILD_DIR) --board $(MICROKIT_BOARD) --config $(MICROKIT_CONFIG) -o $(IMAGE_FILE) -r $(REPORT) |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,20 @@ | ||
| <!-- | ||
| Copyright 2026, UNSW | ||
| SPDX-License-Identifier: CC-BY-SA-4.0 | ||
| --> | ||
| # Example - Memory Region Prefill | ||
|
|
||
| This is an example demostrating prefilling a memory region from a data file at compile time. | ||
|
|
||
| All Microkit platforms are supported. | ||
|
|
||
| ## Building | ||
|
|
||
| ```sh | ||
| mkdir build | ||
| make BUILD_DIR=build MICROKIT_BOARD=<board> MICROKIT_CONFIG=<debug/release/benchmark> MICROKIT_SDK=/path/to/sdk | ||
| ``` | ||
|
|
||
| ## Running | ||
|
|
||
| See instructions for your board in the manual. | ||
Binary file not shown.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,85 @@ | ||
| /* | ||
| * Copyright 2026, UNSW | ||
| * | ||
| * SPDX-License-Identifier: BSD-2-Clause | ||
| */ | ||
| #include <stdint.h> | ||
| #include <microkit.h> | ||
|
|
||
| #define BEGIN_MAGIC 0x53145314 | ||
| #define VALUE_A 0x01234567 | ||
| #define VALUE_B 0x89ABCDEF | ||
| #define END_MAGIC 0x75757575 | ||
|
|
||
| typedef struct __attribute__((packed)) fill_data { | ||
| uint32_t begin_magic; | ||
| uint32_t value_a; | ||
| uint8_t _padding1[0x400]; | ||
| uint32_t value_b; | ||
| uint8_t _padding2[0xc00]; | ||
| uint32_t end_magic; | ||
| } fill_data_t; | ||
|
|
||
| fill_data_t *filled_mr; | ||
| uint64_t filled_mr_data_size; | ||
|
|
||
| void init(void) | ||
| { | ||
| microkit_dbg_puts("hello, world. my name is "); | ||
| microkit_dbg_puts(microkit_name); | ||
| microkit_dbg_puts("\n"); | ||
|
|
||
| microkit_dbg_puts("checking prefilled memory region data length\n"); | ||
| if (filled_mr_data_size != sizeof(fill_data_t)) { | ||
| microkit_dbg_puts("oh no prefilled data length doesn't match: "); | ||
| microkit_dbg_put32(filled_mr_data_size); | ||
| microkit_dbg_puts(" != "); | ||
| microkit_dbg_put32(sizeof(fill_data_t)); | ||
| microkit_dbg_puts("\n"); | ||
| return; | ||
| } | ||
|
|
||
| microkit_dbg_puts("checking prefilled memory region data\n"); | ||
|
|
||
| if (filled_mr->begin_magic != BEGIN_MAGIC) { | ||
| microkit_dbg_puts("oh no begin magic doesn't match: "); | ||
| microkit_dbg_put32(filled_mr->begin_magic); | ||
| microkit_dbg_puts(" != "); | ||
| microkit_dbg_put32(BEGIN_MAGIC); | ||
| microkit_dbg_puts("\n"); | ||
| return; | ||
| } | ||
|
|
||
| if (filled_mr->value_a != VALUE_A) { | ||
| microkit_dbg_puts("oh no value A doesn't match: "); | ||
| microkit_dbg_put32(filled_mr->value_a); | ||
| microkit_dbg_puts(" != "); | ||
| microkit_dbg_put32(VALUE_A); | ||
| microkit_dbg_puts("\n"); | ||
| return; | ||
| } | ||
|
|
||
| if (filled_mr->value_b != VALUE_B) { | ||
| microkit_dbg_puts("oh no value B doesn't match: "); | ||
| microkit_dbg_put32(filled_mr->value_b); | ||
| microkit_dbg_puts(" != "); | ||
| microkit_dbg_put32(VALUE_B); | ||
| microkit_dbg_puts("\n"); | ||
| return; | ||
| } | ||
|
|
||
| if (filled_mr->end_magic != END_MAGIC) { | ||
| microkit_dbg_puts("oh no end magic doesn't match: "); | ||
| microkit_dbg_put32(filled_mr->end_magic); | ||
| microkit_dbg_puts(" != "); | ||
| microkit_dbg_put32(END_MAGIC); | ||
| microkit_dbg_puts("\n"); | ||
| return; | ||
| } | ||
|
|
||
| microkit_dbg_puts("prefilled data OK!\n"); | ||
| } | ||
|
|
||
| void notified(microkit_channel ch) | ||
| { | ||
| } |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,15 @@ | ||
| <?xml version="1.0" encoding="UTF-8"?> | ||
| <!-- | ||
| Copyright 2026, UNSW | ||
|
|
||
| SPDX-License-Identifier: BSD-2-Clause | ||
| --> | ||
| <system> | ||
| <memory_region name="prefilled" prefill_path="fill.bin" /> | ||
|
|
||
| <protection_domain name="mr_prefill" priority="100" > | ||
| <program_image path="mr_prefill.elf" /> | ||
|
|
||
| <map mr="prefilled" vaddr="0x20000000" setvar_vaddr="filled_mr" setvar_prefill_size="filled_mr_data_size"/> | ||
| </protection_domain> | ||
| </system> |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
typo