OpenCores
URL https://opencores.org/ocsvn/openrisc/openrisc/trunk

Subversion Repositories openrisc

[/] [openrisc/] [trunk/] [bootloaders/] [orpmon/] [cmds/] [load.c] - Diff between revs 406 and 464

Show entire file | Details | Blame | View Log

Rev 406 Rev 464
Line 1... Line 1...
#include "common.h"
#include "common.h"
#include "support.h"
#include "support.h"
#include "flash.h"
#include "flash.h"
#include "net.h"
#include "net.h"
 
#include "eth.h"
#include "uart.h"
#include "uart.h"
#include "dosfs.h"
#include "dosfs.h"
#include "spr-defs.h"
#include "spr-defs.h"
 
 
#ifndef MAX_IMAGES
#ifndef MAX_IMAGES
#define MAX_IMAGES 20
#define MAX_IMAGES 20
#endif
#endif
 
 
 
// Put the copyboot program at just before end of memory
 
#define COPYBOOT_LOCATION (SDRAM_SIZE - (32*4))
 
 
 
 
extern unsigned long fprog_addr;
extern unsigned long fprog_addr;
extern char *tftp_filename;
extern char *tftp_filename;
 
 
static flash_cfg_struct gcfg =
static flash_cfg_struct gcfg =
    { BOARD_DEF_IP, BOARD_DEF_MASK, BOARD_DEF_GW, BOARD_DEF_TBOOT_SRVR };
    { BOARD_DEF_IP, BOARD_DEF_MASK, BOARD_DEF_GW, BOARD_DEF_TBOOT_SRVR };
Line 86... Line 91...
int copy_memory_run(register unsigned long src_addr,
int copy_memory_run(register unsigned long src_addr,
                    register unsigned long dst_addr,
                    register unsigned long dst_addr,
                    register unsigned long length,
                    register unsigned long length,
                    register int erase, register unsigned long start_addr)
                    register int erase, register unsigned long start_addr)
{
{
 
#ifdef FLASH_BASE_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 150... Line 156...
                        return 0;
                        return 0;
        }
        }
        /* Run the program */
        /* Run the program */
        ((void (*)(void))start_addr) ();
        ((void (*)(void))start_addr) ();
        return 0;                /* just to satisfy the cc */
        return 0;                /* just to satisfy the cc */
 
#else
 
        return -1;
 
#endif
}
}
 
 
void bf_jump(unsigned long addr)
void bf_jump(unsigned long addr)
{
{
        asm("l.jr   r3");
        asm("l.jr   r3");
        asm("l.nop  0x0");
        asm("l.nop  0x0");
}
}
 
 
int boot_flash_cmd(int argc, char *argv[])
int boot_flash_cmd(int argc, char *argv[])
{
{
 
#ifdef FLASH_BASE_ADDR
        unsigned long addr, val, jaddr;
        unsigned long addr, val, jaddr;
        addr = 17;
        addr = 17;
        val = 0;
        val = 0;
        /* clear SR */
        /* clear SR */
 
 
Line 173... Line 183...
                bf_jump(FLASH_BASE_ADDR + 0x100);
                bf_jump(FLASH_BASE_ADDR + 0x100);
        else {
        else {
                jaddr = strtoul(argv[0], 0, 0);
                jaddr = strtoul(argv[0], 0, 0);
                bf_jump(jaddr);
                bf_jump(jaddr);
        }
        }
 
#endif
        return 0;
        return 0;
}
}
 
 
void init_load(void)
void init_load(void)
{
{
#if 0                           // JB - removing flash stuff
 
#  ifdef CFG_IN_FLASH
 
        copy_memory_run((unsigned long)&fl_word_program,
 
                        (unsigned long)&fprog_addr, 95, 0, 0xffffffff);
 
        copy_memory_run((unsigned long)&fl_block_erase,
 
                        (unsigned long)&fprog_addr + 96, 119, 0, 0xffffffff);
 
        copy_memory_run((unsigned long)&fl_unlock_one_block,
 
                        (unsigned long)&fprog_addr + 96 + 120, 115, 0,
 
                        0xffffffff);
 
 
 
        fl_ext_program = (t_fl_ext_program) & fprog_addr;
 
        fl_ext_erase = (t_fl_erase) & fprog_addr + 96;
 
        fl_ext_unlock = (t_fl_erase) & fprog_addr + 96 + 120;
 
 
 
#    if 0
 
        printf("fl_word_program(): 0x%x\tfl_ext_program(): 0x%x\n",
 
               &fl_word_program, fl_ext_program);
 
        printf("fl_block_erase: 0x%x\tfl_ext_erase(): 0x%x\n",
 
               &fl_block_erase, fl_ext_erase);
 
        printf("fl_unlock_one_block(): 0x%x\tfl_ext_unlock(): 0x%x\n",
 
               &fl_unlock_one_block, fl_ext_unlock);
 
#    endif
 
 
 
#  else /* not CFG_IN_FLASH */
 
        fl_ext_program = (t_fl_ext_program) & fl_word_program;
 
        fl_ext_erase = (t_fl_erase) & fl_block_erase;
 
        fl_ext_unlock = (t_fl_erase) & fl_unlock_one_block;
 
#  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.ip = BOARD_DEF_IP;
        global.gw_ip = BOARD_DEF_GW;
        global.gw_ip = BOARD_DEF_GW;
        global.mask = BOARD_DEF_MASK;
        global.mask = BOARD_DEF_MASK;
        global.srv_ip = BOARD_DEF_TBOOT_SRVR;
        global.srv_ip = BOARD_DEF_TBOOT_SRVR;
        global.src_addr = BOARD_DEF_LOAD_SPACE;
        global.src_addr = ((ETH_BUF_SPACE + ETH_DATA_BASE) + 8) & ~0x3;
        tftp_filename = BOARD_DEF_IMAGE_NAME;
        tftp_filename = BOARD_DEF_IMAGE_NAME;
 
 
        /*memcpy(tftp_filename, gcfg.tftp_filename, strlen(gcfg.tftp_filename));
 
           tftp_filename[strlen(gcfg.tftp_filename)] = '\0'; */
 
}
}
 
 
int tftp_cmd(int argc, char *argv[])
int tftp_cmd(int argc, char *argv[])
{
{
        switch (argc) {
        switch (argc) {
Line 275... Line 245...
        return 0;
        return 0;
}
}
 
 
void save_global_cfg(flash_cfg_struct cfg)
void save_global_cfg(flash_cfg_struct cfg)
{
{
 
#ifdef FLASH_BASE_ADDR
        unsigned long dst = (unsigned long)&gcfg, src = (unsigned long)&cfg;
        unsigned long dst = (unsigned long)&gcfg, src = (unsigned long)&cfg;
        unsigned long i, end, flags;
        unsigned long i, end, flags;
 
 
        end = (unsigned long)&cfg + sizeof(flash_cfg_struct);
        end = (unsigned long)&cfg + sizeof(flash_cfg_struct);
 
 
Line 306... Line 277...
        }
        }
        printf("done\n");
        printf("done\n");
 
 
        /* and than enable it back */
        /* and than enable it back */
        mtspr(SPR_SR, flags);
        mtspr(SPR_SR, flags);
 
#endif
        return;
        return;
}
}
 
 
int save_conf_cmd(int argc, char *argv[])
int save_conf_cmd(int argc, char *argv[])
{
{
Line 360... Line 332...
 * a hole between images, that is big enough (but as small as possible).
 * a hole between images, that is big enough (but as small as possible).
 *
 *
 */
 */
unsigned long get_good_addr(unsigned int size)
unsigned long get_good_addr(unsigned int size)
{
{
 
#ifdef FLASH_BASE_ADDR
        unsigned long start_addr[MAX_IMAGES], end_addr[MAX_IMAGES];
        unsigned long start_addr[MAX_IMAGES], end_addr[MAX_IMAGES];
        unsigned long free[MAX_IMAGES], st_addr[MAX_IMAGES];
        unsigned long free[MAX_IMAGES], st_addr[MAX_IMAGES];
        unsigned long tmpval;
        unsigned long tmpval;
        unsigned int i = 0, j;
        unsigned int i = 0, j;
 
 
Line 442... Line 415...
                if (free[i] >= size)
                if (free[i] >= size)
                        return st_addr[i];
                        return st_addr[i];
 
 
        /* there is not enough space (in one segment) left */
        /* there is not enough space (in one segment) left */
        return 0;
        return 0;
 
#else
 
        return -1;
 
#endif
}
}
 
 
unsigned long prepare_img_data(unsigned int num, unsigned int size)
unsigned long prepare_img_data(unsigned int num, unsigned int size)
{
{
        int i;
        int i;
Line 645... Line 621...
        }
        }
        // Disable timer: clear it all!
        // Disable timer: clear it all!
        mtspr(SPR_SR, mfspr(SPR_SR) & ~SPR_SR_TEE);
        mtspr(SPR_SR, mfspr(SPR_SR) & ~SPR_SR_TEE);
        mtspr(SPR_TTMR, 0);
        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",
        printf("tboot: relocating copy loop to 0x%x ...\n",
               (unsigned long)COPYBOOT_LOCATION);
               (unsigned long)COPYBOOT_LOCATION);
        // Setup where we'll copy the relocation function to
        // Setup where we'll copy the relocation function to
        void (*relocated_function) (unsigned long, unsigned long, unsigned long,
        void (*relocated_function) (unsigned long, unsigned long, unsigned long,
                                    int)
                                    int)
Line 741... Line 715...
 
 
        // Disable timer: clear it all!
        // Disable timer: clear it all!
        mtspr(SPR_SR, mfspr(SPR_SR) & ~SPR_SR_TEE);
        mtspr(SPR_SR, mfspr(SPR_SR) & ~SPR_SR_TEE);
        mtspr(SPR_TTMR, 0);
        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",
        printf("tboot: relocating copy loop to 0x%x ...\n",
               (unsigned long)COPYBOOT_LOCATION);
               (unsigned long)COPYBOOT_LOCATION);
        // Setup where we'll copy the relocation function to
        // Setup where we'll copy the relocation function to
        void (*relocated_function) (unsigned long, unsigned long, unsigned long,
        void (*relocated_function) (unsigned long, unsigned long, unsigned long,
                                    int)
                                    int)

powered by: WebSVN 2.1.0

© copyright 1999-2024 OpenCores.org, equivalent to Oliscience, all rights reserved. OpenCores®, registered trademark.