dimaryaz / jdmtool

A command-line tool for downloading Jeppesen databases and programming Garmin aviation data cards aiming to be compatible with Jeppesen Distribution Manager.
Apache License 2.0
8 stars 0 forks source link

Add support for transferring G1000 databases #2

Open liviro411 opened 1 year ago

liviro411 commented 1 year ago

I am using an official garmin SD card with

lsusb Bus 001 Device 008: ID 05e3:0745 Genesys Logic, Inc. Logilink CR0012

Therefore I modified your device.py:

class GarminProgrammerDevice(): VID = 0x05E3 PID = 0x0745

But "jdmtool detect" returns the following errors:

Found device: Bus 001 Device 008: ID 05e3:0745 Traceback (most recent call last): File "/home/hbu/.local/bin/jdmtool", line 8, in sys.exit(main()) File "/home/hbu/.local/lib/python3.10/site-packages/jdmtool/main.py", line 442, in main func(**kwargs) File "/home/hbu/.local/lib/python3.10/site-packages/jdmtool/main.py", line 66, in wrapper with handle.claimInterface(0): File "/home/hbu/.local/lib/python3.10/site-packages/usb1/init.py", line 1146, in claimInterface mayRaiseUSBError( File "/home/hbu/.local/lib/python3.10/site-packages/usb1/init.py", line 127, in mayRaiseUSBError raiseUSBError(value) File "/home/hbu/.local/lib/python3.10/site-packages/usb1/init.py", line 119, in raiseUSBError raise STATUS_TO_EXCEPTION_DICT.get(value, __USBError)(value) usb1.USBErrorBusy: LIBUSB_ERROR_BUSY [-6]

Do you have any hints/suggestions?

dimaryaz commented 1 year ago

That error most likely means that the device is already in use by some existing driver.

Does your SD card reader already show up as normal storage device? If you can already open the SD card and copy files to it, then there's no need to access the device directly. (That's not the case for GNS 430, which is why I implemented all of the USB logic.)

If you can access the SD card, the next question would be: do you know how the database needs to be stored there? E.g., copy the .zip file to it, or unzip it and copy the contents, or maybe the database is a disk image that should be copied directly to the device, etc. If you know the answer, I can make jdmtool do all that. If not... you'd need to look at an existing SD card and figure out how the database is stored there, or try the official Jeppesen tool and see what it does.

liviro411 commented 1 year ago

The Garmin SD card shows up as a normal storage device. Below you will find a listing of the content:

ls -lR .: insgesamt 3603840 -rw-r--r-- 1 hbu users 587 14. Jan 13:54 airframe_info.xml -rw-r--r-- 1 hbu users 197716 9. Apr 08:29 AirportReport.html -rw-r--r-- 1 hbu users 5095617 9. Apr 08:31 apt_dir.gca -rw-r--r-- 1 hbu users 1037 17. Feb 22:46 apt_dir.gca.sff -rw-r--r-- 1 hbu users 1038 26. Mär 19:10 avtn_db.bin.sff -rw-r--r-- 1 hbu users 21799170 9. Apr 08:31 bmap2.bin -rw-r--r-- 1 hbu users 1385 26. Mär 19:11 bmap2.bin.sff -rw-r--r-- 1 hbu users 21237764 9. Apr 08:30 bmap.bin -rw-r--r-- 1 hbu users 1385 26. Mär 19:11 bmap.bin.sff drwxr-xr-x 2 hbu users 65536 9. Apr 08:28 Charts -rw-r--r-- 1 hbu users 2076 3. Apr 18:36 chartview.hif.sff -r--r--r-- 1 hbu users 18260 9. Apr 08:56 feat_unlk.dat drwxr-xr-x 2 hbu users 65536 17. Feb 21:23 Fonts drwxr-xr-x 2 hbu users 65536 14. Jan 12:44 ldr_sys -rw-r--r-- 1 hbu users 1038 26. Mär 19:10 nav_db2.bin.sff -rw-r--r-- 1 hbu users 13131584 9. Apr 08:32 safetaxi2.gca -rw-r--r-- 1 hbu users 1038 17. Feb 22:47 safetaxi2.gca.sff -rw-r--r-- 1 hbu users 5793796 9. Apr 08:32 safetaxi.bin -rw-r--r-- 1 hbu users 1037 17. Feb 22:47 safetaxi.bin.sff -rw-r--r-- 1 hbu users 16756817 9. Apr 08:30 standard.odb -rw-r--r-- 1 hbu users 1038 26. Mär 19:10 standard.odb.sff drwxr-xr-x 2 hbu users 65536 14. Jan 12:25 System Volume Information -rw-r--r-- 1 hbu users 7250153 9. Apr 08:30 terrain.odb -rw-r--r-- 1 hbu users 1037 26. Mär 19:10 terrain.odb.sff -rw-r--r-- 1 hbu users 3597605726 9. Apr 08:54 trn.dat -rw-r--r-- 1 hbu users 38535 17. Feb 21:19 trn.dat.sff

./Charts: insgesamt 403648 -rw-r--r-- 1 hbu users 448818 9. Apr 08:28 airports.dbf -rw-r--r-- 1 hbu users 391368610 9. Apr 08:28 charts.bin -rw-r--r-- 1 hbu users 2240577 9. Apr 08:28 charts.dbf -rw-r--r-- 1 hbu users 95 3. Apr 18:36 charts.ini -rw-r--r-- 1 hbu users 16612854 3. Apr 18:36 chartview.hif -rw-r--r-- 1 hbu users 1248979 3. Apr 18:36 chrtlink.dbf -rw-r--r-- 1 hbu users 358 9. Apr 08:28 crcfiles.txt -rw-r--r-- 1 hbu users 9834 3. Apr 18:36 ctypes.dbf -rw-r--r-- 1 hbu users 407 3. Apr 18:36 jeppesen.tfl -rw-r--r-- 1 hbu users 8896 3. Apr 18:36 jeppesen.tls -rw-r--r-- 1 hbu users 2526 3. Apr 18:36 lssdef.tcl -rw-r--r-- 1 hbu users 93392 9. Apr 08:28 notams.dbf -rw-r--r-- 1 hbu users 708609 9. Apr 08:28 notams.dbt

