From: Luke Kenneth Casson Leighton Date: Sun, 2 Jan 2022 15:34:38 +0000 (+0000) Subject: rrright. ok. these modifications to sdram_init allow it X-Git-Url: https://git.libre-soc.org/?a=commitdiff_plain;h=9b5bd2d757966b696dddb1d0ec9dd1f953f38983;p=microwatt.git rrright. ok. these modifications to sdram_init allow it to be compiled and used stand-alone. sdram initialisation is disabled. the general idea here is to make this a useful mini-BIOS bootloader, focussing initially on verilator start-up. to that end, the first addition is a SYS_REG_BRAM_BOOTADDR addition to syscon which is the location where the chain-loading continues (if SPI and SDRAM are not available, where SDRAM is definitely out at this point) --- diff --git a/include/microwatt_soc.h b/include/microwatt_soc.h index a224d74..989721b 100644 --- a/include/microwatt_soc.h +++ b/include/microwatt_soc.h @@ -18,7 +18,11 @@ #define LETH_CSR_BASE 0xc8020000 /* LiteEth CSR registers */ #define LETH_SRAM_BASE 0xc8030000 /* LiteEth MMIO space */ #define SPI_FLASH_BASE 0xf0000000 /* SPI Flash memory map */ +#ifdef STANDALONE_MINI_BIOS +#define DRAM_INIT_BASE 0x00000000 /* alternative, for verilator simulation */ +#else #define DRAM_INIT_BASE 0xff000000 /* Internal DRAM init firmware */ +#endif /* * Interrupt numbers @@ -56,6 +60,7 @@ #define SYS_REG_UART0_INFO 0x40 #define SYS_REG_UART1_INFO 0x48 #define SYS_REG_UART_IS_16550 (1ull << 32) +#define SYS_REG_BRAM_BOOTADDR 0x50 /* diff --git a/litedram/gen-src/sdram_init/Makefile b/litedram/gen-src/sdram_init/Makefile index 2e622d4..8311759 100644 --- a/litedram/gen-src/sdram_init/Makefile +++ b/litedram/gen-src/sdram_init/Makefile @@ -1,12 +1,28 @@ #### Directories -include variables.mak +# check for variables.mak and if not, allow stand-alone BIOS to be compiled +# (disables SDRAM) +ifeq ("$(wildcard variables.mak)","") + include variables.mak + NO_SDRAM= +else + BUILD_DIR=. + SRC_DIR=. + GENINC_DIR=. + NO_SDRAM=true + EXTRA_CFLAGS=-DSTANDALONE_MINI_BIOS +endif + OBJ = $(BUILD_DIR)/obj LXINC_DIR=$(LXSRC_DIR)/include PROGRAM = sdram_init +ifeq ($(NO_SDRAM), true) +OBJECTS = $(OBJ)/head.o $(OBJ)/main.o $(OBJ)/console.o +else OBJECTS = $(OBJ)/head.o $(OBJ)/main.o $(OBJ)/sdram.o $(OBJ)/memtest.o $(OBJ)/console.o +endif #### Compiler @@ -32,7 +48,7 @@ CPPFLAGS += -I$(GENINC_DIR) -I$(SRC_DIR)/include -I$(SRC_DIR)/../../../include - CPPFLAGS += -I$(LXSRC_DIR) -I$(LXINC_DIR) -I$(LXINC_DIR)/base -I$(LXSRC_DIR)/liblitedram CPPFLAGS += -isystem $(shell $(CC) -print-file-name=include) -CFLAGS = -Os -g -Wall -std=c99 -m64 -mabi=elfv2 -msoft-float -mno-string -mno-multiple -mno-vsx -mno-altivec -mlittle-endian -fno-stack-protector -mstrict-align -ffreestanding -fdata-sections -ffunction-sections -fno-delete-null-pointer-checks +CFLAGS = -Os -g -Wall -std=c99 -m64 -mabi=elfv2 -msoft-float -mno-string -mno-multiple -mno-vsx -mno-altivec -mlittle-endian -fno-stack-protector -mstrict-align -ffreestanding -fdata-sections -ffunction-sections -fno-delete-null-pointer-checks ASFLAGS = $(CPPFLAGS) $(CFLAGS) LDFLAGS = -static -nostdlib -T $(OBJ)/$(PROGRAM).lds --gc-sections diff --git a/litedram/gen-src/sdram_init/head.S b/litedram/gen-src/sdram_init/head.S index 2e9f053..a008231 100644 --- a/litedram/gen-src/sdram_init/head.S +++ b/litedram/gen-src/sdram_init/head.S @@ -14,7 +14,8 @@ * limitations under the License. */ -#define STACK_TOP 0xff006000 +#include "microwatt_soc.h" +#define STACK_TOP (0x00006000 + DRAM_INIT_BASE) #define FIXUP_ENDIAN \ tdi 0,0,0x48; /* Reverse endian of b . + 8 */ \ diff --git a/litedram/gen-src/sdram_init/main.c b/litedram/gen-src/sdram_init/main.c index 9ba4fd1..36f3d06 100644 --- a/litedram/gen-src/sdram_init/main.c +++ b/litedram/gen-src/sdram_init/main.c @@ -5,12 +5,16 @@ #include #include +#ifndef STANDALONE_MINI_BIOS #include +#endif #include "console.h" #include "microwatt_soc.h" #include "io.h" +#ifndef STANDALONE_MINI_BIOS #include "sdram.h" +#endif #include "elf64.h" #define FLASH_LOADER_USE_MAP @@ -284,13 +288,17 @@ uint64_t main(void) } printf("\n"); if (ftr & SYS_REG_INFO_HAS_DRAM) { +#ifndef STANDALONE_MINI_BIOS printf("LiteDRAM built from Migen %s and LiteX %s\n", MIGEN_GIT_SHA1, LITEX_GIT_SHA1); sdrinit(); +#endif } if (ftr & SYS_REG_INFO_HAS_BRAM) { - printf("Booting from BRAM...\n"); - return 0; + // allow a jump to a config-specified address (just like DRAM can) + val = readq(SYSCON_BASE + SYS_REG_BRAM_BOOTADDR); + printf("Booting from BRAM at %lx...\n", val); + return val; } if (try_flash) { val = boot_flash(fl_off);