Haojian Zhuang | 91f5646 | 2016-07-28 14:19:36 +0800 | [diff] [blame] | 1 | /* |
Govindraj Raja | 998b1e2 | 2023-09-21 18:04:00 -0500 | [diff] [blame] | 2 | * Copyright (c) 2016-2023, Arm Limited and Contributors. All rights reserved. |
Haojian Zhuang | 91f5646 | 2016-07-28 14:19:36 +0800 | [diff] [blame] | 3 | * |
dp-arm | fa3cf0b | 2017-05-03 09:38:09 +0100 | [diff] [blame] | 4 | * SPDX-License-Identifier: BSD-3-Clause |
Haojian Zhuang | 91f5646 | 2016-07-28 14:19:36 +0800 | [diff] [blame] | 5 | */ |
| 6 | |
Antonio Nino Diaz | 5eb8837 | 2018-11-08 10:20:19 +0000 | [diff] [blame] | 7 | #ifndef PARTITION_H |
| 8 | #define PARTITION_H |
Haojian Zhuang | 91f5646 | 2016-07-28 14:19:36 +0800 | [diff] [blame] | 9 | |
Antonio Nino Diaz | 4b32e62 | 2018-08-16 16:52:57 +0100 | [diff] [blame] | 10 | #include <stdint.h> |
Haojian Zhuang | 91f5646 | 2016-07-28 14:19:36 +0800 | [diff] [blame] | 11 | |
Antonio Nino Diaz | e0f9063 | 2018-12-14 00:18:21 +0000 | [diff] [blame] | 12 | #include <lib/cassert.h> |
Sughosh Ganu | e926915 | 2021-12-07 16:49:21 +0530 | [diff] [blame] | 13 | #include <drivers/partition/efi.h> |
Sughosh Ganu | 2436c1c | 2021-07-02 16:22:55 +0530 | [diff] [blame] | 14 | #include <tools_share/uuid.h> |
Antonio Nino Diaz | e0f9063 | 2018-12-14 00:18:21 +0000 | [diff] [blame] | 15 | |
Haojian Zhuang | 91f5646 | 2016-07-28 14:19:36 +0800 | [diff] [blame] | 16 | #if !PLAT_PARTITION_MAX_ENTRIES |
| 17 | # define PLAT_PARTITION_MAX_ENTRIES 128 |
| 18 | #endif /* PLAT_PARTITION_MAX_ENTRIES */ |
| 19 | |
| 20 | CASSERT(PLAT_PARTITION_MAX_ENTRIES <= 128, assert_plat_partition_max_entries); |
| 21 | |
Haojian Zhuang | 42a746d | 2019-09-14 18:01:16 +0800 | [diff] [blame] | 22 | #if !PLAT_PARTITION_BLOCK_SIZE |
| 23 | # define PLAT_PARTITION_BLOCK_SIZE 512 |
| 24 | #endif /* PLAT_PARTITION_BLOCK_SIZE */ |
| 25 | |
| 26 | CASSERT((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 Zhuang | 91f5646 | 2016-07-28 14:19:36 +0800 | [diff] [blame] | 31 | |
Govindraj Raja | 232a11f | 2023-10-03 16:39:32 -0500 | [diff] [blame] | 32 | #define LBA(n) ((unsigned long long)(n) * PLAT_PARTITION_BLOCK_SIZE) |
| 33 | |
Haojian Zhuang | 91f5646 | 2016-07-28 14:19:36 +0800 | [diff] [blame] | 34 | typedef struct partition_entry { |
| 35 | uint64_t start; |
| 36 | uint64_t length; |
| 37 | char name[EFI_NAMELEN]; |
Sughosh Ganu | 2436c1c | 2021-07-02 16:22:55 +0530 | [diff] [blame] | 38 | struct efi_guid part_guid; |
Lionel Debieve | a88ca2e | 2022-02-24 18:56:28 +0100 | [diff] [blame] | 39 | struct efi_guid type_guid; |
Haojian Zhuang | 91f5646 | 2016-07-28 14:19:36 +0800 | [diff] [blame] | 40 | } partition_entry_t; |
| 41 | |
| 42 | typedef struct partition_entry_list { |
| 43 | partition_entry_t list[PLAT_PARTITION_MAX_ENTRIES]; |
| 44 | int entry_count; |
| 45 | } partition_entry_list_t; |
| 46 | |
| 47 | int load_partition_table(unsigned int image_id); |
| 48 | const partition_entry_t *get_partition_entry(const char *name); |
Lionel Debieve | a88ca2e | 2022-02-24 18:56:28 +0100 | [diff] [blame] | 49 | const partition_entry_t *get_partition_entry_by_type(const uuid_t *type_guid); |
Sughosh Ganu | 47b642e | 2021-11-10 13:00:30 +0530 | [diff] [blame] | 50 | const partition_entry_t *get_partition_entry_by_uuid(const uuid_t *part_uuid); |
Haojian Zhuang | 91f5646 | 2016-07-28 14:19:36 +0800 | [diff] [blame] | 51 | const partition_entry_list_t *get_partition_entry_list(void); |
| 52 | void partition_init(unsigned int image_id); |
Govindraj Raja | 20431cf | 2023-10-12 16:41:07 -0500 | [diff] [blame] | 53 | int gpt_partition_init(void); |
Haojian Zhuang | 91f5646 | 2016-07-28 14:19:36 +0800 | [diff] [blame] | 54 | |
Antonio Nino Diaz | 5eb8837 | 2018-11-08 10:20:19 +0000 | [diff] [blame] | 55 | #endif /* PARTITION_H */ |