./Fonts: insgesamt 2944 -rw-r--r-- 1 hbu users 66080 3. Apr 18:36 arialbd.jtf -rw-r--r-- 1 hbu users 60012 3. Apr 18:36 arialn.jtf -rw-r--r-- 1 hbu users 19652 3. Apr 18:36 crysn.jtf -rw-r--r-- 1 hbu users 31684 3. Apr 18:36 font11.jtf -rw-r--r-- 1 hbu users 22200 3. Apr 18:36 font12.jtf -rw-r--r-- 1 hbu users 20500 3. Apr 18:36 font13.jtf -rw-r--r-- 1 hbu users 20660 3. Apr 18:36 font15.jtf -rw-r--r-- 1 hbu users 19732 3. Apr 18:36 font16.jtf -rw-r--r-- 1 hbu users 24772 3. Apr 18:36 font17.jtf -rw-r--r-- 1 hbu users 44664 3. Apr 18:36 font1.jtf -rw-r--r-- 1 hbu users 44224 3. Apr 18:36 font21.jtf -rw-r--r-- 1 hbu users 39788 3. Apr 18:36 font23.jtf -rw-r--r-- 1 hbu users 39144 3. Apr 18:36 font24.jtf -rw-r--r-- 1 hbu users 48120 3. Apr 18:36 font25.jtf -rw-r--r-- 1 hbu users 46208 3. Apr 18:36 font26.jtf -rw-r--r-- 1 hbu users 49424 3. Apr 18:36 font27.jtf -rw-r--r-- 1 hbu users 44224 3. Apr 18:36 font2.jtf -rw-r--r-- 1 hbu users 19352 3. Apr 18:36 font32.jtf -rw-r--r-- 1 hbu users 20052 3. Apr 18:36 font34.jtf -rw-r--r-- 1 hbu users 11928 3. Apr 18:36 font35.jtf -rw-r--r-- 1 hbu users 40356 3. Apr 18:36 font3.jtf -rw-r--r-- 1 hbu users 22292 3. Apr 18:36 font43.jtf -rw-r--r-- 1 hbu users 39340 3. Apr 18:36 font4.jtf -rw-r--r-- 1 hbu users 34908 3. Apr 18:36 font52.jtf -rw-r--r-- 1 hbu users 47328 3. Apr 18:36 font5.jtf -rw-r--r-- 1 hbu users 21652 3. Apr 18:36 font65.jtf -rw-r--r-- 1 hbu users 44556 3. Apr 18:36 font6.jtf -rw-r--r-- 1 hbu users 45476 3. Apr 18:36 font71.jtf -rw-r--r-- 1 hbu users 41264 3. Apr 18:36 font73.jtf -rw-r--r-- 1 hbu users 39352 3. Apr 18:36 font74.jtf -rw-r--r-- 1 hbu users 48284 3. Apr 18:36 font75.jtf -rw-r--r-- 1 hbu users 46836 3. Apr 18:36 font76.jtf -rw-r--r-- 1 hbu users 50128 3. Apr 18:36 font77.jtf -rw-r--r-- 1 hbu users 3648 3. Apr 18:36 font79.jtf -rw-r--r-- 1 hbu users 49560 3. Apr 18:36 font7.jtf -rw-r--r-- 1 hbu users 12924 3. Apr 18:36 font80.jtf -rw-r--r-- 1 hbu users 36492 3. Apr 18:36 font81.jtf -rw-r--r-- 1 hbu users 30384 3. Apr 18:36 font82.jtf -rw-r--r-- 1 hbu users 28992 3. Apr 18:36 font84.jtf -rw-r--r-- 1 hbu users 42996 3. Apr 18:36 font8.jtf -rw-r--r-- 1 hbu users 407 3. Apr 18:36 jeppesen.tfl -rw-r--r-- 1 hbu users 8896 3. Apr 18:36 jeppesen.tls -rw-r--r-- 1 hbu users 2526 3. Apr 18:36 lssdef.tcl -rw-r--r-- 1 hbu users 28968 3. Apr 18:36 monspacb.jtf -rw-r--r-- 1 hbu users 64544 3. Apr 18:36 sserife.jtf

./ldr_sys: insgesamt 20608 -rw-r--r-- 1 hbu users 9421599 9. Apr 08:31 avtn_db.bin -rw-r--r-- 1 hbu users 5577 9. Apr 08:27 grm_feat_key.zip -rw-r--r-- 1 hbu users 11553624 9. Apr 08:31 nav_db2.bin

./System Volume Information: insgesamt 128 -rw-r--r-- 1 hbu users 76 14. Jan 12:25 IndexerVolumeGuid -rw-r--r-- 1 hbu users 12 14. Jan 12:25 WPSettings.dat

dimaryaz commented 1 year ago

Well, I've made some progress here. I realized, I don't need a G1000 or any special hardware for this - just a USB drive.

The biggest remaining piece is the .sff files - they seem to be generated from the downloaded files, but I don't know what they are. Signature? Checksum? Will try to reverse-engineer them.

Two questions for you:

dimaryaz commented 1 year ago

Well, I have something working, but I would NOT try it on the real SD cards just yet.

Turns out, the .sff files were easy - they're just some extra downloads.

But, there's feat_unlk.dat, which appears to be some attempt at copy protection. From the manual:

This file is placed on the card when the databases are written to the card. It is required. It controls the copy protection for all the databases on the card. If this file is missing, NO databases on the card will be accepted by the avionics. If it is deleted, all databases will need to be reinstalled using fly.garmin.com.

And from this forum:

When you download the new data each month from Jeppesen, they write the 2 DB files that contain all the data, PLUS they write a special file just for you called 'feat_unlk.dat' which contains your G1000 system ID and some checksum information about the DB files. When you power up the G1000, it looks at the top slot, and if it finds a card there, it looks for a 'feat_unlk.dat' file on the card. If it finds that file, it checks the System_ID in the file against the hardware ID of your G1000. If it doesn't match, it ignores the data on the card and just boots normally.

So I have not yet figured out how it works - but presumably, the G1000 won't accept the database update without it.

My code copies everything else, though. If you're curious to try it, it's in the g1000 branch. It can work with any directory, not necessarily an SD card. Run jdmtool refresh again and re-download the databases if jdminfo list says they're not downloaded - it needs some extra files now. Then:

$ mkdir tmp
$ jdmtool transfer 4 ./tmp/
WARNING: tmp appears to be a normal directory, not a device.
Transfer databases to tmp? (y/n) y
Copying /home/dima/.local/share/jdmtool/downloads/dga035_2303_29114daf.zip!ldr_sys\avtn_db.bin to tmp/ldr_sys/avtn_db.bin...
Copying /home/dima/.local/share/jdmtool/downloads/dga035_2303_29114daf.zip!ldr_sys\nav_db2.bin to tmp/ldr_sys/nav_db2.bin...
Copying /home/dima/.local/share/jdmtool/downloads/nav_db2.bin.sff to tmp/nav_db2.bin.sff...
Copying /home/dima/.local/share/jdmtool/downloads/avtn_db.bin.sff to tmp/avtn_db.bin.sff...
Done
liviro411 commented 1 year ago

You are right. There is no need to use the original Garmin SD Card. I have used also a normal 32GB SD Card to transfer the database to the G1000NXI.

Here is the list of files in the VFR/IFR charts DB:

unzip -l 023FL01687_TCL_202308.1_202308.1.zip Archive: 023FL01687_TCL_202308.1_202308.1.zip Length Date Time Name


233560138 2023-04-08 00:33 023FL01687_VFRCharts.bin 1513947 2023-04-07 12:35 airports.dbf 10081398 2023-04-07 13:10 charts.dbf 95 2023-04-07 14:33 charts.ini 6317252 2023-04-07 12:35 chrtlink.dbf 8564 2023-04-07 12:35 country.dbf 3150314 2023-04-07 23:15 coverags.dbf 455 2023-04-07 23:15 crcfiles.txt 9834 2023-04-07 12:33 ctypes.dbf 66080 1995-12-08 08:00 Fonts/arialbd.jtf 60012 1994-01-31 20:00 Fonts/arialn.jtf 19652 1995-10-03 07:31 Fonts/crysn.jtf 44664 2004-12-06 13:17 Fonts/font1.jtf 31684 2000-09-19 09:41 Fonts/font11.jtf 22200 1996-05-08 07:11 Fonts/font12.jtf 20500 1996-05-08 07:11 Fonts/font13.jtf 20660 1996-05-09 06:47 Fonts/font15.jtf 19732 1996-05-08 07:14 Fonts/font16.jtf 24772 1996-05-08 07:15 Fonts/font17.jtf 44224 2004-12-22 08:31 Fonts/font2.jtf 44224 2005-10-13 12:33 Fonts/font21.jtf 39788 2005-10-13 12:33 Fonts/font23.jtf 39144 2005-10-13 12:33 Fonts/font24.jtf 48120 2005-10-13 12:33 Fonts/font25.jtf 46208 2005-10-13 12:33 Fonts/font26.jtf 49424 2005-10-13 12:33 Fonts/font27.jtf 40356 2004-12-06 13:36 Fonts/font3.jtf 19352 1998-12-28 08:37 Fonts/font32.jtf 20052 1996-05-09 05:49 Fonts/font34.jtf 11928 1999-04-23 07:53 Fonts/font35.jtf 39340 2004-12-06 13:37 Fonts/font4.jtf 22292 1996-05-08 07:18 Fonts/font43.jtf 47328 2004-12-27 06:44 Fonts/font5.jtf 34908 1996-05-08 07:19 Fonts/font52.jtf 44556 2004-12-22 08:35 Fonts/font6.jtf 21652 1996-05-08 07:20 Fonts/font65.jtf 49560 2004-12-06 13:35 Fonts/font7.jtf 45476 2005-10-13 12:33 Fonts/font71.jtf 41264 2005-10-13 12:33 Fonts/font73.jtf 39352 2005-10-13 12:33 Fonts/font74.jtf 48284 2005-10-13 12:33 Fonts/font75.jtf 46836 2005-10-13 12:33 Fonts/font76.jtf 50128 2005-10-13 12:33 Fonts/font77.jtf 3648 1996-05-08 07:20 Fonts/font79.jtf 42996 2004-12-06 13:41 Fonts/font8.jtf 12924 1996-05-08 07:21 Fonts/font80.jtf 36492 1996-05-08 08:53 Fonts/font81.jtf 30384 1996-05-08 08:55 Fonts/font82.jtf 28992 1996-05-08 08:56 Fonts/font84.jtf 407 2005-10-07 02:43 Fonts/jeppesen.tfl 8896 2004-10-13 09:31 Fonts/jeppesen.tls 2526 2004-10-13 09:31 Fonts/lssdef.tcl 28968 1992-06-30 21:00 Fonts/monspacb.jtf 64544 1993-10-31 23:11 Fonts/sserife.jtf 407 2005-10-07 02:43 jeppesen.tfl 8896 2004-10-13 09:31 jeppesen.tls 2526 2004-10-13 09:31 lssdef.tcl 120303 2023-04-07 12:21 notams.dbf 904705 2023-04-07 12:21 notams.dbt 142208 2023-04-07 23:15 regions.dat 37 2023-04-08 00:33 revision.txt 5107325 2023-04-07 23:15 sbscrips.dbf 2866 2023-04-07 12:35 state.dbf 450065 2023-03-24 16:14 vfrapts.dbf 668358 2023-03-24 17:26 vfrchrts.dbf 83940 2023-04-07 13:03 vfrntms.dbf 636417 2023-04-07 13:03 vfrntms.dbt


264294579 67 files

unzip -l 023KM01684_TCL_202308.1_202308.1.zip Archive: 023KM01684_TCL_202308.1_202308.1.zip Length Date Time Name


