Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
67 commits
Select commit Hold shift + click to select a range
b55c56d
[targets/magia_v2] Add spatz as sub-target for magia_v2
callme-sam Feb 4, 2026
3ec966c
[cmake] Add cmake file for spatz configuration
callme-sam Feb 4, 2026
7490645
[cmake] Add spatz helper cmake functions
callme-sam Feb 5, 2026
06f001a
[cmake] Add bootrom cmake helper functions
callme-sam Feb 5, 2026
3b492bd
[scripts] s19tomeme.py: Fix data memory start address and size
callme-sam Feb 5, 2026
599930a
[scripts] Add python scripts to generate spatz header from binary and…
callme-sam Feb 5, 2026
c88461c
Update main CMakeLists.txt to include Spatz helper files
callme-sam Feb 5, 2026
f242c53
[scripts] update scripts permission (755)
callme-sam Feb 5, 2026
8714040
[test] Import utils from MAGIA
callme-sam Feb 5, 2026
55985c5
[cmake] Add utils to spatz task compilation
callme-sam Feb 5, 2026
6dc527a
[cmake] Add default linker and crt0 files for spatz
callme-sam Feb 5, 2026
e1e2ba0
[test/spatz_on_magia] Add hello world test
callme-sam Feb 5, 2026
375bcbc
[cmake] Fix spatz cmake configuration
callme-sam Feb 5, 2026
2fb3641
[cmake] bootrom_helpers.cmake: Fix function name and create build if …
callme-sam Feb 10, 2026
87a9272
[cmake] spatz_helpers: Fix build output directory
callme-sam Feb 10, 2026
693dfbd
[test/spatz_on_magia] hello_spatz: fix build output dir
callme-sam Feb 10, 2026
ae198b5
[targets/magia_v2] Build spatz bootrom only if sptaz tests are included
callme-sam Feb 10, 2026
ae1afe3
[test] CMakeLists: modify mapping to support Spatz tests
callme-sam Feb 10, 2026
f371a57
Makefile: Add support for spatz tests compilation
callme-sam Feb 10, 2026
3fa52fc
[cmake] spatz_config: cleanup
callme-sam Feb 10, 2026
6b9b746
[scripts] update parse_s19
callme-sam Feb 10, 2026
e57c924
[test/spatz_on_magia] WIP refactor
callme-sam Feb 10, 2026
da2b240
[cmake] spatz_helpers: Better header with binary array generation
callme-sam Feb 11, 2026
f6cc96b
[cmake] fix compilation of Spatz's crt0.S
callme-sam Feb 11, 2026
29b2f60
[tests/spatz_on_magia] hello_stpatz: complete refactor
callme-sam Feb 11, 2026
ba93a2b
[tests/spatz_on_magia] Add double task test
callme-sam Feb 11, 2026
4178033
[test/utils] removed unnecessary header files
callme-sam Feb 12, 2026
2d602ef
[cmake] spatz_config: change ISA extension for CV32 to imcxgap9
callme-sam Feb 12, 2026
aa0786a
[tests/magia/mesh] CMakeLists: compile "amo" test only if target is m…
callme-sam Feb 12, 2026
365e604
[tests/spatz_on_magia] Add onnx add test
callme-sam Feb 12, 2026
7a2e820
[targets/magia_v2] tile_add_map: change number of tiles to 1
callme-sam Feb 13, 2026
129f899
[cmake] spatz_helpers.cmake: Improve Spatz task build logic
callme-sam Feb 13, 2026
f0a04cd
[targets/magia_v2/include] Port utility header from MAGIA to magia v2
callme-sam Feb 16, 2026
079b714
[tests/spatz_on_magia/onnx_add] main: Fix len param in vector compare
callme-sam Feb 17, 2026
b7e3e58
[tests/spatz_on_magia/onnx_add] onnx_add_mem_layout: Map L1 memory ba…
callme-sam Feb 17, 2026
2197e0e
[targets/magia_v2] link.ld: Fix CV32 stack size
callme-sam Feb 17, 2026
2f3929b
[tests/spatz_on_magia] onnx_div: Add ONNX DIV test
callme-sam Feb 19, 2026
b6b5c0d
[tests/spatz_on_magia] onnx_add: Fix typo
callme-sam Feb 23, 2026
ef9bf73
[tests/spatz_on_magia]: onnx_div: Fix typo
callme-sam Feb 23, 2026
331d905
[magia_v2/include/utils] compare_utils: Use raw uint16_t for compare …
callme-sam Feb 23, 2026
f40ccda
[tests/spatz_on_magia] Add onnx clip test
callme-sam Feb 23, 2026
29bff40
[tests/spatz_on_magia] onnx_add: Refactor - use L1 for params
callme-sam Feb 23, 2026
d09fd3f
[tests/spatz_on_magia] onnx_div: Refactor - use L1 for params
callme-sam Feb 23, 2026
d6a80ff
[Makefile] Add rule to support gvsoc simulation for executables with …
callme-sam Feb 23, 2026
3228523
WIP - [cmake] Refactor compilation flow for spatz and add support for…
callme-sam Feb 26, 2026
9b6704c
[targets/magia_v2] compare_utils.h: Introduce tollerance in comparison
callme-sam Feb 26, 2026
22c8c2c
[Makefile] finalize refactor compilation flow for spatz and add suppo…
callme-sam Feb 26, 2026
a792fe3
[scripts] parse_s19.pl: Add execution permission
callme-sam Feb 26, 2026
a283f0e
[cmake] spatz_helper.cmake: re-introduce disassembly generation
callme-sam Feb 26, 2026
cabfa87
[Makefile] Add rule to download and build spatz llvm
callme-sam Feb 27, 2026
6e56ea1
[targets/magia_v2] spatz: Align SDK with recent RTL changes to fix Sp…
callme-sam Feb 27, 2026
7de237c
[targets/magia_v2] link.ld: Fix broken comment
callme-sam Feb 27, 2026
dc5990c
[targets/magia_v2] spatz: Align also magia_spat_utils.h SDK with rece…
callme-sam Feb 27, 2026
09b4084
[tests/spatz_on_magia] Removes unnecessary prints
callme-sam Feb 27, 2026
57e730b
Update README with spatz integration info
callme-sam Feb 27, 2026
ead118e
Makefile: Revert changes to MAGIA_DIR and BUILD_DIR and add a custom …
callme-sam Mar 3, 2026
f635d53
README: Added warning regarding potential inaccuracies in the MAGIA-S…
callme-sam Mar 3, 2026
550f194
[targets/magia_v2] utils: replace tinyprintf with printf for spatz tasks
callme-sam Mar 3, 2026
28e7bf2
[drivers] eventunit: Move Spatz-specific event functions to drivers
callme-sam Mar 4, 2026
889188a
[tests/spatz_on_magia] Remove double task example
callme-sam Mar 4, 2026
d925e39
[targets/magia_v2] utils: remove unnecessary utils
callme-sam Mar 4, 2026
108dd5e
[cmake] Refactor and cleanup of Spatz cmake files
callme-sam Mar 6, 2026
ff5c2fc
[targets/magia_v2] magile_tile_utils: remove unused APIs
callme-sam Mar 6, 2026
89eaf35
[targets/magia_v2] removes unused spatz_perf_counters header file
callme-sam Mar 6, 2026
fff7314
[targets/mavia_v2] move compare_utils from targets/../utils to tests
callme-sam Mar 6, 2026
02d10a6
[drivers] eventunit: Fix return value for eu_spatz_wait
callme-sam Mar 6, 2026
2616a62
[test/common] compare_utils: Refactor compare logic to use ULP and mo…
callme-sam Mar 11, 2026
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -23,3 +23,4 @@ testsuite.py
test.conf
testsuite*
testlogs/
llvm/
9 changes: 7 additions & 2 deletions CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ set(CMAKE_EXPORT_COMPILE_COMMANDS TRUE)
set(CMAKE_VERBOSE_MAKEFILE TRUE)

