U-boot Archive mirror
 help / color / mirror / Atom feed
From: Weizhao Ouyang <o451686892@gmail.com>
To: Tom Rini <trini@konsulko.com>, Simon Glass <sjg@chromium.org>,
	Philipp Tomsich <philipp.tomsich@vrull.eu>,
	Kever Yang <kever.yang@rock-chips.com>,
	Jagan Teki <jagan@amarulasolutions.com>,
	Jonas Karlman <jonas@kwiboo.se>,
	Quentin Schulz <quentin.schulz@theobroma-systems.com>,
	John Keeping <john@metanate.com>,
	Dragan Simic <dsimic@manjaro.org>,
	Weizhao Ouyang <o451686892@gmail.com>,
	Chris Morgan <macromorgan@hotmail.com>,
	Ben Wolsieffer <benwolsieffer@gmail.com>,
	Masahisa Kojima <kojima.masahisa@socionext.com>,
	Peter Robinson <pbrobinson@gmail.com>,
	Ilias Apalodimas <ilias.apalodimas@linaro.org>,
	u-boot@lists.denx.de
Subject: [PATCH] arm: rockchip: using generic capsule update mechanism
Date: Wed,  8 May 2024 19:16:00 +0800	[thread overview]
Message-ID: <20240508111600.154919-1-o451686892@gmail.com> (raw)

Currently Rockchip's capsule update mechanism only accepts capsules in
form of a mmc partition, but a generic capsule update mechanism should
be used to satisfy the universal requirements.

Signed-off-by: Weizhao Ouyang <o451686892@gmail.com>
---
 arch/arm/mach-rockchip/board.c              | 153 ------------------
 board/radxa/rockpi4-rk3399/rockpi4-rk3399.c | 166 +++++++++++++++++++-
 2 files changed, 158 insertions(+), 161 deletions(-)

diff --git a/arch/arm/mach-rockchip/board.c b/arch/arm/mach-rockchip/board.c
index cd226844b6..73fbb3f58c 100644
--- a/arch/arm/mach-rockchip/board.c
+++ b/arch/arm/mach-rockchip/board.c
@@ -35,155 +35,6 @@
 #include <asm/arch-rockchip/periph.h>
 #include <power/regulator.h>
 
