Skip to content

Commit

Permalink
Generate mem.h from SoC description
Browse files Browse the repository at this point in the history
Sebastien Bourdeauducq committed Feb 21, 2014
1 parent fce46ac commit 9e784fc
Showing 11 changed files with 46 additions and 25 deletions.
6 changes: 6 additions & 0 deletions make.py
Original file line number Diff line number Diff line change
@@ -138,6 +138,12 @@ def _misoc_import(default, external, name):
""".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"):
9 changes: 9 additions & 0 deletions misoclib/gensoc/cpuif.py
Original file line number Diff line number Diff line change
@@ -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 = ""

6 changes: 4 additions & 2 deletions software/bios/boot.c
Original file line number Diff line number Diff line change
@@ -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
7 changes: 7 additions & 0 deletions software/bios/main.c
Original file line number Diff line number Diff line change
@@ -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();
2 changes: 1 addition & 1 deletion software/bios/sdram.c
Original file line number Diff line number Diff line change
@@ -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"

17 changes: 0 additions & 17 deletions software/include/hw/mem.h

This file was deleted.

10 changes: 10 additions & 0 deletions software/include/hw/minimac_mem.h
Original file line number Diff line number Diff line change
@@ -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
2 changes: 1 addition & 1 deletion software/libbase/system.c
Original file line number Diff line number Diff line change
@@ -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)
2 changes: 1 addition & 1 deletion software/libnet/microudp.c
Original file line number Diff line number Diff line change
@@ -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>

5 changes: 3 additions & 2 deletions software/videomixer/config.c
Original file line number Diff line number Diff line change
@@ -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);

5 changes: 4 additions & 1 deletion targets/mlabs_video.py
Original file line number Diff line number Diff line change
@@ -74,9 +74,12 @@ def __init__(self, platform, with_memtest=False):
# 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)

0 comments on commit 9e784fc

Please sign in to comment.