From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from mail.kernel.org (mail.kernel.org [198.145.29.99]) by smtp.lore.kernel.org (Postfix) with ESMTP id E2C36C433F5 for ; Thu, 28 Oct 2021 03:28:26 +0000 (UTC) Received: from phobos.denx.de (phobos.denx.de [85.214.62.61]) (using TLSv1.2 with cipher ECDHE-RSA-AES128-GCM-SHA256 (128/128 bits)) (No client certificate requested) by mail.kernel.org (Postfix) with ESMTPS id E682461167 for ; Thu, 28 Oct 2021 03:28:25 +0000 (UTC) DMARC-Filter: OpenDMARC Filter v1.4.1 mail.kernel.org E682461167 Authentication-Results: mail.kernel.org; dmarc=fail (p=none dis=none) header.from=kernel.org Authentication-Results: mail.kernel.org; spf=pass smtp.mailfrom=lists.denx.de Received: from h2850616.stratoserver.net (localhost [IPv6:::1]) by phobos.denx.de (Postfix) with ESMTP id B2C22834E8; Thu, 28 Oct 2021 05:28:23 +0200 (CEST) Authentication-Results: phobos.denx.de; dmarc=pass (p=none dis=none) header.from=kernel.org Authentication-Results: phobos.denx.de; spf=pass smtp.mailfrom=u-boot-bounces@lists.denx.de Authentication-Results: phobos.denx.de; dkim=pass (2048-bit key; unprotected) header.d=kernel.org header.i=@kernel.org header.b="Xp3z19L2"; dkim-atps=neutral Received: by phobos.denx.de (Postfix, from userid 109) id DC79F8347C; Thu, 28 Oct 2021 05:28:19 +0200 (CEST) Received: from mail.kernel.org (mail.kernel.org [198.145.29.99]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by phobos.denx.de (Postfix) with ESMTPS id B846B82D6F for ; Thu, 28 Oct 2021 05:28:15 +0200 (CEST) Authentication-Results: phobos.denx.de; dmarc=pass (p=none dis=none) header.from=kernel.org Authentication-Results: phobos.denx.de; spf=pass smtp.mailfrom=kabel@kernel.org Received: by mail.kernel.org (Postfix) with ESMTPSA id D896460EC0; Thu, 28 Oct 2021 03:28:12 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=k20201202; t=1635391693; bh=svBQDZ3VPIEl+aTN310yJcKoDTh06t5q31J5CNgmfCg=; h=From:To:Cc:Subject:Date:From; b=Xp3z19L29wldP1XKOCm+5jE5utee6qMARgL7bFF6fFF14EpwxzEB/9cX/PqyO4Q35 feEpYDKAu4fpMxAnU6FVvi4HaY/llbcBhciNBHRh8t17u/Psd62jjOpHso92X5jJnv sudAReijn1DbxaLuJapoV5tsYKz+efKIhzQPWR8AB7bVbB7o0stHuFxZhLd5R52Cbu rgkOSIN/mkbyS/sugATxP853apnHka6tkyKTojlSqNRkPmXWIi0TrTIKpurtKDy+Gf /tpZaWiy1E2yiMV2p1Zagr++w2rIdYSWcmlb6lhyNJDxT7hRGZ5dVKMaAC1jC/EPxY wVBmYBxqlQFvQ== From: =?UTF-8?q?Marek=20Beh=C3=BAn?= To: Simon Glass , Stefan Roese , =?UTF-8?q?Pali=20Roh=C3=A1r?= Cc: u-boot@lists.denx.de, =?UTF-8?q?Marek=20Beh=C3=BAn?= Subject: [PATCH 0/5] Board specific runtime determined default env Date: Thu, 28 Oct 2021 05:28:05 +0200 Message-Id: <20211028032810.18146-1-kabel@kernel.org> X-Mailer: git-send-email 2.32.0 MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit X-BeenThere: u-boot@lists.denx.de X-Mailman-Version: 2.1.34 Precedence: list List-Id: U-Boot discussion List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: u-boot-bounces@lists.denx.de Sender: "U-Boot" X-Virus-Scanned: clamav-milter 0.103.2 at phobos.denx.de X-Virus-Status: Clean From: Marek BehĂșn Hello Simon, Stefan, Pali, this series adds support for 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