From: Oleksij Rempel <o.rempel@pengutronix.de>
To: barebox@lists.infradead.org
Cc: Oleksij Rempel <o.rempel@pengutronix.de>
Subject: [PATCH v2 06/10] ARM: i.MX8MP: skov: refactor bootsource and BBU handlers
Date: Mon, 2 Oct 2023 12:16:50 +0200 [thread overview]
Message-ID: <20231002101654.2373000-7-o.rempel@pengutronix.de> (raw)
In-Reply-To: <20231002101654.2373000-1-o.rempel@pengutronix.de>
Rework boot source and Barebox Update (BBU) handlers to support
multiple storage options in a scalable way. This commit allows for
easier extension and better maintainability.
Signed-off-by: Oleksij Rempel <o.rempel@pengutronix.de>
---
arch/arm/boards/skov-imx8mp/board.c | 105 +++++++++++++++++++++++++---
1 file changed, 95 insertions(+), 10 deletions(-)
diff --git a/arch/arm/boards/skov-imx8mp/board.c b/arch/arm/boards/skov-imx8mp/board.c
index 398c74677d..58aca69236 100644
--- a/arch/arm/boards/skov-imx8mp/board.c
+++ b/arch/arm/boards/skov-imx8mp/board.c
@@ -9,21 +9,106 @@
#include <mach/imx/bbu.h>
#include <mach/imx/iomux-mx8mp.h>
-static int skov_imx8mp_probe(struct device *dev)
+struct skov_imx8mp_storage {
+ const char *name;
+ const char *env_path;
+ const char *dev_path;
+ enum bootsource bootsource;
+ int bootsource_ext_id;
+ bool mmc_boot_part;
+};
+
+enum skov_imx8mp_boot_source {
+ SKOV_BOOT_SOURCE_EMMC,
+ SKOV_BOOT_SOURCE_SD,
+ SKOV_BOOT_SOURCE_UNKNOWN,
+};
+
+static const struct skov_imx8mp_storage skov_imx8mp_storages[] = {
+ [SKOV_BOOT_SOURCE_EMMC] = {
+ /* default boot source */
+ .name = "eMMC",
+ .env_path = "/chosen/environment-emmc",
+ .dev_path = "/dev/mmc2",
+ .bootsource = BOOTSOURCE_MMC,
+ .bootsource_ext_id = 2,
+ .mmc_boot_part = true,
+ },
+ [SKOV_BOOT_SOURCE_SD] = {
+ .name = "SD",
+ .env_path = "/chosen/environment-sd",
+ .dev_path = "/dev/mmc1.barebox",
+ .bootsource = BOOTSOURCE_MMC,
+ .bootsource_ext_id = 1,
+ },
+};
+
+static void skov_imx8mp_enable_env(struct device *dev,
+ const struct skov_imx8mp_storage *st,
+ bool *enabled)
{
- int emmc_bbu_flag = 0;
- int sd_bbu_flag = 0;
+ int ret;
- if (bootsource_get() == BOOTSOURCE_MMC && bootsource_get_instance() == 1) {
- of_device_enable_path("/chosen/environment-sd");
- sd_bbu_flag = BBU_HANDLER_FLAG_DEFAULT;
+ if (bootsource_get() != st->bootsource ||
+ bootsource_get_instance() != st->bootsource_ext_id)
+ return;
+
+ ret = of_device_enable_path(st->env_path);
+ if (ret) {
+ dev_err(dev, "Failed to enable environment path: %s, %pe\n",
+ st->env_path, ERR_PTR(ret));
+ return;
+ }
+
+ *enabled = true;
+}
+
+static void skov_imx8mp_add_bbu(struct device *dev,
+ const struct skov_imx8mp_storage *st,
+ bool default_env)
+{
+ unsigned long flags = 0;
+ int ret;
+
+ if (default_env)
+ flags |= BBU_HANDLER_FLAG_DEFAULT;
+
+ if (st->mmc_boot_part) {
+ ret = imx8m_bbu_internal_mmcboot_register_handler(st->name,
+ st->dev_path,
+ flags);
} else {
- of_device_enable_path("/chosen/environment-emmc");
- emmc_bbu_flag = BBU_HANDLER_FLAG_DEFAULT;
+ ret = imx8m_bbu_internal_mmc_register_handler(st->name,
+ st->dev_path,
+ flags);
+ }
+ if (ret)
+ dev_err(dev, "Failed to register %s BBU handler: %pe\n",
+ st->name, ERR_PTR(ret));
+}
+
+static void skov_imx8mp_init_storage(struct device *dev)
+{
+ int default_boot_src = SKOV_BOOT_SOURCE_EMMC;
+ int i;
+
+ for (i = 0; i < ARRAY_SIZE(skov_imx8mp_storages); i++) {
+ bool enabled_env = false;
+
+ skov_imx8mp_enable_env(dev, &skov_imx8mp_storages[i],
+ &enabled_env);
+ if (enabled_env)
+ default_boot_src = i;
}
- imx8m_bbu_internal_mmc_register_handler("SD", "/dev/mmc1.barebox", sd_bbu_flag);
- imx8m_bbu_internal_mmcboot_register_handler("eMMC", "/dev/mmc2", emmc_bbu_flag);
+ for (i = 0; i < ARRAY_SIZE(skov_imx8mp_storages); i++)
+ skov_imx8mp_add_bbu(dev, &skov_imx8mp_storages[i],
+ i == default_boot_src);
+}
+
+static int skov_imx8mp_probe(struct device *dev)
+{
+ skov_imx8mp_init_storage(dev);
return 0;
}
--
2.39.2
next prev parent reply other threads:[~2023-10-02 10:18 UTC|newest]
Thread overview: 16+ messages / expand[flat|nested] mbox.gz Atom feed top
2023-10-02 10:16 [PATCH v2 00/10] SKOV maintenance Oleksij Rempel
2023-10-02 10:16 ` [PATCH v2 01/10] arm: dts: imx8mp-skov: Add reserved-memory for ramoops pstore Oleksij Rempel
2023-10-02 10:16 ` [PATCH v2 02/10] arm: dts: imx8mp-skov: Add pins for hardware variant detection Oleksij Rempel
2023-10-02 10:16 ` [PATCH v2 03/10] arm: dts: imx8mp-skov: Switch to GPT for eMMC partitioning Oleksij Rempel
2023-10-02 10:16 ` [PATCH v2 04/10] arm: dts: imx8mp-skov: Switch to GPT for SD partitioning Oleksij Rempel
2023-10-02 10:16 ` [PATCH v2 05/10] arm: dts: imx8mp-skov: Add barebox state backend in DTS Oleksij Rempel
2023-10-02 10:16 ` Oleksij Rempel [this message]
2023-10-02 10:16 ` [PATCH v2 07/10] ARM: i.MX8MP: skov: Add hardware variant support Oleksij Rempel
2023-10-02 10:16 ` [PATCH v2 08/10] ARM: i.MX8MP: skov: fixup skov,imx8mp-board-version DT property for the kernel Oleksij Rempel
2023-10-02 10:16 ` [PATCH v2 09/10] net: lib: add ether_addr_inc() helper Oleksij Rempel
2023-10-04 6:41 ` Sascha Hauer
2023-10-05 6:48 ` Ahmad Fatoum
2023-10-05 7:07 ` Oleksij Rempel
2023-10-06 11:44 ` Sascha Hauer
2023-10-02 10:16 ` [PATCH v2 10/10] ARM: i.MX8MP: skov: assign Ethernet addresses to all ports Oleksij Rempel
2023-10-05 6:52 ` Ahmad Fatoum
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=20231002101654.2373000-7-o.rempel@pengutronix.de \
--to=o.rempel@pengutronix.de \
--cc=barebox@lists.infradead.org \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox