Skip to content

Firmware modification guide

Carl Kittelberger edited this page Jul 12, 2026 · 1 revision

Firmware Modification Guide

This guide explains how to modify the Denon PRIME 4 firmware to include custom software using Yocto/OpenEmbedded builds.

Overview

The Denon PRIME 4 uses the AZ01 firmware format which relies on SHA1 hash verification, not cryptographic signatures. This means we can modify the firmware by:

  1. Building custom software with Yocto
  2. Extracting the official firmware
  3. Replacing/modifying files
  4. Recalculating SHA1 hashes
  5. Repacking with proper XZ stream

Repository Structure

denon-prime4/
├── docs/
│   └── reveng/
│       ├── yocto-build-guide.md
│       └── firmware-modification-guide.md
├── tools/
│   ├── extract-firmware.sh
│   ├── repack-firmware.sh
│   └── calculate-hashes.sh
├── yocto/
│   └── meta-denon/
│       ├── conf/
│       │   └── layer.conf
│       └── recipes-core/
│           └── images/
│               └── denon-prime4-image.bb
└── README.md

Step 1: Set Up Yocto Build Environment

Follow the Yocto Build Guide to set up the build environment.

Quick Setup

mkdir ~/yocto-prime4
cd ~/yocto-prime4

# Clone layers
git clone -b kirkstone https://git.yoctoproject.org/poky.git
git clone -b kirkstone https://git.openembedded.org/meta-openembedded
cd meta-openembedded
git clone -b kirkstone https://git.openembedded.org/meta-oe
git clone -b kirkstone https://git.openembedded.org/meta-python
git clone -b kirkstone https://git.openembedded.org/meta-networking
git clone https://github.com/JeffyCN/meta-rockchip.git

# Initialize build
cd ~/yocto-prime4/poky
source oe-init-build-env build-prime4

# Add meta-denon layer
echo "BBLAYERS += \"${HOME}/yocto-prime4/meta-denon\"" >> conf/local.conf

Step 2: Extract Official Firmware

cd /path/to/denon-prime4

# Extract XZ data
binwalk -e PRIME4-5.0.0-Update.img
cd extractions/PRIME4-5.0.0-Update.img/7D0194

# Decompress (binwalk already did this, but verify)
file decompressed.bin
# Should show: Linux rev 1.0 ext2 filesystem data

# Copy to working directory
cp decompressed.bin /tmp/firmware-work/firmware.ext2

Step 3: Build Custom Software

Example: Build a Custom Qt Application

# Create Yocto recipe
mkdir -p ~/yocto-prime4/meta-denon/recipes-core/my-app
cat > ~/yocto-prime4/meta-denon/recipes-core/my-app/my-app_1.0.bb << 'EOF'
SUMMARY = "My Custom App"
LICENSE = "CLOSED"
LIC_FILES_CHKSUM = "file://${COMMON_LICENSE_DIR}/MIT;md5=0835ade698e0bcf8506ecda2f7b4f302"

SRC_URI = "file://my-app"

do_install() {
    install -d ${D}${bindir}
    install -m 0755 my-app ${D}${bindir}/
}

FILES:${PN} = "${bindir}/*"
EOF

# Add source file
mkdir -p ~/yocto-prime4/meta-denon/recipes-core/my-app/files
# Copy your compiled app here

# Build
cd ~/yocto-prime4/poky/build-prime4
bitbake my-app

Step 4: Modify Firmware Filesystem

# Mount read-write
sudo mkdir /mnt/firmware
sudo mount -o loop,rw /tmp/firmware-work/firmware.ext2 /mnt/firmware

# Backup original
cp -a /mnt/firmware /tmp/firmware-work/firmware.backup

# Replace files
sudo cp /path/to/your/app /mnt/firmware/usr/Engine/
sudo cp /path/to/your/service /mnt/firmware/lib/systemd/system/

# Unmount
sudo umount /mnt/firmware

Step 5: Recalculate SHA1 Hashes

# Extract partition table
cd /tmp/firmware-work
dd if=PRIME4-5.0.0-Update.img bs=1 skip=$((0xA0)) count=4096 of=partition-table.bin

# Calculate hashes for modified partitions
# (This is complex - see tools/calculate-hashes.sh for details)

# Update partition table with new hashes
# (See tools/repack-firmware.sh)

Step 6: Repack XZ Stream

# Compress with proper XZ footer
cd /tmp/firmware-work
xz -9e firmware.ext2

# Extract XZ data
dd if=firmware.ext2.xz bs=1 skip=$((0x7D0194)) of=firmware.xz

# Replace in firmware image
# (See tools/repack-firmware.sh)

Step 7: Create Update Image

# Use tools/repack-firmware.sh to create final image
cd /tmp/firmware-work
../denon-prime4/tools/repack-firmware.sh \
  --input PRIME4-5.0.0-Update.img \
  --output PRIME4-MODIFIED-5.0.0-Update.img \
  --rootfs firmware.ext2.xz

# Flash to USB drive
dd if=PRIME4-MODIFIED-5.0.0-Update.img of=/dev/sdX bs=1M

Automation Scripts

extract-firmware.sh

#!/bin/bash
set -e

INPUT="${1:-PRIME4-5.0.0-Update.img}"
OUTPUT_DIR="${2:-/tmp/firmware-work}"

mkdir -p "$OUTPUT_DIR"
cd "$OUTPUT_DIR"

echo "Extracting firmware..."
binwalk -e "$INPUT"
cd extractions/$(basename "$INPUT" .img)/7D0194
cp decompressed.bin ../firmware.ext2

echo "Firmware extracted to $OUTPUT_DIR/firmware.ext2"

repack-firmware.sh

#!/bin/bash
set -e

INPUT="${1:---input}"
OUTPUT="${2:---output}"
ROOTFS="${3:---rootfs}"

# Parse arguments
while [[ $# -gt 0 ]]; do
    case $1 in
        --input) INPUT="$2"; shift 2;;
        --output) OUTPUT="$2"; shift 2;;
        --rootfs) ROOTFS="$2"; shift 2;;
        *) echo "Unknown option: $1"; exit 1;;
    esac
done

echo "Repacking firmware..."

# Compress rootfs with proper XZ footer
xz -9e "$ROOTFS"
XZ_FILE="${ROOTFS}.xz"

# Extract XZ data
dd if="$XZ_FILE" bs=1 skip=$((0x7D0194)) of=firmware.xz

# Replace in original image
dd if=firmware.xz of="$OUTPUT" bs=1 seek=$((0x7D0194)) conv=notrunc

echo "Modified firmware: $OUTPUT"

calculate-hashes.sh

#!/bin/bash
# Calculate SHA1 hashes for partition table
# This is complex and depends on partition layout

echo "Hash calculation requires partition table parsing"
echo "See firmware-image-structure.md for details"

Limitations

  1. Partition Table Parsing: The partition table format is complex (80 bytes per entry with variable-length names)
  2. Hash Calculation: Must match exact partition data including padding
  3. Boot Signatures: Some partitions may have additional signatures (need investigation)

Next Steps

  1. Test with overlay method first (simpler, no repackaging needed)
  2. Investigate partition table format in detail
  3. Create proper hash calculation tool
  4. Test flashing modified firmware
  5. Document any issues or workarounds

Related Documentation

Clone this wiki locally