diff --git a/cmd/efi.c b/cmd/efi.c
index 2511c6cb78a0f188572071ced1b323832ccec5d9..6c1eb88424be054c56d26b90da72f3e637acc2c0 100644
--- a/cmd/efi.c
+++ b/cmd/efi.c
@@ -83,7 +83,7 @@ void *efi_build_mem_table(struct efi_entry_memmap *map, int size, bool skip_bs)
 	prev = NULL;
 	addr = 0;
 	dest = base;
-	end = base + count;
+	end = (struct efi_mem_desc *)((ulong)base + count * map->desc_size);
 	for (desc = base; desc < end; desc = efi_get_next_mem_desc(map, desc)) {
 		bool merge = true;
 		int type = desc->type;