From a770159f88214846a66c7d7b6ee894de428e8fae Mon Sep 17 00:00:00 2001 From: Phil Sutter Date: Fri, 5 Mar 2021 21:05:11 +0100 Subject: [PATCH] arm: mvebu: ds414: Auto-populate env if appropriate Define a misc_init_r() which calls "syno populate_env" if the environment seems incomplete (or default), indicated by missing "ethaddr" variable. With this in place, no random MAC address fallback is needed anymore. Signed-off-by: Phil Sutter --- board/Synology/ds414/cmd_syno.c | 9 +++------ board/Synology/ds414/cmd_syno.h | 17 +++++++++++++++++ board/Synology/ds414/ds414.c | 11 +++++++++++ configs/ds414_defconfig | 2 +- 4 files changed, 32 insertions(+), 7 deletions(-) create mode 100644 board/Synology/ds414/cmd_syno.h diff --git a/board/Synology/ds414/cmd_syno.c b/board/Synology/ds414/cmd_syno.c index a120c3123f..a62658a2eb 100644 --- a/board/Synology/ds414/cmd_syno.c +++ b/board/Synology/ds414/cmd_syno.c @@ -17,12 +17,9 @@ #include #include "../drivers/ddr/marvell/axp/ddr3_init.h" -#define ETHADDR_MAX 4 -#define SYNO_SN_TAG "SN=" -#define SYNO_CHKSUM_TAG "CHK=" +#include "cmd_syno.h" - -static int do_syno_populate(int argc, char *const argv[]) +int do_syno_populate(int argc, char *const argv[]) { unsigned int bus = CONFIG_SF_DEFAULT_BUS; unsigned int cs = CONFIG_SF_DEFAULT_CS; @@ -57,7 +54,7 @@ static int do_syno_populate(int argc, char *const argv[]) goto out_unmap; } - for (n = 0; n < ETHADDR_MAX; n++) { + for (n = 0; n < SYNO_ETHADDR_MAX; n++) { char ethaddr[ETH_ALEN]; int i, sum = 0; unsigned char csum = 0; diff --git a/board/Synology/ds414/cmd_syno.h b/board/Synology/ds414/cmd_syno.h new file mode 100644 index 0000000000..42e435c803 --- /dev/null +++ b/board/Synology/ds414/cmd_syno.h @@ -0,0 +1,17 @@ +/* SPDX-License-Identifier: GPL-2.0+ */ +/* + * Commands to deal with Synology specifics. + * + * Copyright (C) 2021 Phil Sutter + */ + +#ifndef _CMD_SYNO_H +#define _CMD_SYNO_H + +#define SYNO_ETHADDR_MAX 4 +#define SYNO_SN_TAG "SN=" +#define SYNO_CHKSUM_TAG "CHK=" + +int do_syno_populate(int argc, char *const argv[]); + +#endif /* _CMD_SYNO_H */ diff --git a/board/Synology/ds414/ds414.c b/board/Synology/ds414/ds414.c index 9c4ce670dd..abe6f9eb5e 100644 --- a/board/Synology/ds414/ds414.c +++ b/board/Synology/ds414/ds414.c @@ -18,6 +18,8 @@ #include "../arch/arm/mach-mvebu/serdes/axp/high_speed_env_spec.h" #include "../arch/arm/mach-mvebu/serdes/axp/board_env_spec.h" +#include "cmd_syno.h" + DECLARE_GLOBAL_DATA_PTR; /* GPP and MPP settings as found in mvBoardEnvSpec.c of Synology's U-Boot */ @@ -179,6 +181,15 @@ int board_init(void) return 0; } +int misc_init_r(void) +{ + if (!env_get("ethaddr")) { + puts("Incomplete environment, populating from SPI flash\n"); + do_syno_populate(0, NULL); + } + return 0; +} + int checkboard(void) { puts("Board: DS414\n"); diff --git a/configs/ds414_defconfig b/configs/ds414_defconfig index 8ef2e79dc9..e1c0f693f3 100644 --- a/configs/ds414_defconfig +++ b/configs/ds414_defconfig @@ -24,6 +24,7 @@ CONFIG_BOOTARGS="console=ttyS0,115200 ip=off initrd=0x8000040,8M root=/dev/md0 r # CONFIG_USE_PREBOOT is not set # CONFIG_DISPLAY_BOARDINFO is not set CONFIG_DISPLAY_BOARDINFO_LATE=y +CONFIG_MISC_INIT_R=y CONFIG_SPL_I2C_SUPPORT=y # CONFIG_CMD_FLASH is not set CONFIG_CMD_I2C=y @@ -46,7 +47,6 @@ CONFIG_ENV_OVERWRITE=y CONFIG_USE_ENV_SPI_MAX_HZ=y CONFIG_ENV_SPI_MAX_HZ=50000000 CONFIG_SYS_RELOC_GD_ENV_ADDR=y -CONFIG_NET_RANDOM_ETHADDR=y CONFIG_SPL_OF_TRANSLATE=y CONFIG_BLK=y # CONFIG_MMC is not set -- 2.39.5