📄 amd_flash.c
字号:
/* * File: amd_flash.c * Purpose: Flash driver for programming all AMD Flash devices * * Notes: This driver supports a single type and width of AMD * Flash. The type and width is determined at compile * time. Multiple devices of the same type and width * are supported. * * Modifications: * * License: All software covered by license agreement in - * dbug/docs/Freescale_Software_License.pdf */#include "common.h"/* * Compiler specific code relocation section */#ifdef __DCC__#pragma section CODE ".code_relocation"#pragma section CONST ".code_relocation"#elif (defined(__ghs__))#pragma ghs section text=".code_relocation"#endif#include "amd_flash.h"/********************************************************************//* * Global pointer to base of AMD Flash device * Initialized in amd_flash_init() */#ifdef __MWERKS____relocate_data__#endifAMD_FLASH_CELL *pFlash;/********************************************************************//* * Flash sector definitions */#ifdef AMD_FLASH_AM29LV004BT #ifdef __MWERKS__ __relocate_const__ #else const #endif AMD_FLASH_SECTOR_INFO sector[] #if defined(__GNUC__) __attribute__ ((section(".data"))) #endif /* defined(__GNUC__) */ = { /* Top Boot */ {64*1024, 0x000000}, /* SA0 */ {64*1024, 0x010000}, /* SA1 */ {64*1024, 0x020000}, /* SA2 */ {64*1024, 0x030000}, /* SA3 */ {64*1024, 0x040000}, /* SA4 */ {64*1024, 0x050000}, /* SA5 */ {64*1024, 0x060000}, /* SA6 */ {32*1024, 0x070000}, /* SA7 */ { 8*1024, 0x078000}, /* SA8 */ { 8*1024, 0x07A000}, /* SA9 */ {16*1024, 0x07C000} /* SA10 */ }; #elif ( defined(AMD_FLASH_AM29LV004BB) || \ defined(ATMEL_FLASH_AT49BV040A)) #ifdef __MWERKS__ __relocate_const__ #else const #endif AMD_FLASH_SECTOR_INFO sector[] #if defined(__GNUC__) __attribute__ ((section(".data"))) #endif /* defined(__GNUC__) */ = { /* Bottom Boot */ {16*1024, 0x000000}, /* SA0 */ { 8*1024, 0x004000}, /* SA1 */ { 8*1024, 0x006000}, /* SA2 */ {32*1024, 0x008000}, /* SA3 */ {64*1024, 0x010000}, /* SA4 */ {64*1024, 0x020000}, /* SA5 */ {64*1024, 0x030000}, /* SA6 */ {32*1024, 0x040000}, /* SA7 */ {64*1024, 0x050000}, /* SA8 */ {64*1024, 0x060000}, /* SA9 */ {64*1024, 0x070000} /* SA10 */ }; #elif defined(AMD_FLASH_AM29PL160CB_16BIT) #ifdef __MWERKS__ __relocate_const__ #else const #endif AMD_FLASH_SECTOR_INFO sector[] #if defined(__GNUC__) __attribute__ ((section(".data"))) #endif /* defined(__GNUC__) */ = { /* Bottom Boot */ { 16*1024, 0x000000}, /* SA0 */ { 8*1024, 0x004000}, /* SA1 */ { 8*1024, 0x006000}, /* SA2 */ {224*1024, 0x008000}, /* SA3 */ {256*1024, 0x040000}, /* SA4 */ {256*1024, 0x080000}, /* SA5 */ {256*1024, 0x0C0000}, /* SA6 */ {256*1024, 0x100000}, /* SA7 */ {256*1024, 0x140000}, /* SA8 */ {256*1024, 0x180000}, /* SA9 */ {256*1024, 0x1C0000} /* SA10 */ }; #elif defined(AMD_FLASH_AM29LV160DB_16BIT) #ifdef __MWERKS__ __relocate_const__ #else const #endif AMD_FLASH_SECTOR_INFO sector[] #if defined(__GNUC__) __attribute__ ((section(".data"))) #endif /* defined(__GNUC__) */ = { /* Bottom Boot */ {16*1024, 0x000000}, /* SA0 */ { 8*1024, 0x004000}, /* SA1 */ { 8*1024, 0x006000}, /* SA2 */ {32*1024, 0x008000}, /* SA3 */ {64*1024, 0x010000}, /* SA4 */ {64*1024, 0x020000}, /* SA5 */ {64*1024, 0x030000}, /* SA6 */ {64*1024, 0x040000}, /* SA7 */ {64*1024, 0x050000}, /* SA8 */ {64*1024, 0x060000}, /* SA9 */ {64*1024, 0x070000}, /* SA10 */ {64*1024, 0x080000}, /* SA11 */ {64*1024, 0x090000}, /* SA12 */ {64*1024, 0x0A0000}, /* SA13 */ {64*1024, 0x0B0000}, /* SA14 */ {64*1024, 0x0C0000}, /* SA15 */ {64*1024, 0x0D0000}, /* SA16 */ {64*1024, 0x0E0000}, /* SA17 */ {64*1024, 0x0F0000}, /* SA18 */ {64*1024, 0x100000}, /* SA19 */ {64*1024, 0x110000}, /* SA20 */ {64*1024, 0x120000}, /* SA21 */ {64*1024, 0x130000}, /* SA22 */ {64*1024, 0x140000}, /* SA23 */ {64*1024, 0x150000}, /* SA24 */ {64*1024, 0x160000}, /* SA25 */ {64*1024, 0x170000}, /* SA26 */ {64*1024, 0x180000}, /* SA27 */ {64*1024, 0x190000}, /* SA28 */ {64*1024, 0x1A0000}, /* SA29 */ {64*1024, 0x1B0000}, /* SA30 */ {64*1024, 0x1C0000}, /* SA31 */ {64*1024, 0x1D0000}, /* SA32 */ {64*1024, 0x1E0000}, /* SA33 */ {64*1024, 0x1F0000} /* SA34 */ }; #elif ( defined(AMD_FLASH_AM29BDD160GB_32BIT) || \ defined(AMD_FLASH_AM29BDD160GB_16BIT) ) #ifdef __MWERKS__ __relocate_const__ #else const #endif AMD_FLASH_SECTOR_INFO sector[] #if defined(__GNUC__) __attribute__ ((section(".data"))) #endif /* defined(__GNUC__) */ = { /* Bottom Boot */ { 8*1024, 0x000000}, /* SA0 */ { 8*1024, 0x002000}, /* SA1 */ { 8*1024, 0x004000}, /* SA2 */ { 8*1024, 0x006000}, /* SA3 */ { 8*1024, 0x008000}, /* SA4 */ { 8*1024, 0x00A000}, /* SA5 */ { 8*1024, 0x00C000}, /* SA6 */ { 8*1024, 0x00E000}, /* SA7 */ {64*1024, 0x010000}, /* SA8 */ {64*1024, 0x020000}, /* SA9 */ {64*1024, 0x030000}, /* SA10 */ {64*1024, 0x040000}, /* SA11 */ {64*1024, 0x050000}, /* SA12 */ {64*1024, 0x060000}, /* SA13 */ {64*1024, 0x070000}, /* SA14 */ {64*1024, 0x080000}, /* SA15 */ {64*1024, 0x090000}, /* SA16 */ {64*1024, 0x0A0000}, /* SA17 */ {64*1024, 0x0B0000}, /* SA18 */ {64*1024, 0x0C0000}, /* SA19 */ {64*1024, 0x0D0000}, /* SA20 */ {64*1024, 0x0E0000}, /* SA21 */ {64*1024, 0x0F0000}, /* SA22 */ {64*1024, 0x100000}, /* SA23 */ {64*1024, 0x110000}, /* SA24 */ {64*1024, 0x120000}, /* SA25 */ {64*1024, 0x130000}, /* SA26 */ {64*1024, 0x140000}, /* SA27 */ {64*1024, 0x150000}, /* SA28 */ {64*1024, 0x160000}, /* SA29 */ {64*1024, 0x170000}, /* SA30 */ {64*1024, 0x180000}, /* SA31 */ {64*1024, 0x190000}, /* SA32 */ {64*1024, 0x1A0000}, /* SA33 */ {64*1024, 0x1B0000}, /* SA34 */ {64*1024, 0x1C0000}, /* SA35 */ {64*1024, 0x1D0000}, /* SA36 */ {64*1024, 0x1E0000}, /* SA37 */ { 8*1024, 0x1F0000}, /* SA38 */ { 8*1024, 0x1F2000}, /* SA39 */ { 8*1024, 0x1F4000}, /* SA40 */ { 8*1024, 0x1F6000}, /* SA41 */ { 8*1024, 0x1F8000}, /* SA42 */ { 8*1024, 0x1FA000}, /* SA43 */ { 8*1024, 0x1FC000}, /* SA44 */ { 8*1024, 0x1FE000} /* SA45 */ };#elif (defined(AMD_FLASH_AM29LV640M_16BIT) || \ defined(AMD_FLASH_AM29LV640MH_16BIT) || \ defined(AMD_FLASH_AM29LV640ML_16BIT) || \ defined(AMD_FLASH_AM29LV128M_16BIT) || \ defined(AMD_FLASH_AM29LV128MH_16BIT) || \ defined(AMD_FLASH_AM29LV128ML_16BIT)) /* Uniform sectors (64KBytes) */ #define SSIZE(n) (0x10000 * AMD_FLASH_DEVICES) #define SOFFSET(n) (SSIZE(n) * n) #define SADDR(n) (SOFFSET(n) >> AMD_FLASH_BUS_SHIFT)#else#error "Unsupported Flash device"#endif#ifndef SSIZE#define SSIZE(n) (sector[n].size * AMD_FLASH_DEVICES)#endif#ifndef SOFFSET#define SOFFSET(n) (sector[n].offset * AMD_FLASH_DEVICES)#endif#ifndef SADDR#define SADDR(n) (SOFFSET(n) >> AMD_FLASH_BUS_SHIFT)#endif/********************************************************************/#ifdef __MWERKS____relocate_code__#elif defined(__GNUC__)void amd_flash_init(ADDRESS base) __attribute__ ((section(".code_relocation")));#endif /* defined(__GNUC__) */voidamd_flash_init(ADDRESS base){ pFlash = (AMD_FLASH_CELL *)base;}/********************************************************************/#ifdef __MWERKS____relocate_code__#elif defined(__GNUC__)AMD_FLASH_CELL amd_flash_product_id(int code) __attribute__ ((section(".code_relocation")));#endif /* defined(__GNUC__) */AMD_FLASH_CELL amd_flash_product_id(int code){ AMD_FLASH_CELL result; pFlash[0x555] = AMD_FLASH_CMD_DATA(0xAA); pFlash[0xAAA] = AMD_FLASH_CMD_DATA(0x55); pFlash[0x555] = AMD_FLASH_CMD_DATA(0x90); result = *(AMD_FLASH_CELL*)(pFlash+code); /* Place device back in normal read mode */ pFlash[0] = AMD_FLASH_CMD_DATA(0xF0); return result;}/********************************************************************/#ifdef __MWERKS____relocate_code__#elif defined(__GNUC__)void amd_flash_sector_erase(int n) __attribute__ ((section(".code_relocation")));
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -