summaryrefslogtreecommitdiff
path: root/meta-arm/meta-arm-bsp/recipes-bsp/trusted-firmware-m/files/corstone1000/0007-Platform-corstone1000-Introduce-GPT-parser.patch
blob: 418c533af0ddea0b6a273fe84ddff7babeaa0a35 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
From 1fdc3000f1ab6f9c1bb792cb8baff16a7517c03a Mon Sep 17 00:00:00 2001
From: Mohamed Omar Asaker <mohamed.omarasaker@arm.com>
Date: Thu, 22 Dec 2022 14:27:41 +0000
Subject: [PATCH 7/10] Platform:corstone1000: Introduce GPT parser

Adding GPT parser
Side changes required:
Includes the implementation of the `plat_get_image_source` function
in the platform.c file.

The GPT parser requires the function. Given the image id, it should
return handle to the IO device contains the image and image
specification that allows IO storage access to the image.

Signed-off-by: Mohamed Omar Asaker <mohamed.omarasaker@arm.com>
Upstream-Status: Pending [Not submitted to upstream yet]
---
 .../target/arm/corstone1000/partition/efi.h   |  36 ++
 .../target/arm/corstone1000/partition/gpt.c   |  58 ++++
 .../target/arm/corstone1000/partition/gpt.h   |  51 +++
 .../target/arm/corstone1000/partition/mbr.h   |  29 ++
 .../arm/corstone1000/partition/partition.c    | 310 ++++++++++++++++++
 .../arm/corstone1000/partition/partition.h    |  47 +++
 .../target/arm/corstone1000/partition/uuid.h  |  76 +++++
 .../ext/target/arm/corstone1000/platform.c    |  20 ++
 .../ext/target/arm/corstone1000/platform.h    |  14 +
 9 files changed, 641 insertions(+)
 create mode 100644 platform/ext/target/arm/corstone1000/partition/efi.h
 create mode 100644 platform/ext/target/arm/corstone1000/partition/gpt.c
 create mode 100644 platform/ext/target/arm/corstone1000/partition/gpt.h
 create mode 100644 platform/ext/target/arm/corstone1000/partition/mbr.h
 create mode 100644 platform/ext/target/arm/corstone1000/partition/partition.c
 create mode 100644 platform/ext/target/arm/corstone1000/partition/partition.h
 create mode 100644 platform/ext/target/arm/corstone1000/partition/uuid.h
 create mode 100644 platform/ext/target/arm/corstone1000/platform.c
 create mode 100644 platform/ext/target/arm/corstone1000/platform.h

