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

Subversion Repositories mlite

[/] [mlite/] [trunk/] [tools/] [bootldr.c] - Diff between revs 267 and 291

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

Rev 267 Rev 291
Line 1... Line 1...
/* bootldr.c */
/*--------------------------------------------------------------------
 
 * TITLE: Plasma Bootloader
 
 * AUTHOR: Steve Rhoads (rhoadss@yahoo.com)
 
 * DATE CREATED: 12/17/05
 
 * FILENAME: bootldr.c
 
 * PROJECT: Plasma CPU core
 
 * COPYRIGHT: Software placed into the public domain by the author.
 
 *    Software 'as is' without warranty.  Author liable for nothing.
 
 * DESCRIPTION:
 
 *    Plasma bootloader.
 
 *--------------------------------------------------------------------*/
#include "plasma.h"
#include "plasma.h"
 
 
#define MemoryRead(A) (*(volatile unsigned long*)(A))
#define MemoryRead(A) (*(volatile unsigned long*)(A))
#define MemoryWrite(A,V) *(volatile unsigned long*)(A)=(V)
#define MemoryWrite(A,V) *(volatile unsigned long*)(A)=(V)
 
 
Line 9... Line 19...
extern int getch(void);
extern int getch(void);
extern int kbhit(void);
extern int kbhit(void);
extern int DdrInit(void);
extern int DdrInit(void);
 
 
typedef void (*FuncPtr)(void);
typedef void (*FuncPtr)(void);
 
typedef unsigned long uint32;
 
typedef unsigned short uint16;
 
 
 
 
 
void FlashRead(uint16 *dst, uint32 byteOffset, int bytes)
 
{
 
   volatile uint32 *ptr=(uint32*)(FLASH_BASE + (byteOffset << 1));
 
   *ptr = 0xff;                   //read mode
 
   while(bytes > 0)
 
   {
 
      *dst++ = (uint16)*ptr++;
 
      bytes -= 2;
 
   }
 
}
 
 
 
 
 
void FlashWrite(uint16 *src, uint32 byteOffset, int bytes)
 
{
 
   volatile uint32 *ptr=(uint32*)(FLASH_BASE + (byteOffset << 1));
 
   while(bytes > 0)
 
   {
 
      *ptr = 0x40;                //write mode
 
      *ptr++ = *src++;            //write data
 
      while((*ptr & 0x80) == 0)   //check status
 
         ;
 
      bytes -= 2;
 
   }
 
}
 
 
 
 
 
void FlashErase(uint32 byteOffset)
 
{
 
   volatile uint32 *ptr=(uint32*)(FLASH_BASE + (byteOffset << 1));
 
   *ptr = 0x20;                   //erase block
 
   *ptr = 0xd0;                   //confirm
 
   while((*ptr & 0x80) == 0)      //check status
 
      ;
 
}
 
 
 
 
char *xtoa(unsigned long num)
char *xtoa(unsigned long num)
{
{
   static char buf[12];
   static char buf[12];
   int i, digit;
   int i, digit;
Line 24... Line 73...
      num >>= 4;
      num >>= 4;
   }
   }
   return buf;
   return buf;
}
}
 
 
 
 
unsigned long getnum(void)
unsigned long getnum(void)
{
{
   int i;
   int i;
   unsigned long ch, ch2, value=0;
   unsigned long ch, ch2, value=0;
   for(i = 0; i < 16; )
   for(i = 0; i < 16; )
Line 60... Line 110...
   putchar('\r');
   putchar('\r');
   putchar('\n');
   putchar('\n');
   return value;
   return value;
}
}
 
 
 
 
int main(void)
int main(void)
{
{
   int i, j, ch;
   int i, j, ch;
   unsigned long address, value, count;
   unsigned long address, value, count;
   FuncPtr funcPtr;
   FuncPtr funcPtr;
Line 74... Line 125...
   puts("\nGreetings from the bootloader ");
   puts("\nGreetings from the bootloader ");
   puts(__DATE__);
   puts(__DATE__);
   puts(" ");
   puts(" ");
   puts(__TIME__);
   puts(__TIME__);
   puts(":\n");
   puts(":\n");
 
   MemoryWrite(FLASH_BASE, 0xff);  //read mode
 
   if((MemoryRead(GPIOA_IN) & 1) && (MemoryRead(FLASH_BASE) & 0xffff) == 0x3c1c)
 
   {
 
      puts("Boot from flash\n");
 
      FlashRead((uint16*)RAM_EXTERNAL_BASE, 0, 1024*128);
 
      funcPtr = (FuncPtr)RAM_EXTERNAL_BASE;
 
      funcPtr();
 
   }
   for(;;)
   for(;;)
   {
   {
      puts("\nWaiting for binary image linked at 0x10000000\n");
      puts("\nWaiting for binary image linked at 0x10000000\n");
      puts("Other Menu Options:\n");
      puts("Other Menu Options:\n");
      puts("1. Memory read word\n");
      puts("1. Memory read word\n");
Line 87... Line 146...
      puts("5. Jump to address\n");
      puts("5. Jump to address\n");
      puts("6. Raw memory read\n");
      puts("6. Raw memory read\n");
      puts("7. Raw memory write\n");
      puts("7. Raw memory write\n");
      puts("8. Checksum\n");
      puts("8. Checksum\n");
      puts("9. Dump\n");
      puts("9. Dump\n");
 
      puts("F. Copy 128KB from DDR to flash\n");
      puts("> ");
      puts("> ");
      ch = getch();
      ch = getch();
      address = 0;
      address = 0;
      if('0' <= ch && ch <= '9')
      if('0' <= ch && ch <= '9')
      {
      {
Line 130... Line 190...
         funcPtr();
         funcPtr();
         break;
         break;
      case '6':
      case '6':
         puts("\nCount in hex> ");
         puts("\nCount in hex> ");
         count = getnum();
         count = getnum();
         //puts(xtoa(count));
 
         //puts("\n");
 
         for(i = 0; i < count; ++i)
         for(i = 0; i < count; ++i)
         {
         {
            ch = *(unsigned char*)(address + i);
            ch = *(unsigned char*)(address + i);
            putchar(ch);
            putchar(ch);
         }
         }
         break;
         break;
      case '7':
      case '7':
         puts("\nCount in hex> ");
         puts("\nCount in hex> ");
         count = getnum();
         count = getnum();
         //puts(xtoa(count));
 
         //putchar('\n');
 
         for(i = 0; i < count; ++i)
         for(i = 0; i < count; ++i)
         {
         {
            ch = getch();
            ch = getch();
            *(unsigned char*)(address+i) = ch;
            *(unsigned char*)(address+i) = ch;
         }
         }
Line 174... Line 230...
            puts(xtoa(value));
            puts(xtoa(value));
            putchar(' ');
            putchar(' ');
         }
         }
         puts("\r\n");
         puts("\r\n");
         break;
         break;
 
      case 'F':
 
         FlashErase(0);
 
         FlashWrite((uint16*)RAM_EXTERNAL_BASE, 0, 1024*128);
 
         break;
      case 0x3c:   //raw test.bin file
      case 0x3c:   //raw test.bin file
         ptr1 = (unsigned char*)0x10000000;
         ptr1 = (unsigned char*)0x10000000;
         for(i = 0; i < 1024*1024; ++i)
         for(i = 0; i < 1024*1024; ++i)
         {
         {
            ptr1[i] = (unsigned char)ch;
            ptr1[i] = (unsigned char)ch;

powered by: WebSVN 2.1.0

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