Date:2010-04-28 16:31:38 (13 years 7 months ago)
Author:Carlos Camargo
Commit:b12a749b1661cb09bdd7b41394faed69ecc765af
Message:Fixing some errors on Makefiles

Files: plasma/Makefile (1 diff)
plasma/bootldr/Makefile (1 diff)
plasma/bootldr/bootldr.c (1 diff)
plasma/logic/ram_image.vhd (4 diffs)
plasma/src/Makefile (1 diff)
plasma/src/bootldr.c (1 diff)

Change Details

plasma/Makefile
1TARGET = bootldr
2DIRS = tools bootldr logic
3
4all:
5    for n in $(DIRS); do $(MAKE) -C $$n || exit 1; done
6
7tool:
8    make -C tools
9
10logic:
11    make -C logic
12
13bootldr: tool
14    make -C bootldr
15
16clean:
17    for n in $(DIRS); do $(MAKE) -C $$n clean || exit 1; done
plasma/bootldr/Makefile
1VHDL_DIR = ../logic
2TOOLS_DIR = ../bin
3LIB_DIR = ../lib
4TARGET = bootldr
5CROSS = mips-elf
6GCC = $(CROSS)-gcc
7AS = $(CROSS)-as
8LD = $(CROSS)-ld
9DUMP = $(CROSS)-objdump
10OBJCOPY = $(CROSS)-objcopy
11INC_PATH = ../include
12CFLAGS = -O2 -I$(INC_PATH) -Wall -c -s
13ILDFLAGS = -Ttext 0 -eentry -Map $@.map -s -N
14LDFLAGS = -Ttext 0x10000000 -eentry -Map $@.map -s -N
15
16#Internal RAM 0x00
17#External RAM 0x10000000
18
19vpath %.c $(LIB_DIR)
20vpath %.S $(LIB_DIR)
21
22.c.o:
23    $(GCC) $(CFLAGS) $<
24.S.o:
25    $(AS) -o $@ $<
26
27all: $(TARGET)
28
29clean:
30    -rm -rf *.o *.txt *.map *.lst *.bin opcodes_iram opcodes_ram test bootldr
31
32$(TARGET): crt0.o $(TARGET).o no_os.o ddr_init.o
33    $(LD) $(ILDFLAGS) -o $@ $^
34    $(OBJCOPY) -I elf32-big -O binary $@ $@.bin
35
36vhdl_mem: $(TARGET)
37    $(TOOLS_DIR)/ramimage $(VHDL_DIR)/ram_xilinx.vhd $^.bin $(VHDL_DIR)/ram_image.vhd
38
39upload: $(TARGET)
40    sudo cat $^.bin > /dev/ttyUSB0
41
42run: $(TARGET)
43    $(TOOLS_DIR)/mlite $^.bin
plasma/bootldr/bootldr.c
1/*--------------------------------------------------------------------
2 * TITLE: Plasma Bootloader
3 * AUTHOR: Steve Rhoads (rhoadss@yahoo.com)
4 * DATE CREATED: 12/17/05
5 * FILENAME: bootldr.c
6 * PROJECT: Plasma CPU core
7 * COPYRIGHT: Software placed into the public domain by the author.
8 * Software 'as is' without warranty. Author liable for nothing.
9 * DESCRIPTION:
10 * Plasma bootloader.
11 *--------------------------------------------------------------------*/
12#include "plasma.h"
13
14#define MemoryRead(A) (*(volatile unsigned long*)(A))
15#define MemoryWrite(A,V) *(volatile unsigned long*)(A)=(V)
16
17extern int putchar(int ch);
18extern int puts(const char *string);
19extern int getch(void);
20extern int kbhit(void);
21extern int DdrInit(void);
22
23typedef void (*FuncPtr)(void);
24typedef unsigned long uint32;
25typedef unsigned short uint16;
26
27
28void FlashRead(uint16 *dst, uint32 byteOffset, int bytes)
29{
30   volatile uint32 *ptr=(uint32*)(FLASH_BASE + (byteOffset << 1));
31   *ptr = 0xff; //read mode
32   while(bytes > 0)
33   {
34      *dst++ = (uint16)*ptr++;
35      bytes -= 2;
36   }
37}
38
39
40void FlashWrite(uint16 *src, uint32 byteOffset, int bytes)
41{
42   volatile uint32 *ptr=(uint32*)(FLASH_BASE + (byteOffset << 1));
43   while(bytes > 0)
44   {
45      *ptr = 0x40; //write mode
46      *ptr++ = *src++; //write data
47      while((*ptr & 0x80) == 0) //check status
48         ;
49      bytes -= 2;
50   }
51}
52
53
54void FlashErase(uint32 byteOffset)
55{
56   volatile uint32 *ptr=(uint32*)(FLASH_BASE + (byteOffset << 1));
57   *ptr = 0x20; //erase block
58   *ptr = 0xd0; //confirm
59   while((*ptr & 0x80) == 0) //check status
60      ;
61}
62
63
64char *xtoa(unsigned long num)
65{
66   static char buf[12];
67   int i, digit;
68   buf[8] = 0;
69   for (i = 7; i >= 0; --i)
70   {
71      digit = num & 0xf;
72      buf[i] = digit + (digit < 10 ? '0' : 'A' - 10);
73      num >>= 4;
74   }
75   return buf;
76}
77
78
79unsigned long getnum(void)
80{
81   int i;
82   unsigned long ch, ch2, value=0;
83   for(i = 0; i < 16; )
84   {
85      ch = ch2 = getch();
86      if(ch == '\n' || ch == '\r')
87         break;
88      if('0' <= ch && ch <= '9')
89         ch -= '0';
90      else if('A' <= ch && ch <= 'Z')
91         ch = ch - 'A' + 10;
92      else if('a' <= ch && ch <= 'z')
93         ch = ch - 'a' + 10;
94      else if(ch == 8)
95      {
96         if(i > 0)
97         {
98            --i;
99            putchar(ch);
100            putchar(' ');
101            putchar(ch);
102         }
103         value >>= 4;
104         continue;
105      }
106      putchar(ch2);
107      value = (value << 4) + ch;
108      ++i;
109   }
110   putchar('\r');
111   putchar('\n');
112   return value;
113}
114
115
116int main(void)
117{
118   int i, j, ch;
119   unsigned long address, value, count;
120   FuncPtr funcPtr;
121   unsigned char *ptr1;
122
123   DdrInit(); //Harmless if SDRAM instead of DDR
124
125   puts("\nGreetings from the bootloader ");
126   puts(__DATE__);
127   puts(" ");
128   puts(__TIME__);
129   puts(":\n");
130   MemoryWrite(FLASH_BASE, 0xff); //read mode
131   if((MemoryRead(GPIOA_IN) & 1) && (MemoryRead(FLASH_BASE) & 0xffff) == 0x3c1c)
132   {
133      puts("Boot from flash\n");
134      FlashRead((uint16*)RAM_EXTERNAL_BASE, 0, 1024*128);
135      funcPtr = (FuncPtr)RAM_EXTERNAL_BASE;
136      funcPtr();
137   }
138   for(;;)
139   {
140      puts("\nWaiting for binary image linked at 0x10000000\n");
141      puts("Other Menu Options:\n");
142      puts("1. Memory read word\n");
143      puts("2. Memory write word\n");
144      puts("3. Memory read byte\n");
145      puts("4. Memory write byte\n");
146      puts("5. Jump to address\n");
147      puts("6. Raw memory read\n");
148      puts("7. Raw memory write\n");
149      puts("8. Checksum\n");
150      puts("9. Dump\n");
151      puts("F. Copy 128KB from DDR to flash\n");
152      puts("> ");
153      ch = getch();
154      address = 0;
155      if('0' <= ch && ch <= '9')
156      {
157         putchar(ch);
158         puts("\nAddress in hex> ");
159         address = getnum();
160         puts("Address = ");
161         puts(xtoa(address));
162         puts("\n");
163      }
164      switch(ch)
165      {
166      case '1':
167         value = MemoryRead(address);
168         puts(xtoa(value));
169         puts("\n");
170         break;
171      case '2':
172         puts("\nValue in hex> ");
173         value = getnum();
174         puts(xtoa(value));
175         MemoryWrite(address, value);
176         break;
177      case '3':
178         value = *(unsigned char*)address;
179         puts(xtoa(value));
180         puts("\n");
181         break;
182      case '4':
183         puts("\nValue in hex> ");
184         value = getnum();
185         puts(xtoa(value));
186         *(unsigned char*)address = value;
187         break;
188      case '5':
189         funcPtr = (FuncPtr)address;
190         funcPtr();
191         break;
192      case '6':
193         puts("\nCount in hex> ");
194         count = getnum();
195         for(i = 0; i < count; ++i)
196         {
197            ch = *(unsigned char*)(address + i);
198            putchar(ch);
199         }
200         break;
201      case '7':
202         puts("\nCount in hex> ");
203         count = getnum();
204         for(i = 0; i < count; ++i)
205         {
206            ch = getch();
207            *(unsigned char*)(address+i) = ch;
208         }
209         break;
210      case '8':
211         puts("\nCount in hex> ");
212         count = getnum();
213         value = 0;
214         for(i = 0; i < count; ++i)
215         {
216            value += *(unsigned char*)(address+i);
217         }
218         puts(xtoa(value));
219         putchar('\n');
220         break;
221      case '9':
222         puts("\nCount in hex> ");
223         count = getnum();
224         value = 0;
225         for(i = 0; i < count; i += 4)
226         {
227            if((i & 15) == 0)
228               puts("\r\n");
229            value = *(unsigned long*)(address+i);
230            puts(xtoa(value));
231            putchar(' ');
232         }
233         puts("\r\n");
234         break;
235      case 'F':
236         puts("\nConfirm with 12345678> ");
237         value = getnum();
238         if(value == 0x12345678)
239         {
240            FlashErase(0);
241            FlashWrite((uint16*)RAM_EXTERNAL_BASE, 0, 1024*128);
242         }
243         break;
244      case 0x3c: //raw test.bin file
245         ptr1 = (unsigned char*)0x10000000;
246         for(i = 0; i < 1024*1024; ++i)
247         {
248            ptr1[i] = (unsigned char)ch;
249            for(j = 0; j < 10000; ++j)
250            {
251               if(kbhit())
252                  break;
253            }
254            if(j >= 10000)
255               break; //assume end of file
256            ch = getch();
257         }
258         funcPtr = (FuncPtr)0x10000000;
259         funcPtr();
260         break;
261      }
262   }
263   return 0;
264}
265
plasma/logic/ram_image.vhd
6262INIT_12 => X"00100082260c00240800100080afafaf270003ac001030008c343c3c08240c00",
6363INIT_13 => X"2424142c3002242400afafafaf272703008f8f8f00140082000c2682000c2414",
6464INIT_14 => X"24243c3c2703008f8c3c10000caf2730038c343c240827038f8f8f8f0216260c",
65INIT_15 => X"740a00616d20423a003231303241656c62747267650a24038c0014ac00248c3c",
65INIT_15 => X"740a00616d20423a003230303241656c62747267650a24038c0014ac00248c3c",
6666INIT_16 => X"617965330a7769796532006f61796531006e706e724f303030206e6569612020",
6767INIT_17 => X"4600753900736838006979656137617965613673647475350a62697965340079",
6868INIT_18 => X"37336820660a0d786e6e0a786e750a3d6541206820720a3e00616f446f42316f",
...... 
139139INIT_12 => X"00400002100040110080400082b1bfb0bd00e0a40040420062a3050200040040",
140140INIT_13 => X"646440624312111080bfb0b1b2bdbde000b0b1bf004000024000100200000451",
141141INIT_14 => X"63440302bde000bf6203400000bfbd42e06263030400bde0b0b1b2bf12111000",
142INIT_15 => X"6957007320666f0a003a38313470726f6f686f73744742e0a200834045848205",
142INIT_15 => X"6957007320666f0a003a36313770726f6f686f73744742e0a200834045848205",
143143INIT_16 => X"64206d2e006f74206d2e007264206d2e007374752074303078616b206d726266",
144144INIT_17 => X"2e006d2e0075652e0074206d772e64206d772e73646f6d2e007974206d2e0074",
145145INIT_18 => X"3834207769430a3e2074433e206556207364006569654120007320526d203270",
...... 
216216INIT_12 => X"00000000000220000280000000000000ff00000010ff00000000200001000220",
217217INIT_13 => X"000000000010ff009000000000ff00001000000000ff000020020000000200ff",
218218INIT_14 => X"0c0c0000000000000020ff000200ff0000000020000200000000000010ffff02",
219INIT_15 => X"6e61006866726f0000343a30207220616f656d20697200000000ff0010000010",
219INIT_15 => X"6e61006866726f0000333a30207220616f656d20697200000000ff0010000010",
220220INIT_16 => X"20726f20007265776f20006420726f20003a69204d680a303174656c6179696f",
221221INIT_17 => X"20007020006d63200065776f20200a726f20200a72207020007465776f200065",
222222INIT_18 => X"3e353169726f002068206f2068206100736400786e7364000068662020663879",
...... 
293293INIT_12 => X"000d00000145210a6021160000141810e000080021fc020000200000400a4521",
294294INIT_13 => X"5730020a0f06fc1c211c101418e020082110141800f500002145010000450df8",
295295INIT_14 => X"fcdc0000180800100000fd008c10e80108002000494520081014181c06f8fc45",
296INIT_15 => X"6769000a6c6f74000030320032200064742020666e6584080000fb0021040000",
296INIT_15 => X"6769000a6c6f74000030340032200064742020666e6584080000fb0021040000",
297297INIT_16 => X"6265724d00642072724d000a7765724d000a6f4f656500303020646967206e72",
298298INIT_17 => X"43000a44000a6b43000a72726d520065726d52006561204a00652072724d000a",
299299INIT_18 => X"203632746d6e00006569750065696c002072003e20736400000a6c7444724b20",
plasma/src/Makefile
1VHDL_DIR = ../logic
2TOOLS_DIR = ../bin
3LIB_DIR = ../lib
4TARGET = bootldr
5CROSS = mips-elf
6GCC = $(CROSS)-gcc
7AS = $(CROSS)-as
8LD = $(CROSS)-ld
9DUMP = $(CROSS)-objdump
10OBJCOPY = $(CROSS)-objcopy
11INC_PATH = ../include
12CFLAGS = -O2 -I$(INC_PATH) -Wall -c -s
13ILDFLAGS = -Ttext 0 -eentry -Map $@.map -s -N
14LDFLAGS = -Ttext 0x10000000 -eentry -Map $@.map -s -N
15
16#Internal RAM 0x00
17#External RAM 0x10000000
18
19vpath %.c $(LIB_DIR)
20vpath %.S $(LIB_DIR)
21
22.c.o:
23    $(GCC) $(CFLAGS) $<
24.S.o:
25    $(AS) -o $@ $<
26
27all: $(TARGET)
28
29clean:
30    -rm -rf *.o *.txt *.map *.lst *.bin opcodes_iram opcodes_ram test bootldr
31
32$(TARGET): crt0.o $(TARGET).o no_os.o ddr_init.o
33    $(LD) $(ILDFLAGS) -o $@ $^
34    $(OBJCOPY) -I elf32-big -O binary $@ $@.bin
35
36vhdl_mem: $(TARGET)
37    $(TOOLS_DIR)/ramimage $(VHDL_DIR)/ram_xilinx.vhd $^.bin $(VHDL_DIR)/ram_image.vhd
38
39upload: $(TARGET)
40    sudo cat $^.bin > /dev/ttyUSB0
41
42run: $(TARGET)
43    $(TOOLS_DIR)/mlite $^.bin
plasma/src/bootldr.c
1/*--------------------------------------------------------------------
2 * TITLE: Plasma Bootloader
3 * AUTHOR: Steve Rhoads (rhoadss@yahoo.com)
4 * DATE CREATED: 12/17/05
5 * FILENAME: bootldr.c
6 * PROJECT: Plasma CPU core
7 * COPYRIGHT: Software placed into the public domain by the author.
8 * Software 'as is' without warranty. Author liable for nothing.
9 * DESCRIPTION:
10 * Plasma bootloader.
11 *--------------------------------------------------------------------*/
12#include "plasma.h"
13
14#define MemoryRead(A) (*(volatile unsigned long*)(A))
15#define MemoryWrite(A,V) *(volatile unsigned long*)(A)=(V)
16
17extern int putchar(int ch);
18extern int puts(const char *string);
19extern int getch(void);
20extern int kbhit(void);
21extern int DdrInit(void);
22
23typedef void (*FuncPtr)(void);
24typedef unsigned long uint32;
25typedef unsigned short uint16;
26
27
28void FlashRead(uint16 *dst, uint32 byteOffset, int bytes)
29{
30   volatile uint32 *ptr=(uint32*)(FLASH_BASE + (byteOffset << 1));
31   *ptr = 0xff; //read mode
32   while(bytes > 0)
33   {
34      *dst++ = (uint16)*ptr++;
35      bytes -= 2;
36   }
37}
38
39
40void FlashWrite(uint16 *src, uint32 byteOffset, int bytes)
41{
42   volatile uint32 *ptr=(uint32*)(FLASH_BASE + (byteOffset << 1));
43   while(bytes > 0)
44   {
45      *ptr = 0x40; //write mode
46      *ptr++ = *src++; //write data
47      while((*ptr & 0x80) == 0) //check status
48         ;
49      bytes -= 2;
50   }
51}
52
53
54void FlashErase(uint32 byteOffset)
55{
56   volatile uint32 *ptr=(uint32*)(FLASH_BASE + (byteOffset << 1));
57   *ptr = 0x20; //erase block
58   *ptr = 0xd0; //confirm
59   while((*ptr & 0x80) == 0) //check status
60      ;
61}
62
63
64char *xtoa(unsigned long num)
65{
66   static char buf[12];
67   int i, digit;
68   buf[8] = 0;
69   for (i = 7; i >= 0; --i)
70   {
71      digit = num & 0xf;
72      buf[i] = digit + (digit < 10 ? '0' : 'A' - 10);
73      num >>= 4;
74   }
75   return buf;
76}
77
78
79unsigned long getnum(void)
80{
81   int i;
82   unsigned long ch, ch2, value=0;
83   for(i = 0; i < 16; )
84   {
85      ch = ch2 = getch();
86      if(ch == '\n' || ch == '\r')
87         break;
88      if('0' <= ch && ch <= '9')
89         ch -= '0';
90      else if('A' <= ch && ch <= 'Z')
91         ch = ch - 'A' + 10;
92      else if('a' <= ch && ch <= 'z')
93         ch = ch - 'a' + 10;
94      else if(ch == 8)
95      {
96         if(i > 0)
97         {
98            --i;
99            putchar(ch);
100            putchar(' ');
101            putchar(ch);
102         }
103         value >>= 4;
104         continue;
105      }
106      putchar(ch2);
107      value = (value << 4) + ch;
108      ++i;
109   }
110   putchar('\r');
111   putchar('\n');
112   return value;
113}
114
115
116int main(void)
117{
118   int i, j, ch;
119   unsigned long address, value, count;
120   FuncPtr funcPtr;
121   unsigned char *ptr1;
122
123   DdrInit(); //Harmless if SDRAM instead of DDR
124
125   puts("\nGreetings from the bootloader ");
126   puts(__DATE__);
127   puts(" ");
128   puts(__TIME__);
129   puts(":\n");
130   MemoryWrite(FLASH_BASE, 0xff); //read mode
131   if((MemoryRead(GPIOA_IN) & 1) && (MemoryRead(FLASH_BASE) & 0xffff) == 0x3c1c)
132   {
133      puts("Boot from flash\n");
134      FlashRead((uint16*)RAM_EXTERNAL_BASE, 0, 1024*128);
135      funcPtr = (FuncPtr)RAM_EXTERNAL_BASE;
136      funcPtr();
137   }
138   for(;;)
139   {
140      puts("\nWaiting for binary image linked at 0x10000000\n");
141      puts("Other Menu Options:\n");
142      puts("1. Memory read word\n");
143      puts("2. Memory write word\n");
144      puts("3. Memory read byte\n");
145      puts("4. Memory write byte\n");
146      puts("5. Jump to address\n");
147      puts("6. Raw memory read\n");
148      puts("7. Raw memory write\n");
149      puts("8. Checksum\n");
150      puts("9. Dump\n");
151      puts("F. Copy 128KB from DDR to flash\n");
152      puts("> ");
153      ch = getch();
154      address = 0;
155      if('0' <= ch && ch <= '9')
156      {
157         putchar(ch);
158         puts("\nAddress in hex> ");
159         address = getnum();
160         puts("Address = ");
161         puts(xtoa(address));
162         puts("\n");
163      }
164      switch(ch)
165      {
166      case '1':
167         value = MemoryRead(address);
168         puts(xtoa(value));
169         puts("\n");
170         break;
171      case '2':
172         puts("\nValue in hex> ");
173         value = getnum();
174         puts(xtoa(value));
175         MemoryWrite(address, value);
176         break;
177      case '3':
178         value = *(unsigned char*)address;
179         puts(xtoa(value));
180         puts("\n");
181         break;
182      case '4':
183         puts("\nValue in hex> ");
184         value = getnum();
185         puts(xtoa(value));
186         *(unsigned char*)address = value;
187         break;
188      case '5':
189         funcPtr = (FuncPtr)address;
190         funcPtr();
191         break;
192      case '6':
193         puts("\nCount in hex> ");
194         count = getnum();
195         for(i = 0; i < count; ++i)
196         {
197            ch = *(unsigned char*)(address + i);
198            putchar(ch);
199         }
200         break;
201      case '7':
202         puts("\nCount in hex> ");
203         count = getnum();
204         for(i = 0; i < count; ++i)
205         {
206            ch = getch();
207            *(unsigned char*)(address+i) = ch;
208         }
209         break;
210      case '8':
211         puts("\nCount in hex> ");
212         count = getnum();
213         value = 0;
214         for(i = 0; i < count; ++i)
215         {
216            value += *(unsigned char*)(address+i);
217         }
218         puts(xtoa(value));
219         putchar('\n');
220         break;
221      case '9':
222         puts("\nCount in hex> ");
223         count = getnum();
224         value = 0;
225         for(i = 0; i < count; i += 4)
226         {
227            if((i & 15) == 0)
228               puts("\r\n");
229            value = *(unsigned long*)(address+i);
230            puts(xtoa(value));
231            putchar(' ');
232         }
233         puts("\r\n");
234         break;
235      case 'F':
236         puts("\nConfirm with 12345678> ");
237         value = getnum();
238         if(value == 0x12345678)
239         {
240            FlashErase(0);
241            FlashWrite((uint16*)RAM_EXTERNAL_BASE, 0, 1024*128);
242         }
243         break;
244      case 0x3c: //raw test.bin file
245         ptr1 = (unsigned char*)0x10000000;
246         for(i = 0; i < 1024*1024; ++i)
247         {
248            ptr1[i] = (unsigned char)ch;
249            for(j = 0; j < 10000; ++j)
250            {
251               if(kbhit())
252                  break;
253            }
254            if(j >= 10000)
255               break; //assume end of file
256            ch = getch();
257         }
258         funcPtr = (FuncPtr)0x10000000;
259         funcPtr();
260         break;
261      }
262   }
263   return 0;
264}
265

Archive Download the corresponding diff file

Branches:
master



interactive