Building an Open-Source Firmware Stack for AMD Ryzen AM5: A Step-by-Step Guide

From 391043 Stack, the free encyclopedia of technology

Overview

In recent developments, the open-source firmware community has made significant strides in bringing Coreboot and AMD's open-source silicon initialization library (openSIL) to modern AMD platforms. 3mdeb, a consulting firm specializing in firmware, has been simultaneously advancing two exciting initiatives: an open-source firmware stack for a Gigabyte EPYC server motherboard and a similar Coreboot + AMD openSIL port to a consumer Ryzen AM5 motherboard — the MSI PRO B850-P WiFi. While not yet ready for end users, 3mdeb's latest blog post highlights the milestone achieved in bringing up openSIL + Coreboot on this AM5 platform.

Building an Open-Source Firmware Stack for AMD Ryzen AM5: A Step-by-Step Guide

This guide provides a detailed walkthrough for developers and firmware enthusiasts who want to understand and replicate the process of building and testing an open-source firmware stack for an AMD Ryzen AM5 motherboard. The steps are based on 3mdeb's work and general Coreboot development practices.

Prerequisites

Before you begin, ensure you have the following:

  • Hardware:
    • MSI PRO B850-P WiFi motherboard (or compatible AM5 board)
    • AMD Ryzen 7000/8000 series CPU (Phoenix or Raphael)
    • DDR5 RAM
    • Dedicated GPU (for testing display)
    • USB flash drive (8GB+) for flashing
    • Serial debug cable (e.g., CH341A or FT232) for early boot debug
  • Software:
    • Linux host (Ubuntu 20.04+ or Fedora 36+)
    • Git, GCC, make, ncurses-dev, flex, bison, python3, etc.
    • Coreboot source code (branch main)
    • AMD openSIL source (from AMD's GitHub or 3mdeb's fork)
    • Flashrom utility
    • SeaBIOS or EDK2 payload (optional)
  • Skills:
    • Basic command-line and C programming knowledge
    • Familiarity with firmware flashing and hardware debugging
    • Understanding of x86 boot process

Step-by-Step Instructions

1. Set Up the Development Environment

Clone the necessary repositories:

git clone https://review.coreboot.org/coreboot.git
cd coreboot
git submodule update --init --checkout
# Clone openSIL
cd 3rdparty
git clone https://github.com/3mdeb/amd_openSIL.git openSIL
cd ..

Install dependencies:

sudo apt-get install -y git gcc g++ make flex bison python3-distutils ncurses-dev
# For Fedora: sudo dnf install @development-tools ncurses-devel

2. Configure Coreboot for MSI PRO B850-P WiFi

Run the configuration interface:

make menuconfig

Set the following options:

  • Mainboard → Vendor: MSI, Model: PRO B850-P WiFi (if not present, select 'Emulation' and manually specify variant)
  • Chipset → AMD → Phoenix (or Raphael depending on CPU)
  • Firmware → Include openSIL: enable (set path to 3rdparty/openSIL)
  • Payload → Add a payload (e.g., SeaBIOS or EDK2)
  • Debug → Enable serial output (COM1, 115200 baud)

Save configuration as .config.

3. Build the Coreboot Image

Compile the firmware:

make crossgcc-i386 CPUS=$(nproc)
make -j$(nproc)

If successful, you'll get build/coreboot.rom. This image includes the Coreboot bootblock, openSIL initialization code, and the payload.

4. Flash the Firmware to the Motherboard

Backup the original firmware first:

sudo flashrom -p internal -r backup.rom

If your board has a SPI flash chip, you may need to use a hardware programmer (e.g., CH341A) because internal flashing while running the old firmware may conflict. Connect the programmer to the SPI header (usually near the CMOS battery). Then:

sudo flashrom -p ch341a_spi -w build/coreboot.rom

Verify the write:

sudo flashrom -p ch341a_spi -v build/coreboot.rom

5. Boot and Debug

Connect a serial cable to the UART header on the motherboard (pins: TX, RX, GND). Open a terminal on your host (e.g., minicom or screen):

screen /dev/ttyUSB0 115200

Power on the board. You should see Coreboot bootlog. Look for openSIL initialization messages. If the system hangs or fails to boot, check the logs for error codes. Common early boot issues include incorrect memory training or missing ACPI tables.

6. Iterate and Improve

Based on debug output, adjust configuration (e.g., enable more debug options in openSIL) or fix code. Rebuild and reflash. The milestone achieved by 3mdeb involved getting past memory initialization and reaching payload execution. Similar steps apply.

Common Mistakes

  • Wrong openSIL version: Use the specific branch or commit that matches your Coreboot version. Mixing versions can cause compilation errors.
  • Incomplete submodule update: After cloning, always run git submodule update --init --recursive to fetch openSIL and other dependencies.
  • Flashing without backup: Always backup the original firmware. Bricking the board may require a hardware programmer to recover.
  • Missing serial debug: Without serial output, diagnosing boot failures is nearly impossible. Invest in a 3.3V UART adapter.
  • Incorrect payload selection: For AM5, SeaBIOS may not support all features; EDK2 (TianoCore) is more compatible.
  • Power supply insufficient: The MSI PRO B850-P WiFi may draw more power during early bring-up; ensure at least 650W PSU.

Summary

This guide covered the essential steps to build and test an open-source firmware stack (Coreboot + AMD openSIL) on an MSI PRO B850-P WiFi AM5 motherboard. The process involves setting up the development environment, configuring Coreboot with openSIL support, building the firmware, flashing via SPI, and debugging through serial output. 3mdeb has achieved a significant milestone in this bring-up, demonstrating the feasibility of open firmware on modern AMD consumer platforms. While end-user readiness is still in progress, developers can use this guide to contribute to the effort. The final output is a functional open-source firmware that replaces the proprietary UEFI, offering greater transparency and customization for the Ryzen AM5 ecosystem.