Configuring Your Raspberry Pi with /boot/firmware/config.txt

Ben
Ben
@benjislab

The /boot/firmware/config.txt file is a critical configuration file on your Raspberry Pi that allows you to customize hardware settings and optimize system performance. With the latest updates to Raspberry Pi OS, this file has been moved to the /boot/firmware/ directory. This guide will help you understand the key settings in config.txt, how to modify them, and best practices for using this file to tailor your Raspberry Pi setup.

Accessing and Editing the /boot/firmware/config.txt File

To modify the config.txt file, you can use a text editor directly on the Raspberry Pi or by accessing the SD card from another computer.

Editing Directly on the Raspberry Pi

  1. Open a Terminal: If you’re using the Raspberry Pi directly or via SSH, open the terminal.

  2. Edit the config.txt File: Use the nano text editor to open the file:

sudo nano /boot/firmware/config.txt
  1. Make Changes: Modify the file according to your needs, as described in the sections below.

  2. Save and Exit: After making changes, save the file by pressing Ctrl+X, then Y, and hit Enter.

Editing from Another Computer

If you need to edit the config.txt file from another computer:

  1. Power Off the Raspberry Pi: Safely shut down the Raspberry Pi.
sudo shutdown now
  1. Remove the SD Card: Take the SD card out and insert it into your computer.

  2. Locate the config.txt File: The config.txt file is in the boot/firmware partition, which is typically accessible on most computers.

  3. Edit the File: Open the file in a text editor, make your changes, save the file, and safely eject the SD card.

  4. Reinsert the SD Card: Put the SD card back into the Raspberry Pi and power it on.

Key Settings in /boot/firmware/config.txt

The config.txt file contains numerous settings that allow you to control the behavior of your Raspberry Pi. Below are some of the most commonly used settings:

1. Enabling Hardware Interfaces

The config.txt file allows you to enable various hardware interfaces that are not enabled by default.

  • Enable I2C, I2S, and SPI:

Uncomment the following lines to enable these interfaces:

dtparam=i2c_arm=on
dtparam=i2s=on
dtparam=spi=on

2. Audio Configuration

The default configuration enables audio output, but you can modify this if necessary.

  • Enable Audio:

Ensure that the following line is set to enable audio:

dtparam=audio=on

3. Camera and Display Auto-Detection

The Raspberry Pi can automatically detect and configure attached cameras and displays.

  • Enable Camera Auto-Detection:
camera_auto_detect=1
  • Enable Display Auto-Detection:
display_auto_detect=1

4. Initramfs Auto-Loading

The config.txt file can be configured to automatically load initramfs files if they are present.

  • Enable Initramfs Auto-Loading:
auto_initramfs=1

5. Graphics and Video Settings

The config.txt file allows you to configure video output settings, including enabling the VC4 graphics driver.

  • Enable DRM VC4 V3D Driver:

This setting enables the open-source VC4 graphics driver, which is required for advanced graphical features:

dtoverlay=vc4-kms-v3d
max_framebuffers=2
  • Disable Firmware Video Configuration:

If you prefer to use the kernel's default video settings instead of those set by the firmware:

disable_fw_kms_setup=1

6. Running in 64-Bit Mode

If your Raspberry Pi hardware and OS support 64-bit operation, you can enable it using this setting.

  • Enable 64-Bit Mode:
arm_64bit=1

7. Disabling Overscan

Some displays might have black borders (overscan). Disabling overscan removes these borders.

  • Disable Overscan:
disable_overscan=1

8. Overclocking and Performance Tuning

You can boost the performance of your Raspberry Pi by enabling the firmware to run at the maximum speed allowed by your board.

  • Enable Arm Boost:
arm_boost=1

9. Custom Settings for Raspberry Pi Compute Module 4 (CM4)

For specific hardware configurations like the CM4, additional settings are available.

  • Enable Host Mode on USB Controller:

If using the built-in USB controller in host mode:

[cm4]
otg_mode=1
  • This line should be removed if you require the legacy USB controller (e.g., for USB device mode).

10. Default Settings for All Raspberry Pi Models

The [all] section can include settings that apply universally across all Raspberry Pi models.

Best Practices for Modifying /boot/firmware/config.txt

  • Backup Your File: Before making any changes, create a backup of your current config.txt file:
sudo cp /boot/firmware/config.txt /boot/firmware/config_backup.txt
  • Make Incremental Changes: Change one setting at a time and test your Raspberry Pi to ensure it behaves as expected.

  • Use Safe Overclocking Values: Overclock in small increments and monitor your Raspberry Pi’s stability and temperature.

  • Restore Defaults: If something goes wrong, you can restore the original configuration by using your backup or by editing the config.txt file on another machine.

Default ## /boot/firmware/config.txt File Example

# http://rptl.io/configtxt
# Some settings may impact device functionality. See link above for details
# Uncomment some or all of these to enable the optional hardware interfaces
#dtparam=i2c_arm=on
#dtparam=i2s=on
#dtparam=spi=on
# Enable audio (loads snd_bcm2835)
dtparam=audio=on
# Additional overlays and parameters are documented
# /boot/firmware/overlays/README
# Automatically load overlays for detected cameras
camera_auto_detect=1
# Automatically load overlays for detected DSI displays
display_auto_detect=1
# Automatically load initramfs files, if found
auto_initramfs=1
# Enable DRM VC4 V3D driver
dtoverlay=vc4-kms-v3d
max_framebuffers=2
# Don't have the firmware create an initial video= setting in cmdline.txt.
# Use the kernel's default instead.
disable_fw_kms_setup=1
# Run in 64-bit mode
arm_64bit=1
# Disable compensation for displays with overscan
disable_overscan=1
# Run as fast as firmware / board allows
arm_boost=1
[cm4]
# Enable host mode on the 2711 built-in XHCI USB controller.
# This line should be removed if the legacy DWC2 controller is required
# (e.g. for USB device mode) or if USB support is not required.
otg_mode=1
[all]

Conclusion

The /boot/firmware/config.txt file is an essential tool for configuring your Raspberry Pi’s hardware and system behavior. Whether you need to enable hardware interfaces, optimize video output, or boost performance, understanding and properly configuring this file will allow you to get the most out of your Raspberry Pi. Always proceed with caution when making changes, particularly when overclocking, and ensure you have backups to restore your system if needed.