Generate mem.h from SoC description
authorSebastien Bourdeauducq <sebastien@milkymist.org>
Fri, 21 Feb 2014 16:55:05 +0000 (17:55 +0100)
committerSebastien Bourdeauducq <sebastien@milkymist.org>
Fri, 21 Feb 2014 16:55:05 +0000 (17:55 +0100)
make.py
misoclib/gensoc/cpuif.py
software/bios/boot.c
software/bios/main.c
software/bios/sdram.c
software/include/hw/mem.h [deleted file]
software/include/hw/minimac_mem.h [new file with mode: 0644]
software/libbase/system.c
software/libnet/microudp.c
software/videomixer/config.c
targets/mlabs_video.py

diff --git a/make.py b/make.py
index 419ed6b6e1a5dfe15057dcef3b8a399916212acd..f08fd4d19820699fe6d024f09efe04f73f175f55 100755 (executable)
--- 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"):
index 9c40b6b9a5826928dcd138f7f28ae514968e9b54..3ebdd118588b2a204f02e0f48723c21bd6ac121c 100644 (file)
@@ -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 = ""
 
index 3c505e1cdf336c79880e3b9c0de62f665f94fd0c..5ba3de79d22f5ddfa9fee1062360d2ef6ccb3ef7 100644 (file)
@@ -7,7 +7,7 @@
 #include <string.h>
 #include <irq.h>
 
-#include <hw/mem.h>
+#include <generated/mem.h>
 #include <generated/csr.h>
 
 #include <net/microudp.h>
@@ -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
index f26ac2109159ca5843c3427b09f049aefde9e2bd..b779496d01bed107e2ca9e9341ec3e3d653211db 100644 (file)
@@ -9,6 +9,7 @@
 #include <crc.h>
 
 #include <generated/csr.h>
+#include <generated/mem.h>
 #include <net/microudp.h>
 
 #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();
index cb05396284ddd80165f73e8720cc591c6b07d0a8..92e1863542a3d519f5ade1dfd94437c4c80b2b3c 100644 (file)
@@ -5,8 +5,8 @@
 #include <stdlib.h>
 
 #include <generated/sdram_phy.h>
+#include <generated/mem.h>
 #include <hw/flags.h>
-#include <hw/mem.h>
 
 #include "sdram.h"
 
diff --git a/software/include/hw/mem.h b/software/include/hw/mem.h
deleted file mode 100644 (file)
index 0f83563..0000000
+++ /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 (file)
index 0000000..cd9615e
--- /dev/null
@@ -0,0 +1,10 @@
+#ifndef __HW_MINIMAC_MEM_H
+#define __HW_MINIMAC_MEM_H
+
+#include <generated/mem.h>
+
+#define MINIMAC_RX0_BASE       MINIMAC_BASE
+#define MINIMAC_RX1_BASE       (MINIMAC_BASE+0x0800)
+#define MINIMAC_TX_BASE                (MINIMAC_BASE+0x1000)
+
+#endif
index 7159e379942378549275241740ecbba2b257e77c..48c6ee22e2cf731c81c320a5fa5a7e17c2d14768 100644 (file)
@@ -2,7 +2,7 @@
 #include <uart.h>
 
 #include <system.h>
-#include <hw/mem.h>
+#include <generated/mem.h>
 #include <generated/csr.h>
 
 void flush_cpu_icache(void)
index 6cd2f1ebe2468abef08214239026c6103c715534..bd5e2a08b395d1316c15d3753fe3fa270e47ceca 100644 (file)
@@ -5,7 +5,7 @@
 #include <system.h>
 #include <crc.h>
 #include <hw/flags.h>
-#include <hw/mem.h>
+#include <hw/minimac_mem.h>
 
 #include <net/microudp.h>
 
index 4b3d56ed1d92ed6c29799cfddc3ba29a25ebb267..b1292efae08320c7bd9be44d2eec8f103d17e29f 100644 (file)
@@ -1,10 +1,11 @@
 #include <stdio.h>
 #include <string.h>
-#include <hw/mem.h>
+#include <generated/mem.h>
 
 #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);
 
index e0a00f86f182baefb1661ea59d514d6bc83168b9..06b9f4c99ba309f6d127c7f611441014ac3f23e7 100644 (file)
@@ -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)