set(CMAKE_EXE_LINKER_FLAGS_INIT "--specs=nosys.specs")
set(CMAKE_LINK_LIBRARY_USING_WHOLE_ARCHIVE
set(CMAKE_LINK_LIBRARY_USING_WHOLE_ARCHIVE
"-Wl,--whole-archive <LIBRARY> -Wl,--no-whole-archive"
)
set(CMAKE_LINK_LIBRARY_USING_WHOLE_ARCHIVE_SUPPORTED True)
Expand Down Expand Up @@ -57,6 +57,11 @@ endif()

include(${CMAKE_CURRENT_LIST_DIR}/cmake/utils.cmake)

# Spatz support
include(${CMAKE_CURRENT_SOURCE_DIR}/cmake/spatz_config.cmake)
include(${CMAKE_CURRENT_SOURCE_DIR}/cmake/spatz_helpers.cmake)
include(${CMAKE_CURRENT_SOURCE_DIR}/cmake/bootrom_helpers.cmake)

################################################################################
# Add subdirectories #
################################################################################
Expand All @@ -74,4 +79,4 @@ add_subdirectory(drivers)
# Testing #
################################################################################

add_subdirectory(tests)
add_subdirectory(tests)
80 changes: 72 additions & 8 deletions Makefile
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
# Copyright (C) 2025 ETH Zurich and University of Bologna
#
# Licensed under the Solderpad Hardware License, Version 0.51
# (the "License"); you may not use this file except in compliance
# Licensed under the Solderpad Hardware License, Version 0.51
# (the "License"); you may not use this file except in compliance
# with the License. You may obtain a copy of the License at
#
# http://www.apache.org/licenses/LICENSE-2.0
Expand All @@ -15,13 +15,15 @@
#
# Authors: Victor Isachi <victor.isachi@unibo.it>
# Alberto Dequino <alberto.dequino@unibo.it>
#
#
# Magia-sdk Makefile

SHELL := /bin/bash

BUILD_DIR ?= ../sw/tests/$(test)
MAGIA_DIR ?= ../
MAGIA_DIR_ABS ?= $(abspath $(MAGIA_DIR))
BUILD_DIR_ABS ?= $(MAGIA_DIR_ABS)/sw/tests/$(test)
GVSOC_DIR ?= ./gvsoc
CURR_DIR ?= $(shell pwd)
GVSOC_ABS_PATH ?= $(CURR_DIR)/gvsoc
Expand All @@ -46,6 +48,15 @@ compiler ?= GCC_PULP
ISA ?= rv32imcxgap9
gui ?= 0
tiles ?= 2
spatz_tests ?= 1

LLVM_CMAKE ?= cmake
LLVM_DIR ?= llvm
LLVM_REPO ?= git@github.com:pulp-platform/llvm-project.git
LLVM_COMMIT ?= b494f2d8dde88723026db8ec16ac6c7ee1e140ca
LLVM_INSTALL_DIR ?= $(CURR_DIR)/llvm/install
LLVM_BUILD_DIR ?= $(LLVM_DIR)/llvm-project/build
LLVM_JOBS ?= 8

tiles_2 := $(shell echo $$(( $(tiles) * $(tiles) )))
tiles_log := $(shell awk 'BEGIN { printf "%.0f", log($(tiles_2))/log(2) }')
Expand Down Expand Up @@ -79,13 +90,13 @@ ifeq ($(compiler), GCC_MULTILIB)
sed -i -E 's/^#add_subdirectory\(flatatt\)/add_subdirectory\(flatatt\)/' ./tests/magia/mesh/CMakeLists.txt
sed -i -E 's/^\/\/#include "utils\/attention_utils.h"/#include "utils\/attention_utils.h"/' ./targets/$(target_platform)/include/tile.h
endif
cmake -DTARGET_PLATFORM=$(target_platform) -DEVAL=$(eval) -DSTALLING=$(stalling) -DFSYNC_MM=$(fsync_mm) -DIDMA_MM=$(idma_mm) -DREDMULE_MM=$(redmule_mm) -DCOMPILER=$(compiler) -DPROFILE_CMP=$(profile_cmp) -DPROFILE_CMI=$(profile_cmi) -DPROFILE_CMO=$(profile_cmo) -DPROFILE_SNC=$(profile_snc) -B build --trace-expand
cmake -DTARGET_PLATFORM=$(target_platform) -DEVAL=$(eval) -DSTALLING=$(stalling) -DFSYNC_MM=$(fsync_mm) -DIDMA_MM=$(idma_mm) -DREDMULE_MM=$(redmule_mm) -DCOMPILER=$(compiler) -DPROFILE_CMP=$(profile_cmp) -DPROFILE_CMI=$(profile_cmi) -DPROFILE_CMO=$(profile_cmo) -DPROFILE_SNC=$(profile_snc) -DSPATZ_TESTS=$(spatz_tests) -DSPATZ_LLVM_PATH=$(LLVM_INSTALL_DIR) -B build --trace-expand
cmake --build build --verbose

set_mesh:
ifeq ($(tiles), 1)
$(eval mesh_dv=0)
endif
endif

run: set_mesh
@echo 'Magia is available at https://github.com/pulp-platform/MAGIA.git'
Expand All @@ -107,10 +118,10 @@ else ifeq ($(platform), rtl)
cp ./build/bin/$(test) $(BUILD_DIR)/build/verif
objcopy --srec-len 1 --output-target=srec $(BIN) $(BIN).s19
scripts/parse_s19.pl $(BIN).s19 > $(BIN).txt
python3 scripts/s19tomem.py $(BIN).txt $(BUILD_DIR)/build/stim_instr.txt $(BUILD_DIR)/build/stim_data.txt
python3 scripts/s19tomem.py $(BIN).txt $(BUILD_DIR)/build/stim_instr.txt $(BUILD_DIR)/build/stim_data.txt
cd $(BUILD_DIR) && \
cp -sf ../../../sim/modelsim.ini modelsim.ini && \
ln -sfn ../../../sim/work work
ln -sfn ../../../sim/work work
riscv32-unknown-elf-objdump -d -S -Mmarch=$(ISA) $(BIN) > $(BIN).dump
riscv32-unknown-elf-objdump -d -l -s -Mmarch=$(ISA) $(BIN) > $(BIN).objdump
python3 scripts/objdump2itb.py $(BIN).objdump > $(BIN).itb
Expand All @@ -120,6 +131,36 @@ else
$(error Only rtl and gvsoc are supported as platforms.)
endif

run_with_spatz: set_mesh
ifndef test
$(error Proper formatting is: make run_with_spatz test=<test_name> platform=<rtl|gvsoc>)
endif
ifeq (,$(wildcard ./build/bin/$(test)))
$(error No test found with name: $(test))
endif
ifndef platform
$(error Proper formatting is: make run_with_spatz test=<test_name> platform=rtl|gvsoc)
endif
ifeq ($(platform), gvsoc)
$(GVSOC_DIR)/install/bin/gvrun --target magia_v2 --work-dir $(GVSOC_ABS_PATH)/Documents/test --param binary=$(BIN_ABS_PATH)/$(test) run --attr magia/n_tiles_x=$(tiles) --attr magia/n_tiles_y=$(tiles) --attr magia_v2/spatz_romfile=$(BIN_ABS_PATH)/bootrom/spatz_init.bin
else ifeq ($(platform), rtl)
mkdir -p $(BUILD_DIR_ABS) && cd $(BUILD_DIR_ABS) && mkdir -p build
cp ./build/bin/$(test) $(BUILD_DIR_ABS)/build/verif
objcopy --srec-len 1 --output-target=srec $(BUILD_DIR_ABS)/build/verif $(BUILD_DIR_ABS)/build/verif.s19
scripts/parse_s19.pl $(BUILD_DIR_ABS)/build/verif.s19 > $(BUILD_DIR_ABS)/build/verif.txt
python3 scripts/s19tomem.py $(BUILD_DIR_ABS)/build/verif.txt $(BUILD_DIR_ABS)/build/stim_instr.txt $(BUILD_DIR_ABS)/build/stim_data.txt
cd $(BUILD_DIR_ABS) && \
cp -sf "$(MAGIA_DIR_ABS)/sim/modelsim.ini" modelsim.ini && \
ln -sfn "$(MAGIA_DIR_ABS)/sim/work" work
riscv32-unknown-elf-objdump -d -S -Mmarch=$(ISA) $(BUILD_DIR_ABS)/build/verif > $(BUILD_DIR_ABS)/build/verif.dump
riscv32-unknown-elf-objdump -d -l -s -Mmarch=$(ISA) $(BUILD_DIR_ABS)/build/verif > $(BUILD_DIR_ABS)/build/verif.objdump
python3 scripts/objdump2itb.py $(BUILD_DIR_ABS)/build/verif.objdump > $(BUILD_DIR_ABS)/build/verif.itb
cd $(MAGIA_DIR_ABS) && \
make run test=$(test) gui=$(gui) mesh_dv=$(mesh_dv)
else
$(error Only rtl and gvsoc are supported as platforms.)
endif

MAGIA: set_mesh
ifeq ($(shell expr $(tiles_2) \> 256), 1)
$(eval tiles_2=256)
Expand Down Expand Up @@ -175,4 +216,27 @@ gvsoc_init:
cd ../pulp && \
git checkout lz/magia-v2-pulp


llvm:
mkdir -p $(LLVM_DIR)
if [ ! -d "$(LLVM_DIR)/llvm-project/.git" ]; then \
cd $(LLVM_DIR) && git clone $(LLVM_REPO); \
fi
cd $(LLVM_DIR)/llvm-project && \
git checkout $(LLVM_COMMIT) && \
git submodule update --init --recursive --jobs=$(LLVM_JOBS) .
mkdir -p $(LLVM_INSTALL_DIR)
cd $(LLVM_DIR)/llvm-project && mkdir -p build && cd build && \
$(LLVM_CMAKE) \
-DCMAKE_INSTALL_PREFIX=$(LLVM_INSTALL_DIR) \
-DCMAKE_CXX_COMPILER=${CXX} \
-DCMAKE_C_COMPILER=${CC} \
-DLLVM_OPTIMIZED_TABLEGEN=True \
-DLLVM_ENABLE_PROJECTS="clang;lld" \
-DLLVM_TARGETS_TO_BUILD="RISCV" \
-DLLVM_DEFAULT_TARGET_TRIPLE=riscv32-unknown-elf \
-DLLVM_ENABLE_LLD=False \
-DLLVM_APPEND_VC_REV=ON \
-DCMAKE_BUILD_TYPE=Release \
../llvm && \
make -j$(LLVM_JOBS) all && \
make install
87 changes: 80 additions & 7 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,8 @@ The following *optional* parameters can be specified when running the make comma

`profile_cmp|cmi|cmo|snc`: **0**|**1** (**Default**: 0). Activates the profiling utilities for computing|comunication(input line)|comunication(output line)|synchronization

`spatz_tests`: **0**|**1** (**Default**: 1). Enable compilation of tests with Spatz task (along with default mesh tests)

0. In case you are using this SDK as non-submodule: Clone the [MAGIA](https://github.com/pulp-platform/MAGIA/tree/main) repository:

`git clone git@github.com:pulp-platform/MAGIA.git`
Expand All @@ -51,9 +53,9 @@ The following *optional* parameters can be specified when running the make comma
1. Initialize the GVSoC submodule:

`make gvsoc_init`

2. Build the Magia architecture (*this command may take time and return an error, please be patient.*):

`make MAGIA <target_platform> <tiles> <build_mode> <fsync_mode>`

And/Or the GVSoC module:
Expand Down Expand Up @@ -90,7 +92,7 @@ The following *optional* parameters can be specified when running the make comma

`make run test=<test_name> <platform>`

***WARNING: YOU HAVE TO REBUILD BOTH RTL/GVSOC AND THE TEST BINARY EACH TIME YOU WANT TO TEST A MAGIA MESH WITH A DIFFERENT NUMBER OF TILES.***
***WARNING: YOU HAVE TO REBUILD BOTH RTL/GVSOC AND THE TEST BINARY EACH TIME YOU WANT TO TEST A MAGIA MESH WITH A DIFFERENT NUMBER OF TILES.***

If you want to run gvsoc or a binary from outside the magia-sdk directory you can edit the **GVSOC_ABS_PATH** and **BIN_ABS_PATH** option in Makefile or directly on the *run* command line.

Expand Down Expand Up @@ -122,7 +124,7 @@ To add your own test, you have to integrate a new test folder inside the **tests
4. Add to the *\<test_name\>* directory:

1. A new CMakeList.txt file following this template:

set(TEST_NAME <test_name>)

file(GLOB_RECURSE TEST_SRCS
Expand All @@ -142,11 +144,83 @@ To add your own test, you have to integrate a new test folder inside the **tests
TARGET ${TEST_NAME}
POST_BUILD
COMMAND ${CMAKE_OBJDUMP} -dhS -Mmarch=${ISA} $<TARGET_FILE:${TEST_NAME}> > $<TARGET_FILE:${TEST_NAME}>.s)

2. An **src** directory containing your test's source (.c) files

3. An **include** directory containing your test's header (.h) files

## Spatz integration in MAGIA

This SDK provides a flow to compile C code for the Spatz vector accelerator, embed the resulting binary into the main CV32 executable, and manage the execution. This allows the main RISC-V core (CV32) to offload tasks to the Spatz accelerator.

Examples using this flow are available in the `tests/spatz_on_magia/` directory. Each test sub-folder contains a `main.c` for the CV32 host and a `spatz_task/` directory with the source code for the Spatz accelerator.

For more informations about hardware integration, configuration parameters, control interface, programming APIs and execution flow please refer to the [MAGIA-Spatz README](https://github.com/pulp-platform/MAGIA/tree/lb/magia-spatz/spatz)

> **Warning:** The external README linked above is tailored for baremetal hardware development. Some information may overlap or contain minor inaccuracies regarding the specific abstractions and automation provided by this SDK.

### Prerequisites

The compilation flow requires a dedicated Spatz LLVM toolchain.
You can install it automatically by running the following command from the SDK root:

```sh
make llvm
```
This will clone the required repository and build the toolchain in the `llvm/install` directory. Alternatively, if you have a pre-built toolchain, you can specify its location by passing the `LLVM_INSTALL_DIR` variable to the make command:
```sh
make build LLVM_INSTALL_DIR=/path/to/your/llvm/install
```

### Compilation Flow

The compilation process is managed by two CMake functions defined in `cmake/spatz_helpers.cmake`: `add_spatz_task` and `add_cv32_executable_with_spatz`.

#### 1. `add_spatz_task`
This function compiles the C code for the Spatz accelerator and prepares it for embedding.

* **What it does**:
1. Compiles the Spatz source code into an ELF binary using a dedicated `clang` compiler from the Spatz LLVM toolchain.
2. Converts the ELF file into a raw binary format (`.bin`).
3. Uses the `scripts/bin2header.py` script to transform the raw binary into a C header file. This header contains a `uint32_t` array holding the machine code of the Spatz task. This array is placed in a special linker section named `.spatz_binary`.
4. Runs the `scripts/extract_task_symbols.sh` script to append additional information to the header. This script inspects the Spatz ELF file and extracts the addresses of key symbols, defining them as macros. These symbols include:
* `SPATZ_BINARY_START`: The starting memory address where the Spatz binary will be loaded. This is resolved by the CV32 linker.
* `SPATZ_DISPATCHER_LOOP`: The entry point for the Spatz control loop.
* Task function addresses (e.g., `MY_TASK`): Entry points for specific functions within the Spatz code that can be called from the CV32 host.

#### 2. `add_cv32_executable_with_spatz`
This function compiles the main application for the CV32 core and embeds the Spatz binary within it.

* **What it does**:
1. Compiles the C source code for the CV32 processor.
2. Includes the header file generated by `add_spatz_task`. By including this header, the Spatz binary (as a C array) becomes part of the CV32 application's source.
3. Links the compiled CV32 code with the Spatz binary data. The main linker script (`targets/magia_v2/link.ld`) ensures that the `.spatz_binary` section is placed at the correct memory address.

### Example Usage
To use this flow, you need to call the two functions in your `CMakeLists.txt`. The convention is to have separate sources for the host (CV32) and the accelerator (Spatz).

Here is an example from `tests/spatz_on_magia/hello_spatz/CMakeLists.txt`:
```cmake
set(TEST_NAME hello_spatz)

# Step 1: Compile the Spatz task and generate the C header
add_spatz_task(
TEST_NAME ${TEST_NAME}
TASK_SOURCES ${CMAKE_CURRENT_SOURCE_DIR}/spatz_task/hello_task.c
FIRST_TASK_NAME hello_task
)

# Step 2: Compile the CV32 executable and embed the Spatz binary
add_cv32_executable_with_spatz(
TARGET_NAME ${TEST_NAME}
SPATZ_HEADER ${SPATZ_HEADER}
SOURCES ${CMAKE_CURRENT_SOURCE_DIR}/main.c
)
```

### Run Tests
To run test a special Makefile rule can be used: `make run_with_spatz test=<test_name> platform=<rtl|gvsoc>`.

## Folder Structure

### README.md
Expand All @@ -171,7 +245,7 @@ Contains the weak definitions of this SDK APIs. These are the API instruction th
Contains the architecture-specific implementation and source code for the HAL APIs. Despite each implementation having different names, thanks to an aliasing system the programmer can use the same name for the same API instruction on different architectures.

### devices
Nothing there.
Nothing there.

If MAGIA ever evolves to have a host-offload mechanism, this folder will contain the trampoline functions.

Expand All @@ -180,4 +254,3 @@ Contains utility files for *cmake* automatic compilation.

### gvsoc
A submodule containing the Germain Virtual System on Chip, built to simulate MAGIA (and other PULP-related platforms).

43 changes: 43 additions & 0 deletions cmake/bootrom_helpers.cmake
Original file line number Diff line number Diff line change
@@ -0,0 +1,43 @@
# Spatz bootrom compilation helpers

# add_spatz_bootrom()
# Builds the Spatz bootrom artifacts (ELF/BIN/DUMP).
function(add_spatz_bootrom)
file(MAKE_DIRECTORY "${SPATZ_BOOTROM_OUTPUT_DIR}")

# Compile bootrom ELF [MAGIA/spatz/bootrom/Makefile: $(ELF)]
add_custom_command(
OUTPUT ${SPATZ_BOOTROM_ELF}
COMMAND ${SPATZ_CLANG}
${SPATZ_COMPILE_FLAGS}
${SPATZ_CFLAGS_DEFINES}
${SPATZ_LINK_FLAGS}
-T${SPATZ_BOOTROM_LINK_SCRIPT}
-o ${SPATZ_BOOTROM_ELF}
${SPATZ_BOOTROM_SRC}
DEPENDS ${SPATZ_BOOTROM_SRC} ${SPATZ_BOOTROM_LINK_SCRIPT}
COMMENT "[SPATZ-BOOTROM] Compiling bootrom ELF..."
VERBATIM
)

# Extract binary [MAGIA/spatz/bootrom/Makefile: $(BIN)]
add_custom_command(
OUTPUT ${SPATZ_BOOTROM_BIN}
COMMAND ${SPATZ_OBJCOPY} -O binary ${SPATZ_BOOTROM_ELF} ${SPATZ_BOOTROM_BIN}
DEPENDS ${SPATZ_BOOTROM_ELF}
COMMENT "[SPATZ-BOOTROM] Generating bootrom binary..."
VERBATIM
)

# Generate disassembly [MAGIA/spatz/bootrom/Makefile: $(DUMP)]
add_custom_command(
OUTPUT ${SPATZ_BOOTROM_DUMP}
COMMAND ${SPATZ_OBJDUMP} -D ${SPATZ_BOOTROM_ELF} > ${SPATZ_BOOTROM_DUMP}
DEPENDS ${SPATZ_BOOTROM_ELF}
COMMENT "[SPATZ-BOOTROM] Generating disassembly..."
VERBATIM
)

add_custom_target(spatz_bootrom ALL DEPENDS ${SPATZ_BOOTROM_BIN} ${SPATZ_BOOTROM_DUMP})
set(SPATZ_BOOTROM_BIN ${SPATZ_BOOTROM_BIN} PARENT_SCOPE)
endfunction()
Loading