⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 flash.h

📁 采用ST20 CPU的机顶盒的烧写程序
💻 H
字号:
/*
 * flash.h
 *
 * Copyright (c) 2003-2007 STMicroelectronics Limited. All right reserved.
 *
 * Header file containing types & defines pertaining
 * to the layout, of FLASH memory, the supported
 * flash parts, and the flashutil functions.
 */
#ifndef __flash_h_
#define __flash_h_

#include <os21.h>

/* This is needed by old OS21s without the vmem API (but is benign with an OS21
   with the vmem API as vmemadapt functions are weak).
 */
#include "vmemadapt.h"

#if defined(__mb390__) || defined(__mb424__)
#ifndef FLASH_START
#define FLASH_START                      0x7f800000 /* 8MB ending at 0x7FFFFFFF */
#endif
#define FLASH_MAX_CPUS                   1
#elif defined(__mb435__)
#ifndef FLASH_START
#define FLASH_START                      0x7e000000 /* 32MB ending at 0x7FFFFFFF */
#endif
#define FLASH_MAX_CPUS                   1
#endif /* defined(__mb390__) || defined(__mb424__) || defined(__mb435__) */

#if defined(__mb548__)
#ifndef FLASH_START
#define FLASH_START                      0x01000000 /* Bootrom at address 0, so FLASH here */
#endif
#endif

#ifndef FLASH_START
#define FLASH_START                      0x00000000
#endif
#ifndef FLASH_MAX_CPUS
#define FLASH_MAX_CPUS                   8
#endif
#define FLASH_DESC_LEN                   32
#define FLASH_BOOT_VECTOR_SIZE           64
#define FLASH_IMAGE_DIRECTORY_SIZE       64
#define FLASH_BOOT_FLAG                  0x80000000
#define FLASH_CPU_MASK                   0x000000ff
#define FLASH_CPU_ARCH_SH4               0x00000100
#define FLASH_CPU_ARCH_LX                0x00000200
#define FLASH_CPU_ARCH_ST20              0x00000300
#define FLASH_CPU_ARCH_MASK              0x0000ff00
#define FLASH_IMAGE_TYPE_RELOC_LIB       0x00010000
#define FLASH_IMAGE_TYPE_DATA            0x00020000
#define FLASH_IMAGE_TYPE_CC_SIGDMA       0x00030000
#define FLASH_IMAGE_TYPE_MASK            0x00ff0000

#if defined(__mb376__) || defined(__espresso__)
#define FLASH_BASE                       (FLASH_START+0x0400)
#else
#define FLASH_BASE                       FLASH_START
#endif /* defined(__mb376__) || defined(__espresso__) */

#define FLASH_IMAGE_CONTROL_STRUCTS_SIZE (0x3700 - 4) /* -4 as CRC in that word */

