Generate mem.h from SoC description

This commit is contained in:
Sebastien Bourdeauducq 2014-02-21 17:55:05 +01:00
parent fce46ac0ca
commit 9e784fc82c
11 changed files with 46 additions and 25 deletions

View file

@ -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"):

View 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 = ""

View 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

View 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();

View 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"

View file

@ -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 */

View file

@ -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

View 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)

View 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>

View 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);

View 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)