
Hi Marek,
On Wed, 27 Oct 2021 at 21:28, Marek Behún kabel@kernel.org wrote:
From: Marek Behún marek.behun@nic.cz
Hello Simon, Stefan, Pali,
this series adds support for board specific runtime determined
grammarian here
board-specific, runtime-determined
default environment variables.
IMPORTANT: This series depends on the series http://patchwork.ozlabs.org/project/uboot/list/?series=268452
Currently the env default [-a] command uses the default_environment[] buffer to get the default env variables.
Sometimes it makes sense to have runtime determined default env settings.
For example the ESPRESSObin board has 4 variants ([ddr3 vs ddr4] x [emmc vs sd]), and each uses different device tree. Thus the `fdtfile` env variable has different values for these 4 variants. (We can't set this variable via env_set() in some board init function, because then the user would be unable to overwrite it.) In order for the command env default fdtfile to work as the user would expect, we need to support overwriting default environment in runtime.
Pali solved this for ESPRESSObin by declaring the default_environment[] buffer read-write, instead of read-only, and adding ad-hoc code into board_late_init() that writes into the default_environment[] buffer.
This ad-hoc code works, but it would be better to have a generic API for this, since there are other boards which could benefit.
The first 3 patches in this series fix and simplify code in env/common.c.
The 4th patch adds support for board specific runtime determined default environment in such a way that if a board code defines function
const char *board_special_default_env(unsigned i, const char **name);
The default weak implementation of this function is trivial and just returns NULL. This function is to be defined in board code, and when defined, it must return the value of the i-th runtime determined default env variable, while storing its name into *name.
For example: const char *board_special_default_env(unsigned i, const char **name) { switch (i) { case 0: *name = "board"; return is_ddr4() ? "my_board_ddr4" : "my_board"; case 1: *name = "fdtfile"; return is_ddr4() ? "my-board-ddr4.dtb" : "my-board.dtb"; default: return NULL; }
The last patch (NOT TESTED) converts the ESPRESSObin ad-hoc code to use this API.
Marek
Marek Behún (5): env: Don't set ready flag if import failed in env_set_default() env: Fix env_get() when returning empty string using env_get_f() env: Simplify env_get_default() env: Add support for board specific special default environment arm: mvebu: Espressobin: Use new API for setting default env at runtime
board/Marvell/mvebu_armada-37xx/board.c | 120 ++++++++++------ configs/mvebu_espressobin-88f3720_defconfig | 1 - env/common.c | 150 ++++++++++++++++---- include/configs/mvebu_armada-37xx.h | 17 +-- include/env_default.h | 2 - include/env_internal.h | 4 - 6 files changed, 199 insertions(+), 95 deletions(-)
-- 2.32.0
Regards, Simon