"forbidden" memory areas (bootloader, etc)

Todd Brown
  • Todd Brown
    Todd Brown


    The processor I'm using (NXP P89V662, an 8052-variant) has a built-in bootloader that resides at a specific location in memory.  Using ESA's FlashMagic, I don't really have to worry about overwriting the bootloader, because it will automatically prevent that.  However, I am writing my own programming software (I want to move away from FlashMagic because it's only available on Windows, and I don't want to have to worry about licensing issues when providing firmware updates to my customers).

    The problem is this: how does FlashMagic "protect" that section of memory?  The only thing I can think of is that it actually re-writes the HEX file on the fly, making sure none of the records are written to that section of memory.  Which wouldn't be so hard except then all jump instructions will have to be modified, as well as adding a jump to jump across the bootloader; a complication I would rather avoid.

    So, question #1 is a little off-topic, but I figured someone here might know: am I missing something that makes it easy to take any hex file and program it to a device while skipping over a section of memory?

    Question #2 is on-topic: is there any way to tell sdcc (or, more likely, the linker) to avoid certain sections of memory?  This will be important again later on because this processor supports in-application programming, which means I can have firmware save defaults that will be available even through a power cycle.  But those will always be located in a specific location in code memory, and it wouldn't do to have the linked hex file put user code in those locations!

      Todd Brown

    • Hi Todd,

      Last year I wrote a boot loader for the P89LPC925 which does basically what you want to do.  It should be very easy to change it for the P89V662.  It is a single C file available at


      Some tips:

      Make sure you do not erase the boot loader code!  This is certainly possible with the P89LPC925.  I am not sure if it possible with the P89V662.  For the program above check lines 421 to 424 where the Intel hex string are defined to erase all but the last sector where the boot loader is.  In the P89V662 the boot block is allocated from FC00H to FFFFH...

      Also make sure you do no write anything where the boot loader is.  In the program above this is achieved by setting a maximum size for the user code (check line 42).  That maximum size is checked when loading the hex file to program (line 269).

      To completely prevent SDCC from placing code where the boot loader is, you can use '--code-size 0xfc00' when linking.