]> Git Repo - u-boot.git/blobdiff - lib/fwu_updates/fwu_mtd.c
Merge patch series "FWU: Add support for FWU metadata version 2"
[u-boot.git] / lib / fwu_updates / fwu_mtd.c
index b73111ae24da7a64557d5208af869ed54c411552..ccaba3f3115ae97aa77dcb309396dcdfbdd50c8c 100644 (file)
 #include <malloc.h>
 #include <mtd.h>
 #include <uuid.h>
-#include <vsprintf.h>
+#include <stdio.h>
 
 #include <dm/ofnode.h>
 
-struct fwu_mtd_image_info
-fwu_mtd_images[CONFIG_FWU_NUM_BANKS * CONFIG_FWU_NUM_IMAGES_PER_BANK];
-
 static struct fwu_mtd_image_info *mtd_img_by_uuid(const char *uuidbuf)
 {
-       int num_images = ARRAY_SIZE(fwu_mtd_images);
+       int num_images;
+       struct fwu_mdata_mtd_priv *mtd_priv = dev_get_priv(fwu_get_dev());
+       struct fwu_mtd_image_info *image_info = mtd_priv->fwu_mtd_images;
+
+       if (!image_info)
+               return NULL;
+
+       num_images = CONFIG_FWU_NUM_BANKS *
+               CONFIG_FWU_NUM_IMAGES_PER_BANK;
 
        for (int i = 0; i < num_images; i++)
-               if (!strcmp(uuidbuf, fwu_mtd_images[i].uuidbuf))
-                       return &fwu_mtd_images[i];
+               if (!strcmp(uuidbuf, image_info[i].uuidbuf))
+                       return &image_info[i];
 
        return NULL;
 }
@@ -107,7 +112,7 @@ __weak int fwu_plat_get_alt_num(struct udevice *dev, efi_guid_t *image_id,
        return fwu_mtd_get_alt_num(image_id, alt_num, "nor1");
 }
 
-static int gen_image_alt_info(char *buf, size_t len, int sidx,
+static int gen_image_alt_info(char *buf, size_t len,
                              struct fwu_image_entry *img, struct mtd_info *mtd)
 {
        char *p = buf, *end = buf + len;
@@ -131,7 +136,7 @@ static int gen_image_alt_info(char *buf, size_t len, int sidx,
 
                /* Query a partition by image UUID */
                bank = &img->img_bank_info[i];
-               uuid_bin_to_str(bank->image_uuid.b, uuidbuf, UUID_STR_FORMAT_STD);
+               uuid_bin_to_str(bank->image_guid.b, uuidbuf, UUID_STR_FORMAT_STD);
 
                mtd_img_info = mtd_img_by_uuid(uuidbuf);
                if (!mtd_img_info) {
@@ -158,25 +163,22 @@ static int gen_image_alt_info(char *buf, size_t len, int sidx,
 
 int fwu_gen_alt_info_from_mtd(char *buf, size_t len, struct mtd_info *mtd)
 {
-       struct fwu_mdata mdata;
        int i, l, ret;
-
-       ret = fwu_get_mdata(&mdata);
-       if (ret < 0) {
-               log_err("Failed to get the FWU mdata.\n");
-               return ret;
-       }
+       struct fwu_data *data = fwu_get_data();
+       struct fwu_image_entry *img_entry;
 
        for (i = 0; i < CONFIG_FWU_NUM_IMAGES_PER_BANK; i++) {
-               ret = gen_image_alt_info(buf, len, i * CONFIG_FWU_NUM_BANKS,
-                                        &mdata.img_entry[i], mtd);
+               img_entry = &data->fwu_images[i];
+               ret = gen_image_alt_info(buf, len, img_entry, mtd);
                if (ret)
                        break;
 
                l = strlen(buf);
                /* Replace the last ';' with '&' if there is another image. */
-               if (i != CONFIG_FWU_NUM_IMAGES_PER_BANK - 1 && l)
-                       buf[l - 1] = '&';
+               if (i != CONFIG_FWU_NUM_IMAGES_PER_BANK - 1 && l) {
+                       buf[l] = '&';
+                       buf++;
+               }
                len -= l;
                buf += l;
        }
This page took 0.027806 seconds and 4 git commands to generate.