aboutsummaryrefslogtreecommitdiff
path: root/libflash/ffs.h
blob: 64e5e6a16cef40e3d55266de2bb5a77aa60411b3 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
/* Copyright 2013-2014 IBM Corp.
 *
 * Licensed under the Apache License, Version 2.0 (the "License");
 * you may not use this file except in compliance with the License.
 * You may obtain a copy of the License at
 *
 * 	http://www.apache.org/licenses/LICENSE-2.0
 *
 * Unless required by applicable law or agreed to in writing, software
 * distributed under the License is distributed on an "AS IS" BASIS,
 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or
 * implied.
 * See the License for the specific language governing permissions and
 * limitations under the License.
 */
/*
 * Copyright (c) International Business Machines Corp., 2012
 *
 * FSP Flash Structure
 *
 * This header defines the layout for the FSP Flash Structure.
 */

#ifndef __FFS_H__
#define __FFS_H__

/* Pull in the correct header depending on what is being built */
#ifndef __SKIBOOT__
#include <linux/types.h>
#else
#include <stdint.h>
#endif
#include <ccan/short_types/short_types.h>
#include <ccan/endian/endian.h>
#include <ccan/list/list.h>

#include "libffs.h"

/* The version of this partition implementation */
#define FFS_VERSION_1	1

/* Magic number for the partition header (ASCII 'PART') */
#define FFS_MAGIC	0x50415254

/* pid of logical partitions/containers */
#define FFS_PID_TOPLEVEL   0xFFFFFFFF

/*
 * Type of image contained w/in partition
 */
enum ffs_type {
	FFS_TYPE_DATA      = 1,
	FFS_TYPE_LOGICAL   = 2,
	FFS_TYPE_PARTITION = 3,
};

/**
 * struct __ffs_entry_user - On flash user data entries
 *
 * Represents the on flash layout of FFS structures
 *
 *  @chip:		Chip Select (0,1)
 *  @compressType:	Compression Indication/alg (0=not compressed)
 *  @dataInteg:		Indicates Data Integrity mechanism
 *  @verCheck:		Indicates Version check type
 *  @miscFlags:		Misc Partition related Flags
 *  @freeMisc[2]:	Unused Miscellaneious Info
 *  @freeUser[14]:	Unused User Data
 */
struct __ffs_entry_user {
	uint8_t chip;
	uint8_t compresstype;
	be16 datainteg;
	uint8_t vercheck;
	uint8_t miscflags;
	uint8_t freemisc[2];
	be32 reserved[14];
} __attribute__ ((packed));

/**
 * struct __ffs_entry - On flash partition entry
 *
 * Represents the on flash layout of FFS structures
 * Note: Unlike the in memory structures base and size of the entry are in
 * units of block_size and the actual size is in bytes
 *
 * @name:	Opaque null terminated string
 * @base:	Starting offset of partition in flash (in hdr.block_size)
 * @size:	Partition size (in hdr.block_size)
 * @pid:	Parent partition entry (FFS_PID_TOPLEVEL for toplevel)
 * @id:		Partition entry ID [1..65536]
 * @type:	Describe type of partition
 * @flags:	Partition attributes (optional)
 * @actual:	Actual partition size (in bytes)
 * @resvd:	Reserved words for future use
 * @user:	User data (optional)
 * @checksum:	Partition entry checksum (includes all above)
 */
struct __ffs_entry {
	char name[FFS_PART_NAME_MAX + 1];
	be32 base;
	be32 size;
	be32 pid;
	be32 id;
	be32 type;
	be32 flags;
	be32 actual;
	be32 resvd[4];
	struct __ffs_entry_user user;
	/* The checksum is actually endian agnostic */
	uint32_t checksum;
} __attribute__ ((packed));

/**
 * struct ffs_entry - Partition entry
 *
 * Useable in memory representation of a struct __ffs_entry
 * Note: Unlike the on flash structure, all sizes here are in bytes!
 *
 * @name:	Opaque null terminated string
 * @base:	Starting offset of partition in flash (in bytes)
 * @size:	Partition size (in bytes)
 * @actual:	Actual partition size (in bytes)
 * @pid:	Parent partition entry (FFS_PID_TOPLEVEL for toplevel)
 * @type:	Describe type of partition
 * @flags:	Partition attributes (optional)
 * @user:	User data (optional)
 */
struct ffs_entry {
	char name[FFS_PART_NAME_MAX + 1];
	uint32_t base;
	uint32_t size;
	uint32_t actual;
	uint32_t pid;
	enum ffs_type type;
	uint32_t flags;
	struct ffs_entry_user user;
	struct list_node list;
};


/**
 * struct __ffs_hdr - On flash FSP Flash Structure header
 *
 * Represents the on flash layout of FFS structures
 * Note: Beware that the size of the partition table is in units of block_size
 *
 * @magic:		Eye catcher/corruption detector
 * @version:		Version of the structure
 * @size:		Size of partition table (in block_size)
 * @entry_size:		Size of struct ffs_entry element (in bytes)
 * @entry_count:	Number of struct ffs_entry elements in @entries array
 * @block_size:		Size of block on device (in bytes)
 * @block_count:	Number of blocks on device
 * @resvd[4]:		Reserved words for future use
 * @checksum:		Header checksum
 * @entries:		Pointer to array of partition entries
 */
struct __ffs_hdr {
	be32 magic;
	be32 version;
	be32 size;
	be32 entry_size;
	be32 entry_count;
	be32 block_size;
	be32 block_count;
	be32 resvd[4];
	/* The checksum is actually endian agnostic */
	uint32_t checksum;
	struct __ffs_entry entries[];
} __attribute__ ((packed));

/**
 * struct ffs_hdr - FSP Flash Structure header
 *
 * Useable in memory representation of a struct __ffs_hdr
 * Note: All sizes here are in bytes
 *
 * @version:		Version of the structure
 * @size:		Size of partition table (in bytes)
 * @block_size:		Size of block on device (in bytes)
 * @block_count:	Number of blocks on device.
 * @backup		The backup partition
 * @side		The ffs header for the other side
 * @entries:		List of partition entries
 */
struct ffs_hdr {
	uint32_t version;
	uint32_t size;
	uint32_t block_size;
	uint32_t block_count;
	struct list_head entries;
};

#endif /* __FFS_H__ */