Skip to content

Commit

Permalink
align qemu-arm-virt
Browse files Browse the repository at this point in the history
  • Loading branch information
Axel Heider committed Apr 11, 2022
1 parent e4cdb9e commit 6e86a4d
Showing 1 changed file with 96 additions and 65 deletions.
161 changes: 96 additions & 65 deletions src/plat/qemu-arm-virt/config.cmake
Original file line number Diff line number Diff line change
Expand Up @@ -8,9 +8,12 @@ cmake_minimum_required(VERSION 3.7.2)

declare_platform(qemu-arm-virt KernelPlatformQEMUArmVirt PLAT_QEMU_ARM_VIRT KernelArchARM)

set(MIN_QEMU_VERSION "3.1.0")

if(KernelPlatformQEMUArmVirt)
if("${ARM_CPU}" STREQUAL "cortex-a7")
declare_seL4_arch(aarch32)
set(QEMU_ARCH "arm")
set(KernelArmCortexA7 ON)
set(KernelArchArmV7a ON)
if("${ARM_CPU}" STREQUAL "cortex-a15")
declare_seL4_arch(aarch32)
set(QEMU_ARCH "arm")
Expand All @@ -26,6 +29,11 @@ if(KernelPlatformQEMUArmVirt)
set(QEMU_ARCH "aarch64")
set(KernelArmCortexA57 ON)
set(KernelArchArmV8a ON)
elseif("${ARM_CPU}" STREQUAL "cortex-a72")
declare_seL4_arch(aarch64)
set(QEMU_ARCH "aarch64")
set(KernelArmCortexA72 ON)
set(KernelArchArmV8a ON)
else()
message(STATUS "Default cpu specified for virt board: cortex-a53")
declare_seL4_arch(aarch64)
Expand All @@ -34,75 +42,98 @@ if(KernelPlatformQEMUArmVirt)
set(KernelArmCortexA53 ON)
set(KernelArchArmV8a ON)
endif()
execute_process(
COMMAND qemu-system-${QEMU_ARCH} -version
OUTPUT_VARIABLE QEMU_VERSION_STR
RESULT_VARIABLE error
)
if(error)
message(FATAL_ERROR "Failed to determine qemu version (qemu-system-${QEMU_ARCH})")
endif()
string(
REGEX
MATCH
"[0-9](\\.[0-9])+"
QEMU_VERSION
${QEMU_VERSION_STR}
)
if("${QEMU_VERSION}" VERSION_LESS "${MIN_QEMU_VERSION}")
message(FATAL_ERROR "Error: qemu version must be at least ${MIN_QEMU_VERSION}")
endif()

if("${QEMU_MEMORY}" STREQUAL "")
set(QEMU_MEMORY "1024")
endif()
message(STATUS "QEMU MEMORY is: ${QEMU_MEMORY}")
config_set(KernelARMPlatform ARM_PLAT qemu-arm-virt)
set(DTBPath "${CMAKE_BINARY_DIR}/virt.dtb")
set(DTSPath "${CMAKE_BINARY_DIR}/virt.dts")
if(KernelArmHypervisorSupport)
set(QEMU_VIRT_OPTION "virtualization=on,highmem=off,secure=off")
else()
if(Kernel32)
set(QEMU_VIRT_OPTION "virtualization=off,highmem=off")

# Unless QEMU_DTS is set explicitly, the device tree is extract from QEMU.
# This keeps it nicely up to date with the newer QEMU versions and is quite
# convenient for the development usecase.
if(NOT DEFINED QEMU_DTS)

message(STATUS "Extracting device tree from QEMU")

set(QEMU_BINARY "qemu-system-${KernelSel4Arch}")
find_program(QEMU_BINARY ${QEMU_BINARY})

# ARM virtual platform works since QEMU 3.1.0
set(MIN_QEMU_VERSION "3.1.0")
execute_process(
COMMAND ${QEMU_BINARY} -version
RESULT_VARIABLE error
OUTPUT_VARIABLE QEMU_STDOUT_MESSAGE
)
if(error)
message(FATAL_ERROR "Failed to determine QEMU version (${QEMU_BINARY})")
endif()
string(
REGEX
MATCH
"[0-9](\\.[0-9])+"
QEMU_VERSION
"${QEMU_STDOUT_MESSAGE}"
)
if("${QEMU_VERSION}" VERSION_LESS "${MIN_QEMU_VERSION}")
message(
FATAL_ERROR
"Error: need at least QEMU version ${MIN_QEMU_VERSION}, found '${QEMU_VERSION}'"
)
endif()