-#if IS_ENABLED(CONFIG_EFI_HAVE_CAPSULE_SUPPORT) && IS_ENABLED(CONFIG_EFI_PARTITION)
-
-#define DFU_ALT_BUF_LEN			SZ_1K
-
-static struct efi_fw_image *fw_images;
-
-static bool updatable_image(struct disk_partition *info)
-{
-	int i;
-	bool ret = false;
-	efi_guid_t image_type_guid;
-
-	uuid_str_to_bin(info->type_guid, image_type_guid.b,
-			UUID_STR_FORMAT_GUID);
-
-	for (i = 0; i < update_info.num_images; i++) {
-		if (!guidcmp(&fw_images[i].image_type_id, &image_type_guid)) {
-			ret = true;
-			break;
-		}
-	}
-
-	return ret;
-}
-
-static void set_image_index(struct disk_partition *info, int index)
-{
-	int i;
-	efi_guid_t image_type_guid;
-
-	uuid_str_to_bin(info->type_guid, image_type_guid.b,
-			UUID_STR_FORMAT_GUID);
-
-	for (i = 0; i < update_info.num_images; i++) {
-		if (!guidcmp(&fw_images[i].image_type_id, &image_type_guid)) {
-			fw_images[i].image_index = index;
-			break;
-		}
-	}
-}
-
-static int get_mmc_desc(struct blk_desc **desc)
-{
-	int ret;
-	struct mmc *mmc;
-	struct udevice *dev;
-
-	/*
-	 * For now the firmware images are assumed to
-	 * be on the SD card
-	 */
-	ret = uclass_get_device(UCLASS_MMC, 1, &dev);
-	if (ret)
-		return -1;
-
-	mmc = mmc_get_mmc_dev(dev);
-	if (!mmc)
-		return -ENODEV;
-
-	if ((ret = mmc_init(mmc)))
-		return ret;
-
-	*desc = mmc_get_blk_desc(mmc);
-	if (!*desc)
-		return -1;
-
-	return 0;
-}
-
-void set_dfu_alt_info(char *interface, char *devstr)
-{
-	const char *name;
-	bool first = true;
-	int p, len, devnum, ret;
-	char buf[DFU_ALT_BUF_LEN];
-	struct disk_partition info;
-	struct blk_desc *desc = NULL;
-
-	ret = get_mmc_desc(&desc);
-	if (ret) {
-		log_err("Unable to get mmc desc\n");
-		return;
-	}
-
-	memset(buf, 0, sizeof(buf));
-	name = blk_get_uclass_name(desc->uclass_id);
-	devnum = desc->devnum;
-	len = strlen(buf);
-
-	len += snprintf(buf + len, DFU_ALT_BUF_LEN - len,
-			 "%s %d=", name, devnum);
-
-	for (p = 1; p <= MAX_SEARCH_PARTITIONS; p++) {
-		if (part_get_info(desc, p, &info))
-			continue;
-
-		/* Add entry to dfu_alt_info only for updatable images */
-		if (updatable_image(&info)) {
-			if (!first)
-				len += snprintf(buf + len,
-						DFU_ALT_BUF_LEN - len, ";");
-
-			len += snprintf(buf + len, DFU_ALT_BUF_LEN - len,
-					"%s%d_%s part %d %d",
-					name, devnum, info.name, devnum, p);
-			first = false;
-		}
-	}
-
-	log_debug("dfu_alt_info => %s\n", buf);
-	env_set("dfu_alt_info", buf);
-}
-
-__weak void rockchip_capsule_update_board_setup(void)
-{
-}
-
-static void gpt_capsule_update_setup(void)
-{
-	int p, i, ret;
-	struct disk_partition info;
-	struct blk_desc *desc = NULL;
-
-	fw_images = update_info.images;
-	rockchip_capsule_update_board_setup();
-
-	ret = get_mmc_desc(&desc);
-	if (ret) {
-		log_err("Unable to get mmc desc\n");
-		return;
-	}
-
-	for (p = 1, i = 1; p <= MAX_SEARCH_PARTITIONS; p++) {
-		if (part_get_info(desc, p, &info))
-			continue;
-
-		/*
-		 * Since we have a GPT partitioned device, the updatable
-		 * images could be stored in any order. Populate the
-		 * image_index at runtime.
-		 */
-		if (updatable_image(&info)) {
-			set_image_index(&info, i);
-			i++;
-		}
-	}
-}
-#endif /* CONFIG_EFI_HAVE_CAPSULE_SUPPORT && CONFIG_EFI_PARTITION */
-
 __weak int rk_board_late_init(void)
 {
 	return 0;
@@ -193,10 +44,6 @@ int board_late_init(void)
 {
 	setup_boot_mode();
 
-#if IS_ENABLED(CONFIG_EFI_HAVE_CAPSULE_SUPPORT) && IS_ENABLED(CONFIG_EFI_PARTITION)
-	gpt_capsule_update_setup();
-#endif
-
 	return rk_board_late_init();
 }
 
diff --git a/board/radxa/rockpi4-rk3399/rockpi4-rk3399.c b/board/radxa/rockpi4-rk3399/rockpi4-rk3399.c
index a533128b92..01c3b7d5a2 100644
--- a/board/radxa/rockpi4-rk3399/rockpi4-rk3399.c
+++ b/board/radxa/rockpi4-rk3399/rockpi4-rk3399.c
@@ -4,22 +4,132 @@
  */
 
 #include <dm.h>
+#include <mmc.h>
+#include <part.h>
 #include <efi_loader.h>
 
 #define ROCKPI4_UPDATABLE_IMAGES	2
 
-#if IS_ENABLED(CONFIG_EFI_HAVE_CAPSULE_SUPPORT)
-static struct efi_fw_image fw_images[ROCKPI4_UPDATABLE_IMAGES] = {0};
+#if IS_ENABLED(CONFIG_EFI_HAVE_CAPSULE_SUPPORT) && IS_ENABLED(CONFIG_EFI_PARTITION)
+
+#define DFU_ALT_BUF_LEN			SZ_1K
+
+static struct efi_fw_image *fw_images = {0};
+static struct efi_fw_image fw_images_d[ROCKPI4_UPDATABLE_IMAGES] = {0};
 
 struct efi_capsule_update_info update_info = {
 	.num_images = ROCKPI4_UPDATABLE_IMAGES,
-	.images = fw_images,
+	.images = fw_images_d,
 };
 
-#endif
+static bool updatable_image(struct disk_partition *info)
+{
+	int i;
+	bool ret = false;
+	efi_guid_t image_type_guid;
+
+	uuid_str_to_bin(info->type_guid, image_type_guid.b,
+			UUID_STR_FORMAT_GUID);
+
+	for (i = 0; i < update_info.num_images; i++) {
+		if (!guidcmp(&fw_images[i].image_type_id, &image_type_guid)) {
+			ret = true;
+			break;
+		}
+	}
+
+	return ret;
+}
+
+static void set_image_index(struct disk_partition *info, int index)
+{
+	int i;
+	efi_guid_t image_type_guid;
+
+	uuid_str_to_bin(info->type_guid, image_type_guid.b,
+			UUID_STR_FORMAT_GUID);
+
+	for (i = 0; i < update_info.num_images; i++) {
+		if (!guidcmp(&fw_images[i].image_type_id, &image_type_guid)) {
+			fw_images[i].image_index = index;
+			break;
+		}
+	}
+}
+
+static int get_mmc_desc(struct blk_desc **desc)
+{
+	int ret;
+	struct mmc *mmc;
+	struct udevice *dev;
+
+	/*
+	 * For now the firmware images are assumed to
+	 * be on the SD card
+	 */
+	ret = uclass_get_device(UCLASS_MMC, 1, &dev);
+	if (ret)
+		return -1;
+
+	mmc = mmc_get_mmc_dev(dev);
+	if (!mmc)
+		return -ENODEV;
+
+	ret = mmc_init(mmc);
+	if (ret)
+		return ret;
+
+	*desc = mmc_get_blk_desc(mmc);
+	if (!*desc)
+		return -1;
+
+	return 0;
+}
+
+void set_dfu_alt_info(char *interface, char *devstr)
+{
+	const char *name;
+	bool first = true;
+	int p, len, devnum, ret;
+	char buf[DFU_ALT_BUF_LEN];
+	struct disk_partition info;
+	struct blk_desc *desc = NULL;
+
+	ret = get_mmc_desc(&desc);
+	if (ret) {
+		log_err("Unable to get mmc desc\n");
+		return;
+	}
+
+	memset(buf, 0, sizeof(buf));
+	name = blk_get_uclass_name(desc->uclass_id);
+	devnum = desc->devnum;
+	len = strlen(buf);
+
+	len += snprintf(buf + len, DFU_ALT_BUF_LEN - len,
+			 "%s %d=", name, devnum);
+
+	for (p = 1; p <= MAX_SEARCH_PARTITIONS; p++) {
+		if (part_get_info(desc, p, &info))
+			continue;
+
+		/* Add entry to dfu_alt_info only for updatable images */
+		if (updatable_image(&info)) {
+			if (!first)
+				len += snprintf(buf + len,
+						DFU_ALT_BUF_LEN - len, ";");
+
+			len += snprintf(buf + len, DFU_ALT_BUF_LEN - len,
+					"%s%d_%s part %d %d",
+					name, devnum, info.name, devnum, p);
+			first = false;
+		}
+	}
+
+	log_debug("dfu_alt_info => %s\n", buf);
+	env_set("dfu_alt_info", buf);
+}
 
-#ifndef CONFIG_SPL_BUILD
-#if IS_ENABLED(CONFIG_EFI_HAVE_CAPSULE_SUPPORT) && IS_ENABLED(CONFIG_EFI_PARTITION)
 static bool board_is_rockpi_4b(void)
 {
 	return of_machine_is_compatible("radxa,rockpi4b");
@@ -30,7 +140,7 @@ static bool board_is_rockpi_4c(void)
 	return of_machine_is_compatible("radxa,rockpi4c");
 }
 
-void rockchip_capsule_update_board_setup(void)
+static void rockchip_capsule_update_board_setup(void)
 {
 	if (board_is_rockpi_4b()) {
 		efi_guid_t idbldr_image_type_guid =
@@ -54,5 +164,45 @@ void rockchip_capsule_update_board_setup(void)
 		fw_images[1].fw_name = u"ROCKPI4C-UBOOT";
 	}
 }
+
+static void gpt_capsule_update_setup(void)
+{
+	int p, i, ret;
+	struct disk_partition info;
+	struct blk_desc *desc = NULL;
+
+	fw_images = update_info.images;
+	rockchip_capsule_update_board_setup();
+
+	ret = get_mmc_desc(&desc);
+	if (ret) {
+		log_err("Unable to get mmc desc\n");
+		return;
+	}
+
+	for (p = 1, i = 1; p <= MAX_SEARCH_PARTITIONS; p++) {
+		if (part_get_info(desc, p, &info))
+			continue;
+
+		/*
+		 * Since we have a GPT partitioned device, the updatable
+		 * images could be stored in any order. Populate the
+		 * image_index at runtime.
+		 */
+		if (updatable_image(&info)) {
+			set_image_index(&info, i);
+			i++;
+		}
+	}
+}
 #endif /* CONFIG_EFI_HAVE_CAPSULE_SUPPORT && CONFIG_EFI_PARTITION */
-#endif /* !CONFIG_SPL_BUILD */
+
+int rk_board_late_init(void)
+{
+#if IS_ENABLED(CONFIG_EFI_HAVE_CAPSULE_SUPPORT) && IS_ENABLED(CONFIG_EFI_PARTITION)
+	gpt_capsule_update_setup();
+#endif
+
+	return 0;
+}
+
-- 
2.40.1


                 reply	other threads:[~2024-05-08 11:16 UTC|newest]

Thread overview: [no followups] expand[flat|nested]  mbox.gz  Atom feed

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=20240508111600.154919-1-o451686892@gmail.com \
    --to=o451686892@gmail.com \
    --cc=benwolsieffer@gmail.com \
    --cc=dsimic@manjaro.org \
    --cc=ilias.apalodimas@linaro.org \
    --cc=jagan@amarulasolutions.com \
    --cc=john@metanate.com \
    --cc=jonas@kwiboo.se \
    --cc=kever.yang@rock-chips.com \
    --cc=kojima.masahisa@socionext.com \
    --cc=macromorgan@hotmail.com \
    --cc=pbrobinson@gmail.com \
    --cc=philipp.tomsich@vrull.eu \
    --cc=quentin.schulz@theobroma-systems.com \
    --cc=sjg@chromium.org \
    --cc=trini@konsulko.com \
    --cc=u-boot@lists.denx.de \
    /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;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).