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