+static uint32_t partition_entries_offset(struct blk_desc *dev_desc)
+{
+ uint32_t offset_blks = 2;
+ uint32_t __maybe_unused offset_bytes;
+ int __maybe_unused config_offset;
+
+#if defined(CONFIG_EFI_PARTITION_ENTRIES_OFF)
+ /*
+ * Some architectures require their SPL loader at a fixed
+ * address within the first 16KB of the disk. To avoid an
+ * overlap with the partition entries of the EFI partition
+ * table, the first safe offset (in bytes, from the start of
+ * the disk) for the entries can be set in
+ * CONFIG_EFI_PARTITION_ENTRIES_OFF.
+ */
+ offset_bytes =
+ PAD_TO_BLOCKSIZE(CONFIG_EFI_PARTITION_ENTRIES_OFF, dev_desc);
+ offset_blks = offset_bytes / dev_desc->blksz;
+#endif
+
+#if defined(CONFIG_OF_CONTROL)
+ /*
+ * Allow the offset of the first partition entires (in bytes
+ * from the start of the device) to be specified as a property
+ * of the device tree '/config' node.
+ */
+ config_offset = fdtdec_get_config_int(gd->fdt_blob,
+ "u-boot,efi-partition-entries-offset",
+ -EINVAL);
+ if (config_offset != -EINVAL) {
+ offset_bytes = PAD_TO_BLOCKSIZE(config_offset, dev_desc);
+ offset_blks = offset_bytes / dev_desc->blksz;
+ }
+#endif
+
+ debug("efi: partition entries offset (in blocks): %d\n", offset_blks);
+
+ /*
+ * The earliest LBA this can be at is LBA#2 (i.e. right behind
+ * the (protective) MBR and the GPT header.
+ */
+ if (offset_blks < 2)
+ offset_blks = 2;
+
+ return offset_blks;
+}
+