This configuration enable to create normal and administrative operating system on one device.
-
Preparation of an "administrative" Linux system: This system was designed as a rescue system operating in the initramfs file system and included tools necessary for managing the SD card and loading Linux kernel images.
-
Loading the "administrative" system: The device was prepared for user system boot. Memory on the card was divided into three partitions with the following formats: two ext4 partitions and one VFAT partition. Finally, the user system was loaded, including the kernel image and file system.
-
Bootloader Preparation: A bootloader was created to determine which system (administrative or user) should be loaded. A WHITE LED was used to indicate that buttons would be checked shortly. After one second, the state of the buttons was read. If no button was pressed, the "user" system was to be loaded. After checking the buttons, the WHITE LED was turned off. If the "user" system was selected, a GREEN LED was lit; if the "administrative" system was chosen, a RED LED was lit.
-
Preparation of the "user" Linux system: This system operated with an ext4 file system on the second partition and included a WWW server in the Tornado environment, controlled via a web interface. The server was to provide files from the third partition on the SD card, display a list of these files, and allow file selection for download. The server was also to permit uploading new files to this partition after user authentication.
The attached archive contained two folders: admin
and user
. Each of these folders had to be unpacked using Buildroot. The admin
folder included files necessary to restore the administrative system project with the appropriate bootloader. The .config
file was located in the main Buildroot directory. The system image was then built using the make
command. The second folder contained files needed to restore the user system project. The .config
file was located in the main Buildroot directory. The overlay
folder was to be placed one level below the buildroot-xxx
directory. In the /buildroot-xxx/board/raspberrypi4-64/
directory, there was a file named genimage-raspberrypi4-64.cfg
. The system image was built using the make
command.
A configuration file was prepared by saving the default configuration. Then, a bootloader was written, which allowed for system selection according to the exercise requirements. The dd
tool was included in the system by default. After building the system image, the boot.txt
file was processed using the mkimage
tool into the boot.scr
file, which was loaded by the device by default. For the laboratory, the bootloader was executed by the internal RPi4 bootloader.
Default Buildroot Configuration:
- Set the target system architecture by running the command
make raspberrypi4_64_defconfig
in the Buildroot directory. - Set the TTY port to
console
in the section:System configuration/Run a getty.../TTY port
. - Set the package source by entering
http://192.168.137.24/dl
in the section:Build options/Mirrors and Download locations/Primary download site
. - Select an external toolchain in the section
Toolchain/Toolchain type
– version:Arm AArch64 2021.07
. - Enable compiler caching -
BR2_CCACHE
inBuild options/Enable compiler cache
. Set the location to../ccache-br
. This configuration was saved as default.
Further Buildroot Configuration:
- Configure appropriate system image generation by selecting in the section:
Filesystem images
initial RAM filesystem linked into linux kernel
.
- Add IP address assignment by including the
BR2_PACKAGE_DHCP
package and theclient
suboption (to enable network usage). To add this package, first add theBR2_PACKAGE_BUSYBOX_SHOW_OTHERS
package. - Add the
BR2_PACKAGE_NETPLUG
package (to enable automatic network connection). - Select the
BR2_PACKAGE_NTP
package and set the NTP server (to enable system clock synchronization). - Set the system name to
BR2_TARGET_GENERIC_HOSTNAME="admin"
. - Add packages for formatting:
BR2_PACKAGE_DOSDSTOOLS_MKFS_FAT
BR2_PACKAGE_E2FSPROGS
BR2_TARGET_ROOTFS_EXT2_MKFS_OPTIONS
- Add packages for mounting devices:
BR2_PACKAGE_UTIL_LINUX_MOUNT
- Add packages for file system checking:
BR2_PACKAGE_E2FSPROGS_FSCK
- Add packages for resizing partitions:
BR2_PACKAGE_FLOT_RESIZE
BR2_PACKAGE_E2FSPROGS_RESIZE2FS
- Add tools for bootloader preparation:
BR2_PACKAGE_UBOOT_TOOLS_MKIMAGE
BR2_PACKAGE_HOST_IMX_MKIMAGE
U-Boot Configuration:
In the Bootloaders
section, the U-Boot
option was selected. The Board defconfig
was set to rpi_4
. After building the system image, the script was modified using the mkimage
tool:
mkimage -T script -C none -n 'Start script' -d boot.txt boot.scr
The system configuration was started from the default configuration used for the administrative system. The file system type for the user system was then added. Subsequently, packages for internet usage and those required to run the Tornado server were added. Finally, the created server was placed in a directory that acted as an overlay on the system with the necessary files for running the server in daemon mode. Upon booting the system on the RPi4, it was found that a more advanced version of the start-stop-daemon program was required to start the server, which was added using the BR2_PACKAGE_START_STOP_DAEMON
package.
Buildroot Configuration:
- Load the default configuration as for the administrative system.
- Configure appropriate system image generation by selecting in the section:
Filesystem images
ext4
.
- Change the size from 32M to 256M in the file
board/raspberrypi4-64/genimage-raspberrypi4-64.cfg
. - Add IP address assignment by including the
BR2_PACKAGE_DHCP
package and theclient
suboption (to enable network usage). To add this package, first add theBR2_PACKAGE_BUSYBOX_SHOW_OTHERS
package. - Add the
BR2_PACKAGE_NETPLUG
package (to enable automatic network connection). - Select the
BR2_PACKAGE_NTP
package and set the NTP server (to enable system clock synchronization). - Set the system name to
BR2_TARGET_GENERIC_HOSTNAME="stanislaw_tabisz"
. - Choose the package that adds an extended start-stop-daemon program:
BR2_PACKAGE_START_STOP_DAEMON
. - Select the following packages to enable operation.
- Add rootfs overlay:
BR2_ROOTFS_OVERLAY=../overlay
. - Add the Tornado server:
BR2_PACKAGE_PYTHON3
Toolchain -> Enable WCHAR support
BR2_PACKAGE_PYTHON_TORNADO
BR2_PACKAGE_PYTHON_URLLIB3
After preparing the bootloader and administrative system image, they were loaded into the appropriate locations on the first SD card partition. The uboot
name was changed to Image
and loaded as the boot system – an overlay on the bootloader into the user
directory. System images were then loaded into this folder: the administrative system as Image.admin
and the user system as Image.user
. Finally, the processed boot.scr
file was added to the main directory of the first partition.
The administrative system was then booted, and two partitions were created on the SD card with ext4 formatting using the commands:
fdisk /dev/mmcblk0
D
3
D
2
N
P
2
<enter>
+500M
N
P
3
<enter>
+500M
W
and
mkfs.ext4 /dev/mmcblk0p2
mkfs.ext4 /dev/mmcblk0p3
Data from the user system file system was transferred using the command:
wget -O - 192.168.145.101:8000/rootfs.ext2 | dd of=/dev/mmcblk0p2 bs=4096
Finally, the transferred file system image was resized to the partition size with:
resize2fs /dev/mmcblk0p2
After these operations, the system was restarted, and the user system was booted. Console messages indicated that the third partition was mounted and the file-serving server was running.
On the departmental computer, a webpage was opened at the address reported by the RPi4 device. After logging in, it was possible to upload and download files contained on the third partition.
Bootloader Sources:
Bootloader Button Configuration Sources:
Disk Partitioning in Linux Sources:
Disk Resizing in Linux Sources:
Tornado Server Creation Sources: