LibXenon
Bare-metal Xbox 360 homebrew library
Loading...
Searching...
No Matches
xenon_sfcx.h
Go to the documentation of this file.
1#ifndef __xenon_sfcx_h
2#define __xenon_sfcx_h
3
4//Registers
5#define SFCX_CONFIG 0x00
6#define SFCX_STATUS 0x04
7#define SFCX_COMMAND 0x08
8#define SFCX_ADDRESS 0x0C
9#define SFCX_DATA 0x10
10#define SFCX_LOGICAL 0x14
11#define SFCX_PHYSICAL 0x18
12#define SFCX_DPHYSADDR 0x1C
13#define SFCX_MPHYSADDR 0x20
14#define SFCX_PHISON 0xFC
15
16//Commands for Command Register
17#define PAGE_BUF_TO_REG 0x00 //Read page buffer to data register
18#define REG_TO_PAGE_BUF 0x01 //Write data register to page buffer
19#define LOG_PAGE_TO_BUF 0x02 //Read logical page into page buffer
20#define PHY_PAGE_TO_BUF 0x03 //Read physical page into page buffer
21#define WRITE_PAGE_TO_PHY 0x04 //Write page buffer to physical page
22#define BLOCK_ERASE 0x05 //Block Erase
23#define DMA_LOG_TO_RAM 0x06 //DMA logical flash to main memory
24#define DMA_PHY_TO_RAM 0x07 //DMA physical flash to main memory
25#define DMA_RAM_TO_PHY 0x08 //DMA main memory to physical flash
26#define UNLOCK_CMD_0 0x55 //Unlock command 0
27#define UNLOCK_CMD_1 0xAA //Unlock command 1
28
29//Config Register bitmasks
30#define CONFIG_DBG_MUX_SEL 0x7C000000u //Debug MUX Select
31#define CONFIG_DIS_EXT_ER 0x2000000u //Disable External Error (Pre Jasper?)
32#define CONFIG_CSR_DLY 0x1FE0000u //Chip Select to Timing Delay
33#define CONFIG_ULT_DLY 0x1F800u //Unlocking Timing Delay
34#define CONFIG_BYPASS 0x400u //Debug Bypass
35#define CONFIG_DMA_LEN 0x3C0u //DMA Length in Pages
36#define CONFIG_FLSH_SIZE 0x30u //Flash Size (Pre Jasper)
37#define CONFIG_WP_EN 0x8u //Write Protect Enable
38#define CONFIG_INT_EN 0x4u //Interrupt Enable
39#define CONFIG_ECC_DIS 0x2u //ECC Decode Disable
40#define CONFIG_SW_RST 0x1u //Software reset
41
42//Status Register bitmasks
43#define STATUS_ILL_LOG 0x800u //Illegal Logical Access
44#define STATUS_PIN_WP_N 0x400u //NAND Not Write Protected
45#define STATUS_PIN_BY_N 0x200u //NAND Not Busy
46#define STATUS_INT_CP 0x100u //Interrupt
47#define STATUS_ADDR_ER 0x80u //Address Alignment Error
48#define STATUS_BB_ER 0x40u //Bad Block Error
49#define STATUS_RNP_ER 0x20u //Logical Replacement not found
50#define STATUS_ECC_ER 0x1Cu //ECC Error, 3 bits, need to determine each
51#define STATUS_WR_ER 0x2u //Write or Erase Error
52#define STATUS_BUSY 0x1u //Busy
53#define STATUS_ERROR (STATUS_ILL_LOG|STATUS_ADDR_ER|STATUS_BB_ER|STATUS_RNP_ER|STATUS_ECC_ER|STATUS_WR_ER)
54
55//Page bitmasks
56#define PAGE_VALID 0x4000000u
57#define PAGE_PID 0x3FFFE00u
58
59// API Consumers should use these two defines to
60// use for creating static buffers at compile time
61#define MAX_PAGE_SZ 0x210 //Max known hardware physical page size
62#define MAX_BLOCK_SZ 0x42000 //Max known hardware physical block size
63
64#define META_TYPE_0 0x00 //Pre Jasper
65#define META_TYPE_1 0x01 //Jasper 16MB
66#define META_TYPE_2 0x02 //Jasper 256MB and 512MB Large Block
67
68#define CONFIG_BLOCKS 0x04 //Number of blocks assigned for config data
69
70// variables should NOT be in a header file! anything that uses this header is increased in size by this amount! [cOz]
71// static unsigned char sfcx_page[MAX_PAGE_SZ]; //Max known hardware physical page size
72// static unsigned char sfcx_block[MAX_BLOCK_SZ]; //Max known hardware physical block size
73
74#define RAW_NAND_64 0x4200000
75
76#define SFCX_INITIALIZED 1
77
78// status ok or status ecc corrected
79//#define SFCX_SUCCESS(status) (((int) status == STATUS_PIN_BY_N) || ((int) status & STATUS_ECC_ER))
80// define success as no ecc error and no bad block error
81#define SFCX_SUCCESS(status) ((status&STATUS_ERROR)==0)
82
83struct sfc
84{
87
91
95
101
106};
107
108unsigned int sfcx_init(void);
109
110void sfcx_writereg(int addr, unsigned long data);
111unsigned long sfcx_readreg(int addr);
112
114int sfcx_read_page(unsigned char *data, int address, int raw);
115int sfcx_write_page(unsigned char *data, int address);
116int sfcx_read_block(unsigned char *data, int address, int raw);
117int sfcx_write_block(unsigned char *data, int address);
118
119void sfcx_calcecc(unsigned int *data);
120int sfcx_get_blocknumber(unsigned char *data);
121void sfcx_set_blocknumber(unsigned char *data, int num);
122int sfcx_get_blockversion(unsigned char *data);
123void sfcx_set_blockversion(unsigned char *data, int ver);
124void sfcx_set_pagevalid(unsigned char *data);
125void sfcx_set_pageinvalid(unsigned char *data);
126int sfcx_is_pagevalid(unsigned char *data);
127int sfcx_is_pagezeroed(unsigned char *data);
128int sfcx_is_pageerased(unsigned char *data);
129int sfcx_block_to_address(int block);
131int sfcx_block_to_rawaddress(int block);
133int rawflash_writeImage(int len, int f);
134int try_rawflash(char *filename);
135
137
138// for use in other files
139extern struct sfc sfc;
140#endif
uint32_t address
Definition: ata.h:0
Definition: xenon_sfcx.h:84
int page_sz_phys
Definition: xenon_sfcx.h:90
int page_sz
Definition: xenon_sfcx.h:88
int len_config
Definition: xenon_sfcx.h:105
int size_bytes_phys
Definition: xenon_sfcx.h:98
int meta_type
Definition: xenon_sfcx.h:86
int size_blocks
Definition: xenon_sfcx.h:100
int blocks_per_lg_block
Definition: xenon_sfcx.h:102
int size_bytes
Definition: xenon_sfcx.h:97
int size_mb
Definition: xenon_sfcx.h:96
int meta_sz
Definition: xenon_sfcx.h:89
int block_sz
Definition: xenon_sfcx.h:93
int initialized
Definition: xenon_sfcx.h:85
int addr_config
Definition: xenon_sfcx.h:104
int pages_in_block
Definition: xenon_sfcx.h:92
int size_usable_fs
Definition: xenon_sfcx.h:103
int block_sz_phys
Definition: xenon_sfcx.h:94
int size_pages
Definition: xenon_sfcx.h:99
unsigned long sfcx_readreg(int addr)
Definition: xenon_sfcx.c:20
int sfcx_is_pageerased(unsigned char *data)
Definition: xenon_sfcx.c:361
int sfcx_read_page(unsigned char *data, int address, int raw)
Definition: xenon_sfcx.c:25
void sfcx_set_pagevalid(unsigned char *data)
Definition: xenon_sfcx.c:300
int sfcx_write_page(unsigned char *data, int address)
Definition: xenon_sfcx.c:74
void sfcx_set_pageinvalid(unsigned char *data)
Definition: xenon_sfcx.c:316
int sfcx_rawaddress_to_block(int address)
Definition: xenon_sfcx.c:387
int sfcx_block_to_rawaddress(int block)
Definition: xenon_sfcx.c:382
int sfcx_get_blocknumber(unsigned char *data)
Definition: xenon_sfcx.c:217
int sfcx_address_to_block(int address)
Definition: xenon_sfcx.c:377
int sfcx_get_blockversion(unsigned char *data)
Definition: xenon_sfcx.c:254
void sfcx_set_blockversion(unsigned char *data, int ver)
Definition: xenon_sfcx.c:275
int sfcx_read_block(unsigned char *data, int address, int raw)
Definition: xenon_sfcx.c:121
int rawflash_writeImage(int len, int f)
Definition: xenon_sfcx.c:504
int sfcx_is_pagezeroed(unsigned char *data)
Definition: xenon_sfcx.c:350
void sfcx_calcecc(unsigned int *data)
Definition: xenon_sfcx.c:211
int sfcx_read_metadata_type(void)
void sfcx_writereg(int addr, unsigned long data)
Definition: xenon_sfcx.c:15
int sfcx_is_pagevalid(unsigned char *data)
Definition: xenon_sfcx.c:332
int try_rawflash(char *filename)
Definition: xenon_sfcx.c:559
unsigned int sfcx_init(void)
Definition: xenon_sfcx.c:645
int sfcx_erase_block(int address)
Definition: xenon_sfcx.c:150
int sfcx_block_to_address(int block)
Definition: xenon_sfcx.c:372
int sfcx_write_block(unsigned char *data, int address)
Definition: xenon_sfcx.c:136
void sfcx_set_blocknumber(unsigned char *data, int num)
Definition: xenon_sfcx.c:235
union @15 data