summaryrefslogtreecommitdiffstats
path: root/lib/ps3-flash.h
blob: ae427f37d3fd909bb4f22d9d8842ec27167ed39e (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
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
/*
 *  PS3 flash memory os area.
 *
 *  Copyright (C) 2006 Sony Computer Entertainment Inc.
 *  Copyright 2006 Sony Corp.
 *
 * This library is free software; you can redistribute it and/or
 * modify it under the terms of the GNU Lesser General Public
 * License as published by the Free Software Foundation; either
 * version 2.1 of the License, or (at your option) any later version.
 *
 * This library is distributed in the hope that it will be useful,
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
 * Lesser General Public License for more details.
 *
 * You should have received a copy of the GNU Lesser General Public
 * License along with this library; if not, write to the Free Software
 * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA  02110-1301  USA
 */

#if !defined(_C5A0A0BE_F815_48A6_BBE0_F553923CEFEE_H)
#define _C5A0A0BE_F815_48A6_BBE0_F553923CEFEE_H

#include <stdint.h>
#include <stdio.h>

enum {
	OS_AREA_SEGMENT_SIZE = 0X200,
};

enum os_area_ldr_format {
	HEADER_LDR_FORMAT_RAW = 0,
	HEADER_LDR_FORMAT_GZIP = 1,
};

/**
 * struct os_area_header - os area header segment.
 * @magic_num: Always 'cell_ext_os_area'.
 * @hdr_version: Header format version number.
 * @db_area_offset: Starting segment number of other os database area.
 * @ldr_area_offset: Starting segment number of bootloader image area.
 * @ldr_format: HEADER_LDR_FORMAT flag.
 * @ldr_size: Size of bootloader image in bytes.
 *
 * Note that the docs refer to area offsets.  These are offsets in units of
 * segments from the start of the os area (top of the header).  These are
 * better thought of as segment numbers.  The os area of the os area is
 * reserved for the os image.
 */

struct os_area_header {
	uint8_t magic_num[16];
	uint32_t hdr_version;
	uint32_t db_area_offset;
	uint32_t ldr_area_offset;
	uint32_t _reserved_1;
	uint32_t ldr_format;
	uint32_t ldr_size;
	uint32_t _reserved_2[6];
};

enum os_area_boot_flag {
	PARAM_BOOT_FLAG_GAME_OS = 0,
	PARAM_BOOT_FLAG_OTHER_OS = 1,
};

enum {
	PARAM_CTRL_BUTTON_O_IS_YES = 0,
	PARAM_CTRL_BUTTON_X_IS_YES = 1,
};

/**
 * struct os_area_params - os area params segment.
 * @boot_flag: User preference of operating system, PARAM_BOOT_FLAG flag.
 * @num_params: Number of params in this (params) segment.
 * @rtc_diff: Difference in seconds between game os wall time and the ps3 rtc value.
 * @av_multi_out: User preference of AV output, PARAM_AV_MULTI_OUT flag.
 * @ctrl_button: User preference of controller button config, PARAM_CTRL_BUTTON
 *	flag.
 * @static_ip_addr: User preference of static IP address.
 * @network_mask: User preference of static network mask.
 * @default_gateway: User preference of static default gateway.
 * @dns_primary: User preference of static primary dns server.
 * @dns_secondary: User preference of static secondary dns server.
 *
 * User preference of zero for static_ip_addr means use dhcp.
 */

struct os_area_params {
	uint32_t boot_flag;
	uint32_t _reserved_1[3];
	uint32_t num_params;
	uint32_t _reserved_2[3];
	/* param 0 */
	int64_t rtc_diff;
	uint8_t av_multi_out;
	uint8_t ctrl_button;
	uint8_t _reserved_3[6];
	/* param 1 */
	uint8_t static_ip_addr[4];
	uint8_t network_mask[4];
	uint8_t default_gateway[4];
	uint8_t _reserved_4[4];
	/* param 2 */
	uint8_t dns_primary[4];
	uint8_t dns_secondary[4];
	uint8_t _reserved_5[8];
};

#if defined(__cplusplus)
extern "C" {
#endif

FILE *os_area_set_log_stream(FILE *log);
int os_area_log(const char *fmt, ...);

int os_area_header_read(struct os_area_header *h, FILE *dev);
int os_area_header_write(const struct os_area_header *h, FILE *dev);
int os_area_params_read(struct os_area_params *p, FILE *dev);
int os_area_params_write(const struct os_area_params *p, FILE *dev);
int os_area_image_write(FILE *image, struct os_area_header *h, FILE *dev);
int os_area_header_verify(const struct os_area_header *h);
static inline int os_area_fixed_read(struct os_area_header *h,
	struct os_area_params *p, FILE *dev)
{
	int result = os_area_header_read(h, dev);
	return result ? result : os_area_params_read(p, dev);
}
int os_area_set_ldr_format(struct os_area_header *h, FILE *dev,
	enum os_area_ldr_format value);
int os_area_set_ldr_size(struct os_area_header *h, FILE *dev,
	unsigned int value);
int os_area_set_boot_flag(struct os_area_params *p, FILE *dev,
	enum os_area_boot_flag value);
#define os_area_header_debug_dump(_a) os_area_header_dump(_a, __func__, \
	__LINE__)
void os_area_header_dump(const struct os_area_header *h, const char *header,
	int id);
#define os_area_params_debug_dump(_a) os_area_params_dump(_a, __func__, \
	__LINE__)
