Bootloader and Instant Interrupts Atn:_DT_


Closed Thread
Results 1 to 9 of 9

Hybrid View

  1. #1
    Join Date
    Sep 2005
    Location
    Campbell, CA
    Posts
    1,107


    Did you find this post helpful? Yes | No

    Default

    There are probably simpler ways, but I have documented the procedure I used. Note that I started with Mechanique's MCLoader.



    Disclaimer: This is a complicated process that requires some knowledge of assembly. It also works
    better with chips that have some "space" above MCLoader. If you use this approach on chips that don't have
    at least one erase block above MCLoader (such as an 18F452), if programming is interrupted before successful completion, the BOOTLOADER WILL CEASE TO FUNCTION. This is because PIC memory must be erased before being
    written. All codespace below MCLoader (which resides in high memory) is erased before the new program is
    loaded.

    Proceed at your own risk!



    The scheme is basically as follows: (assuming 18F8722 here).

    Look at the chip's datasheet and find the "block size" in the section on writing to FLASH memory. Note the ERASE block size and the WRITE block size. On an 18F8722 those are both 64 bytes.

    Import the appropriate MCLoader .HEX file into MPLAB. View PROGRAM MEMORY, which basically does a disassembly of the code. Leave this window open, you will be using it again.

    #1. Note the jump address - found at address 2 & 3 (it is a WORD, so it takes two bytes). In an 18F8722, this address is 0x1fd04.

    Now scroll down to the address pointed to in step #1.

    #2. About 16 bytes before this, (1FCF0 in a 18F8722) you will find a series of bytes filled with "0000"'s (the surrounding bytes will be filled with "FFFF"'s). The first byte of these "0000" is the INIT jump vector address. Write that address down as the "INIT JUMP VECTOR LOCATION"

    #3. Scroll to the end of MCLoader and check if there is at least one "erase block size" between the end of MCLoader and the end of memory. In an 18F8722 there is. In an 18F450 there is not - Skip to step #5.

    #4. Look for a byte on a segment boundary (evenly divisible by the erase segment size) that is just ABOVE the last address used by MCLoader. Write this address down as the "INTERCEPT ADDRESS". This address is 1FFC0 in an 18F8722. Go to step #6

    #5. Look for a byte on a segment boundary (evenly divisible by the erase segment size) that is at least 1 erase block size BELOW the address you found in Step #2. Write this address down as the "INTERCEPT ADDRESS".


    You will need to modify MCLoader. You can do this in at least two ways: Modify the appropriate MCLoader .HEX file (not for the timid). or you can write a "patcher" in PBP. I have done both.
    If you choose to write a patcher, it needs to reside above the first block of memory (you will use the code itself to erase that block, so put an "@ ORG 0x40" at the beginning of your code to make sure it loads above that point. You need to modify the JUMP instruction at location 2 (&3) to point to your INTERCEPT ADDRESS. Before you can write to FLASH, you must erase it, so use the instruction "ERASECODE 0". This will erase the first block of FLASH.
    Now use WRITECODE to write the ENTIRE first block of memory and put INTERCEPT ADDRESS in locations 2 & 3. For
    an 18F8722 this would be:

    WRITECODE $0,$0000
    WRITECODE $2,$EFE0 ; Change the initial jump vector to 0x1FFC0
    WRITECODE $4,$F0FF

    FOR X = $6 TO $3E STEP 2 ; Finish writing the block
    WRITECODE X,$FF
    NEXT X


    Next, you will have to add an instruction at 0x1FFC0 (or whatever INTERCEPT ADDRESS you are using) to add a JUMP to the address found in step #1 - the beginning of MCLoader (Don't forget to erase the block first).

    1FFC0 = FFD6 EF82
    1FFC2 = FFD8 F0FE

    (This is for 0x1FD04)



    What you have done is to cause the code to immediately jump to an address of YOUR choosing, and then jump to the
    beginning of MCLoader. All this is necessary because you want the bootloader to be able to load your code the first time. So far, all will work normally.

    ;END OF BOOTLOADER PATCHING



    Now, for the application code modification:

    A. Add a block in your program to read the INTERCEPT ADDRESS to determine whether or not it is pointing to the beginning of MCLoader.

    B. Go to a block that first ERASES the block starting at the INTERCEPT ADDRESS and changes the jump vector there to the INIT JUMP VECTOR LOCATION found in step #2.

    C. Write another block that ERASES the block starting at the INTERCEPT ADDRESS and changes the jump vector there to the beginning of MCLoader.


    When the program starts, it should perform "A" to see if the jump vector is pointing to MCLoader. If it is, it should call block "B". (Don't write to FLASH unless you really need to change it).

    When you wish to unprotect the loader, call block "C"
    Charles Linquist

  2. #2


    Did you find this post helpful? Yes | No

    Default Thanks Charles, you might forgot...

    Hi.

    This seems like really complex to me, begining with the fact that almost everything is done to make it work with de MCloader, wich i donīt intend to use, if you can help me with this i would be grateful:

    1. Change made to pbp 18f lib to make wirtecode usefull at the end of program memory.

    2. The INIT position, is it always the same for same uC? how can i know it to go there if no sync with pc during bootloader is made.

    3. 18f452 has 64 bytes blocks, can I use the last one for the bootloader and avoid erasing it?

    Thanks for your help here.

  3. #3


    Did you find this post helpful? Yes | No

    Default I get some stuff now!

    Ok i donīt need writecode to work over FFFF because 452 doesnīt has that memory size.

    I am trying something already, by the way, can you help me with some info about the hex format? i need now to open an HEX file and send it through the serial port of my PC. When i open an HEX with notepad i get:

    :10000000126AA5EF00F0ABB2AB98AB880C50006E53
    :100010000D50016E026A036A000000D004009EBA0F
    :1000200013D0FF0E0226D8A00326D8A00026D8A001
    :100030000126D8A0A2EF00F00248033CEDD7FA0E4B
    :10004000026E000E036EEAD7AE50D880A2EF00F029
    :1000500004009EA8FDD7AD6ED880A2EF00F0076E19
    :100060008490809A809A9690929A929AF00E941622
    :10007000075012B222D03A0E016E980E93EC00F0A7
    :10008000330E066E30D8130E016E880E93EC00F01E
    :100090002AD8640E92EC00F026D8640E92EC00F0A0
    :1000A000220E066E20D8280E07D80C0E05D8060E94
    :1000B00003D81282075001D01280066E12A00BD016
    :1000C000809A03080EE30DD8070E016ED00E93EC54
    :1000D00000F0D88012001280FE08D8B4A2EF00F021
    :1000E000808A063A12A012908480F00E8216065082

    this doesnīt look nice at all, and i dont find the match with for example

    0000- 6a12 efa5 f000 b2ab 98ab 88ab 500c 6e00
    0008- 500d 6e01 6a02 6a03 0000 d000 0004 ba9e
    0010- d013 0eff 2602 a0d8 2603 a0d8 2600 a0d8
    0018- 2601 a0d8 efa2 f000 4802 3c03 d7ed 0efa

    presented by EPICWIN.

    Is it correct for me to think that writing this last words to the appropiate addreses will get the uC correctly programmed?
    Last edited by Josuetas; - 15th May 2007 at 20:27.

  4. #4
    skimask's Avatar
    skimask Guest


    Did you find this post helpful? Yes | No

    Default

    :10 0000 00 126A A5EF 00F0 ABB2 AB98 AB88 0C50 006E 53
    10 = record type
    0000 = start address
    00 = number of bytes in record, 00=16??? Not 100% sure on this
    126A = data, look below at your 2nd chunk of data sent...look familiar?

    0000- 6a12 efa5 f000 b2ab 98ab 88ab 500c 6e00


    The 1st file you sent is an actual INTEL HEX file, which is a different format than...
    The 2nd file chunk you sent...which is actual data.

    Google 'INTEL HEX record', you should find all the info you need somewhere out there...

  5. #5
    Join Date
    Sep 2005
    Location
    Campbell, CA
    Posts
    1,107


    Did you find this post helpful? Yes | No

Similar Threads

  1. Hserin with Instant Interrupts.
    By ronjodu in forum Serial
    Replies: 17
    Last Post: - 30th December 2014, 20:17
  2. Unusual Interrupts Application Problem
    By Joe Rocci in forum mel PIC BASIC Pro
    Replies: 2
    Last Post: - 8th May 2009, 11:55
  3. Microchip Bootloader and Interrupts
    By Josuetas in forum mel PIC BASIC Pro
    Replies: 0
    Last Post: - 18th May 2007, 00:11

Members who have read this thread : 0

You do not have permission to view the list of names.

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts