starfive-tech / JH7100_secondBoot

Other
14 stars 9 forks source link

Information of a working toolchain needed #3

Open lbmeng opened 3 years ago

lbmeng commented 3 years ago

I am using a bootlin RISC-V toolchain (GCC 10.2.0, binutils 2.34) to build second boot.

First of all, this toolchain does not support nano specs, and I had to do the following changes otherwise it cannot build.

diff --git a/build/Makefile b/build/Makefile
index ee5fc38..e70a6e8 100755
--- a/build/Makefile
+++ b/build/Makefile
@@ -37,7 +37,7 @@ CFLAGS += -mcmodel=medany
 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 -Wl,-Map,$(MAP_FILE)

 # object list
 OBJECTLIST=../boot/start.o\

With that, lots of warnings were generated during the build process, like:

In file included from ../spi/cadence_qspi_apb.c:28:
../common/comdef.h:105:51: note: expected ‘volatile void *’ but argument is of type ‘unsigned int’
  105 | static inline void writel(u32 val, volatile void *addr)
      |                                    ~~~~~~~~~~~~~~~^~~~
../spi/cadence_qspi_apb.c:948:9: warning: cast from pointer to integer of different size [-Wpointer-to-int-cast]
  948 |         (u32)plat->regbase + CQSPI_REG_INDIRECTWR);
      |         ^
../spi/cadence_qspi_apb.c:948:28: warning: passing argument 2 of ‘writel’ makes pointer from integer without a cast [-Wint-conversion]
  948 |         (u32)plat->regbase + CQSPI_REG_INDIRECTWR);
      |                            ^
      |                            |
      |                            unsigned int
In file included from ../spi/cadence_qspi_apb.c:28:

In the end the linker complains:

riscv64-buildroot-linux-gnu/bin/ld: section .rodata LMA [0000000018002200,000000001800237b] overlaps section .plt LMA [00000000180021f0,000000001800221f]
riscv64-buildroot-linux-gnu/bin/ld: section .dynamic LMA [0000000018002380,00000000180024ff] overlaps section .interp LMA [000000001800237c,000000001800239c]
riscv64-buildroot-linux-gnu/bin/ld: section .gnu.version LMA [000000001800239e,00000000180023a1] overlaps section .dynamic LMA [0000000018002380,00000000180024ff]
collect2: error: ld returned 1 exit status

I believe this is due to the reason that this toolchain does not support the nano specs, which is used to generate small footprint images. It seems size is a problem on BeagleV.

Hence the information of a working toolchain is needed.

davidlt commented 3 years ago

The SoC has SiFive U74 cores inside. Maybe try SiFive toolchain? A quick google points me to: https://github.com/sifive/freedom-tools/releases/tag/v2020.12.0

pdp7 commented 3 years ago

@yimingyiming @MichaelZhuxx could you please advise @lbmeng on how to compile secondBoot? Bin Meng is an upstream u-boot developer.

MichaelZhuxx commented 3 years ago

@pdp7 @lbmeng we use sifive tools as @davidlt and it works well.

riscv64-unknown-elf-gcc -o bootloader-EVBV1-210430.elf  -march=rv64imafdc -mabi=lp64d -T bootloader.lds -nostartfiles --specs=nano.specs -Wl,-Map,bootloader.map ../boot/start.o ../boot/bootmain.o ../boot/trap.o ../uart/uart.o ../common/util.o ../spi/spi.o ../spi/spi_probe.o ../spi/cadence_qspi.o ../spi/spi_flash.o ../spi/cadence_qspi_apb.o ../timer/timer.o
bootloader-EVBV1-210430.elf LINK SUCCEED!
riscv64-unknown-elf-objcopy -O binary bootloader-EVBV1-210430.elf bootloader-EVBV1-210430.bin
inFile: bootloader-EVBV1-210430.bin
inSize: 9276 (0x0000243c, LE:0x3c240000)
outFile: bootloader-EVBV1-210430.bin.out
outSize: 9280 (0x00002440)
riscv64-unknown-elf-objdump -S bootloader-EVBV1-210430.elf > bootloader-EVBV1-210430.asm
davidlt commented 3 years ago

Could you rework it to work properly with upstream GCC?

--specs=nano.specs is for newlib-nano that's part of SiFive GNU toolchain. Short info about it: https://keithp.com/newlib-nano/

pdp7 commented 3 years ago

@MichaelZhuxx @davidlt which version of sifive gcc toolchain do you recommend?

davidlt commented 3 years ago

Whatever is latest. I believe right now it's at 10.2.

