XINU
flash.h
Go to the documentation of this file.
1 
8 /* Embedded XINU, Copyright (C) 2007. All rights reserved. */
9 
10 
11 #ifndef _FLASH_H_
12 #define _FLASH_H_
13 
14 /* Disk variables */
15 #define MAX_LIVE_BLOCKS 8
16 #define FLASH_BLK_SIZE 512
18 #define FLASH_BLOCK_FREE 0
19 #define FLASH_BLOCK_CLEAN 1
20 #define FLASH_BLOCK_DIRTY 2
22 /* Important disk block sections */
23 #define CFE_MIN_BLOCK 0x0000
24 #define CFE_MAX_BLOCK 0x01FF
25 #define KERNEL_MIN_BLOCK 0x0200
26 #define KERNEL_MAX_BLOCK 0x03FF
27 #define NVRAM_MIN_BLOCK 0x1FC0
28 #define NVRAM_MAX_BLOCK 0x1FFF
30 /* Flash control switch values */
31 #define FLASH_BLOCK_SIZE 0x0000
32 #define FLASH_N_BLOCKS 0x0001
33 #define FLASH_SYNC 0x0002
35 /* Flash variables */
36 #define FLASH_WIDEMODE 1
37 #define MAX_REGIONS 8
38 
39 /* TRX variables */
40 #define TRX_MAGIC 0x30524448
41 
42 /* Structures */
43 struct trx_header
44 {
50 };
51 
52 /* File structure */
53 struct file
54 {
56  char *name;
57  void *data;
58 };
59 
61 {
66 };
67 
69 {
73  void *buffer;
74 };
75 
76 struct flash
77 {
78  struct dentry *device;
85  struct flash_region regions[MAX_REGIONS];
91  struct flash_block erase_blocks[MAX_LIVE_BLOCKS];
93 };
94 
95 extern struct flash_block bad_block;
96 
97 /*
98  * Common Flash Interface Query commands and macros
99  */
100 
101 /* put/get 8-bits commands for CFI */
102 #define CFI_PUT_8(addr,offset,cmd) \
103  *((volatile unsigned char *)((addr)+((offset)<<FLASH_WIDEMODE)))=(cmd)
104 #define CFI_GET_8(addr,offset) \
105  *((volatile unsigned char *)((addr)+((offset)<<FLASH_WIDEMODE)))
106 
107 /* commands for data gathering */
108 #define CFI_QUERY_ADDR 0x55
109 #define CFI_QUERY_MODE 0x98
110 #define CFI_QUERY_EXIT 0xFF
111 
112 #define CFI_MANUFACTURER 0x00
113 #define CFI_DEVICE 0x01
114 #define CFI_SIGNATURE 0x10
115 #define CFI_QUERY_STRING 0x10
116 #define CFI_COMMAND_SET 0x13
117 #define CFI_DEV_SIZE 0x27
118 #define CFI_DEV_INTERFACE 0x28
119 #define CFI_MAX_BUFFER 0x2A
120 #define CFI_REGION_COUNT 0x2C
121 #define CFI_REGION_TAB 0x2D
122 
123 /* Known command sets (from CFI publication 100) */
124 #define FLASH_INTEL_ECS 0x0001
125 #define FLASH_AMD_SCS 0x0002
126 #define FLASH_INTEL_SCS 0x0003
127 #define FLASH_AMD_ECS 0x0004
128 #define FLASH_MTSU_SCS 0x0100
129 #define FLASH_MTSU_ECS 0x0101
130 
131 /*
132  * Intel Flash specifc commands and macros
133  */
134 
135 /* put/get 8-bits commands for Intel */
136 #define INTEL_PUT_8(addr,byte) \
137  *((volatile unsigned char *)((unsigned int)(addr)))=(byte)
138 #define INTEL_GET_8(addr) \
139  *((volatile unsigned char *)((unsigned int)(addr)))
140 
141 /* put/get 8-bits commands for AMD */
142 #define AMD_PUT_8(addr,byte) \
143  *((volatile unsigned char *)((unsigned int)(addr)))=(byte)
144 #define AMD_GET_8(addr) \
145  *((volatile unsigned char *)((unsigned int)(addr)))
146 
147 /* put/get 16-bits commands for Intel */
148 #define INTEL_PUT_16(addr,word) \
149  *((volatile unsigned int16 *)((unsigned int)(addr)))=(word)
150 #define INTEL_GET_16(addr) \
151  *((volatile unsigned int16 *)((unsigned int)(addr)))
152 
153 /* put/get 16-bits commands for AMD */
154 #define AMD_PUT_16(addr,word) \
155  *((volatile unsigned int16 *)((unsigned int)(addr)))=(word)
156 #define AMD_GET_16(addr) \
157  *((volatile unsigned int16 *)((unsigned int)(addr)))
158 
159 
160 /* Intel command codes */
161 #define INTEL_READ 0xFF
162 #define INTEL_PROGRAM 0x40
163 #define INTEL_ERASE 0x20
164 #define INTEL_CONFIRM 0xD0
165 #define INTEL_RESUME 0xD0
166 #define INTEL_UNLOCK 0xD0
167 #define INTEL_SUSPEND 0xB0
168 #define INTEL_READ_SR 0x70
169 #define INTEL_CLR_SR 0x50
170 #define INTEL_READ_ID 0x90
171 #define INTEL_BLOCKMOD 0x60
172 #define INTEL_LOCK 0x01
173 #define INTEL_LOCKDOWN 0x2F
175 /* AMD Command Codes */
176 #define AMD_UNLOCK_CYCLE1 0xAA
177 #define AMD_UNLOCK_CYCLE2 0x55
178 #define AMD_ERASE_CYCLE3 0x80
179 #define AMD_ERASE_CYCLE6 0x30
180 #define AMD_PROGRAM_CYCLE3 0xA0
181 #define AMD_RESET 0xF0
182 #define AMD_READ 0xFF
183 #define AMD_BLOCKMOD 0x60
184 #define AMD_LOCK 0x01
185 #define AMD_CLR_SR 0x50
187 /* AMD */
188 #define AMD_REG_CYCLE1 0x555
189 #define AMD_REG_CYCLE2 0x2AA
190 #define AMD_SR_WSMS 0x001
192 /* Intel status register offsets */
193 #define INTEL_SR_WSMS 7
194 #define INTEL_SR_ESS 6
195 #define INTEL_SR_ES 5
196 #define INTEL_SR_PS 4
197 #define INTEL_SR_PSS 2
198 #define INTEL_SR_BLS 1
200 /* Intel identifier register offsets */
201 #define INTEL_ID_MFG 0x00
202 #define INTEL_ID_DEV 0x02
203 #define INTEL_ID_BLS 0x04
205 /* Intel block lock constants */
206 #define INTEL_S_LOCK 0x01
207 #define INTEL_H_LOCK 0x02
209 /* AMD block lock constants */
210 #define AMD_S_LOCK 0x01
211 #define AMD_H_LOCK 0x02
213 /* flashControl constants */
214 #define FLASH_BLOCK 0x00
215 #define FLASH_LOGBLOCK 0x01
217 /* physicalLock commands */
218 #define FLASH_STATUS 0x0000
219 #define FLASH_MODE 0x0001
220 #define FLASH_LOCKED 0x0010
221 #define FLASH_LOCK 0x0011
222 #define FLASH_UNLOCK 0x0012
223 #define FLASH_LOCKDOWN 0x0013
224 #define FLASH_ERASE_PREP 0x0014
225 #define FLASH_RESET 0x0015
226 
227 extern struct flash flashtab[];
228 
229 /* Prototypes for flash function calls */
230 devcall flashInit(struct dentry *);
231 devcall flashOpen(struct dentry *, va_list);
232 devcall flashRead(struct dentry *, byte *, uint32);
233 devcall flashWrite(struct dentry *, byte *, uint32);
234 devcall flashSeek(struct dentry *, uint32);
236 devcall flashClose(struct dentry *);
237 
238 /* Prototypes for the Logical Flash Interface */
239 devcall logicalRead(struct flash *, byte *, uint32);
240 devcall logicalWrite(struct flash *, byte *, uint32);
241 struct flash_block logicalMap(struct flash *, uint32);
242 
243 /* Prototypes for Physical Flash functions */
244 devcall physicalRead(struct flash *, struct flash_block *);
245 devcall physicalWrite(struct flash *, struct flash_block *);
246 devcall physicalErase(struct flash *, struct flash_block *);
247 devcall physicalControl(struct flash *, struct flash_block *, byte,
248  uint32);
249 devcall physicalIntelRead(struct flash *, struct flash_block *);
250 devcall physicalIntelWrite(struct flash *, struct flash_block *);
251 devcall physicalIntelErase(struct flash *, struct flash_block *);
253  uint32);
254 devcall physicalAMDRead(struct flash *, struct flash_block *);
255 
256 /* Prototypes for changing OS in flash memory */
257 bool validateTrx(struct file *);
258 
259 /* File function prototypes */
260 syscall printFileStats(struct file *, char *, char *, int, int);
261 syscall freeFile(struct file *);
262 
263 #endif /* _FLASH_H_ */
devcall physicalIntelRead(struct flash *, struct flash_block *)
byte commands
Definition: flash.h:79
byte curr_block
Definition: flash.h:92
uint32 log_size
Definition: flash.h:87
unsigned char byte
符号なし8ビット値(unsigned char)
Definition: kernel.h:7
uint16 nregions
Definition: flash.h:84
devcall physicalAMDRead(struct flash *, struct flash_block *)
Definition: flash.h:76
devcall physicalIntelControl(struct flash *, struct flash_block *, byte, uint32)
void * data
Definition: flash.h:57
uint32 block_size
Definition: flash.h:63
struct flash flashtab[]
uint32 size
Definition: flash.h:71
devcall flashSeek(struct dentry *, uint32)
void * buffer
Definition: flash.h:73
devcall flashOpen(struct dentry *, va_list)
char * name
Definition: flash.h:56
uint32 offsets[3]
Definition: flash.h:49
devcall flashInit(struct dentry *)
struct flash_block bad_block
devcall physicalIntelWrite(struct flash *, struct flash_block *)
devcall logicalRead(struct flash *, byte *, uint32)
Definition: conf.h:6
#define MAX_LIVE_BLOCKS
Definition: flash.h:15
uint32 len
Definition: flash.h:46
struct dentry * device
Definition: flash.h:78
byte state
Definition: flash.h:72
uint32 region_start
Definition: flash.h:64
devcall flashClose(struct dentry *)
uint32 nblocks
Definition: flash.h:62
struct flash_block logicalMap(struct flash *, uint32)
devcall flashWrite(struct dentry *, byte *, uint32)
uint32 start_pos
Definition: flash.h:70
devcall physicalControl(struct flash *, struct flash_block *, byte, uint32)
uint32 magic
Definition: flash.h:45
int int32
符号あり32ビット整数(int)
Definition: kernel.h:11
devcall flashRead(struct dentry *, byte *, uint32)
unsigned short uint16
符号なし16ビット整数(unsigned short)
Definition: kernel.h:17
bool validateTrx(struct file *)
devcall physicalIntelErase(struct flash *, struct flash_block *)
byte mode
Definition: flash.h:83
uint32 nlog_blocks
Definition: flash.h:88
__builtin_va_list va_list
可変個の実引数を扱うための情報を保持するための型(__builtin_va_listはGCCに定義された型) ...
Definition: stdarg.h:7
uint32 crc
Definition: flash.h:47
int32 syscall
システムコール関数 返り値の型
Definition: kernel.h:47
uint32 base
Definition: flash.h:80
sid32 lock
Definition: flash.h:81
devcall logicalWrite(struct flash *, byte *, uint32)
devcall physicalErase(struct flash *, struct flash_block *)
devcall flashControl(struct dentry *, uint16, int32, int32)
devcall physicalWrite(struct flash *, struct flash_block *)
unsigned int uint32
符号なし32ビット整数(unsigned int)
Definition: kernel.h:15
uint32 region_size
Definition: flash.h:65
int32 devcall
デバイスコール関数 返り値の型
Definition: kernel.h:49
uint32 len
Definition: flash.h:55
syscall freeFile(struct file *)
uint32 flags_vers
Definition: flash.h:48
uint32 size
Definition: flash.h:82
int32 sid32
セマフォID
Definition: kernel.h:22
devcall physicalRead(struct flash *, struct flash_block *)
#define MAX_REGIONS
Definition: flash.h:37
Definition: flash.h:53
syscall printFileStats(struct file *, char *, char *, int, int)