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