[U-Boot] [PATCH 1/8] mach-stm32: Add get_cpu_id support

patrice.chotard at st.com patrice.chotard at st.com
Wed Jan 31 16:09:00 UTC 2018


From: Patrice Chotard <patrice.chotard at st.com>

This allows to read the CPU ID into STM32 DBGMCU_IDCODE register
and create an environment variable which contains the soc name.

Signed-off-by: Christophe Priouzeau <christophe.priouzeau at st.com>
Signed-off-by: Patrice Chotard <patrice.chotard at st.com>
---
 arch/arm/include/asm/arch-stm32f4/stm32.h |  2 ++
 arch/arm/include/asm/arch-stm32f7/stm32.h |  2 ++
 arch/arm/include/asm/arch-stm32h7/stm32.h |  4 +++
 arch/arm/mach-stm32/soc.c                 | 46 +++++++++++++++++++++++++++++++
 4 files changed, 54 insertions(+)

diff --git a/arch/arm/include/asm/arch-stm32f4/stm32.h b/arch/arm/include/asm/arch-stm32f4/stm32.h
index 0449fcecede0..87fd0fa893e5 100644
--- a/arch/arm/include/asm/arch-stm32f4/stm32.h
+++ b/arch/arm/include/asm/arch-stm32f4/stm32.h
@@ -50,5 +50,7 @@ static const u32 sect_sz_kb[CONFIG_SYS_MAX_FLASH_SECT] = {
 };
 
 void stm32_flash_latency_cfg(int latency);
+int get_cpu_id(void);
+void set_env_soc_name(int cpu_id);
 
 #endif /* _MACH_STM32_H_ */
diff --git a/arch/arm/include/asm/arch-stm32f7/stm32.h b/arch/arm/include/asm/arch-stm32f7/stm32.h
index f54e6f195575..dade6e9661ac 100644
--- a/arch/arm/include/asm/arch-stm32f7/stm32.h
+++ b/arch/arm/include/asm/arch-stm32f7/stm32.h
@@ -63,5 +63,7 @@ static const u32 sect_sz_kb[CONFIG_SYS_MAX_FLASH_SECT] = {
 
 
 void stm32_flash_latency_cfg(int latency);
+int get_cpu_id(void);
+void set_env_soc_name(int cpu_id);
 
 #endif /* _ASM_ARCH_HARDWARE_H */
diff --git a/arch/arm/include/asm/arch-stm32h7/stm32.h b/arch/arm/include/asm/arch-stm32h7/stm32.h
index f2922aa3237e..e520c7ea0dbd 100644
--- a/arch/arm/include/asm/arch-stm32h7/stm32.h
+++ b/arch/arm/include/asm/arch-stm32h7/stm32.h
@@ -18,4 +18,8 @@
  * arch/arm/include/asm/arch-stm32f4/stm32.h
  * arch/arm/include/asm/arch-stm32f7/stm32.h
  */
+
+int get_cpu_id(void);
+void set_env_soc_name(int cpu_id);
+
 #endif /* _ASM_ARCH_HARDWARE_H */
diff --git a/arch/arm/mach-stm32/soc.c b/arch/arm/mach-stm32/soc.c
index df20d547c500..0933dfce656d 100644
--- a/arch/arm/mach-stm32/soc.c
+++ b/arch/arm/mach-stm32/soc.c
@@ -9,6 +9,30 @@
 #include <asm/io.h>
 #include <asm/armv7m_mpu.h>
 
+#define STM32_DBGMCU_IDCODE_DEV_ID	GENMASK(11, 0)
+
+#if !defined(CONFIG_STM32H7)
+#define STM32_DBGMCU_IDCODE		0xE0042000
+#else
+#define STM32_DBGMCU_IDCODE		0x5C001000
+#endif
+
+struct cpu_id_table {
+	unsigned int	id;
+	const char	*name;
+	};
+
+const struct cpu_id_table stm32_cpu_id_table[] = {
+	{ 0x413, "stm32f4" },
+	{ 0x419, "stm32f4" },
+	{ 0x434, "stm32f4" },
+	{ 0x449, "stm32f7" },
+	{ 0x451, "stm32f7" },
+	{ 0x450, "stm32h7" },
+	{ 0x452, "stm32f7" },
+	{ 0 },
+};
+
 int arch_cpu_init(void)
 {
 	int i;
@@ -54,3 +78,25 @@ int arch_cpu_init(void)
 
 	return 0;
 }
+
+int get_cpu_id(void)
+{
+	return readl(STM32_DBGMCU_IDCODE) & STM32_DBGMCU_IDCODE_DEV_ID;
+}
+
+void set_env_soc_name(int cpu_id)
+{
+	char soc[16];
+	int i;
+
+	memset(soc, '\0', sizeof(soc));
+
+	for (i = 0; i < sizeof(stm32_cpu_id_table); i++) {
+		if (stm32_cpu_id_table[i].id == cpu_id) {
+			snprintf(soc, sizeof(soc), stm32_cpu_id_table[i].name);
+			break;
+		}
+	}
+
+	env_set("soc_name", soc);
+}
-- 
1.9.1



More information about the U-Boot mailing list