Device Tree Implementation Guide for ARM Devices

Device Tree Implementation Guide for ARM Devices

1. Core Concepts

Device Tree Source (DTS)

  • Human-readable text files describing hardware components
  • Contains CPU, memory, and peripheral configurations
  • Examples:
  • bcm2711-rpi-4-b.dts for Raspberry Pi 4 Model B
  • bcm2712-rpi-5-b.dts for Raspberry Pi 5 Model B
  • Base Configuration:
  • Includes bcm2712.dtsi for base SoC configuration
  • Includes bcm2712-rpi.dtsi for common Raspberry Pi specific configurations

Device Tree Blob (DTB)

  • Compiled binary format of DTS files
  • Loaded by bootloader during system initialization
  • Examples:
  • bcm2711-rpi-4-b.dtb for Pi 4
  • bcm2712-rpi-5-b.dtb for Pi 5

2. File System Structure


arch/arm64/boot/dts/
├── broadcom/
│   ├── bcm2711-rpi-4-b.dts    # Pi 4 Model B DTS
│   ├── bcm2711-rpi-4-b.dtb    # Pi 4 Model B DTB
│   ├── bcm2712-rpi-5-b.dts    # Pi 5 Model B DTS
│   ├── bcm2712-rpi-5-b.dtb    # Pi 5 Model B DTB
│   ├── bcm2711-rpi.dtsi       # Shared Pi 4 definitions
│   └── bcm2712.dtsi           # Shared Pi 5 definitions
├── overlays/                   # Device Tree Overlays
├── northstar2/                 # BCM490x router configs
└── stingray/                   # BCM95852x switch configs
        

3. Implementation Process

3.1 Deployment Steps

  • DTB Selection
  • Raspberry Pi 4: Use bcm2711-rpi-4-b.dtb
  • Raspberry Pi 5: Use bcm2712-rpi-5-b.dtb

File Installation bash
# For Raspberry Pi 5:
sudo cp arch/arm64/boot/dts/broadcom/bcm2712-rpi-5-b.dtb /boot/firmware
sudo cp arch/arm64/boot/Image /boot/firmware/kernel8.img
Boot ConfigurationCopy
# In /boot/firmware/config.txt
kernel=kernel8.img
device_tree=bcm2712-rpi-5-b.dtb
        

  • Architecture Verification
  • Ensure kernel8.img for 64-bit ARMv8 systems
  • Verify compatibility with target device

3.2 Dynamic Memory Configuration


/* Will be filled by the bootloader */
memory@0 {
    device_type = "memory";
    reg = <0 0 0x28000000>;
};
        

This placeholder in the DTS allows the bootloader to dynamically configure system memory. The actual values are filled in during the boot process based on the hardware configuration.

3.3 Boot Process Integration

Bootloader Phase

  1. Bootloader retrieves kernel and DTB from /boot/
  2. U-Boot loads both into RAM
  3. DTB modifications if needed (memory, boot args)
  4. DTB address passed to kernel via register x0

4. U-Boot DTB Usage

4.1 Hardware Configuration

U-Boot uses DTB to:

  • Configure hardware initialization
  • Set up memory controllers
  • Initialize critical peripherals
  • Configure boot parameters

4.2 DTB Modification Capabilities

  • Can modify DTB before passing to kernel
  • Updates memory information
  • Adjusts clock speeds
  • Modifies boot parameters

5. Technical Implementation

5.1 Key Source Files in linux kernel

Entry Point (/arch/arm64/kernel/head.S)

assembly
preserve_boot_args:
    mov     x21, x0             // x21=FDT
    adr_l   x0, boot_args       // record the contents of
    stp     x21, x1, [x0]       // x0 .. x3 at kernel entry
...
    str_l   x21, __fdt_pointer, x5      // Save FDT pointer
        

Architecture Setup (/arch/arm64/kernel/setup.c)

c
void __init __no_sanitize_address setup_arch(char **cmdline_p)
{
    setup_machine_fdt(__fdt_pointer);
    
    if (acpi_disabled)
        unflatten_device_tree();
}
        

6. Raspberry Pi 5 Specific Configuration

This DTS file is the device tree source for the Raspberry Pi 5 Model B, which describes the hardware configuration of the board. Let me explain the key components:

6.1 Hardware Components

  • Memory: Configurable system memory
  • LEDs:
  • Power LED: RP1 GPIO 44
  • Activity LED: GIO AON pin 9
  • Power Management:
  • SD card I/O voltage regulator (1.8V/3.3V switchable)
  • SD card VCC regulator (3.3V fixed)

6.2 Interfaces

  • Multiple I2C buses (i2c0, i2c3, i2c4, i2c5, i2c6, i2c8)
  • SPI interfaces (spi0, spi3, spi4, spi5, spi6)
  • UART ports (uart0, uart2, uart5)
  • PWM controllers (pwm0, pwm1)
  • I2S audio interface

7. Boot Chain DTB Handling

  • VideoCore Firmware Reads config.txt
  • Loads specified DTB
  • Modifies based on hardware detection and settings
  • Fills in dynamic values like memory configuration
  • U-Boot Stage
  • Receives modified DTB
  • Can perform additional modifications
  • Passes to kernel
  • Linux Kernel
  • Receives final DTB
  • Uses for hardware initialization
  • Sets up drivers and system environment


要查看或添加评论,请登录

David Zhu的更多文章

社区洞察

其他会员也浏览了