Skip to main content
Topic: PK2DeviceFile.dat editing tool (cli) (Read 2694 times) previous topic - next topic

PK2DeviceFile.dat editing tool (cli)


I wrote a small command line tool to modify device files that are used by
the pk2cmd tool. It can dump a device file like
Code: [Select]
./pk2dft -d PK2DeviceFile.dat dump
whereby it creates a directory structure that looks like
Code: [Select]
 +- config.cfg
 +- devices
    +- Unsupported
 +- families
    +- Baseline.fam
+- PIC24.fam
+- PIC32.fam
 +- scripts
    +- 18F_26K80ChpErase.scr
+- MR_UsrIDWrInt.3.scr
+- MR_WrOSCCALInt.1.scr
It is then possble to edit files and recompile it:
Code: [Select]
./pk2dft -c dump pk2dev.dat
This gives a new device file named "pk2dev.dat".
I was able to dump and recompile the PK2DeviceFile.dat I am using and
checked that the files are identical using "diff". There are probably
still some bugs but I think it might be usable already.
I attached the source code, you need libconfuse to compile it and it
probaly wont work under windows natively (because the are some
system("mkdir ...") calls as well as "/" in filenames ...).
Code: [Select]
gcc pk2dft.c -lconfuse -o pk2dft

I still have some problems figuring out the instructions of the scripts. I know that they are documented (for example here: ... 2_commands) but looking at the script commads stored inside the PK2DeviceFile.dat the data doesnt make too much sense.
For example the script code from '32MX_DevIDRd.scr':
Code: [Select]
script        = {
 0xbb, 0xaa, 0x04, 0xbb, 0xbb, 0xaa, 0x01, 0xbb,
 0xb9, 0xaa, 0x00, 0xbb, 0x00, 0xbb, 0x00, 0xbb,
 0x00, 0xbb,
hexdump from original file:
0002ad80  65 64 2e f5 00 0c 33 32  4d 58 5f 44 65 76 49 44  |ed....32MX_DevID|
0002ad90  52 64 00 00 00 00 00 00  09 00 bb aa 04 bb bb aa  |Rd..............|
0002ada0  01 bb b9 aa 00 bb 00 bb  00 bb 00 bb 3c 53 65 6e  |............<Sen|
0002adb0  64 43 4d 44 28 4d 54 41  50 5f 53 57 5f 4d 54 41  |dCMD(MTAP_SW_MTA|
0xbb stands for JT2_SENDCMD and takes an additional parameter, but
this would mean that they next instruction is 0x04 which is invalid. Has somebody got
an idea how to interpret the above code? Maybe the byte order is messed up (stored as 16bit unsigned integers)?


Re: PK2DeviceFile.dat editing tool (cli)

Reply #1
The MSB in the DAT file script is META DATA for the programmer client and not the pickit 2. It is not in fact sent to the pickit. The MSB is each second byte in the script. If you ignore them all then the script makes sense.

This information is on the very last page of the pickit 2 firmware source code guide:


Script,  ushort Array

Array containing script elements (control bytes and arguments). The first element to execute is in array position [0].

The control bytes and arguments are stored in the low byte of each array element.
The upper byte is used for tags:

0xAA = Control Byte (as opposed to argument byte)
0xBB = Display argument byte as hexadecimal
0x00 = Display argument byte as decimal

Therefore the interpretation of the script you showed without the META TAGS is:

BB 04
BB 01
B9 00 00 00 00

From towards the end of the page you linked to you can see confirmation.

Read device id, 9 bytes.
bb 04    JT2_SENDCMD
bb 01    JT2_SENDCMD
b9 00 00 00 00    JT2_XFERDATA32_LIT

Nowhere on this page is there anything mentioned about the meta tags because this page is dealing with the actual pickit 2 firmware that does not see them and not the client that does.

I got caught on this too and it had me scratching my head for some hours until I RTFM right to the last word were all was revealed.