Skip to content

Commit

Permalink
software/bios: add new mem_list command to list available memory regi…
Browse files Browse the repository at this point in the history
…ons.

This is useful to know the memory regions available and use the mem_xy commands
on them:

List the memory regions:

litex> mem_list
Available memory regions:
ROM       0x00000000 0x8000
SRAM      0x01000000 0x2000
MAIN_RAM  0x40000000 0x10000000
CSR       0x82000000 0x10000

Test 0x1000 bytes of MAIN_RAM:

litex> mem_test 0x40000000 0x1000
Memtest at 0x40000000 (4KiB)...
  Write: 0x40000000-0x40001000 4KiB
   Read: 0x40000000-0x40001000 4KiB
Memtest OK

Test speed on 0x1000 bytes of MAIN_RAM:

litex> mem_speed 0x40000000 0x1000
Memspeed at 0x40000000 (4KiB)...
  Write speed: 352KiB/s
   Read speed: 288KiB/s
  • Loading branch information
enjoy-digital committed Dec 22, 2020
1 parent b3a0b4b commit 1a338b6
Show file tree
Hide file tree
Showing 2 changed files with 29 additions and 3 deletions.
17 changes: 14 additions & 3 deletions litex/soc/integration/export.py
Original file line number Diff line number Diff line change
Expand Up @@ -121,16 +121,27 @@ def get_mem_header(regions):
r = generated_banner("//")
r += "#ifndef __GENERATED_MEM_H\n#define __GENERATED_MEM_H\n\n"
for name, region in regions.items():
r += "#ifndef {name}\n".format(name=name.upper())
r += "#define {name}_BASE 0x{base:08x}L\n#define {name}_SIZE 0x{size:08x}\n\n".format(
r += "#ifndef {name}_BASE\n".format(name=name.upper())
r += "#define {name}_BASE 0x{base:08x}L\n#define {name}_SIZE 0x{size:08x}\n".format(
name=name.upper(), base=region.origin, size=region.length)
r += "#endif\n"
r += "#endif\n\n"

r += "#ifndef MEM_REGIONS\n"
r += "#define MEM_REGIONS \"";
for name, region in regions.items():
r += f"{name.upper()} {' '*(8-len(name))} 0x{region.origin:08x} 0x{region.size:x} \\n"
r = r[:-2]
r += "\"\n"
r += "#endif\n"

r += "#endif\n"
return r

def get_soc_header(constants, with_access_functions=True):
r = generated_banner("//")
r += "#ifndef __GENERATED_SOC_H\n#define __GENERATED_SOC_H\n"


for name, value in constants.items():
if value is None:
r += "#define "+name+"\n"
Expand Down
15 changes: 15 additions & 0 deletions litex/soc/software/bios/cmds/cmd_mem.c
Original file line number Diff line number Diff line change
Expand Up @@ -5,10 +5,25 @@
#include <memtest.h>

#include <generated/csr.h>
#include <generated/mem.h>

#include "../command.h"
#include "../helpers.h"

/**
* Command "mem_list"
*
* Memory list
*
*/
static void mem_list_handler(int nb_params, char **params)
{
printf("Available memory regions:\n");
puts(MEM_REGIONS);
}

define_command(mem_list, mem_list_handler, "List available memory regions", MEM_CMDS);

/**
* Command "mem_read"
*
Expand Down

0 comments on commit 1a338b6

Please sign in to comment.