Contents
Building the examples
The examples are built using the CMake
build system that is included in KasperskyOS Community Edition.
The code of the examples and build scripts are available at the following path:
/opt/KasperskyOS-Community-Edition-<version>/examples
Examples must be built in the home directory. For this reason, the directory containing the example that you need to build must be copied from /opt/KasperskyOS-Community-Edition-<version>/examples
to the home directory.
Building the examples to run on QEMU
To build an example, go to the directory with the example and run this command:
$ sudo ./cross-build.sh
Running cross-build.sh
creates a KasperskyOS-based solution image that includes the example. The kos-qemu-image
solution image is located in the <name of example>/build/einit
directory.
Building the examples to run on Raspberry Pi 4 B
To build an example:
- Go to the directory with the example.
- Open the
cross-build.sh
script file in a text editor. - In the last line of the script file, replace the
make sim
command withmake kos-image
. - Save the script file and then run the command:
$ sudo ./cross-build.sh
Running cross-build.sh
creates a KasperskyOS-based solution image that includes the example. The kos-image
solution image is located in the <name of example>/build/einit
directory.
Running examples on QEMU
Running examples on QEMU on Linux with a graphical shell
An example is run on QEMU on Linux with a graphical shell using the cross-build.sh
script, which also builds the example. To run the script, go to the folder with the example and run the command:
$ sudo ./cross-build.sh
Additional QEMU parameters must be used to run certain examples. The commands used to run these examples are provided in the descriptions of these examples.
Running examples on QEMU on Linux without a graphical shell
To run an example on QEMU on Linux without a graphical shell, go to the directory with the example, build the example and run the following commands:
$ cd build/einit
# Before running the following command, be sure that the path to
# the directory with the qemu-system-arm executable file is saved in
# the PATH environment variable. If it is not there,
# add it to the PATH variable.
$ qemu-system-arm -m 2048 -machine vexpress-a15 -nographic -monitor none -serial stdio -kernel kos-qemu-image
Running examples on Raspberry Pi 4 B
Connecting a computer and Raspberry Pi 4 B
To see the output of the examples on the computer:
- Connect the pins of the FT232 USB-UART converter to the corresponding GPIO pins of the Raspberry Pi 4 B (see the figure below).
Diagram for connecting the USB-UART converter and Raspberry Pi 4 B
- Connect the computer's USB port to the USB-UART converter.
- Install PuTTY or a similar program for reading data from a COM port. Configure the settings as follows:
bps = 115200
,data bits = 8
,stop bits = 1
,parity = none
,flow control = none
.
To allow a computer and Raspberry Pi 4 B to interact through Ethernet:
- Connect the network cards of the computer and Raspberry Pi 4 B to a switch or to each other.
- Configure the computer's network card so that its IP address is in the same subnet as the IP address of the Raspberry Pi 4 B network card (the settings of the Raspberry Pi 4 B network card are defined in the
dhcpcd.conf
file, which is found at the path<example name>/resources/...
).
Preparing a bootable SD card for Raspberry Pi 4 B
A bootable SD card for Raspberry Pi 4 B can be prepared automatically or manually.
To automatically prepare the bootable SD card, connect the SD card to the computer and run the following commands:
# The following command creates an image file for the bootable
# drive (*.img).
$ sudo /opt/KasperskyOS-Community-Edition-<version>/examples/rpi4_prepare_fs_image.sh
# In the following command, path_to_img is the path to the image file
# of the bootable drive (this path is displayed upon completion
# of the previous command), [X] is the final character
# in the name of the SD card block device.
$ sudo dd bs=4M if=path_to_img of=/dev/sd[X] conv=fsync
To manually prepare the bootable SD card:
- Build the U-Boot bootloader for ARMv7, which will automatically run the example. To do this, run the following commands:
$ sudo apt install gcc-arm-linux-gnueabi gcc-arm-linux-gnueabihf git bison flex
$ git clone https://github.com/u-boot/u-boot.git u-boot-armv7
$ cd u-boot-armv7 && git checkout tags/v2020.10
$ make ARCH=arm CROSS_COMPILE=arm-linux-gnueabihf- rpi_4_32b_defconfig
# In the menu that appears when you run the following command, enable
# the 'Enable a default value for bootcmd' option. In the 'bootcmd value' field, enter
# fatload mmc 0 ${loadaddr} kos-image; bootelf ${loadaddr}.
# Then exit the menu after saving the settings.
$ make ARCH=arm CROSS_COMPILE=arm-linux-gnueabihf- menuconfig
$ make ARCH=arm CROSS_COMPILE=arm-linux-gnueabihf- u-boot.bin
- Format the SD card. To do this, connect the SD card to the computer and run the following commands:
$ wget https://downloads.raspberrypi.org/raspbian_lite_latest
$ unzip raspbian_lite_latest
# In the following command, [X] is the last symbol in the name of the block device
# for the SD card.
$ sudo dd bs=4M if=$(ls *raspbian*lite.img) of=/dev/sd[X] conv=fsync
- Copy the U-Boot bootloader to the SD card by running the following commands:
# In the following commands, the path ~/mnt/fat32 is just an example. You
# can use a different path.
$ mkdir -p ~/mnt/fat32
# In the following command, [X] is the last alphabetic character in the name of the block
# device for the partition on the formatted SD card.
$ sudo mount /dev/sd[X]1 ~/mnt/fat32/
$ sudo cp u-boot.bin ~/mnt/fat32/u-boot.bin
- Copy the configuration file for the U-Boot bootloader to the SD card. To do so, go to the directory
/opt/KasperskyOS-Community-Edition-<version>/examples
and run the following commands:$ sudo cp config.txt ~/mnt/fat32/config.txt
$ sync
$ sudo umount ~/mnt/fat32
Running an example on a Raspberry Pi 4 B
To run an example on a Raspberry Pi 4 B:
- Go to the directory with the example and build the example.
- Copy the KasperskyOS-based solution image to the bootable SD card. To do this, connect the bootable SD card to the computer and run the following commands:
# In the following command, [X] is the last alphabetic character in the name of the block
# device for the partition on the bootable SD card.
# In the following commands, the path ~/mnt/fat32 is just an example. You
# can use a different path.
$ sudo mount /dev/sd[X]1 ~/mnt/fat32/
$ sudo cp build/einit/kos-image ~/mnt/fat32/kos-image
$ sync
$ sudo umount ~/mnt/fat32
- Connect the bootable SD card to the Raspberry Pi 4 B.
- Supply power to the Raspberry Pi 4 B and wait for the example to run.
The output displayed on the computer indicates that the example started.