165845779 2023-04-07 23:28 023KM01684_Charts.bin 1513947 2023-04-07 12:35 Airports.dbf 10081398 2023-04-07 13:10 charts.dbf 95 2023-04-07 14:33 charts.ini 6317252 2023-04-07 12:35 chrtlink.dbf 8564 2023-04-07 12:35 country.dbf 3150314 2023-04-07 23:15 coverags.dbf 455 2023-04-07 23:15 crcfiles.txt 9834 2023-04-07 12:33 ctypes.dbf 66080 1995-12-08 08:00 Fonts/arialbd.jtf 60012 1994-01-31 20:00 Fonts/arialn.jtf 19652 1995-10-03 07:31 Fonts/crysn.jtf 44664 2004-12-06 13:17 Fonts/font1.jtf 31684 2000-09-19 09:41 Fonts/font11.jtf 22200 1996-05-08 07:11 Fonts/font12.jtf 20500 1996-05-08 07:11 Fonts/font13.jtf 20660 1996-05-09 06:47 Fonts/font15.jtf 19732 1996-05-08 07:14 Fonts/font16.jtf 24772 1996-05-08 07:15 Fonts/font17.jtf 44224 2004-12-22 08:31 Fonts/font2.jtf 44224 2005-10-13 12:33 Fonts/font21.jtf 39788 2005-10-13 12:33 Fonts/font23.jtf 39144 2005-10-13 12:33 Fonts/font24.jtf 48120 2005-10-13 12:33 Fonts/font25.jtf 46208 2005-10-13 12:33 Fonts/font26.jtf 49424 2005-10-13 12:33 Fonts/font27.jtf 40356 2004-12-06 13:36 Fonts/font3.jtf 19352 1998-12-28 08:37 Fonts/font32.jtf 20052 1996-05-09 05:49 Fonts/font34.jtf 11928 1999-04-23 07:53 Fonts/font35.jtf 39340 2004-12-06 13:37 Fonts/font4.jtf 22292 1996-05-08 07:18 Fonts/font43.jtf 47328 2004-12-27 06:44 Fonts/font5.jtf 34908 1996-05-08 07:19 Fonts/font52.jtf 44556 2004-12-22 08:35 Fonts/font6.jtf 21652 1996-05-08 07:20 Fonts/font65.jtf 49560 2004-12-06 13:35 Fonts/font7.jtf 45476 2005-10-13 12:33 Fonts/font71.jtf 41264 2005-10-13 12:33 Fonts/font73.jtf 39352 2005-10-13 12:33 Fonts/font74.jtf 48284 2005-10-13 12:33 Fonts/font75.jtf 46836 2005-10-13 12:33 Fonts/font76.jtf 50128 2005-10-13 12:33 Fonts/font77.jtf 3648 1996-05-08 07:20 Fonts/font79.jtf 42996 2004-12-06 13:41 Fonts/font8.jtf 12924 1996-05-08 07:21 Fonts/font80.jtf 36492 1996-05-08 08:53 Fonts/font81.jtf 30384 1996-05-08 08:55 Fonts/font82.jtf 28992 1996-05-08 08:56 Fonts/font84.jtf 407 2005-10-07 02:43 Fonts/jeppesen.tfl 8896 2004-10-13 09:31 Fonts/jeppesen.tls 2526 2004-10-13 09:31 Fonts/lssdef.tcl 28968 1992-06-30 21:00 Fonts/monspacb.jtf 64544 1993-10-31 23:11 Fonts/sserife.jtf 407 2005-10-07 02:43 jeppesen.tfl 8896 2004-10-13 09:31 jeppesen.tls 2526 2004-10-13 09:31 lssdef.tcl 120303 2023-04-07 12:21 notams.dbf 904705 2023-04-07 12:21 notams.dbt 142208 2023-04-07 23:15 regions.dat 37 2023-04-07 23:29 revision.txt 5107325 2023-04-07 23:15 sbscrips.dbf 2866 2023-04-07 12:35 state.dbf 450065 2023-03-24 16:14 vfrapts.dbf 668358 2023-03-24 17:26 vfrchrts.dbf 83940 2023-04-07 13:03 vfrntms.dbf 636417 2023-04-07 13:03 vfrntms.dbt


196580220 67 files

liviro411 commented 1 year ago

Just a side note about the G1000NXi:

I do not use the top slot for the SD card on the G1000NXi, I always use the bottom slot (where normally the FS510 is installed). With a "normal = non Garmin" SD Card and JDM I was able to upgrade the databases on the G1000NXi.

I will check if the dabases can be upgraded using your newest version of jdmtool, a normal SD Card and using the bottom slot. Hopefully the feat_unlk.dat file is not checked using the bottom slot.

I can give you a feedback in a week (since I probably will have no access to the plane until then).

dimaryaz commented 1 year ago

Interesting, sounds good.

These are the databases that use feat_unlk.dat, by the way:

I've made some progress on reverse-engineering feat_unlk.dat. Besides the databases, it also uses the ID of the partition - I guess that's how they stop you from just copying everything to a different SD card.

But of course, you can set the ID yourself when formatting the device. E.g., set it to 1234abcd:

$ sudo chown dima:dima /dev/sda
$ mkdosfs -i 1234abcd -F 32 -n GARMIN /dev/sda
mkfs.fat 4.2 (2021-01-31)
$ blkid /dev/sda 
/dev/sda: LABEL_FATBOOT="GARMIN" LABEL="GARMIN" UUID="1234-ABCD" BLOCK_SIZE="512" TYPE="vfat"

