Line 10... |
Line 10... |
#endif
|
#endif
|
|
|
extern unsigned long fprog_addr;
|
extern unsigned long fprog_addr;
|
extern char *tftp_filename;
|
extern char *tftp_filename;
|
|
|
static flash_cfg_struct __attribute__ ((section(".config"))) gcfg = { 0, 0, 0, 0 };
|
static flash_cfg_struct gcfg =
|
|
{ BOARD_DEF_IP, BOARD_DEF_MASK, BOARD_DEF_GW, BOARD_DEF_TBOOT_SRVR };
|
|
|
#define FLASH_IMAGES_BASE 0xf0300000
|
// Not booting from flash, so just set these from board.h -- jb
|
|
//static flash_cfg_struct __attribute__ ((section(".config"))) gcfg = { BOARD_DEF_IP, BOARD_DEF_MASK, BOARD_DEF_GW, BOARD_DEF_TBOOT_SRVR };
|
/* Buffer Address == for example internal RAM */
|
//static flash_cfg_struct __attribute__ ((section(".config"))) gcfg = { 0, 0, 0, 0 };
|
#define BUF_BASE_ADDR 0x00400000 - 0x00042000
|
|
#define BUF_LENGTH 4096
|
|
|
|
|
#define FLASH_IMAGES_BASE 0xf0300000
|
|
|
#define ALIGN(addr,size) ((addr + (size-1))&(~(size-1)))
|
#define ALIGN(addr,size) ((addr + (size-1))&(~(size-1)))
|
|
// If the image buffer is word aligned, then uncomment this, but it was set up
|
|
// so that the tftp images would download quicker
|
|
#define COPY_AND_BOOT_WORD_ALIGNED
|
|
#ifdef COPY_AND_BOOT_WORD_ALIGNED
|
void copy_and_boot(unsigned long src,
|
void copy_and_boot(unsigned long src,
|
unsigned long dst,
|
unsigned long dst,
|
unsigned long len,
|
unsigned long len,
|
int tx_next)
|
int tx_next)
|
{
|
{
|
Line 48... |
Line 51... |
1: l.sw 0x0(r0),r6 ;\
|
1: l.sw 0x0(r0),r6 ;\
|
l.ori r8,r0,0x100 ;\
|
l.ori r8,r0,0x100 ;\
|
l.jr r8 ;\
|
l.jr r8 ;\
|
l.nop");
|
l.nop");
|
}
|
}
|
|
#else
|
/* WARNING: stack and non-const globals should not be used in this function -- it may corrupt what have we loaded;
|
void copy_and_boot(unsigned long src,
|
|
unsigned long dst,
|
|
unsigned long len,
|
|
int tx_next)
|
|
{
|
|
__asm__ __volatile__(" ;\
|
|
l.addi r8,r0,0x1 ;\
|
|
l.mtspr r0,r8,0x11 ;\
|
|
l.nop ;\
|
|
l.nop ;\
|
|
l.nop ;\
|
|
l.nop ;\
|
|
l.nop ;\
|
|
2: ;\
|
|
l.sfgeu r4,r5 ;\
|
|
l.bf 1f ;\
|
|
l.nop ;\
|
|
l.lbz r8,0(r3) ;\
|
|
l.sb 0(r4),r8 ;\
|
|
l.addi r3,r3,1 ;\
|
|
l.j 2b ;\
|
|
l.addi r4,r4,1 ;\
|
|
1: l.sw 0x0(r0),r6 ;\
|
|
l.ori r8,r0,0x100 ;\
|
|
l.jr r8 ;\
|
|
l.nop");
|
|
}
|
|
#endif
|
|
/* WARNING: stack and non-const globals should not be used in this function
|
|
-- it may corrupt what have we loaded;
|
start_addr should be 0xffffffff if only copying should be made
|
start_addr should be 0xffffffff if only copying should be made
|
no return, when start_addr != 0xffffffff, if successful */
|
no return, when start_addr != 0xffffffff, if successful */
|
int copy_memory_run (register unsigned long src_addr, register unsigned long dst_addr, register unsigned long length, register int erase, register unsigned long start_addr)
|
int copy_memory_run (register unsigned long src_addr,
|
|
register unsigned long dst_addr,
|
|
register unsigned long length,
|
|
register int erase,
|
|
register unsigned long start_addr)
|
{
|
{
|
unsigned long i, flags;
|
unsigned long i, flags;
|
|
|
register char *dst = (char *) dst_addr;
|
register char *dst = (char *) dst_addr;
|
register const char *src = (const char *) src_addr;
|
register const char *src = (const char *) src_addr;
|
Line 95... |
Line 131... |
}
|
}
|
}
|
}
|
printf("Verifying flash... ");
|
printf("Verifying flash... ");
|
for(i = 0; i < length; i += INC_ADDR) {
|
for(i = 0; i < length; i += INC_ADDR) {
|
if( reg_read(dst_addr+i) != reg_read(src_addr + i)) {
|
if( reg_read(dst_addr+i) != reg_read(src_addr + i)) {
|
printf ("error at %08lx: %08lx != %08lx\n", src_addr + i, reg_read(src_addr + i), reg_read(dst_addr + i));
|
printf ("error at %08lx: %08lx != %08lx\n", src_addr + i,
|
|
reg_read(src_addr + i), reg_read(dst_addr + i));
|
return 1;
|
return 1;
|
}
|
}
|
}
|
}
|
printf("OK!\n");
|
printf("OK!\n");
|
mtspr(SPR_SR, flags);
|
mtspr(SPR_SR, flags);
|
Line 142... |
Line 179... |
}
|
}
|
|
|
void
|
void
|
init_load (void)
|
init_load (void)
|
{
|
{
|
|
#if 0 // JB - removing flash stuff
|
#ifdef CFG_IN_FLASH
|
#ifdef CFG_IN_FLASH
|
copy_memory_run((unsigned long)&fl_word_program, (unsigned long)&fprog_addr,
|
copy_memory_run((unsigned long)&fl_word_program, (unsigned long)&fprog_addr,
|
95, 0, 0xffffffff);
|
95, 0, 0xffffffff);
|
copy_memory_run((unsigned long)&fl_block_erase, (unsigned long)&fprog_addr+96,
|
copy_memory_run((unsigned long)&fl_block_erase, (unsigned long)&fprog_addr+96,
|
119, 0, 0xffffffff);
|
119, 0, 0xffffffff);
|
Line 169... |
Line 207... |
#else /* not CFG_IN_FLASH */
|
#else /* not CFG_IN_FLASH */
|
fl_ext_program = (t_fl_ext_program)&fl_word_program;
|
fl_ext_program = (t_fl_ext_program)&fl_word_program;
|
fl_ext_erase = (t_fl_erase)&fl_block_erase;
|
fl_ext_erase = (t_fl_erase)&fl_block_erase;
|
fl_ext_unlock = (t_fl_erase)&fl_unlock_one_block;
|
fl_ext_unlock = (t_fl_erase)&fl_unlock_one_block;
|
#endif /* CFG_IN_FLASH */
|
#endif /* CFG_IN_FLASH */
|
|
#endif
|
|
|
|
/*
|
|
global.ip = gcfg.eth_ip;
|
|
global.gw_ip = gcfg.eth_gw;
|
|
global.mask = gcfg.eth_mask;
|
|
global.srv_ip = gcfg.tftp_srv_ip;
|
|
global.src_addr = 0x100000;
|
|
tftp_filename = "boot.img";
|
|
*/
|
|
|
|
global.ip = BOARD_DEF_IP;
|
|
global.gw_ip = BOARD_DEF_GW;
|
|
global.mask = BOARD_DEF_MASK;
|
|
global.srv_ip = BOARD_DEF_TBOOT_SRVR;
|
|
global.src_addr = BOARD_DEF_LOAD_SPACE;
|
|
tftp_filename = BOARD_DEF_IMAGE_NAME;
|
|
|
global.ip = gcfg.eth_ip;
|
|
global.gw_ip = gcfg.eth_gw;
|
|
global.mask = gcfg.eth_mask;
|
|
global.srv_ip = gcfg.tftp_srv_ip;
|
|
tftp_filename = "boot.img";
|
|
/*memcpy(tftp_filename, gcfg.tftp_filename, strlen(gcfg.tftp_filename));
|
/*memcpy(tftp_filename, gcfg.tftp_filename, strlen(gcfg.tftp_filename));
|
tftp_filename[strlen(gcfg.tftp_filename)] = '\0';*/
|
tftp_filename[strlen(gcfg.tftp_filename)] = '\0';*/
|
}
|
}
|
|
|
int tftp_cmd (int argc, char *argv[])
|
int tftp_cmd (int argc, char *argv[])
|
Line 274... |
Line 324... |
{
|
{
|
switch (argc) {
|
switch (argc) {
|
case 3: global.src_addr = strtoul (argv[2], 0, 0);
|
case 3: global.src_addr = strtoul (argv[2], 0, 0);
|
case 2: global.length = strtoul (argv[2], 0, 0);
|
case 2: global.length = strtoul (argv[2], 0, 0);
|
case 1: global.src_addr = strtoul (argv[2], 0, 0);
|
case 1: global.src_addr = strtoul (argv[2], 0, 0);
|
case 0: return copy_memory_run (global.src_addr, global.dst_addr, global.length,
|
case 0: return copy_memory_run (global.src_addr, global.dst_addr,
|
global.erase_method, 0xffffffff);
|
global.length, global.erase_method,
|
|
0xffffffff);
|
}
|
}
|
return -1;
|
return -1;
|
}
|
}
|
|
|
void
|
void
|
Line 359... |
Line 410... |
/* here we calcuta first position (starting with FLASH_IMAGES_BASE)... */
|
/* here we calcuta first position (starting with FLASH_IMAGES_BASE)... */
|
st_addr[0] = FLASH_IMAGES_BASE + 0;
|
st_addr[0] = FLASH_IMAGES_BASE + 0;
|
free[0] = start_addr[0] - FLASH_IMAGES_BASE;
|
free[0] = start_addr[0] - FLASH_IMAGES_BASE;
|
/* ... and last one (ending with FLASH_IMAGES_BASE + FLASH_SIZE). */
|
/* ... and last one (ending with FLASH_IMAGES_BASE + FLASH_SIZE). */
|
st_addr[myCfg.img_number] = end_addr[myCfg.img_number-1];
|
st_addr[myCfg.img_number] = end_addr[myCfg.img_number-1];
|
free[myCfg.img_number] = (FLASH_IMAGES_BASE + FLASH_SIZE) - end_addr[myCfg.img_number-1];
|
free[myCfg.img_number] = (FLASH_IMAGES_BASE + FLASH_SIZE) -
|
|
end_addr[myCfg.img_number-1];
|
/* for(i = 0; i < myCfg.img_number+1; i++)
|
|
printf("start: 0x%08x, free: %x\n", st_addr[i], free[i]);
|
|
printf("\n");*/
|
|
|
|
/* yet another bubble sort by free (space) */
|
/* yet another bubble sort by free (space) */
|
for(j = myCfg.img_number; j > 0; j--)
|
for(j = myCfg.img_number; j > 0; j--)
|
for(i = 0; i < j; i++)
|
for(i = 0; i < j; i++)
|
if(free[i] > free[i+1]) {
|
if(free[i] > free[i+1]) {
|
Line 377... |
Line 425... |
tmpval = st_addr[i];
|
tmpval = st_addr[i];
|
st_addr[i] = st_addr[i+1];
|
st_addr[i] = st_addr[i+1];
|
st_addr[i+1] = tmpval;
|
st_addr[i+1] = tmpval;
|
}
|
}
|
|
|
/* for(i = 0; i < myCfg.img_number+1; i++)
|
|
printf("start: 0x%08x, free: %x\n", st_addr[i], free[i]);
|
|
printf("\n");*/
|
|
|
|
/* now we pick the smallest but just big enough for our size */
|
/* now we pick the smallest but just big enough for our size */
|
for(i = 0; i <= myCfg.img_number; i++)
|
for(i = 0; i <= myCfg.img_number; i++)
|
if(free[i] >= size)
|
if(free[i] >= size)
|
return st_addr[i];
|
return st_addr[i];
|
|
|
Line 483... |
Line 527... |
return 0;
|
return 0;
|
}
|
}
|
|
|
num = strtoul(argv[0],0,0);
|
num = strtoul(argv[0],0,0);
|
if(gcfg.img_number < num) {
|
if(gcfg.img_number < num) {
|
printf("There are only %lu images, you requested %d!\n", gcfg.img_number, num);
|
printf("There are only %lu images, you requested %d!\n",
|
|
gcfg.img_number, num);
|
return -1;
|
return -1;
|
}
|
}
|
|
|
printf("Copying image number %d from 0x%lx, size: 0x%lx...",
|
printf("Copying image number %d from 0x%lx, size: 0x%lx...",
|
num, gcfg.img_start_addr[num-1], gcfg.img_length[num-1]);
|
num, gcfg.img_start_addr[num-1], gcfg.img_length[num-1]);
|
|
|
printf("booting...\n");
|
printf("booting...\n");
|
copy_and_boot(gcfg.img_start_addr[num-1], 0x0, gcfg.img_length[num-1], tx_next);
|
copy_and_boot(gcfg.img_start_addr[num-1], 0x0, gcfg.img_length[num-1],
|
|
tx_next);
|
return 0;
|
return 0;
|
}
|
}
|
|
|
int mGetData(unsigned long);
|
int mGetData(unsigned long);
|
|
|
|
#if 0 // Disable sboot - JB
|
int sboot_cmd (int argc, char *argv[])
|
int sboot_cmd (int argc, char *argv[])
|
{
|
{
|
int copied;
|
int copied;
|
unsigned int num = 0xffffffff, addr = 0x0;
|
unsigned int num = 0xffffffff, addr = 0x0;
|
|
|
Line 531... |
Line 578... |
}
|
}
|
}
|
}
|
|
|
return 0;
|
return 0;
|
}
|
}
|
|
#endif
|
|
|
|
void relocate_code(void* destination, void* function, int length_words)
|
|
{
|
|
// Just copy the function word at a time from one place to another
|
|
int i;
|
|
unsigned long * p1 = (unsigned long*) destination;
|
|
unsigned long * p2 = (unsigned long*) function;
|
|
for(i=0;i<length_words;i++)
|
|
p1[i] = p2[i];
|
|
}
|
|
|
int tboot_cmd (int argc, char *argv[])
|
int tboot_cmd (int argc, char *argv[])
|
{
|
{
|
int copied;
|
int copied;
|
unsigned int num = 0xffffffff, addr = 0x0;
|
unsigned int num = 0xffffffff, addr = 0x0;
|
extern int tx_next;
|
extern int tx_next;
|
|
// NetTxPacket wasn't getting cleared before we used it...
|
|
NetTxPacket = 0;
|
|
NetBootFileSize = 0;
|
|
|
switch (argc) {
|
switch (argc) {
|
case 0:
|
case 0:
|
num = 0xffffffff;
|
num = 0xffffffff;
|
break;
|
break;
|
Line 553... |
Line 614... |
|
|
// global.src_addr = (unsigned long)0x0;
|
// global.src_addr = (unsigned long)0x0;
|
|
|
copied =NetLoop(TFTP);
|
copied =NetLoop(TFTP);
|
if (copied <= 0) {
|
if (copied <= 0) {
|
printf("tboot: error while getting the image '%s'",
|
printf("tboot: error while getting the image '%s'", tftp_filename);
|
tftp_filename);
|
|
return -1;
|
return -1;
|
}
|
}
|
|
|
if(num != 0xffffffff) {
|
if (global.src_addr > 0)
|
addr = prepare_img_data(num, copied);
|
{
|
if(addr == 0xffffffff)
|
|
printf("Image not written to flash!\n");
|
|
else {
|
|
printf("Copying image to flash, image number: %d, dst_addr: 0x%x\n",
|
|
num, addr);
|
|
copy_memory_run(global.src_addr, gcfg.img_start_addr[num-1], copied, 2, 0xffffffff);
|
|
}
|
|
}
|
|
/* the point of no return */
|
/* the point of no return */
|
printf("tboot: copying 0x%lx -> 0x0, image size 0x%x...\n",
|
printf("tboot: copying 0x%lx -> 0x0, image size 0x%x...\n",
|
global.src_addr, copied);
|
global.src_addr, copied);
|
|
}
|
|
|
|
// Disable timer: clear it all!
|
|
mtspr (SPR_SR, mfspr(SPR_SR) & ~SPR_SR_TEE);
|
|
mtspr(SPR_TTMR, 0);
|
|
|
|
// Put the copyboot program at 24MB mark in memory
|
|
#define COPYBOOT_LOCATION (1024*1024*24)
|
|
printf("tboot: relocating copy loop to 0x%x ...\n", (unsigned long)COPYBOOT_LOCATION);
|
|
// Setup where we'll copy the relocation function to
|
|
void (*relocated_function)(unsigned long, unsigned long, unsigned long, int)
|
|
= (void*) COPYBOOT_LOCATION;
|
|
// Now copy the function there, 32 words worth, increase this if needed...
|
|
relocate_code((void*)COPYBOOT_LOCATION, copy_and_boot, 32);
|
|
// Indicate we'll jump there...
|
|
printf("tboot: Relocate (%d bytes from 0x%x to 0) and boot image, ...\n", copied, (unsigned long) global.src_addr);
|
|
// Now do the copy and boot
|
|
(*relocated_function)(global.src_addr, 0x0, 0x0 + copied, tx_next);
|
|
|
printf("tboot: jumping to 0x100, booting image ...\n");
|
|
copy_and_boot(global.src_addr, 0x0, 0x0 + copied, tx_next);
|
|
return 0;
|
return 0;
|
}
|
}
|
|
|
|
|
|
|
|
|
void module_load_init (void)
|
void module_load_init (void)
|
{
|
{
|
register_command ("tftp", "[<file> [<srv_ip> [<src_addr>]]]", "TFTP download", tftp_cmd);
|
|
register_command ("tftp_conf", "[ <file> [ <srv_ip> [ <src_addr>]]]", "TFTP configuration", tftp_conf_cmd);
|
register_command ("tftp_conf", "[ <file> [ <srv_ip> [ <src_addr>]]]", "TFTP configuration", tftp_conf_cmd);
|
register_command ("copy", "[<dst_addr> [<src_addr [<length>]]]", "Copy memory", copy_cmd);
|
|
register_command ("tboot", "[<image number>]", "Bootstrap image downloaded via tftp", tboot_cmd);
|
register_command ("tboot", "[<image number>]", "Bootstrap image downloaded via tftp", tboot_cmd);
|
|
#if 0
|
|
register_command ("tftp", "[<file> [<srv_ip> [<src_addr>]]]", "TFTP download", tftp_cmd);
|
|
register_command ("copy", "[<dst_addr> [<src_addr [<length>]]]", "Copy memory", copy_cmd);
|
register_command ("sboot", "[<image number>]", "Bootstrap image downloaded via serial (Y/X modem)", sboot_cmd);
|
register_command ("sboot", "[<image number>]", "Bootstrap image downloaded via serial (Y/X modem)", sboot_cmd);
|
register_command ("boot", "[<image number>]", "Bootstrap image copied from flash.", boot_cmd);
|
register_command ("boot", "[<image number>]", "Bootstrap image copied from flash.", boot_cmd);
|
register_command ("del_image", "[<image number>]", "Delete image", del_image_cmd);
|
register_command ("del_image", "[<image number>]", "Delete image", del_image_cmd);
|
register_command ("save_conf", "", "Save current configuration into flash", save_conf_cmd);
|
register_command ("save_conf", "", "Save current configuration into flash", save_conf_cmd);
|
register_command ("boot_flash", "[<start_addr>]", "Boot image from <start_addr> (default from flash)", boot_flash_cmd);
|
register_command ("boot_flash", "[<start_addr>]", "Boot image from <start_addr> (default from flash)", boot_flash_cmd);
|
|
#endif
|
init_load();
|
init_load();
|
}
|
}
|
|
|
No newline at end of file
|
No newline at end of file
|