CCS C Software and Maintenance Offers
FAQFAQ   FAQForum Help   FAQOfficial CCS Support   SearchSearch  RegisterRegister 

ProfileProfile   Log in to check your private messagesLog in to check your private messages   Log inLog in 

CCS does not monitor this forum on a regular basis.

Please do not post bug reports on this forum. Send them to support@ccsinfo.com

changing fuses by editing HEX file

 
Post new topic   Reply to topic    CCS Forum Index -> General CCS C Discussion
View previous topic :: View next topic  
Author Message
mikehagans



Joined: 20 Jun 2007
Posts: 7
Location: Texas, USA

View user's profile Send private message

changing fuses by editing HEX file
PostPosted: Sun Jan 23, 2011 1:44 pm     Reply with quote

I'm a hardware guy trying to modify some code that I own and having little luck.

I have an 18F4620 project written by a contract employee that has the config register data set to values that I need to change.

Specifically I want to set 7L and 7H (read protect) to all zeroes.

My config registers are: (1H 1L 2H 2L ... 7L then checksum?)

02 00 1F 0E 81 00 00 81 80 00 80 00 40 0F 72 ( 72 as checksum?)

I edit the hex file and change the values to:
02 00 1F 0E 81 00 00 81 80 00 80 00 00 00 72

When I try to program a device, ICD thinks for a couple of seconds then display an ICD error: Bad file format or checksum.

So far, I believe that the last word (72) above is the checksum for the config registers, and the ICD sees that doesn't match what's in Config7L and config7H.

Or does the error signify that the overall checksum for the hex file is wrong and I just have to make these changes using config parameters in the source and recompile?

I'm trying to do it this way instead of editing the source code because I'm a complete noob and always seem to mess something up when i make changes in PCW.

I'm using ICD2.85 on an ICD-u40. The code was compiled using CCS C compiler v4.038 within the PCW IDE.

Any help or light-shedding comments would be appreciated.

Best,

Mike
PCM programmer



Joined: 06 Sep 2003
Posts: 21708

View user's profile Send private message

PostPosted: Sun Jan 23, 2011 2:20 pm     Reply with quote

So all you have is a hex file and no source code ?

Do you want to modify the config bits in the Hex file, so that you
don't have to use the Configure / Configuration Bits menu every time
(or whatever the equivalent of that menu is in the CCS IDE) ?
If so, you can edit the Config Bits of the Hex file in MPLAB:

1. Start up MPLAB with no project and no workspace.
2. Select the PIC device type in the Configure / Select Device menu.
3. Use the File / Import menu to load the Hex file.
4. Go to the Configure / Configuration Bits menu. Disable the tickbox
called "Configuration bits set in code". Now edit the drop-down boxes
for each Config bits setting that you want to change.
5. Use the File / Export menu to save the edited Hex file with a new
name. Note that MPLAB will export the whole program memory size of
the specified PIC, unless you edit the address range. It's not really an
issue unless you want a small hex file for the new one. You would have
to note the maximum program memory address used by the original file
and enter that value in to the Export dialog box. It's optional.

6. Load both the old and new hex files into a text editor and compare
the config bits settings. Be aware that the Config bits bytes are stored
in "Lo-Hi" format in the Hex file. The LSB byte comes first.
mikehagans



Joined: 20 Jun 2007
Posts: 7
Location: Texas, USA

View user's profile Send private message

PostPosted: Sun Jan 23, 2011 2:48 pm     Reply with quote

Thanks PCM Programmer. I do have the source and the hex, but I'm not a C programmer and am only slightly familiar with the CCS IDE.

My contract guy got a real job and now I'm trying to learn so I can (hopefully) make minor tweaks to the code if needed. The first tweak involves setting a slew of program configuration items (not to be confused with fuses) in the running product to values that make sense for my test environment, then exporting the hex file so I can use the TEST default values; once I test the this default version of the code I will go back to config7 H &L and re-enable the read protection. The protected version will be saved as my production version (read-protect enabled, but valid data in the unit's setup eeprom). This will shave a few minutes of setup time off each unit I program and test.

If there's no simple way to manipulate the bits in HEX (I have a simple hex editor, but not MPLAB), I'll download MPLAB and follow your suggestions. From what I've seen lurking, MPLAB is an important alternate tool to have anyway.

Thanks again - this is a great forum for users of all levels. I appreciate you taking the time to help someone as ignorant as I am.

Mike
Ttelmah



Joined: 11 Mar 2010
Posts: 19236

View user's profile Send private message

PostPosted: Sun Jan 23, 2011 2:59 pm     Reply with quote

Using MPLAB, is about 200* easier than trying to go DIY. Smile

The hex lines have an offset address that has to be added to the line address, to get the real address. Each line also has a checksum.
It _can_ be done, but is much more work than letting MPLAB do it for you.
Remember also that MPLAB will let you edit the EEPROM contents as well, which will simplify putting new values in here....

Best Wishes
mikehagans



Joined: 20 Jun 2007
Posts: 7
Location: Texas, USA

View user's profile Send private message

PostPosted: Sun Jan 23, 2011 3:54 pm     Reply with quote

MPLAB it is!
It's uncomfortable to not know what I don't know!
Thank you both for the recommendation.

Best,

Mike
mikehagans



Joined: 20 Jun 2007
Posts: 7
Location: Texas, USA

View user's profile Send private message

PostPosted: Sun Jan 23, 2011 7:55 pm     Reply with quote

Worked like a charm! Thanks again.

Mike
MotoDan



Joined: 30 Dec 2011
Posts: 55

View user's profile Send private message

PostPosted: Fri Oct 16, 2015 12:50 pm     Reply with quote

I just ran across this thread while searching for some information regarding fuse settings in the hex file. From what has been said, this method of importing the hex file into MPLAB and changing certain configuration bits and then exporting the file looks like a way to override Microchip's code protection mechanism. Doesn't make me feel very safe about giving my hex files to a PCB manufacturer.
PCM programmer



Joined: 06 Sep 2003
Posts: 21708

View user's profile Send private message

PostPosted: Fri Oct 16, 2015 11:06 pm     Reply with quote

Get them to sign a non-disclosure agreement. That way if they cheat,
you have a legal right to sue them.
Ttelmah



Joined: 11 Mar 2010
Posts: 19236

View user's profile Send private message

PostPosted: Sat Oct 17, 2015 1:19 am     Reply with quote

Don't get me wrong, but if you give them the hex files, you are giving them the code.....
The hex file is the code, and has no protection.

This is nothing to do with Microchip's code protection mechanism. This doesn't apply till the code is programmed into the chip.

As PCM_Programmer says, this is the point of things like non-disclosure agreements.

There are other ways of approaching this though:

1) The non-disclosure approach.
2) Have them program an encrypted bootloader, not your code. Put the code in afterwards using the bootloader. This way they will have the core to reading the encryption, but not the actual code, so unless they can get these files as well, do not have the code.
3) Have the chips programmed at factory by Microchip. For any large order this is usually cheaper, and if you can't trust them, then you can't trust the chip itself...
temtronic



Joined: 01 Jul 2010
Posts: 9120
Location: Greensville,Ontario

View user's profile Send private message

PostPosted: Sat Oct 17, 2015 5:01 am     Reply with quote

If you want to be really paranoid...
...there's nothing to stop the PCB mfr from making a few extra boards, giving them to some 3rd party and then having your board reverse engineered. It'd be real easy for them as they have every part number, schematic and well the real PCB !

In the 'old days' we'd sand off the ID info of the chips,some would add there own 'OEM numbers', others get mfr to make mirror image chip (pin 1=16, 2=15,etc.) so 'bad guys' couldn't get that chip. Lots of other ways to 'discourage' anyone from stealing your PCB.

These days though with fast PCs, software and China, IF the demand is there you can 'clone' any product, have it made and in your lab in less than a week.

Jay
soonc



Joined: 03 Dec 2013
Posts: 215

View user's profile Send private message

Another way
PostPosted: Wed Oct 21, 2015 2:12 pm     Reply with quote

MotoDan wrote:
I just ran across this thread while searching for some information regarding fuse settings in the hex file. From what has been said, this method of importing the hex file into MPLAB and changing certain configuration bits and then exporting the file looks like a way to override Microchip's code protection mechanism. Doesn't make me feel very safe about giving my hex files to a PCB manufacturer.


Using the CCS Load-n-Go allows you to protect the Hex Code, and your assembly shop can program the PCBs.
If you use a serial number you have control of how many boards get programmed.

It costs $200 but gives you peace of mind that not even you can read the hex file.
Display posts from previous:   
Post new topic   Reply to topic    CCS Forum Index -> General CCS C Discussion All times are GMT - 6 Hours
Page 1 of 1

 
Jump to:  
You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot vote in polls in this forum


Powered by phpBB © 2001, 2005 phpBB Group