diff mbox series

[v2,3/6] package/riscv64-elf-toolchain: new package

Message ID 20210502212141.934384-11-thomas.petazzoni@bootlin.com
State Not Applicable
Headers show
Series None | expand

Commit Message

Thomas Petazzoni May 2, 2021, 9:21 p.m. UTC
This commit adds a new package for a prebuilt bare-metal toolchain for
RISC-V 64-bit. Indeed, some bootloader/firmware for the BeagleV (and
potentially later for other platforms?) do not build with a
Linux-capable toolchain.

This uses a pre-built toolchain from SiFive, precompiled for x86-64,
so all packages using this toolchain must have the appropriate
BR2_HOSTARCH dependency.

This package is modeled after package/arm-gnu-a-toolchain/, which
package a pre-built ARM32 bare-metal toolchain.

Signed-off-by: Thomas Petazzoni <thomas.petazzoni@bootlin.com>
---
 DEVELOPERS                                    |  1 +
 .../riscv64-elf-toolchain.mk                  | 25 +++++++++++++++++++
 2 files changed, 26 insertions(+)
 create mode 100644 package/riscv64-elf-toolchain/riscv64-elf-toolchain.mk

Comments

Alistair Francis May 3, 2021, 12:14 a.m. UTC | #1
On Mon, May 3, 2021 at 7:24 AM Thomas Petazzoni
<thomas.petazzoni@bootlin.com> wrote:
>
> This commit adds a new package for a prebuilt bare-metal toolchain for
> RISC-V 64-bit. Indeed, some bootloader/firmware for the BeagleV (and
> potentially later for other platforms?) do not build with a
> Linux-capable toolchain.
>
> This uses a pre-built toolchain from SiFive, precompiled for x86-64,
> so all packages using this toolchain must have the appropriate
> BR2_HOSTARCH dependency.
>
> This package is modeled after package/arm-gnu-a-toolchain/, which
> package a pre-built ARM32 bare-metal toolchain.
>
> Signed-off-by: Thomas Petazzoni <thomas.petazzoni@bootlin.com>
> ---
>  DEVELOPERS                                    |  1 +
>  .../riscv64-elf-toolchain.mk                  | 25 +++++++++++++++++++
>  2 files changed, 26 insertions(+)
>  create mode 100644 package/riscv64-elf-toolchain/riscv64-elf-toolchain.mk
>
> diff --git a/DEVELOPERS b/DEVELOPERS
> index cec63a3715..7ce78742fc 100644
> --- a/DEVELOPERS
> +++ b/DEVELOPERS
> @@ -2651,6 +2651,7 @@ F:        package/python3/
>  F:     package/python-mad/
>  F:     package/python-serial/
>  F:     package/qextserialport/
> +F:     package/riscv64-elf-toolchain/
>  F:     package/rpcbind/
>  F:     package/rt-tests/
>  F:     package/rtc-tools/
> diff --git a/package/riscv64-elf-toolchain/riscv64-elf-toolchain.mk b/package/riscv64-elf-toolchain/riscv64-elf-toolchain.mk
> new file mode 100644
> index 0000000000..9b08ee0fec
> --- /dev/null
> +++ b/package/riscv64-elf-toolchain/riscv64-elf-toolchain.mk
> @@ -0,0 +1,25 @@
> +################################################################################
> +#
> +# riscv64-elf-toolchain
> +#
> +################################################################################
> +
> +RISCV64_ELF_TOOLCHAIN_VERSION = 2020.12.8
> +RISCV64_ELF_TOOLCHAIN_SITE = https://static.dev.sifive.com/dev-tools/freedom-tools/v2020.12

Could we not get an official GCC build instead of SiFives custom toolchain?

Alistair

