From patchwork Wed Dec 7 08:50:31 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Simon Glass X-Patchwork-Id: 1713073 X-Patchwork-Delegate: trini@ti.com Return-Path: X-Original-To: incoming@patchwork.ozlabs.org Delivered-To: patchwork-incoming@legolas.ozlabs.org Authentication-Results: legolas.ozlabs.org; spf=pass (sender SPF authorized) smtp.mailfrom=lists.denx.de (client-ip=2a01:238:438b:c500:173d:9f52:ddab:ee01; helo=phobos.denx.de; envelope-from=u-boot-bounces@lists.denx.de; receiver=) Authentication-Results: legolas.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=MI8eTrjb; dkim-atps=neutral Received: from phobos.denx.de (phobos.denx.de [IPv6:2a01:238:438b:c500:173d:9f52:ddab:ee01]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature ECDSA (P-384)) (No client certificate requested) by legolas.ozlabs.org (Postfix) with ESMTPS id 4NRrhN0r0Pz23ns for ; Wed, 7 Dec 2022 19:55:00 +1100 (AEDT) Received: from h2850616.stratoserver.net (localhost [IPv6:::1]) by phobos.denx.de (Postfix) with ESMTP id 2F9DC85582; Wed, 7 Dec 2022 09:54:10 +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="MI8eTrjb"; dkim-atps=neutral Received: by phobos.denx.de (Postfix, from userid 109) id 1FB088557A; Wed, 7 Dec 2022 09:54:08 +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.1 required=5.0 tests=BAYES_00,DKIMWL_WL_HIGH, DKIM_SIGNED,DKIM_VALID,DKIM_VALID_AU,DKIM_VALID_EF,SPF_HELO_NONE, SPF_PASS autolearn=unavailable autolearn_force=no version=3.4.2 Received: from mail-pf1-x431.google.com (mail-pf1-x431.google.com [IPv6:2607:f8b0:4864:20::431]) (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 D746485467 for ; Wed, 7 Dec 2022 09:54:04 +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-pf1-x431.google.com with SMTP id 140so16953012pfz.6 for ; Wed, 07 Dec 2022 00:54:04 -0800 (PST) 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 :message-id:reply-to; bh=gdnqDcNn9bQSsob8nBsBGor/5oARsf2NMaFOdGRCUa8=; b=MI8eTrjbujYTissEcf9l4WRhdz3YW+8NbTyYCrZ2koZVYaEM+ZXLZMO/zgMEsGi9by IN2R35eQ61ZWvHt45JSHfuqF0D3dIXdAIrzG7rOhXq9WiK8qa7Atna8pDVFdkMmBWXbJ Qm5ip6CgrgDWEFsl5vepSOE34oH1xfM3CBdKI= 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:message-id:reply-to; bh=gdnqDcNn9bQSsob8nBsBGor/5oARsf2NMaFOdGRCUa8=; b=36z2asV/w7Cv62LB7A1407+Gt14WRSE7doSJlweNtaCI/g8raDwZz4CqJgIMYAdKW7 foc+QyxO3UbOtCBNOjarz+ModnGJf2Lo9olVXhx8u7pdFSBcKOlBDUab2d7aJzltjI+i q7jiXMMzRmh0sIhbmGHyOzqBYDfIjNF7NmnZhx/J7Tkot0s6Jnz32DahSuVs1w+ZNVpU jjO26UFMMXuEtw9P4bzyKvDsmACChyoEoPzPwRLNE/ykzBjxdluiefvtr5dCaOD3efi+ vx1tDXsUUFZ10qa+ycaFW3Zk7APLRmuuX757Hn4+AjzNqKwH4aaJZgdf/4hewha9+AM2 xfJA== X-Gm-Message-State: ANoB5plNFZxp3Yo/284hvIWS5fVZdeaSqcGP5fm6ujip6petj7g9gMrn AP0nbxZAcdelQeVBSpqvI4NoUEUuCL8qdtxF X-Google-Smtp-Source: AA0mqf51ARbx4VIXsn0Ks1r8g9xUTHDRqnI5m4sRNSBQk/m6thv6WGY9qyn254LFKF3A3mRTmt7oyg== X-Received: by 2002:a62:648a:0:b0:572:76dd:3756 with SMTP id y132-20020a62648a000000b0057276dd3756mr74178529pfb.9.1670403242747; Wed, 07 Dec 2022 00:54:02 -0800 (PST) Received: from localhost.localdomain ([27.110.126.54]) by smtp.gmail.com with ESMTPSA id l16-20020a170903121000b0018157b415dbsm14145514plh.63.2022.12.07.00.54.00 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Wed, 07 Dec 2022 00:54:02 -0800 (PST) From: Simon Glass To: U-Boot Mailing List Cc: U-Boot Custodians , Simon Glass Subject: [PATCH 05/71] bootstd: Remove special-case code for boot_targets Date: Wed, 7 Dec 2022 21:50:31 +1300 Message-Id: <20221207085137.445249-6-sjg@chromium.org> X-Mailer: git-send-email 2.39.0.rc0.267.gcb52ba06e7-goog In-Reply-To: <20221207085137.445249-1-sjg@chromium.org> References: <20221207085137.445249-1-sjg@chromium.org> MIME-Version: 1.0 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 Rather than implement this as its own case in build_order(), process the boot_targets environment variable in the bootstd_get_bootdev_order() function. This allows build_order() to be simplified. Signed-off-by: Simon Glass --- boot/bootdev-uclass.c | 32 +++++--------------------------- boot/bootstd-uclass.c | 17 ++++++++++++++++- include/bootstd.h | 14 +++++++++++--- 3 files changed, 32 insertions(+), 31 deletions(-) diff --git a/boot/bootdev-uclass.c b/boot/bootdev-uclass.c index affe0d3e04e..696efb4b19e 100644 --- a/boot/bootdev-uclass.c +++ b/boot/bootdev-uclass.c @@ -12,7 +12,6 @@ #include #include #include -#include #include #include #include @@ -504,34 +503,13 @@ static int build_order(struct udevice *bootstd, struct udevice **order, const char *overflow_target = NULL; const char *const *labels; struct udevice *dev; - const char *targets; int i, ret, count; + bool ok; - targets = env_get("boot_targets"); - labels = IS_ENABLED(CONFIG_BOOTSTD_FULL) ? - bootstd_get_bootdev_order(bootstd) : NULL; - if (targets) { - char str[BOOT_TARGETS_MAX_LEN]; - char *target; - - if (strlen(targets) >= BOOT_TARGETS_MAX_LEN) - return log_msg_ret("len", -E2BIG); - - /* make a copy of the string, since strok() will change it */ - strcpy(str, targets); - for (i = 0, target = strtok(str, " "); target; - target = strtok(NULL, " ")) { - ret = bootdev_find_by_label(target, &dev); - if (!ret) { - if (i == max_count) { - overflow_target = target; - break; - } - order[i++] = dev; - } - } - count = i; - } else if (labels) { + labels = bootstd_get_bootdev_order(bootstd, &ok); + if (!ok) + return log_msg_ret("ord", -ENOMEM); + if (labels) { int upto; upto = 0; diff --git a/boot/bootstd-uclass.c b/boot/bootstd-uclass.c index 565c22a36e7..8b44edc42a8 100644 --- a/boot/bootstd-uclass.c +++ b/boot/bootstd-uclass.c @@ -10,6 +10,7 @@ #include #include #include +#include #include #include #include @@ -70,9 +71,23 @@ static int bootstd_remove(struct udevice *dev) return 0; } -const char *const *const bootstd_get_bootdev_order(struct udevice *dev) +const char *const *const bootstd_get_bootdev_order(struct udevice *dev, + bool *okp) { struct bootstd_priv *std = dev_get_priv(dev); + const char *targets = env_get("boot_targets"); + + *okp = true; + log_debug("- targets %s %p\n", targets, std->bootdev_order); + if (targets && *targets) { + str_free_list(std->env_order); + std->env_order = str_to_list(targets); + if (!std->env_order) { + *okp = false; + return NULL; + } + return std->env_order; + } return std->bootdev_order; } diff --git a/include/bootstd.h b/include/bootstd.h index 01be249d16e..a826bd5f247 100644 --- a/include/bootstd.h +++ b/include/bootstd.h @@ -20,7 +20,10 @@ struct udevice; * @prefixes: NULL-terminated list of prefixes to use for bootflow filenames, * e.g. "/", "/boot/"; NULL if none * @bootdev_order: Order to use for bootdevs (or NULL if none), with each item - * being a bootdev label, e.g. "mmc2", "mmc1"; + * being a bootdev label, e.g. "mmc2", "mmc1" (NULL terminated) + * @env_order: Order as specified by the boot_targets env var (or NULL if none), + * with each item being a bootdev label, e.g. "mmc2", "mmc1" (NULL + * terminated) * @cur_bootdev: Currently selected bootdev (for commands) * @cur_bootflow: Currently selected bootflow (for commands) * @glob_head: Head for the global list of all bootflows across all bootdevs @@ -31,6 +34,7 @@ struct udevice; struct bootstd_priv { const char **prefixes; const char **bootdev_order; + const char **env_order; struct udevice *cur_bootdev; struct bootflow *cur_bootflow; struct list_head glob_head; @@ -47,9 +51,13 @@ struct bootstd_priv { * The list is alloced by the bootstd driver so should not be freed. That is the * reason for all the const stuff in the function signature * - * Return: list of string points, terminated by NULL; or NULL if no boot order + * @dev: bootstd device + * @okp: returns true if OK, false if out of memory + * Return: list of string pointers, terminated by NULL; or NULL if no boot + * order. Note that this returns NULL in the case of an empty list */ -const char *const *const bootstd_get_bootdev_order(struct udevice *dev); +const char *const *const bootstd_get_bootdev_order(struct udevice *dev, + bool *okp); /** * bootstd_get_prefixes() - Get the filename-prefixes list