📄 flash.h
字号:
/* * (C) Copyright 2000-2005 * Wolfgang Denk, DENX Software Engineering, wd@denx.de. * * See file CREDITS for list of people who contributed to this * project. * * This program is free software; you can redistribute it and/or * modify it under the terms of the GNU General Public License as * published by the Free Software Foundation; either version 2 of * the License, or (at your option) any later version. * * This program is distributed in the hope that it will be useful, * but WITHOUT ANY WARRANTY; without even the implied warranty of * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * GNU General Public License for more details. * * You should have received a copy of the GNU General Public License * along with this program; if not, write to the Free Software * Foundation, Inc., 59 Temple Place, Suite 330, Boston, * MA 02111-1307 USA */#ifndef _FLASH_H_#define _FLASH_H_#include "types.h"/* * FLASH and environment organization */#define CFG_MAX_FLASH_BANKS 1 /* max number of memory banks */#define CFG_MAX_FLASH_SECT 128 /* max number of sectors on one chip *//* timeout values are in ticks */#define CFG_FLASH_ERASE_TOUT (25*CFG_HZ) /* Timeout for Flash Erase */#define CFG_FLASH_WRITE_TOUT (25*CFG_HZ) /* Timeout for Flash Write */#define PHYS_FLASH_1 0x00000000 /* Flash Bank #1 */#define PHYS_FLASH_SIZE 0x02000000 /* 32 MB */#define PHYS_FLASH_BANK_SIZE 0x02000000 /* 32 MB Banks */#define PHYS_FLASH_SECT_SIZE 0x00040000 /* 256 KB sectors (x2) */#define CFG_FLASH_BASE PHYS_FLASH_1/* NOTE: many default partitioning schemes assume the kernel starts at the * second sector, not an environment. You have been warned! */#define CFG_MONITOR_LEN PHYS_FLASH_SECT_SIZE#define CFG_ENV_IS_IN_FLASH 1#define CFG_ENV_ADDR (PHYS_FLASH_1 + PHYS_FLASH_SECT_SIZE)#define CFG_ENV_SECT_SIZE PHYS_FLASH_SECT_SIZE#define CFG_ENV_SIZE (PHYS_FLASH_SECT_SIZE / 16)#ifndef CFG_NO_FLASH/*----------------------------------------------------------------------- * FLASH Info: contains chip specific data, per FLASH bank */typedef struct { ulong size; /* total bank size in bytes */ ushort sector_count; /* number of erase units */ ulong flash_id; /* combined device & manufacturer code */ ulong start[CFG_MAX_FLASH_SECT]; /* physical sector start addresses */ uchar protect[CFG_MAX_FLASH_SECT]; /* sector protection status */#ifdef CFG_FLASH_CFI uchar portwidth; /* the width of the port */ uchar chipwidth; /* the width of the chip */ ushort buffer_size; /* # of bytes in write buffer */ ulong erase_blk_tout; /* maximum block erase timeout */ ulong write_tout; /* maximum write timeout */ ulong buffer_write_tout; /* maximum buffer write timeout */ ushort vendor; /* the primary vendor id */ ushort cmd_reset; /* vendor specific reset command */ ushort interface; /* used for x8/x16 adjustments */ ushort legacy_unlock; /* support Intel legacy (un)locking */ uchar manufacturer_id; /* manufacturer id */ ushort device_id; /* device id */ ushort device_id2; /* extended device id */ ushort ext_addr; /* extended query table address */ ushort cfi_version; /* cfi version */ ushort cfi_offset; /* offset for cfi query */ ulong addr_unlock1; /* unlock address 1 for AMD flash roms */ ulong addr_unlock2; /* unlock address 2 for AMD flash roms */ const char *name; /* human-readable name */#endif} flash_info_t;/* * Values for the width of the port */#define FLASH_CFI_8BIT 0x01#define FLASH_CFI_16BIT 0x02#define FLASH_CFI_32BIT 0x04#define FLASH_CFI_64BIT 0x08/* * Values for the width of the chip */#define FLASH_CFI_BY8 0x01#define FLASH_CFI_BY16 0x02#define FLASH_CFI_BY32 0x04#define FLASH_CFI_BY64 0x08/* convert between bit value and numeric value */#define CFI_FLASH_SHIFT_WIDTH 3/* * Values for the flash device interface */#define FLASH_CFI_X8 0x00#define FLASH_CFI_X16 0x01#define FLASH_CFI_X8X16 0x02#define FLASH_CFI_X16X32 0x05/* convert between bit value and numeric value */#define CFI_FLASH_SHIFT_WIDTH 3/* Prototypes */extern unsigned long flash_init (void);extern void flash_print_info (flash_info_t *);extern int flash_erase (flash_info_t *, int, int);extern int flash_sect_erase (ulong addr_first, ulong addr_last);extern int flash_sect_protect (int flag, ulong addr_first, ulong addr_last);/* common/flash.c */extern void flash_protect (int flag, ulong from, ulong to, flash_info_t *info);extern int flash_write (char *, ulong, ulong);extern flash_info_t *addr2info (ulong);extern int write_buff (flash_info_t *info, uchar *src, ulong addr, ulong cnt);/* board/?/flash.c */#if defined(CFG_FLASH_PROTECTION)extern int flash_real_protect(flash_info_t *info, long sector, int prot);extern void flash_read_user_serial(flash_info_t * info, void * buffer, int offset, int len);extern void flash_read_factory_serial(flash_info_t * info, void * buffer, int offset, int len);#endif /* CFG_FLASH_PROTECTION */#ifdef CONFIG_FLASH_CFI_LEGACYextern ulong board_flash_get_legacy(ulong base, int banknum, flash_info_t *info);extern int jedec_flash_match(flash_info_t *info, ulong base);#define CFI_CMDSET_AMD_LEGACY 0xFFF0#endif/*----------------------------------------------------------------------- * return codes from flash_write(): */#define ERR_OK 0#define ERR_TIMOUT 1#define ERR_NOT_ERASED 2#define ERR_PROTECTED 4#define ERR_INVAL 8#define ERR_ALIGN 16#define ERR_UNKNOWN_FLASH_VENDOR 32#define ERR_UNKNOWN_FLASH_TYPE 64#define ERR_PROG_ERROR 128/*----------------------------------------------------------------------- * Protection Flags for flash_protect(): */#define FLAG_PROTECT_SET 0x01#define FLAG_PROTECT_CLEAR 0x02#define FLAG_PROTECT_INVALID 0x03/*----------------------------------------------------------------------- * Set Environment according to label: */#define FLAG_SETENV 0x80/*----------------------------------------------------------------------- * Device IDs */#define AMD_MANUFACT 0x00010001 /* AMD manuf. ID in D23..D16, D7..D0 */#define FUJ_MANUFACT 0x00040004 /* FUJITSU manuf. ID in D23..D16, D7..D0 */#define ATM_MANUFACT 0x001F001F /* ATMEL */#define STM_MANUFACT 0x00200020 /* STM (Thomson) manuf. ID in D23.. -"- */#define SST_MANUFACT 0x00BF00BF /* SST manuf. ID in D23..D16, D7..D0 */#define MT_MANUFACT 0x00890089 /* MT manuf. ID in D23..D16, D7..D0 */#define INTEL_MANUFACT 0x00890089 /* INTEL manuf. ID in D23..D16, D7..D0 */#define INTEL_ALT_MANU 0x00B000B0 /* alternate INTEL namufacturer ID */#define MX_MANUFACT 0x00C200C2 /* MXIC manuf. ID in D23..D16, D7..D0 */#define TOSH_MANUFACT 0x00980098 /* TOSHIBA manuf. ID in D23..D16, D7..D0 */#define MT2_MANUFACT 0x002C002C /* alternate MICRON manufacturer ID*/#define EXCEL_MANUFACT 0x004A004A /* Excel Semiconductor */ /* Micron Technologies (INTEL compat.) */#define MT_ID_28F400_T 0x44704470 /* 28F400B3 ID ( 4 M, top boot sector) */#define MT_ID_28F400_B 0x44714471 /* 28F400B3 ID ( 4 M, bottom boot sect) */#define AMD_ID_LV040B 0x4F /* 29LV040B ID */ /* 4 Mbit, 512K x 8, */ /* 8 64K x 8 uniform sectors */#define AMD_ID_F033C 0xA3 /* 29LV033C ID */ /* 32 Mbit, 4Mbits x 8, */ /* 64 64K x 8 uniform sectors */#define AMD_ID_F065D 0x93 /* 29LV065D ID */ /* 64 Mbit, 8Mbits x 8, */ /* 126 64K x 8 uniform sectors */#define ATM_ID_LV040 0x13 /* 29LV040B ID */ /* 4 Mbit, 512K x 8, */ /* 8 64K x 8 uniform sectors */#define AMD_ID_F040B 0xA4 /* 29F040B ID */ /* 4 Mbit, 512K x 8, */ /* 8 64K x 8 uniform sectors */#define STM_ID_M29W040B 0xE3 /* M29W040B ID */ /* 4 Mbit, 512K x 8, */ /* 8 64K x 8 uniform sectors */#define AMD_ID_F080B 0xD5 /* 29F080 ID ( 1 M) */ /* 8 Mbit, 512K x 16, */ /* 8 64K x 16 uniform sectors */#define AMD_ID_F016D 0xAD /* 29F016 ID ( 2 M x 8) */#define AMD_ID_F032B 0x41 /* 29F032 ID ( 4 M x 8) */#define AMD_ID_LV116DT 0xC7 /* 29LV116DT ( 2 M x 8, top boot sect) */#define AMD_ID_LV116DB 0x4C /* 29LV116DB ( 2 M x 8, bottom boot sect) */#define AMD_ID_LV016B 0xc8 /* 29LV016 ID ( 2 M x 8) */#define AMD_ID_PL160CB 0x22452245 /* 29PL160CB ID (16 M, bottom boot sect */#define AMD_ID_LV400T 0x22B922B9 /* 29LV400T ID ( 4 M, top boot sector) */#define AMD_ID_LV400B 0x22BA22BA /* 29LV400B ID ( 4 M, bottom boot sect) */#define AMD_ID_LV033C 0xA3 /* 29LV033C ID ( 4 M x 8) */#define AMD_ID_LV065D 0x93 /* 29LV065D ID ( 8 M x 8) */#define AMD_ID_LV800T 0x22DA22DA /* 29LV800T ID ( 8 M, top boot sector) */#define AMD_ID_LV800B 0x225B225B /* 29LV800B ID ( 8 M, bottom boot sect) */#define AMD_ID_LV160T 0x22C422C4 /* 29LV160T ID (16 M, top boot sector) */#define AMD_ID_LV160B 0x22492249 /* 29LV160B ID (16 M, bottom boot sect) */#define AMD_ID_DL163T 0x22282228 /* 29DL163T ID (16 M, top boot sector) */#define AMD_ID_DL163B 0x222B222B /* 29DL163B ID (16 M, bottom boot sect) */#define AMD_ID_LV320T 0x22F622F6 /* 29LV320T ID (32 M, top boot sector) */#define MX_ID_LV320T 0x22A722A7 /* 29LV320T by Macronix, AMD compatible */#define AMD_ID_LV320B 0x22F922F9 /* 29LV320B ID (32 M, bottom boot sect) */#define MX_ID_LV320B 0x22A822A8 /* 29LV320B by Macronix, AMD compatible */#define AMD_ID_DL322T 0x22552255 /* 29DL322T ID (32 M, top boot sector) */#define AMD_ID_DL322B 0x22562256 /* 29DL322B ID (32 M, bottom boot sect) */#define AMD_ID_DL323T 0x22502250 /* 29DL323T ID (32 M, top boot sector) */#define AMD_ID_DL323B 0x22532253 /* 29DL323B ID (32 M, bottom boot sect) */#define AMD_ID_DL324T 0x225C225C /* 29DL324T ID (32 M, top boot sector) */#define AMD_ID_DL324B 0x225F225F /* 29DL324B ID (32 M, bottom boot sect) */#define AMD_ID_DL640 0x227E227E /* 29DL640D ID (64 M, dual boot sectors)*/#define AMD_ID_MIRROR 0x227E227E /* 1st ID word for MirrorBit family */#define AMD_ID_DL640G_2 0x22022202 /* 2nd ID word for AM29DL640G at 0x38 */#define AMD_ID_DL640G_3 0x22012201 /* 3rd ID word for AM29DL640G at 0x3c */#define AMD_ID_LV640U_2 0x220C220C /* 2nd ID word for AM29LV640M at 0x38 */#define AMD_ID_LV640U_3 0x22012201 /* 3rd ID word for AM29LV640M at 0x3c */#define AMD_ID_LV640MT_2 0x22102210 /* 2nd ID word for AM29LV640MT at 0x38 */#define AMD_ID_LV640MT_3 0x22012201 /* 3rd ID word for AM29LV640MT at 0x3c */#define AMD_ID_LV640MB_2 0x22102210 /* 2nd ID word for AM29LV640MB at 0x38 */#define AMD_ID_LV640MB_3 0x22002200 /* 3rd ID word for AM29LV640MB at 0x3c */#define AMD_ID_LV128U_2 0x22122212 /* 2nd ID word for AM29LV128M at 0x38 */#define AMD_ID_LV128U_3 0x22002200 /* 3rd ID word for AM29LV128M at 0x3c */#define AMD_ID_LV256U_2 0x22122212 /* 2nd ID word for AM29LV256M at 0x38 */#define AMD_ID_LV256U_3 0x22012201 /* 3rd ID word for AM29LV256M at 0x3c */#define AMD_ID_GL064M_2 0x22132213 /* 2nd ID word for S29GL064M-R6 */#define AMD_ID_GL064M_3 0x22012201 /* 3rd ID word for S29GL064M-R6 */#define AMD_ID_GL064MT_2 0x22102210 /* 2nd ID word for S29GL064M-R3 (top boot sector) */#define AMD_ID_GL064MT_3 0x22012201 /* 3rd ID word for S29GL064M-R3 (top boot sector) */#define AMD_ID_GL128N_2 0x22212221 /* 2nd ID word for S29GL128N */#define AMD_ID_GL128N_3 0x22012201 /* 3rd ID word for S29GL128N */
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -