blob: 309363d8646e0d60cd038b33d43df913e225a4c9 [file] [log] [blame]
Andrew Jefferyacee6832018-02-21 22:17:08 +10301/*
2 * Mailbox Daemon Implementation
3 *
4 * Copyright 2018 IBM
5 *
6 * Licensed under the Apache License, Version 2.0 (the "License");
7 * you may not use this file except in compliance with the License.
8 * You may obtain a copy of the License at
9 *
10 * http://www.apache.org/licenses/LICENSE-2.0
11 *
12 * Unless required by applicable law or agreed to in writing, software
13 * distributed under the License is distributed on an "AS IS" BASIS,
14 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
15 * See the License for the specific language governing permissions and
16 * limitations under the License.
17 *
18 */
Deepak Kodihalli393821d2017-04-28 04:44:38 -050019#pragma once
20
21#include <stdint.h>
22#include <sys/types.h>
23
24/* There are two structures outlined here - one that represents the PNOR
25 * partition table (or header) - this appears first in the PNOR image.
26 * The last field of the PNOR partition table structure is an array
27 * of another structure - which represents the partition.
28 *
29 * The flash structures used here have been borrowed from
30 * https://github.com/open-power/hostboot/blob/master/src/usr/pnor/ffs.h */
31
32
33/* The maximum length of a partition's name */
34#define PARTITION_NAME_MAX 15
35
36/* The version of this partition implementation. This is an
37 * incrementing value */
38#define PARTITION_VERSION_1 1
39
40/* Magic number for the partition partition_table (ASCII 'PART') */
41#define PARTITION_HEADER_MAGIC 0x50415254
42
43/* Default parent partition id */
44#define PARENT_PATITION_ID 0xFFFFFFFF
45
46/* The partition structure has 16 'user data' words, which can be used to store
47 * miscellaneous information. This is typically used to store bits that state
48 * whether a partition is ECC protected, is read-only, is preserved across
Adriana Kobylakacb32ef2017-12-05 16:12:06 -060049 * updates, etc.
50 *
51 * TODO: Replace with libflash (!) or at least refactor the data structures to
52 * better match hostboot's layout[1]. The latter would avoid the headache of
53 * verifying these flags match the expected functionality (taking into account
54 * changes in endianness).
55 *
56 * [1] https://github.com/open-power/hostboot/blob/9acfce99596f12dcc60952f8506a77e542609cbf/src/usr/pnor/common/ffs_hb.H#L81
57 */
Deepak Kodihalli393821d2017-04-28 04:44:38 -050058#define PARTITION_USER_WORDS 16
59#define PARTITION_ECC_PROTECTED 0x8000
Deepak Kodihallie8b0e8a2017-07-12 10:01:31 -050060#define PARTITION_PRESERVED 0x00800000
61#define PARTITION_READONLY 0x00400000
Adriana Kobylakacb32ef2017-12-05 16:12:06 -060062#define PARTITION_REPROVISION 0x00100000
63#define PARTITION_VOLATILE 0x00080000
64#define PARTITION_CLEARECC 0x00040000
Deepak Kodihallie8b0e8a2017-07-12 10:01:31 -050065#define PARTITION_VERSION_CHECK_SHA512 0x80000000
66#define PARTITION_VERSION_CHECK_SHA512_PER_EC 0x40000000
Deepak Kodihalli393821d2017-04-28 04:44:38 -050067
68/* Partition flags */
69enum partition_flags {
70 PARTITION_FLAGS_PROTECTED = 0x0001,
71 PARTITION_FLAGS_U_BOOT_ENV = 0x0002
72};
73
74/* Type of image contained within partition */
75enum partition_type {
76 PARTITION_TYPE_DATA = 1,
77 PARTITION_TYPE_LOGICAL = 2,
78 PARTITION_TYPE_PARTITION = 3
79};
80
81
82/**
83 * struct pnor_partition
84 *
85 * @name: Name of the partition - a null terminated string
86 * @base: The offset in the PNOR, in block-size (1 block = 4KB),
87 * where this partition is placed
88 * @size: Partition size in blocks.
89 * @pid: Parent partition id
90 * @id: Partition ID [1..65536]
91 * @type: Type of partition, see the 'type' enum
92 * @flags: Partition flags (optional), see the 'flags' enum
93 * @actual: Actual partition size (in bytes)
94 * @resvd: Reserved words for future use
95 * @user: User data (optional), see user data macros above
96 * @checksum: Partition checksum (includes all words above) - the
97 * checksum is obtained by a XOR operation on all of the
98 * words above. This is used for detecting a corruption
99 * in this structure
100 */
101struct pnor_partition {
102 struct {
103 char name[PARTITION_NAME_MAX + 1];
104 uint32_t base;
105 uint32_t size;
106 uint32_t pid;
107 uint32_t id;
108 uint32_t type;
109 uint32_t flags;
110 uint32_t actual;
111 uint32_t resvd[4];
112 struct
113 {
114 uint32_t data[PARTITION_USER_WORDS];
115 } user;
116 } __attribute__ ((packed)) data;
117 uint32_t checksum;
118} __attribute__ ((packed));
119
120/**
121 * struct pnor_partition_table
122 *
123 * @magic: Eye catcher/corruption detector - set to
124 * PARTITION_HEADER_MAGIC
125 * @version: Version of the structure, set to
126 * PARTITION_VERSION_1
127 * @size: Size of partition table (in blocks)
128 * @entry_size: Size of struct pnor_partition element (in bytes)
129 * @entry_count: Number of struct pnor_partition elements in partitions array
130 * @block_size: Size of an erase-block on the PNOR (in bytes)
131 * @block_count: Number of blocks on the PNOR
132 * @resvd: Reserved words for future use
133 * @checksum: Header checksum (includes all words above) - the
134 * checksum is obtained by a XOR operation on all of the
135 * words above. This is used for detecting a corruption
136 * in this structure
137 * @partitions: Array of struct pnor_partition
138 */
139struct pnor_partition_table {
140 struct {
141 uint32_t magic;
142 uint32_t version;
143 uint32_t size;
144 uint32_t entry_size;
145 uint32_t entry_count;
146 uint32_t block_size;
147 uint32_t block_count;
148 uint32_t resvd[4];
149 } __attribute__ ((packed)) data;
150 uint32_t checksum;
151 struct pnor_partition partitions[];
152} __attribute__ ((packed));