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

Subversion Repositories openrisc

[/] [openrisc/] [trunk/] [rtos/] [ecos-3.0/] [packages/] [hal/] [arm/] [pid/] [current/] [src/] [prog_flash.c] - Blame information for rev 786

Details | Compare with Previous | View Log

Line No. Rev Author Line
1 786 skrzyp
//==========================================================================
2
//
3
//        prog_flash.c
4
//
5
//        ARM PID7 eval board FLASH program tool
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):     gthomas
43
// Contributors:  gthomas
44
// Date:          1998-11-18
45
// Description:   Tool used to program onboard FLASH image
46
//####DESCRIPTIONEND####
47
 
48
//
49
// This program will program the FLASH on the PID board
50
// It is similar to 'flash' (which also downloads S records) but it always
51
// programs from a fixed buffer.  This is sufficient to load/update the GDB
52
// stubs on the board.
53
//
54
 
55
#include <pkgconf/libc.h>   // Configuration header
56
 
57
#include <cyg/kernel/kapi.h>
58
#include <stdlib.h>
59
#include <ctype.h>
60
#include <cyg/infra/testcase.h>
61
#include <sys/cstartup.h>
62
 
63
#ifndef FALSE
64
#define FALSE 0
65
#define TRUE  1
66
#endif
67
 
68
extern void diag_printf(const char *, ...);
69
int identify_FLASH(void);
70
void write_sector(int, char *);
71
 
72
char *flash_buffer =     (char *)0x60000;
73
char *flash_buffer_end = (char *)0x80000;
74
 
75
#ifdef BE_IMAGE
76
#define BUF(x) buf[x^3]
77
#else
78
#define BUF(x) buf[x]
79
#endif
80
 
81
// FUNCTIONS
82
 
83
externC void
84
cyg_package_start( void )
85
{
86
#ifdef CYGPKG_LIBC
87
    cyg_iso_c_start();
88
#else
89
    (void)main(0, NULL);
90
#endif
91
} // cyg_package_start()
92
 
93
int
94
main( int argc, char *argv[] )
95
{
96
    int i;
97
 
98
    diag_printf("FLASH here!\n");
99
    while (identify_FLASH() == 0) {
100
        diag_printf("... Please change FLASH jumper\n");
101
        cyg_thread_delay(5*100);
102
    }
103
    diag_printf("About to program FLASH using data at %x..%x\n", flash_buffer, flash_buffer_end);
104
    diag_printf("*** Press RESET now to abort!\n");
105
    cyg_thread_delay(5*100);
106
    diag_printf("\n");
107
    diag_printf("...Programming FLASH\n");
108
 
109
    i = 0;
110
    while (flash_buffer < flash_buffer_end) {
111
        write_sector(i++, flash_buffer);
112
        flash_buffer += 256;
113
    }
114
    diag_printf("All done!\n");
115
    while (1) ;
116
}
117
 
118
// Adapted from ARM sample code
119
#define SEQ_ADD1                0x5555
120
#define SEQ_ADD2                0xAAAA
121
#define START_CMD1              0xAA
122
#define START_CMD2              0x55
123
#define ID_CMD                  0x90
124
#define PROG_CMD                0xA0
125
#define STOP_CMD                0xF0
126
 
127
#define MAN_ATMEL               0x1F
128
#define ATMEL_AT29C040_ID       0X5B
129
#define ATMEL_AT29C040A_ID      0XA4
130
#define ATMEL_AT29C1024_ID      0X25
131
#define ATMEL_SECTOR_SIZE       256
132
#define ATMEL_MAX_SECTORS       2048
133
 
134
int manuf_code, device_code, sector_size, max_no_of_sectors, word_mode;
135
volatile char *FLASH = (volatile char *)0x04000000;
136
 
137
int
138
identify_FLASH(void )
139
{
140
    // Enter Software Product Identification Mode
141
    FLASH[SEQ_ADD1] = START_CMD1;
142
    FLASH[SEQ_ADD2] = START_CMD2;
143
    FLASH[SEQ_ADD1] = ID_CMD;
144
 
145
    // Wait at least 10ms
146
    cyg_thread_delay(2);
147
 
148
    // Read Manufacturer and device code from the device
149
    manuf_code = FLASH[0];
150
    device_code = FLASH[1];
151
 
152
    diag_printf("manuf: %x, device: %x\n", manuf_code, device_code);
153
 
154
    // Exit Software Product Identification Mode
155
    FLASH[SEQ_ADD1] = START_CMD1;
156
    FLASH[SEQ_ADD2] = START_CMD2;
157
    FLASH[SEQ_ADD1] = STOP_CMD;
158
 
159
    // Wait at least 10ms
160
    cyg_thread_delay(5);
161
 
162
    if (manuf_code != MAN_ATMEL) {
163
        diag_printf ( "Error: Wrong Manufaturer: %02x\n",manuf_code );
164
        return (0);
165
    }
166
 
167
    switch (device_code) {
168
    case  ATMEL_AT29C040A_ID:
169
        diag_printf ("AT29C040A recognised\n");
170
        sector_size = ATMEL_SECTOR_SIZE;
171
        max_no_of_sectors = ATMEL_MAX_SECTORS;
172
        word_mode = FALSE;
173
        break;
174
    case  ATMEL_AT29C1024_ID:
175
        diag_printf ("AT29C1024 recognised\n");
176
        sector_size = ATMEL_SECTOR_SIZE;
177
        max_no_of_sectors = ATMEL_MAX_SECTORS;
178
        word_mode = TRUE;
179
        break;
180
    default :
181
        diag_printf ( "Error: Unsupported device: %02x\n", device_code);
182
        return (0);
183
    }
184
    return (1);
185
}
186
 
187
void
188
write_sector(int num, char *buf)
189
{
190
    int i, cnt;
191
    volatile char *wrt = (volatile char *)&FLASH[num*sector_size];
192
 
193
//    diag_printf("Writing to %08x\n", wrt);
194
    // Enter Program Mode
195
    FLASH[SEQ_ADD1] = START_CMD1;
196
    FLASH[SEQ_ADD2] = START_CMD2;
197
    FLASH[SEQ_ADD1] = PROG_CMD;
198
 
199
    // Note: write bytes as longs regardless of bus width
200
    for (i = 0;  i < sector_size;  i++) {
201
        wrt[i] = BUF(i);
202
    }
203
 
204
    // Wait for sector to program
205
    cnt = 0;
206
    i = sector_size - 1;
207
    while (wrt[i] != BUF(i)) {
208
        if (cnt++ > 0x01000000) break;
209
    }
210
//    diag_printf("Out - i: %d, wrt[i] = %08X.%08X, BUF(i) = %08X, count = %x\n", i, &wrt[i], wrt[i], BUF(i), cnt);
211
 
212
    // Verify
213
    for (i = 0;  i < sector_size;  i++) {
214
        for (cnt = 0;  cnt < 10;  cnt++) {
215
            if (wrt[i] == BUF(i)) break;
216
            cyg_thread_delay(1);
217
        }
218
        if (cnt == 10) {
219
            diag_printf("Can't program at 0x%08X: %02X not %02X\n", wrt, *wrt, BUF(0));
220
        }
221
    }
222
}

powered by: WebSVN 2.1.0

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