Deepak Kodihalli | 393821d | 2017-04-28 04:44:38 -0500 | [diff] [blame] | 1 | #pragma once |
| 2 | |
| 3 | #include <stdint.h> |
| 4 | #include <sys/types.h> |
| 5 | |
| 6 | /* There are two structures outlined here - one that represents the PNOR |
| 7 | * partition table (or header) - this appears first in the PNOR image. |
| 8 | * The last field of the PNOR partition table structure is an array |
| 9 | * of another structure - which represents the partition. |
| 10 | * |
| 11 | * The flash structures used here have been borrowed from |
| 12 | * https://github.com/open-power/hostboot/blob/master/src/usr/pnor/ffs.h */ |
| 13 | |
| 14 | |
| 15 | /* The maximum length of a partition's name */ |
| 16 | #define PARTITION_NAME_MAX 15 |
| 17 | |
| 18 | /* The version of this partition implementation. This is an |
| 19 | * incrementing value */ |
| 20 | #define PARTITION_VERSION_1 1 |
| 21 | |
| 22 | /* Magic number for the partition partition_table (ASCII 'PART') */ |
| 23 | #define PARTITION_HEADER_MAGIC 0x50415254 |
| 24 | |
| 25 | /* Default parent partition id */ |
| 26 | #define PARENT_PATITION_ID 0xFFFFFFFF |
| 27 | |
| 28 | /* The partition structure has 16 'user data' words, which can be used to store |
| 29 | * miscellaneous information. This is typically used to store bits that state |
| 30 | * whether a partition is ECC protected, is read-only, is preserved across |
Adriana Kobylak | acb32ef | 2017-12-05 16:12:06 -0600 | [diff] [blame] | 31 | * updates, etc. |
| 32 | * |
| 33 | * TODO: Replace with libflash (!) or at least refactor the data structures to |
| 34 | * better match hostboot's layout[1]. The latter would avoid the headache of |
| 35 | * verifying these flags match the expected functionality (taking into account |
| 36 | * changes in endianness). |
| 37 | * |
| 38 | * [1] https://github.com/open-power/hostboot/blob/9acfce99596f12dcc60952f8506a77e542609cbf/src/usr/pnor/common/ffs_hb.H#L81 |
| 39 | */ |
Deepak Kodihalli | 393821d | 2017-04-28 04:44:38 -0500 | [diff] [blame] | 40 | #define PARTITION_USER_WORDS 16 |
| 41 | #define PARTITION_ECC_PROTECTED 0x8000 |
Deepak Kodihalli | e8b0e8a | 2017-07-12 10:01:31 -0500 | [diff] [blame] | 42 | #define PARTITION_PRESERVED 0x00800000 |
| 43 | #define PARTITION_READONLY 0x00400000 |
Adriana Kobylak | acb32ef | 2017-12-05 16:12:06 -0600 | [diff] [blame] | 44 | #define PARTITION_REPROVISION 0x00100000 |
| 45 | #define PARTITION_VOLATILE 0x00080000 |
| 46 | #define PARTITION_CLEARECC 0x00040000 |
Deepak Kodihalli | e8b0e8a | 2017-07-12 10:01:31 -0500 | [diff] [blame] | 47 | #define PARTITION_VERSION_CHECK_SHA512 0x80000000 |
| 48 | #define PARTITION_VERSION_CHECK_SHA512_PER_EC 0x40000000 |
Deepak Kodihalli | 393821d | 2017-04-28 04:44:38 -0500 | [diff] [blame] | 49 | |
| 50 | /* Partition flags */ |
| 51 | enum partition_flags { |
| 52 | PARTITION_FLAGS_PROTECTED = 0x0001, |
| 53 | PARTITION_FLAGS_U_BOOT_ENV = 0x0002 |
| 54 | }; |
| 55 | |
| 56 | /* Type of image contained within partition */ |
| 57 | enum partition_type { |
| 58 | PARTITION_TYPE_DATA = 1, |
| 59 | PARTITION_TYPE_LOGICAL = 2, |
| 60 | PARTITION_TYPE_PARTITION = 3 |
| 61 | }; |
| 62 | |
| 63 | |
| 64 | /** |
| 65 | * struct pnor_partition |
| 66 | * |
| 67 | * @name: Name of the partition - a null terminated string |
| 68 | * @base: The offset in the PNOR, in block-size (1 block = 4KB), |
| 69 | * where this partition is placed |
| 70 | * @size: Partition size in blocks. |
| 71 | * @pid: Parent partition id |
| 72 | * @id: Partition ID [1..65536] |
| 73 | * @type: Type of partition, see the 'type' enum |
| 74 | * @flags: Partition flags (optional), see the 'flags' enum |
| 75 | * @actual: Actual partition size (in bytes) |
| 76 | * @resvd: Reserved words for future use |
| 77 | * @user: User data (optional), see user data macros above |
| 78 | * @checksum: Partition checksum (includes all words above) - the |
| 79 | * checksum is obtained by a XOR operation on all of the |
| 80 | * words above. This is used for detecting a corruption |
| 81 | * in this structure |
| 82 | */ |
| 83 | struct pnor_partition { |
| 84 | struct { |
| 85 | char name[PARTITION_NAME_MAX + 1]; |
| 86 | uint32_t base; |
| 87 | uint32_t size; |
| 88 | uint32_t pid; |
| 89 | uint32_t id; |
| 90 | uint32_t type; |
| 91 | uint32_t flags; |
| 92 | uint32_t actual; |
| 93 | uint32_t resvd[4]; |
| 94 | struct |
| 95 | { |
| 96 | uint32_t data[PARTITION_USER_WORDS]; |
| 97 | } user; |
| 98 | } __attribute__ ((packed)) data; |
| 99 | uint32_t checksum; |
| 100 | } __attribute__ ((packed)); |
| 101 | |
| 102 | /** |
| 103 | * struct pnor_partition_table |
| 104 | * |
| 105 | * @magic: Eye catcher/corruption detector - set to |
| 106 | * PARTITION_HEADER_MAGIC |
| 107 | * @version: Version of the structure, set to |
| 108 | * PARTITION_VERSION_1 |
| 109 | * @size: Size of partition table (in blocks) |
| 110 | * @entry_size: Size of struct pnor_partition element (in bytes) |
| 111 | * @entry_count: Number of struct pnor_partition elements in partitions array |
| 112 | * @block_size: Size of an erase-block on the PNOR (in bytes) |
| 113 | * @block_count: Number of blocks on the PNOR |
| 114 | * @resvd: Reserved words for future use |
| 115 | * @checksum: Header checksum (includes all words above) - the |
| 116 | * checksum is obtained by a XOR operation on all of the |
| 117 | * words above. This is used for detecting a corruption |
| 118 | * in this structure |
| 119 | * @partitions: Array of struct pnor_partition |
| 120 | */ |
| 121 | struct pnor_partition_table { |
| 122 | struct { |
| 123 | uint32_t magic; |
| 124 | uint32_t version; |
| 125 | uint32_t size; |
| 126 | uint32_t entry_size; |
| 127 | uint32_t entry_count; |
| 128 | uint32_t block_size; |
| 129 | uint32_t block_count; |
| 130 | uint32_t resvd[4]; |
| 131 | } __attribute__ ((packed)) data; |
| 132 | uint32_t checksum; |
| 133 | struct pnor_partition partitions[]; |
| 134 | } __attribute__ ((packed)); |