QUOTE (_Артём_ @ Mar 27 2012, 01:28)

А вы как делали?
Несколько проще. Загрузчик занимает место с 0 до 0x1000. Со своими векторами, прибитыми гвоздями. Приложение линкуется как обычно, но начиная не с 0, а с 0x1000, в остальном это обычная программа:
CODE
MEMORY
{
REMAPED(r) : ORIGIN = 0x00000000, LENGTH = 192 /* 192 = vectors table size */
TEXT (rx) : ORIGIN = 0x00001000, LENGTH = 32K - 4K - 4K /* 4K - boot, 4K - config */
CONFIG(r) : ORIGIN = 32K - 4K, LENGTH = 4K
RAM (rw) : ORIGIN = 0x10000000 + 192, LENGTH = 8K - 192 - 32 /* 192 - remaped vectors, 32 - iap working area */
}
Для загрузчика карта памяти будет, соответственно:
CODE
MEMORY
{
TEXT (rx) : ORIGIN = 0x00000000, LENGTH = 4K
APPLICATION(rx) : ORIGIN = 4K, LENGTH = 32K - 4K - 4K /* 4K - boot, 4K - config */
CONFIG(r) : ORIGIN = 32K - 4K, LENGTH = 4K
RAM (rw) : ORIGIN = 0x10000000 + 512, LENGTH = 8K - 512 - 32 /* 32 - IAP reserved space */
REMAPPED (xrw) : ORIGIN = 0x10000000, LENGTH = 512 /* 512 = remappable area size */
}
SECTIONS
{
.remapped (NOLOAD) :
{
_remap_area = .;
} > REMAPPED
.......
.application (NOLOAD):
{
Application = .;
} > APPLICATION
}
И загрузчик просто копирует всю таблицу векторов приложения начиная с метки Application в _remap_area:
CODE
struct application
{
struct vectors
{
typedef void( *handler )( void );
uint32_t MSP_init;
handler Reset_vector;
handler Core_handler[14];
handler MCU_handler[32];
} Vectors;
};
extern const application Application;
extern application::vectors _remap_area;
....
if (CRC.ok()) // Application Section OK
{
// copy application vectors table to remap area
// memcpy(&_remap_area, &Application.Vectors, sizeof(Application.Vectors));
uint32_t const * pSrc = (uint32_t const *)&Application.Vectors;
uint32_t * pDst = (uint32_t *)&_remap_area;
do
{
*pDst++ = *pSrc++;
}
while(pSrc < (uint32_t const *)(&Application.Vectors + 1));
asm volatile
(
" MSR MSP, %0\n" // store App stack init value to MSP
:
: "r" (Application.Vectors.MSP_init)
);
LPC_SYSCON->SYSMEMREMAP = LPC_MAP_RAM; // remap to ram
Application.Vectors.Reset_vector();
}
}
Вообще-то у меня еще в начале приложения хранится его размер, чтобы считать CRC только занятой памяти:
CODE
struct application
{
uint32_t Size;
struct vectors
{
typedef void( *handler )( void );
uint32_t MSP_init;
handler Reset_vector;
handler Core_handler[14];
handler MCU_handler[32];
} Vectors;
};