KallistiOS git master
Independent SDK for the Sega Dreamcast
Loading...
Searching...
No Matches
flashrom.h
Go to the documentation of this file.
1/* KallistiOS ##version##
2
3 dc/flashrom.h
4 Copyright (C) 2003 Megan Potter
5 Copyright (C) 2008 Lawrence Sebald
6
7*/
8
9/** \file dc/flashrom.h
10 \brief Dreamcast flashrom read/write support.
11
12 This file provides wrappers for the BIOS flashrom syscalls and utilities to
13 facilitate the use of flashrom data. Since writing to the flashrom can be
14 risky and potentially destructive, extreme caution is advised when using
15 these functions.
16
17 The Dreamcast flashrom stores important system data including user settings,
18 ISP configurations, and game-specific settings. This file contains functions
19 to read, write, and manage this data.
20
21 Writing to the flashrom should be done with caution:
22 - Always back up existing data before making changes.
23 - Verify the data you are writing is correct.
24 - Avoid frequent writes to minimize wear on the flashrom memory cells.
25
26 Flashrom Structure
27
28 The flashrom is divided into several partitions and logical blocks:
29 - **Partitions**: Defined sections of the flashrom used for different types of data.
30 - **Logical Blocks**: Subsections within partitions that store specific settings.
31
32 \author Megan Potter
33 \author Lawrence Sebald
34*/
35
36#ifndef __DC_FLASHROM_H
37#define __DC_FLASHROM_H
38
39#include <sys/cdefs.h>
40__BEGIN_DECLS
41
42#include <arch/types.h>
43
44/** \defgroup flashrom Flashrom
45 \brief Driver for the Dreamcast's Internal Flash Storage
46 \ingroup vfs
47*/
48
49/** \defgroup fr_parts Partitions
50 \brief Partitions available within the flashrom
51 \ingroup flashrom
52 @{
53*/
54#define FLASHROM_PT_SYSTEM 0 /**< \brief Factory settings (read-only, 8K) */
55#define FLASHROM_PT_RESERVED 1 /**< \brief reserved (all 0s, 8K) */
56#define FLASHROM_PT_BLOCK_1 2 /**< \brief Block allocated (16K) */
57#define FLASHROM_PT_SETTINGS 3 /**< \brief Game settings (block allocated, 32K) */
58#define FLASHROM_PT_BLOCK_2 4 /**< \brief Block allocated (64K) */
59/** @} */
60
61
62/** \defgroup fr_blocks Logical Blocks
63 \brief Logical blocks available in the flashrom
64 \ingroup flashrom
65 @{
66*/
67#define FLASHROM_B1_SYSCFG 0x05 /**< \brief System config (BLOCK_1) */
68#define FLASHROM_B1_PW_SETTINGS_1 0x80 /**< \brief PlanetWeb settings (BLOCK_1) */
69#define FLASHROM_B1_PW_SETTINGS_2 0x81 /**< \brief PlanetWeb settings (BLOCK_1) */
70#define FLASHROM_B1_PW_SETTINGS_3 0x82 /**< \brief PlanetWeb settings (BLOCK_1) */
71#define FLASHROM_B1_PW_SETTINGS_4 0x83 /**< \brief PlanetWeb settings (BLOCK_1) */
72#define FLASHROM_B1_PW_SETTINGS_5 0x84 /**< \brief PlanetWeb settings (BLOCK_1) */
73#define FLASHROM_B1_PW_PPP1 0xC0 /**< \brief PlanetWeb PPP settings (BLOCK_1) */
74#define FLASHROM_B1_PW_PPP2 0xC1 /**< \brief PlanetWeb PPP settings (BLOCK_1) */
75#define FLASHROM_B1_PW_DNS 0xC2 /**< \brief PlanetWeb DNS settings (BLOCK_1) */
76#define FLASHROM_B1_PW_EMAIL1 0xC3 /**< \brief PlanetWeb Email settings (BLOCK_1) */
77#define FLASHROM_B1_PW_EMAIL2 0xC4 /**< \brief PlanetWeb Email settings (BLOCK_1) */
78#define FLASHROM_B1_PW_EMAIL_PROXY 0xC5 /**< \brief PlanetWeb Email/Proxy settings (BLOCK_1) */
79#define FLASHROM_B1_DK_PPP1 0xC6 /**< \brief DreamKey PPP settings (also seen in PW) */
80#define FLASHROM_B1_DK_PPP2 0xC7 /**< \brief DreamKey PPP settings (also seen in PW) */
81#define FLASHROM_B1_DK_DNS 0xC8 /**< \brief DreamKey PPP settings (also seen in PW) */
82#define FLASHROM_B1_IP_SETTINGS 0xE0 /**< \brief IP settings for BBA (BLOCK_1) */
83#define FLASHROM_B1_EMAIL 0xE2 /**< \brief Email address (BLOCK_1) */
84#define FLASHROM_B1_SMTP 0xE4 /**< \brief SMTP server setting (BLOCK_1) */
85#define FLASHROM_B1_POP3 0xE5 /**< \brief POP3 server setting (BLOCK_1) */
86#define FLASHROM_B1_POP3LOGIN 0xE6 /**< \brief POP3 login setting (BLOCK_1) */
87#define FLASHROM_B1_POP3PASSWD 0xE7 /**< \brief POP3 password setting + proxy (BLOCK_1) */
88#define FLASHROM_B1_PPPLOGIN 0xE8 /**< \brief PPP username + proxy (BLOCK_1) */
89#define FLASHROM_B1_PPPPASSWD 0xE9 /**< \brief PPP passwd (BLOCK_1) */
90#define FLASHROM_B1_PPPMODEM 0xEB /**< \brief PPP modem settings */
91/** @} */
92
93#define FLASHROM_OFFSET_CRC 62 /**< \brief Location of CRC in each block */
94
95/** \defgroup fr_errs Error Values
96 \brief Error values for the flashrom_get_block() function
97 \ingroup flashrom
98 @{
99*/
100#define FLASHROM_ERR_NONE 0 /**< \brief Success */
101#define FLASHROM_ERR_NOT_FOUND -1 /**< \brief Block not found */
102#define FLASHROM_ERR_NO_PARTITION -2 /**< \brief Partition not found */
103#define FLASHROM_ERR_READ_PART -3 /**< \brief Error reading partition */
104#define FLASHROM_ERR_BAD_MAGIC -4 /**< \brief Invalid block magic */
105#define FLASHROM_ERR_BOGUS_PART -5 /**< \brief Bogus partition size */
106#define FLASHROM_ERR_NOMEM -6 /**< \brief Memory allocation failure */
107#define FLASHROM_ERR_READ_BITMAP -7 /**< \brief Error reading bitmap */
108#define FLASHROM_ERR_EMPTY_PART -8 /**< \brief Empty partition */
109#define FLASHROM_ERR_READ_BLOCK -9 /**< \brief Error reading block */
110/** @} */
111
112/** \brief Retrieve information about the given partition.
113 \ingroup flashrom
114
115 This function implements the FLASHROM_INFO syscall; given a partition ID,
116 it returns the offset from the start of the flashrom and the size of the
117 partition in bytes.
118
119 \param part_id The partition ID in question.
120 \param start_offset Buffer for storing the partition's start offset, in bytes,
121 from the beginning of the flashrom.
122 \param size_out Buffer for storing the size of the partition in bytes.
123 \retval 0 On success.
124 \retval -1 On error.
125*/
126int flashrom_info(uint32_t part_id, uint32_t *start_offset, size_t *size_out);
127
128/** \brief Read data from the flashrom.
129 \ingroup flashrom
130
131 This function implements the FLASHROM_READ syscall; given a flashrom offset,
132 an output buffer, and a count, this reads data from the flashrom.
133
134 \param offset The offset to read from.
135 \param buffer_out Space to read into.
136 \param bytes The number of bytes to read.
137 \return The number of bytes read if successful, or -1
138 otherwise.
139*/
140int flashrom_read(uint32_t offset, void *buffer_out, size_t bytes);
141
142/** \brief Write data to the flashrom.
143 \ingroup flashrom
144
145 This function implements the FLASHROM_WRITE syscall; given a flashrom
146 offset, an input buffer, and a count, this writes data to the flashrom.
147
148 \note It is not possible to write ones to the flashrom over zeros. If you
149 want to do this, you must save the old data in the flashrom, delete it out,
150 and save the new data back.
151
152 \param offset The offset to write at.
153 \param buffer The data to write.
154 \param bytes The number of bytes to write.
155 \return The number of bytes written if successful, -1
156 otherwise.
157*/
158int flashrom_write(uint32_t offset, const void *buffer, size_t bytes);
159
160/** \brief Delete data from the flashrom.
161 \ingroup flashrom
162
163 This function implements the FLASHROM_DELETE syscall; given a partition
164 offset, that entire partition of the flashrom will be deleted and all data
165 will be reset to 0xFF bytes.
166
167 \note This does not rewrite the magic block to the start of the partition.
168 It is your responsibility to do this after running this function.
169
170 \param offset The offset of the start of the partition to erase.
171 \retval 0 On success.
172 \retval -1 On error.
173*/
174int flashrom_delete(uint32_t offset);
175
176
177/* Medium-level functions */
178
179/** \brief Get a logical block from the specified partition.
180 \ingroup flashrom
181
182 This function retrieves the specified block ID from the given partition. The
183 newest version of the data is returned.
184
185 \param part_id The partition ID to look in.
186 \param block_id The logical block ID to look for.
187 \param buffer_out Space to store the data. Must be at least 60 bytes.
188 \return 0 on success, <0 on error.
189 \see fr_errs
190*/
191int flashrom_get_block(uint32_t part_id, uint32_t block_id, uint8_t *buffer_out);
192
193
194/* Higher level functions */
195
196/** \defgroup fr_langs Language Settings
197 \brief Language settings possible in the BIOS menu
198 \ingroup flashrom
199
200 This set of constants will be returned as the language value in the
201 flashrom_syscfg_t structure.
202
203 @{
204*/
205#define FLASHROM_LANG_JAPANESE 0 /**< \brief Japanese language code */
206#define FLASHROM_LANG_ENGLISH 1 /**< \brief English language code */
207#define FLASHROM_LANG_GERMAN 2 /**< \brief German language code */
208#define FLASHROM_LANG_FRENCH 3 /**< \brief French language code */
209#define FLASHROM_LANG_SPANISH 4 /**< \brief Spanish language code */
210#define FLASHROM_LANG_ITALIAN 5 /**< \brief Italian language code */
211/** @} */
212
213/** \brief System configuration structure.
214 \ingroup flashrom
215
216 This structure is filled in with the settings set in the BIOS from the
217 flashrom_get_syscfg() function.
218
219 \headerfile dc/flashrom.h
220*/
221typedef struct flashrom_syscfg {
222 uint32_t language; /**< \brief Language setting.
223 \see fr_langs */
224 uint32_t audio; /**< \brief Stereo/mono setting. 0 == mono, 1 == stereo */
225 uint32_t autostart; /**< \brief Autostart discs? 0 == off, 1 == on */
227
228/** \brief Retrieve the current system configuration settings.
229 \ingroup flashrom
230
231 \param out Storage for the configuration.
232 \return 0 on success, <0 on error.
233 \see fr_errs
234*/
236
237
238/** \defgroup fr_region Region Settings
239 \brief Region settings possible in the system
240 \ingroup flashrom
241
242 One of these values should be returned by flashrom_get_region().
243
244 @{
245*/
246#define FLASHROM_REGION_UNKNOWN 0 /**< \brief Unknown region */
247#define FLASHROM_REGION_JAPAN 1 /**< \brief Japanese region */
248#define FLASHROM_REGION_US 2 /**< \brief US/Canada region */
249#define FLASHROM_REGION_EUROPE 3 /**< \brief European region */
250/** @} */
251
252/** \brief Retrieve the console's region code.
253 \ingroup flashrom
254
255 This function attempts to find the region of the Dreamcast. It may or may
256 not work on 100% of Dreamcasts, apparently.
257
258 \return A region code (>=0), or error (<0).
259 \see fr_region
260 \see fr_errs
261*/
263
264/** \defgroup fr_method Connection Methods
265 \brief Connection method types stored within flashrom
266 \ingroup flashrom
267
268 These values are representative of what type of ISP is configured in the
269 flashrom.
270
271 @{
272*/
273#define FLASHROM_ISP_DIALUP 0 /**< \brief Dialup ISP */
274#define FLASHROM_ISP_DHCP 1 /**< \brief DHCP-based ethernet */
275#define FLASHROM_ISP_PPPOE 2 /**< \brief PPPoE-based ethernet */
276#define FLASHROM_ISP_STATIC 3 /**< \brief Static IP-based ethernet */
277/** @} */
278
279/** \defgroup fr_fields ISP Config Fields
280 \brief Valid field constants for the flashrom_ispcfg_t struct
281 \ingroup flashrom
282
283 The valid_fields field of the flashrom_ispcfg_t will have some combination
284 of these ORed together to represent what data is filled in and believed
285 valid.
286
287 @{
288*/
289#define FLASHROM_ISP_IP (1 << 0) /**< \brief Static IP address */
290#define FLASHROM_ISP_NETMASK (1 << 1) /**< \brief Netmask */
291#define FLASHROM_ISP_BROADCAST (1 << 2) /**< \brief Broadcast address */
292#define FLASHROM_ISP_GATEWAY (1 << 3) /**< \brief Gateway address */
293#define FLASHROM_ISP_DNS (1 << 4) /**< \brief DNS servers */
294#define FLASHROM_ISP_HOSTNAME (1 << 5) /**< \brief Hostname */
295#define FLASHROM_ISP_EMAIL (1 << 6) /**< \brief Email address */
296#define FLASHROM_ISP_SMTP (1 << 7) /**< \brief SMTP server */
297#define FLASHROM_ISP_POP3 (1 << 8) /**< \brief POP3 server */
298#define FLASHROM_ISP_POP3_USER (1 << 9) /**< \brief POP3 username */
299#define FLASHROM_ISP_POP3_PASS (1 << 10) /**< \brief POP3 password */
300#define FLASHROM_ISP_PROXY_HOST (1 << 11) /**< \brief Proxy hostname */
301#define FLASHROM_ISP_PROXY_PORT (1 << 12) /**< \brief Proxy port */
302#define FLASHROM_ISP_PPP_USER (1 << 13) /**< \brief PPP username */
303#define FLASHROM_ISP_PPP_PASS (1 << 14) /**< \brief PPP password */
304#define FLASHROM_ISP_OUT_PREFIX (1 << 15) /**< \brief Outside dial prefix */
305#define FLASHROM_ISP_CW_PREFIX (1 << 16) /**< \brief Call waiting prefix */
306#define FLASHROM_ISP_REAL_NAME (1 << 17) /**< \brief Real name */
307#define FLASHROM_ISP_MODEM_INIT (1 << 18) /**< \brief Modem init string */
308#define FLASHROM_ISP_AREA_CODE (1 << 19) /**< \brief Area code */
309#define FLASHROM_ISP_LD_PREFIX (1 << 20) /**< \brief Long distance prefix */
310#define FLASHROM_ISP_PHONE1 (1 << 21) /**< \brief Phone number 1 */
311#define FLASHROM_ISP_PHONE2 (1 << 22) /**< \brief Phone number 2 */
312/** @} */
313
314/** \defgroup fr_flags ISP Config Flags
315 \brief Flags for the flashrom_ispcfg_t struct
316 \ingroup flashrom
317
318 The flags field of the flashrom_ispcfg_t will have some combination of these
319 ORed together to represent what settings were set.
320
321 @{
322*/
323#define FLASHROM_ISP_DIAL_AREACODE (1 << 0) /**< \brief Dial area code before number */
324#define FLASHROM_ISP_USE_PROXY (1 << 1) /**< \brief Proxy enabled */
325#define FLASHROM_ISP_PULSE_DIAL (1 << 2) /**< \brief Pulse dialing (instead of tone) */
326#define FLASHROM_ISP_BLIND_DIAL (1 << 3) /**< \brief Blind dial (don't wait for tone) */
327/** @} */
328
329/** \brief ISP configuration structure.
330 \ingroup flashrom
331
332 This structure will be filled in by flashrom_get_ispcfg() (DreamPassport) or
333 flashrom_get_pw_ispcfg() (PlanetWeb). Thanks to Sam Steele for the
334 information about DreamPassport's ISP settings.
335
336 \headerfile dc/flashrom.h
337*/
338typedef struct flashrom_ispcfg {
339 int method; /**< \brief DHCP, Static, dialup(?), PPPoE
340 \see fr_method */
341 uint32_t valid_fields; /**< \brief Which fields are valid?
342 \see fr_fields */
343 uint32_t flags; /**< \brief Various flags that can be set in options
344 \see fr_flags */
345
346 uint8_t ip[4]; /**< \brief Host IP address */
347 uint8_t nm[4]; /**< \brief Netmask */
348 uint8_t bc[4]; /**< \brief Broadcast address */
349 uint8_t gw[4]; /**< \brief Gateway address */
350 uint8_t dns[2][4]; /**< \brief DNS servers (2) */
351 int proxy_port; /**< \brief Proxy server port */
352 char hostname[24]; /**< \brief DHCP/Host name */
353 char email[64]; /**< \brief Email address */
354 char smtp[31]; /**< \brief SMTP server */
355 char pop3[31]; /**< \brief POP3 server */
356 char pop3_login[20]; /**< \brief POP3 login */
357 char pop3_passwd[32];/**< \brief POP3 passwd */
358 char proxy_host[31]; /**< \brief Proxy server hostname */
359 char ppp_login[29]; /**< \brief PPP login */
360 char ppp_passwd[20]; /**< \brief PPP password */
361 char out_prefix[9]; /**< \brief Outside dial prefix */
362 char cw_prefix[9]; /**< \brief Call waiting prefix */
363 char real_name[31]; /**< \brief The "Real Name" field of PlanetWeb */
364 char modem_init[33]; /**< \brief The modem init string to use */
365 char area_code[4]; /**< \brief The area code the user is in */
366 char ld_prefix[21]; /**< \brief The long-distance dial prefix */
367 char p1_areacode[4]; /**< \brief Phone number 1's area code */
368 char phone1[26]; /**< \brief Phone number 1 */
369 char p2_areacode[4]; /**< \brief Phone number 2's area code */
370 char phone2[26]; /**< \brief Phone number 2 */
372
373/** \brief Retrieve DreamPassport's ISP configuration.
374 \ingroup flashrom
375
376 This function retrieves the console's ISP settings as set by DreamPassport,
377 if they exist. You should check the valid_fields bitfield for the part of
378 the struct you want before relying on the data.
379
380 \param out Storage for the structure.
381 \retval 0 On success.
382 \retval -1 On error (no settings found, or other errors).
383*/
385
386/** \brief Retrieve PlanetWeb's ISP configuration.
387 \ingroup flashrom
388
389 This function retrieves the console's ISP settings as set by PlanetWeb (1.0
390 and 2.1 have been verified to work), if they exist. You should check the
391 valid_fields bitfield for the part of the struct you want before relying on
392 the data.
393
394 \param out Storage for the structure.
395 \retval 0 On success.
396 \retval -1 On error (i.e, no PlanetWeb settings found).
397*/
399
400/* More to come later */
401
402__END_DECLS
403
404#endif /* __DC_FLASHROM_H */
int flashrom_get_syscfg(flashrom_syscfg_t *out)
Retrieve the current system configuration settings.
int flashrom_get_ispcfg(flashrom_ispcfg_t *out)
Retrieve DreamPassport's ISP configuration.
int flashrom_info(uint32_t part_id, uint32_t *start_offset, size_t *size_out)
Retrieve information about the given partition.
int flashrom_get_pw_ispcfg(flashrom_ispcfg_t *out)
Retrieve PlanetWeb's ISP configuration.
int flashrom_get_block(uint32_t part_id, uint32_t block_id, uint8_t *buffer_out)
Get a logical block from the specified partition.
int flashrom_get_region(void)
Retrieve the console's region code.
int flashrom_read(uint32_t offset, void *buffer_out, size_t bytes)
Read data from the flashrom.
int flashrom_delete(uint32_t offset)
Delete data from the flashrom.
int flashrom_write(uint32_t offset, const void *buffer, size_t bytes)
Write data to the flashrom.
int modem_init(void)
Initialize the modem.
ISP configuration structure.
Definition flashrom.h:338
int proxy_port
Proxy server port.
Definition flashrom.h:351
uint32_t flags
Various flags that can be set in options.
Definition flashrom.h:343
uint32_t valid_fields
Which fields are valid?
Definition flashrom.h:341
int method
DHCP, Static, dialup(?), PPPoE.
Definition flashrom.h:339
System configuration structure.
Definition flashrom.h:221
uint32_t language
Language setting.
Definition flashrom.h:222
uint32_t audio
Stereo/mono setting.
Definition flashrom.h:224
uint32_t autostart
Autostart discs? 0 == off, 1 == on.
Definition flashrom.h:225
Common integer types.