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