June 6, 2021

Garmin IMG file format

I have downloaded several ".img" files from garmin.openstreetmap.nl. So far I have not been able to get them to display on my device and I am curious to find out how these IMG files are laid out and what they contain.

The garmin "imgdecode" program

This is what I found on SourceForge by John Mechalas (copyright in 2005, but BSD license). It is 4000 some lines of C++ that aims to "dump" a Garmin IMG file. This project has seen no activity since 2015 There is a "configure" file, so I type "configure ; make" and get a variety of compiler warnings. I add an include of cstring.h to garminimg.cc and fix two other warnings and I get a clean compile with less than 10 minutes effort. However when I run it against one of the image files I downloaded from garmin.openstreetmap.nl it goes into some kind of loop, keeps the CPU busy and never gives me any output. I let it go for several minutes and then give up.

It does create a directory with several files inside. When I run it on US-Tucson.img I get a US-Tucson directory with the contents:

-rw-rw-r-- 1 tom tom       3997 Jun  6 15:40 00371a00-00371acf.LBL.header
-rw-rw-r-- 1 tom tom       1421 Jun  6 15:40 0036da55-0036da68.TRE.levels
-rw-rw-r-- 1 tom tom       2459 Jun  6 15:40 0036d8bc-0036da54.TRE.mapinfo
-rw-rw-r-- 1 tom tom       2970 Jun  6 15:40 0036d800-0036d8bb.TRE.header
-rw-rw-r-- 1 tom tom      41147 Jun  6 15:40 00000001-000091ff.DSKIMG.header
-rw-rw-r-- 1 tom tom       4679 Jun  6 15:40 003718a7-003718ee.TRE.polylines
-rw-rw-r-- 1 tom tom     562632 Jun  6 15:40 0036da69-0037177a.TRE.subdivs
-rw-rw-r-- 1 tom tom       7519 Jun  6 15:40 003718d7-0037194b.TRE.polygons
-rw-rw-r-- 1 tom tom        211 Jun  6 15:40 00371ac4-00371ad9.LBL.sort
-rw-rw-r-- 1 tom tom        117 Jun  6 15:40 003718a7-00371780.TRE.unknown1
-rw-rw-r-- 1 tom tom      19952 Jun  6 15:40 00371781-003718a6.TRE.points
-rw-rw-r-- 1 tom tom        268 Jun  6 15:40 0037177b-00371780.TRE.copyright
-rw-rw-r-- 1 tom tom        117 Jun  6 15:40 0036d800-00371780.TRE.unknown2
-rw-rw-r-- 1 tom tom 2085723286 Jun  6 15:42 00371ada-XXXXXXXX.LBL.labels
The "labels" file is big, and growing all the time. It contains this over and over:
         |                         | Offset 0x000000
0037177e | f1 7b 00                | XXX
Clearly a bug.

Wikipedia description

The claim is that a Garmin IMG file is a filesystem, complete with partition table. The linux "file" command says "DOS/MBR boot sector", which is consistent with that. However, although some references call this a FAT type filesystem, it is by no means a windows FAT, FAT32, or any other windows FAT. It is its own thing entirely. The OSM Wiki gives a lot of details. Also note that if "garmin.openstreetmap.nl" is generating IMG files, it must include code that can generate the format.
Have any comments? Questions? Drop me a line!

Tom's backpacking pages / [email protected]