This problem can be solved if newlib-nano is installed (I think it might be even packaged on Debian). Alternative would be to attempt without newlib-nano if size is not a concern. There shouldn't be a need for SiFive toolchain here.

esmil commented 3 years ago

It seems like it doesn't actually use anything from newlib. This still compiles:

diff --git build/Makefile build/Makefile
index ee5fc38..8425d56 100755
--- build/Makefile
+++ build/Makefile
@@ -1,11 +1,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

 # BOARD IS BEAGLEV OR EVBV1
 BOARD=EVBV1
@@ -34,10 +34,11 @@ CFLAGS += -O2 -g -c -Wall -DVERSION=\"$(BLD_VERSION)\" -D$(BOARD)
 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) -nostdlib -lgcc -Wl,-Map,$(MAP_FILE),--build-id=none

 # object list
 OBJECTLIST=../boot/start.o\

This also compiles with make CROSS_COMPILE=riscv64-linux-gnu- for me.

esmil commented 3 years ago

@lbmeng Sorry, I should have read your original post properly before posting above. Compared to my patch I think you just need to tell the linker to not add the build-id. Eg -Wl,--build-id=none

MichaelZhuxx commented 3 years ago

according to @davidlt advice, add this compile to PATH, here is the version:

michael@michael-KVM-1804:~/work/starfive-github/beagle_secondBoot/build$ riscv64-unknown-elf-gcc -v
Using built-in specs.
COLLECT_GCC=riscv64-unknown-elf-gcc
COLLECT_LTO_WRAPPER=/home/michael/work/riscv64-unknown-elf-toolchain-10.2.0-2020.12.8-x86_64-linux-ubuntu14/bin/../libexec/gcc/riscv64-unknown-elf/10.2.0/lto-wrapper
Target: riscv64-unknown-elf
Configured with: /scratch/jenkins/workspace/tpp-freedom-tools/tpp03--build-binary-packages--parameterized/obj/x86_64-linux-ubuntu14/build/riscv64-unknown-elf-gcc/riscv-gcc/configure --target=riscv64-unknown-elf --host=x86_64-linux-gnu --prefix=/scratch/jenkins/workspace/tpp-freedom-tools/tpp03--build-binary-packages--parameterized/obj/x86_64-linux-ubuntu14/install/riscv64-unknown-elf-gcc-10.2.0-2020.12.8-x86_64-linux-ubuntu14 --with-pkgversion='SiFive GCC-Metal 10.2.0-2020.12.8' --with-bugurl=https://github.com/sifive/freedom-tools/issues --disable-shared --disable-threads --enable-languages=c,c++ --enable-tls --with-newlib --with-sysroot=/scratch/jenkins/workspace/tpp-freedom-tools/tpp03--build-binary-packages--parameterized/obj/x86_64-linux-ubuntu14/install/riscv64-unknown-elf-gcc-10.2.0-2020.12.8-x86_64-linux-ubuntu14/riscv64-unknown-elf --with-native-system-header-dir=/include --disable-libmudflap --disable-libssp --disable-libquadmath --disable-libgomp --disable-nls --disable-tm-clone-registry --src=../riscv-gcc --with-system-zlib --enable-checking=yes --enable-multilib --with-abi=lp64d --with-arch=rv64imafdc CFLAGS=-O2 CXXFLAGS=-O2 'CFLAGS_FOR_TARGET=-Os -mcmodel=medany' 'CXXFLAGS_FOR_TARGET=-Os -mcmodel=medany'
Thread model: single
Supported LTO compression algorithms: zlib
gcc version 10.2.0 (SiFive GCC-Metal 10.2.0-2020.12.8)

then do make in build directory, new binary was generated like bootloader-BEAGLEV-21xxxx.bin.out

michael@michael-KVM-1804:~/work/starfive-github/beagle_secondBoot/build$ ll
total 944
drwxrwxr-x 2 michael michael   4096 4月  30 23:37 ./
drwxrwxr-x 9 michael michael   4096 4月  30 00:15 ../
-rw-rw-r-- 1 michael michael   8516 4月  30 00:15 bootloader-BEAGLEV-210209.bin.out
-rw-rw-r-- 1 michael michael 242379 4月  30 23:37 bootloader-BEAGLEV-210430.asm
-rwxrwxr-x 1 michael michael   9404 4月  30 23:37 bootloader-BEAGLEV-210430.bin*
-rw-rw-r-- 1 michael michael   9408 4月  30 23:37 bootloader-BEAGLEV-210430.bin.out
-rwxrwxr-x 1 michael michael 165160 4月  30 23:37 bootloader-BEAGLEV-210430.elf*

