📄 ixdp2400_flash.c
字号:
//==========================================================================
//
// ixdp2400_flash.c
//
// Flash programming
//
//==========================================================================
//####COPYRIGHTBEGIN####
//
// -------------------------------------------
// The contents of this file are subject to the Red Hat eCos Public License
// Version 1.1 (the "License"); you may not use this file except in
// compliance with the License. You may obtain a copy of the License at
// http://www.redhat.com/
//
// Software distributed under the License is distributed on an "AS IS"
// basis, WITHOUT WARRANTY OF ANY KIND, either express or implied. See the
// License for the specific language governing rights and limitations under
// the License.
//
// The Original Code is eCos - Embedded Configurable Operating System,
// released September 30, 1998.
//
// The Initial Developer of the Original Code is Red Hat.
// Portions created by Red Hat are
// Copyright (C) 1998, 1999, 2000 Red Hat, Inc.
// All Rights Reserved.
// -------------------------------------------
//
//####COPYRIGHTEND####
//==========================================================================
//#####DESCRIPTIONBEGIN####
//
// Author(s): lagarwal
// Contributors:
// Date: 2002-03-08
// Purpose:
// Description: contains routine to initialize flash device
//
//####DESCRIPTIONEND####
//
//==========================================================================
#include <pkgconf/hal.h>
#include <cyg/hal/hal_arch.h>
#include <cyg/hal/hal_cache.h>
#include <cyg/hal/cfg_utility.h>
#include <cyg/hal/hal_platform_ints.h>
#include <redboot.h>
#define _FLASH_PRIVATE_
#include <cyg/io/flash.h>
#include "flash.h"
extern struct board_config *board_config_data;
extern int strncmp(const char *s1, const char *s2, int len);
#ifndef CYGHWR_IO_FLASH_DEVICE_NOT_IN_RAM
// Use this function to make function pointers anonymous - forcing the
// compiler to use jumps instead of branches when calling driver
// services.
static void* __anonymizer(void* p)
{
return p;
}
#endif
int
flash_hwr_init(void)
{
unsigned char data[2];
typedef int code_fun(unsigned char *);
code_fun *_flash_query;
int stat, num_regions, region_size;
display_led('F', 'L', 'S', 'H');
#ifdef CYGHWR_IO_FLASH_DEVICE_NOT_IN_RAM
{
extern char flash_query, flash_query_end;
int code_len;
// Copy 'program' code to RAM for execution
code_len = (unsigned long)&flash_query_end - (unsigned long)&flash_query;
_flash_query = (code_fun *)flash_info.work_space;
memcpy(_flash_query, &flash_query, code_len);
HAL_DCACHE_SYNC(); // Should guarantee this code will run
HAL_ICACHE_DISABLE(); // is also required to avoid old contents
}
#else
{
externC code_fun flash_query;
_flash_query = (code_fun*) __anonymizer(&flash_query);
}
#endif
memset(data,0,2);
stat = (*_flash_query)(data);
#ifdef CYGHWR_IO_FLASH_DEVICE_NOT_IN_RAM
HAL_ICACHE_ENABLE();
#endif
if(data[0] != FLASH_Intel_code)
{
(*flash_info.pf)("Unknown flash manufacturer: 0x%02x\n", data[0]);
return FLASH_ERR_HWR;
}
switch (data[1])
{
case (unsigned char)0x18:
num_regions = 128;
region_size = 0x20000; //128K
break;
case (unsigned char)0x17:
num_regions = 64;
region_size = 0x20000;
break;
case (unsigned char)0x16:
num_regions = 32;
region_size = 0x20000;
break;
default:
(*flash_info.pf)("Unknown device type: 0x%02x\n", data[1]);
return FLASH_ERR_HWR;
}
board_config_data->flash_size = num_regions * region_size;
flash_info.block_size = region_size;
flash_info.blocks = num_regions;
flash_info.start = (void *)FLASH_BASE;
flash_info.end = (void *)(FLASH_BASE + (num_regions * region_size));
return FLASH_ERR_OK;
}
// Map a hardware status to a package error
int
flash_hwr_map_error(int err)
{
if (err & 0x7E) {
(*flash_info.pf)("Err = %x\n", err);
switch(err)
{
case(0x2):
return FLASH_ERR_PROTECT;
case(0x4):
return FLASH_ERR_PROGRAM_SUSPEND;
case(0x8):
return FLASH_ERR_LOW_VOLTAGE;
case(0x10):
return FLASH_ERR_LOCK;
case(0x20):
return FLASH_ERR_ERASE;
case(0x40):
return FLASH_ERR_ERASE_SUSPEND;
default:
return FLASH_ERR_HWR;
}
} else {
return FLASH_ERR_OK;
}
}
// See if a range of FLASH addresses overlaps BootMonitor code
bool
flash_code_overlaps(void *start, void *end, bool *overlap)
{
if(((FLASH_BASE >= (unsigned long)start) &&
(FLASH_BASE < (unsigned long)end)) ||
(((FLASH_BASE + CYGBLD_REDBOOT_MIN_IMAGE_SIZE) > (unsigned long)start) &&
((FLASH_BASE + CYGBLD_REDBOOT_MIN_IMAGE_SIZE) < (unsigned long)end)))
{
*overlap = true;
printf("Your action requires changes to BootMonitor blocks\n");
if(!verify_action("Continue"))
{
return true;
}
}
return false;
}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -