mail archive of the barebox mailing list
 help / color / mirror / Atom feed
* [PATCH 1/3] RISC-V: Makefile: cleanup layout
@ 2023-02-02 13:26 Marco Felsch
  2023-02-02 13:26 ` [PATCH 2/3] RISC-V: Makefile: align the isa string setting with the kernel Marco Felsch
                   ` (2 more replies)
  0 siblings, 3 replies; 4+ messages in thread
From: Marco Felsch @ 2023-02-02 13:26 UTC (permalink / raw)
  To: barebox

The cflag and cppflag handling is rather complicated for this small
Makefile. The code uses two helper variables riscv-cflags-y cflags-y
which are assigned later to PBL_CPPFLAGS, KBUILD_CPPFLAGS and
KBUILD_CFLAGS.

Remove this complexity by assigning the flags directly to
KBUILD_CPPFLAGS. The variable is used during pbl/barebox compile and
during cpp process.

While on it move the KBUILD_IMAGE to the KBUILD_BINARY to bundle the
usage.

Signed-off-by: Marco Felsch <m.felsch@pengutronix.de>
---
 arch/riscv/Makefile | 18 ++++++------------
 1 file changed, 6 insertions(+), 12 deletions(-)

diff --git a/arch/riscv/Makefile b/arch/riscv/Makefile
index 279db046c0..b4cf5983a2 100644
--- a/arch/riscv/Makefile
+++ b/arch/riscv/Makefile
@@ -5,21 +5,19 @@ KBUILD_DEFCONFIG := rv64i_defconfig
 KBUILD_CPPFLAGS += -fno-strict-aliasing
 
 ifeq ($(CONFIG_ARCH_RV32I),y)
-	riscv-cflags-y += -march=rv32im -mabi=ilp32
+	KBUILD_CPPFLAGS += -march=rv32im -mabi=ilp32
 	riscv-ldflags-y += -melf32lriscv
 else
-	riscv-cflags-y += -march=rv64im -mabi=lp64
+	KBUILD_CPPFLAGS += -march=rv64im -mabi=lp64
 	riscv-ldflags-y += -melf64lriscv
 endif
 
-riscv-cflags-y += -Wstrict-prototypes -mcmodel=medany -fpic
-riscv-ldflags-y += -pie -static
 
-PBL_CPPFLAGS += $(riscv-cflags-y)
-LDFLAGS_pbl += $(riscv-ldflags-y)
 
-cflags-y += $(riscv-cflags-y)
+KBUILD_CPPFLAGS += -Wstrict-prototypes -mcmodel=medany -fpic
+riscv-ldflags-y += -pie -static
 
+LDFLAGS_pbl += $(riscv-ldflags-y)
 LDFLAGS_barebox += $(riscv-ldflags-y)
 
 ifndef CONFIG_MODULES
@@ -29,6 +27,7 @@ LDFLAGS_barebox += -static --gc-sections
 endif
 
 KBUILD_BINARY := barebox.bin
+KBUILD_IMAGE := $(KBUILD_BINARY)
 
 archprepare: maketools
 
@@ -41,11 +40,6 @@ common-y += arch/riscv/boot/
 
 common-$(CONFIG_OFTREE) += arch/riscv/dts/
 
-KBUILD_CPPFLAGS += $(cflags-y)
-KBUILD_CFLAGS += $(cflags-y)
-
 lds-y	:= arch/riscv/lib/barebox.lds
 
 CLEAN_FILES += arch/riscv/lib/barebox.lds
-
-KBUILD_IMAGE := $(KBUILD_BINARY)
-- 
2.39.1




^ permalink raw reply	[flat|nested] 4+ messages in thread

* [PATCH 2/3] RISC-V: Makefile: align the isa string setting with the kernel
  2023-02-02 13:26 [PATCH 1/3] RISC-V: Makefile: cleanup layout Marco Felsch
@ 2023-02-02 13:26 ` Marco Felsch
  2023-02-02 13:26 ` [PATCH 3/3] RISC-V: Makefile: fix build with binutils 2.38 Marco Felsch
  2023-02-03  8:04 ` [PATCH 1/3] RISC-V: Makefile: cleanup layout Sascha Hauer
  2 siblings, 0 replies; 4+ messages in thread
From: Marco Felsch @ 2023-02-02 13:26 UTC (permalink / raw)
  To: barebox

Factor out the isa string setting. This is in preparation of adding
support for binutils-2.38 [1] furthermore it aligns the makefile with the
kernel. The commit is based on kernel commit:

  | commit e8be5302330281bd9f77834600f63e8cc4560d3d
  | Author: Alan Kao <alankao@andestech.com>
  | Date:   Tue Oct 9 10:18:32 2018 +0800
  |
  |     Cleanup ISA string setting
  |
  |     This patch cleanup the MARCH string passing to both compiler and
  |     assembler.  Note that the CFLAGS should not contain "fd" before we
  |     have mechnisms like kernel_fpu_begin/end in other architectures.
  |
  |     Signed-off-by: Alan Kao <alankao@andestech.com>
  |     Cc: Greentime Hu <greentime@andestech.com>
  |     Cc: Vincent Chen <vincentc@andestech.com>
  |     Cc: Zong Li <zong@andestech.com>
  |     Cc: Nick Hu <nickhu@andestech.com>
  |     Signed-off-by: Palmer Dabbelt <palmer@sifive.com>

[1] https://lore.kernel.org/linux-riscv/20221015111856.3869148-1-conor@kernel.org/

Signed-off-by: Marco Felsch <m.felsch@pengutronix.de>
---
 arch/riscv/Makefile | 8 ++++++--
 1 file changed, 6 insertions(+), 2 deletions(-)

diff --git a/arch/riscv/Makefile b/arch/riscv/Makefile
index b4cf5983a2..d1b689b493 100644
--- a/arch/riscv/Makefile
+++ b/arch/riscv/Makefile
@@ -5,15 +5,19 @@ KBUILD_DEFCONFIG := rv64i_defconfig
 KBUILD_CPPFLAGS += -fno-strict-aliasing
 
 ifeq ($(CONFIG_ARCH_RV32I),y)
-	KBUILD_CPPFLAGS += -march=rv32im -mabi=ilp32
+	KBUILD_CPPFLAGS += -mabi=ilp32
 	riscv-ldflags-y += -melf32lriscv
 else
-	KBUILD_CPPFLAGS += -march=rv64im -mabi=lp64
+	KBUILD_CPPFLAGS += -mabi=lp64
 	riscv-ldflags-y += -melf64lriscv
 endif
 
+# ISA string setting
+riscv-march-$(CONFIG_ARCH_RV32I)	:= rv32im
+riscv-march-$(CONFIG_ARCH_RV64I)	:= rv64im
 
 
+KBUILD_CPPFLAGS += -march=$(riscv-march-y)
 KBUILD_CPPFLAGS += -Wstrict-prototypes -mcmodel=medany -fpic
 riscv-ldflags-y += -pie -static
 
-- 
2.39.1




^ permalink raw reply	[flat|nested] 4+ messages in thread

* [PATCH 3/3] RISC-V: Makefile: fix build with binutils 2.38
  2023-02-02 13:26 [PATCH 1/3] RISC-V: Makefile: cleanup layout Marco Felsch
  2023-02-02 13:26 ` [PATCH 2/3] RISC-V: Makefile: align the isa string setting with the kernel Marco Felsch
@ 2023-02-02 13:26 ` Marco Felsch
  2023-02-03  8:04 ` [PATCH 1/3] RISC-V: Makefile: cleanup layout Sascha Hauer
  2 siblings, 0 replies; 4+ messages in thread
From: Marco Felsch @ 2023-02-02 13:26 UTC (permalink / raw)
  To: barebox

With binutils >= 2.38 the default risc-v ISA spec version has been
bumped to 20191213, so we now need to specify the extension for csr and
fence.i as well. Do it the kernel way and port commit

  | commit 6df2a016c0c8a3d0933ef33dd192ea6606b115e3
  | Author: Aurelien Jarno <aurelien@aurel32.net>
  | Date:   Wed Jan 26 18:14:42 2022 +0100
  |
  |     riscv: fix build with binutils 2.38
  |
  |     From version 2.38, binutils default to ISA spec version 20191213. This
  |     means that the csr read/write (csrr*/csrw*) instructions and fence.i
  |     instruction has separated from the `I` extension, become two standalone
  |     extensions: Zicsr and Zifencei. As the kernel uses those instruction,
  |     this causes the following build failure:
  |
  |       CC      arch/riscv/kernel/vdso/vgettimeofday.o
  |       <<BUILDDIR>>/arch/riscv/include/asm/vdso/gettimeofday.h: Assembler messages:
  |       <<BUILDDIR>>/arch/riscv/include/asm/vdso/gettimeofday.h:71: Error: unrecognized opcode `csrr a5,0xc01'
  |       <<BUILDDIR>>/arch/riscv/include/asm/vdso/gettimeofday.h:71: Error: unrecognized opcode `csrr a5,0xc01'
  |       <<BUILDDIR>>/arch/riscv/include/asm/vdso/gettimeofday.h:71: Error: unrecognized opcode `csrr a5,0xc01'
  |       <<BUILDDIR>>/arch/riscv/include/asm/vdso/gettimeofday.h:71: Error: unrecognized opcode `csrr a5,0xc01'
  |
  |     The fix is to specify those extensions explicitely in -march. However as
  |     older binutils version do not support this, we first need to detect
  |     that.
  |
  |     Signed-off-by: Aurelien Jarno <aurelien@aurel32.net>
  |     Tested-by: Alexandre Ghiti <alexandre.ghiti@canonical.com>
  |     Cc: stable@vger.kernel.org
  |     Signed-off-by: Palmer Dabbelt <palmer@rivosinc.com>

Signed-off-by: Marco Felsch <m.felsch@pengutronix.de>
---
 arch/riscv/Makefile | 4 ++++
 1 file changed, 4 insertions(+)

diff --git a/arch/riscv/Makefile b/arch/riscv/Makefile
index d1b689b493..1371f17e7c 100644
--- a/arch/riscv/Makefile
+++ b/arch/riscv/Makefile
@@ -16,6 +16,10 @@ endif
 riscv-march-$(CONFIG_ARCH_RV32I)	:= rv32im
 riscv-march-$(CONFIG_ARCH_RV64I)	:= rv64im
 
+# Newer binutils versions default to ISA spec version 20191213 which moves some
+# instructions from the I extension to the Zicsr and Zifencei extensions.
+toolchain-need-zicsr-zifencei := $(call cc-option-yn, -march=$(riscv-march-y)_zicsr_zifencei)
+riscv-march-$(toolchain-need-zicsr-zifencei) := $(riscv-march-y)_zicsr_zifencei
 
 KBUILD_CPPFLAGS += -march=$(riscv-march-y)
 KBUILD_CPPFLAGS += -Wstrict-prototypes -mcmodel=medany -fpic
-- 
2.39.1




^ permalink raw reply	[flat|nested] 4+ messages in thread

* Re: [PATCH 1/3] RISC-V: Makefile: cleanup layout
  2023-02-02 13:26 [PATCH 1/3] RISC-V: Makefile: cleanup layout Marco Felsch
  2023-02-02 13:26 ` [PATCH 2/3] RISC-V: Makefile: align the isa string setting with the kernel Marco Felsch
  2023-02-02 13:26 ` [PATCH 3/3] RISC-V: Makefile: fix build with binutils 2.38 Marco Felsch
