User:MPC/IMG File Format

From OpenStreetMap Wiki
Jump to navigation Jump to search

User:MPC

A reverse-engineering of Garmin's IMG file format

The IMG file contains all the info needed to render a map on a Garmin GPS unit, and may support autorouting information for those GPS units that offer navigation (i.e in-car GPS routers and some types of devices intended for hikers).

The .img file is basically a hard-disk image (complete with partition table) containing a filesystem which itself contains subfiles that provide the functionality for the Garmin GPS unit. The filesystem seems to be 'flat': that is, it doesn't directly support the concept of subdirectories, however the .GMP subfiles do provide a kind-of subdirectory structure. See below for more on that.

Here is source code for a simple Linux/Unix command-line program to take an .IMG file and to create a directory of files corresponding to its contents. It would be simple to modify this to run on DOS/Windows... help yourselves!

The IMG Header

Byte Offset Length (bytes) Description
0x00 1 If non-zero, every byte of the entire .img file is to be XORed with this value
0x01 7 ??? All zeroes
0x08 1 Map's version major
0x09 1 Map's version minor
0x0A 1 Map's month
0x0B 1 Map's year
0x0C 2 ??? All zeroes
0x0E 1 Mapsource flag, 1 - file created by Mapsource, 0 - Garmin map visible in Basecamp and Homeport
0x0F 1 Checksum, sum of all bytes modulo 256 should be 0
0x10 7 Signature: DSKIMG 0x00 or DSDIMG 0x00 for demo map

The Filestore

The File Allocation Table starts at offset 0x1200 (instead of 0x600). Each sequence is 0x200 Bytes (512 B) long. It is terminated by a sequence of FF, interrupted by some 00. Example:

00001200   01 30 30 30 30 32 34 31 39 4D 44 52 61 96 00   .00002419MDRa... (first entry)
00000800   01 30 30 30 30 32 34 31 39 4D 44 52 00 00 00   .00002419MDR.... (second entry)
(...)
00004C00   4D 41 50 53 4F 55 52 43 4D 50 53 55 01 00 00   .MAPSOURCMPSU.... ("last" entry)
00004C10   00 00 FF FF FF FF FF FF FF FF FF FF FF FF FF   ................ unknown
00004C20   DD 0E FF FF FF FF FF FF FF FF FF FF FF FF FF   ................ unknown

Next "00" at 4E00 (Offset=0x200) till 6000 (5120 byte)

Now GARMIN GMP starts, followed by GARMIN TRE. Then GARMIN RGN follows and GARMIN LBL, NET and NOD. Then a new set of GMP, TRE, RGN, LBL, NET and NOD starts (it the depends on number of tiles (???)). At the end is a MDR, SRT, TRF, TYP-Section.

The Subfiles

Each subfile has its own page, but as a quick reference the known subfiles are:

The TRE Subfile

Information of this subfile can be found here.

The NOD Subfile

This contains the routing information, unused by those GPS units that don't offer routing. Fill in here ..

The MDR Subfile

This contains the searchable address table used for finding routing destinations. See here for details.

The SRT Subfile

This is a fairly short file, containing a lookup table that categorises the characters in the map's codepage, and defines their collating sequence. Details are here ..

The GMP Subfile

This appears to represent a subtile of the larger area covered by the .IMG file. Its filename is of the form IXXXXXXX.GMP (where the 'X' characters are uppercase hexadecimal digits). Inside the .GMP file is a copyright message and the contents of a .TRE file, an .RGN file, an .LBL file, a .NET file and a .NOD file corresponding to that subtile. See here for details.

The DEM Subfile

The DEM (Digital Elevation Model) subfile contains elevation data used by Mapsource (shading, height profiles of routes) and Basecamp (3D view, height profiles of routes). Unfortunately, it seems that not much information is available right now. GMapTool can create "empty" DEM files and can also be used to extract DEM subfiles from IMG files with DEM information. See here for some preliminary results.

Links