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:UBI and UBIFS

From ReverseEngineering.wiki
Format
Magic UBI# (55 42 49 23), UBI! (55 42 49 21), UBIFS node 31 18 10 06
Extensions .ubi, .ubifs
Endianness big (UBI headers), little (UBIFS nodes)
License GPL-2.0 (Linux)
On this wiki Facts · Code · Notes · Topics

Raw NAND layer (UBI, erase blocks starting with 'UBI#' and 'UBI!' headers) and the filesystem on top (UBIFS, nodes with magic 0x06101831) found in NAND-based firmware dumps.

UBI (volume management over raw NAND)

The flash is split into physical erase blocks (PEB). Each starts with a 64-byte erase counter header (all big-endian):

  • magic UBI# (0x55424923), version (1), padding, ec (u64 erase counter), vid_hdr_offset (u32), data_offset (u32), image_seq (u32), padding, hdr_crc.

At vid_hdr_offset (usually 64 or the minimum I/O size, e.g. 512/2048) comes the 64-byte volume ID header: magic UBI! (0x55424921), version, vol_type (1 dynamic, 2 static), copy_flag, compat, vol_id (u32), lnum (logical erase block number), data_size, used_ebs, data_pad, data_crc, sqnum (u64), hdr_crc. Data starts at data_offset. The layout volume (vol_id 0x7FFFEFFF) holds the volume table; fastmap blocks are optional.

Reassemble a volume by collecting PEBs of one vol_id and ordering by lnum (higher sqnum wins on duplicates). The ubireader tools and ubi_reader extract images; nanddump plus knowledge of page/OOB layout is needed first when dumps include spare area.

UBIFS

On each volume: nodes with a 24-byte little-endian common header: magic 0x06101831 (bytes 31 18 10 06), crc, sqnum (u64), len, node_type, group_type. Format version 5. Compression ids: 0 none, 1 LZO, 2 zlib, 3 zstd (see Library:LZO, Format:Zstandard). Inode, data, directory entry, superblock and master nodes live in LEBs; the superblock is in LEB 0, masters in LEBs 1 and 2. Payload files are chunked in 4096-byte data nodes.

Analyst notes

Scan for UBI# at multiples of the PEB size to find the start and derive the PEB size from the spacing. Typical NAND router/camera firmware: kernel in a raw partition (maybe a Format:FIT image or Format:U-Boot legacy uImage), rootfs as UBIFS or a SquashFS volume inside UBI. Compare Format:JFFS2 for NOR.

Sources: Linux drivers/mtd/ubi/ubi-media.h, fs/ubifs/ubifs-media.h.