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

Should be possible to build with a RISC-V Linux toolchain #4

Open
tpetazzoni opened this issue May 1, 2021 · 4 comments
Open

Should be possible to build with a RISC-V Linux toolchain #4

tpetazzoni opened this issue May 1, 2021 · 4 comments

Comments

@tpetazzoni
Copy link

Right now, building the ddrinit code requires using the bare-metal toolchain provided from Sifive, it references a nano.spec gcc spec file that is apparently only available in the Sifive bare-metal toolchain. It should however be possible to build the ddrinit code with a regular Linux toolchain for RISC-V. This will make life much simpler for build systems such as Yocto/Buildroot. Both OpenSBI and U-Boot, while being bare-metal code, build perfectly fine with a Linux toolchain.

@davidlt
Copy link

davidlt commented May 1, 2021

nano.spec comes from newlib-nano, which might be available as a package in Debian at least.

See discussion here: starfive-tech/JH7100_secondBoot#3

@sndwvs
Copy link

sndwvs commented Dec 17, 2021

for ddrinit the flags are slightly different

--- a/build/Makefile    2021-12-16 17:37:22.457037194 +0200
+++ b/build/Makefile    2021-12-16 17:48:42.878889216 +0200
@@ -2,11 +2,11 @@
 # Copyright (c) 2020 StarFiveTech, Inc
 
 # compiler tool chain
-CROSSCOMPILE?=riscv64-unknown-elf-
-CC=${CROSSCOMPILE}gcc
-LD=${CROSSCOMPILE}ld
-OBJCOPY=${CROSSCOMPILE}objcopy
-OBJDUMP=${CROSSCOMPILE}objdump
+CROSS_COMPILE?=riscv64-unknown-elf-
+CC=${CROSS_COMPILE}gcc
+LD=${CROSS_COMPILE}ld
+OBJCOPY=${CROSS_COMPILE}objcopy
+OBJDUMP=${CROSS_COMPILE}objdump
 
 # SoC IS JH7100 FOR VISIONFIVE OR BEAGLEV OR EVBV1 
 SoC=JH7100
@@ -35,10 +35,11 @@
 CFLAGS += -march=$(RISCV_ARCH)
 CFLAGS += -mabi=$(RISCV_ABI)
 CFLAGS += -mcmodel=medany
+CFLAGS += -ffreestanding
 CFLAGS += $(INCLUDE_DIR)
 CCASFLAGS= -mcmodel=medany -mexplicit-relocs   
                                        
-LDFLAGS = -march=$(RISCV_ARCH) -mabi=$(RISCV_ABI)-T $(LINKER_SCRIPT) -nostartfiles --specs=nano.specs -Wl,-Map,$(MAP_FILE)
+LDFLAGS = -march=$(RISCV_ARCH) -mabi=$(RISCV_ABI)-T $(LINKER_SCRIPT) -nostartfiles -lgcc -Wl,-Map,$(MAP_FILE),--build-id=none
 
 # object list
 OBJECTLIST=../boot/start.o\

@orangecms
Copy link

Hi, I'm rewriting this here in Rust for oreboot, which can then just be built with the default Rust toolchain. There is a lot of unnecessary code in this repo that is not about DRAM, e.g., SDIO and GPT. I will only translate the many magic values written to the many registers.

@orangecms
Copy link

orangecms commented Apr 25, 2023

Just FYI: The rewrite works fine. I've been using it all along; pending in this PR: oreboot/oreboot#606

With the JH7100 no longer produced (as it seems?), it may sound a bit odd to have gone through the effort. However, it turns out that the successor JH7110 has the same DRAM controller and PHY, just with some slightly different parameters, so we're working on that now, porting it over from StarFive's U-Boot code. Ours is orders of magnitude smaller and more efficient (only 25% binary size!). We will have SBI included in a single stage and hand over to LinuxBoot directly. Some minor issue remains though, likely with clocks. Otherwise, we're quite done:
oreboot/oreboot#686
You're welcome to join the effort!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

4 participants