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 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 smtp.lore.kernel.org (Postfix) with ESMTPS id A3AC2C54EE9 for ; Sun, 25 Sep 2022 15:09:05 +0000 (UTC) Received: from h2850616.stratoserver.net (localhost [IPv6:::1]) by phobos.denx.de (Postfix) with ESMTP id 989EE84D97; Sun, 25 Sep 2022 17:04:48 +0200 (CEST) Authentication-Results: phobos.denx.de; dmarc=pass (p=none dis=none) header.from=chromium.org Authentication-Results: phobos.denx.de; spf=pass smtp.mailfrom=u-boot-bounces@lists.denx.de Authentication-Results: phobos.denx.de; dkim=pass (1024-bit key; unprotected) header.d=chromium.org header.i=@chromium.org header.b="Cg0oEhAE"; dkim-atps=neutral Received: by phobos.denx.de (Postfix, from userid 109) id 5633184C60; Sun, 25 Sep 2022 17:03:56 +0200 (CEST) Received: from mail-io1-xd33.google.com (mail-io1-xd33.google.com [IPv6:2607:f8b0:4864:20::d33]) (using TLSv1.3 with cipher TLS_AES_128_GCM_SHA256 (128/128 bits)) (No client certificate requested) by phobos.denx.de (Postfix) with ESMTPS id B1AF784AF7 for ; Sun, 25 Sep 2022 17:03:51 +0200 (CEST) Authentication-Results: phobos.denx.de; dmarc=pass (p=none dis=none) header.from=chromium.org Authentication-Results: phobos.denx.de; spf=pass smtp.mailfrom=sjg@chromium.org Received: by mail-io1-xd33.google.com with SMTP id r134so3416715iod.8 for ; Sun, 25 Sep 2022 08:03:51 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=chromium.org; s=google; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:from:to:cc:subject:date; bh=RhZO2sTIGI6Sk8JDufQuJsih4P+TRovzEhzRrvS0hY0=; b=Cg0oEhAEarr0BvjlLYkqokqpmQ5nybHg/vrpXRIAu0gSZSf1u4QZwXxLs/W9TpwDZr keoNHSyfQMEN7WA5f1t2wZnTYNv3IDzZJL2/qIVBwihOuFMgqcIskQB1YTgKFo6E5DPT bqNOqPRaA7+nina3JuZWOGeaEnYF/YX/V58Eo= X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:x-gm-message-state:from:to:cc :subject:date; bh=RhZO2sTIGI6Sk8JDufQuJsih4P+TRovzEhzRrvS0hY0=; b=3vrB2MQLdSzT8r66z2ImgQ7GQKDZ86nmgVhOOAO4nTP7UBKFhqTZhs01PoQp4BztW2 k/8V3EJFW0syrYKLGNH+tWxKSX40mYZPulKStVP3n7RznIMeVoUx7MWXqNh306krXaSY cqPYNfqm7guXuAmGUhTZaCr8fzT57c5kPfPd5i/6dxzcwgPaLQkeIqnf+7RCMFqL3QLf 7xJxpkwmdDxQc2p8j64l0P7pJGoRv3KGfjprufAWAYpwQo88Idp4TfFo2ptOFJR7ZHRI qF2jx2u7+7adD23ZVDNBBGf0oNoVBW9paC/9RLAFVfdBGAsL5egVyw3f4kZiBKZFJiPn 6b8Q== X-Gm-Message-State: ACrzQf0KpVFBhVehCw+L3U+Q4reHh2KNIgTecENh0kloROZjy5Sb89+W s5t6k2vvpDYQ7Djl7sD7YRtyNYB6lzOEPg== X-Google-Smtp-Source: AMsMyM6ewwVp930rwzpLcYBsioewzxLPvKauiDq0NfFUw/GuVkImo12qqgRmfpjTazX3KFXqwTk7nA== X-Received: by 2002:a02:a313:0:b0:35b:877:1d11 with SMTP id q19-20020a02a313000000b0035b08771d11mr9735262jai.120.1664118218879; Sun, 25 Sep 2022 08:03:38 -0700 (PDT) Received: from sjg1.roam.corp.google.com (c-67-190-102-125.hsd1.co.comcast.net. [67.190.102.125]) by smtp.gmail.com with ESMTPSA id u19-20020a926013000000b002f19d9838c6sm5360578ilb.25.2022.09.25.08.03.37 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Sun, 25 Sep 2022 08:03:38 -0700 (PDT) From: Simon Glass To: U-Boot Mailing List Cc: Tom Rini , Simon Glass , Alexandru Gagniuc , Andre Przywara , Heinrich Schuchardt , Jan Kiszka , Joe Hershberger , Joel Stanley , Marek Vasut , Philippe Reynes , Sean Anderson Subject: [PATCH 27/45] image: Allow loading a FIT config for a particular phase Date: Sun, 25 Sep 2022 09:02:30 -0600 Message-Id: <20220925150248.2524421-28-sjg@chromium.org> X-Mailer: git-send-email 2.37.3.998.g577e59143f-goog In-Reply-To: <20220925150248.2524421-1-sjg@chromium.org> References: <20220925150248.2524421-1-sjg@chromium.org> MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-BeenThere: u-boot@lists.denx.de X-Mailman-Version: 2.1.39 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.6 at phobos.denx.de X-Virus-Status: Clean Add support for filtering out FIT configs by phase. Rather than adding yet another argument to this already overloaded function, use a composite value, where the phase is only added in if needed. Tests for this come in a little later, as part of the updated VPL test. Signed-off-by: Simon Glass --- boot/image-fit.c | 67 ++++++++++++++++++++++++++++++++++++++++++++---- include/image.h | 12 ++++++--- 2 files changed, 70 insertions(+), 9 deletions(-) diff --git a/boot/image-fit.c b/boot/image-fit.c index 94074515258..c325116b82f 100644 --- a/boot/image-fit.c +++ b/boot/image-fit.c @@ -803,6 +803,40 @@ int fit_image_get_comp(const void *fit, int noffset, uint8_t *comp) return 0; } +/** + * fit_image_get_phase() - get the phase for a configuration node + * @fit: pointer to the FIT format image header + * @offset: configuration-node offset + * @phasep: returns the phase + * + * Finds the phase property in a given configuration node. If the property is + * found, its (string) value is translated to the numeric id which is returned + * to the caller. + * + * Returns: 0 on success, -ENOENT if missing, -EINVAL for invalid value + */ +int fit_image_get_phase(const void *fit, int offset, enum image_phase_t *phasep) +{ + const void *data; + int len, ret; + + /* Get phase name from property data */ + data = fdt_getprop(fit, offset, FIT_PHASE_PROP, &len); + if (!data) { + fit_get_debug(fit, offset, FIT_PHASE_PROP, len); + *phasep = 0; + return -ENOENT; + } + + /* Translate phase name to id */ + ret = genimg_get_phase_id(data); + if (ret < 0) + return ret; + *phasep = ret; + + return 0; +} + static int fit_image_get_address(const void *fit, int noffset, char *name, ulong *load) { @@ -1687,7 +1721,8 @@ int fit_check_format(const void *fit, ulong size) return 0; } -int fit_conf_find_compat(const void *fit, const void *fdt) +int fit_conf_find_compat(const void *fit, const void *fdt, + enum image_phase_t phase) { int ndepth = 0; int noffset, confs_noffset, images_noffset; @@ -1726,6 +1761,27 @@ int fit_conf_find_compat(const void *fit, const void *fdt) if (ndepth > 1) continue; + if (phase) { + enum image_phase_t conf_phase; + int ret; + + ret = fit_image_get_phase(fit, noffset, &conf_phase); + if (ret == -EINVAL) { + log_debug("Invalid phase in node '%s'\n", + fdt_get_name(fit, noffset, NULL)); + continue; + } else if (ret) { + log_debug("Missing phase in node '%s'\n", + fdt_get_name(fit, noffset, NULL)); + continue; + } else if (conf_phase != phase) { + log_debug("Phase %s mismatch in node '%s'\n", + genimg_get_phase_name(conf_phase), + fdt_get_name(fit, noffset, NULL)); + continue; + } + } + /* If there's a compat property in the config node, use that. */ if (fdt_getprop(fit, noffset, "compatible", NULL)) { fdt = fit; /* search in FIT image */ @@ -1954,9 +2010,10 @@ static const char *fit_get_image_type_property(int type) int fit_image_load(struct bootm_headers *images, ulong addr, const char **fit_unamep, const char **fit_uname_configp, - int arch, int image_type, int bootstage_id, + int arch, int ph_type, int bootstage_id, enum fit_load_op load_op, ulong *datap, ulong *lenp) { + int image_type = image_ph_type(ph_type); int cfg_noffset, noffset; const char *fit_uname; const char *fit_uname_config; @@ -2000,10 +2057,10 @@ int fit_image_load(struct bootm_headers *images, ulong addr, */ bootstage_mark(bootstage_id + BOOTSTAGE_SUB_NO_UNIT_NAME); if (IS_ENABLED(CONFIG_FIT_BEST_MATCH) && !fit_uname_config) { - cfg_noffset = fit_conf_find_compat(fit, gd_fdt_blob()); + cfg_noffset = fit_conf_find_compat(fit, gd_fdt_blob(), + image_ph_phase(ph_type)); } else { - cfg_noffset = fit_conf_get_node(fit, - fit_uname_config); + cfg_noffset = fit_conf_get_node(fit, fit_uname_config); } if (cfg_noffset < 0) { puts("Could not find configuration node\n"); diff --git a/include/image.h b/include/image.h index 09821dce642..2aef364e836 100644 --- a/include/image.h +++ b/include/image.h @@ -691,9 +691,10 @@ int boot_get_fdt_fit(struct bootm_headers *images, ulong addr, * name (e.g. "conf-1") or NULL to use the default. On * exit points to the selected configuration name. * @param arch Expected architecture (IH_ARCH_...) - * @param image_type Required image type (IH_TYPE_...). If this is + * @param image_ph_type Required image type (IH_TYPE_...). If this is * IH_TYPE_KERNEL then we allow IH_TYPE_KERNEL_NOLOAD - * also. + * also. If a phase is required, this is included also, + * see image_phase_and_type() * @param bootstage_id ID of starting bootstage to use for progress updates. * This will be added to the BOOTSTAGE_SUB values when * calling bootstage_mark() @@ -704,7 +705,7 @@ int boot_get_fdt_fit(struct bootm_headers *images, ulong addr, */ int fit_image_load(struct bootm_headers *images, ulong addr, const char **fit_unamep, const char **fit_uname_configp, - int arch, int image_type, int bootstage_id, + int arch, int image_ph_type, int bootstage_id, enum fit_load_op load_op, ulong *datap, ulong *lenp); /** @@ -1210,6 +1211,8 @@ int fit_check_format(const void *fit, ulong size); * fit_conf_find_compat * @fit: pointer to the FIT format image header * @fdt: pointer to the device tree to compare against + * @phase: U-Boot phase to look for. If not IH_PHASE_NONE then only + * configurations with the given phase will be considered * * fit_conf_find_compat() attempts to find the configuration whose fdt is the * most compatible with the passed in device tree. @@ -1249,7 +1252,8 @@ int fit_check_format(const void *fit, ulong size); * offset to the configuration to use if one was found * -1 otherwise */ -int fit_conf_find_compat(const void *fit, const void *fdt); +int fit_conf_find_compat(const void *fit, const void *fdt, + enum image_phase_t phase); /** * fit_conf_get_node - get node offset for configuration of a given unit name -- 2.37.3.998.g577e59143f-goog