Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Terminal: add history and auto completion #474

Merged
merged 5 commits into from
May 2, 2020
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
8 changes: 7 additions & 1 deletion litex/soc/integration/builder.py
Original file line number Diff line number Diff line change
Expand Up @@ -49,7 +49,8 @@ def __init__(self, soc,
csr_json = None,
csr_csv = None,
csr_svd = None,
memory_x = None):
memory_x = None,
bios_options = None):
self.soc = soc

# From Python doc: makedirs() will become confused if the path
Expand All @@ -66,6 +67,7 @@ def __init__(self, soc,
self.csr_json = csr_json
self.csr_svd = csr_svd
self.memory_x = memory_x
self.bios_options = bios_options

self.software_packages = []
for name in soc_software_packages:
Expand Down Expand Up @@ -110,6 +112,10 @@ def define(k, v):
for name, src_dir in self.software_packages:
define(name.upper() + "_DIRECTORY", src_dir)

if self.bios_options is not None:
for option in self.bios_options:
define(option, "1")

write_to_file(
os.path.join(self.generated_dir, "variables.mak"),
"".join(variables_contents))
Expand Down
40 changes: 37 additions & 3 deletions litex/soc/software/bios/Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -2,15 +2,46 @@ include ../include/generated/variables.mak
include $(SOC_DIRECTORY)/software/common.mak

ifeq ($(CPU),blackparrot)
BP_LIBS = -L$(BP_EXTERNAL_DIR)/lib/gcc/riscv64-unknown-elf/8.3.0
BP_LIBS = -L$(BP_EXTERNAL_DIR)/lib/gcc/riscv64-unknown-elf/8.3.0
BP_FLAGS = -lgcc
endif
# Permit TFTP_SERVER_PORT override from shell environment / command line
ifdef TFTP_SERVER_PORT
CFLAGS += -DTFTP_SERVER_PORT=$(TFTP_SERVER_PORT)
endif

OBJECTS=isr.o sdram.o sdcard.o main.o boot-helper.o boot.o
OBJECTS = isr.o \
sdram.o \
sdcard.o \
main.o \
boot-helper.o \
boot.o \
helpers.o \
cmd_bios.o \
cmd_boot.o \
cmd_dram.o \
cmd_mdio.o \
cmd_mem_access.o \
cmd_sdcard.o \
cmd_spi_flash.o \
cmd_usddrphy.o

ifneq "$(or $(TERM_NO_COMPLETE),$(TERM_MINI))" ""
CFLAGS += -DTERM_NO_COMPLETE
else
OBJECTS += complete.o
endif

ifdef TERM_NO_HIST
CFLAGS += -DTERM_NO_HIST
endif

ifdef TERM_MINI
CFLAGS += -DTERM_MINI
OBJECTS += readline_simple.o
else
OBJECTS += readline.o
endif

all: bios.bin
$(PYTHON) -m litex.soc.software.memusage bios.elf $(CURDIR)/../include/generated/regions.ld $(TRIPLE)
Expand Down Expand Up @@ -39,7 +70,7 @@ bios.elf: $(BIOS_DIRECTORY)/linker.ld $(OBJECTS)
$(BP_LIBS) \
-lnet -lbase-nofloat -lcompiler_rt \
$(BP_FLAGS)

ifneq ($(OS),Windows_NT)
chmod -x $@
endif
Expand All @@ -50,6 +81,9 @@ endif
%.o: $(BIOS_DIRECTORY)/%.c
$(compile)

%.o: $(BIOS_DIRECTORY)/commands/%.c
$(compile)

%.o: $(BIOS_DIRECTORY)/%.S
$(assemble)

Expand Down
49 changes: 49 additions & 0 deletions litex/soc/software/bios/command.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,49 @@
// This file is Copyright (c) 2020 Franck Jullien <franck.jullien@gmail.com>

// SPDX-License-Identifier: BSD-Source-Code

#ifndef __COMMAND_H__
#define __COMMAND_H__

#define MAX_PARAM 8

#define HIST_DEPTH 10 /* Used in string list, complete.c */

#define MISC_CMDS 0
#define SYSTEM_CMDS 1
#define CACHE_CMDS 2
#define BOOT_CMDS 3
#define DRAM_CMDS 4
#define MDIO_CMDS 5
#define MEM_CMDS 6
#define SD_CMDS 7
#define SPIFLASH_CMDS 8
#define DDR_CMDS 9
#define NB_OF_GROUPS 10

typedef void (*cmd_handler)(int nb_params, char **params);

struct command_struct {
void (*func)(int nb_params, char **params);
const char *name;
const char *help;
int group;
};

extern struct command_struct *const __bios_cmd_start[];
extern struct command_struct *const __bios_cmd_end[];

#define define_command(cmd_name, handler, help_txt, group_id) \
struct command_struct s_##cmd_name = { \
.func = (cmd_handler)handler, \
.name = #cmd_name, \
.help = help_txt, \
.group = group_id, \
}; \
const struct command_struct *__bios_cmd_##cmd_name __attribute__((__used__)) \
__attribute__((__section__(".bios_cmd"))) = &s_##cmd_name


