[haiku-commits] Change in haiku[master]: riscv64/boot: Add same u-boot potential that arm has, drop L_DYNAMIC

  • From: Gerrit <review@xxxxxxxxxxxxxxxxxxx>
  • To: waddlesplash <waddlesplash@xxxxxxxxx>, haiku-commits@xxxxxxxxxxxxx
  • Date: Thu, 27 Aug 2020 15:33:22 +0000

From Alex von Gluck IV <kallisti5@xxxxxxxxxxx>:

Alex von Gluck IV has uploaded this change for review. ( 
https://review.haiku-os.org/c/haiku/+/3176 ;)


Change subject: riscv64/boot: Add same u-boot potential that arm has, drop 
L_DYNAMIC
......................................................................

riscv64/boot: Add same u-boot potential that arm has, drop L_DYNAMIC

* Tianocore is still in an early state for RISCV64 with a lot of work
  needed around qemu support.
* u-boot however is working, and can load EFI binaries... so follow the
  arm model for now. (EFI via u-boot, or EFI via EFI Bios)

Change-Id: I3dfde25db17b114aedce6faefc58d7556e17a46a
---
M build/jam/images/MMCImage
A data/boot/u-boot/boot-riscv64.scr.txt
M src/system/boot/Jamfile
M src/system/boot/platform/efi/arch/riscv64/crt0-efi-riscv64.S
4 files changed, 35 insertions(+), 11 deletions(-)



  git pull ssh://git.haiku-os.org:22/haiku refs/changes/76/3176/1

diff --git a/build/jam/images/MMCImage b/build/jam/images/MMCImage
index b4bfff6..0d9df0d 100644
--- a/build/jam/images/MMCImage
+++ b/build/jam/images/MMCImage
@@ -132,7 +132,7 @@
        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 0000000..ba8b12e
--- /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 84f2ca8..8478422 100644
--- a/src/system/boot/Jamfile
+++ b/src/system/boot/Jamfile
@@ -167,13 +167,19 @@
        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 @@
                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 6b034e8..c97ea9a 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 @@
        .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 @@
        .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

--
To view, visit https://review.haiku-os.org/c/haiku/+/3176
To unsubscribe, or for help writing mail filters, visit 
https://review.haiku-os.org/settings

Gerrit-Project: haiku
Gerrit-Branch: master
Gerrit-Change-Id: I3dfde25db17b114aedce6faefc58d7556e17a46a
Gerrit-Change-Number: 3176
Gerrit-PatchSet: 1
Gerrit-Owner: Alex von Gluck IV <kallisti5@xxxxxxxxxxx>
Gerrit-MessageType: newchange

Other related posts:

  • » [haiku-commits] Change in haiku[master]: riscv64/boot: Add same u-boot potential that arm has, drop L_DYNAMIC - Gerrit