diff mbox series

[v6,03/10] package/newlib-bare-metal: new package

Message ID 20231020114236.4129636-3-neal.frager@amd.com
State Changes Requested
Headers show
Series [v6,01/10] package/binutils-bare-metal: new package | expand

Commit Message

Neal Frager Oct. 20, 2023, 11:42 a.m. UTC
This patch adds a new package for building newlib for a bare-metal toolchain.
The cpu architecture is defined by a toolchain-bare-metal virtual package.
While any cpu architecture could be used, the default configuration will be a
Xilinx microblaze little endian architecture, so that buildroot will be able
to build the microblaze firmware applications for zynqmp and versal.

Signed-off-by: Ibai Erkiaga <ibai.erkiaga-elorza@amd.com>
Signed-off-by: Neal Frager <neal.frager@amd.com>
---
V1->V2:
 - removed default enable to be replaced with toolchain select config
V2->V3:
 - no changes
V3->V4:
 - replaced unnecessary =? with = for assignments
 - improved menuconfig help comment
V4->V5:
 - added license files
 - reduced all lines to <80 chars
V5->V6:
 - migrated to toolchain-bare-metal-buildroot
---
 DEVELOPERS                                    |  2 +
 package/newlib-bare-metal/Config.in.host      | 12 ++++++
 .../newlib-bare-metal/newlib-bare-metal.hash  |  8 ++++
 .../newlib-bare-metal/newlib-bare-metal.mk    | 37 +++++++++++++++++++
 4 files changed, 59 insertions(+)
 create mode 100644 package/newlib-bare-metal/Config.in.host
 create mode 100644 package/newlib-bare-metal/newlib-bare-metal.hash
 create mode 100644 package/newlib-bare-metal/newlib-bare-metal.mk

Comments

Luca Ceresoli Oct. 26, 2023, 4:07 p.m. UTC | #1
On Fri, 20 Oct 2023 12:42:29 +0100
Neal Frager <neal.frager@amd.com> wrote:

> This patch adds a new package for building newlib for a bare-metal toolchain.
> The cpu architecture is defined by a toolchain-bare-metal virtual package.
> While any cpu architecture could be used, the default configuration will be a
> Xilinx microblaze little endian architecture, so that buildroot will be able
> to build the microblaze firmware applications for zynqmp and versal.
> 
> Signed-off-by: Ibai Erkiaga <ibai.erkiaga-elorza@amd.com>
> Signed-off-by: Neal Frager <neal.frager@amd.com>

[Tested on Kria KV260 starter kit]
Tested-by: Luca Ceresoli <luca.ceresoli@bootlin.com>
Reviewed-by: Luca Ceresoli <luca.ceresoli@bootlin.com>
Thomas Petazzoni Oct. 31, 2023, 12:43 p.m. UTC | #2
Hello,

On Fri, 20 Oct 2023 12:42:29 +0100
Neal Frager via buildroot <buildroot@buildroot.org> wrote:


> diff --git a/package/newlib-bare-metal/Config.in.host b/package/newlib-bare-metal/Config.in.host
> new file mode 100644
> index 0000000000..be92a1d6a6
> --- /dev/null
> +++ b/package/newlib-bare-metal/Config.in.host
> @@ -0,0 +1,12 @@
> +config BR2_PACKAGE_HOST_NEWLIB_BARE_METAL
> +	bool "host newlib-bare-metal"
> +	help
> +	  Build the newlib C library for a bare-metal toolchain
> +
> +if BR2_PACKAGE_HOST_NEWLIB_BARE_METAL
> +
> +config BR2_PACKAGE_HOST_NEWLIB_BARE_METAL_VERSION
> +	string
> +	default "4.1.0"
> +
> +endif #BR2_PACKAGE_HOST_NEWLIB_BARE_METAL

Like the other packages: this Config.in is useless, so it can be
dropped.

> diff --git a/package/newlib-bare-metal/newlib-bare-metal.hash b/package/newlib-bare-metal/newlib-bare-metal.hash
> new file mode 100644
> index 0000000000..1a681ecf77
> --- /dev/null
> +++ b/package/newlib-bare-metal/newlib-bare-metal.hash
> @@ -0,0 +1,8 @@
> +# Locally calculated
> +sha256  f296e372f51324224d387cc116dc37a6bd397198756746f93a2b02e9a5d40154  newlib-4.1.0.tar.gz
> +
> +# Hashes for license files locally calculated
> +sha256  231f7edcc7352d7734a96eef0b8030f77982678c516876fcb81e25b32d68564c  COPYING
> +sha256  a9bdde5616ecdd1e980b44f360600ee8783b1f99b8cc83a2beb163a0a390e861  COPYING.LIB
> +sha256  f3b7f3e4426b1fa6f60198dae7adfedd94b77b28db2d108adc0253575011e0ff  COPYING.LIBGLOSS
> +sha256  422aa40293093fb54fc66e692a0d68fd0b24ed5602e5d1d33ad05ba3909057e9  COPYING.NEWLIB
> diff --git a/package/newlib-bare-metal/newlib-bare-metal.mk b/package/newlib-bare-metal/newlib-bare-metal.mk
> new file mode 100644
> index 0000000000..a42e04877a
> --- /dev/null
> +++ b/package/newlib-bare-metal/newlib-bare-metal.mk
> @@ -0,0 +1,37 @@
> +################################################################################
> +#
> +# newlib-bare-metal
> +#
> +################################################################################
> +
> +HOST_NEWLIB_BARE_METAL_VERSION = \
> +	$(call qstrip,$(BR2_PACKAGE_HOST_NEWLIB_BARE_METAL_VERSION))
> +ifeq ($(HOST_NEWLIB_BARE_METAL_VERSION),)
> +HOST_NEWLIB_BARE_METAL_VERSION = 4.1.0
> +endif

