Jump to content
Setting up an AI agent? ReverseEngineering.wiki skill (works from the command line, no configuration): https://reverseengineering.wiki/skill/rewiki/SKILL.md · setup for every client, including MCP: https://reverseengineering.wiki/llms.txt · REWiki:Connect

Format:Broadcom TRX

From ReverseEngineering.wiki
Format
Magic 48 44 52 30 ("HDR0", 0x30524448 little-endian)
Extensions .trx, .bin
Endianness little
On this wiki Facts · Code · Notes · Topics

The little-endian firmware container of Broadcom-based routers (magic "HDR0"): a 28-byte (v1) or 32-byte (v2) header with length, CRC32, flags/version and up to 3 (v1) or 4 (v2) partition offsets, followed by the loader, kernel and root filesystem.

Header

All fields are little-endian. In OpenWrt firmware-utils trx.c the header is struct trx_header (lines 61-67) with TRX_MAGIC 0x30524448 (line 57).

Offset Size Field
0x00 4 magic HDR0 (bytes 48 44 52 30)
0x04 4 len: length of the file including the header
0x08 4 crc32: CRC-32 from offset 0x0C (flag_version) to the end of the file
0x0C 2 flags
0x0E 2 version: 1 or 2
0x10 4 x 3 offsets[0..2]: partition offsets from the start of the header (0 = unused)
0x1C 4 offsets[3]: only present in version 2

The struct declares four offsets, but a v1 file is written with sizeof(struct) - 4 = 28 bytes of header, so the first partition starts at 0x1C. Option -2 makes the tool use version 2 and a 32-byte header (the first partition then starts at 0x20). Partition offsets are measured from the header start, so the first one equals the header size (28 or 32).

How the tool lays it out

  • Each input file is zero-padded to a multiple of 4 bytes (lines 145-153); the whole image is padded to a multiple of 0x1000 (line 255). Default maximum length TRX_MAX_LEN is 0x720000 (line 58).
  • The usual contents are a loader or kernel, then a kernel/rootfs pair. Unverified: on many Broadcom routers offset 1 is an LZMA-compressed kernel and offset 2 a SquashFS root filesystem (carve at the offsets and identify each part, see Format:SquashFS and Format:LZMA).
  • The -M option replaces the magic (line 234), so vendor variants of the same layout exist with another 4-byte magic. Unverified: which vendors use which values.

CRC rule

The CRC is the plain reflected CRC-32 table loop with initial value 0xFFFFFFFF and no final inversion (crc32buf, lines 403-415), computed over the bytes from flag_version (offset 0x0C) to the end of the padded image, so crc32 and len themselves are not covered. For version 2 the tool first sets 8 bytes at offset 22 of the last partition's 32-byte "bin header" to 0xFF (the stable and try1-3 counters, as the CFE bootloader does) while computing the CRC, then restores them (lines 261-282). A reader that verifies the CRC of a v2 file must apply the same masking. Unverified: the exact meaning of the bin-header fields beyond the comment in the source.

Recognising and carving

  • binwalk (ReFirmLabs/binwalk, src/structures/trx.rs lines 14-83) parses the header little-endian, accepts only versions 1 and 2, requires total_size greater than the fixed header, requires offsets 1 to 3 not to exceed total_size, ignores zero offsets, and treats the fourth offset only for version 2 (header size 28 otherwise).
  • Next steps: split the file at the offsets, run the kernel part through the matching decompressor and mount or extract the root filesystem; see Technique:Unpacking firmware update containers and Platform:Linux kernel.
  • Vendors often wrap a TRX in another header, for example Format:Netgear CHK.

Sources

openwrt/firmware-utils src/trx.c (GPL-2.0-or-later); ReFirmLabs/binwalk (MIT).

Code & repositories

  • https://github.com/openwrt/firmware-utils @ 0179ab1e367f756ac108a485f26585661d4c528c · license: GPL-2.0-or-later (declared by the contributor; GitHub's detector did not recognize a license file)
    Image-building tools for router firmware: trx.c, mkchkimg.c, mktplinkfw.c, tplink-safeloader.c, seama.c/seama.h; per-file licenses (GPL-2.0-or-later, GPL-2.0-only, BSD-2-Clause, BSD-3-Clause, LGPL-2.1-or-later)
    Tested on: source read, not run: source read, not built · checked 2026-10-19; last activity 2026-10-12
  • https://github.com/ReFirmLabs/binwalk @ 26713972e3f9f52dc37d4a421c4554b0bd9e82ef · license: MIT
    binwalk 3 (Rust): signature and header parsers for TRX, CHK, SEAMA, TP-Link and other firmware formats
    Tested on: source read, not run: source read, not built · checked 2026-10-19; last activity 2026-08-11