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