- minor changes
Committed on the Free edition of March Hare Software CVSNT Server. Upgrade to CVS Suite for more features and support: http://march-hare.com/cvsnt/ git-svn-id: http://moon:8086/svn/vhdl/trunk@442 cc03376c-175c-47c8-b038-4cd826a8556b
This commit is contained in:
@@ -1,6 +1,9 @@
|
||||
#include "libsys_boot.h"
|
||||
#include "cfiflash.h"
|
||||
|
||||
#define MAGIC_EB 0x4A464931 // "JFI1" in big-endian;
|
||||
#define MAGIC_EL 0x3149464A // "JFI1" in little-endian;
|
||||
|
||||
typedef struct _ssrec_t
|
||||
{
|
||||
UINT32 addr;
|
||||
@@ -17,7 +20,7 @@ typedef struct _sflash_alloc_tbl_t
|
||||
|
||||
typedef struct _sflash_img_hdr_t
|
||||
{
|
||||
UINT8 magic[4];
|
||||
UINT32 magic;
|
||||
UINT32 target_base;
|
||||
UINT32 img_base;
|
||||
UINT32 img_size;
|
||||
@@ -124,6 +127,18 @@ int srec_getline(UINT8 *pLine)
|
||||
return i;
|
||||
}
|
||||
|
||||
UINT32 conv_endian32(UINT32 src)
|
||||
{
|
||||
UINT32 dst;
|
||||
|
||||
dst = (0xFF000000 & (src << 24))
|
||||
| (0x00FF0000 & (src << 8))
|
||||
| (0x0000FF00 & (src >> 8))
|
||||
| (0x000000FF & (src >> 24));
|
||||
|
||||
return dst;
|
||||
};
|
||||
|
||||
void Jump_to(void *pEntry)
|
||||
{
|
||||
__asm
|
||||
@@ -179,6 +194,41 @@ void Exec_at(void *pEntry)
|
||||
);
|
||||
}
|
||||
|
||||
void Exec_RE_at(void *pEntry)
|
||||
{
|
||||
__asm
|
||||
(
|
||||
".set noreorder\n"
|
||||
);
|
||||
|
||||
__asm
|
||||
(
|
||||
"mfc0 $26, $12\n" // change exception vector
|
||||
"li $27, 0xFFBFFFFF\n"
|
||||
"and $26, $27\n"
|
||||
"li $27, 0x02000000\n" // Reverse Endianess
|
||||
"or $26, $27\n"
|
||||
"mtc0 $26, $12\n"
|
||||
);
|
||||
|
||||
__asm
|
||||
(
|
||||
"jr %[pEntry]\n" // jump entry
|
||||
:
|
||||
: [pEntry] "r" (pEntry)
|
||||
);
|
||||
|
||||
__asm
|
||||
(
|
||||
"rfe\n"
|
||||
);
|
||||
|
||||
__asm
|
||||
(
|
||||
".set reorder\n"
|
||||
);
|
||||
}
|
||||
|
||||
void PrintCPUinfo(void)
|
||||
{
|
||||
int result, rev_id;
|
||||
@@ -212,7 +262,7 @@ void PrintCPUinfo(void)
|
||||
|
||||
#define MAX_IMG_SIZE (1024*1024) // bytes
|
||||
#define SDRAM_BASE 0x40000000
|
||||
#define FLASHIO_OFFSET 0x00000000
|
||||
#define FLASH_USE_BLOCK 1
|
||||
#define FLASH_BASE 0x00000000
|
||||
|
||||
int main(int argc, char *argv[])
|
||||
@@ -224,7 +274,7 @@ int main(int argc, char *argv[])
|
||||
flash_t flash;
|
||||
flash_img_hdr_t img_hdr = {0};
|
||||
flash_img_hdr_t *pImg_hdr;
|
||||
UINT32 img_size;
|
||||
UINT32 img_size, block_sel;
|
||||
|
||||
volatile UINT32 *pReg = (UINT32*)sys_led_port;
|
||||
volatile UINT32 *pBtn = (UINT32*)sys_gpio0;
|
||||
@@ -238,20 +288,38 @@ int main(int argc, char *argv[])
|
||||
volatile UINT8 *ram8 = (UINT8*)SDRAM_BASE;
|
||||
volatile UINT16 *ram16 = (UINT16*)SDRAM_BASE;
|
||||
volatile UINT32 *ram32 = (UINT32*)SDRAM_BASE;
|
||||
UINT32 flashio_offset;
|
||||
|
||||
*pReg = 0;
|
||||
haddr = 0;
|
||||
block_sel = 0x7F & (UINT32)*pDip;
|
||||
|
||||
// ----------------------------------------------------------
|
||||
if (flash_find(&flash, sys_flash_io))
|
||||
{
|
||||
sputs("Cannot find flash device. Exit now!\n\n");
|
||||
return 1;
|
||||
}
|
||||
|
||||
flashio_offset = flash_aligned_addr_by_blocknum(&flash, block_sel);
|
||||
|
||||
ram32 = (UINT32*)(SDRAM_BASE);
|
||||
pFlashIO = (UINT32*)(sys_flash_io + FLASHIO_OFFSET);
|
||||
pFlashIO = (UINT32*)(sys_flash_io + flashio_offset);
|
||||
|
||||
if (!*pBtn)
|
||||
{
|
||||
sputs("\n\n");
|
||||
sputs("Booting application from flash...");
|
||||
|
||||
pImg_hdr = (flash_img_hdr_t*)pFlashIO;
|
||||
if ((pImg_hdr->magic != MAGIC_EL) && (pImg_hdr->magic != MAGIC_EB))
|
||||
{
|
||||
sputs("\n\n");
|
||||
sputs("Invalid image found at ");print_word(flashio_offset); sputs(". Abort.\n");
|
||||
return 1;
|
||||
}
|
||||
|
||||
sputs("Booting application from flash (");print_word(flashio_offset);sputs(")...");
|
||||
|
||||
|
||||
ram32 = (UINT32*)pImg_hdr->target_base;
|
||||
pFlashIO = (UINT32*)(sys_flash_io + pImg_hdr->img_base);
|
||||
img_size = pImg_hdr->img_size;
|
||||
@@ -268,21 +336,8 @@ int main(int argc, char *argv[])
|
||||
|
||||
sputs("\n\n");
|
||||
|
||||
if (*pDip)
|
||||
{
|
||||
sputs("Booting stage 2 from flash.\n");
|
||||
Jump_to((void*)FLASH_BASE);
|
||||
|
||||
}
|
||||
|
||||
sputs("Reading HEX-Record from UART..");
|
||||
|
||||
if (flash_find(&flash, sys_flash_io) < 0)
|
||||
{
|
||||
sputs("Cannot find flash device. Exit now!\n\n");
|
||||
return 1;
|
||||
}
|
||||
|
||||
// Erase SDRAM
|
||||
for (i=0; i < MAX_IMG_SIZE/4; i++)
|
||||
ram32[i] = 0;
|
||||
@@ -310,19 +365,17 @@ int main(int argc, char *argv[])
|
||||
|
||||
case srec_eob:
|
||||
sputs("done\n\n");
|
||||
|
||||
img_hdr.magic[0] = 'J';
|
||||
img_hdr.magic[1] = 'F';
|
||||
img_hdr.magic[2] = 'I';
|
||||
img_hdr.magic[3] = '1';
|
||||
img_hdr.magic = MAGIC_EB;
|
||||
img_hdr.target_base = srec.addr;
|
||||
img_hdr.img_size = haddr - srec.addr;
|
||||
img_hdr.img_base = FLASHIO_OFFSET + sizeof(flash_img_hdr_t);
|
||||
img_hdr.hdr_next = flash_get_nextblock(&flash, img_hdr.img_base + img_hdr.img_size);
|
||||
sputs("Next free flash offset: ");print_word(img_hdr.hdr_next); sputs("\n");
|
||||
img_hdr.img_base = flashio_offset + sizeof(flash_img_hdr_t);
|
||||
img_hdr.hdr_next = flash_aligned_addr_by_offset(&flash, img_hdr.img_base + img_hdr.img_size);
|
||||
sputs("Size of application : ");print_word(img_hdr.img_size); sputs("\n");
|
||||
sputs("Programming flash at : ");print_word(flashio_offset); sputs("\n");
|
||||
sputs("Next free flash offset : ");print_word(img_hdr.hdr_next); sputs("\n");
|
||||
|
||||
sputs("Flash erase...");
|
||||
result = flash_erase(&flash, FLASHIO_OFFSET, img_hdr.img_size + sizeof(flash_img_hdr_t));
|
||||
result = flash_erase(&flash, flashio_offset, img_hdr.img_size + sizeof(flash_img_hdr_t));
|
||||
if (result < 0)
|
||||
{
|
||||
sputs("failed!\n");
|
||||
@@ -331,7 +384,7 @@ int main(int argc, char *argv[])
|
||||
sputs("done\n");
|
||||
|
||||
sputs("Flash write...");
|
||||
result = flash_program(&flash, FLASHIO_OFFSET, (UINT8*)&img_hdr, sizeof(flash_img_hdr_t));
|
||||
result = flash_program(&flash, flashio_offset, (UINT8*)&img_hdr, sizeof(flash_img_hdr_t));
|
||||
if (result < 0)
|
||||
{
|
||||
sputs("failed!\n");
|
||||
|
||||
Reference in New Issue
Block a user