From 80bd4ac4ecd756db755b1f758f0b59052402340c Mon Sep 17 00:00:00 2001 From: Florent Kermarrec Date: Wed, 24 Feb 2021 11:40:40 +0100 Subject: [PATCH] bios: Add boot command to be able to boot directly from system memory. This is useful for un-usual boot sequences where the binaries are not loaded directly by the BIOS but externally (over a bridge for example). Example of use: $litex_sim $litex_bare_metal_demo --build-path=build/sim $litex_sim --ram-init=demo.bin Press Esc during the LiteX boot. litex> help LiteX BIOS, available commands: flush_cpu_dcache - Flush CPU data cache crc - Compute CRC32 of a part of the address space ident - Identifier of the system help - Print this help serialboot - Boot from Serial (SFL) romboot - Boot from ROM reboot - Reboot boot - Boot from Memory mem_speed - Test memory speed mem_test - Test memory access mem_copy - Copy address space mem_write - Write address space mem_read - Read address space mem_list - List available memory regions litex> litex> mem_list Available memory regions: ROM 0x00000000 0x8000 SRAM 0x01000000 0x2000 MAIN_RAM 0x40000000 0x10000000 CSR 0x82000000 0x10000 litex> litex> boot 0x40000000 Executing booted program at 0x40000000 --============= Liftoff! ===============-- LiteX minimal demo app built Feb 24 2021 11:30:05 Available commands: help - Show this command reboot - Reboot CPU donut - Spinning Donut demo litex-demo-app> --- litex/soc/software/bios/boot.c | 2 +- litex/soc/software/bios/boot.h | 2 + litex/soc/software/bios/cmds/cmd_boot.c | 52 +++++++++++++++++++++++++ 3 files changed, 55 insertions(+), 1 deletion(-) diff --git a/litex/soc/software/bios/boot.c b/litex/soc/software/bios/boot.c index d4c66e84e..501b8a4d5 100644 --- a/litex/soc/software/bios/boot.c +++ b/litex/soc/software/bios/boot.c @@ -48,7 +48,7 @@ extern void boot_helper(unsigned long r1, unsigned long r2, unsigned long r3, unsigned long addr); -static void __attribute__((noreturn)) boot(unsigned long r1, unsigned long r2, unsigned long r3, unsigned long addr) +void __attribute__((noreturn)) boot(unsigned long r1, unsigned long r2, unsigned long r3, unsigned long addr) { printf("Executing booted program at 0x%08lx\n\n", addr); printf("--============= \e[1mLiftoff!\e[0m ===============--\n"); diff --git a/litex/soc/software/bios/boot.h b/litex/soc/software/bios/boot.h index 5b783fba5..59234d7b2 100644 --- a/litex/soc/software/bios/boot.h +++ b/litex/soc/software/bios/boot.h @@ -4,6 +4,8 @@ void set_local_ip(const char * ip_address); void set_remote_ip(const char * ip_address); void set_mac_addr(const char * mac_address); + +void __attribute__((noreturn)) boot(unsigned long r1, unsigned long r2, unsigned long r3, unsigned long addr); int serialboot(void); void netboot(void); void flashboot(void); diff --git a/litex/soc/software/bios/cmds/cmd_boot.c b/litex/soc/software/bios/cmds/cmd_boot.c index 24743bf15..ed3061cb0 100644 --- a/litex/soc/software/bios/cmds/cmd_boot.c +++ b/litex/soc/software/bios/cmds/cmd_boot.c @@ -9,6 +9,58 @@ #include "../helpers.h" #include "../boot.h" +/** + * Command "boot" + * + * Boot software from system memory + * + */ + +static void boot_handler(int nb_params, char **params) +{ + char *c; + unsigned long addr; + unsigned long r1; + unsigned long r2; + unsigned long r3; + + if (nb_params < 1) { + printf("boot
[r1] [r2] [r3]"); + return; + } + addr = strtoul(params[0], &c, 0); + if (*c != 0) { + printf("Incorrect address"); + return; + } + r1 = 0; + if (nb_params > 1) { + r1 = strtoul(params[1], &c, 0); + if (*c != 0) { + printf("Incorrect r1"); + return; + } + } + r2 = 0; + if (nb_params > 2) { + r2 = strtoul(params[2], &c, 0); + if (*c != 0) { + printf("Incorrect r2"); + return; + } + } + r3 = 0; + if (nb_params > 3) { + r2 = strtoul(params[3], &c, 0); + if (*c != 0) { + printf("Incorrect r3"); + return; + } + } + boot(r1, r2, r3, addr); +} +define_command(boot, boot_handler, "Boot from Memory", BOOT_CMDS); + /** * Command "reboot" *