AnsweredAssumed Answered

A boot loader for 9S12X

Question asked by John Dammeyer on Oct 3, 2014
Latest reply on Nov 3, 2014 by John Dammeyer

I need some help developing a boot loader for a 9S12XDP512 and none of the app notes out there address the 9S12X series which appears to have different Flash.  Also I need to boot from an image stored in an unused part of the 9S12X flash.  (I have 512K total).  I've written code to receive an .phy file and store the text in unused pages in the flash memory.  That's with the structures below for file name and size information.  That same flash area is also used to hold update code for PIC series modules and will be sent over CANOpen to those devices.  So the 9S12X is the gateway for upgrading all the modules on a CANOpen network.  Eventually this 9S12 may have an add on SD card on some versions.  That's why the 'file' oriented format for saving code upgrades.


The file 24 pointers now work for writing and reading flash but my next problem is setting up a bootloader.  The 9S12X has the IVBR so theoretically I can code the boot loader to use the standard default upper vectors and then if the application code image is healthy map the user's interrupt vector base into the IVBR and jump to the user start location.


Where I'm having trouble is how to set up the PRM files for the Bootloader and the application.  The bootloader just has to start up, verify that the code image is correct and that a location in EEROM doesn't say install new code.  If the EEROM location says install new code it verifies that the image in flash is for the right processor and that it's intact.  Then just read the phy file line by line and program flash.  If it suceeds, jump to the application.  If not flash some LEDs.


Can anyone give me some guidance on setting up the .prm?



John Dammeyer


    The Code Control Block holds all the information required for the

    9S12 or dsPIC or PIC boot loaders.



#define CONTROL_BLOCK_SIZE      16  // 16 words 32 bytes.

typedef union _codecontrolblock {

  struct {

    ULONG Id;          // Holds 0xFEEDCODE

    WORD CRC;          // Block CRC

    char FileName[9];  // general format name is xIMn_ssv

    char Suffix[4];    // .phy, .hex, .bin

    char Format;       // 'S' (Motorola) or 'I' HEX (Intel) format or 'B' BIN

    char TargetID;     // CANOpen NodeID of destination. (1 == ourselves)

    char Open;         // Ram Structure holds 1 if file open, 0 if closed.   

    WORD Size;         // Size in WORDs.

    WORD WritePosition;

  } f;

  unsigned int a[CONTROL_BLOCK_SIZE];




typedef struct _codeblock {


    WORD CodeImage[1]; //[1] to be able to set a pointer.