hw/riscv: Add support for loading a firmware

Add support for loading a firmware file for the virt machine and the
SiFive U. This can be run with the following command:

    qemu-system-riscv64 -machine virt -bios fw_jump.bin -kernel vmlinux

Signed-off-by: Alistair Francis <alistair.francis@wdc.com>
Reviewed-by: Bin Meng <bmeng.cn@gmail.com>
Tested-by: Bin Meng <bmeng.cn@gmail.com>
Signed-off-by: Palmer Dabbelt <palmer@sifive.com>
This commit is contained in:
Alistair Francis 2019-06-24 15:11:52 -07:00 committed by Palmer Dabbelt
parent 0ac24d56c5
commit b30422231b
No known key found for this signature in database
GPG key ID: EF4CA1502CCBAB41
4 changed files with 36 additions and 0 deletions

View file

@ -23,8 +23,34 @@
#include "exec/cpu-defs.h"
#include "hw/loader.h"
#include "hw/riscv/boot.h"
#include "hw/boards.h"
#include "elf.h"
#if defined(TARGET_RISCV32)
# define KERNEL_BOOT_ADDRESS 0x80400000
#else
# define KERNEL_BOOT_ADDRESS 0x80200000
#endif
target_ulong riscv_load_firmware(const char *firmware_filename,
hwaddr firmware_load_addr)
{
uint64_t firmware_entry, firmware_start, firmware_end;
if (load_elf(firmware_filename, NULL, NULL, NULL, &firmware_entry,
&firmware_start, &firmware_end, 0, EM_RISCV, 1, 0) > 0) {
return firmware_entry;
}
if (load_image_targphys_as(firmware_filename, firmware_load_addr,
ram_size, NULL) > 0) {
return firmware_load_addr;
}
error_report("could not load firmware '%s'", firmware_filename);
exit(1);
}
target_ulong riscv_load_kernel(const char *kernel_filename)
{
uint64_t kernel_entry, kernel_high;