diff mbox series

[5/5] andes: ae350: Save cpu name to env

Message ID 20231225130528.1954968-5-ycliang@andestech.com
State Superseded
Headers show
Series [1/5] andes: csr.h: Clean up CSR definition | expand

Commit Message

Leo Liang Dec. 25, 2023, 1:05 p.m. UTC
Detect CPU name through marchid and then save it to env.

Signed-off-by: Leo Yu-Chi Liang <ycliang@andestech.com>
---
 board/AndesTech/ae350/ae350.c | 20 ++++++++++++++++++++
 1 file changed, 20 insertions(+)
diff mbox series

Patch

diff --git a/board/AndesTech/ae350/ae350.c b/board/AndesTech/ae350/ae350.c
index bef9e3149e..9faf46d96e 100644
--- a/board/AndesTech/ae350/ae350.c
+++ b/board/AndesTech/ae350/ae350.c
@@ -28,6 +28,26 @@  DECLARE_GLOBAL_DATA_PTR;
  * Miscellaneous platform dependent initializations
  */
 
+int misc_init_r(void)
+{
+    long csr_marchid = 0;
+    const long mask_64 = 0x8000;
+    const long mask_cpu = 0xff;
+    char cpu_name[10] = {};
+
+#if CONFIG_IS_ENABLED(RISCV_SMODE)
+    sbi_get_marchid(&csr_marchid);
+#elif CONFIG_IS_ENABLED(RISCV_MMODE)
+    csr_marchid = csr_read(CSR_MARCHID);
+#endif
+    if (mask_64 & csr_marchid)
+        snprintf(cpu_name, sizeof(cpu_name), "ax%lx", (mask_cpu & csr_marchid));
+    else
+        snprintf(cpu_name, sizeof(cpu_name), "a%lx", (mask_cpu & csr_marchid));
+
+    return env_set("cpu", cpu_name);
+}
+
 #if CONFIG_IS_ENABLED(LOAD_FIT) || CONFIG_IS_ENABLED(LOAD_FIT_FULL)
 #define ANDES_SPL_FDT_ADDR	(CONFIG_TEXT_BASE - 0x100000)
 void spl_perform_fixups(struct spl_image_info *spl_image)