Browse Source

Set the ROM offset at the beginning of the image

Put the ROM offset into a field in the image header, at the bottom of
the NULL pointer reserved region. testimg.S adjusts this field so that
the handling of the ROM offset becomes "automatic".
H. Peter Anvin 3 years ago
parent
commit
d7ef705e4a
9 changed files with 649 additions and 666 deletions
  1. 2 2
      fw/Makefile
  2. 586 586
      fw/boot.mif
  3. 4 0
      fw/fw.h
  4. 13 2
      fw/head.S
  5. 0 30
      fw/main.c
  6. 4 1
      fw/max80.ld
  7. 32 0
      fw/romcopy.c
  8. 0 44
      fw/test/main.c
  9. 8 1
      fw/testimg.S

+ 2 - 2
fw/Makefile

@@ -40,7 +40,7 @@ ROMS    := $(wildcard roms/*.rom)
 ROMOBJS  = $(ROMS:.rom=.o)
 
 max80.elf: head.o die.o main.o dummy.o irqtable.o irqasm.o sbrk.o \
-	  console.o rtc.o \
+	  console.o rtc.o romcopy.o \
 	  sdcard.o diskcache.o \
 	  abcio.o abcdisk.o \
 	  memset.o memcpy.o \
@@ -49,7 +49,7 @@ max80.elf: head.o die.o main.o dummy.o irqtable.o irqasm.o sbrk.o \
 	  fatfs.a
 
 testimg.elf: head.o die.o test/main.o dummy.o irqtable.o irqasm.o sbrk.o \
-	  console.o rtc.o \
+	  console.o rtc.o romcopy.o \
 	  sdcard.o diskcache.o \
 	  abcio.o abcdisk.o \
 	  memset.o memcpy.o \

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


+ 4 - 0
fw/fw.h

@@ -56,6 +56,8 @@ typedef union xcptr {
 #define __dram_bss	__attribute__((section(".dram.bss")))
 #define __dram_noinit	__attribute__((section(".dram.noinit")))
 
+extern const size_t __rom_offset;
+
 extern no_return _die(void);
 extern no_return exit(int);
 extern no_return _exit(int);
@@ -68,4 +70,6 @@ extern void mount_abcdrives(void);
 
 extern void read_rtc(void);
 
+extern uint32_t romcopy_time[2];
+
 #endif /* FW_H */

+ 13 - 2
fw/head.S

@@ -10,11 +10,22 @@
 	// NULL pointer guard area
 	// This needs to be an explicitly allocated section or the binary
 	// memory initialization file ends up broken.
+	//
+	// This also contains a pointer to the ROM area associated
+	// with this image. For a non-primary image it is patched to
+	// the preferred value.
 	.section ".null","a"
 	.globl _NULL
-_NULL:	.space _PC_RESET
+_NULL:
+	.space 12
 	.type	_NULL, @object
-	.size	_NULL, _PC_RESET
+	.size	_NULL, . - _NULL
+
+	.globl __rom_offset
+__rom_offset:
+	.long ROM_OFFSET
+	.type	__rom_offset, @object
+	.size	__rom_offset, . - __rom_offset
 
 	// The linker will always assign this to _PC_RESET
 	.section ".init.reset","ax"

+ 0 - 30
fw/main.c

@@ -30,35 +30,6 @@ static void init_abc_memmap(void)
     }
 }
 