struct command_struct *command_dispatcher(char *command, int nb_params, char **params);

#endif
125 changes: 125 additions & 0 deletions litex/soc/software/bios/commands/cmd_bios.c
Original file line number Diff line number Diff line change
@@ -0,0 +1,125 @@
// SPDX-License-Identifier: BSD-Source-Code

#include <stdio.h>
#include <stdlib.h>

#include <id.h>
#include <generated/csr.h>
#include <crc.h>
#include <system.h>

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

/**
* Command "help"
*
* Print a list of available commands with their help text
*
*/
static void help_handler(int nb_params, char **params)
{
struct command_struct * const *cmd;
int i, not_empty;

puts("\nLiteX BIOS, available commands:\n");

for (i = 0; i < NB_OF_GROUPS; i++) {
not_empty = 0;
for (cmd = __bios_cmd_start; cmd != __bios_cmd_end; cmd++) {
if ((*cmd)->group == i) {
printf("%-16s - %s\n", (*cmd)->name, (*cmd)->help ? (*cmd)->help : "-");
not_empty = 1;
}
}
if (not_empty)
printf("\n");
}
}

define_command(help, help_handler, "Print this help", MISC_CMDS);

/**
* Command "ident"
*
* Print SoC identyifier if available
*
*/
static void ident_helper(int nb_params, char **params)
{
char buffer[IDENT_SIZE];

get_ident(buffer);
printf("Ident: %s", *buffer ? buffer : "-");
}

define_command(ident, ident_helper, "Display identifier", SYSTEM_CMDS);

/**
* Command "reboot"
*
* Reboot the system
*
*/
#ifdef CSR_CTRL_BASE
static void reboot(int nb_params, char **params)
{
ctrl_reset_write(1);
}

define_command(reboot, reboot, "Reset processor", SYSTEM_CMDS);
#endif

/**
* Command "crc"
*
* Compute CRC32 over an address range
*
*/
static void crc(int nb_params, char **params)
{
char *c;
unsigned int addr;
unsigned int length;

if (nb_params < 2) {
printf("crc <address> <length>");
return;
}

addr = strtoul(params[0], &c, 0);
if (*c != 0) {
printf("Incorrect address");
return;
}

length = strtoul(params[1], &c, 0);
if (*c != 0) {
printf("Incorrect length");
return;
}

printf("CRC32: %08x", crc32((unsigned char *)addr, length));
}

define_command(crc, crc, "Compute CRC32 of a part of the address space", MISC_CMDS);

/**
* Command "flush_cpu_dcache"
*
* Flush CPU data cache
*
*/

define_command(flush_cpu_dcache, flush_cpu_dcache, "Flush CPU data cache", CACHE_CMDS);

/**
* Command "flush_l2_cache"
*
* Flush L2 cache
*
*/
#ifdef CONFIG_L2_SIZE
define_command(flush_l2_cache, flush_l2_cache, "Flush L2 cache", CACHE_CMDS);
#endif

59 changes: 59 additions & 0 deletions litex/soc/software/bios/commands/cmd_boot.c
Original file line number Diff line number Diff line change
@@ -0,0 +1,59 @@
// SPDX-License-Identifier: BSD-Source-Code

#include <stdio.h>
#include <stdlib.h>

#include <generated/csr.h>

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

/**
* Command "flashboot"
*
* Boot software from flash
*
*/
#ifdef FLASH_BOOT_ADDRESS
define_command(flashboot, flashboot, "Boot from flash", BOOT_CMDS);
#endif

/**
* Command "romboot"
*
* Boot software from embedded rom
*
*/
#ifdef ROM_BOOT_ADDRESS
define_command(romboot, romboot, "Boot from embedded rom", BOOT_CMDS);
#endif

/**
* Command "serialboot"
*
* Boot software from serial interface
*
*/
define_command(serialboot, serialboot, "Boot via SFL", BOOT_CMDS);

/**
* Command "netboot"
*
* Boot software from TFTP server
*
*/
#ifdef CSR_ETHMAC_BASE
define_command(netboot, netboot, "Boot via TFTP", BOOT_CMDS);
#endif

/**
* Command "spisdcardboot"
*
* Boot software from SDcard
*
*/
#ifdef CSR_SPISDCARD_BASE
define_command(spisdcardboot, spisdcardboot, "Boot from SDCard via SPI hardware bitbang", BOOT_CMDS);
#endif

Loading