Skip to contentSkip to conversation

opensbi: patch Makefile for zicsr, zifencei extension check

PATCH New Trevor Gamblin 1 participant 2 messages Sep 10 RISC-V

lore
Share & tools
lore
#0 lore raw

PATCH 1/2 opensbi: patch Makefile for zicsr, zifencei extension check

Backport a patch from upstream to fix the way OpenSBI's Makefile checks for zicsr and zifencei extension support. The use of grep incorrectly matches against build paths generated by Yocto, so the patch directly checks the exit status from the assignment instead.

[YOCTO #15897]

---
 ...rep-when-setting-CC_SUPPORT_ZICSR_ZI.patch | 33 +++++++++++++++++++
 meta/recipes-bsp/opensbi/opensbi_1.9.bb       |  5 ++-
 2 files changed, 37 insertions(+), 1 deletion(-)
 create mode 100644 meta/recipes-bsp/opensbi/files/0001-Makefile-don-t-grep-when-setting-CC_SUPPORT_ZICSR_ZI.patch
meta/recipes-bsp/opensbi/files/0001-Makefile-don-t-grep-when-setting-CC_SUPPORT_ZICSR_ZI.patch new file +33 -0
new file mode 100644
index 0000000000..db93d69e7c
@@ -0,0 +1,33 @@
+From b4ea30a4e46fa6fe4293f86c601394052e5e2b43 Mon Sep 17 00:00:00 2001
+From: Trevor Gamblin <[email protected]>
+Date: Wed, 9 Sep 2026 14:33:24 -0400
+Subject: [PATCH 1/3] Makefile: don't grep when setting
+ CC_SUPPORT_ZICSR_ZIFENCEI
+
+Upstream-Status: Submitted [https://lists.infradead.org/pipermail/opensbi/2026-September/010606.html]
+
+Check exit status from the compiler/linker check directly (similar to
+OPENSBI_LD_PIE), rather than using grep to search for a pattern. This
+avoids potential unrelated matches in the command.
+
+Signed-off-by: Trevor Gamblin <[email protected]>
+---
+ Makefile | 2 +-
+ 1 file changed, 1 insertion(+), 1 deletion(-)
+
+diff --git a/Makefile b/Makefile
+index aebaa98c..07ac7e30 100644
+--- a/Makefile
++++ b/Makefile
+@@ -204,7 +204,7 @@ CC_SUPPORT_SAVE_RESTORE := $(shell $(CC) $(CLANG_TARGET) $(RELAX_FLAG) -nostdlib
+ CC_SUPPORT_STRICT_ALIGN := $(shell $(CC) $(CLANG_TARGET) $(RELAX_FLAG) -nostdlib -mstrict-align -x c /dev/null -o /dev/null 2>&1 | grep -e "-mstrict-align" -e "-mno-unaligned-access" >/dev/null && echo n || echo y)
+ 
+ # Check whether the assembler and the compiler support the Zicsr and Zifencei extensions
+-CC_SUPPORT_ZICSR_ZIFENCEI := $(shell $(CC) $(CLANG_TARGET) $(RELAX_FLAG) -nostdlib -march=rv$(OPENSBI_CC_XLEN)imafd_zicsr_zifencei -x c /dev/null -o /dev/null 2>&1 | grep -e "zicsr" -e "zifencei" > /dev/null && echo n || echo y)
++CC_SUPPORT_ZICSR_ZIFENCEI := $(shell $(CC) $(CLANG_TARGET) $(RELAX_FLAG) -nostdlib -march=rv$(OPENSBI_CC_XLEN)imafd_zicsr_zifencei -x c /dev/null -o /dev/null >/dev/null 2>&1 && echo y || echo n)
+ 
+ # Check whether the assembler and the compiler support the Vector extension
+ CC_SUPPORT_VECTOR := $(shell $(CC) $(CLANG_TARGET) $(RELAX_FLAG) -nostdlib -march=rv$(OPENSBI_CC_XLEN)gv -dM -E -x c /dev/null 2>&1 | grep -q riscv.*vector && echo y || echo n)
+-- 
+2.55.0
+
meta/recipes-bsp/opensbi/opensbi_1.9.bb +4 -1
index 0142ef6787..954753d97e 100644
@@ -9,7 +9,10 @@ require opensbi-payloads.inc
 inherit deploy
 
 SRCREV = "cbf9f6734dd85a982c63e3cb5db7ffe09da839ca"
-SRC_URI = "git://github.com/riscv/opensbi.git;branch=master;protocol=https;tag=v${PV}"
+SRC_URI = " \
+            git://github.com/riscv/opensbi.git;branch=master;protocol=https;tag=v${PV} \
+            file://0001-Makefile-don-t-grep-when-setting-CC_SUPPORT_ZICSR_ZI.patch \
+            "
 
 TARGET_DBGSRC_DIR = "/share/opensbi/*/generic/firmware/"
 
Signature · 1 line
2.55.0
#1 lore raw

PATCH 2/2 arch-riscv.inc: allow zicsr, zifencei in TUNE_RISCV_PKGARCH

With the OpenSBI Makefile fix backported in 7bd2a8ce2618, we can safely enable this.

[YOCTO #15897]

---
 meta/conf/machine/include/riscv/arch-riscv.inc | 13 ++-----------
 1 file changed, 2 insertions(+), 11 deletions(-)
meta/conf/machine/include/riscv/arch-riscv.inc +2 -11
index 99bed8fde5..6f9b74974d 100644
@@ -88,20 +88,11 @@ TUNE_RISCV_PKGARCH .= "${@bb.utils.contains_any("TUNE_FEATURES", "zicbom", "_zic
 
 TUNEVALID[zicsr] = "Control and status register access extension"
 TUNE_RISCV_MARCH .= "${@bb.utils.contains_any("TUNE_FEATURES", "zicsr f d", "_zicsr", "", d)}"
-# If zicsr (or zifencei) is in the path, OpenSBI fails to use the extensions, do to (Makefile):
-#   # Check whether the assembler and the compiler support the Zicsr and Zifencei extensions
-#   CC_SUPPORT_ZICSR_ZIFENCEI := $(shell $(CC) $(CLANG_TARGET) $(RELAX_FLAG) -nostdlib -march=rv$(OPENSBI_CC_XLEN)imafd_zicsr_zifencei -x c /dev/null -o /dev/null 2>&1 | grep -e "zicsr" -e "zifencei" > /dev/null && echo n || echo y)
-# this will match on the path containing zicsr or zifencei when an error is reported, which
-# will always happens in this check.
-#
-# Yocto Project Bugzilla 15897
-#
-#TUNE_RISCV_PKGARCH .= "${@bb.utils.contains_any("TUNE_FEATURES", "zicsr f d", "_zicsr", "", d)}"
+TUNE_RISCV_PKGARCH .= "${@bb.utils.contains_any("TUNE_FEATURES", "zicsr f d", "_zicsr", "", d)}"
 
 TUNEVALID[zifencei] = "Instruction-fetch fence extension"
 TUNE_RISCV_MARCH .= "${@bb.utils.contains("TUNE_FEATURES", "zifencei", "_zifencei", "", d)}"
-# See above Bug 15897
-#TUNE_RISCV_PKGARCH .= "${@bb.utils.contains("TUNE_FEATURES", "zifencei", "_zifencei", "", d)}"
+TUNE_RISCV_PKGARCH .= "${@bb.utils.contains("TUNE_FEATURES", "zifencei", "_zifencei", "", d)}"
 
 TUNEVALID[zba] = "Address bit manipulation extension"
 TUNE_RISCV_MARCH .= "${@bb.utils.contains_any("TUNE_FEATURES", "b zba", "_zba", "", d)}"
Signature · 1 line
2.55.0