-extern const char __dram_init_start[], __dram_init_end[], __dram_init_len[];
-extern const char __dram_bss_start[], __dram_bss_end[], __dram_bss_len[];
-
-static uint32_t romcopy_time[2];
-static unsigned int romcopy_state;
-IRQHANDLER(romcopy)
-{
-    switch (romcopy_state++) {
-    case 0:
-	/* Copy testdata */
-	ROMCOPY_RAMADDR = (size_t)__dram_init_start;
-	ROMCOPY_ROMADDR = ROM_OFFSET;
-	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;	/* Clear */
-	ROMCOPY_DATALEN = (size_t)__dram_bss_len;
-	break;
-    default:
-	romcopy_time[1] = rdtime() - romcopy_time[0];
-	mask_irq(ROMCOPY_IRQ);
-	return;
-    }
-}
-
 static no_return killed(const char *how, size_t pc)
 {
     con_printf("ERROR: %s at 0x%08x\n", how, pc);
@@ -86,7 +57,6 @@ static void init(void)
 	"Firmware compiled on: " __DATE__ " " __TIME__ "\n\n";
 
     /* Start ROM copy engine */
-    romcopy_state = 0;
     unmask_irqs((1U << ROMCOPY_IRQ)|(1U << EBREAK_IRQ)|(1U << BUSERR_IRQ));
 
     set_led(0);

+ 4 - 1
fw/max80.ld

@@ -181,6 +181,9 @@ SECTIONS
 		__abcrom_end = .;
 		/* Make sure this section is not empty */
 		LONG(0xffffffff)
+		LONG(0xffffffff)
+		LONG(0xffffffff)
+		LONG(0xffffffff)
 	} >DRAM
 
 	.dram.text : ALIGN(4) {
@@ -201,7 +204,7 @@ SECTIONS
 
 	/* Test program image */
 	.dram.test : ALIGN(4) {
-		*(.dram.test*)
+		KEEP(*(.dram.test*))
 	} >DRAM
 
 	__dram_bss_start = .;

+ 32 - 0
fw/romcopy.c

@@ -0,0 +1,32 @@
+#include "fw.h"
+#include "io.h"
+
+extern const char __dram_init_start[], __dram_init_end[], __dram_init_len[];
+extern const char __dram_bss_start[], __dram_bss_end[], __dram_bss_len[];
+
+uint32_t romcopy_time[2];
+IRQHANDLER(romcopy)
+{
+    static unsigned int romcopy_state;
+
+    switch (romcopy_state++) {
+    case 0:
+	/* Copy testdata */
+	ROMCOPY_RAMADDR = (size_t)__dram_init_start;
+	ROMCOPY_ROMADDR = __rom_offset;
+	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;	/* Clear */
+	ROMCOPY_DATALEN = (size_t)__dram_bss_len;
+	break;
+    default:
+	romcopy_time[1] = rdtime() - romcopy_time[0];
+	mask_irq(ROMCOPY_IRQ);
+	return;
+    }
+}

+ 0 - 44
fw/test/main.c

@@ -207,49 +207,6 @@ 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, not including the SRAM image.
-     */
-    asm("mv %0,tp" : "=r" (rombase));
-
-    if (rombase) {
-	/* Test-only ROM image? */
-	rombase = ROM_OFFSET;
-    }
-
-    switch (romcopy_state++) {
-    case 0:
-	/* Copy testdata */
-	ROMCOPY_RAMADDR = (size_t)__dram_init_start;
-	ROMCOPY_ROMADDR = rombase;
-	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;	/* Clear */
-	ROMCOPY_DATALEN = (size_t)__dram_bss_len;
-	break;
-    default:
-	romcopy_time[1] = rdtime() - romcopy_time[0];
-	mask_irq(ROMCOPY_IRQ);
-	return;
-    }
-}
-
 static no_return killed(const char *how, size_t pc)
 {
     con_printf("ERROR: %s at 0x%08x\n", how, pc);
@@ -301,7 +258,6 @@ void main(void)
     unmask_irq(EBREAK_IRQ);
 
     CON_DATA = '3';
-    romcopy_state = 0;
     unmask_irq(ROMCOPY_IRQ);
 
     CON_DATA = '4';

+ 8 - 1
fw/testimg.S

@@ -1,8 +1,15 @@
+#include "sys.h"
+
 	.section ".dram.test","a"
 
+	.balign 16
 	.globl __dram_test_start
 __dram_test_start:
-	.incbin "testimg.bin"
+	/* Override the rom offset pointer */
+	.long 0, 0, 0
+	.long __dram_test_start - SDRAM_ADDR + ROM_OFFSET + SRAM_SIZE
+
+	.incbin "testimg.bin", 16
 	.type __dram_test_start, @object
 	.size __dram_test_start, . - __dram_test_start
 

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