[PATCH V3 3/3] board: dhelectronics: Sync env variable dh_som_serial_number with SN
Marek Vasut
marex at denx.de
Sun Nov 24 22:10:11 CET 2024
On 11/21/24 6:21 PM, Christoph Niedermaier wrote:
> The env variable "SN" is used to store the serial number on DH electronics
> SoMs. New SoMs will use the variable "dh_som_serial_number". To ensure
> compatibility, these env variables are synchronized. This is achieved
> using callback functions. To avoid recursive calls, these are locked
> against each other.
What kind of recursive calls?
It would be good to expand the commit message and elaborate on the
recursive calls problem .
> diff --git a/board/dhelectronics/common/dh_common.c b/board/dhelectronics/common/dh_common.c
> index a7b0472a09..2e3e5c483b 100644
> --- a/board/dhelectronics/common/dh_common.c
> +++ b/board/dhelectronics/common/dh_common.c
> @@ -45,6 +45,32 @@ struct eeprom_id_page {
> #define DH_EEPROM_ID_PAGE_V1_0_DATA_LEN (sizeof(struct eeprom_id_page) - \
> offsetof(struct eeprom_id_page, mac0))
>
> +static bool in_dh_som_serial_number;
> +static bool in_SN;
> +
> +static int on_dh_som_serial_number(const char *name, const char *value, enum env_op op,
> + int flags)
> +{
> + in_dh_som_serial_number = true;
> + if (!in_SN)
> + env_set("SN", value);
> + in_dh_som_serial_number = false;
> + return 0;
> +}
> +
> +U_BOOT_ENV_CALLBACK(dh_som_serial_number, on_dh_som_serial_number);
> +
> +static int on_SN(const char *name, const char *value, enum env_op op, int flags)
> +{
> + in_SN = true;
> + if (!in_dh_som_serial_number)
> + env_set("dh_som_serial_number", value);
> + in_SN = false;
> + return 0;
> +}
> +
> +U_BOOT_ENV_CALLBACK(SN, on_SN);
> +
> bool dh_mac_is_in_env(const char *env)
> {
> unsigned char enetaddr[6];
> diff --git a/configs/imx8mp_dhsom.config b/configs/imx8mp_dhsom.config
> index 416143178c..87bf3bf65e 100644
> --- a/configs/imx8mp_dhsom.config
> +++ b/configs/imx8mp_dhsom.config
> @@ -59,6 +59,7 @@ CONFIG_SYS_EEPROM_PAGE_WRITE_DELAY_MS=20
> CONFIG_SYS_EEPROM_SIZE=16384
> CONFIG_SYS_I2C_EEPROM_ADDR_LEN=2
>
> +CONFIG_ENV_CALLBACK_LIST_STATIC="dh_som_serial_number:dh_som_serial_number,SN:SN,"
dh_common.c is also used on imx6 and stm32 boards, so this has to go
into configs/dhsom.config fragment I think ?
More information about the U-Boot
mailing list