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

Patrice CHOTARD patrice.chotard at st.com
Fri Feb 2 07:58:51 UTC 2018


Hi Vikas

On 01/31/2018 07:20 PM, Vikas Manocha wrote:
> Hi Patrice,
> 
> On 01/31/2018 08:09 AM, patrice.chotard at st.com wrote:
>> 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
> 
> how about creating one common header file for stm32.

It will be done in another series which is in preparation :
    _ factorize arch/arm/include/asm/arch-stm32xx/stm32.h and all others
      acrh files (gpio.h, stm32_defs.h, stm32_periph.h ....)
    _ add a common stm32_timer driver and remove arch/arm/mach-
      stm32/stm32f4/timer.c and arch/arm/mach-stm32/stm32f7/timer.c

> 
>> @@ -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)
> 
> to make it clear it is MASK macro, pls replace xx_DEV_D with xx_MASK.

ok

> 
>> +
>> +#if !defined(CONFIG_STM32H7)
>> +#define STM32_DBGMCU_IDCODE		0xE0042000
>> +#else
>> +#define STM32_DBGMCU_IDCODE		0x5C001000
>> +#endif
> 
> move it to arch/soc register definitions like to arch/arm/include/asm/arch-stm32f7/stm32.h

ok

> 
>> +
>> +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));
> 
> do we need it ?

No, i will remove it

Thanks

Patrice
> 
> Cheers,
> Vikas
> 
>> +
>> +	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);
>> +}
>>


More information about the U-Boot mailing list