0001-riscv-Fix-build-against-binutils-2.38.patch 2.4 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758
  1. From 0cf11f3c0478f4286adcfb09bf9137f8b00212e3 Mon Sep 17 00:00:00 2001
  2. From: Alexandre Ghiti <alexandre.ghiti@canonical.com>
  3. Date: Mon, 3 Oct 2022 18:07:54 +0200
  4. Subject: [PATCH] riscv: Fix build against binutils 2.38
  5. The following description is copied from the equivalent patch for the
  6. Linux Kernel proposed by Aurelien Jarno:
  7. >From version 2.38, binutils default to ISA spec version 20191213. This
  8. means that the csr read/write (csrr*/csrw*) instructions and fence.i
  9. instruction has separated from the `I` extension, become two standalone
  10. extensions: Zicsr and Zifencei. As the kernel uses those instruction,
  11. this causes the following build failure:
  12. arch/riscv/cpu/mtrap.S: Assembler messages:
  13. arch/riscv/cpu/mtrap.S:65: Error: unrecognized opcode `csrr a0,scause'
  14. arch/riscv/cpu/mtrap.S:66: Error: unrecognized opcode `csrr a1,sepc'
  15. arch/riscv/cpu/mtrap.S:67: Error: unrecognized opcode `csrr a2,stval'
  16. arch/riscv/cpu/mtrap.S:70: Error: unrecognized opcode `csrw sepc,a0'
  17. Signed-off-by: Alexandre Ghiti <alexandre.ghiti@canonical.com>
  18. Reviewed-by: Bin Meng <bmeng.cn@gmail.com>
  19. Tested-by: Heinrich Schuchardt <heinrich.schuchardt@canonical.com>
  20. Tested-by: Heiko Stuebner <heiko@sntech.de>
  21. Tested-by: Christian Stewart <christian@paral.in>
  22. Reviewed-by: Rick Chen <rick@andestech.com>
  23. (cherry picked from commit 1dde977518f13824b847e23275001191139bc384)
  24. Upstream: https://gitlab.com/u-boot/u-boot/-/commit/1dde977518f13824b847e23275001191139bc384
  25. Signed-off-by: Romain Naour <romain.naour@gmail.com>
  26. ---
  27. arch/riscv/Makefile | 11 ++++++++++-
  28. 1 file changed, 10 insertions(+), 1 deletion(-)
  29. diff --git a/arch/riscv/Makefile b/arch/riscv/Makefile
  30. index 0b80eb8d864..53d1194ffb6 100644
  31. --- a/arch/riscv/Makefile
  32. +++ b/arch/riscv/Makefile
  33. @@ -24,7 +24,16 @@ ifeq ($(CONFIG_CMODEL_MEDANY),y)
  34. CMODEL = medany
  35. endif
  36. -ARCH_FLAGS = -march=$(ARCH_BASE)$(ARCH_A)$(ARCH_C) -mabi=$(ABI) \
  37. +RISCV_MARCH = $(ARCH_BASE)$(ARCH_A)$(ARCH_C)
  38. +
  39. +# Newer binutils versions default to ISA spec version 20191213 which moves some
  40. +# instructions from the I extension to the Zicsr and Zifencei extensions.
  41. +toolchain-need-zicsr-zifencei := $(call cc-option-yn, -mabi=$(ABI) -march=$(RISCV_MARCH)_zicsr_zifencei)
  42. +ifeq ($(toolchain-need-zicsr-zifencei),y)
  43. + RISCV_MARCH := $(RISCV_MARCH)_zicsr_zifencei
  44. +endif
  45. +
  46. +ARCH_FLAGS = -march=$(RISCV_MARCH) -mabi=$(ABI) \
  47. -mcmodel=$(CMODEL)
  48. PLATFORM_CPPFLAGS += $(ARCH_FLAGS)
  49. --
  50. 2.41.0