Flash Magic Forum

In-System Programming Support => LPC9xx/LPC9xxx => Topic started by: Sarsam NL on April 29, 2005, 05:43:38 AM

Title: making an application updateable using IAP in P89LPC936?
Post by: Sarsam NL on April 29, 2005, 05:43:38 AM
hi all,
I am working on an application which should be updateable using a firmware not readable to the outside world. My question was whether it is possible to use IAP with P89LPC936 to update firmware of my application.

  Any C code could be very helpfull.
 Any help is highly appreciated.
best regards
Sarsam

Title: Re: making an application updateable using IAP in P89LPC936?
Post by: erikm on April 29, 2005, 06:26:14 AM
how are you going to have the customer update "not readable to the outside world" when it requires providing a file.

If You, yourself, are going to do the updates, then read up on security bits.

Erik
Title: Re: making an application updateable using IAP in P89LPC936?
Post by: Jan Waclawek on April 29, 2005, 10:35:27 PM
But why, you can encrypt the data and include the decryption routine into your "updater".
You can get inspired by the "des bootloader" adn "aes bootloader" for AVRs by Atmel:
http://www.atmel.com/dyn/resources/prod_documents/doc2541.pdf
http://www.atmel.com/dyn/resources/prod_documents/AVR230.zip
http://www.atmel.com/dyn/resources/prod_documents/doc2589.pdf
http://www.atmel.com/dyn/resources/prod_documents/AVR231.zip

Have fun!

Jan Waclawek



Post Edited (04-29-05 22:51)
Title: Re: making an application updateable using IAP in P89LPC936?
Post by: sarsam NL on April 29, 2005, 10:48:21 PM
thank you Jan,
I will look at it. The firmware can be copied and if no encryption, the application could be stolen and made immitated, i want to research on it how it should be built such that the update should not be hackable. If i have more questions i will certainly post it here.
Thank you for the help,
best regards,
Sarsam
Title: Re: making an application updateable using IAP in P89LPC936?
Post by: Jan Waclawek on April 29, 2005, 10:54:46 PM
Note I  have updated for the AES bootloader too.
I would recommend you AES better than DES; it is newer, said to be better and - surprise - more compact, so you spare memory implementing it.
But you can use any encryption scheme you chose.
Note, that you still can be compatible with the style of ISP commands (and you can replace the old bootloader with yours), so you (or your customer) can use FlashMagic for convenient updating of the firmware.

Jan Waclawek

PS. If needed, you can use a different key to DES/AES/whichever encryption scheme you use, for each customer; so the update issued for one woun't work for the other.
Title: Re: making an application updateable using IAP in P89LPC936?
Post by: sarsam NL on April 30, 2005, 03:01:46 AM
dear Jan,
Thank you for the reply,
yes indeed, each customer has its own serial number so dependent on the serial number a encryption scheme is generated. I am new to the embedded systems, do you have any samples which i can work on it? The entering of the ISP mode is clear now thanks to erik, now just wondering how to place the decryption algorithm routine into the isp code, as I can program in C but less in Assembly. If you could help me,

best regards,
Sarsam
Title: Re: making an application updateable using IAP in P89LPC936?
Post by: Andy Ayre on April 30, 2005, 07:12:18 AM
You can use the Just In Time feature of Flash Magic to automatically program in changing serial numbers. There are even some example JIT modules included with Flash Magic.

Title: Re: making an application updateable using IAP in P89LPC936?
Post by: Jan Waclawek on April 30, 2005, 08:28:57 AM
You need either to write your own ISP bootloader, or to modify the existing one. The following link might help:
http://www.8052.com/forum/thread.phtml?thread=84899

Jan Waclawek
Title: Re: making an application updateable using IAP in P89LPC936?
Post by: Sarsam NL on May 01, 2005, 01:55:56 PM
Dear Jan,
the link you gave me is not working, i found plenty of threads discussing the bootcode. As i said that i am not much good in ASM :)but know bit of C, so the bootcodes I found were mostly written in ASM, now if i want to use encryption and decryption i must know, when the byte is recieved from the UART so that i can use decryption to decrypt it back to the original, so if you guys could help me a bit, some samples will be very helpfull as i am newbie in programming world.
best regards,
Sarsam
Title: Re: making an application updateable using IAP in P89LPC936?
Post by: Jan Waclawek on May 02, 2005, 01:11:05 AM
The main result of the "many threads" is in fact the following file
http://www.semiconductors.philips.com/files/markets/microcontrollers/Adding%20ISP%20in%20source%20code.zip
which contains the source files of the LPC9xx bootloader.
Yes, it's asm. I am sorry, but if you want to use it, you will need to learn it.
Alternatively, you can write your own bootloader from scrap in C.

Have fun,

Jan Waclawek
Title: Re: making an application updateable using IAP in P89LPC936?
Post by: Sarsam NL on May 02, 2005, 02:24:44 AM
Thanks again for the reply, yesterday whole night I was working on learning ASM abit, and i indeed found the source for the ISP. I found also the code where the characters are recieved trough UART, and i will go and play around it. Has anyone written an ISP boot for LPC935/936 of philips which is easy to modify to place encryption or decryption?
best regards,
Sarsam
Title: Re: making an application updateable using IAP in P89LPC936?
Post by: Sarsam NL on May 02, 2005, 03:28:51 AM
Does anybody know how to exit boot(ISP). I can enter ISP but cant come out of it without reprogramming it. Can anybody help me on this?
best regards
Sarsam
Title: Re: making an application updateable using IAP in P89LPC936?
Post by: Andy Ayre on May 02, 2005, 07:58:43 AM
Program the status bit to zero and reset.

Title: Re: making an application updateable using IAP in P89LPC936?
Post by: sarsam NL on May 02, 2005, 02:32:55 PM
thank you andy, ;)
Is there an ISP code for the LPC9XX family which is able to use data encryption as ones for the ATMEL's AVR's?

Thank you all mates

Sarsam
Title: Re: making an application updateable using IAP in P89LPC936?
Post by: Andy Ayre on May 02, 2005, 05:38:57 PM
Not that I know of. I'm sure someone will eventually write it.

Title: Re: making an application updateable using IAP in P89LPC936?
Post by: Sarsam NL on May 03, 2005, 01:44:57 AM
I want to write it but need alots of help. I am not so experienced into ASM and also about bootloaders. If anyone can help me writing such a ISP-loader. I think it is very important. Nowdays the programs has to be updateable and you dont want to lose your hard effort on writing an update and somebody can tap it and place it into a copy of the device, and your hard work is lost. To prevent, there must be a program written such as that one of ATMEL's.
Best regareds
Sarsam
Title: Re: making an application updateable using IAP in P89LPC936?
Post by: Sarsam NL on May 03, 2005, 04:30:25 AM
Dear Andy,.
Thanks again,
Could you provide me more details about the FLASHMAGIC just in time module. I could not find it here at the site.
another question, I use LPC935 and i tried to update the ISP-loader and a bit modified. I changed the asm file of the LPC_ISP_8KV03.a51, where the bytes are been stored, there i just manupulated the data by Xoring the data with #34 to make the Hex file uploaded not easy readable to others. and then it writes it to the flash. when programming i disable the "protect ISP" and then choose "erase blocks used by the HEX file". FM even asks if i am sure while overwriting ISP and I type yes. After update, the ISP should respond as downloading the file but each single byte should be XORed by #34 but the program that i run just works perfect, even without modifing it in the HEX file. So a bit strange. Hope you have more suggestions, i modified the a51 file here,
LCMD:
   MOV   R5,#0   ;begin record... zero checksum
   ACALL   ECHO      ;get first char and echo
   CJNE   A,#':',LCMD   ;record starts with ':' char
   ACALL   GET2      ;get the number of bytes in record
   MOV   NBYTES,TMP3   ;and save
   ACALL   GET2      ;get MSB of load address
   MOV   ADR1,TMP3   ;and save
   ACALL   GET2      ;get LSB of load address
   MOV   ADR0,TMP3   ;and save it
   ACALL   GET2      ;get record type
   MOV   RTYPE,TMP3   ;and save it
   MOV   A,NBYTES   ;else, more than
   MOV   R2,A   
   JZ   EOR      ;zero data bytes ?
   MOV   R1,#DBYTES   ;pointer for data bytes
LDATA:   ACALL   GET2      ;get data byte
   MOV A,TMP3;After GET2 is called it stores the byte to TMP3   XRL  A,#34;XOR the data 34(decrypt the data)
   MOV TMP3,A;move it back to TMP3
   MOV   @R1,TMP3   ;store it
   INC   R1      ;and bump up the pointer   
   DJNZ   R2,LDATA   ;repeat if more bytes in record

Title: Re: making an application updateable using IAP in P89LPC936?
Post by: Jan Waclawek on May 03, 2005, 07:10:28 AM
Sarsam,

You are on the right track.

The problem might be in this line:

MOV A,TMP3;After GET2 is called it stores the byte to TMP3   XRL A,#34;XOR the data 34(decrypt the data)

If you place the XRL after any ";"  (i.e. after the comment),  it becomes a part of the comment.


Try

        MOV A,TMP3;After GET2 is called it stores the byte to TMP3
   XRL A,#34;XOR the data 34(decrypt the data)
        MOV TMP3,A;move it back to TMP3


Jan Waclawek

Title: Re: making an application updateable using IAP in P89LPC936?
Post by: Sarsam NL on May 03, 2005, 08:17:23 AM
Thank you Jan,
I am sorry was my mistake, actually while copy pasting this was taken wrongly over as the line was as you suggested. I XOR it as it is mentioned, if you or anybody else can take a look at the ISP code written by philips for the LPC family. There i modified it but the loader places the right bytes at the right places so the data does not become currupted as i hoped. I am not familiar with these ISP codes. I am really stuck.
Anyhow i am researching all methods possible as LPC is my best choice.
Best regards,
Sarsam