Just hardcode the version number.

> +
> +HOST_NEWLIB_BARE_METAL_SITE = ftp://sourceware.org/pub/newlib
> +HOST_NEWLIB_BARE_METAL_SOURCE = newlib-$(HOST_NEWLIB_BARE_METAL_VERSION).tar.gz
> +HOST_NEWLIB_BARE_METAL_DEPENDENCIES = host-gcc-bare-metal
> +
> +HOST_NEWLIB_BARE_METAL_LICENSE = GPL-2.0, GPL-3.0, LGPL-2.1, LGPL-3.0
> +HOST_NEWLIB_BARE_METAL_LICENSE_FILES = COPYING \
> +	COPYING.LIB \
> +	COPYING.LIBGLOSS \
> +	COPYING.NEWLIB
> +
> +NEWLIB_ARCH = \
> +	$(call qstrip,$(BR2_PACKAGE_HOST_TOOLCHAIN_BARE_METAL_BUILDROOT_ARCH))
> +
> +HOST_NEWLIB_BARE_METAL_CONF_OPTS = \
> +	--target=$(NEWLIB_ARCH)-elf \
> +	CC_FOR_TARGET=$(HOST_DIR)/bin/$(NEWLIB_ARCH)-elf-gcc \
> +	AR_FOR_TARGET=$(HOST_DIR)/bin/$(NEWLIB_ARCH)-elf-ar \
> +	RANLIB_FOR_TARGET=$(HOST_DIR)/bin/$(NEWLIB_ARCH)-elf-ranlib \

Same comment as on the gcc patch on whether
BR2_PACKAGE_HOST_TOOLCHAIN_BARE_METAL_BUILDROOT_ARCH should carry the
architecture name, or the full tuple. Preference for the latter on my
side.

Thomas
Thomas Petazzoni Oct. 31, 2023, 12:52 p.m. UTC | #3
On Fri, 20 Oct 2023 12:42:29 +0100
Neal Frager via buildroot <buildroot@buildroot.org> wrote:

> +$(eval $(host-autotools-package))

Thinking more about this, this should very likely be a target package
(newlib-bare-metal) rather than a host package
(host-newlib-bare-metal). Indeed, newlib is really cross-compiled for
the target, it's akin to the glibc/musl/uclibc packages, but for the
bare metal toolchain.

Best regards,

Thomas
yegorslists--- via buildroot Nov. 1, 2023, 11:43 a.m. UTC | #4
Hello Thomas,


> diff --git a/package/newlib-bare-metal/Config.in.host 
> b/package/newlib-bare-metal/Config.in.host
> new file mode 100644
> index 0000000000..be92a1d6a6
> --- /dev/null
> +++ b/package/newlib-bare-metal/Config.in.host
> @@ -0,0 +1,12 @@
> +config BR2_PACKAGE_HOST_NEWLIB_BARE_METAL
> +	bool "host newlib-bare-metal"
> +	help
> +	  Build the newlib C library for a bare-metal toolchain
> +
> +if BR2_PACKAGE_HOST_NEWLIB_BARE_METAL
> +
> +config BR2_PACKAGE_HOST_NEWLIB_BARE_METAL_VERSION
> +	string
> +	default "4.1.0"
> +
> +endif #BR2_PACKAGE_HOST_NEWLIB_BARE_METAL

> Like the other packages: this Config.in is useless, so it can be dropped.

Are you sure that the Config.in files can be dropped?  

When I drop them, I am stuck with the following build error:
Makefile:576: *** newlib-bare-metal is in the dependency chain of toolchain-bare-metal-buildroot that has added it to its _DEPENDENCIES variable without selecting it or depending on it from Config.in.  Stop.

How can we deal with this without selecting the packages and having Config.in files?

Thanks for your help!

Best regards,
Neal Frager
AMD

> diff --git a/package/newlib-bare-metal/newlib-bare-metal.hash 
> b/package/newlib-bare-metal/newlib-bare-metal.hash
> new file mode 100644
> index 0000000000..1a681ecf77
> --- /dev/null
> +++ b/package/newlib-bare-metal/newlib-bare-metal.hash
> @@ -0,0 +1,8 @@
> +# Locally calculated
> +sha256  
> +f296e372f51324224d387cc116dc37a6bd397198756746f93a2b02e9a5d40154  
> +newlib-4.1.0.tar.gz
> +
> +# Hashes for license files locally calculated
> +sha256  
> +231f7edcc7352d7734a96eef0b8030f77982678c516876fcb81e25b32d68564c  
> +COPYING
> +sha256  
> +a9bdde5616ecdd1e980b44f360600ee8783b1f99b8cc83a2beb163a0a390e861  
> +COPYING.LIB
> +sha256  
> +f3b7f3e4426b1fa6f60198dae7adfedd94b77b28db2d108adc0253575011e0ff  
> +COPYING.LIBGLOSS
> +sha256  
> +422aa40293093fb54fc66e692a0d68fd0b24ed5602e5d1d33ad05ba3909057e9  
> +COPYING.NEWLIB
> diff --git a/package/newlib-bare-metal/newlib-bare-metal.mk 
> b/package/newlib-bare-metal/newlib-bare-metal.mk
> new file mode 100644
> index 0000000000..a42e04877a
> --- /dev/null
> +++ b/package/newlib-bare-metal/newlib-bare-metal.mk
> @@ -0,0 +1,37 @@
> +#####################################################################
> +###########
> +#
> +# newlib-bare-metal
> +#
> +#####################################################################
> +###########
> +
> +HOST_NEWLIB_BARE_METAL_VERSION = \
> +	$(call qstrip,$(BR2_PACKAGE_HOST_NEWLIB_BARE_METAL_VERSION))
> +ifeq ($(HOST_NEWLIB_BARE_METAL_VERSION),)
> +HOST_NEWLIB_BARE_METAL_VERSION = 4.1.0 endif

Just hardcode the version number.

> +
> +HOST_NEWLIB_BARE_METAL_SITE = ftp://sourceware.org/pub/newlib 
> +HOST_NEWLIB_BARE_METAL_SOURCE = 
> +newlib-$(HOST_NEWLIB_BARE_METAL_VERSION).tar.gz
> +HOST_NEWLIB_BARE_METAL_DEPENDENCIES = host-gcc-bare-metal
> +
> +HOST_NEWLIB_BARE_METAL_LICENSE = GPL-2.0, GPL-3.0, LGPL-2.1, LGPL-3.0 
> +HOST_NEWLIB_BARE_METAL_LICENSE_FILES = COPYING \
> +	COPYING.LIB \
> +	COPYING.LIBGLOSS \
> +	COPYING.NEWLIB
> +
> +NEWLIB_ARCH = \
> +	$(call 
> +qstrip,$(BR2_PACKAGE_HOST_TOOLCHAIN_BARE_METAL_BUILDROOT_ARCH))
> +
> +HOST_NEWLIB_BARE_METAL_CONF_OPTS = \
> +	--target=$(NEWLIB_ARCH)-elf \
> +	CC_FOR_TARGET=$(HOST_DIR)/bin/$(NEWLIB_ARCH)-elf-gcc \
> +	AR_FOR_TARGET=$(HOST_DIR)/bin/$(NEWLIB_ARCH)-elf-ar \
> +	RANLIB_FOR_TARGET=$(HOST_DIR)/bin/$(NEWLIB_ARCH)-elf-ranlib \
Thomas Petazzoni Nov. 1, 2023, 11:50 a.m. UTC | #5
Hello,

On Wed, 1 Nov 2023 11:43:34 +0000
"Frager, Neal" <neal.frager@amd.com> wrote:

> Are you sure that the Config.in files can be dropped?  
> 
> When I drop them, I am stuck with the following build error:
> Makefile:576: *** newlib-bare-metal is in the dependency chain of toolchain-bare-metal-buildroot that has added it to its _DEPENDENCIES variable without selecting it or depending on it from Config.in.  Stop.
> 
> How can we deal with this without selecting the packages and having Config.in files?

Ah, yes, I asked to change the newlib-bare-metal package to be a target
package. In this case indeed you do need a Config.in file. However, its
option doesn't have to be visible, it should simply be selected by the
toolchain-bare-metal-buildroot package.

config BR2_PACKAGE_NEWLIB_BARE_METAL
	bool

Thomas
yegorslists--- via buildroot Nov. 1, 2023, 1:23 p.m. UTC | #6
Hello Thomas,

> Are you sure that the Config.in files can be dropped?  
> 
> When I drop them, I am stuck with the following build error:
> Makefile:576: *** newlib-bare-metal is in the dependency chain of toolchain-bare-metal-buildroot that has added it to its _DEPENDENCIES variable without selecting it or depending on it from Config.in.  Stop.
> 
> How can we deal with this without selecting the packages and having Config.in files?

