[PATCH] ARM: i.MX: prevent use of imx_cpu_type in PBL

Ahmad Fatoum <[email protected]>
Newsgroups org.infradead.lists.barebox
Message-ID <[email protected]>
Functions like cpu_is_mx6q internally call cpu_is_mx6() first,
which can be evaluated at compile-time if only i.MX6 boards are enabled.

This allowed calling cpu_is_mx6q in PBL entry points as long as barebox was
compiled for only a single SoC.

Since the multi-arch/multi-platform support was added however,
cpu_is_mx6 became a runtime check that's never true in PBL, leading all
cpu_is_mx* in 32-boards to silently fail at runtime.

We have no in-tree boards that are affected by this, so until some
out-of-tree user is bothered enough to fix is, acknowledge that this no
longer works and turn the silent breakage into a loud compile-time error
whenever anything ends up referencing __imx_cpu_type.

Fixes: 1826809f122e ("ARM: i.MX: fix cpu_is_imx on CONFIG_ARM_MULTIARCH configurations")
Fixes: 60a3fd36fa1e ("arm: mach-imx: set cpu type in pbl")
Signed-off-by: Ahmad Fatoum <[email protected]>
---
 arch/arm/mach-imx/Makefile |  4 ++--
 include/mach/imx/generic.h | 11 +++++++++++
 2 files changed, 13 insertions(+), 2 deletions(-)

diff --git a/arch/arm/mach-imx/Makefile b/arch/arm/mach-imx/Makefile
index a7d60068b954..5c26af577504 100644
--- a/arch/arm/mach-imx/Makefile
+++ b/arch/arm/mach-imx/Makefile
@@ -20,7 +20,7 @@ obj-$(CONFIG_ARCH_VF610) += vf610.o
 obj-pbl-$(CONFIG_ARCH_IMX8M) += imx8m.o
 obj-pbl-$(CONFIG_ARCH_IMX_SCRATCHMEM) += scratch.o
 obj-$(CONFIG_ARCH_IMX9) += imx9.o imx-v3-image.o
-lwl-$(CONFIG_ARCH_IMX_ATF) += atf.o
+lwl-$(CONFIG_ARCH_IMX_ATF) += atf.o imx.o
 obj-pbl-$(CONFIG_ARCH_IMX_TZASC) += tzasc.o
 obj-pbl-$(CONFIG_ARCH_IMX_ROMAPI) += romapi.o
 obj-$(CONFIG_IMX_IIM)	+= iim.o
@@ -28,7 +28,7 @@ obj-$(CONFIG_NAND_IMX) += nand.o
 lwl-$(CONFIG_ARCH_IMX_EXTERNAL_BOOT_NAND) += external-nand-boot.o
 obj-y += imx.o
 obj-$(CONFIG_CMD_BOOTROM) += bootrom-cmd.o
-obj-pbl-y += esdctl.o boot.o imx.o
+obj-pbl-y += esdctl.o boot.o
 obj-$(CONFIG_BAREBOX_UPDATE) += imx-bbu-internal.o
 obj-$(CONFIG_BAREBOX_UPDATE_IMX_EXTERNAL_NAND) += imx-bbu-external-nand.o
 pbl-$(CONFIG_USB_GADGET_DRIVER_ARC_PBL) += imx-udc.o
diff --git a/include/mach/imx/generic.h b/include/mach/imx/generic.h
index 5f81aa65a745..0b06c00ac46d 100644
--- a/include/mach/imx/generic.h
+++ b/include/mach/imx/generic.h
@@ -86,12 +86,23 @@ static inline bool imx8mp_keep_compatible_soc_uid(void)
 /* range e.g. GPIO_1_5 is gpio 5 under linux */
 #define IMX_GPIO_NR(bank, nr)		(((bank) - 1) * 32 + (nr))
 
+#if IN_PROPER || defined(CONFIG_ARCH_IMX_ATF)
 extern unsigned int __imx_cpu_type;
 
 static __always_inline void imx_set_cpu_type(unsigned int cpu_type)
 {
 	__imx_cpu_type = cpu_type;
 }
+#else
+/*
+ * If you need this in your PBL entry point, consider using functions
+ * that only query the hardware directly like __cpu_mx6_is_*().
+ */
+extern int __imx_cpu_type(void) __compiletime_error("This API is not available in PBL");
+
+#define __imx_cpu_type __imx_cpu_type()
+#endif
+
 
 #ifdef CONFIG_ARCH_IMX1
 # ifdef imx_cpu_type
-- 
2.47.3
lmpx.com only provides a reader for public news (NNTP) servers. It is not affiliated with the servers or forums shown here and is not responsible for the content of articles, which is written by their respective authors.