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 <o451686...@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 via email to