> Ah, yes, I asked to change the newlib-bare-metal package to be a target package. In this case indeed you do need a Config.in file. However, its option doesn't have to be visible, it should simply be selected by the toolchain-bare-metal-buildroot package.

> config BR2_PACKAGE_NEWLIB_BARE_METAL
> 	bool

Unfortunately, by making newlib a target package instead of host, the buildroot
infrastructure does not seem to like that newlib was built for Xilinx MicroBlaze
and not the expected AArch64 target architecture.

Below is an example of the error message:
ERROR: architecture for "/usr/microblazeel-xilinx-elf/lib/libc.a" is "Xilinx MicroBlaze", should be "AArch64"

Is there a way around this, or do we need to keep newlib-bare-metal as a "host" package
to avoid this issue?z

Best regards,
Neal Frager
AMD
Yann E. MORIN Nov. 1, 2023, 1:42 p.m. UTC | #7
Neal, All,

On 2023-11-01 13:23 +0000, Frager, Neal via buildroot spake thusly:
[--SNIP--]
> Unfortunately, by making newlib a target package instead of host, the buildroot
> infrastructure does not seem to like that newlib was built for Xilinx MicroBlaze
> and not the expected AArch64 target architecture.
> 
> Below is an example of the error message:
> ERROR: architecture for "/usr/microblazeel-xilinx-elf/lib/libc.a" is "Xilinx MicroBlaze", should be "AArch64"
> 
> Is there a way around this, or do we need to keep newlib-bare-metal as a "host" package
> to avoid this issue?z

You can use _BIN_ARCH_EXCLUDE, see the manual:
    https://buildroot.org/downloads/manual/manual.html#_infrastructure_for_packages_with_specific_build_systems

