Keyboard shortcuts

Press or to navigate between chapters

Press S or / to search in the book

Press ? to show this help

Press Esc to hide this help

PowerPC Toolchain

Build Linux kernels and software for PowerPC targets.

Quick Install (Debian/Ubuntu)

sudo apt install -y \
    gcc-powerpc64-linux-gnu \
    g++-powerpc64-linux-gnu \
    binutils-powerpc64-linux-gnu

Verify:

powerpc64-linux-gnu-gcc --version

Test Cross-Compilation

Hello World

// hello.c
#include <stdio.h>
int main() {
    printf("Hello from PowerPC!\n");
    return 0;
}

Compile:

powerpc64-linux-gnu-gcc -o hello hello.c
file hello

Expected:

hello: ELF 64-bit MSB executable, 64-bit PowerPC

Linux Kernel Build

1. Get Kernel Source

git clone --depth 1 -b v6.1 https://git.kernel.org/pub/scm/linux/kernel/git/stable/linux.git
cd linux

2. Configure for Microwatt

make ARCH=powerpc CROSS_COMPILE=powerpc64-linux-gnu- microwatt_defconfig

Or for custom config:

make ARCH=powerpc CROSS_COMPILE=powerpc64-linux-gnu- menuconfig

3. Build

make ARCH=powerpc CROSS_COMPILE=powerpc64-linux-gnu- -j$(nproc)

Build time: 10-30 minutes depending on CPU.

Output: arch/powerpc/boot/zImage

Device Tree Compilation

Install DTC

sudo apt install -y device-tree-compiler

Compile DTB

dtc -I dts -O dtb -o microwatt.dtb microwatt.dts

Decompile for inspection

dtc -I dtb -O dts microwatt.dtb

Endianness

PowerPC is big-endian. Common issues:

// Wrong (host endian)
uint32_t val = *(uint32_t*)ptr;

// Correct (explicit)
uint32_t val = be32_to_cpu(*(uint32_t*)ptr);

Or in userspace:

#include <endian.h>
uint32_t val = be32toh(raw_val);

Environment Variables

For kernel builds, add to ~/.bashrc:

export ARCH=powerpc
export CROSS_COMPILE=powerpc64-linux-gnu-

Then simply:

make microwatt_defconfig
make -j$(nproc)

Common Issues

“Compiler not found”

sudo apt install -y gcc-powerpc64-linux-gnu

“Cannot execute binary” Cross-compiled binaries only run on PowerPC hardware or QEMU:

sudo apt install -y qemu-user-static
qemu-ppc64-static ./hello

Toolchain for A2O

A2O uses same PowerPC64 toolchain. Additional flags may be needed for specific ISA features:

powerpc64-linux-gnu-gcc -mcpu=power7 -maltivec -o program program.c

Next Steps