diff --git a/litex/soc/software/bios/boot.c b/litex/soc/software/bios/boot.c index 7c62409e42..bcd72f0ba4 100755 --- a/litex/soc/software/bios/boot.c +++ b/litex/soc/software/bios/boot.c @@ -7,6 +7,7 @@ // This file is Copyright (c) 2018 William D. Jones // License: BSD +#include #include #include #include @@ -579,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) { @@ -589,29 +590,30 @@ static unsigned int check_image_in_flash(unsigned int base_address) length = MMPTR(base_address); if((length < 32) || (length > 16*1024*1024)) { - printf("Error: Invalid image length 0x%08x\n", length); + printf("Error: Invalid image length 0x%" PRIx32 "\n", length); return 0; } crc = MMPTR(base_address + 4); got_crc = crc32((unsigned char *)(base_address + 8), length); if(crc != got_crc) { - printf("CRC failed (expected %08x, got %08x)\n", crc, got_crc); + printf("CRC failed (expected 0x%" PRIx32 ", got 0x%" PRIx32 ")\n", crc, got_crc); return 0; } 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; length = check_image_in_flash(flash_address); if(length > 0) { - printf("Copying 0x%08x to 0x%08lx (%d bytes)...\n", flash_address, ram_address, length); + printf("Copying 0x%08x to 0x%08lx (%" PRIu32 " bytes)...\n", flash_address, ram_address, length); offset = 0; init_progression_bar(length); while (length > 0) { @@ -631,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 338312d090..9128292b17 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/cmds/cmd_bios.c b/litex/soc/software/bios/cmds/cmd_bios.c index 5acf671403..db6d1cbf0b 100644 --- a/litex/soc/software/bios/cmds/cmd_bios.c +++ b/litex/soc/software/bios/cmds/cmd_bios.c @@ -73,13 +73,13 @@ define_command(ident, ident_handler, "Identifier of the system", SYSTEM_CMDS); #ifdef CSR_TIMER0_UPTIME_CYCLES_ADDR static void uptime_handler(int nb_params, char **params) { - unsigned long uptime; + uint64_t uptime; timer0_uptime_latch_write(1); uptime = timer0_uptime_cycles_read(); - printf("Uptime: %ld sys_clk cycles / %ld seconds", - uptime, - uptime/CONFIG_CLOCK_FREQUENCY + printf("Uptime: %" PRIu64 " sys_clk cycles / %" PRIu64 " seconds\n", + uptime, + uptime / CONFIG_CLOCK_FREQUENCY ); } diff --git a/litex/soc/software/bios/main.c b/litex/soc/software/bios/main.c index e576b6878c..5e4d9abfb5 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) {