diff --git a/platform/ext/target/arm/corstone1000/partition/efi.h b/platform/ext/target/arm/corstone1000/partition/efi.h
new file mode 100644
index 0000000000..f66daffb32
--- /dev/null
+++ b/platform/ext/target/arm/corstone1000/partition/efi.h
@@ -0,0 +1,36 @@
+/*
+ * Copyright (c) 2021, Linaro Limited
+ *
+ * SPDX-License-Identifier: BSD-3-Clause
+ *
+ */
+
+#ifndef DRIVERS_PARTITION_EFI_H
+#define DRIVERS_PARTITION_EFI_H
+
+#include <string.h>
+
+#include "uuid.h"
+
+#define EFI_NAMELEN 36
+
+static inline int guidcmp(const void *g1, const void *g2) {
+    return memcmp(g1, g2, sizeof(struct efi_guid));
+}
+
+static inline void *guidcpy(void *dst, const void *src) {
+    return memcpy(dst, src, sizeof(struct efi_guid));
+}
+
+#define EFI_GUID(a, b, c, d0, d1, d2, d3, d4, d5, d6, d7)  \
+    {                                                      \
+        (a) & 0xffffffff, (b)&0xffff, (c)&0xffff, {        \
+            (d0), (d1), (d2), (d3), (d4), (d5), (d6), (d7) \
+        }                                                  \
+    }
+
+#define NULL_GUID                                                            \
+    EFI_GUID(0x00000000, 0x0000, 0x0000, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, \
+             0x00, 0x00)
+
+#endif /* DRIVERS_PARTITION_EFI_H */
diff --git a/platform/ext/target/arm/corstone1000/partition/gpt.c b/platform/ext/target/arm/corstone1000/partition/gpt.c
new file mode 100644
index 0000000000..8549785e3b
--- /dev/null
+++ b/platform/ext/target/arm/corstone1000/partition/gpt.c
@@ -0,0 +1,58 @@
+/*
+ * Copyright (c) 2016-2022, ARM Limited and Contributors. All rights reserved.
+ *
+ * SPDX-License-Identifier: BSD-3-Clause
+ */
+
+#include "gpt.h"
+
+#include <assert.h>
+#include <errno.h>
+#include <string.h>
+
+#include "efi.h"
+
+static int unicode_to_ascii(unsigned short *str_in, unsigned char *str_out) {
+    uint8_t *name;
+    int i;
+
+    assert((str_in != NULL) && (str_out != NULL));
+
+    name = (uint8_t *)str_in;
+
+    assert(name[0] != '\0');
+
+    /* check whether the unicode string is valid */
+    for (i = 1; i < (EFI_NAMELEN << 1); i += 2) {
+        if (name[i] != '\0') return -EINVAL;
+    }
+    /* convert the unicode string to ascii string */
+    for (i = 0; i < (EFI_NAMELEN << 1); i += 2) {
+        str_out[i >> 1] = name[i];
+        if (name[i] == '\0') break;
+    }
+    return 0;
+}
+
+int parse_gpt_entry(gpt_entry_t *gpt_entry, partition_entry_t *entry) {
+    int result;
+
+    assert((gpt_entry != NULL) && (entry != NULL));
+
+    if ((gpt_entry->first_lba == 0) && (gpt_entry->last_lba == 0)) {
+        return -EINVAL;
+    }
+
+    memset(entry, 0, sizeof(partition_entry_t));
+    result = unicode_to_ascii(gpt_entry->name, (uint8_t *)entry->name);
+    if (result != 0) {
+        return result;
+    }
+    entry->start = (uint64_t)gpt_entry->first_lba * PLAT_PARTITION_BLOCK_SIZE;
+    entry->length = (uint64_t)(gpt_entry->last_lba - gpt_entry->first_lba + 1) *
+                    PLAT_PARTITION_BLOCK_SIZE;
+    guidcpy(&entry->part_guid, &gpt_entry->unique_uuid);
+    guidcpy(&entry->type_guid, &gpt_entry->type_uuid);
+
+    return 0;
+}
diff --git a/platform/ext/target/arm/corstone1000/partition/gpt.h b/platform/ext/target/arm/corstone1000/partition/gpt.h
new file mode 100644
index 0000000000..b528fc05c0
--- /dev/null
+++ b/platform/ext/target/arm/corstone1000/partition/gpt.h
@@ -0,0 +1,51 @@
+/*
+ * Copyright (c) 2016, ARM Limited and Contributors. All rights reserved.
+ *
+ * SPDX-License-Identifier: BSD-3-Clause
+ */
+
+#ifndef GPT_H
+#define GPT_H
+
+#include "efi.h"
+#include "partition.h"
+#include "uuid.h"
+
+#define PARTITION_TYPE_GPT 0xee
+#define GPT_HEADER_OFFSET PLAT_PARTITION_BLOCK_SIZE
+#define GPT_ENTRY_OFFSET (GPT_HEADER_OFFSET + PLAT_PARTITION_BLOCK_SIZE)
+
+#define GPT_SIGNATURE "EFI PART"
+
+typedef struct gpt_entry {
+    struct efi_guid type_uuid;
+    struct efi_guid unique_uuid;
+    unsigned long long first_lba;
+    unsigned long long last_lba;
+    unsigned long long attr;
+    unsigned short name[EFI_NAMELEN];
+} gpt_entry_t;
+
+typedef struct gpt_header {
+    unsigned char signature[8];
+    unsigned int revision;
+    unsigned int size;
+    unsigned int header_crc;
+    unsigned int reserved;
+    unsigned long long current_lba;
+    unsigned long long backup_lba;
+    unsigned long long first_lba;
+    unsigned long long last_lba;
+    struct efi_guid disk_uuid;
+    /* starting LBA of array of partition entries */
+    unsigned long long part_lba;
+    /* number of partition entries in array */
+    unsigned int list_num;
+    /* size of a single partition entry (usually 128) */
+    unsigned int part_size;
+    unsigned int part_crc;
+} gpt_header_t;
+
+int parse_gpt_entry(gpt_entry_t *gpt_entry, partition_entry_t *entry);
+
+#endif /* GPT_H */
diff --git a/platform/ext/target/arm/corstone1000/partition/mbr.h b/platform/ext/target/arm/corstone1000/partition/mbr.h
new file mode 100644
index 0000000000..e77f367016
--- /dev/null
+++ b/platform/ext/target/arm/corstone1000/partition/mbr.h
@@ -0,0 +1,29 @@
+/*
+ * Copyright (c) 2016, ARM Limited and Contributors. All rights reserved.
+ *
+ * SPDX-License-Identifier: BSD-3-Clause
+ */
+
+#ifndef MBR_H
+#define MBR_H
+
+#define MBR_OFFSET 0
+
+#define MBR_PRIMARY_ENTRY_OFFSET 0x1be
+#define MBR_PRIMARY_ENTRY_SIZE 0x10
+#define MBR_PRIMARY_ENTRY_NUMBER 4
+#define MBR_CHS_ADDRESS_LEN 3
+
+#define MBR_SIGNATURE_FIRST 0x55
+#define MBR_SIGNATURE_SECOND 0xAA
+
+typedef struct mbr_entry {
+    unsigned char status;
+    unsigned char first_sector[MBR_CHS_ADDRESS_LEN];
+    unsigned char type;
+    unsigned char last_sector[MBR_CHS_ADDRESS_LEN];
+    unsigned int first_lba;
+    unsigned int sector_nums;
+} mbr_entry_t;
+
+#endif /* MBR_H */
diff --git a/platform/ext/target/arm/corstone1000/partition/partition.c b/platform/ext/target/arm/corstone1000/partition/partition.c
new file mode 100644
index 0000000000..afc6aa1c5c
--- /dev/null
+++ b/platform/ext/target/arm/corstone1000/partition/partition.c
@@ -0,0 +1,310 @@
+/*
+ * Copyright (c) 2016-2022, ARM Limited and Contributors. All rights reserved.
+ *
+ * SPDX-License-Identifier: BSD-3-Clause
+ */
+
+#include "partition.h"
+
+#include <assert.h>
+#include <errno.h>
+#include <inttypes.h>
+#include <stdio.h>
+#include <string.h>
+
+#include "efi.h"
+#include "gpt.h"
+#include "mbr.h"
+
+#include "io_storage.h"
+#include "platform.h"
+#include "soft_crc.h"
+
+#define PLAT_LOG_MODULE_NAME "partition"
+#include "platform_log.h"
+
+static uint8_t mbr_sector[PLAT_PARTITION_BLOCK_SIZE];
+static partition_entry_list_t list;
+
+#if LOG_LEVEL >= LOG_LEVEL_DEBUG
+static void dump_entries(int num) {
+    char name[EFI_NAMELEN];
+    int i, j, len;
+
+    VERBOSE("Partition table with %d entries:", num);
+    for (i = 0; i < num; i++) {
+        len = snprintf(name, EFI_NAMELEN, "%s", list.list[i].name);
+        for (j = 0; j < EFI_NAMELEN - len - 1; j++) {
+            name[len + j] = ' ';
+        }
+        name[EFI_NAMELEN - 1] = '\0';
+        VERBOSE("%d: %s %x%x %d", i + 1, name,
+                (uint32_t)(list.list[i].start >> 32),
+                (uint32_t)list.list[i].start,
+                (uint32_t)(list.list[i].start + list.list[i].length - 4));
+    }
+}
+#else
+#define dump_entries(num) ((void)num)
+#endif
+
+/*
+ * Load the first sector that carries MBR header.
+ * The MBR boot signature should be always valid whether it's MBR or GPT.
+ */
+static int load_mbr_header(uintptr_t image_handle, mbr_entry_t *mbr_entry) {
+    size_t bytes_read;
+    uintptr_t offset;
+    int result;
+
+    assert(mbr_entry != NULL);
+    /* MBR partition table is in LBA0. */
+    result = io_seek(image_handle, IO_SEEK_SET, MBR_OFFSET);
+    if (result != 0) {
+        WARN("Failed to seek (%i)\n", result);
+        return result;
+    }
+    result = io_read(image_handle, (uintptr_t)&mbr_sector,
+                     PLAT_PARTITION_BLOCK_SIZE, &bytes_read);
+    if (result != 0) {
+        WARN("Failed to read data (%i)\n", result);
+        return result;
+    }
+
+    /* Check MBR boot signature. */
+    if ((mbr_sector[LEGACY_PARTITION_BLOCK_SIZE - 2] != MBR_SIGNATURE_FIRST) ||
+        (mbr_sector[LEGACY_PARTITION_BLOCK_SIZE - 1] != MBR_SIGNATURE_SECOND)) {
+        ERROR("MBR signature isn't correct");
+        return -ENOENT;
+    }
+    offset = (uintptr_t)&mbr_sector + MBR_PRIMARY_ENTRY_OFFSET;
+    memcpy(mbr_entry, (void *)offset, sizeof(mbr_entry_t));
+    return 0;
+}
+
+/*
+ * Load GPT header and check the GPT signature and header CRC.
+ * If partition numbers could be found, check & update it.
+ */
+static int load_gpt_header(uintptr_t image_handle) {
+    gpt_header_t header;
+    size_t bytes_read;
+    int result;
+    uint32_t header_crc, calc_crc;
+
+    result = io_seek(image_handle, IO_SEEK_SET, GPT_HEADER_OFFSET);
+    if (result != 0) {
+        return result;
+    }
+    result = io_read(image_handle, (uintptr_t)&header, sizeof(gpt_header_t),
+                     &bytes_read);
+    if ((result != 0) || (sizeof(gpt_header_t) != bytes_read)) {
+        return result;
+    }
+    if (memcmp(header.signature, GPT_SIGNATURE, sizeof(header.signature)) !=
+        0) {
+        return -EINVAL;
+    }
+
+    /*
+     * UEFI Spec 2.8 March 2019 Page 119: HeaderCRC32 value is
+     * computed by setting this field to 0, and computing the
+     * 32-bit CRC for HeaderSize bytes.
+     */
+    header_crc = header.header_crc;
+    header.header_crc = 0U;
+
+    calc_crc = crc32((uint8_t *)&header, DEFAULT_GPT_HEADER_SIZE);
+    if (header_crc != calc_crc) {
+        ERROR("Invalid GPT Header CRC: Expected 0x%x but got 0x%x.\n",
+              header_crc, calc_crc);
+        return -EINVAL;
+    }
+
+    header.header_crc = header_crc;
+
+    /* partition numbers can't exceed PLAT_PARTITION_MAX_ENTRIES */
+    list.entry_count = header.list_num;
+    if (list.entry_count > PLAT_PARTITION_MAX_ENTRIES) {
+        list.entry_count = PLAT_PARTITION_MAX_ENTRIES;
+    }
+    return 0;
+}
+
+static int load_mbr_entry(uintptr_t image_handle, mbr_entry_t *mbr_entry,
+                          int part_number) {
+    size_t bytes_read;
+    uintptr_t offset;
+    int result;
+
+    assert(mbr_entry != NULL);
+    /* MBR partition table is in LBA0. */
+    result = io_seek(image_handle, IO_SEEK_SET, MBR_OFFSET);
+    if (result != 0) {
+        WARN("Failed to seek (%i)\n", result);
+        return result;
+    }
+    result = io_read(image_handle, (uintptr_t)&mbr_sector,
+                     PLAT_PARTITION_BLOCK_SIZE, &bytes_read);
+    if (result != 0) {
+        WARN("Failed to read data (%i)\n", result);
+        return result;
+    }
+
+    /* Check MBR boot signature. */
+    if ((mbr_sector[LEGACY_PARTITION_BLOCK_SIZE - 2] != MBR_SIGNATURE_FIRST) ||
+        (mbr_sector[LEGACY_PARTITION_BLOCK_SIZE - 1] != MBR_SIGNATURE_SECOND)) {
+        return -ENOENT;
+    }
+    offset = (uintptr_t)&mbr_sector + MBR_PRIMARY_ENTRY_OFFSET +
+             MBR_PRIMARY_ENTRY_SIZE * part_number;
+    memcpy(mbr_entry, (void *)offset, sizeof(mbr_entry_t));
+
+    return 0;
+}
+
+static int load_mbr_entries(uintptr_t image_handle) {
+    mbr_entry_t mbr_entry;
+    int i;
+
+    list.entry_count = MBR_PRIMARY_ENTRY_NUMBER;
+
+    for (i = 0; i < list.entry_count; i++) {
+        load_mbr_entry(image_handle, &mbr_entry, i);
+        list.list[i].start = mbr_entry.first_lba * 512;
+        list.list[i].length = mbr_entry.sector_nums * 512;
+        list.list[i].name[0] = mbr_entry.type;
+    }
+
+    return 0;
+}
+
+static int load_gpt_entry(uintptr_t image_handle, gpt_entry_t *entry) {
+    size_t bytes_read;
+    int result;
+
+    assert(entry != NULL);
+    result = io_read(image_handle, (uintptr_t)entry, sizeof(gpt_entry_t),
+                     &bytes_read);
+    if (sizeof(gpt_entry_t) != bytes_read) return -EINVAL;
+    return result;
+}
+
+static int verify_partition_gpt(uintptr_t image_handle) {
+    gpt_entry_t entry;
+    int result, i;
+
+    for (i = 0; i < list.entry_count; i++) {
+        result = load_gpt_entry(image_handle, &entry);
+        assert(result == 0);
+        if (result != 0) {
+            break;
+        }
+        result = parse_gpt_entry(&entry, &list.list[i]);
+        if (result != 0) {
+            break;
+        }
+    }
+    if (i == 0) {
+        return -EINVAL;
+    }
+    /*
+     * Only records the valid partition number that is loaded from
+     * partition table.
+     */
+    list.entry_count = i;
+    dump_entries(list.entry_count);
+
+    return 0;
+}
+
+int load_partition_table(unsigned int image_id) {
+    uintptr_t dev_handle, image_handle, image_spec = 0;
+    mbr_entry_t mbr_entry;
+    int result;
+
+    result = plat_get_image_source(image_id, &dev_handle, &image_spec);
+    if (result != 0) {
+        WARN("Failed to obtain reference to image id=%u (%i)\n", image_id,
+             result);
+        return result;
+    }
+
+    result = io_open(dev_handle, image_spec, &image_handle);
+    if (result != 0) {
+        WARN("Failed to open image id=%u (%i)\n", image_id, result);
+        return result;
+    }
+
+    result = load_mbr_header(image_handle, &mbr_entry);
+    if (result != 0) {
+        ERROR("Loading mbr header failed with image id=%u (%i)\n", image_id,
+              result);
+        return result;
+    }
+    if (mbr_entry.type == PARTITION_TYPE_GPT) {
+        INFO("Loading gpt header");
+        result = load_gpt_header(image_handle);
+        assert(result == 0);
+        if (result != 0) {
+            ERROR("Failed load gpt header! %i", result);
+            goto load_partition_table_exit;
+        }
+        result = io_seek(image_handle, IO_SEEK_SET, GPT_ENTRY_OFFSET);
+        assert(result == 0);
+        if (result != 0) {
+            ERROR("Failed seek gpt header! %i", result);
+            goto load_partition_table_exit;
+        }
+        result = verify_partition_gpt(image_handle);
+        if (result != 0) {
+            ERROR("Failed verify gpt partition %i", result);
+            goto load_partition_table_exit;
+        }
+    } else {
+        result = load_mbr_entries(image_handle);
+    }
+
+load_partition_table_exit:
+    io_close(image_handle);
+    return result;
+}
+
+const partition_entry_t *get_partition_entry(const char *name) {
+    int i;
+
+    for (i = 0; i < list.entry_count; i++) {
+        if (strcmp(name, list.list[i].name) == 0) {
+            return &list.list[i];
+        }
+    }
+    return NULL;
+}
+
+const partition_entry_t *get_partition_entry_by_type(const uuid_t *type_uuid) {
+    int i;
+
+    for (i = 0; i < list.entry_count; i++) {
+        if (guidcmp(type_uuid, &list.list[i].type_guid) == 0) {
+            return &list.list[i];
+        }
+    }
+
+    return NULL;
+}
+
+const partition_entry_t *get_partition_entry_by_uuid(const uuid_t *part_uuid) {
+    int i;
+
+    for (i = 0; i < list.entry_count; i++) {
+        if (guidcmp(part_uuid, &list.list[i].part_guid) == 0) {
+            return &list.list[i];
+        }
+    }
+
+    return NULL;
+}
+
+const partition_entry_list_t *get_partition_entry_list(void) { return &list; }
+
+void partition_init(unsigned int image_id) { load_partition_table(image_id); }
diff --git a/platform/ext/target/arm/corstone1000/partition/partition.h b/platform/ext/target/arm/corstone1000/partition/partition.h
new file mode 100644
index 0000000000..54af47aca4
--- /dev/null
+++ b/platform/ext/target/arm/corstone1000/partition/partition.h
@@ -0,0 +1,47 @@
+/*
+ * Copyright (c) 2016-2022, ARM Limited and Contributors. All rights reserved.
+ *
+ * SPDX-License-Identifier: BSD-3-Clause
+ */
+
+#ifndef PARTITION_H
+#define PARTITION_H
+
+#include <stdint.h>
+
+#include "efi.h"
+#include "uuid.h"
+
+#if !PLAT_PARTITION_MAX_ENTRIES
+#define PLAT_PARTITION_MAX_ENTRIES 16
+#endif /* PLAT_PARTITION_MAX_ENTRIES */
+
+#if !PLAT_PARTITION_BLOCK_SIZE
+#define PLAT_PARTITION_BLOCK_SIZE 512
+#endif /* PLAT_PARTITION_BLOCK_SIZE */
+
+#define LEGACY_PARTITION_BLOCK_SIZE 512
+
+#define DEFAULT_GPT_HEADER_SIZE 92
+
+typedef struct partition_entry {
+    uint64_t start;
+    uint64_t length;
+    char name[EFI_NAMELEN];
+    struct efi_guid part_guid;
+    struct efi_guid type_guid;
+} partition_entry_t;
+
+typedef struct partition_entry_list {
+    partition_entry_t list[PLAT_PARTITION_MAX_ENTRIES];
+    int entry_count;
+} partition_entry_list_t;
+
+int load_partition_table(unsigned int image_id);
+const partition_entry_t *get_partition_entry(const char *name);
+const partition_entry_t *get_partition_entry_by_type(const uuid_t *type_guid);
+const partition_entry_t *get_partition_entry_by_uuid(const uuid_t *part_uuid);
+const partition_entry_list_t *get_partition_entry_list(void);
+void partition_init(unsigned int image_id);
+
+#endif /* PARTITION_H */
diff --git a/platform/ext/target/arm/corstone1000/partition/uuid.h b/platform/ext/target/arm/corstone1000/partition/uuid.h
new file mode 100644
index 0000000000..06fec5a3c0
--- /dev/null
+++ b/platform/ext/target/arm/corstone1000/partition/uuid.h
@@ -0,0 +1,76 @@
+/*-
+ * Copyright (c) 2002 Marcel Moolenaar
+ * All rights reserved.
+ *
+ * Redistribution and use in source and binary forms, with or without
+ * modification, are permitted provided that the following conditions
+ * are met:
+ *
+ * 1. Redistributions of source code must retain the above copyright
+ *    notice, this list of conditions and the following disclaimer.
+ * 2. Redistributions in binary form must reproduce the above copyright
+ *    notice, this list of conditions and the following disclaimer in the
+ *    documentation and/or other materials provided with the distribution.
+ *
+ * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR
+ * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
+ * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
+ * IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT,
+ * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
+ * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
+ * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
+ * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
+ * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF
+ * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
+ *
+ * $FreeBSD$
+ */
+
+/*
+ * Portions copyright (c) 2014-2020, ARM Limited and Contributors.
+ * All rights reserved.
+ */
+
+#ifndef UUID_H
+#define UUID_H
+
+#include <stdint.h>
+
+/* Length of a node address (an IEEE 802 address). */
+#define _UUID_NODE_LEN 6
+
+/* Length of UUID string including dashes. */
+#define _UUID_STR_LEN 36
+
+/*
+ * See also:
+ *      http://www.opengroup.org/dce/info/draft-leach-uuids-guids-01.txt
+ *      http://www.opengroup.org/onlinepubs/009629399/apdxa.htm
+ *
+ * A DCE 1.1 compatible source representation of UUIDs.
+ */
+struct uuid {
+    uint8_t time_low[4];
+    uint8_t time_mid[2];
+    uint8_t time_hi_and_version[2];
+    uint8_t clock_seq_hi_and_reserved;
+    uint8_t clock_seq_low;
+    uint8_t node[_UUID_NODE_LEN];
+};
+
+struct efi_guid {
+    uint32_t time_low;
+    uint16_t time_mid;
+    uint16_t time_hi_and_version;
+    uint8_t clock_seq_and_node[8];
+};
+
+union uuid_helper_t {
+    struct uuid uuid_struct;
+    struct efi_guid efi_guid;
+};
+
+/* XXX namespace pollution? */
+typedef struct uuid uuid_t;
+
+#endif /* UUID_H */
diff --git a/platform/ext/target/arm/corstone1000/platform.c b/platform/ext/target/arm/corstone1000/platform.c
new file mode 100644
index 0000000000..908b66b7ac
--- /dev/null
+++ b/platform/ext/target/arm/corstone1000/platform.c
@@ -0,0 +1,20 @@
+/*
+ * Copyright (c) 2023, Arm Limited. All rights reserved.
+ *
+ * SPDX-License-Identifier: BSD-3-Clause
+ *
+ */
+
+#include "platform.h"
+
+#include <stdint.h>
+
+/* Return an IO device handle and specification which can be used to access
+ * an image. This has to be implemented for the GPT parser. */
+int32_t plat_get_image_source(unsigned int image_id, uintptr_t *dev_handle,
+                              uintptr_t *image_spec) {
+    (void)image_id;
+    *dev_handle = NULL;
+    *image_spec = NULL;
+    return 0;
+}
diff --git a/platform/ext/target/arm/corstone1000/platform.h b/platform/ext/target/arm/corstone1000/platform.h
new file mode 100644
index 0000000000..250f9cd9f5
--- /dev/null
+++ b/platform/ext/target/arm/corstone1000/platform.h
@@ -0,0 +1,14 @@
+/*
+ * Copyright (c) 2023, Arm Limited. All rights reserved.
+ *
+ * SPDX-License-Identifier: BSD-3-Clause
+ *
+ */
+
+#ifndef __PLATFORM_H__
+#define __PLATFORM_H__
+
+int32_t plat_get_image_source(unsigned int image_id, uintptr_t *dev_handle,
+                              uintptr_t *image_spec);
+
+#endif /*__PLATFORM_H__*/
-- 
2.25.1