[PATCH v2 07/14] stm32mp: add setup_serial_number for stm32mp25

Igor Opaniuk igor.opaniuk at gmail.com
Mon Jan 15 17:23:39 CET 2024


Hello Patrick,

On Mon, Jan 15, 2024 at 5:03 PM Patrick Delaunay
<patrick.delaunay at foss.st.com> wrote:
>
> From: Patrice Chotard <patrice.chotard at foss.st.com>
>
> Add support of serial number for stm32mp25, gets from OTP with BSEC driver.
>
> Reviewed-by: Patrice Chotard <patrice.chotard at foss.st.com>
> Signed-off-by: Patrice Chotard <patrice.chotard at foss.st.com>
> Signed-off-by: Patrick Delaunay <patrick.delaunay at foss.st.com>
> ---
>
> (no changes since v1)
>
>  .../arm/mach-stm32mp/include/mach/sys_proto.h |  1 +
>  arch/arm/mach-stm32mp/soc.c                   | 31 +++++++++++++++++++
>  arch/arm/mach-stm32mp/stm32mp1/cpu.c          | 27 ----------------
>  arch/arm/mach-stm32mp/stm32mp2/cpu.c          |  2 ++
>  4 files changed, 34 insertions(+), 27 deletions(-)
>
> diff --git a/arch/arm/mach-stm32mp/include/mach/sys_proto.h b/arch/arm/mach-stm32mp/include/mach/sys_proto.h
> index 83388fdb7371..2a65efc0a50a 100644
> --- a/arch/arm/mach-stm32mp/include/mach/sys_proto.h
> +++ b/arch/arm/mach-stm32mp/include/mach/sys_proto.h
> @@ -97,6 +97,7 @@ u32 get_bootauth(void);
>
>  int get_eth_nb(void);
>  int setup_mac_address(void);
> +int setup_serial_number(void);
>
>  /* board power management : configure vddcore according OPP */
>  void board_vddcore_init(u32 voltage_mv);
> diff --git a/arch/arm/mach-stm32mp/soc.c b/arch/arm/mach-stm32mp/soc.c
> index 8d5fa474ccaf..ff70ebe97464 100644
> --- a/arch/arm/mach-stm32mp/soc.c
> +++ b/arch/arm/mach-stm32mp/soc.c
> @@ -3,7 +3,11 @@
>   * Copyright (C) 2024, STMicroelectronics - All Rights Reserved
>   */
>
> +#include <env.h>
> +#include <misc.h>
>  #include <asm/arch/sys_proto.h>
> +#include <dm/device.h>
> +#include <dm/uclass.h>
>
>  /* used when CONFIG_DISPLAY_CPUINFO is activated */
>  int print_cpuinfo(void)
> @@ -15,3 +19,30 @@ int print_cpuinfo(void)
>
>         return 0;
>  }
> +
> +int setup_serial_number(void)
> +{
> +       char serial_string[25];
> +       u32 otp[3] = {0, 0, 0 };
> +       struct udevice *dev;
> +       int ret;
> +
> +       if (env_get("serial#"))
> +               return 0;
> +
> +       ret = uclass_get_device_by_driver(UCLASS_MISC,
> +                                         DM_DRIVER_GET(stm32mp_bsec),
> +                                         &dev);
> +       if (ret)
> +               return ret;
> +
> +       ret = misc_read(dev, STM32_BSEC_SHADOW(BSEC_OTP_SERIAL),
> +                       otp, sizeof(otp));
> +       if (ret < 0)
> +               return ret;
> +
> +       sprintf(serial_string, "%08X%08X%08X", otp[0], otp[1], otp[2]);
> +       env_set("serial#", serial_string);
> +
> +       return 0;
> +}
> diff --git a/arch/arm/mach-stm32mp/stm32mp1/cpu.c b/arch/arm/mach-stm32mp/stm32mp1/cpu.c
> index 00fea7929b2f..f84cb26fa565 100644
> --- a/arch/arm/mach-stm32mp/stm32mp1/cpu.c
> +++ b/arch/arm/mach-stm32mp/stm32mp1/cpu.c
> @@ -336,33 +336,6 @@ __weak int setup_mac_address(void)
>         return 0;
>  }
>
> -static int setup_serial_number(void)
> -{
> -       char serial_string[25];
> -       u32 otp[3] = {0, 0, 0 };
> -       struct udevice *dev;
> -       int ret;
> -
> -       if (env_get("serial#"))
> -               return 0;
> -
> -       ret = uclass_get_device_by_driver(UCLASS_MISC,
> -                                         DM_DRIVER_GET(stm32mp_bsec),
> -                                         &dev);
> -       if (ret)
> -               return ret;
> -
> -       ret = misc_read(dev, STM32_BSEC_SHADOW(BSEC_OTP_SERIAL),
> -                       otp, sizeof(otp));
> -       if (ret < 0)
> -               return ret;
> -
> -       sprintf(serial_string, "%08X%08X%08X", otp[0], otp[1], otp[2]);
> -       env_set("serial#", serial_string);
> -
> -       return 0;
> -}
> -
>  __weak void stm32mp_misc_init(void)
>  {
>  }
> diff --git a/arch/arm/mach-stm32mp/stm32mp2/cpu.c b/arch/arm/mach-stm32mp/stm32mp2/cpu.c
> index c0f6519e8d7c..301e365cf4f4 100644
> --- a/arch/arm/mach-stm32mp/stm32mp2/cpu.c
> +++ b/arch/arm/mach-stm32mp/stm32mp2/cpu.c
> @@ -69,6 +69,8 @@ void enable_caches(void)
>
>  int arch_misc_init(void)
>  {
> +       setup_serial_number();
> +
>         return 0;
>  }
>
> --
> 2.25.1
>

Reviewed-by: Igor Opaniuk <igor.opaniuk at foundries.io>

-- 
Best regards - Freundliche Grüsse - Meilleures salutations

Igor Opaniuk

mailto: igor.opaniuk at gmail.com
skype: igor.opanyuk
+48 666 108 041
http://ua.linkedin.com/in/iopaniuk


More information about the U-Boot mailing list