From patchwork Thu Feb 25 19:31:23 2021 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Simon Glass X-Patchwork-Id: 1444577 X-Patchwork-Delegate: trini@ti.com Return-Path: X-Original-To: incoming@patchwork.ozlabs.org Delivered-To: patchwork-incoming@bilbo.ozlabs.org Authentication-Results: ozlabs.org; spf=pass (sender SPF authorized) smtp.mailfrom=lists.denx.de (client-ip=85.214.62.61; helo=phobos.denx.de; envelope-from=u-boot-bounces@lists.denx.de; receiver=) Authentication-Results: ozlabs.org; dkim=pass (1024-bit key; unprotected) header.d=chromium.org header.i=@chromium.org header.a=rsa-sha256 header.s=google header.b=Z9nX43sv; dkim-atps=neutral Received: from phobos.denx.de (phobos.denx.de [85.214.62.61]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature RSA-PSS (4096 bits)) (No client certificate requested) by ozlabs.org (Postfix) with ESMTPS id 4DmjbF1cJmz9sBJ for ; Fri, 26 Feb 2021 06:31:41 +1100 (AEDT) Received: from h2850616.stratoserver.net (localhost [IPv6:::1]) by phobos.denx.de (Postfix) with ESMTP id 9B3EE804F4; Thu, 25 Feb 2021 20:31:34 +0100 (CET) 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="Z9nX43sv"; dkim-atps=neutral Received: by phobos.denx.de (Postfix, from userid 109) id B4D4580505; Thu, 25 Feb 2021 20:31:32 +0100 (CET) X-Spam-Checker-Version: SpamAssassin 3.4.2 (2018-09-13) on phobos.denx.de X-Spam-Level: X-Spam-Status: No, score=-2.0 required=5.0 tests=BAYES_00,DKIMWL_WL_HIGH, DKIM_SIGNED,DKIM_VALID,DKIM_VALID_AU,SPF_HELO_NONE autolearn=ham autolearn_force=no version=3.4.2 Received: from mail-qk1-x731.google.com (mail-qk1-x731.google.com [IPv6:2607:f8b0:4864:20::731]) (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 97F2F804EA for ; Thu, 25 Feb 2021 20:31:29 +0100 (CET) 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-qk1-x731.google.com with SMTP id d20so5797278qkc.2 for ; Thu, 25 Feb 2021 11:31:29 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=chromium.org; s=google; h=from:to:cc:subject:date:message-id:mime-version :content-transfer-encoding; bh=2UqbbgjmPQUx1UNvHKILs+Iohad16vcRuaoPClqU9Qs=; b=Z9nX43svvAt7ZZDPKfbQ/GhplcR3iKG8MZ3jiAl9WFo13te+mBztKJFInnBrsQX5xz s7IfYvJnqiC2IKu4vDZ+lCz8CDw4ZJ//CK2SQhXGWqBm9OP4hCKTp64AQ2uXrygsHUyT JqzenTFMkIelt+gdLTvRJvo9JJy4l5dw15+Z4= X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:from:to:cc:subject:date:message-id:mime-version :content-transfer-encoding; bh=2UqbbgjmPQUx1UNvHKILs+Iohad16vcRuaoPClqU9Qs=; b=HWON0+2BrYZhb9RzIjLMaaKxYlIvn737Pob6SoGaDCBFWVX1R/rju++u+ICvv2h/ho Tye5hvD+eqNpMuypVPF0rQn+LKcva+HAp5s3aJJDW2Xwp3PIjj1GVcGK3MwUxrs06SPg FwcpaXBtIrFpKocDB7Ygs3t3vtvJHRMNkIak7+lcGWZvZ2+wi7cElr2bYjSKvFgAf8nn ZpJ5XDURtNwKJnY3/aCACBzJRYfPSiPu+YCScOEAsvRrdqVQ7/SedSxNyAFXPvmrJzlI Gxt8LyYUkAS2zilBRHEvM6fmJzxbwWghF1aFhPZAZZZx9FQOA8ngPLTVM/WuJcpBd/mR 2Mlg== X-Gm-Message-State: AOAM532TTGIvsGsXVn9H13F4y3fZtV+L6iTsHn29theLOqLqmEgnLZIb 3+vkFEgUiwMG1XDHj2KXTjCouGvdGqpX5rpZ X-Google-Smtp-Source: ABdhPJyrfyjbtfA0JxkA5vgoLWih/k/V+Mc2oTWoOr8+SD7R0wXR1WHbnIfXo2a3qKPQyBNyHA1qeQ== X-Received: by 2002:a37:b1c2:: with SMTP id a185mr4259576qkf.95.1614281488196; Thu, 25 Feb 2021 11:31:28 -0800 (PST) Received: from sjg1.roam.corp.google.com ([70.127.249.40]) by smtp.gmail.com with ESMTPSA id t19sm4948646qke.109.2021.02.25.11.31.26 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Thu, 25 Feb 2021 11:31:27 -0800 (PST) From: Simon Glass To: U-Boot Mailing List Cc: Farhan Ali , Tom Rini , Andre Przywara , Simon Glass , Alexandru Gagniuc , Marek Vasut , Michal Simek , Philippe Reynes , Samuel Holland Subject: [PATCH] RFC: spl: fit: Use libfdt functions to read stringlist Date: Thu, 25 Feb 2021 14:31:23 -0500 Message-Id: <20210225143118.1.Ib1a20614bbab61d1c9ef8a1df528f10ce98c5bcc@changeid> X-Mailer: git-send-email 2.30.1.766.gb4fecdf3b7-goog MIME-Version: 1.0 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.102.4 at phobos.denx.de X-Virus-Status: Clean At present the code here reimplements a few libfdt functions and does not always respect the property length. The !str check is unlikely to fire since 1 is added to the string address. If strchr() returns NULL then the code produces (void*)1 instead. Also it might extend beyond the property value since strchr() does not have a maximum length. In any case it does not seem worthwhile to implement the libfdt functions again, despite small code-size advantages. There is no function to return the count after a failed get, but we can call two functions. We could add one if code size is considered critical here. Update the code to use libfdt directly. For lion-rk3368 (aarch64) this adds 68 bytes of code. For am57xx_hs_evm (arm) it adds 134 bytes. Signed-off-by: Simon Glass Reviewed-by: Tom Rini --- common/spl/spl_fit.c | 31 +++++++++++-------------------- 1 file changed, 11 insertions(+), 20 deletions(-) diff --git a/common/spl/spl_fit.c b/common/spl/spl_fit.c index 75c8ff065bb..3b5307e4b2d 100644 --- a/common/spl/spl_fit.c +++ b/common/spl/spl_fit.c @@ -83,33 +83,24 @@ static int spl_fit_get_image_name(const struct spl_fit_info *ctx, const char **outname) { struct udevice *sysinfo; - const char *name, *str; - __maybe_unused int node; - int len, i; - bool found = true; - - name = fdt_getprop(ctx->fit, ctx->conf_node, type, &len); - if (!name) { - debug("cannot find property '%s': %d\n", type, len); - return -EINVAL; - } + const char *str; + int count; + bool found; - str = name; - for (i = 0; i < index; i++) { - str = strchr(str, '\0') + 1; - if (!str || (str - name >= len)) { - found = false; - break; - } - } + count = fdt_stringlist_count(ctx->fit, ctx->conf_node, type); + str = fdt_stringlist_get(ctx->fit, ctx->conf_node, type, index, NULL); + found = str; if (!found && CONFIG_IS_ENABLED(SYSINFO) && !sysinfo_get(&sysinfo)) { int rc; /* * no string in the property for this index. Check if the - * sysinfo-level code can supply one. + * sysinfo-level code can supply one. Subtract the number of + * strings found in the devicetre node, so that @index numbers + * the options in order from 0, starting with the devicetree + * property and ending with sysinfo. */ - rc = sysinfo_get_fit_loadable(sysinfo, index - i - 1, type, + rc = sysinfo_get_fit_loadable(sysinfo, index - count, type, &str); if (rc && rc != -ENOENT) return rc;