Re: [PATCH v2 5/6] andes: ae350: Save cpu name to env

2023-12-25 Thread Yu-Chien Peter Lin
On Tue, Dec 26, 2023 at 02:54:27PM +0800, Leo Yu-Chi Liang wrote:
> Detect CPU name through marchid and then save it to env.
> 
> Signed-off-by: Leo Yu-Chi Liang 

Reviewed-by: Yu Chien Peter Lin 

> ---
>  board/AndesTech/ae350/ae350.c | 23 +++
>  1 file changed, 23 insertions(+)
> 
> diff --git a/board/AndesTech/ae350/ae350.c b/board/AndesTech/ae350/ae350.c
> index bef9e3149e..4e53fee5d2 100644
> --- a/board/AndesTech/ae350/ae350.c
> +++ b/board/AndesTech/ae350/ae350.c
> @@ -13,7 +13,9 @@
>  #if defined(CONFIG_FTMAC100) && !defined(CONFIG_DM_ETH)
>  #include 
>  #endif
> +#include 
>  #include 
> +#include 
>  #include 
>  #include 
>  #include 
> @@ -27,6 +29,27 @@ DECLARE_GLOBAL_DATA_PTR;
>  /*
>   * Miscellaneous platform dependent initializations
>   */
> +#if IS_ENABLED(CONFIG_MISC_INIT_R)
> +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(_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);
> +}
> +#endif
>  
>  #if CONFIG_IS_ENABLED(LOAD_FIT) || CONFIG_IS_ENABLED(LOAD_FIT_FULL)
>  #define ANDES_SPL_FDT_ADDR   (CONFIG_TEXT_BASE - 0x10)
> -- 
> 2.34.1
> 


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

2023-12-25 Thread Leo Yu-Chi Liang
Detect CPU name through marchid and then save it to env.

Signed-off-by: Leo Yu-Chi Liang 
---
 board/AndesTech/ae350/ae350.c | 23 +++
 1 file changed, 23 insertions(+)

diff --git a/board/AndesTech/ae350/ae350.c b/board/AndesTech/ae350/ae350.c
index bef9e3149e..4e53fee5d2 100644
--- a/board/AndesTech/ae350/ae350.c
+++ b/board/AndesTech/ae350/ae350.c
@@ -13,7 +13,9 @@
 #if defined(CONFIG_FTMAC100) && !defined(CONFIG_DM_ETH)
 #include 
 #endif
+#include 
 #include 
+#include 
 #include 
 #include 
 #include 
@@ -27,6 +29,27 @@ DECLARE_GLOBAL_DATA_PTR;
 /*
  * Miscellaneous platform dependent initializations
  */
+#if IS_ENABLED(CONFIG_MISC_INIT_R)
+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(_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);
+}
+#endif
 
 #if CONFIG_IS_ENABLED(LOAD_FIT) || CONFIG_IS_ENABLED(LOAD_FIT_FULL)
 #define ANDES_SPL_FDT_ADDR (CONFIG_TEXT_BASE - 0x10)
-- 
2.34.1