Connecting a computer and Raspberry Pi 4 B
To see the output from Raspberry Pi 4 B on a computer, do the following:
Diagram for connecting the USB-UART converter and Raspberry Pi 4 B
bps = 115200
, data bits = 8
, stop bits = 1
, parity = none
, flow control = none
. Define the USB port connected to the USB-UART converter used for receiving output from Raspberry Pi 4 B.To allow a computer and Raspberry Pi 4 B to interact through Ethernet:
dhcpcd.conf
file, which is found at the path <example name>/resources/...
).Preparing a bootable SD card for Raspberry Pi 4 B
If the rpi4kos.img
image was created when building the example, all you have to do is write the resulting image to the SD card. To do this, connect the SD card to the computer and run the following command:
# In the following command, path_to_img is the path to the image file
# [X] is the final character in the name of the SD card block device.
$ sudo pv -L 32M path_to_img | sudo dd bs=64k of=/dev/sd[X] conv=fsync
If kos-image
was created when building the example, the SD card requires additional preparations before you can write the image to it. 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:
# To create a bootable drive image file (*.img),
# run the script:
$ sudo /opt/KasperskyOS-Community-Edition-<version>/common/rpi4_prepare_sdcard_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 pv -L 32M path_to_img | sudo dd bs=64k of=/dev/sd[X] conv=fsync
To manually prepare the bootable SD card:
$ sudo apt install git build-essential libssl-dev bison flex unzip parted gcc-aarch64-linux-gnu pv -y
$ git clone --depth 1 --branch v2022.01 https://github.com/u-boot/u-boot.git u-boot-armv8
$ cd u-boot-armv8
$ make ARCH=arm CROSS_COMPILE=aarch64-linux-gnu- rpi_4_defconfig
$ echo 'CONFIG_SERIAL_PROBE_ALL=y' > ./.custom_config
$ echo 'CONFIG_BOOTCOMMAND="fatload mmc 0 ${loadaddr} kos-image; bootelf ${loadaddr} ${fdt_addr}"' >> ./.custom_config
$ echo 'CONFIG_PREBOOT="pci enum;"' >> ./.custom_config
$ ./scripts/kconfig/merge_config.sh '.config' '.custom_config'
$ make ARCH=arm CROSS_COMPILE=aarch64-linux-gnu- u-boot.bin
# Image will contain a boot partition of 1 GB in fat32 and three partitions of 350 MB each in ext2, ext3 and ext4, respectively.
$ fs_image_name=sdcard.img
$ dd if=/dev/zero of=${fs_image_name} bs=1024k count=2048
$ sudo parted ${fs_image_name} mklabel msdos
$ loop_device=$(sudo losetup --find --show --partscan ${fs_image_name})
$ sudo parted ${loop_device} mkpart primary fat32 8192s 50%
$ sudo parted ${loop_device} mkpart extended 50% 100%
$ sudo parted ${loop_device} mkpart logical ext2 50% 67%
$ sudo parted ${loop_device} mkpart logical ext3 67% 84%
$ sudo parted ${loop_device} mkpart logical ext4 84% 100%
$ sudo parted ${loop_device} set 1 boot on
$ sudo mkfs.vfat ${loop_device}p1
$ sudo mkfs.ext2 ${loop_device}p5
$ sudo mkfs.ext3 ${loop_device}p6
$ sudo mkfs.ext4 -O ^64bit,^extent ${loop_device}p7
# In the following commands, the path ~/mnt/fat32 is just an example.
# You can use a different path.
$ mount_temp_dir=~/mnt/fat32
$ mkdir -p ${mount_temp_dir}
$ sudo mount ${loop_device}p1 ${mount_temp_dir}
$ git clone --depth 1 --branch 1.20220331 https://github.com/raspberrypi/firmware.git firmware
$ sudo cp u-boot.bin ${mount_temp_dir}/u-boot.bin
$ sudo cp -r firmware/boot/. ${mount_temp_dir}
$ sudo sh -c "echo '[all]' > ${mount_temp_dir}/config.txt"
$ sudo sh -c "echo 'arm_64bit=1' >> ${mount_temp_dir}/config.txt"
$ sudo sh -c "echo 'enable_uart=1' >> ${mount_temp_dir}/config.txt"
$ sudo sh -c "echo 'kernel=u-boot.bin' >> ${mount_temp_dir}/config.txt"
$ sudo sh -c "echo 'dtparam=i2c_arm=on' >> ${mount_temp_dir}/config.txt"
$ sudo sh -c "echo 'dtparam=i2c=on' >> ${mount_temp_dir}/config.txt"
$ sudo sh -c "echo 'dtparam=spi=on' >> ${mount_temp_dir}/config.txt"
$ sudo sh -c "echo 'device_tree_address=0x2eff5b00' >> ${mount_temp_dir}/config.txt"
$ sudo sh -c "echo 'device_tree_end=0x2f0f5b00' >> ${mount_temp_dir}/config.txt"
$ sudo sh -c "echo 'dtoverlay=uart5' >> ${mount_temp_dir}/config.txt"
$ sudo umount ${mount_temp_dir}
$ sudo losetup -d ${loop_device}
# In the following command, [X] is the last symbol in the name of the block device for the SD card.
$ sudo pv -L 32M ${fs_image_name} | sudo dd bs=64k of=/dev/sd[X] conv=fsync