/**
* @file flash.h
* This file provides various definitions and prototypes for the flash
* driver and all its affiliates
*
* $Id: flash.h 2065 2009-09-04 21:44:36Z brylow $
*/
/* Embedded XINU, Copyright (C) 2007. All rights reserved. */
#ifndef _FLASH_H_
#define _FLASH_H_
/* Disk variables */
#define MAX_LIVE_BLOCKS 8 /**< number of blocks to keep in memory */
#define FLASH_BLK_SIZE 512 /**< disk blocks are 512 bytes */
#define FLASH_BLOCK_FREE 0 /**< block can be allocated */
#define FLASH_BLOCK_CLEAN 1 /**< block has been read but not writted */
#define FLASH_BLOCK_DIRTY 2 /**< block has been changed */
/* Important disk block sections */
#define CFE_MIN_BLOCK 0x0000 /**< Physical addr: 0x000000 */
#define CFE_MAX_BLOCK 0x01FF /**< Physical addr: 0x03ffff */
#define KERNEL_MIN_BLOCK 0x0200 /**< Physical addr: 0x040000 */
#define KERNEL_MAX_BLOCK 0x03FF /**< Physical addr: 0x07ffff */
#define NVRAM_MIN_BLOCK 0x1FC0 /**< Physical addr: 0x3F8000 */
#define NVRAM_MAX_BLOCK 0x1FFF /**< Physical addr: 0x3fffff */
/* Flash control switch values */
#define FLASH_BLOCK_SIZE 0x0000 /**< get the size of disk blocks */
#define FLASH_N_BLOCKS 0x0001 /**< get number of disk blocks */
#define FLASH_SYNC 0x0002 /**< force sync of disk device */
/* Flash variables */
#define FLASH_WIDEMODE 1
#define MAX_REGIONS 8
/* TRX variables */
#define TRX_MAGIC 0x30524448
/* Structures */
struct trx_header
{
uint32 magic; /**< "HDR0" */
uint32 len; /**< Length of file including header */
uint32 crc; /**< 32-bit CRC from flag_vers to EOF */
uint32 flags_vers; /**< 0-15 flags, 16-31 version */
uint32 offsets[3]; /**< Partition offsets from header start */
};
/* File structure */
struct file
{
uint32 len;
char *name;
void *data;
};
struct flash_region
{
uint32 nblocks; /**< number of blocks within region */
uint32 block_size; /**< size of block in region */
uint32 region_start; /**< beginning of region in memory */
uint32 region_size; /**< size of region in bytes */
};
struct flash_block
{
uint32 start_pos; /**< physical position data starts at */
uint32 size; /**< size of this block */
byte state; /**< state of this block */
void *buffer; /**< buffer for this block */
};
struct flash
{
struct dentry *device; /**< flash entry in dev structure */
byte commands; /**< command set the interface uses */
uint32 base; /**< base address for flash memory */
sid32 lock; /**< lock for execution flash operations */
uint32 size; /**< size (in bytes) of flash memory */
byte mode; /**< current mode of flash */
uint16 nregions; /**< number of regions on device */
struct flash_region regions[MAX_REGIONS]; /**< region info. */
uint32 log_size; /**< size of logical disk blocks */
uint32 nlog_blocks; /**< number of logical blocks on disk */
/** list of open blocks on flash device */
struct flash_block erase_blocks[MAX_LIVE_BLOCKS];
byte curr_block; /**< offset of the oldest block stored */
};
extern struct flash_block bad_block;
/*
* Common Flash Interface Query commands and macros
*/
/* put/get 8-bits commands for CFI */
#define CFI_PUT_8(addr,offset,cmd) \
*((volatile unsigned char *)((addr)+((offset)<