OpenCores
URL https://opencores.org/ocsvn/openrisc/openrisc/trunk

Subversion Repositories openrisc

[/] [openrisc/] [trunk/] [rtos/] [ecos-3.0/] [packages/] [devs/] [flash/] [synth/] [current/] [src/] [synth.c] - Blame information for rev 786

Details | Compare with Previous | View Log

Line No. Rev Author Line
1 786 skrzyp
//==========================================================================
2
//
3
//      synth.c
4
//
5
//      Flash programming
6
//
7
//==========================================================================
8
// ####ECOSGPLCOPYRIGHTBEGIN####                                            
9
// -------------------------------------------                              
10
// This file is part of eCos, the Embedded Configurable Operating System.   
11
// Copyright (C) 1998, 1999, 2000, 2001, 2002 Free Software Foundation, Inc.
12
//
13
// eCos is free software; you can redistribute it and/or modify it under    
14
// the terms of the GNU General Public License as published by the Free     
15
// Software Foundation; either version 2 or (at your option) any later      
16
// version.                                                                 
17
//
18
// eCos is distributed in the hope that it will be useful, but WITHOUT      
19
// ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or    
20
// FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License    
21
// for more details.                                                        
22
//
23
// You should have received a copy of the GNU General Public License        
24
// along with eCos; if not, write to the Free Software Foundation, Inc.,    
25
// 51 Franklin Street, Fifth Floor, Boston, MA  02110-1301, USA.            
26
//
27
// As a special exception, if other files instantiate templates or use      
28
// macros or inline functions from this file, or you compile this file      
29
// and link it with other works to produce a work based on this file,       
30
// this file does not by itself cause the resulting work to be covered by   
31
// the GNU General Public License. However the source code for this file    
32
// must still be made available in accordance with section (3) of the GNU   
33
// General Public License v2.                                               
34
//
35
// This exception does not invalidate any other reasons why a work based    
36
// on this file might be covered by the GNU General Public License.         
37
// -------------------------------------------                              
38
// ####ECOSGPLCOPYRIGHTEND####                                              
39
//==========================================================================
40
//#####DESCRIPTIONBEGIN####
41
//
42
// Author(s):    andrew.lunn@ascom.ch
43
// Contributors: jlarmour
44
// Date:         2001-10-30
45
// Purpose:      
46
// Description:  
47
//              
48
//####DESCRIPTIONEND####
49
//
50
//==========================================================================
51
 
52
#include <pkgconf/devs_flash_synth.h>
53
 
54
#include <cyg/hal/hal_io.h>
55
#include <cyg/infra/cyg_ass.h>
56
#include <errno.h>
57
#include <string.h>
58
 
59
#include <cyg/io/flash.h>
60
#include <cyg/io/flash_dev.h>
61
 
62
#include "synth.h"
63
 
64
/* Holds the fd for the flash file */
65
int cyg_dev_flash_synth_flashfd;
66
 
67
/* Holds the base address of the mmap'd region */
68
flash_t *cyg_dev_flash_synth_base;
69
 
70
int
71
flash_hwr_init(void)
72
{
73
    flash_info.block_size = CYGNUM_FLASH_SYNTH_BLOCKSIZE;
74
    flash_info.buffer_size = 0;
75
    flash_info.blocks = CYGNUM_FLASH_SYNTH_NUMBLOCKS;
76
 
77
    cyg_dev_flash_synth_flashfd = cyg_hal_sys_open(CYGDAT_FLASH_SYNTH_FILENAME,
78
                CYG_HAL_SYS_O_RDWR,
79
                CYG_HAL_SYS_S_IRWXU|CYG_HAL_SYS_S_IRWXG|CYG_HAL_SYS_S_IRWXO);
80
    if (cyg_dev_flash_synth_flashfd == -ENOENT) {
81
        long w, bytesleft;
82
        char buf[128];
83
 
84
        cyg_dev_flash_synth_flashfd = cyg_hal_sys_open(
85
                CYGDAT_FLASH_SYNTH_FILENAME,
86
                CYG_HAL_SYS_O_RDWR|CYG_HAL_SYS_O_CREAT,
87
                CYG_HAL_SYS_S_IRWXU|CYG_HAL_SYS_S_IRWXG|CYG_HAL_SYS_S_IRWXO);
88
        CYG_ASSERT( cyg_dev_flash_synth_flashfd >= 0,
89
                    "Opening of the file for the synth flash failed!");
90
        // fill with 0xff
91
        memset( buf, 0xff, sizeof(buf) );
92
        bytesleft = CYGNUM_FLASH_SYNTH_BLOCKSIZE * CYGNUM_FLASH_SYNTH_NUMBLOCKS;
93
        while (bytesleft > 0)
94
        {
95
            int bytesneeded;
96
            bytesneeded = bytesleft < sizeof(buf) ?  bytesleft : sizeof(buf);
97
 
98
            w = cyg_hal_sys_write( cyg_dev_flash_synth_flashfd, buf,
99
                                   bytesneeded );
100
            CYG_ASSERT(w == bytesneeded, "initialization of flash file failed");
101
            bytesleft -= bytesneeded;
102
        } // while
103
    }
104
    CYG_ASSERT( cyg_dev_flash_synth_flashfd >= 0,
105
                "Opening of the file for the synth flash failed!");
106
    if ( cyg_dev_flash_synth_flashfd <= 0 ) {
107
        return FLASH_ERR_HWR;
108
    }
109
    cyg_dev_flash_synth_base = (flash_t *)cyg_hal_sys_mmap(
110
#ifdef CYGMEM_FLASH_SYNTH_BASE
111
                (void *)CYGMEM_FLASH_SYNTH_BASE,
112
#else
113
                NULL,
114
#endif
115
                (CYGNUM_FLASH_SYNTH_BLOCKSIZE * CYGNUM_FLASH_SYNTH_NUMBLOCKS),
116
                CYG_HAL_SYS_PROT_READ,
117
#ifdef CYGSEM_FLASH_SYNTH_FILE_WRITEBACK
118
                CYG_HAL_SYS_MAP_SHARED
119
#else
120
                CYG_HAL_SYS_MAP_PRIVATE
121
#endif
122
#ifdef CYGMEM_FLASH_SYNTH_BASE
123
                |CYG_HAL_SYS_MAP_FIXED
124
#endif
125
                , cyg_dev_flash_synth_flashfd, 0 );
126
    CYG_ASSERT( cyg_dev_flash_synth_base != (void *) -1, "mmap of flash file failed!" );
127
 
128
    if (cyg_dev_flash_synth_base == (void *) -1) {
129
        return FLASH_ERR_HWR;
130
    }
131
    flash_info.start = cyg_dev_flash_synth_base;
132
    flash_info.end = (void *)(((char *)cyg_dev_flash_synth_base) -1 +
133
        (CYGNUM_FLASH_SYNTH_BLOCKSIZE * CYGNUM_FLASH_SYNTH_NUMBLOCKS));
134
 
135
    return FLASH_ERR_OK;
136
}
137
 
138
// Map a hardware status to a package error
139
int
140
flash_hwr_map_error(int err)
141
{
142
    return err;
143
}
144
 
145
// See if a range of FLASH addresses overlaps currently running code
146
bool
147
flash_code_overlaps(void *start, void *end)
148
{
149
    extern char _stext[], _etext[];
150
 
151
    return ((((unsigned long)&_stext >= (unsigned long)start) &&
152
             ((unsigned long)&_stext < (unsigned long)end)) ||
153
            (((unsigned long)&_etext >= (unsigned long)start) &&
154
             ((unsigned long)&_etext < (unsigned long)end)));
155
}
156
 
157
// EOF synth.c

powered by: WebSVN 2.1.0

© copyright 1999-2024 OpenCores.org, equivalent to Oliscience, all rights reserved. OpenCores®, registered trademark.