“Building an Embedded Linux Environment on Raspberry Pi 4B: A Complete Guide from Scratch”
Introduction
The Raspberry Pi 4B, as a widely popular embedded development platform, is an ideal choice for embedded Linux development due to its powerful performance and rich peripheral interfaces. This article is aimed at embedded development engineers and provides a detailed guide on how to set up a professional Raspberry Pi Linux development environment, enabling you to perform kernel development, driver writing, and application building.

Hardware and Software Requirements
Hardware Requirements:
- Raspberry Pi 4B (4GB/8GB RAM version)
- High-speed SD card (32GB or larger)
- 5V/3A USB-C power supply
- USB to serial module
Software Requirements:
- Host Operating System: Ubuntu 22.04 LTS
- GNU Toolchain (gcc-arm-linux-gnueabihf 10.3)
- Linux Kernel Source Code (5.15 LTS)
- Buildroot 2024.02
Overview of the Development Environment
We will set up a complete cross-compilation environment, including toolchain configuration, kernel compilation, and root filesystem construction. Buildroot will be used to simplify the system building process, achieving an efficient development workflow. The entire environment supports kernel debugging, device tree modifications, and driver development.
Preparing the Host Development Environment
# Install basic development tools
sudo apt-get update
sudo apt-get install -y build-essential git bc bison flex libssl-dev make libc6-dev libncurses5-dev crossbuild-essential-arm64
Configuring the Cross-Compilation Toolchain
# Set up the cross-compilation environment
export PATH=/usr/bin:$PATH
export CROSS_COMPILE=arm-linux-gnueabihf-
export ARCH=arm
Obtaining and Configuring the Kernel Source Code
# Get the kernel source code
git clone --depth=1 -b rpi-5.15.y https://github.com/raspberrypi/linux.git
cd linux
# Configure and compile the kernel
make bcm2711_defconfig
make -j4 zImage modules dtbs
Building the Root Filesystem
# Get and configure Buildroot
git clone https://git.buildroot.net/buildroot
cd buildroot
make raspberrypi4_64_defconfig
make menuconfig # Select the required packages
make -j4
Configuring the System Boot
# Configure the boot partition
cp arch/arm/boot/zImage /media/boot/
cp arch/arm/boot/dts/*.dtb /media/boot/
Common Issues and Solutions
- Compilation Errors: Check the compatibility of the toolchain version
- Boot Failure: Ensure the device tree is correctly configured
- Network Issues: Check the network driver options in the kernel configuration
Conclusion
After completing the above configurations, you will have a complete Raspberry Pi Linux development environment. This provides a solid foundation for subsequent driver development and application porting. It is recommended to further study device tree development and kernel debugging techniques.