From 1a338b602a125ba07ed348b7d63db49cb73f0bd8 Mon Sep 17 00:00:00 2001 From: Florent Kermarrec Date: Tue, 22 Dec 2020 19:14:07 +0100 Subject: [PATCH] software/bios: add new mem_list command to list available memory regions. 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 --- litex/soc/integration/export.py | 17 ++++++++++++++--- litex/soc/software/bios/cmds/cmd_mem.c | 15 +++++++++++++++ 2 files changed, 29 insertions(+), 3 deletions(-) diff --git a/litex/soc/integration/export.py b/litex/soc/integration/export.py index 3b8916507..e2fabb35d 100644 --- a/litex/soc/integration/export.py +++ b/litex/soc/integration/export.py @@ -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" diff --git a/litex/soc/software/bios/cmds/cmd_mem.c b/litex/soc/software/bios/cmds/cmd_mem.c index d434c42d2..cb01a3926 100644 --- a/litex/soc/software/bios/cmds/cmd_mem.c +++ b/litex/soc/software/bios/cmds/cmd_mem.c @@ -5,10 +5,25 @@ #include #include +#include #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" *