From: Sebastien Bourdeauducq Date: Fri, 21 Feb 2014 16:55:05 +0000 (+0100) Subject: Generate mem.h from SoC description X-Git-Tag: 24jan2021_ls180~2737 X-Git-Url: https://git.libre-soc.org/?a=commitdiff_plain;h=9e784fc82ce28d2ee67905bac4cee214df087877;p=litex.git Generate mem.h from SoC description --- diff --git a/make.py b/make.py index 419ed6b6..f08fd4d1 100755 --- a/make.py +++ b/make.py @@ -138,6 +138,12 @@ Subtarget: {} """.format(platform_name, args.target, top_class.__name__) linker_header = cpuif.get_linker_regions(soc.cpu_memory_regions) write_to_file("software/include/generated/regions.ld", boilerplate + linker_header) + try: + flash_boot_address = soc.flash_boot_address + except AttributeError: + flash_boot_address = None + mem_header = cpuif.get_mem_header(soc.cpu_memory_regions, flash_boot_address) + write_to_file("software/include/generated/mem.h", boilerplate + mem_header) csr_header = cpuif.get_csr_header(soc.csr_base, soc.csrbankarray, soc.interrupt_map) write_to_file("software/include/generated/csr.h", boilerplate + csr_header) if hasattr(soc, "ddrphy"): diff --git a/misoclib/gensoc/cpuif.py b/misoclib/gensoc/cpuif.py index 9c40b6b9..3ebdd118 100644 --- a/misoclib/gensoc/cpuif.py +++ b/misoclib/gensoc/cpuif.py @@ -7,6 +7,15 @@ def get_linker_regions(regions): r += "}\n" return r +def get_mem_header(regions, flash_boot_address): + r = "#ifndef __GENERATED_MEM_H\n#define __GENERATED_MEM_H\n\n" + for name, base, size in regions: + r += "#define {name}_BASE 0x{base:08x}\n#define {name}_SIZE 0x{size:08x}\n\n".format(name=name.upper(), base=base, size=size) + if flash_boot_address is not None: + r += "#define FLASH_BOOT_ADDRESS 0x{:08x}\n\n".format(flash_boot_address) + r += "#endif\n" + return r + def _get_rw_functions(reg_name, reg_base, size, read_only): r = "" diff --git a/software/bios/boot.c b/software/bios/boot.c index 3c505e1c..5ba3de79 100644 --- a/software/bios/boot.c +++ b/software/bios/boot.c @@ -7,7 +7,7 @@ #include #include -#include +#include #include #include @@ -241,6 +241,7 @@ void netboot(void) #endif +#ifdef FLASH_BOOT_ADDRESS void flashboot(void) { unsigned int *flashbase; @@ -249,7 +250,7 @@ void flashboot(void) unsigned int got_crc; printf("Booting from flash...\n"); - flashbase = (unsigned int *)FLASH_OFFSET_APP; + flashbase = (unsigned int *)FLASH_BOOT_ADDRESS; length = *flashbase++; crc = *flashbase++; if((length < 32) || (length > 4*1024*1024)) { @@ -266,3 +267,4 @@ void flashboot(void) } boot(0, 0, 0, SDRAM_BASE); } +#endif diff --git a/software/bios/main.c b/software/bios/main.c index f26ac210..b779496d 100644 --- a/software/bios/main.c +++ b/software/bios/main.c @@ -9,6 +9,7 @@ #include #include +#include #include #include "sdram.h" @@ -317,7 +318,9 @@ static void help(void) puts("netboot - boot via TFTP"); #endif puts("serialboot - boot via SFL"); +#ifdef FLASH_BOOT_ADDRESS puts("flashboot - boot from flash"); +#endif puts("revision - display revision"); } @@ -349,7 +352,9 @@ static void do_command(char *c) else if(strcmp(token, "crc") == 0) crc(get_token(&c), get_token(&c)); else if(strcmp(token, "flushl2") == 0) flush_l2_cache(); +#ifdef FLASH_BOOT_ADDRESS else if(strcmp(token, "flashboot") == 0) flashboot(); +#endif else if(strcmp(token, "serialboot") == 0) serialboot(); #ifdef MINIMAC_BASE else if(strcmp(token, "netboot") == 0) netboot(); @@ -479,7 +484,9 @@ static int test_user_abort(void) static void boot_sequence(void) { if(test_user_abort()) { +#ifdef FLASH_BOOT_ADDRESS flashboot(); +#endif serialboot(); #ifdef MINIMAC_BASE netboot(); diff --git a/software/bios/sdram.c b/software/bios/sdram.c index cb053962..92e18635 100644 --- a/software/bios/sdram.c +++ b/software/bios/sdram.c @@ -5,8 +5,8 @@ #include #include +#include #include -#include #include "sdram.h" diff --git a/software/include/hw/mem.h b/software/include/hw/mem.h deleted file mode 100644 index 0f83563d..00000000 --- a/software/include/hw/mem.h +++ /dev/null @@ -1,17 +0,0 @@ -#ifndef __HW_MEM_H -#define __HW_MEM_H - -/* TODO: those FLASH_ defines are platform-dependent, generate them from SoC description */ -#define FLASH_OFFSET_BITSTREAM 0x00000000 /* 1536k */ -#define FLASH_OFFSET_BIOS 0x00180000 /* 128k */ -#define FLASH_OFFSET_APP 0x001A0000 /* remaining space */ - -#define FLASH_BLOCK_SIZE (128*1024) - -#define SDRAM_BASE 0x40000000 - -#define MINIMAC_RX0_BASE 0xb0000000 -#define MINIMAC_RX1_BASE 0xb0000800 -#define MINIMAC_TX_BASE 0xb0001000 - -#endif /* __HW_MEM_H */ diff --git a/software/include/hw/minimac_mem.h b/software/include/hw/minimac_mem.h new file mode 100644 index 00000000..cd9615e5 --- /dev/null +++ b/software/include/hw/minimac_mem.h @@ -0,0 +1,10 @@ +#ifndef __HW_MINIMAC_MEM_H +#define __HW_MINIMAC_MEM_H + +#include + +#define MINIMAC_RX0_BASE MINIMAC_BASE +#define MINIMAC_RX1_BASE (MINIMAC_BASE+0x0800) +#define MINIMAC_TX_BASE (MINIMAC_BASE+0x1000) + +#endif diff --git a/software/libbase/system.c b/software/libbase/system.c index 7159e379..48c6ee22 100644 --- a/software/libbase/system.c +++ b/software/libbase/system.c @@ -2,7 +2,7 @@ #include #include -#include +#include #include void flush_cpu_icache(void) diff --git a/software/libnet/microudp.c b/software/libnet/microudp.c index 6cd2f1eb..bd5e2a08 100644 --- a/software/libnet/microudp.c +++ b/software/libnet/microudp.c @@ -5,7 +5,7 @@ #include #include #include -#include +#include #include diff --git a/software/videomixer/config.c b/software/videomixer/config.c index 4b3d56ed..b1292efa 100644 --- a/software/videomixer/config.c +++ b/software/videomixer/config.c @@ -1,10 +1,11 @@ #include #include -#include +#include #include "config.h" -#define FLASH_OFFSET_CONFIG (FLASH_OFFSET_APP + FLASH_BLOCK_SIZE) +#define FLASH_BLOCK_SIZE (128*1024) +#define FLASH_OFFSET_CONFIG (FLASH_BOOT_ADDRESS + FLASH_BLOCK_SIZE) static volatile unsigned short *flash_config = (unsigned short *)(0x80000000 | FLASH_OFFSET_CONFIG); diff --git a/targets/mlabs_video.py b/targets/mlabs_video.py index e0a00f86..06b9f4c9 100644 --- a/targets/mlabs_video.py +++ b/targets/mlabs_video.py @@ -74,9 +74,12 @@ class MiniSoC(SDRAMSoC): # Wishbone self.submodules.norflash = norflash16.NorFlash16(platform.request("norflash"), self.ns(110), self.ns(50)) - self.submodules.minimac = minimac3.MiniMAC(platform.request("eth")) + self.flash_boot_address = 0x001a0000 self.register_rom(self.norflash.bus) + + self.submodules.minimac = minimac3.MiniMAC(platform.request("eth")) self.add_wb_slave(lambda a: a[26:29] == 3, self.minimac.membus) + self.add_cpu_memory_region("minimac_mem", 0xb0000000, 0x1800) # CSR self.submodules.crg = mxcrg.MXCRG(_MXClockPads(platform), self.clk_freq)