### Introduction
In today's rapidly developing Internet of Things (IoT) and edge computing landscape, the Raspberry Pi 4B, with its powerful quad-core Cortex-A72 architecture and rich expansion interfaces, has become an ideal platform for embedded Linux development. This article will detail the process of building a complete embedded Linux development environment from scratch, aimed at developers with a basic understanding of Linux, providing a standardized configuration scheme that can be reused directly.
### Hardware and Software Requirements
Hardware Requirements:
- Raspberry Pi 4B (Broadcom BCM2711, 4GB RAM)
- 32GB Class 10 microSD card and card reader
- 5V/3A Type-C power adapter
- USB to serial debugging module (CP2102/CH340)
Software Requirements:
- Host Operating System: Ubuntu 22.04 LTS
- Cross-compilation Toolchain: gcc-linaro-arm-linux-gnueabihf-raspbian
- Kernel Version: linux-rpi-5.15.y
- Buildroot 2023.02.1
### Overview of the Development Environment
This environment uses a cross-compilation architecture to build a complete system for the ARM architecture on an x86 host. The workflow includes: toolchain configuration → kernel compilation → root filesystem construction → firmware packaging → SD card flashing. Each component is version-controlled through a unified SDK directory structure.
### Preparing the Host Development Environment
```bash
# Install basic dependencies
sudo apt install build-essential git bc bison flex libssl-dev
# Install SD card tools
sudo apt install dosfstools parted
Configuring the Cross-compilation Toolchain
# Download the precompiled toolchain
wget https://github.com/raspberrypi/tools/archive/refs/tags/1.0.2.tar.gz
# Configure environment variables
export PATH=$PATH:/opt/rpi-tools/arm-bcm2708/gcc-linaro-arm-linux-gnueabihf-raspbian/bin
export CROSS_COMPILE=arm-linux-gnueabihf-
export ARCH=arm
Obtaining and Configuring the Kernel Source
git clone --depth=1 --branch rpi-5.15.y https://github.com/raspberrypi/linux
cd linux
make bcm2711_defconfig
# Graphical configuration (optional)
make menuconfig
# Compile the kernel
make -j4 zImage modules dtbs
Building the Root Filesystem
Use Buildroot to quickly build a minimal system:
make raspberrypi4_defconfig
make menuconfig # Select SSH and necessary drivers
make
The output image is located at output/images/sdcard.img
System Boot Configuration
Create config.txt to configure boot parameters
arm_64bit=1
kernel=zImage
dtoverlay=vc4-fkms-v3d
Deploying the System on the Development Board
# Check the SD card device path (assumed to be /dev/sdb)
sudo fdisk -l
# Write the image
sudo dd if=sdcard.img of=/dev/sdb bs=4M status=progress
Environment Testing and Verification
After powering on, log into the system via the serial terminal (115200bps) to verify:
- Use ifconfig to check network status
- Use lsmod to confirm driver loading
- Use dmesg | grep -i error to check for errors
Common Issues and Solutions
Q1: SD card boot failureA: Check if the partition table is in MBR format and ensure the boot partition is FAT32 format
Q2: USB device not recognizedA: Enable CONFIG_USB_EHCI_HCD and CONFIG_USB_OHCI_HCD in the kernel configuration
Development Environment Optimization
It is recommended to install openocd for JTAG debugging and configure the VSCode remote development plugin as follows:
// .vscode/settings.json
"remote.SSH.defaultExtensions": [ "ms-vscode.cpptools"]
The embedded Linux environment built using this guide provides a foundation for application development. Future exploration can delve into advanced topics such as device tree customization and real-time kernel patches, along with using Yocto to build more complex industrial-grade systems. It is advisable to regularly synchronize with the official SDK updates to obtain the latest security patches.
undefined