Welcome
Username:

Password:


Remember me

[ ]
[ ]
[ ]
Online
Guests: 5, Members: 0 ...

most ever online: 27
(Members: 0, Guests: 27) on 01 Jul : 17:15

Members: 12
Newest member: tlew
GigaFast WF719-CAPR 802.1b/g wireless router
Collected notes on the router, it's operation, and hacks.
on Sunday 09 April 2006
by mattei author list
in Notebook > Technical
hits: 8384


**Please note (for this page)**
I went through this a while back with earlier firmware and wanted to get it put up. This isn't everything, what's here is incomplete, and likely contains mistakes. I hope to update and complete it as time permits.

Examining the firmware

In the reference/turnkey designs from RealTek, a 16KB plus 8KB total boot block is always configured at 0xbfc0_0000. The next 8KB block, at 0xbfc0_6000, contains 8186 hardware settings (MAC address, RF parameters, etc.). The 32KB block following at 0xbfc0_8000, organized as two identical 16KB structures, holds the default and current parameters referenced by the OS/kernel, such as IP address, SSID, channel number, etc. respectively.

RealTek selected Linux as the embedded operating system for their Access Point, Gateway, and VPN reference designs. Web-based configuration is made possible with the inclusion of an embedded system focused webserver, GoAhead Webserver. The daemon is started by the OS and serves pages allowing configuration changes via form submissions. These web pages are stored in a 64KB block located at 0xbfc1_0000.

Flash memory layout
Virtual address Flash sector size Usage
0xbfc0_0000 16K Boot code
8K
0xbfc0_6000 8K Hardware settings
0xbfc0_8000 32K Default settings (16K)
Current settings (16K)
0xbfc1_0000 64K Web pages
0xbfc2_0000 64K (?? VPN model) or
896K - 1920K
Linux

The remainder of flash memory stores the operating system. While the size of allocated memory changes, dependent on product model and size of the flash part, the image always begins at 0xbfc2_0000. Apparently, a 1024KB read-only Squashfs root file system can be configured at 0xbfd0_0000 on some reference designs.

btcode v1.4 Flash memory layout
Virtual address Flash sector size Usage
0xbfc0_0000 16K Boot code
8K
0xbfc0_6000 1K Hardware settings
0xbfc0_6400 7K Default settings
0xbfc0_8000 32K Current settings
0xbfc1_0000 64K Web pages
0xbfc2_0000 896K or 1920K Linux

CC & C WA-2204 firmware v1.4.2

I'll be using firmware v1.4.2 here for reference. Any version changes will be marked.


Boot code

The RealTek boot loader is named btcode and is currently at version 1.4. An alternative boot loader, rtk-lxload, is available from the RTL8181 sourceforge project. It is based on the hfload open-source boot code written by Jay Carlson. In firmware versions before 1.4, direct network flashing was not possible. Since v1.4, the Linux and web page images can be written to the flash part of the device via TFTP.

btcode v1.4 checks 0xBFC1_0000, 0xBFC2_0000, and 0xBFC3_0000 for a vaild CSYS image, verifying the hardware, default, and current settings at each check. When found, the image (minus header) is copied to SDRAM, starting at the address specified in the CSYS header. After transfer, execution begins at the start of the image in SDRAM: 0x8080_0000 in the case of firmware v1.4.2.


Hardware settings

The sector begins with a 2 byte signature, "HS", and ends with a 2 byte checksum.

TODO: map settings
Hardware settings are manipulated by the system using the "flash" command line binary. Individual settings, or MIBS, can be listed and are "set" or "get".This flash tool also extracts the contents of the 64KB web page area.


Configuration settings

The default settings sector begins with a 6 byte header and ends with a 2 byte checksum:
<6 byte header><settings><2 byte checksum>
The header is composed of:
2 byte signature: DS
2 byte version code
2 byte length

Current settings are located after default settings and use the same header layout with a "CS" signature. The current settings version must match the default settings version. To obtain a plaintext version of a saved configuration settings file, subtract each byte value of the binary default/saved image from 0xc7.

Perl one-liner:
perl -mbytes=no -npe "s/./chr(0xc7-ord($&))/eg" config.dat > config-plaintext.dat 

The example above was first posted on BC Wireless.


Web pages

A "WEBP" image consisting of a 16 byte header and 2 byte checksum at the end:
<16 byte header><image><2 byte checksum>
Our header: 57 45 42 50 00 01 00 00 00 01 00 00 00 00 FF 34

The header breaks down as:
4 byte signature:     WEBP
4 byte start address: 00 01 00 00 = 0x0001_0000
4 byte burn address:  00 01 00 00 = 0x0001_0000
4 byte length:        00 00 FF 34 = 65,332 bytes

The checksum, composed of the final 2 bytes, is 23 ED. The web page binary image appears to be a bzip2 archive, leading with the magic "BZh91AY". To obtain the uncompressed web page binary image:
dd if=webpages-vpn.bin of=webpages-vpn.bz2 skip=1 bs=16
bunzip webpages-vpn.bz2
Pages seem to be stored using the following structure:
64 byte path string
2 byte record length
<record length> byte binary page



Linux

A "CSYS" image consisting of a 16 byte header and 2 byte checksum at the end:
<16 byte header><image><2 byte checksum>
Our header: 43 53 59 53 80 80 00 00 00 03 00 00 00 17 5C 02

The header breaks down as:
4 byte signature:     CSYS
4 byte start address: 80 80 00 00 = 0x8080_0000
4 byte burn address:  00 03 00 00 = 0x0030_0000
4 byte length:        00 17 5C 02 = 1,530,882 bytes

The final two bytes in our v1.4.2 file are CF 57, the checksum. While prior system images used gzip compression, LZMA has now replaced it.

To uncompress the system image, the CSYS header and bootloader must be removed. The resulting binary can then be decompressed as an LZMA stream. A utility to decompress LZMA streams is available for Windows in the LZMA SDK. Tukaani LZMA Tools can be used in Linux.

The boot log indicates a 6,348,800 byte (6,200 KB) RAM disk, starting at address 0x801d_8000. 6,455,296 bytes (6,304 KB) are available, leaving 104 KB.

To retrieve the ramdisk ext2 partition from the uncompressed system image:
  0x801D_8000
- 0x8000_0000
  -----------
  0x001D_8000 = 1,933,312 bytes

or

  <size of uncompressed image> = 8,282,112 bytes
- <size of ramdisk>            = 6,348,800 bytes
  ----------------------------   ---------------
  <size of offset>             = 1,933,312 bytes

then

dd if=image of=image.ext2 skip=1 bs=1933312





article index
page 1 : Introduction
page 2 : RealTek 8186 SoC
page 3 - current : The firmware
page 4 : Interfacing with the board
page 5 : RTL8186 (Lexra5280) Toolchain
page 6 : Device drivers
News for 2010
MoTuWeThFrSaSu
 12345
6789101112
13141516171819
20212223242526
27282930 
 
Counter
This page today ...
total: 0
unique: 0

This page ever ...
total: 7827
unique: 2991

Site ...
total: 35823
unique: 13222
Site content Copyright mattei.