Table of Contents
Firmware Basics
Understanding firmware structure is key to unbricking and flashing.
Firmware Structure
A router firmware typically consists of the following parts.
Flash Partitions
| Partition Name | Size (Typical) | Contents |
|---|---|---|
| u-boot | 256KB-512KB | Bootloader |
| kernel | 3MB-5MB | Linux kernel |
| rootfs | Remaining space | Root filesystem |
| nvram | 64KB-128KB | Configuration storage |
| art | 64KB | Wireless parameters |
Filesystem Types
- SquashFS: Read-only compressed filesystem, common in OEM firmware
- JFFS2: Read-write, common in OpenWrt
- UBIFS: For large-capacity NAND Flash
- YAFFS2: Used in early embedded devices
Firmware Formats
Common Extensions
- .bin: Generic binary format
- .trx: Linksys/ASUS firmware format
- .chk: Netgear-specific format
- .img: Generic image format
Firmware Header
Most firmware starts with a fixed header:
00 00 00 00 4D 49 50 53 # MIPS identifier
or
FF FF FF FF # Common in TP-Link
Boot Process
Complete Boot Sequence
- Power on β CPU initialization
- U-Boot β Reads environment variables
- Kernel load β Reads kernel from Flash
- Filesystem β Mounts root filesystem
- Network init β Starts network services
- Web service β HTTP service ready
U-Boot Boot Arguments
bootcmd=bootm 9f020000 bootargs=console=ttyS0,115200 root=/dev/mtdblock2
Interrupting Boot
Press a specific key during boot to enter:
- Enter: Enter command mode
- tftp: Network boot
- firmware: Specify firmware location
Bootloader Introduction
U-Boot
The most versatile open-source bootloader.
- Supports multiple CPU architectures (MIPS/ARM/x86)
- Supports network boot (TFTP)
- Boot arguments can be modified
- Common in some Xiaomi and Huawei models
setenv ipaddr 192.168.1.1 setenv serverip 192.168.1.100 tftpboot 0x81000000 firmware.bin erase 0x9f000000 +0x300000 cp.b 0x81000000 0x9f000000 0x300000
Breed
A closed-source bootloader common in domestic routers in China.
- User-friendly interface (Web console)
- Supports multiple firmware backups
- Built-in TFTP recovery
- Common in PandoraBox and Padavan firmware
CFE
Broadcom chip-specific bootloader.
- Used in some Netgear and ASUS models
- Serial console operation
- Supports NFS network boot
OEM Boot
- Simple functionality
- Can only flash official firmware
- Some can be unlocked for third-party firmware
Firmware Modification
Extracting Firmware
# Use binwalk to extract binwalk -e firmware.bin # Or manually decompress tar -xvf openwrt.bin
Modification Tools
- firmware-mod-kit: Firmware modification toolkit
- binwalk: Firmware analysis tool
- squashfs-tools: SquashFS filesystem tools
Flashing Firmware
- Upload via Web interface
- Flash via TFTP
- Via U-Boot command line
- Direct Flash write via TTL Serial
Security Checks
Firmware Signing
Modern routers have firmware signature verification:
- Secure Boot: Only allows official firmware
- Bootloader lock: Flash write disabled
- Flash lock: Read protection enabled
Bypass Methods
- Direct Flash write via TTL Serial
- Short specific pins on the Flash chip
- Exploit downgrade vulnerability to lower version