However (but I haven't read all the previous reviews), why would that
file end up in target to beging with?

It is a static library, and from what I understand about this bare-metal
toolchain, the goal is to build firmwares for co-processors, and those
are alwys going to be statically linked, right?

Furthermore, newlib is always going to be a static library, never a
shared one, right?

As such, it should only need to be installed in staging/, not in
target/, and thus:
    NEWLIB_BARE_METAL_INSTALL_STAGING = YES
    NEWLIB_BARE_METAL_INSTALL_TARGET = NO

And then, the check-bin-arch would not find that file, because it would
not be in target/ anymore (and thus _BIN_ARCH_EXCLUDE would not be
needed either).

And then, thinking yet a bit more: it not not even need to be in
staging/ either, as staging/ is for stuff that actually runs on the
target's CPU, not co-procs.

So, I think the gcc-bare-metal package should be configured with a
special sysroot, and newlib-bare-metal installed in that sysroot, e.g.
somethig like:

    HOST_GCC_BARE_METAL_SYSROOT = $(HOST_DIR)/$(GCC_BARE_METAL_ARCH)-elf/sysroot

    HOST_GCC_BARE_METAL_CONF_OPTS = \
        [...]
        --with-sysroot=$(HOST_GCC_BARE_METAL_SYSROOT)

and then:

    NEWLIB_BARE_METAL_INSTALL_OPTS = DESTDIR=$(HOST_GCC_BARE_METAL_SYSROOT)

Totally untested, but this should give some hints as to where to install
stuff.

Thomas, what do you think?

Regards,
Yann E. MORIN.
yegorslists--- via buildroot Nov. 2, 2023, 9:35 a.m. UTC | #8
Hi Yann,


> Le 1 nov. 2023 à 07:42, Yann E. MORIN <yann.morin.1998@free.fr> a écrit :
> 
> Neal, All,
> 
> On 2023-11-01 13:23 +0000, Frager, Neal via buildroot spake thusly:
> [--SNIP--]
>> Unfortunately, by making newlib a target package instead of host, the buildroot
>> infrastructure does not seem to like that newlib was built for Xilinx MicroBlaze
>> and not the expected AArch64 target architecture.
>> 
>> Below is an example of the error message:
>> ERROR: architecture for "/usr/microblazeel-xilinx-elf/lib/libc.a" is "Xilinx MicroBlaze", should be "AArch64"
>> 
>> Is there a way around this, or do we need to keep newlib-bare-metal as a "host" package
>> to avoid this issue?z
> 
> You can use _BIN_ARCH_EXCLUDE, see the manual:
>    https://buildroot.org/downloads/manual/manual.html#_infrastructure_for_packages_with_specific_build_systems
> 
> However (but I haven't read all the previous reviews), why would that
> file end up in target to beging with?
> 
> It is a static library, and from what I understand about this bare-metal
> toolchain, the goal is to build firmwares for co-processors, and those
> are alwys going to be statically linked, right?
> 
> Furthermore, newlib is always going to be a static library, never a
> shared one, right?
> 
> As such, it should only need to be installed in staging/, not in
> target/, and thus:
>    NEWLIB_BARE_METAL_INSTALL_STAGING = YES
>    NEWLIB_BARE_METAL_INSTALL_TARGET = NO
> 
> And then, the check-bin-arch would not find that file, because it would
> not be in target/ anymore (and thus _BIN_ARCH_EXCLUDE would not be
> needed either).
> 
> And then, thinking yet a bit more: it not not even need to be in
> staging/ either, as staging/ is for stuff that actually runs on the
> target's CPU, not co-procs.
> 
> So, I think the gcc-bare-metal package should be configured with a
> special sysroot, and newlib-bare-metal installed in that sysroot, e.g.
> somethig like:
> 
>    HOST_GCC_BARE_METAL_SYSROOT = $(HOST_DIR)/$(GCC_BARE_METAL_ARCH)-elf/sysroot
> 
>    HOST_GCC_BARE_METAL_CONF_OPTS = \
>        [...]
>        --with-sysroot=$(HOST_GCC_BARE_METAL_SYSROOT)
> 
> and then:
> 
>    NEWLIB_BARE_METAL_INSTALL_OPTS = DESTDIR=$(HOST_GCC_BARE_METAL_SYSROOT)
> 
> Totally untested, but this should give some hints as to where to install
> stuff.
> 
> Thomas, what do you think?

Thank you for these details.  I will start working on implementing this.

It would be great to get feedback from Thomas as well.

Thank you both for your support!

Best regards,
Neal Frager
AMD
Thomas Petazzoni Nov. 2, 2023, 9:37 a.m. UTC | #9
On Thu, 2 Nov 2023 09:35:35 +0000
"Frager, Neal" <neal.frager@amd.com> wrote:

> It would be great to get feedback from Thomas as well.

On which specific point do you need feedback from me? On the suggestion
from Yann to use a separate sysroot? Then yes: I agree with Yann.

Best regards,

Thomas
yegorslists--- via buildroot Nov. 2, 2023, 10:27 a.m. UTC | #10
Hi Thomas,


> Le 2 nov. 2023 à 03:38, Thomas Petazzoni <thomas.petazzoni@bootlin.com> a écrit :
> 
> On Thu, 2 Nov 2023 09:35:35 +0000
> "Frager, Neal" <neal.frager@amd.com> wrote:
> 
>> It would be great to get feedback from Thomas as well.
> 
> On which specific point do you need feedback from me? On the suggestion
> from Yann to use a separate sysroot? Then yes: I agree with Yann.

Yes, I just wanted to verify you agree with Yann.  Thanks!

Best regards,
Neal Frager
AMD
yegorslists--- via buildroot Nov. 14, 2023, 5:47 a.m. UTC | #11
Hi Yann,

> Unfortunately, by making newlib a target package instead of host, the 
> buildroot infrastructure does not seem to like that newlib was built 
> for Xilinx MicroBlaze and not the expected AArch64 target architecture.
> 
> Below is an example of the error message:
> ERROR: architecture for "/usr/microblazeel-xilinx-elf/lib/libc.a" is "Xilinx MicroBlaze", should be "AArch64"
> 
> Is there a way around this, or do we need to keep newlib-bare-metal as 
> a "host" package to avoid this issue?z

> You can use _BIN_ARCH_EXCLUDE, see the manual:
>    https://buildroot.org/downloads/manual/manual.html#_infrastructure_for_packages_with_specific_build_systems

> However (but I haven't read all the previous reviews), why would that file end up in target to beging with?

> It is a static library, and from what I understand about this bare-metal toolchain, the goal is to build firmwares for co-processors, and those are alwys going to be statically linked, right?

> Furthermore, newlib is always going to be a static library, never a shared one, right?

> As such, it should only need to be installed in staging/, not in target/, and thus:
>    NEWLIB_BARE_METAL_INSTALL_STAGING = YES
>    NEWLIB_BARE_METAL_INSTALL_TARGET = NO

> And then, the check-bin-arch would not find that file, because it would not be in target/ anymore (and thus _BIN_ARCH_EXCLUDE would not be needed either).

> And then, thinking yet a bit more: it not not even need to be in staging/ either, as staging/ is for stuff that actually runs on the target's CPU, not co-procs.

> So, I think the gcc-bare-metal package should be configured with a special sysroot, and newlib-bare-metal installed in that sysroot, e.g.
> somethig like:

>    HOST_GCC_BARE_METAL_SYSROOT = $(HOST_DIR)/$(GCC_BARE_METAL_ARCH)-elf/sysroot

>    HOST_GCC_BARE_METAL_CONF_OPTS = \
>        [...]
>        --with-sysroot=$(HOST_GCC_BARE_METAL_SYSROOT)

> and then:

>    NEWLIB_BARE_METAL_INSTALL_OPTS = DESTDIR=$(HOST_GCC_BARE_METAL_SYSROOT)

> Totally untested, but this should give some hints as to where to install stuff.

I finally got the time to get back on this, but there appears to be another issue.

When I use the following for installing the newlib in the sysroot staging area:

NEWLIB_BARE_METAL_INSTALL_STAGING_OPTS = \
	DESTDIR=$(HOST_GCC_BARE_METAL_SYSROOT) \
	Install

I get the following error message:
/usr/bin/install: cannot create regular file '/buildroot/output/host/microblazeel-xilinx-elf/sysroot/usr/microblazeel-xilinx-elf/lib': No such file or directory

This is because newlib tries to install libraries to this directory before the autotools runs the following command later on:
/usr/bin/mkdir -p '/buildroot/output/host/microblazeel-xilinx-elf/sysroot/usr/microblazeel-xilinx-elf/lib'

I have a hack solution by manually doing the mkdir in advance, but this should not be needed.
The autotools should make all the directories that are needed for the install.

Would you be able to look at the pkg-autotools to see if we can fix this problem at its root by creating the lib directory from the beginning of install_staging?

Thank you for your help!

Best regards,
Neal Frager
AMD
Yann E. MORIN Nov. 15, 2023, 6:12 p.m. UTC | #12
Neal, All,

On 2023-11-14 05:47 +0000, Frager, Neal via buildroot spake thusly:
[--SNIP--]
> I finally got the time to get back on this, but there appears to be another issue.
> When I use the following for installing the newlib in the sysroot staging area:
> NEWLIB_BARE_METAL_INSTALL_STAGING_OPTS = \
> 	DESTDIR=$(HOST_GCC_BARE_METAL_SYSROOT) \
> 	Install
> I get the following error message:
> /usr/bin/install: cannot create regular file '/buildroot/output/host/microblazeel-xilinx-elf/sysroot/usr/microblazeel-xilinx-elf/lib': No such file or directory

I had a very quick glance at the newlib Makefile, and it seems it might
not be totally parallel-safe, especially for installation, so maybe:

    NEWLIB_BARE_METAL_MAKE = $(MAKE1)

Can you try that, please?

> This is because newlib tries to install libraries to this directory before the autotools runs the following command later on:
> /usr/bin/mkdir -p '/buildroot/output/host/microblazeel-xilinx-elf/sysroot/usr/microblazeel-xilinx-elf/lib'
> 
> I have a hack solution by manually doing the mkdir in advance, but this should not be needed.
> The autotools should make all the directories that are needed for the install.

The issue is that newlib is not really an autotools package: the
Makefile is generated from Makefile.in, itself generated by autogen
(https://www.gnu.org/software/autogen/) which, AFAIK, is not part of the
autotools suite.

So, newlib uses autoconf, but does not use automake, and thus uses a
custom Makefile template, which might explain why it is not
parallel-safe.

Regards,
Yann E. MORIN.

> Would you be able to look at the pkg-autotools to see if we can fix this problem at its root by creating the lib directory from the beginning of install_staging?
> 
> Thank you for your help!
> 
> Best regards,
> Neal Frager
> AMD
> _______________________________________________
> buildroot mailing list
> buildroot@buildroot.org
> https://lists.buildroot.org/mailman/listinfo/buildroot
yegorslists--- via buildroot Nov. 16, 2023, 10:20 a.m. UTC | #13
Hi Yann,

> I finally got the time to get back on this, but there appears to be another issue.
> When I use the following for installing the newlib in the sysroot staging area:
> NEWLIB_BARE_METAL_INSTALL_STAGING_OPTS = \
> 	DESTDIR=$(HOST_GCC_BARE_METAL_SYSROOT) \
> 	Install
> I get the following error message:
> /usr/bin/install: cannot create regular file 
> '/buildroot/output/host/microblazeel-xilinx-elf/sysroot/usr/microblaze
> el-xilinx-elf/lib': No such file or directory

> I had a very quick glance at the newlib Makefile, and it seems it might not be totally parallel-safe, especially for installation, so maybe:

>    NEWLIB_BARE_METAL_MAKE = $(MAKE1)

> Can you try that, please?

Yes, you were right.  newlib has an issue with parallel installation.  
Using $(MAKE1) or "make -j1" solves the problem.

Now I am encountering another issue.

newlib is installing correctly to the /buildroot/output/host/microblazeel-xilinx-elf/sysroot directory.

However, gcc does not seem to be able to find it when building, as I am getting the following build error:
/buildroot/output/host/lib/gcc/microblazeel-xilinx-elf/13.2.0/include/stdint.h:9:16: fatal error: stdint.h: No such file or directory

When installing newlib as a host package, the stdint.h can be found here:
/buildroot/output/host/microblazeel-xilinx-elf/include/stdint.h

And the microblaze gcc finds it.

When installing newlib to the gcc sysroot as a target package, the stdint.h is found here:
/buildroot/output/host/microblazeel-xilinx-elf/sysroot/usr/microblazeel-xilinx-elf/include/stdint.h

And the microblaze gcc does not find it.

If I simply create the following symbolic links:
/buildroot/output/host/microblazeel-xilinx-elf/sysroot/usr/include -> /buildroot/output/host/microblazeel-xilinx-elf/sysroot/usr/microblazeel-xilinx-elf/include
/buildroot/output/host/microblazeel-xilinx-elf/sysroot/usr/lib -> /buildroot/output/host/microblazeel-xilinx-elf/sysroot/usr/microblazeel-xilinx-elf/lib

Then everything works, and I can build correctly.

How would you recommend I solve this?
Should I be creating these symbolic links or is there a way to install to 
'sysroot/usr/include' and 'sysroot/usr/lib' without the 'microblazeel-xilinx-elf' directory?

Thank you for your help!

Best regards,
Neal Frager
AMD
yegorslists--- via buildroot Nov. 16, 2023, 11:32 a.m. UTC | #14
Hi Yann, all,

> I finally got the time to get back on this, but there appears to be another issue.
> When I use the following for installing the newlib in the sysroot staging area:
> NEWLIB_BARE_METAL_INSTALL_STAGING_OPTS = \
> 	DESTDIR=$(HOST_GCC_BARE_METAL_SYSROOT) \
> 	Install
> I get the following error message:
> /usr/bin/install: cannot create regular file 
> '/buildroot/output/host/microblazeel-xilinx-elf/sysroot/usr/microblaze
> el-xilinx-elf/lib': No such file or directory

> I had a very quick glance at the newlib Makefile, and it seems it might not be totally parallel-safe, especially for installation, so maybe:

>    NEWLIB_BARE_METAL_MAKE = $(MAKE1)

> Can you try that, please?

> Yes, you were right.  newlib has an issue with parallel installation.  
> Using $(MAKE1) or "make -j1" solves the problem.

> Now I am encountering another issue.

> newlib is installing correctly to the /buildroot/output/host/microblazeel-xilinx-elf/sysroot directory.

> However, gcc does not seem to be able to find it when building, as I am getting the following build error:
> /buildroot/output/host/lib/gcc/microblazeel-xilinx-elf/13.2.0/include/stdint.h:9:16: fatal error: stdint.h: No such file or directory

> When installing newlib as a host package, the stdint.h can be found here:
> /buildroot/output/host/microblazeel-xilinx-elf/include/stdint.h

> And the microblaze gcc finds it.

> When installing newlib to the gcc sysroot as a target package, the stdint.h is found here:
> /buildroot/output/host/microblazeel-xilinx-elf/sysroot/usr/microblazeel-xilinx-elf/include/stdint.h

> And the microblaze gcc does not find it.

> If I simply create the following symbolic links:
> /buildroot/output/host/microblazeel-xilinx-elf/sysroot/usr/include -> /buildroot/output/host/microblazeel-xilinx-elf/sysroot/usr/microblazeel-xilinx-elf/include
> /buildroot/output/host/microblazeel-xilinx-elf/sysroot/usr/lib -> /buildroot/output/host/microblazeel-xilinx-elf/sysroot/usr/microblazeel-xilinx-elf/lib

> Then everything works, and I can build correctly.

> How would you recommend I solve this?
> Should I be creating these symbolic links or is there a way to install to 'sysroot/usr/include' and 'sysroot/usr/lib' without the 'microblazeel-xilinx-elf' directory?

The below solution works.  Newlib is installed to the gcc-bare-metal sysroot.

Do you have any better solution for the post install fixup I am doing?

NEWLIB_BARE_METAL_MAKE = $(MAKE1)

NEWLIB_BARE_METAL_INSTALL_STAGING = YES
NEWLIB_BARE_METAL_INSTALL_TARGET = NO

NEWLIB_BARE_METAL_INSTALL_STAGING_OPTS = \
	DESTDIR=$(HOST_GCC_BARE_METAL_SYSROOT) \
	install

define NEWLIB_BARE_METAL_FIXUP
mv $(HOST_GCC_BARE_METAL_SYSROOT)/usr/$(NEWLIB_BARE_METAL_ARCH)/include \
	$(HOST_GCC_BARE_METAL_SYSROOT)/usr/include
mv $(HOST_GCC_BARE_METAL_SYSROOT)/usr/$(NEWLIB_BARE_METAL_ARCH)/lib \
	$(HOST_GCC_BARE_METAL_SYSROOT)/usr/lib
endef

NEWLIB_BARE_METAL_POST_INSTALL_STAGING_HOOKS += NEWLIB_BARE_METAL_FIXUP

Best regards,
Neal Frager
AMD
diff mbox series

Patch

diff --git a/DEVELOPERS b/DEVELOPERS
index 922a74e426..677b8f09bd 100644
--- a/DEVELOPERS
+++ b/DEVELOPERS
@@ -1369,6 +1369,7 @@  F:	package/python-rpi-gpio/
 N:	Ibai Erkiaga <ibai.erkiaga-elorza@amd.com>
 F:	package/binutils-bare-metal/
 F:	package/gcc-bare-metal/
+F:	package/newlib-bare-metal/
 
 N:	Ignacy Gawędzki <ignacy.gawedzki@green-communications.fr>
 F:	package/angularjs/
@@ -2204,6 +2205,7 @@  F:	configs/zynqmp_zcu106_defconfig
 F:	package/binutils-bare-metal/
 F:	package/bootgen/
 F:	package/gcc-bare-metal/
+F:	package/newlib-bare-metal/
 F:	package/versal-firmware/
 
 N:	Nicola Di Lieto <nicola.dilieto@gmail.com>
diff --git a/package/newlib-bare-metal/Config.in.host b/package/newlib-bare-metal/Config.in.host
new file mode 100644
index 0000000000..be92a1d6a6
--- /dev/null
+++ b/package/newlib-bare-metal/Config.in.host
@@ -0,0 +1,12 @@ 
+config BR2_PACKAGE_HOST_NEWLIB_BARE_METAL
+	bool "host newlib-bare-metal"
+	help
+	  Build the newlib C library for a bare-metal toolchain
+
+if BR2_PACKAGE_HOST_NEWLIB_BARE_METAL
+
+config BR2_PACKAGE_HOST_NEWLIB_BARE_METAL_VERSION
+	string
+	default "4.1.0"
+
+endif #BR2_PACKAGE_HOST_NEWLIB_BARE_METAL
diff --git a/package/newlib-bare-metal/newlib-bare-metal.hash b/package/newlib-bare-metal/newlib-bare-metal.hash
new file mode 100644
index 0000000000..1a681ecf77
--- /dev/null
+++ b/package/newlib-bare-metal/newlib-bare-metal.hash
@@ -0,0 +1,8 @@ 
+# Locally calculated
+sha256  f296e372f51324224d387cc116dc37a6bd397198756746f93a2b02e9a5d40154  newlib-4.1.0.tar.gz
+
+# Hashes for license files locally calculated
+sha256  231f7edcc7352d7734a96eef0b8030f77982678c516876fcb81e25b32d68564c  COPYING
+sha256  a9bdde5616ecdd1e980b44f360600ee8783b1f99b8cc83a2beb163a0a390e861  COPYING.LIB
+sha256  f3b7f3e4426b1fa6f60198dae7adfedd94b77b28db2d108adc0253575011e0ff  COPYING.LIBGLOSS
+sha256  422aa40293093fb54fc66e692a0d68fd0b24ed5602e5d1d33ad05ba3909057e9  COPYING.NEWLIB
diff --git a/package/newlib-bare-metal/newlib-bare-metal.mk b/package/newlib-bare-metal/newlib-bare-metal.mk
new file mode 100644
index 0000000000..a42e04877a
--- /dev/null
+++ b/package/newlib-bare-metal/newlib-bare-metal.mk
@@ -0,0 +1,37 @@ 
+################################################################################
+#
+# newlib-bare-metal
+#
+################################################################################
+
+HOST_NEWLIB_BARE_METAL_VERSION = \
+	$(call qstrip,$(BR2_PACKAGE_HOST_NEWLIB_BARE_METAL_VERSION))
+ifeq ($(HOST_NEWLIB_BARE_METAL_VERSION),)
+HOST_NEWLIB_BARE_METAL_VERSION = 4.1.0
+endif
+
+HOST_NEWLIB_BARE_METAL_SITE = ftp://sourceware.org/pub/newlib
+HOST_NEWLIB_BARE_METAL_SOURCE = newlib-$(HOST_NEWLIB_BARE_METAL_VERSION).tar.gz
+HOST_NEWLIB_BARE_METAL_DEPENDENCIES = host-gcc-bare-metal
+
+HOST_NEWLIB_BARE_METAL_LICENSE = GPL-2.0, GPL-3.0, LGPL-2.1, LGPL-3.0
+HOST_NEWLIB_BARE_METAL_LICENSE_FILES = COPYING \
+	COPYING.LIB \
+	COPYING.LIBGLOSS \
+	COPYING.NEWLIB
+
+NEWLIB_ARCH = \
+	$(call qstrip,$(BR2_PACKAGE_HOST_TOOLCHAIN_BARE_METAL_BUILDROOT_ARCH))
+
+HOST_NEWLIB_BARE_METAL_CONF_OPTS = \
+	--target=$(NEWLIB_ARCH)-elf \
+	CC_FOR_TARGET=$(HOST_DIR)/bin/$(NEWLIB_ARCH)-elf-gcc \
+	AR_FOR_TARGET=$(HOST_DIR)/bin/$(NEWLIB_ARCH)-elf-ar \
+	RANLIB_FOR_TARGET=$(HOST_DIR)/bin/$(NEWLIB_ARCH)-elf-ranlib \
+	--enable-newlib-io-c99-formats \
+	--enable-newlib-io-long-long \
+	--enable-newlib-io-float \
+	--enable-newlib-io-long-double \
+	--disable-multilib
+
+$(eval $(host-autotools-package))