Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
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
2 changes: 1 addition & 1 deletion doc/ref/dev_guide.md
Original file line number Diff line number Diff line change
Expand Up @@ -149,7 +149,7 @@ ctest --test-dir build/sw -R fpga_genesys2

To run CHERI Linux on the Genesys 2 board, run:
```sh
util/fpga_runner.py run -e build/sw/opensbi_with_uboot/opensbi_with_uboot_fw_payload.elf -f build/sw/linux/linux_image 0x90000000 -f build/sw/rootfs_uboot_image 0xa0000000
util/fpga_runner.py run -e build/sw/opensbi/opensbi_fw_jump.elf -e build/sw/uboot/u-boot -f build/sw/linux/linux_image 0x90000000 -f build/sw/rootfs_uboot_image 0xa0000000
```

### Standalone UART
Expand Down
84 changes: 32 additions & 52 deletions sw/cmake/opensbi.cmake
Original file line number Diff line number Diff line change
Expand Up @@ -2,17 +2,8 @@
# Licensed under the Apache License, Version 2.0, see LICENSE for details.
# SPDX-License-Identifier: Apache-2.0

# Function that builds OpenSBI with a specific payload for Mocha.
function(mocha_opensbi_with_payload)
set(options TEST)
set(one_value_args TARGET)
cmake_parse_arguments(arg "${options}" "${one_value_args}" "" ${ARGN})

# find the target payload file.
set(PAYLOAD "$<TARGET_FILE:${arg_TARGET}>.bin")
# name of the target OpenSBI build.
set(NAME opensbi_with_${arg_TARGET})

