blob: d567d4cbba3139e915628798045cdd8eb8f7643e [file] [log] [blame]
Haojian Zhuang91f56462016-07-28 14:19:36 +08001/*
Govindraj Raja998b1e22023-09-21 18:04:00 -05002 * Copyright (c) 2016-2023, Arm Limited and Contributors. All rights reserved.
Haojian Zhuang91f56462016-07-28 14:19:36 +08003 *
dp-armfa3cf0b2017-05-03 09:38:09 +01004 * SPDX-License-Identifier: BSD-3-Clause
Haojian Zhuang91f56462016-07-28 14:19:36 +08005 */
6
Antonio Nino Diaz5eb88372018-11-08 10:20:19 +00007#ifndef PARTITION_H
8#define PARTITION_H
Haojian Zhuang91f56462016-07-28 14:19:36 +08009
Antonio Nino Diaz4b32e622018-08-16 16:52:57 +010010#include <stdint.h>
Haojian Zhuang91f56462016-07-28 14:19:36 +080011
Antonio Nino Diaze0f90632018-12-14 00:18:21 +000012#include <lib/cassert.h>
Sughosh Ganue9269152021-12-07 16:49:21 +053013#include <drivers/partition/efi.h>
Sughosh Ganu2436c1c2021-07-02 16:22:55 +053014#include <tools_share/uuid.h>
Antonio Nino Diaze0f90632018-12-14 00:18:21 +000015
Haojian Zhuang91f56462016-07-28 14:19:36 +080016#if !PLAT_PARTITION_MAX_ENTRIES
17# define PLAT_PARTITION_MAX_ENTRIES 128
18#endif /* PLAT_PARTITION_MAX_ENTRIES */
19
20CASSERT(PLAT_PARTITION_MAX_ENTRIES <= 128, assert_plat_partition_max_entries);
21
Haojian Zhuang42a746d2019-09-14 18:01:16 +080022#if !PLAT_PARTITION_BLOCK_SIZE
23# define PLAT_PARTITION_BLOCK_SIZE 512
24#endif /* PLAT_PARTITION_BLOCK_SIZE */
25
26CASSERT((PLAT_PARTITION_BLOCK_SIZE == 512) ||
27 (PLAT_PARTITION_BLOCK_SIZE == 4096),
28 assert_plat_partition_block_size);
29
30#define LEGACY_PARTITION_BLOCK_SIZE 512
Haojian Zhuang91f56462016-07-28 14:19:36 +080031
Govindraj Raja232a11f2023-10-03 16:39:32 -050032#define LBA(n) ((unsigned long long)(n) * PLAT_PARTITION_BLOCK_SIZE)
33
Haojian Zhuang91f56462016-07-28 14:19:36 +080034typedef struct partition_entry {
35 uint64_t start;
36 uint64_t length;
37 char name[EFI_NAMELEN];
Sughosh Ganu2436c1c2021-07-02 16:22:55 +053038 struct efi_guid part_guid;
Lionel Debievea88ca2e2022-02-24 18:56:28 +010039 struct efi_guid type_guid;
Haojian Zhuang91f56462016-07-28 14:19:36 +080040} partition_entry_t;
41
42typedef struct partition_entry_list {
43 partition_entry_t list[PLAT_PARTITION_MAX_ENTRIES];
44 int entry_count;
45} partition_entry_list_t;
46
47int load_partition_table(unsigned int image_id);
48const partition_entry_t *get_partition_entry(const char *name);
Lionel Debievea88ca2e2022-02-24 18:56:28 +010049const partition_entry_t *get_partition_entry_by_type(const uuid_t *type_guid);
Sughosh Ganu47b642e2021-11-10 13:00:30 +053050const partition_entry_t *get_partition_entry_by_uuid(const uuid_t *part_uuid);
Haojian Zhuang91f56462016-07-28 14:19:36 +080051const partition_entry_list_t *get_partition_entry_list(void);
52void partition_init(unsigned int image_id);
Govindraj Raja20431cf2023-10-12 16:41:07 -050053int gpt_partition_init(void);
Haojian Zhuang91f56462016-07-28 14:19:36 +080054
Antonio Nino Diaz5eb88372018-11-08 10:20:19 +000055#endif /* PARTITION_H */