> +RISCV64_ELF_TOOLCHAIN_SOURCE = riscv64-unknown-elf-toolchain-10.2.0-$(RISCV64_ELF_TOOLCHAIN_VERSION)-x86_64-linux-centos6.tar.gz
> +
> +HOST_RISCV64_ELF_TOOLCHAIN_INSTALL_DIR = $(HOST_DIR)/opt/riscv64-elf
> +
> +define HOST_RISCV64_ELF_TOOLCHAIN_INSTALL_CMDS
> +       rm -rf $(HOST_RISCV64_ELF_TOOLCHAIN_INSTALL_DIR)
> +       mkdir -p $(HOST_RISCV64_ELF_TOOLCHAIN_INSTALL_DIR)
> +       cp -rf $(@D)/* $(HOST_RISCV64_ELF_TOOLCHAIN_INSTALL_DIR)/
> +
> +       mkdir -p $(HOST_DIR)/bin
> +       cd $(HOST_DIR)/bin && \
> +       for i in ../opt/riscv64-elf/bin/*; do \
> +               ln -sf $$i; \
> +       done
> +endef
> +
> +$(eval $(host-generic-package))
> --
> 2.30.2
>
> _______________________________________________
> buildroot mailing list
> buildroot@busybox.net
> http://lists.busybox.net/mailman/listinfo/buildroot
Peter Korsgaard May 3, 2021, 6:17 a.m. UTC | #2
>>>>> "Thomas" == Thomas Petazzoni <thomas.petazzoni@bootlin.com> writes:

 > This commit adds a new package for a prebuilt bare-metal toolchain for
 > RISC-V 64-bit. Indeed, some bootloader/firmware for the BeagleV (and
 > potentially later for other platforms?) do not build with a
 > Linux-capable toolchain.

Out of interest, why is that? For the ARM32 case it was a question of
32bit / 64bit, but that does not seem to be the issue here?

Just crappy firmware or are there any deeper differences between a bare
metal and Linux toolchain on riscv64?
Thomas Petazzoni May 3, 2021, 6:54 a.m. UTC | #3
Hello,

On Mon, 3 May 2021 10:14:38 +1000
Alistair Francis <alistair23@gmail.com> wrote:

> > +RISCV64_ELF_TOOLCHAIN_VERSION = 2020.12.8
> > +RISCV64_ELF_TOOLCHAIN_SITE = https://static.dev.sifive.com/dev-tools/freedom-tools/v2020.12  
> 
> Could we not get an official GCC build instead of SiFives custom toolchain?

What do you call an "official GCC build" ? A toolchain built by
Buildroot from source ? Buildroot can only build a single toolchain,
which is Linux capable. Buildroot does not know how to build a separate
bare-metal toolchain, which is why in such situations we use an
existing pre-compiled toolchain.

Best regards,

Thomas
Thomas Petazzoni May 3, 2021, 6:57 a.m. UTC | #4
Hello,

On Mon, 03 May 2021 08:17:33 +0200
Peter Korsgaard <peter@korsgaard.com> wrote:

> Out of interest, why is that? For the ARM32 case it was a question of
> 32bit / 64bit, but that does not seem to be the issue here?
> 
> Just crappy firmware or are there any deeper differences between a bare
> metal and Linux toolchain on riscv64?

It is not yet 100% sure what's going on. The firmware clearly doesn't
build with a Linux toolchain. I've done a bit of work to try to get it
to build, by adding -ffrestanding -nostdinc, but it does include a few
standard headers (stdint.h for example). Once this was fixed, the build
system of the firmware uses a specific gcc spec file, called nano.spec,
which isn't available except in their bare-metal toolchain.

So for now, I opened a bug report at
https://github.com/starfive-tech/beagle_ddrlnit/issues/4, and decided
to go on with building this with the recommended bare-metal toolchain.

Best regards,

Thomas
Peter Korsgaard May 3, 2021, 7:09 a.m. UTC | #5
>>>>> "Thomas" == Thomas Petazzoni <thomas.petazzoni@bootlin.com> writes:

 > Hello,
 > On Mon, 03 May 2021 08:17:33 +0200
 > Peter Korsgaard <peter@korsgaard.com> wrote:

 >> Out of interest, why is that? For the ARM32 case it was a question of
 >> 32bit / 64bit, but that does not seem to be the issue here?
 >> 
 >> Just crappy firmware or are there any deeper differences between a bare
 >> metal and Linux toolchain on riscv64?

 > It is not yet 100% sure what's going on. The firmware clearly doesn't
 > build with a Linux toolchain. I've done a bit of work to try to get it
 > to build, by adding -ffrestanding -nostdinc, but it does include a few
 > standard headers (stdint.h for example). Once this was fixed, the build
 > system of the firmware uses a specific gcc spec file, called nano.spec,
 > which isn't available except in their bare-metal toolchain.

 > So for now, I opened a bug report at
 > https://github.com/starfive-tech/beagle_ddrlnit/issues/4, and decided
 > to go on with building this with the recommended bare-metal toolchain.

Ok, thanks for the description.
Alistair Francis May 3, 2021, 7:11 a.m. UTC | #6
On Mon, May 3, 2021 at 4:54 PM Thomas Petazzoni
<thomas.petazzoni@bootlin.com> wrote:
>
> Hello,
>
> On Mon, 3 May 2021 10:14:38 +1000
> Alistair Francis <alistair23@gmail.com> wrote:
>
> > > +RISCV64_ELF_TOOLCHAIN_VERSION = 2020.12.8
> > > +RISCV64_ELF_TOOLCHAIN_SITE = https://static.dev.sifive.com/dev-tools/freedom-tools/v2020.12
> >
> > Could we not get an official GCC build instead of SiFives custom toolchain?
>
> What do you call an "official GCC build" ? A toolchain built by
> Buildroot from source ? Buildroot can only build a single toolchain,
> which is Linux capable. Buildroot does not know how to build a separate
> bare-metal toolchain, which is why in such situations we use an
> existing pre-compiled toolchain.

I just meant something from upstream GCC and not a vendor.

Alistair

>
> Best regards,
>
> Thomas
> --
> Thomas Petazzoni, co-owner and CEO, Bootlin
> Embedded Linux and Kernel engineering
> https://bootlin.com
Thomas Petazzoni May 3, 2021, 7:13 a.m. UTC | #7
On Mon, 3 May 2021 17:11:09 +1000
Alistair Francis <alistair23@gmail.com> wrote:

> > What do you call an "official GCC build" ? A toolchain built by
> > Buildroot from source ? Buildroot can only build a single toolchain,
> > which is Linux capable. Buildroot does not know how to build a separate
> > bare-metal toolchain, which is why in such situations we use an
> > existing pre-compiled toolchain.  
> 
> I just meant something from upstream GCC and not a vendor.

But where is "upstream GCC" providing pre-compiled bare-metal toolchains?

Thomas
Alistair Francis May 3, 2021, 7:29 a.m. UTC | #8
On Mon, May 3, 2021 at 5:13 PM Thomas Petazzoni
<thomas.petazzoni@bootlin.com> wrote:
>
> On Mon, 3 May 2021 17:11:09 +1000
> Alistair Francis <alistair23@gmail.com> wrote:
>
> > > What do you call an "official GCC build" ? A toolchain built by
> > > Buildroot from source ? Buildroot can only build a single toolchain,
> > > which is Linux capable. Buildroot does not know how to build a separate
> > > bare-metal toolchain, which is why in such situations we use an
> > > existing pre-compiled toolchain.
> >
> > I just meant something from upstream GCC and not a vendor.
>
> But where is "upstream GCC" providing pre-compiled bare-metal toolchains?

Argh, I thought there was somewhere but I can't find anywhere.

Alistair

>
> Thomas
> --
> Thomas Petazzoni, co-owner and CEO, Bootlin
> Embedded Linux and Kernel engineering
> https://bootlin.com
diff mbox series

Patch

diff --git a/DEVELOPERS b/DEVELOPERS
index cec63a3715..7ce78742fc 100644
--- a/DEVELOPERS
+++ b/DEVELOPERS
@@ -2651,6 +2651,7 @@  F:	package/python3/
 F:	package/python-mad/
 F:	package/python-serial/
 F:	package/qextserialport/
+F:	package/riscv64-elf-toolchain/
 F:	package/rpcbind/
 F:	package/rt-tests/
 F:	package/rtc-tools/
diff --git a/package/riscv64-elf-toolchain/riscv64-elf-toolchain.mk b/package/riscv64-elf-toolchain/riscv64-elf-toolchain.mk
new file mode 100644
index 0000000000..9b08ee0fec
--- /dev/null
+++ b/package/riscv64-elf-toolchain/riscv64-elf-toolchain.mk
@@ -0,0 +1,25 @@ 
+################################################################################
+#
+# riscv64-elf-toolchain
+#
+################################################################################
+
+RISCV64_ELF_TOOLCHAIN_VERSION = 2020.12.8
+RISCV64_ELF_TOOLCHAIN_SITE = https://static.dev.sifive.com/dev-tools/freedom-tools/v2020.12
+RISCV64_ELF_TOOLCHAIN_SOURCE = riscv64-unknown-elf-toolchain-10.2.0-$(RISCV64_ELF_TOOLCHAIN_VERSION)-x86_64-linux-centos6.tar.gz
+
+HOST_RISCV64_ELF_TOOLCHAIN_INSTALL_DIR = $(HOST_DIR)/opt/riscv64-elf
+
+define HOST_RISCV64_ELF_TOOLCHAIN_INSTALL_CMDS
+	rm -rf $(HOST_RISCV64_ELF_TOOLCHAIN_INSTALL_DIR)
+	mkdir -p $(HOST_RISCV64_ELF_TOOLCHAIN_INSTALL_DIR)
+	cp -rf $(@D)/* $(HOST_RISCV64_ELF_TOOLCHAIN_INSTALL_DIR)/
+
+	mkdir -p $(HOST_DIR)/bin
+	cd $(HOST_DIR)/bin && \
+	for i in ../opt/riscv64-elf/bin/*; do \
+		ln -sf $$i; \
+	done
+endef
+
+$(eval $(host-generic-package))