# Function that builds OpenSBI for Mocha.
function(mocha_opensbi OPENSBI_NAME)
# OpenSBI repository and tag to use.
set(OPENSBI_REPOSITORY https://github.com/lowrisc/opensbi)
set(OPENSBI_TAG mocha-devel)
Expand All @@ -30,11 +21,9 @@ function(mocha_opensbi_with_payload)
PLATFORM=generic
# Use the Mocha defconfig file.
PLATFORM_DEFCONFIG=mocha_defconfig
# Build a 'payload' firmware.
FW_PAYLOAD=y
FW_JUMP=n
# Build with the given payload.
FW_PAYLOAD_PATH=${PAYLOAD}
# Build a 'jump' firmware.
FW_JUMP=y
FW_PAYLOAD=n
# Disable position-independent code and link to DRAM base,
# as loading position-independent executables is not supported by
# our Verilator ELF loader.
Expand All @@ -47,16 +36,16 @@ function(mocha_opensbi_with_payload)
# Built firmware binary to copy into the root of the external project directory.
# This consists of OpenSBI + the provided payload for the next stage.
set(FIRMWARE
build/platform/generic/firmware/fw_payload.elf
build/platform/generic/firmware/fw_jump.elf
)

# install command - copy the firmware binaries to the root of the external project directory.
set(INSTALL_COMMAND
cp ${FIRMWARE} <INSTALL_DIR>/${NAME}_fw_payload.elf
cp ${FIRMWARE} <INSTALL_DIR>/${OPENSBI_NAME}_fw_jump.elf
)

ExternalProject_Add(
${NAME} PREFIX ${NAME}
${OPENSBI_NAME} PREFIX ${OPENSBI_NAME}
GIT_REPOSITORY ${OPENSBI_REPOSITORY}
GIT_TAG ${OPENSBI_TAG}
# OpenSBI builds in its own 'build' sub-directory.
Expand All @@ -66,8 +55,6 @@ function(mocha_opensbi_with_payload)
CONFIGURE_COMMAND "" # no configure step needed, do nothing here.
BUILD_COMMAND ${BUILD_COMMAND}
INSTALL_COMMAND ${INSTALL_COMMAND}
# depend on the given payload target.
DEPENDS ${PAYLOAD_TARGET}
# suppress output from stdout.
LOG_DOWNLOAD true
LOG_UPDATE true
Expand All @@ -79,46 +66,39 @@ function(mocha_opensbi_with_payload)
LOG_OUTPUT_ON_FAILURE true
)

add_dependencies(${NAME} ${arg_TARGET})

if(${arg_TEST})
install(FILES
${CMAKE_CURRENT_BINARY_DIR}/${NAME}/${NAME}_fw_payload.elf
DESTINATION .
COMPONENT ${NAME}
)
else()
install(FILES
${CMAKE_CURRENT_BINARY_DIR}/${NAME}/${NAME}_fw_payload.elf
DESTINATION .
COMPONENT boot
)
endif()
install(FILES
${CMAKE_CURRENT_BINARY_DIR}/${OPENSBI_NAME}/${OPENSBI_NAME}_fw_jump.elf
DESTINATION .
COMPONENT boot
)
endfunction()

# Like mocha_opensbi_with_payload, but also adds a test for
# Verilator and FPGA environments.
# TODO: Integrate this with the build system better.
function(mocha_opensbi_with_payload_test PAYLOAD_TARGET)
# name of the target OpenSBI build.
set(NAME opensbi_with_${PAYLOAD_TARGET})
function(mocha_opensbi_test OPENSBI_NAME TARGET_NAME)

mocha_opensbi_with_payload(TARGET ${PAYLOAD_TARGET} TEST)
add_dependencies(${TARGET_NAME} ${OPENSBI_NAME})
set(TEST_NAME opensbi_with_${TARGET_NAME})

add_test(
NAME ${NAME}_sim_verilator
COMMAND ${PROJECT_SOURCE_DIR}/../util/verilator_runner.sh -r $<TARGET_FILE:bootrom>_scrambled.vmem -E ${NAME}/${NAME}_fw_payload.elf
NAME ${TEST_NAME}_sim_verilator
COMMAND ${PROJECT_SOURCE_DIR}/../util/verilator_runner.sh
-r $<TARGET_FILE:bootrom>_scrambled.vmem
-E ${OPENSBI_NAME}/${OPENSBI_NAME}_fw_jump.elf
-E $<TARGET_FILE:${TARGET_NAME}>
)

add_test(
NAME ${NAME}_fpga_genesys2
COMMAND ${PROJECT_SOURCE_DIR}/../util/fpga_runner.py test -e ${NAME}/${NAME}_fw_payload.elf
NAME ${TEST_NAME}_fpga_genesys2
COMMAND ${PROJECT_SOURCE_DIR}/../util/fpga_runner.py test
-e ${OPENSBI_NAME}/${OPENSBI_NAME}_fw_jump.elf
-e $<TARGET_FILE:${TARGET_NAME}>
)

set_property(TEST ${NAME}_sim_verilator PROPERTY TIMEOUT 7200)
set_property(TEST ${NAME}_sim_verilator PROPERTY LABELS opensbi verilator slow)
set_property(TEST ${NAME}_fpga_genesys2 PROPERTY TIMEOUT 60)
set_property(TEST ${NAME}_fpga_genesys2 PROPERTY LABELS opensbi fpga)
set_property(TEST ${TEST_NAME}_sim_verilator PROPERTY TIMEOUT 7200)
set_property(TEST ${TEST_NAME}_sim_verilator PROPERTY LABELS opensbi verilator slow)
set_property(TEST ${TEST_NAME}_fpga_genesys2 PROPERTY TIMEOUT 60)
set_property(TEST ${TEST_NAME}_fpga_genesys2 PROPERTY LABELS opensbi fpga)
endfunction()

mocha_opensbi_with_payload_test(opensbi_test_payload)
mocha_opensbi(opensbi)

mocha_opensbi_test(opensbi opensbi_test_payload)
26 changes: 14 additions & 12 deletions sw/cmake/uboot.cmake
Original file line number Diff line number Diff line change
Expand Up @@ -3,8 +3,7 @@
# SPDX-License-Identifier: Apache-2.0

# Function that builds U-Boot, creating a target with the given output name.
function(mocha_uboot OUTPUT_NAME)
set(UBOOT_BUILD_NAME ${OUTPUT_NAME}_build)
function(mocha_uboot UBOOT_NAME)
# U-Boot repository and tag to use.
set(UBOOT_REPOSITORY https://github.com/lowrisc/u-boot)
set(UBOOT_TAG mocha-devel)
Expand All @@ -22,10 +21,15 @@ function(mocha_uboot OUTPUT_NAME)
"CC=clang -target riscv64-unknown-elf"
"LD=ld.lld"
)

# install command - copy the built U-Boot binary to the root of the external project directory.
set(INSTALL_COMMAND
cp u-boot <INSTALL_DIR>
)

ExternalProject_Add(
${UBOOT_BUILD_NAME}
PREFIX ${UBOOT_BUILD_NAME}
${UBOOT_NAME}
PREFIX ${UBOOT_NAME}
GIT_REPOSITORY ${UBOOT_REPOSITORY}
GIT_TAG ${UBOOT_TAG}
GIT_SHALLOW true
Expand All @@ -35,7 +39,7 @@ function(mocha_uboot OUTPUT_NAME)
BUILD_JOB_SERVER_AWARE true
CONFIGURE_COMMAND ${CONFIGURE_COMMAND}
BUILD_COMMAND ${BUILD_COMMAND}
INSTALL_COMMAND ""
INSTALL_COMMAND ${INSTALL_COMMAND}
# suppress output from stdout.
LOG_DOWNLOAD true
LOG_UPDATE true
Expand All @@ -47,13 +51,11 @@ function(mocha_uboot OUTPUT_NAME)
LOG_OUTPUT_ON_FAILURE true
)

add_executable(${OUTPUT_NAME} IMPORTED GLOBAL)
set_target_properties(${OUTPUT_NAME} PROPERTIES
IMPORTED_LOCATION ${CMAKE_CURRENT_BINARY_DIR}/${UBOOT_BUILD_NAME}/src/${UBOOT_BUILD_NAME}/u-boot
)
add_dependencies(${OUTPUT_NAME} ${UBOOT_BUILD_NAME})
install(FILES
${CMAKE_CURRENT_BINARY_DIR}/${UBOOT_NAME}/u-boot
DESTINATION .
COMPONENT boot
)
endfunction()

mocha_uboot(uboot)

mocha_opensbi_with_payload(TARGET uboot)
10 changes: 3 additions & 7 deletions sw/device/tests/opensbi/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -12,11 +12,7 @@ target_compile_options(${NAME} PUBLIC ${VANILLA_FLAGS})
# so that S-mode software can map itself into virtual memory
# using just a few large pages. This is a requirement for Linux too,
# see https://docs.kernel.org/arch/riscv/boot.html#kernel-location.
target_link_options(${NAME} PUBLIC "-Wl,--Ttext=0x80200000")
# Objcopy to a binary, to be used as the OpenSBI payload.
add_custom_command(
TARGET ${NAME} POST_BUILD
COMMAND ${CMAKE_OBJCOPY} -O binary "$<TARGET_FILE:${NAME}>"
"$<TARGET_FILE:${NAME}>.bin"
VERBATIM
target_link_options(${NAME} PUBLIC
"-Wl,--Ttext=0x80200000"
"-Tmocha_dram.ld" "-L${LDS_DIR}"
)
2 changes: 2 additions & 0 deletions sw/device/tests/opensbi/test_payload.S
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,9 @@

.section .text

.globl _init_vector
.globl _start
_init_vector:
_start:
/* Perform an SBI call to print test_status_string. */
li a7, SBI_DEBUG_CONSOLE
Expand Down