blob: fe2a338fd16191705f556915964f15f86e3670cb [file] [log] [blame]
Deepak Kodihalli393821d2017-04-28 04:44:38 -05001#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
31 * updates, etc. */
32#define PARTITION_USER_WORDS 16
33#define PARTITION_ECC_PROTECTED 0x8000
Deepak Kodihallie8b0e8a2017-07-12 10:01:31 -050034#define PARTITION_PRESERVED 0x00800000
35#define PARTITION_READONLY 0x00400000
36#define PARTITION_VERSION_CHECK_SHA512 0x80000000
37#define PARTITION_VERSION_CHECK_SHA512_PER_EC 0x40000000
Deepak Kodihalli393821d2017-04-28 04:44:38 -050038
39/* Partition flags */
40enum partition_flags {
41 PARTITION_FLAGS_PROTECTED = 0x0001,
42 PARTITION_FLAGS_U_BOOT_ENV = 0x0002
43};
44
45/* Type of image contained within partition */
46enum partition_type {
47 PARTITION_TYPE_DATA = 1,
48 PARTITION_TYPE_LOGICAL = 2,
49 PARTITION_TYPE_PARTITION = 3
50};
51
52
53/**
54 * struct pnor_partition
55 *
56 * @name: Name of the partition - a null terminated string
57 * @base: The offset in the PNOR, in block-size (1 block = 4KB),
58 * where this partition is placed
59 * @size: Partition size in blocks.
60 * @pid: Parent partition id
61 * @id: Partition ID [1..65536]
62 * @type: Type of partition, see the 'type' enum
63 * @flags: Partition flags (optional), see the 'flags' enum
64 * @actual: Actual partition size (in bytes)
65 * @resvd: Reserved words for future use
66 * @user: User data (optional), see user data macros above
67 * @checksum: Partition checksum (includes all words above) - the
68 * checksum is obtained by a XOR operation on all of the
69 * words above. This is used for detecting a corruption
70 * in this structure
71 */
72struct pnor_partition {
73 struct {
74 char name[PARTITION_NAME_MAX + 1];
75 uint32_t base;
76 uint32_t size;
77 uint32_t pid;
78 uint32_t id;
79 uint32_t type;
80 uint32_t flags;
81 uint32_t actual;
82 uint32_t resvd[4];
83 struct
84 {
85 uint32_t data[PARTITION_USER_WORDS];
86 } user;
87 } __attribute__ ((packed)) data;
88 uint32_t checksum;
89} __attribute__ ((packed));
90
91/**
92 * struct pnor_partition_table
93 *
94 * @magic: Eye catcher/corruption detector - set to
95 * PARTITION_HEADER_MAGIC
96 * @version: Version of the structure, set to
97 * PARTITION_VERSION_1
98 * @size: Size of partition table (in blocks)
99 * @entry_size: Size of struct pnor_partition element (in bytes)
100 * @entry_count: Number of struct pnor_partition elements in partitions array
101 * @block_size: Size of an erase-block on the PNOR (in bytes)
102 * @block_count: Number of blocks on the PNOR
103 * @resvd: Reserved words for future use
104 * @checksum: Header checksum (includes all words above) - the
105 * checksum is obtained by a XOR operation on all of the
106 * words above. This is used for detecting a corruption
107 * in this structure
108 * @partitions: Array of struct pnor_partition
109 */
110struct pnor_partition_table {
111 struct {
112 uint32_t magic;
113 uint32_t version;
114 uint32_t size;
115 uint32_t entry_size;
116 uint32_t entry_count;
117 uint32_t block_size;
118 uint32_t block_count;
119 uint32_t resvd[4];
120 } __attribute__ ((packed)) data;
121 uint32_t checksum;
122 struct pnor_partition partitions[];
123} __attribute__ ((packed));