To automate the process of preparing the solution image, you need to configure the CMake
build system. You can base this system on the build system parameters used in the examples from KasperskyOS Community Edition.
CMakeLists.txt
files use the standard CMake
syntax, and commands and macros from libraries provided in KasperskyOS Community Edition.
Recommended structure of project directories
When creating a KasperskyOS-based solution, it is recommended to use the following directory structure in a project to simplify the use of CMake
scripts:
src
subdirectory.Einit
program, you should create a separate einit
directory containing the src
subdirectory in which you should put the init.yaml.in and security.psl.in templates.Any other files that need to be included in the solution image can also be put into this directory.
Einit
program in the einit
directory.resources
directory in the project root.cross-build.sh
build script containing the commands to start generating build files (cmake
command), to build the solution (make
command), and to start the solution.Example structure of project directories
example$ tree
.
├── CMakeLists.txt
├── cross-build.sh
├── hello
│ ├── CMakeLists.txt
│ ├── src
│ │ ├── hello.c
├── einit
│ ├── CMakeLists.txt
│ ├── src
│ │ ├── init.yaml.in
│ │ ├── security.psl.in
│ │ ├── fstab
├── resources
│ ├── Hello.idl
│ ├── Hello.cdl
│ ├── Hello.edl
Building a project
To prepare for a build using the CMake
build system, the following is required:
init.yaml.in
and security.psl.in
templates.To perform cross-compilation using the CMake
build automation system, the following is required:
BUILD=$PWD/.build
mkdir -p $BUILD && cd $BUILD
cmake
command), set the following values for environment variables:export LANG=C
export PKG_CONFIG=""
export SDK_PREFIX="/opt/KasperskyOS-Community-Edition-<version>"
export PATH="$SDK_PREFIX/toolchain/bin:$PATH"
export INSTALL_PREFIX=$BUILD/../install
export TARGET="aarch64-kos"
cmake
command), specify the following:-G "Unix Makefiles"
parametertoolchain.cmake
) in the CMAKE_TOOLCHAIN_FILE
variable.The file with the build system extension is located in the following directory: /opt/KasperskyOS-Community-Edition-<version>/toolchain/share/toolchain-aarch64-kos.cmake
CMAKE_BUILD_TYPE:STRING=Debug
variableCMAKE_INSTALL_PREFIX:STRING=$INSTALL_PREFIX
variablemake
command), specify one of the build targets.The target name must match the build target name passed to the solution build command in the CMakeLists.txt file for the Einit program.
Example cross-build.sh build script
cross-build.sh
#!/bin/bash
# Create a subdirectory for the build
BUILD=$PWD/.build
mkdir -p $BUILD && cd $BUILD
# Set the values of environment variables
export LANG=C
export PKG_CONFIG=""
export SDK_PREFIX="/opt/KasperskyOS-Community-Edition-<version>"
export PATH="$SDK_PREFIX/toolchain/bin:$PATH"
export INSTALL_PREFIX=$BUILD/../install
export TARGET="aarch64-kos"
# Start generating files for the build. The current directory is $BUILD,
# so the CMakeLists.txt boot file is in the parent directory
cmake -G "Unix Makefiles" \
-D CMAKE_BUILD_TYPE:STRING=Debug \
-D CMAKE_INSTALL_PREFIX:STRING=$BUILD/../.install \
-D CMAKE_TOOLCHAIN_FILE=$SDK_PREFIX/toolchain/share/toolchain-$TARGET.cmake \
../
# Start the build. Include the VERBOSE flag for Make and redirect the output to the build.log file
VERBOSE=1 make kos-qemu-image 2>&1 | tee build.log
# Run the built solution image in QEMU.
# -kernel $BUILD/einit/kos-qemu-image path to the built kernel image
$SDK_PREFIX/toolchain/bin/qemu-system-aarch64 \
-m 1024 \
-cpu core2duo \
-serial stdio \
-kernel $BUILD/einit/kos-qemu-image