after that, follow the instructions from Update bootloader, ddr init boot, u-boot and Recover bootloader to update the secondboot.

here is the startup log after successful upgrade:

bootloader version:210430-44193cb
ddr 0x00000000, 1M test
ddr 0x00100000, 2M test
DDR clk 2133M,Version: 210302-5aea32f
pdp7 commented 3 years ago

@MichaelZhuxx

according to @davidlt advice, add this compile to PATH, here is the version:

michael@michael-KVM-1804:~/work/starfive-github/beagle_secondBoot/build$ riscv64-unknown-elf-gcc -v
Using built-in specs.
COLLECT_GCC=riscv64-unknown-elf-gcc
COLLECT_LTO_WRAPPER=/home/michael/work/riscv64-unknown-elf-toolchain-10.2.0-2020.12.8-x86_64-linux-ubuntu14/bin/../libexec/gcc/riscv64-unknown-elf/10.2.0/lto-wrapper
Target: riscv64-unknown-elf
Configured with: /scratch/jenkins/workspace/tpp-freedom-tools/tpp03--build-binary-packages--parameterized/obj/x86_64-linux-ubuntu14/build/riscv64-unknown-elf-gcc/riscv-gcc/configure --target=riscv64-unknown-elf --host=x86_64-linux-gnu --prefix=/scratch/jenkins/workspace/tpp-freedom-tools/tpp03--build-binary-packages--parameterized/obj/x86_64-linux-ubuntu14/install/riscv64-unknown-elf-gcc-10.2.0-2020.12.8-x86_64-linux-ubuntu14 --with-pkgversion='SiFive GCC-Metal 10.2.0-2020.12.8' --with-bugurl=https://github.com/sifive/freedom-tools/issues --disable-shared --disable-threads --enable-languages=c,c++ --enable-tls --with-newlib --with-sysroot=/scratch/jenkins/workspace/tpp-freedom-tools/tpp03--build-binary-packages--parameterized/obj/x86_64-linux-ubuntu14/install/riscv64-unknown-elf-gcc-10.2.0-2020.12.8-x86_64-linux-ubuntu14/riscv64-unknown-elf --with-native-system-header-dir=/include --disable-libmudflap --disable-libssp --disable-libquadmath --disable-libgomp --disable-nls --disable-tm-clone-registry --src=../riscv-gcc --with-system-zlib --enable-checking=yes --enable-multilib --with-abi=lp64d --with-arch=rv64imafdc CFLAGS=-O2 CXXFLAGS=-O2 'CFLAGS_FOR_TARGET=-Os -mcmodel=medany' 'CXXFLAGS_FOR_TARGET=-Os -mcmodel=medany'
Thread model: single
Supported LTO compression algorithms: zlib
gcc version 10.2.0 (SiFive GCC-Metal 10.2.0-2020.12.8)

then do make in build directory, new binary was generated like bootloader-BEAGLEV-21xxxx.bin.out

michael@michael-KVM-1804:~/work/starfive-github/beagle_secondBoot/build$ ll
total 944
drwxrwxr-x 2 michael michael   4096 4月  30 23:37 ./
drwxrwxr-x 9 michael michael   4096 4月  30 00:15 ../
-rw-rw-r-- 1 michael michael   8516 4月  30 00:15 bootloader-BEAGLEV-210209.bin.out
-rw-rw-r-- 1 michael michael 242379 4月  30 23:37 bootloader-BEAGLEV-210430.asm
-rwxrwxr-x 1 michael michael   9404 4月  30 23:37 bootloader-BEAGLEV-210430.bin*
-rw-rw-r-- 1 michael michael   9408 4月  30 23:37 bootloader-BEAGLEV-210430.bin.out
-rwxrwxr-x 1 michael michael 165160 4月  30 23:37 bootloader-BEAGLEV-210430.elf*

after that, follow the instructions from Update bootloader, ddr init boot, u-boot and Recover bootloader to update the secondboot.

here is the startup log after successful upgrade:

bootloader version:210430-44193cb
ddr 0x00000000, 1M test
ddr 0x00100000, 2M test
DDR clk 2133M,Version: 210302-5aea32f

@MichaelZhuxx What is the difference between bootloader-BEAGLEV-210209.bin.out and vic_second_boot.bin in those instructions that you linked two?

MichaelZhuxx commented 3 years ago

vic_second_boot.bin is based on beagle_secondBoot code, adding the function of upload ddrinit/secondboot binary to spi flash