Henry Luong

mc9s12dg256: lrae&lfae-style bootloader help

Discussion created by Henry Luong on Dec 24, 2008
Latest reply on Jan 14, 2009 by Henry Luong
I am implementing a bootloader similar to the app notes for LRAE & LFAE.

I am using Cosmic compiler generating three s19 files
BOOT1.s19 (equivalent to LRAE)
BOOT2.s19 (equivalent to LFAE)
MAIN.s19 (the main app)

BOOT1 resides in ppage $3F starting at address $F800. It looks for an EE variable that stores an address to the MAIN app. If empty or invalid, will then wait to be programmed.

BOOT2 gets programmed into RAM (mapped at $1000 - $4000) via BOOT1.

MAIN is multi paged starting at $5100 and is programmed via BOOT2. I've mapped eeprom to $4000 to $5000, so ppage $3E actually starts at $5000, and a jumptable for interrupts reside at $5000 to $5100, so the MAIN app starts at $5100. After programming, I write $5100 to the EEprom variable that BOOT1 looks for.

All this is done successfully, raw data from s19 files are written to the appropriate locations in flash and eeprom. But I cannot get the MAIN to execute. On bootup to BOOT1, I tell the micro to jump to the location stored in the EE variable like this
    _asm("tfr d,y", GEuintAppAddr);
    _asm("jmp 0,y");

but nothing happens. either wrong address, or MAIN has an error. But I've flashed the micro via BDM using MAIN.s19 directly without problems. Only difference is when flashing directly, I include the interrupt vector in linking. The interrupt vector is already linked in BOOT1 since I've protected that sector of flash. This is what the jumptable is for. Interrupt vector points to a location in the jumptable, which then jumps to the actual function performing interrupt routines.

My other suspicion is that both BOOT1 and MAIN has linked the startup file crtsi.s required by COSMIC, and it gets executed twice in the code (once in BOOT1, and 2nd when BOOT1 jumps to $5100) which somehow interferes.

I know most ppl use codewarrior here, but if anybody can give me some pointers or ideas of where to look, I'd very much appreciate it.