diff --git a/build/jam/images/MMCImage b/build/jam/images/MMCImage index b4bfff6ca8..0d9df0ded3 100644 --- a/build/jam/images/MMCImage +++ b/build/jam/images/MMCImage @@ -132,7 +132,7 @@ for platform in [ MultiBootSubDirSetup ] { on $(platform) { # SD/mmc image targets if $(TARGET_BOOT_PLATFORM) = efi { - if $(TARGET_ARCH) = arm || $(TARGET_ARCH) = arm64 { + if $(TARGET_ARCH) = arm || $(TARGET_ARCH) = arm64 || $(TARGET_ARCH) = riscv64 { # These EFI platforms need u-boot to get them going BuildSDImage $(HAIKU_MMC_NAME) : $(HAIKU_IMAGE) haiku_loader.$(TARGET_BOOT_PLATFORM) diff --git a/data/boot/u-boot/boot-riscv64.scr.txt b/data/boot/u-boot/boot-riscv64.scr.txt new file mode 100644 index 0000000000..ba8b12e848 --- /dev/null +++ b/data/boot/u-boot/boot-riscv64.scr.txt @@ -0,0 +1,17 @@ +echo "Haiku u-boot script entry" +test -e mmc 0 uEnv.txt && setenv media mmc +test -e virtio 0 uEnv.txt && setenv media virtio +test -e nvme 0 uEnv.txt && setenv media nvme +env exists media || echo "ERROR: Unable to locate uEnv.txt on any known media!" && exit +test -e ${media} 0 uEnv.txt && fatload ${media} 0 ${scriptaddr} uEnv.txt && env import -t ${scriptaddr} ${filesize} +env exists loader || echo "ERROR: uEnv.txt doesn't specify bootloader!" && exit +env exists platform || echo "ERROR: uEnv.txt doesn't specify platform!" && exit +echo "uEnv.txt says to look for ${platform} bootloader named ${loader} on ${media} 0!" +test -e ${media} 0 ${loader} && echo "Found ${loader} on ${media} 0!" +echo "Loading bootloader..." +fatload ${media} 0 ${kernel_addr_r} ${loader} +test -e ${media} 0 haiku_floppyboot.ub && fatload ${media} 0 ${ramdisk_addr_r} haiku_floppyboot.ub +env exists dtb && echo "Using custom DTB..." && fatload ${media} 0 ${fdt_addr_r} ${dtb} && fdt addr ${fdt_addr_r} +env exists dtb || echo "Using internal DTB..." && fdt addr ${fdtcontroladdr} +test "${platform}" = "efi" && echo "Launching EFI loader..." && bootefi ${kernel_addr_r} +echo "Haiku u-boot script fell through!" && exit diff --git a/src/system/boot/Jamfile b/src/system/boot/Jamfile index 84f2ca8f53..84784224b5 100644 --- a/src/system/boot/Jamfile +++ b/src/system/boot/Jamfile @@ -167,13 +167,19 @@ rule BuildUImageScript script : source LocalClean clean : $(script) ; SCRIPTNAME on $(script) = $(script) ; FAKEOS on $(script) = "linux" ; + ARCH on $(script) = $(TARGET_ARCH) ; + + if $(TARGET_ARCH) = "riscv64" || $(TARGET_ARCH) = "riscv32" { + ARCH on $(script) = "riscv" ; + } + BuildUImageScript1 $(script) : $(source) ; } actions BuildUImageScript1 { rm -f $(1) - mkimage -A $(TARGET_ARCH) -O $(FAKEOS) -T script -C none -n $(SCRIPTNAME) \ + mkimage -A $(ARCH) -O $(FAKEOS) -T script -C none -n $(SCRIPTNAME) \ -d $(2) $(1) } @@ -336,7 +342,7 @@ for platform in [ MultiBootSubDirSetup ] { switch $(TARGET_BOOT_PLATFORM) { case efi : BuildEFILoader haiku_loader.$(TARGET_BOOT_PLATFORM) : boot_loader_$(TARGET_BOOT_PLATFORM) ; - if $(TARGET_ARCH) = arm || $(TARGET_ARCH) = arm64 { + if $(TARGET_ARCH) = arm || $(TARGET_ARCH) = arm64 || $(TARGET_ARCH) = riscv64 { # These EFI platforms need u-boot to get them going BuildUImageScript boot.scr : [ FDirName $(HAIKU_TOP) data boot u-boot boot-$(TARGET_ARCH).scr.txt ] ; diff --git a/src/system/boot/platform/efi/arch/riscv64/crt0-efi-riscv64.S b/src/system/boot/platform/efi/arch/riscv64/crt0-efi-riscv64.S index 6b034e8a62..c97ea9a657 100644 --- a/src/system/boot/platform/efi/arch/riscv64/crt0-efi-riscv64.S +++ b/src/system/boot/platform/efi/arch/riscv64/crt0-efi-riscv64.S @@ -45,7 +45,7 @@ coff_header: .short 2 // nr_sections .long 0 // TimeDateStamp .long 0 // PointerToSymbolTable - .long 1 // NumberOfSymbols + .long 0 // NumberOfSymbols .short section_table - optional_header // SizeOfOptionalHeader .short 0x206 // Characteristics. // IMAGE_FILE_DEBUG_STRIPPED | @@ -135,22 +135,23 @@ section_table: .globl _start _start: /* Save boot parameters to the stack */ - addi sp, sp, -16 + addi sp, sp, -24 sd a0, 0(sp) sd a1, 8(sp) + sd ra, 16(sp) /* Run relocation */ lla a0, ImageBase - lla a1, .L_DYNAMIC + lla a1, _DYNAMIC call _relocate + bne a0, zero, 0f /* Call EFI code */ ld a1, 8(sp) ld a0, 0(sp) - tail efi_main + call efi_main -2: wfi - j 2b + ld ra, 16(sp) -.L_DYNAMIC: - .word _DYNAMIC - . +0: addi sp, sp, 24 + ret