From 222848298f55d9f85b2fecaab097ccac8b479034 Mon Sep 17 00:00:00 2001 From: Andrew Dennison Date: Thu, 29 Feb 2024 12:41:28 +1100 Subject: [PATCH] software/bios: add target hooks This allows the target to supply custom target_init() and target_boot() functions, eg: # add custom target specific library to the bios: src="libtarget" src_dir = os.path.abspath(os.path.join(os.path.dirname(__file__), src)) builder.add_software_package(src, src_dir) builder.add_software_library(src) --- litex/soc/software/bios/boot.c | 8 +++++--- litex/soc/software/bios/boot.h | 3 +++ litex/soc/software/bios/main.c | 6 ++++++ 3 files changed, 14 insertions(+), 3 deletions(-) diff --git a/litex/soc/software/bios/boot.c b/litex/soc/software/bios/boot.c index 67abc88c2..bcd72f0ba 100755 --- a/litex/soc/software/bios/boot.c +++ b/litex/soc/software/bios/boot.c @@ -580,7 +580,7 @@ void netboot(int nb_params, char **params) /* Flash Boot */ /*-----------------------------------------------------------------------*/ -#ifdef FLASH_BOOT_ADDRESS +#if defined(FLASH_BOOT_ADDRESS) || defined(MAIN_RAM_BASE) static unsigned int check_image_in_flash(unsigned int base_address) { @@ -603,9 +603,10 @@ static unsigned int check_image_in_flash(unsigned int base_address) return length; } +#endif -#if defined(MAIN_RAM_BASE) && defined(FLASH_BOOT_ADDRESS) -static int copy_image_from_flash_to_ram(unsigned int flash_address, unsigned long ram_address) +#if defined(MAIN_RAM_BASE) +int copy_image_from_flash_to_ram(unsigned int flash_address, unsigned long ram_address) { uint32_t length; uint32_t offset; @@ -632,6 +633,7 @@ static int copy_image_from_flash_to_ram(unsigned int flash_address, unsigned lon } #endif +#if defined(FLASH_BOOT_ADDRESS) void flashboot(void) { uint32_t length; diff --git a/litex/soc/software/bios/boot.h b/litex/soc/software/bios/boot.h index 338312d09..9128292b1 100644 --- a/litex/soc/software/bios/boot.h +++ b/litex/soc/software/bios/boot.h @@ -12,5 +12,8 @@ void flashboot(void); void romboot(void); void sdcardboot(void); void sataboot(void); +extern void target_init(void) __attribute__((weak)); +extern void target_boot(void) __attribute__((weak)); +extern int copy_image_from_flash_to_ram(unsigned int flash_address, unsigned long ram_address); #endif /* __BOOT_H */ diff --git a/litex/soc/software/bios/main.c b/litex/soc/software/bios/main.c index e576b6878..5e4d9abfb 100644 --- a/litex/soc/software/bios/main.c +++ b/litex/soc/software/bios/main.c @@ -57,6 +57,8 @@ static void boot_sequence(void) if (serialboot() == 0) return; #endif + if (target_boot) + target_boot(); #ifdef FLASH_BOOT_ADDRESS flashboot(); #endif @@ -297,6 +299,10 @@ __attribute__((__used__)) int main(int i, char **c) /* Execute initialization functions */ init_dispatcher(); + /* Execute any target specific initialisation (if linked) */ + if (target_init) + target_init(); + /* Execute Boot sequence */ #ifndef CONFIG_BIOS_NO_BOOT if(sdr_ok) {