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

Subversion Repositories openrisc_me

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

Go to most recent revision | Show entire file | Details | Blame | View Log

Rev 389 Rev 406
Line 26... Line 26...
// If the image buffer is word aligned, then uncomment this, but it was set up 
// If the image buffer is word aligned, then uncomment this, but it was set up 
// so that the tftp images would download quicker
// so that the tftp images would download quicker
#define COPY_AND_BOOT_WORD_ALIGNED
#define COPY_AND_BOOT_WORD_ALIGNED
#ifdef 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, int tx_next)
                   unsigned long len,
 
                   int tx_next)
 
{
{
  __asm__ __volatile__("   ;\
  __asm__ __volatile__("   ;\
        l.addi  r8,r0,0x1  ;\
        l.addi  r8,r0,0x1  ;\
        l.mtspr r0,r8,0x11  ;\
        l.mtspr r0,r8,0x11  ;\
        l.nop               ;\
        l.nop               ;\
Line 54... Line 52...
        l.jr    r8          ;\
        l.jr    r8          ;\
        l.nop");
        l.nop");
}
}
#else
#else
void copy_and_boot(unsigned long src,
void copy_and_boot(unsigned long src,
                   unsigned long dst,
                   unsigned long dst, unsigned long len, int tx_next)
                   unsigned long len,
 
                   int tx_next)
 
{
{
  __asm__ __volatile__("   ;\
  __asm__ __volatile__("   ;\
        l.addi  r8,r0,0x1  ;\
        l.addi  r8,r0,0x1  ;\
        l.mtspr r0,r8,0x11  ;\
        l.mtspr r0,r8,0x11  ;\
        l.nop               ;\
        l.nop               ;\
Line 88... Line 84...
   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,
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 int erase, register unsigned long start_addr)
                     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 102... Line 97...
    if (dst_addr + length >= FLASH_BASE_ADDR + FLASH_SIZE) {
    if (dst_addr + length >= FLASH_BASE_ADDR + FLASH_SIZE) {
      printf ("error: region does not fit into flash.\n");
      printf ("error: region does not fit into flash.\n");
       return 1;
       return 1;
    }
    }
#ifndef CFG_IN_FLASH
#ifndef CFG_IN_FLASH
    fl_program (src_addr, dst_addr, length, erase, 1 /* do verify */);
                fl_program(src_addr, dst_addr, length, erase,
 
                           1 /* do verify */ );
#else
#else
    /* we must disable interrupts! */
    /* we must disable interrupts! */
    flags=mfspr(SPR_SR);
    flags=mfspr(SPR_SR);
    mtspr(SPR_SR,flags & ~(SPR_SR_TEE | SPR_SR_IEE));
    mtspr(SPR_SR,flags & ~(SPR_SR_TEE | SPR_SR_IEE));
 
 
Line 124... Line 120...
    for (i = 0; i < length; i += INC_ADDR) {
    for (i = 0; i < length; i += INC_ADDR) {
      if(((i+INC_ADDR) % 1000) == 0)
      if(((i+INC_ADDR) % 1000) == 0)
        printf("#");
        printf("#");
      if((i % (65*1000)) == 0)
      if((i % (65*1000)) == 0)
        printf("\n\t");
        printf("\n\t");
      if (fl_ext_program (dst_addr + i, reg_read(src_addr + i))) {
                        if (fl_ext_program
        printf("error programing at 0x%08lx!\n", dst_addr+i);
                            (dst_addr + i, reg_read(src_addr + i))) {
 
                                printf("error programing at 0x%08lx!\n",
 
                                       dst_addr + i);
        return 1;
        return 1;
      }
      }
    }
    }
    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,
                                printf("error at %08lx: %08lx != %08lx\n",
                reg_read(src_addr + i), reg_read(dst_addr + i));
                                       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);
#endif
#endif
    if(start_addr == 0xffffffff)
    if(start_addr == 0xffffffff)
      return 0;
      return 0;
  }
        } else {
  else {
                while (length--)
    while (length--) *dst++ = *src++;
                        *dst++ = *src++;
    if (start_addr == 0xffffffff)
    if (start_addr == 0xffffffff)
      return 0;
      return 0;
  }
  }
  /* Run the program */
  /* Run the program */
  ((void (*)(void)) start_addr)();
  ((void (*)(void)) start_addr)();
