Browse Source

fw: add infrastructure for a secondary test mode image

We will need to be able to test the card, but don't want to burden the
SRAM with a bunch of test code. Make the test mode a separate binary
that can be loaded from ROM by the standard code; it would also be
possible to build a separate mif/flash image for it to bypass the
standard image.
H. Peter Anvin 3 years ago
parent
commit
82649f078e
9 changed files with 1547 additions and 1502 deletions
  1. BIN
      fpga/output_files/max80.jbc
  2. BIN
      fpga/output_files/max80.jic
  3. BIN
      fpga/output_files/max80.pof
  4. BIN
      fpga/output_files/max80.sof
  5. 17 3
      fw/Makefile
  6. 1486 1486
      fw/boot.mif
  7. 11 2
      fw/max80.ld
  8. 20 11
      fw/test/main.c
  9. 13 0
      fw/testimg.S

BIN
fpga/output_files/max80.jbc


BIN
fpga/output_files/max80.jic


BIN
fpga/output_files/max80.pof


BIN
fpga/output_files/max80.sof


+ 17 - 3
fw/Makefile

@@ -44,7 +44,16 @@ max80.elf: head.o die.o main.o dummy.o irqtable.o irqasm.o sbrk.o \
 	  sdcard.o diskcache.o \
 	  abcio.o abcdisk.o \
 	  memset.o memcpy.o \
-	  testdata.o $(ROMOBJS) \
+	  $(ROMOBJS) \
+	  testimg.o \
+	  fatfs.a
+
+testimg.elf: head.o die.o test/main.o dummy.o irqtable.o irqasm.o sbrk.o \
+	  console.o rtc.o \
+	  sdcard.o diskcache.o \
+	  abcio.o abcdisk.o \
+	  memset.o memcpy.o \
+	  testdata.o \
 	  fatfs.a
 
 FATFS_C = $(wildcard fatfs/source/*.c)
@@ -70,8 +79,13 @@ boot.bin: max80.elf
 dram.bin: max80.elf
 	$(OBJCOPY) -O binary -j '.dram*' $< $@
 
-dram.hex: max80.elf
-	$(OBJCOPY) -O ihex -j '.dram*' $< $@
+testimg.bin: testimg.elf
+	$(OBJCOPY) -O binary $< $@
+
+testimg.o: testimg.S testimg.bin
+
+%.hex: %.bin
+	$(OBJCOPY) -I binary -O ihex $< $@
 
 %.elf: $(LDSCRIPT)
 	$(CC) $(LDFLAGS) -o $@ $(filter-out $(LDSCRIPT),$^)

File diff suppressed because it is too large
+ 1486 - 1486
fw/boot.mif


+ 11 - 2
fw/max80.ld

@@ -175,8 +175,12 @@ SECTIONS
 	__dram_start = .;
 	__dram_init_start = .;
 
-	.dram.abcrom : ALIGN(4) {
+	.dram.abcrom : AT(SRAM_SIZE) ALIGN(4) {
+		__abcrom_start = .;
 		KEEP(*(SORT_NONE(.dram.abcrom*)))
+		__abcrom_end = .;
+		/* Make sure this section is not empty */
+		LONG(0xffffffff)
 	} >DRAM
 
 	.dram.text : ALIGN(4) {
@@ -195,6 +199,11 @@ SECTIONS
 	__dram_init_end = .;
 	__dram_init_len = __dram_init_end - __dram_init_start;
 
+	/* Test program image */
+	.dram.test : ALIGN(4) {
+		*(.dram.test*)
+	} >DRAM
+
 	__dram_bss_start = .;
 	.dram.bss (NOLOAD) : ALIGN(8) {
 		*(.dram.bss*)
@@ -206,7 +215,7 @@ SECTIONS
 	/* Like BSS except no need to clear on boot */
 	.dram.noinit (NOLOAD) : ALIGN(8) {
 		*(.dram.noinit*)
-	}
+	} >DRAM
 
 	/* No need to zero the heap */
 	.heap (NOLOAD) : ALIGN(16) {

+ 20 - 11
fw/hello.c → fw/test/main.c

@@ -207,23 +207,32 @@ static void init(void)
     read_rtc();
 }
 
+static uint32_t romcopy_time[2];
+static unsigned int romcopy_state;
+extern const char __dram_init_start[], __dram_init_end[], __dram_init_len[];
+
 static uint32_t romcopy_time[2];
 static unsigned int romcopy_state;
 IRQHANDLER(romcopy)
 {
+    size_t rombase;
+
+    /* The handover code from the normal startup will set tp to our ROM area */
+    asm("mv %0,tp" : "=r" (rombase));
+
     switch (romcopy_state++) {
     case 0:
 	/* Copy testdata */
-	ROMCOPY_RAMADDR = 0;
-	ROMCOPY_ROMADDR = 0x100000;
-	ROMCOPY_DATALEN = TESTDATA_WORDS << 2;
+	ROMCOPY_RAMADDR = (size_t)__dram_init_start;
+	ROMCOPY_ROMADDR = rombase + SRAM_SIZE;
+	ROMCOPY_DATALEN = (size_t)__dram_init_len;
 	break;
     case 1:
 	/* Zero .dram.bss */
 	romcopy_time[0] = rdtime() - time_zero;
 
 	ROMCOPY_RAMADDR = (size_t)__dram_bss_start;
-	ROMCOPY_ROMADDR = 0;	/* Zero */
+	ROMCOPY_ROMADDR = 0;	/* Clear */
 	ROMCOPY_DATALEN = (size_t)__dram_bss_len;
 	break;
     default:
@@ -252,7 +261,7 @@ IRQHANDLER(EBREAK)
     killed("invalid instruction", pc);
 }
 
-static uint32_t get_reset_vector(void)
+static uint32_t get_null_ptr(void)
 {
     uint32_t rv;
 
@@ -266,14 +275,14 @@ void main(void)
     /* The data section is not reinitialized on reset */
     static unsigned int loops = 1;
 
-    uint32_t reset_vector;
+    uint32_t null_ptr;
     uint32_t irq_count;
     uint32_t abc_status;
     uint32_t done;
     uint32_t time_to_main;
 
     time_to_main = rdtime() - time_zero;
-    reset_vector = get_reset_vector();
+    null_ptr = get_null_ptr();
 
     con_set_baudrate(115200);
 
@@ -325,10 +334,10 @@ void main(void)
 	       (done+(CPU_HZ/64))/(CPU_HZ/32));
 
     udelay(1000000);
-    uint32_t reset_vector_now = get_reset_vector();
-    if (reset_vector != reset_vector_now) {
-	con_printf("*** RESET VECTOR CORRUPT: 0x%08x not 0x%08x\n",
-		   reset_vector_now, reset_vector);
+    uint32_t null_ptr_now = get_null_ptr();
+    if (null_ptr != null_ptr_now) {
+	con_printf("*** NULL POINTER AREA CORRUPT: 0x%08x not 0x%08x\n",
+		   null_ptr_now, null_ptr);
 	con_flush();
 	_die();
     }

+ 13 - 0
fw/testimg.S

@@ -0,0 +1,13 @@
+	.section ".dram.test","a"
+
+	.globl __dram_test_start
+__dram_test_start:
+	.incbin "testimg.bin"
+	.type __dram_test_start, @object
+	.size __dram_test_start, . - __dram_test_start
+
+	.globl __dram_test_end
+__dram_test_end:
+
+	.globl __dram_test_size
+	__dram_test_size = . - __dram_test_start

Some files were not shown because too many files changed in this diff