(Or change it without formatting using gparted or whatever, but I haven't tried it.

Also, they were nice enough to move all copy protection code into a separate executable, plugins/oem_garmin/g_plugin.exe, that's only 200KB. So I don't need to reverse engineer the whole JDM - just the plugin. It communicates over JSONRPC, and even runs in wine! (Though wine needs the device file to be readable by the user - otherwise, it's not smart enough to get its ID.)

Transferring the databases:

$ jdmtool transfer 2 /run/media/dima/GARMIN/
WARNING: this database requires feat_unlk.dat, and will likely not work!
Transfer databases to /run/media/dima/GARMIN? (y/n) y
Copying /home/dima/.local/share/jdmtool/downloads/dgs235_23s1_5d913c72.zip!safetaxi.bin to /run/media/dima/GARMIN/safetaxi.bin...
Copying /home/dima/.local/share/jdmtool/downloads/dgs235_23s1_5d913c72.zip!safetaxi2.gca to /run/media/dima/GARMIN/safetaxi2.gca...
Done

Running the plugin:

$ wine g_plugin.exe 
0178:fixme:msvcp:_Locinfo__Locinfo_ctor_cat_cstr (0063FA5C 1 C) semi-stub
0178:fixme:msvcp:_Locinfo__Locinfo_ctor_cat_cstr (0063F9CC 1 C) semi-stub
0178:fixme:msvcp:_Locinfo__Locinfo_ctor_cat_cstr (0063F744 1 C) semi-stub
verifying crc
card will unlock feature "safetaxi" on system(s) with the following IDs: 0x5DC5F1B0. card S/N = 0x0
verifying crc
card will unlock feature "safetaxi2" on system(s) with the following IDs: 0x5DC5F1B0. card S/N = 0x0

Sending requests for the two files:

$ curl -d '{"id":"33102457_23S1","jsonrpc":"2.0","method":"program","params":{"datafile":"E:/safetaxi.bin","featunlk":"E:/feat_unlk.dat","garmin_sec_id":191,"numaircraft":0,"sysid":"0x25DC5F1AE","uid":"33102457","vers":"23S1"}}' http://localhost:8010/
{"id":"33102457_23S1","jsonrpc":"2.0","result":{"code":0,"message":"Garmin Programming has passed."}}
$ curl -d '{"id":"33102457_23S1","jsonrpc":"2.0","method":"program","params":{"datafile":"E:/safetaxi2.gca","featunlk":"E:/feat_unlk.dat","garmin_sec_id":191,"numaircraft":0,"sysid":"0x25DC5F1AE","uid":"33102457","vers":"23S1"}}' http://localhost:8010/
{"id":"33102457_23S1","jsonrpc":"2.0","result":{"code":0,"message":"Garmin Programming has passed."}}

And it produces a feat_unlk.dat that's identical to the one created by JDM.

If I can't reverse-engineer the plugin, I can just run it on some server. CPAAS - Copy Protection As A Service!

liviro411 commented 1 year ago

Thanks a lot for your comments. However "g_plugin.exe" seems not work on my system.

I had to copy the library GrmNavdata.dll to the wine c:\windows folder in order to use g_plugin.exe.

I am using a SD card with one database:

hbu@laptophbu2:/run/media/hbu/GARMIN> ll insgesamt 18544 drwxr-xr-x 2 hbu users 16384 16. Apr 16:39 ldr_sys -rw-r--r-- 1 hbu users 13130982 16. Apr 16:39 safetaxi2.gca -rw-r--r-- 1 hbu users 5816324 16. Apr 16:39 safetaxi.bin

wine ~/bin/g_plugin.exe 015c:fixme:msvcp:_LocinfoLocinfo_ctor_cat_cstr (0053FA5C 1 C) semi-stub 015c:fixme:msvcp:_LocinfoLocinfo_ctor_cat_cstr (0053F9CC 1 C) semi-stub 015c:fixme:msvcp:_Locinfo__Locinfo_ctor_cat_cstr (0053F744 1 C) semi-stub

I seems that g_plugin.exe does not find the wine windows drive with the SD card. But according to winecfg the SD card is there.

Do you have any hints?

dimaryaz commented 1 year ago

Oh, yeah, I'm still working on automating most of this. I couldn't decide if my goal was to just make it work on Linux (and relying on g_plugin.exe was an acceptable compromise), or fully reverse-engineer featunlk.dat and create it from Python.

Anyways, a few things:

I'll try to make jdmtool actually run wine and perform all the necessary checks.

dimaryaz commented 1 year ago

Just updated the g1000 branch - it will now try to find g_plugin.exe and run everything automatically. (You can also set G_PLUGIN_PATH environment variable to point it at the g_plugin.exe.)

This is what it looks like for me:

$ jdmtool transfer 6 /run/media/dima/GARMIN/
NOTE: this database requires feat_unlk.dat; will need to run g_plugin from JDM!
Transfer databases to /run/media/dima/GARMIN? (y/n) y
Found device: /dev/sda
Found serial number: 0000-0001
Creating /run/media/dima/GARMIN/.windows-serial so Wine can find the serial number...
Getting Windows drive for /run/media/dima/GARMIN...
Found E:
Found g_plugin at '/home/dima/.wine/dosdevices/c:/Program Files (x86)/Jeppesen/Jdm/plugins/oem_garmin/g_plugin.exe'
Copying /home/dima/.local/share/jdmtool/downloads/dgb000_22m1_2ff68ff3.zip!bmap.bin to /run/media/dima/GARMIN/bmap.bin...
Copying /home/dima/.local/share/jdmtool/downloads/dgb000_22m1_2ff68ff3.zip!bmap2.bin to /run/media/dima/GARMIN/bmap2.bin...
Starting g_plugin...
Started g_plugin successfully
Updating feat_unlk.dat for bmap.bin...
verifying crc
card will unlock feature "basemap" on system(s) with the following IDs: 0x5DC5F1B0. card S/N = 0x0
Got response: {'id': '33810500_22M1', 'jsonrpc': '2.0', 'result': {'code': 0, 'message': 'Garmin Programming has passed.'}}
Updating feat_unlk.dat for bmap2.bin...
verifying crc
card will unlock feature "basemap2" on system(s) with the following IDs: 0x5DC5F1B0. card S/N = 0x0
Got response: {'id': '33810500_22M1', 'jsonrpc': '2.0', 'result': {'code': 0, 'message': 'Garmin Programming has passed.'}}
Shutting down g_plugin.
Copying /home/dima/.local/share/jdmtool/downloads/sff/33810500_22M1/bmap.bin.sff to /run/media/dima/GARMIN/bmap.bin.sff...
Copying /home/dima/.local/share/jdmtool/downloads/sff/33810500_22M1/bmap2.bin.sff to /run/media/dima/GARMIN/bmap2.bin.sff...
Copying /home/dima/.local/share/jdmtool/grm_feat_key.zip to /run/media/dima/GARMIN/ldr_sys/grm_feat_key.zip...
Done

(Some of the output there actually comes from g_plugin.exe.)

It produces exactly the same files as JDM, as far as I can tell (except that it doesn't create .jdm - it's a JSON file, and I'm pretty sure it's only used by JDM itself; I can't imagine G1000 reading JSON.)

There are a couple Wine bugs to be aware of:

Let me know if this works! Ideally, compare it to the files created by JDM, and see if they're identical. If they are, then that's a pretty good guarantee that it'll work on the G1000.

dimaryaz commented 1 year ago

Oh, you'll also need to run pip install again - I added a dependency on psutil.

liviro411 commented 1 year ago

The file feat_unlk.dat was created on my SD card!

jdmtool transfer 5 /run/media/hbu/GARMIN/ NOTE: this database requires feat_unlk.dat; will need to run g_plugin from JDM! Transfer databases to /run/media/hbu/GARMIN? (y/n) y Found device: /dev/sda1 Found serial number: F292-70A6 Creating /run/media/hbu/GARMIN/.windows-serial so Wine can find the serial number... Getting Windows drive for /run/media/hbu/GARMIN... Found E: Found g_plugin at '/home/hbu/.wine/dosdevices/c:/Program Files (x86)/Jeppesen/Jdm/plugins/oem_garmin/g_plugin.exe' Copying /home/hbu/.local/share/jdmtool/downloads/dgs235_23s2_5267159b.zip!safetaxi.bin to /run/media/hbu/GARMIN/safetaxi.bin... Copying /home/hbu/.local/share/jdmtool/downloads/dgs235_23s2_5267159b.zip!safetaxi2.gca to /run/media/hbu/GARMIN/safetaxi2.gca... Starting g_plugin... Started g_plugin successfully Updating feat_unlk.dat for safetaxi.bin... verifying crc card will unlock feature "safetaxi" on system(s) with the following IDs: 0x5DC5F1B0. card S/N = 0x0 Got response: {'code': 0, 'message': 'Garmin Programming has passed.'} Updating feat_unlk.dat for safetaxi2.gca... verifying crc card will unlock feature "safetaxi2" on system(s) with the following IDs: 0x5DC5F1B0. card S/N = 0x0 Got response: {'code': 0, 'message': 'Garmin Programming has passed.'} Shutting down g_plugin. Done

ll /run/media/hbu/GARMIN/ insgesamt 18560 -r--r--r-- 1 hbu users 17347 18. Apr 11:37 feat_unlk.dat -rw-r--r-- 1 hbu users 13130982 18. Apr 11:37 safetaxi2.gca -rw-r--r-- 1 hbu users 5816324 18. Apr 11:37 safetaxi.bin

On friday I will try to load all new databases from this card into the G1000NXi system. Keep finger crossed!

dimaryaz commented 1 year ago

So were you able to load them into the G1000NXi?

liviro411 commented 1 year ago

Partially! Several database could be loaded using jdmtool (including safetaxi). So the generation of the "feat_unlk.dat" file seems to work. Great news!

However the jeppesen chart were not recognized as new and were therefore not be uploaded. I had to use the orginal JDM tool. It might be due to different folder structure using either jdm or jdmtool:

Original Garmin SD Card using JDM: ll insgesamt 3604224 -rw-r--r-- 1 587 14. Jan 13:54 airframe_info.xml -rw-r--r-- 1 197806 18. Apr 14:02 AirportReport.html -rw-r--r-- 1 5115037 18. Apr 14:05 apt_dir.gca -rw-r--r-- 1 1037 17. Feb 22:46 apt_dir.gca.sff -rw-r--r-- 1 1038 13. Apr 01:07 avtn_db.bin.sff -rw-r--r-- 1 21799170 18. Apr 14:05 bmap2.bin -rw-r--r-- 1 1385 26. Mär 19:11 bmap2.bin.sff -rw-r--r-- 1 21237764 18. Apr 14:04 bmap.bin -rw-r--r-- 1 1385 26. Mär 19:11 bmap.bin.sff drwxr-xr-x 2 65536 9. Apr 08:28 Charts -rw-r--r-- 1 1385 13. Apr 01:07 chartview.hif.sff -r--r--r-- 1 18260 18. Apr 14:05 feat_unlk.dat drwxr-xr-x 2 65536 17. Feb 21:23 Fonts drwxr-xr-x 2 65536 14. Jan 12:44 ldr_sys -rw-r--r-- 1 1038 13. Apr 01:07 nav_db2.bin.sff -rw-r--r-- 1 13130982 18. Apr 14:05 safetaxi2.gca -rw-r--r-- 1 1038 17. Feb 22:47 safetaxi2.gca.sff -rw-r--r-- 1 5816324 18. Apr 14:05 safetaxi.bin -rw-r--r-- 1 1037 17. Feb 22:47 safetaxi.bin.sff -rw-r--r-- 1 16994877 18. Apr 14:04 standard.odb -rw-r--r-- 1 1385 13. Apr 01:07 standard.odb.sff drwxr-xr-x 2 65536 14. Jan 12:25 System Volume Information -rw-r--r-- 1 7317305 18. Apr 14:04 terrain.odb -rw-r--r-- 1 1037 13. Apr 01:07 terrain.odb.sff -rw-r--r-- 1 3597605726 9. Apr 08:54 trn.dat -rw-r--r-- 1 38535 17. Feb 21:19 trn.dat.sff

ll Charts/ insgesamt 412160 -rw-r--r-- 1 449029 18. Apr 14:01 airports.dbf -rw-r--r-- 1 399405890 18. Apr 14:02 charts.bin -rw-r--r-- 1 2269697 18. Apr 14:01 charts.dbf -rw-r--r-- 1 95 13. Apr 01:07 charts.ini -rw-r--r-- 1 17212317 13. Apr 01:07 chartview.hif -rw-r--r-- 1 1259077 13. Apr 01:08 chrtlink.dbf -rw-r--r-- 1 358 18. Apr 14:01 crcfiles.txt -rw-r--r-- 1 9834 13. Apr 01:07 ctypes.dbf -rw-r--r-- 1 407 13. Apr 01:07 jeppesen.tfl -rw-r--r-- 1 8896 13. Apr 01:07 jeppesen.tls -rw-r--r-- 1 2526 13. Apr 01:07 lssdef.tcl -rw-r--r-- 1 98222 18. Apr 14:01 notams.dbf -rw-r--r-- 1 744961 18. Apr 14:01 notams.dbt

ll Charts/ insgesamt 412160 -rw-r--r-- 1 449029 18. Apr 14:01 airports.dbf -rw-r--r-- 1 399405890 18. Apr 14:02 charts.bin -rw-r--r-- 1 2269697 18. Apr 14:01 charts.dbf -rw-r--r-- 1 95 13. Apr 01:07 charts.ini -rw-r--r-- 1 17212317 13. Apr 01:07 chartview.hif -rw-r--r-- 1 1259077 13. Apr 01:08 chrtlink.dbf -rw-r--r-- 1 358 18. Apr 14:01 crcfiles.txt -rw-r--r-- 1 9834 13. Apr 01:07 ctypes.dbf -rw-r--r-- 1 407 13. Apr 01:07 jeppesen.tfl -rw-r--r-- 1 8896 13. Apr 01:07 jeppesen.tls -rw-r--r-- 1 2526 13. Apr 01:07 lssdef.tcl -rw-r--r-- 1 98222 18. Apr 14:01 notams.dbf -rw-r--r-- 1 744961 18. Apr 14:01 notams.dbt

ll ldr_sys/ insgesamt 20672 -rw-r--r-- 1 9449990 18. Apr 14:05 avtn_db.bin -rw-r--r-- 1 5577 18. Apr 14:00 grm_feat_key.zip -rw-r--r-- 1 11588311 18. Apr 14:05 nav_db2.bin

SDcard using JDMTOOL: ll insgesamt 4021632 -rw-r--r-- 1 233560138 18. Apr 11:46 023FL01687_VFRCharts.bin -rw-r--r-- 1 165845779 18. Apr 11:46 023KM01684_Charts.bin -rw-r--r-- 1 587 9. Apr 18:09 airframe_info.xml -rw-r--r-- 1 1513947 18. Apr 11:46 Airports.dbf -rw-r--r-- 1 5115037 18. Apr 11:42 apt_dir.gca -rw-r--r-- 1 1038 18. Apr 11:43 avtn_db.bin.sff -rw-r--r-- 1 21799170 18. Apr 11:45 bmap2.bin -rw-r--r-- 1 1385 18. Apr 11:45 bmap2.bin.sff -rw-r--r-- 1 21237764 18. Apr 11:45 bmap.bin -rw-r--r-- 1 1385 18. Apr 11:45 bmap.bin.sff -rw-r--r-- 1 10081398 18. Apr 11:46 charts.dbf -rw-r--r-- 1 95 18. Apr 11:46 charts.ini -rw-r--r-- 1 1385 18. Apr 11:46 chartview.hif.sff -rw-r--r-- 1 6317252 18. Apr 11:46 chrtlink.dbf -rw-r--r-- 1 8564 18. Apr 11:46 country.dbf -rw-r--r-- 1 3150314 18. Apr 11:46 coverags.dbf -rw-r--r-- 1 455 18. Apr 11:46 crcfiles.txt -rw-r--r-- 1 9834 18. Apr 11:46 ctypes.dbf -r--r--r-- 1 18260 18. Apr 11:45 feat_unlk.dat drwxr-xr-x 2 16384 18. Apr 11:46 Fonts -rw-r--r-- 1 407 18. Apr 11:46 jeppesen.tfl -rw-r--r-- 1 8896 18. Apr 11:46 jeppesen.tls drwxr-xr-x 2 16384 18. Apr 11:43 ldr_sys -rw-r--r-- 1 2526 18. Apr 11:46 lssdef.tcl -rw-r--r-- 1 1038 18. Apr 11:43 nav_db2.bin.sff -rw-r--r-- 1 120303 18. Apr 11:46 notams.dbf -rw-r--r-- 1 904705 18. Apr 11:46 notams.dbt -rw-r--r-- 1 142208 18. Apr 11:46 regions.dat -rw-r--r-- 1 37 18. Apr 11:46 revision.txt -rw-r--r-- 1 13130982 18. Apr 11:37 safetaxi2.gca -rw-r--r-- 1 5816324 18. Apr 11:37 safetaxi.bin -rw-r--r-- 1 5107325 18. Apr 11:46 sbscrips.dbf -rw-r--r-- 1 16994877 18. Apr 11:44 standard.odb -rw-r--r-- 1 1385 18. Apr 11:44 standard.odb.sff -rw-r--r-- 1 2866 18. Apr 11:46 state.dbf -rw-r--r-- 1 7317305 18. Apr 11:44 terrain.odb -rw-r--r-- 1 1037 18. Apr 11:44 terrain.odb.sff -rw-r--r-- 1 3597605726 18. Apr 11:47 trn.dat -rw-r--r-- 1 450065 18. Apr 11:46 vfrapts.dbf -rw-r--r-- 1 668358 18. Apr 11:46 vfrchrts.dbf -rw-r--r-- 1 83940 18. Apr 11:46 vfrntms.dbf -rw-r--r-- 1 636417 18. Apr 11:46 vfrntms.dbt

ll Fonts/ insgesamt 1856 -rw-r--r-- 1 66080 18. Apr 11:46 arialbd.jtf -rw-r--r-- 1 60012 18. Apr 11:46 arialn.jtf -rw-r--r-- 1 19652 18. Apr 11:46 crysn.jtf -rw-r--r-- 1 31684 18. Apr 11:46 font11.jtf -rw-r--r-- 1 22200 18. Apr 11:46 font12.jtf -rw-r--r-- 1 20500 18. Apr 11:46 font13.jtf -rw-r--r-- 1 20660 18. Apr 11:46 font15.jtf -rw-r--r-- 1 19732 18. Apr 11:46 font16.jtf -rw-r--r-- 1 24772 18. Apr 11:46 font17.jtf -rw-r--r-- 1 44664 18. Apr 11:46 font1.jtf -rw-r--r-- 1 44224 18. Apr 11:46 font21.jtf -rw-r--r-- 1 39788 18. Apr 11:46 font23.jtf -rw-r--r-- 1 39144 18. Apr 11:46 font24.jtf -rw-r--r-- 1 48120 18. Apr 11:46 font25.jtf -rw-r--r-- 1 46208 18. Apr 11:46 font26.jtf -rw-r--r-- 1 49424 18. Apr 11:46 font27.jtf -rw-r--r-- 1 44224 18. Apr 11:46 font2.jtf -rw-r--r-- 1 19352 18. Apr 11:46 font32.jtf -rw-r--r-- 1 20052 18. Apr 11:46 font34.jtf -rw-r--r-- 1 11928 18. Apr 11:46 font35.jtf -rw-r--r-- 1 40356 18. Apr 11:46 font3.jtf -rw-r--r-- 1 22292 18. Apr 11:46 font43.jtf -rw-r--r-- 1 39340 18. Apr 11:46 font4.jtf -rw-r--r-- 1 34908 18. Apr 11:46 font52.jtf -rw-r--r-- 1 47328 18. Apr 11:46 font5.jtf -rw-r--r-- 1 21652 18. Apr 11:46 font65.jtf -rw-r--r-- 1 44556 18. Apr 11:46 font6.jtf -rw-r--r-- 1 45476 18. Apr 11:46 font71.jtf -rw-r--r-- 1 41264 18. Apr 11:46 font73.jtf -rw-r--r-- 1 39352 18. Apr 11:46 font74.jtf -rw-r--r-- 1 48284 18. Apr 11:46 font75.jtf -rw-r--r-- 1 46836 18. Apr 11:46 font76.jtf -rw-r--r-- 1 50128 18. Apr 11:46 font77.jtf -rw-r--r-- 1 3648 18. Apr 11:46 font79.jtf -rw-r--r-- 1 49560 18. Apr 11:46 font7.jtf -rw-r--r-- 1 12924 18. Apr 11:46 font80.jtf -rw-r--r-- 1 36492 18. Apr 11:46 font81.jtf -rw-r--r-- 1 30384 18. Apr 11:46 font82.jtf -rw-r--r-- 1 28992 18. Apr 11:46 font84.jtf -rw-r--r-- 1 42996 18. Apr 11:46 font8.jtf -rw-r--r-- 1 407 18. Apr 11:46 jeppesen.tfl -rw-r--r-- 1 8896 18. Apr 11:46 jeppesen.tls -rw-r--r-- 1 2526 18. Apr 11:46 lssdef.tcl -rw-r--r-- 1 28968 18. Apr 11:46 monspacb.jtf -rw-r--r-- 1 64544 18. Apr 11:46 sserife.jtf

ll ldr_sys/ insgesamt 20576 -rw-r--r-- 1 9449990 18. Apr 11:43 avtn_db.bin -rw-r--r-- 1 5577 18. Apr 11:46 grm_feat_key.zip -rw-r--r-- 1 11588311 18. Apr 11:43 nav_db2.bin

dimaryaz commented 1 year ago

Interesting. Well, it's great that feat_unlk.dat worked - that was probably the most difficult part.

So simply extracting the .zip is not enough. Looks like a bunch of files need to be moved into a Charts subdirectory. Also, 023FL01687_VFRCharts.bin and 023KM01684_Charts.bin somehow get converted into charts.bin.

Of course those are the two zips that I can't access myself, so it's hard to tell what's going on. I'd really like to look at them, but you probably shouldn't upload them here. Could you email me at dima [at] gmail.com, so we can figure something out?

dimaryaz commented 1 year ago

I finally cracked the format of the Charts.bin file. It's basically a Zip without compression. Documenting it here, mostly for myself:

Byte Offset Length Value
0 4 CRC32Q (not CRC32!) checksum of everything after it
4 4 Magic number? Always 1B000001
8 4 N, Number of files
12 4 T, Byte offset of the table of contents
16 11 Same as Database Begin Date in charts.ini, padded with null bytes
27 T - 27 Contents of all files
T N * 40 Table of contents
Each entry in the table of contents is 40 bytes long, and has the following format: Byte Offset Length Value
0 26 File name, padded with null bytes
26 4 Byte offset of the contents of the file
30 4 File size
34 6 Unknown, but some property of the file

It looks like ChartView is broken into multiple downloads (Europe IFR, Europe VFR, etc.). Each one is a .zip containing a charts.bin file (though with different names like 023KM01684_Charts.bin or 023FL01687_VFRCharts.bin). JDM first sorts each charts.bin file so its entries are ordered by their byte offsets, then combines them into one file. I'm assuming they wanted to let the user buy any combination of regions and VFR/IFR, but G1000 needs to have everything in a single file.

The rest of the files in the .zip are mostly copied unchanged. The .dbf files might be getting merged, but it's a common file format.

digivation commented 11 months ago

Great work! Just ran across this repo, and I suspect that once the G1000 issues are solved, it will be very easy to extend to other Garmin flight displays. I have a new-to-me G500 & G430W, and am using the Garmin database subscription service. I think the code here will be a great basis for extending to a tool that supports both download sources & multiple devices. Would be great to be able to process updates with out needing the Garmin DB Manager (currently running it on a Mac, haven't attempted to get running under Wine yet).

I'll experiment more when I have some free time!

dimaryaz commented 11 months ago

@digivation: Thanks!

Programming of the G430W should already work; I have a G430 myself. The G500 might work, too - do you use the same data cards and a USB programming device as for the G430W, or regular SD cards?

Of course, you'd need to get the database file first. I haven't used the Garmin DB Manager, so no idea what it would take to reverse engineer it.

If you want to do a quick test to see if anything works at all, you can read the existing database from the data card by running jdmtool read-database db.bin (where db.bin is the output).

digivation commented 10 months ago

@dimaryaz I haven't tried the G430W but expect that to work just fine once I can get the databases from Garmin.

The G500 uses SD cards, just like the G1000 - I suspect the data set is very similar.

The 430 data cards are at the hangar, I'll check those next time I bring them home.

dimaryaz commented 2 weeks ago

Hey @liviro411! I know it's been over a year... but I haven't given up yet. If you're still around, I'd love for you to try the new code.

The latest released version of jdmtool should support everything but Electron Charts, and should produce results byte-for-byte identical to JDM itself.

If you install the chartview branch, you'll be able to transfer Electron Charts, too - though those are way more complicated. I was only able to test them using your zips from a year ago, so who knows how well it will work for the current charts. But, for the old ones, it was almost identical to JDM, with a few missing pieces:

Anyways... if you get a chance, try it and tell me how it works.