build/cmake: add initial KERNEL mode support

Currently only FLAT mode development can enjoy cmake build system. This
patch tries to add initial kernel mode support. It can build NuttX kernel
and libproxies.a, the latter will be further checked though.

This can already help to build an AMP remote node image as it can share
userland apps living in the AMP master node.

Major changes:

- in top folder:
  - CMakeLists.txt    adjust for KERNEL mode, separate from PROTECTED mode.
- in `syscall`:
  - CMakeLists.txt    add mksyscall target for stubs/proxies generation
- in `syscall/stubs`:
  - CMakeLists.txt    use dependency to mksyscall
- in `syscall/proxies`:
  - CMakeLists.txt    use dependency to mksyscall
- in `arch`:
  - CMakeLists.txt    separate KERNEL from PROTECTED mode.
- in `arch/risc-v/src`:
  - CMakeLists.txt    separate from PROTECTED mode, add sub folders.
- in `arch/risc-v/common`:
  - CMakeLists.txt    add sources and sub-folders for KERNEL mode.
- in `arch/risc-v/k230`:
  - CMakeLists.txt    add sources for KERNEL mode.
- in `boards/risc-v/k230/canmv230/src`:
  - CMakeLists.txt    adjust k230 specific scripts for kernel mode.

New additions:

- in `arch/risc-v/src/nuttsbi/`           add CMakeLists.txt
- in `arch/risc-v/src/common/supervisor/` add CMakeLists.txt

Signed-off-by: Yanfeng Liu <yfliu2008@qq.com>
This commit is contained in:
Yanfeng Liu 2024-03-14 15:00:46 +08:00 committed by archer
parent 8bf6b17cc0
commit ea8682572c
11 changed files with 118 additions and 25 deletions

View File

@ -550,11 +550,15 @@ endif()
# Add apps/ to the build (if present)
if(EXISTS ${NUTTX_APPS_DIR}/CMakeLists.txt)
add_subdirectory(${NUTTX_APPS_DIR} apps)
else()
message(
STATUS "Application directory not found at ${NUTTX_APPS_DIR}, skipping")
if(NOT CONFIG_BUILD_KERNEL)
if(EXISTS ${NUTTX_APPS_DIR}/CMakeLists.txt)
add_subdirectory(${NUTTX_APPS_DIR} apps)
else()
message(
STATUS "Application directory not found at ${NUTTX_APPS_DIR}, skipping")
endif()
endif()
# Link step ##################################################################
@ -597,11 +601,15 @@ endif()
file(TOUCH ${CMAKE_BINARY_DIR}/nuttx.manifest)
get_property(nuttx_kernel_libs GLOBAL PROPERTY NUTTX_KERNEL_LIBRARIES)
get_property(nuttx_extra_libs GLOBAL PROPERTY NUTTX_EXTRA_LIBRARIES)
if(CONFIG_BUILD_FLAT)
get_property(nuttx_system_libs GLOBAL PROPERTY NUTTX_SYSTEM_LIBRARIES)
endif()
get_property(nuttx_apps_libs GLOBAL PROPERTY NUTTX_APPS_LIBRARIES)
get_property(nuttx_extra_libs GLOBAL PROPERTY NUTTX_EXTRA_LIBRARIES)
if(NOT CONFIG_BUILD_KERNEL)
get_property(nuttx_apps_libs GLOBAL PROPERTY NUTTX_APPS_LIBRARIES)
endif()
set(nuttx_libs ${nuttx_kernel_libs} ${nuttx_system_libs} ${nuttx_apps_libs})
@ -734,7 +742,7 @@ endif()
# Userspace portion ##########################################################
if(NOT CONFIG_BUILD_FLAT)
if(CONFIG_BUILD_PROTECTED)
add_executable(nuttx_user)
get_property(nuttx_system_libs GLOBAL PROPERTY NUTTX_SYSTEM_LIBRARIES)
@ -779,3 +787,8 @@ if(NOT CONFIG_BUILD_FLAT)
# TODO: could also merge elf binaries
endif()
if(CONFIG_BUILD_KERNEL)
# TODO: generate nuttx-export-xxx.tar.gz for userland development
endif()

View File

@ -25,7 +25,7 @@
nuttx_add_kernel_library(arch)
target_include_directories(arch PRIVATE ${CMAKE_SOURCE_DIR}/sched)
if(NOT CONFIG_BUILD_FLAT)
if(CONFIG_BUILD_PROTECTED)
nuttx_add_system_library(arch_interface)
target_include_directories(arch_interface PRIVATE ${CMAKE_SOURCE_DIR}/sched)
endif()

View File

@ -21,11 +21,16 @@
add_subdirectory(${NUTTX_CHIP_ABS_DIR} EXCLUDE_FROM_ALL exclude_chip)
add_subdirectory(common)
if(CONFIG_BUILD_KERNEL)
add_subdirectory(nuttsbi)
target_include_directories(arch BEFORE PUBLIC ${NUTTX_CHIP_ABS_DIR} nuttsbi)
endif()
# Include directories (before system ones) as PUBLIC so that it can be exposed
# to libboard
target_include_directories(arch BEFORE PUBLIC ${NUTTX_CHIP_ABS_DIR} common)
if(NOT CONFIG_BUILD_FLAT)
if(CONFIG_BUILD_PROTECTED)
target_include_directories(arch_interface BEFORE PUBLIC ${NUTTX_CHIP_ABS_DIR}
common)
endif()

View File