Line 177... Line 176...
    bf_jump(jaddr);
    bf_jump(jaddr);
  }
  }
  return 0;
  return 0;
}
}
 
 
void
void init_load(void)
init_load (void)
 
{
{
#if 0 // JB - removing flash stuff
#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,
                  95, 0, 0xffffffff);
                        (unsigned long)&fprog_addr, 95, 0, 0xffffffff);
  copy_memory_run((unsigned long)&fl_block_erase, (unsigned long)&fprog_addr+96,
        copy_memory_run((unsigned long)&fl_block_erase,
                  119, 0, 0xffffffff);
                        (unsigned long)&fprog_addr + 96, 119, 0, 0xffffffff);
  copy_memory_run((unsigned long)&fl_unlock_one_block,
  copy_memory_run((unsigned long)&fl_unlock_one_block,
                  (unsigned long)&fprog_addr+96+120,
                        (unsigned long)&fprog_addr + 96 + 120, 115, 0,
                  115, 0, 0xffffffff);
                        0xffffffff);
 
 
  fl_ext_program = (t_fl_ext_program)&fprog_addr;
  fl_ext_program = (t_fl_ext_program)&fprog_addr;
  fl_ext_erase = (t_fl_erase)&fprog_addr+96;
  fl_ext_erase = (t_fl_erase)&fprog_addr+96;
  fl_ext_unlock = (t_fl_erase)&fprog_addr+96+120;
  fl_ext_unlock = (t_fl_erase)&fprog_addr+96+120;
 
 
Line 233... Line 231...
}
}
 
 
int tftp_cmd (int argc, char *argv[])
int tftp_cmd (int argc, char *argv[])
{
{
  switch (argc) {
  switch (argc) {
    case 0: tftp_filename = "boot.img";
        case 0:
 
                tftp_filename = "boot.img";
                  break;
                  break;
    case 3: global.src_addr = strtoul (argv[2], 0, 0);
        case 3:
    case 2: global.srv_ip = parse_ip (argv[1]);
                global.src_addr = strtoul(argv[2], 0, 0);
    case 1: tftp_filename = &argv[0][0];
        case 2:
 
                global.srv_ip = parse_ip(argv[1]);
 
        case 1:
 
                tftp_filename = &argv[0][0];
            break;
            break;
  }
  }
  NetLoop(TFTP);
 
 
        NetLoop(TFTP);          // TFTP is enumerated value in net.h
 
 
  return 0;
  return 0;
}
}
 
 
int tftp_conf_cmd(int argc, char *argv[])
int tftp_conf_cmd(int argc, char *argv[])
{
{
Line 276... Line 280...
  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);
 
 
  printf("Saving global cfg from 0x%lx (end: 0x%lx) to 0x%lx...", src, end, dst);
        printf("Saving global cfg from 0x%lx (end: 0x%lx) to 0x%lx...", src,
 
               end, dst);
 
 
  /* we must disable interrupts! */
  /* we must disable interrupts! */
  flags=mfspr(SPR_SR);
  flags=mfspr(SPR_SR);
  mtspr(SPR_SR,flags & ~(SPR_SR_TEE | SPR_SR_IEE));
  mtspr(SPR_SR,flags & ~(SPR_SR_TEE | SPR_SR_IEE));
  /*  printf("Unlocking... ");*/
  /*  printf("Unlocking... ");*/
Line 319... Line 324...
  /*  memcpy(newCfg.tftp_filename, tftp_filename, strlen(tftp_filename));*/
  /*  memcpy(newCfg.tftp_filename, tftp_filename, strlen(tftp_filename));*/
 
 
  save_global_cfg(newCfg);
  save_global_cfg(newCfg);
  return 0;
  return 0;
}
}
 
 
int copy_cmd (int argc, char *argv[])
int copy_cmd (int argc, char *argv[])
{
{
  switch (argc) {
  switch (argc) {
    case 3: global.src_addr = strtoul (argv[2], 0, 0);
        case 3:
    case 2: global.length = strtoul (argv[2], 0, 0);
                global.src_addr = strtoul(argv[2], 0, 0);
    case 1: global.src_addr = strtoul (argv[2], 0, 0);
        case 2:
    case 0: return copy_memory_run (global.src_addr, global.dst_addr,
                global.length = 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, global.erase_method,
                                    global.length, global.erase_method,
                                    0xffffffff);
                                    0xffffffff);
  }
  }
  return -1;
  return -1;
}
}
 
 
void
void images_info(void)
images_info(void)
 
{
{
  int i;
  int i;
  printf("Number of images: 0x%lx\n", gcfg.img_number);
  printf("Number of images: 0x%lx\n", gcfg.img_number);
  for(i = 0; i < gcfg.img_number; i++)
  for(i = 0; i < gcfg.img_number; i++)
    printf("%d. image size: 0x%lx (at 0x%08lx)\n", i+1,
    printf("%d. image size: 0x%lx (at 0x%08lx)\n", i+1,
Line 349... Line 358...
 *
 *
 * Here we try to find the most suitable place for our image. We search for
 * Here we try to find the most suitable place for our image. We search for
 * 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
unsigned long get_good_addr(unsigned int size)
get_good_addr(unsigned int size)
 
{
{
  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 376... Line 384...
    st_addr[i] = 0;
    st_addr[i] = 0;
  }
  }
 
 
  for(i = 0; i < myCfg.img_number; i++) {
  for(i = 0; i < myCfg.img_number; i++) {
    start_addr[i] = myCfg.img_start_addr[i];
    start_addr[i] = myCfg.img_start_addr[i];
    end_addr[i] = ALIGN((myCfg.img_start_addr[i] + myCfg.img_length[i]),
                end_addr[i] =
 
                    ALIGN((myCfg.img_start_addr[i] + myCfg.img_length[i]),
                        FLASH_BLOCK_SIZE);
                        FLASH_BLOCK_SIZE);
  }
  }
  /*  printf("\n");
  /*  printf("\n");
  for(i = 0; i < myCfg.img_number; i++)
  for(i = 0; i < myCfg.img_number; i++)
    printf("start: 0x%08x, end: 0x%08x\n", start_addr[i], end_addr[i]);
    printf("start: 0x%08x, end: 0x%08x\n", start_addr[i], end_addr[i]);
Line 435... Line 444...
 
 
  /* there is not enough space (in one segment) left */
  /* there is not enough space (in one segment) left */
  return 0;
  return 0;
}
}
 
 
unsigned long
unsigned long prepare_img_data(unsigned int num, unsigned int size)
prepare_img_data(unsigned int num, unsigned int size)
 
{
{
  int i;
  int i;
  unsigned long addr=0;
  unsigned long addr=0;
  flash_cfg_struct newCfg;
  flash_cfg_struct newCfg;
 
 
Line 456... Line 464...
  if((num > newCfg.img_number) || (num == 0))
  if((num > newCfg.img_number) || (num == 0))
    num = newCfg.img_number;
    num = newCfg.img_number;
 
 
  addr = get_good_addr(size);
  addr = get_good_addr(size);
  if(addr == 0x00) {
  if(addr == 0x00) {
    printf("Can not find suitable place in flash. (None of free segments are big enough)\n");
                printf
 
                    ("Can not find suitable place in flash. (None of free segments are big enough)\n");
    return 0xffffffff;
    return 0xffffffff;
  }
  }
 
 
  if(num < newCfg.img_number)
  if(num < newCfg.img_number)
    for(i=newCfg.img_number-1; i >= num; i--) {
    for(i=newCfg.img_number-1; i >= num; i--) {
Line 473... Line 482...
 
 
  save_global_cfg(newCfg);
  save_global_cfg(newCfg);
  return addr;
  return addr;
}
}
 
 
int
int del_image_cmd(int argc, char *argv[])
del_image_cmd(int argc, char *argv[])
 
{
{
  unsigned num, i;
  unsigned num, i;
  flash_cfg_struct newCfg = gcfg;
  flash_cfg_struct newCfg = gcfg;
 
 
  newCfg.img_number = gcfg.img_number;
  newCfg.img_number = gcfg.img_number;
Line 493... Line 501...
      newCfg.img_length[i] = 0;
      newCfg.img_length[i] = 0;
      newCfg.img_start_addr[i] = 0;
      newCfg.img_start_addr[i] = 0;
    }
    }
    save_global_cfg(newCfg);
    save_global_cfg(newCfg);
    return 0;
    return 0;
  }
        } else {
  else {
 
    num = strtoul(argv[0], 0, 0);
    num = strtoul(argv[0], 0, 0);
  }
  }
 
 
  if(newCfg.img_number == 0) {
  if(newCfg.img_number == 0) {
    printf("Nothing to delete!\n");
    printf("Nothing to delete!\n");
Line 515... Line 522...
  newCfg.img_number--;
  newCfg.img_number--;
  save_global_cfg(newCfg);
  save_global_cfg(newCfg);
  return 0;
  return 0;
}
}
 
 
int
int boot_cmd(int argc, char *argv[])
boot_cmd(int argc, char *argv[])
 
{
{
  int num;
  int num;
  extern int tx_next;
  extern int tx_next;
 
 
  if(argc == 0) {
  if(argc == 0) {
Line 537... Line 543...
 
 
  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],
        copy_and_boot(gcfg.img_start_addr[num - 1], 0x0,
                tx_next);
                      gcfg.img_length[num - 1], tx_next);
  return 0;
  return 0;
}
}
 
 
int mGetData(unsigned long);
int mGetData(unsigned long);
 
 
Line 571... Line 577...
  if(num != 0xffffffff) {
  if(num != 0xffffffff) {
    addr = prepare_img_data(num, copied);
    addr = prepare_img_data(num, copied);
    if(addr == 0xffffffff)
    if(addr == 0xffffffff)
      printf("Image not written to flash!\n");
      printf("Image not written to flash!\n");
    else {
    else {
      printf("Copying image to flash, image number: %d, dst_addr: 0x%x\n",
                        printf
 
                            ("Copying image to flash, image number: %d, dst_addr: 0x%x\n",
             num, addr);
             num, addr);
      copy_memory_run(global.src_addr, gcfg.img_start_addr[num-1], copied, 2, 0xffffffff);
                        copy_memory_run(global.src_addr,
 
                                        gcfg.img_start_addr[num - 1], copied, 2,
 
                                        0xffffffff);
    }
    }
  }
  }
 
 
  return 0;
  return 0;
}
}
Line 615... Line 624...
    printf("num %d\n", num);
    printf("num %d\n", num);
    break;
    break;
  }
  }
 
 
  // Disable data cache if present
  // Disable data cache if present
  if (mfspr(SPR_SR) & SPR_SR_DCE)
        if (mfspr(SPR_SR) & SPR_SR_DCE) {
    {
 
      printf("Disabling data cache\n");
      printf("Disabling data cache\n");
      dc_disable_cmd(0, 0);
      dc_disable_cmd(0, 0);
    }
    }
 
 
  // Kick off copy
  // Kick off copy
  copied =NetLoop(TFTP);
  copied =NetLoop(TFTP);
  if (copied <= 0) {
  if (copied <= 0) {
    printf("tboot: error while getting the image '%s'", tftp_filename);
                printf("tboot: error while getting the image '%s'",
 
                       tftp_filename);
    return -1;
    return -1;
  }
  }
 
 
  if (global.src_addr > 0)
        if (global.src_addr > 0) {
    {
 
      /* 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!
  // 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
  // Put the copyboot program at 24MB mark in memory
#define COPYBOOT_LOCATION (1024*1024*24) 
#define COPYBOOT_LOCATION (1024*1024*24) 
  printf("tboot: relocating copy loop to 0x%x ...\n", (unsigned long)COPYBOOT_LOCATION);
        printf("tboot: relocating copy loop to 0x%x ...\n",
 
               (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, int)
        void (*relocated_function) (unsigned long, unsigned long, unsigned long,
 
                                    int)
    = (void*) COPYBOOT_LOCATION;
    = (void*) COPYBOOT_LOCATION;
  // Now copy the function there, 32 words worth, increase this if needed...
  // Now copy the function there, 32 words worth, increase this if needed...
  relocate_code((void*)COPYBOOT_LOCATION, copy_and_boot, 32);
  relocate_code((void*)COPYBOOT_LOCATION, copy_and_boot, 32);
  // Indicate we'll jump there...
  // 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);
        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
  // Now do the copy and boot
  (*relocated_function)(global.src_addr, 0x0, 0x0 + copied, tx_next);
  (*relocated_function)(global.src_addr, 0x0, 0x0 + copied, tx_next);
 
 
  return 0;
  return 0;
}
}
Line 670... Line 680...
        DIRENT de;
        DIRENT de;
        unsigned long int cache;
        unsigned long int cache;
 
 
                // Obtain pointer to first partition on first (only) unit
                // Obtain pointer to first partition on first (only) unit
          // Disable data cache if present
          // Disable data cache if present
  if (mfspr(SPR_SR) & SPR_SR_DCE)
        if (mfspr(SPR_SR) & SPR_SR_DCE) {
    {
 
      printf("Disabling data cache\n");
      printf("Disabling data cache\n");
      dc_disable_cmd(0, 0);
      dc_disable_cmd(0, 0);
    }
    }
 
 
 
 
        buf_ptr=global.src_addr;
        buf_ptr=global.src_addr;
 
 
 
 
        printf("SD-BOOT start \n");
        printf("SD-BOOT start \n");
        i=init_fat(&vi);
        i=init_fat(&vi);
 
 
 
 
 
 
        printf("Volume label '%-11.11s'\n", vi.label);
        printf("Volume label '%-11.11s'\n", vi.label);
        printf("%d sector/s per cluster, %d reserved sector/s, volume total %d sectors.\n", vi.secperclus, vi.reservedsecs, vi.numsecs);
        printf
        printf("%d sectors per FAT, first FAT at sector #%d, root dir at #%d.\n",vi.secperfat,vi.fat1,vi.rootdir);
            ("%d sector/s per cluster, %d reserved sector/s, volume total %d sectors.\n",
        printf("(For FAT32, the root dir is a CLUSTER number, FAT12/16 it is a SECTOR number)\n");
             vi.secperclus, vi.reservedsecs, vi.numsecs);
        printf("%d root dir entries, data area commences at sector #%d.\n",vi.rootentries,vi.dataarea);
        printf
        printf("%d clusters (%d bytes) in data area, filesystem IDd as ", vi.numclusters, vi.numclusters * vi.secperclus * SECTOR_SIZE);
            ("%d sectors per FAT, first FAT at sector #%d, root dir at #%d.\n",
 
             vi.secperfat, vi.fat1, vi.rootdir);
 
        printf
 
            ("(For FAT32, the root dir is a CLUSTER number, FAT12/16 it is a SECTOR number)\n");
 
        printf("%d root dir entries, data area commences at sector #%d.\n",
 
               vi.rootentries, vi.dataarea);
 
        printf("%d clusters (%d bytes) in data area, filesystem IDd as ",
 
               vi.numclusters, vi.numclusters * vi.secperclus * SECTOR_SIZE);
        if (vi.filesystem == FAT12)
        if (vi.filesystem == FAT12)
                printf("FAT12.\n");
                printf("FAT12.\n");
        else if (vi.filesystem == FAT16)
        else if (vi.filesystem == FAT16)
                printf("FAT16.\n");
                printf("FAT16.\n");
        else if (vi.filesystem == FAT32)
        else if (vi.filesystem == FAT32)
                printf("FAT32.\n");
                printf("FAT32.\n");
        else
        else
                printf("[unknown]\n");
                printf("[unknown]\n");
 
 
 
 
 
 
        if (DFS_OpenDir(&vi, "", &di)) {
        if (DFS_OpenDir(&vi, "", &di)) {
                        printf("Error opening root directory\n");
                        printf("Error opening root directory\n");
                return -1;
                return -1;
        }
        }
 
 
 
 
        printf("Readback test\n");
        printf("Readback test\n");
        if (DFS_OpenFile(&vi,"vmlinux.bin", DFS_READ, sector, &fi)) {
        if (DFS_OpenFile(&vi,"vmlinux.bin", DFS_READ, sector, &fi)) {
                printf("error opening file\n");
                printf("error opening file\n");
 
 
                return -1;
                return -1;
        }
        }
 
 
        printf("fi.filen %d, pointer adress:%d, data:%d \n", fi.filelen, buf_ptr, *buf_ptr);
        printf("fi.filen %d, pointer adress:%d, data:%d \n", fi.filelen,
 
               buf_ptr, *buf_ptr);
 
 
        DFS_ReadFile(&fi, sector, buf_ptr, &i, fi.filelen);
        DFS_ReadFile(&fi, sector, buf_ptr, &i, fi.filelen);
        printf("\n read complete %d bytes (expected %d) pointer %d\n", i, fi.filelen, fi.pointer);
        printf("\n read complete %d bytes (expected %d) pointer %d\n", i,
 
               fi.filelen, fi.pointer);
 
 
 
 
      if (global.src_addr > 0)
        if (global.src_addr > 0) {
      {
 
       /* 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, i);
              global.src_addr, i);
      }
      }
 
 
 
 
 
 
 
 
  // 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
      // Put the copyboot program at 24MB mark in memory
      #define COPYBOOT_LOCATION (1024*1024*24) 
      #define COPYBOOT_LOCATION (1024*1024*24) 
      printf("tboot: relocating copy loop to 0x%x ...\n", (unsigned long)COPYBOOT_LOCATION);
        printf("tboot: relocating copy loop to 0x%x ...\n",
 
               (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, int)
        void (*relocated_function) (unsigned long, unsigned long, unsigned long,
 
                                    int)
        = (void*) COPYBOOT_LOCATION;
        = (void*) COPYBOOT_LOCATION;
      // Now copy the function there, 32 words worth, increase this if needed...
      // Now copy the function there, 32 words worth, increase this if needed...
      relocate_code((void*)COPYBOOT_LOCATION, copy_and_boot, 32);
      relocate_code((void*)COPYBOOT_LOCATION, copy_and_boot, 32);
      // Indicate we'll jump there...
      // Indicate we'll jump there...
      printf("tboot: Relocate (%d bytes from 0x%x to 0) and boot image, ...\n", i, (unsigned long) global.src_addr);
        printf
 
            ("tboot: Relocate (%d bytes from 0x%x to 0) and boot image, ...\n",
 
             i, (unsigned long)global.src_addr);
      // Now do the copy and boot
      // Now do the copy and boot
      (*relocated_function)(global.src_addr, 0x0, 0x0 + i, 0);
      (*relocated_function)(global.src_addr, 0x0, 0x0 + i, 0);
 
 
      return 0;
      return 0;
 
 
}
}
 
 
void module_load_init (void)
void module_load_init (void)
{
{
 
 
  register_command ("tftp_conf", "[ <file> [ <srv_ip> [ <src_addr>]]]", "TFTP configuration", tftp_conf_cmd);
        register_command("tftp_conf", "[ <file> [ <srv_ip> [ <src_addr>]]]",
  register_command ("tboot", "[<image number>]", "Bootstrap image downloaded via tftp", tboot_cmd);
                         "TFTP configuration", tftp_conf_cmd);
  register_command ("sdboot", "[<image number>]", "Read image from SD-CARD", sdboot_cmd);
        register_command("tboot", "[<image number>]",
 
                         "Bootstrap image downloaded via tftp", tboot_cmd);
 
        register_command("sdboot", "[<image number>]",
 
                         "Read image from SD-CARD", sdboot_cmd);
#if 0
#if 0
  register_command ("tftp", "[<file> [<srv_ip> [<src_addr>]]]",  "TFTP download", tftp_cmd);
        register_command("tftp", "[<file> [<srv_ip> [<src_addr>]]]",
  register_command ("copy", "[<dst_addr> [<src_addr [<length>]]]", "Copy memory", copy_cmd);
                         "TFTP download", tftp_cmd);
  register_command ("sboot", "[<image number>]", "Bootstrap image downloaded via serial (Y/X modem)", sboot_cmd);
        register_command("copy", "[<dst_addr> [<src_addr [<length>]]]",
  register_command ("boot", "[<image number>]", "Bootstrap image copied from flash.", boot_cmd);
                         "Copy memory", copy_cmd);
  register_command ("del_image", "[<image number>]", "Delete image", del_image_cmd);
        register_command("sboot", "[<image number>]",
  register_command ("save_conf", "", "Save current configuration into flash", save_conf_cmd);
                         "Bootstrap image downloaded via serial (Y/X modem)",
  register_command ("boot_flash", "[<start_addr>]", "Boot image from <start_addr> (default from flash)", boot_flash_cmd);
                         sboot_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("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);
#endif
#endif
  init_load();
  init_load();
 
 
}
}
 
 
 No newline at end of file
 No newline at end of file

powered by: WebSVN 2.1.0

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