]> git.ipfire.org Git - people/ms/u-boot.git/blobdiff - lib/efi_loader/efi_device_path.c
gpio/hsdk: Depend on DM_GPIO instead of simple DM
[people/ms/u-boot.git] / lib / efi_loader / efi_device_path.c
index 5d5c3b346467d3b2ddcfb3d38c09ee7ba91f7437..b4e2f933cb602113af249c3e9d7aa92b5981440b 100644 (file)
@@ -68,7 +68,8 @@ struct efi_device_path *efi_dp_next(const struct efi_device_path *dp)
  * representing a device with one representing a file on the device, or
  * a device with a parent device.
  */
-int efi_dp_match(struct efi_device_path *a, struct efi_device_path *b)
+int efi_dp_match(const struct efi_device_path *a,
+                const struct efi_device_path *b)
 {
        while (1) {
                int ret;
@@ -127,32 +128,27 @@ static struct efi_object *find_obj(struct efi_device_path *dp, bool short_path,
        struct efi_object *efiobj;
 
        list_for_each_entry(efiobj, &efi_obj_list, link) {
-               int i;
-
-               for (i = 0; i < ARRAY_SIZE(efiobj->protocols); i++) {
-                       struct efi_handler *handler = &efiobj->protocols[i];
-                       struct efi_device_path *obj_dp;
-
-                       if (!handler->guid)
-                               break;
-
-                       if (guidcmp(handler->guid, &efi_guid_device_path))
-                               continue;
-
-                       obj_dp = handler->protocol_interface;
-
-                       do {
-                               if (efi_dp_match(dp, obj_dp) == 0) {
-                                       if (rem) {
-                                               *rem = ((void *)dp) +
-                                                       efi_dp_size(obj_dp);
-                                       }
-                                       return efiobj;
+               struct efi_handler *handler;
+               struct efi_device_path *obj_dp;
+               efi_status_t ret;
+
+               ret = efi_search_protocol(efiobj->handle,
+                                         &efi_guid_device_path, &handler);
+               if (ret != EFI_SUCCESS)
+                       continue;
+               obj_dp = handler->protocol_interface;
+
+               do {
+                       if (efi_dp_match(dp, obj_dp) == 0) {
+                               if (rem) {
+                                       *rem = ((void *)dp) +
+                                               efi_dp_size(obj_dp);
                                }
+                               return efiobj;
+                       }
 
-                               obj_dp = shorten_path(efi_dp_next(obj_dp));
-                       } while (short_path && obj_dp);
-               }
+                       obj_dp = shorten_path(efi_dp_next(obj_dp));
+               } while (short_path && obj_dp);
        }
 
        return NULL;
@@ -427,10 +423,27 @@ static void *dp_part_fill(void *buf, struct blk_desc *desc, int part)
                        hddp->partmap_type = 2;
                else
                        hddp->partmap_type = 1;
-               hddp->signature_type = desc->sig_type;
-               if (hddp->signature_type != 0)
+
+               switch (desc->sig_type) {
+               case SIG_TYPE_NONE:
+               default:
+                       hddp->signature_type = 0;
+                       memset(hddp->partition_signature, 0,
+                              sizeof(hddp->partition_signature));
+                       break;
+               case SIG_TYPE_MBR:
+                       hddp->signature_type = 1;
+                       memset(hddp->partition_signature, 0,
+                              sizeof(hddp->partition_signature));
+                       memcpy(hddp->partition_signature, &desc->mbr_sig,
+                              sizeof(desc->mbr_sig));
+                       break;
+               case SIG_TYPE_GUID:
+                       hddp->signature_type = 2;
                        memcpy(hddp->partition_signature, &desc->guid_sig,
                               sizeof(hddp->partition_signature));
+                       break;
+               }
 
                buf = &hddp[1];
        }
@@ -538,6 +551,30 @@ struct efi_device_path *efi_dp_from_eth(void)
 }
 #endif
 
+/* Construct a device-path for memory-mapped image */
+struct efi_device_path *efi_dp_from_mem(uint32_t memory_type,
+                                       uint64_t start_address,
+                                       uint64_t end_address)
+{
+       struct efi_device_path_memory *mdp;
+       void *buf, *start;
+
+       start = buf = dp_alloc(sizeof(*mdp) + sizeof(END));
+
+       mdp = buf;
+       mdp->dp.type = DEVICE_PATH_TYPE_HARDWARE_DEVICE;
+       mdp->dp.sub_type = DEVICE_PATH_SUB_TYPE_MEMORY;
+       mdp->dp.length = sizeof(*mdp);
+       mdp->memory_type = memory_type;
+       mdp->start_address = start_address;
+       mdp->end_address = end_address;
+       buf = &mdp[1];
+
+       *((struct efi_device_path *)buf) = END;
+
+       return start;
+}
+
 /*
  * Helper to split a full device path (containing both device and file
  * parts) into it's constituent parts.