if(KernelArmHypervisorSupport)
set(QEMU_MACHINE_OPTION "virtualization=on,highmem=off,secure=off")
else()
set(QEMU_VIRT_OPTION "virtualization=off")
if(Kernel32)
set(QEMU_MACHINE_OPTION "virtualization=off,highmem=off")
else()
set(QEMU_MACHINE_OPTION "virtualization=off")
endif()
endif()
endif()
if(KernelMaxNumNodes)
set(QEMU_SMP_OPTION "${KernelMaxNumNodes}")
else()
set(QEMU_SMP_OPTION "1")
endif()
find_program(QEMU_BINARY qemu-system-${QEMU_ARCH})
execute_process(
COMMAND
${QEMU_BINARY} -machine virt,dumpdtb=${DTBPath},${QEMU_VIRT_OPTION} -m ${QEMU_MEMORY}
-cpu ${ARM_CPU} -smp ${QEMU_SMP_OPTION} -nographic
ERROR_VARIABLE QEMU_OUTPUT_MESSAGE
RESULT_VARIABLE error
)
if(${QEMU_OUTPUT_MESSAGE})
string(STRIP ${QEMU_OUTPUT_MESSAGE} QEMU_OUTPUT_MESSAGE)
endif()
message(STATUS ${QEMU_OUTPUT_MESSAGE})
if(error)
message(FATAL_ERROR "Failed to dump DTB using ${QEMU_BINARY})")
endif()
execute_process(
COMMAND
dtc -q -I dtb -O dts ${DTBPath}
OUTPUT_FILE ${DTSPath}
RESULT_VARIABLE error
)
if(error)
message(FATAL_ERROR "Failed to convert DTB to DTS (${DTBPath})")
endif()
list(APPEND KernelDTSList "${DTSPath}")
list(APPEND KernelDTSList "src/plat/qemu-arm-virt/overlay-qemu-arm-virt.dts")

if(NOT DEFINED QEMU_MEMORY)
# Having 1 GiB of memory as default is a legacy from the past that
# is kept for compatibility. It should be increased to 2 GiB, which
# seems a good trade-off nowadays. It's sufficient for test/demo
# systems, but still something the host can provide without running
# short on resources.
set(QEMU_MEMORY "1024")
endif()

if(KernelMaxNumNodes)
set(QEMU_SMP_OPTION "${KernelMaxNumNodes}")
else()
set(QEMU_SMP_OPTION "1")
endif()

set(QEMU_DT_BASE_NAME "${CMAKE_BINARY_DIR}/qemu-riscv-virt")
set(QEMU_DTB "${QEMU_DT_BASE_NAME}.dtb")
set(QEMU_DTS "${QEMU_DT_BASE_NAME}.dts")

execute_process(
COMMAND
${QEMU_BINARY} -machine virt,dumpdtb=${QEMU_DTB},${QEMU_VIRT_OPTION}
-cpu rv${KernelWordSize} -smp ${QEMU_SMP_OPTION} -m ${QEMU_MEMORY}
-nographic
RESULT_VARIABLE error
)
if(error)
message(FATAL_ERROR "Failed to dump DTB using ${QEMU_BINARY})")
endif()

execute_process(
COMMAND
dtc -q -I dtb -O dts -o ${QEMU_DTS} ${QEMU_DTB}
RESULT_VARIABLE error
)
if(error)
message(FATAL_ERROR "Failed to convert QEMU's DTB to a DTS (${QEMU_DTB})")
endif()


list(APPEND KernelDTSList "${DTSPath}" "${CMAKE_CURRENT_LIST_DIR}/overlay-qemu-arm-virt.dts")
if(KernelArmHypervisorSupport)
list(APPEND KernelDTSList "src/plat/qemu-arm-virt/overlay-reserve-vm-memory.dts")
list(APPEND KernelDTSList "${CMAKE_CURRENT_LIST_DIR}/overlay-reserve-vm-memory.dts")
endif()

declare_default_headers(
TIMER_FREQUENCY 62500000
MAX_IRQ 159
Expand Down

0 comments on commit 6e86a4d

Please sign in to comment.