void os_area_params_dump(const struct os_area_params *p, const char *header,
	int id);

#if defined(__cplusplus)
}
#endif

/* flash db routines */

/**
 * struct os_area_db - Shared flash memory database.
 * @magic_num: Always '-db-' = 0x2d64622d.
 * @version: os_area_db format version number.
 * @index_64: byte offset of the database id index for 64 bit variables.
 * @count_64: number of usable 64 bit index entries
 * @index_32: byte offset of the database id index for 32 bit variables.
 * @count_32: number of usable 32 bit index entries
 * @index_16: byte offset of the database id index for 16 bit variables.
 * @count_16: number of usable 16 bit index entries
 *
 * Flash rom storage for exclusive use by guests running in the other os lpar.
 * The current system configuration allocates 1K (two segments) for other os
 * use.
 */

struct os_area_db {
	uint32_t magic_num;
	uint16_t version;
	uint16_t _reserved_1;
	uint16_t index_64;
	uint16_t count_64;
	uint16_t index_32;
	uint16_t count_32;
	uint16_t index_16;
	uint16_t count_16;
	uint32_t _reserved_2;
	uint8_t _reserved_3[1000];
};

/**
 * enum os_area_db_owner - Data owners.
 */

enum os_area_db_owner {
	OS_AREA_DB_OWNER_ANY = -1,
	OS_AREA_DB_OWNER_NONE = 0,
	OS_AREA_DB_OWNER_PROTOTYPE = 1,
	OS_AREA_DB_OWNER_LINUX = 2,
	OS_AREA_DB_OWNER_PETITBOOT = 3,
	OS_AREA_DB_OWNER_MAX = 32,
};

enum os_area_db_key {
	OS_AREA_DB_KEY_ANY = -1,
	OS_AREA_DB_KEY_NONE = 0,
	OS_AREA_DB_KEY_RTC_DIFF = 1,
	OS_AREA_DB_KEY_VIDEO_MODE = 2,
	OS_AREA_DB_KEY_MAX = 8,
};

struct os_area_db_id {
	int owner;
	int key;
};

static const struct os_area_db_id os_area_db_empty_id =
	{OS_AREA_DB_OWNER_NONE, OS_AREA_DB_KEY_NONE};
static const struct os_area_db_id os_area_db_any_id =
	{OS_AREA_DB_OWNER_ANY, OS_AREA_DB_KEY_ANY};

#if defined(__cplusplus)
extern "C" {
#endif

int os_area_db_read(struct os_area_db *db, const struct os_area_header *h,
		FILE *dev);
int os_area_db_write(const struct os_area_db *db, const struct os_area_header *h,
	FILE *dev);
void os_area_db_init(struct os_area_db *db);
int os_area_db_verify(const struct os_area_db *db);
int os_area_db_get(const struct os_area_db *db, const struct os_area_db_id *id,
	uint64_t *value);
int os_area_db_remove(struct os_area_db *db, const struct os_area_db_id *id);
int os_area_db_set_64(struct os_area_db *db, const struct os_area_db_id *id,
	uint64_t value);
int os_area_db_set_32(struct os_area_db *db, const struct os_area_db_id *id,
	uint32_t value);
int os_area_db_set_16(struct os_area_db *db, const struct os_area_db_id *id,
	uint16_t value);
void os_area_db_print(const struct os_area_db *db,
	const struct os_area_db_id *id, int verbose);
int os_area_db_format(struct os_area_db *db, const struct os_area_header *h,
	FILE *dev);
int os_area_db_get_rtc_diff(const struct os_area_db *db, int64_t *rtc_diff);
int os_area_db_get_video_mode(const struct os_area_db *db,
	unsigned int *video_mode);
int os_area_db_list_owners(char *buf, unsigned int size);
void os_area_db_dump_header(const struct os_area_db *db, const char *header,
	int id);

#if defined(__cplusplus)
}
#endif

#endif