@ -91,7 +91,7 @@ if(CONFIG_ARCH_USE_MMU)
endif()
if(CONFIG_ARCH_KERNEL_STACK)
list(APPEND SRCS riscv_addrenv_kstack.c)
list(APPEND SRCS riscv_addrenv_kstack.c riscv_ksp.c)
endif()
if(CONFIG_ARCH_ADDRENV)
@ -99,4 +99,9 @@ if(CONFIG_ARCH_ADDRENV)
list(APPEND SRCS riscv_addrenv_utils.c riscv_addrenv_shm.c)
endif()
if(CONFIG_BUILD_KERNEL)
list(APPEND SRCS riscv_percpu.c)
add_subdirectory(supervisor)
endif()
target_sources(arch PRIVATE ${SRCS})

View File

@ -0,0 +1,29 @@
# ##############################################################################
# arch/arm/src/common/supervisor/CMakeLists.txt
#
# Licensed to the Apache Software Foundation (ASF) under one or more contributor
# license agreements. See the NOTICE file distributed with this work for
# additional information regarding copyright ownership. The ASF licenses this
# file to you under the Apache License, Version 2.0 (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
#
# Unless required by applicable law or agreed to in writing, software
# distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
# WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the
# License for the specific language governing permissions and limitations under
# the License.
#
# ##############################################################################
if(CONFIG_BUILD_KERNEL)
set(SRCS)
list(APPEND SRCS riscv_syscall.S riscv_perform_syscall.c riscv_sbi.c)
target_sources(arch PRIVATE ${SRCS})
endif()

View File

@ -18,17 +18,9 @@
#
# ##############################################################################
set(SRCS k230_head.S)
set(SRCS k230_head.S k230_start.c k230_irq.c k230_irq_dispatch.c)
list(
APPEND
SRCS
k230_start.c
k230_irq_dispatch.c
k230_irq.c
k230_hart.c
k230_timerisr.c
k230_allocateheap.c)
list(APPEND SRCS k230_timerisr.c k230_allocateheap.c k230_hart.c)
if(CONFIG_BUILD_KERNEL)
list(APPEND SRCS k230_mm_init.c)
@ -40,4 +32,12 @@ if(CONFIG_MM_PGALLOC)
list(APPEND SRCS k230_pgalloc.c)
endif()
if(CONFIG_K230_IPI)
list(APPEND SRCS k230_ipi.c)
endif()
if(CONFIG_RPTUN)
list(APPEND SRCS k230_rptun.c)
endif()
target_sources(arch PRIVATE ${SRCS})

View File

@ -0,0 +1,29 @@
# ##############################################################################
# arch/risc-v/src/nuttsbi/CMakeLists.txt
#
# Licensed to the Apache Software Foundation (ASF) under one or more contributor
# license agreements. See the NOTICE file distributed with this work for
# additional information regarding copyright ownership. The ASF licenses this
# file to you under the Apache License, Version 2.0 (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
#
# Unless required by applicable law or agreed to in writing, software
# distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
# WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the
# License for the specific language governing permissions and limitations under
# the License.
#
# ##############################################################################
if(CONFIG_NUTTSBI)
set(SRCS sbi_head.S sbi_mtrap.S sbi_vectors.S sbi_start.c)
list(APPEND SRCS sbi_mtimer.c sbi_mexception.c sbi_mcall.c sbi_mscratch.c)
target_sources(arch PRIVATE ${SRCS})
endif()

View File

@ -32,8 +32,12 @@ target_sources(board PRIVATE ${SRCS})
if(CONFIG_ARCH_CHIP_K230)
if(CONFIG_BUILD_KERNEL)
if(CONFIG_ARCH_NUTTSBI)
set(LDFILE ld-nuttsbi.script)
if(CONFIG_NUTTSBI)
if(CONFIG_RPTUN)
set(LDFILE ld-rptun.script)
else()
set(LDFILE ld-nuttsbi.script)
endif()
else()
set(LDFILE ld-kernel.script)
endif()

View File

@ -22,6 +22,14 @@ file(STRINGS syscall.csv SYSCALLS)
list(TRANSFORM SYSCALLS REPLACE "^\"([^,]+)\",.+" "\\1")
list(TRANSFORM SYSCALLS APPEND ".c")
# generate the host tool
add_custom_target(
mksyscall
COMMAND cmake -B ${CMAKE_BINARY_DIR}/bin -S ${CMAKE_SOURCE_DIR}/tools && cmake
--build ${CMAKE_BINARY_DIR}/bin --target mksyscall
SOURCES ${CMAKE_SOURCE_DIR}/tools/mksyscall.c)
if(CONFIG_LIB_SYSCALL)
add_subdirectory(proxies)
add_subdirectory(stubs)

View File

@ -27,7 +27,7 @@ add_custom_command(
COMMAND ${CMAKE_BINARY_DIR}/bin/mksyscall -p
${CMAKE_CURRENT_LIST_DIR}/../syscall.csv
WORKING_DIRECTORY ${CMAKE_CURRENT_BINARY_DIR}
DEPENDS nuttx_host_tools)
DEPENDS mksyscall)
# add sources to target
target_sources(proxies PRIVATE ${SYSCALLS})

View File

@ -27,7 +27,7 @@ add_custom_command(
COMMAND ${CMAKE_BINARY_DIR}/bin/mksyscall -s
${CMAKE_CURRENT_LIST_DIR}/../syscall.csv
WORKING_DIRECTORY ${CMAKE_CURRENT_BINARY_DIR}
DEPENDS nuttx_host_tools)
DEPENDS mksyscall)
# add sources to target
target_sources(stubs PRIVATE ${SYSCALLS})