@ 2023-02-03  8:04 ` Sascha Hauer
  2 siblings, 0 replies; 4+ messages in thread
From: Sascha Hauer @ 2023-02-03  8:04 UTC (permalink / raw)
  To: Marco Felsch; +Cc: barebox

On Thu, Feb 02, 2023 at 02:26:10PM +0100, Marco Felsch wrote:
> The cflag and cppflag handling is rather complicated for this small
> Makefile. The code uses two helper variables riscv-cflags-y cflags-y
> which are assigned later to PBL_CPPFLAGS, KBUILD_CPPFLAGS and
> KBUILD_CFLAGS.
> 
> Remove this complexity by assigning the flags directly to
> KBUILD_CPPFLAGS. The variable is used during pbl/barebox compile and
> during cpp process.
> 
> While on it move the KBUILD_IMAGE to the KBUILD_BINARY to bundle the
> usage.
> 
> Signed-off-by: Marco Felsch <m.felsch@pengutronix.de>
> ---
>  arch/riscv/Makefile | 18 ++++++------------
>  1 file changed, 6 insertions(+), 12 deletions(-)

Applied, thanks

Sascha

> 
> diff --git a/arch/riscv/Makefile b/arch/riscv/Makefile
> index 279db046c0..b4cf5983a2 100644
> --- a/arch/riscv/Makefile
> +++ b/arch/riscv/Makefile
> @@ -5,21 +5,19 @@ KBUILD_DEFCONFIG := rv64i_defconfig
>  KBUILD_CPPFLAGS += -fno-strict-aliasing
>  
>  ifeq ($(CONFIG_ARCH_RV32I),y)
> -	riscv-cflags-y += -march=rv32im -mabi=ilp32
> +	KBUILD_CPPFLAGS += -march=rv32im -mabi=ilp32
>  	riscv-ldflags-y += -melf32lriscv
>  else
> -	riscv-cflags-y += -march=rv64im -mabi=lp64
> +	KBUILD_CPPFLAGS += -march=rv64im -mabi=lp64
>  	riscv-ldflags-y += -melf64lriscv
>  endif
>  
> -riscv-cflags-y += -Wstrict-prototypes -mcmodel=medany -fpic
> -riscv-ldflags-y += -pie -static
>  
> -PBL_CPPFLAGS += $(riscv-cflags-y)
> -LDFLAGS_pbl += $(riscv-ldflags-y)
>  
> -cflags-y += $(riscv-cflags-y)
> +KBUILD_CPPFLAGS += -Wstrict-prototypes -mcmodel=medany -fpic
> +riscv-ldflags-y += -pie -static
>  
> +LDFLAGS_pbl += $(riscv-ldflags-y)
>  LDFLAGS_barebox += $(riscv-ldflags-y)
>  
>  ifndef CONFIG_MODULES
> @@ -29,6 +27,7 @@ LDFLAGS_barebox += -static --gc-sections
>  endif
>  
>  KBUILD_BINARY := barebox.bin
> +KBUILD_IMAGE := $(KBUILD_BINARY)
>  
>  archprepare: maketools
>  
> @@ -41,11 +40,6 @@ common-y += arch/riscv/boot/
>  
>  common-$(CONFIG_OFTREE) += arch/riscv/dts/
>  
> -KBUILD_CPPFLAGS += $(cflags-y)
> -KBUILD_CFLAGS += $(cflags-y)
> -
>  lds-y	:= arch/riscv/lib/barebox.lds
>  
>  CLEAN_FILES += arch/riscv/lib/barebox.lds
> -
> -KBUILD_IMAGE := $(KBUILD_BINARY)
> -- 
> 2.39.1
> 
> 
> 

-- 
Pengutronix e.K.                           |                             |
Steuerwalder Str. 21                       | http://www.pengutronix.de/  |
31137 Hildesheim, Germany                  | Phone: +49-5121-206917-0    |
Amtsgericht Hildesheim, HRA 2686           | Fax:   +49-5121-206917-5555 |



^ permalink raw reply	[flat|nested] 4+ messages in thread

end of thread, other threads:[~2023-02-03  8:06 UTC | newest]

Thread overview: 4+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2023-02-02 13:26 [PATCH 1/3] RISC-V: Makefile: cleanup layout Marco Felsch
2023-02-02 13:26 ` [PATCH 2/3] RISC-V: Makefile: align the isa string setting with the kernel Marco Felsch
2023-02-02 13:26 ` [PATCH 3/3] RISC-V: Makefile: fix build with binutils 2.38 Marco Felsch
2023-02-03  8:04 ` [PATCH 1/3] RISC-V: Makefile: cleanup layout Sascha Hauer

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox