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