#ifdef __cplusplus
extern "C" {
#endif /* __cplusplus */

/*
 * The first pages in FLASH are the boot page
 * consisting of the boot vectors, and boot
 * descriptors.
 */
typedef struct
{
  unsigned char code[FLASH_BOOT_VECTOR_SIZE];
} bootVector_t;

typedef struct
{
  unsigned int startAddress;
  unsigned int length;
  char description[FLASH_DESC_LEN];
} bootStrapDescriptor_t;

/*
 * Images are made up of sections of code/data.
 * Each section has a type, which indicates what is to be
 * done with it by the bootstrap code
 */
typedef enum
{
  SECTION_TYPE_SKIP = 0x00, /* No processing required */
  SECTION_TYPE_COPY = 0x01, /* Copy to RAM */
  SECTION_TYPE_ZERO = 0x02, /* Zeroing in RAM */
  SECTION_TYPE_RUN_LENGTH = 0x03, /* Runlength decode to RAM */
  SECTION_TYPE_DEFLATED = 0x04, /* Inflating to RAM */
  SECTION_TYPE_SYMBOLS = 0x05, /* ELF symbol table */
  SECTION_TYPE_RELOCATIONS = 0x06, /* ELF relocations */
  SECTION_TYPE_LX_BOOT = 0x07, /* .boot for an LX */

  /* The following are only used in img files - how to place sections */

  PLACEMENT_TYPE_ANYWHERE = 0x00000000, /* Can go anywhere */
  PLACEMENT_TYPE_NONE = 0x10000000, /* Has no presence in ROM */
  PLACEMENT_TYPE_INPLACE_BLANK = 0x20000000, /* Place here, init to 0xff */
  PLACEMENT_TYPE_INPLACE = 0x30000000 /* Must be place exactly here in ROM */
} sectionType_t;

#define SECTION_TYPE_MASK   0x000000FF
#define PLACEMENT_TYPE_MASK 0xF0000000

typedef struct
{
  sectionType_t type;
  unsigned int sourceAddress;
  unsigned int destinationAddress;
  unsigned int length;
} imageSection_t;

typedef struct
{
  char description[FLASH_DESC_LEN];
  unsigned int CPU;
  unsigned int stackAddress;
  unsigned int entryAddress;
  unsigned int numSections;
  imageSection_t sections[1];
} imageControl_t;

#if defined(__mb390__) || defined(__mb424__) || defined(__mb435__)
/* The top of FLASH looks like this ...*/
typedef struct
{
  imageControl_t failsafeImageControlStructure;               /* At 0x7ffffe04 */
  unsigned char failsafeImageControlSpace[0xBC];              /* At 0x7ffffe48 */
  bootVector_t bootVectors[FLASH_MAX_CPUS];                   /* At 0x7fffff00 */
  char padding[0x90];                                         /* At 0x7fffff40 */
  bootStrapDescriptor_t bootStrapDescriptors[FLASH_MAX_CPUS]; /* At 0x7fffffD0 */
  unsigned int* imageControlDirectoryPtr;                     /* At 0x7ffffff8 */
  unsigned int crc;                                           /* At 0x7ffffffc */
} bootPages_t;
#else
/* The bottom of the FLASH looks like this ... */
typedef struct
{                                                                /* Size  */
  bootVector_t bootVectors[FLASH_MAX_CPUS];                      /* 0x200 */
  char bootVectorDescriptions[FLASH_MAX_CPUS][FLASH_DESC_LEN];   /* 0x100 */
  bootStrapDescriptor_t bootStrapDescriptors[FLASH_MAX_CPUS];    /* 0x140 */
  unsigned int* imageControlDirectoryPtr;                        /* 0x4   */
  imageControl_t failsafeImageControlStructure;                  /* 0x40  */
  unsigned char failsafeImageControlSpace[0xB8];                 /* 0xB8  */
  unsigned int crc;                                              /* 0x4   */
} bootPages_t;
#endif /* defined(__mb390__) || defined(__mb424__) || defined(__mb435__) */

/*
 * After the locked FLASH blocks for the fail-safe application we have the FLASH
 * image directory pages for the main application(s).
 */

typedef struct
{
  imageControl_t* entries[FLASH_IMAGE_DIRECTORY_SIZE];
} imageDirectory_t;

/*
 * These pages consists of the image directory table,
 * followed by a bunch of boot control blocks, and a crc.
 * The directory table consists of pointers to boot control
 * blocks.
 */
typedef struct
{
  imageDirectory_t directory;
  unsigned char imageControlSpace[FLASH_IMAGE_CONTROL_STRUCTS_SIZE];
  unsigned int crc;
} imageDirectoryPages_t;

/*
 * Description of an img file -
 * a magic number (0x13a9f17e == 'imagefile')
 * and an image control struct
 */
#define IMAGE_FILE_MAGIC   0x13a9f17e

typedef struct fileHeader_s fileHeader_t;

/*
 * An image file starts with a magic number followed
 * by a standard image control structure.
 */
struct fileHeader_s
{
  unsigned int magic; /* IMAGE_FILE_MAGIC */
  imageControl_t imageInfo; /* Image information, as held in FLASH */
};

/*
 * Types used by flashutil.c
 */
typedef enum
{
  M58LT256GT,
  M58LT256GT_ALT_ID,
  M58LT128GSB,
  M29W160BT,
  M29W160BB,
  M28W320CB,
  E28F640J3A,
  M58LW064Cx16,
  M58LW032A,
  E28F640J3Ax16,
  M29DW324DB,
  M29DW324DBx16,
  M29KW064E,
  M29W640DT,
  M29W640DB,
  M29W640FT,
  M29W640FB,
  M29W320EB,
  M28W640FSUx16,
  S29GL064A  /*spansion*/
} flashType_t;
/*
 * Type used for describing the block layout
 * of devices
 */
typedef struct flashBlockInfo_s flashBlockInfo_t;

struct flashBlockInfo_s
{
  unsigned int offset; /* Blocks lower than this offset ... */
  unsigned int size; /* ... have this size */
};

/*
 * A progress reporting function
 */
typedef void (*flashProgress_t) (unsigned int done, unsigned int total);

/*
 * A supported target board
 */
typedef struct flashTarget_s flashTarget_t;

struct flashTarget_s
{
  const char* name;
  int         maxBanks;
  void       (*writeEnable)(void);
  void       (*writeDisable)(void);
  void       (*switchOnVDD)(void);
  void       (*switchOffVDD)(void);
};

/*
 * A FLASH device
 */
typedef struct flashDevice_s flashDevice_t;

struct flashDevice_s
{
  flashType_t type;
  const char* deviceName;
  const char* manufacturerName;
  unsigned int deviceID;
  unsigned int bankSize;
  unsigned int baseAddress;
  flashBlockInfo_t* blockInfo;

/*
 * Methods
 */
  void (*reset) (flashDevice_t*);
  void (*blockUnprotect) (flashDevice_t*, unsigned int);
  void (*blockErase) (flashDevice_t*, unsigned int);
  void (*chipErase) (flashTarget_t*, flashDevice_t*, flashProgress_t);
  void (*writeWord) (flashDevice_t*, unsigned int, unsigned int);
};

/*
 * flashutil.c functions
 */

/*
 * Routine to dump a FLASH block map file to a given FILE*
 */
void dumpBlockMap(flashDevice_t** devices, FILE* fp);

/*
 * Return the target info structure for the named target
 */
flashTarget_t* flashGetTarget(char* name);

/*
 * Return an array of strings listing the supported targets.
 */
const char** flashGetTargetNameList(void);

/*
 * Return a string containing the supported targets.
 */
const char* flashGetTargetNames(void);

/*
 * Scan for upto this many banks of FLASH
 * return an array of FLASH device descriptors
 */
flashDevice_t** flashIdentifyFlashes(flashTarget_t* target);

/*
 * Erase the given block within the device
 */
void flashBlockErase(flashTarget_t* target, flashDevice_t* device, unsigned int blockAddress);

/*
 * Erase the entire device
 * If progressFn is not NULL, it will be called back as the erase progresses.
 */
void flashChipErase(flashTarget_t* target, flashDevice_t* device, flashProgress_t progressFn);

/*
 * Program the given block within the device
 * If progressFn is not NULL, it will be called back as the write progresses.
 */
void flashBlockWrite(flashTarget_t* target, flashDevice_t* device,
                     unsigned int blockAddress, void* data, flashProgress_t progressFn);

/*
 * Program part of the given block within the device
 * If progressFn is not NULL, it will be called back as the write progresses.
 */
void flashPartBlockWrite(flashTarget_t* target, flashDevice_t* device,
                         unsigned int blockAddress, void* data, flashProgress_t progressFn, int size);

/*
 * Return the address of the block which contains the given address (in any
 * device on the target).
 */
unsigned int flashBlockBase(flashDevice_t** devices, unsigned int address, int* deviceIndex);

/*
 * Return the size of the block which contains the given
 * address within the device.
 */
unsigned int flashBlockSize(flashDevice_t* device, unsigned int address);

/*
 * Routine to calculate a 32-bit CRC over the region specified.
 */
unsigned int flashCalcCRC(unsigned int* pdata, unsigned int size);

/*
 * Routine to perform any core specific initialisation required.
 */
extern void init_flash_access(void);

/*
 * Flash virtual memory support functions.
 */

/* Function for getting the uncached base address of FLASH */
extern unsigned int getUncachedFlashBase(void);

/* Function for getting the cached base address of FLASH */
extern unsigned int getCachedFlashBase(void);

/* Function for converting a physical FLASH address to uncached */
extern unsigned int physToUncachedFlashAddr(unsigned int addr);

/* Function for converting a physical FLASH address to cached */
extern unsigned int physToCachedFlashAddr(unsigned int addr);

/* Unmap any vmem mapped FLASH regions implicitly created by the
   get<mode>FlashBase functions.
 */
extern void unmapFlash();

#ifdef __cplusplus
}
#endif /* __cplusplus */

#endif /* __flash_h_ */

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -