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

Target hooks #1942

Open
wants to merge 3 commits into
base: master
Choose a base branch
from
Open
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
15 changes: 9 additions & 6 deletions litex/soc/software/bios/boot.c
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@
// This file is Copyright (c) 2018 William D. Jones <thor0505@comcast.net>
// License: BSD

#include <inttypes.h>
#include <stdio.h>
#include <stdint.h>
#include <stdlib.h>
Expand Down Expand Up @@ -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)
{
Expand All @@ -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) {
Expand All @@ -631,6 +633,7 @@ static int copy_image_from_flash_to_ram(unsigned int flash_address, unsigned lon
}
#endif

#if defined(FLASH_BOOT_ADDRESS)
trabucayre marked this conversation as resolved.
Show resolved Hide resolved
void flashboot(void)
{
uint32_t length;
Expand Down
3 changes: 3 additions & 0 deletions litex/soc/software/bios/boot.h
Original file line number Diff line number Diff line change
Expand Up @@ -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));
Comment on lines +15 to +16
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

why not something like:

void target_nop() {}
void target_init(void) __attribute__((weak, alias("target_nop")));
void target_boot(void) __attribute__((weak, alias("target_nop")));

to avoid having to test if function exist

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yes that's another alternative I onsidered.I like the fact that the test makes it's clear that it's optional, but that's personal preference.
There doesn't appear to have been any goal to minimise code size in the bios so i opted for clarity.

extern int copy_image_from_flash_to_ram(unsigned int flash_address, unsigned long ram_address);

#endif /* __BOOT_H */
8 changes: 4 additions & 4 deletions litex/soc/software/bios/cmds/cmd_bios.c
Original file line number Diff line number Diff line change
Expand Up @@ -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
);
}

Expand Down
6 changes: 6 additions & 0 deletions litex/soc/software/bios/main.c
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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) {
Expand Down
Loading