1
0
mirror of git://projects.qi-hardware.com/nn-usb-fpga.git synced 2024-12-05 04:06:14 +02:00

Fixing cai9n loader for lm32 errors

This commit is contained in:
Carlos Camargo 2010-10-15 12:59:46 -05:00
parent 7b666c041a
commit 43de1a582c
10 changed files with 1144 additions and 76 deletions

View File

@ -25,7 +25,7 @@ xmodem.o: xmodem.c
$(LM32_CC) $(CFLAGS) -c xmodem.c
image: crt0ram.o main.o soc-hw.o xmodem.o
$(LM32_LD) $(LDFLAGS) -Map image.map -N -o image crt0ram.o main.o soc-hw.o xmodem.o
$(LM32_LD) $(LDFLAGS) -Map image.map -N -o image crt0ram.o main.o soc-hw.o xmodem.o
image.lst: image
$(LM32_OBJDUMP) -h -S $< > $@
@ -44,7 +44,7 @@ $(VRAMFILE): image.srec
$(SREC2VRAM) image.srec 0x00000000 0x1000 > $(VRAMFILE)
clean:
rm -f image image.lst image.bin image.srec image.map image.ram *.o *.d
rm -f image image.lst image.bin image.srec image.map *.o *.d *.bin
DEPS := $(wildcard *.d)
ifneq ($(DEPS),)

File diff suppressed because it is too large Load Diff

View File

@ -0,0 +1,114 @@
/**
* Primitive first stage bootloader
*
*
*/
#include "soc-hw.h"
/* prototypes */
uint32_t read_uint32()
{
uint32_t val = 0, i;
for (i = 0; i < 4; i++) {
val <<= 8;
val += (uint8_t)uart_getchar();
}
return val;
}
void hexprint(unsigned int hexval)
{
int digit[8], pos;
uart_putstr("0x");
for(pos = 0; pos < 8; pos++)
{
digit[pos] = (hexval & 0xF); /* last hexit */
hexval = hexval >> 4;
}
for(pos = 7; pos > -1; pos--)
{
if(digit[pos] < 0xA)
uart_putstr((char *)digit[pos] + '0');
else
uart_putstr((char *)digit[pos] + 'A' - 10);
}
uart_putchar(' ');
}
int main(int argc, char **argv)
{
int8_t *p;
uint8_t c;
int key, len, autoboot = 1, dispmenu = 1;
// Initialize UART
uart_init();
while(1){ /* loop forever until u-boot gets booted or the board is reset */
if(dispmenu){
uart_putstr("\n1: Upload program to RAM\r\n");
// uart_putstr("2: Upload u-boot to Dataflash\r\n");
// uart_putstr("3: Upload Kernel to Dataflash\r\n");
// uart_putstr("4: Start u-boot\r\n");
// uart_putstr("5: Upload Filesystem image\r\n");
// uart_putstr("6: Memory test\r\n");
dispmenu = 0;
}
key = uart_getchar();
autoboot = 0;
if(key == '1'){
len = rxmodem((unsigned char *)0x2000);
uart_putstr("Received ");
hexprint(len);
uart_putstr(" bytes\r\n");
// jump(0x1000);
dispmenu = 1;
}
else{
uart_putstr("Invalid input\r\n");
dispmenu = 1;
}
}
c = '*'; // print msg on first iteration
for(;;) {
uint32_t start, size;
switch (c) {
case 'u': // upload
start = read_uint32();
size = read_uint32();
for (p = (int8_t *) start; p < (int8_t *) (start+size); p++)
*p = uart_getchar();
break;
case 'd': // download
start = read_uint32();
size = read_uint32();
for (p = (int8_t *) start; p < (int8_t *) (start+size); p++)
uart_putchar( *p );
break;
case 'g': // goto
start = read_uint32();
jump(start);
break;
default:
uart_putstr("**SAKC/bootloader** > \r\n");
break;
};
c = uart_getchar();
}
}

View File

@ -3,6 +3,7 @@
uart_t *uart0 = (uart_t *) 0xF0000000;
timer_t *timer0 = (timer_t *) 0xF0010000;
gpio_t *gpio0 = (gpio_t *) 0xF0020000;
// uint32_t *sram0 = (uint32_t *) 0x40000000;
uint32_t msec = 0;
@ -66,24 +67,3 @@ void uart_putstr(char *str)
}
}
void hexprint(unsigned int hexval)
{
int digit[8], pos;
uart_putstr("0x");
for(pos = 0; pos < 8; pos++)
{
digit[pos] = (hexval & 0xF); /* last hexit */
hexval = hexval >> 4;
}
for(pos = 7; pos > -1; pos--)
{
if(digit[pos] < 0xA)
uart_putstr((char *)digit[pos] + '0');
else
uart_putstr((char *)digit[pos] + 'A' - 10);
}
uart_putchar(' ');
}

View File

@ -105,7 +105,4 @@ extern uart_t *uart0;
extern gpio_t *gpio0;
extern uint32_t *sram0;
int rxmodem(unsigned char *dest);
void hexprint(unsigned int hexval);
#endif // SPIKEHW_H

View File

@ -77,16 +77,10 @@ int rxmodem(unsigned char *dest)
unsigned short crc, tcrc;
int i, pid = 1, len = 0;
for (i = 0; i < 0x100000; i++)
{
*ptr = 0;
ptr++;
}
for(i = 0; i < 0x20000; i++) { asm("nop;"); }
uart_putstr("Receiving Xmodem transfer\n");
uart_getchar ();
for(i = 0; i < 0x20000000; i++) { asm("nop;"); }
for(i = 0; i < 0x20000; i++) { asm("nop;"); }
uart_putchar ('C');
while(1)

View File

@ -1,41 +0,0 @@
#include "soc-hw.h"
unsigned int i, j,k; // Loop counter.
int main() {
int key, len, autoboot = 1, dispmenu = 1;
uart_putstr("Cain's bootloader!!! \r\n");
while(1){ /* loop forever until u-boot gets booted or the board is reset */
if(dispmenu){
uart_putstr("\n1: Upload program to RAM\r\n");
// uart_putstr("2: Upload u-boot to Dataflash\r\n");
// uart_putstr("3: Upload Kernel to Dataflash\r\n");
// uart_putstr("4: Start u-boot\r\n");
// uart_putstr("5: Upload Filesystem image\r\n");
// uart_putstr("6: Memory test\r\n");
dispmenu = 0;
}
key = uart_getchar();
autoboot = 0;
if(key == '1'){
len = rxmodem((unsigned char *)0x1000);
uart_putstr("Received ");
hexprint(len);
uart_putstr(" bytes\r\n");
// jump(RAM_BASE);
dispmenu = 1;
}
else{
uart_putstr("Invalid input\r\n");
dispmenu = 1;
}
}
while(1){ asm("nop;"); }
return (0);
}

View File

@ -6,7 +6,7 @@
module system
#(
parameter bootram_file = "../firmware/loader_cain/image.ram",
parameter bootram_file = "../firmware/cain_loader/image.ram",
// parameter bootram_file = "../firmware/boot0-serial/image.ram",
parameter clk_freq = 50000000,
parameter uart_baud_rate = 57600